diff options
| author | 2023-12-07 18:03:13 +0000 | |
|---|---|---|
| committer | 2023-12-07 18:03:13 +0000 | |
| commit | f3e4351ed08b3be72190cdabc6533af76a64b7b7 (patch) | |
| tree | 9e81d01c8895c1659c40b087722233c6aa60cf05 | |
| parent | 5d0a104b96036d9f345c1eb4fdf245d14963d87b (diff) | |
| parent | 490567fd9a4f8ecf3a0a9ab8582e9bce2c93bbe4 (diff) | |
Merge "Add app op reserved specifically for testing" into main
| -rw-r--r-- | core/api/test-current.txt | 1 | ||||
| -rw-r--r-- | core/java/android/app/AppOpsManager.java | 26 | ||||
| -rw-r--r-- | services/core/java/com/android/server/appop/DiscreteRegistry.java | 3 |
3 files changed, 27 insertions, 3 deletions
diff --git a/core/api/test-current.txt b/core/api/test-current.txt index 98a78cfaa38c..7417137b3725 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -259,6 +259,7 @@ package android.app { field public static final String OPSTR_ACTIVITY_RECOGNITION_SOURCE = "android:activity_recognition_source"; field public static final String OPSTR_MANAGE_ONGOING_CALLS = "android:manage_ongoing_calls"; field public static final String OPSTR_RECORD_AUDIO_HOTWORD = "android:record_audio_hotword"; + field public static final String OPSTR_RESERVED_FOR_TESTING = "android:reserved_for_testing"; field public static final String OPSTR_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER = "android:use_icc_auth_with_device_identifier"; field public static final int OP_COARSE_LOCATION = 0; // 0x0 field public static final int OP_RECORD_AUDIO = 27; // 0x1b diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 71fe47e7b949..ec43184bd42c 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -16,8 +16,8 @@ package android.app; -import static android.view.contentprotection.flags.Flags.FLAG_CREATE_ACCESSIBILITY_OVERLAY_APP_OP_ENABLED; import static android.permission.flags.Flags.FLAG_OP_ENABLE_MOBILE_DATA_BY_USER; +import static android.view.contentprotection.flags.Flags.FLAG_CREATE_ACCESSIBILITY_OVERLAY_APP_OP_ENABLED; import static java.lang.Long.max; @@ -1521,9 +1521,17 @@ public class AppOpsManager { */ public static final int OP_MEDIA_ROUTING_CONTROL = AppProtoEnums.APP_OP_MEDIA_ROUTING_CONTROL; + /** + * Op code for use by tests to avoid interfering history logs that the wider system might + * trigger. + * + * @hide + */ + public static final int OP_RESERVED_FOR_TESTING = AppProtoEnums.APP_OP_RESERVED_FOR_TESTING; + /** @hide */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) - public static final int _NUM_OP = 141; + public static final int _NUM_OP = 142; /** * All app ops represented as strings. @@ -1671,6 +1679,7 @@ public class AppOpsManager { OPSTR_CREATE_ACCESSIBILITY_OVERLAY, OPSTR_MEDIA_ROUTING_CONTROL, OPSTR_ENABLE_MOBILE_DATA_BY_USER, + OPSTR_RESERVED_FOR_TESTING, }) public @interface AppOpString {} @@ -2330,6 +2339,17 @@ public class AppOpsManager { public static final String OPSTR_ENABLE_MOBILE_DATA_BY_USER = "android:enable_mobile_data_by_user"; + /** + * Reserved for use by appop tests so that operations done legitimately by the platform don't + * interfere with expected results. Platform code should never use this. + * + * @hide + */ + @TestApi + @SuppressLint("UnflaggedApi") + public static final String OPSTR_RESERVED_FOR_TESTING = + "android:reserved_for_testing"; + /** {@link #sAppOpsToNote} not initialized yet for this op */ private static final byte SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED = 0; /** Should not collect noting of this app-op in {@link #sAppOpsToNote} */ @@ -2887,6 +2907,8 @@ public class AppOpsManager { .setPermission(Manifest.permission.MEDIA_ROUTING_CONTROL).build(), new AppOpInfo.Builder(OP_ENABLE_MOBILE_DATA_BY_USER, OPSTR_ENABLE_MOBILE_DATA_BY_USER, "ENABLE_MOBILE_DATA_BY_USER").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(), + new AppOpInfo.Builder(OP_RESERVED_FOR_TESTING, OPSTR_RESERVED_FOR_TESTING, + "OP_RESERVED_FOR_TESTING").setDefaultMode(AppOpsManager.MODE_ALLOWED).build(), }; // The number of longs needed to form a full bitmask of app ops diff --git a/services/core/java/com/android/server/appop/DiscreteRegistry.java b/services/core/java/com/android/server/appop/DiscreteRegistry.java index e91b7e8e37fc..b1a12f7338da 100644 --- a/services/core/java/com/android/server/appop/DiscreteRegistry.java +++ b/services/core/java/com/android/server/appop/DiscreteRegistry.java @@ -37,6 +37,7 @@ import static android.app.AppOpsManager.OP_PHONE_CALL_MICROPHONE; import static android.app.AppOpsManager.OP_RECEIVE_AMBIENT_TRIGGER_AUDIO; import static android.app.AppOpsManager.OP_RECEIVE_SANDBOX_TRIGGER_AUDIO; import static android.app.AppOpsManager.OP_RECORD_AUDIO; +import static android.app.AppOpsManager.OP_RESERVED_FOR_TESTING; import static android.app.AppOpsManager.flagsToString; import static android.app.AppOpsManager.getUidStateName; @@ -136,7 +137,7 @@ final class DiscreteRegistry { private static final String DEFAULT_DISCRETE_OPS = OP_FINE_LOCATION + "," + OP_COARSE_LOCATION + "," + OP_CAMERA + "," + OP_RECORD_AUDIO + "," + OP_PHONE_CALL_MICROPHONE + "," + OP_PHONE_CALL_CAMERA + "," + OP_RECEIVE_AMBIENT_TRIGGER_AUDIO + "," - + OP_RECEIVE_SANDBOX_TRIGGER_AUDIO; + + OP_RECEIVE_SANDBOX_TRIGGER_AUDIO + "," + OP_RESERVED_FOR_TESTING; private static final long DEFAULT_DISCRETE_HISTORY_CUTOFF = Duration.ofDays(7).toMillis(); private static final long MAXIMUM_DISCRETE_HISTORY_CUTOFF = Duration.ofDays(30).toMillis(); private static final long DEFAULT_DISCRETE_HISTORY_QUANTIZATION = |