summaryrefslogtreecommitdiffstats
path: root/wifi/java/android/net
diff options
context:
space:
mode:
authorRobert Greenwalt <robdroid@android.com>2009-05-22 15:09:51 -0700
committerRobert Greenwalt <robdroid@android.com>2009-05-28 13:37:06 -0700
commitfc1b15cfbfc5f69235ec1f367abd7a909381cd05 (patch)
treeeeca713d5c9078989763d3777aafd41007a2846f /wifi/java/android/net
parent1cb62b83241c5d1cac9e9cda60d0d5d9218b44fb (diff)
downloadframeworks_base-fc1b15cfbfc5f69235ec1f367abd7a909381cd05.zip
frameworks_base-fc1b15cfbfc5f69235ec1f367abd7a909381cd05.tar.gz
frameworks_base-fc1b15cfbfc5f69235ec1f367abd7a909381cd05.tar.bz2
Fix wifi multicast API for public use.
Applying API review comments and taking it public.
Diffstat (limited to 'wifi/java/android/net')
-rw-r--r--wifi/java/android/net/wifi/IWifiManager.aidl4
-rw-r--r--wifi/java/android/net/wifi/WifiManager.java143
-rw-r--r--wifi/java/android/net/wifi/WifiStateTracker.java6
3 files changed, 110 insertions, 43 deletions
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl
index 7c3af69..3d65d3c 100644
--- a/wifi/java/android/net/wifi/IWifiManager.aidl
+++ b/wifi/java/android/net/wifi/IWifiManager.aidl
@@ -72,8 +72,8 @@ interface IWifiManager
boolean isMulticastEnabled();
- void enableMulticast(IBinder binder, String tag);
+ void acquireMulticastLock(IBinder binder, String tag);
- void disableMulticast();
+ void releaseMulticastLock();
}
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 1a7caef..5b8ced6 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -824,62 +824,127 @@ public class WifiManager {
return new WifiLock(WIFI_MODE_FULL, tag);
}
+
/**
- * Check multicast filter status.
+ * Create a new MulticastLock
*
- * @return true if multicast packets are allowed.
+ * @param tag a tag for the MulticastLock to identify it in debugging
+ * messages.
*
- * @hide pending API council approval
+ * @return a new, unacquired MulticastLock with the given tag.
+ *
+ * @see MulticastLock
*/
- public boolean isMulticastEnabled() {
- try {
- return mService.isMulticastEnabled();
- } catch (RemoteException e) {
- return false;
- }
+ public MulticastLock createMulticastLock(String tag) {
+ return new MulticastLock(tag);
}
/**
- * Turn on the reception of multicast packets.
- * The default behavior is to disable multicast packets as they
- * have a noticable negative effect on battery life. An
- * application can turn them on, but should not leave it on for longer
- * than needed. When the app quits (or crashes) its request will
- * be reverted.
- *
- * @param tag a string associated with this request for debugging.
- *
- * @return true on success
- *
- * @see #disableMulticast
- *
- * @hide pending API council approval
+ * Allows an application to receive Wifi Multicast packets.
+ * Normally the Wifi stack filters out packets not explicitly
+ * addressed to this device. Acquring a MulticastLock will
+ * cause the stack to receive packets addressed to multicast
+ * addresses. Processing these extra packets can cause a noticable
+ * battery drain and should be disabled when not needed
*/
- public boolean enableMulticast(String tag) {
- try {
- mService.enableMulticast(new Binder(), tag);
- return true;
- } catch (RemoteException e) {
- return false;
+ public class MulticastLock {
+ private String mTag;
+ private final IBinder mBinder;
+ private boolean mHeld;
+
+ private MulticastLock(String tag) {
+ mTag = tag;
+ mBinder = new Binder();
+ mHeld = false;
+ }
+
+ /**
+ * Locks Wifi Multicast on until {@link #release} is called.
+ *
+ * The first call to {@code acquire} will lock the Multicast on
+ * but subsequent calls will be ignored. Only one call to
+ * {@link #release} will be required, regardless of the number of
+ * times that {@code acquire} is called.
+ *
+ * Note that other applications may also lock Wifi Multicast on.
+ * Only they can relinquish their lock.
+ *
+ * Also note that applications cannot leave Multicast locked on.
+ * When an app exits or crashes, any Multicast locks will be released.
+ */
+ public void acquire() {
+ synchronized (mBinder) {
+ if (!mHeld) {
+ try {
+ mService.acquireMulticastLock(mBinder, mTag);
+ mHeld = true;
+ } catch (RemoteException ignore) {
+ }
+ }
+ }
+ }
+
+ /**
+ * Unlocks Wifi Multicast, restoring the filter of packets
+ * not addressed specifically to this device and saving power.
+ *
+ * Note that if any other Wifi Multicast Locks are still outstanding
+ * this {@code release} call will not have an immediate effect. Only
+ * when all applications have released all their Multicast Locks will
+ * the Multicast filter be turned back on.
+ *
+ * Also note that when an app exits or crashes all of its Multicast
+ * Locks will be automatically released.
+ */
+ public void release() {
+ synchronized (mBinder) {
+ if (mHeld) {
+ try {
+ mService.releaseMulticastLock();
+ mHeld = false;
+ } catch (RemoteException ignore) {
+ }
+ }
+ }
+ }
+
+ /**
+ * Checks whether this MulticastLock is currently held.
+ *
+ * @return true if this MulticastLock is held, false otherwise
+ */
+ public boolean isHeld() {
+ synchronized (mBinder) {
+ return mHeld;
+ }
+ }
+
+ public String toString() {
+ String s1, s2;
+ synchronized (mBinder) {
+ s1 = Integer.toHexString(System.identityHashCode(this));
+ s2 = mHeld ? "held; " : "";
+ return "MulticastLock{ " + s1 + "; " + s2 + " }";
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ release();
}
}
/**
- * Return to the default multicast-off setting.
- * Note that if others had turned on Multicast reception, your
- * call will not turn it back off - they must also turn off their
- * request for multicast reception.
- *
- * @return true on success
+ * Check multicast filter status.
*
- * @see #enableMulticast
+ * @return true if multicast packets are allowed.
*
* @hide pending API council approval
*/
- public boolean disableMulticast() {
+ public boolean isMulticastEnabled() {
try {
- mService.disableMulticast();
- return true;
+ return mService.isMulticastEnabled();
} catch (RemoteException e) {
return false;
}
diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java
index 6771136..2fbc779 100644
--- a/wifi/java/android/net/wifi/WifiStateTracker.java
+++ b/wifi/java/android/net/wifi/WifiStateTracker.java
@@ -747,8 +747,10 @@ public class WifiStateTracker extends NetworkStateTracker {
* first and then off.. if nobody else wants it on it'll be
* off then and it's all synchronized within the API.
*/
- mWM.enableMulticast("WifiStateTracker");
- mWM.disableMulticast();
+ WifiManager.MulticastLock l =
+ mWM.createMulticastLock("WifiStateTracker");
+ l.acquire();
+ l.release();
if (mBluetoothA2dp == null) {
mBluetoothA2dp = new BluetoothA2dp(mContext);