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

Commit e95c3cd8 authored by Jeff Brown's avatar Jeff Brown
Browse files

Plumb display state and interactive information to BatteryStats.

Fixes an issue where dozing was treated the same as the screen
being fully on.  Now dozing is treated the same as the screen
being fully off which is slightly better.  The decision of how
to represent this state is now internal to the battery stats
so it can be improved later.

Removed noteInputEvent() since it is unused.

Bug: 14480844
Change-Id: Iee8cf8dce1a1f91c62678bb6d3d9fe567ad6db42
parent c74b3cb6
Loading
Loading
Loading
Loading
+16 −5
Original line number Original line Diff line number Diff line
@@ -911,6 +911,8 @@ public abstract class BatteryStats implements Parcelable {
     */
     */
    public abstract int getScreenOnCount(int which);
    public abstract int getScreenOnCount(int which);


    public abstract long getInteractiveTime(long elapsedRealtimeUs, int which);

    public static final int SCREEN_BRIGHTNESS_DARK = 0;
    public static final int SCREEN_BRIGHTNESS_DARK = 0;
    public static final int SCREEN_BRIGHTNESS_DIM = 1;
    public static final int SCREEN_BRIGHTNESS_DIM = 1;
    public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
    public static final int SCREEN_BRIGHTNESS_MEDIUM = 2;
@@ -936,8 +938,6 @@ public abstract class BatteryStats implements Parcelable {
    public abstract long getScreenBrightnessTime(int brightnessBin,
    public abstract long getScreenBrightnessTime(int brightnessBin,
            long elapsedRealtimeUs, int which);
            long elapsedRealtimeUs, int which);


    public abstract int getInputEventCount(int which);
    
    /**
    /**
     * Returns the time in microseconds that the phone has been on while the device was
     * Returns the time in microseconds that the phone has been on while the device was
     * running on battery.
     * running on battery.
@@ -1571,6 +1571,7 @@ public abstract class BatteryStats implements Parcelable {
        final long totalRealtime = computeRealtime(rawRealtime, which);
        final long totalRealtime = computeRealtime(rawRealtime, which);
        final long totalUptime = computeUptime(rawUptime, which);
        final long totalUptime = computeUptime(rawUptime, which);
        final long screenOnTime = getScreenOnTime(rawRealtime, which);
        final long screenOnTime = getScreenOnTime(rawRealtime, which);
        final long interactiveTime = getInteractiveTime(rawRealtime, which);
        final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
        final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
        final long wifiOnTime = getWifiOnTime(rawRealtime, which);
        final long wifiOnTime = getWifiOnTime(rawRealtime, which);
        final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
        final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
@@ -1639,8 +1640,8 @@ public abstract class BatteryStats implements Parcelable {
                wifiRunningTime / 1000, bluetoothOnTime / 1000,
                wifiRunningTime / 1000, bluetoothOnTime / 1000,
                mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
                mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes,
                fullWakeLockTimeTotal, partialWakeLockTimeTotal,
                fullWakeLockTimeTotal, partialWakeLockTimeTotal,
                getInputEventCount(which), getMobileRadioActiveTime(rawRealtime, which),
                0 /*legacy input event count*/, getMobileRadioActiveTime(rawRealtime, which),
                getMobileRadioActiveAdjustedTime(which));
                getMobileRadioActiveAdjustedTime(which), interactiveTime / 1000);
        
        
        // Dump screen brightness stats
        // Dump screen brightness stats
        Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
        Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
