From 456b496e4a5afb3c790dd82bbb5e47d2c0806b51 Mon Sep 17 00:00:00 2001 From: Stanislav Zholnin Date: Thu, 18 Jun 2020 16:52:50 +0100 Subject: [PATCH] Save AsyncOps for later forwarding instead of SyncOps. Fixes: 159082266 Test: atest AppOpsLoggingTest Change-Id: I3f8da9d7c2925233e5e53cfa7fd5e4cd1c258b29 --- core/java/android/app/AppOpsManager.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 71b866b7b16a3..3347e045886af 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -227,7 +227,7 @@ public class AppOpsManager { * {@link #sMessageCollector}, which forces {@link COLLECT_SYNC} mode. */ @GuardedBy("sLock") - private static ArrayList sUnforwardedOps = new ArrayList<>(); + private static ArrayList sUnforwardedOps = new ArrayList<>(); /** * Additional collector that collect accesses and forwards a few of them them via @@ -8195,7 +8195,10 @@ public class AppOpsManager { if (sOnOpNotedCallback != null) { sOnOpNotedCallback.onNoted(new SyncNotedAppOp(code, attributionTag)); } else { - sUnforwardedOps.add(new SyncNotedAppOp(code, attributionTag)); + String message = getFormattedStackTrace(); + sUnforwardedOps.add( + new AsyncNotedAppOp(code, Process.myUid(), attributionTag, + message, System.currentTimeMillis())); if (sUnforwardedOps.size() > MAX_UNFORWARDED_OPS) { sUnforwardedOps.remove(0); } @@ -8268,10 +8271,10 @@ public class AppOpsManager { synchronized (this) { int numMissedSyncOps = sUnforwardedOps.size(); for (int i = 0; i < numMissedSyncOps; i++) { - final SyncNotedAppOp syncNotedAppOp = sUnforwardedOps.get(i); + final AsyncNotedAppOp syncNotedAppOp = sUnforwardedOps.get(i); if (sOnOpNotedCallback != null) { sOnOpNotedCallback.getAsyncNotedExecutor().execute( - () -> sOnOpNotedCallback.onNoted(syncNotedAppOp)); + () -> sOnOpNotedCallback.onAsyncNoted(syncNotedAppOp)); } } sUnforwardedOps.clear();