Loading apex/jobscheduler/framework/java/android/os/PowerExemptionManager.java +10 −0 Original line number Diff line number Diff line Loading @@ -379,6 +379,11 @@ public class PowerExemptionManager { * @hide */ public static final int REASON_DISALLOW_APPS_CONTROL = 323; /** * Active device admin package. * @hide */ public static final int REASON_ACTIVE_DEVICE_ADMIN = 324; /** @hide The app requests out-out. */ public static final int REASON_OPT_OUT_REQUESTED = 1000; Loading Loading @@ -459,6 +464,7 @@ public class PowerExemptionManager { REASON_OPT_OUT_REQUESTED, REASON_DPO_PROTECTED_APP, REASON_DISALLOW_APPS_CONTROL, REASON_ACTIVE_DEVICE_ADMIN, }) @Retention(RetentionPolicy.SOURCE) public @interface ReasonCode {} Loading Loading @@ -669,6 +675,8 @@ public class PowerExemptionManager { return AppBackgroundRestrictionsInfo.REASON_DPO_PROTECTED_APP; case REASON_DISALLOW_APPS_CONTROL: return AppBackgroundRestrictionsInfo.REASON_DISALLOW_APPS_CONTROL; case REASON_ACTIVE_DEVICE_ADMIN: return AppBackgroundRestrictionsInfo.REASON_ACTIVE_DEVICE_ADMIN; default: return AppBackgroundRestrictionsInfo.REASON_DENIED; } Loading Loading @@ -818,6 +826,8 @@ public class PowerExemptionManager { return "DPO_PROTECTED_APP"; case REASON_DISALLOW_APPS_CONTROL: return "DISALLOW_APPS_CONTROL"; case REASON_ACTIVE_DEVICE_ADMIN: return "ACTIVE_DEVICE_ADMIN"; case REASON_OPT_OUT_REQUESTED: return "REASON_OPT_OUT_REQUESTED"; default: Loading apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java +5 −0 Original line number Diff line number Diff line Loading @@ -218,6 +218,11 @@ public interface AppStandbyInternal { void setActiveAdminApps(Set<String> adminPkgs, int userId); /** * @return {@code true} if the given package is an active device admin app. */ boolean isActiveDeviceAdmin(String packageName, int userId); void onAdminDataAvailable(); void clearCarrierPrivilegedApps(); Loading apex/jobscheduler/service/java/com/android/server/alarm/Alarm.java +6 −0 Original line number Diff line number Diff line Loading @@ -88,6 +88,10 @@ class Alarm { * Change wasn't enable for the caller due to compat reasons. */ static final int EXACT_ALLOW_REASON_COMPAT = 2; /** * Caller had USE_EXACT_ALARM permission. */ static final int EXACT_ALLOW_REASON_POLICY_PERMISSION = 3; public final int type; /** Loading Loading @@ -275,6 +279,8 @@ class Alarm { return "compat"; case EXACT_ALLOW_REASON_PERMISSION: return "permission"; case EXACT_ALLOW_REASON_POLICY_PERMISSION: return "policy_permission"; case EXACT_ALLOW_REASON_NOT_APPLICABLE: return "N/A"; default: Loading apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java +35 −36 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import static com.android.server.alarm.Alarm.EXACT_ALLOW_REASON_ALLOW_LIST; import static com.android.server.alarm.Alarm.EXACT_ALLOW_REASON_COMPAT; import static com.android.server.alarm.Alarm.EXACT_ALLOW_REASON_NOT_APPLICABLE; import static com.android.server.alarm.Alarm.EXACT_ALLOW_REASON_PERMISSION; import static com.android.server.alarm.Alarm.EXACT_ALLOW_REASON_POLICY_PERMISSION; import static com.android.server.alarm.Alarm.REQUESTER_POLICY_INDEX; import static com.android.server.alarm.Alarm.TARE_POLICY_INDEX; import static com.android.server.alarm.AlarmManagerService.RemovedAlarm.REMOVE_REASON_ALARM_CANCELLED; Loading Loading @@ -2698,8 +2699,7 @@ public class AlarmManagerService extends SystemService { // Make sure the caller is allowed to use the requested kind of alarm, and also // decide what quota and broadcast options to use. boolean allowListed = false; // For logging the reason. boolean changeDisabled = false; // For logging the reason. int exactAllowReason = EXACT_ALLOW_REASON_NOT_APPLICABLE; Bundle idleOptions = null; if ((flags & FLAG_PRIORITIZE) != 0) { getContext().enforcePermission( Loading @@ -2721,57 +2721,56 @@ public class AlarmManagerService extends SystemService { idleOptions = mOptsWithoutFgs.toBundle(); } } else { changeDisabled = true; needsPermission = false; lowerQuota = allowWhileIdle; idleOptions = allowWhileIdle ? mOptsWithFgs.toBundle() : null; if (exact) { exactAllowReason = EXACT_ALLOW_REASON_COMPAT; } if (needsPermission && !hasScheduleExactAlarmInternal(callingPackage, callingUid) && !hasUseExactAlarmInternal(callingPackage, callingUid)) { if (!isExemptFromExactAlarmPermissionNoLock(callingUid)) { final String errorMessage = "Caller " + callingPackage + " needs to hold " + Manifest.permission.SCHEDULE_EXACT_ALARM + " to set " } if (needsPermission) { if (hasUseExactAlarmInternal(callingPackage, callingUid)) { exactAllowReason = EXACT_ALLOW_REASON_POLICY_PERMISSION; } else if (hasScheduleExactAlarmInternal(callingPackage, callingUid)) { exactAllowReason = EXACT_ALLOW_REASON_PERMISSION; } else { if (isExemptFromExactAlarmPermissionNoLock(callingUid)) { exactAllowReason = EXACT_ALLOW_REASON_ALLOW_LIST; } else { final String errorMessage = "Caller " + callingPackage + " needs to hold " + Manifest.permission.SCHEDULE_EXACT_ALARM + " or " + Manifest.permission.USE_EXACT_ALARM + " to set " + "exact alarms."; if (mConstants.CRASH_NON_CLOCK_APPS) { throw new SecurityException(errorMessage); } else { Slog.wtf(TAG, errorMessage); } } else { allowListed = true; } // If the app is on the full system power allow-list (not except-idle), or the // user-elected allow-list, or we're in a soft failure mode, we still allow the // alarms. // In both cases, ALLOW_WHILE_IDLE alarms get a lower quota equivalent to what // pre-S apps got. Note that user-allow-listed apps don't use the flag // If the app is on the full system power allow-list (not except-idle), // or the user-elected allow-list, or we're in a soft failure mode, we still // allow the alarms. // In both cases, ALLOW_WHILE_IDLE alarms get a lower quota equivalent to // what pre-S apps got. Note that user-allow-listed apps don't use the flag // ALLOW_WHILE_IDLE. // We grant temporary allow-list to allow-while-idle alarms but without FGS // capability. AlarmClock alarms do not get the temporary allow-list. This is // consistent with pre-S behavior. Note that apps that are in either of the // power-save allow-lists do not need it. // capability. AlarmClock alarms do not get the temporary allow-list. // This is consistent with pre-S behavior. Note that apps that are in // either of the power-save allow-lists do not need it. idleOptions = allowWhileIdle ? mOptsWithoutFgs.toBundle() : null; lowerQuota = allowWhileIdle; } } if (lowerQuota) { flags &= ~FLAG_ALLOW_WHILE_IDLE; flags |= FLAG_ALLOW_WHILE_IDLE_COMPAT; } } final int exactAllowReason; if (exact) { // If this is an exact time alarm, then it can't be batched with other alarms. flags |= AlarmManager.FLAG_STANDALONE; if (changeDisabled) { exactAllowReason = EXACT_ALLOW_REASON_COMPAT; } else if (allowListed) { exactAllowReason = EXACT_ALLOW_REASON_ALLOW_LIST; } else { exactAllowReason = EXACT_ALLOW_REASON_PERMISSION; } } else { exactAllowReason = EXACT_ALLOW_REASON_NOT_APPLICABLE; } setImpl(type, triggerAtTime, windowLength, interval, operation, directReceiver, Loading apex/jobscheduler/service/java/com/android/server/alarm/MetricsHelper.java +3 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static com.android.internal.util.FrameworkStatsLog.ALARM_SCHEDULED__EXACT import static com.android.internal.util.FrameworkStatsLog.ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__CHANGE_DISABLED; import static com.android.internal.util.FrameworkStatsLog.ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__NOT_APPLICABLE; import static com.android.internal.util.FrameworkStatsLog.ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__PERMISSION; import static com.android.internal.util.FrameworkStatsLog.ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__POLICY_PERMISSION; import static com.android.server.alarm.AlarmManagerService.INDEFINITE_DELAY; import android.app.ActivityManager; Loading Loading @@ -89,6 +90,8 @@ class MetricsHelper { return ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__PERMISSION; case Alarm.EXACT_ALLOW_REASON_COMPAT: return ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__CHANGE_DISABLED; case Alarm.EXACT_ALLOW_REASON_POLICY_PERMISSION: return ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__POLICY_PERMISSION; default: return ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__NOT_APPLICABLE; } Loading Loading
apex/jobscheduler/framework/java/android/os/PowerExemptionManager.java +10 −0 Original line number Diff line number Diff line Loading @@ -379,6 +379,11 @@ public class PowerExemptionManager { * @hide */ public static final int REASON_DISALLOW_APPS_CONTROL = 323; /** * Active device admin package. * @hide */ public static final int REASON_ACTIVE_DEVICE_ADMIN = 324; /** @hide The app requests out-out. */ public static final int REASON_OPT_OUT_REQUESTED = 1000; Loading Loading @@ -459,6 +464,7 @@ public class PowerExemptionManager { REASON_OPT_OUT_REQUESTED, REASON_DPO_PROTECTED_APP, REASON_DISALLOW_APPS_CONTROL, REASON_ACTIVE_DEVICE_ADMIN, }) @Retention(RetentionPolicy.SOURCE) public @interface ReasonCode {} Loading Loading @@ -669,6 +675,8 @@ public class PowerExemptionManager { return AppBackgroundRestrictionsInfo.REASON_DPO_PROTECTED_APP; case REASON_DISALLOW_APPS_CONTROL: return AppBackgroundRestrictionsInfo.REASON_DISALLOW_APPS_CONTROL; case REASON_ACTIVE_DEVICE_ADMIN: return AppBackgroundRestrictionsInfo.REASON_ACTIVE_DEVICE_ADMIN; default: return AppBackgroundRestrictionsInfo.REASON_DENIED; } Loading Loading @@ -818,6 +826,8 @@ public class PowerExemptionManager { return "DPO_PROTECTED_APP"; case REASON_DISALLOW_APPS_CONTROL: return "DISALLOW_APPS_CONTROL"; case REASON_ACTIVE_DEVICE_ADMIN: return "ACTIVE_DEVICE_ADMIN"; case REASON_OPT_OUT_REQUESTED: return "REASON_OPT_OUT_REQUESTED"; default: Loading
apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java +5 −0 Original line number Diff line number Diff line Loading @@ -218,6 +218,11 @@ public interface AppStandbyInternal { void setActiveAdminApps(Set<String> adminPkgs, int userId); /** * @return {@code true} if the given package is an active device admin app. */ boolean isActiveDeviceAdmin(String packageName, int userId); void onAdminDataAvailable(); void clearCarrierPrivilegedApps(); Loading
apex/jobscheduler/service/java/com/android/server/alarm/Alarm.java +6 −0 Original line number Diff line number Diff line Loading @@ -88,6 +88,10 @@ class Alarm { * Change wasn't enable for the caller due to compat reasons. */ static final int EXACT_ALLOW_REASON_COMPAT = 2; /** * Caller had USE_EXACT_ALARM permission. */ static final int EXACT_ALLOW_REASON_POLICY_PERMISSION = 3; public final int type; /** Loading Loading @@ -275,6 +279,8 @@ class Alarm { return "compat"; case EXACT_ALLOW_REASON_PERMISSION: return "permission"; case EXACT_ALLOW_REASON_POLICY_PERMISSION: return "policy_permission"; case EXACT_ALLOW_REASON_NOT_APPLICABLE: return "N/A"; default: Loading
apex/jobscheduler/service/java/com/android/server/alarm/AlarmManagerService.java +35 −36 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import static com.android.server.alarm.Alarm.EXACT_ALLOW_REASON_ALLOW_LIST; import static com.android.server.alarm.Alarm.EXACT_ALLOW_REASON_COMPAT; import static com.android.server.alarm.Alarm.EXACT_ALLOW_REASON_NOT_APPLICABLE; import static com.android.server.alarm.Alarm.EXACT_ALLOW_REASON_PERMISSION; import static com.android.server.alarm.Alarm.EXACT_ALLOW_REASON_POLICY_PERMISSION; import static com.android.server.alarm.Alarm.REQUESTER_POLICY_INDEX; import static com.android.server.alarm.Alarm.TARE_POLICY_INDEX; import static com.android.server.alarm.AlarmManagerService.RemovedAlarm.REMOVE_REASON_ALARM_CANCELLED; Loading Loading @@ -2698,8 +2699,7 @@ public class AlarmManagerService extends SystemService { // Make sure the caller is allowed to use the requested kind of alarm, and also // decide what quota and broadcast options to use. boolean allowListed = false; // For logging the reason. boolean changeDisabled = false; // For logging the reason. int exactAllowReason = EXACT_ALLOW_REASON_NOT_APPLICABLE; Bundle idleOptions = null; if ((flags & FLAG_PRIORITIZE) != 0) { getContext().enforcePermission( Loading @@ -2721,57 +2721,56 @@ public class AlarmManagerService extends SystemService { idleOptions = mOptsWithoutFgs.toBundle(); } } else { changeDisabled = true; needsPermission = false; lowerQuota = allowWhileIdle; idleOptions = allowWhileIdle ? mOptsWithFgs.toBundle() : null; if (exact) { exactAllowReason = EXACT_ALLOW_REASON_COMPAT; } if (needsPermission && !hasScheduleExactAlarmInternal(callingPackage, callingUid) && !hasUseExactAlarmInternal(callingPackage, callingUid)) { if (!isExemptFromExactAlarmPermissionNoLock(callingUid)) { final String errorMessage = "Caller " + callingPackage + " needs to hold " + Manifest.permission.SCHEDULE_EXACT_ALARM + " to set " } if (needsPermission) { if (hasUseExactAlarmInternal(callingPackage, callingUid)) { exactAllowReason = EXACT_ALLOW_REASON_POLICY_PERMISSION; } else if (hasScheduleExactAlarmInternal(callingPackage, callingUid)) { exactAllowReason = EXACT_ALLOW_REASON_PERMISSION; } else { if (isExemptFromExactAlarmPermissionNoLock(callingUid)) { exactAllowReason = EXACT_ALLOW_REASON_ALLOW_LIST; } else { final String errorMessage = "Caller " + callingPackage + " needs to hold " + Manifest.permission.SCHEDULE_EXACT_ALARM + " or " + Manifest.permission.USE_EXACT_ALARM + " to set " + "exact alarms."; if (mConstants.CRASH_NON_CLOCK_APPS) { throw new SecurityException(errorMessage); } else { Slog.wtf(TAG, errorMessage); } } else { allowListed = true; } // If the app is on the full system power allow-list (not except-idle), or the // user-elected allow-list, or we're in a soft failure mode, we still allow the // alarms. // In both cases, ALLOW_WHILE_IDLE alarms get a lower quota equivalent to what // pre-S apps got. Note that user-allow-listed apps don't use the flag // If the app is on the full system power allow-list (not except-idle), // or the user-elected allow-list, or we're in a soft failure mode, we still // allow the alarms. // In both cases, ALLOW_WHILE_IDLE alarms get a lower quota equivalent to // what pre-S apps got. Note that user-allow-listed apps don't use the flag // ALLOW_WHILE_IDLE. // We grant temporary allow-list to allow-while-idle alarms but without FGS // capability. AlarmClock alarms do not get the temporary allow-list. This is // consistent with pre-S behavior. Note that apps that are in either of the // power-save allow-lists do not need it. // capability. AlarmClock alarms do not get the temporary allow-list. // This is consistent with pre-S behavior. Note that apps that are in // either of the power-save allow-lists do not need it. idleOptions = allowWhileIdle ? mOptsWithoutFgs.toBundle() : null; lowerQuota = allowWhileIdle; } } if (lowerQuota) { flags &= ~FLAG_ALLOW_WHILE_IDLE; flags |= FLAG_ALLOW_WHILE_IDLE_COMPAT; } } final int exactAllowReason; if (exact) { // If this is an exact time alarm, then it can't be batched with other alarms. flags |= AlarmManager.FLAG_STANDALONE; if (changeDisabled) { exactAllowReason = EXACT_ALLOW_REASON_COMPAT; } else if (allowListed) { exactAllowReason = EXACT_ALLOW_REASON_ALLOW_LIST; } else { exactAllowReason = EXACT_ALLOW_REASON_PERMISSION; } } else { exactAllowReason = EXACT_ALLOW_REASON_NOT_APPLICABLE; } setImpl(type, triggerAtTime, windowLength, interval, operation, directReceiver, Loading
apex/jobscheduler/service/java/com/android/server/alarm/MetricsHelper.java +3 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import static com.android.internal.util.FrameworkStatsLog.ALARM_SCHEDULED__EXACT import static com.android.internal.util.FrameworkStatsLog.ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__CHANGE_DISABLED; import static com.android.internal.util.FrameworkStatsLog.ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__NOT_APPLICABLE; import static com.android.internal.util.FrameworkStatsLog.ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__PERMISSION; import static com.android.internal.util.FrameworkStatsLog.ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__POLICY_PERMISSION; import static com.android.server.alarm.AlarmManagerService.INDEFINITE_DELAY; import android.app.ActivityManager; Loading Loading @@ -89,6 +90,8 @@ class MetricsHelper { return ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__PERMISSION; case Alarm.EXACT_ALLOW_REASON_COMPAT: return ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__CHANGE_DISABLED; case Alarm.EXACT_ALLOW_REASON_POLICY_PERMISSION: return ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__POLICY_PERMISSION; default: return ALARM_SCHEDULED__EXACT_ALARM_ALLOWED_REASON__NOT_APPLICABLE; } Loading