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

Commit a426817a authored by Adam Lesinski's avatar Adam Lesinski
Browse files

BatteryStats: Fix DivideByZero error

As we hand out proportional blame to apps for transmitting/receiving
packets, make sure to check that the total packets sent never
becomes zero.
Bug:26873610

Change-Id: I3e0fc3c9e8d4dafce2e88c75d8f44701d8fba0d4
parent a74cce60
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -8160,7 +8160,7 @@ public final class BatteryStatsImpl extends BatteryStats {
            final int size = delta.size();
            for (int i = 0; i < size; i++) {
                final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry);
                if (entry.rxPackets == 0 || entry.txPackets == 0) {
                if (entry.rxPackets == 0 && entry.txPackets == 0) {
                    continue;
                }

@@ -8211,13 +8211,13 @@ public final class BatteryStatsImpl extends BatteryStats {
                    if (activityInfo != null) {
                        ControllerActivityCounterImpl activityCounter =
                                u.getOrCreateModemControllerActivityLocked();
                        if (entry.rxPackets != 0) {
                        if (totalRxPackets > 0 && entry.rxPackets > 0) {
                            final long rxMs = (entry.rxPackets * activityInfo.getRxTimeMillis())
                                    / totalRxPackets;
                            activityCounter.getRxTimeCounter().addCountLocked(rxMs);
                        }

                        if (entry.txPackets != 0) {
                        if (totalTxPackets > 0 && entry.txPackets > 0) {
                            for (int lvl = 0; lvl < ModemActivityInfo.TX_POWER_LEVELS; lvl++) {
                                long txMs = entry.txPackets * activityInfo.getTxTimeMillis()[lvl];
                                txMs /= totalTxPackets;