summaryrefslogtreecommitdiffstats
path: root/wifi
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-05-28 14:34:28 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-05-28 14:34:28 -0700
commit96cdc61c69aa735e65295a50e3e2922425b3c877 (patch)
tree7d88100a2f15856e87086c6dee8a85cad656e1a4 /wifi
parentaebadd2cf489948847f262d917ee39cb285815b3 (diff)
parent1e2e44e900cb9a25d548e27a20d65292a7f321bc (diff)
downloadframeworks_base-96cdc61c69aa735e65295a50e3e2922425b3c877.zip
frameworks_base-96cdc61c69aa735e65295a50e3e2922425b3c877.tar.gz
frameworks_base-96cdc61c69aa735e65295a50e3e2922425b3c877.tar.bz2
am 1e2e44e9: Merge change 2365 into donut
Merge commit '1e2e44e900cb9a25d548e27a20d65292a7f321bc' * commit '1e2e44e900cb9a25d548e27a20d65292a7f321bc': Fix wifi multicast API for public use. Revert "Bug fixes and performance improvements"
Diffstat (limited to 'wifi')
-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 0db868e..c31577c 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 141d53f..c4dff6a 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -825,62 +825,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 7ba124f..e6f4130 100644
--- a/wifi/java/android/net/wifi/WifiStateTracker.java
+++ b/wifi/java/android/net/wifi/WifiStateTracker.java
@@ -755,8 +755,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);