diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-12-05 23:48:47 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-12-05 23:48:47 +0000 |
commit | acd8df826e2651a1ce5f221119e1552367f4d994 (patch) | |
tree | 2ab508f15083fa8ad539b0cfebc72a5ae99f28b9 | |
parent | 8c820b3f6b9a43785ef8c5cba8acb968d4874f77 (diff) | |
parent | 4bfbb2e886fb24b8201e26c52e3642362a089f27 (diff) | |
download | base-oreo-mr1-dev.tar.gz |
Merge "Return non-negetive value in getMobileStats method" into oreo-mr1-devoreo-mr1-dev
-rw-r--r-- | core/java/android/net/TrafficStats.java | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/core/java/android/net/TrafficStats.java b/core/java/android/net/TrafficStats.java index c339856f4388..fd822a76e8a4 100644 --- a/core/java/android/net/TrafficStats.java +++ b/core/java/android/net/TrafficStats.java @@ -395,6 +395,10 @@ public class TrafficStats { } } + private static long addIfSupported(long stat) { + return (stat == UNSUPPORTED) ? 0 : stat; + } + /** * Return number of packets transmitted across mobile networks since device * boot. Counts packets across all mobile network interfaces, and always @@ -407,7 +411,7 @@ public class TrafficStats { public static long getMobileTxPackets() { long total = 0; for (String iface : getMobileIfaces()) { - total += getTxPackets(iface); + total += addIfSupported(getTxPackets(iface)); } return total; } @@ -424,7 +428,7 @@ public class TrafficStats { public static long getMobileRxPackets() { long total = 0; for (String iface : getMobileIfaces()) { - total += getRxPackets(iface); + total += addIfSupported(getRxPackets(iface)); } return total; } @@ -441,7 +445,7 @@ public class TrafficStats { public static long getMobileTxBytes() { long total = 0; for (String iface : getMobileIfaces()) { - total += getTxBytes(iface); + total += addIfSupported(getTxBytes(iface)); } return total; } @@ -458,7 +462,7 @@ public class TrafficStats { public static long getMobileRxBytes() { long total = 0; for (String iface : getMobileIfaces()) { - total += getRxBytes(iface); + total += addIfSupported(getRxBytes(iface)); } return total; } @@ -468,9 +472,7 @@ public class TrafficStats { long total = 0; for (String iface : getMobileIfaces()) { final long stat = nativeGetIfaceStat(iface, TYPE_TCP_RX_PACKETS); - if (stat != UNSUPPORTED) { - total += stat; - } + total += addIfSupported(stat); } return total; } @@ -480,9 +482,7 @@ public class TrafficStats { long total = 0; for (String iface : getMobileIfaces()) { final long stat = nativeGetIfaceStat(iface, TYPE_TCP_TX_PACKETS); - if (stat != UNSUPPORTED) { - total += stat; - } + total += addIfSupported(stat); } return total; } |