diff options
| author | 2020-07-27 19:14:36 -0700 | |
|---|---|---|
| committer | 2020-08-05 10:26:39 -0700 | |
| commit | 4c789e0168c0b7b200dddc190c1731b5c553c387 (patch) | |
| tree | 1db30fa5b6ac8de51b47eb801b8fd44bdf691f11 | |
| parent | b20a507711ff467a8b088901afc17fa01d4e0281 (diff) | |
Fixed how com.android.server.pm.Settings handle pre-created users.
Its getAllUsers() method was not returning pre-created users, so
packages installed for a "regular" user were not marked as
"installed=false" for the pre-created users. Hence, when the
pre-created was "promoted" to a full user, it contained such
packages.
Here's how to reproduce the issue:
$ m -j ApiDemos
$ adb shell pm create-user --pre-create-only
Success: created user id 10
$ adb install --user cur $OUT/testcases/ApiDemos/arm64/ApiDemos.apk
Performing Streamed Install
Success
$ adb shell pm list packages --user cur | grep com.example.android.apis || echo
package:com.example.android.apis
$ adb shell pm list packages --user 10 | grep com.example.android.apis || echo "NOT FOUND"
package:com.example.android.apis # Should return "NOT FOUND"
$ adb shell pm create-user FullUserIAm
Success: created user id 10
$ adb shell pm list packages --user 10 | grep com.example.android.apis || echo "NOT FOUND"
package:com.example.android.apis # Should return "NOT FOUND"
With this fix, it returns "NOT FOUND" in the expected steps.
Fixes: 160252062
Fixes: 162847145
Test: see above
Change-Id: I6cd17ac588a4d95bf0ea704dd18387e19eeab374
(cherry picked from commit 00175974ba24d982ecfe760ee78a1a17bb326d04)
| -rw-r--r-- | services/core/java/com/android/server/pm/Settings.java | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java index 3de2dc2fdef3..a0feb94fd3fc 100644 --- a/services/core/java/com/android/server/pm/Settings.java +++ b/services/core/java/com/android/server/pm/Settings.java @@ -2709,7 +2709,7 @@ public final class Settings { private void writePackageListLPrInternal(int creatingUserId) { // Only derive GIDs for active users (not dying) - final List<UserInfo> users = getUsers(UserManagerService.getInstance(), true); + final List<UserInfo> users = getActiveUsers(UserManagerService.getInstance(), true); int[] userIds = new int[users.size()]; for (int i = 0; i < userIds.length; i++) { userIds[i] = users.get(i).id; @@ -4449,25 +4449,43 @@ public final class Settings { } /** - * Return all users on the device, including partial or dying users. + * Returns all users on the device, including pre-created and dying users. + * * @param userManager UserManagerService instance * @return the list of users */ private static List<UserInfo> getAllUsers(UserManagerService userManager) { - return getUsers(userManager, false); + return getUsers(userManager, /* excludeDying= */ false, /* excludePreCreated= */ false); + } + + /** + * Returns the list of users on the device, excluding pre-created ones. + * + * @param userManager UserManagerService instance + * @param excludeDying Indicates whether to exclude any users marked for deletion. + * + * @return the list of users + */ + private static List<UserInfo> getActiveUsers(UserManagerService userManager, + boolean excludeDying) { + return getUsers(userManager, excludeDying, /* excludePreCreated= */ true); } /** - * Return the list of users on the device. Clear the calling identity before calling into - * UserManagerService. + * Returns the list of users on the device. + * * @param userManager UserManagerService instance * @param excludeDying Indicates whether to exclude any users marked for deletion. + * @param excludePreCreated Indicates whether to exclude any pre-created users. + * * @return the list of users */ - private static List<UserInfo> getUsers(UserManagerService userManager, boolean excludeDying) { + private static List<UserInfo> getUsers(UserManagerService userManager, boolean excludeDying, + boolean excludePreCreated) { long id = Binder.clearCallingIdentity(); try { - return userManager.getUsers(excludeDying); + return userManager.getUsers(/* excludePartial= */ true, excludeDying, + excludePreCreated); } catch (NullPointerException npe) { // packagemanager not yet initialized } finally { |