Fix the missing history event problem.
[ag/8009931 is to fix the missing event problem and it get reverted in ag/15961577. Now revert the change that causes the problem.] Make a copy of mHistoryCur and add the copy to history buffer after starting a new history file. Bug: 230799882 Test: ag/8009931 reproduce steps. Change-Id: If9339ed5182b65b9c59c119894e4f317b2e5751c
This commit is contained in:
@@ -4503,10 +4503,13 @@ public class BatteryStatsImpl extends BatteryStats {
|
||||
for (Map.Entry<HistoryTag, Integer> entry: mHistoryTagPool.entrySet()) {
|
||||
entry.setValue(entry.getValue() | TAG_FIRST_OCCURRENCE_FLAG);
|
||||
}
|
||||
// Make a copy of mHistoryCur.
|
||||
HistoryItem copy = new HistoryItem();
|
||||
copy.setTo(cur);
|
||||
// startRecordingHistory will reset mHistoryCur.
|
||||
startRecordingHistory(elapsedRealtimeMs, uptimeMs, false);
|
||||
HistoryItem newItem = new HistoryItem();
|
||||
newItem.setTo(cur);
|
||||
addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, newItem);
|
||||
// Add the copy into history buffer.
|
||||
addHistoryBufferLocked(elapsedRealtimeMs, HistoryItem.CMD_UPDATE, copy);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -154,19 +154,21 @@ public class BatteryStatsHistoryIteratorTest {
|
||||
|
||||
for (int i = 0; i < eventCount; i++) {
|
||||
String name = "a" + (i % 10);
|
||||
assertThat(iterator.next(item)).isTrue();
|
||||
// Skip a blank event inserted at the start of every buffer
|
||||
if (item.eventCode == BatteryStats.HistoryItem.EVENT_NONE) {
|
||||
do {
|
||||
assertThat(iterator.next(item)).isTrue();
|
||||
}
|
||||
// Skip a blank event inserted at the start of every buffer
|
||||
} while (item.cmd != BatteryStats.HistoryItem.CMD_UPDATE
|
||||
|| item.eventCode == BatteryStats.HistoryItem.EVENT_NONE);
|
||||
|
||||
assertThat(item.eventCode).isEqualTo(BatteryStats.HistoryItem.EVENT_ALARM
|
||||
| BatteryStats.HistoryItem.EVENT_FLAG_START);
|
||||
assertThat(item.eventTag.string).isEqualTo(name);
|
||||
|
||||
assertThat(iterator.next(item)).isTrue();
|
||||
if (item.eventCode == BatteryStats.HistoryItem.EVENT_NONE) {
|
||||
do {
|
||||
assertThat(iterator.next(item)).isTrue();
|
||||
}
|
||||
} while (item.cmd != BatteryStats.HistoryItem.CMD_UPDATE
|
||||
|| item.eventCode == BatteryStats.HistoryItem.EVENT_NONE);
|
||||
|
||||
assertThat(item.eventCode).isEqualTo(BatteryStats.HistoryItem.EVENT_ALARM
|
||||
| BatteryStats.HistoryItem.EVENT_FLAG_FINISH);
|
||||
assertThat(item.eventTag.string).isEqualTo(name);
|
||||
|
||||
Reference in New Issue
Block a user