Loading api/current.txt +0 −12 Original line number Diff line number Diff line Loading @@ -25443,18 +25443,6 @@ package android.telephony { field public static final android.os.Parcelable.Creator CREATOR; } public class DataConnectionRealTimeInfo implements android.os.Parcelable { method public int describeContents(); method public int getDcPowerState(); method public long getTime(); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; field public static int DC_POWER_STATE_HIGH; field public static int DC_POWER_STATE_LOW; field public static int DC_POWER_STATE_MEDIUM; field public static int DC_POWER_STATE_UNKNOWN; } public class NeighboringCellInfo implements android.os.Parcelable { ctor public deprecated NeighboringCellInfo(); ctor public deprecated NeighboringCellInfo(int, int); core/java/android/os/BatteryStats.java +63 −28 Original line number Diff line number Diff line Loading @@ -130,7 +130,7 @@ public abstract class BatteryStats implements Parcelable { // NOTE: Update this list if you add/change any stats above. // These characters are supposed to represent "total", "last", "current", // and "unplugged". They were shortened for efficiency sake. private static final String[] STAT_NAMES = { "t", "l", "c", "u" }; private static final String[] STAT_NAMES = { "l", "c", "u" }; /** * Bump the version on this if the checkin format changes. Loading Loading @@ -186,7 +186,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the count associated with this Counter for the * selected type of statistics. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT */ public abstract int getCountLocked(int which); Loading @@ -205,7 +205,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the count associated with this Counter for the * selected type of statistics. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT */ public abstract long getCountLocked(int which); Loading @@ -224,7 +224,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the count associated with this Timer for the * selected type of statistics. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT */ public abstract int getCountLocked(int which); Loading @@ -233,7 +233,7 @@ public abstract class BatteryStats implements Parcelable { * selected type of statistics. * * @param elapsedRealtimeUs current elapsed realtime of system in microseconds * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT * @return a time in microseconds */ public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); Loading Loading @@ -385,27 +385,27 @@ public abstract class BatteryStats implements Parcelable { /** * Returns the total time (in 1/100 sec) spent executing in user code. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long getUserTime(int which); /** * Returns the total time (in 1/100 sec) spent executing in system code. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long getSystemTime(int which); /** * Returns the number of times the process has been started. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract int getStarts(int which); /** * Returns the cpu time spent in microseconds while the process was in the foreground. * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. * @return foreground cpu time in microseconds */ public abstract long getForegroundTime(int which); Loading @@ -414,7 +414,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the approximate cpu time spent in microseconds, at a certain CPU speed. * @param speedStep the index of the CPU speed. This is not the actual speed of the * CPU. * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. * @see BatteryStats#getCpuSpeedSteps() */ public abstract long getTimeAtCpuSpeedStep(int speedStep, int which); Loading @@ -433,7 +433,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the number of times this package has done something that could wake up the * device from sleep. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract int getWakeups(int which); Loading @@ -451,7 +451,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the amount of time spent started. * * @param batteryUptime elapsed uptime on battery in microseconds. * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. * @return */ public abstract long getStartTime(long batteryUptime, int which); Loading @@ -459,14 +459,14 @@ public abstract class BatteryStats implements Parcelable { /** * Returns the total number of times startService() has been called. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract int getStarts(int which); /** * Returns the total number times the service has been launched. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract int getLaunches(int which); } Loading Loading @@ -1285,7 +1285,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the total, last, or current battery uptime in microseconds. * * @param curTime the elapsed realtime in microseconds. * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long computeBatteryUptime(long curTime, int which); Loading @@ -1293,7 +1293,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the total, last, or current battery realtime in microseconds. * * @param curTime the current elapsed realtime in microseconds. * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long computeBatteryRealtime(long curTime, int which); Loading @@ -1301,7 +1301,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the total, last, or current battery screen off uptime in microseconds. * * @param curTime the elapsed realtime in microseconds. * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long computeBatteryScreenOffUptime(long curTime, int which); Loading @@ -1309,7 +1309,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the total, last, or current battery screen off realtime in microseconds. * * @param curTime the current elapsed realtime in microseconds. * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long computeBatteryScreenOffRealtime(long curTime, int which); Loading @@ -1317,18 +1317,38 @@ public abstract class BatteryStats implements Parcelable { * Returns the total, last, or current uptime in microseconds. * * @param curTime the current elapsed realtime in microseconds. * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long computeUptime(long curTime, int which); /** * Returns the total, last, or current realtime in microseconds. * * * * @param curTime the current elapsed realtime in microseconds. * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long computeRealtime(long curTime, int which); /** * Compute an approximation for how much run time (in microseconds) is remaining on * the battery. Returns -1 if no time can be computed: either there is not * enough current data to make a decision, or the battery is currently * charging. * * @param curTime The current elepsed realtime in microseconds. */ public abstract long computeBatteryTimeRemaining(long curTime); /** * Compute an approximation for how much time (in microseconds) remains until the battery * is fully charged. Returns -1 if no time can be computed: either there is not * enough current data to make a decision, or the battery is currently * discharging. * * @param curTime The current elepsed realtime in microseconds. */ public abstract long computeChargeTimeRemaining(long curTime); public abstract Map<String, ? extends LongCounter> getWakeupReasonStats(); public abstract Map<String, ? extends Timer> getKernelWakelockStats(); Loading Loading @@ -1430,7 +1450,7 @@ public abstract class BatteryStats implements Parcelable { * @param timer a Timer object contining the wakelock times. * @param elapsedRealtimeUs the current on-battery time in microseconds. * @param name the name of the wakelock. * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. * @param linePrefix a String to be prepended to each line of output. * @return the line prefix */ Loading Loading @@ -1464,7 +1484,7 @@ public abstract class BatteryStats implements Parcelable { * @param timer a Timer object contining the wakelock times. * @param elapsedRealtimeUs the current time in microseconds. * @param name the name of the wakelock. * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. * @param linePrefix a String to be prepended to each line of output. * @return the line prefix */ Loading Loading @@ -1682,7 +1702,7 @@ public abstract class BatteryStats implements Parcelable { } } BatteryStatsHelper helper = new BatteryStatsHelper(context); BatteryStatsHelper helper = new BatteryStatsHelper(context, false); helper.create(this); helper.refreshStats(which, UserHandle.USER_ALL); List<BatterySipper> sippers = helper.getUsageList(); Loading Loading @@ -1929,6 +1949,8 @@ public abstract class BatteryStats implements Parcelable { final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, which); final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); StringBuilder sb = new StringBuilder(128); Loading Loading @@ -1963,7 +1985,20 @@ public abstract class BatteryStats implements Parcelable { sb.append("realtime, "); formatTimeMs(sb, totalUptime / 1000); sb.append("uptime"); if (batteryTimeRemaining >= 0) { sb.setLength(0); sb.append(prefix); sb.append(" Battery time remaining: "); formatTimeMs(sb, batteryTimeRemaining / 1000); pw.println(sb.toString()); } if (chargeTimeRemaining >= 0) { sb.setLength(0); sb.append(prefix); sb.append(" Charge time remaining: "); formatTimeMs(sb, chargeTimeRemaining / 1000); pw.println(sb.toString()); } pw.print(" Start clock time: "); pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); Loading Loading @@ -2268,7 +2303,7 @@ public abstract class BatteryStats implements Parcelable { pw.println(); } BatteryStatsHelper helper = new BatteryStatsHelper(context); BatteryStatsHelper helper = new BatteryStatsHelper(context, false); helper.create(this); helper.refreshStats(which, UserHandle.USER_ALL); List<BatterySipper> sippers = helper.getUsageList(); Loading core/java/com/android/internal/app/IBatteryStats.aidl +2 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.internal.app; import com.android.internal.os.BatteryStatsImpl; import android.os.WorkSource; import android.telephony.DataConnectionRealTimeInfo; import android.telephony.SignalStrength; interface IBatteryStats { Loading Loading @@ -55,7 +56,7 @@ interface IBatteryStats { void noteScreenOff(); void noteInputEvent(); void noteUserActivity(int uid, int event); void noteDataConnectionActive(int type, boolean active, long timestampNs); void noteMobileRadioPowerState(int powerState, long timestampNs); void notePhoneOn(); void notePhoneOff(); void notePhoneSignalStrength(in SignalStrength signalStrength); Loading core/java/com/android/internal/os/BatteryStatsHelper.java +31 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ import static android.os.BatteryStats.NETWORK_WIFI_RX_DATA; import static android.os.BatteryStats.NETWORK_WIFI_TX_DATA; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.hardware.Sensor; import android.hardware.SensorManager; import android.net.ConnectivityManager; Loading Loading @@ -60,11 +62,14 @@ public class BatteryStatsHelper { private static final String TAG = BatteryStatsHelper.class.getSimpleName(); private static BatteryStats sStatsXfer; private static Intent sBatteryBroadcastXfer; final private Context mContext; final private boolean mCollectBatteryBroadcast; private IBatteryStats mBatteryInfo; private BatteryStats mStats; private Intent mBatteryBroadcast; private PowerProfile mPowerProfile; private final List<BatterySipper> mUsageList = new ArrayList<BatterySipper>(); Loading @@ -85,6 +90,8 @@ public class BatteryStatsHelper { long mBatteryUptime; long mTypeBatteryRealtime; long mTypeBatteryUptime; long mBatteryTimeRemaining; long mChargeTimeRemaining; private long mStatsPeriod = 0; private double mMaxPower = 1; Loading @@ -102,7 +109,12 @@ public class BatteryStatsHelper { private long mAppWifiRunning; public BatteryStatsHelper(Context context) { this(context, true); } public BatteryStatsHelper(Context context, boolean collectBatteryBroadcast) { mContext = context; mCollectBatteryBroadcast = collectBatteryBroadcast; } /** Clears the current stats and forces recreating for future use. */ Loading @@ -117,6 +129,13 @@ public class BatteryStatsHelper { return mStats; } public Intent getBatteryBroadcast() { if (mBatteryBroadcast == null && mCollectBatteryBroadcast) { load(); } return mBatteryBroadcast; } public PowerProfile getPowerProfile() { return mPowerProfile; } Loading @@ -129,6 +148,7 @@ public class BatteryStatsHelper { public void create(Bundle icicle) { if (icicle != null) { mStats = sStatsXfer; mBatteryBroadcast = sBatteryBroadcastXfer; } mBatteryInfo = IBatteryStats.Stub.asInterface( ServiceManager.getService(BatteryStats.SERVICE_NAME)); Loading @@ -137,6 +157,7 @@ public class BatteryStatsHelper { public void storeState() { sStatsXfer = mStats; sBatteryBroadcastXfer = mBatteryBroadcast; } public static String makemAh(double power) { Loading Loading @@ -190,6 +211,8 @@ public class BatteryStatsHelper { mBatteryRealtime = mStats.getBatteryRealtime(rawRealtimeUs); mTypeBatteryUptime = mStats.computeBatteryUptime(rawUptimeUs, mStatsType); mTypeBatteryRealtime = mStats.computeBatteryRealtime(rawRealtimeUs, mStatsType); mBatteryTimeRemaining = mStats.computeBatteryTimeRemaining(rawRealtimeUs); mChargeTimeRemaining = mStats.computeChargeTimeRemaining(rawRealtimeUs); if (DEBUG) { Log.d(TAG, "Raw time: realtime=" + (rawRealtimeUs/1000) + " uptime=" Loading Loading @@ -787,6 +810,10 @@ public class BatteryStatsHelper { return mMaxDrainedPower; } public long getBatteryTimeRemaining() { return mBatteryTimeRemaining; } public long getChargeTimeRemaining() { return mChargeTimeRemaining; } private void load() { if (mBatteryInfo == null) { return; Loading @@ -803,5 +830,9 @@ public class BatteryStatsHelper { } catch (RemoteException e) { Log.e(TAG, "RemoteException:", e); } if (mCollectBatteryBroadcast) { mBatteryBroadcast = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); } } } core/java/com/android/internal/os/BatteryStatsImpl.java +94 −38 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
api/current.txt +0 −12 Original line number Diff line number Diff line Loading @@ -25443,18 +25443,6 @@ package android.telephony { field public static final android.os.Parcelable.Creator CREATOR; } public class DataConnectionRealTimeInfo implements android.os.Parcelable { method public int describeContents(); method public int getDcPowerState(); method public long getTime(); method public void writeToParcel(android.os.Parcel, int); field public static final android.os.Parcelable.Creator CREATOR; field public static int DC_POWER_STATE_HIGH; field public static int DC_POWER_STATE_LOW; field public static int DC_POWER_STATE_MEDIUM; field public static int DC_POWER_STATE_UNKNOWN; } public class NeighboringCellInfo implements android.os.Parcelable { ctor public deprecated NeighboringCellInfo(); ctor public deprecated NeighboringCellInfo(int, int);
core/java/android/os/BatteryStats.java +63 −28 Original line number Diff line number Diff line Loading @@ -130,7 +130,7 @@ public abstract class BatteryStats implements Parcelable { // NOTE: Update this list if you add/change any stats above. // These characters are supposed to represent "total", "last", "current", // and "unplugged". They were shortened for efficiency sake. private static final String[] STAT_NAMES = { "t", "l", "c", "u" }; private static final String[] STAT_NAMES = { "l", "c", "u" }; /** * Bump the version on this if the checkin format changes. Loading Loading @@ -186,7 +186,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the count associated with this Counter for the * selected type of statistics. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT */ public abstract int getCountLocked(int which); Loading @@ -205,7 +205,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the count associated with this Counter for the * selected type of statistics. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT */ public abstract long getCountLocked(int which); Loading @@ -224,7 +224,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the count associated with this Timer for the * selected type of statistics. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT */ public abstract int getCountLocked(int which); Loading @@ -233,7 +233,7 @@ public abstract class BatteryStats implements Parcelable { * selected type of statistics. * * @param elapsedRealtimeUs current elapsed realtime of system in microseconds * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT * @return a time in microseconds */ public abstract long getTotalTimeLocked(long elapsedRealtimeUs, int which); Loading Loading @@ -385,27 +385,27 @@ public abstract class BatteryStats implements Parcelable { /** * Returns the total time (in 1/100 sec) spent executing in user code. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long getUserTime(int which); /** * Returns the total time (in 1/100 sec) spent executing in system code. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long getSystemTime(int which); /** * Returns the number of times the process has been started. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract int getStarts(int which); /** * Returns the cpu time spent in microseconds while the process was in the foreground. * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. * @return foreground cpu time in microseconds */ public abstract long getForegroundTime(int which); Loading @@ -414,7 +414,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the approximate cpu time spent in microseconds, at a certain CPU speed. * @param speedStep the index of the CPU speed. This is not the actual speed of the * CPU. * @param which one of STATS_TOTAL, STATS_LAST, STATS_CURRENT or STATS_UNPLUGGED * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. * @see BatteryStats#getCpuSpeedSteps() */ public abstract long getTimeAtCpuSpeedStep(int speedStep, int which); Loading @@ -433,7 +433,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the number of times this package has done something that could wake up the * device from sleep. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract int getWakeups(int which); Loading @@ -451,7 +451,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the amount of time spent started. * * @param batteryUptime elapsed uptime on battery in microseconds. * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. * @return */ public abstract long getStartTime(long batteryUptime, int which); Loading @@ -459,14 +459,14 @@ public abstract class BatteryStats implements Parcelable { /** * Returns the total number of times startService() has been called. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract int getStarts(int which); /** * Returns the total number times the service has been launched. * * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract int getLaunches(int which); } Loading Loading @@ -1285,7 +1285,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the total, last, or current battery uptime in microseconds. * * @param curTime the elapsed realtime in microseconds. * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long computeBatteryUptime(long curTime, int which); Loading @@ -1293,7 +1293,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the total, last, or current battery realtime in microseconds. * * @param curTime the current elapsed realtime in microseconds. * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long computeBatteryRealtime(long curTime, int which); Loading @@ -1301,7 +1301,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the total, last, or current battery screen off uptime in microseconds. * * @param curTime the elapsed realtime in microseconds. * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long computeBatteryScreenOffUptime(long curTime, int which); Loading @@ -1309,7 +1309,7 @@ public abstract class BatteryStats implements Parcelable { * Returns the total, last, or current battery screen off realtime in microseconds. * * @param curTime the current elapsed realtime in microseconds. * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long computeBatteryScreenOffRealtime(long curTime, int which); Loading @@ -1317,18 +1317,38 @@ public abstract class BatteryStats implements Parcelable { * Returns the total, last, or current uptime in microseconds. * * @param curTime the current elapsed realtime in microseconds. * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long computeUptime(long curTime, int which); /** * Returns the total, last, or current realtime in microseconds. * * * * @param curTime the current elapsed realtime in microseconds. * @param which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. */ public abstract long computeRealtime(long curTime, int which); /** * Compute an approximation for how much run time (in microseconds) is remaining on * the battery. Returns -1 if no time can be computed: either there is not * enough current data to make a decision, or the battery is currently * charging. * * @param curTime The current elepsed realtime in microseconds. */ public abstract long computeBatteryTimeRemaining(long curTime); /** * Compute an approximation for how much time (in microseconds) remains until the battery * is fully charged. Returns -1 if no time can be computed: either there is not * enough current data to make a decision, or the battery is currently * discharging. * * @param curTime The current elepsed realtime in microseconds. */ public abstract long computeChargeTimeRemaining(long curTime); public abstract Map<String, ? extends LongCounter> getWakeupReasonStats(); public abstract Map<String, ? extends Timer> getKernelWakelockStats(); Loading Loading @@ -1430,7 +1450,7 @@ public abstract class BatteryStats implements Parcelable { * @param timer a Timer object contining the wakelock times. * @param elapsedRealtimeUs the current on-battery time in microseconds. * @param name the name of the wakelock. * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. * @param linePrefix a String to be prepended to each line of output. * @return the line prefix */ Loading Loading @@ -1464,7 +1484,7 @@ public abstract class BatteryStats implements Parcelable { * @param timer a Timer object contining the wakelock times. * @param elapsedRealtimeUs the current time in microseconds. * @param name the name of the wakelock. * @param which which one of STATS_TOTAL, STATS_LAST, or STATS_CURRENT. * @param which which one of STATS_SINCE_CHARGED, STATS_SINCE_UNPLUGGED, or STATS_CURRENT. * @param linePrefix a String to be prepended to each line of output. * @return the line prefix */ Loading Loading @@ -1682,7 +1702,7 @@ public abstract class BatteryStats implements Parcelable { } } BatteryStatsHelper helper = new BatteryStatsHelper(context); BatteryStatsHelper helper = new BatteryStatsHelper(context, false); helper.create(this); helper.refreshStats(which, UserHandle.USER_ALL); List<BatterySipper> sippers = helper.getUsageList(); Loading Loading @@ -1929,6 +1949,8 @@ public abstract class BatteryStats implements Parcelable { final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which); final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, which); final long batteryTimeRemaining = computeBatteryTimeRemaining(rawRealtime); final long chargeTimeRemaining = computeChargeTimeRemaining(rawRealtime); StringBuilder sb = new StringBuilder(128); Loading Loading @@ -1963,7 +1985,20 @@ public abstract class BatteryStats implements Parcelable { sb.append("realtime, "); formatTimeMs(sb, totalUptime / 1000); sb.append("uptime"); if (batteryTimeRemaining >= 0) { sb.setLength(0); sb.append(prefix); sb.append(" Battery time remaining: "); formatTimeMs(sb, batteryTimeRemaining / 1000); pw.println(sb.toString()); } if (chargeTimeRemaining >= 0) { sb.setLength(0); sb.append(prefix); sb.append(" Charge time remaining: "); formatTimeMs(sb, chargeTimeRemaining / 1000); pw.println(sb.toString()); } pw.print(" Start clock time: "); pw.println(DateFormat.format("yyyy-MM-dd-HH-mm-ss", getStartClockTime()).toString()); Loading Loading @@ -2268,7 +2303,7 @@ public abstract class BatteryStats implements Parcelable { pw.println(); } BatteryStatsHelper helper = new BatteryStatsHelper(context); BatteryStatsHelper helper = new BatteryStatsHelper(context, false); helper.create(this); helper.refreshStats(which, UserHandle.USER_ALL); List<BatterySipper> sippers = helper.getUsageList(); Loading
core/java/com/android/internal/app/IBatteryStats.aidl +2 −1 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.internal.app; import com.android.internal.os.BatteryStatsImpl; import android.os.WorkSource; import android.telephony.DataConnectionRealTimeInfo; import android.telephony.SignalStrength; interface IBatteryStats { Loading Loading @@ -55,7 +56,7 @@ interface IBatteryStats { void noteScreenOff(); void noteInputEvent(); void noteUserActivity(int uid, int event); void noteDataConnectionActive(int type, boolean active, long timestampNs); void noteMobileRadioPowerState(int powerState, long timestampNs); void notePhoneOn(); void notePhoneOff(); void notePhoneSignalStrength(in SignalStrength signalStrength); Loading
core/java/com/android/internal/os/BatteryStatsHelper.java +31 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,8 @@ import static android.os.BatteryStats.NETWORK_WIFI_RX_DATA; import static android.os.BatteryStats.NETWORK_WIFI_TX_DATA; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.hardware.Sensor; import android.hardware.SensorManager; import android.net.ConnectivityManager; Loading Loading @@ -60,11 +62,14 @@ public class BatteryStatsHelper { private static final String TAG = BatteryStatsHelper.class.getSimpleName(); private static BatteryStats sStatsXfer; private static Intent sBatteryBroadcastXfer; final private Context mContext; final private boolean mCollectBatteryBroadcast; private IBatteryStats mBatteryInfo; private BatteryStats mStats; private Intent mBatteryBroadcast; private PowerProfile mPowerProfile; private final List<BatterySipper> mUsageList = new ArrayList<BatterySipper>(); Loading @@ -85,6 +90,8 @@ public class BatteryStatsHelper { long mBatteryUptime; long mTypeBatteryRealtime; long mTypeBatteryUptime; long mBatteryTimeRemaining; long mChargeTimeRemaining; private long mStatsPeriod = 0; private double mMaxPower = 1; Loading @@ -102,7 +109,12 @@ public class BatteryStatsHelper { private long mAppWifiRunning; public BatteryStatsHelper(Context context) { this(context, true); } public BatteryStatsHelper(Context context, boolean collectBatteryBroadcast) { mContext = context; mCollectBatteryBroadcast = collectBatteryBroadcast; } /** Clears the current stats and forces recreating for future use. */ Loading @@ -117,6 +129,13 @@ public class BatteryStatsHelper { return mStats; } public Intent getBatteryBroadcast() { if (mBatteryBroadcast == null && mCollectBatteryBroadcast) { load(); } return mBatteryBroadcast; } public PowerProfile getPowerProfile() { return mPowerProfile; } Loading @@ -129,6 +148,7 @@ public class BatteryStatsHelper { public void create(Bundle icicle) { if (icicle != null) { mStats = sStatsXfer; mBatteryBroadcast = sBatteryBroadcastXfer; } mBatteryInfo = IBatteryStats.Stub.asInterface( ServiceManager.getService(BatteryStats.SERVICE_NAME)); Loading @@ -137,6 +157,7 @@ public class BatteryStatsHelper { public void storeState() { sStatsXfer = mStats; sBatteryBroadcastXfer = mBatteryBroadcast; } public static String makemAh(double power) { Loading Loading @@ -190,6 +211,8 @@ public class BatteryStatsHelper { mBatteryRealtime = mStats.getBatteryRealtime(rawRealtimeUs); mTypeBatteryUptime = mStats.computeBatteryUptime(rawUptimeUs, mStatsType); mTypeBatteryRealtime = mStats.computeBatteryRealtime(rawRealtimeUs, mStatsType); mBatteryTimeRemaining = mStats.computeBatteryTimeRemaining(rawRealtimeUs); mChargeTimeRemaining = mStats.computeChargeTimeRemaining(rawRealtimeUs); if (DEBUG) { Log.d(TAG, "Raw time: realtime=" + (rawRealtimeUs/1000) + " uptime=" Loading Loading @@ -787,6 +810,10 @@ public class BatteryStatsHelper { return mMaxDrainedPower; } public long getBatteryTimeRemaining() { return mBatteryTimeRemaining; } public long getChargeTimeRemaining() { return mChargeTimeRemaining; } private void load() { if (mBatteryInfo == null) { return; Loading @@ -803,5 +830,9 @@ public class BatteryStatsHelper { } catch (RemoteException e) { Log.e(TAG, "RemoteException:", e); } if (mCollectBatteryBroadcast) { mBatteryBroadcast = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); } } }
core/java/com/android/internal/os/BatteryStatsImpl.java +94 −38 File changed.Preview size limit exceeded, changes collapsed. Show changes