Merge "Allow bucket elevation for timed-out restricted apps." into sc-dev
This commit is contained in:
@@ -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_FORCED_BY_USER;
|
||||||
import static android.app.usage.UsageStatsManager.REASON_MAIN_MASK;
|
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_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_MAIN_USAGE;
|
||||||
import static android.app.usage.UsageStatsManager.REASON_SUB_MASK;
|
import static android.app.usage.UsageStatsManager.REASON_SUB_MASK;
|
||||||
import static android.app.usage.UsageStatsManager.REASON_SUB_USAGE_USER_INTERACTION;
|
import static android.app.usage.UsageStatsManager.REASON_SUB_USAGE_USER_INTERACTION;
|
||||||
@@ -259,8 +260,10 @@ public class AppIdleHistory {
|
|||||||
int bucketingReason = REASON_MAIN_USAGE | usageReason;
|
int bucketingReason = REASON_MAIN_USAGE | usageReason;
|
||||||
final boolean isUserUsage = isUserUsage(bucketingReason);
|
final boolean isUserUsage = isUserUsage(bucketingReason);
|
||||||
|
|
||||||
if (appUsageHistory.currentBucket == STANDBY_BUCKET_RESTRICTED && !isUserUsage) {
|
if (appUsageHistory.currentBucket == STANDBY_BUCKET_RESTRICTED && !isUserUsage
|
||||||
// Only user usage should bring an app out of the RESTRICTED bucket.
|
&& (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;
|
newBucket = STANDBY_BUCKET_RESTRICTED;
|
||||||
bucketingReason = appUsageHistory.bucketingReason;
|
bucketingReason = appUsageHistory.bucketingReason;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1179,6 +1179,36 @@ public class AppStandbyControllerTests {
|
|||||||
assertBucket(STANDBY_BUCKET_RESTRICTED);
|
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
|
@Test
|
||||||
public void testRestrictedBucketDisabled() throws Exception {
|
public void testRestrictedBucketDisabled() throws Exception {
|
||||||
mInjector.mIsRestrictedBucketEnabled = false;
|
mInjector.mIsRestrictedBucketEnabled = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user