From c6a61a6b0ce93a5ede0842fdaefca73a1bf243a9 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Wed, 18 Dec 2019 07:01:25 +0100 Subject: [PATCH] Fix IsolatedUidAllocator for non-primary users. The UID allocator stores complete UIDs, not app IDs. When removing a UID from the range, we should therefore also use the UID, not the app ID. Also added a test to cover this scenario, which passes with this change. Bug: 146313311 Test: atest ActivityManagerTest Change-Id: I1118ec73dcee5987e12f35aabce5cfa8cbe407a1 (cherry picked from commit c9a0df2d88884617b86c09a0ab86363200d6a66d) --- .../java/com/android/server/am/ProcessList.java | 4 +--- .../server/am/ActivityManagerServiceTest.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/am/ProcessList.java b/services/core/java/com/android/server/am/ProcessList.java index fe29a36ec45f3..278163b9dfe4d 100644 --- a/services/core/java/com/android/server/am/ProcessList.java +++ b/services/core/java/com/android/server/am/ProcessList.java @@ -422,9 +422,7 @@ public final class ProcessList { @GuardedBy("ProcessList.this.mService") void freeIsolatedUidLocked(int uid) { - // Strip out userId - final int appId = UserHandle.getAppId(uid); - mUidUsed.delete(appId); + mUidUsed.delete(uid); } }; diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/am/ActivityManagerServiceTest.java index 3df6976a2caef..2b849e71fdafb 100644 --- a/services/tests/servicestests/src/com/android/server/am/ActivityManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/am/ActivityManagerServiceTest.java @@ -346,10 +346,21 @@ public class ActivityManagerServiceTest { verifyUidRangesNoOverlap(range, range2); verifyIsolatedUidAllocator(range2); - // Free both, then try to allocate the maximum number of UID ranges + // Free both allocator.freeUidRangeLocked(appInfo); allocator.freeUidRangeLocked(appInfo2); + // Verify for a secondary user + ApplicationInfo appInfo3 = new ApplicationInfo(); + appInfo3.processName = "com.android.test.app"; + appInfo3.uid = 1010000; + final IsolatedUidRange range3 = allocator.getOrCreateIsolatedUidRangeLocked( + appInfo3.processName, appInfo3.uid); + validateAppZygoteIsolatedUidRange(range3); + verifyIsolatedUidAllocator(range3); + + allocator.freeUidRangeLocked(appInfo3); + // Try to allocate the maximum number of UID ranges int maxNumUidRanges = (Process.LAST_APP_ZYGOTE_ISOLATED_UID - Process.FIRST_APP_ZYGOTE_ISOLATED_UID + 1) / Process.NUM_UIDS_PER_APP_ZYGOTE; for (int i = 0; i < maxNumUidRanges; i++) {