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

Commit 0ee6a0e5 authored by Dmitri Plotnikov's avatar Dmitri Plotnikov
Browse files

Fix initialization of procState counters after a failed readSummary

The code before this change assumes that `mProcStateTimeMs`
and `mProcStateScreenOffTimeMs` are either both null or both non-null.
However, if during the readSummary operation one of the two counters
is read successfully while the other fails, we end up in
an inconsistent state.

Bug: 305894439
Test: atest PowerStatsTests
Change-Id: I7928031e78d742e196750a95f6a17795b4192530
parent 448c60ca
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -8239,21 +8239,21 @@ public class BatteryStatsImpl extends BatteryStats {
        @GuardedBy("mBsi")
        private void ensureMultiStateCounters(long timestampMs) {
            if (mProcStateTimeMs != null) {
                return;
            }
            if (mProcStateTimeMs == null) {
                mProcStateTimeMs =
                        new TimeInFreqMultiStateCounter(mBsi.mOnBatteryTimeBase,
                                PROC_STATE_TIME_COUNTER_STATE_COUNT,
                                mBsi.mCpuScalingPolicies.getScalingStepCount(),
                                timestampMs);
            }
            if (mProcStateScreenOffTimeMs == null) {
                mProcStateScreenOffTimeMs =
                        new TimeInFreqMultiStateCounter(mBsi.mOnBatteryScreenOffTimeBase,
                                PROC_STATE_TIME_COUNTER_STATE_COUNT,
                                mBsi.mCpuScalingPolicies.getScalingStepCount(),
                                timestampMs);
            }
        }
        @GuardedBy("mBsi")
        private TimeInFreqMultiStateCounter getProcStateTimeCounter(long timestampMs) {