Add a device config about moving abusive apps to restricted level

Bug: 203105544
Test: Manual - toggle the flag in device_config
Change-Id: I69fab1de00c9a02beea517252fb6dd4706c608e1
This commit is contained in:
Jing Ji
2022-04-21 16:31:55 -07:00
parent 04b94c550d
commit c75fdad219
3 changed files with 39 additions and 0 deletions

View File

@@ -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) {

View File

@@ -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.
@@ -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}.
*/
@@ -1138,6 +1150,8 @@ public final class AppRestrictionController {
volatile boolean mBgAutoRestrictedBucket;
volatile boolean mBgAutoRestrictAbusiveApps;
volatile boolean mRestrictedBucketEnabled;
volatile long mBgAbusiveNotificationMinIntervalMs;
@@ -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;
@@ -1232,6 +1249,7 @@ public final class AppRestrictionController {
void updateDeviceConfig() {
updateBgAutoRestrictedBucketChanged();
updateBgAutoRestrictAbusiveApps();
updateBgAbusiveNotificationMinimalInterval();
updateBgLongFgsNotificationMinimalInterval();
updateBgPromptFgsWithNotiToBgRestricted();
@@ -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,
@@ -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);
@@ -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.

View File

@@ -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) {