@@ -2013,6 +2014,7 @@ public abstract class BatteryStats implements Parcelable {
                sb.append("realtime, ");
                sb.append("realtime, ");
                formatTimeMs(sb, totalUptime / 1000);
                formatTimeMs(sb, totalUptime / 1000);
                sb.append("uptime");
                sb.append("uptime");
        pw.println(sb.toString());
        if (batteryTimeRemaining >= 0) {
        if (batteryTimeRemaining >= 0) {
            sb.setLength(0);
            sb.setLength(0);
            sb.append(prefix);
            sb.append(prefix);
@@ -2031,16 +2033,25 @@ public abstract class BatteryStats implements Parcelable {
        pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());
        pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString());


        final long screenOnTime = getScreenOnTime(rawRealtime, which);
        final long screenOnTime = getScreenOnTime(rawRealtime, which);
        final long interactiveTime = getInteractiveTime(rawRealtime, which);
        final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
        final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
        final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
        final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
        final long wifiOnTime = getWifiOnTime(rawRealtime, which);
        final long wifiOnTime = getWifiOnTime(rawRealtime, which);
        final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
        final long bluetoothOnTime = getBluetoothOnTime(rawRealtime, which);
        sb.setLength(0);
        sb.setLength(0);
        sb.append(prefix);
                sb.append("  Interactive: "); formatTimeMs(sb, interactiveTime / 1000);
                sb.append("("); sb.append(formatRatioLocked(interactiveTime, whichBatteryRealtime));
                sb.append(")");
        pw.println(sb.toString());
        sb.setLength(0);
        sb.append(prefix);
        sb.append(prefix);
                sb.append("  Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
                sb.append("  Screen on: "); formatTimeMs(sb, screenOnTime / 1000);
                sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
                sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime));
                sb.append(") "); sb.append(getScreenOnCount(which));
                sb.append(") "); sb.append(getScreenOnCount(which));
                sb.append("x, Input events: "); sb.append(getInputEventCount(which));
                sb.append("x, Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000);
                sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
                sb.append(")");
        pw.println(sb.toString());
        pw.println(sb.toString());
        if (phoneOnTime != 0) {
        if (phoneOnTime != 0) {
            sb.setLength(0);
            sb.setLength(0);
+2 −3
Original line number Original line Diff line number Diff line
@@ -59,11 +59,10 @@ interface IBatteryStats {
    void noteVibratorOff(int uid);
    void noteVibratorOff(int uid);
    void noteStartGps(int uid);
    void noteStartGps(int uid);
    void noteStopGps(int uid);
    void noteStopGps(int uid);
    void noteScreenOn();
    void noteScreenState(int state);
    void noteScreenBrightness(int brightness);
    void noteScreenBrightness(int brightness);
    void noteScreenOff();
    void noteInputEvent();
    void noteUserActivity(int uid, int event);
    void noteUserActivity(int uid, int event);
    void noteInteractive(boolean interactive);
    void noteMobileRadioPowerState(int powerState, long timestampNs);
    void noteMobileRadioPowerState(int powerState, long timestampNs);
    void notePhoneOn();
    void notePhoneOn();
    void notePhoneOff();
    void notePhoneOff();
+101 −79
Original line number Original line Diff line number Diff line
@@ -51,6 +51,7 @@ import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.SparseBooleanArray;
import android.util.SparseIntArray;
import android.util.SparseIntArray;
import android.util.TimeUtils;
import android.util.TimeUtils;
import android.view.Display;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.net.NetworkStatsFactory;
import com.android.internal.net.NetworkStatsFactory;
@@ -88,7 +89,7 @@ public final class BatteryStatsImpl extends BatteryStats {
    private static final int MAGIC = 0xBA757475; // 'BATSTATS'
    private static final int MAGIC = 0xBA757475; // 'BATSTATS'


    // Current on-disk Parcel version
    // Current on-disk Parcel version
    private static final int VERSION = 104 + (USE_OLD_HISTORY ? 1000 : 0);
    private static final int VERSION = 105 + (USE_OLD_HISTORY ? 1000 : 0);


    // Maximum number of items we will record in the history.
    // Maximum number of items we will record in the history.
    private static final int MAX_HISTORY_ITEMS = 2000;
    private static final int MAX_HISTORY_ITEMS = 2000;
@@ -237,13 +238,14 @@ public final class BatteryStatsImpl extends BatteryStats {
    int mWakeLockNesting;
    int mWakeLockNesting;
    boolean mWakeLockImportant;
    boolean mWakeLockImportant;


    boolean mScreenOn;
    int mScreenState = Display.STATE_UNKNOWN;
    StopwatchTimer mScreenOnTimer;
    StopwatchTimer mScreenOnTimer;


    int mScreenBrightnessBin = -1;
    int mScreenBrightnessBin = -1;
    final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS];
    final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS];


    Counter mInputEventCounter;
    boolean mInteractive;
    StopwatchTimer mInteractiveTimer;


    boolean mPhoneOn;
    boolean mPhoneOn;
    StopwatchTimer mPhoneOnTimer;
    StopwatchTimer mPhoneOnTimer;
@@ -2661,15 +2663,21 @@ public final class BatteryStatsImpl extends BatteryStats {
        getUidStatsLocked(uid).noteStopGps(elapsedRealtime);
        getUidStatsLocked(uid).noteStopGps(elapsedRealtime);
    }
    }


    public void noteScreenOnLocked() {
    public void noteScreenStateLocked(int state) {
        if (!mScreenOn) {
        if (mScreenState != state) {
            final int oldState = mScreenState;
            mScreenState = state;
            if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState)
                    + ", newState=" + Display.stateToString(state));

            if (state == Display.STATE_ON) {
                // Screen turning on.
                final long elapsedRealtime = SystemClock.elapsedRealtime();
                final long elapsedRealtime = SystemClock.elapsedRealtime();
                final long uptime = SystemClock.uptimeMillis();
                final long uptime = SystemClock.uptimeMillis();
                mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG;
                mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG;
                if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: "
                if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: "
                        + Integer.toHexString(mHistoryCur.states));
                        + Integer.toHexString(mHistoryCur.states));
                addHistoryRecordLocked(elapsedRealtime, uptime);
                addHistoryRecordLocked(elapsedRealtime, uptime);
            mScreenOn = true;
                mScreenOnTimer.startRunningLocked(elapsedRealtime);
                mScreenOnTimer.startRunningLocked(elapsedRealtime);
                if (mScreenBrightnessBin >= 0) {
                if (mScreenBrightnessBin >= 0) {
                    mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime);
                    mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(elapsedRealtime);
@@ -2687,18 +2695,14 @@ public final class BatteryStatsImpl extends BatteryStats {
                if (mOnBatteryInternal) {
                if (mOnBatteryInternal) {
                    updateDischargeScreenLevelsLocked(false, true);
                    updateDischargeScreenLevelsLocked(false, true);
                }
                }
        }
            } else if (oldState == Display.STATE_ON) {
    }
                // Screen turning off or dozing.

    public void noteScreenOffLocked() {
        if (mScreenOn) {
                final long elapsedRealtime = SystemClock.elapsedRealtime();
                final long elapsedRealtime = SystemClock.elapsedRealtime();
                final long uptime = SystemClock.uptimeMillis();
                final long uptime = SystemClock.uptimeMillis();
                mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG;
                mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG;
                if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: "
                if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: "
                        + Integer.toHexString(mHistoryCur.states));
                        + Integer.toHexString(mHistoryCur.states));
                addHistoryRecordLocked(elapsedRealtime, uptime);
                addHistoryRecordLocked(elapsedRealtime, uptime);
            mScreenOn = false;
                mScreenOnTimer.stopRunningLocked(elapsedRealtime);
                mScreenOnTimer.stopRunningLocked(elapsedRealtime);
                if (mScreenBrightnessBin >= 0) {
                if (mScreenBrightnessBin >= 0) {
                    mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime);
                    mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime);
@@ -2716,6 +2720,7 @@ public final class BatteryStatsImpl extends BatteryStats {
                }
                }
            }
            }
        }
        }
    }


    public void noteScreenBrightnessLocked(int brightness) {
    public void noteScreenBrightnessLocked(int brightness) {
        // Bin the brightness.
        // Bin the brightness.
@@ -2730,7 +2735,7 @@ public final class BatteryStatsImpl extends BatteryStats {
            if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: "
            if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: "
                    + Integer.toHexString(mHistoryCur.states));
                    + Integer.toHexString(mHistoryCur.states));
            addHistoryRecordLocked(elapsedRealtime, uptime);
            addHistoryRecordLocked(elapsedRealtime, uptime);
            if (mScreenOn) {
            if (mScreenState == Display.STATE_ON) {
                if (mScreenBrightnessBin >= 0) {
                if (mScreenBrightnessBin >= 0) {
                    mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime);
                    mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(elapsedRealtime);
                }
                }
@@ -2740,10 +2745,6 @@ public final class BatteryStatsImpl extends BatteryStats {
        }
        }
    }
    }


    public void noteInputEventAtomic() {
        mInputEventCounter.stepAtomic();
    }

    public void noteUserActivityLocked(int uid, int event) {
    public void noteUserActivityLocked(int uid, int event) {
        if (mOnBatteryInternal) {
        if (mOnBatteryInternal) {
            uid = mapUid(uid);
            uid = mapUid(uid);
@@ -2751,6 +2752,19 @@ public final class BatteryStatsImpl extends BatteryStats {
        }
        }
    }
    }


    public void noteInteractiveLocked(boolean interactive) {
        if (mInteractive != interactive) {
            final long elapsedRealtime = SystemClock.elapsedRealtime();
            mInteractive = interactive;
            if (DEBUG) Slog.v(TAG, "Interactive: " + interactive);
            if (interactive) {
                mInteractiveTimer.startRunningLocked(elapsedRealtime);
            } else {
                mInteractiveTimer.stopRunningLocked(elapsedRealtime);
            }
        }
    }

    public void noteMobileRadioPowerState(int powerState, long timestampNs) {
    public void noteMobileRadioPowerState(int powerState, long timestampNs) {
        final long elapsedRealtime = SystemClock.elapsedRealtime();
        final long elapsedRealtime = SystemClock.elapsedRealtime();
        final long uptime = SystemClock.uptimeMillis();
        final long uptime = SystemClock.uptimeMillis();
@@ -3449,8 +3463,8 @@ public final class BatteryStatsImpl extends BatteryStats {
                elapsedRealtimeUs, which);
                elapsedRealtimeUs, which);
    }
    }


    @Override public int getInputEventCount(int which) {
    @Override public long getInteractiveTime(long elapsedRealtimeUs, int which) {
        return mInputEventCounter.getCountLocked(which);
        return mInteractiveTimer.getTotalTimeLocked(elapsedRealtimeUs, which);
    }
    }


    @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) {
    @Override public long getPhoneOnTime(long elapsedRealtimeUs, int which) {
@@ -5499,7 +5513,6 @@ public final class BatteryStatsImpl extends BatteryStats {
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
            mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase);
            mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase);
        }
        }
        mInputEventCounter = new Counter(mOnBatteryTimeBase);
        mPhoneOnTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase);
        mPhoneOnTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase);
        for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
        for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
            mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, null,
            mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, null,
