Merge "Add a config to control if show the prompt on abusive apps" into tm-dev am: 8caeb7d061
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17768181 Change-Id: Iea5cfac88d4d9b750cc44e11dc4ca8cf8b9d9f6e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -5682,8 +5682,8 @@
|
|||||||
restricted level.
|
restricted level.
|
||||||
-->
|
-->
|
||||||
<array name="config_bg_current_drain_threshold_to_bg_restricted">
|
<array name="config_bg_current_drain_threshold_to_bg_restricted">
|
||||||
<item>10.0</item> <!-- regular device -->
|
<item>4.0</item> <!-- regular device -->
|
||||||
<item>20.0</item> <!-- low ram device -->
|
<item>8.0</item> <!-- low ram device -->
|
||||||
</array>
|
</array>
|
||||||
|
|
||||||
<!-- The background current drain monitoring window size. -->
|
<!-- The background current drain monitoring window size. -->
|
||||||
@@ -5744,6 +5744,12 @@
|
|||||||
-->
|
-->
|
||||||
<bool name="config_bg_prompt_fgs_with_noti_to_bg_restricted">false</bool>
|
<bool name="config_bg_prompt_fgs_with_noti_to_bg_restricted">false</bool>
|
||||||
|
|
||||||
|
<!-- The behavior when the system detects it's abusive, should the system prompt the user
|
||||||
|
to put it into the bg restricted level.
|
||||||
|
True - we'll show the prompt to user, False - we'll not show it.
|
||||||
|
-->
|
||||||
|
<bool name="config_bg_prompt_abusive_apps_to_bg_restricted">false</bool>
|
||||||
|
|
||||||
<!-- The types of state where we'll exempt its battery usage during that state.
|
<!-- The types of state where we'll exempt its battery usage during that state.
|
||||||
The state here must be one or a combination of STATE_TYPE_* in BaseAppStateTracker.
|
The state here must be one or a combination of STATE_TYPE_* in BaseAppStateTracker.
|
||||||
-->
|
-->
|
||||||
|
|||||||
@@ -4765,6 +4765,7 @@
|
|||||||
<java-symbol type="integer" name="config_bg_current_drain_media_playback_min_duration" />
|
<java-symbol type="integer" name="config_bg_current_drain_media_playback_min_duration" />
|
||||||
<java-symbol type="integer" name="config_bg_current_drain_location_min_duration" />
|
<java-symbol type="integer" name="config_bg_current_drain_location_min_duration" />
|
||||||
<java-symbol type="bool" name="config_bg_prompt_fgs_with_noti_to_bg_restricted" />
|
<java-symbol type="bool" name="config_bg_prompt_fgs_with_noti_to_bg_restricted" />
|
||||||
|
<java-symbol type="bool" name="config_bg_prompt_abusive_apps_to_bg_restricted" />
|
||||||
<java-symbol type="integer" name="config_bg_current_drain_exempted_types" />
|
<java-symbol type="integer" name="config_bg_current_drain_exempted_types" />
|
||||||
<java-symbol type="bool" name="config_bg_current_drain_high_threshold_by_bg_location" />
|
<java-symbol type="bool" name="config_bg_current_drain_high_threshold_by_bg_location" />
|
||||||
<java-symbol type="drawable" name="ic_swap_horiz" />
|
<java-symbol type="drawable" name="ic_swap_horiz" />
|
||||||
|
|||||||
@@ -1094,6 +1094,14 @@ public final class AppRestrictionController {
|
|||||||
static final String KEY_BG_RESTRICTION_EXEMPTED_PACKAGES =
|
static final String KEY_BG_RESTRICTION_EXEMPTED_PACKAGES =
|
||||||
DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "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}.
|
* Default value to {@link #mBgAutoRestrictedBucket}.
|
||||||
*/
|
*/
|
||||||
@@ -1119,6 +1127,11 @@ public final class AppRestrictionController {
|
|||||||
*/
|
*/
|
||||||
final boolean mDefaultBgPromptFgsWithNotiToBgRestricted;
|
final boolean mDefaultBgPromptFgsWithNotiToBgRestricted;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default value to {@link #mBgPromptAbusiveAppsToBgRestricted}.
|
||||||
|
*/
|
||||||
|
final boolean mDefaultBgPromptAbusiveAppToBgRestricted;
|
||||||
|
|
||||||
volatile boolean mBgAutoRestrictedBucket;
|
volatile boolean mBgAutoRestrictedBucket;
|
||||||
|
|
||||||
volatile boolean mRestrictedBucketEnabled;
|
volatile boolean mRestrictedBucketEnabled;
|
||||||
@@ -1144,10 +1157,17 @@ public final class AppRestrictionController {
|
|||||||
*/
|
*/
|
||||||
volatile boolean mBgPromptFgsWithNotiOnLongRunning;
|
volatile boolean mBgPromptFgsWithNotiOnLongRunning;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see #KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED.
|
||||||
|
*/
|
||||||
|
volatile boolean mBgPromptAbusiveAppsToBgRestricted;
|
||||||
|
|
||||||
ConstantsObserver(Handler handler, Context context) {
|
ConstantsObserver(Handler handler, Context context) {
|
||||||
super(handler);
|
super(handler);
|
||||||
mDefaultBgPromptFgsWithNotiToBgRestricted = context.getResources().getBoolean(
|
mDefaultBgPromptFgsWithNotiToBgRestricted = context.getResources().getBoolean(
|
||||||
com.android.internal.R.bool.config_bg_prompt_fgs_with_noti_to_bg_restricted);
|
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
|
@Override
|
||||||
@@ -1172,6 +1192,9 @@ public final class AppRestrictionController {
|
|||||||
case KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING:
|
case KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING:
|
||||||
updateBgPromptFgsWithNotiOnLongRunning();
|
updateBgPromptFgsWithNotiOnLongRunning();
|
||||||
break;
|
break;
|
||||||
|
case KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED:
|
||||||
|
updateBgPromptAbusiveAppToBgRestricted();
|
||||||
|
break;
|
||||||
case KEY_BG_RESTRICTION_EXEMPTED_PACKAGES:
|
case KEY_BG_RESTRICTION_EXEMPTED_PACKAGES:
|
||||||
updateBgRestrictionExemptedPackages();
|
updateBgRestrictionExemptedPackages();
|
||||||
break;
|
break;
|
||||||
@@ -1209,6 +1232,7 @@ public final class AppRestrictionController {
|
|||||||
updateBgLongFgsNotificationMinimalInterval();
|
updateBgLongFgsNotificationMinimalInterval();
|
||||||
updateBgPromptFgsWithNotiToBgRestricted();
|
updateBgPromptFgsWithNotiToBgRestricted();
|
||||||
updateBgPromptFgsWithNotiOnLongRunning();
|
updateBgPromptFgsWithNotiOnLongRunning();
|
||||||
|
updateBgPromptAbusiveAppToBgRestricted();
|
||||||
updateBgRestrictionExemptedPackages();
|
updateBgRestrictionExemptedPackages();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1251,6 +1275,13 @@ public final class AppRestrictionController {
|
|||||||
DEFAULT_BG_PROMPT_FGS_WITH_NOTIFICATION_ON_LONG_RUNNING);
|
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() {
|
private void updateBgRestrictionExemptedPackages() {
|
||||||
final String settings = DeviceConfig.getString(
|
final String settings = DeviceConfig.getString(
|
||||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||||
@@ -1290,6 +1321,10 @@ public final class AppRestrictionController {
|
|||||||
pw.print('=');
|
pw.print('=');
|
||||||
pw.println(mBgPromptFgsWithNotiToBgRestricted);
|
pw.println(mBgPromptFgsWithNotiToBgRestricted);
|
||||||
pw.print(prefix);
|
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(KEY_BG_RESTRICTION_EXEMPTED_PACKAGES);
|
||||||
pw.print('=');
|
pw.print('=');
|
||||||
pw.println(mBgRestrictionExemptedPackages.toString());
|
pw.println(mBgRestrictionExemptedPackages.toString());
|
||||||
@@ -2296,6 +2331,13 @@ public final class AppRestrictionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void postRequestBgRestrictedIfNecessary(String packageName, int uid) {
|
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);
|
final Intent intent = new Intent(Settings.ACTION_VIEW_ADVANCED_POWER_USAGE_DETAIL);
|
||||||
intent.setData(Uri.fromParts(PACKAGE_SCHEME, packageName, null));
|
intent.setData(Uri.fromParts(PACKAGE_SCHEME, packageName, null));
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
|||||||
@@ -585,6 +585,7 @@ public final class BackgroundRestrictionTest {
|
|||||||
DeviceConfigSession<Float> bgCurrentDrainRestrictedBucketThreshold = null;
|
DeviceConfigSession<Float> bgCurrentDrainRestrictedBucketThreshold = null;
|
||||||
DeviceConfigSession<Float> bgCurrentDrainBgRestrictedThreshold = null;
|
DeviceConfigSession<Float> bgCurrentDrainBgRestrictedThreshold = null;
|
||||||
DeviceConfigSession<Boolean> bgPromptFgsWithNotiToBgRestricted = null;
|
DeviceConfigSession<Boolean> bgPromptFgsWithNotiToBgRestricted = null;
|
||||||
|
DeviceConfigSession<Boolean> bgPromptAbusiveAppToBgRestricted = null;
|
||||||
DeviceConfigSession<Long> bgNotificationMinInterval = null;
|
DeviceConfigSession<Long> bgNotificationMinInterval = null;
|
||||||
DeviceConfigSession<Integer> bgBatteryExemptionTypes = null;
|
DeviceConfigSession<Integer> bgBatteryExemptionTypes = null;
|
||||||
DeviceConfigSession<Boolean> bgCurrentDrainDecoupleThresholds = null;
|
DeviceConfigSession<Boolean> bgCurrentDrainDecoupleThresholds = null;
|
||||||
@@ -642,6 +643,14 @@ public final class BackgroundRestrictionTest {
|
|||||||
R.bool.config_bg_prompt_fgs_with_noti_to_bg_restricted));
|
R.bool.config_bg_prompt_fgs_with_noti_to_bg_restricted));
|
||||||
bgPromptFgsWithNotiToBgRestricted.set(true);
|
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<>(
|
bgNotificationMinInterval = new DeviceConfigSession<>(
|
||||||
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
|
||||||
ConstantsObserver.KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL,
|
ConstantsObserver.KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL,
|
||||||
@@ -1055,6 +1064,7 @@ public final class BackgroundRestrictionTest {
|
|||||||
closeIfNotNull(bgCurrentDrainRestrictedBucketThreshold);
|
closeIfNotNull(bgCurrentDrainRestrictedBucketThreshold);
|
||||||
closeIfNotNull(bgCurrentDrainBgRestrictedThreshold);
|
closeIfNotNull(bgCurrentDrainBgRestrictedThreshold);
|
||||||
closeIfNotNull(bgPromptFgsWithNotiToBgRestricted);
|
closeIfNotNull(bgPromptFgsWithNotiToBgRestricted);
|
||||||
|
closeIfNotNull(bgPromptAbusiveAppToBgRestricted);
|
||||||
closeIfNotNull(bgNotificationMinInterval);
|
closeIfNotNull(bgNotificationMinInterval);
|
||||||
closeIfNotNull(bgBatteryExemptionTypes);
|
closeIfNotNull(bgBatteryExemptionTypes);
|
||||||
closeIfNotNull(bgCurrentDrainDecoupleThresholds);
|
closeIfNotNull(bgCurrentDrainDecoupleThresholds);
|
||||||
@@ -1613,6 +1623,7 @@ public final class BackgroundRestrictionTest {
|
|||||||
DeviceConfigSession<String> bgPermissionsInMonitor = null;
|
DeviceConfigSession<String> bgPermissionsInMonitor = null;
|
||||||
DeviceConfigSession<Boolean> bgCurrentDrainHighThresholdByBgLocation = null;
|
DeviceConfigSession<Boolean> bgCurrentDrainHighThresholdByBgLocation = null;
|
||||||
DeviceConfigSession<Boolean> bgCurrentDrainDecoupleThresholds = null;
|
DeviceConfigSession<Boolean> bgCurrentDrainDecoupleThresholds = null;
|
||||||
|
DeviceConfigSession<Boolean> bgPromptAbusiveAppToBgRestricted = null;
|
||||||
|
|
||||||
mBgRestrictionController.addAppBackgroundRestrictionListener(listener);
|
mBgRestrictionController.addAppBackgroundRestrictionListener(listener);
|
||||||
|
|
||||||
@@ -1751,6 +1762,14 @@ public final class BackgroundRestrictionTest {
|
|||||||
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_DECOUPLE_THRESHOLD);
|
AppBatteryPolicy.DEFAULT_BG_CURRENT_DRAIN_DECOUPLE_THRESHOLD);
|
||||||
bgCurrentDrainDecoupleThresholds.set(true);
|
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;
|
mCurrentTimeMillis = 10_000L;
|
||||||
doReturn(mCurrentTimeMillis - windowMs).when(stats).getStatsStartTimestamp();
|
doReturn(mCurrentTimeMillis - windowMs).when(stats).getStatsStartTimestamp();
|
||||||
doReturn(mCurrentTimeMillis).when(stats).getStatsEndTimestamp();
|
doReturn(mCurrentTimeMillis).when(stats).getStatsEndTimestamp();
|
||||||
@@ -2168,6 +2187,7 @@ public final class BackgroundRestrictionTest {
|
|||||||
closeIfNotNull(bgBatteryExemptionTypes);
|
closeIfNotNull(bgBatteryExemptionTypes);
|
||||||
closeIfNotNull(bgPermissionMonitorEnabled);
|
closeIfNotNull(bgPermissionMonitorEnabled);
|
||||||
closeIfNotNull(bgPermissionsInMonitor);
|
closeIfNotNull(bgPermissionsInMonitor);
|
||||||
|
closeIfNotNull(bgPromptAbusiveAppToBgRestricted);
|
||||||
closeIfNotNull(bgCurrentDrainHighThresholdByBgLocation);
|
closeIfNotNull(bgCurrentDrainHighThresholdByBgLocation);
|
||||||
closeIfNotNull(bgCurrentDrainDecoupleThresholds);
|
closeIfNotNull(bgCurrentDrainDecoupleThresholds);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user