From 2ae82e1302f1f5cdae5e171e19b9c6da988642e2 Mon Sep 17 00:00:00 2001 From: Svet Ganov Date: Fri, 7 May 2021 00:12:08 +0000 Subject: [PATCH] Fix a serialization issue in sync op reporting If the application thread is not ready yet we cannot get the package name and were shrt circuiting which let to leaving the remainder of the payload in the parcel breaking subsequent content reads. bug: 184616098 Test: atest CtsAppOpsTestCases Change-Id: I83f0d74deb87f2b4517d8a4d10b5331c7d41bb89 --- core/java/android/app/AppOpsManager.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 36d161dfe7b4b..428252290043e 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -9038,8 +9038,11 @@ public class AppOpsManager { * * @hide */ - // TODO (b/186872903) Refactor how sync noted ops are propagaged. + // TODO (b/186872903) Refactor how sync noted ops are propagated. public static void prefixParcelWithAppOpsIfNeeded(@NonNull Parcel p) { + if (!isListeningForOpNotedInBinderTransaction()) { + return; + } final ArrayMap> notedAppOps = sAppOpsNotedInThisBinderTransaction.get(); if (notedAppOps == null) { @@ -9083,9 +9086,6 @@ public class AppOpsManager { } final String myPackageName = ActivityThread.currentPackageName(); - if (myPackageName == null) { - return; - } synchronized (sLock) { for (int i = 0; i < packageCount; i++) { @@ -9105,7 +9105,7 @@ public class AppOpsManager { final BitSet notedAppOps = BitSet.valueOf(rawNotedAppOps); for (int code = notedAppOps.nextSetBit(0); code != -1; code = notedAppOps.nextSetBit(code + 1)) { - if (myPackageName.equals(packageName)) { + if (Objects.equals(myPackageName, packageName)) { if (sOnOpNotedCallback != null) { sOnOpNotedCallback.onNoted(new SyncNotedAppOp(code, attributionTag, packageName)); @@ -9123,7 +9123,7 @@ public class AppOpsManager { } for (int code = notedAppOps.nextSetBit(0); code != -1; code = notedAppOps.nextSetBit(code + 1)) { - if (myPackageName.equals(packageName)) { + if (Objects.equals(myPackageName, packageName)) { sMessageCollector.onNoted(new SyncNotedAppOp(code, attributionTag, packageName)); }