Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae5e234c authored by huiyu's avatar huiyu
Browse files

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
parent 1fbb452d
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -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;
        }
+9 −7
Original line number Diff line number Diff line
@@ -154,19 +154,21 @@ public class BatteryStatsHistoryIteratorTest {

        for (int i = 0; i < eventCount; i++) {
            String name = "a" + (i % 10);
            do {
                assertThat(iterator.next(item)).isTrue();
                // Skip a blank event inserted at the start of every buffer
            if (item.eventCode == BatteryStats.HistoryItem.EVENT_NONE) {
                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_START);
            assertThat(item.eventTag.string).isEqualTo(name);

            do {
                assertThat(iterator.next(item)).isTrue();
            if (item.eventCode == BatteryStats.HistoryItem.EVENT_NONE) {
                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);