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

Commit dbc78eeb authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Allow standby timeouts to occur after usage"

parents 7b1ed775 84cd7b7a
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -118,7 +118,15 @@ public abstract class UsageStatsManagerInternal {
            AppIdleStateChangeListener listener);

    public static abstract class AppIdleStateChangeListener {
        public abstract void onAppIdleStateChanged(String packageName, int userId, boolean idle);

        /** Callback to inform listeners that the idle state has changed to a new bucket. */
        public abstract void onAppIdleStateChanged(String packageName, int userId, boolean idle,
                                                   int bucket);

        /**
         * Callback to inform listeners that the parole state has changed. This means apps are
         * allowed to do work even if they're idle or in a low bucket.
         */
        public abstract void onParoleStateChanged(boolean isParoleOn);
    }

+1 −1
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ public final class AppIdleController extends StateController {
    private final class AppIdleStateChangeListener
            extends UsageStatsManagerInternal.AppIdleStateChangeListener {
        @Override
        public void onAppIdleStateChanged(String packageName, int userId, boolean idle) {
        public void onAppIdleStateChanged(String packageName, int userId, boolean idle, int bucket) {
            boolean changed = false;
            synchronized (mLock) {
                if (mAppIdleParoleOn) {
+1 −1
Original line number Diff line number Diff line
@@ -3746,7 +3746,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
            extends UsageStatsManagerInternal.AppIdleStateChangeListener {

        @Override
        public void onAppIdleStateChanged(String packageName, int userId, boolean idle) {
        public void onAppIdleStateChanged(String packageName, int userId, boolean idle, int bucket) {
            try {
                final int uid = mContext.getPackageManager().getPackageUidAsUser(packageName,
                        PackageManager.MATCH_UNINSTALLED_PACKAGES, userId);
+6 −4
Original line number Diff line number Diff line
@@ -16,16 +16,14 @@

package com.android.server.usage;

import static android.app.usage.AppStandby.REASON_TIMEOUT;
import static android.app.usage.AppStandby.STANDBY_BUCKET_ACTIVE;
import static android.app.usage.AppStandby.STANDBY_BUCKET_RARE;

import android.app.usage.AppStandby;
import android.os.FileUtils;
import android.test.AndroidTestCase;

import java.io.File;

import static android.app.usage.AppStandby.*;

public class AppIdleHistoryTests extends AndroidTestCase {

    File mStorageDir;
@@ -111,5 +109,9 @@ public class AppIdleHistoryTests extends AndroidTestCase {
        assertEquals(aih.getAppStandbyBucket(PACKAGE_1, USER_ID, 5000), STANDBY_BUCKET_RARE);
        assertEquals(aih.getAppStandbyBucket(PACKAGE_2, USER_ID, 5000), STANDBY_BUCKET_ACTIVE);
        assertEquals(aih.getAppStandbyReason(PACKAGE_1, USER_ID, 5000), REASON_TIMEOUT);

        assertTrue(aih.shouldInformListeners(PACKAGE_1, USER_ID, 5000, STANDBY_BUCKET_RARE));
        assertFalse(aih.shouldInformListeners(PACKAGE_1, USER_ID, 5000, STANDBY_BUCKET_RARE));
        assertTrue(aih.shouldInformListeners(PACKAGE_1, USER_ID, 5000, STANDBY_BUCKET_FREQUENT));
    }
}
 No newline at end of file
+18 −10
Original line number Diff line number Diff line
@@ -16,11 +16,7 @@

package com.android.server.usage;

import static android.app.usage.AppStandby.STANDBY_BUCKET_ACTIVE;
import static android.app.usage.AppStandby.STANDBY_BUCKET_FREQUENT;
import static android.app.usage.AppStandby.STANDBY_BUCKET_RARE;
import static android.app.usage.AppStandby.STANDBY_BUCKET_WORKING_SET;

import static android.app.usage.AppStandby.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -251,10 +247,22 @@ public class AppStandbyControllerTests {
                        false));
    }

    private void reportEvent(AppStandbyController controller, long elapsedTime) {
        // Back to ACTIVE on event
        UsageEvents.Event ev = new UsageEvents.Event();
        ev.mPackage = PACKAGE_1;
        ev.mEventType = UsageEvents.Event.USER_INTERACTION;
        controller.reportEvent(ev, elapsedTime, USER_ID);
    }

    @Test
    public void testBuckets() throws Exception {
        AppStandbyController controller = setupController();

        assertTimeout(controller, 0, STANDBY_BUCKET_NEVER);

        reportEvent(controller, 0);

        // ACTIVE bucket
        assertTimeout(controller, 11 * HOUR_MS, STANDBY_BUCKET_ACTIVE);

@@ -270,11 +278,7 @@ public class AppStandbyControllerTests {
        // RARE bucket
        assertTimeout(controller, 9 * DAY_MS, STANDBY_BUCKET_RARE);

        // Back to ACTIVE on event
        UsageEvents.Event ev = new UsageEvents.Event();
        ev.mPackage = PACKAGE_1;
        ev.mEventType = UsageEvents.Event.USER_INTERACTION;
        controller.reportEvent(ev, mInjector.mElapsedRealtime, USER_ID);
        reportEvent(controller, 9 * DAY_MS);

        assertTimeout(controller, 9 * DAY_MS, STANDBY_BUCKET_ACTIVE);

@@ -287,6 +291,10 @@ public class AppStandbyControllerTests {
        AppStandbyController controller = setupController();
        mInjector.setDisplayOn(false);

        assertTimeout(controller, 0, STANDBY_BUCKET_NEVER);

        reportEvent(controller, 0);

        // ACTIVE bucket
        assertTimeout(controller, 11 * HOUR_MS, STANDBY_BUCKET_ACTIVE);

Loading