AI 144333: Change the way the battery level tracking code works in BatteryStats. Before we simply kept track of the last
2 levels as recorded at plug and unplug events. During charge cycles this would be useful because it would tell us
what the start and end levels were in the last discharge cycle. However during a discharge cycle this information could
be misleading as it would give you the level at the last unplug event (beginning the the discharge cycle) and last plug
event (end of the previous discharge cycle).
Now we are still keeping track of 2 values, but they are "discharge cycle start level" and "discharge cycle current level".
During a discharge cycle this will give you the level the current discharge cycle started at, and the current level. During
a charge cycle the same data will be supplied as before (the start/end of the last discharge cycle).
B=144249
Automated import of CL 144333
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 8085080..f492ad1 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -131,8 +131,8 @@
/*
* 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
@@ -1947,8 +1947,8 @@
mRealtimeStart = mTrackBatteryRealtimeStart = SystemClock.elapsedRealtime() * 1000;
mUnpluggedBatteryUptime = getBatteryUptimeLocked(mUptimeStart);
mUnpluggedBatteryRealtime = getBatteryRealtimeLocked(mRealtimeStart);
- mUnpluggedStartLevel = 0;
- mPluggedStartLevel = 0;
+ mDischargeStartLevel = 0;
+ mDischargeCurrentLevel = 0;
}
public BatteryStatsImpl(Parcel p) {
@@ -1978,12 +1978,12 @@
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) {
@@ -1994,6 +1994,10 @@
}
}
}
+
+ public void recordCurrentLevel(int level) {
+ mDischargeCurrentLevel = level;
+ }
public long getAwakeTimeBattery() {
return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT);
@@ -2086,25 +2090,25 @@
}
@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;
}
/**
@@ -2266,8 +2270,8 @@
mLastUptime = in.readLong();
mRealtime = in.readLong();
mLastRealtime = in.readLong();
- mUnpluggedStartLevel = in.readInt();
- mPluggedStartLevel = in.readInt();
+ mDischargeStartLevel = in.readInt();
+ mDischargeCurrentLevel = in.readInt();
mStartCount++;
@@ -2396,8 +2400,8 @@
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);
@@ -2577,8 +2581,8 @@
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();
@@ -2640,8 +2644,8 @@
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();