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

Commit 7c103a89 authored by Kweku Adams's avatar Kweku Adams Committed by Automerger Merge Worker
Browse files

Merge "Allow bucket elevation for timed-out restricted apps." into sc-dev am: aa8f6da7

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15004406

Change-Id: Ib7e6c9cbc4e9a934d3ac87039997afc138490cfa
parents 0c6fb492 aa8f6da7
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.usage.UsageStatsManager.REASON_MAIN_DEFAULT;
import static android.app.usage.UsageStatsManager.REASON_MAIN_FORCED_BY_USER;
import static android.app.usage.UsageStatsManager.REASON_MAIN_MASK;
import static android.app.usage.UsageStatsManager.REASON_MAIN_PREDICTED;
import static android.app.usage.UsageStatsManager.REASON_MAIN_TIMEOUT;
import static android.app.usage.UsageStatsManager.REASON_MAIN_USAGE;
import static android.app.usage.UsageStatsManager.REASON_SUB_MASK;
import static android.app.usage.UsageStatsManager.REASON_SUB_USAGE_USER_INTERACTION;
@@ -259,8 +260,10 @@ public class AppIdleHistory {
        int bucketingReason = REASON_MAIN_USAGE | usageReason;
        final boolean isUserUsage = isUserUsage(bucketingReason);

        if (appUsageHistory.currentBucket == STANDBY_BUCKET_RESTRICTED && !isUserUsage) {
            // Only user usage should bring an app out of the RESTRICTED bucket.
        if (appUsageHistory.currentBucket == STANDBY_BUCKET_RESTRICTED && !isUserUsage
                && (appUsageHistory.bucketingReason & REASON_MAIN_MASK) != REASON_MAIN_TIMEOUT) {
            // Only user usage should bring an app out of the RESTRICTED bucket, unless the app
            // just timed out into RESTRICTED.
            newBucket = STANDBY_BUCKET_RESTRICTED;
            bucketingReason = appUsageHistory.bucketingReason;
        } else {
+30 −0
Original line number Diff line number Diff line
@@ -1182,6 +1182,36 @@ public class AppStandbyControllerTests {
        assertBucket(STANDBY_BUCKET_RESTRICTED);
    }

    /**
     * Test that an app that "timed out" into the RESTRICTED bucket can be raised out by system
     * interaction.
     */
    @Test
    public void testSystemInteractionOverridesRestrictedTimeout() throws Exception {
        reportEvent(mController, USER_INTERACTION, mInjector.mElapsedRealtime, PACKAGE_1);
        assertBucket(STANDBY_BUCKET_ACTIVE);

        // Long enough that it could have timed out into RESTRICTED.
        mInjector.mElapsedRealtime += RESTRICTED_THRESHOLD * 4;
        mController.checkIdleStates(USER_ID);
        assertBucket(STANDBY_BUCKET_RESTRICTED);

        // Report system interaction.
        mInjector.mElapsedRealtime += 1000;
        reportEvent(mController, SYSTEM_INTERACTION, mInjector.mElapsedRealtime, PACKAGE_1);

        // Ensure that it's raised out of RESTRICTED for the system interaction elevation duration.
        assertBucket(STANDBY_BUCKET_ACTIVE);
        mInjector.mElapsedRealtime += 1000;
        mController.checkIdleStates(USER_ID);
        assertBucket(STANDBY_BUCKET_ACTIVE);

        // Elevation duration over. Should fall back down.
        mInjector.mElapsedRealtime += 10 * MINUTE_MS;
        mController.checkIdleStates(USER_ID);
        assertBucket(STANDBY_BUCKET_RESTRICTED);
    }

    @Test
    public void testRestrictedBucketDisabled() throws Exception {
        mInjector.mIsRestrictedBucketEnabled = false;