From 641e23cc3366b5b3b41727b932f8222afe11f0c9 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Fri, 17 May 2019 14:04:48 -0700 Subject: WifiNetworkSelector: Clear all configured network status Currently, only the SaveNetworkEvaluator clears status for each saved network before network selction is performed. This pre-selection step is required to a) Try and re-enable any temporarily disabled networks. b) Clear the candidate field in the NetworkSelectionStatus object for each network. This pre-selection step is needed for all configured networks (not just saved) since ephemeral networks are no longer removed after disconnect. Changes in the CL: a) Move the pre-selection network reset to the common WifiNetworkSelector from SavedNetworkEvaluator. b) Ensure that all configured networks (including ephemeral & passpoint networks) are reset in this common method. a) was done to avoid duplicating this logic in all of the evaluators. Bug: 132979765 Test: Manual verification of the steps mentioned in the bug. Test: Unit tests Change-Id: Id2e629712958b04356367985ef41e2094bbeb712 --- .../server/wifi/WifiNetworkSelectorTest.java | 52 +++++++++++++++++++--- .../server/wifi/WifiNetworkSelectorTestUtil.java | 4 +- 2 files changed, 47 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java index cda5d626b..53dae5229 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java @@ -167,13 +167,19 @@ public class WifiNetworkSelectorTest { if (!mEvaluatorShouldSelectCandidate) { return null; } - ScanDetail scanDetail = scanDetails.get(mNetworkIndexToReturn); - mWifiConfigManager.setNetworkCandidateScanResult(0, scanDetail.getScanResult(), 100); - WifiConfiguration config = - mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(scanDetail); - assertNotNull("Saved network must not be null", config); - onConnectableListener.onConnectable(scanDetail, config, 100); - return config; + for (ScanDetail scanDetail : scanDetails) { + WifiConfiguration config = + mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(scanDetail); + mWifiConfigManager.setNetworkCandidateScanResult( + config.networkId, scanDetail.getScanResult(), 100); + } + ScanDetail scanDetailToReturn = scanDetails.get(mNetworkIndexToReturn); + WifiConfiguration configToReturn = + mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache( + scanDetailToReturn); + assertNotNull("Saved network must not be null", configToReturn); + onConnectableListener.onConnectable(scanDetailToReturn, configToReturn, 100); + return configToReturn; } } @@ -539,6 +545,38 @@ public class WifiNetworkSelectorTest { chosenScanResult, candidate); } + /** + * Ensure that network selector update's network selection status for all configured + * networks before performing network selection. + * + * Expected behavior: the first network is recommended by Network Selector + */ + @Test + public void updateConfiguredNetworks() { + String[] ssids = {"\"test1\"", "\"test2\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; + int[] freqs = {2437, 2457}; + String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-PSK][ESS]"}; + int[] levels = {mThresholdMinimumRssi2G + 20, mThresholdMinimumRssi2G + RSSI_BUMP}; + int[] securities = {SECURITY_EAP, SECURITY_PSK}; + + ScanDetailsAndWifiConfigs scanDetailsAndConfigs = + WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, + freqs, caps, levels, securities, mWifiConfigManager, mClock); + List scanDetails = scanDetailsAndConfigs.getScanDetails(); + HashSet blacklist = new HashSet(); + WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); + + // Do network selection. + mWifiNetworkSelector.selectNetwork(scanDetails, + blacklist, mWifiInfo, true, false, false); + + verify(mWifiConfigManager).getConfiguredNetworks(); + verify(mWifiConfigManager, times(savedConfigs.length)).tryEnableNetwork(anyInt()); + verify(mWifiConfigManager, times(savedConfigs.length)) + .clearNetworkCandidateScanResult(anyInt()); + } + /** * Blacklisted BSSID is filtered out for network selection. * diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java index 4f795ad03..74d6cb747 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java @@ -218,9 +218,9 @@ public class WifiNetworkSelectorTestUtil { return null; } }); - when(wifiConfigManager.getSavedNetworks(anyInt())) + when(wifiConfigManager.getConfiguredNetworks()) .then(new AnswerWithArguments() { - public List answer(int uid) { + public List answer() { List savedNetworks = new ArrayList<>(); for (int netId = 0; netId < configs.length; netId++) { savedNetworks.add(new WifiConfiguration(configs[netId])); -- cgit v1.2.3