Loading core/java/android/os/BatteryStats.java +13 −10 Original line number Diff line number Diff line Loading @@ -472,15 +472,16 @@ public abstract class BatteryStats implements Parcelable { public abstract long getBatteryRealtime(long curTime); /** * Returns the battery percentage level at the last time the device was unplugged from power, * or the last time it was booted while unplugged. * Returns the battery percentage level at the last time the device was unplugged from power, or * the last time it booted on battery power. */ public abstract int getUnpluggedStartLevel(); public abstract int getDischargeStartLevel(); /** * Returns the battery percentage level at the last time the device was plugged into power. * Returns the current battery percentage level if we are in a discharge cycle, otherwise * returns the level at the last plug event. */ public abstract int getPluggedStartLevel(); public abstract int getDischargeCurrentLevel(); /** * Returns the total, last, or current battery uptime in microseconds. Loading Loading @@ -774,8 +775,8 @@ public abstract class BatteryStats implements Parcelable { dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); if (which == STATS_UNPLUGGED) { dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, getUnpluggedStartLevel(), getPluggedStartLevel()); dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, getDischargeStartLevel(), getDischargeCurrentLevel()); } for (int iu = 0; iu < NU; iu++) { Loading Loading @@ -1059,13 +1060,15 @@ public abstract class BatteryStats implements Parcelable { if (getIsOnBattery()) { pw.println(prefix + " Device is currently unplugged"); pw.println(prefix + " Discharge cycle start level: " + getUnpluggedStartLevel()); getDischargeStartLevel()); pw.println(prefix + " Discharge cycle current level: " + getDischargeCurrentLevel()); } else { pw.println(prefix + " Device is currently plugged into power"); pw.println(prefix + " Last discharge cycle start level: " + getUnpluggedStartLevel()); getDischargeStartLevel()); pw.println(prefix + " Last discharge cycle end level: " + getPluggedStartLevel()); getDischargeCurrentLevel()); } pw.println(" "); } Loading core/java/com/android/internal/app/IBatteryStats.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ interface IBatteryStats { void noteScanWifiLockAcquired(int uid); void noteScanWifiLockReleased(int uid); void setOnBattery(boolean onBattery, int level); void recordCurrentLevel(int level); long getAwakeTimeBattery(); long getAwakeTimePlugged(); } core/java/com/android/internal/os/BatteryStatsImpl.java +26 −22 Original line number Diff line number Diff line Loading @@ -131,8 +131,8 @@ public final class BatteryStatsImpl extends BatteryStats { /* * These keep track of battery levels (1-100) at the last plug event and the last unplug event. */ int mUnpluggedStartLevel; int mPluggedStartLevel; int mDischargeStartLevel; int mDischargeCurrentLevel; long mLastWriteTime = 0; // Milliseconds Loading Loading @@ -1947,8 +1947,8 @@ public final class BatteryStatsImpl extends BatteryStats { mRealtimeStart = mTrackBatteryRealtimeStart = SystemClock.elapsedRealtime() * 1000; mUnpluggedBatteryUptime = getBatteryUptimeLocked(mUptimeStart); mUnpluggedBatteryRealtime = getBatteryRealtimeLocked(mRealtimeStart); mUnpluggedStartLevel = 0; mPluggedStartLevel = 0; mDischargeStartLevel = 0; mDischargeCurrentLevel = 0; } public BatteryStatsImpl(Parcel p) { Loading Loading @@ -1978,12 +1978,12 @@ public final class BatteryStatsImpl extends BatteryStats { mTrackBatteryRealtimeStart = realtime; mUnpluggedBatteryUptime = getBatteryUptimeLocked(uptime); mUnpluggedBatteryRealtime = getBatteryRealtimeLocked(realtime); mUnpluggedStartLevel = level; mDischargeCurrentLevel = mDischargeStartLevel = level; doUnplug(mUnpluggedBatteryUptime, mUnpluggedBatteryRealtime); } else { mTrackBatteryPastUptime += uptime - mTrackBatteryUptimeStart; mTrackBatteryPastRealtime += realtime - mTrackBatteryRealtimeStart; mPluggedStartLevel = level; mDischargeCurrentLevel = level; doPlug(getBatteryUptimeLocked(uptime), getBatteryRealtimeLocked(realtime)); } if ((mLastWriteTime + (60 * 1000)) < mSecRealtime) { Loading @@ -1995,6 +1995,10 @@ public final class BatteryStatsImpl extends BatteryStats { } } public void recordCurrentLevel(int level) { mDischargeCurrentLevel = level; } public long getAwakeTimeBattery() { return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); } Loading Loading @@ -2086,25 +2090,25 @@ public final class BatteryStatsImpl extends BatteryStats { } @Override public int getUnpluggedStartLevel() { public int getDischargeStartLevel() { synchronized(this) { return getUnluggedStartLevelLocked(); return getDischargeStartLevelLocked(); } } public int getUnluggedStartLevelLocked() { return mUnpluggedStartLevel; public int getDischargeStartLevelLocked() { return mDischargeStartLevel; } @Override public int getPluggedStartLevel() { public int getDischargeCurrentLevel() { synchronized(this) { return getPluggedStartLevelLocked(); return getDischargeCurrentLevelLocked(); } } public int getPluggedStartLevelLocked() { return mPluggedStartLevel; public int getDischargeCurrentLevelLocked() { return mDischargeCurrentLevel; } /** Loading Loading @@ -2266,8 +2270,8 @@ public final class BatteryStatsImpl extends BatteryStats { mLastUptime = in.readLong(); mRealtime = in.readLong(); mLastRealtime = in.readLong(); mUnpluggedStartLevel = in.readInt(); mPluggedStartLevel = in.readInt(); mDischargeStartLevel = in.readInt(); mDischargeCurrentLevel = in.readInt(); mStartCount++; Loading Loading @@ -2396,8 +2400,8 @@ public final class BatteryStatsImpl extends BatteryStats { out.writeLong(computeUptime(NOW_SYS, STATS_CURRENT)); out.writeLong(computeRealtime(NOWREAL_SYS, STATS_TOTAL)); out.writeLong(computeRealtime(NOWREAL_SYS, STATS_CURRENT)); out.writeInt(mUnpluggedStartLevel); out.writeInt(mPluggedStartLevel); out.writeInt(mDischargeStartLevel); out.writeInt(mDischargeCurrentLevel); mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); Loading Loading @@ -2577,8 +2581,8 @@ public final class BatteryStatsImpl extends BatteryStats { mTrackBatteryRealtimeStart = in.readLong(); mUnpluggedBatteryUptime = in.readLong(); mUnpluggedBatteryRealtime = in.readLong(); mUnpluggedStartLevel = in.readInt(); mPluggedStartLevel = in.readInt(); mDischargeStartLevel = in.readInt(); mDischargeCurrentLevel = in.readInt(); mLastWriteTime = in.readLong(); mPartialTimers.clear(); Loading Loading @@ -2640,8 +2644,8 @@ public final class BatteryStatsImpl extends BatteryStats { out.writeLong(mTrackBatteryRealtimeStart); out.writeLong(mUnpluggedBatteryUptime); out.writeLong(mUnpluggedBatteryRealtime); out.writeInt(mUnpluggedStartLevel); out.writeInt(mPluggedStartLevel); out.writeInt(mDischargeStartLevel); out.writeInt(mDischargeCurrentLevel); out.writeLong(mLastWriteTime); int size = mUidStats.size(); Loading services/java/com/android/server/BatteryService.java +10 −0 Original line number Diff line number Diff line Loading @@ -229,6 +229,16 @@ class BatteryService extends Binder { EventLog.writeEvent(LOG_BATTERY_LEVEL, mBatteryLevel, mBatteryVoltage, mBatteryTemperature); } if (mBatteryLevel != mLastBatteryLevel && mPlugType == BATTERY_PLUGGED_NONE) { // If the battery level has changed and we are on battery, update the current level. // This is used for discharge cycle tracking so this shouldn't be updated while the // battery is charging. try { mBatteryStats.recordCurrentLevel(mBatteryLevel); } catch (RemoteException e) { // Should never happen. } } if (mBatteryLevelCritical && !mLastBatteryLevelCritical && mPlugType == BATTERY_PLUGGED_NONE) { // We want to make sure we log discharge cycle outliers Loading services/java/com/android/server/am/BatteryStatsService.java +5 −0 Original line number Diff line number Diff line Loading @@ -264,6 +264,11 @@ public final class BatteryStatsService extends IBatteryStats.Stub { mStats.setOnBattery(onBattery, level); } public void recordCurrentLevel(int level) { enforceCallingPermission(); mStats.recordCurrentLevel(level); } public long getAwakeTimeBattery() { mContext.enforceCallingOrSelfPermission( android.Manifest.permission.BATTERY_STATS, null); Loading Loading
core/java/android/os/BatteryStats.java +13 −10 Original line number Diff line number Diff line Loading @@ -472,15 +472,16 @@ public abstract class BatteryStats implements Parcelable { public abstract long getBatteryRealtime(long curTime); /** * Returns the battery percentage level at the last time the device was unplugged from power, * or the last time it was booted while unplugged. * Returns the battery percentage level at the last time the device was unplugged from power, or * the last time it booted on battery power. */ public abstract int getUnpluggedStartLevel(); public abstract int getDischargeStartLevel(); /** * Returns the battery percentage level at the last time the device was plugged into power. * Returns the current battery percentage level if we are in a discharge cycle, otherwise * returns the level at the last plug event. */ public abstract int getPluggedStartLevel(); public abstract int getDischargeCurrentLevel(); /** * Returns the total, last, or current battery uptime in microseconds. Loading Loading @@ -774,8 +775,8 @@ public abstract class BatteryStats implements Parcelable { dumpLine(pw, 0 /* uid */, category, DATA_CONNECTION_COUNT_DATA, args); if (which == STATS_UNPLUGGED) { dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, getUnpluggedStartLevel(), getPluggedStartLevel()); dumpLine(pw, 0 /* uid */, category, BATTERY_DATA, getDischargeStartLevel(), getDischargeCurrentLevel()); } for (int iu = 0; iu < NU; iu++) { Loading Loading @@ -1059,13 +1060,15 @@ public abstract class BatteryStats implements Parcelable { if (getIsOnBattery()) { pw.println(prefix + " Device is currently unplugged"); pw.println(prefix + " Discharge cycle start level: " + getUnpluggedStartLevel()); getDischargeStartLevel()); pw.println(prefix + " Discharge cycle current level: " + getDischargeCurrentLevel()); } else { pw.println(prefix + " Device is currently plugged into power"); pw.println(prefix + " Last discharge cycle start level: " + getUnpluggedStartLevel()); getDischargeStartLevel()); pw.println(prefix + " Last discharge cycle end level: " + getPluggedStartLevel()); getDischargeCurrentLevel()); } pw.println(" "); } Loading
core/java/com/android/internal/app/IBatteryStats.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ interface IBatteryStats { void noteScanWifiLockAcquired(int uid); void noteScanWifiLockReleased(int uid); void setOnBattery(boolean onBattery, int level); void recordCurrentLevel(int level); long getAwakeTimeBattery(); long getAwakeTimePlugged(); }
core/java/com/android/internal/os/BatteryStatsImpl.java +26 −22 Original line number Diff line number Diff line Loading @@ -131,8 +131,8 @@ public final class BatteryStatsImpl extends BatteryStats { /* * These keep track of battery levels (1-100) at the last plug event and the last unplug event. */ int mUnpluggedStartLevel; int mPluggedStartLevel; int mDischargeStartLevel; int mDischargeCurrentLevel; long mLastWriteTime = 0; // Milliseconds Loading Loading @@ -1947,8 +1947,8 @@ public final class BatteryStatsImpl extends BatteryStats { mRealtimeStart = mTrackBatteryRealtimeStart = SystemClock.elapsedRealtime() * 1000; mUnpluggedBatteryUptime = getBatteryUptimeLocked(mUptimeStart); mUnpluggedBatteryRealtime = getBatteryRealtimeLocked(mRealtimeStart); mUnpluggedStartLevel = 0; mPluggedStartLevel = 0; mDischargeStartLevel = 0; mDischargeCurrentLevel = 0; } public BatteryStatsImpl(Parcel p) { Loading Loading @@ -1978,12 +1978,12 @@ public final class BatteryStatsImpl extends BatteryStats { mTrackBatteryRealtimeStart = realtime; mUnpluggedBatteryUptime = getBatteryUptimeLocked(uptime); mUnpluggedBatteryRealtime = getBatteryRealtimeLocked(realtime); mUnpluggedStartLevel = level; mDischargeCurrentLevel = mDischargeStartLevel = level; doUnplug(mUnpluggedBatteryUptime, mUnpluggedBatteryRealtime); } else { mTrackBatteryPastUptime += uptime - mTrackBatteryUptimeStart; mTrackBatteryPastRealtime += realtime - mTrackBatteryRealtimeStart; mPluggedStartLevel = level; mDischargeCurrentLevel = level; doPlug(getBatteryUptimeLocked(uptime), getBatteryRealtimeLocked(realtime)); } if ((mLastWriteTime + (60 * 1000)) < mSecRealtime) { Loading @@ -1995,6 +1995,10 @@ public final class BatteryStatsImpl extends BatteryStats { } } public void recordCurrentLevel(int level) { mDischargeCurrentLevel = level; } public long getAwakeTimeBattery() { return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT); } Loading Loading @@ -2086,25 +2090,25 @@ public final class BatteryStatsImpl extends BatteryStats { } @Override public int getUnpluggedStartLevel() { public int getDischargeStartLevel() { synchronized(this) { return getUnluggedStartLevelLocked(); return getDischargeStartLevelLocked(); } } public int getUnluggedStartLevelLocked() { return mUnpluggedStartLevel; public int getDischargeStartLevelLocked() { return mDischargeStartLevel; } @Override public int getPluggedStartLevel() { public int getDischargeCurrentLevel() { synchronized(this) { return getPluggedStartLevelLocked(); return getDischargeCurrentLevelLocked(); } } public int getPluggedStartLevelLocked() { return mPluggedStartLevel; public int getDischargeCurrentLevelLocked() { return mDischargeCurrentLevel; } /** Loading Loading @@ -2266,8 +2270,8 @@ public final class BatteryStatsImpl extends BatteryStats { mLastUptime = in.readLong(); mRealtime = in.readLong(); mLastRealtime = in.readLong(); mUnpluggedStartLevel = in.readInt(); mPluggedStartLevel = in.readInt(); mDischargeStartLevel = in.readInt(); mDischargeCurrentLevel = in.readInt(); mStartCount++; Loading Loading @@ -2396,8 +2400,8 @@ public final class BatteryStatsImpl extends BatteryStats { out.writeLong(computeUptime(NOW_SYS, STATS_CURRENT)); out.writeLong(computeRealtime(NOWREAL_SYS, STATS_TOTAL)); out.writeLong(computeRealtime(NOWREAL_SYS, STATS_CURRENT)); out.writeInt(mUnpluggedStartLevel); out.writeInt(mPluggedStartLevel); out.writeInt(mDischargeStartLevel); out.writeInt(mDischargeCurrentLevel); mScreenOnTimer.writeSummaryFromParcelLocked(out, NOWREAL); Loading Loading @@ -2577,8 +2581,8 @@ public final class BatteryStatsImpl extends BatteryStats { mTrackBatteryRealtimeStart = in.readLong(); mUnpluggedBatteryUptime = in.readLong(); mUnpluggedBatteryRealtime = in.readLong(); mUnpluggedStartLevel = in.readInt(); mPluggedStartLevel = in.readInt(); mDischargeStartLevel = in.readInt(); mDischargeCurrentLevel = in.readInt(); mLastWriteTime = in.readLong(); mPartialTimers.clear(); Loading Loading @@ -2640,8 +2644,8 @@ public final class BatteryStatsImpl extends BatteryStats { out.writeLong(mTrackBatteryRealtimeStart); out.writeLong(mUnpluggedBatteryUptime); out.writeLong(mUnpluggedBatteryRealtime); out.writeInt(mUnpluggedStartLevel); out.writeInt(mPluggedStartLevel); out.writeInt(mDischargeStartLevel); out.writeInt(mDischargeCurrentLevel); out.writeLong(mLastWriteTime); int size = mUidStats.size(); Loading
services/java/com/android/server/BatteryService.java +10 −0 Original line number Diff line number Diff line Loading @@ -229,6 +229,16 @@ class BatteryService extends Binder { EventLog.writeEvent(LOG_BATTERY_LEVEL, mBatteryLevel, mBatteryVoltage, mBatteryTemperature); } if (mBatteryLevel != mLastBatteryLevel && mPlugType == BATTERY_PLUGGED_NONE) { // If the battery level has changed and we are on battery, update the current level. // This is used for discharge cycle tracking so this shouldn't be updated while the // battery is charging. try { mBatteryStats.recordCurrentLevel(mBatteryLevel); } catch (RemoteException e) { // Should never happen. } } if (mBatteryLevelCritical && !mLastBatteryLevelCritical && mPlugType == BATTERY_PLUGGED_NONE) { // We want to make sure we log discharge cycle outliers Loading
services/java/com/android/server/am/BatteryStatsService.java +5 −0 Original line number Diff line number Diff line Loading @@ -264,6 +264,11 @@ public final class BatteryStatsService extends IBatteryStats.Stub { mStats.setOnBattery(onBattery, level); } public void recordCurrentLevel(int level) { enforceCallingPermission(); mStats.recordCurrentLevel(level); } public long getAwakeTimeBattery() { mContext.enforceCallingOrSelfPermission( android.Manifest.permission.BATTERY_STATS, null); Loading