diff options
author | Rebecca Silberstein <silberst@google.com> | 2018-01-23 02:03:34 -0800 |
---|---|---|
committer | Rebecca Silberstein <silberst@google.com> | 2018-02-20 17:25:48 -0800 |
commit | 0fa22852a84b9eda94edf73700fb5971116dcac9 (patch) | |
tree | 910b14dbf18996e1a9fd2bbaa5a8d5cc59f48237 /tests | |
parent | 03ba3e6683b20c22d6dd4fb32c93bcaf7858cfa2 (diff) |
WifiStateMachine: create dedicated WifiRssiEventHandler
Instead of having WifiStateMachine implement the WifiRssiEventHandler,
create a class and instance of it in Client mode to use for
rssi events.
Added a new test to verify the callback is registered.
Bug: 72358444
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: I33072e9ec61196f091fde731a6093d59d3e44a05
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index 50555975d..c6abff6c7 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -37,6 +37,8 @@ import android.net.DhcpResults; import android.net.LinkProperties; import android.net.NetworkCapabilities; import android.net.NetworkFactory; +import android.net.NetworkInfo; +import android.net.NetworkMisc; import android.net.NetworkRequest; import android.net.dhcp.DhcpClient; import android.net.ip.IpClient; @@ -136,6 +138,13 @@ public class WifiStateMachineTest { private static final String OP_PACKAGE_NAME = "com.xxx"; private static final int TEST_UID = Process.SYSTEM_UID + 1000; + // NetworkAgent creates threshold ranges with Integers + private static final int RSSI_THRESHOLD_MAX = -30; + private static final int RSSI_THRESHOLD_MIN = -76; + // Threshold breach callbacks are called with bytes + private static final byte RSSI_THRESHOLD_BREACH_MIN = -80; + private static final byte RSSI_THRESHOLD_BREACH_MAX = -20; + private long mBinderToken; private static <T> T mockWithInterfaces(Class<T> class1, Class<?>... interfaces) { @@ -2316,4 +2325,44 @@ public class WifiStateMachineTest { mWsm.takeBugReport(anyString(), anyString()); verify(mWifiDiagnostics).takeBugReport(anyString(), anyString()); } + + /** + * Verify that Rssi Monitoring is started and the callback registered after connecting. + */ + @Test + public void verifyRssiMonitoringCallbackIsRegistered() throws Exception { + // Simulate the first connection. + connect(); + ArgumentCaptor<Messenger> messengerCaptor = ArgumentCaptor.forClass(Messenger.class); + verify(mConnectivityManager).registerNetworkAgent(messengerCaptor.capture(), + any(NetworkInfo.class), any(LinkProperties.class), any(NetworkCapabilities.class), + anyInt(), any(NetworkMisc.class)); + + ArrayList<Integer> thresholdsArray = new ArrayList(); + thresholdsArray.add(RSSI_THRESHOLD_MAX); + thresholdsArray.add(RSSI_THRESHOLD_MIN); + Bundle thresholds = new Bundle(); + thresholds.putIntegerArrayList("thresholds", thresholdsArray); + Message message = new Message(); + message.what = android.net.NetworkAgent.CMD_SET_SIGNAL_STRENGTH_THRESHOLDS; + message.obj = thresholds; + messengerCaptor.getValue().send(message); + mLooper.dispatchAll(); + + ArgumentCaptor<WifiNative.WifiRssiEventHandler> rssiEventHandlerCaptor = + ArgumentCaptor.forClass(WifiNative.WifiRssiEventHandler.class); + verify(mWifiNative).startRssiMonitoring(anyString(), anyByte(), anyByte(), + rssiEventHandlerCaptor.capture()); + + // breach below min + rssiEventHandlerCaptor.getValue().onRssiThresholdBreached(RSSI_THRESHOLD_BREACH_MIN); + mLooper.dispatchAll(); + WifiInfo wifiInfo = mWsm.getWifiInfo(); + assertEquals(RSSI_THRESHOLD_BREACH_MIN, wifiInfo.getRssi()); + + // breach above max + rssiEventHandlerCaptor.getValue().onRssiThresholdBreached(RSSI_THRESHOLD_BREACH_MAX); + mLooper.dispatchAll(); + assertEquals(RSSI_THRESHOLD_BREACH_MAX, wifiInfo.getRssi()); + } } |