From 1bb20b4eccf3564221ee2238c6905c621f1e0f4c Mon Sep 17 00:00:00 2001 From: Evan Severson Date: Fri, 16 Sep 2022 09:04:35 -0700 Subject: [PATCH] Use delayed uid state update in AppOpsService It appears that Ib1b93148669ee04d7c16195540906b388550ee68 fixed the issues we were seeing with the test. Test: CtsAppOpsTestCases, CtsAppOps2TestCases, AppOpUidStateTrackerTest Bug: 241447638 Fixes: 246429313 Change-Id: Iaf72791e536f69572d469b0ce5fa801812053e76 --- .../android/server/appop/AppOpsService.java | 66 ++++--------------- 1 file changed, 13 insertions(+), 53 deletions(-) diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java index 548842be86949..48fb8795834de 100644 --- a/services/core/java/com/android/server/appop/AppOpsService.java +++ b/services/core/java/com/android/server/appop/AppOpsService.java @@ -238,13 +238,6 @@ public class AppOpsService extends IAppOpsService.Stub implements PersistenceSch private static final int MAX_UNUSED_POOLED_OBJECTS = 3; private static final int RARELY_USED_PACKAGES_INITIALIZATION_DELAY_MILLIS = 300000; - /* - * TODO b/246429313 - * android.app.appops.cts.AppOpEventCollectionTest#switchUidStateWhileOpsAreRunning breaks when - * set to true - */ - private static final boolean USE_DELAYED_UID_STATE_CHANGES_FOR_ATTR_OP_UPDATES = false; - final Context mContext; final AtomicFile mFile; private final @Nullable File mNoteOpCallerStacktracesFile; @@ -2077,28 +2070,22 @@ public class AppOpsService extends IAppOpsService.Stub implements PersistenceSch } } - if (USE_DELAYED_UID_STATE_CHANGES_FOR_ATTR_OP_UPDATES) { - // Proposed behavior change, previously there were two rounds of UID state change - // operations. It seems like there is no need for - // attributedOp.onUidStateChanged(state) to update before settle time is reached, - // which if true then this is the preferred route. - if (uidState != null && uidState.pkgOps != null) { - int numPkgs = uidState.pkgOps.size(); - for (int pkgNum = 0; pkgNum < numPkgs; pkgNum++) { - Ops ops = uidState.pkgOps.valueAt(pkgNum); + if (uidState != null && uidState.pkgOps != null) { + int numPkgs = uidState.pkgOps.size(); + for (int pkgNum = 0; pkgNum < numPkgs; pkgNum++) { + Ops ops = uidState.pkgOps.valueAt(pkgNum); - int numOps = ops.size(); - for (int opNum = 0; opNum < numOps; opNum++) { - Op op = ops.valueAt(opNum); + int numOps = ops.size(); + for (int opNum = 0; opNum < numOps; opNum++) { + Op op = ops.valueAt(opNum); - int numAttributions = op.mAttributions.size(); - for (int attributionNum = 0; attributionNum < numAttributions; - attributionNum++) { - AttributedOp attributedOp = op.mAttributions.valueAt( - attributionNum); + int numAttributions = op.mAttributions.size(); + for (int attributionNum = 0; attributionNum < numAttributions; + attributionNum++) { + AttributedOp attributedOp = op.mAttributions.valueAt( + attributionNum); - attributedOp.onUidStateChanged(state); - } + attributedOp.onUidStateChanged(state); } } } @@ -2119,33 +2106,6 @@ public class AppOpsService extends IAppOpsService.Stub implements PersistenceSch onUidStateChanged(uid, AppOpsUidStateTracker.processStateToUidState(procState), false); } - - if (!USE_DELAYED_UID_STATE_CHANGES_FOR_ATTR_OP_UPDATES) { - UidState uidState = mUidStates.get(uid); - - if (uidState != null && uidState.pkgOps != null) { - int numPkgs = uidState.pkgOps.size(); - for (int pkgNum = 0; pkgNum < numPkgs; pkgNum++) { - Ops ops = uidState.pkgOps.valueAt(pkgNum); - - int numOps = ops.size(); - for (int opNum = 0; opNum < numOps; opNum++) { - Op op = ops.valueAt(opNum); - - int numAttributions = op.mAttributions.size(); - for (int attributionNum = 0; attributionNum < numAttributions; - attributionNum++) { - AttributedOp attributedOp = op.mAttributions.valueAt( - attributionNum); - - attributedOp.onUidStateChanged( - AppOpsUidStateTracker.processStateToUidState( - procState)); - } - } - } - } - } } }