summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Daniel Chapin <chapin@google.com> 2024-02-16 19:50:04 +0000
committer Daniel Chapin <chapin@google.com> 2024-02-16 19:50:04 +0000
commit1305ab6dbc090804e9432864c5cf02eb831fba6a (patch)
tree706698c9d59732403a65f259c7c43a305a3931bd
parentbbd2c5a969b619b0ca1d9d91be6c299ec2d7db12 (diff)
Revert "[AppOps] Make some corrections towards UidState initiali..."
Revert submission 25954841 Reason for revert: b/325556565 Reverted changes: /q/submissionid:25954841 Change-Id: I63d1024a3f02439736dc1e8a1d055a65bbb2042a
-rw-r--r--services/core/java/com/android/server/appop/AppOpsService.java51
1 files changed, 11 insertions, 40 deletions
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java
index fe3617087ec4..5c95d433a6c1 100644
--- a/services/core/java/com/android/server/appop/AppOpsService.java
+++ b/services/core/java/com/android/server/appop/AppOpsService.java
@@ -1034,7 +1034,7 @@ public class AppOpsService extends IAppOpsService.Stub {
new Ops(pkgName, uidState));
}
- createSandboxUidStateIfNotExistsForAppLocked(uid, null);
+ createSandboxUidStateIfNotExistsForAppLocked(uid);
}
} else if (action.equals(ACTION_PACKAGE_REMOVED) && !intent.hasExtra(EXTRA_REPLACING)) {
synchronized (AppOpsService.this) {
@@ -1253,33 +1253,19 @@ public class AppOpsService extends IAppOpsService.Stub {
void initializeUidStates() {
UserManagerInternal umi = getUserManagerInternal();
synchronized (this) {
- SparseBooleanArray knownUids = new SparseBooleanArray();
-
- for (int uid : NON_PACKAGE_UIDS) {
- if (!mUidStates.contains(uid)) {
- mUidStates.put(uid, new UidState(uid));
- }
- knownUids.put(uid, true);
- }
-
int[] userIds = umi.getUserIds();
try (PackageManagerLocal.UnfilteredSnapshot snapshot =
getPackageManagerLocal().withUnfilteredSnapshot()) {
Map<String, PackageState> packageStates = snapshot.getPackageStates();
for (int i = 0; i < userIds.length; i++) {
int userId = userIds[i];
- initializeUserUidStatesLocked(userId, packageStates, knownUids);
+ initializeUserUidStatesLocked(userId, packageStates);
}
}
- // Remove what may have been added during persistence parsing
- for (int i = mUidStates.size() - 1; i >= 0; i--) {
- int uid = mUidStates.keyAt(i);
- if (!knownUids.get(uid, false)) {
- mUidStates.removeAt(i);
- }
+ for (int uid : NON_PACKAGE_UIDS) {
+ mUidStates.put(uid, new UidState(uid));
}
-
mUidStatesInitialized = true;
}
}
@@ -1288,34 +1274,26 @@ public class AppOpsService extends IAppOpsService.Stub {
synchronized (this) {
try (PackageManagerLocal.UnfilteredSnapshot snapshot =
getPackageManagerLocal().withUnfilteredSnapshot()) {
- initializeUserUidStatesLocked(userId, snapshot.getPackageStates(), null);
+ initializeUserUidStatesLocked(userId, snapshot.getPackageStates());
}
}
}
private void initializeUserUidStatesLocked(int userId, Map<String,
- PackageState> packageStates, SparseBooleanArray knownUids) {
+ PackageState> packageStates) {
for (Map.Entry<String, PackageState> entry : packageStates.entrySet()) {
- PackageState packageState = entry.getValue();
- if (packageState.isApex()) {
- continue;
- }
- int appId = packageState.getAppId();
+ int appId = entry.getValue().getAppId();
String packageName = entry.getKey();
- initializePackageUidStateLocked(userId, appId, packageName, knownUids);
+ initializePackageUidStateLocked(userId, appId, packageName);
}
}
/*
Be careful not to clear any existing data; only want to add objects that don't already exist.
*/
- private void initializePackageUidStateLocked(int userId, int appId, String packageName,
- SparseBooleanArray knownUids) {
+ private void initializePackageUidStateLocked(int userId, int appId, String packageName) {
int uid = UserHandle.getUid(userId, appId);
- if (knownUids != null) {
- knownUids.put(uid, true);
- }
UidState uidState = getUidStateLocked(uid, true);
Ops ops = uidState.pkgOps.get(packageName);
if (ops == null) {
@@ -1333,7 +1311,7 @@ public class AppOpsService extends IAppOpsService.Stub {
}
}
- createSandboxUidStateIfNotExistsForAppLocked(uid, knownUids);
+ createSandboxUidStateIfNotExistsForAppLocked(uid);
}
/**
@@ -4268,15 +4246,8 @@ public class AppOpsService extends IAppOpsService.Stub {
return uidState;
}
- private void createSandboxUidStateIfNotExistsForAppLocked(int uid,
- SparseBooleanArray knownUids) {
- if (UserHandle.getAppId(uid) < Process.FIRST_APPLICATION_UID) {
- return;
- }
+ private void createSandboxUidStateIfNotExistsForAppLocked(int uid) {
final int sandboxUid = Process.toSdkSandboxUid(uid);
- if (knownUids != null) {
- knownUids.put(sandboxUid, true);
- }
getUidStateLocked(sandboxUid, true);
}