summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Amith Yamasani <yamasani@google.com> 2019-04-19 13:39:51 -0700
committer Amith Yamasani <yamasani@google.com> 2019-04-19 13:39:51 -0700
commite744669389a9e9ba9995ec79e739021b46dc6571 (patch)
treea7e98aede1eaa66a288fc06097829ad97755fa9f
parent3a15b6c1dfef54f41cc8938aba0a5ede6902a7dd (diff)
Clear calling identity before calling into UserManagerService
For cases where the settings are being written synchronously from an API call, make sure to clear the calling identity before querying users to avoid a SecurityException. Bug: 113105346 Test: atest CtsContentTestCases:PackageManagerTest Change-Id: I28b78dce99d36caa58ab448476ec01a51689246b
-rw-r--r--services/core/java/com/android/server/pm/Settings.java20
1 files changed, 18 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index db2fba97f4ac..2a9cb8998cac 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -2687,7 +2687,7 @@ public final class Settings {
private void writePackageListLPrInternal(int creatingUserId) {
// Only derive GIDs for active users (not dying)
- final List<UserInfo> users = UserManagerService.getInstance().getUsers(true);
+ final List<UserInfo> users = getUsers(UserManagerService.getInstance(), true);
int[] userIds = new int[users.size()];
for (int i = 0; i < userIds.length; i++) {
userIds[i] = users.get(i).id;
@@ -4357,10 +4357,26 @@ public final class Settings {
return pkgSetting.getHarmfulAppWarning(userId);
}
+ /**
+ * Return all users on the device, including partial or dying users.
+ * @param userManager UserManagerService instance
+ * @return the list of users
+ */
private static List<UserInfo> getAllUsers(UserManagerService userManager) {
+ return getUsers(userManager, false);
+ }
+
+ /**
+ * Return the list of users on the device. Clear the calling identity before calling into
+ * UserManagerService.
+ * @param userManager UserManagerService instance
+ * @param excludeDying Indicates whether to exclude any users marked for deletion.
+ * @return the list of users
+ */
+ private static List<UserInfo> getUsers(UserManagerService userManager, boolean excludeDying) {
long id = Binder.clearCallingIdentity();
try {
- return userManager.getUsers(false);
+ return userManager.getUsers(excludeDying);
} catch (NullPointerException npe) {
// packagemanager not yet initialized
} finally {