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

Commit 6810242c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Introduce JobScheduler quota bumps in lieu of bucket changes." into...

Merge "Introduce JobScheduler quota bumps in lieu of bucket changes." into tm-dev am: d0333d36 am: 455742b6 am: 41065cad am: 3a77ef59

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



Change-Id: I749c45a568d36033997146530c3deb4c50cf0594
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 70044984 3a77ef59
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -59,6 +59,13 @@ public interface AppStandbyInternal {
        public void onUserInteractionStarted(String packageName, @UserIdInt int userId) {
            // No-op by default
        }

        /**
         * Optional callback to inform the listener to give the app a temporary quota bump.
         */
        public void triggerTemporaryQuotaBump(String packageName, @UserIdInt int userId) {
            // No-op by default
        }
    }

    void onBootPhase(int phase);
+337 −69

File changed.

Preview size limit exceeded, changes collapsed.

+37 −0
Original line number Diff line number Diff line
@@ -289,6 +289,7 @@ public class AppStandbyController
    static final int MSG_INFORM_LISTENERS = 3;
    static final int MSG_FORCE_IDLE_STATE = 4;
    static final int MSG_CHECK_IDLE_STATES = 5;
    static final int MSG_TRIGGER_LISTENER_QUOTA_BUMP = 7;
    static final int MSG_REPORT_CONTENT_PROVIDER_USAGE = 8;
    static final int MSG_PAROLE_STATE_CHANGED = 9;
    static final int MSG_ONE_TIME_CHECK_IDLE_STATES = 10;
@@ -318,6 +319,12 @@ public class AppStandbyController
    /** The standby bucket that an app will be promoted on a notification-seen event */
    int mNotificationSeenPromotedBucket =
            ConstantsObserver.DEFAULT_NOTIFICATION_SEEN_PROMOTED_BUCKET;
    /**
     * If true, tell each {@link AppIdleStateChangeListener} to give quota bump for each
     * notification seen event.
     */
    private boolean mTriggerQuotaBumpOnNotificationSeen =
            ConstantsObserver.DEFAULT_TRIGGER_QUOTA_BUMP_ON_NOTIFICATION_SEEN;
    /** Minimum time a system update event should keep the buckets elevated. */
    long mSystemUpdateUsageTimeoutMillis = ConstantsObserver.DEFAULT_SYSTEM_UPDATE_TIMEOUT;
    /** Maximum time to wait for a prediction before using simple timeouts to downgrade buckets. */
