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)
This commit is contained in:
@@ -782,7 +782,9 @@ public abstract class BatteryStats implements Parcelable {
|
|||||||
* {@hide}
|
* {@hide}
|
||||||
*/
|
*/
|
||||||
public abstract long getScreenOnTime(long batteryRealtime, int which);
|
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_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;
|
||||||
@@ -804,8 +806,6 @@ public abstract class BatteryStats implements Parcelable {
|
|||||||
public abstract long getScreenBrightnessTime(int brightnessBin,
|
public abstract long getScreenBrightnessTime(int brightnessBin,
|
||||||
long batteryRealtime, int which);
|
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
|
* Returns the time in microseconds that the phone has been on while the device was
|
||||||
* running on battery.
|
* running on battery.
|
||||||
@@ -1303,7 +1303,7 @@ public abstract class BatteryStats implements Parcelable {
|
|||||||
wifiRunningTime / 1000, bluetoothOnTime / 1000,
|
wifiRunningTime / 1000, bluetoothOnTime / 1000,
|
||||||
mobileRxTotal, mobileTxTotal, wifiRxTotal, wifiTxTotal,
|
mobileRxTotal, mobileTxTotal, wifiRxTotal, wifiTxTotal,
|
||||||
fullWakeLockTimeTotal, partialWakeLockTimeTotal,
|
fullWakeLockTimeTotal, partialWakeLockTimeTotal,
|
||||||
getInputEventCount(which));
|
0 /*legacy input event count*/);
|
||||||
|
|
||||||
// Dump screen brightness stats
|
// Dump screen brightness stats
|
||||||
Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
|
Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
|
||||||
@@ -1564,16 +1564,22 @@ public abstract class BatteryStats implements Parcelable {
|
|||||||
pw.println(sb.toString());
|
pw.println(sb.toString());
|
||||||
|
|
||||||
final long screenOnTime = getScreenOnTime(batteryRealtime, which);
|
final long screenOnTime = getScreenOnTime(batteryRealtime, which);
|
||||||
|
final long interactiveTime = getInteractiveTime(batteryRealtime, which);
|
||||||
final long phoneOnTime = getPhoneOnTime(batteryRealtime, which);
|
final long phoneOnTime = getPhoneOnTime(batteryRealtime, which);
|
||||||
final long wifiRunningTime = getGlobalWifiRunningTime(batteryRealtime, which);
|
final long wifiRunningTime = getGlobalWifiRunningTime(batteryRealtime, which);
|
||||||
final long wifiOnTime = getWifiOnTime(batteryRealtime, which);
|
final long wifiOnTime = getWifiOnTime(batteryRealtime, which);
|
||||||
final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which);
|
final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, 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("), 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("("); sb.append(formatRatioLocked(phoneOnTime, whichBatteryRealtime));
|
||||||
sb.append(")");
|
sb.append(")");
|
||||||
pw.println(sb.toString());
|
pw.println(sb.toString());
|
||||||
|
|||||||
@@ -41,11 +41,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 notePhoneOn();
|
void notePhoneOn();
|
||||||
void notePhoneOff();
|
void notePhoneOff();
|
||||||
void notePhoneSignalStrength(in SignalStrength signalStrength);
|
void notePhoneSignalStrength(in SignalStrength signalStrength);
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ import android.util.Printer;
|
|||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
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;
|
||||||
@@ -85,7 +86,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 = 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.
|
// 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;
|
||||||
@@ -211,13 +212,14 @@ public final class BatteryStatsImpl extends BatteryStats {
|
|||||||
long mRealtimeStart;
|
long mRealtimeStart;
|
||||||
long mLastRealtime;
|
long mLastRealtime;
|
||||||
|
|
||||||
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;
|
||||||
@@ -1742,7 +1744,7 @@ public final class BatteryStatsImpl extends BatteryStats {
|
|||||||
public int startAddingCpuLocked() {
|
public int startAddingCpuLocked() {
|
||||||
mHandler.removeMessages(MSG_UPDATE_WAKELOCKS);
|
mHandler.removeMessages(MSG_UPDATE_WAKELOCKS);
|
||||||
|
|
||||||
if (mScreenOn) {
|
if (mScreenState == Display.STATE_ON) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1917,46 +1919,49 @@ public final class BatteryStatsImpl extends BatteryStats {
|
|||||||
getUidStatsLocked(uid).noteStopGps();
|
getUidStatsLocked(uid).noteStopGps();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void noteScreenOnLocked() {
|
public void noteScreenStateLocked(int state) {
|
||||||
if (!mScreenOn) {
|
if (mScreenState != state) {
|
||||||
mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG;
|
final int oldState = mScreenState;
|
||||||
if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: "
|
mScreenState = state;
|
||||||
+ Integer.toHexString(mHistoryCur.states));
|
if (DEBUG) Slog.v(TAG, "Screen state: oldState=" + Display.stateToString(oldState)
|
||||||
addHistoryRecordLocked(SystemClock.elapsedRealtime());
|
+ ", newState=" + Display.stateToString(state));
|
||||||
mScreenOn = true;
|
|
||||||
mScreenOnTimer.startRunningLocked(this);
|
|
||||||
if (mScreenBrightnessBin >= 0) {
|
|
||||||
mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fake a wake lock, so we consider the device waked as long
|
if (state == Display.STATE_ON) {
|
||||||
// as the screen is on.
|
// Screen turning on.
|
||||||
noteStartWakeLocked(-1, -1, "dummy", WAKE_TYPE_PARTIAL);
|
mHistoryCur.states |= HistoryItem.STATE_SCREEN_ON_FLAG;
|
||||||
|
if (DEBUG_HISTORY) Slog.v(TAG, "Screen on to: "
|
||||||
// Update discharge amounts.
|
+ Integer.toHexString(mHistoryCur.states));
|
||||||
if (mOnBatteryInternal) {
|
addHistoryRecordLocked(SystemClock.elapsedRealtime());
|
||||||
updateDischargeScreenLevelsLocked(false, true);
|
mScreenOnTimer.startRunningLocked(this);
|
||||||
}
|
if (mScreenBrightnessBin >= 0) {
|
||||||
}
|
mScreenBrightnessTimer[mScreenBrightnessBin].startRunningLocked(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void noteScreenOffLocked() {
|
// Fake a wake lock, so we consider the device waked as long
|
||||||
if (mScreenOn) {
|
// as the screen is on.
|
||||||
mHistoryCur.states &= ~HistoryItem.STATE_SCREEN_ON_FLAG;
|
noteStartWakeLocked(-1, -1, "dummy", WAKE_TYPE_PARTIAL);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
noteStopWakeLocked(-1, -1, "dummy", WAKE_TYPE_PARTIAL);
|
// Update discharge amounts.
|
||||||
|
if (mOnBatteryInternal) {
|
||||||
// Update discharge amounts.
|
updateDischargeScreenLevelsLocked(false, true);
|
||||||
if (mOnBatteryInternal) {
|
}
|
||||||
updateDischargeScreenLevelsLocked(true, false);
|
} 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: "
|
if (DEBUG_HISTORY) Slog.v(TAG, "Screen brightness " + bin + " to: "
|
||||||
+ Integer.toHexString(mHistoryCur.states));
|
+ Integer.toHexString(mHistoryCur.states));
|
||||||
addHistoryRecordLocked(SystemClock.elapsedRealtime());
|
addHistoryRecordLocked(SystemClock.elapsedRealtime());
|
||||||
if (mScreenOn) {
|
if (mScreenState == Display.STATE_ON) {
|
||||||
if (mScreenBrightnessBin >= 0) {
|
if (mScreenBrightnessBin >= 0) {
|
||||||
mScreenBrightnessTimer[mScreenBrightnessBin].stopRunningLocked(this);
|
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) {
|
public void noteUserActivityLocked(int uid, int event) {
|
||||||
getUidStatsLocked(uid).noteUserActivityLocked(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() {
|
public void notePhoneOnLocked() {
|
||||||
if (!mPhoneOn) {
|
if (!mPhoneOn) {
|
||||||
mHistoryCur.states |= HistoryItem.STATE_PHONE_IN_CALL_FLAG;
|
mHistoryCur.states |= HistoryItem.STATE_PHONE_IN_CALL_FLAG;
|
||||||
@@ -2529,8 +2542,8 @@ public final class BatteryStatsImpl extends BatteryStats {
|
|||||||
batteryRealtime, which);
|
batteryRealtime, which);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public int getInputEventCount(int which) {
|
@Override public long getInteractiveTime(long batteryRealtime, int which) {
|
||||||
return mInputEventCounter.getCountLocked(which);
|
return mInteractiveTimer.getTotalTimeLocked(batteryRealtime, which);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public long getPhoneOnTime(long batteryRealtime, int 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++) {
|
for (int i=0; i<NUM_SCREEN_BRIGHTNESS_BINS; i++) {
|
||||||
mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mUnpluggables);
|
mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i, null, mUnpluggables);
|
||||||
}
|
}
|
||||||
mInputEventCounter = new Counter(mUnpluggables);
|
|
||||||
mPhoneOnTimer = new StopwatchTimer(null, -2, null, mUnpluggables);
|
mPhoneOnTimer = new StopwatchTimer(null, -2, null, mUnpluggables);
|
||||||
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, mUnpluggables);
|
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);
|
mBluetoothOnTimer = new StopwatchTimer(null, -5, null, mUnpluggables);
|
||||||
mAudioOnTimer = new StopwatchTimer(null, -6, null, mUnpluggables);
|
mAudioOnTimer = new StopwatchTimer(null, -6, null, mUnpluggables);
|
||||||
mVideoOnTimer = new StopwatchTimer(null, -7, null, mUnpluggables);
|
mVideoOnTimer = new StopwatchTimer(null, -7, null, mUnpluggables);
|
||||||
|
mInteractiveTimer = new StopwatchTimer(null, -8, null, mUnpluggables);
|
||||||
mOnBattery = mOnBatteryInternal = false;
|
mOnBattery = mOnBatteryInternal = false;
|
||||||
initTimes();
|
initTimes();
|
||||||
mTrackBatteryPastUptime = 0;
|
mTrackBatteryPastUptime = 0;
|
||||||
@@ -4649,7 +4662,7 @@ public final class BatteryStatsImpl extends BatteryStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isScreenOn() {
|
public boolean isScreenOn() {
|
||||||
return mScreenOn;
|
return mScreenState == Display.STATE_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initTimes() {
|
void initTimes() {
|
||||||
@@ -4677,7 +4690,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(this, false);
|
mScreenBrightnessTimer[i].reset(this, false);
|
||||||
}
|
}
|
||||||
mInputEventCounter.reset(false);
|
mInteractiveTimer.reset(this, false);
|
||||||
mPhoneOnTimer.reset(this, false);
|
mPhoneOnTimer.reset(this, false);
|
||||||
mAudioOnTimer.reset(this, false);
|
mAudioOnTimer.reset(this, false);
|
||||||
mVideoOnTimer.reset(this, false);
|
mVideoOnTimer.reset(this, false);
|
||||||
@@ -4753,6 +4766,7 @@ public final class BatteryStatsImpl extends BatteryStats {
|
|||||||
long uptime = SystemClock.uptimeMillis() * 1000;
|
long uptime = SystemClock.uptimeMillis() * 1000;
|
||||||
long mSecRealtime = SystemClock.elapsedRealtime();
|
long mSecRealtime = SystemClock.elapsedRealtime();
|
||||||
long realtime = mSecRealtime * 1000;
|
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
|
||||||
@@ -4777,7 +4791,7 @@ public final class BatteryStatsImpl extends BatteryStats {
|
|||||||
mUnpluggedBatteryUptime = getBatteryUptimeLocked(uptime);
|
mUnpluggedBatteryUptime = getBatteryUptimeLocked(uptime);
|
||||||
mUnpluggedBatteryRealtime = getBatteryRealtimeLocked(realtime);
|
mUnpluggedBatteryRealtime = getBatteryRealtimeLocked(realtime);
|
||||||
mDischargeCurrentLevel = mDischargeUnplugLevel = level;
|
mDischargeCurrentLevel = mDischargeUnplugLevel = level;
|
||||||
if (mScreenOn) {
|
if (screenOn) {
|
||||||
mDischargeScreenOnUnplugLevel = level;
|
mDischargeScreenOnUnplugLevel = level;
|
||||||
mDischargeScreenOffUnplugLevel = 0;
|
mDischargeScreenOffUnplugLevel = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -4802,7 +4816,7 @@ 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);
|
||||||
doPlugLocked(realtime, getBatteryUptimeLocked(uptime), getBatteryRealtimeLocked(realtime));
|
doPlugLocked(realtime, getBatteryUptimeLocked(uptime), getBatteryRealtimeLocked(realtime));
|
||||||
}
|
}
|
||||||
if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) {
|
if (doWrite || (mLastWriteTime + (60 * 1000)) < mSecRealtime) {
|
||||||
@@ -5105,7 +5119,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;
|
||||||
}
|
}
|
||||||
@@ -5116,7 +5130,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;
|
||||||
}
|
}
|
||||||
@@ -5127,7 +5141,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;
|
||||||
}
|
}
|
||||||
@@ -5138,7 +5152,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;
|
||||||
}
|
}
|
||||||
@@ -5522,12 +5536,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++) {
|
||||||
@@ -5748,7 +5763,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);
|
mScreenBrightnessTimer[i].writeSummaryFromParcelLocked(out, NOWREAL);
|
||||||
}
|
}
|
||||||
mInputEventCounter.writeSummaryFromParcelLocked(out);
|
mInteractiveTimer.writeSummaryFromParcelLocked(out, NOWREAL);
|
||||||
mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL);
|
mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL);
|
||||||
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);
|
mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL);
|
||||||
@@ -5970,13 +5985,12 @@ public final class BatteryStatsImpl extends BatteryStats {
|
|||||||
mBatteryLastUptime = 0;
|
mBatteryLastUptime = 0;
|
||||||
mBatteryRealtime = in.readLong();
|
mBatteryRealtime = in.readLong();
|
||||||
mBatteryLastRealtime = 0;
|
mBatteryLastRealtime = 0;
|
||||||
mScreenOn = false;
|
mScreenState = Display.STATE_UNKNOWN;
|
||||||
mScreenOnTimer = new StopwatchTimer(null, -1, null, mUnpluggables, in);
|
mScreenOnTimer = new StopwatchTimer(null, -1, null, mUnpluggables, 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,
|
mScreenBrightnessTimer[i] = new StopwatchTimer(null, -100-i,
|
||||||
null, mUnpluggables, in);
|
null, mUnpluggables, in);
|
||||||
}
|
}
|
||||||
mInputEventCounter = new Counter(mUnpluggables, in);
|
|
||||||
mPhoneOn = false;
|
mPhoneOn = false;
|
||||||
mPhoneOnTimer = new StopwatchTimer(null, -2, null, mUnpluggables, in);
|
mPhoneOnTimer = new StopwatchTimer(null, -2, null, mUnpluggables, in);
|
||||||
for (int i=0; i<SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
|
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);
|
mNetworkActivityCounters[i] = new LongSamplingCounter(mUnpluggables, in);
|
||||||
}
|
}
|
||||||
mWifiOn = false;
|
mWifiOn = false;
|
||||||
mWifiOnTimer = new StopwatchTimer(null, -2, null, mUnpluggables, in);
|
mWifiOnTimer = new StopwatchTimer(null, -3, null, mUnpluggables, in);
|
||||||
mGlobalWifiRunning = false;
|
mGlobalWifiRunning = false;
|
||||||
mGlobalWifiRunningTimer = new StopwatchTimer(null, -2, null, mUnpluggables, in);
|
mGlobalWifiRunningTimer = new StopwatchTimer(null, -4, null, mUnpluggables, in);
|
||||||
mBluetoothOn = false;
|
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();
|
mUptime = in.readLong();
|
||||||
mUptimeStart = in.readLong();
|
mUptimeStart = in.readLong();
|
||||||
mLastUptime = 0;
|
mLastUptime = 0;
|
||||||
@@ -6089,7 +6109,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, batteryRealtime);
|
mScreenBrightnessTimer[i].writeToParcel(out, batteryRealtime);
|
||||||
}
|
}
|
||||||
mInputEventCounter.writeToParcel(out);
|
mInteractiveTimer.writeToParcel(out, batteryRealtime);
|
||||||
mPhoneOnTimer.writeToParcel(out, batteryRealtime);
|
mPhoneOnTimer.writeToParcel(out, batteryRealtime);
|
||||||
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, batteryRealtime);
|
mPhoneSignalStrengthsTimer[i].writeToParcel(out, batteryRealtime);
|
||||||
@@ -6188,8 +6208,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++) {
|
||||||
|
|||||||
@@ -175,10 +175,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,18 +189,6 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void noteScreenOff() {
|
|
||||||
enforceCallingPermission();
|
|
||||||
synchronized (mStats) {
|
|
||||||
mStats.noteScreenOffLocked();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void noteInputEvent() {
|
|
||||||
enforceCallingPermission();
|
|
||||||
mStats.noteInputEventAtomic();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void noteUserActivity(int uid, int event) {
|
public void noteUserActivity(int uid, int event) {
|
||||||
enforceCallingPermission();
|
enforceCallingPermission();
|
||||||
synchronized (mStats) {
|
synchronized (mStats) {
|
||||||
@@ -208,6 +196,13 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void noteInteractive(boolean interactive) {
|
||||||
|
enforceCallingPermission();
|
||||||
|
synchronized (mStats) {
|
||||||
|
mStats.noteInteractiveLocked(interactive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void notePhoneOn() {
|
public void notePhoneOn() {
|
||||||
enforceCallingPermission();
|
enforceCallingPermission();
|
||||||
synchronized (mStats) {
|
synchronized (mStats) {
|
||||||
|
|||||||
@@ -544,6 +544,14 @@ final class DisplayPowerController {
|
|||||||
|
|
||||||
mScreenBrightnessRampAnimator = new RampAnimator<DisplayPowerState>(
|
mScreenBrightnessRampAnimator = new RampAnimator<DisplayPowerState>(
|
||||||
mPowerState, DisplayPowerState.SCREEN_BRIGHTNESS);
|
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() {
|
private final Animator.AnimatorListener mAnimatorListener = new Animator.AnimatorListener() {
|
||||||
@@ -783,11 +791,7 @@ final class DisplayPowerController {
|
|||||||
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,6 +131,11 @@ final class Notifier {
|
|||||||
mScreenOffIntent = new Intent(Intent.ACTION_SCREEN_OFF);
|
mScreenOffIntent = new Intent(Intent.ACTION_SCREEN_OFF);
|
||||||
mScreenOffIntent.addFlags(
|
mScreenOffIntent.addFlags(
|
||||||
Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
|
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...
|
// Going to sleep...
|
||||||
mLastGoToSleepReason = reason;
|
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) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user