From 0fa22852a84b9eda94edf73700fb5971116dcac9 Mon Sep 17 00:00:00 2001 From: Rebecca Silberstein Date: Tue, 23 Jan 2018 02:03:34 -0800 Subject: 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 --- .../android/server/wifi/WifiStateMachineTest.java | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'tests') 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 mockWithInterfaces(Class 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 messengerCaptor = ArgumentCaptor.forClass(Messenger.class); + verify(mConnectivityManager).registerNetworkAgent(messengerCaptor.capture(), + any(NetworkInfo.class), any(LinkProperties.class), any(NetworkCapabilities.class), + anyInt(), any(NetworkMisc.class)); + + ArrayList 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 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()); + } } -- cgit v1.2.3 From ab4d540e20b656f3723fe016c91a886e76f69f86 Mon Sep 17 00:00:00 2001 From: Rebecca Silberstein Date: Tue, 30 Jan 2018 23:03:37 -0800 Subject: WifiStateMachine: create dedicated object for FilterController Instead of passing WifiStateMachine as the WifiMulticastLockManager.FilterController to the WifiMulticastLockManager, create an object to explicitly handle these callbacks. Added a new unit test to WSM to verify that the new object is plumbed (that code had never been unittested). Bug: 72721052 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: Wifi Integration tests Change-Id: I8fd23d926d707fc11cfa3a7c94542cf62126cb20 --- .../com/android/server/wifi/WifiStateMachineTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index c6abff6c7..7aeccbef6 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -2365,4 +2365,20 @@ public class WifiStateMachineTest { mLooper.dispatchAll(); assertEquals(RSSI_THRESHOLD_BREACH_MAX, wifiInfo.getRssi()); } + + /** + * Verify that calls to start and stop filtering multicast packets are passed on to the IpClient + * instance. + */ + @Test + public void verifyMcastLockManagerFilterControllerCallsUpdateIpClient() throws Exception { + loadComponentsInStaMode(); + reset(mIpClient); + WifiMulticastLockManager.FilterController filterController = + mWsm.getMcastLockManagerFilterController(); + filterController.startFilteringMulticastPackets(); + verify(mIpClient).setMulticastFilter(eq(true)); + filterController.stopFilteringMulticastPackets(); + verify(mIpClient).setMulticastFilter(eq(false)); + } } -- cgit v1.2.3 From 9a50fce0dd19fa80a37c2f851772811f823685bd Mon Sep 17 00:00:00 2001 From: Rebecca Silberstein Date: Wed, 31 Jan 2018 00:24:55 -0800 Subject: WifiStateMachine: remove link debouncing Remove logic related to link debouncing. Bug: 72643098 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: Wifi Integration tests Change-Id: Ied69a6b4feed3a97523b97076ca0b6da3bc95b2e --- .../src/com/android/server/wifi/WifiConnectivityManagerTest.java | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index acc3a66e1..490d34bb8 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -254,7 +254,6 @@ public class WifiConnectivityManagerTest { WifiStateMachine mockWifiStateMachine() { WifiStateMachine stateMachine = mock(WifiStateMachine.class); - when(stateMachine.isLinkDebouncing()).thenReturn(false); when(stateMachine.isConnected()).thenReturn(false); when(stateMachine.isDisconnected()).thenReturn(true); when(stateMachine.isSupplicantTransientState()).thenReturn(false); -- cgit v1.2.3 From 73dd0f219113f68ca1451b3a6ca48642f7775c82 Mon Sep 17 00:00:00 2001 From: Rebecca Silberstein Date: Wed, 31 Jan 2018 00:51:50 -0800 Subject: WifiStateMachine: remove scan related code Now that we have ScanRequestProxy hooked up with WifiServiceImpl, we no longer need scan request/result handling in WSM. Bug: 31444878 Bug: 31445200 Bug: 70359905 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: Wifi Integration tests Change-Id: I63ab7efe1f43310faf92c927c31bdcfa6d8bb7da --- .../android/server/wifi/WifiStateMachineTest.java | 64 ---------------------- 1 file changed, 64 deletions(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index 7aeccbef6..29f8b4847 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -108,9 +108,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.function.Consumer; @@ -921,68 +919,6 @@ public class WifiStateMachineTest { return null; } - private void verifyScan(int band, int reportEvents, Set hiddenNetworkSSIDSet) { - ArgumentCaptor scanSettingsCaptor = - ArgumentCaptor.forClass(WifiScanner.ScanSettings.class); - ArgumentCaptor scanListenerCaptor = - ArgumentCaptor.forClass(WifiScanner.ScanListener.class); - verify(mWifiScanner).startScan(scanSettingsCaptor.capture(), scanListenerCaptor.capture(), - eq(null)); - WifiScanner.ScanSettings actualSettings = scanSettingsCaptor.getValue(); - assertEquals("band", band, actualSettings.band); - assertEquals("reportEvents", reportEvents, actualSettings.reportEvents); - - if (hiddenNetworkSSIDSet == null) { - hiddenNetworkSSIDSet = new HashSet<>(); - } - Set actualHiddenNetworkSSIDSet = new HashSet<>(); - if (actualSettings.hiddenNetworks != null) { - for (int i = 0; i < actualSettings.hiddenNetworks.length; ++i) { - actualHiddenNetworkSSIDSet.add(actualSettings.hiddenNetworks[i].ssid); - } - } - assertEquals("hidden networks", hiddenNetworkSSIDSet, actualHiddenNetworkSSIDSet); - - when(mWifiNative.getScanResults(WIFI_IFACE_NAME)).thenReturn(getMockScanResults()); - mWsm.sendMessage(WifiMonitor.SCAN_RESULTS_EVENT); - - mLooper.dispatchAll(); - - List reportedResults = mWsm.syncGetScanResultsList(); - assertEquals(8, reportedResults.size()); - } - - @Test - public void scan() throws Exception { - initializeAndAddNetworkAndVerifySuccess(); - - mWsm.startScan(-1, 0, null, null); - mLooper.dispatchAll(); - - verifyScan(WifiScanner.WIFI_BAND_BOTH_WITH_DFS, - WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN - | WifiScanner.REPORT_EVENT_FULL_SCAN_RESULT, null); - } - - @Test - public void scanWithHiddenNetwork() throws Exception { - initializeAndAddNetworkAndVerifySuccess(true); - - Set hiddenNetworkSet = new HashSet<>(); - hiddenNetworkSet.add(sSSID); - List hiddenNetworkList = new ArrayList<>(); - hiddenNetworkList.add(new WifiScanner.ScanSettings.HiddenNetwork(sSSID)); - when(mWifiConfigManager.retrieveHiddenNetworkList()).thenReturn(hiddenNetworkList); - - mWsm.startScan(-1, 0, null, null); - mLooper.dispatchAll(); - - verifyScan(WifiScanner.WIFI_BAND_BOTH_WITH_DFS, - WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN - | WifiScanner.REPORT_EVENT_FULL_SCAN_RESULT, - hiddenNetworkSet); - } - private void setupAndStartConnectSequence(WifiConfiguration config) throws Exception { when(mWifiConfigManager.enableNetwork(eq(config.networkId), eq(true), anyInt())) .thenReturn(true); -- cgit v1.2.3