From e8dd3f50bd9ca6fbb8528fbfcc08cc026609cf50 Mon Sep 17 00:00:00 2001 From: Alex Johnston Date: Wed, 25 Jan 2023 13:15:01 +0000 Subject: [PATCH] Add system exemption for power restrictions * Introduce the appop OP_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS. * An app with this appop will be made exempt from all power restrictions, including app standby and doze. * In addition, the app will be able to start fgs from the bg, and the user will not be able to stop fgs run by the app. * This new appop is replacing an appop in Android U that was unused. Bug: 246330879 Test: atest AppOpsTests Change-Id: I9ecdb529f4342e676d2a9587637e9efdd59059d6 --- core/java/android/app/AppOpsManager.java | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java index 84320caf4abc0..1eaf9009b5f62 100644 --- a/core/java/android/app/AppOpsManager.java +++ b/core/java/android/app/AppOpsManager.java @@ -1408,14 +1408,16 @@ public class AppOpsManager { AppProtoEnums.APP_OP_FOREGROUND_SERVICE_SPECIAL_USE; /** - * Exempt from start foreground service from background restriction. + * Exempt an app from all power-related restrictions, including app standby and doze. + * In addition, the app will be able to start foreground services from the background, and the + * user will not be able to stop foreground services run by the app. * * Only to be used by the system. * * @hide */ - public static final int OP_SYSTEM_EXEMPT_FROM_FGS_BG_START_RESTRICTION = - AppProtoEnums.APP_OP_SYSTEM_EXEMPT_FROM_FGS_BG_START_RESTRICTION; + public static final int OP_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS = + AppProtoEnums.APP_OP_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS; /** * Exempt from start foreground service from background with while in user permission @@ -1989,14 +1991,16 @@ public class AppOpsManager { "android:foreground_service_special_use"; /** - * Exempt from start foreground service from background restriction. + * Exempt an app from all power-related restrictions, including app standby and doze. + * In addition, the app will be able to start foreground services from the background, and the + * user will not be able to stop foreground services run by the app. * * Only to be used by the system. * * @hide */ - public static final String OPSTR_SYSTEM_EXEMPT_FROM_FGS_BG_START_RESTRICTION = - "android:system_exempt_from_fgs_bg_start_restriction"; + public static final String OPSTR_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS = + "android:system_exempt_from_power_restrictions"; /** * Exempt from start foreground service from background with while in user permission @@ -2525,9 +2529,9 @@ public class AppOpsManager { new AppOpInfo.Builder(OP_FOREGROUND_SERVICE_SPECIAL_USE, OPSTR_FOREGROUND_SERVICE_SPECIAL_USE, "FOREGROUND_SERVICE_SPECIAL_USE") .setPermission(Manifest.permission.FOREGROUND_SERVICE_SPECIAL_USE).build(), - new AppOpInfo.Builder(OP_SYSTEM_EXEMPT_FROM_FGS_BG_START_RESTRICTION, - OPSTR_SYSTEM_EXEMPT_FROM_FGS_BG_START_RESTRICTION, - "SYSTEM_EXEMPT_FROM_FGS_BG_START_RESTRICTION").build(), + new AppOpInfo.Builder(OP_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS, + OPSTR_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS, + "SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS").build(), new AppOpInfo.Builder( OP_SYSTEM_EXEMPT_FROM_FGS_BG_START_WHILE_IN_USE_PERMISSION_RESTRICTION, OPSTR_SYSTEM_EXEMPT_FROM_FGS_BG_START_WHILE_IN_USE_PERMISSION_RESTRICTION,