From cb1bb0f3ee07cd7d94e51ae43d2283c4ebbd2fbc Mon Sep 17 00:00:00 2001 From: Eghosa Ewansiha-Vlachavas Date: Mon, 17 Oct 2022 11:31:30 +0000 Subject: Add forced app standby and app standby exemption app-ops to AppOpsManager Bug: 246330879 Test: atest AppOpsTests Change-Id: Ia1de6dc91c12bdf43d66d9cf4d936dd908bdb962 --- core/java/android/app/AppOpsManager.java | 54 ++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 267e5b699241..dc325ff96de1 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -1368,9 +1368,31 @@ public class AppOpsManager { public static final int OP_READ_MEDIA_VISUAL_USER_SELECTED = AppProtoEnums.APP_OP_READ_MEDIA_VISUAL_USER_SELECTED; + /** + * Prevent an app from being placed into app standby buckets. + * + * Only to be used by the system. + * + * @hide + */ + public static final int OP_SYSTEM_EXEMPT_FROM_APP_STANDBY = + AppProtoEnums.APP_OP_SYSTEM_EXEMPT_FROM_APP_STANDBY; + + /** + * Prevent an app from being placed into forced app standby. + * {@link ActivityManager#isBackgroundRestricted()} + * {@link #OP_RUN_ANY_IN_BACKGROUND} + * + * Only to be used by the system. + * + * @hide + */ + public static final int OP_SYSTEM_EXEMPT_FROM_FORCED_APP_STANDBY = + AppProtoEnums.APP_OP_SYSTEM_EXEMPT_FROM_FORCED_APP_STANDBY; + /** @hide */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) - public static final int _NUM_OP = 124; + public static final int _NUM_OP = 126; /** Access to coarse location information. */ public static final String OPSTR_COARSE_LOCATION = "android:coarse_location"; @@ -1869,6 +1891,28 @@ public class AppOpsManager { */ public static final String OPSTR_RUN_LONG_JOBS = "android:run_long_jobs"; + /** + * Prevent an app from being placed into app standby buckets. + * + * Only to be used by the system. + * + * @hide + */ + public static final String OPSTR_SYSTEM_EXEMPT_FROM_APP_STANDBY = + "android:system_exempt_from_app_standby"; + + /** + * Prevent an app from being placed into forced app standby. + * {@link ActivityManager#isBackgroundRestricted()} + * {@link #OP_RUN_ANY_IN_BACKGROUND} + * + * Only to be used by the system. + * + * @hide + */ + public static final String OPSTR_SYSTEM_EXEMPT_FROM_FORCED_APP_STANDBY = + "android:system_exempt_from_forced_app_standby"; + /** {@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} */ @@ -2350,7 +2394,13 @@ public class AppOpsManager { new AppOpInfo.Builder(OP_READ_MEDIA_VISUAL_USER_SELECTED, OPSTR_READ_MEDIA_VISUAL_USER_SELECTED, "READ_MEDIA_VISUAL_USER_SELECTED") .setPermission(Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED) - .setDefaultMode(AppOpsManager.MODE_ALLOWED).build() + .setDefaultMode(AppOpsManager.MODE_ALLOWED).build(), + new AppOpInfo.Builder(OP_SYSTEM_EXEMPT_FROM_APP_STANDBY, + OPSTR_SYSTEM_EXEMPT_FROM_APP_STANDBY, + "SYSTEM_EXEMPT_FROM_APP_STANDBY").build(), + new AppOpInfo.Builder(OP_SYSTEM_EXEMPT_FROM_FORCED_APP_STANDBY, + OPSTR_SYSTEM_EXEMPT_FROM_FORCED_APP_STANDBY, + "SYSTEM_EXEMPT_FROM_FORCED_APP_STANDBY").build() }; /** -- cgit v1.2.3-59-g8ed1b