@@ -5530,6 +5543,7 @@ public final class BatteryStatsImpl extends BatteryStats {
        }
        }
        mAudioOnTimer = new StopwatchTimer(null, -6, null, mOnBatteryTimeBase);
        mAudioOnTimer = new StopwatchTimer(null, -6, null, mOnBatteryTimeBase);
        mVideoOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase);
        mVideoOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase);
        mInteractiveTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase);
        mOnBattery = mOnBatteryInternal = false;
        mOnBattery = mOnBatteryInternal = false;
        long uptime = SystemClock.uptimeMillis() * 1000;
        long uptime = SystemClock.uptimeMillis() * 1000;
        long realtime = SystemClock.elapsedRealtime() * 1000;
        long realtime = SystemClock.elapsedRealtime() * 1000;
@@ -5713,7 +5727,7 @@ public final class BatteryStatsImpl extends BatteryStats {
    }
    }


    public boolean isScreenOn() {
    public boolean isScreenOn() {
        return mScreenOn;
        return mScreenState == Display.STATE_ON;
    }
    }


    void initTimes(long uptime, long realtime) {
    void initTimes(long uptime, long realtime) {
@@ -5753,7 +5767,7 @@ public final class BatteryStatsImpl extends BatteryStats {
        mOnBatteryTimeBase.reset(uptime, realtime);
        mOnBatteryTimeBase.reset(uptime, realtime);
        mOnBatteryScreenOffTimeBase.reset(uptime, realtime);
        mOnBatteryScreenOffTimeBase.reset(uptime, realtime);
        if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) {
        if ((mHistoryCur.states&HistoryItem.STATE_BATTERY_PLUGGED_FLAG) == 0) {
            if (mScreenOn) {
            if (mScreenState == Display.STATE_ON) {
                mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel;
                mDischargeScreenOnUnplugLevel = mHistoryCur.batteryLevel;
                mDischargeScreenOffUnplugLevel = 0;
                mDischargeScreenOffUnplugLevel = 0;
            } else {
            } else {
@@ -5773,7 +5787,7 @@ public final class BatteryStatsImpl extends BatteryStats {
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
            mScreenBrightnessTimer[i].reset(false);
            mScreenBrightnessTimer[i].reset(false);
        }
        }
        mInputEventCounter.reset(false);
        mInteractiveTimer.reset(false);
        mPhoneOnTimer.reset(false);
        mPhoneOnTimer.reset(false);
        mAudioOnTimer.reset(false);
        mAudioOnTimer.reset(false);
        mVideoOnTimer.reset(false);
        mVideoOnTimer.reset(false);
@@ -5874,7 +5888,8 @@ public final class BatteryStatsImpl extends BatteryStats {
        updateKernelWakelocksLocked();
        updateKernelWakelocksLocked();
        updateNetworkActivityLocked(NET_UPDATE_ALL, SystemClock.elapsedRealtime());
        updateNetworkActivityLocked(NET_UPDATE_ALL, SystemClock.elapsedRealtime());
        if (mOnBatteryInternal) {
        if (mOnBatteryInternal) {
            updateDischargeScreenLevelsLocked(mScreenOn, mScreenOn);
            final boolean screenOn = mScreenState == Display.STATE_ON;
            updateDischargeScreenLevelsLocked(screenOn, screenOn);
        }
        }
    }
    }


@@ -5888,6 +5903,7 @@ public final class BatteryStatsImpl extends BatteryStats {


        final long uptime = mSecUptime * 1000;
        final long uptime = mSecUptime * 1000;
        final long realtime = mSecRealtime * 1000;
        final long realtime = mSecRealtime * 1000;
        final boolean screenOn = mScreenState == Display.STATE_ON;
        if (onBattery) {
        if (onBattery) {
            // We will reset our status if we are unplugging after the
            // We will reset our status if we are unplugging after the
            // battery was last full, or the level is at 100, or
            // battery was last full, or the level is at 100, or
@@ -5916,7 +5932,7 @@ public final class BatteryStatsImpl extends BatteryStats {
            }
            }
            addHistoryRecordLocked(mSecRealtime, mSecUptime);
            addHistoryRecordLocked(mSecRealtime, mSecUptime);
            mDischargeCurrentLevel = mDischargeUnplugLevel = level;
            mDischargeCurrentLevel = mDischargeUnplugLevel = level;
            if (mScreenOn) {
            if (screenOn) {
                mDischargeScreenOnUnplugLevel = level;
                mDischargeScreenOnUnplugLevel = level;
                mDischargeScreenOffUnplugLevel = 0;
                mDischargeScreenOffUnplugLevel = 0;
            } else {
            } else {
@@ -5925,7 +5941,7 @@ public final class BatteryStatsImpl extends BatteryStats {
            }
            }
            mDischargeAmountScreenOn = 0;
            mDischargeAmountScreenOn = 0;
            mDischargeAmountScreenOff = 0;
            mDischargeAmountScreenOff = 0;
            updateTimeBasesLocked(true, !mScreenOn, uptime, realtime);
            updateTimeBasesLocked(true, !screenOn, uptime, realtime);
        } else {
        } else {
            pullPendingStateUpdatesLocked();
            pullPendingStateUpdatesLocked();
            mHistoryCur.batteryLevel = (byte)level;
            mHistoryCur.batteryLevel = (byte)level;
@@ -5938,8 +5954,8 @@ public final class BatteryStatsImpl extends BatteryStats {
                mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1;
                mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1;
                mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level;
                mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level;
            }
            }
            updateDischargeScreenLevelsLocked(mScreenOn, mScreenOn);
            updateDischargeScreenLevelsLocked(screenOn, screenOn);
            updateTimeBasesLocked(false, !mScreenOn, uptime, realtime);
            updateTimeBasesLocked(false, !screenOn, uptime, realtime);
            mNumChargeStepDurations = 0;
            mNumChargeStepDurations = 0;
            mLastChargeStepLevel = level;
            mLastChargeStepLevel = level;
            mLastChargeStepTime = -1;
            mLastChargeStepTime = -1;
@@ -6475,7 +6491,7 @@ public final class BatteryStatsImpl extends BatteryStats {
    public int getDischargeAmountScreenOn() {
    public int getDischargeAmountScreenOn() {
        synchronized(this) {
        synchronized(this) {
            int val = mDischargeAmountScreenOn;
            int val = mDischargeAmountScreenOn;
            if (mOnBattery && mScreenOn
            if (mOnBattery && mScreenState == Display.STATE_ON
                    && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) {
                    && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) {
                val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel;
                val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel;
            }
            }
@@ -6486,7 +6502,7 @@ public final class BatteryStatsImpl extends BatteryStats {
    public int getDischargeAmountScreenOnSinceCharge() {
    public int getDischargeAmountScreenOnSinceCharge() {
        synchronized(this) {
        synchronized(this) {
            int val = mDischargeAmountScreenOnSinceCharge;
            int val = mDischargeAmountScreenOnSinceCharge;
            if (mOnBattery && mScreenOn
            if (mOnBattery && mScreenState == Display.STATE_ON
                    && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) {
                    && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) {
                val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel;
                val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel;
            }
            }
@@ -6497,7 +6513,7 @@ public final class BatteryStatsImpl extends BatteryStats {
    public int getDischargeAmountScreenOff() {
    public int getDischargeAmountScreenOff() {
        synchronized(this) {
        synchronized(this) {
            int val = mDischargeAmountScreenOff;
            int val = mDischargeAmountScreenOff;
            if (mOnBattery && !mScreenOn
            if (mOnBattery && mScreenState != Display.STATE_ON
                    && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) {
                    && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) {
                val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel;
                val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel;
            }
            }
@@ -6508,7 +6524,7 @@ public final class BatteryStatsImpl extends BatteryStats {
    public int getDischargeAmountScreenOffSinceCharge() {
    public int getDischargeAmountScreenOffSinceCharge() {
        synchronized(this) {
        synchronized(this) {
            int val = mDischargeAmountScreenOffSinceCharge;
            int val = mDischargeAmountScreenOffSinceCharge;
            if (mOnBattery && !mScreenOn
            if (mOnBattery && mScreenState != Display.STATE_ON
                    && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) {
                    && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) {
                val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel;
                val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel;
            }
            }
@@ -6915,12 +6931,13 @@ public final class BatteryStatsImpl extends BatteryStats {


        mStartCount++;
        mStartCount++;


        mScreenOn = false;
        mScreenState = Display.STATE_UNKNOWN;
        mScreenOnTimer.readSummaryFromParcelLocked(in);
        mScreenOnTimer.readSummaryFromParcelLocked(in);
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
            mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in);
            mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in);
        }
        }
        mInputEventCounter.readSummaryFromParcelLocked(in);
        mInteractive = false;
        mInteractiveTimer.readSummaryFromParcelLocked(in);
        mPhoneOn = false;
        mPhoneOn = false;
        mPhoneOnTimer.readSummaryFromParcelLocked(in);
        mPhoneOnTimer.readSummaryFromParcelLocked(in);
        for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
        for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
@@ -7175,7 +7192,7 @@ public final class BatteryStatsImpl extends BatteryStats {
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
            mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS);
            mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS);
        }
        }
        mInputEventCounter.writeSummaryFromParcelLocked(out);
        mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS);
        mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS);
        mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL_SYS);
        for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
        for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
            mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS);
            mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL_SYS);
@@ -7431,13 +7448,12 @@ public final class BatteryStatsImpl extends BatteryStats {
        mOnBatteryTimeBase.readFromParcel(in);
        mOnBatteryTimeBase.readFromParcel(in);
        mOnBatteryScreenOffTimeBase.readFromParcel(in);
        mOnBatteryScreenOffTimeBase.readFromParcel(in);


        mScreenOn = false;
        mScreenState = Display.STATE_UNKNOWN;
        mScreenOnTimer = new StopwatchTimer(null, -1, null, mOnBatteryTimeBase, in);
        mScreenOnTimer = new StopwatchTimer(null, -1, null, mOnBatteryTimeBase, in);
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
            mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase,
            mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mOnBatteryTimeBase,
                    in);
                    in);
        }
        }
        mInputEventCounter = new Counter(mOnBatteryTimeBase, in);
        mPhoneOn = false;
        mPhoneOn = false;
        mPhoneOnTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase, in);
        mPhoneOnTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase, in);
        for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
        for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
@@ -7461,19 +7477,25 @@ public final class BatteryStatsImpl extends BatteryStats {
        mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in);
        mMobileRadioActiveUnknownTime = new LongSamplingCounter(mOnBatteryTimeBase, in);
        mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in);
        mMobileRadioActiveUnknownCount = new LongSamplingCounter(mOnBatteryTimeBase, in);
        mWifiOn = false;
        mWifiOn = false;
        mWifiOnTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase, in);
        mWifiOnTimer = new StopwatchTimer(null, -3, null, mOnBatteryTimeBase, in);
        mGlobalWifiRunning = false;
        mGlobalWifiRunning = false;
        mGlobalWifiRunningTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase, in);
        mGlobalWifiRunningTimer = new StopwatchTimer(null, -4, null, mOnBatteryTimeBase, in);
        for (int i=0; i<NUM_WIFI_STATES; i++) {
        for (int i=0; i<NUM_WIFI_STATES; i++) {
            mWifiStateTimer[i] = new StopwatchTimer(null, -600-i,
            mWifiStateTimer[i] = new StopwatchTimer(null, -600-i,
                    null, mOnBatteryTimeBase, in);
                    null, mOnBatteryTimeBase, in);
        }
        }
        mBluetoothOn = false;
        mBluetoothOn = false;
        mBluetoothOnTimer = new StopwatchTimer(null, -2, null, mOnBatteryTimeBase, in);
        mBluetoothOnTimer = new StopwatchTimer(null, -5, null, mOnBatteryTimeBase, in);
        for (int i=0; i< NUM_BLUETOOTH_STATES; i++) {
        for (int i=0; i< NUM_BLUETOOTH_STATES; i++) {
            mBluetoothStateTimer[i] = new StopwatchTimer(null, -500-i,
            mBluetoothStateTimer[i] = new StopwatchTimer(null, -500-i,
                    null, mOnBatteryTimeBase, in);
                    null, mOnBatteryTimeBase, in);
        }
        }
        mAudioOn = false;
        mAudioOnTimer = new StopwatchTimer(null, -6, null, mOnBatteryTimeBase);
        mVideoOn = false;
        mVideoOnTimer = new StopwatchTimer(null, -7, null, mOnBatteryTimeBase);
        mInteractive = false;
        mInteractiveTimer = new StopwatchTimer(null, -8, null, mOnBatteryTimeBase, in);
        mDischargeUnplugLevel = in.readInt();
        mDischargeUnplugLevel = in.readInt();
        mDischargePlugLevel = in.readInt();
        mDischargePlugLevel = in.readInt();
        mDischargeCurrentLevel = in.readInt();
        mDischargeCurrentLevel = in.readInt();
@@ -7571,7 +7593,7 @@ public final class BatteryStatsImpl extends BatteryStats {
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
        for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
            mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime);
            mScreenBrightnessTimer[i].writeToParcel(out, uSecRealtime);
        }
        }
        mInputEventCounter.writeToParcel(out);
        mInteractiveTimer.writeToParcel(out, uSecRealtime);
        mPhoneOnTimer.writeToParcel(out, uSecRealtime);
        mPhoneOnTimer.writeToParcel(out, uSecRealtime);
        for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
        for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
            mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime);
            mPhoneSignalStrengthsTimer[i].writeToParcel(out, uSecRealtime);
@@ -7688,8 +7710,8 @@ public final class BatteryStatsImpl extends BatteryStats {
                pr.println("*** Screen brightness #" + i + ":");
                pr.println("*** Screen brightness #" + i + ":");
                mScreenBrightnessTimer[i].logState(pr, "  ");
                mScreenBrightnessTimer[i].logState(pr, "  ");
            }
            }
            pr.println("*** Input event counter:");
            pr.println("*** Interactive timer:");
            mInputEventCounter.logState(pr, "  ");
            mInteractiveTimer.logState(pr, "  ");
            pr.println("*** Phone timer:");
            pr.println("*** Phone timer:");
            mPhoneOnTimer.logState(pr, "  ");
            mPhoneOnTimer.logState(pr, "  ");
            for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
            for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
+6 −11
Original line number Original line Diff line number Diff line
@@ -230,10 +230,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
        }
        }
    }
    }
        
        
    public void noteScreenOn() {
    public void noteScreenState(int state) {
        enforceCallingPermission();
        enforceCallingPermission();
        synchronized (mStats) {
        synchronized (mStats) {
            mStats.noteScreenOnLocked();
            mStats.noteScreenStateLocked(state);
        }
        }
    }
    }
    
    
