Correctly update in-progress events when switching uidStates
A in-progress event might have been started multiple times. So to remove the event and then re-add it we have to temporarily reduce the number of unfinished started (== the nesting count) to 1 so that finish() actually removes the event. Test: atest android.app.appops.cts.AppOpEventCollectionTest#switchUidStateWhileOpsAreRunning Fixes: 148527247 Change-Id: I40afd83946be202be048c69611f62974a762bdc6
This commit is contained in:
@@ -847,7 +847,12 @@ public class AppOpsService extends IAppOpsService.Stub {
|
||||
*/
|
||||
public void started(@NonNull IBinder clientId, @AppOpsManager.UidState int uidState)
|
||||
throws RemoteException {
|
||||
if (!parent.isRunning()) {
|
||||
started(clientId, uidState, true);
|
||||
}
|
||||
|
||||
private void started(@NonNull IBinder clientId, @AppOpsManager.UidState int uidState,
|
||||
boolean triggerCallbackIfNeeded) throws RemoteException {
|
||||
if (triggerCallbackIfNeeded && !parent.isRunning()) {
|
||||
scheduleOpActiveChangedIfNeededLocked(parent.op, parent.uid,
|
||||
parent.packageName, true);
|
||||
}
|
||||
@@ -966,8 +971,16 @@ public class AppOpsService extends IAppOpsService.Stub {
|
||||
|
||||
if (event.getUidState() != newState) {
|
||||
try {
|
||||
// Remove all but one unfinished start count and then call finished() to
|
||||
// remove start event object
|
||||
int numPreviousUnfinishedStarts = event.numUnfinishedStarts;
|
||||
event.numUnfinishedStarts = 1;
|
||||
finished(event.getClientId(), false);
|
||||
started(event.getClientId(), newState);
|
||||
|
||||
// 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;
|
||||
} catch (RemoteException e) {
|
||||
if (DEBUG) Slog.e(TAG, "Cannot switch to new uidState " + newState);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user