diff options
author | Randy Pan <zpan@google.com> | 2017-02-24 15:08:35 -0800 |
---|---|---|
committer | Randy Pan <zpan@google.com> | 2017-03-21 16:11:22 -0700 |
commit | 167b90b5e002698378728a54a417a08c317d29dc (patch) | |
tree | 3a2fbe45da70fae0e0e3f8d16de0e3d4057473b3 /tests | |
parent | 168fba718720b54cf0a88cfad7f96948925fb1e3 (diff) |
Move BSSID blacklist to WifiConnectivityManager
Now the BSSID blacklist is managed by WifiConnectivityManager and
passed to WifiNetworkSelector for scan results filtration.
Bug: 35642214
Test: runtests.sh and manual tests
Change-Id: I7afb5e66be471f3582075adb687a7d85ba49a80b
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java | 83 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java | 89 |
2 files changed, 109 insertions, 63 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index 39fa247bf..04af78dc5 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -115,7 +115,6 @@ public class WifiConnectivityManagerTest { private static final int CANDIDATE_NETWORK_ID = 0; private static final String CANDIDATE_SSID = "\"AnSsid\""; private static final String CANDIDATE_BSSID = "6c:f3:7f:ae:8c:f3"; - private static final String TAG = "WifiConnectivityManager Unit Test"; private static final long CURRENT_SYSTEM_TIME_MS = 1000; Resources mockResource() { @@ -225,8 +224,8 @@ public class WifiConnectivityManagerTest { candidateScanResult.BSSID = CANDIDATE_BSSID; candidate.getNetworkSelectionStatus().setCandidate(candidateScanResult); - when(ns.selectNetwork(anyObject(), anyObject(), anyBoolean(), anyBoolean(), - anyBoolean())).thenReturn(candidate); + when(ns.selectNetwork(anyObject(), anyObject(), anyObject(), anyBoolean(), + anyBoolean(), anyBoolean())).thenReturn(candidate); return ns; } @@ -501,8 +500,8 @@ public class WifiConnectivityManagerTest { @Test @Ignore("b/32977707") public void pnoRetryForLowRssiNetwork() { - when(mWifiNS.selectNetwork(anyObject(), anyObject(), anyBoolean(), anyBoolean(), - anyBoolean())).thenReturn(null); + when(mWifiNS.selectNetwork(anyObject(), anyObject(), anyObject(), anyBoolean(), + anyBoolean(), anyBoolean())).thenReturn(null); // Set screen to off mWifiConnectivityManager.handleScreenStateChanged(false); @@ -558,8 +557,8 @@ public class WifiConnectivityManagerTest { @Ignore("b/32977707") public void watchdogBitePnoGoodIncrementsMetrics() { // Qns returns no candidate after watchdog single scan. - when(mWifiNS.selectNetwork(anyObject(), anyObject(), anyBoolean(), anyBoolean(), - anyBoolean())).thenReturn(null); + when(mWifiNS.selectNetwork(anyObject(), anyObject(), anyObject(), anyBoolean(), + anyBoolean(), anyBoolean())).thenReturn(null); // Set screen to off mWifiConnectivityManager.handleScreenStateChanged(false); @@ -1047,4 +1046,74 @@ public class WifiConnectivityManagerTest { verify(mWifiStateMachine).startConnectToNetwork( CANDIDATE_NETWORK_ID, CANDIDATE_BSSID); } + + /** + * Verify the BSSID blacklist implementation. + * + * Expected behavior: A BSSID gets blacklisted after being disabled + * for 3 times, and becomes available after being re-enabled. + */ + @Test + public void blacklistAndReenableBssid() { + String bssid = "6c:f3:7f:ae:8c:f3"; + + // Verify that a BSSID gets blacklisted only after being disabled + // for BSSID_BLACKLIST_THRESHOLD times for reasons other than + // REASON_CODE_AP_UNABLE_TO_HANDLE_NEW_STA. + for (int i = 0; i < WifiConnectivityManager.BSSID_BLACKLIST_THRESHOLD; i++) { + assertFalse(mWifiConnectivityManager.isBssidDisabled(bssid)); + mWifiConnectivityManager.trackBssid(bssid, false, 1); + } + + assertTrue(mWifiConnectivityManager.isBssidDisabled(bssid)); + + // Re-enable the bssid. + mWifiConnectivityManager.trackBssid(bssid, true, 1); + + // The bssid should no longer be blacklisted. + assertFalse(mWifiConnectivityManager.isBssidDisabled(bssid)); + } + + /** + * Verify that a network gets blacklisted immediately if it is unable + * to handle new stations. + */ + @Test + public void blacklistNetworkImmediatelyIfApHasNoCapacityForNewStation() { + String bssid = "6c:f3:7f:ae:8c:f3"; + + mWifiConnectivityManager.trackBssid(bssid, false, + WifiConnectivityManager.REASON_CODE_AP_UNABLE_TO_HANDLE_NEW_STA); + + assertTrue(mWifiConnectivityManager.isBssidDisabled(bssid)); + } + + /** + * Verify that a blacklisted BSSID becomes available only after + * BSSID_BLACKLIST_EXPIRE_TIME_MS. + */ + @Test + public void verifyBlacklistRefreshedAfterScanResults() { + String bssid = "6c:f3:7f:ae:8c:f3"; + + mWifiConnectivityManager.trackBssid(bssid, false, + WifiConnectivityManager.REASON_CODE_AP_UNABLE_TO_HANDLE_NEW_STA); + assertTrue(mWifiConnectivityManager.isBssidDisabled(bssid)); + + // Force a connectivity scan in less than BSSID_BLACKLIST_EXPIRE_TIME_MS. + // Arrival of scan results will trigger WifiConnectivityManager to refresh its + // BSSID blacklist. Verify that the blacklisted BSSId is not freed because + // its blacklist expiration time hasn't reached yet. + when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime() + + WifiConnectivityManager.BSSID_BLACKLIST_EXPIRE_TIME_MS / 2); + mWifiConnectivityManager.forceConnectivityScan(); + assertTrue(mWifiConnectivityManager.isBssidDisabled(bssid)); + + // Force another connectivity scan at BSSID_BLACKLIST_EXPIRE_TIME_MS from when the + // BSSID was blacklisted. Verify that the blacklisted BSSId is freed. + when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime() + + WifiConnectivityManager.BSSID_BLACKLIST_EXPIRE_TIME_MS); + mWifiConnectivityManager.forceConnectivityScan(); + assertFalse(mWifiConnectivityManager.isBssidDisabled(bssid)); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java index 4a38f402f..73469a386 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java @@ -41,6 +41,7 @@ import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import java.util.HashSet; import java.util.List; /** @@ -176,8 +177,9 @@ public class WifiNetworkSelectorTest { WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + HashSet<String> blacklist = new HashSet<String>(); WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, false, true, false); + blacklist, mWifiInfo, false, true, false); assertEquals("Expect null configuration", null, candidate); } @@ -204,8 +206,9 @@ public class WifiNetworkSelectorTest { WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + HashSet<String> blacklist = new HashSet<String>(); WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, false, true, false); + blacklist, mWifiInfo, false, true, false); assertEquals("Expect null configuration", null, candidate); } @@ -233,15 +236,16 @@ public class WifiNetworkSelectorTest { WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + HashSet<String> blacklist = new HashSet<String>(); WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, false, true, false); + blacklist, mWifiInfo, false, true, false); when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime() + WifiNetworkSelector.MINIMUM_NETWORK_SELECTION_INTERVAL_MS - 2000); // Do another network selection with WSM in CONNECTED state. candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, true, false, false); + blacklist, mWifiInfo, true, false, false); assertEquals("Expect null configuration", null, candidate); } @@ -271,8 +275,9 @@ public class WifiNetworkSelectorTest { freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); + HashSet<String> blacklist = new HashSet<String>(); WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, false, true, false); + blacklist, mWifiInfo, false, true, false); WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate); when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime() @@ -280,7 +285,7 @@ public class WifiNetworkSelectorTest { // Do another network selection with WSM in DISCONNECTED state. candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, false, true, false); + blacklist, mWifiInfo, false, true, false); ScanResult chosenScanResult = scanDetails.get(0).getScanResult(); WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate); @@ -310,9 +315,10 @@ public class WifiNetworkSelectorTest { WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + HashSet<String> blacklist = new HashSet<String>(); // connect to test1 - mWifiNetworkSelector.selectNetwork(scanDetails, mWifiInfo, false, true, false); + mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); when(mWifiInfo.getNetworkId()).thenReturn(0); when(mWifiInfo.getBSSID()).thenReturn(bssids[0]); when(mWifiInfo.is24GHz()).thenReturn(false); @@ -327,7 +333,7 @@ public class WifiNetworkSelectorTest { scanDetails = scanDetailsAndConfigs.getScanDetails(); WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, true, false, false); + blacklist, mWifiInfo, true, false, false); assertEquals("Expect null configuration", null, candidate); } @@ -354,10 +360,11 @@ public class WifiNetworkSelectorTest { WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + HashSet<String> blacklist = new HashSet<String>(); WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); // connect to test1 - mWifiNetworkSelector.selectNetwork(scanDetails, mWifiInfo, false, true, false); + mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); when(mWifiInfo.getNetworkId()).thenReturn(0); when(mWifiInfo.getBSSID()).thenReturn(bssids[0]); when(mWifiInfo.is24GHz()).thenReturn(true); @@ -367,7 +374,7 @@ public class WifiNetworkSelectorTest { // Do another network selection. WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, true, false, false); + blacklist, mWifiInfo, true, false, false); ScanResult chosenScanResult = scanDetails.get(0).getScanResult(); WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate); @@ -399,10 +406,11 @@ public class WifiNetworkSelectorTest { WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + HashSet<String> blacklist = new HashSet<String>(); WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); // connect to test1 - mWifiNetworkSelector.selectNetwork(scanDetails, mWifiInfo, false, true, false); + mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); when(mWifiInfo.getNetworkId()).thenReturn(0); when(mWifiInfo.getBSSID()).thenReturn(bssids[0]); when(mWifiInfo.is24GHz()).thenReturn(false); @@ -413,7 +421,7 @@ public class WifiNetworkSelectorTest { // Do another network selection. WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, true, false, false); + blacklist, mWifiInfo, true, false, false); ScanResult chosenScanResult = scanDetails.get(0).getScanResult(); WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate); @@ -444,10 +452,11 @@ public class WifiNetworkSelectorTest { WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + HashSet<String> blacklist = new HashSet<String>(); WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); // connect to test1 - mWifiNetworkSelector.selectNetwork(scanDetails, mWifiInfo, false, true, false); + mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); when(mWifiInfo.getNetworkId()).thenReturn(0); when(mWifiInfo.getBSSID()).thenReturn(bssids[0]); when(mWifiInfo.is24GHz()).thenReturn(false); @@ -459,7 +468,7 @@ public class WifiNetworkSelectorTest { // Do another network selection. WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, true, false, false); + blacklist, mWifiInfo, true, false, false); ScanResult chosenScanResult = scanDetails.get(0).getScanResult(); WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate); @@ -488,15 +497,11 @@ public class WifiNetworkSelectorTest { WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); - - // Disable this network for BSSID_BLACKLIST_THRESHOLD times so it gets - // blacklisted by WNS. - for (int i = 0; i < WifiNetworkSelector.BSSID_BLACKLIST_THRESHOLD; i++) { - mWifiNetworkSelector.enableBssidForNetworkSelection(bssids[0], false, 1); - } + HashSet<String> blacklist = new HashSet<String>(); + blacklist.add(bssids[0]); WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, false, true, false); + blacklist, mWifiInfo, false, true, false); assertEquals("Expect null configuration", null, candidate); } @@ -524,8 +529,9 @@ public class WifiNetworkSelectorTest { WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + HashSet<String> blacklist = new HashSet<String>(); WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, false, true, false); + blacklist, mWifiInfo, false, true, false); when(mWifiInfo.getNetworkId()).thenReturn(0); when(mWifiInfo.getBSSID()).thenReturn(bssids[0]); @@ -543,7 +549,8 @@ public class WifiNetworkSelectorTest { int[] levelsNew = {mThresholdMinimumRssi2G + 40}; scanDetails = WifiNetworkSelectorTestUtil.buildScanDetails(ssidsNew, bssidsNew, freqsNew, capsNew, levelsNew, mClock); - candidate = mWifiNetworkSelector.selectNetwork(scanDetails, mWifiInfo, true, false, false); + candidate = mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, + true, false, false); // The second network selection is skipped since current connected network is // missing from the scan results. @@ -618,6 +625,7 @@ public class WifiNetworkSelectorTest { WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + HashSet<String> blacklist = new HashSet<String>(); // DummyEvaluator always selects the first network in the list. WifiConfiguration networkSelectorChoice = scanDetailsAndConfigs.getWifiConfigs()[0]; @@ -630,7 +638,7 @@ public class WifiNetworkSelectorTest { // With no user choice set, networkSelectorChoice should be chosen. WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, false, true, false); + blacklist, mWifiInfo, false, true, false); WifiConfigurationTestUtil.assertConfigurationEqual(networkSelectorChoice, candidate); @@ -641,39 +649,8 @@ public class WifiNetworkSelectorTest { // After user connect choice is set, userChoice should override networkSelectorChoice. candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, false, true, false); + blacklist, mWifiInfo, false, true, false); WifiConfigurationTestUtil.assertConfigurationEqual(userChoice, candidate); } - - /** - * Wifi network selector blacklists a BSSID immediately if it's unable to handle - * new stations. - * - * Expected behavior: no network recommended by Network Selector - */ - @Test - public void blacklistNetworkImmediatelyIfApHasNoCapacityForNewStation() { - String[] ssids = {"\"test1\""}; - String[] bssids = {"6c:f3:7f:ae:99:f3"}; - int[] freqs = {2437}; - String[] caps = {"[WPA2-EAP-CCMP][ESS]"}; - int[] levels = {mThresholdMinimumRssi2G + 20}; - int[] securities = {SECURITY_PSK}; - - // Disable test1 with reason code indicating it is unable to handle new stations. - mWifiNetworkSelector.enableBssidForNetworkSelection(bssids[0], false, - WifiNetworkSelector.REASON_CODE_AP_UNABLE_TO_HANDLE_NEW_STA); - - // Make a network selection with test1 in the scan results. - ScanDetailsAndWifiConfigs scanDetailsAndConfigs = - WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, - freqs, caps, levels, securities, mWifiConfigManager, mClock); - List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); - WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - mWifiInfo, false, true, false); - - // No network recommended by WNS as test1 is blacklisted. - assertEquals("Expect null configuration", null, candidate); - } } |