From e4334721104f3fa6df8886f5f46e43e0317a8dd2 Mon Sep 17 00:00:00 2001 From: Ecco Park Date: Tue, 30 Jan 2018 11:18:58 -0800 Subject: WifiTrafficPoller: Implement Unit test Bug: 72549299 Test: All the tests are passed ./frameworks/opt/net/wifi/tests/wifitests/runtests.sh -e class com.android.server.wifi.WifiTrafficPollerTest OK (4 tests) Change-Id: Icc4a5688ecc7dfb6fc1de9210cb25a71000ba59b Signed-off-by: Ecco Park --- .../java/com/android/server/wifi/WifiNative.java | 21 +++++++++++++++++++++ .../com/android/server/wifi/WifiTrafficPoller.java | 8 ++++---- 2 files changed, 25 insertions(+), 4 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 56a57348d..dd1fb4492 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -21,6 +21,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.net.InterfaceConfiguration; import android.net.MacAddress; +import android.net.TrafficStats; import android.net.apf.ApfCapabilities; import android.net.wifi.RttManager; import android.net.wifi.RttManager.ResponderConfig; @@ -2476,6 +2477,26 @@ public class WifiNative { return mWifiVendorHal.getRxPktFates(ifaceName, reportBufs); } + /** + * Get the tx packet counts for the interface. + * + * @param ifaceName Name of the interface. + * @return tx packet counts + */ + public long getTxPackets(@NonNull String ifaceName) { + return TrafficStats.getTxPackets(ifaceName); + } + + /** + * Get the rx packet counts for the interface. + * + * @param ifaceName Name of the interface + * @return rx packet counts + */ + public long getRxPackets(@NonNull String ifaceName) { + return TrafficStats.getRxPackets(ifaceName); + } + /** * Start sending the specified keep alive packets periodically. * diff --git a/service/java/com/android/server/wifi/WifiTrafficPoller.java b/service/java/com/android/server/wifi/WifiTrafficPoller.java index cd6c72d57..bcb625ed6 100644 --- a/service/java/com/android/server/wifi/WifiTrafficPoller.java +++ b/service/java/com/android/server/wifi/WifiTrafficPoller.java @@ -24,7 +24,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.NetworkInfo; -import android.net.TrafficStats; import android.net.wifi.WifiManager; import android.os.Handler; import android.os.Looper; @@ -75,7 +74,8 @@ public class WifiTrafficPoller { private boolean mVerboseLoggingEnabled = false; - WifiTrafficPoller(Context context, Looper looper, WifiNative wifiNative) { + WifiTrafficPoller(@NonNull Context context, @NonNull Looper looper, + @NonNull WifiNative wifiNative) { mTrafficHandler = new TrafficHandler(looper); mWifiNative = wifiNative; @@ -195,8 +195,8 @@ public class WifiTrafficPoller { long preTxPkts = mTxPkts, preRxPkts = mRxPkts; int dataActivity = WifiManager.DATA_ACTIVITY_NONE; - mTxPkts = TrafficStats.getTxPackets(ifaceName); - mRxPkts = TrafficStats.getRxPackets(ifaceName); + mTxPkts = mWifiNative.getTxPackets(ifaceName); + mRxPkts = mWifiNative.getRxPackets(ifaceName); if (DBG) { Log.d(TAG, " packet count Tx=" -- cgit v1.2.3