Loading services/core/java/com/android/server/am/AppRestrictionController.java +5 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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. Loading @@ -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) { Loading services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading
services/core/java/com/android/server/am/AppRestrictionController.java +5 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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. Loading @@ -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) { Loading
services/tests/mockingservicestests/src/com/android/server/am/BackgroundRestrictionTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading