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

Commit 7b5cb3c0 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Fix issue #4068088: NPE at com.android.internal.os.BatteryStatsImpl..." into honeycomb-mr1

parents 564f12eb 32de2f67
Loading
Loading
Loading
Loading
+125 −119
Original line number Diff line number Diff line
@@ -1581,7 +1581,7 @@ public final class BatteryStatsImpl extends BatteryStats {
            
            // Update discharge amounts.
            if (mOnBatteryInternal) {
                updateDischargeScreenLevels(false, true);
                updateDischargeScreenLevelsLocked(false, true);
            }
        }
    }
@@ -1602,7 +1602,7 @@ public final class BatteryStatsImpl extends BatteryStats {
            
            // Update discharge amounts.
            if (mOnBatteryInternal) {
                updateDischargeScreenLevels(true, false);
                updateDischargeScreenLevelsLocked(true, false);
            }
        }
    }
@@ -4030,7 +4030,7 @@ public final class BatteryStatsImpl extends BatteryStats {
        clearHistoryLocked();
    }

    void updateDischargeScreenLevels(boolean oldScreenOn, boolean newScreenOn) {
    void updateDischargeScreenLevelsLocked(boolean oldScreenOn, boolean newScreenOn) {
        if (oldScreenOn) {
            int diff = mDischargeScreenOnUnplugLevel - mDischargeCurrentLevel;
            if (diff > 0) {
@@ -4055,6 +4055,11 @@ public final class BatteryStatsImpl extends BatteryStats {
    
    void setOnBattery(boolean onBattery, int oldStatus, int level) {
        synchronized(this) {
            setOnBatteryLocked(onBattery, oldStatus, level);
        }
    }

    void setOnBatteryLocked(boolean onBattery, int oldStatus, int level) {
        boolean doWrite = false;
        Message m = mHandler.obtainMessage(MSG_REPORT_POWER_CHANGE);
        m.arg1 = onBattery ? 1 : 0;
@@ -4111,7 +4116,7 @@ public final class BatteryStatsImpl extends BatteryStats {
                mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1;
                mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level;
            }
                updateDischargeScreenLevels(mScreenOn, mScreenOn);
            updateDischargeScreenLevelsLocked(mScreenOn, mScreenOn);
            doPlugLocked(getBatteryUptimeLocked(uptime), getBatteryRealtimeLocked(realtime));
        }
        if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) {
@@ -4120,13 +4125,13 @@ public final class BatteryStatsImpl extends BatteryStats {
            }
        }
    }
    }

    // This should probably be exposed in the API, though it's not critical
    private static final int BATTERY_PLUGGED_NONE = 0;

    public void setBatteryState(int status, int health, int plugType, int level,
            int temp, int volt) {
        synchronized(this) {
            boolean onBattery = plugType == BATTERY_PLUGGED_NONE;
            int oldStatus = mHistoryCur.batteryStatus;
            if (!mHaveBatteryLevel) {
@@ -4155,7 +4160,7 @@ public final class BatteryStatsImpl extends BatteryStats {
                mHistoryCur.batteryPlugType = (byte)plugType;
                mHistoryCur.batteryTemperature = (char)temp;
                mHistoryCur.batteryVoltage = (char)volt;
            setOnBattery(onBattery, oldStatus, level);
                setOnBatteryLocked(onBattery, oldStatus, level);
            } else {
                boolean changed = false;
                if (mHistoryCur.batteryLevel != level) {
@@ -4194,6 +4199,7 @@ public final class BatteryStatsImpl extends BatteryStats {
                mRecordingHistory = false;
            }
        }
    }

    public void updateKernelWakelocksLocked() {
        Map<String, KernelWakelockStats> m = readKernelWakelockStats();