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
This commit is contained in:
Svet Ganov
2021-05-07 00:12:08 +00:00
parent 4bf102ae26
commit 2ae82e1302

View File

@@ -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<String, ArrayMap<String, long[]>> 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));
}