Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9bb7cb8a authored by Peter Collingbourne's avatar Peter Collingbourne
Browse files

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
parent 5fe69e14
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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;