Fix divide-by-zero in mobile radio remaining power calculation

Fixes: 262258554
Test: atest
CtsDumpsysHostTestCases:android.dumpsys.cts.BatteryStatsDumpsysTest#testBatterystatsOutput
(on a non ODPM enabled device)

Change-Id: Iae006a2fd74f456c0ec4ca6e9c33d4f80fd48f9c
This commit is contained in:
Michael Wachenschwanz
2023-02-02 16:37:09 -08:00
parent e4241197f5
commit 3619c4bc23

View File

@@ -264,8 +264,10 @@ public class MobileRadioPowerCalculator extends PowerCalculator {
if (total.remainingPowerMah < 0) total.remainingPowerMah = 0;
} else {
// Smear unattributed active time and add it to the remaining power consumption.
total.remainingPowerMah +=
(totalActivePowerMah * total.remainingDurationMs) / totalActiveDurationMs;
if (totalActiveDurationMs != 0) {
total.remainingPowerMah +=
(totalActivePowerMah * total.remainingDurationMs) / totalActiveDurationMs;
}
// Calculate the inactive modem power consumption.
final BatteryStats.ControllerActivityCounter modemActivity =