Fix ConcurrentModification in onUidStateChanged

Bug: 172776374
Fixes: 173078211
Test: Presubmit
Change-Id: Ib4c96e81cbe2adcfd53ea23ae644e978effb7a92
This commit is contained in:
Nate Myren
2020-11-30 09:43:47 -08:00
parent b7c12297dc
commit aad5f733cd

View File

@@ -1057,19 +1057,20 @@ public class AppOpsService extends IAppOpsService.Stub {
} }
int numInProgressEvents = mInProgressEvents.size(); int numInProgressEvents = mInProgressEvents.size();
List<IBinder> binders = new ArrayList<>(mInProgressEvents.keySet());
for (int i = 0; i < numInProgressEvents; i++) { 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 { try {
// Remove all but one unfinished start count and then call finished() to // Remove all but one unfinished start count and then call finished() to
// remove start event object // remove start event object
int numPreviousUnfinishedStarts = event.numUnfinishedStarts; int numPreviousUnfinishedStarts = event.numUnfinishedStarts;
event.numUnfinishedStarts = 1; event.numUnfinishedStarts = 1;
finished(event.getClientId(), false);
OpEventProxyInfo proxy = event.getProxy(); OpEventProxyInfo proxy = event.getProxy();
finished(event.getClientId(), false);
// Call started() to add a new start event object and then add the // Call started() to add a new start event object and then add the
// previously removed unfinished start counts back // previously removed unfinished start counts back
if (proxy != null) { if (proxy != null) {
@@ -1079,7 +1080,11 @@ public class AppOpsService extends IAppOpsService.Stub {
started(event.getClientId(), Process.INVALID_UID, null, null, newState, started(event.getClientId(), Process.INVALID_UID, null, null, newState,
OP_FLAG_SELF, false); OP_FLAG_SELF, false);
} }
event.numUnfinishedStarts += numPreviousUnfinishedStarts - 1;
InProgressStartOpEvent newEvent = mInProgressEvents.get(binders.get(i));
if (newEvent != null) {
newEvent.numUnfinishedStarts += numPreviousUnfinishedStarts - 1;
}
} catch (RemoteException e) { } catch (RemoteException e) {
if (DEBUG) Slog.e(TAG, "Cannot switch to new uidState " + newState); if (DEBUG) Slog.e(TAG, "Cannot switch to new uidState " + newState);
} }