diff options
author | Dianne Hackborn <hackbod@google.com> | 2014-09-14 14:39:52 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2014-09-14 19:17:17 -0700 |
commit | 2b54a9fa571a429e188b5e37d4732debd3e90ac0 (patch) | |
tree | 68253b1c193765f8fd260db7d2c1356107d54743 /src/com/android/settings/fuelgauge/BatteryHistoryChart.java | |
parent | c0deb7dac00b4fcbc64866042788e3247474538e (diff) | |
download | packages_apps_Settings-2b54a9fa571a429e188b5e37d4732debd3e90ac0.zip packages_apps_Settings-2b54a9fa571a429e188b5e37d4732debd3e90ac0.tar.gz packages_apps_Settings-2b54a9fa571a429e188b5e37d4732debd3e90ac0.tar.bz2 |
Fix issue #17495264: Battery history graph is bad
Deal better with wall clock time changes in the battery history.
Change-Id: I9d63edafc37bbf663e328a08ba09300be2142594
Diffstat (limited to 'src/com/android/settings/fuelgauge/BatteryHistoryChart.java')
-rw-r--r-- | src/com/android/settings/fuelgauge/BatteryHistoryChart.java | 55 |
1 files changed, 36 insertions, 19 deletions
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) { |