summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Kweku Adams <kwekua@google.com> 2020-04-08 14:56:46 -0700
committer Kweku Adams <kwekua@google.com> 2020-04-08 14:56:46 -0700
commit54391335505f27c93c7baada2b6eb0c955a8f330 (patch)
treea0a3f79c98e1852500428dcc67ea52ebdeff7f72
parentedb826c298b525a3a13678db27e8e25c6c579a6d (diff)
Drop down late RARE prediction into RESTRICTED.
When an app hasn't been used in a long time (long enough for it to have naturally time out into the RESTRICTED bucket) and a prediction service anticipates that an app will not be used anytime soon (by predicting the app into the RARE bucket), then we drop the app into the RESTRICTED bucket in such a way that the prediction service can bring it back out at the appropriate time. Bug: 153567783 Test: atest FrameworksServicesTests:AppIdleHistoryTests Test: atest FrameworksServicesTests:AppStandbyControllerTests Change-Id: I0ec846a6d1bc8e254cabe6a9b504f4cae071def8
-rw-r--r--apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java13
-rw-r--r--services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java63
2 files changed, 76 insertions, 0 deletions
diff --git a/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java b/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java
index b6f85b2d06bf..1ab79380fb0d 100644
--- a/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java
+++ b/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java
@@ -1364,6 +1364,19 @@ public class AppStandbyController implements AppStandbyInternal {
if (DEBUG) {
Slog.d(TAG, " Keeping at WORKING_SET due to min timeout");
}
+ } else if (newBucket == STANDBY_BUCKET_RARE
+ && getBucketForLocked(packageName, userId, elapsedRealtime)
+ == STANDBY_BUCKET_RESTRICTED) {
+ // Prediction doesn't think the app will be used anytime soon and
+ // it's been long enough that it could just time out into restricted,
+ // so time it out there instead. Using TIMEOUT will allow prediction
+ // to raise the bucket when it needs to.
+ newBucket = STANDBY_BUCKET_RESTRICTED;
+ reason = REASON_MAIN_TIMEOUT;
+ if (DEBUG) {
+ Slog.d(TAG,
+ "Prediction to RARE overridden by timeout into RESTRICTED");
+ }
}
}
diff --git a/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java b/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
index 327cfc74dac5..39062f017a73 100644
--- a/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
+++ b/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
@@ -818,6 +818,69 @@ public class AppStandbyControllerTests {
assertBucket(STANDBY_BUCKET_RESTRICTED);
}
+ /**
+ * Test that an app is "timed out" into the RESTRICTED bucket if prediction tries to put it into
+ * a low bucket after the RESTRICTED timeout.
+ */
+ @Test
+ public void testRestrictedTimeoutOverridesRestoredLowBucketPrediction() {
+ reportEvent(mController, USER_INTERACTION, mInjector.mElapsedRealtime, PACKAGE_1);
+ assertBucket(STANDBY_BUCKET_ACTIVE);
+
+ // Predict to RARE Not long enough to time out into RESTRICTED.
+ mInjector.mElapsedRealtime += RARE_THRESHOLD;
+ mController.setAppStandbyBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_RARE,
+ REASON_MAIN_PREDICTED);
+ assertBucket(STANDBY_BUCKET_RARE);
+
+ // Add a short timeout event
+ mInjector.mElapsedRealtime += 1000;
+ reportEvent(mController, SYSTEM_INTERACTION, mInjector.mElapsedRealtime, PACKAGE_1);
+ assertBucket(STANDBY_BUCKET_ACTIVE);
+ mInjector.mElapsedRealtime += 1000;
+ mController.checkIdleStates(USER_ID);
+ assertBucket(STANDBY_BUCKET_ACTIVE);
+
+ // Long enough that it could have timed out into RESTRICTED. Instead of reverting to
+ // predicted RARE, should go into RESTRICTED
+ mInjector.mElapsedRealtime += RESTRICTED_THRESHOLD * 4;
+ mController.checkIdleStates(USER_ID);
+ assertBucket(STANDBY_BUCKET_RESTRICTED);
+
+ // Ensure that prediction can still raise it out despite this override.
+ mInjector.mElapsedRealtime += 1;
+ mController.setAppStandbyBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_ACTIVE,
+ REASON_MAIN_PREDICTED);
+ assertBucket(STANDBY_BUCKET_ACTIVE);
+ }
+
+ /**
+ * Test that an app is "timed out" into the RESTRICTED bucket if prediction tries to put it into
+ * a low bucket after the RESTRICTED timeout.
+ */
+ @Test
+ public void testRestrictedTimeoutOverridesPredictionLowBucket() {
+ reportEvent(mController, USER_INTERACTION, mInjector.mElapsedRealtime, PACKAGE_1);
+
+ // Not long enough to time out into RESTRICTED.
+ mInjector.mElapsedRealtime += RARE_THRESHOLD;
+ mController.setAppStandbyBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_RARE,
+ REASON_MAIN_PREDICTED);
+ assertBucket(STANDBY_BUCKET_RARE);
+
+ mInjector.mElapsedRealtime += 1;
+ reportEvent(mController, USER_INTERACTION, mInjector.mElapsedRealtime, PACKAGE_1);
+
+ // Long enough that it could have timed out into RESTRICTED.
+ mInjector.mElapsedRealtime += RESTRICTED_THRESHOLD * 4;
+ mController.setAppStandbyBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_ACTIVE,
+ REASON_MAIN_PREDICTED);
+ assertBucket(STANDBY_BUCKET_ACTIVE);
+ mController.setAppStandbyBucket(PACKAGE_1, USER_ID, STANDBY_BUCKET_RARE,
+ REASON_MAIN_PREDICTED);
+ assertBucket(STANDBY_BUCKET_RESTRICTED);
+ }
+
@Test
public void testPredictionRaiseFromRestrictedTimeout_highBucket() {
reportEvent(mController, USER_INTERACTION, mInjector.mElapsedRealtime, PACKAGE_1);