From 162b047e746e31a74a1944aed9ab52f9f807fb3e Mon Sep 17 00:00:00 2001 From: Tyler Wear Date: Thu, 26 Aug 2021 10:06:28 -0700 Subject: [PATCH] NetworkStats: Avoid Division By 0 RawBytes should always be at least 1 to avoid division by 0 and ArithmeticException resulting in Settings crash. Bug: 197292638 Change-Id: I4e5ac9da7adf707d7f991483555ab5c6d0cc3245 --- .../java/com/android/server/net/NetworkStatsCollection.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/net/NetworkStatsCollection.java b/services/core/java/com/android/server/net/NetworkStatsCollection.java index 6aefe41891..a090c1aab6 100644 --- a/services/core/java/com/android/server/net/NetworkStatsCollection.java +++ b/services/core/java/com/android/server/net/NetworkStatsCollection.java @@ -285,7 +285,8 @@ public class NetworkStatsCollection implements FileRotator.Reader, FileRotator.W combined.getValues(augmentStart, augmentEnd, entry); } - final long rawBytes = entry.rxBytes + entry.txBytes; + final long rawBytes = (entry.rxBytes + entry.txBytes) == 0 ? 1 : + (entry.rxBytes + entry.txBytes); final long rawRxBytes = entry.rxBytes == 0 ? 1 : entry.rxBytes; final long rawTxBytes = entry.txBytes == 0 ? 1 : entry.txBytes; final long targetBytes = augmentPlan.getDataUsageBytes();