diff options
| author | 2010-09-30 19:47:00 -0700 | |
|---|---|---|
| committer | 2010-09-30 19:47:00 -0700 | |
| commit | fc32a6023676c2f1b13c890c7295cccad6f0000c (patch) | |
| tree | 604c67c12fdfa067a9709fcac1eabe025fb03785 | |
| parent | 9e95468bbb4b4cb48d817cee2960681aa876b12a (diff) | |
| parent | 0f064de830d11ddb08a3c000b894b46aa530348a (diff) | |
am 0f064de8: am 27358a69: Only allow 8 OBBs to be mounted by a UID
Merge commit '0f064de830d11ddb08a3c000b894b46aa530348a'
* commit '0f064de830d11ddb08a3c000b894b46aa530348a':
Only allow 8 OBBs to be mounted by a UID
| -rw-r--r-- | services/java/com/android/server/MountService.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java index 509fb995c309..43c0f6ebf5ae 100644 --- a/services/java/com/android/server/MountService.java +++ b/services/java/com/android/server/MountService.java @@ -76,6 +76,8 @@ class MountService extends IMountService.Stub private static final String VOLD_TAG = "VoldConnector"; + protected static final int MAX_OBBS = 8; + /* * Internal vold volume state constants */ @@ -156,6 +158,7 @@ class MountService extends IMountService.Stub * Mounted OBB tracking information. Used to track the current state of all * OBBs. */ + final private Map<Integer, Integer> mObbUidUsage = new HashMap<Integer, Integer>(); final private Map<IObbActionListener, List<ObbState>> mObbMounts = new HashMap<IObbActionListener, List<ObbState>>(); final private Map<String, ObbState> mObbPathToStateMap = new HashMap<String, ObbState>(); @@ -1589,6 +1592,12 @@ class MountService extends IMountService.Stub } final int callerUid = Binder.getCallingUid(); + + final Integer uidUsage = mObbUidUsage.get(callerUid); + if (uidUsage != null && uidUsage > MAX_OBBS) { + throw new IllegalStateException("Maximum number of OBBs mounted!"); + } + obbState = new ObbState(filename, token, callerUid); addObbState(obbState); } @@ -1650,6 +1659,15 @@ class MountService extends IMountService.Stub } obbStates.add(obbState); mObbPathToStateMap.put(obbState.filename, obbState); + + // Track the number of OBBs used by this UID. + final int uid = obbState.callerUid; + final Integer uidUsage = mObbUidUsage.get(uid); + if (uidUsage == null) { + mObbUidUsage.put(uid, 1); + } else { + mObbUidUsage.put(uid, uidUsage + 1); + } } } @@ -1663,6 +1681,20 @@ class MountService extends IMountService.Stub mObbMounts.remove(obbState.token); } mObbPathToStateMap.remove(obbState.filename); + + // Track the number of OBBs used by this UID. + final int uid = obbState.callerUid; + final Integer uidUsage = mObbUidUsage.get(uid); + if (uidUsage == null) { + Slog.e(TAG, "Called removeObbState for UID that isn't in map: " + uid); + } else { + final int newUsage = uidUsage - 1; + if (newUsage == 0) { + mObbUidUsage.remove(uid); + } else { + mObbUidUsage.put(uid, newUsage); + } + } } } |