@@ -767,6 +774,17 @@ public class AppStandbyController
                appUsage.bucketingReason, false);
    }

    /** Trigger a quota bump in the listeners. */
    private void triggerListenerQuotaBump(String packageName, int userId) {
        if (!mAppIdleEnabled) return;

        synchronized (mPackageAccessListeners) {
            for (AppIdleStateChangeListener listener : mPackageAccessListeners) {
                listener.triggerTemporaryQuotaBump(packageName, userId);
            }
        }
    }

    @VisibleForTesting
    void setChargingState(boolean isCharging) {
        if (mIsCharging != isCharging) {
@@ -1080,6 +1098,10 @@ public class AppStandbyController
        final int subReason = usageEventToSubReason(eventType);
        final int reason = REASON_MAIN_USAGE | subReason;
        if (eventType == UsageEvents.Event.NOTIFICATION_SEEN) {
            if (mTriggerQuotaBumpOnNotificationSeen) {
                mHandler.obtainMessage(MSG_TRIGGER_LISTENER_QUOTA_BUMP, userId, -1, pkg)
                        .sendToTarget();
            }
            // Notification-seen elevates to a higher bucket (depending on
            // {@link ConstantsObserver#KEY_NOTIFICATION_SEEN_PROMOTED_BUCKET}) but doesn't
            // change usage time.
@@ -2201,6 +2223,9 @@ public class AppStandbyController
        pw.print("  mNotificationSeenPromotedBucket=");
        pw.print(standbyBucketToString(mNotificationSeenPromotedBucket));
        pw.println();
        pw.print("  mTriggerQuotaBumpOnNotificationSeen=");
        pw.print(mTriggerQuotaBumpOnNotificationSeen);
        pw.println();
        pw.print("  mSlicePinnedTimeoutMillis=");
        TimeUtils.formatDuration(mSlicePinnedTimeoutMillis, pw);
        pw.println();
@@ -2597,6 +2622,10 @@ public class AppStandbyController
                    checkIdleStates(UserHandle.USER_ALL);
                    break;

                case MSG_TRIGGER_LISTENER_QUOTA_BUMP:
                    triggerListenerQuotaBump((String) msg.obj, msg.arg1);
                    break;

                case MSG_REPORT_CONTENT_PROVIDER_USAGE:
                    ContentProviderUsageRecord record = (ContentProviderUsageRecord) msg.obj;
                    reportContentProviderUsage(record.name, record.packageName, record.userId);
@@ -2683,6 +2712,8 @@ public class AppStandbyController
                "notification_seen_duration";
        private static final String KEY_NOTIFICATION_SEEN_PROMOTED_BUCKET =
                "notification_seen_promoted_bucket";
        private static final String KEY_TRIGGER_QUOTA_BUMP_ON_NOTIFICATION_SEEN =
                "trigger_quota_bump_on_notification_seen";
        private static final String KEY_SLICE_PINNED_HOLD_DURATION =
                "slice_pinned_duration";
        private static final String KEY_SYSTEM_UPDATE_HOLD_DURATION =
@@ -2742,6 +2773,7 @@ public class AppStandbyController
                COMPRESS_TIME ? 12 * ONE_MINUTE : 12 * ONE_HOUR;
        public static final int DEFAULT_NOTIFICATION_SEEN_PROMOTED_BUCKET =
                STANDBY_BUCKET_WORKING_SET;
        public static final boolean DEFAULT_TRIGGER_QUOTA_BUMP_ON_NOTIFICATION_SEEN = false;
        public static final long DEFAULT_SYSTEM_UPDATE_TIMEOUT =
                COMPRESS_TIME ? 2 * ONE_MINUTE : 2 * ONE_HOUR;
        public static final long DEFAULT_SYSTEM_INTERACTION_TIMEOUT =
@@ -2842,6 +2874,11 @@ public class AppStandbyController
                                    KEY_NOTIFICATION_SEEN_PROMOTED_BUCKET,
                                    DEFAULT_NOTIFICATION_SEEN_PROMOTED_BUCKET);
                            break;
                        case KEY_TRIGGER_QUOTA_BUMP_ON_NOTIFICATION_SEEN:
                            mTriggerQuotaBumpOnNotificationSeen = properties.getBoolean(
                                    KEY_TRIGGER_QUOTA_BUMP_ON_NOTIFICATION_SEEN,
                                    DEFAULT_TRIGGER_QUOTA_BUMP_ON_NOTIFICATION_SEEN);
                            break;
                        case KEY_SLICE_PINNED_HOLD_DURATION:
                            mSlicePinnedTimeoutMillis = properties.getLong(
                                    KEY_SLICE_PINNED_HOLD_DURATION,
+427 −3

File changed.

Preview size limit exceeded, changes collapsed.

+59 −3
Original line number Diff line number Diff line
@@ -179,7 +179,9 @@ public class AppStandbyControllerTests {
    private AppStandbyController mController;

    private CountDownLatch mStateChangedLatch = new CountDownLatch(1);
    private CountDownLatch mQuotaBumpLatch = new CountDownLatch(1);
    private String mLatchPkgName = null;
    private int mLatchUserId = -1;
    private AppIdleStateChangeListener mListener = new AppIdleStateChangeListener() {
        @Override
        public void onAppIdleStateChanged(String packageName, int userId,
@@ -188,6 +190,16 @@ public class AppStandbyControllerTests {
            if (mLatchPkgName != null && !mLatchPkgName.equals(packageName)) return;
            mStateChangedLatch.countDown();
        }

        @Override
        public void triggerTemporaryQuotaBump(String packageName, int userId) {
            // Ignore events not related to mLatchPkgName, if set.
            if ((mLatchPkgName != null && !mLatchPkgName.equals(packageName))
                    || (mLatchUserId != -1 && mLatchUserId != userId)) {
                return;
            }
            mQuotaBumpLatch.countDown();
        }
    };

    static class MyContextWrapper extends ContextWrapper {
@@ -880,20 +892,27 @@ public class AppStandbyControllerTests {
    }

    @Test
    public void testNotificationEvent() throws Exception {
    public void testNotificationEvent_bucketPromotion() throws Exception {
        mInjector.mPropertiesChangedListener
                .onPropertiesChanged(mInjector.getDeviceConfigProperties());

        reportEvent(mController, USER_INTERACTION, 0, PACKAGE_1);
        assertEquals(STANDBY_BUCKET_ACTIVE, getStandbyBucket(mController, PACKAGE_1));
        mInjector.mElapsedRealtime = 1;
        rearmQuotaBumpLatch(PACKAGE_1, USER_ID);
        reportEvent(mController, NOTIFICATION_SEEN, mInjector.mElapsedRealtime, PACKAGE_1);
        assertEquals(STANDBY_BUCKET_ACTIVE, getStandbyBucket(mController, PACKAGE_1));

        mController.forceIdleState(PACKAGE_1, USER_ID, true);
        reportEvent(mController, NOTIFICATION_SEEN, mInjector.mElapsedRealtime, PACKAGE_1);
        assertEquals(STANDBY_BUCKET_WORKING_SET, getStandbyBucket(mController, PACKAGE_1));
        assertFalse(mQuotaBumpLatch.await(1, TimeUnit.SECONDS));
    }

    @Test
    public void testNotificationEvent_changePromotedBucket() throws Exception {
    public void testNotificationEvent_bucketPromotion_changePromotedBucket() throws Exception {
        mInjector.mPropertiesChangedListener
                .onPropertiesChanged(mInjector.getDeviceConfigProperties());
        mController.forceIdleState(PACKAGE_1, USER_ID, true);
        reportEvent(mController, NOTIFICATION_SEEN, mInjector.mElapsedRealtime, PACKAGE_1);
        assertEquals(STANDBY_BUCKET_WORKING_SET, getStandbyBucket(mController, PACKAGE_1));
@@ -908,6 +927,28 @@ public class AppStandbyControllerTests {
        assertEquals(STANDBY_BUCKET_FREQUENT, getStandbyBucket(mController, PACKAGE_1));
    }

    @Test
    public void testNotificationEvent_quotaBump() throws Exception {
        mInjector.mSettingsBuilder
                .setBoolean("trigger_quota_bump_on_notification_seen", true);
        mInjector.mSettingsBuilder
                .setInt("notification_seen_promoted_bucket", STANDBY_BUCKET_NEVER);
        mInjector.mPropertiesChangedListener
                .onPropertiesChanged(mInjector.getDeviceConfigProperties());

        reportEvent(mController, USER_INTERACTION, 0, PACKAGE_1);
        assertEquals(STANDBY_BUCKET_ACTIVE, getStandbyBucket(mController, PACKAGE_1));
        mInjector.mElapsedRealtime = RARE_THRESHOLD * 2;
        setAndAssertBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_RARE, REASON_MAIN_FORCED_BY_SYSTEM);

        rearmQuotaBumpLatch(PACKAGE_1, USER_ID);
        mInjector.mElapsedRealtime += 1;

        reportEvent(mController, NOTIFICATION_SEEN, mInjector.mElapsedRealtime, PACKAGE_1);
        assertTrue(mQuotaBumpLatch.await(1, TimeUnit.SECONDS));
        assertEquals(STANDBY_BUCKET_RARE, getStandbyBucket(mController, PACKAGE_1));
    }

    @Test
    @FlakyTest(bugId = 185169504)
    public void testSlicePinnedEvent() throws Exception {
@@ -1384,6 +1425,9 @@ public class AppStandbyControllerTests {
    @Test
    @FlakyTest(bugId = 185169504)
    public void testCascadingTimeouts() throws Exception {
        mInjector.mPropertiesChangedListener
                .onPropertiesChanged(mInjector.getDeviceConfigProperties());

        reportEvent(mController, USER_INTERACTION, 0, PACKAGE_1);
        assertBucket(STANDBY_BUCKET_ACTIVE);

@@ -1408,6 +1452,9 @@ public class AppStandbyControllerTests {
    @Test
    @FlakyTest(bugId = 185169504)
    public void testOverlappingTimeouts() throws Exception {
        mInjector.mPropertiesChangedListener
                .onPropertiesChanged(mInjector.getDeviceConfigProperties());

        reportEvent(mController, USER_INTERACTION, 0, PACKAGE_1);
        assertBucket(STANDBY_BUCKET_ACTIVE);

@@ -1498,6 +1545,9 @@ public class AppStandbyControllerTests {
    @Test
    @FlakyTest(bugId = 185169504)
    public void testPredictionNotOverridden() throws Exception {
        mInjector.mPropertiesChangedListener
                .onPropertiesChanged(mInjector.getDeviceConfigProperties());

        reportEvent(mController, USER_INTERACTION, 0, PACKAGE_1);
        assertBucket(STANDBY_BUCKET_ACTIVE);

@@ -2096,7 +2146,7 @@ public class AppStandbyControllerTests {
    private void setAndAssertBucket(String pkg, int user, int bucket, int reason) throws Exception {
        rearmLatch(pkg);
        mController.setAppStandbyBucket(pkg, user, bucket, reason);
        mStateChangedLatch.await(100, TimeUnit.MILLISECONDS);
        mStateChangedLatch.await(1, TimeUnit.SECONDS);
        assertEquals("Failed to set package bucket", bucket,
                getStandbyBucket(mController, PACKAGE_1));
    }
@@ -2109,4 +2159,10 @@ public class AppStandbyControllerTests {
    private void rearmLatch() {
        rearmLatch(null);
    }

    private void rearmQuotaBumpLatch(String pkgName, int userId) {
        mLatchPkgName = pkgName;
        mLatchUserId = userId;
        mQuotaBumpLatch = new CountDownLatch(1);
    }
}