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

Commit 9453f928 authored by Nate Myren's avatar Nate Myren
Browse files

Add shouldForceCollectOp to appOpInfo

This allows us to manually specify which app op should have noteOp
events collected for them, if applicable

Bug: 44518166
Test: manual
Change-Id: I3988679fd9b8ccedde37a47cacc0ac2c276b78e6
parent 8d937f34
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import java.util.Objects;
 * Information about a particular app op.
 */
class AppOpInfo {

    /**
     * A unique constant identifying this app op.
     */
@@ -91,6 +92,11 @@ class AppOpInfo {
     */
    public final boolean restrictRead;

    /**
     * Whether to collect noteOp instances, and send them to callbacks.
     */
    public final boolean forceCollectNotes;

    AppOpInfo(int code,
            int switchCode,
            @NonNull String name,
@@ -100,7 +106,8 @@ class AppOpInfo {
            AppOpsManager.RestrictionBypass allowSystemRestrictionBypass,
            int defaultMode,
            boolean disableReset,
            boolean restrictRead) {
            boolean restrictRead,
            boolean forceCollectNotes) {
        if (code < OP_NONE) throw new IllegalArgumentException();
        if (switchCode < OP_NONE) throw new IllegalArgumentException();
        Objects.requireNonNull(name);
@@ -115,6 +122,7 @@ class AppOpInfo {
        this.defaultMode = defaultMode;
        this.disableReset = disableReset;
        this.restrictRead = restrictRead;
        this.forceCollectNotes = forceCollectNotes;
    }

    static class Builder {
@@ -128,6 +136,7 @@ class AppOpInfo {
        private int mDefaultMode = AppOpsManager.MODE_DEFAULT;
        private boolean mDisableReset = false;
        private boolean mRestrictRead = false;
        private boolean mForceCollectNotes = false;

        Builder(int code, @NonNull String name, @NonNull String simpleName) {
            if (code < OP_NONE) throw new IllegalArgumentException();
@@ -190,9 +199,15 @@ class AppOpInfo {
            return this;
        }

        public Builder setForceCollectNotes(boolean value) {
            this.mForceCollectNotes = value;
            return this;
        }

        public AppOpInfo build() {
            return new AppOpInfo(mCode, mSwitchCode, mName, mSimpleName, mPermission, mRestriction,
                mAllowSystemRestrictionBypass, mDefaultMode, mDisableReset, mRestrictRead);
                mAllowSystemRestrictionBypass, mDefaultMode, mDisableReset, mRestrictRead,
                    mForceCollectNotes);
        }
    }
}
+13 −4
Original line number Diff line number Diff line
@@ -1831,6 +1831,9 @@ public class AppOpsManager {
    })
    private @interface ShouldCollectNoteOp {}

    /** Whether noting for an appop should be collected */
    private static final @ShouldCollectNoteOp byte[] sAppOpsToNote = new byte[_NUM_OP];

    private static final int[] RUNTIME_AND_APPOP_PERMISSIONS_OPS = {
            // RUNTIME PERMISSIONS
            // Contacts
@@ -2281,9 +2284,18 @@ public class AppOpsManager {
                "ACCESS_RESTRICTED_SETTINGS").setDefaultMode(AppOpsManager.MODE_ALLOWED)
            .setDisableReset(true).setRestrictRead(true).build(),
        new AppOpInfo.Builder(OP_RECEIVE_AMBIENT_TRIGGER_AUDIO, OPSTR_RECEIVE_AMBIENT_TRIGGER_AUDIO,
                "RECEIVE_SOUNDTRIGGER_AUDIO").setDefaultMode(AppOpsManager.MODE_ALLOWED).build()
                "RECEIVE_SOUNDTRIGGER_AUDIO").setDefaultMode(AppOpsManager.MODE_ALLOWED)
                .setForceCollectNotes(true).build()
    };

    /**
     * @hide
     */
    public static boolean shouldForceCollectNoteForOp(int op) {
        Preconditions.checkArgumentInRange(op, 0, _NUM_OP - 1, "opCode");
        return sAppOpInfos[op].forceCollectNotes;
    }

    /**
     * Mapping from an app op name to the app op code.
     */
@@ -2313,9 +2325,6 @@ public class AppOpsManager {
    private static final ThreadLocal<ArrayMap<String, long[]>> sAppOpsNotedInThisBinderTransaction =
            new ThreadLocal<>();

    /** Whether noting for an appop should be collected */
    private static final @ShouldCollectNoteOp byte[] sAppOpsToNote = new byte[_NUM_OP];

    static {
        if (sAppOpInfos.length != _NUM_OP) {
            throw new IllegalStateException("mAppOpInfos length " + sAppOpInfos.length
+1 −5
Original line number Diff line number Diff line
@@ -267,10 +267,6 @@ public class AppOpsService extends IAppOpsService.Stub implements PersistenceSch
            OP_CAMERA,
    };

    private static final int[] WATCHABLE_NON_PERMISSION_OPS = {
            OP_RECEIVE_AMBIENT_TRIGGER_AUDIO,
    };

    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;
@@ -4252,7 +4248,7 @@ public class AppOpsService extends IAppOpsService.Stub implements PersistenceSch
    public boolean shouldCollectNotes(int opCode) {
        Preconditions.checkArgumentInRange(opCode, 0, _NUM_OP - 1, "opCode");

        if (ArrayUtils.contains(WATCHABLE_NON_PERMISSION_OPS, opCode)) {
        if (AppOpsManager.shouldForceCollectNoteForOp(opCode)) {
            return true;
        }