diff options
| author | Jeff Brown <jeffbrown@google.com> | 2014-05-06 20:30:49 +0000 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2014-05-06 20:30:49 +0000 |
| commit | a93369a819c9d4cfd4fe7ce3dd519f1c974bce4d (patch) | |
| tree | 53cde5487397c666ab5fa634bcbadce41f923f8f | |
| parent | c41fa708271e204a7983aba291389ea1554227b2 (diff) | |
| parent | 84aaf124b762b9eeb0957aaea9df8424a429b148 (diff) | |
| download | frameworks_base-a93369a819c9d4cfd4fe7ce3dd519f1c974bce4d.zip frameworks_base-a93369a819c9d4cfd4fe7ce3dd519f1c974bce4d.tar.gz frameworks_base-a93369a819c9d4cfd4fe7ce3dd519f1c974bce4d.tar.bz2 | |
am 84aaf124: Merge "Plumb display state and interactive information to BatteryStats. (DO NOT MERGE)" into klp-modular-dev
* commit '84aaf124b762b9eeb0957aaea9df8424a429b148':
Plumb display state and interactive information to BatteryStats. (DO NOT MERGE)
6 files changed, 136 insertions, 94 deletions
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java index b1a9ea3..5736c7a 100644 --- a/core/java/android/os/BatteryStats.java +++ b/core/java/android/os/BatteryStats.java @@ -782,7 +782,9 @@ public abstract class BatteryStats implements Parcelable { * {@hide} */ public abstract long getScreenOnTime(long batteryRealtime, int which); - + + public abstract long getInteractiveTime(long batteryRealtime, int which); + public static final int SCREEN_BRIGHTNESS_DARK = 0; public static final int SCREEN_BRIGHTNESS_DIM = 1; public static final int SCREEN_BRIGHTNESS_MEDIUM = 2; @@ -804,8 +806,6 @@ public abstract class BatteryStats implements Parcelable { public abstract long getScreenBrightnessTime(int brightnessBin, long batteryRealtime, int which); - public abstract int getInputEventCount(int which); - /** * Returns the time in microseconds that the phone has been on while the device was * running on battery. @@ -1303,7 +1303,7 @@ public abstract class BatteryStats implements Parcelable { wifiRunningTime / 1000, bluetoothOnTime / 1000, mobileRxTotal, mobileTxTotal, wifiRxTotal, wifiTxTotal, fullWakeLockTimeTotal, partialWakeLockTimeTotal, - getInputEventCount(which)); + 0 /*legacy input event count*/); // Dump screen brightness stats Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS]; @@ -1564,16 +1564,22 @@ public abstract class BatteryStats implements Parcelable { pw.println(sb.toString()); final long screenOnTime = getScreenOnTime(batteryRealtime, which); + final long interactiveTime = getInteractiveTime(batteryRealtime, which); final long phoneOnTime = getPhoneOnTime(batteryRealtime, which); final long wifiRunningTime = getGlobalWifiRunningTime(batteryRealtime, which); final long wifiOnTime = getWifiOnTime(batteryRealtime, which); final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which); 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(" Screen on: "); formatTimeMs(sb, screenOnTime / 1000); sb.append("("); sb.append(formatRatioLocked(screenOnTime, whichBatteryRealtime)); - sb.append("), Input events: "); sb.append(getInputEventCount(which)); - sb.append(", Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); + sb.append("), Active phone call: "); formatTimeMs(sb, phoneOnTime / 1000); sb.append("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime)); sb.append(")"); pw.println(sb.toString()); diff --git a/core/java/com/android/internal/app/IBatteryStats.aidl b/core/java/com/android/internal/app/IBatteryStats.aidl index 43c4b49..5413113 100644 --- a/core/java/com/android/internal/app/IBatteryStats.aidl +++ b/core/java/com/android/internal/app/IBatteryStats.aidl @@ -41,11 +41,10 @@ interface IBatteryStats { void noteVibratorOff(int uid); void noteStartGps(int uid); void noteStopGps(int uid); - void noteScreenOn(); + void noteScreenState(int state); void noteScreenBrightness(int brightness); - void noteScreenOff(); - void noteInputEvent(); void noteUserActivity(int uid, int event); + void noteInteractive(boolean interactive); void notePhoneOn(); void notePhoneOff(); void notePhoneSignalStrength(in SignalStrength signalStrength); diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java index 8728610..9c82fac 100644 --- a/core/java/com/android/internal/os/BatteryStatsImpl.java +++ b/core/java/com/android/internal/os/BatteryStatsImpl.java @@ -45,6 +45,7 @@ import android.util.Printer; import android.util.Slog; import android.util.SparseArray; import android.util.TimeUtils; +import android.view.Display; import com.android.internal.annotations.GuardedBy; import com.android.internal.net.NetworkStatsFactory; @@ -85,7 +86,7 @@ public final class BatteryStatsImpl extends BatteryStats { private static final int MAGIC = 0xBA757475; // 'BATSTATS' // Current on-disk Parcel version - private static final int VERSION = 67 + (USE_OLD_HISTORY ? 1000 : 0); + private static final int VERSION = 68 + (USE_OLD_HISTORY ? 1000 : 0); // Maximum number of items we will record in the history. private static final int MAX_HISTORY_ITEMS = 2000; @@ -211,13 +212,14 @@ public final class BatteryStatsImpl extends BatteryStats { long mRealtimeStart; long mLastRealtime; - boolean mScreenOn; + int mScreenState = Display.STATE_UNKNOWN; StopwatchTimer mScreenOnTimer; int mScreenBrightnessBin = -1; final StopwatchTimer[] mScreenBrightnessTimer = new StopwatchTimer[NUM_SCREEN_BRIGHTNESS_BINS]; - Counter mInputEventCounter; + boolean mInteractive; + StopwatchTimer mInteractiveTimer; boolean mPhoneOn; StopwatchTimer mPhoneOnTimer; @@ -1742,7 +1744,7 @@ public final class BatteryStatsImpl extends BatteryStats { public int startAddingCpuLocked() { mHandler.removeMessages(MSG_UPDATE_WAKELOCKS); - if (mScreenOn) { + if (mScreenState == Display.STATE_ON) { return 0; } @@ -1917,46 +1919,49 @@ public final class BatteryStatsImpl extends BatteryStats { getUidStatsLocked(uid).noteStopGps(); } - public void noteScreenOnLocked() { - if (!mScreenOn) { - mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; - if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " - + Integer.toHexString(mHistoryCur.states)); - addHistoryRecordLocked(SystemClock.elapsedRealtime()); - mScreenOn = true; - mScreenOnTimer.startRunningLocked(this); - if (mScreenBrightnessBin >= 0) { - mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(this); - } + public void noteScreenStateLocked(int state) { + if (mScreenState != state) { + final int oldState = mScreenState; + mScreenState = state; + if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState) + + ", newState=" + Display.stateToString(state)); - // Fake a wake lock, so we consider the device waked as long - // as the screen is on. - noteStartWakeLocked(-1, -1, "dummy", WAKE_TYPE_PARTIAL); - - // Update discharge amounts. - if (mOnBatteryInternal) { - updateDischargeScreenLevelsLocked(false, true); - } - } - } + if (state == Display.STATE_ON) { + // Screen turning on. + mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG; + if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: " + + Integer.toHexString(mHistoryCur.states)); + addHistoryRecordLocked(SystemClock.elapsedRealtime()); + mScreenOnTimer.startRunningLocked(this); + if (mScreenBrightnessBin >= 0) { + mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(this); + } - public void noteScreenOffLocked() { - if (mScreenOn) { - mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; - if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " - + Integer.toHexString(mHistoryCur.states)); - addHistoryRecordLocked(SystemClock.elapsedRealtime()); - mScreenOn = false; - mScreenOnTimer.stopRunningLocked(this); - if (mScreenBrightnessBin >= 0) { - mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(this); - } + // Fake a wake lock, so we consider the device waked as long + // as the screen is on. + noteStartWakeLocked(-1, -1, "dummy", WAKE_TYPE_PARTIAL); - noteStopWakeLocked(-1, -1, "dummy", WAKE_TYPE_PARTIAL); - - // Update discharge amounts. - if (mOnBatteryInternal) { - updateDischargeScreenLevelsLocked(true, false); + // Update discharge amounts. + if (mOnBatteryInternal) { + updateDischargeScreenLevelsLocked(false, true); + } + } else if (oldState == Display.STATE_ON) { + // Screen turning off or dozing. + mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG; + if (DEBUG_HISTORY) Slog.v(TAG, "Screen off to: " + + Integer.toHexString(mHistoryCur.states)); + addHistoryRecordLocked(SystemClock.elapsedRealtime()); + mScreenOnTimer.stopRunningLocked(this); + if (mScreenBrightnessBin >= 0) { + mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(this); + } + + noteStopWakeLocked(-1, -1, "dummy", WAKE_TYPE_PARTIAL); + + // Update discharge amounts. + if (mOnBatteryInternal) { + updateDischargeScreenLevelsLocked(true, false); + } } } } @@ -1972,7 +1977,7 @@ public final class BatteryStatsImpl extends BatteryStats { if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: " + Integer.toHexString(mHistoryCur.states)); addHistoryRecordLocked(SystemClock.elapsedRealtime()); - if (mScreenOn) { + if (mScreenState == Display.STATE_ON) { if (mScreenBrightnessBin >= 0) { mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(this); } @@ -1982,14 +1987,22 @@ public final class BatteryStatsImpl extends BatteryStats { } } - public void noteInputEventAtomic() { - mInputEventCounter.stepAtomic(); - } - public void noteUserActivityLocked(int uid, int event) { getUidStatsLocked(uid).noteUserActivityLocked(event); } + public void noteInteractiveLocked(boolean interactive) { + if (mInteractive != interactive) { + mInteractive = interactive; + if (DEBUG) Slog.v(TAG, "Interactive: " + interactive); + if (interactive) { + mInteractiveTimer.startRunningLocked(this); + } else { + mInteractiveTimer.stopRunningLocked(this); + } + } + } + public void notePhoneOnLocked() { if (!mPhoneOn) { mHistoryCur.states |= HistoryItem.STATE_PHONE_IN_CALL_FLAG; @@ -2529,8 +2542,8 @@ public final class BatteryStatsImpl extends BatteryStats { batteryRealtime, which); } - @Override public int getInputEventCount(int which) { - return mInputEventCounter.getCountLocked(which); + @Override public long getInteractiveTime(long batteryRealtime, int which) { + return mInteractiveTimer.getTotalTimeLocked(batteryRealtime, which); } @Override public long getPhoneOnTime(long batteryRealtime, int which) { @@ -4500,7 +4513,6 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mUnpluggables); } - mInputEventCounter = new Counter(mUnpluggables); mPhoneOnTimer = new StopwatchTimer(null, -2, null, mUnpluggables); for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { mPhoneSignalStrengthsTimer[i] = new StopwatchTimer(null, -200-i, null, mUnpluggables); @@ -4517,6 +4529,7 @@ public final class BatteryStatsImpl extends BatteryStats { mBluetoothOnTimer = new StopwatchTimer(null, -5, null, mUnpluggables); mAudioOnTimer = new StopwatchTimer(null, -6, null, mUnpluggables); mVideoOnTimer = new StopwatchTimer(null, -7, null, mUnpluggables); + mInteractiveTimer = new StopwatchTimer(null, -8, null, mUnpluggables); mOnBattery = mOnBatteryInternal = false; initTimes(); mTrackBatteryPastUptime = 0; @@ -4649,7 +4662,7 @@ public final class BatteryStatsImpl extends BatteryStats { } public boolean isScreenOn() { - return mScreenOn; + return mScreenState == Display.STATE_ON; } void initTimes() { @@ -4677,7 +4690,7 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { mScreenBrightnessTimer[i].reset(this, false); } - mInputEventCounter.reset(false); + mInteractiveTimer.reset(this, false); mPhoneOnTimer.reset(this, false); mAudioOnTimer.reset(this, false); mVideoOnTimer.reset(this, false); @@ -4753,6 +4766,7 @@ public final class BatteryStatsImpl extends BatteryStats { long uptime = SystemClock.uptimeMillis() * 1000; long mSecRealtime = SystemClock.elapsedRealtime(); long realtime = mSecRealtime * 1000; + final boolean screenOn = mScreenState == Display.STATE_ON; if (onBattery) { // We will reset our status if we are unplugging after the // battery was last full, or the level is at 100, or @@ -4777,7 +4791,7 @@ public final class BatteryStatsImpl extends BatteryStats { mUnpluggedBatteryUptime = getBatteryUptimeLocked(uptime); mUnpluggedBatteryRealtime = getBatteryRealtimeLocked(realtime); mDischargeCurrentLevel = mDischargeUnplugLevel = level; - if (mScreenOn) { + if (screenOn) { mDischargeScreenOnUnplugLevel = level; mDischargeScreenOffUnplugLevel = 0; } else { @@ -4802,7 +4816,7 @@ public final class BatteryStatsImpl extends BatteryStats { mLowDischargeAmountSinceCharge += mDischargeUnplugLevel-level-1; mHighDischargeAmountSinceCharge += mDischargeUnplugLevel-level; } - updateDischargeScreenLevelsLocked(mScreenOn, mScreenOn); + updateDischargeScreenLevelsLocked(screenOn, screenOn); doPlugLocked(realtime, getBatteryUptimeLocked(uptime), getBatteryRealtimeLocked(realtime)); } if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) { @@ -5105,7 +5119,7 @@ public final class BatteryStatsImpl extends BatteryStats { public int getDischargeAmountScreenOn() { synchronized(this) { int val = mDischargeAmountScreenOn; - if (mOnBattery && mScreenOn + if (mOnBattery && mScreenState == Display.STATE_ON && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; } @@ -5116,7 +5130,7 @@ public final class BatteryStatsImpl extends BatteryStats { public int getDischargeAmountScreenOnSinceCharge() { synchronized(this) { int val = mDischargeAmountScreenOnSinceCharge; - if (mOnBattery && mScreenOn + if (mOnBattery && mScreenState == Display.STATE_ON && mDischargeCurrentLevel < mDischargeScreenOnUnplugLevel) { val += mDischargeScreenOnUnplugLevel-mDischargeCurrentLevel; } @@ -5127,7 +5141,7 @@ public final class BatteryStatsImpl extends BatteryStats { public int getDischargeAmountScreenOff() { synchronized(this) { int val = mDischargeAmountScreenOff; - if (mOnBattery && !mScreenOn + if (mOnBattery && mScreenState != Display.STATE_ON && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; } @@ -5138,7 +5152,7 @@ public final class BatteryStatsImpl extends BatteryStats { public int getDischargeAmountScreenOffSinceCharge() { synchronized(this) { int val = mDischargeAmountScreenOffSinceCharge; - if (mOnBattery && !mScreenOn + if (mOnBattery && mScreenState != Display.STATE_ON && mDischargeCurrentLevel < mDischargeScreenOffUnplugLevel) { val += mDischargeScreenOffUnplugLevel-mDischargeCurrentLevel; } @@ -5522,12 +5536,13 @@ public final class BatteryStatsImpl extends BatteryStats { mStartCount++; - mScreenOn = false; + mScreenState = Display.STATE_UNKNOWN; mScreenOnTimer.readSummaryFromParcelLocked(in); for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { mScreenBrightnessTimer[i].readSummaryFromParcelLocked(in); } - mInputEventCounter.readSummaryFromParcelLocked(in); + mInteractive = false; + mInteractiveTimer.readSummaryFromParcelLocked(in); mPhoneOn = false; mPhoneOnTimer.readSummaryFromParcelLocked(in); for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { @@ -5748,7 +5763,7 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL); } - mInputEventCounter.writeSummaryFromParcelLocked(out); + mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL); mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL); @@ -5970,13 +5985,12 @@ public final class BatteryStatsImpl extends BatteryStats { mBatteryLastUptime = 0; mBatteryRealtime = in.readLong(); mBatteryLastRealtime = 0; - mScreenOn = false; + mScreenState = Display.STATE_UNKNOWN; mScreenOnTimer = new StopwatchTimer(null, -1, null, mUnpluggables, in); for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mUnpluggables, in); } - mInputEventCounter = new Counter(mUnpluggables, in); mPhoneOn = false; mPhoneOnTimer = new StopwatchTimer(null, -2, null, mUnpluggables, in); for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { @@ -5992,11 +6006,17 @@ public final class BatteryStatsImpl extends BatteryStats { mNetworkActivityCounters[i] = new LongSamplingCounter(mUnpluggables, in); } mWifiOn = false; - mWifiOnTimer = new StopwatchTimer(null, -2, null, mUnpluggables, in); + mWifiOnTimer = new StopwatchTimer(null, -3, null, mUnpluggables, in); mGlobalWifiRunning = false; - mGlobalWifiRunningTimer = new StopwatchTimer(null, -2, null, mUnpluggables, in); + mGlobalWifiRunningTimer = new StopwatchTimer(null, -4, null, mUnpluggables, in); mBluetoothOn = false; - mBluetoothOnTimer = new StopwatchTimer(null, -2, null, mUnpluggables, in); + mBluetoothOnTimer = new StopwatchTimer(null, -5, null, mUnpluggables, in); + mAudioOn = false; + mAudioOnTimer = new StopwatchTimer(null, -6, null, mUnpluggables); + mVideoOn = false; + mVideoOnTimer = new StopwatchTimer(null, -7, null, mUnpluggables); + mInteractive = false; + mInteractiveTimer = new StopwatchTimer(null, -8, null, mUnpluggables, in); mUptime = in.readLong(); mUptimeStart = in.readLong(); mLastUptime = 0; @@ -6089,7 +6109,7 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) { mScreenBrightnessTimer[i].writeToParcel(out, batteryRealtime); } - mInputEventCounter.writeToParcel(out); + mInteractiveTimer.writeToParcel(out, batteryRealtime); mPhoneOnTimer.writeToParcel(out, batteryRealtime); for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { mPhoneSignalStrengthsTimer[i].writeToParcel(out, batteryRealtime); @@ -6188,8 +6208,8 @@ public final class BatteryStatsImpl extends BatteryStats { pr.println("*** Screen brightness #" + i + ":"); mScreenBrightnessTimer[i].logState(pr, " "); } - pr.println("*** Input event counter:"); - mInputEventCounter.logState(pr, " "); + pr.println("*** Interactive timer:"); + mInteractiveTimer.logState(pr, " "); pr.println("*** Phone timer:"); mPhoneOnTimer.logState(pr, " "); for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) { diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java index ff06513..89e96fd 100644 --- a/services/core/java/com/android/server/am/BatteryStatsService.java +++ b/services/core/java/com/android/server/am/BatteryStatsService.java @@ -175,10 +175,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub { } } - public void noteScreenOn() { + public void noteScreenState(int state) { enforceCallingPermission(); synchronized (mStats) { - mStats.noteScreenOnLocked(); + mStats.noteScreenStateLocked(state); } } @@ -189,22 +189,17 @@ public final class BatteryStatsService extends IBatteryStats.Stub { } } - public void noteScreenOff() { + public void noteUserActivity(int uid, int event) { enforceCallingPermission(); synchronized (mStats) { - mStats.noteScreenOffLocked(); + mStats.noteUserActivityLocked(uid, event); } } - - public void noteInputEvent() { - enforceCallingPermission(); - mStats.noteInputEventAtomic(); - } - public void noteUserActivity(int uid, int event) { + public void noteInteractive(boolean interactive) { enforceCallingPermission(); synchronized (mStats) { - mStats.noteUserActivityLocked(uid, event); + mStats.noteInteractiveLocked(interactive); } } diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index 7abf88c..279a9cc 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -544,6 +544,14 @@ final class DisplayPowerController { mScreenBrightnessRampAnimator = new RampAnimator<DisplayPowerState>( mPowerState, DisplayPowerState.SCREEN_BRIGHTNESS); + + // Initialize screen state for battery stats. + try { + mBatteryStats.noteScreenState(mPowerState.getScreenState()); + mBatteryStats.noteScreenBrightness(mPowerState.getScreenBrightness()); + } catch (RemoteException ex) { + // same process + } } private final Animator.AnimatorListener mAnimatorListener = new Animator.AnimatorListener() { @@ -783,11 +791,7 @@ final class DisplayPowerController { if (mPowerState.getScreenState() != state) { mPowerState.setScreenState(state); try { - if (state != Display.STATE_OFF) { - mBatteryStats.noteScreenOn(); - } else { - mBatteryStats.noteScreenOff(); - } + mBatteryStats.noteScreenState(state); } catch (RemoteException ex) { // same process } diff --git a/services/core/java/com/android/server/power/Notifier.java b/services/core/java/com/android/server/power/Notifier.java index d9c1aa8..f431b0d 100644 --- a/services/core/java/com/android/server/power/Notifier.java +++ b/services/core/java/com/android/server/power/Notifier.java @@ -131,6 +131,11 @@ final class Notifier { mScreenOffIntent = new Intent(Intent.ACTION_SCREEN_OFF); mScreenOffIntent.addFlags( Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND); + + // Initialize interactive state for battery stats. + try { + mBatteryStats.noteInteractive(true); + } catch (RemoteException ex) { } } /** @@ -221,7 +226,14 @@ final class Notifier { // Going to sleep... mLastGoToSleepReason = reason; } - mInputManagerInternal.setInteractive(interactive); + } + + mInputManagerInternal.setInteractive(interactive); + + if (interactive) { + try { + mBatteryStats.noteInteractive(true); + } catch (RemoteException ex) { } } } @@ -251,6 +263,12 @@ final class Notifier { } } } + + if (!interactive) { + try { + mBatteryStats.noteInteractive(false); + } catch (RemoteException ex) { } + } } /** |