@@ -244,22 +244,17 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
        }
        }
    }
    }
    
    
    public void noteScreenOff() {
    public void noteUserActivity(int uid, int event) {
        enforceCallingPermission();
        enforceCallingPermission();
        synchronized (mStats) {
        synchronized (mStats) {
            mStats.noteScreenOffLocked();
            mStats.noteUserActivityLocked(uid, event);
        }
        }
    }
    }
    
    
    public void noteInputEvent() {
    public void noteInteractive(boolean interactive) {
        enforceCallingPermission();
        mStats.noteInputEventAtomic();
    }
    
    public void noteUserActivity(int uid, int event) {
        enforceCallingPermission();
        enforceCallingPermission();
        synchronized (mStats) {
        synchronized (mStats) {
            mStats.noteUserActivityLocked(uid, event);
            mStats.noteInteractiveLocked(interactive);
        }
        }
    }
    }


+2 −10
Original line number Original line Diff line number Diff line
@@ -393,11 +393,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call


        // Initialize screen state for battery stats.
        // Initialize screen state for battery stats.
        try {
        try {
            if (mPowerState.getScreenState() != Display.STATE_OFF) {
            mBatteryStats.noteScreenState(mPowerState.getScreenState());
                mBatteryStats.noteScreenOn();
            } else {
                mBatteryStats.noteScreenOff();
            }
            mBatteryStats.noteScreenBrightness(mPowerState.getScreenBrightness());
            mBatteryStats.noteScreenBrightness(mPowerState.getScreenBrightness());
        } catch (RemoteException ex) {
        } catch (RemoteException ex) {
            // same process
            // same process
@@ -641,11 +637,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        if (mPowerState.getScreenState() != state) {
        if (mPowerState.getScreenState() != state) {
            mPowerState.setScreenState(state);
            mPowerState.setScreenState(state);
            try {
            try {
                if (state != Display.STATE_OFF) {
                mBatteryStats.noteScreenState(state);
                    mBatteryStats.noteScreenOn();
                } else {
                    mBatteryStats.noteScreenOff();
                }
            } catch (RemoteException ex) {
            } catch (RemoteException ex) {
                // same process
                // same process
            }
            }
Loading