From e0097f5092f76521e99fd9a69489bb4a610102eb Mon Sep 17 00:00:00 2001 From: Ilyas Sung Date: Wed, 8 Feb 2023 16:48:58 +0000 Subject: [PATCH] Add exemption that prevents apps from being placed in hibernation Bug: 246330879 Test: atest AppOpsTests Change-Id: I61d1a7b092b9b0a41c60ca6ef14aad48122f9221 --- core/api/system-current.txt | 1 + core/java/android/app/AppOpsManager.java | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 489b1eed77ffb..dfd7f8fcb30ee 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -623,6 +623,7 @@ package android.app { field public static final String OPSTR_RUN_ANY_IN_BACKGROUND = "android:run_any_in_background"; field public static final String OPSTR_RUN_IN_BACKGROUND = "android:run_in_background"; field public static final String OPSTR_START_FOREGROUND = "android:start_foreground"; + field public static final String OPSTR_SYSTEM_EXEMPT_FROM_HIBERNATION = "android:system_exempt_from_hibernation"; field public static final String OPSTR_TAKE_AUDIO_FOCUS = "android:take_audio_focus"; field public static final String OPSTR_TAKE_MEDIA_BUTTONS = "android:take_media_buttons"; field public static final String OPSTR_TOAST_WINDOW = "android:toast_window"; diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 7d40a2299a802..dd717bddb7bfb 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -1461,9 +1461,17 @@ public class AppOpsManager { */ public static final int OP_USE_FULL_SCREEN_INTENT = AppProtoEnums.APP_OP_USE_FULL_SCREEN_INTENT; + /** + * Prevent an app from being placed into hibernation. + * + * @hide + */ + public static final int OP_SYSTEM_EXEMPT_FROM_HIBERNATION = + AppProtoEnums.APP_OP_SYSTEM_EXEMPT_FROM_HIBERNATION; + /** @hide */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) - public static final int _NUM_OP = 134; + public static final int _NUM_OP = 135; /** Access to coarse location information. */ public static final String OPSTR_COARSE_LOCATION = "android:coarse_location"; @@ -2057,6 +2065,15 @@ public class AppOpsManager { */ public static final String OPSTR_USE_FULL_SCREEN_INTENT = "android:use_full_screen_intent"; + /** + * Prevent an app from being placed into hibernation. + * + * @hide + */ + @SystemApi + public static final String OPSTR_SYSTEM_EXEMPT_FROM_HIBERNATION = + "android:system_exempt_from_hibernation"; + /** {@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} */ @@ -2578,7 +2595,10 @@ public class AppOpsManager { .setDefaultMode(AppOpsManager.MODE_ALLOWED).build(), new AppOpInfo.Builder(OP_USE_FULL_SCREEN_INTENT, OPSTR_USE_FULL_SCREEN_INTENT, "USE_FULL_SCREEN_INTENT").setPermission(Manifest.permission.USE_FULL_SCREEN_INTENT) - .build() + .build(), + new AppOpInfo.Builder(OP_SYSTEM_EXEMPT_FROM_HIBERNATION, + OPSTR_SYSTEM_EXEMPT_FROM_HIBERNATION, + "SYSTEM_EXEMPT_FROM_HIBERNATION").build() }; // The number of longs needed to form a full bitmask of app ops