Update the method about foreground time.

For now it uses MIN(STATE_TOP_TIME, FOREGROUND_ACTIVITY_TIME) and this
method is used in both display and screen smearing.

Bug: 63080621
Test: RunSettingsRoboTests
Change-Id: I2ca3109697aa66fae67d8b2f4f10c4d08bb99d59
This commit is contained in:
jackqdyulei
2017-06-30 10:18:34 -07:00
parent 2354fae941
commit 43cbee6914
3 changed files with 29 additions and 21 deletions

View File

@@ -122,7 +122,10 @@ public class BatteryUtils {
}
Log.v(TAG, "foreground time(us): " + timeUs);
return convertUsToMs(timeUs);
// Return the min value of STATE_TOP time and foreground activity time, since both of these
// time have some errors.
return convertUsToMs(
Math.min(timeUs, getForegroundActivityTotalTimeUs(uid, rawRealTimeUs)));
}
/**
@@ -167,15 +170,13 @@ public class BatteryUtils {
*/
@VisibleForTesting
void smearScreenBatterySipper(List<BatterySipper> sippers, BatterySipper screenSipper) {
final long rawRealtimeMs = SystemClock.elapsedRealtime();
long totalActivityTimeMs = 0;
final SparseLongArray activityTimeArray = new SparseLongArray();
for (int i = 0, size = sippers.size(); i < size; i++) {
final BatteryStats.Uid uid = sippers.get(i).uidObj;
if (uid != null) {
final long timeMs = Math.min(getForegroundActivityTotalTimeMs(uid, rawRealtimeMs),
getProcessTimeMs(StatusType.FOREGROUND, uid,
BatteryStats.STATS_SINCE_CHARGED));
final long timeMs = getProcessTimeMs(StatusType.FOREGROUND, uid,
BatteryStats.STATS_SINCE_CHARGED);
activityTimeArray.put(uid.getUid(), timeMs);
totalActivityTimeMs += timeMs;
}
@@ -328,11 +329,10 @@ public class BatteryUtils {
}
@VisibleForTesting
long getForegroundActivityTotalTimeMs(BatteryStats.Uid uid, long rawRealtimeMs) {
long getForegroundActivityTotalTimeUs(BatteryStats.Uid uid, long rawRealtimeUs) {
final BatteryStats.Timer timer = uid.getForegroundActivityTimer();
if (timer != null) {
return convertUsToMs(timer.getTotalTimeLocked(convertMsToUs(rawRealtimeMs),
BatteryStats.STATS_SINCE_CHARGED));
return timer.getTotalTimeLocked(rawRealtimeUs, BatteryStats.STATS_SINCE_CHARGED);
}
return 0;