diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 4284e7e4bfe16..757f40963bf71 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -5682,8 +5682,8 @@
restricted level.
-->
- - 10.0
- - 20.0
+ - 4.0
+ - 8.0
@@ -5744,6 +5744,12 @@
-->
false
+
+ false
+
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 41d340fd1f886..3334822727896 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -4765,6 +4765,7 @@
+
diff --git a/services/core/java/com/android/server/am/AppRestrictionController.java b/services/core/java/com/android/server/am/AppRestrictionController.java
index bdda0b7eb63b0..a164b0a601a23 100644
--- a/services/core/java/com/android/server/am/AppRestrictionController.java
+++ b/services/core/java/com/android/server/am/AppRestrictionController.java
@@ -1094,6 +1094,14 @@ public final class AppRestrictionController {
static final String KEY_BG_RESTRICTION_EXEMPTED_PACKAGES =
DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "restriction_exempted_packages";
+ /**
+ * Whether or not to show the notification for abusive apps, i.e. when the system
+ * detects it's draining significant amount of battery in the background.
+ * {@code true} - we'll show the prompt to user, {@code false} - we'll not show it.
+ */
+ 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 #mBgAutoRestrictedBucket}.
*/
@@ -1119,6 +1127,11 @@ public final class AppRestrictionController {
*/
final boolean mDefaultBgPromptFgsWithNotiToBgRestricted;
+ /**
+ * Default value to {@link #mBgPromptAbusiveAppsToBgRestricted}.
+ */
+ final boolean mDefaultBgPromptAbusiveAppToBgRestricted;
+
volatile boolean mBgAutoRestrictedBucket;
volatile boolean mRestrictedBucketEnabled;
@@ -1144,10 +1157,17 @@ public final class AppRestrictionController {
*/
volatile boolean mBgPromptFgsWithNotiOnLongRunning;
+ /**
+ * @see #KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED.
+ */
+ volatile boolean mBgPromptAbusiveAppsToBgRestricted;
+
ConstantsObserver(Handler handler, Context context) {
super(handler);
mDefaultBgPromptFgsWithNotiToBgRestricted = context.getResources().getBoolean(
com.android.internal.R.bool.config_bg_prompt_fgs_with_noti_to_bg_restricted);
+ mDefaultBgPromptAbusiveAppToBgRestricted = context.getResources().getBoolean(
+ com.android.internal.R.bool.config_bg_prompt_abusive_apps_to_bg_restricted);
}
@Override
@@ -1172,6 +1192,9 @@ public final class AppRestrictionController {
case KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING:
updateBgPromptFgsWithNotiOnLongRunning();
break;
+ case KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED:
+ updateBgPromptAbusiveAppToBgRestricted();
+ break;
case KEY_BG_RESTRICTION_EXEMPTED_PACKAGES:
updateBgRestrictionExemptedPackages();
break;
@@ -1209,6 +1232,7 @@ public final class AppRestrictionController {
updateBgLongFgsNotificationMinimalInterval();
updateBgPromptFgsWithNotiToBgRestricted();
updateBgPromptFgsWithNotiOnLongRunning();
+ updateBgPromptAbusiveAppToBgRestricted();
updateBgRestrictionExemptedPackages();
}
@@ -1251,6 +1275,13 @@ public final class AppRestrictionController {
DEFAULT_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING);
}
+ private void updateBgPromptAbusiveAppToBgRestricted() {
+ mBgPromptAbusiveAppsToBgRestricted = DeviceConfig.getBoolean(
+ DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
+ KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED,
+ mDefaultBgPromptAbusiveAppToBgRestricted);
+ }
+
private void updateBgRestrictionExemptedPackages() {
final String settings = DeviceConfig.getString(
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
@@ -1290,6 +1321,10 @@ public final class AppRestrictionController {
pw.print('=');
pw.println(mBgPromptFgsWithNotiToBgRestricted);
pw.print(prefix);
+ pw.print(KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED);
+ pw.print('=');
+ pw.println(mBgPromptAbusiveAppsToBgRestricted);
+ pw.print(prefix);
pw.print(KEY_BG_RESTRICTION_EXEMPTED_PACKAGES);
pw.print('=');
pw.println(mBgRestrictionExemptedPackages.toString());
@@ -2296,6 +2331,13 @@ public final class AppRestrictionController {
}
void postRequestBgRestrictedIfNecessary(String packageName, int uid) {
+ if (!mBgController.mConstantsObserver.mBgPromptAbusiveAppsToBgRestricted) {
+ if (DEBUG_BG_RESTRICTION_CONTROLLER) {
+ Slog.i(TAG, "Not requesting bg-restriction due to config");
+ }
+ return;
+ }
+
final Intent intent = new Intent(Settings.ACTION_VIEW_ADVANCED_POWER_USAGE_DETAIL);
intent.setData(Uri.fromParts(PACKAGE_SCHEME, packageName, null));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
diff --git a/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java b/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java
index c0b4f0fe58121..ac542935fa0a3 100644
--- a/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java
@@ -585,6 +585,7 @@ public final class BackgroundRestrictionTest {
DeviceConfigSession bgCurrentDrainRestrictedBucketThreshold = null;
DeviceConfigSession bgCurrentDrainBgRestrictedThreshold = null;
DeviceConfigSession bgPromptFgsWithNotiToBgRestricted = null;
+ DeviceConfigSession bgPromptAbusiveAppToBgRestricted = null;
DeviceConfigSession bgNotificationMinInterval = null;
DeviceConfigSession bgBatteryExemptionTypes = null;
DeviceConfigSession bgCurrentDrainDecoupleThresholds = null;
@@ -642,6 +643,14 @@ public final class BackgroundRestrictionTest {
R.bool.config_bg_prompt_fgs_with_noti_to_bg_restricted));
bgPromptFgsWithNotiToBgRestricted.set(true);
+ bgPromptAbusiveAppToBgRestricted = new DeviceConfigSession<>(
+ DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
+ ConstantsObserver.KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED,
+ DeviceConfig::getBoolean,
+ mContext.getResources().getBoolean(
+ R.bool.config_bg_prompt_abusive_apps_to_bg_restricted));
+ bgPromptAbusiveAppToBgRestricted.set(true);
+
bgNotificationMinInterval = new DeviceConfigSession<>(
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
ConstantsObserver.KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL,
@@ -1055,6 +1064,7 @@ public final class BackgroundRestrictionTest {
closeIfNotNull(bgCurrentDrainRestrictedBucketThreshold);
closeIfNotNull(bgCurrentDrainBgRestrictedThreshold);
closeIfNotNull(bgPromptFgsWithNotiToBgRestricted);
+ closeIfNotNull(bgPromptAbusiveAppToBgRestricted);
closeIfNotNull(bgNotificationMinInterval);
closeIfNotNull(bgBatteryExemptionTypes);
closeIfNotNull(bgCurrentDrainDecoupleThresholds);
@@ -1613,6 +1623,7 @@ public final class BackgroundRestrictionTest {
DeviceConfigSession bgPermissionsInMonitor = null;
DeviceConfigSession bgCurrentDrainHighThresholdByBgLocation = null;
DeviceConfigSession bgCurrentDrainDecoupleThresholds = null;
+ DeviceConfigSession bgPromptAbusiveAppToBgRestricted = null;
mBgRestrictionController.addAppBackgroundRestrictionListener(listener);
@@ -1751,6 +1762,14 @@ public final class BackgroundRestrictionTest {
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_DECOUPLE_THRESHOLD);
bgCurrentDrainDecoupleThresholds.set(true);
+ bgPromptAbusiveAppToBgRestricted = new DeviceConfigSession<>(
+ DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
+ ConstantsObserver.KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED,
+ DeviceConfig::getBoolean,
+ mContext.getResources().getBoolean(
+ R.bool.config_bg_prompt_abusive_apps_to_bg_restricted));
+ bgPromptAbusiveAppToBgRestricted.set(true);
+
mCurrentTimeMillis = 10_000L;
doReturn(mCurrentTimeMillis - windowMs).when(stats).getStatsStartTimestamp();
doReturn(mCurrentTimeMillis).when(stats).getStatsEndTimestamp();
@@ -2168,6 +2187,7 @@ public final class BackgroundRestrictionTest {
closeIfNotNull(bgBatteryExemptionTypes);
closeIfNotNull(bgPermissionMonitorEnabled);
closeIfNotNull(bgPermissionsInMonitor);
+ closeIfNotNull(bgPromptAbusiveAppToBgRestricted);
closeIfNotNull(bgCurrentDrainHighThresholdByBgLocation);
closeIfNotNull(bgCurrentDrainDecoupleThresholds);
}