Loading services/core/java/com/android/server/am/AppBatteryTracker.java +1 −0 Original line number Diff line number Diff line Loading @@ -1673,6 +1673,7 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy> if (pair != null) { final long[] ts = pair.first; final int restrictedLevel = ts[TIME_STAMP_INDEX_RESTRICTED_BUCKET] > 0 && mTracker.mAppRestrictionController.isAutoRestrictAbusiveAppEnabled() ? RESTRICTION_LEVEL_RESTRICTED_BUCKET : RESTRICTION_LEVEL_ADAPTIVE_BUCKET; if (maxLevel > RESTRICTION_LEVEL_BACKGROUND_RESTRICTED) { Loading services/core/java/com/android/server/am/AppRestrictionController.java +37 −0 Original line number Diff line number Diff line Loading @@ -1062,6 +1062,13 @@ public final class AppRestrictionController { static final String KEY_BG_AUTO_RESTRICTED_BUCKET_ON_BG_RESTRICTION = DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "auto_restricted_bucket_on_bg_restricted"; /** * Whether or not to move the app to restricted standby level automatically * when system detects it's abusive. */ static final String KEY_BG_AUTO_RESTRICT_ABUSIVE_APPS = DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "auto_restrict_abusive_apps"; /** * The minimal interval in ms before posting a notification again on abusive behaviors * of a certain package. Loading Loading @@ -1106,6 +1113,11 @@ public final class AppRestrictionController { static final String KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED = DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "prompt_abusive_apps_to_bg_restricted"; /** * Default value to {@link #mBgAutoRestrictAbusiveApps}. */ static final boolean DEFAULT_BG_AUTO_RESTRICT_ABUSIVE_APPS = true; /** * Default value to {@link #mBgAutoRestrictedBucket}. */ Loading Loading @@ -1138,6 +1150,8 @@ public final class AppRestrictionController { volatile boolean mBgAutoRestrictedBucket; volatile boolean mBgAutoRestrictAbusiveApps; volatile boolean mRestrictedBucketEnabled; volatile long mBgAbusiveNotificationMinIntervalMs; Loading Loading @@ -1184,6 +1198,9 @@ public final class AppRestrictionController { case KEY_BG_AUTO_RESTRICTED_BUCKET_ON_BG_RESTRICTION: updateBgAutoRestrictedBucketChanged(); break; case KEY_BG_AUTO_RESTRICT_ABUSIVE_APPS: updateBgAutoRestrictAbusiveApps(); break; case KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL: updateBgAbusiveNotificationMinimalInterval(); break; Loading Loading @@ -1232,6 +1249,7 @@ public final class AppRestrictionController { void updateDeviceConfig() { updateBgAutoRestrictedBucketChanged(); updateBgAutoRestrictAbusiveApps(); updateBgAbusiveNotificationMinimalInterval(); updateBgLongFgsNotificationMinimalInterval(); updateBgPromptFgsWithNotiToBgRestricted(); Loading @@ -1251,6 +1269,13 @@ public final class AppRestrictionController { } } private void updateBgAutoRestrictAbusiveApps() { mBgAutoRestrictAbusiveApps = DeviceConfig.getBoolean( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, KEY_BG_AUTO_RESTRICT_ABUSIVE_APPS, DEFAULT_BG_AUTO_RESTRICT_ABUSIVE_APPS); } private void updateBgAbusiveNotificationMinimalInterval() { mBgAbusiveNotificationMinIntervalMs = DeviceConfig.getLong( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, Loading Loading @@ -1313,6 +1338,10 @@ public final class AppRestrictionController { pw.print('='); pw.println(mBgAutoRestrictedBucket); pw.print(prefix); pw.print(KEY_BG_AUTO_RESTRICT_ABUSIVE_APPS); pw.print('='); pw.println(mBgAutoRestrictAbusiveApps); pw.print(prefix); pw.print(KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL); pw.print('='); pw.println(mBgAbusiveNotificationMinIntervalMs); Loading Loading @@ -1771,6 +1800,14 @@ public final class AppRestrictionController { return mRestrictionSettings.getRestrictionLevel(packageName, userId); } /** * @return Whether or not to move the app to restricted level automatically * when system detects it's abusive. */ boolean isAutoRestrictAbusiveAppEnabled() { return mConstantsObserver.mBgAutoRestrictAbusiveApps; } /** * @return The total foreground service durations for the given package/uid with given * foreground service type, or the total durations regardless the type if the given type is 0. Loading services/core/java/com/android/server/am/BaseAppStateTimeSlotEventsTracker.java +1 −0 Original line number Diff line number Diff line Loading @@ -301,6 +301,7 @@ abstract class BaseAppStateTimeSlotEventsTracker @RestrictionLevel int maxLevel) { synchronized (mLock) { final int level = mExcessiveEventPkgs.get(packageName, uid) == null || !mTracker.mAppRestrictionController.isAutoRestrictAbusiveAppEnabled() ? RESTRICTION_LEVEL_ADAPTIVE_BUCKET : RESTRICTION_LEVEL_RESTRICTED_BUCKET; if (maxLevel > RESTRICTION_LEVEL_RESTRICTED_BUCKET) { Loading Loading
services/core/java/com/android/server/am/AppBatteryTracker.java +1 −0 Original line number Diff line number Diff line Loading @@ -1673,6 +1673,7 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy> if (pair != null) { final long[] ts = pair.first; final int restrictedLevel = ts[TIME_STAMP_INDEX_RESTRICTED_BUCKET] > 0 && mTracker.mAppRestrictionController.isAutoRestrictAbusiveAppEnabled() ? RESTRICTION_LEVEL_RESTRICTED_BUCKET : RESTRICTION_LEVEL_ADAPTIVE_BUCKET; if (maxLevel > RESTRICTION_LEVEL_BACKGROUND_RESTRICTED) { Loading
services/core/java/com/android/server/am/AppRestrictionController.java +37 −0 Original line number Diff line number Diff line Loading @@ -1062,6 +1062,13 @@ public final class AppRestrictionController { static final String KEY_BG_AUTO_RESTRICTED_BUCKET_ON_BG_RESTRICTION = DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "auto_restricted_bucket_on_bg_restricted"; /** * Whether or not to move the app to restricted standby level automatically * when system detects it's abusive. */ static final String KEY_BG_AUTO_RESTRICT_ABUSIVE_APPS = DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "auto_restrict_abusive_apps"; /** * The minimal interval in ms before posting a notification again on abusive behaviors * of a certain package. Loading Loading @@ -1106,6 +1113,11 @@ public final class AppRestrictionController { static final String KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED = DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "prompt_abusive_apps_to_bg_restricted"; /** * Default value to {@link #mBgAutoRestrictAbusiveApps}. */ static final boolean DEFAULT_BG_AUTO_RESTRICT_ABUSIVE_APPS = true; /** * Default value to {@link #mBgAutoRestrictedBucket}. */ Loading Loading @@ -1138,6 +1150,8 @@ public final class AppRestrictionController { volatile boolean mBgAutoRestrictedBucket; volatile boolean mBgAutoRestrictAbusiveApps; volatile boolean mRestrictedBucketEnabled; volatile long mBgAbusiveNotificationMinIntervalMs; Loading Loading @@ -1184,6 +1198,9 @@ public final class AppRestrictionController { case KEY_BG_AUTO_RESTRICTED_BUCKET_ON_BG_RESTRICTION: updateBgAutoRestrictedBucketChanged(); break; case KEY_BG_AUTO_RESTRICT_ABUSIVE_APPS: updateBgAutoRestrictAbusiveApps(); break; case KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL: updateBgAbusiveNotificationMinimalInterval(); break; Loading Loading @@ -1232,6 +1249,7 @@ public final class AppRestrictionController { void updateDeviceConfig() { updateBgAutoRestrictedBucketChanged(); updateBgAutoRestrictAbusiveApps(); updateBgAbusiveNotificationMinimalInterval(); updateBgLongFgsNotificationMinimalInterval(); updateBgPromptFgsWithNotiToBgRestricted(); Loading @@ -1251,6 +1269,13 @@ public final class AppRestrictionController { } } private void updateBgAutoRestrictAbusiveApps() { mBgAutoRestrictAbusiveApps = DeviceConfig.getBoolean( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, KEY_BG_AUTO_RESTRICT_ABUSIVE_APPS, DEFAULT_BG_AUTO_RESTRICT_ABUSIVE_APPS); } private void updateBgAbusiveNotificationMinimalInterval() { mBgAbusiveNotificationMinIntervalMs = DeviceConfig.getLong( DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, Loading Loading @@ -1313,6 +1338,10 @@ public final class AppRestrictionController { pw.print('='); pw.println(mBgAutoRestrictedBucket); pw.print(prefix); pw.print(KEY_BG_AUTO_RESTRICT_ABUSIVE_APPS); pw.print('='); pw.println(mBgAutoRestrictAbusiveApps); pw.print(prefix); pw.print(KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL); pw.print('='); pw.println(mBgAbusiveNotificationMinIntervalMs); Loading Loading @@ -1771,6 +1800,14 @@ public final class AppRestrictionController { return mRestrictionSettings.getRestrictionLevel(packageName, userId); } /** * @return Whether or not to move the app to restricted level automatically * when system detects it's abusive. */ boolean isAutoRestrictAbusiveAppEnabled() { return mConstantsObserver.mBgAutoRestrictAbusiveApps; } /** * @return The total foreground service durations for the given package/uid with given * foreground service type, or the total durations regardless the type if the given type is 0. Loading
services/core/java/com/android/server/am/BaseAppStateTimeSlotEventsTracker.java +1 −0 Original line number Diff line number Diff line Loading @@ -301,6 +301,7 @@ abstract class BaseAppStateTimeSlotEventsTracker @RestrictionLevel int maxLevel) { synchronized (mLock) { final int level = mExcessiveEventPkgs.get(packageName, uid) == null || !mTracker.mAppRestrictionController.isAutoRestrictAbusiveAppEnabled() ? RESTRICTION_LEVEL_ADAPTIVE_BUCKET : RESTRICTION_LEVEL_RESTRICTED_BUCKET; if (maxLevel > RESTRICTION_LEVEL_RESTRICTED_BUCKET) { Loading