Merge "SamplingTimer: Fix issue with summary recording too much" into nyc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
8aacc3cf98
@@ -108,7 +108,7 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
private static final int MAGIC = 0xBA757475; // 'BATSTATS'
|
private static final int MAGIC = 0xBA757475; // 'BATSTATS'
|
||||||
|
|
||||||
// Current on-disk Parcel version
|
// 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.
|
// Maximum number of items we will record in the history.
|
||||||
private static final int MAX_HISTORY_ITEMS = 2000;
|
private static final int MAX_HISTORY_ITEMS = 2000;
|
||||||
@@ -1415,22 +1415,6 @@ public class BatteryStatsImpl extends BatteryStats {
|
|||||||
mUnpluggedReportedCount = 0;
|
mUnpluggedReportedCount = 0;
|
||||||
return true;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -178,19 +178,40 @@ public class BatteryStatsSamplingTimerTest extends TestCase {
|
|||||||
clocks.elapsedRealtime() * 1000);
|
clocks.elapsedRealtime() * 1000);
|
||||||
offBatterySummaryParcel.setDataPosition(0);
|
offBatterySummaryParcel.setDataPosition(0);
|
||||||
|
|
||||||
// Read the on battery summary from the parcel.
|
// Set the timebase running again. That way any issues with tracking reported values
|
||||||
BatteryStatsImpl.SamplingTimer unparceledTimer = new BatteryStatsImpl.SamplingTimer(
|
// get tested when we unparcel the timers below.
|
||||||
clocks, timeBase);
|
timeBase.setRunning(true, clocks.uptimeMillis(), clocks.elapsedRealtime());
|
||||||
unparceledTimer.readSummaryFromParcelLocked(onBatterySummaryParcel);
|
|
||||||
|
|
||||||
assertEquals(10, unparceledTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED));
|
// Read the on battery summary from the parcel.
|
||||||
assertEquals(1, unparceledTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
|
BatteryStatsImpl.SamplingTimer unparceledOnBatteryTimer =
|
||||||
|
new BatteryStatsImpl.SamplingTimer(clocks, timeBase);
|
||||||
|
unparceledOnBatteryTimer.readSummaryFromParcelLocked(onBatterySummaryParcel);
|
||||||
|
|
||||||
|
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.
|
// Read the off battery summary from the parcel.
|
||||||
unparceledTimer = new BatteryStatsImpl.SamplingTimer(clocks, timeBase);
|
BatteryStatsImpl.SamplingTimer unparceledOffBatteryTimer =
|
||||||
unparceledTimer.readSummaryFromParcelLocked(offBatterySummaryParcel);
|
new BatteryStatsImpl.SamplingTimer(clocks, timeBase);
|
||||||
|
unparceledOffBatteryTimer.readSummaryFromParcelLocked(offBatterySummaryParcel);
|
||||||
|
|
||||||
assertEquals(10, unparceledTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED));
|
assertEquals(10, unparceledOffBatteryTimer.getTotalTimeLocked(0,
|
||||||
assertEquals(1, unparceledTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
|
BatteryStats.STATS_SINCE_CHARGED));
|
||||||
|
assertEquals(1, unparceledOffBatteryTimer.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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user