diff options
author | 2017-07-12 14:22:19 +0000 | |
---|---|---|
committer | 2017-07-12 14:22:19 +0000 | |
commit | 5b3d97a8ab5a9c0b13cacb621dcb4f999623dec7 (patch) | |
tree | 95f309c6f5f2661c078cd3033da93d906b705430 | |
parent | a406ddd028d34040ce7a50cb5afba8813295cf97 (diff) | |
parent | 154bcbe5181d46f79a01d682ab10018b28ac7936 (diff) |
Merge "Add OffloadHardwareInterface.getForwardedStats() wrapper" into oc-dr1-dev am: 9df88e1fe7
am: 154bcbe518
Change-Id: I41f837e16eff9a4cd763d65155bd9b5d5d980acd
-rw-r--r-- | services/core/java/com/android/server/connectivity/tethering/OffloadHardwareInterface.java | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/connectivity/tethering/OffloadHardwareInterface.java b/services/core/java/com/android/server/connectivity/tethering/OffloadHardwareInterface.java index cd98b30027d2..913096cb5bef 100644 --- a/services/core/java/com/android/server/connectivity/tethering/OffloadHardwareInterface.java +++ b/services/core/java/com/android/server/connectivity/tethering/OffloadHardwareInterface.java @@ -35,6 +35,7 @@ import java.util.ArrayList; */ public class OffloadHardwareInterface { private static final String TAG = OffloadHardwareInterface.class.getSimpleName(); + private static final String YIELDS = " -> "; // Change this value to control whether tether offload is enabled or // disabled by default in the absence of an explicit Settings value. // See accompanying unittest to distinguish 0 from non-0 values. @@ -59,6 +60,25 @@ public class OffloadHardwareInterface { String dstAddr, int dstPort) {} } + public static class ForwardedStats { + public long rxBytes; + public long txBytes; + + public ForwardedStats() { + rxBytes = 0; + txBytes = 0; + } + + public void add(ForwardedStats other) { + rxBytes += other.rxBytes; + txBytes += other.txBytes; + } + + public String toString() { + return String.format("rx:%s tx:%s", rxBytes, txBytes); + } + } + public OffloadHardwareInterface(Handler h, SharedLog log) { mHandler = h; mLog = log.forSubComponent(TAG); @@ -123,6 +143,26 @@ public class OffloadHardwareInterface { mLog.log("stopOffloadControl()"); } + public ForwardedStats getForwardedStats(String upstream) { + final String logmsg = String.format("getForwardedStats(%s)", upstream); + + final ForwardedStats stats = new ForwardedStats(); + try { + mOffloadControl.getForwardedStats( + upstream, + (long rxBytes, long txBytes) -> { + stats.rxBytes = (rxBytes > 0) ? rxBytes : 0; + stats.txBytes = (txBytes > 0) ? txBytes : 0; + }); + } catch (RemoteException e) { + record(logmsg, e); + return stats; + } + + mLog.log(logmsg + YIELDS + stats); + return stats; + } + public boolean setUpstreamParameters( String iface, String v4addr, String v4gateway, ArrayList<String> v6gws) { iface = (iface != null) ? iface : NO_INTERFACE_NAME; @@ -151,11 +191,11 @@ public class OffloadHardwareInterface { } private void record(String msg, Throwable t) { - mLog.e(msg + " -> exception: " + t); + mLog.e(msg + YIELDS + "exception: " + t); } private void record(String msg, CbResults results) { - final String logmsg = msg + " -> " + results; + final String logmsg = msg + YIELDS + results; if (!results.success) { mLog.e(logmsg); } else { |