Merge "Add config for the auto restricted bucket on abusive bg battery drain" into tm-dev am: ce0daea7ca

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18338039

Change-Id: I5398053eec11c0c1439a336829f7b8fe6fcc1549
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Jing Ji
2022-05-13 18:21:08 +00:00
committed by Automerger Merge Worker
4 changed files with 72 additions and 3 deletions

View File

@@ -5754,6 +5754,14 @@
--> -->
<integer name="config_bg_current_drain_location_min_duration">1800</integer> <integer name="config_bg_current_drain_location_min_duration">1800</integer>
<!-- The behavior when the system detects it has abusive current drains, whether or not to
move the app to the restricted standby bucket level.
True - we'll move the app to restricted standby bucket as long as its bg battery usage
goes beyond the threshold, False - we'll not move it.
Note: This should be only enabled on devices with high confidence on power measurement.
-->
<bool name="config_bg_current_drain_auto_restrict_abusive_apps">false</bool>
<!-- The behavior for an app with a FGS and its notification is still showing, when the system <!-- The behavior for an app with a FGS and its notification is still showing, when the system
detects it's abusive and should be put into bg restricted level. True - we'll detects it's abusive and should be put into bg restricted level. True - we'll
show the prompt to user, False - we'll not show it. show the prompt to user, False - we'll not show it.

View File

@@ -4779,6 +4779,7 @@
<java-symbol type="array" name="config_bg_current_drain_high_threshold_to_bg_restricted" /> <java-symbol type="array" name="config_bg_current_drain_high_threshold_to_bg_restricted" />
<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_current_drain_auto_restrict_abusive_apps" />
<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="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" />

View File

