Merge "Return non-negetive value in getMobileStats method" am: 9fb04e29e5 am: 515a54a93e

am: 4ae5e0c06c

Change-Id: I304f42d473289ad876f6ceae8d6866e4248686a9
This commit is contained in:
Chenbo Feng
2018-02-02 17:59:53 +00:00
committed by android-build-merger

View File

@@ -439,6 +439,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 * Return number of packets transmitted across mobile networks since device
* boot. Counts packets across all mobile network interfaces, and always * boot. Counts packets across all mobile network interfaces, and always
@@ -451,7 +455,7 @@ public class TrafficStats {
public static long getMobileTxPackets() { public static long getMobileTxPackets() {
long total = 0; long total = 0;
for (String iface : getMobileIfaces()) { for (String iface : getMobileIfaces()) {
total += getTxPackets(iface); total += addIfSupported(getTxPackets(iface));
} }
return total; return total;
} }
@@ -468,7 +472,7 @@ public class TrafficStats {
public static long getMobileRxPackets() { public static long getMobileRxPackets() {
long total = 0; long total = 0;
for (String iface : getMobileIfaces()) { for (String iface : getMobileIfaces()) {
total += getRxPackets(iface); total += addIfSupported(getRxPackets(iface));
} }
return total; return total;
} }
@@ -485,7 +489,7 @@ public class TrafficStats {
public static long getMobileTxBytes() { public static long getMobileTxBytes() {
long total = 0; long total = 0;
for (String iface : getMobileIfaces()) { for (String iface : getMobileIfaces()) {
total += getTxBytes(iface); total += addIfSupported(getTxBytes(iface));
} }
return total; return total;
} }
@@ -502,7 +506,7 @@ public class TrafficStats {
public static long getMobileRxBytes() { public static long getMobileRxBytes() {
long total = 0; long total = 0;
for (String iface : getMobileIfaces()) { for (String iface : getMobileIfaces()) {
total += getRxBytes(iface); total += addIfSupported(getRxBytes(iface));
} }
return total; return total;
} }
@@ -517,9 +521,7 @@ public class TrafficStats {
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }
if (stat != UNSUPPORTED) { total += addIfSupported(stat);
total += stat;
}
} }
return total; return total;
} }
@@ -534,9 +536,7 @@ public class TrafficStats {
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowFromSystemServer(); throw e.rethrowFromSystemServer();
} }
if (stat != UNSUPPORTED) { total += addIfSupported(stat);
total += stat;
}
} }
return total; return total;
} }