Loading core/java/android/os/BatteryStats.java +106 −9 Original line number Diff line number Diff line Loading @@ -4,8 +4,6 @@ import java.io.PrintWriter; import java.util.Formatter; import java.util.Map; import com.android.internal.os.BatteryStatsImpl.Timer; import android.util.Log; import android.util.Printer; import android.util.SparseArray; Loading Loading @@ -92,6 +90,8 @@ public abstract class BatteryStats implements Parcelable { private static final String BATTERY_DATA = "battery"; private static final String WIFI_LOCK_DATA = "wifilock"; private static final String MISC_DATA = "misc"; private static final String SIGNAL_STRENGTH_DATA = "signal"; private static final String DATA_CONNECTION_DATA = "dataconn"; private final StringBuilder mFormatBuilder = new StringBuilder(8); private final Formatter mFormatter = new Formatter(mFormatBuilder); Loading Loading @@ -122,7 +122,7 @@ public abstract class BatteryStats implements Parcelable { /** * Temporary for debugging. */ public abstract void logState(); public abstract void logState(Printer pw, String prefix); } /** Loading Loading @@ -293,6 +293,48 @@ public abstract class BatteryStats implements Parcelable { */ public abstract long getPhoneOnTime(long batteryRealtime, int which); public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0; public static final int SIGNAL_STRENGTH_POOR = 1; public static final int SIGNAL_STRENGTH_MODERATE = 2; public static final int SIGNAL_STRENGTH_GOOD = 3; public static final int SIGNAL_STRENGTH_GREAT = 4; static final String[] SIGNAL_STRENGTH_NAMES = { "none", "poor", "moderate", "good", "great" }; public static final int NUM_SIGNAL_STRENGTH_BINS = 5; /** * Returns the time in milliseconds that the phone has been running with * the given signal strength. * * {@hide} */ public abstract long getPhoneSignalStrengthTime(int strengthBin, long batteryRealtime, int which); public static final int DATA_CONNECTION_NONE = 0; public static final int DATA_CONNECTION_GPRS = 1; public static final int DATA_CONNECTION_EDGE = 2; public static final int DATA_CONNECTION_UMTS = 3; public static final int DATA_CONNECTION_OTHER = 4; static final String[] DATA_CONNECTION_NAMES = { "none", "gprs", "edge", "umts", "other" }; public static final int NUM_DATA_CONNECTION_TYPES = 5; /** * Returns the time in milliseconds that the phone has been running with * the given data connection. * * {@hide} */ public abstract long getPhoneDataConnectionTime(int dataType, long batteryRealtime, int which); /** * Returns the time in milliseconds that wifi has been on while the device was * running on battery. Loading Loading @@ -561,6 +603,20 @@ public abstract class BatteryStats implements Parcelable { screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000, wifiRunningTime / 1000, bluetoothOnTime / 1000); // Dump signal strength stats Object[] args = new Object[NUM_SIGNAL_STRENGTH_BINS]; for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { args[i] = getPhoneSignalStrengthTime(i, batteryRealtime, which) / 1000; } dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_DATA, args); // Dump network type stats args = new Object[NUM_DATA_CONNECTION_TYPES]; for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { args[i] = getPhoneDataConnectionTime(i, batteryRealtime, which) / 1000; } dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_DATA, args); if (which == STATS_UNPLUGGED) { dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, getUnpluggedStartLevel(), getPluggedStartLevel()); Loading Loading @@ -706,17 +762,58 @@ public abstract class BatteryStats implements Parcelable { final long wifiOnTime = getWifiOnTime(batteryRealtime, which); final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which); pw.println(prefix + " Time with screen on: " + formatTimeMs(screenOnTime / 1000) + " Screen on: " + formatTimeMs(screenOnTime / 1000) + "(" + formatRatioLocked(screenOnTime, whichBatteryRealtime) + "), time with phone on: " + formatTimeMs(phoneOnTime / 1000) + "(" + formatRatioLocked(phoneOnTime, whichBatteryRealtime) + "), time with wifi on: " + formatTimeMs(wifiOnTime / 1000) + "), Phone on: " + formatTimeMs(phoneOnTime / 1000) + "(" + formatRatioLocked(phoneOnTime, whichBatteryRealtime)); pw.println(prefix + " Wifi on: " + formatTimeMs(wifiOnTime / 1000) + "(" + formatRatioLocked(wifiOnTime, whichBatteryRealtime) + "), time with wifi running: " + formatTimeMs(wifiRunningTime / 1000) + "), Wifi running: " + formatTimeMs(wifiRunningTime / 1000) + "(" + formatRatioLocked(wifiRunningTime, whichBatteryRealtime) + "), time with bluetooth on: " + formatTimeMs(bluetoothOnTime / 1000) + "), Bluetooth on: " + formatTimeMs(bluetoothOnTime / 1000) + "(" + formatRatioLocked(bluetoothOnTime, whichBatteryRealtime)+ ")"); sb.setLength(0); sb.append(" Signal strengths: "); boolean didOne = false; for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { final long time = getPhoneSignalStrengthTime(i, batteryRealtime, which); if (time == 0) { continue; } if (didOne) sb.append(", "); didOne = true; sb.append(SIGNAL_STRENGTH_NAMES[i]); sb.append(" "); sb.append(formatTimeMs(time/1000)); sb.append("("); sb.append(formatRatioLocked(time, whichBatteryRealtime)); sb.append(")"); } if (!didOne) sb.append("No activity"); pw.println(sb.toString()); sb.setLength(0); sb.append(" Data types: "); didOne = false; for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { final long time = getPhoneDataConnectionTime(i, batteryRealtime, which); if (time == 0) { continue; } if (didOne) sb.append(", "); didOne = true; sb.append(DATA_CONNECTION_NAMES[i]); sb.append(" "); sb.append(formatTimeMs(time/1000)); sb.append("("); sb.append(formatRatioLocked(time, whichBatteryRealtime)); sb.append(")"); } if (!didOne) sb.append("No activity"); pw.println(sb.toString()); pw.println(" "); if (which == STATS_UNPLUGGED) { Loading core/java/com/android/internal/app/IBatteryStats.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ interface IBatteryStats { void noteScreenOff(); void notePhoneOn(); void notePhoneOff(); void notePhoneSignalStrength(int asu); void notePhoneDataConnectionState(int dataType, boolean hasData); void noteWifiOn(); void noteWifiOff(); void noteWifiRunning(); Loading core/java/com/android/internal/os/BatteryStatsImpl.java +117 −16 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.os.Parcel; import android.os.ParcelFormatException; import android.os.Parcelable; import android.os.SystemClock; import android.telephony.TelephonyManager; import android.util.Log; import android.util.Printer; import android.util.SparseArray; Loading @@ -47,7 +48,7 @@ public final class BatteryStatsImpl extends BatteryStats { private static final int MAGIC = 0xBA757475; // 'BATSTATS' // Current on-disk Parcel version private static final int VERSION = 28; private static final int VERSION = 29; private final File mFile; private final File mBackupFile; Loading Loading @@ -92,6 +93,12 @@ public final class BatteryStatsImpl extends BatteryStats { boolean mPhoneOn; Timer mPhoneOnTimer; int mPhoneSignalStrengthBin = -1; final Timer[] mPhoneSignalStrengthsTimer = new Timer[NUM_SIGNAL_STRENGTH_BINS]; int mPhoneDataConnectionType = -1; final Timer[] mPhoneDataConnectionsTimer = new Timer[NUM_DATA_CONNECTION_TYPES]; boolean mWifiOn; Timer mWifiOnTimer; Loading Loading @@ -307,15 +314,15 @@ public final class BatteryStatsImpl extends BatteryStats { return val; } public void logState() { Log.i("foo", "mNesting=" + mNesting + " mCount=" + mCount public void logState(Printer pw, String prefix) { pw.println(prefix + "mNesting=" + mNesting + " mCount=" + mCount + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount + " mUnpluggedCount=" + mUnpluggedCount); Log.i("foo", "mTotalTime=" + mTotalTime pw.println(prefix + "mTotalTime=" + mTotalTime + " mLoadedTime=" + mLoadedTime); Log.i("foo", "mLastTime=" + mLastTime pw.println(prefix + "mLastTime=" + mLastTime + " mUnpluggedTime=" + mUnpluggedTime); Log.i("foo", "mUpdateTime=" + mUpdateTime pw.println(prefix + "mUpdateTime=" + mUpdateTime + " mAcquireTime=" + mAcquireTime); } Loading Loading @@ -486,6 +493,50 @@ public final class BatteryStatsImpl extends BatteryStats { } } public void notePhoneSignalStrengthLocked(int asu) { // Bin the strength. int bin; if (asu < 0 || asu >= 99) bin = SIGNAL_STRENGTH_NONE_OR_UNKNOWN; else if (asu >= 16) bin = SIGNAL_STRENGTH_GREAT; else if (asu >= 8) bin = SIGNAL_STRENGTH_GOOD; else if (asu >= 4) bin = SIGNAL_STRENGTH_MODERATE; else bin = SIGNAL_STRENGTH_POOR; if (mPhoneSignalStrengthBin != bin) { if (mPhoneSignalStrengthBin >= 0) { mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked(this); } mPhoneSignalStrengthBin = bin; mPhoneSignalStrengthsTimer[bin].startRunningLocked(this); } } public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { int bin = DATA_CONNECTION_NONE; if (hasData) { switch (dataType) { case TelephonyManager.NETWORK_TYPE_EDGE: bin = DATA_CONNECTION_EDGE; break; case TelephonyManager.NETWORK_TYPE_GPRS: bin = DATA_CONNECTION_GPRS; break; case TelephonyManager.NETWORK_TYPE_UMTS: bin = DATA_CONNECTION_UMTS; break; default: bin = DATA_CONNECTION_OTHER; break; } } if (mPhoneDataConnectionType != bin) { if (mPhoneDataConnectionType >= 0) { mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked(this); } mPhoneDataConnectionType = bin; mPhoneDataConnectionsTimer[bin].startRunningLocked(this); } } public void noteWifiOnLocked() { if (!mWifiOn) { mWifiOn = true; Loading Loading @@ -564,6 +615,18 @@ public final class BatteryStatsImpl extends BatteryStats { return mPhoneOnTimer.getTotalTime(batteryRealtime, which); } @Override public long getPhoneSignalStrengthTime(int strengthBin, long batteryRealtime, int which) { return mPhoneSignalStrengthsTimer[strengthBin].getTotalTime( batteryRealtime, which); } @Override public long getPhoneDataConnectionTime(int dataType, long batteryRealtime, int which) { return mPhoneDataConnectionsTimer[dataType].getTotalTime( batteryRealtime, which); } @Override public long getWifiOnTime(long batteryRealtime, int which) { return mWifiOnTimer.getTotalTime(batteryRealtime, which); } Loading Loading @@ -1617,6 +1680,12 @@ public final class BatteryStatsImpl extends BatteryStats { mStartCount++; mScreenOnTimer = new Timer(-1, null, mUnpluggables); mPhoneOnTimer = new Timer(-2, null, mUnpluggables); for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { mPhoneSignalStrengthsTimer[i] = new Timer(-100-i, null, mUnpluggables); } for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { mPhoneDataConnectionsTimer[i] = new Timer(-200-i, null, mUnpluggables); } mWifiOnTimer = new Timer(-3, null, mUnpluggables); mWifiRunningTimer = new Timer(-4, null, mUnpluggables); mBluetoothOnTimer = new Timer(-5, null, mUnpluggables); Loading Loading @@ -1955,6 +2024,12 @@ public final class BatteryStatsImpl extends BatteryStats { mScreenOnTimer.readSummaryFromParcelLocked(in); mPhoneOn = false; mPhoneOnTimer.readSummaryFromParcelLocked(in); for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); } for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); } mWifiOn = false; mWifiOnTimer.readSummaryFromParcelLocked(in); mWifiRunning = false; Loading Loading @@ -2061,6 +2136,12 @@ public final class BatteryStatsImpl extends BatteryStats { mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL); } for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL); } mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL); mBluetoothOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); Loading Loading @@ -2186,6 +2267,12 @@ public final class BatteryStatsImpl extends BatteryStats { mScreenOnTimer = new Timer(-1, null, mUnpluggables, in); mPhoneOn = false; mPhoneOnTimer = new Timer(-2, null, mUnpluggables, in); for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { mPhoneSignalStrengthsTimer[i] = new Timer(-100-i, null, mUnpluggables, in); } for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { mPhoneDataConnectionsTimer[i] = new Timer(-200-i, null, mUnpluggables, in); } mWifiOn = false; mWifiOnTimer = new Timer(-2, null, mUnpluggables, in); mWifiRunning = false; Loading Loading @@ -2243,6 +2330,12 @@ public final class BatteryStatsImpl extends BatteryStats { out.writeLong(mBatteryLastRealtime); mScreenOnTimer.writeToParcel(out, batteryRealtime); mPhoneOnTimer.writeToParcel(out, batteryRealtime); for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { mPhoneSignalStrengthsTimer[i].writeToParcel(out, batteryRealtime); } for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { mPhoneDataConnectionsTimer[i].writeToParcel(out, batteryRealtime); } mWifiOnTimer.writeToParcel(out, batteryRealtime); mWifiRunningTimer.writeToParcel(out, batteryRealtime); mBluetoothOnTimer.writeToParcel(out, batteryRealtime); Loading Loading @@ -2286,16 +2379,24 @@ public final class BatteryStatsImpl extends BatteryStats { public void dumpLocked(Printer pw) { if (DEBUG) { Log.i(TAG, "*** Screen timer:"); mScreenOnTimer.logState(); Log.i(TAG, "*** Phone timer:"); mPhoneOnTimer.logState(); Log.i(TAG, "*** Wifi timer:"); mWifiOnTimer.logState(); Log.i(TAG, "*** WifiRunning timer:"); mWifiRunningTimer.logState(); Log.i(TAG, "*** Bluetooth timer:"); mBluetoothOnTimer.logState(); pw.println("*** Screen timer:"); mScreenOnTimer.logState(pw, " "); pw.println("*** Phone timer:"); mPhoneOnTimer.logState(pw, " "); for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { pw.println("*** Signal strength #" + i + ":"); mPhoneSignalStrengthsTimer[i].logState(pw, " "); } for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { pw.println("*** Data connection type #" + i + ":"); mPhoneDataConnectionsTimer[i].logState(pw, " "); } pw.println("*** Wifi timer:"); mWifiOnTimer.logState(pw, " "); pw.println("*** WifiRunning timer:"); mWifiRunningTimer.logState(pw, " "); pw.println("*** Bluetooth timer:"); mBluetoothOnTimer.logState(pw, " "); } super.dumpLocked(pw); } Loading services/java/com/android/server/TelephonyRegistry.java +11 −0 Original line number Diff line number Diff line Loading @@ -440,6 +440,14 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { } private void broadcastSignalStrengthChanged(int asu) { long ident = Binder.clearCallingIdentity(); try { mBatteryStats.notePhoneSignalStrength(asu); } catch (RemoteException e) { } finally { Binder.restoreCallingIdentity(ident); } Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED); intent.putExtra(PhoneStateIntentReceiver.INTENT_KEY_ASU, asu); mContext.sendStickyBroadcast(intent); Loading Loading @@ -469,6 +477,9 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { private void broadcastDataConnectionStateChanged(int state, boolean isDataConnectivityPossible, String reason, String apn, String interfaceName) { // Note: not reporting to the battery stats service here, because the // status bar takes care of that after taking into account all of the // required info. Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); intent.putExtra(Phone.STATE_KEY, DefaultPhoneNotifier.convertDataState(state).toString()); if (!isDataConnectivityPossible) { Loading services/java/com/android/server/am/BatteryStatsService.java +15 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.os.IBinder; import android.os.Parcel; import android.os.Process; import android.os.ServiceManager; import android.telephony.TelephonyManager; import android.util.PrintWriterPrinter; import java.io.FileDescriptor; Loading Loading @@ -149,6 +150,20 @@ public final class BatteryStatsService extends IBatteryStats.Stub { } } public void notePhoneSignalStrength(int asu) { enforceCallingPermission(); synchronized (mStats) { mStats.notePhoneSignalStrengthLocked(asu); } } public void notePhoneDataConnectionState(int dataType, boolean hasData) { enforceCallingPermission(); synchronized (mStats) { mStats.notePhoneDataConnectionStateLocked(dataType, hasData); } } public void noteWifiOn() { enforceCallingPermission(); synchronized (mStats) { Loading Loading
core/java/android/os/BatteryStats.java +106 −9 Original line number Diff line number Diff line Loading @@ -4,8 +4,6 @@ import java.io.PrintWriter; import java.util.Formatter; import java.util.Map; import com.android.internal.os.BatteryStatsImpl.Timer; import android.util.Log; import android.util.Printer; import android.util.SparseArray; Loading Loading @@ -92,6 +90,8 @@ public abstract class BatteryStats implements Parcelable { private static final String BATTERY_DATA = "battery"; private static final String WIFI_LOCK_DATA = "wifilock"; private static final String MISC_DATA = "misc"; private static final String SIGNAL_STRENGTH_DATA = "signal"; private static final String DATA_CONNECTION_DATA = "dataconn"; private final StringBuilder mFormatBuilder = new StringBuilder(8); private final Formatter mFormatter = new Formatter(mFormatBuilder); Loading Loading @@ -122,7 +122,7 @@ public abstract class BatteryStats implements Parcelable { /** * Temporary for debugging. */ public abstract void logState(); public abstract void logState(Printer pw, String prefix); } /** Loading Loading @@ -293,6 +293,48 @@ public abstract class BatteryStats implements Parcelable { */ public abstract long getPhoneOnTime(long batteryRealtime, int which); public static final int SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0; public static final int SIGNAL_STRENGTH_POOR = 1; public static final int SIGNAL_STRENGTH_MODERATE = 2; public static final int SIGNAL_STRENGTH_GOOD = 3; public static final int SIGNAL_STRENGTH_GREAT = 4; static final String[] SIGNAL_STRENGTH_NAMES = { "none", "poor", "moderate", "good", "great" }; public static final int NUM_SIGNAL_STRENGTH_BINS = 5; /** * Returns the time in milliseconds that the phone has been running with * the given signal strength. * * {@hide} */ public abstract long getPhoneSignalStrengthTime(int strengthBin, long batteryRealtime, int which); public static final int DATA_CONNECTION_NONE = 0; public static final int DATA_CONNECTION_GPRS = 1; public static final int DATA_CONNECTION_EDGE = 2; public static final int DATA_CONNECTION_UMTS = 3; public static final int DATA_CONNECTION_OTHER = 4; static final String[] DATA_CONNECTION_NAMES = { "none", "gprs", "edge", "umts", "other" }; public static final int NUM_DATA_CONNECTION_TYPES = 5; /** * Returns the time in milliseconds that the phone has been running with * the given data connection. * * {@hide} */ public abstract long getPhoneDataConnectionTime(int dataType, long batteryRealtime, int which); /** * Returns the time in milliseconds that wifi has been on while the device was * running on battery. Loading Loading @@ -561,6 +603,20 @@ public abstract class BatteryStats implements Parcelable { screenOnTime / 1000, phoneOnTime / 1000, wifiOnTime / 1000, wifiRunningTime / 1000, bluetoothOnTime / 1000); // Dump signal strength stats Object[] args = new Object[NUM_SIGNAL_STRENGTH_BINS]; for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { args[i] = getPhoneSignalStrengthTime(i, batteryRealtime, which) / 1000; } dumpLine(pw, 0 /* uid */, category, SIGNAL_STRENGTH_DATA, args); // Dump network type stats args = new Object[NUM_DATA_CONNECTION_TYPES]; for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { args[i] = getPhoneDataConnectionTime(i, batteryRealtime, which) / 1000; } dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_DATA, args); if (which == STATS_UNPLUGGED) { dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, getUnpluggedStartLevel(), getPluggedStartLevel()); Loading Loading @@ -706,17 +762,58 @@ public abstract class BatteryStats implements Parcelable { final long wifiOnTime = getWifiOnTime(batteryRealtime, which); final long bluetoothOnTime = getBluetoothOnTime(batteryRealtime, which); pw.println(prefix + " Time with screen on: " + formatTimeMs(screenOnTime / 1000) + " Screen on: " + formatTimeMs(screenOnTime / 1000) + "(" + formatRatioLocked(screenOnTime, whichBatteryRealtime) + "), time with phone on: " + formatTimeMs(phoneOnTime / 1000) + "(" + formatRatioLocked(phoneOnTime, whichBatteryRealtime) + "), time with wifi on: " + formatTimeMs(wifiOnTime / 1000) + "), Phone on: " + formatTimeMs(phoneOnTime / 1000) + "(" + formatRatioLocked(phoneOnTime, whichBatteryRealtime)); pw.println(prefix + " Wifi on: " + formatTimeMs(wifiOnTime / 1000) + "(" + formatRatioLocked(wifiOnTime, whichBatteryRealtime) + "), time with wifi running: " + formatTimeMs(wifiRunningTime / 1000) + "), Wifi running: " + formatTimeMs(wifiRunningTime / 1000) + "(" + formatRatioLocked(wifiRunningTime, whichBatteryRealtime) + "), time with bluetooth on: " + formatTimeMs(bluetoothOnTime / 1000) + "), Bluetooth on: " + formatTimeMs(bluetoothOnTime / 1000) + "(" + formatRatioLocked(bluetoothOnTime, whichBatteryRealtime)+ ")"); sb.setLength(0); sb.append(" Signal strengths: "); boolean didOne = false; for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { final long time = getPhoneSignalStrengthTime(i, batteryRealtime, which); if (time == 0) { continue; } if (didOne) sb.append(", "); didOne = true; sb.append(SIGNAL_STRENGTH_NAMES[i]); sb.append(" "); sb.append(formatTimeMs(time/1000)); sb.append("("); sb.append(formatRatioLocked(time, whichBatteryRealtime)); sb.append(")"); } if (!didOne) sb.append("No activity"); pw.println(sb.toString()); sb.setLength(0); sb.append(" Data types: "); didOne = false; for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { final long time = getPhoneDataConnectionTime(i, batteryRealtime, which); if (time == 0) { continue; } if (didOne) sb.append(", "); didOne = true; sb.append(DATA_CONNECTION_NAMES[i]); sb.append(" "); sb.append(formatTimeMs(time/1000)); sb.append("("); sb.append(formatRatioLocked(time, whichBatteryRealtime)); sb.append(")"); } if (!didOne) sb.append("No activity"); pw.println(sb.toString()); pw.println(" "); if (which == STATS_UNPLUGGED) { Loading
core/java/com/android/internal/app/IBatteryStats.aidl +2 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ interface IBatteryStats { void noteScreenOff(); void notePhoneOn(); void notePhoneOff(); void notePhoneSignalStrength(int asu); void notePhoneDataConnectionState(int dataType, boolean hasData); void noteWifiOn(); void noteWifiOff(); void noteWifiRunning(); Loading
core/java/com/android/internal/os/BatteryStatsImpl.java +117 −16 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.os.Parcel; import android.os.ParcelFormatException; import android.os.Parcelable; import android.os.SystemClock; import android.telephony.TelephonyManager; import android.util.Log; import android.util.Printer; import android.util.SparseArray; Loading @@ -47,7 +48,7 @@ public final class BatteryStatsImpl extends BatteryStats { private static final int MAGIC = 0xBA757475; // 'BATSTATS' // Current on-disk Parcel version private static final int VERSION = 28; private static final int VERSION = 29; private final File mFile; private final File mBackupFile; Loading Loading @@ -92,6 +93,12 @@ public final class BatteryStatsImpl extends BatteryStats { boolean mPhoneOn; Timer mPhoneOnTimer; int mPhoneSignalStrengthBin = -1; final Timer[] mPhoneSignalStrengthsTimer = new Timer[NUM_SIGNAL_STRENGTH_BINS]; int mPhoneDataConnectionType = -1; final Timer[] mPhoneDataConnectionsTimer = new Timer[NUM_DATA_CONNECTION_TYPES]; boolean mWifiOn; Timer mWifiOnTimer; Loading Loading @@ -307,15 +314,15 @@ public final class BatteryStatsImpl extends BatteryStats { return val; } public void logState() { Log.i("foo", "mNesting=" + mNesting + " mCount=" + mCount public void logState(Printer pw, String prefix) { pw.println(prefix + "mNesting=" + mNesting + " mCount=" + mCount + " mLoadedCount=" + mLoadedCount + " mLastCount=" + mLastCount + " mUnpluggedCount=" + mUnpluggedCount); Log.i("foo", "mTotalTime=" + mTotalTime pw.println(prefix + "mTotalTime=" + mTotalTime + " mLoadedTime=" + mLoadedTime); Log.i("foo", "mLastTime=" + mLastTime pw.println(prefix + "mLastTime=" + mLastTime + " mUnpluggedTime=" + mUnpluggedTime); Log.i("foo", "mUpdateTime=" + mUpdateTime pw.println(prefix + "mUpdateTime=" + mUpdateTime + " mAcquireTime=" + mAcquireTime); } Loading Loading @@ -486,6 +493,50 @@ public final class BatteryStatsImpl extends BatteryStats { } } public void notePhoneSignalStrengthLocked(int asu) { // Bin the strength. int bin; if (asu < 0 || asu >= 99) bin = SIGNAL_STRENGTH_NONE_OR_UNKNOWN; else if (asu >= 16) bin = SIGNAL_STRENGTH_GREAT; else if (asu >= 8) bin = SIGNAL_STRENGTH_GOOD; else if (asu >= 4) bin = SIGNAL_STRENGTH_MODERATE; else bin = SIGNAL_STRENGTH_POOR; if (mPhoneSignalStrengthBin != bin) { if (mPhoneSignalStrengthBin >= 0) { mPhoneSignalStrengthsTimer[mPhoneSignalStrengthBin].stopRunningLocked(this); } mPhoneSignalStrengthBin = bin; mPhoneSignalStrengthsTimer[bin].startRunningLocked(this); } } public void notePhoneDataConnectionStateLocked(int dataType, boolean hasData) { int bin = DATA_CONNECTION_NONE; if (hasData) { switch (dataType) { case TelephonyManager.NETWORK_TYPE_EDGE: bin = DATA_CONNECTION_EDGE; break; case TelephonyManager.NETWORK_TYPE_GPRS: bin = DATA_CONNECTION_GPRS; break; case TelephonyManager.NETWORK_TYPE_UMTS: bin = DATA_CONNECTION_UMTS; break; default: bin = DATA_CONNECTION_OTHER; break; } } if (mPhoneDataConnectionType != bin) { if (mPhoneDataConnectionType >= 0) { mPhoneDataConnectionsTimer[mPhoneDataConnectionType].stopRunningLocked(this); } mPhoneDataConnectionType = bin; mPhoneDataConnectionsTimer[bin].startRunningLocked(this); } } public void noteWifiOnLocked() { if (!mWifiOn) { mWifiOn = true; Loading Loading @@ -564,6 +615,18 @@ public final class BatteryStatsImpl extends BatteryStats { return mPhoneOnTimer.getTotalTime(batteryRealtime, which); } @Override public long getPhoneSignalStrengthTime(int strengthBin, long batteryRealtime, int which) { return mPhoneSignalStrengthsTimer[strengthBin].getTotalTime( batteryRealtime, which); } @Override public long getPhoneDataConnectionTime(int dataType, long batteryRealtime, int which) { return mPhoneDataConnectionsTimer[dataType].getTotalTime( batteryRealtime, which); } @Override public long getWifiOnTime(long batteryRealtime, int which) { return mWifiOnTimer.getTotalTime(batteryRealtime, which); } Loading Loading @@ -1617,6 +1680,12 @@ public final class BatteryStatsImpl extends BatteryStats { mStartCount++; mScreenOnTimer = new Timer(-1, null, mUnpluggables); mPhoneOnTimer = new Timer(-2, null, mUnpluggables); for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { mPhoneSignalStrengthsTimer[i] = new Timer(-100-i, null, mUnpluggables); } for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { mPhoneDataConnectionsTimer[i] = new Timer(-200-i, null, mUnpluggables); } mWifiOnTimer = new Timer(-3, null, mUnpluggables); mWifiRunningTimer = new Timer(-4, null, mUnpluggables); mBluetoothOnTimer = new Timer(-5, null, mUnpluggables); Loading Loading @@ -1955,6 +2024,12 @@ public final class BatteryStatsImpl extends BatteryStats { mScreenOnTimer.readSummaryFromParcelLocked(in); mPhoneOn = false; mPhoneOnTimer.readSummaryFromParcelLocked(in); for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { mPhoneSignalStrengthsTimer[i].readSummaryFromParcelLocked(in); } for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { mPhoneDataConnectionsTimer[i].readSummaryFromParcelLocked(in); } mWifiOn = false; mWifiOnTimer.readSummaryFromParcelLocked(in); mWifiRunning = false; Loading Loading @@ -2061,6 +2136,12 @@ public final class BatteryStatsImpl extends BatteryStats { mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); mPhoneOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { mPhoneSignalStrengthsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL); } for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { mPhoneDataConnectionsTimer[i].writeSummaryFromParcelLocked(out, NOWREAL); } mWifiOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); mWifiRunningTimer.writeSummaryFromParcelLocked(out, NOWREAL); mBluetoothOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); Loading Loading @@ -2186,6 +2267,12 @@ public final class BatteryStatsImpl extends BatteryStats { mScreenOnTimer = new Timer(-1, null, mUnpluggables, in); mPhoneOn = false; mPhoneOnTimer = new Timer(-2, null, mUnpluggables, in); for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { mPhoneSignalStrengthsTimer[i] = new Timer(-100-i, null, mUnpluggables, in); } for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { mPhoneDataConnectionsTimer[i] = new Timer(-200-i, null, mUnpluggables, in); } mWifiOn = false; mWifiOnTimer = new Timer(-2, null, mUnpluggables, in); mWifiRunning = false; Loading Loading @@ -2243,6 +2330,12 @@ public final class BatteryStatsImpl extends BatteryStats { out.writeLong(mBatteryLastRealtime); mScreenOnTimer.writeToParcel(out, batteryRealtime); mPhoneOnTimer.writeToParcel(out, batteryRealtime); for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { mPhoneSignalStrengthsTimer[i].writeToParcel(out, batteryRealtime); } for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { mPhoneDataConnectionsTimer[i].writeToParcel(out, batteryRealtime); } mWifiOnTimer.writeToParcel(out, batteryRealtime); mWifiRunningTimer.writeToParcel(out, batteryRealtime); mBluetoothOnTimer.writeToParcel(out, batteryRealtime); Loading Loading @@ -2286,16 +2379,24 @@ public final class BatteryStatsImpl extends BatteryStats { public void dumpLocked(Printer pw) { if (DEBUG) { Log.i(TAG, "*** Screen timer:"); mScreenOnTimer.logState(); Log.i(TAG, "*** Phone timer:"); mPhoneOnTimer.logState(); Log.i(TAG, "*** Wifi timer:"); mWifiOnTimer.logState(); Log.i(TAG, "*** WifiRunning timer:"); mWifiRunningTimer.logState(); Log.i(TAG, "*** Bluetooth timer:"); mBluetoothOnTimer.logState(); pw.println("*** Screen timer:"); mScreenOnTimer.logState(pw, " "); pw.println("*** Phone timer:"); mPhoneOnTimer.logState(pw, " "); for (int i=0; i<NUM_SIGNAL_STRENGTH_BINS; i++) { pw.println("*** Signal strength #" + i + ":"); mPhoneSignalStrengthsTimer[i].logState(pw, " "); } for (int i=0; i<NUM_DATA_CONNECTION_TYPES; i++) { pw.println("*** Data connection type #" + i + ":"); mPhoneDataConnectionsTimer[i].logState(pw, " "); } pw.println("*** Wifi timer:"); mWifiOnTimer.logState(pw, " "); pw.println("*** WifiRunning timer:"); mWifiRunningTimer.logState(pw, " "); pw.println("*** Bluetooth timer:"); mBluetoothOnTimer.logState(pw, " "); } super.dumpLocked(pw); } Loading
services/java/com/android/server/TelephonyRegistry.java +11 −0 Original line number Diff line number Diff line Loading @@ -440,6 +440,14 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { } private void broadcastSignalStrengthChanged(int asu) { long ident = Binder.clearCallingIdentity(); try { mBatteryStats.notePhoneSignalStrength(asu); } catch (RemoteException e) { } finally { Binder.restoreCallingIdentity(ident); } Intent intent = new Intent(TelephonyIntents.ACTION_SIGNAL_STRENGTH_CHANGED); intent.putExtra(PhoneStateIntentReceiver.INTENT_KEY_ASU, asu); mContext.sendStickyBroadcast(intent); Loading Loading @@ -469,6 +477,9 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { private void broadcastDataConnectionStateChanged(int state, boolean isDataConnectivityPossible, String reason, String apn, String interfaceName) { // Note: not reporting to the battery stats service here, because the // status bar takes care of that after taking into account all of the // required info. Intent intent = new Intent(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED); intent.putExtra(Phone.STATE_KEY, DefaultPhoneNotifier.convertDataState(state).toString()); if (!isDataConnectivityPossible) { Loading
services/java/com/android/server/am/BatteryStatsService.java +15 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.os.IBinder; import android.os.Parcel; import android.os.Process; import android.os.ServiceManager; import android.telephony.TelephonyManager; import android.util.PrintWriterPrinter; import java.io.FileDescriptor; Loading Loading @@ -149,6 +150,20 @@ public final class BatteryStatsService extends IBatteryStats.Stub { } } public void notePhoneSignalStrength(int asu) { enforceCallingPermission(); synchronized (mStats) { mStats.notePhoneSignalStrengthLocked(asu); } } public void notePhoneDataConnectionState(int dataType, boolean hasData) { enforceCallingPermission(); synchronized (mStats) { mStats.notePhoneDataConnectionStateLocked(dataType, hasData); } } public void noteWifiOn() { enforceCallingPermission(); synchronized (mStats) { Loading