Merge "Ensure that UID state changes are propagated to paused app ops" into sc-dev am: 8f10280b15

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14909312

Change-Id: I78c526af3366f77410804197c5fdc4dced4fc808
This commit is contained in:
Nate Myren
2021-06-15 15:55:51 +00:00
committed by Automerger Merge Worker

View File

@@ -1029,7 +1029,7 @@ public class AppOpsService extends IAppOpsService.Stub {
if (isStarted && mInProgressEvents == null) { if (isStarted && mInProgressEvents == null) {
mInProgressEvents = new ArrayMap<>(1); mInProgressEvents = new ArrayMap<>(1);
} else if (mPausedInProgressEvents == null) { } else if (!isStarted && mPausedInProgressEvents == null) {
mPausedInProgressEvents = new ArrayMap<>(1); mPausedInProgressEvents = new ArrayMap<>(1);
} }
ArrayMap<IBinder, InProgressStartOpEvent> events = isStarted ArrayMap<IBinder, InProgressStartOpEvent> events = isStarted
@@ -1231,11 +1231,13 @@ public class AppOpsService extends IAppOpsService.Stub {
*/ */
void onClientDeath(@NonNull IBinder clientId) { void onClientDeath(@NonNull IBinder clientId) {
synchronized (AppOpsService.this) { synchronized (AppOpsService.this) {
if (mInProgressEvents == null) { if (mInProgressEvents == null && mPausedInProgressEvents == null) {
return; return;
} }
InProgressStartOpEvent deadEvent = mInProgressEvents.get(clientId); ArrayMap<IBinder, InProgressStartOpEvent> events = isPaused()
? mPausedInProgressEvents : mInProgressEvents;
InProgressStartOpEvent deadEvent = events.get(clientId);
if (deadEvent != null) { if (deadEvent != null) {
deadEvent.numUnfinishedStarts = 1; deadEvent.numUnfinishedStarts = 1;
} }
@@ -1250,14 +1252,18 @@ public class AppOpsService extends IAppOpsService.Stub {
* @param newState The new state * @param newState The new state
*/ */
public void onUidStateChanged(@AppOpsManager.UidState int newState) { public void onUidStateChanged(@AppOpsManager.UidState int newState) {
if (mInProgressEvents == null) { if (mInProgressEvents == null && mPausedInProgressEvents == null) {
return; return;
} }
int numInProgressEvents = mInProgressEvents.size(); boolean isRunning = isRunning();
List<IBinder> binders = new ArrayList<>(mInProgressEvents.keySet()); ArrayMap<IBinder, AppOpsService.InProgressStartOpEvent> events =
isRunning ? mInProgressEvents : mPausedInProgressEvents;
int numInProgressEvents = events.size();
List<IBinder> binders = new ArrayList<>(events.keySet());
for (int i = 0; i < numInProgressEvents; i++) { for (int i = 0; i < numInProgressEvents; i++) {
InProgressStartOpEvent event = mInProgressEvents.get(binders.get(i)); InProgressStartOpEvent event = events.get(binders.get(i));
if (event != null && event.getUidState() != newState) { if (event != null && event.getUidState() != newState) {
try { try {
@@ -1272,16 +1278,17 @@ public class AppOpsService extends IAppOpsService.Stub {
// 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) {
started(event.getClientId(), proxy.getUid(), proxy.getPackageName(), startedOrPaused(event.getClientId(), proxy.getUid(),
proxy.getAttributionTag(), newState, event.getFlags(), false, proxy.getPackageName(), proxy.getAttributionTag(), newState,
event.getFlags(), false, isRunning,
event.getAttributionFlags(), event.getAttributionChainId()); event.getAttributionFlags(), event.getAttributionChainId());
} else { } else {
started(event.getClientId(), Process.INVALID_UID, null, null, newState, startedOrPaused(event.getClientId(), Process.INVALID_UID, null, null,
OP_FLAG_SELF, false, event.getAttributionFlags(), newState, event.getFlags(), false, isRunning,
event.getAttributionChainId()); event.getAttributionFlags(), event.getAttributionChainId());
} }
InProgressStartOpEvent newEvent = mInProgressEvents.get(binders.get(i)); InProgressStartOpEvent newEvent = events.get(binders.get(i));
if (newEvent != null) { if (newEvent != null) {
newEvent.numUnfinishedStarts += numPreviousUnfinishedStarts - 1; newEvent.numUnfinishedStarts += numPreviousUnfinishedStarts - 1;
} }
@@ -6494,9 +6501,9 @@ public class AppOpsService extends IAppOpsService.Stub {
int numAttrTags = op.mAttributions.size(); int numAttrTags = op.mAttributions.size();
for (int attrNum = 0; attrNum < numAttrTags; attrNum++) { for (int attrNum = 0; attrNum < numAttrTags; attrNum++) {
AttributedOp attrOp = op.mAttributions.valueAt(attrNum); AttributedOp attrOp = op.mAttributions.valueAt(attrNum);
if (restricted) { if (restricted && attrOp.isRunning()) {
attrOp.pause(); attrOp.pause();
} else { } else if (attrOp.isPaused()) {
attrOp.resume(); attrOp.resume();
} }
} }