Allow bucket elevation for timed-out restricted apps.

Ensure SYSTEM_INTERACTION can bring an app out of the RESTRICTED bucket
(temporarily) if the app is only in the bucket due to timeout.

Bug: 191297958
Test: atest AppStandbyControllerTests
Change-Id: Ie76d224710228a8654d4d57ee0c73bb9441ef28f
This commit is contained in:
Kweku Adams
2021-06-16 15:39:20 -07:00
parent cf3e019bee
commit 183ec609e8
2 changed files with 35 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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;