Set the auto restricted standby bucket on bg restriction OFF by default

Bug: 200326767
Bug: 217964313
Test: atest CtsJobSchedulerTestCases
Test: atest CtsAlarmManagerTestCases
Test: atest FrameworksMockingServicesTests
Change-Id: I7fae6339fdfab3396159e24eb2f4f9f937223cad
This commit is contained in:
Jing Ji
2022-02-05 17:31:59 -08:00
parent c871906b60
commit 7ed4be8e91
2 changed files with 22 additions and 4 deletions

View File

@@ -546,7 +546,7 @@ public final class AppRestrictionController {
static final String KEY_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL =
DEVICE_CONFIG_SUBNAMESPACE_PREFIX + "abusive_notification_minimal_interval";
static final boolean DEFAULT_BG_AUTO_RESTRICTED_BUCKET_ON_BG_RESTRICTION = true;
static final boolean DEFAULT_BG_AUTO_RESTRICTED_BUCKET_ON_BG_RESTRICTION = false;
static final long DEFAULT_BG_ABUSIVE_NOTIFICATION_MINIMAL_INTERVAL_MS = 24 * 60 * 60 * 1000;
volatile boolean mBgAutoRestrictedBucket;
@@ -1136,8 +1136,7 @@ public final class AppRestrictionController {
final AppStandbyInternal appStandbyInternal = mInjector.getAppStandbyInternal();
if (level >= RESTRICTION_LEVEL_RESTRICTED_BUCKET
&& curLevel < RESTRICTION_LEVEL_RESTRICTED_BUCKET) {
if (!mConstantsObserver.mRestrictedBucketEnabled
|| !mConstantsObserver.mBgAutoRestrictedBucket) {
if (!mConstantsObserver.mRestrictedBucketEnabled) {
return;
}
// Moving the app standby bucket to restricted in the meanwhile.
@@ -1146,7 +1145,9 @@ public final class AppRestrictionController {
Slog.i(TAG, pkgName + "/" + UserHandle.formatUid(uid)
+ " is bg-restricted, moving to restricted standby bucket");
}
if (curBucket != STANDBY_BUCKET_RESTRICTED) {
if (curBucket != STANDBY_BUCKET_RESTRICTED
&& (mConstantsObserver.mBgAutoRestrictedBucket
|| level == RESTRICTION_LEVEL_RESTRICTED_BUCKET)) {
// restrict the app if it hasn't done so.
boolean doIt = true;
synchronized (mLock) {

View File

@@ -117,6 +117,7 @@ import com.android.server.am.AppBindServiceEventsTracker.AppBindServiceEventsPol
import com.android.server.am.AppBroadcastEventsTracker.AppBroadcastEventsPolicy;
import com.android.server.am.AppFGSTracker.AppFGSPolicy;
import com.android.server.am.AppMediaSessionTracker.AppMediaSessionPolicy;
import com.android.server.am.AppRestrictionController.ConstantsObserver;
import com.android.server.am.AppRestrictionController.NotificationHelper;
import com.android.server.am.AppRestrictionController.UidBatteryUsageProvider;
import com.android.server.am.BaseAppStateTimeEvents.BaseTimeEvent;
@@ -350,6 +351,22 @@ public final class BackgroundRestrictionTest {
@Test
public void testTogglingBackgroundRestrict() throws Exception {
DeviceConfigSession<Boolean> bgAutoRestrictedBucketOnBgRestriction = null;
try {
bgAutoRestrictedBucketOnBgRestriction = new DeviceConfigSession<>(
DeviceConfig.NAMESPACE_ACTIVITY_MANAGER,
ConstantsObserver.KEY_BG_AUTO_RESTRICTED_BUCKET_ON_BG_RESTRICTION,
DeviceConfig::getBoolean,
ConstantsObserver.DEFAULT_BG_AUTO_RESTRICTED_BUCKET_ON_BG_RESTRICTION);
bgAutoRestrictedBucketOnBgRestriction.set(true);
testTogglingBackgroundRestrictInternal();
} finally {
closeIfNotNull(bgAutoRestrictedBucketOnBgRestriction);
}
}
private void testTogglingBackgroundRestrictInternal() throws Exception {
final int testPkgIndex = 2;
final String testPkgName = TEST_PACKAGE_BASE + testPkgIndex;
final int testUser = TEST_USER0;