Merge "Add a device config about moving abusive apps to restricted level" into tm-dev

This commit is contained in:
Jing Ji
2022-04-22 07:28:50 +00:00
committed by Android (Google) Code Review
3 changed files with 39 additions and 0 deletions

View File

@@ -1673,6 +1673,7 @@ final class AppBatteryTracker extends BaseAppStateTracker<AppBatteryPolicy>
if (pair != null) { if (pair != null) {
final long[] ts = pair.first; final long[] ts = pair.first;
final int restrictedLevel = ts[TIME_STAMP_INDEX_RESTRICTED_BUCKET] > 0 final int restrictedLevel = ts[TIME_STAMP_INDEX_RESTRICTED_BUCKET] > 0
&& mTracker.mAppRestrictionController.isAutoRestrictAbusiveAppEnabled()
? 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) {

View File

@@ -1062,6 +1062,13 @@ public final class AppRestrictionController {
static final String KEY_BG_AUTO_RESTRICTED_BUCKET_ON_BG_RESTRICTION = static final String KEY_BG_AUTO_RESTRICTED_BUCKET_ON_BG_RESTRICTION =
DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "auto_restricted_bucket_on_bg_restricted"; 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 * The minimal interval in ms before posting a notification again on abusive behaviors
* of a certain package. * of a certain package.
@@ -1106,6 +1113,11 @@ public final class AppRestrictionController {
static final String KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED = static final String KEY_BG_PROMPT_ABUSIVE_APPS_TO_BG_RESTRICTED =
DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "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}. * Default value to {@link #mBgAutoRestrictedBucket}.
*/ */
@@ -1138,6 +1150,8 @@ public final class AppRestrictionController {
volatile boolean mBgAutoRestrictedBucket; volatile boolean mBgAutoRestrictedBucket;
volatile boolean mBgAutoRestrictAbusiveApps;
volatile boolean mRestrictedBucketEnabled; volatile boolean mRestrictedBucketEnabled;
volatile long mBgAbusiveNotificationMinIntervalMs; volatile long mBgAbusiveNotificationMinIntervalMs;
@@ -1184,6 +1198,9 @@ public final class AppRestrictionController {
case KEY_BG_AUTO_RESTRICTED_BUCKET_ON_BG_RESTRICTION: case KEY_BG_AUTO_RESTRICTED_BUCKET_ON_BG_RESTRICTION:
updateBgAutoRestrictedBucketChanged(); updateBgAutoRestrictedBucketChanged();
break; break;
case KEY_BG_AUTO_RESTRICT_ABUSIVE_APPS:
updateBgAutoRestrictAbusiveApps();
break;
case KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL: case KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL:
updateBgAbusiveNotificationMinimalInterval(); updateBgAbusiveNotificationMinimalInterval();
break; break;
@@ -1232,6 +1249,7 @@ public final class AppRestrictionController {
void updateDeviceConfig() { void updateDeviceConfig() {
updateBgAutoRestrictedBucketChanged(); updateBgAutoRestrictedBucketChanged();
updateBgAutoRestrictAbusiveApps();
updateBgAbusiveNotificationMinimalInterval(); updateBgAbusiveNotificationMinimalInterval();
updateBgLongFgsNotificationMinimalInterval(); updateBgLongFgsNotificationMinimalInterval();
updateBgPromptFgsWithNotiToBgRestricted(); 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() { private void updateBgAbusiveNotificationMinimalInterval() {
mBgAbusiveNotificationMinIntervalMs = DeviceConfig.getLong( mBgAbusiveNotificationMinIntervalMs = DeviceConfig.getLong(
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER, DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
@@ -1313,6 +1338,10 @@ public final class AppRestrictionController {
pw.print('='); pw.print('=');
pw.println(mBgAutoRestrictedBucket); pw.println(mBgAutoRestrictedBucket);
pw.print(prefix); 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(KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL);
pw.print('='); pw.print('=');
pw.println(mBgAbusiveNotificationMinIntervalMs); pw.println(mBgAbusiveNotificationMinIntervalMs);
@@ -1771,6 +1800,14 @@ public final class AppRestrictionController {
return mRestrictionSettings.getRestrictionLevel(packageName, userId); 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 * @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. * 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) { @RestrictionLevel int maxLevel) {
synchronized (mLock) { synchronized (mLock) {
final int level = mExcessiveEventPkgs.get(packageName, uid) == null final int level = mExcessiveEventPkgs.get(packageName, uid) == null
|| !mTracker.mAppRestrictionController.isAutoRestrictAbusiveAppEnabled()
? RESTRICTION_LEVEL_ADAPTIVE_BUCKET ? RESTRICTION_LEVEL_ADAPTIVE_BUCKET
: RESTRICTION_LEVEL_RESTRICTED_BUCKET; : RESTRICTION_LEVEL_RESTRICTED_BUCKET;
if (maxLevel > RESTRICTION_LEVEL_RESTRICTED_BUCKET) { if (maxLevel > RESTRICTION_LEVEL_RESTRICTED_BUCKET) {