diff options
| author | 2016-08-14 00:45:24 +0000 | |
|---|---|---|
| committer | 2016-08-14 00:45:24 +0000 | |
| commit | 3e1cd845e6f2db3125647f025356ce334a4e7263 (patch) | |
| tree | 84c3bd0559eb2e41367bc72dc5842af6483d7b52 | |
| parent | 723c1fd0144b6320b92048cc2284d4f494ee5b72 (diff) | |
| parent | 4e4e50cd02a75a8b151ee7034730d6decd35bc14 (diff) | |
SamplingTimer: Fix issue with summary recording too much am: 9edd6be542 am: e5852eb501
am: 4e4e50cd02
Change-Id: If5f2313532774ef113fbb682beba6b51de45b45c
| -rw-r--r-- | core/java/com/android/internal/os/BatteryStatsImpl.java | 18 | ||||
| -rw-r--r-- | core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java | 39 |
2 files changed, 31 insertions, 26 deletions
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index fef4a5381485..0aa3a7e9c8a4 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -111,7 +111,7 @@ public class BatteryStatsImpl extends BatteryStats { private static final int MAGIC = 0xBA757475; // 'BATSTATS' // Current on-disk Parcel version - private static final int VERSION = 149 + (USE_OLD_HISTORY ? 1000 : 0); + private static final int VERSION = 150 + (USE_OLD_HISTORY ? 1000 : 0); // Maximum number of items we will record in the history. private static final int MAX_HISTORY_ITEMS = 2000; @@ -1425,22 +1425,6 @@ public class BatteryStatsImpl extends BatteryStats { mUnpluggedReportedCount = 0; return true; } - - @Override - public void writeSummaryFromParcelLocked(Parcel out, long batteryRealtime) { - super.writeSummaryFromParcelLocked(out, batteryRealtime); - out.writeLong(mCurrentReportedTotalTime); - out.writeInt(mCurrentReportedCount); - out.writeInt(mTrackingReportedValues ? 1 : 0); - } - - @Override - public void readSummaryFromParcelLocked(Parcel in) { - super.readSummaryFromParcelLocked(in); - mUnpluggedReportedTotalTime = mCurrentReportedTotalTime = in.readLong(); - mUnpluggedReportedCount = mCurrentReportedCount = in.readInt(); - mTrackingReportedValues = in.readInt() == 1; - } } /** diff --git a/core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java b/core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java index ce6879d0ef4e..b4afddab97c9 100644 --- a/core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BatteryStatsSamplingTimerTest.java @@ -178,19 +178,40 @@ public class BatteryStatsSamplingTimerTest extends TestCase { clocks.elapsedRealtime() * 1000); offBatterySummaryParcel.setDataPosition(0); + // Set the timebase running again. That way any issues with tracking reported values + // get tested when we unparcel the timers below. + timeBase.setRunning(true, clocks.uptimeMillis(), clocks.elapsedRealtime()); + // Read the on battery summary from the parcel. - BatteryStatsImpl.SamplingTimer unparceledTimer = new BatteryStatsImpl.SamplingTimer( - clocks, timeBase); - unparceledTimer.readSummaryFromParcelLocked(onBatterySummaryParcel); + BatteryStatsImpl.SamplingTimer unparceledOnBatteryTimer = + new BatteryStatsImpl.SamplingTimer(clocks, timeBase); + unparceledOnBatteryTimer.readSummaryFromParcelLocked(onBatterySummaryParcel); - assertEquals(10, unparceledTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED)); - assertEquals(1, unparceledTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); + assertEquals(10, unparceledOnBatteryTimer.getTotalTimeLocked(0, + BatteryStats.STATS_SINCE_CHARGED)); + assertEquals(1, unparceledOnBatteryTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); // Read the off battery summary from the parcel. - unparceledTimer = new BatteryStatsImpl.SamplingTimer(clocks, timeBase); - unparceledTimer.readSummaryFromParcelLocked(offBatterySummaryParcel); + BatteryStatsImpl.SamplingTimer unparceledOffBatteryTimer = + new BatteryStatsImpl.SamplingTimer(clocks, timeBase); + unparceledOffBatteryTimer.readSummaryFromParcelLocked(offBatterySummaryParcel); + + assertEquals(10, unparceledOffBatteryTimer.getTotalTimeLocked(0, + BatteryStats.STATS_SINCE_CHARGED)); + assertEquals(1, unparceledOffBatteryTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); - assertEquals(10, unparceledTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED)); - assertEquals(1, unparceledTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); + // Now, just like with a fresh timer, the first update should be absorbed to account for + // data being collected when we weren't recording. + unparceledOnBatteryTimer.update(10, 10); + + assertEquals(10, unparceledOnBatteryTimer.getTotalTimeLocked(0, + BatteryStats.STATS_SINCE_CHARGED)); + assertEquals(1, unparceledOnBatteryTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); + + unparceledOffBatteryTimer.update(10, 10); + + assertEquals(10, unparceledOffBatteryTimer.getTotalTimeLocked(0, + BatteryStats.STATS_SINCE_CHARGED)); + assertEquals(1, unparceledOffBatteryTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED)); } } |