diff --git a/api/current.txt b/api/current.txt index f6aa0a316b707..95b2719f983a0 100644 --- a/api/current.txt +++ b/api/current.txt @@ -4499,7 +4499,6 @@ package android.app { method public int describeContents(); method @Nullable public String getFeatureId(); method @NonNull public String getMessage(); - method @Nullable public String getNotingPackageName(); method @IntRange(from=0) public int getNotingUid(); method @NonNull public String getOp(); method @IntRange(from=0) public long getTime(); diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index c94e61a9a041a..5c4c37cba0849 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -2046,7 +2046,7 @@ public class AppOpsManager { * transaction. Not set if this thread is currently not executing a two way binder transaction. * * @see #startNotedAppOpsCollection - * @see #markAppOpNoted + * @see #getNotedOpCollectionMode */ private static final ThreadLocal sBinderThreadCallingUid = new ThreadLocal<>(); @@ -2054,7 +2054,8 @@ public class AppOpsManager { * If a thread is currently executing a two-way binder transaction, this stores the op-codes of * the app-ops that were noted during this transaction. * - * @see #markAppOpNoted + * @see #getNotedOpCollectionMode + * @see #collectNotedOpSync */ private static final ThreadLocal> sAppOpsNotedInThisBinderTransaction = new ThreadLocal<>(); @@ -6322,9 +6323,23 @@ public class AppOpsManager { public int noteOpNoThrow(int op, int uid, @Nullable String packageName, @Nullable String featureId, @Nullable String message) { try { - int mode = mService.noteOperation(op, uid, packageName, featureId); + int collectionMode = getNotedOpCollectionMode(uid, packageName, op); + if (collectionMode == COLLECT_ASYNC) { + if (message == null) { + // Set stack trace as default message + message = getFormattedStackTrace(); + } + } + + int mode = mService.noteOperation(op, uid, packageName, featureId, + collectionMode == COLLECT_ASYNC, message); + if (mode == MODE_ALLOWED) { - markAppOpNoted(uid, packageName, op, featureId, message); + if (collectionMode == COLLECT_SELF) { + collectNotedOpForSelf(op, featureId); + } else if (collectionMode == COLLECT_SYNC) { + collectNotedOpSync(op, featureId); + } } return mode; @@ -6468,14 +6483,27 @@ public class AppOpsManager { int myUid = Process.myUid(); try { + int collectionMode = getNotedOpCollectionMode(proxiedUid, proxiedPackageName, op); + if (collectionMode == COLLECT_ASYNC) { + if (message == null) { + // Set stack trace as default message + message = getFormattedStackTrace(); + } + } + int mode = mService.noteProxyOperation(op, proxiedUid, proxiedPackageName, proxiedFeatureId, myUid, mContext.getOpPackageName(), - mContext.getFeatureId()); - if (mode == MODE_ALLOWED - // Only collect app-ops when the proxy is trusted - && mContext.checkPermission(Manifest.permission.UPDATE_APP_OPS_STATS, -1, myUid) - == PackageManager.PERMISSION_GRANTED) { - markAppOpNoted(proxiedUid, proxiedPackageName, op, proxiedFeatureId, message); + mContext.getFeatureId(), collectionMode == COLLECT_ASYNC, message); + + if (mode == MODE_ALLOWED) { + if (collectionMode == COLLECT_SELF) { + collectNotedOpForSelf(op, proxiedFeatureId); + } 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) { + collectNotedOpSync(op, proxiedFeatureId); + } } return mode; @@ -6765,10 +6793,23 @@ public class AppOpsManager { public int startOpNoThrow(int op, int uid, @NonNull String packageName, boolean startIfModeDefault, @Nullable String featureId, @Nullable String message) { try { + int collectionMode = getNotedOpCollectionMode(uid, packageName, op); + if (collectionMode == COLLECT_ASYNC) { + if (message == null) { + // Set stack trace as default message + message = getFormattedStackTrace(); + } + } + int mode = mService.startOperation(getClientId(), op, uid, packageName, - featureId, startIfModeDefault); + featureId, startIfModeDefault, collectionMode == COLLECT_ASYNC, message); + if (mode == MODE_ALLOWED) { - markAppOpNoted(uid, packageName, op, featureId, message); + if (collectionMode == COLLECT_SELF) { + collectNotedOpForSelf(op, featureId); + } else if (collectionMode == COLLECT_SYNC) { + collectNotedOpSync(op, featureId); + } } return mode; @@ -6932,85 +6973,106 @@ public class AppOpsManager { } /** - * Mark an app-op as noted + * Collect a noted op for the current process. + * + * @param op The noted op + * @param featureId The feature the op is noted for */ - private void markAppOpNoted(int uid, @Nullable String packageName, int code, - @Nullable String featureId, @Nullable String message) { + private void collectNotedOpForSelf(int op, @Nullable String featureId) { + synchronized (sLock) { + if (sNotedAppOpsCollector != null) { + sNotedAppOpsCollector.onSelfNoted(new SyncNotedAppOp(op, featureId)); + } + } + } + + /** + * Collect a noted op when inside of a two-way binder call. + * + *

Delivered to caller via {@link #prefixParcelWithAppOpsIfNeeded} + * + * @param op The noted op + * @param featureId The feature the op is noted for + */ + private void collectNotedOpSync(int op, @Nullable String featureId) { + // 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} + ArrayMap appOpsNoted = sAppOpsNotedInThisBinderTransaction.get(); + if (appOpsNoted == null) { + appOpsNoted = new ArrayMap<>(1); + sAppOpsNotedInThisBinderTransaction.set(appOpsNoted); + } + + long[] appOpsNotedForFeature = appOpsNoted.get(featureId); + if (appOpsNotedForFeature == null) { + appOpsNotedForFeature = new long[2]; + appOpsNoted.put(featureId, appOpsNotedForFeature); + } + + if (op < 64) { + appOpsNotedForFeature[0] |= 1L << op; + } else { + appOpsNotedForFeature[1] |= 1L << (op - 64); + } + } + + /** @hide */ + @Retention(RetentionPolicy.SOURCE) + @IntDef(value = { + DONT_COLLECT, + COLLECT_SELF, + COLLECT_SYNC, + COLLECT_ASYNC + }) + private @interface NotedOpCollectionMode {} + private static final int DONT_COLLECT = 0; + private static final int COLLECT_SELF = 1; + private static final int COLLECT_SYNC = 2; + private static final int COLLECT_ASYNC = 3; + + /** + * Mark an app-op as noted. + */ + private @NotedOpCollectionMode int getNotedOpCollectionMode(int uid, + @Nullable String packageName, int op) { if (packageName == null) { packageName = "android"; } // check it the appops needs to be collected and cache result - if (sAppOpsToNote[code] == SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED) { + if (sAppOpsToNote[op] == SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED) { boolean shouldCollectNotes; try { - shouldCollectNotes = mService.shouldCollectNotes(code); + shouldCollectNotes = mService.shouldCollectNotes(op); } catch (RemoteException e) { - return; + return DONT_COLLECT; } if (shouldCollectNotes) { - sAppOpsToNote[code] = SHOULD_COLLECT_NOTE_OP; + sAppOpsToNote[op] = SHOULD_COLLECT_NOTE_OP; } else { - sAppOpsToNote[code] = SHOULD_NOT_COLLECT_NOTE_OP; + sAppOpsToNote[op] = SHOULD_NOT_COLLECT_NOTE_OP; } } - if (sAppOpsToNote[code] != SHOULD_COLLECT_NOTE_OP) { - return; + if (sAppOpsToNote[op] != SHOULD_COLLECT_NOTE_OP) { + return DONT_COLLECT; + } + + synchronized (sLock) { + if (uid == Process.myUid() + && packageName.equals(ActivityThread.currentOpPackageName())) { + return COLLECT_SELF; + } } Integer binderUid = sBinderThreadCallingUid.get(); - synchronized (sLock) { - if (sNotedAppOpsCollector != null && uid == Process.myUid() && packageName.equals( - ActivityThread.currentOpPackageName())) { - // This app is noting an app-op for itself. Deliver immediately. - sNotedAppOpsCollector.onSelfNoted(new SyncNotedAppOp(code, featureId)); - - return; - } - } - if (binderUid != null && binderUid == uid) { - // If this is inside of a two-way binder call: Delivered to caller via - // {@link #prefixParcelWithAppOpsIfNeeded} - // We are inside of a two-way binder call. Delivered to caller via - // {@link #prefixParcelWithAppOpsIfNeeded} - ArrayMap appOpsNoted = sAppOpsNotedInThisBinderTransaction.get(); - if (appOpsNoted == null) { - appOpsNoted = new ArrayMap<>(1); - sAppOpsNotedInThisBinderTransaction.set(appOpsNoted); - } - - long[] appOpsNotedForFeature = appOpsNoted.get(featureId); - if (appOpsNotedForFeature == null) { - appOpsNotedForFeature = new long[2]; - appOpsNoted.put(featureId, appOpsNotedForFeature); - } - - if (code < 64) { - appOpsNotedForFeature[0] |= 1L << code; - } else { - appOpsNotedForFeature[1] |= 1L << (code - 64); - } + return COLLECT_SYNC; } else { - // Cannot deliver the note synchronous: Hence send it to the system server to - // notify the noted process. - if (message == null) { - // Default message is a stack trace - message = getFormattedStackTrace(); - } - - long token = Binder.clearCallingIdentity(); - try { - mService.noteAsyncOp(mContext.getOpPackageName(), uid, packageName, code, - featureId, message); - } catch (RemoteException e) { - e.rethrowFromSystemServer(); - } finally { - Binder.restoreCallingIdentity(token); - } + return COLLECT_ASYNC; } } diff --git a/core/java/android/app/AppOpsManagerInternal.java b/core/java/android/app/AppOpsManagerInternal.java index bd7ef2ac3f682..099037c02bbbc 100644 --- a/core/java/android/app/AppOpsManagerInternal.java +++ b/core/java/android/app/AppOpsManagerInternal.java @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.util.SparseIntArray; +import com.android.internal.util.function.HexFunction; import com.android.internal.util.function.QuadFunction; /** @@ -63,12 +64,16 @@ public abstract class AppOpsManagerInternal { * @param uid The UID for which to note. * @param packageName The package for which to note. {@code null} for system package. * @param featureId Id of the feature in the package + * @param shouldCollectAsyncNotedOp If an {@link AsyncNotedAppOp} should be collected + * @param message The message in the async noted op * @param superImpl The super implementation. * @return The app op note result. */ int noteOperation(int code, int uid, @Nullable String packageName, - @Nullable String featureId, - @NonNull QuadFunction superImpl); + @Nullable String featureId, boolean shouldCollectAsyncNotedOp, + @Nullable String message, + @NonNull HexFunction + superImpl); } /** diff --git a/core/java/android/app/AsyncNotedAppOp.java b/core/java/android/app/AsyncNotedAppOp.java index 0e1f92177e9da..c3ef3adb60371 100644 --- a/core/java/android/app/AsyncNotedAppOp.java +++ b/core/java/android/app/AsyncNotedAppOp.java @@ -45,12 +45,6 @@ public final class AsyncNotedAppOp implements Parcelable { /** Uid that noted the op */ private final @IntRange(from = 0) int mNotingUid; - /** - * Package that noted the op. {@code null} if the package name that noted the op could be not - * be determined (e.g. when the op is noted from native code). - */ - private final @Nullable String mNotingPackageName; - /** {@link android.content.Context#createFeatureContext Feature} in the app */ private final @Nullable String mFeatureId; @@ -69,7 +63,7 @@ public final class AsyncNotedAppOp implements Parcelable { - // Code below generated by codegen v1.0.9. + // Code below generated by codegen v1.0.14. // // DO NOT MODIFY! // CHECKSTYLE:OFF Generated code @@ -89,9 +83,6 @@ public final class AsyncNotedAppOp implements Parcelable { * Op that was noted * @param notingUid * Uid that noted the op - * @param notingPackageName - * Package that noted the op. {@code null} if the package name that noted the op could be not - * be determined (e.g. when the op is noted from native code). * @param featureId * {@link android.content.Context#createFeatureContext Feature} in the app * @param message @@ -104,7 +95,6 @@ public final class AsyncNotedAppOp implements Parcelable { public AsyncNotedAppOp( @IntRange(from = 0, to = AppOpsManager._NUM_OP - 1) int opCode, @IntRange(from = 0) int notingUid, - @Nullable String notingPackageName, @Nullable String featureId, @NonNull String message, @IntRange(from = 0) long time) { @@ -117,7 +107,6 @@ public final class AsyncNotedAppOp implements Parcelable { com.android.internal.util.AnnotationValidations.validate( IntRange.class, null, mNotingUid, "from", 0); - this.mNotingPackageName = notingPackageName; this.mFeatureId = featureId; this.mMessage = message; com.android.internal.util.AnnotationValidations.validate( @@ -138,15 +127,6 @@ public final class AsyncNotedAppOp implements Parcelable { return mNotingUid; } - /** - * Package that noted the op. {@code null} if the package name that noted the op could be not - * be determined (e.g. when the op is noted from native code). - */ - @DataClass.Generated.Member - public @Nullable String getNotingPackageName() { - return mNotingPackageName; - } - /** * {@link android.content.Context#createFeatureContext Feature} in the app */ @@ -186,7 +166,6 @@ public final class AsyncNotedAppOp implements Parcelable { return true && mOpCode == that.mOpCode && mNotingUid == that.mNotingUid - && java.util.Objects.equals(mNotingPackageName, that.mNotingPackageName) && java.util.Objects.equals(mFeatureId, that.mFeatureId) && java.util.Objects.equals(mMessage, that.mMessage) && mTime == that.mTime; @@ -201,7 +180,6 @@ public final class AsyncNotedAppOp implements Parcelable { int _hash = 1; _hash = 31 * _hash + mOpCode; _hash = 31 * _hash + mNotingUid; - _hash = 31 * _hash + java.util.Objects.hashCode(mNotingPackageName); _hash = 31 * _hash + java.util.Objects.hashCode(mFeatureId); _hash = 31 * _hash + java.util.Objects.hashCode(mMessage); _hash = 31 * _hash + Long.hashCode(mTime); @@ -215,12 +193,10 @@ public final class AsyncNotedAppOp implements Parcelable { // void parcelFieldName(Parcel dest, int flags) { ... } byte flg = 0; - if (mNotingPackageName != null) flg |= 0x4; - if (mFeatureId != null) flg |= 0x8; + if (mFeatureId != null) flg |= 0x4; dest.writeByte(flg); dest.writeInt(mOpCode); dest.writeInt(mNotingUid); - if (mNotingPackageName != null) dest.writeString(mNotingPackageName); if (mFeatureId != null) dest.writeString(mFeatureId); dest.writeString(mMessage); dest.writeLong(mTime); @@ -240,8 +216,7 @@ public final class AsyncNotedAppOp implements Parcelable { byte flg = in.readByte(); int opCode = in.readInt(); int notingUid = in.readInt(); - String notingPackageName = (flg & 0x4) == 0 ? null : in.readString(); - String featureId = (flg & 0x8) == 0 ? null : in.readString(); + String featureId = (flg & 0x4) == 0 ? null : in.readString(); String message = in.readString(); long time = in.readLong(); @@ -254,7 +229,6 @@ public final class AsyncNotedAppOp implements Parcelable { com.android.internal.util.AnnotationValidations.validate( IntRange.class, null, mNotingUid, "from", 0); - this.mNotingPackageName = notingPackageName; this.mFeatureId = featureId; this.mMessage = message; com.android.internal.util.AnnotationValidations.validate( @@ -282,11 +256,15 @@ public final class AsyncNotedAppOp implements Parcelable { }; @DataClass.Generated( - time = 1571327470155L, - codegenVersion = "1.0.9", + time = 1576864422226L, + codegenVersion = "1.0.14", sourceFile = "frameworks/base/core/java/android/app/AsyncNotedAppOp.java", - inputSignatures = "private final @android.annotation.IntRange(from=0L, to=92L) int mOpCode\nprivate final @android.annotation.IntRange(from=0L) int mNotingUid\nprivate final @android.annotation.Nullable java.lang.String mNotingPackageName\nprivate final @android.annotation.Nullable java.lang.String mFeatureId\nprivate final @android.annotation.NonNull java.lang.String mMessage\nprivate final @android.annotation.IntRange(from=0L) long mTime\npublic @android.annotation.NonNull java.lang.String getOp()\nclass AsyncNotedAppOp extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genAidl=true, genHiddenConstructor=true)") + inputSignatures = "private final @android.annotation.IntRange(from=0L, to=92L) int mOpCode\nprivate final @android.annotation.IntRange(from=0L) int mNotingUid\nprivate final @android.annotation.Nullable java.lang.String mFeatureId\nprivate final @android.annotation.NonNull java.lang.String mMessage\nprivate final @android.annotation.IntRange(from=0L) long mTime\npublic @android.annotation.NonNull java.lang.String getOp()\nclass AsyncNotedAppOp extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genAidl=true, genHiddenConstructor=true)") @Deprecated private void __metadata() {} + + //@formatter:on + // End of generated code + } diff --git a/core/java/com/android/internal/app/IAppOpsService.aidl b/core/java/com/android/internal/app/IAppOpsService.aidl index 46025aa2d6f0f..4e764fcab7b70 100644 --- a/core/java/com/android/internal/app/IAppOpsService.aidl +++ b/core/java/com/android/internal/app/IAppOpsService.aidl @@ -31,9 +31,11 @@ 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 featureId); + int noteOperation(int code, int uid, String packageName, @nullable String featureId, + boolean shouldCollectAsyncNotedOp, String message); int startOperation(IBinder clientId, int code, int uid, String packageName, - @nullable String featureId, boolean startIfModeDefault); + @nullable String featureId, boolean startIfModeDefault, + boolean shouldCollectAsyncNotedOp, String message); @UnsupportedAppUsage void finishOperation(IBinder clientId, int code, int uid, String packageName, @nullable String featureId); @@ -41,8 +43,6 @@ interface IAppOpsService { void stopWatchingMode(IAppOpsCallback callback); int permissionToOpCode(String permission); int checkAudioOperation(int code, int usage, int uid, String packageName); - void noteAsyncOp(@nullable String callingPackageName, int uid, @nullable String packageName, - int opCode, @nullable String featureId, String message); boolean shouldCollectNotes(int opCode); void setCameraAudioRestriction(int mode); // End of methods also called by native code. @@ -50,7 +50,7 @@ interface IAppOpsService { int noteProxyOperation(int code, int proxiedUid, String proxiedPackageName, String proxiedFeatureId, int proxyUid, String proxyPackageName, - String proxyFeatureId); + String proxyFeatureId, boolean shouldCollectAsyncNotedOp, String message); // Remaining methods are only used in Java. int checkPackage(int uid, String packageName); diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 154d16f013db5..a58bd9bf32ff6 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -570,7 +570,7 @@ public final class ActiveServices { } mAm.mAppOpsService.startOperation(AppOpsManager.getToken(mAm.mAppOpsService), AppOpsManager.OP_START_FOREGROUND, r.appInfo.uid, r.packageName, null, - true); + true, false, null); } final ServiceMap smap = getServiceMapLocked(r.userId); @@ -1395,7 +1395,7 @@ public final class ActiveServices { mAm.mAppOpsService.startOperation( AppOpsManager.getToken(mAm.mAppOpsService), AppOpsManager.OP_START_FOREGROUND, r.appInfo.uid, r.packageName, - null, true); + null, true, false, ""); StatsLog.write(StatsLog.FOREGROUND_SERVICE_STATE_CHANGED, r.appInfo.uid, r.shortInstanceName, StatsLog.FOREGROUND_SERVICE_STATE_CHANGED__STATE__ENTER); diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index d7a46fec77671..dd1f3704e46f3 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -324,6 +324,7 @@ import com.android.internal.util.DumpUtils; import com.android.internal.util.FastPrintWriter; import com.android.internal.util.MemInfoReader; import com.android.internal.util.Preconditions; +import com.android.internal.util.function.HexFunction; import com.android.internal.util.function.QuadFunction; import com.android.internal.util.function.TriFunction; import com.android.server.AlarmManagerInternal; @@ -3120,7 +3121,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); + Binder.getCallingUid(), callingPackage, null, false, ""); if (mode == AppOpsManager.MODE_DEFAULT) { return checkCallingPermission(Manifest.permission.PACKAGE_USAGE_STATS) == PackageManager.PERMISSION_GRANTED; @@ -5816,7 +5817,8 @@ public class ActivityManagerService extends IActivityManager.Stub public int noteOp(String op, int uid, String packageName) { // TODO moltmann: Allow to specify featureId return mActivityManagerService.mAppOpsService - .noteOperation(AppOpsManager.strOpToOp(op), uid, packageName, null); + .noteOperation(AppOpsManager.strOpToOp(op), uid, packageName, null, + false, ""); } @Override @@ -5968,7 +5970,7 @@ public class ActivityManagerService extends IActivityManager.Stub } // ...and legacy apps get an AppOp check int appop = mAppOpsService.noteOperation(AppOpsManager.OP_RUN_IN_BACKGROUND, - uid, packageName, null); + uid, packageName, null, false, ""); if (DEBUG_BACKGROUND_CHECK) { Slog.i(TAG, "Legacy app " + uid + "/" + packageName + " bg appop " + appop); } @@ -19253,18 +19255,22 @@ public class ActivityManagerService extends IActivityManager.Stub @Override public int noteOperation(int code, int uid, @Nullable String packageName, - @Nullable String featureId, - @NonNull QuadFunction superImpl) { + @Nullable String featureId, boolean shouldCollectAsyncNotedOp, + @Nullable String message, + @NonNull HexFunction + superImpl) { if (uid == mTargetUid && isTargetOp(code)) { final long identity = Binder.clearCallingIdentity(); try { return mAppOpsService.noteProxyOperation(code, Process.SHELL_UID, - "com.android.shell", null, uid, packageName, featureId); + "com.android.shell", null, uid, packageName, featureId, + shouldCollectAsyncNotedOp, message); } finally { Binder.restoreCallingIdentity(identity); } } - return superImpl.apply(code, uid, packageName, featureId); + return superImpl.apply(code, uid, packageName, featureId, shouldCollectAsyncNotedOp, + message); } @Override diff --git a/services/core/java/com/android/server/am/BroadcastQueue.java b/services/core/java/com/android/server/am/BroadcastQueue.java index 10492a71f1118..6fca3f61e6706 100644 --- a/services/core/java/com/android/server/am/BroadcastQueue.java +++ b/services/core/java/com/android/server/am/BroadcastQueue.java @@ -650,7 +650,7 @@ public final class BroadcastQueue { // TODO moltmann: Set featureId from caller if (opCode != AppOpsManager.OP_NONE && mService.mAppOpsService.noteOperation(opCode, r.callingUid, - r.callerPackage, null) != AppOpsManager.MODE_ALLOWED) { + r.callerPackage, null, false, "") != AppOpsManager.MODE_ALLOWED) { Slog.w(TAG, "Appop Denial: broadcasting " + r.intent.toString() + " from " + r.callerPackage + " (pid=" @@ -680,10 +680,10 @@ public final class BroadcastQueue { break; } int appOp = AppOpsManager.permissionToOpCode(requiredPermission); - // TODO moltmann: Set componentId from caller + // TODO moltmann: Set featureId from caller if (appOp != AppOpsManager.OP_NONE && appOp != r.appOp && mService.mAppOpsService.noteOperation(appOp, - filter.receiverList.uid, filter.packageName, null) + filter.receiverList.uid, filter.packageName, null, false, "") != AppOpsManager.MODE_ALLOWED) { Slog.w(TAG, "Appop Denial: receiving " + r.intent.toString() @@ -713,10 +713,10 @@ public final class BroadcastQueue { skip = true; } } - // TODO moltmann: Set componentId from caller + // TODO moltmann: Set featureId from caller if (!skip && r.appOp != AppOpsManager.OP_NONE && mService.mAppOpsService.noteOperation(r.appOp, - filter.receiverList.uid, filter.packageName, null) + filter.receiverList.uid, filter.packageName, null, false, "") != AppOpsManager.MODE_ALLOWED) { Slog.w(TAG, "Appop Denial: receiving " + r.intent.toString() @@ -1370,10 +1370,10 @@ public final class BroadcastQueue { skip = true; } else if (!skip && info.activityInfo.permission != null) { final int opCode = AppOpsManager.permissionToOpCode(info.activityInfo.permission); - // TODO moltmann: Set componentId from caller + // TODO moltmann: Set featureId from caller if (opCode != AppOpsManager.OP_NONE - && mService.mAppOpsService.noteOperation(opCode, r.callingUid, - r.callerPackage, null) != AppOpsManager.MODE_ALLOWED) { + && mService.mAppOpsService.noteOperation(opCode, r.callingUid, r.callerPackage, + null, false, "") != AppOpsManager.MODE_ALLOWED) { Slog.w(TAG, "Appop Denial: broadcasting " + r.intent.toString() + " from " + r.callerPackage + " (pid=" @@ -1409,10 +1409,11 @@ public final class BroadcastQueue { break; } int appOp = AppOpsManager.permissionToOpCode(requiredPermission); - // TODO moltmann: Set componentId from caller + // TODO moltmann: Set featureId from caller if (appOp != AppOpsManager.OP_NONE && appOp != r.appOp && mService.mAppOpsService.noteOperation(appOp, - info.activityInfo.applicationInfo.uid, info.activityInfo.packageName, null) + info.activityInfo.applicationInfo.uid, info.activityInfo.packageName, null, + false, "") != AppOpsManager.MODE_ALLOWED) { Slog.w(TAG, "Appop Denial: receiving " + r.intent + " to " @@ -1426,10 +1427,11 @@ public final class BroadcastQueue { } } } - // TODO moltmann: Set componentId from caller + // TODO moltmann: Set featureId from caller if (!skip && r.appOp != AppOpsManager.OP_NONE && mService.mAppOpsService.noteOperation(r.appOp, - info.activityInfo.applicationInfo.uid, info.activityInfo.packageName, null) + info.activityInfo.applicationInfo.uid, info.activityInfo.packageName, null, false, + "") != AppOpsManager.MODE_ALLOWED) { Slog.w(TAG, "Appop Denial: receiving " + r.intent + " to " diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java index 1e136617bf24b..5bbb517f60716 100644 --- a/services/core/java/com/android/server/appop/AppOpsService.java +++ b/services/core/java/com/android/server/appop/AppOpsService.java @@ -221,7 +221,7 @@ public class AppOpsService extends IAppOpsService.Stub { = new AppOpsManagerInternalImpl(); /** - * Registered callbacks, called from {@link #noteAsyncOp}. + * Registered callbacks, called from {@link #collectAsyncNotedOp}. * *

(package name, uid) -> callbacks * @@ -232,7 +232,7 @@ public class AppOpsService extends IAppOpsService.Stub { mAsyncOpWatchers = new ArrayMap<>(); /** - * Async note-ops collected from {@link #noteAsyncOp} that have not been delivered to a + * Async note-ops collected from {@link #collectAsyncNotedOp} that have not been delivered to a * callback yet. * *

(package name, uid) -> list<ops> @@ -1436,11 +1436,13 @@ public class AppOpsService extends IAppOpsService.Stub { return Zygote.MOUNT_EXTERNAL_NONE; } if (noteOperation(AppOpsManager.OP_READ_EXTERNAL_STORAGE, uid, - packageName, null) != AppOpsManager.MODE_ALLOWED) { + packageName, null, true, "External storage policy") + != AppOpsManager.MODE_ALLOWED) { return Zygote.MOUNT_EXTERNAL_NONE; } if (noteOperation(AppOpsManager.OP_WRITE_EXTERNAL_STORAGE, uid, - packageName, null) != AppOpsManager.MODE_ALLOWED) { + packageName, null, true, "External storage policy") + != AppOpsManager.MODE_ALLOWED) { return Zygote.MOUNT_EXTERNAL_READ; } return Zygote.MOUNT_EXTERNAL_WRITE; @@ -2521,7 +2523,7 @@ public class AppOpsService extends IAppOpsService.Stub { @Override public int noteProxyOperation(int code, int proxiedUid, String proxiedPackageName, String proxiedFeatureId, int proxyUid, String proxyPackageName, - String proxyFeatureId) { + String proxyFeatureId, boolean shouldCollectAsyncNotedOp, String message) { verifyIncomingUid(proxyUid); verifyIncomingOp(code); @@ -2537,7 +2539,8 @@ public class AppOpsService extends IAppOpsService.Stub { final int proxyFlags = isProxyTrusted ? AppOpsManager.OP_FLAG_TRUSTED_PROXY : AppOpsManager.OP_FLAG_UNTRUSTED_PROXY; final int proxyMode = noteOperationUnchecked(code, proxyUid, resolveProxyPackageName, - proxyFeatureId, Process.INVALID_UID, null, null, proxyFlags); + proxyFeatureId, Process.INVALID_UID, null, null, proxyFlags, + !isProxyTrusted, "proxy " + message); if (proxyMode != AppOpsManager.MODE_ALLOWED || Binder.getCallingUid() == proxiedUid) { return proxyMode; } @@ -2550,23 +2553,27 @@ public class AppOpsService extends IAppOpsService.Stub { : AppOpsManager.OP_FLAG_UNTRUSTED_PROXIED; return noteOperationUnchecked(code, proxiedUid, resolveProxiedPackageName, proxiedFeatureId, proxyUid, resolveProxyPackageName, proxyFeatureId, - proxiedFlags); + proxiedFlags, shouldCollectAsyncNotedOp, message); } @Override - public int noteOperation(int code, int uid, String packageName, String featureId) { + public int noteOperation(int code, int uid, String packageName, String featureId, + boolean shouldCollectAsyncNotedOp, String message) { final CheckOpsDelegate delegate; synchronized (this) { delegate = mCheckOpsDelegate; } if (delegate == null) { - return noteOperationImpl(code, uid, packageName, featureId); + return noteOperationImpl(code, uid, packageName, featureId, shouldCollectAsyncNotedOp, + message); } - return delegate.noteOperation(code, uid, packageName, featureId, - AppOpsService.this::noteOperationImpl); + return delegate.noteOperation(code, uid, packageName, featureId, shouldCollectAsyncNotedOp, + message, AppOpsService.this::noteOperationImpl); } - private int noteOperationImpl(int code, int uid, String packageName, String featureId) { + private int noteOperationImpl(int code, int uid, @Nullable String packageName, + @Nullable String featureId, boolean shouldCollectAsyncNotedOp, + @Nullable String message) { verifyIncomingUid(uid); verifyIncomingOp(code); String resolvedPackageName = resolvePackageName(uid, packageName); @@ -2574,12 +2581,14 @@ public class AppOpsService extends IAppOpsService.Stub { return AppOpsManager.MODE_IGNORED; } return noteOperationUnchecked(code, uid, resolvedPackageName, featureId, - Process.INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF); + Process.INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF, + shouldCollectAsyncNotedOp, message); } - private int noteOperationUnchecked(int code, int uid, String packageName, String featureId, - int proxyUid, String proxyPackageName, @Nullable String proxyFeatureId, - @OpFlags int flags) { + private int noteOperationUnchecked(int code, int uid, @NonNull String packageName, + @Nullable String featureId, int proxyUid, String proxyPackageName, + @Nullable String proxyFeatureId, @OpFlags int flags, boolean shouldCollectAsyncNotedOp, + @Nullable String message) { boolean isPrivileged; try { isPrivileged = verifyAndGetIsPrivileged(uid, packageName, featureId); @@ -2650,6 +2659,11 @@ public class AppOpsService extends IAppOpsService.Stub { uidState.state, flags); scheduleOpNotedIfNeededLocked(code, uid, packageName, AppOpsManager.MODE_ALLOWED); + + if (shouldCollectAsyncNotedOp) { + collectAsyncNotedOp(uid, packageName, code, featureId, message); + } + return AppOpsManager.MODE_ALLOWED; } } @@ -2746,21 +2760,20 @@ public class AppOpsService extends IAppOpsService.Stub { } } - @Override - public void noteAsyncOp(String callingPackageName, int uid, String packageName, int opCode, - String featureId, String message) { + /** + * Collect an {@link AsyncNotedAppOp}. + * + * @param uid The uid the op was noted for + * @param packageName The package the op was noted for + * @param opCode The code of the op noted + * @param featureId The id of the feature to op was noted for + * @param message The message for the op noting + */ + private void collectAsyncNotedOp(int uid, @NonNull String packageName, int opCode, + @Nullable String featureId, @NonNull String message) { Objects.requireNonNull(message); - verifyAndGetIsPrivileged(uid, packageName, featureId); - - verifyIncomingUid(uid); - verifyIncomingOp(opCode); int callingUid = Binder.getCallingUid(); - long now = System.currentTimeMillis(); - - if (callingPackageName != null) { - verifyAndGetIsPrivileged(callingUid, callingPackageName, featureId); - } long token = Binder.clearCallingIdentity(); try { @@ -2769,7 +2782,7 @@ public class AppOpsService extends IAppOpsService.Stub { RemoteCallbackList callbacks = mAsyncOpWatchers.get(key); AsyncNotedAppOp asyncNotedOp = new AsyncNotedAppOp(opCode, callingUid, - callingPackageName, featureId, message, now); + featureId, message, System.currentTimeMillis()); final boolean[] wasNoteForwarded = {false}; if (callbacks != null) { @@ -2882,7 +2895,8 @@ public class AppOpsService extends IAppOpsService.Stub { @Override public int startOperation(IBinder clientId, int code, int uid, String packageName, - String featureId, boolean startIfModeDefault) { + String featureId, boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp, + String message) { verifyIncomingUid(uid); verifyIncomingOp(code); String resolvedPackageName = resolvePackageName(uid, packageName); @@ -2953,6 +2967,10 @@ public class AppOpsService extends IAppOpsService.Stub { } } + if (shouldCollectAsyncNotedOp) { + collectAsyncNotedOp(uid, packageName, code, featureId, message); + } + return AppOpsManager.MODE_ALLOWED; } @@ -4379,7 +4397,8 @@ public class AppOpsService extends IAppOpsService.Stub { if (shell.packageName != null) { shell.mInterface.startOperation(shell.mToken, shell.op, shell.packageUid, - shell.packageName, shell.featureId, true); + shell.packageName, shell.featureId, true, true, + "appops start shell command"); } else { return -1; } diff --git a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java index a380efc43a82b..c9ef851cc97d4 100644 --- a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java @@ -1211,8 +1211,8 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { } // TODO moltmann b/136595429: Set featureId from caller - if (mService.getAppOpsService().noteOperation(opCode, callingUid, callingPackage, /* featureId */ null) - != AppOpsManager.MODE_ALLOWED) { + if (mService.getAppOpsService().noteOperation(opCode, callingUid, + callingPackage, /* featureId */ null, false, "") != AppOpsManager.MODE_ALLOWED) { if (!ignoreTargetSecurity) { return ACTIVITY_RESTRICTION_APPOP; } @@ -1254,9 +1254,9 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks { return ACTIVITY_RESTRICTION_NONE; } - // TODO moltmann b/136595429: Set componentId from caller - if (mService.getAppOpsService().noteOperation(opCode, callingUid, callingPackage, /* featureId */ null) - != AppOpsManager.MODE_ALLOWED) { + // TODO moltmann b/136595429: Set featureId from caller + if (mService.getAppOpsService().noteOperation(opCode, callingUid, + callingPackage, /* featureId */ null, false, "") != AppOpsManager.MODE_ALLOWED) { return ACTIVITY_RESTRICTION_APPOP; } diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java index 6c3b58018392f..fb3343e5b8b10 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java @@ -902,7 +902,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { boolean hasSystemAlertWindowPermission(int callingUid, int callingPid, String callingPackage) { final int mode = getAppOpsService().noteOperation(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, - callingUid, callingPackage, /* featureId */ null); + callingUid, callingPackage, /* featureId */ null, false, ""); if (mode == AppOpsManager.MODE_DEFAULT) { return checkPermission(Manifest.permission.SYSTEM_ALERT_WINDOW, callingPid, callingUid) == PERMISSION_GRANTED; diff --git a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java index f553a4818fa22..0504d14317c27 100644 --- a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java @@ -168,12 +168,12 @@ public class AppOpsServiceTest { mAppOpsService.setMode(OP_WRITE_SMS, mMyUid, sMyPackageName, MODE_ERRORED); // Note an op that's allowed. - mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null); + mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null); List loggedOps = getLoggedOps(); assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED); // Note another op that's not allowed. - mAppOpsService.noteOperation(OP_WRITE_SMS, mMyUid, sMyPackageName, null); + mAppOpsService.noteOperation(OP_WRITE_SMS, mMyUid, sMyPackageName, null, false, null); loggedOps = getLoggedOps(); assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED); assertContainsOp(loggedOps, OP_WRITE_SMS, -1, mTestStartMillis, MODE_ERRORED); @@ -189,16 +189,16 @@ public class AppOpsServiceTest { // This op controls WIFI_SCAN mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, sMyPackageName, MODE_ALLOWED); - assertThat(mAppOpsService.noteOperation(OP_WIFI_SCAN, mMyUid, sMyPackageName, null)) - .isEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_WIFI_SCAN, mMyUid, sMyPackageName, null, false, + null)).isEqualTo(MODE_ALLOWED); assertContainsOp(getLoggedOps(), OP_WIFI_SCAN, mTestStartMillis, -1, MODE_ALLOWED /* default for WIFI_SCAN; this is not changed or used in this test */); // Now set COARSE_LOCATION to ERRORED -> this will make WIFI_SCAN disabled as well. mAppOpsService.setMode(OP_COARSE_LOCATION, mMyUid, sMyPackageName, MODE_ERRORED); - assertThat(mAppOpsService.noteOperation(OP_WIFI_SCAN, mMyUid, sMyPackageName, null)) - .isEqualTo(MODE_ERRORED); + assertThat(mAppOpsService.noteOperation(OP_WIFI_SCAN, mMyUid, sMyPackageName, null, false, + null)).isEqualTo(MODE_ERRORED); assertContainsOp(getLoggedOps(), OP_WIFI_SCAN, mTestStartMillis, mTestStartMillis, MODE_ALLOWED /* default for WIFI_SCAN; this is not changed or used in this test */); @@ -209,8 +209,8 @@ public class AppOpsServiceTest { public void testStatePersistence() { mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED); mAppOpsService.setMode(OP_WRITE_SMS, mMyUid, sMyPackageName, MODE_ERRORED); - mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null); - mAppOpsService.noteOperation(OP_WRITE_SMS, mMyUid, sMyPackageName, null); + mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null); + mAppOpsService.noteOperation(OP_WRITE_SMS, mMyUid, sMyPackageName, null, false, null); mAppOpsService.writeState(); // Create a new app ops service, and initialize its state from XML. @@ -227,7 +227,7 @@ public class AppOpsServiceTest { @Test public void testShutdown() { mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED); - mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null); + mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null); mAppOpsService.shutdown(); // Create a new app ops service, and initialize its state from XML. @@ -242,7 +242,7 @@ public class AppOpsServiceTest { @Test public void testGetOpsForPackage() { mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED); - mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null); + mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null); // Query all ops List loggedOps = mAppOpsService.getOpsForPackage( @@ -271,7 +271,7 @@ public class AppOpsServiceTest { @Test public void testPackageRemoved() { mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED); - mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null); + mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null); List loggedOps = getLoggedOps(); assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED); @@ -284,7 +284,7 @@ public class AppOpsServiceTest { @Test public void testPackageRemovedHistoricalOps() throws InterruptedException { mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED); - mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null); + mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null); AppOpsManager.HistoricalOps historicalOps = new AppOpsManager.HistoricalOps(0, 15000); historicalOps.increaseAccessCount(OP_READ_SMS, mMyUid, sMyPackageName, @@ -323,7 +323,7 @@ public class AppOpsServiceTest { @Test public void testUidRemoved() { mAppOpsService.setMode(OP_READ_SMS, mMyUid, sMyPackageName, MODE_ALLOWED); - mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null); + mAppOpsService.noteOperation(OP_READ_SMS, mMyUid, sMyPackageName, null, false, null); List loggedOps = getLoggedOps(); assertContainsOp(loggedOps, OP_READ_SMS, mTestStartMillis, -1, MODE_ALLOWED); @@ -346,13 +346,13 @@ public class AppOpsServiceTest { mAppOpsService.updateUidProcState(mMyUid, ActivityManager.PROCESS_STATE_CACHED_EMPTY, ActivityManager.PROCESS_CAPABILITY_NONE); - assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null)) - .isNotEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null, + false, null)).isNotEqualTo(MODE_ALLOWED); mAppOpsService.updateUidProcState(mMyUid, ActivityManager.PROCESS_STATE_TOP, ActivityManager.PROCESS_CAPABILITY_FOREGROUND_LOCATION); - assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null)) - .isEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null, + false, null)).isEqualTo(MODE_ALLOWED); mAppOpsService.updateUidProcState(mMyUid, ActivityManager.PROCESS_STATE_CACHED_EMPTY, ActivityManager.PROCESS_CAPABILITY_NONE); @@ -360,8 +360,8 @@ public class AppOpsServiceTest { Thread.sleep(50); mAppOpsService.updateUidProcState(mMyUid, ActivityManager.PROCESS_STATE_CACHED_EMPTY, ActivityManager.PROCESS_CAPABILITY_NONE); - assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null)) - .isNotEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null, + false, null)).isNotEqualTo(MODE_ALLOWED); } @Test @@ -369,13 +369,13 @@ public class AppOpsServiceTest { setupProcStateTests(); mAppOpsService.updateUidProcState(mMyUid, ActivityManager.PROCESS_STATE_CACHED_EMPTY, ActivityManager.PROCESS_CAPABILITY_NONE); - assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null)) - .isNotEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null, + false, null)).isNotEqualTo(MODE_ALLOWED); mAppOpsService.updateUidProcState(mMyUid, PROCESS_STATE_FOREGROUND_SERVICE, ActivityManager.PROCESS_CAPABILITY_NONE); - assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null)) - .isNotEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null, + false, null)).isNotEqualTo(MODE_ALLOWED); } @Test @@ -384,13 +384,13 @@ public class AppOpsServiceTest { mAppOpsService.updateUidProcState(mMyUid, ActivityManager.PROCESS_STATE_CACHED_EMPTY, ActivityManager.PROCESS_CAPABILITY_NONE); - assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null)) - .isNotEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null, + false, null)).isNotEqualTo(MODE_ALLOWED); mAppOpsService.updateUidProcState(mMyUid, PROCESS_STATE_FOREGROUND_SERVICE, ActivityManager.PROCESS_CAPABILITY_FOREGROUND_LOCATION); - assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null)) - .isEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null, + false, null)).isEqualTo(MODE_ALLOWED); } @Test @@ -399,13 +399,13 @@ public class AppOpsServiceTest { mAppOpsService.updateUidProcState(mMyUid, ActivityManager.PROCESS_STATE_CACHED_EMPTY, ActivityManager.PROCESS_CAPABILITY_NONE); - assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null)) - .isNotEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null, + false, null)).isNotEqualTo(MODE_ALLOWED); mAppOpsService.updateUidProcState(mMyUid, ActivityManager.PROCESS_STATE_TOP, ActivityManager.PROCESS_CAPABILITY_FOREGROUND_LOCATION); - assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null)) - .isEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null, + false, null)).isEqualTo(MODE_ALLOWED); mAppOpsService.updateUidProcState(mMyUid, PROCESS_STATE_FOREGROUND_SERVICE, ActivityManager.PROCESS_CAPABILITY_NONE); @@ -413,8 +413,8 @@ public class AppOpsServiceTest { Thread.sleep(50); mAppOpsService.updateUidProcState(mMyUid, PROCESS_STATE_FOREGROUND_SERVICE, ActivityManager.PROCESS_CAPABILITY_NONE); - assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null)) - .isNotEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null, + false, null)).isNotEqualTo(MODE_ALLOWED); } @Test @@ -423,13 +423,13 @@ public class AppOpsServiceTest { mAppOpsService.updateUidProcState(mMyUid, ActivityManager.PROCESS_STATE_CACHED_EMPTY, ActivityManager.PROCESS_CAPABILITY_NONE); - assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null)) - .isNotEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null, + false, null)).isNotEqualTo(MODE_ALLOWED); mAppOpsService.updateUidProcState(mMyUid, ActivityManager.PROCESS_STATE_TOP, ActivityManager.PROCESS_CAPABILITY_FOREGROUND_LOCATION); - assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null)) - .isEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null, + false, null)).isEqualTo(MODE_ALLOWED); mAppOpsService.updateUidProcState(mMyUid, PROCESS_STATE_FOREGROUND_SERVICE, ActivityManager.PROCESS_CAPABILITY_FOREGROUND_LOCATION); @@ -437,8 +437,8 @@ public class AppOpsServiceTest { Thread.sleep(50); mAppOpsService.updateUidProcState(mMyUid, PROCESS_STATE_FOREGROUND_SERVICE, ActivityManager.PROCESS_CAPABILITY_FOREGROUND_LOCATION); - assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null)) - .isEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null, + false, null)).isEqualTo(MODE_ALLOWED); mAppOpsService.updateUidProcState(mMyUid, PROCESS_STATE_FOREGROUND_SERVICE, ActivityManager.PROCESS_CAPABILITY_NONE); @@ -446,8 +446,8 @@ public class AppOpsServiceTest { Thread.sleep(50); mAppOpsService.updateUidProcState(mMyUid, PROCESS_STATE_FOREGROUND_SERVICE, ActivityManager.PROCESS_CAPABILITY_NONE); - assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null)) - .isNotEqualTo(MODE_ALLOWED); + assertThat(mAppOpsService.noteOperation(OP_COARSE_LOCATION, mMyUid, sMyPackageName, null, + false, null)).isNotEqualTo(MODE_ALLOWED); } private List getLoggedOps() { diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/am/ActivityManagerServiceTest.java index 2ce17a1d0cea0..f8bcff55ba416 100644 --- a/services/tests/servicestests/src/com/android/server/am/ActivityManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/am/ActivityManagerServiceTest.java @@ -485,7 +485,7 @@ public class ActivityManagerServiceTest { @Test public void testDispatchUids_dispatchNeededChanges() throws RemoteException { when(mAppOpsService.noteOperation(AppOpsManager.OP_GET_USAGE_STATS, Process.myUid(), null, - null)).thenReturn(AppOpsManager.MODE_ALLOWED); + null, false, null)).thenReturn(AppOpsManager.MODE_ALLOWED); final int[] changesToObserve = { ActivityManager.UID_OBSERVER_PROCSTATE, diff --git a/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java b/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java index f90eca35d22a6..e27c724821956 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java +++ b/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java @@ -433,7 +433,7 @@ public class SystemServicesTestRule implements TestRule { doReturn(aos).when(this).getAppOpsService(); // Make sure permission checks aren't overridden. doReturn(AppOpsManager.MODE_DEFAULT).when(aos).noteOperation(anyInt(), anyInt(), - anyString(), nullable(String.class)); + anyString(), nullable(String.class), anyBoolean(), nullable(String.class)); // UserManagerService final UserManagerService ums = mock(UserManagerService.class);