Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1360cb8a authored by Jing Ji's avatar Jing Ji Committed by Android (Google) Code Review
Browse files

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

parents b1b3e3fb 7ed4be8e
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -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) {
+17 −0
Original line number Diff line number Diff line
@@ -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;