summaryrefslogtreecommitdiffstats
path: root/wifi/java/android/net
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-07-06 09:12:56 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-07-06 09:12:56 -0700
commitfca3ae1517b19c3cd40b761cd4bc134e98c0c565 (patch)
tree56c6d5432fb6d17ae831bd1e5271e6cd5fcb3069 /wifi/java/android/net
parent699379f974b08f349418b05b55da221b9bab07a0 (diff)
parent3bc64a2cb97da7bf7dc203416ad6c7d86c5925fc (diff)
downloadframeworks_base-fca3ae1517b19c3cd40b761cd4bc134e98c0c565.zip
frameworks_base-fca3ae1517b19c3cd40b761cd4bc134e98c0c565.tar.gz
frameworks_base-fca3ae1517b19c3cd40b761cd4bc134e98c0c565.tar.bz2
am 3bc64a2c: Merge change 6088 into donut
Merge commit '3bc64a2cb97da7bf7dc203416ad6c7d86c5925fc' * commit '3bc64a2cb97da7bf7dc203416ad6c7d86c5925fc': WifiManager: Limit the number of WifiLocks that can be active simultaneously.
Diffstat (limited to 'wifi/java/android/net')
-rw-r--r--wifi/java/android/net/wifi/WifiManager.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index c4dff6a..79b8fc4 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -253,6 +253,15 @@ public class WifiManager {
IWifiManager mService;
Handler mHandler;
+ /* Maximum number of active locks we allow.
+ * This limit was added to prevent apps from creating a ridiculous number
+ * of locks and crashing the system by overflowing the global ref table.
+ */
+ private static final int MAX_ACTIVE_LOCKS = 50;
+
+ /* Number of currently active WifiLocks and MulticastLocks */
+ private int mActiveLockCount;
+
/**
* Create a new WifiManager instance.
* Applications will almost always want to use
@@ -703,6 +712,14 @@ public class WifiManager {
if (mRefCounted ? (++mRefCount > 0) : (!mHeld)) {
try {
mService.acquireWifiLock(mBinder, mLockType, mTag);
+ synchronized (WifiManager.this) {
+ if (mActiveLockCount >= MAX_ACTIVE_LOCKS) {
+ mService.releaseWifiLock(mBinder);
+ throw new UnsupportedOperationException(
+ "Exceeded maximum number of wifi locks");
+ }
+ mActiveLockCount++;
+ }
} catch (RemoteException ignore) {
}
mHeld = true;
@@ -727,6 +744,9 @@ public class WifiManager {
if (mRefCounted ? (--mRefCount == 0) : (mHeld)) {
try {
mService.releaseWifiLock(mBinder);
+ synchronized (WifiManager.this) {
+ mActiveLockCount--;
+ }
} catch (RemoteException ignore) {
}
mHeld = false;
@@ -784,6 +804,9 @@ public class WifiManager {
if (mHeld) {
try {
mService.releaseWifiLock(mBinder);
+ synchronized (WifiManager.this) {
+ mActiveLockCount--;
+ }
} catch (RemoteException ignore) {
}
}
@@ -878,6 +901,14 @@ public class WifiManager {
if (!mHeld) {
try {
mService.acquireMulticastLock(mBinder, mTag);
+ synchronized (WifiManager.this) {
+ if (mActiveLockCount >= MAX_ACTIVE_LOCKS) {
+ mService.releaseMulticastLock();
+ throw new UnsupportedOperationException(
+ "Exceeded maximum number of wifi locks");
+ }
+ mActiveLockCount++;
+ }
mHeld = true;
} catch (RemoteException ignore) {
}
@@ -902,6 +933,9 @@ public class WifiManager {
if (mHeld) {
try {
mService.releaseMulticastLock();
+ synchronized (WifiManager.this) {
+ mActiveLockCount--;
+ }
mHeld = false;
} catch (RemoteException ignore) {
}