diff options
| author | 2021-03-19 13:15:54 -0700 | |
|---|---|---|
| committer | 2021-03-19 20:28:38 +0000 | |
| commit | 9601383b2590186ba6740b56c1fc87f3d23c7ebc (patch) | |
| tree | 1e8daa52840bfbe87de7105c174b4d870901163d | |
| parent | 1bdbcffaa16dc5e5e1ca2992ca339957ee7a937e (diff) | |
Fix error in MeasuredEnergySnapshot voltage
The voltage algorithm didn't seem quite right; e.g.
if avgVoltageMV == 1, this would give the wrong value.
We presumably should round off, not up. Indeed, the tests
in MeasuredEnergySnapshotTest already do so.
Bug: 173765509
Test: atest BatteryStatsTests
Change-Id: Iefc5011d2df01b2f24dd13145d39fdc4de34753f
| -rw-r--r-- | services/core/java/com/android/server/am/MeasuredEnergySnapshot.java | 8 | 
1 files changed, 4 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/am/MeasuredEnergySnapshot.java b/services/core/java/com/android/server/am/MeasuredEnergySnapshot.java index 4c9ab63a100b..d789bbb04d7a 100644 --- a/services/core/java/com/android/server/am/MeasuredEnergySnapshot.java +++ b/services/core/java/com/android/server/am/MeasuredEnergySnapshot.java @@ -241,7 +241,7 @@ public class MeasuredEnergySnapshot {      /**       * For a consumer of type {@link EnergyConsumerType#OTHER}, updates       * {@link #mAttributionSnapshots} with freshly measured energies (per uid) and returns the -     * charge consumed (in microcouloumbs) between the previously stored values and the passed-in +     * charge consumed (in microcoulombs) between the previously stored values and the passed-in       * values.       *       * @param consumerInfo a consumer of type {@link EnergyConsumerType#OTHER}. @@ -341,11 +341,11 @@ public class MeasuredEnergySnapshot {          return numOrdinals;      } -    /** Calculate charge consumption (in microcouloumbs) from a given energy and voltage */ +    /** Calculate charge consumption (in microcoulombs) from a given energy and voltage */      private long calculateChargeConsumedUC(long deltaEnergyUJ, int avgVoltageMV) {          // To overflow, a 3.7V 10000mAh battery would need to completely drain 69244 times -        // since the last snapshot. Round up to the nearest whole long. -        return (deltaEnergyUJ * MILLIVOLTS_PER_VOLT + (avgVoltageMV + 1) / 2) / avgVoltageMV; +        // since the last snapshot. Round off to the nearest whole long. +        return (deltaEnergyUJ * MILLIVOLTS_PER_VOLT + (avgVoltageMV / 2)) / avgVoltageMV;      }  }  |