From 8af4657207a54b9b1f2ec8155c665897bb3cf5a9 Mon Sep 17 00:00:00 2001 From: Dmitri Plotnikov Date: Mon, 29 Nov 2021 16:54:49 -0800 Subject: [PATCH] Drop TAG_FIRST_OCCURRENCE_FLAG when populating history tag array When there are more than MAX_HISTORY_BUFFER of history events, we store the history buffer and create a new one. At that point, we set the TAG_FIRST_OCCURRENCE_FLAG flag on all pre-existing indexes in the history tag pool to indicate that those tags have not yet occurred in the current history buffer and therefore would still need to be written into the buffer if they occur in the future. As a result, we end up with some indexes in the history tag pool having the TAG_FIRST_OCCURRENCE_FLAG set. We need to reset this flag when adding tags to mHistoryTags in order to restore the natural sequence of indexes. Bug: 206823946 Test: atest CtsDumpsysHostTestCases:BatteryStatsDumpsysTest Change-Id: I3affd09ea45accf3ac8706bd8114d0d7ca385a69 --- core/java/com/android/internal/os/BatteryStatsImpl.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index 3aac0b18a7fc5..aba43d859db47 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -12186,7 +12186,7 @@ public class BatteryStatsImpl extends BatteryStats { mHistoryTags = new SparseArray<>(mHistoryTagPool.size()); for (Map.Entry entry: mHistoryTagPool.entrySet()) { - mHistoryTags.put(entry.getValue(), entry.getKey()); + mHistoryTags.put(entry.getValue() & ~TAG_FIRST_OCCURRENCE_FLAG, entry.getKey()); } } @@ -16345,9 +16345,6 @@ public class BatteryStatsImpl extends BatteryStats { for (int i=0; i