diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java index a49a27a06368b..b706c5c1cae40 100644 --- a/core/java/android/os/BatteryStats.java +++ b/core/java/android/os/BatteryStats.java @@ -130,6 +130,7 @@ public abstract class BatteryStats implements Parcelable { private static final String MISC_DATA = "m"; private static final String SCREEN_BRIGHTNESS_DATA = "br"; private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; + private static final String SIGNAL_SCANNING_TIME_DATA = "sst"; private static final String SIGNAL_STRENGTH_COUNT_DATA = "sgc"; private static final String DATA_CONNECTION_TIME_DATA = "dct"; private static final String DATA_CONNECTION_COUNT_DATA = "dcc"; @@ -439,6 +440,15 @@ public abstract class BatteryStats implements Parcelable { public abstract long getPhoneSignalStrengthTime(int strengthBin, long batteryRealtime, int which); + /** + * Returns the time in microseconds that the phone has been trying to + * acquire a signal. + * + * {@hide} + */ + public abstract long getPhoneSignalScanningTime( + long batteryRealtime, int which); + /** * Returns the number of times the phone has entered the given signal strength. * @@ -823,6 +833,8 @@ public abstract class BatteryStats implements Parcelable { args[i] = getPhoneSignalStrengthTime(i, batteryRealtime, which) / 1000; } dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_TIME_DATA, args); + dumpLine(pw, 0 /* uid */, category, SIGNAL_SCANNING_TIME_DATA, + getPhoneSignalScanningTime(batteryRealtime, which) / 1000); for (int i=0; i timerPool, ArrayList unpluggables, Parcel in) { super(type, unpluggables, in); @@ -694,6 +701,10 @@ public final class BatteryStatsImpl extends BatteryStats { mTimerPool = timerPool; } + void setTimeout(long timeout) { + mTimeout = timeout; + } + public void writeToParcel(Parcel out, long batteryRealtime) { super.writeToParcel(out, batteryRealtime); out.writeLong(mUpdateTime); @@ -797,6 +808,9 @@ public final class BatteryStatsImpl extends BatteryStats { @Override protected long computeRunTimeLocked(long curBatteryRealtime) { + if (mTimeout > 0 && curBatteryRealtime > mUpdateTime + mTimeout) { + curBatteryRealtime = mUpdateTime + mTimeout; + } return mTotalTime + (mNesting > 0 ? (curBatteryRealtime - mUpdateTime) / (mTimerPool != null ? mTimerPool.size() : 1) @@ -1123,34 +1137,59 @@ public final class BatteryStatsImpl extends BatteryStats { } } - public void noteAirplaneModeLocked(boolean isAirplaneMode) { - final int bin = mPhoneSignalStrengthBin; - if (bin >= 0) { - if (!isAirplaneMode) { - if (!mPhoneSignalStrengthsTimer[bin].isRunningLocked()) { - mPhoneSignalStrengthsTimer[bin].startRunningLocked(this); - } - } else { - for (int i = 0; i < NUM_SIGNAL_STRENGTH_BINS; i++) { - while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { - mPhoneSignalStrengthsTimer[i].stopRunningLocked(this); - } + /** + * Telephony stack updates the phone state. + * @param state phone state from ServiceState.getState() + */ + public void notePhoneStateLocked(int state) { + int bin = mPhoneSignalStrengthBin; + boolean isAirplaneMode = state == ServiceState.STATE_POWER_OFF; + // Stop all timers + if (isAirplaneMode || state == ServiceState.STATE_OUT_OF_SERVICE) { + for (int i = 0; i < NUM_SIGNAL_STRENGTH_BINS; i++) { + while (mPhoneSignalStrengthsTimer[i].isRunningLocked()) { + mPhoneSignalStrengthsTimer[i].stopRunningLocked(this); } } } + // Stop Signal Scanning timer, in case we're going into service + while (mPhoneSignalScanningTimer.isRunningLocked()) { + mPhoneSignalScanningTimer.stopRunningLocked(this); + } + + // If we're back in service or continuing in service, restart the old timer. + if (state == ServiceState.STATE_IN_SERVICE) { + if (bin == -1) bin = SIGNAL_STRENGTH_NONE_OR_UNKNOWN; + if (!mPhoneSignalStrengthsTimer[bin].isRunningLocked()) { + mPhoneSignalStrengthsTimer[bin].startRunningLocked(this); + } + } else if (state == ServiceState.STATE_OUT_OF_SERVICE) { + mPhoneSignalStrengthBin = SIGNAL_STRENGTH_NONE_OR_UNKNOWN; + if (!mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].isRunningLocked()) { + mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].startRunningLocked(this); + } + if (!mPhoneSignalScanningTimer.isRunningLocked()) { + mPhoneSignalScanningTimer.startRunningLocked(this); + } + } + mPhoneServiceState = state; } public void notePhoneSignalStrengthLocked(SignalStrength signalStrength) { // Bin the strength. int bin; - + if (mPhoneServiceState == ServiceState.STATE_POWER_OFF + || mPhoneServiceState == ServiceState.STATE_OUT_OF_SERVICE) { + // Ignore any signal strength changes when radio was turned off or out of service. + return; + } if (!signalStrength.isGsm()) { int dBm = signalStrength.getCdmaDbm(); - if (dBm >= -75) bin = SIGNAL_STRENGTH_NONE_OR_UNKNOWN; - else if (dBm >= -85) bin = SIGNAL_STRENGTH_GREAT; - else if (dBm >= -95) bin = SIGNAL_STRENGTH_GOOD; - else if (dBm >= -100) bin = SIGNAL_STRENGTH_MODERATE; - else bin = SIGNAL_STRENGTH_POOR; + if (dBm >= -75) bin = SIGNAL_STRENGTH_GREAT; + else if (dBm >= -85) bin = SIGNAL_STRENGTH_GOOD; + else if (dBm >= -95) bin = SIGNAL_STRENGTH_MODERATE; + else if (dBm >= -100) bin = SIGNAL_STRENGTH_POOR; + else bin = SIGNAL_STRENGTH_NONE_OR_UNKNOWN; } else { int asu = signalStrength.getGsmSignalStrength(); if (asu < 0 || asu >= 99) bin = SIGNAL_STRENGTH_NONE_OR_UNKNOWN; @@ -1328,7 +1367,13 @@ public final class BatteryStatsImpl extends BatteryStats { return mPhoneSignalStrengthsTimer[strengthBin].getTotalTimeLocked( batteryRealtime, which); } - + + @Override public long getPhoneSignalScanningTime( + long batteryRealtime, int which) { + return mPhoneSignalScanningTimer.getTotalTimeLocked( + batteryRealtime, which); + } + @Override public int getPhoneSignalStrengthCount(int dataType, int which) { return mPhoneDataConnectionsTimer[dataType].getCountLocked(which); } @@ -2653,6 +2698,7 @@ public final class BatteryStatsImpl extends BatteryStats { for (int i=0; i 400 + + 0 + diff --git a/core/res/res/xml/power_profile.xml b/core/res/res/xml/power_profile.xml index 710b71ea7e75c..ce623e8d4d359 100644 --- a/core/res/res/xml/power_profile.xml +++ b/core/res/res/xml/power_profile.xml @@ -29,10 +29,12 @@ 0.1 0.1 1 + + 0.5 1 - 1 + 0.2 0.1