diff options
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/AppOpsManager.java | 59 | ||||
| -rw-r--r-- | core/java/android/app/AppOpsManagerInternal.java | 12 | ||||
| -rw-r--r-- | core/java/android/app/SyncNotedAppOp.java | 59 |
3 files changed, 78 insertions, 52 deletions
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 6ce0b2283603..015b1af3feef 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -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; @@ -8015,18 +8015,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(); } @@ -8183,23 +8183,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(); } @@ -8496,19 +8496,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(); } @@ -8611,24 +8611,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(); } @@ -8869,13 +8868,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); } /** @@ -8883,23 +8882,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) { diff --git a/core/java/android/app/AppOpsManagerInternal.java b/core/java/android/app/AppOpsManagerInternal.java index a3d0cf2e972f..6af4d9364ad2 100644 --- a/core/java/android/app/AppOpsManagerInternal.java +++ b/core/java/android/app/AppOpsManagerInternal.java @@ -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. diff --git a/core/java/android/app/SyncNotedAppOp.java b/core/java/android/app/SyncNotedAppOp.java index 0a880dc0cbb7..bc4e5436996d 100644 --- a/core/java/android/app/SyncNotedAppOp.java +++ b/core/java/android/app/SyncNotedAppOp.java @@ -34,19 +34,37 @@ 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. * * @param opCode @@ -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() {} |
