From 1ebf7dcacecddccfb63ed99fa46a67f321438a52 Mon Sep 17 00:00:00 2001 From: Nate Myren Date: Mon, 30 Nov 2020 09:43:47 -0800 Subject: [PATCH] Fix ConcurrentModification in onUidStateChanged Bug: 172776374 Fixes: 173078211 Test: Presubmit Merged-In: Ib4c96e81cbe2adcfd53ea23ae644e978effb7a92 Change-Id: Ib4c96e81cbe2adcfd53ea23ae644e978effb7a92 --- .../java/com/android/server/appop/AppOpsService.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java index 12eb8f2141212..1b12dc79d98fb 100644 --- a/services/core/java/com/android/server/appop/AppOpsService.java +++ b/services/core/java/com/android/server/appop/AppOpsService.java @@ -1011,10 +1011,11 @@ public class AppOpsService extends IAppOpsService.Stub { } int numInProgressEvents = mInProgressEvents.size(); + List binders = new ArrayList<>(mInProgressEvents.keySet()); for (int i = 0; i < numInProgressEvents; i++) { - InProgressStartOpEvent event = mInProgressEvents.valueAt(i); + InProgressStartOpEvent event = mInProgressEvents.get(binders.get(i)); - if (event.getUidState() != newState) { + if (event != null && event.getUidState() != newState) { try { // Remove all but one unfinished start count and then call finished() to // remove start event object @@ -1025,7 +1026,10 @@ public class AppOpsService extends IAppOpsService.Stub { // Call started() to add a new start event object and then add the // previously removed unfinished start counts back started(event.getClientId(), newState, false); - event.numUnfinishedStarts += numPreviousUnfinishedStarts - 1; + InProgressStartOpEvent newEvent = mInProgressEvents.get(binders.get(i)); + if (newEvent != null) { + newEvent.numUnfinishedStarts += numPreviousUnfinishedStarts - 1; + } } catch (RemoteException e) { if (DEBUG) Slog.e(TAG, "Cannot switch to new uidState " + newState); }