Loading apex/jobscheduler/framework/java/android/os/IDeviceIdleController.aidl +4 −4 Original line number Diff line number Diff line Loading @@ -43,10 +43,10 @@ interface IDeviceIdleController { boolean isPowerSaveWhitelistApp(String name); @UnsupportedAppUsage(maxTargetSdk = 30, publicAlternatives = "Use SystemApi {@code PowerWhitelistManager#whitelistAppTemporarily(String, int, String)}.") void addPowerSaveTempWhitelistApp(String name, long duration, int userId, String reason); long addPowerSaveTempWhitelistAppForMms(String name, int userId, String reason); long addPowerSaveTempWhitelistAppForSms(String name, int userId, String reason); long whitelistAppTemporarily(String name, int userId, String reason); void addPowerSaveTempWhitelistApp(String name, long duration, int userId, int reasonCode, String reason); long addPowerSaveTempWhitelistAppForMms(String name, int userId, int reasonCode, String reason); long addPowerSaveTempWhitelistAppForSms(String name, int userId, int reasonCode, String reason); long whitelistAppTemporarily(String name, int userId, int reasonCode, String reason); void exitIdle(String reason); int setPreIdleTimeoutMode(int Mode); void resetPreIdleTimeoutMode(); Loading apex/jobscheduler/framework/java/android/os/PowerWhitelistManager.java +416 −8 Original line number Diff line number Diff line Loading @@ -16,8 +16,16 @@ package android.os; import static android.app.ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE; import static android.app.ActivityManager.PROCESS_STATE_BOUND_TOP; import static android.app.ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE; import static android.app.ActivityManager.PROCESS_STATE_PERSISTENT; import static android.app.ActivityManager.PROCESS_STATE_PERSISTENT_UI; import static android.app.ActivityManager.PROCESS_STATE_TOP; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SystemApi; import android.annotation.SystemService; Loading Loading @@ -94,6 +102,239 @@ public class PowerWhitelistManager { @Retention(RetentionPolicy.SOURCE) public @interface TempAllowListType {} /* Reason code for BG-FGS-launch. */ /** * BG-FGS-launch is denied. * @hide */ public static final int REASON_DENIED = -1; /** * The default reason code if reason is unknown. */ public static final int REASON_UNKNOWN = 0; /** * Use REASON_OTHER if there is no better choice. */ public static final int REASON_OTHER = 1; /** @hide */ public static final int REASON_PROC_STATE_PERSISTENT = 10; /** @hide */ public static final int REASON_PROC_STATE_PERSISTENT_UI = 11; /** @hide */ public static final int REASON_PROC_STATE_TOP = 12; /** @hide */ public static final int REASON_PROC_STATE_BTOP = 13; /** @hide */ public static final int REASON_PROC_STATE_FGS = 14; /** @hide */ public static final int REASON_PROC_STATE_BFGS = 15; /** @hide */ public static final int REASON_UID_VISIBLE = 50; /** @hide */ public static final int REASON_SYSTEM_UID = 51; /** @hide */ public static final int REASON_ACTIVITY_STARTER = 52; /** @hide */ public static final int REASON_START_ACTIVITY_FLAG = 53; /** @hide */ public static final int REASON_FGS_BINDING = 54; /** @hide */ public static final int REASON_DEVICE_OWNER = 55; /** @hide */ public static final int REASON_PROFILE_OWNER = 56; /** @hide */ public static final int REASON_COMPANION_DEVICE_MANAGER = 57; /** * START_ACTIVITIES_FROM_BACKGROUND permission. * @hide */ public static final int REASON_BACKGROUND_ACTIVITY_PERMISSION = 58; /** * START_FOREGROUND_SERVICES_FROM_BACKGROUND permission. * @hide */ public static final int REASON_BACKGROUND_FGS_PERMISSION = 59; /** @hide */ public static final int REASON_INSTR_BACKGROUND_ACTIVITY_PERMISSION = 60; /** @hide */ public static final int REASON_INSTR_BACKGROUND_FGS_PERMISSION = 61; /** @hide */ public static final int REASON_SYSTEM_ALERT_WINDOW_PERMISSION = 62; /** @hide */ public static final int REASON_DEVICE_DEMO_MODE = 63; /** @hide */ public static final int REASON_EXEMPTED_PACKAGE = 64; /** @hide */ public static final int REASON_ALLOWLISTED_PACKAGE = 65; /** * If it's because of a role, * @hide */ public static final int REASON_APPOP = 66; /* BG-FGS-launch is allowed by temp-allowlist or system-allowlist. Reason code for temp and system allowlist starts here. */ public static final int REASON_GEOFENCING = 100; public static final int REASON_PUSH_MESSAGING = 101; public static final int REASON_ACTIVITY_RECOGNITION = 102; /** * Broadcast ACTION_BOOT_COMPLETED. * @hide */ public static final int REASON_BOOT_COMPLETED = 103; /** * Broadcast ACTION_PRE_BOOT_COMPLETED. * @hide */ public static final int REASON_PRE_BOOT_COMPLETED = 104; /** * Broadcast ACTION_LOCKED_BOOT_COMPLETED. * @hide */ public static final int REASON_LOCKED_BOOT_COMPLETED = 105; /** * Device idle system allowlist, including EXCEPT-IDLE * @hide */ public static final int REASON_SYSTEM_ALLOW_LISTED = 106; /** @hide */ public static final int REASON_ALARM_MANAGER_ALARM_CLOCK = 107; /** * AlarmManagerService. * @hide */ public static final int REASON_ALARM_MANAGER_WHILE_IDLE = 108; /** * ActiveServices. * @hide */ public static final int REASON_SERVICE_LAUNCH = 109; /** * KeyChainSystemService. * @hide */ public static final int REASON_KEY_CHAIN = 110; /** * PackageManagerService. * @hide */ public static final int REASON_PACKAGE_VERIFIER = 111; /** * SyncManager. * @hide */ public static final int REASON_SYNC_MANAGER = 112; /** * DomainVerificationProxyV1. * @hide */ public static final int REASON_DOMAIN_VERIFICATION_V1 = 113; /** * DomainVerificationProxyV2. * @hide */ public static final int REASON_DOMAIN_VERIFICATION_V2 = 114; /** @hide */ public static final int REASON_VPN = 115; /** * NotificationManagerService. * @hide */ public static final int REASON_NOTIFICATION_SERVICE = 116; /** * Broadcast ACTION_MY_PACKAGE_REPLACED. * @hide */ public static final int REASON_PACKAGE_REPLACED = 117; /** * LocationProviderManager. * @hide */ public static final int REASON_LOCATION_PROVIDER = 118; /** * MediaButtonReceiver. * @hide */ public static final int REASON_MEDIA_BUTTON = 119; /** * InboundSmsHandler. * @hide */ public static final int REASON_EVENT_SMS = 120; /** * InboundSmsHandler. * @hide */ public static final int REASON_EVENT_MMS = 121; /** * Shell app. * @hide */ public static final int REASON_SHELL = 122; /** * The list of BG-FGS-Launch and temp-allowlist reason code. * @hide */ @IntDef(flag = true, prefix = { "REASON_" }, value = { // BG-FGS-Launch reasons. REASON_DENIED, REASON_UNKNOWN, REASON_OTHER, REASON_PROC_STATE_PERSISTENT, REASON_PROC_STATE_PERSISTENT_UI, REASON_PROC_STATE_TOP, REASON_PROC_STATE_BTOP, REASON_PROC_STATE_FGS, REASON_PROC_STATE_BFGS, REASON_UID_VISIBLE, REASON_SYSTEM_UID, REASON_ACTIVITY_STARTER, REASON_START_ACTIVITY_FLAG, REASON_FGS_BINDING, REASON_DEVICE_OWNER, REASON_PROFILE_OWNER, REASON_COMPANION_DEVICE_MANAGER, REASON_BACKGROUND_ACTIVITY_PERMISSION, REASON_BACKGROUND_FGS_PERMISSION, REASON_INSTR_BACKGROUND_ACTIVITY_PERMISSION, REASON_INSTR_BACKGROUND_FGS_PERMISSION, REASON_SYSTEM_ALERT_WINDOW_PERMISSION, REASON_DEVICE_DEMO_MODE, REASON_EXEMPTED_PACKAGE, REASON_ALLOWLISTED_PACKAGE, REASON_APPOP, // temp and system allowlist reasons. REASON_GEOFENCING, REASON_PUSH_MESSAGING, REASON_ACTIVITY_RECOGNITION, REASON_BOOT_COMPLETED, REASON_PRE_BOOT_COMPLETED, REASON_LOCKED_BOOT_COMPLETED, REASON_SYSTEM_ALLOW_LISTED, REASON_ALARM_MANAGER_ALARM_CLOCK, REASON_ALARM_MANAGER_WHILE_IDLE, REASON_SERVICE_LAUNCH, REASON_KEY_CHAIN, REASON_PACKAGE_VERIFIER, REASON_SYNC_MANAGER, REASON_DOMAIN_VERIFICATION_V1, REASON_DOMAIN_VERIFICATION_V2, REASON_VPN, REASON_NOTIFICATION_SERVICE, REASON_PACKAGE_REPLACED, REASON_LOCATION_PROVIDER, REASON_MEDIA_BUTTON, REASON_EVENT_SMS, REASON_EVENT_MMS, REASON_SHELL, }) @Retention(RetentionPolicy.SOURCE) public @interface ReasonCode {} /** * @hide */ Loading Loading @@ -184,18 +425,52 @@ public class PowerWhitelistManager { * * @param packageName The package to add to the temp whitelist * @param durationMs How long to keep the app on the temp whitelist for (in milliseconds) * @param reasonCode one of {@link ReasonCode}, use {@link #REASON_UNKNOWN} if not sure. * @param reason a optional human readable reason string, could be null or empty string. */ @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST) public void whitelistAppTemporarily(@NonNull String packageName, long durationMs) { String reason = "from:" + UserHandle.formatUid(Binder.getCallingUid()); public void whitelistAppTemporarily(@NonNull String packageName, long durationMs, @ReasonCode int reasonCode, @Nullable String reason) { try { mService.addPowerSaveTempWhitelistApp(packageName, durationMs, mContext.getUserId(), reason); reasonCode, reason); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Add an app to the temporary whitelist for a short amount of time. * * @param packageName The package to add to the temp whitelist * @param durationMs How long to keep the app on the temp whitelist for (in milliseconds) * @deprecated Use {@link #whitelistAppTemporarily(String, long, int, String)} instead */ @Deprecated @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST) public void whitelistAppTemporarily(@NonNull String packageName, long durationMs) { whitelistAppTemporarily(packageName, durationMs, REASON_UNKNOWN, packageName); } /** * Add an app to the temporary whitelist for a short amount of time for a specific reason. The * temporary whitelist is kept separately from the permanent whitelist and apps are * automatically removed from the temporary whitelist after a predetermined amount of time. * * @param packageName The package to add to the temp whitelist * @param event The reason to add the app to the temp whitelist * @param reason A human-readable reason explaining why the app is temp whitelisted. Only * used for logging purposes. Could be null or empty string. * @return The duration (in milliseconds) that the app is whitelisted for * @deprecated Use {@link #whitelistAppTemporarilyForEvent(String, int, int, String)} instead */ @Deprecated @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST) public long whitelistAppTemporarilyForEvent(@NonNull String packageName, @WhitelistEvent int event, @Nullable String reason) { return whitelistAppTemporarilyForEvent(packageName, event, REASON_UNKNOWN, reason); } /** * Add an app to the temporary whitelist for a short amount of time for a specific reason. The * temporary whitelist is kept separately from the permanent whitelist and apps are Loading @@ -203,28 +478,161 @@ public class PowerWhitelistManager { * * @param packageName The package to add to the temp whitelist * @param event The reason to add the app to the temp whitelist * @param reasonCode one of {@link ReasonCode}, use {@link #REASON_UNKNOWN} if not sure. * @param reason A human-readable reason explaining why the app is temp whitelisted. Only * used for logging purposes * used for logging purposes. Could be null or empty string. * @return The duration (in milliseconds) that the app is whitelisted for */ @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST) public long whitelistAppTemporarilyForEvent(@NonNull String packageName, @WhitelistEvent int event, @NonNull String reason) { @WhitelistEvent int event, @ReasonCode int reasonCode, @Nullable String reason) { try { switch (event) { case EVENT_MMS: return mService.addPowerSaveTempWhitelistAppForMms( packageName, mContext.getUserId(), reason); packageName, mContext.getUserId(), reasonCode, reason); case EVENT_SMS: return mService.addPowerSaveTempWhitelistAppForSms( packageName, mContext.getUserId(), reason); packageName, mContext.getUserId(), reasonCode, reason); case EVENT_UNSPECIFIED: default: return mService.whitelistAppTemporarily( packageName, mContext.getUserId(), reason); packageName, mContext.getUserId(), reasonCode, reason); } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * @hide */ public static @ReasonCode int getReasonCodeFromProcState(int procState) { if (procState <= PROCESS_STATE_PERSISTENT) { return REASON_PROC_STATE_PERSISTENT; } else if (procState <= PROCESS_STATE_PERSISTENT_UI) { return REASON_PROC_STATE_PERSISTENT_UI; } else if (procState <= PROCESS_STATE_TOP) { return REASON_PROC_STATE_TOP; } else if (procState <= PROCESS_STATE_BOUND_TOP) { return REASON_PROC_STATE_BTOP; } else if (procState <= PROCESS_STATE_FOREGROUND_SERVICE) { return REASON_PROC_STATE_FGS; } else if (procState <= PROCESS_STATE_BOUND_FOREGROUND_SERVICE) { return REASON_PROC_STATE_BFGS; } else { return REASON_DENIED; } } /** * Return string name of the integer reason code. * @hide * @param reasonCode * @return string name of the reason code. */ public static String reasonCodeToString(@ReasonCode int reasonCode) { switch (reasonCode) { case REASON_DENIED: return "DENIED"; case REASON_UNKNOWN: return "UNKNOWN"; case REASON_OTHER: return "OTHER"; case REASON_PROC_STATE_PERSISTENT: return "PROC_STATE_PERSISTENT"; case REASON_PROC_STATE_PERSISTENT_UI: return "PROC_STATE_PERSISTENT_UI"; case REASON_PROC_STATE_TOP: return "PROC_STATE_TOP"; case REASON_PROC_STATE_BTOP: return "PROC_STATE_BTOP"; case REASON_PROC_STATE_FGS: return "PROC_STATE_FGS"; case REASON_PROC_STATE_BFGS: return "PROC_STATE_BFGS"; case REASON_UID_VISIBLE: return "UID_VISIBLE"; case REASON_SYSTEM_UID: return "SYSTEM_UID"; case REASON_ACTIVITY_STARTER: return "ACTIVITY_STARTER"; case REASON_START_ACTIVITY_FLAG: return "START_ACTIVITY_FLAG"; case REASON_FGS_BINDING: return "FGS_BINDING"; case REASON_DEVICE_OWNER: return "DEVICE_OWNER"; case REASON_PROFILE_OWNER: return "PROFILE_OWNER"; case REASON_COMPANION_DEVICE_MANAGER: return "COMPANION_DEVICE_MANAGER"; case REASON_BACKGROUND_ACTIVITY_PERMISSION: return "BACKGROUND_ACTIVITY_PERMISSION"; case REASON_BACKGROUND_FGS_PERMISSION: return "BACKGROUND_FGS_PERMISSION"; case REASON_INSTR_BACKGROUND_ACTIVITY_PERMISSION: return "INSTR_BACKGROUND_ACTIVITY_PERMISSION"; case REASON_INSTR_BACKGROUND_FGS_PERMISSION: return "INSTR_BACKGROUND_FGS_PERMISSION"; case REASON_SYSTEM_ALERT_WINDOW_PERMISSION: return "SYSTEM_ALERT_WINDOW_PERMISSION"; case REASON_DEVICE_DEMO_MODE: return "DEVICE_DEMO_MODE"; case REASON_EXEMPTED_PACKAGE: return "EXEMPTED_PACKAGE"; case REASON_ALLOWLISTED_PACKAGE: return "ALLOWLISTED_PACKAGE"; case REASON_APPOP: return "APPOP"; case REASON_GEOFENCING: return "GEOFENCING"; case REASON_PUSH_MESSAGING: return "PUSH_MESSAGING"; case REASON_ACTIVITY_RECOGNITION: return "ACTIVITY_RECOGNITION"; case REASON_BOOT_COMPLETED: return "BOOT_COMPLETED"; case REASON_PRE_BOOT_COMPLETED: return "PRE_BOOT_COMPLETED"; case REASON_LOCKED_BOOT_COMPLETED: return "LOCKED_BOOT_COMPLETED"; case REASON_SYSTEM_ALLOW_LISTED: return "SYSTEM_ALLOW_LISTED"; case REASON_ALARM_MANAGER_ALARM_CLOCK: return "ALARM_MANAGER_ALARM_CLOCK"; case REASON_ALARM_MANAGER_WHILE_IDLE: return "ALARM_MANAGER_WHILE_IDLE"; case REASON_SERVICE_LAUNCH: return "SERVICE_LAUNCH"; case REASON_KEY_CHAIN: return "KEY_CHAIN"; case REASON_PACKAGE_VERIFIER: return "PACKAGE_VERIFIER"; case REASON_SYNC_MANAGER: return "SYNC_MANAGER"; case REASON_DOMAIN_VERIFICATION_V1: return "DOMAIN_VERIFICATION_V1"; case REASON_DOMAIN_VERIFICATION_V2: return "DOMAIN_VERIFICATION_V2"; case REASON_VPN: return "VPN"; case REASON_NOTIFICATION_SERVICE: return "NOTIFICATION_SERVICE"; case REASON_PACKAGE_REPLACED: return "PACKAGE_REPLACED"; case REASON_LOCATION_PROVIDER: return "LOCATION_PROVIDER"; case REASON_MEDIA_BUTTON: return "MEDIA_BUTTON"; case REASON_EVENT_SMS: return "EVENT_SMS"; case REASON_EVENT_MMS: return "EVENT_MMS"; case REASON_SHELL: return "SHELL"; default: return "(unknown:" + reasonCode + ")"; } } } apex/jobscheduler/framework/java/com/android/server/DeviceIdleInternal.java +9 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server; import android.annotation.Nullable; import android.os.PowerWhitelistManager.ReasonCode; import android.os.PowerWhitelistManager.TempAllowListType; import com.android.server.deviceidle.IDeviceIdleConstraint; Loading @@ -34,6 +36,10 @@ public interface DeviceIdleInternal { void addPowerSaveTempWhitelistApp(int callingUid, String packageName, long duration, int userId, boolean sync, String reason); void addPowerSaveTempWhitelistApp(int callingUid, String packageName, long duration, int userId, boolean sync, @ReasonCode int reasonCode, @Nullable String reason); /** * Called by ActivityManagerService to directly add UID to DeviceIdleController's temp * allowlist. Loading @@ -41,11 +47,12 @@ public interface DeviceIdleInternal { * @param duration duration in milliseconds * @param type temp allowlist type defined at {@link TempAllowListType} * @param sync * @param reasonCode one of {@link ReasonCode} * @param reason */ void addPowerSaveTempWhitelistAppDirect(int uid, long duration, @TempAllowListType int type, boolean sync, String reason); @TempAllowListType int type, boolean sync, @ReasonCode int reasonCode, @Nullable String reason); // duration in milliseconds long getNotificationAllowlistDuration(); Loading Loading
apex/jobscheduler/framework/java/android/os/IDeviceIdleController.aidl +4 −4 Original line number Diff line number Diff line Loading @@ -43,10 +43,10 @@ interface IDeviceIdleController { boolean isPowerSaveWhitelistApp(String name); @UnsupportedAppUsage(maxTargetSdk = 30, publicAlternatives = "Use SystemApi {@code PowerWhitelistManager#whitelistAppTemporarily(String, int, String)}.") void addPowerSaveTempWhitelistApp(String name, long duration, int userId, String reason); long addPowerSaveTempWhitelistAppForMms(String name, int userId, String reason); long addPowerSaveTempWhitelistAppForSms(String name, int userId, String reason); long whitelistAppTemporarily(String name, int userId, String reason); void addPowerSaveTempWhitelistApp(String name, long duration, int userId, int reasonCode, String reason); long addPowerSaveTempWhitelistAppForMms(String name, int userId, int reasonCode, String reason); long addPowerSaveTempWhitelistAppForSms(String name, int userId, int reasonCode, String reason); long whitelistAppTemporarily(String name, int userId, int reasonCode, String reason); void exitIdle(String reason); int setPreIdleTimeoutMode(int Mode); void resetPreIdleTimeoutMode(); Loading
apex/jobscheduler/framework/java/android/os/PowerWhitelistManager.java +416 −8 Original line number Diff line number Diff line Loading @@ -16,8 +16,16 @@ package android.os; import static android.app.ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE; import static android.app.ActivityManager.PROCESS_STATE_BOUND_TOP; import static android.app.ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE; import static android.app.ActivityManager.PROCESS_STATE_PERSISTENT; import static android.app.ActivityManager.PROCESS_STATE_PERSISTENT_UI; import static android.app.ActivityManager.PROCESS_STATE_TOP; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SystemApi; import android.annotation.SystemService; Loading Loading @@ -94,6 +102,239 @@ public class PowerWhitelistManager { @Retention(RetentionPolicy.SOURCE) public @interface TempAllowListType {} /* Reason code for BG-FGS-launch. */ /** * BG-FGS-launch is denied. * @hide */ public static final int REASON_DENIED = -1; /** * The default reason code if reason is unknown. */ public static final int REASON_UNKNOWN = 0; /** * Use REASON_OTHER if there is no better choice. */ public static final int REASON_OTHER = 1; /** @hide */ public static final int REASON_PROC_STATE_PERSISTENT = 10; /** @hide */ public static final int REASON_PROC_STATE_PERSISTENT_UI = 11; /** @hide */ public static final int REASON_PROC_STATE_TOP = 12; /** @hide */ public static final int REASON_PROC_STATE_BTOP = 13; /** @hide */ public static final int REASON_PROC_STATE_FGS = 14; /** @hide */ public static final int REASON_PROC_STATE_BFGS = 15; /** @hide */ public static final int REASON_UID_VISIBLE = 50; /** @hide */ public static final int REASON_SYSTEM_UID = 51; /** @hide */ public static final int REASON_ACTIVITY_STARTER = 52; /** @hide */ public static final int REASON_START_ACTIVITY_FLAG = 53; /** @hide */ public static final int REASON_FGS_BINDING = 54; /** @hide */ public static final int REASON_DEVICE_OWNER = 55; /** @hide */ public static final int REASON_PROFILE_OWNER = 56; /** @hide */ public static final int REASON_COMPANION_DEVICE_MANAGER = 57; /** * START_ACTIVITIES_FROM_BACKGROUND permission. * @hide */ public static final int REASON_BACKGROUND_ACTIVITY_PERMISSION = 58; /** * START_FOREGROUND_SERVICES_FROM_BACKGROUND permission. * @hide */ public static final int REASON_BACKGROUND_FGS_PERMISSION = 59; /** @hide */ public static final int REASON_INSTR_BACKGROUND_ACTIVITY_PERMISSION = 60; /** @hide */ public static final int REASON_INSTR_BACKGROUND_FGS_PERMISSION = 61; /** @hide */ public static final int REASON_SYSTEM_ALERT_WINDOW_PERMISSION = 62; /** @hide */ public static final int REASON_DEVICE_DEMO_MODE = 63; /** @hide */ public static final int REASON_EXEMPTED_PACKAGE = 64; /** @hide */ public static final int REASON_ALLOWLISTED_PACKAGE = 65; /** * If it's because of a role, * @hide */ public static final int REASON_APPOP = 66; /* BG-FGS-launch is allowed by temp-allowlist or system-allowlist. Reason code for temp and system allowlist starts here. */ public static final int REASON_GEOFENCING = 100; public static final int REASON_PUSH_MESSAGING = 101; public static final int REASON_ACTIVITY_RECOGNITION = 102; /** * Broadcast ACTION_BOOT_COMPLETED. * @hide */ public static final int REASON_BOOT_COMPLETED = 103; /** * Broadcast ACTION_PRE_BOOT_COMPLETED. * @hide */ public static final int REASON_PRE_BOOT_COMPLETED = 104; /** * Broadcast ACTION_LOCKED_BOOT_COMPLETED. * @hide */ public static final int REASON_LOCKED_BOOT_COMPLETED = 105; /** * Device idle system allowlist, including EXCEPT-IDLE * @hide */ public static final int REASON_SYSTEM_ALLOW_LISTED = 106; /** @hide */ public static final int REASON_ALARM_MANAGER_ALARM_CLOCK = 107; /** * AlarmManagerService. * @hide */ public static final int REASON_ALARM_MANAGER_WHILE_IDLE = 108; /** * ActiveServices. * @hide */ public static final int REASON_SERVICE_LAUNCH = 109; /** * KeyChainSystemService. * @hide */ public static final int REASON_KEY_CHAIN = 110; /** * PackageManagerService. * @hide */ public static final int REASON_PACKAGE_VERIFIER = 111; /** * SyncManager. * @hide */ public static final int REASON_SYNC_MANAGER = 112; /** * DomainVerificationProxyV1. * @hide */ public static final int REASON_DOMAIN_VERIFICATION_V1 = 113; /** * DomainVerificationProxyV2. * @hide */ public static final int REASON_DOMAIN_VERIFICATION_V2 = 114; /** @hide */ public static final int REASON_VPN = 115; /** * NotificationManagerService. * @hide */ public static final int REASON_NOTIFICATION_SERVICE = 116; /** * Broadcast ACTION_MY_PACKAGE_REPLACED. * @hide */ public static final int REASON_PACKAGE_REPLACED = 117; /** * LocationProviderManager. * @hide */ public static final int REASON_LOCATION_PROVIDER = 118; /** * MediaButtonReceiver. * @hide */ public static final int REASON_MEDIA_BUTTON = 119; /** * InboundSmsHandler. * @hide */ public static final int REASON_EVENT_SMS = 120; /** * InboundSmsHandler. * @hide */ public static final int REASON_EVENT_MMS = 121; /** * Shell app. * @hide */ public static final int REASON_SHELL = 122; /** * The list of BG-FGS-Launch and temp-allowlist reason code. * @hide */ @IntDef(flag = true, prefix = { "REASON_" }, value = { // BG-FGS-Launch reasons. REASON_DENIED, REASON_UNKNOWN, REASON_OTHER, REASON_PROC_STATE_PERSISTENT, REASON_PROC_STATE_PERSISTENT_UI, REASON_PROC_STATE_TOP, REASON_PROC_STATE_BTOP, REASON_PROC_STATE_FGS, REASON_PROC_STATE_BFGS, REASON_UID_VISIBLE, REASON_SYSTEM_UID, REASON_ACTIVITY_STARTER, REASON_START_ACTIVITY_FLAG, REASON_FGS_BINDING, REASON_DEVICE_OWNER, REASON_PROFILE_OWNER, REASON_COMPANION_DEVICE_MANAGER, REASON_BACKGROUND_ACTIVITY_PERMISSION, REASON_BACKGROUND_FGS_PERMISSION, REASON_INSTR_BACKGROUND_ACTIVITY_PERMISSION, REASON_INSTR_BACKGROUND_FGS_PERMISSION, REASON_SYSTEM_ALERT_WINDOW_PERMISSION, REASON_DEVICE_DEMO_MODE, REASON_EXEMPTED_PACKAGE, REASON_ALLOWLISTED_PACKAGE, REASON_APPOP, // temp and system allowlist reasons. REASON_GEOFENCING, REASON_PUSH_MESSAGING, REASON_ACTIVITY_RECOGNITION, REASON_BOOT_COMPLETED, REASON_PRE_BOOT_COMPLETED, REASON_LOCKED_BOOT_COMPLETED, REASON_SYSTEM_ALLOW_LISTED, REASON_ALARM_MANAGER_ALARM_CLOCK, REASON_ALARM_MANAGER_WHILE_IDLE, REASON_SERVICE_LAUNCH, REASON_KEY_CHAIN, REASON_PACKAGE_VERIFIER, REASON_SYNC_MANAGER, REASON_DOMAIN_VERIFICATION_V1, REASON_DOMAIN_VERIFICATION_V2, REASON_VPN, REASON_NOTIFICATION_SERVICE, REASON_PACKAGE_REPLACED, REASON_LOCATION_PROVIDER, REASON_MEDIA_BUTTON, REASON_EVENT_SMS, REASON_EVENT_MMS, REASON_SHELL, }) @Retention(RetentionPolicy.SOURCE) public @interface ReasonCode {} /** * @hide */ Loading Loading @@ -184,18 +425,52 @@ public class PowerWhitelistManager { * * @param packageName The package to add to the temp whitelist * @param durationMs How long to keep the app on the temp whitelist for (in milliseconds) * @param reasonCode one of {@link ReasonCode}, use {@link #REASON_UNKNOWN} if not sure. * @param reason a optional human readable reason string, could be null or empty string. */ @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST) public void whitelistAppTemporarily(@NonNull String packageName, long durationMs) { String reason = "from:" + UserHandle.formatUid(Binder.getCallingUid()); public void whitelistAppTemporarily(@NonNull String packageName, long durationMs, @ReasonCode int reasonCode, @Nullable String reason) { try { mService.addPowerSaveTempWhitelistApp(packageName, durationMs, mContext.getUserId(), reason); reasonCode, reason); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * Add an app to the temporary whitelist for a short amount of time. * * @param packageName The package to add to the temp whitelist * @param durationMs How long to keep the app on the temp whitelist for (in milliseconds) * @deprecated Use {@link #whitelistAppTemporarily(String, long, int, String)} instead */ @Deprecated @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST) public void whitelistAppTemporarily(@NonNull String packageName, long durationMs) { whitelistAppTemporarily(packageName, durationMs, REASON_UNKNOWN, packageName); } /** * Add an app to the temporary whitelist for a short amount of time for a specific reason. The * temporary whitelist is kept separately from the permanent whitelist and apps are * automatically removed from the temporary whitelist after a predetermined amount of time. * * @param packageName The package to add to the temp whitelist * @param event The reason to add the app to the temp whitelist * @param reason A human-readable reason explaining why the app is temp whitelisted. Only * used for logging purposes. Could be null or empty string. * @return The duration (in milliseconds) that the app is whitelisted for * @deprecated Use {@link #whitelistAppTemporarilyForEvent(String, int, int, String)} instead */ @Deprecated @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST) public long whitelistAppTemporarilyForEvent(@NonNull String packageName, @WhitelistEvent int event, @Nullable String reason) { return whitelistAppTemporarilyForEvent(packageName, event, REASON_UNKNOWN, reason); } /** * Add an app to the temporary whitelist for a short amount of time for a specific reason. The * temporary whitelist is kept separately from the permanent whitelist and apps are Loading @@ -203,28 +478,161 @@ public class PowerWhitelistManager { * * @param packageName The package to add to the temp whitelist * @param event The reason to add the app to the temp whitelist * @param reasonCode one of {@link ReasonCode}, use {@link #REASON_UNKNOWN} if not sure. * @param reason A human-readable reason explaining why the app is temp whitelisted. Only * used for logging purposes * used for logging purposes. Could be null or empty string. * @return The duration (in milliseconds) that the app is whitelisted for */ @RequiresPermission(android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST) public long whitelistAppTemporarilyForEvent(@NonNull String packageName, @WhitelistEvent int event, @NonNull String reason) { @WhitelistEvent int event, @ReasonCode int reasonCode, @Nullable String reason) { try { switch (event) { case EVENT_MMS: return mService.addPowerSaveTempWhitelistAppForMms( packageName, mContext.getUserId(), reason); packageName, mContext.getUserId(), reasonCode, reason); case EVENT_SMS: return mService.addPowerSaveTempWhitelistAppForSms( packageName, mContext.getUserId(), reason); packageName, mContext.getUserId(), reasonCode, reason); case EVENT_UNSPECIFIED: default: return mService.whitelistAppTemporarily( packageName, mContext.getUserId(), reason); packageName, mContext.getUserId(), reasonCode, reason); } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** * @hide */ public static @ReasonCode int getReasonCodeFromProcState(int procState) { if (procState <= PROCESS_STATE_PERSISTENT) { return REASON_PROC_STATE_PERSISTENT; } else if (procState <= PROCESS_STATE_PERSISTENT_UI) { return REASON_PROC_STATE_PERSISTENT_UI; } else if (procState <= PROCESS_STATE_TOP) { return REASON_PROC_STATE_TOP; } else if (procState <= PROCESS_STATE_BOUND_TOP) { return REASON_PROC_STATE_BTOP; } else if (procState <= PROCESS_STATE_FOREGROUND_SERVICE) { return REASON_PROC_STATE_FGS; } else if (procState <= PROCESS_STATE_BOUND_FOREGROUND_SERVICE) { return REASON_PROC_STATE_BFGS; } else { return REASON_DENIED; } } /** * Return string name of the integer reason code. * @hide * @param reasonCode * @return string name of the reason code. */ public static String reasonCodeToString(@ReasonCode int reasonCode) { switch (reasonCode) { case REASON_DENIED: return "DENIED"; case REASON_UNKNOWN: return "UNKNOWN"; case REASON_OTHER: return "OTHER"; case REASON_PROC_STATE_PERSISTENT: return "PROC_STATE_PERSISTENT"; case REASON_PROC_STATE_PERSISTENT_UI: return "PROC_STATE_PERSISTENT_UI"; case REASON_PROC_STATE_TOP: return "PROC_STATE_TOP"; case REASON_PROC_STATE_BTOP: return "PROC_STATE_BTOP"; case REASON_PROC_STATE_FGS: return "PROC_STATE_FGS"; case REASON_PROC_STATE_BFGS: return "PROC_STATE_BFGS"; case REASON_UID_VISIBLE: return "UID_VISIBLE"; case REASON_SYSTEM_UID: return "SYSTEM_UID"; case REASON_ACTIVITY_STARTER: return "ACTIVITY_STARTER"; case REASON_START_ACTIVITY_FLAG: return "START_ACTIVITY_FLAG"; case REASON_FGS_BINDING: return "FGS_BINDING"; case REASON_DEVICE_OWNER: return "DEVICE_OWNER"; case REASON_PROFILE_OWNER: return "PROFILE_OWNER"; case REASON_COMPANION_DEVICE_MANAGER: return "COMPANION_DEVICE_MANAGER"; case REASON_BACKGROUND_ACTIVITY_PERMISSION: return "BACKGROUND_ACTIVITY_PERMISSION"; case REASON_BACKGROUND_FGS_PERMISSION: return "BACKGROUND_FGS_PERMISSION"; case REASON_INSTR_BACKGROUND_ACTIVITY_PERMISSION: return "INSTR_BACKGROUND_ACTIVITY_PERMISSION"; case REASON_INSTR_BACKGROUND_FGS_PERMISSION: return "INSTR_BACKGROUND_FGS_PERMISSION"; case REASON_SYSTEM_ALERT_WINDOW_PERMISSION: return "SYSTEM_ALERT_WINDOW_PERMISSION"; case REASON_DEVICE_DEMO_MODE: return "DEVICE_DEMO_MODE"; case REASON_EXEMPTED_PACKAGE: return "EXEMPTED_PACKAGE"; case REASON_ALLOWLISTED_PACKAGE: return "ALLOWLISTED_PACKAGE"; case REASON_APPOP: return "APPOP"; case REASON_GEOFENCING: return "GEOFENCING"; case REASON_PUSH_MESSAGING: return "PUSH_MESSAGING"; case REASON_ACTIVITY_RECOGNITION: return "ACTIVITY_RECOGNITION"; case REASON_BOOT_COMPLETED: return "BOOT_COMPLETED"; case REASON_PRE_BOOT_COMPLETED: return "PRE_BOOT_COMPLETED"; case REASON_LOCKED_BOOT_COMPLETED: return "LOCKED_BOOT_COMPLETED"; case REASON_SYSTEM_ALLOW_LISTED: return "SYSTEM_ALLOW_LISTED"; case REASON_ALARM_MANAGER_ALARM_CLOCK: return "ALARM_MANAGER_ALARM_CLOCK"; case REASON_ALARM_MANAGER_WHILE_IDLE: return "ALARM_MANAGER_WHILE_IDLE"; case REASON_SERVICE_LAUNCH: return "SERVICE_LAUNCH"; case REASON_KEY_CHAIN: return "KEY_CHAIN"; case REASON_PACKAGE_VERIFIER: return "PACKAGE_VERIFIER"; case REASON_SYNC_MANAGER: return "SYNC_MANAGER"; case REASON_DOMAIN_VERIFICATION_V1: return "DOMAIN_VERIFICATION_V1"; case REASON_DOMAIN_VERIFICATION_V2: return "DOMAIN_VERIFICATION_V2"; case REASON_VPN: return "VPN"; case REASON_NOTIFICATION_SERVICE: return "NOTIFICATION_SERVICE"; case REASON_PACKAGE_REPLACED: return "PACKAGE_REPLACED"; case REASON_LOCATION_PROVIDER: return "LOCATION_PROVIDER"; case REASON_MEDIA_BUTTON: return "MEDIA_BUTTON"; case REASON_EVENT_SMS: return "EVENT_SMS"; case REASON_EVENT_MMS: return "EVENT_MMS"; case REASON_SHELL: return "SHELL"; default: return "(unknown:" + reasonCode + ")"; } } }
apex/jobscheduler/framework/java/com/android/server/DeviceIdleInternal.java +9 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.server; import android.annotation.Nullable; import android.os.PowerWhitelistManager.ReasonCode; import android.os.PowerWhitelistManager.TempAllowListType; import com.android.server.deviceidle.IDeviceIdleConstraint; Loading @@ -34,6 +36,10 @@ public interface DeviceIdleInternal { void addPowerSaveTempWhitelistApp(int callingUid, String packageName, long duration, int userId, boolean sync, String reason); void addPowerSaveTempWhitelistApp(int callingUid, String packageName, long duration, int userId, boolean sync, @ReasonCode int reasonCode, @Nullable String reason); /** * Called by ActivityManagerService to directly add UID to DeviceIdleController's temp * allowlist. Loading @@ -41,11 +47,12 @@ public interface DeviceIdleInternal { * @param duration duration in milliseconds * @param type temp allowlist type defined at {@link TempAllowListType} * @param sync * @param reasonCode one of {@link ReasonCode} * @param reason */ void addPowerSaveTempWhitelistAppDirect(int uid, long duration, @TempAllowListType int type, boolean sync, String reason); @TempAllowListType int type, boolean sync, @ReasonCode int reasonCode, @Nullable String reason); // duration in milliseconds long getNotificationAllowlistDuration(); Loading