summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2018-02-02 04:22:34 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2018-02-02 04:22:34 +0000
commitbb1d07e681d8f5a438d2aec43b8bd760d5bde9c8 (patch)
treee9005c78b3fab079f6d8ee713261d24bfcdafcaf
parent871202da2f7e09e5de395d8aac8b229d47b99b8f (diff)
parent20328e8df09733a622370707a0b4e0479bc99607 (diff)
Merge "Return non-negetive value in getMobileStats method"
-rw-r--r--core/java/android/net/TrafficStats.java20
1 files changed, 10 insertions, 10 deletions
diff --git a/core/java/android/net/TrafficStats.java b/core/java/android/net/TrafficStats.java
index 196a3bc9c8d7..fa4624ef5635 100644
--- a/core/java/android/net/TrafficStats.java
+++ b/core/java/android/net/TrafficStats.java
@@ -433,6 +433,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
@@ -445,7 +449,7 @@ public class TrafficStats {
public static long getMobileTxPackets() {
long total = 0;
for (String iface : getMobileIfaces()) {
- total += getTxPackets(iface);
+ total += addIfSupported(getTxPackets(iface));
}
return total;
}
@@ -462,7 +466,7 @@ public class TrafficStats {
public static long getMobileRxPackets() {
long total = 0;
for (String iface : getMobileIfaces()) {
- total += getRxPackets(iface);
+ total += addIfSupported(getRxPackets(iface));
}
return total;
}
@@ -479,7 +483,7 @@ public class TrafficStats {
public static long getMobileTxBytes() {
long total = 0;
for (String iface : getMobileIfaces()) {
- total += getTxBytes(iface);
+ total += addIfSupported(getTxBytes(iface));
}
return total;
}
@@ -496,7 +500,7 @@ public class TrafficStats {
public static long getMobileRxBytes() {
long total = 0;
for (String iface : getMobileIfaces()) {
- total += getRxBytes(iface);
+ total += addIfSupported(getRxBytes(iface));
}
return total;
}
@@ -511,9 +515,7 @@ public class TrafficStats {
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
- if (stat != UNSUPPORTED) {
- total += stat;
- }
+ total += addIfSupported(stat);
}
return total;
}
@@ -528,9 +530,7 @@ public class TrafficStats {
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
- if (stat != UNSUPPORTED) {
- total += stat;
- }
+ total += addIfSupported(stat);
}
return total;
}