@@ -1257,6 +1257,16 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
DEVICE_CONFIG_SUBNAMESPACE_PREFIX DEVICE_CONFIG_SUBNAMESPACE_PREFIX
+ "current_drain_event_duration_based_threshold_enabled"; + "current_drain_event_duration_based_threshold_enabled";
/**
* Whether or not we should move the app into the restricted bucket level if its background
* battery usage goes beyond the threshold. Note this different from the flag
* {@link AppRestrictionController.ConstantsObserver#KEY_BG_AUTO_RESTRICT_ABUSIVE_APPS}
* which is to control the overall auto bg restrictions.
*/
static final String KEY_BG_CURRENT_DRAIN_AUTO_RESTRICT_ABUSIVE_APPS_ENABLED =
DEVICE_CONFIG_SUBNAMESPACE_PREFIX
+ "current_drain_auto_restrict_abusive_apps_enabled";
/** /**
* The types of battery drain we're checking on each app; if the sum of the battery drain * The types of battery drain we're checking on each app; if the sum of the battery drain
* exceeds the threshold, it'll be moved to restricted standby bucket; the type here * exceeds the threshold, it'll be moved to restricted standby bucket; the type here
@@ -1352,6 +1362,11 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
*/ */
final boolean mDefaultBgCurrentDrainEventDurationBasedThresholdEnabled; final boolean mDefaultBgCurrentDrainEventDurationBasedThresholdEnabled;
/**
* Default value to {@link #mBgCurrentDrainAutoRestrictAbusiveAppsEnabled}.
*/
final boolean mDefaultBgCurrentDrainAutoRestrictAbusiveAppsEnabled;
/** /**
* Default value to {@link #mBgCurrentDrainRestrictedBucketTypes}. * Default value to {@link #mBgCurrentDrainRestrictedBucketTypes}.
*/ */
@@ -1429,6 +1444,11 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
*/ */
volatile boolean mBgCurrentDrainEventDurationBasedThresholdEnabled; volatile boolean mBgCurrentDrainEventDurationBasedThresholdEnabled;
/**
* @see #KEY_BG_CURRENT_DRAIN_AUTO_RESTRICT_ABUSIVE_APPS_ENABLED.
*/
volatile boolean mBgCurrentDrainAutoRestrictAbusiveAppsEnabled;
/** /**
* @see #KEY_BG_CURRENT_DRAIN_TYPES_TO_RESTRICTED_BUCKET. * @see #KEY_BG_CURRENT_DRAIN_TYPES_TO_RESTRICTED_BUCKET.
*/ */
@@ -1520,6 +1540,8 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
R.integer.config_bg_current_drain_location_min_duration) * 1_000; R.integer.config_bg_current_drain_location_min_duration) * 1_000;
mDefaultBgCurrentDrainEventDurationBasedThresholdEnabled = resources.getBoolean( mDefaultBgCurrentDrainEventDurationBasedThresholdEnabled = resources.getBoolean(
R.bool.config_bg_current_drain_event_duration_based_threshold_enabled); R.bool.config_bg_current_drain_event_duration_based_threshold_enabled);
mDefaultBgCurrentDrainAutoRestrictAbusiveAppsEnabled = resources.getBoolean(
R.bool.config_bg_current_drain_auto_restrict_abusive_apps);
mDefaultCurrentDrainTypesToRestrictedBucket = resources.getInteger( mDefaultCurrentDrainTypesToRestrictedBucket = resources.getInteger(
R.integer.config_bg_current_drain_types_to_restricted_bucket); R.integer.config_bg_current_drain_types_to_restricted_bucket);
mDefaultBgCurrentDrainTypesToBgRestricted = resources.getInteger( mDefaultBgCurrentDrainTypesToBgRestricted = resources.getInteger(
@@ -1569,6 +1591,9 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
case KEY_BG_CURRENT_DRAIN_POWER_COMPONENTS: case KEY_BG_CURRENT_DRAIN_POWER_COMPONENTS:
updateCurrentDrainThreshold(); updateCurrentDrainThreshold();
break; break;
case KEY_BG_CURRENT_DRAIN_AUTO_RESTRICT_ABUSIVE_APPS_ENABLED:
updateBgCurrentDrainAutoRestrictAbusiveAppsEnabled();
break;
case KEY_BG_CURRENT_DRAIN_WINDOW: case KEY_BG_CURRENT_DRAIN_WINDOW:
updateCurrentDrainWindow(); updateCurrentDrainWindow();
break; break;
@@ -1701,6 +1726,13 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
DEFAULT_BG_CURRENT_DRAIN_DECOUPLE_THRESHOLD); DEFAULT_BG_CURRENT_DRAIN_DECOUPLE_THRESHOLD);
} }
private void updateBgCurrentDrainAutoRestrictAbusiveAppsEnabled() {
mBgCurrentDrainAutoRestrictAbusiveAppsEnabled = DeviceConfig.getBoolean(
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
KEY_BG_CURRENT_DRAIN_AUTO_RESTRICT_ABUSIVE_APPS_ENABLED,
mDefaultBgCurrentDrainAutoRestrictAbusiveAppsEnabled);
}
@Override @Override
public void onSystemReady() { public void onSystemReady() {
mBatteryFullChargeMah = mBatteryFullChargeMah =
@@ -1714,6 +1746,7 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
updateCurrentDrainEventDurationBasedThresholdEnabled(); updateCurrentDrainEventDurationBasedThresholdEnabled();
updateCurrentDrainExemptedTypes(); updateCurrentDrainExemptedTypes();
updateCurrentDrainDecoupleThresholds(); updateCurrentDrainDecoupleThresholds();
updateBgCurrentDrainAutoRestrictAbusiveAppsEnabled();
} }
@Override @Override
@@ -1728,9 +1761,12 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
if (pair != null) { if (pair != null) {
final long lastInteractionTime = mLastInteractionTime.get(uid, 0L); final long lastInteractionTime = mLastInteractionTime.get(uid, 0L);
final long[] ts = pair.first; final long[] ts = pair.first;
final int restrictedLevel = ts[TIME_STAMP_INDEX_RESTRICTED_BUCKET] final boolean noInteractionRecently = ts[TIME_STAMP_INDEX_RESTRICTED_BUCKET]
> (lastInteractionTime + mBgCurrentDrainInteractionGracePeriodMs) > (lastInteractionTime + mBgCurrentDrainInteractionGracePeriodMs);
&& mTracker.mAppRestrictionController.isAutoRestrictAbusiveAppEnabled() final boolean canRestrict =
mTracker.mAppRestrictionController.isAutoRestrictAbusiveAppEnabled()
&& mBgCurrentDrainAutoRestrictAbusiveAppsEnabled;
final int restrictedLevel = noInteractionRecently && canRestrict
? RESTRICTION_LEVEL_RESTRICTED_BUCKET ? RESTRICTION_LEVEL_RESTRICTED_BUCKET
: RESTRICTION_LEVEL_ADAPTIVE_BUCKET; : RESTRICTION_LEVEL_ADAPTIVE_BUCKET;
if (maxLevel > RESTRICTION_LEVEL_BACKGROUND_RESTRICTED) { if (maxLevel > RESTRICTION_LEVEL_BACKGROUND_RESTRICTED) {
@@ -2066,6 +2102,10 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
pw.print('='); pw.print('=');
pw.println(mBgCurrentDrainEventDurationBasedThresholdEnabled); pw.println(mBgCurrentDrainEventDurationBasedThresholdEnabled);
pw.print(prefix); pw.print(prefix);
pw.print(KEY_BG_CURRENT_DRAIN_AUTO_RESTRICT_ABUSIVE_APPS_ENABLED);
pw.print('=');
pw.println(mBgCurrentDrainAutoRestrictAbusiveAppsEnabled);
pw.print(prefix);
pw.print(KEY_BG_CURRENT_DRAIN_TYPES_TO_RESTRICTED_BUCKET); pw.print(KEY_BG_CURRENT_DRAIN_TYPES_TO_RESTRICTED_BUCKET);
pw.print('='); pw.print('=');
pw.println(batteryUsageTypesToString(mBgCurrentDrainRestrictedBucketTypes)); pw.println(batteryUsageTypesToString(mBgCurrentDrainRestrictedBucketTypes));

View File

@@ -585,6 +585,7 @@ public final class BackgroundRestrictionTest {
DeviceConfigSession<Long> bgCurrentDrainInteractionGracePeriod = null; DeviceConfigSession<Long> bgCurrentDrainInteractionGracePeriod = null;
DeviceConfigSession<Float> bgCurrentDrainRestrictedBucketThreshold = null; DeviceConfigSession<Float> bgCurrentDrainRestrictedBucketThreshold = null;
DeviceConfigSession<Float> bgCurrentDrainBgRestrictedThreshold = null; DeviceConfigSession<Float> bgCurrentDrainBgRestrictedThreshold = null;
DeviceConfigSession<Boolean> bgCurrentDrainAutoRestrictAbusiveApps = null;
DeviceConfigSession<Boolean> bgPromptFgsWithNotiToBgRestricted = null; DeviceConfigSession<Boolean> bgPromptFgsWithNotiToBgRestricted = null;
DeviceConfigSession<Boolean> bgPromptAbusiveAppToBgRestricted = null; DeviceConfigSession<Boolean> bgPromptAbusiveAppToBgRestricted = null;
DeviceConfigSession<Long> bgNotificationMinInterval = null; DeviceConfigSession<Long> bgNotificationMinInterval = null;
@@ -644,6 +645,14 @@ public final class BackgroundRestrictionTest {
isLowRamDeviceStatic() ? 1 : 0]); isLowRamDeviceStatic() ? 1 : 0]);
bgCurrentDrainBgRestrictedThreshold.set(bgRestrictedThreshold); bgCurrentDrainBgRestrictedThreshold.set(bgRestrictedThreshold);
bgCurrentDrainAutoRestrictAbusiveApps = new DeviceConfigSession<>(
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_AUTO_RESTRICT_ABUSIVE_APPS_ENABLED,
DeviceConfig::getBoolean,
mContext.getResources().getBoolean(
R.bool.config_bg_current_drain_auto_restrict_abusive_apps));
bgCurrentDrainAutoRestrictAbusiveApps.set(true);
bgPromptFgsWithNotiToBgRestricted = new DeviceConfigSession<>( bgPromptFgsWithNotiToBgRestricted = new DeviceConfigSession<>(
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
ConstantsObserver.KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_TO_BG_RESTRICTED, ConstantsObserver.KEY_BG_PROMPT_FGS_WITH_NOTIFICATION_TO_BG_RESTRICTED,
@@ -1099,6 +1108,7 @@ public final class BackgroundRestrictionTest {
closeIfNotNull(bgCurrentDrainInteractionGracePeriod); closeIfNotNull(bgCurrentDrainInteractionGracePeriod);
closeIfNotNull(bgCurrentDrainRestrictedBucketThreshold); closeIfNotNull(bgCurrentDrainRestrictedBucketThreshold);
closeIfNotNull(bgCurrentDrainBgRestrictedThreshold); closeIfNotNull(bgCurrentDrainBgRestrictedThreshold);
closeIfNotNull(bgCurrentDrainAutoRestrictAbusiveApps);
closeIfNotNull(bgPromptFgsWithNotiToBgRestricted); closeIfNotNull(bgPromptFgsWithNotiToBgRestricted);
closeIfNotNull(bgPromptAbusiveAppToBgRestricted); closeIfNotNull(bgPromptAbusiveAppToBgRestricted);
closeIfNotNull(bgNotificationMinInterval); closeIfNotNull(bgNotificationMinInterval);
@@ -1651,6 +1661,7 @@ public final class BackgroundRestrictionTest {
DeviceConfigSession<Float> bgCurrentDrainBgRestrictedThreshold = null; DeviceConfigSession<Float> bgCurrentDrainBgRestrictedThreshold = null;
DeviceConfigSession<Float> bgCurrentDrainRestrictedBucketHighThreshold = null; DeviceConfigSession<Float> bgCurrentDrainRestrictedBucketHighThreshold = null;
DeviceConfigSession<Float> bgCurrentDrainBgRestrictedHighThreshold = null; DeviceConfigSession<Float> bgCurrentDrainBgRestrictedHighThreshold = null;
DeviceConfigSession<Boolean> bgCurrentDrainAutoRestrictAbusiveApps = null;
DeviceConfigSession<Long> bgMediaPlaybackMinDurationThreshold = null; DeviceConfigSession<Long> bgMediaPlaybackMinDurationThreshold = null;
DeviceConfigSession<Long> bgLocationMinDurationThreshold = null; DeviceConfigSession<Long> bgLocationMinDurationThreshold = null;
DeviceConfigSession<Boolean> bgCurrentDrainEventDurationBasedThresholdEnabled = null; DeviceConfigSession<Boolean> bgCurrentDrainEventDurationBasedThresholdEnabled = null;
@@ -1736,6 +1747,14 @@ public final class BackgroundRestrictionTest {
isLowRamDeviceStatic() ? 1 : 0]); isLowRamDeviceStatic() ? 1 : 0]);
bgCurrentDrainBgRestrictedHighThreshold.set(bgRestrictedHighThreshold); bgCurrentDrainBgRestrictedHighThreshold.set(bgRestrictedHighThreshold);
bgCurrentDrainAutoRestrictAbusiveApps = new DeviceConfigSession<>(
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_AUTO_RESTRICT_ABUSIVE_APPS_ENABLED,
DeviceConfig::getBoolean,
mContext.getResources().getBoolean(
R.bool.config_bg_current_drain_auto_restrict_abusive_apps));
bgCurrentDrainAutoRestrictAbusiveApps.set(true);
bgMediaPlaybackMinDurationThreshold = new DeviceConfigSession<>( bgMediaPlaybackMinDurationThreshold = new DeviceConfigSession<>(
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_MEDIA_PLAYBACK_MIN_DURATION, AppBatteryPolicy.KEY_BG_CURRENT_DRAIN_MEDIA_PLAYBACK_MIN_DURATION,
@@ -2226,6 +2245,7 @@ public final class BackgroundRestrictionTest {
closeIfNotNull(bgCurrentDrainBgRestrictedThreshold); closeIfNotNull(bgCurrentDrainBgRestrictedThreshold);
closeIfNotNull(bgCurrentDrainRestrictedBucketHighThreshold); closeIfNotNull(bgCurrentDrainRestrictedBucketHighThreshold);
closeIfNotNull(bgCurrentDrainBgRestrictedHighThreshold); closeIfNotNull(bgCurrentDrainBgRestrictedHighThreshold);
closeIfNotNull(bgCurrentDrainAutoRestrictAbusiveApps);
closeIfNotNull(bgMediaPlaybackMinDurationThreshold); closeIfNotNull(bgMediaPlaybackMinDurationThreshold);
closeIfNotNull(bgLocationMinDurationThreshold); closeIfNotNull(bgLocationMinDurationThreshold);
closeIfNotNull(bgCurrentDrainEventDurationBasedThresholdEnabled); closeIfNotNull(bgCurrentDrainEventDurationBasedThresholdEnabled);