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

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

Prevent DivideByZero error in BatteryStatsImpl

It was assumed that when a UID had either rx or tx bytes/packets that it would
have the other as well.

Bug:25706750
Change-Id: Iefac59a6bd02876aed9a0bac218d187b81807a95
parent 180dd72a
Loading
Loading
Loading
Loading
+29 −20
Original line number Diff line number Diff line
@@ -7699,26 +7699,35 @@ public final class BatteryStatsImpl extends BatteryStats {
                }

                final Uid u = getUidStatsLocked(mapUid(entry.uid));
                if (entry.rxBytes != 0) {
                    u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes,
                            entry.rxPackets);
                u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes,
                        entry.txPackets);
                    mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked(
                            entry.rxBytes);
                    mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked(
                            entry.rxPackets);

                    rxPackets.put(u.getUid(), entry.rxPackets);
                txPackets.put(u.getUid(), entry.txPackets);

                // Sum the total number of packets so that the Rx Power and Tx Power can
                    // Sum the total number of packets so that the Rx Power can
                    // be evenly distributed amongst the apps.
                    totalRxPackets += entry.rxPackets;
                totalTxPackets += entry.txPackets;
                }

                mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked(
                        entry.rxBytes);
                if (entry.txBytes != 0) {
                    u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes,
                            entry.txPackets);
                    mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked(
                            entry.txBytes);
                mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked(
                        entry.rxPackets);
                    mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked(
                            entry.txPackets);

                    txPackets.put(u.getUid(), entry.txPackets);

                    // Sum the total number of packets so that the Tx Power can
                    // be evenly distributed amongst the apps.
                    totalTxPackets += entry.txPackets;
                }
            }
        }