Merge "Initialize lastUsedElapsedTime to Integer.MIN_VALUE." into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b8dcd0b86c
@@ -384,14 +384,16 @@ public class AppIdleHistory {
|
|||||||
return userHistory;
|
return userHistory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO (206518483): Remove unused parameter 'elapsedRealtime'.
|
||||||
private AppUsageHistory getPackageHistory(ArrayMap<String, AppUsageHistory> userHistory,
|
private AppUsageHistory getPackageHistory(ArrayMap<String, AppUsageHistory> userHistory,
|
||||||
String packageName, long elapsedRealtime, boolean create) {
|
String packageName, long elapsedRealtime, boolean create) {
|
||||||
AppUsageHistory appUsageHistory = userHistory.get(packageName);
|
AppUsageHistory appUsageHistory = userHistory.get(packageName);
|
||||||
if (appUsageHistory == null && create) {
|
if (appUsageHistory == null && create) {
|
||||||
appUsageHistory = new AppUsageHistory();
|
appUsageHistory = new AppUsageHistory();
|
||||||
appUsageHistory.lastUsedElapsedTime = getElapsedTime(elapsedRealtime);
|
appUsageHistory.lastUsedByUserElapsedTime = Integer.MIN_VALUE;
|
||||||
appUsageHistory.lastUsedScreenTime = getScreenOnTime(elapsedRealtime);
|
appUsageHistory.lastUsedElapsedTime = Integer.MIN_VALUE;
|
||||||
appUsageHistory.lastPredictedTime = getElapsedTime(0);
|
appUsageHistory.lastUsedScreenTime = Integer.MIN_VALUE;
|
||||||
|
appUsageHistory.lastPredictedTime = Integer.MIN_VALUE;
|
||||||
appUsageHistory.currentBucket = STANDBY_BUCKET_NEVER;
|
appUsageHistory.currentBucket = STANDBY_BUCKET_NEVER;
|
||||||
appUsageHistory.bucketingReason = REASON_MAIN_DEFAULT;
|
appUsageHistory.bucketingReason = REASON_MAIN_DEFAULT;
|
||||||
appUsageHistory.lastInformedBucket = -1;
|
appUsageHistory.lastInformedBucket = -1;
|
||||||
@@ -544,7 +546,7 @@ public class AppIdleHistory {
|
|||||||
AppUsageHistory appUsageHistory =
|
AppUsageHistory appUsageHistory =
|
||||||
getPackageHistory(userHistory, packageName, elapsedRealtime, false);
|
getPackageHistory(userHistory, packageName, elapsedRealtime, false);
|
||||||
if (appUsageHistory == null || appUsageHistory.lastUsedByUserElapsedTime == Long.MIN_VALUE
|
if (appUsageHistory == null || appUsageHistory.lastUsedByUserElapsedTime == Long.MIN_VALUE
|
||||||
|| appUsageHistory.lastUsedByUserElapsedTime == 0) {
|
|| appUsageHistory.lastUsedByUserElapsedTime <= 0) {
|
||||||
return Long.MAX_VALUE;
|
return Long.MAX_VALUE;
|
||||||
}
|
}
|
||||||
return getElapsedTime(elapsedRealtime) - appUsageHistory.lastUsedByUserElapsedTime;
|
return getElapsedTime(elapsedRealtime) - appUsageHistory.lastUsedByUserElapsedTime;
|
||||||
@@ -631,8 +633,12 @@ public class AppIdleHistory {
|
|||||||
// 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) return screenTimeThresholds.length - 1;
|
||||||
|
|
||||||
long screenOnDelta = getScreenOnTime(elapsedRealtime) - appUsageHistory.lastUsedScreenTime;
|
long screenOnDelta = appUsageHistory.lastUsedScreenTime >= 0
|
||||||
long elapsedDelta = getElapsedTime(elapsedRealtime) - appUsageHistory.lastUsedElapsedTime;
|
? getScreenOnTime(elapsedRealtime) - appUsageHistory.lastUsedScreenTime
|
||||||
|
: 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
|
||||||
@@ -951,14 +957,14 @@ public class AppIdleHistory {
|
|||||||
+ " reason="
|
+ " reason="
|
||||||
+ UsageStatsManager.reasonToString(appUsageHistory.bucketingReason));
|
+ UsageStatsManager.reasonToString(appUsageHistory.bucketingReason));
|
||||||
idpw.print(" used=");
|
idpw.print(" used=");
|
||||||
TimeUtils.formatDuration(totalElapsedTime - appUsageHistory.lastUsedElapsedTime, idpw);
|
printLastActionElapsedTime(idpw, totalElapsedTime, appUsageHistory.lastUsedElapsedTime);
|
||||||
idpw.print(" usedByUser=");
|
idpw.print(" usedByUser=");
|
||||||
TimeUtils.formatDuration(totalElapsedTime - appUsageHistory.lastUsedByUserElapsedTime,
|
printLastActionElapsedTime(idpw, totalElapsedTime,
|
||||||
idpw);
|
appUsageHistory.lastUsedByUserElapsedTime);
|
||||||
idpw.print(" usedScr=");
|
idpw.print(" usedScr=");
|
||||||
TimeUtils.formatDuration(screenOnTime - appUsageHistory.lastUsedScreenTime, idpw);
|
printLastActionElapsedTime(idpw, totalElapsedTime, appUsageHistory.lastUsedScreenTime);
|
||||||
idpw.print(" lastPred=");
|
idpw.print(" lastPred=");
|
||||||
TimeUtils.formatDuration(totalElapsedTime - appUsageHistory.lastPredictedTime, idpw);
|
printLastActionElapsedTime(idpw, totalElapsedTime, appUsageHistory.lastPredictedTime);
|
||||||
dumpBucketExpiryTimes(idpw, appUsageHistory, totalElapsedTime);
|
dumpBucketExpiryTimes(idpw, appUsageHistory, totalElapsedTime);
|
||||||
idpw.print(" lastJob=");
|
idpw.print(" lastJob=");
|
||||||
TimeUtils.formatDuration(totalElapsedTime - appUsageHistory.lastJobRunTime, idpw);
|
TimeUtils.formatDuration(totalElapsedTime - appUsageHistory.lastJobRunTime, idpw);
|
||||||
@@ -986,6 +992,15 @@ public class AppIdleHistory {
|
|||||||
idpw.decreaseIndent();
|
idpw.decreaseIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void printLastActionElapsedTime(IndentingPrintWriter idpw, long totalElapsedTimeMS,
|
||||||
|
long lastActionTimeMs) {
|
||||||
|
if (lastActionTimeMs < 0) {
|
||||||
|
idpw.print("<uninitialized>");
|
||||||
|
} else {
|
||||||
|
TimeUtils.formatDuration(totalElapsedTimeMS - lastActionTimeMs, idpw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void dumpBucketExpiryTimes(IndentingPrintWriter idpw, AppUsageHistory appUsageHistory,
|
private void dumpBucketExpiryTimes(IndentingPrintWriter idpw, AppUsageHistory appUsageHistory,
|
||||||
long totalElapsedTimeMs) {
|
long totalElapsedTimeMs) {
|
||||||
idpw.print(" expiryTimes=");
|
idpw.print(" expiryTimes=");
|
||||||
|
|||||||
@@ -898,8 +898,11 @@ public class AppStandbyController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final long elapsedLastUsedByUserTimeDelta = app.lastUsedByUserElapsedTime >= 0
|
||||||
|
? elapsedTimeAdjusted - app.lastUsedByUserElapsedTime
|
||||||
|
: Long.MAX_VALUE;
|
||||||
if (app.lastRestrictAttemptElapsedTime > app.lastUsedByUserElapsedTime
|
if (app.lastRestrictAttemptElapsedTime > app.lastUsedByUserElapsedTime
|
||||||
&& elapsedTimeAdjusted - app.lastUsedByUserElapsedTime
|
&& elapsedLastUsedByUserTimeDelta
|
||||||
>= mInjector.getAutoRestrictedBucketDelayMs()) {
|
>= mInjector.getAutoRestrictedBucketDelayMs()) {
|
||||||
newBucket = STANDBY_BUCKET_RESTRICTED;
|
newBucket = STANDBY_BUCKET_RESTRICTED;
|
||||||
reason = app.lastRestrictReason;
|
reason = app.lastRestrictReason;
|
||||||
|
|||||||
Reference in New Issue
Block a user