Loading apex/jobscheduler/service/java/com/android/server/usage/AppIdleHistory.java +5 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 { Loading services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java +30 −0 Original line number Diff line number Diff line Loading @@ -1179,6 +1179,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; Loading Loading
apex/jobscheduler/service/java/com/android/server/usage/AppIdleHistory.java +5 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 { Loading
services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java +30 −0 Original line number Diff line number Diff line Loading @@ -1179,6 +1179,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; Loading