Implement issue #3326435: Battery stats improvements
Keep track of discharge while screen is on vs. off.
Checkin looks like:
5,0,u,dc,1,1,1,0
The last four numbers are, from left:
- Maximum battery drain over time period.
- Minimum battery drain over time period.
- Battery drain while screen was on.
- Battery drain while screen was off.
Change-Id: Ie4026a7cc8aabb2a6d47d03d2e278aa51c2d5ddf
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index 7dd5e31..6e6731e 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -132,6 +132,7 @@
private static final String NETWORK_DATA = "nt";
private static final String USER_ACTIVITY_DATA = "ua";
private static final String BATTERY_DATA = "bt";
+ private static final String BATTERY_DISCHARGE_DATA = "dc";
private static final String BATTERY_LEVEL_DATA = "lv";
private static final String WIFI_LOCK_DATA = "wfl";
private static final String MISC_DATA = "m";
@@ -804,6 +805,30 @@
public abstract int getHighDischargeAmountSinceCharge();
/**
+ * Get the amount the battery has discharged while the screen was on,
+ * since the last time power was unplugged.
+ */
+ public abstract int getDischargeAmountScreenOn();
+
+ /**
+ * Get the amount the battery has discharged while the screen was on,
+ * since the last time the device was charged.
+ */
+ public abstract int getDischargeAmountScreenOnSinceCharge();
+
+ /**
+ * Get the amount the battery has discharged while the screen was off,
+ * since the last time power was unplugged.
+ */
+ public abstract int getDischargeAmountScreenOff();
+
+ /**
+ * Get the amount the battery has discharged while the screen was off,
+ * since the last time the device was charged.
+ */
+ public abstract int getDischargeAmountScreenOffSinceCharge();
+
+ /**
* Returns the total, last, or current battery uptime in microseconds.
*
* @param curTime the elapsed realtime in microseconds.
@@ -1098,6 +1123,17 @@
getDischargeCurrentLevel());
}
+ if (which == STATS_SINCE_UNPLUGGED) {
+ dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
+ getDischargeStartLevel()-getDischargeCurrentLevel(),
+ getDischargeStartLevel()-getDischargeCurrentLevel(),
+ getDischargeAmountScreenOn(), getDischargeAmountScreenOff());
+ } else {
+ dumpLine(pw, 0 /* uid */, category, BATTERY_DISCHARGE_DATA,
+ getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(),
+ getDischargeAmountScreenOn(), getDischargeAmountScreenOff());
+ }
+
if (reqUid < 0) {
Map<String, ? extends BatteryStats.Timer> kernelWakelocks = getKernelWakelockStats();
if (kernelWakelocks.size() > 0) {
@@ -1454,6 +1490,10 @@
pw.print(prefix); pw.print(" Last discharge cycle end level: ");
pw.println(getDischargeCurrentLevel());
}
+ pw.print(prefix); pw.print(" Amount discharged while screen on: ");
+ pw.println(getDischargeAmountScreenOn());
+ pw.print(prefix); pw.print(" Amount discharged while screen off: ");
+ pw.println(getDischargeAmountScreenOff());
pw.println(" ");
} else {
pw.print(prefix); pw.println(" Device battery use since last full charge");
@@ -1461,6 +1501,10 @@
pw.println(getLowDischargeAmountSinceCharge());
pw.print(prefix); pw.print(" Amount discharged (upper bound): ");
pw.println(getHighDischargeAmountSinceCharge());
+ pw.print(prefix); pw.print(" Amount discharged while screen on: ");
+ pw.println(getDischargeAmountScreenOnSinceCharge());
+ pw.print(prefix); pw.print(" Amount discharged while screen off: ");
+ pw.println(getDischargeAmountScreenOffSinceCharge());
pw.println(" ");
}