Fix division by zero in maybeAdjustDesiredStockLevelLocked().

If getBatteryScreenOffDischargeMah() returns zero that will lead to
a division by zero when computing estimatedLifeHours that will
bring down the entire system server. Guard against this by returning
from the function early if it returns zero.

Change-Id: I4905d7184e5185a07e4185fa0e263559d85cff49
This commit is contained in:
Peter Collingbourne
2022-11-02 20:02:29 -07:00
parent 5fe69e14ca
commit 9bb7cb8af1

View File

@@ -701,6 +701,10 @@ public class InternalResourceService extends SystemService {
return;
}
final long totalDischargeMah = mAnalyst.getBatteryScreenOffDischargeMah();
if (totalDischargeMah == 0) {
Slog.i(TAG, "Total discharge was 0");
return;
}
final long batteryCapacityMah = mBatteryManagerInternal.getBatteryFullCharge() / 1000;
final long estimatedLifeHours = batteryCapacityMah * totalScreenOffDurationMs
/ totalDischargeMah / HOUR_IN_MILLIS;