Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e8b16dea authored by Stanislav Zholnin's avatar Stanislav Zholnin Committed by Automerger Merge Worker
Browse files

Merge "Keep unforwarded operation for noted ops." into rvc-dev am: c784a29d am: 6eca51ab

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

Change-Id: Ie8666e3f9a5e8c962b9d0dc2d613945280a0eec3
parents 2552d9df 6eca51ab
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -182,6 +182,8 @@ public class AppOpsManager {
    @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q)
    public static final long CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE = 148180766L;

    private static final int MAX_UNFORWARDED_OPS = 10;

    final Context mContext;

    @UnsupportedAppUsage
@@ -216,6 +218,17 @@ public class AppOpsManager {
    @GuardedBy("sLock")
    private static @Nullable OnOpNotedCallback sOnOpNotedCallback;

    /**
     * Sync note-ops collected from {@link #readAndLogNotedAppops(Parcel)} that have not been
     * delivered to a callback yet.
     *
     * Similar to {@link com.android.server.appop.AppOpsService#mUnforwardedAsyncNotedOps} for
     * {@link COLLECT_ASYNC}. Used in situation when AppOpsManager asks to collect stacktrace with
     * {@link #sMessageCollector}, which forces {@link COLLECT_SYNC} mode.
     */
    @GuardedBy("sLock")
    private static ArrayList<SyncNotedAppOp> sUnforwardedOps = new ArrayList<>();

    /**
     * Additional collector that collect accesses and forwards a few of them them via
     * {@link IAppOpsService#reportRuntimeAppOpAccessMessageAndGetConfig}.
@@ -8163,6 +8176,11 @@ public class AppOpsManager {
                            code = notedAppOps.nextSetBit(code + 1)) {
                        if (sOnOpNotedCallback != null) {
                            sOnOpNotedCallback.onNoted(new SyncNotedAppOp(code, attributionTag));
                        } else {
                            sUnforwardedOps.add(new SyncNotedAppOp(code, attributionTag));
                            if (sUnforwardedOps.size() > MAX_UNFORWARDED_OPS) {
                                sUnforwardedOps.remove(0);
                            }
                        }
                    }
                }
@@ -8229,6 +8247,17 @@ public class AppOpsManager {
                        }
                    }
                }
                synchronized (this) {
                    int numMissedSyncOps = sUnforwardedOps.size();
                    for (int i = 0; i < numMissedSyncOps; i++) {
                        final SyncNotedAppOp syncNotedAppOp = sUnforwardedOps.get(i);
                        if (sOnOpNotedCallback != null) {
                            sOnOpNotedCallback.getAsyncNotedExecutor().execute(
                                    () -> sOnOpNotedCallback.onNoted(syncNotedAppOp));
                        }
                    }
                    sUnforwardedOps.clear();
                }
            }
        }
    }
+2 −2
Original line number Diff line number Diff line
@@ -249,7 +249,7 @@ public class AppOpsService extends IAppOpsService.Stub {
            OP_CAMERA,
    };

    private static final int MAX_UNFORWARED_OPS = 10;
    private static final int MAX_UNFORWARDED_OPS = 10;
    private static final int MAX_UNUSED_POOLED_OBJECTS = 3;
    private static final int RARELY_USED_PACKAGES_INITIALIZATION_DELAY_MILLIS = 300000;

@@ -3371,7 +3371,7 @@ public class AppOpsService extends IAppOpsService.Stub {
                    }

                    unforwardedOps.add(asyncNotedOp);
                    if (unforwardedOps.size() > MAX_UNFORWARED_OPS) {
                    if (unforwardedOps.size() > MAX_UNFORWARDED_OPS) {
                        unforwardedOps.remove(0);
                    }
                }