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 elapsedRealtime current time
|
||||||
* @param screenTimeThresholds Array of screen times, in ascending order, first one is 0
|
* @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
|
* @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,
|
int getThresholdIndex(String packageName, int userId, long elapsedRealtime,
|
||||||
long[] screenTimeThresholds, long[] elapsedTimeThresholds) {
|
long[] screenTimeThresholds, long[] elapsedTimeThresholds) {
|
||||||
@@ -631,14 +632,13 @@ public class AppIdleHistory {
|
|||||||
AppUsageHistory appUsageHistory = getPackageHistory(userHistory, packageName,
|
AppUsageHistory appUsageHistory = getPackageHistory(userHistory, packageName,
|
||||||
elapsedRealtime, false);
|
elapsedRealtime, false);
|
||||||
// If we don't have any state for the app, assume never used
|
// 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
|
long screenOnDelta = getScreenOnTime(elapsedRealtime) - appUsageHistory.lastUsedScreenTime;
|
||||||
? getScreenOnTime(elapsedRealtime) - appUsageHistory.lastUsedScreenTime
|
long elapsedDelta = getElapsedTime(elapsedRealtime) - appUsageHistory.lastUsedElapsedTime;
|
||||||
: Long.MAX_VALUE;
|
|
||||||
long elapsedDelta = appUsageHistory.lastUsedElapsedTime >= 0
|
|
||||||
? getElapsedTime(elapsedRealtime) - appUsageHistory.lastUsedElapsedTime
|
|
||||||
: Long.MAX_VALUE;
|
|
||||||
|
|
||||||
if (DEBUG) Slog.d(TAG, packageName
|
if (DEBUG) Slog.d(TAG, packageName
|
||||||
+ " lastUsedScreen=" + appUsageHistory.lastUsedScreenTime
|
+ " lastUsedScreen=" + appUsageHistory.lastUsedScreenTime
|
||||||
|
|||||||
@@ -898,11 +898,9 @@ public class AppStandbyController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final long elapsedLastUsedByUserTimeDelta = app.lastUsedByUserElapsedTime >= 0
|
if (app.lastUsedByUserElapsedTime >= 0
|
||||||
? elapsedTimeAdjusted - app.lastUsedByUserElapsedTime
|
&& app.lastRestrictAttemptElapsedTime > app.lastUsedByUserElapsedTime
|
||||||
: Long.MAX_VALUE;
|
&& elapsedTimeAdjusted - app.lastUsedByUserElapsedTime
|
||||||
if (app.lastRestrictAttemptElapsedTime > app.lastUsedByUserElapsedTime
|
|
||||||
&& elapsedLastUsedByUserTimeDelta
|
|
||||||
>= mInjector.getAutoRestrictedBucketDelayMs()) {
|
>= mInjector.getAutoRestrictedBucketDelayMs()) {
|
||||||
newBucket = STANDBY_BUCKET_RESTRICTED;
|
newBucket = STANDBY_BUCKET_RESTRICTED;
|
||||||
reason = app.lastRestrictReason;
|
reason = app.lastRestrictReason;
|
||||||
@@ -974,7 +972,7 @@ public class AppStandbyController
|
|||||||
long elapsedRealtime) {
|
long elapsedRealtime) {
|
||||||
int bucketIndex = mAppIdleHistory.getThresholdIndex(packageName, userId,
|
int bucketIndex = mAppIdleHistory.getThresholdIndex(packageName, userId,
|
||||||
elapsedRealtime, mAppStandbyScreenThresholds, mAppStandbyElapsedThresholds);
|
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) {
|
private void notifyBatteryStats(String packageName, int userId, boolean idle) {
|
||||||
|
|||||||
Reference in New Issue
Block a user