BatteryStats: Fix units on battery charge counter
The unit for the battery charge counter is in micro-Ampere-hours, not coulombs.
We store the value as uAh but display it in dumpsys as mAh.
Bug:27174034
Change-Id: Ib5cc1ee1c5c191336a3e1f18dbb12c38e833f8d0
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index 959b309..a4bd8eb 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -1158,7 +1158,8 @@
public short batteryTemperature;
public char batteryVoltage;
- public int batteryChargeCoulombs;
+ // The charge of the battery in micro-Ampere-hours.
+ public int batteryChargeUAh;
// Constants from SCREEN_BRIGHTNESS_*
public static final int STATE_BRIGHTNESS_SHIFT = 0;
@@ -1356,7 +1357,7 @@
bat = (((int)batteryTemperature)&0xffff)
| ((((int)batteryVoltage)<<16)&0xffff0000);
dest.writeInt(bat);
- dest.writeInt(batteryChargeCoulombs);
+ dest.writeInt(batteryChargeUAh);
dest.writeInt(states);
dest.writeInt(states2);
if (wakelockTag != null) {
@@ -1385,7 +1386,7 @@
int bat2 = src.readInt();
batteryTemperature = (short)(bat2&0xffff);
batteryVoltage = (char)((bat2>>16)&0xffff);
- batteryChargeCoulombs = src.readInt();
+ batteryChargeUAh = src.readInt();
states = src.readInt();
states2 = src.readInt();
if ((bat&0x10000000) != 0) {
@@ -1425,7 +1426,7 @@
batteryPlugType = 0;
batteryTemperature = 0;
batteryVoltage = 0;
- batteryChargeCoulombs = 0;
+ batteryChargeUAh = 0;
states = 0;
states2 = 0;
wakelockTag = null;
@@ -1453,7 +1454,7 @@
batteryPlugType = o.batteryPlugType;
batteryTemperature = o.batteryTemperature;
batteryVoltage = o.batteryVoltage;
- batteryChargeCoulombs = o.batteryChargeCoulombs;
+ batteryChargeUAh = o.batteryChargeUAh;
states = o.states;
states2 = o.states2;
if (o.wakelockTag != null) {
@@ -1485,7 +1486,7 @@
&& batteryPlugType == o.batteryPlugType
&& batteryTemperature == o.batteryTemperature
&& batteryVoltage == o.batteryVoltage
- && batteryChargeCoulombs == o.batteryChargeCoulombs
+ && batteryChargeUAh == o.batteryChargeUAh
&& states == o.states
&& states2 == o.states2
&& currentTime == o.currentTime;
@@ -4536,7 +4537,7 @@
int oldPlug = -1;
int oldTemp = -1;
int oldVolt = -1;
- int oldCharge = -1;
+ int oldChargeMAh = -1;
long lastTime = -1;
void reset() {
@@ -4547,7 +4548,7 @@
oldPlug = -1;
oldTemp = -1;
oldVolt = -1;
- oldCharge = -1;
+ oldChargeMAh = -1;
}
public void printNextItem(PrintWriter pw, HistoryItem rec, long baseTime, boolean checkin,
@@ -4709,10 +4710,11 @@
pw.print(checkin ? ",Bv=" : " volt=");
pw.print(oldVolt);
}
- if (oldCharge != rec.batteryChargeCoulombs) {
- oldCharge = rec.batteryChargeCoulombs;
+ final int chargeMAh = rec.batteryChargeUAh / 1000;
+ if (oldChargeMAh != chargeMAh) {
+ oldChargeMAh = chargeMAh;
pw.print(checkin ? ",Bcc=" : " charge=");
- pw.print(oldCharge);
+ pw.print(oldChargeMAh);
}
printBitDescriptions(pw, oldState, rec.states, rec.wakelockTag,
HISTORY_STATE_DESCRIPTIONS, !checkin);
diff --git a/core/java/com/android/internal/app/IBatteryStats.aidl b/core/java/com/android/internal/app/IBatteryStats.aidl
index 42b89d5..44e072d 100644
--- a/core/java/com/android/internal/app/IBatteryStats.aidl
+++ b/core/java/com/android/internal/app/IBatteryStats.aidl
@@ -123,7 +123,7 @@
void noteNetworkStatsEnabled();
void noteDeviceIdleMode(int mode, String activeReason, int activeUid);
void setBatteryState(int status, int health, int plugType, int level, int temp, int volt,
- int chargeCount);
+ int chargeUAh);
long getAwakeTimeBattery();
long getAwakeTimePlugged();
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 654a4f1..9fdc9c4 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -2185,8 +2185,8 @@
static final int DELTA_WAKELOCK_FLAG = 0x00400000;
// Flag in delta int: contains an event description.
static final int DELTA_EVENT_FLAG = 0x00800000;
- // Flag in delta int: contains a coulomb charge count.
- static final int DELTA_BATTERY_CHARGE_COULOMBS_FLAG = 0x01000000;
+ // Flag in delta int: contains the battery charge count in uAh.
+ static final int DELTA_BATTERY_CHARGE_FLAG = 0x01000000;
// These upper bits are the frequently changing state bits.
static final int DELTA_STATE_MASK = 0xfe000000;
@@ -2250,10 +2250,9 @@
firstToken |= DELTA_EVENT_FLAG;
}
- final boolean batteryChargeCoulombsChanged = cur.batteryChargeCoulombs
- != last.batteryChargeCoulombs;
- if (batteryChargeCoulombsChanged) {
- firstToken |= DELTA_BATTERY_CHARGE_COULOMBS_FLAG;
+ final boolean batteryChargeChanged = cur.batteryChargeUAh != last.batteryChargeUAh;
+ if (batteryChargeChanged) {
+ firstToken |= DELTA_BATTERY_CHARGE_FLAG;
}
dest.writeInt(firstToken);
if (DEBUG) Slog.i(TAG, "WRITE DELTA: firstToken=0x" + Integer.toHexString(firstToken)
@@ -2338,10 +2337,9 @@
}
mLastHistoryStepLevel = cur.batteryLevel;
- if (batteryChargeCoulombsChanged) {
- if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryChargeCoulombs="
- + cur.batteryChargeCoulombs);
- dest.writeInt(cur.batteryChargeCoulombs);
+ if (batteryChargeChanged) {
+ if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryChargeUAh=" + cur.batteryChargeUAh);
+ dest.writeInt(cur.batteryChargeUAh);
}
}
@@ -2590,8 +2588,8 @@
cur.stepDetails = null;
}
- if ((firstToken&DELTA_BATTERY_CHARGE_COULOMBS_FLAG) != 0) {
- cur.batteryChargeCoulombs = src.readInt();
+ if ((firstToken&DELTA_BATTERY_CHARGE_FLAG) != 0) {
+ cur.batteryChargeUAh = src.readInt();
}
}
@@ -9310,7 +9308,7 @@
public static final int BATTERY_PLUGGED_NONE = 0;
public void setBatteryStateLocked(int status, int health, int plugType, int level,
- int temp, int volt, int chargeCount) {
+ int temp, int volt, int chargeUAh) {
final boolean onBattery = plugType == BATTERY_PLUGGED_NONE;
final long uptime = mClocks.uptimeMillis();
final long elapsedRealtime = mClocks.elapsedRealtime();
@@ -9362,7 +9360,7 @@
mHistoryCur.batteryPlugType = (byte)plugType;
mHistoryCur.batteryTemperature = (short)temp;
mHistoryCur.batteryVoltage = (char)volt;
- mHistoryCur.batteryChargeCoulombs = chargeCount;
+ mHistoryCur.batteryChargeUAh = chargeUAh;
setOnBatteryLocked(elapsedRealtime, uptime, onBattery, oldStatus, level);
} else {
boolean changed = false;
@@ -9396,9 +9394,9 @@
mHistoryCur.batteryVoltage = (char)volt;
changed = true;
}
- if (chargeCount >= (mHistoryCur.batteryChargeCoulombs+10)
- || chargeCount <= (mHistoryCur.batteryChargeCoulombs-10)) {
- mHistoryCur.batteryChargeCoulombs = chargeCount;
+ if (chargeUAh >= (mHistoryCur.batteryChargeUAh+10)
+ || chargeUAh <= (mHistoryCur.batteryChargeUAh-10)) {
+ mHistoryCur.batteryChargeUAh = chargeUAh;
changed = true;
}
long modeBits = (((long)mInitStepMode) << STEP_LEVEL_INITIAL_MODE_SHIFT)