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

Commit 1acf06a6 authored by Todd Poynor's avatar Todd Poynor
Browse files

BatteryStats: Don't collect battery stats if no battery

If the device has no battery, or has a removeable battery that is
currently removed, do not collect battery statistics.

Bug: 34507420
Test: manual: dumpsys batterystats
Change-Id: Id8edb494f353a40c648f798690f611f89f464d34
parent 10adc355
Loading
Loading
Loading
Loading
+11 −5
Original line number Original line Diff line number Diff line
@@ -11228,7 +11228,9 @@ public class BatteryStatsImpl extends BatteryStats {
        reportChangesToStatsLog(mHaveBatteryLevel ? mHistoryCur : null,
        reportChangesToStatsLog(mHaveBatteryLevel ? mHistoryCur : null,
                status, plugType, level, temp);
                status, plugType, level, temp);
        final boolean onBattery = plugType == BATTERY_PLUGGED_NONE;
        final boolean onBattery =
            plugType == BATTERY_PLUGGED_NONE &&
            status != BatteryManager.BATTERY_STATUS_UNKNOWN;
        final long uptime = mClocks.uptimeMillis();
        final long uptime = mClocks.uptimeMillis();
        final long elapsedRealtime = mClocks.elapsedRealtime();
        final long elapsedRealtime = mClocks.elapsedRealtime();
        if (!mHaveBatteryLevel) {
        if (!mHaveBatteryLevel) {
@@ -11262,7 +11264,8 @@ public class BatteryStatsImpl extends BatteryStats {
                mRecordingHistory = true;
                mRecordingHistory = true;
                startRecordingHistory(elapsedRealtime, uptime, true);
                startRecordingHistory(elapsedRealtime, uptime, true);
            }
            }
        } else if (level < 96) {
        } else if (level < 96 &&
            status != BatteryManager.BATTERY_STATUS_UNKNOWN) {
            if (!mRecordingHistory) {
            if (!mRecordingHistory) {
                mRecordingHistory = true;
                mRecordingHistory = true;
                startRecordingHistory(elapsedRealtime, uptime, true);
                startRecordingHistory(elapsedRealtime, uptime, true);
@@ -11400,9 +11403,12 @@ public class BatteryStatsImpl extends BatteryStats {
                addHistoryRecordLocked(elapsedRealtime, uptime);
                addHistoryRecordLocked(elapsedRealtime, uptime);
            }
            }
        }
        }
        if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) {
        if (!onBattery &&
            // We don't record history while we are plugged in and fully charged.
            (status == BatteryManager.BATTERY_STATUS_FULL ||
            // The next time we are unplugged, history will be cleared.
             status == BatteryManager.BATTERY_STATUS_UNKNOWN)) {
            // We don't record history while we are plugged in and fully charged
            // (or when battery is not present).  The next time we are
            // unplugged, history will be cleared.
            mRecordingHistory = DEBUG;
            mRecordingHistory = DEBUG;
        }
        }