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

Commit 0751e1b1 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make note/startOperation return SyncNotedAppOp, add mode" into sc-dev

parents f8fa4efc ee9a4741
Loading
Loading
Loading
Loading
+29 −30
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.compat.Compatibility;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.AttributionSource;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
@@ -50,7 +51,6 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
import android.content.AttributionSource;
import android.os.Process;
import android.os.RemoteCallback;
import android.os.RemoteException;
@@ -8029,18 +8029,18 @@ public class AppOpsManager {
                }
            }

            int mode = mService.noteOperation(op, uid, packageName, attributionTag,
            SyncNotedAppOp syncOp = mService.noteOperation(op, uid, packageName, attributionTag,
                    collectionMode == COLLECT_ASYNC, message, shouldCollectMessage);

            if (mode == MODE_ALLOWED) {
            if (syncOp.getOpMode()== MODE_ALLOWED) {
                if (collectionMode == COLLECT_SELF) {
                    collectNotedOpForSelf(op, attributionTag);
                    collectNotedOpForSelf(syncOp);
                } else if (collectionMode == COLLECT_SYNC) {
                    collectNotedOpSync(op, attributionTag);
                    collectNotedOpSync(syncOp);
                }
            }

            return mode;
            return syncOp.getOpMode();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -8197,23 +8197,23 @@ public class AppOpsManager {
                }
            }

            int mode = mService.noteProxyOperation(op, attributionSource,
            SyncNotedAppOp syncOp = mService.noteProxyOperation(op, attributionSource,
                    collectionMode == COLLECT_ASYNC, message,
                    shouldCollectMessage, skipProxyOperation);

            if (mode == MODE_ALLOWED) {
            if (syncOp.getOpMode() == MODE_ALLOWED) {
                if (collectionMode == COLLECT_SELF) {
                    collectNotedOpForSelf(op, attributionSource.getNextAttributionTag());
                    collectNotedOpForSelf(syncOp);
                } else if (collectionMode == COLLECT_SYNC
                        // Only collect app-ops when the proxy is trusted
                        && (mContext.checkPermission(Manifest.permission.UPDATE_APP_OPS_STATS, -1,
                        myUid) == PackageManager.PERMISSION_GRANTED ||
                            Binder.getCallingUid() == attributionSource.getNextUid())) {
                    collectNotedOpSync(op, attributionSource.getNextAttributionTag());
                    collectNotedOpSync(syncOp);
                }
            }

            return mode;
            return syncOp.getOpMode();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -8510,19 +8510,19 @@ public class AppOpsManager {
                }
            }

            int mode = mService.startOperation(getClientId(), op, uid, packageName,
            SyncNotedAppOp syncOp = mService.startOperation(getClientId(), op, uid, packageName,
                    attributionTag, startIfModeDefault, collectionMode == COLLECT_ASYNC, message,
                    shouldCollectMessage);

            if (mode == MODE_ALLOWED) {
            if (syncOp.getOpMode() == MODE_ALLOWED) {
                if (collectionMode == COLLECT_SELF) {
                    collectNotedOpForSelf(op, attributionTag);
                    collectNotedOpForSelf(syncOp);
                } else if (collectionMode == COLLECT_SYNC) {
                    collectNotedOpSync(op, attributionTag);
                    collectNotedOpSync(syncOp);
                }
            }

            return mode;
            return syncOp.getOpMode();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -8625,24 +8625,23 @@ public class AppOpsManager {
                }
            }

            int mode = mService.startProxyOperation(getClientId(), op,
            SyncNotedAppOp syncOp = mService.startProxyOperation(getClientId(), op,
                    attributionSource, false, collectionMode == COLLECT_ASYNC, message,
                    shouldCollectMessage, skipProxyOperation);

            if (mode == MODE_ALLOWED) {
            if (syncOp.getOpMode() == MODE_ALLOWED) {
                if (collectionMode == COLLECT_SELF) {
                    collectNotedOpForSelf(op,
                            attributionSource.getNextAttributionTag());
                    collectNotedOpForSelf(syncOp);
                } else if (collectionMode == COLLECT_SYNC
                        // Only collect app-ops when the proxy is trusted
                        && (mContext.checkPermission(Manifest.permission.UPDATE_APP_OPS_STATS, -1,
                        Process.myUid()) == PackageManager.PERMISSION_GRANTED
                        || Binder.getCallingUid() == attributionSource.getNextUid())) {
                    collectNotedOpSync(op, attributionSource.getNextAttributionTag());
                    collectNotedOpSync(syncOp);
                }
            }

            return mode;
            return syncOp.getOpMode();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -8883,13 +8882,13 @@ public class AppOpsManager {
     * @param op The noted op
     * @param attributionTag The attribution tag the op is noted for
     */
    private void collectNotedOpForSelf(int op, @Nullable String attributionTag) {
    private void collectNotedOpForSelf(SyncNotedAppOp syncOp) {
        synchronized (sLock) {
            if (sOnOpNotedCallback != null) {
                sOnOpNotedCallback.onSelfNoted(new SyncNotedAppOp(op, attributionTag));
                sOnOpNotedCallback.onSelfNoted(syncOp);
            }
        }
        sMessageCollector.onSelfNoted(new SyncNotedAppOp(op, attributionTag));
        sMessageCollector.onSelfNoted(syncOp);
    }

    /**
@@ -8897,23 +8896,23 @@ public class AppOpsManager {
     *
     * <p> Delivered to caller via {@link #prefixParcelWithAppOpsIfNeeded}
     *
     * @param op The noted op
     * @param attributionTag The attribution tag the op is noted for
     * @param syncOp the op and attribution tag to note for
     */
    private void collectNotedOpSync(int op, @Nullable String attributionTag) {
    private void collectNotedOpSync(@NonNull SyncNotedAppOp syncOp) {
        // If this is inside of a two-way binder call:
        // We are inside of a two-way binder call. Delivered to caller via
        // {@link #prefixParcelWithAppOpsIfNeeded}
        int op = sOpStrToOp.get(syncOp.getOp());
        ArrayMap<String, long[]> appOpsNoted = sAppOpsNotedInThisBinderTransaction.get();
        if (appOpsNoted == null) {
            appOpsNoted = new ArrayMap<>(1);
            sAppOpsNotedInThisBinderTransaction.set(appOpsNoted);
        }

        long[] appOpsNotedForAttribution = appOpsNoted.get(attributionTag);
        long[] appOpsNotedForAttribution = appOpsNoted.get(syncOp.getAttributionTag());
        if (appOpsNotedForAttribution == null) {
            appOpsNotedForAttribution = new long[2];
            appOpsNoted.put(attributionTag, appOpsNotedForAttribution);
            appOpsNoted.put(syncOp.getAttributionTag(), appOpsNotedForAttribution);
        }

        if (op < 64) {
+6 −6
Original line number Diff line number Diff line
@@ -76,11 +76,11 @@ public abstract class AppOpsManagerInternal {
         * @param superImpl The super implementation.
         * @return The app op note result.
         */
        int noteOperation(int code, int uid, @Nullable String packageName,
        SyncNotedAppOp noteOperation(int code, int uid, @Nullable String packageName,
                @Nullable String featureId, boolean shouldCollectAsyncNotedOp,
                @Nullable String message, boolean shouldCollectMessage,
                @NonNull HeptFunction<Integer, Integer, String, String, Boolean, String, Boolean,
                        Integer> superImpl);
                        SyncNotedAppOp> superImpl);

        /**
         * Allows overriding note proxy operation behavior.
@@ -94,11 +94,11 @@ public abstract class AppOpsManagerInternal {
         * @param superImpl The super implementation.
         * @return The app op note result.
         */
        int noteProxyOperation(int code, @NonNull AttributionSource attributionSource,
        SyncNotedAppOp noteProxyOperation(int code, @NonNull AttributionSource attributionSource,
                boolean shouldCollectAsyncNotedOp, @Nullable String message,
                boolean shouldCollectMessage, boolean skipProxyOperation,
                @NonNull HexFunction<Integer, AttributionSource, Boolean, String, Boolean,
                        Boolean, Integer> superImpl);
                        Boolean, SyncNotedAppOp> superImpl);

        /**
         * Allows overriding start proxy operation behavior.
@@ -113,12 +113,12 @@ public abstract class AppOpsManagerInternal {
         * @param superImpl The super implementation.
         * @return The app op note result.
         */
        int startProxyOperation(IBinder token, int code,
        SyncNotedAppOp startProxyOperation(IBinder token, int code,
                @NonNull AttributionSource attributionSource, boolean startIfModeDefault,
                boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
                boolean skipProxyOperation, @NonNull OctFunction<IBinder, Integer,
                        AttributionSource, Boolean, Boolean, String, Boolean, Boolean,
                        Integer> superImpl);
                        SyncNotedAppOp> superImpl);

        /**
         * Allows overriding finish proxy op.
+43 −16
Original line number Diff line number Diff line
@@ -34,18 +34,36 @@ import com.android.internal.util.DataClass;
 * itself}.
 */
@Immutable
/*@DataClass(
@DataClass(
        genEqualsHashCode = true,
        genAidl = true,
        genConstructor = false
)
@DataClass.Suppress("getOpCode")*/
@DataClass.Suppress({"getOpCode", "getOpMode"})
public final class SyncNotedAppOp implements Parcelable {

    /** mode returned by the system on a call to note/startOp, if applicable */
    private final int mOpMode;
    /** op code of synchronous appop noted */
    private final @IntRange(from = 0L, to = AppOpsManager._NUM_OP - 1) int mOpCode;
    /** attributionTag of synchronous appop noted */
    private final @Nullable String mAttributionTag;

    /**
     * Native code relies on parcel ordering, do not change
     * @hide
     */
    public SyncNotedAppOp(int opMode, @IntRange(from = 0L) int opCode,
            @Nullable String attributionTag) {
        this.mOpCode = opCode;
        com.android.internal.util.AnnotationValidations.validate(
                IntRange.class, null, mOpCode,
                "from", 0,
                "to", AppOpsManager._NUM_OP - 1);
        this.mAttributionTag = attributionTag;
        this.mOpMode = opMode;
    }

    /**
     * Creates a new SyncNotedAppOp.
     *
@@ -55,12 +73,7 @@ public final class SyncNotedAppOp implements Parcelable {
     *   attributionTag of synchronous appop noted
     */
    public SyncNotedAppOp(@IntRange(from = 0L) int opCode, @Nullable String attributionTag) {
        this.mOpCode = opCode;
        com.android.internal.util.AnnotationValidations.validate(
                IntRange.class, null, mOpCode,
                "from", 0,
                "to", AppOpsManager._NUM_OP - 1);
        this.mAttributionTag = attributionTag;
        this(AppOpsManager.MODE_IGNORED, opCode, attributionTag);
    }

    /**
@@ -70,7 +83,16 @@ public final class SyncNotedAppOp implements Parcelable {
        return AppOpsManager.opToPublicName(mOpCode);
    }

    // Code below generated by codegen v1.0.14.
    /**
     * @hide
     */
    public int getOpMode() {
        return mOpMode;
    }



    // Code below generated by codegen v1.0.23.
    //
    // DO NOT MODIFY!
    // CHECKSTYLE:OFF Generated code
@@ -104,6 +126,7 @@ public final class SyncNotedAppOp implements Parcelable {
        SyncNotedAppOp that = (SyncNotedAppOp) o;
        //noinspection PointlessBooleanExpression
        return true
                && mOpMode == that.mOpMode
                && mOpCode == that.mOpCode
                && java.util.Objects.equals(mAttributionTag, that.mAttributionTag);
    }
@@ -115,6 +138,7 @@ public final class SyncNotedAppOp implements Parcelable {
        // int fieldNameHashCode() { ... }

        int _hash = 1;
        _hash = 31 * _hash + mOpMode;
        _hash = 31 * _hash + mOpCode;
        _hash = 31 * _hash + java.util.Objects.hashCode(mAttributionTag);
        return _hash;
@@ -127,8 +151,9 @@ public final class SyncNotedAppOp implements Parcelable {
        // void parcelFieldName(Parcel dest, int flags) { ... }

        byte flg = 0;
        if (mAttributionTag != null) flg |= 0x2;
        if (mAttributionTag != null) flg |= 0x4;
        dest.writeByte(flg);
        dest.writeInt(mOpMode);
        dest.writeInt(mOpCode);
        if (mAttributionTag != null) dest.writeString(mAttributionTag);
    }
@@ -145,13 +170,15 @@ public final class SyncNotedAppOp implements Parcelable {
        // static FieldType unparcelFieldName(Parcel in) { ... }

        byte flg = in.readByte();
        int opMode = in.readInt();
        int opCode = in.readInt();
        String attributionTag = (flg & 0x2) == 0 ? null : in.readString();
        String attributionTag = (flg & 0x4) == 0 ? null : in.readString();

        this.mOpMode = opMode;
        this.mOpCode = opCode;
        com.android.internal.util.AnnotationValidations.validate(
                IntRange.class, null, mOpCode,
                "from", 0,
                "from", 0L,
                "to", AppOpsManager._NUM_OP - 1);
        this.mAttributionTag = attributionTag;

@@ -172,11 +199,11 @@ public final class SyncNotedAppOp implements Parcelable {
        }
    };

    /*@DataClass.Generated(
            time = 1579188889960L,
            codegenVersion = "1.0.14",
    @DataClass.Generated(
            time = 1617317997768L,
            codegenVersion = "1.0.23",
            sourceFile = "frameworks/base/core/java/android/app/SyncNotedAppOp.java",
            inputSignatures = "private final @android.annotation.IntRange(from=0L, to=AppOpsManager._NUM_OP - 1) int mOpCode\nprivate final @android.annotation.Nullable java.lang.String mAttributionTag\npublic @android.annotation.NonNull java.lang.String getOp()\npublic @android.annotation.SystemApi int getOpCode()\nclass SyncNotedAppOp extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genConstructor=false)")*/
            inputSignatures = "private final  int mOpMode\nprivate final @android.annotation.IntRange int mOpCode\nprivate final @android.annotation.Nullable java.lang.String mAttributionTag\npublic @android.annotation.NonNull java.lang.String getOp()\npublic  int getOpMode()\nclass SyncNotedAppOp extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genAidl=true, genConstructor=false)")
    @Deprecated
    private void __metadata() {}

+4 −4
Original line number Diff line number Diff line
@@ -36,9 +36,9 @@ interface IAppOpsService {
    // be kept in sync with frameworks/native/libs/binder/include/binder/IAppOpsService.h
    // and not be reordered
    int checkOperation(int code, int uid, String packageName);
    int noteOperation(int code, int uid, String packageName, @nullable String attributionTag,
    SyncNotedAppOp noteOperation(int code, int uid, String packageName, @nullable String attributionTag,
            boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage);
    int startOperation(IBinder clientId, int code, int uid, String packageName,
    SyncNotedAppOp startOperation(IBinder clientId, int code, int uid, String packageName,
            @nullable String attributionTag, boolean startIfModeDefault,
            boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage);
    @UnsupportedAppUsage
@@ -53,10 +53,10 @@ interface IAppOpsService {
    // End of methods also called by native code.
    // Any new method exposed to native must be added after the last one, do not reorder

    int noteProxyOperation(int code, in AttributionSource attributionSource,
    SyncNotedAppOp noteProxyOperation(int code, in AttributionSource attributionSource,
            boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
            boolean skipProxyOperation);
    int startProxyOperation(IBinder clientId, int code, in AttributionSource attributionSource,
    SyncNotedAppOp startProxyOperation(IBinder clientId, int code, in AttributionSource attributionSource,
            boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, String message,
            boolean shouldCollectMessage, boolean skipProxyOperation);
    void finishProxyOperation(IBinder clientId, int code, in AttributionSource attributionSource);
+11 −11
Original line number Diff line number Diff line
@@ -179,6 +179,7 @@ import android.app.PendingIntent;
import android.app.ProcessMemoryState;
import android.app.ProfilerInfo;
import android.app.PropertyInvalidatedCache;
import android.app.SyncNotedAppOp;
import android.app.WaitResult;
import android.app.backup.BackupManager.OperationType;
import android.app.backup.IBackupManager;
@@ -344,7 +345,6 @@ import com.android.internal.util.function.HeptFunction;
import com.android.internal.util.function.HexFunction;
import com.android.internal.util.function.OctFunction;
import com.android.internal.util.function.QuadFunction;
import com.android.internal.util.function.QuintFunction;
import com.android.internal.util.function.TriFunction;
import com.android.server.AlarmManagerInternal;
import com.android.server.DeviceIdleInternal;
@@ -2744,7 +2744,7 @@ public class ActivityManagerService extends IActivityManager.Stub
    private boolean hasUsageStatsPermission(String callingPackage) {
        final int mode = mAppOpsService.noteOperation(AppOpsManager.OP_GET_USAGE_STATS,
                Binder.getCallingUid(), callingPackage, null, false, "", false);
                Binder.getCallingUid(), callingPackage, null, false, "", false).getOpMode();
        if (mode == AppOpsManager.MODE_DEFAULT) {
            return checkCallingPermission(Manifest.permission.PACKAGE_USAGE_STATS)
                    == PackageManager.PERMISSION_GRANTED;
@@ -5244,7 +5244,7 @@ public class ActivityManagerService extends IActivityManager.Stub
            // TODO moltmann: Allow to specify featureId
            return mActivityManagerService.mAppOpsService
                    .noteOperation(AppOpsManager.strOpToOp(op), uid, packageName, null,
                            false, "", false);
                            false, "", false).getOpMode();
        }
        @Override
@@ -16606,11 +16606,11 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        @Override
        public int noteOperation(int code, int uid, @Nullable String packageName,
        public SyncNotedAppOp noteOperation(int code, int uid, @Nullable String packageName,
                @Nullable String featureId, boolean shouldCollectAsyncNotedOp,
                @Nullable String message, boolean shouldCollectMessage,
                @NonNull HeptFunction<Integer, Integer, String, String, Boolean, String, Boolean,
                        Integer> superImpl) {
                        SyncNotedAppOp> superImpl) {
            if (uid == mTargetUid && isTargetOp(code)) {
                final int shellUid = UserHandle.getUid(UserHandle.getUserId(uid),
                        Process.SHELL_UID);
@@ -16627,11 +16627,11 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        @Override
        public int noteProxyOperation(int code, @NonNull AttributionSource attributionSource,
                boolean shouldCollectAsyncNotedOp, @Nullable String message,
                boolean shouldCollectMessage, boolean skiProxyOperation,
        public SyncNotedAppOp noteProxyOperation(int code,
                @NonNull AttributionSource attributionSource, boolean shouldCollectAsyncNotedOp,
                @Nullable String message, boolean shouldCollectMessage, boolean skiProxyOperation,
                @NonNull HexFunction<Integer, AttributionSource, Boolean, String, Boolean,
                                Boolean, Integer> superImpl) {
                                Boolean, SyncNotedAppOp> superImpl) {
            if (attributionSource.getUid() == mTargetUid && isTargetOp(code)) {
                final int shellUid = UserHandle.getUid(UserHandle.getUserId(
                        attributionSource.getUid()), Process.SHELL_UID);
@@ -16651,12 +16651,12 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        @Override
        public int startProxyOperation(IBinder token, int code,
        public SyncNotedAppOp startProxyOperation(IBinder token, int code,
                @NonNull AttributionSource attributionSource, boolean startIfModeDefault,
                boolean shouldCollectAsyncNotedOp, String message, boolean shouldCollectMessage,
                boolean skipProsyOperation, @NonNull OctFunction<IBinder, Integer,
                        AttributionSource, Boolean, Boolean, String, Boolean, Boolean,
                        Integer> superImpl) {
                        SyncNotedAppOp> superImpl) {
            if (attributionSource.getUid() == mTargetUid && isTargetOp(code)) {
                final int shellUid = UserHandle.getUid(UserHandle.getUserId(
                        attributionSource.getUid()), Process.SHELL_UID);
Loading