diff --git a/services/core/java/com/android/server/am/AppRestrictionController.java b/services/core/java/com/android/server/am/AppRestrictionController.java index 465623f800c58..8cff13e88fd28 100644 --- a/services/core/java/com/android/server/am/AppRestrictionController.java +++ b/services/core/java/com/android/server/am/AppRestrictionController.java @@ -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) { diff --git a/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java b/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java index 3489b3ba841fd..a112bafbe4f94 100644 --- a/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java @@ -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 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;