From 2b54a9fa571a429e188b5e37d4732debd3e90ac0 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Sun, 14 Sep 2014 14:39:52 -0700 Subject: Fix issue #17495264: Battery history graph is bad Deal better with wall clock time changes in the battery history. Change-Id: I9d63edafc37bbf663e328a08ba09300be2142594 --- .../settings/fuelgauge/BatteryHistoryChart.java | 55 ++++++++++++++-------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java index c16708d..2f36c5f 100644 --- a/src/com/android/settings/fuelgauge/BatteryHistoryChart.java +++ b/src/com/android/settings/fuelgauge/BatteryHistoryChart.java @@ -565,10 +565,17 @@ public class BatteryHistoryChart extends View { } if (rec.cmd == HistoryItem.CMD_CURRENT_TIME || rec.cmd == HistoryItem.CMD_RESET) { + // If there is a ridiculously large jump in time, then we won't be + // able to create a good chart with that data, so just ignore the + // times we got before and pretend like our data extends back from + // the time we have now. + if (rec.currentTime > (lastWallTime+(365*24*60*60*1000))) { + mStartWallTime = 0; + } lastWallTime = rec.currentTime; lastRealtime = rec.time; if (mStartWallTime == 0) { - mStartWallTime = lastWallTime; + mStartWallTime = lastWallTime - (lastRealtime-mHistStart); } } if (rec.isDeltaData()) { @@ -774,7 +781,7 @@ public class BatteryHistoryChart extends View { final long walltimeStart = mStartWallTime; final long walltimeChange = mEndWallTime > walltimeStart ? (mEndWallTime-walltimeStart) : 1; - long curWalltime = 0; + long curWalltime = mStartWallTime; long lastRealtime = 0; final int batLow = mBatLow; @@ -791,17 +798,12 @@ public class BatteryHistoryChart extends View { boolean lastWifiRunning = false, lastWifiSupplRunning = false, lastCpuRunning = false; int lastWifiSupplState = BatteryStats.WIFI_SUPPL_STATE_INVALID; final int N = mNumHist; - if (mStats.startIteratingHistoryLocked()) { + if (mEndDataWallTime > mStartWallTime && mStats.startIteratingHistoryLocked()) { final HistoryItem rec = new HistoryItem(); while (mStats.getNextHistoryLocked(rec) && i < N) { - if (rec.cmd == HistoryItem.CMD_CURRENT_TIME || rec.cmd == HistoryItem.CMD_RESET) { - curWalltime = rec.currentTime; - lastRealtime = rec.time; - } else if (curWalltime != 0) { + if (rec.isDeltaData()) { curWalltime += rec.time-lastRealtime; lastRealtime = rec.time; - } - if (curWalltime != 0 && rec.isDeltaData()) { x = mLevelLeft + (int)(((curWalltime-walltimeStart)*levelWidth)/walltimeChange); if (x < 0) { x = 0; @@ -950,21 +952,36 @@ public class BatteryHistoryChart extends View { } } - } else if (rec.cmd != HistoryItem.CMD_OVERFLOW - && rec.cmd != HistoryItem.CMD_CURRENT_TIME) { - if (curLevelPath != null) { - finishPaths(x+1, h, levelh, startX, lastY, curLevelPath, lastX, - lastCharging, lastScreenOn, lastGpsOn, lastWifiRunning, - lastCpuRunning, lastLinePath); - lastX = lastY = -1; - curLevelPath = null; - lastLinePath = null; - lastCharging = lastScreenOn = lastGpsOn = lastCpuRunning = false; + } else { + long lastWalltime = curWalltime; + if (rec.cmd == HistoryItem.CMD_CURRENT_TIME + || rec.cmd == HistoryItem.CMD_RESET) { + if (rec.currentTime >= mStartWallTime) { + curWalltime = rec.currentTime; + } else { + curWalltime = mStartWallTime + (rec.time-mHistStart); + } + lastRealtime = rec.time; + } + + if (rec.cmd != HistoryItem.CMD_OVERFLOW + && (rec.cmd != HistoryItem.CMD_CURRENT_TIME + || Math.abs(lastWalltime-curWalltime) > (60*60*1000))) { + if (curLevelPath != null) { + finishPaths(x+1, h, levelh, startX, lastY, curLevelPath, lastX, + lastCharging, lastScreenOn, lastGpsOn, lastWifiRunning, + lastCpuRunning, lastLinePath); + lastX = lastY = -1; + curLevelPath = null; + lastLinePath = null; + lastCharging = lastScreenOn = lastGpsOn = lastCpuRunning = false; + } } } i++; } + mStats.finishIteratingHistoryLocked(); } if (lastY < 0 || lastX < 0) { -- cgit v1.1