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

Commit e911b478 authored by Yuting's avatar Yuting
Browse files

[DeviceAwareAppOp] Add device Id in OpEventProxyInfo

An AppOp's proxy can be from a different device indicated by the device
Id in AttributionSource. Hence we need to add device Id in
OpEventProxyInfo to show which device the proxy is on.

Bug: 337340961
Test: presubmit
Change-Id: I8067de74eedce209b4007c2ced5bbdbc25d92926
parent 41f15711
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -872,6 +872,7 @@ package android.app {
  public static final class AppOpsManager.OpEventProxyInfo implements android.os.Parcelable {
    method public int describeContents();
    method @Nullable public String getAttributionTag();
    method @FlaggedApi("android.permission.flags.device_id_in_op_proxy_info_enabled") @Nullable public String getDeviceId();
    method @Nullable public String getPackageName();
    method @IntRange(from=0) public int getUid();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
+33 −6
Original line number Diff line number Diff line
@@ -3459,6 +3459,8 @@ public class AppOpsManager {
        private @Nullable String mPackageName;
        /** Attribution tag of the proxy that noted the op */
        private @Nullable String mAttributionTag;
        /** Persistent device Id of the proxy that noted the op */
        private @Nullable String mDeviceId;

        /**
         * Reinit existing object with new state.
@@ -3466,14 +3468,16 @@ public class AppOpsManager {
         * @param uid UID of the proxy app that noted the op
         * @param packageName Package of the proxy that noted the op
         * @param attributionTag attribution tag of the proxy that noted the op
         * @param deviceId Persistent device Id of the proxy that noted the op
         *
         * @hide
         */
        public void reinit(@IntRange(from = 0) int uid, @Nullable String packageName,
                @Nullable String attributionTag) {
                @Nullable String attributionTag, @Nullable String deviceId) {
            mUid = Preconditions.checkArgumentNonnegative(uid);
            mPackageName = packageName;
            mAttributionTag = attributionTag;
            mDeviceId = deviceId;
        }


@@ -3507,16 +3511,33 @@ public class AppOpsManager {
                @IntRange(from = 0) int uid,
                @Nullable String packageName,
                @Nullable String attributionTag) {
            this(uid, packageName, attributionTag,
                    VirtualDeviceManager.PERSISTENT_DEVICE_ID_DEFAULT);
        }

        /**
         * Creates a new OpEventProxyInfo.
         *
         * @param uid UID of the proxy app that noted the op
         * @param packageName Package of the proxy that noted the op
         * @param attributionTag Attribution tag of the proxy that noted the op
         * @param deviceId Persistent device Id of the proxy that noted the op
         *
         * @hide
         */
        public OpEventProxyInfo(
                @IntRange(from = 0) int uid,
                @Nullable String packageName,
                @Nullable String attributionTag,
                @Nullable String deviceId) {
            this.mUid = uid;
            com.android.internal.util.AnnotationValidations.validate(
                    IntRange.class, null, mUid,
                    "from", 0);
            this.mPackageName = packageName;
            this.mAttributionTag = attributionTag;

            // onConstructed(); // You can define this method to get a callback
            this.mDeviceId = deviceId;
        }

        /**
         * Copy constructor
         *
@@ -3527,6 +3548,7 @@ public class AppOpsManager {
            mUid = orig.mUid;
            mPackageName = orig.mPackageName;
            mAttributionTag = orig.mAttributionTag;
            mDeviceId = orig.mDeviceId;
        }

        /**
@@ -3553,6 +3575,9 @@ public class AppOpsManager {
            return mAttributionTag;
        }

        @FlaggedApi(Flags.FLAG_DEVICE_ID_IN_OP_PROXY_INFO_ENABLED)
        public @Nullable String getDeviceId() { return mDeviceId; }

        @Override
        @DataClass.Generated.Member
        public void writeToParcel(@NonNull Parcel dest, int flags) {
@@ -3562,10 +3587,12 @@ public class AppOpsManager {
            byte flg = 0;
            if (mPackageName != null) flg |= 0x2;
            if (mAttributionTag != null) flg |= 0x4;
            if (mDeviceId != null) flg |= 0x8;
            dest.writeByte(flg);
            dest.writeInt(mUid);
            if (mPackageName != null) dest.writeString(mPackageName);
            if (mAttributionTag != null) dest.writeString(mAttributionTag);
            if (mDeviceId != null) dest.writeString(mDeviceId);
        }

        @Override
@@ -3583,14 +3610,14 @@ public class AppOpsManager {
            int uid = in.readInt();
            String packageName = (flg & 0x2) == 0 ? null : in.readString();
            String attributionTag = (flg & 0x4) == 0 ? null : in.readString();

            String deviceId = (flg & 0x8) == 0 ? null : in.readString();
            this.mUid = uid;
            com.android.internal.util.AnnotationValidations.validate(
                    IntRange.class, null, mUid,
                    "from", 0);
            this.mPackageName = packageName;
            this.mAttributionTag = attributionTag;

            this.mDeviceId = deviceId;
            // onConstructed(); // You can define this method to get a callback
        }

+8 −0
Original line number Diff line number Diff line
@@ -180,3 +180,11 @@ flag {
    description: "Use runtime permission state to determine appop state"
    bug: "266164193"
}

flag {
    name: "device_id_in_op_proxy_info_enabled"
    is_fixed_read_only: true
    namespace: "permissions"
    description: "Enable getDeviceId API in OpEventProxyInfo"
    bug: "337340961"
}
 No newline at end of file
+6 −4
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.AppOpsManager;
import android.companion.virtual.VirtualDeviceManager;
import android.os.IBinder;
import android.os.Process;
import android.os.RemoteException;
@@ -134,7 +135,7 @@ final class AttributedOp {
        AppOpsManager.OpEventProxyInfo proxyInfo = null;
        if (proxyUid != Process.INVALID_UID) {
            proxyInfo = mAppOpsService.mOpEventProxyInfoPool.acquire(proxyUid, proxyPackageName,
                    proxyAttributionTag);
                            proxyAttributionTag, VirtualDeviceManager.PERSISTENT_DEVICE_ID_DEFAULT);
        }

        AppOpsManager.NoteOpEvent existingEvent = mAccessEvents.get(key);
@@ -855,7 +856,7 @@ final class AttributedOp {
            AppOpsManager.OpEventProxyInfo proxyInfo = null;
            if (proxyUid != Process.INVALID_UID) {
                proxyInfo = mOpEventProxyInfoPool.acquire(proxyUid, proxyPackageName,
                        proxyAttributionTag);
                        proxyAttributionTag, VirtualDeviceManager.PERSISTENT_DEVICE_ID_DEFAULT);
            }

            if (recycled != null) {
@@ -881,10 +882,11 @@ final class AttributedOp {

        AppOpsManager.OpEventProxyInfo acquire(@IntRange(from = 0) int uid,
                @Nullable String packageName,
                @Nullable String attributionTag) {
                @Nullable String attributionTag,
                @Nullable String deviceId) {
            AppOpsManager.OpEventProxyInfo recycled = acquire();
            if (recycled != null) {
                recycled.reinit(uid, packageName, attributionTag);
                recycled.reinit(uid, packageName, attributionTag, deviceId);
                return recycled;
            }