From dc379a48d1e7b456649d04daa66bbf00a3f32e2c Mon Sep 17 00:00:00 2001 From: Dmitry Muhomor Date: Mon, 6 Jan 2025 22:35:48 +0200 Subject: [PATCH] add workaround for updateWifiBatteryStats() system_server crash --- .../android/server/power/stats/BatteryStatsImpl.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/power/stats/BatteryStatsImpl.java b/services/core/java/com/android/server/power/stats/BatteryStatsImpl.java index cb8e1a0f35b82..9a9464f5736cd 100644 --- a/services/core/java/com/android/server/power/stats/BatteryStatsImpl.java +++ b/services/core/java/com/android/server/power/stats/BatteryStatsImpl.java @@ -12660,11 +12660,13 @@ private void updateWifiBatteryStats(WifiActivityEnergyInfo info, // Distribute the remaining Tx power appropriately between all apps that transmitted // packets. - for (int i = 0; i < txPackets.size(); i++) { - final int uid = txPackets.keyAt(i); - final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) - / totalTxPackets; - txTimesMs.incrementValue(uid, myTxTimeMs); + if (totalTxPackets > 0) { // see https://github.com/GrapheneOS/os-issue-tracker/issues/4627 + for (int i = 0; i < txPackets.size(); i++) { + final int uid = txPackets.keyAt(i); + final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) + / totalTxPackets; + txTimesMs.incrementValue(uid, myTxTimeMs); + } } // Distribute the remaining Rx power appropriately between all apps that received