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

Commit cf031239 authored by Kweku Adams's avatar Kweku Adams
Browse files

Fix accounting bug in BatteryStatsImpl.

A line was added to set mLastChargeStepLevel to level every time the
battery level changed when the device was plugged in. However, it was
added right before an if block that checked if mLastChargeStepLevel was
not equal to level, which then meant that the if block would never
execute. Moving the setting line below the if block to fix that and
removing redundant lines.

Bug: 111360323
Test: atest com.android.internal.os.BatteryStatsTests
Test: atest CtsJobSchedulerTestCases
Test: atest CtsBatterySavingTestCases
Change-Id: I36f1b05f8d344b4d2432696acbf370d47a769d03
parent 8e24abad
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -12028,7 +12028,7 @@ public class BatteryStatsImpl extends BatteryStats {
        // if the device is now charging, it means that this is either called
        // 1. directly when level >= 90
        // 2. or from within the runnable that we deferred
        // For 1. if we have an existing callback, remove it, since we will immediatelly send a
        // For 1. if we have an existing callback, remove it, since we will immediately send a
        // ACTION_CHARGING
        // For 2. we remove existing callback so we don't send multiple ACTION_CHARGING
        mHandler.removeCallbacks(mDeferSetCharging);
@@ -12369,7 +12369,6 @@ public class BatteryStatsImpl extends BatteryStats {
                    // If the battery level is at least 90%, always consider the device to be
                    // charging even if it happens to go down a level.
                    changed |= setChargingLocked(true);
                    mLastChargeStepLevel = level;
                } else if (!mCharging) {
                    if (mLastChargeStepLevel < level) {
                        // We have not reported that we are charging, but the level has gone up,
@@ -12395,17 +12394,16 @@ public class BatteryStatsImpl extends BatteryStats {
                        changed |= setChargingLocked(false);
                    }
                }
                mLastChargeStepLevel = level;
                if (mLastChargeStepLevel != level && mMaxChargeStepLevel < level) {
                    mChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel,
                            modeBits, elapsedRealtime);
                    mDailyChargeStepTracker.addLevelSteps(level - mLastChargeStepLevel,
                            modeBits, elapsedRealtime);
                    mLastChargeStepLevel = level;
                    mMaxChargeStepLevel = level;
                    mInitStepMode = mCurStepMode;
                    mModStepMode = 0;
                }
                mLastChargeStepLevel = level;
            }
            if (changed) {
                addHistoryRecordLocked(elapsedRealtime, uptime);