Merge "Ensure standby bucket of an unused app gets treated correctly." into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f0692adb89
@@ -623,7 +623,8 @@ public class AppIdleHistory {
|
||||
* @param elapsedRealtime current time
|
||||
* @param screenTimeThresholds Array of screen times, in ascending order, first one is 0
|
||||
* @param elapsedTimeThresholds Array of elapsed time, in ascending order, first one is 0
|
||||
* @return The index whose values the app's used time exceeds (in both arrays)
|
||||
* @return The index whose values the app's used time exceeds (in both arrays) or {@code -1} to
|
||||
* indicate that the app has never been used.
|
||||
*/
|
||||
int getThresholdIndex(String packageName, int userId, long elapsedRealtime,
|
||||
long[] screenTimeThresholds, long[] elapsedTimeThresholds) {
|
||||
@@ -631,14 +632,13 @@ public class AppIdleHistory {
|
||||
AppUsageHistory appUsageHistory = getPackageHistory(userHistory, packageName,
|
||||
elapsedRealtime, false);
|
||||
// If we don't have any state for the app, assume never used
|
||||
if (appUsageHistory == null) return screenTimeThresholds.length - 1;
|
||||
if (appUsageHistory == null || appUsageHistory.lastUsedElapsedTime < 0
|
||||
|| appUsageHistory.lastUsedScreenTime < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
long screenOnDelta = appUsageHistory.lastUsedScreenTime >= 0
|
||||
? getScreenOnTime(elapsedRealtime) - appUsageHistory.lastUsedScreenTime
|
||||
: Long.MAX_VALUE;
|
||||
long elapsedDelta = appUsageHistory.lastUsedElapsedTime >= 0
|
||||
? getElapsedTime(elapsedRealtime) - appUsageHistory.lastUsedElapsedTime
|
||||
: Long.MAX_VALUE;
|
||||
long screenOnDelta = getScreenOnTime(elapsedRealtime) - appUsageHistory.lastUsedScreenTime;
|
||||
long elapsedDelta = getElapsedTime(elapsedRealtime) - appUsageHistory.lastUsedElapsedTime;
|
||||
|
||||
if (DEBUG) Slog.d(TAG, packageName
|
||||
+ " lastUsedScreen=" + appUsageHistory.lastUsedScreenTime
|
||||
|
||||
@@ -898,11 +898,9 @@ public class AppStandbyController
|
||||
}
|
||||
}
|
||||
|
||||
final long elapsedLastUsedByUserTimeDelta = app.lastUsedByUserElapsedTime >= 0
|
||||
? elapsedTimeAdjusted - app.lastUsedByUserElapsedTime
|
||||
: Long.MAX_VALUE;
|
||||
if (app.lastRestrictAttemptElapsedTime > app.lastUsedByUserElapsedTime
|
||||
&& elapsedLastUsedByUserTimeDelta
|
||||
if (app.lastUsedByUserElapsedTime >= 0
|
||||
&& app.lastRestrictAttemptElapsedTime > app.lastUsedByUserElapsedTime
|
||||
&& elapsedTimeAdjusted - app.lastUsedByUserElapsedTime
|
||||
>= mInjector.getAutoRestrictedBucketDelayMs()) {
|
||||
newBucket = STANDBY_BUCKET_RESTRICTED;
|
||||
reason = app.lastRestrictReason;
|
||||
@@ -974,7 +972,7 @@ public class AppStandbyController
|
||||
long elapsedRealtime) {
|
||||
int bucketIndex = mAppIdleHistory.getThresholdIndex(packageName, userId,
|
||||
elapsedRealtime, mAppStandbyScreenThresholds, mAppStandbyElapsedThresholds);
|
||||
return THRESHOLD_BUCKETS[bucketIndex];
|
||||
return bucketIndex >= 0 ? THRESHOLD_BUCKETS[bucketIndex] : STANDBY_BUCKET_NEVER;
|
||||
}
|
||||
|
||||
private void notifyBatteryStats(String packageName, int userId, boolean idle) {
|
||||
|
||||
Reference in New Issue
Block a user