diff options
author | Oscar Shu <xshu@google.com> | 2020-02-27 01:44:08 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-02-27 01:44:08 +0000 |
commit | 2d7d6154fd751d28114cc63af2af6963b125dc75 (patch) | |
tree | 7b67844e25c5163878e50a309db6cf3424e232a1 /tests | |
parent | dd457ab2f2f359415e4ea0893a4b09136ece8223 (diff) | |
parent | 560f74b8c633834ad952a44a2a650ad63b618f83 (diff) |
Merge changes from topic "duplicateScansHighMovement-rvc-dev" into rvc-dev
* changes:
High movement - trigger delayed partial scan
Re-trigger scan to confirm network in HIGH_MVMT
Diffstat (limited to 'tests')
3 files changed, 265 insertions, 78 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java b/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java index 9cf47cb74..4b64f71a6 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java @@ -113,6 +113,16 @@ public class WifiCandidatesTest extends WifiBaseTest { } /** + * Test retrieving the list of candidates. + */ + @Test + public void testGetCandidates() { + assertTrue(mWifiCandidates.add(mScanDetail1, mConfig1, 2, 0.0, false, 100)); + assertNotNull(mWifiCandidates.getCandidates()); + assertEquals(1, mWifiCandidates.getCandidates().size()); + } + + /** * Make sure we catch SSID mismatch due to quoting error */ @Test diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index 2f231519b..3c37cdfee 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -21,6 +21,7 @@ import static com.android.server.wifi.WifiConfigurationTestUtil.generateWifiConf import static org.junit.Assert.*; import static org.mockito.Mockito.*; +import static org.mockito.Mockito.argThat; import android.app.test.MockAnswerUtil.AnswerWithArguments; import android.app.test.TestAlarmManager; @@ -55,6 +56,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; +import org.mockito.ArgumentMatcher; import org.mockito.Captor; import org.mockito.InOrder; import org.mockito.Mock; @@ -131,6 +133,12 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { resources.setIntArray( R.array.config_wifiSingleSavedNetworkConnectedScanIntervalScheduleSec, SCHEDULE_EMPTY); + resources.setInteger( + R.integer.config_wifiHighMovementNetworkSelectionOptimizationScanDelayMs, + HIGH_MVMT_SCAN_DELAY_MS); + resources.setInteger( + R.integer.config_wifiHighMovementNetworkSelectionOptimizationRssiDelta, + HIGH_MVMT_RSSI_DELTA); } /** @@ -169,7 +177,9 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { @Mock private WifiScoreCard mWifiScoreCard; @Mock private WifiScoreCard.PerNetwork mPerNetwork; @Mock private WifiScoreCard.PerNetwork mPerNetwork1; - + @Mock WifiCandidates.Candidate mCandidate1; + @Mock WifiCandidates.Candidate mCandidate2; + private List<WifiCandidates.Candidate> mCandidateList; @Captor ArgumentCaptor<ScanResult> mCandidateScanResultCaptor; @Captor ArgumentCaptor<ArrayList<String>> mBssidBlacklistCaptor; @Captor ArgumentCaptor<ArrayList<String>> mSsidWhitelistCaptor; @@ -182,6 +192,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { private static final String CANDIDATE_SSID = "\"AnSsid\""; private static final String CANDIDATE_BSSID = "6c:f3:7f:ae:8c:f3"; private static final String INVALID_SCAN_RESULT_BSSID = "6c:f3:7f:ae:8c:f4"; + private static final int TEST_FREQUENCY = 2420; private static final long CURRENT_SYSTEM_TIME_MS = 1000; private static final int MAX_BSSID_BLACKLIST_SIZE = 16; private static final int[] VALID_CONNECTED_SINGLE_SCAN_SCHEDULE = {10, 30, 50}; @@ -196,6 +207,8 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { private static final int TEST_FREQUENCY_1 = 2412; private static final int TEST_FREQUENCY_2 = 5180; private static final int TEST_FREQUENCY_3 = 5240; + private static final int HIGH_MVMT_SCAN_DELAY_MS = 10000; + private static final int HIGH_MVMT_RSSI_DELTA = 10; Context mockContext() { Context context = mock(Context.class); @@ -302,8 +315,25 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { candidate.getNetworkSelectionStatus().setCandidate(candidateScanResult); when(mWifiConfigManager.getConfiguredNetwork(CANDIDATE_NETWORK_ID)).thenReturn(candidate); - when(ns.selectNetwork(anyObject(), anyObject(), anyObject(), anyBoolean(), - anyBoolean(), anyBoolean())).thenReturn(candidate); + WifiCandidates.Key key = mock(WifiCandidates.Key.class); + when(mCandidate1.getKey()).thenReturn(key); + when(mCandidate1.getScanRssi()).thenReturn(-40); + when(mCandidate1.getFrequency()).thenReturn(TEST_FREQUENCY); + when(mCandidate2.getKey()).thenReturn(key); + when(mCandidate2.getScanRssi()).thenReturn(-60); + mCandidateList = new ArrayList<WifiCandidates.Candidate>(); + mCandidateList.add(mCandidate1); + when(ns.getCandidatesFromScan(any(), any(), any(), anyBoolean(), anyBoolean(), + anyBoolean())).thenReturn(mCandidateList); + when(ns.selectNetwork(any())) + .then(new AnswerWithArguments() { + public WifiConfiguration answer(List<WifiCandidates.Candidate> candidateList) { + if (candidateList == null) { + return null; + } + return candidate; + } + }); return ns; } @@ -579,8 +609,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { */ @Test public void pnoRetryForLowRssiNetwork() { - when(mWifiNS.selectNetwork(anyObject(), anyObject(), anyObject(), anyBoolean(), - anyBoolean(), anyBoolean())).thenReturn(null); + when(mWifiNS.selectNetwork(any())).thenReturn(null); // Set screen to off mWifiConnectivityManager.handleScreenStateChanged(false); @@ -634,8 +663,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { @Test public void watchdogBitePnoGoodIncrementsMetrics() { // Qns returns no candidate after watchdog single scan. - when(mWifiNS.selectNetwork(anyObject(), anyObject(), anyObject(), anyBoolean(), - anyBoolean(), anyBoolean())).thenReturn(null); + when(mWifiNS.selectNetwork(any())).thenReturn(null); // Set screen to off mWifiConnectivityManager.handleScreenStateChanged(false); @@ -653,6 +681,130 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { } /** + * Verify that 2 scans that are sufficiently far apart are required to initiate a connection + * when the high mobility scanning optimization is enabled. + */ + @Test + public void testHighMovementNetworkSelection() { + when(mClock.getElapsedSinceBootMillis()).thenReturn(0L); + // Enable high movement optimization + mResources.setBoolean(R.bool.config_wifiHighMovementNetworkSelectionOptimizationEnabled, + true); + mWifiConnectivityManager.setDeviceMobilityState( + WifiManager.DEVICE_MOBILITY_STATE_HIGH_MVMT); + + // Set WiFi to disconnected state to trigger scan + mWifiConnectivityManager.handleConnectionStateChanged( + WifiConnectivityManager.WIFI_STATE_DISCONNECTED); + mLooper.dispatchAll(); + + // Verify there is no connection due to currently having no cached candidates. + verify(mClientModeImpl, never()).startConnectToNetwork( + CANDIDATE_NETWORK_ID, Process.WIFI_UID, CANDIDATE_BSSID); + + // Move time forward but do not cross HIGH_MVMT_SCAN_DELAY_MS yet. + when(mClock.getElapsedSinceBootMillis()).thenReturn(HIGH_MVMT_SCAN_DELAY_MS - 1L); + // Set WiFi to disconnected state to trigger scan + mWifiConnectivityManager.handleConnectionStateChanged( + WifiConnectivityManager.WIFI_STATE_DISCONNECTED); + mLooper.dispatchAll(); + + // Verify we still don't connect because not enough time have passed since the candidates + // were cached. + verify(mClientModeImpl, never()).startConnectToNetwork( + CANDIDATE_NETWORK_ID, Process.WIFI_UID, CANDIDATE_BSSID); + + // Move time past HIGH_MVMT_SCAN_DELAY_MS. + when(mClock.getElapsedSinceBootMillis()).thenReturn((long) HIGH_MVMT_SCAN_DELAY_MS); + // Set WiFi to disconnected state to trigger scan + mWifiConnectivityManager.handleConnectionStateChanged( + WifiConnectivityManager.WIFI_STATE_DISCONNECTED); + mLooper.dispatchAll(); + + // Verify a candidate if found this time. + verify(mClientModeImpl).startConnectToNetwork( + CANDIDATE_NETWORK_ID, Process.WIFI_UID, CANDIDATE_BSSID); + } + + /** + * Verify that the device is initiating partial scans to verify AP stability in the high + * movement mobility state. + */ + @Test + public void testHighMovementTriggerPartialScan() { + when(mClock.getElapsedSinceBootMillis()).thenReturn(0L); + // Enable high movement optimization + mResources.setBoolean(R.bool.config_wifiHighMovementNetworkSelectionOptimizationEnabled, + true); + mWifiConnectivityManager.setDeviceMobilityState( + WifiManager.DEVICE_MOBILITY_STATE_HIGH_MVMT); + + // Set WiFi to disconnected state to trigger scan + mWifiConnectivityManager.handleConnectionStateChanged( + WifiConnectivityManager.WIFI_STATE_DISCONNECTED); + mLooper.dispatchAll(); + // Verify there is no connection due to currently having no cached candidates. + verify(mClientModeImpl, never()).startConnectToNetwork( + CANDIDATE_NETWORK_ID, Process.WIFI_UID, CANDIDATE_BSSID); + + // Move time forward and verify that a delayed partial scan is scheduled. + when(mClock.getElapsedSinceBootMillis()).thenReturn(HIGH_MVMT_SCAN_DELAY_MS + 1L); + mAlarmManager.dispatch(WifiConnectivityManager.DELAYED_PARTIAL_SCAN_TIMER_TAG); + mLooper.dispatchAll(); + + verify(mWifiScanner).startScan((ScanSettings) argThat(new WifiPartialScanSettingMatcher()), + any(), any(), any()); + } + + private class WifiPartialScanSettingMatcher implements ArgumentMatcher<ScanSettings> { + @Override + public boolean matches(ScanSettings scanSettings) { + return scanSettings.band == WifiScanner.WIFI_BAND_UNSPECIFIED + && scanSettings.channels[0].frequency == TEST_FREQUENCY; + } + } + + /** + * Verify that in the high movement mobility state, when the RSSI delta of a BSSID from + * 2 consecutive scans becomes greater than a threshold, the candidate get ignored from + * network selection. + */ + @Test + public void testHighMovementRssiFilter() { + when(mClock.getElapsedSinceBootMillis()).thenReturn(0L); + // Enable high movement optimization + mResources.setBoolean(R.bool.config_wifiHighMovementNetworkSelectionOptimizationEnabled, + true); + mWifiConnectivityManager.setDeviceMobilityState( + WifiManager.DEVICE_MOBILITY_STATE_HIGH_MVMT); + + // Set WiFi to disconnected state to trigger scan + mWifiConnectivityManager.handleConnectionStateChanged( + WifiConnectivityManager.WIFI_STATE_DISCONNECTED); + mLooper.dispatchAll(); + + // Verify there is no connection due to currently having no cached candidates. + verify(mClientModeImpl, never()).startConnectToNetwork( + CANDIDATE_NETWORK_ID, Process.WIFI_UID, CANDIDATE_BSSID); + + // Move time past HIGH_MVMT_SCAN_DELAY_MS. + when(mClock.getElapsedSinceBootMillis()).thenReturn((long) HIGH_MVMT_SCAN_DELAY_MS); + + // Mock the current Candidate to have RSSI over the filter threshold + mCandidateList.clear(); + mCandidateList.add(mCandidate2); + + // Set WiFi to disconnected state to trigger scan + mWifiConnectivityManager.handleConnectionStateChanged( + WifiConnectivityManager.WIFI_STATE_DISCONNECTED); + mLooper.dispatchAll(); + + // Verify connect is not started. + verify(mClientModeImpl, never()).startConnectToNetwork( + CANDIDATE_NETWORK_ID, Process.WIFI_UID, CANDIDATE_BSSID); + } + + /** * {@link OpenNetworkNotifier} handles scan results on network selection. * * Expected behavior: ONA handles scan results @@ -660,8 +812,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { @Test public void wifiDisconnected_noConnectionCandidate_openNetworkNotifierScanResultsHandled() { // no connection candidate selected - when(mWifiNS.selectNetwork(anyObject(), anyObject(), anyObject(), anyBoolean(), - anyBoolean(), anyBoolean())).thenReturn(null); + when(mWifiNS.selectNetwork(any())).thenReturn(null); List<ScanDetail> expectedOpenNetworks = new ArrayList<>(); expectedOpenNetworks.add( @@ -1652,9 +1803,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { candidateScanResult.SSID = CANDIDATE_SSID; candidateScanResult.BSSID = CANDIDATE_BSSID; candidate.getNetworkSelectionStatus().setCandidate(candidateScanResult); - - when(mWifiNS.selectNetwork(anyObject(), anyObject(), anyObject(), anyBoolean(), - anyBoolean(), anyBoolean())).thenReturn(candidate); + when(mWifiNS.selectNetwork(any())).thenReturn(candidate); // Set screen to on mWifiConnectivityManager.handleScreenStateChanged(true); @@ -1706,9 +1855,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { candidateScanResult.SSID = CANDIDATE_SSID; candidateScanResult.BSSID = CANDIDATE_BSSID; candidate.getNetworkSelectionStatus().setCandidate(candidateScanResult); - - when(mWifiNS.selectNetwork(anyObject(), anyObject(), anyObject(), anyBoolean(), - anyBoolean(), anyBoolean())).thenReturn(candidate); + when(mWifiNS.selectNetwork(any())).thenReturn(candidate); // Set screen to on mWifiConnectivityManager.handleScreenStateChanged(true); @@ -1796,9 +1943,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { // Set up the scan result BSSID to be different from the config specified one. candidateScanResult.BSSID = INVALID_SCAN_RESULT_BSSID; candidate.getNetworkSelectionStatus().setCandidate(candidateScanResult); - - when(mWifiNS.selectNetwork(anyObject(), anyObject(), anyObject(), anyBoolean(), - anyBoolean(), anyBoolean())).thenReturn(candidate); + when(mWifiNS.selectNetwork(any())).thenReturn(candidate); // Set screen to on mWifiConnectivityManager.handleScreenStateChanged(true); @@ -1836,9 +1981,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { // Set up the scan result BSSID to be different from the config specified one. candidateScanResult.BSSID = INVALID_SCAN_RESULT_BSSID; candidate.getNetworkSelectionStatus().setCandidate(candidateScanResult); - - when(mWifiNS.selectNetwork(anyObject(), anyObject(), anyObject(), anyBoolean(), - anyBoolean(), anyBoolean())).thenReturn(candidate); + when(mWifiNS.selectNetwork(any())).thenReturn(candidate); // Set WiFi to connected state mWifiConnectivityManager.handleConnectionStateChanged( @@ -1924,8 +2067,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { mResources.setBoolean( R.bool.config_wifi_framework_use_single_radio_chain_scan_results_network_selection, false); - when(mWifiNS.selectNetwork(any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean())) - .thenReturn(null); + when(mWifiNS.selectNetwork(any())).thenReturn(null); mWifiConnectivityManager = createConnectivityManager(); mScanData = createScanDataWithDifferentRadioChainInfos(); @@ -1933,13 +2075,13 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { // Capture scan details which were sent to network selector. final List<ScanDetail> capturedScanDetails = new ArrayList<>(); doAnswer(new AnswerWithArguments() { - public WifiConfiguration answer( + public List<WifiCandidates.Candidate> answer( List<ScanDetail> scanDetails, Set<String> bssidBlacklist, WifiInfo wifiInfo, boolean connected, boolean disconnected, boolean untrustedNetworkAllowed) throws Exception { capturedScanDetails.addAll(scanDetails); return null; - }}).when(mWifiNS).selectNetwork( + }}).when(mWifiNS).getCandidatesFromScan( any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean()); mWifiConnectivityManager.setTrustedConnectionAllowed(true); @@ -1980,8 +2122,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { mResources.setBoolean( R.bool.config_wifi_framework_use_single_radio_chain_scan_results_network_selection, true); - when(mWifiNS.selectNetwork(any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean())) - .thenReturn(null); + when(mWifiNS.selectNetwork(any())).thenReturn(null); mWifiConnectivityManager = createConnectivityManager(); mScanData = createScanDataWithDifferentRadioChainInfos(); @@ -1989,13 +2130,13 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { // Capture scan details which were sent to network selector. final List<ScanDetail> capturedScanDetails = new ArrayList<>(); doAnswer(new AnswerWithArguments() { - public WifiConfiguration answer( + public List<WifiCandidates.Candidate> answer( List<ScanDetail> scanDetails, Set<String> bssidBlacklist, WifiInfo wifiInfo, boolean connected, boolean disconnected, boolean untrustedNetworkAllowed) throws Exception { capturedScanDetails.addAll(scanDetails); return null; - }}).when(mWifiNS).selectNetwork( + }}).when(mWifiNS).getCandidatesFromScan( any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean()); mWifiConnectivityManager.setTrustedConnectionAllowed(true); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java index 0b91ea675..dcef7e11f 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java @@ -292,8 +292,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); HashSet<String> blacklist = new HashSet<String>(); - WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); assertEquals("Expect null configuration", null, candidate); assertTrue(mWifiNetworkSelector.getConnectableScanDetails().isEmpty()); } @@ -322,8 +323,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); HashSet<String> blacklist = new HashSet<String>(); - WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); assertEquals("Expect null configuration", null, candidate); assertTrue(mWifiNetworkSelector.getConnectableScanDetails().isEmpty()); } @@ -353,15 +355,17 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); HashSet<String> blacklist = new HashSet<String>(); - WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime() + WifiNetworkSelector.MINIMUM_NETWORK_SELECTION_INTERVAL_MS - 2000); // Do another network selection with CMI in CONNECTED state. - candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, true, false, false); + candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, true, false, false); + candidate = mWifiNetworkSelector.selectNetwork(candidates); assertEquals("Expect null configuration", null, candidate); assertTrue(mWifiNetworkSelector.getConnectableScanDetails().isEmpty()); @@ -395,16 +399,18 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); HashSet<String> blacklist = new HashSet<String>(); - WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate); when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime() + WifiNetworkSelector.MINIMUM_NETWORK_SELECTION_INTERVAL_MS - 2000); // Do another network selection with CMI in DISCONNECTED state. - candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, false, true, false); + candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + candidate = mWifiNetworkSelector.selectNetwork(candidates); ScanResult chosenScanResult = scanDetails.get(0).getScanResult(); WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate); @@ -439,7 +445,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); // connect to test1 - mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); when(mWifiInfo.getSupplicantState()).thenReturn(SupplicantState.COMPLETED); when(mWifiInfo.getNetworkId()).thenReturn(0); when(mWifiInfo.getBSSID()).thenReturn(bssids[0]); @@ -452,8 +460,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { + WifiNetworkSelector.MINIMUM_NETWORK_SELECTION_INTERVAL_MS + 2000); // Do another network selection. - WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, true, false, false); + candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, true, false, false); + candidate = mWifiNetworkSelector.selectNetwork(candidates); ScanResult chosenScanResult = scanDetails.get(0).getScanResult(); WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, @@ -487,7 +496,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); // connect to test1 - mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); when(mWifiInfo.getSupplicantState()).thenReturn(SupplicantState.COMPLETED); when(mWifiInfo.getNetworkId()).thenReturn(0); when(mWifiInfo.getBSSID()).thenReturn(bssids[0]); @@ -507,8 +518,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { savedConfigs[0].numNoInternetAccessReports = 5; // Do another network selection. - WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, true, false, false); + candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, true, false, false); + candidate = mWifiNetworkSelector.selectNetwork(candidates); ScanResult chosenScanResult = scanDetails.get(0).getScanResult(); WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, @@ -537,8 +549,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); // Do network selection. - mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, true, false, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, true, false, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); verify(mWifiMetrics).incrementNetworkSelectionFilteredBssidCount(0); verify(mWifiConfigManager).getConfiguredNetworks(); @@ -571,8 +584,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { HashSet<String> blacklist = new HashSet<String>(); blacklist.add(bssids[0]); - WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); verify(mWifiMetrics).incrementNetworkSelectionFilteredBssidCount(1); assertEquals("Expect null configuration", null, candidate); assertTrue(mWifiNetworkSelector.getConnectableScanDetails().isEmpty()); @@ -603,8 +617,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); HashSet<String> blacklist = new HashSet<String>(); - WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); when(mWifiInfo.getSupplicantState()).thenReturn(SupplicantState.COMPLETED); when(mWifiInfo.getNetworkId()).thenReturn(0); @@ -625,8 +640,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { int[] levelsNew = {mThresholdMinimumRssi2G + 40}; scanDetails = WifiNetworkSelectorTestUtil.buildScanDetails(ssidsNew, bssidsNew, freqsNew, capsNew, levelsNew, mClock); - candidate = mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, - true, false, false); + candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, true, false, false); + candidate = mWifiNetworkSelector.selectNetwork(candidates); // The second network selection is skipped since current connected network is // missing from the scan results. @@ -714,8 +730,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { .setCandidate(scanDetailsAndConfigs.getScanDetails().get(1).getScanResult()); // With no user choice set, networkSelectorChoice should be chosen. - WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); ArgumentCaptor<Integer> nominatorIdCaptor = ArgumentCaptor.forClass(int.class); verify(mWifiMetrics, atLeastOnce()).setNominatorForNetwork(eq(candidate.networkId), @@ -733,8 +750,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { assertTrue(mWifiNetworkSelector.setUserConnectChoice(userChoice.networkId)); // After user connect choice is set, userChoice should override networkSelectorChoice. - candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, false, true, false); + candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + candidate = mWifiNetworkSelector.selectNetwork(candidates); verify(mWifiMetrics, atLeastOnce()).setNominatorForNetwork(eq(candidate.networkId), nominatorIdCaptor.capture()); @@ -780,8 +798,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { userChoice.getNetworkSelectionStatus() .setCandidate(scanDetailsAndConfigs.getScanDetails().get(1).getScanResult()); - WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); ArgumentCaptor<Integer> nominatorIdCaptor = ArgumentCaptor.forClass(int.class); verify(mWifiMetrics, atLeastOnce()).setNominatorForNetwork(eq(candidate.networkId), @@ -979,8 +998,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { HashSet<String> blacklist = new HashSet<String>(); // DummyNetworkNominator always return the first network in the scan results // for connection, so this should connect to the first network. - WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, false, true, true); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, true); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); assertNotNull("Result should be not null", candidate); WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, scanDetails.get(0).getScanResult(), candidate); @@ -1002,8 +1022,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime() + WifiNetworkSelector.MINIMUM_NETWORK_SELECTION_INTERVAL_MS + 2000); - candidate = mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, - true, false, false); + candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, true, false, false); + candidate = mWifiNetworkSelector.selectNetwork(candidates); // DummyNetworkNominator always return the first network in the scan results // for connection, so if network selection is performed, the first network should @@ -1036,7 +1057,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { ssids, bssids, freqs, caps, levels, mClock); HashSet<String> blacklist = new HashSet<>(); - mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); List<ScanDetail> expectedOpenUnsavedNetworks = new ArrayList<>(); expectedOpenUnsavedNetworks.add(scanDetails.get(1)); assertEquals("Expect open unsaved networks", @@ -1066,8 +1089,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { ssids, bssids, freqs, caps, levels, mClock); HashSet<String> blacklist = new HashSet<>(); - mWifiNetworkSelector.selectNetwork( + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( unSavedScanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); assertEquals("Expect open unsaved networks", unSavedScanDetails, mWifiNetworkSelector.getFilteredScanDetailsForOpenUnsavedNetworks()); @@ -1077,8 +1101,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { freqs, caps, levels, securities, mWifiConfigManager, mClock); List<ScanDetail> savedScanDetails = scanDetailsAndConfigs.getScanDetails(); - mWifiNetworkSelector.selectNetwork( + candidates = mWifiNetworkSelector.getCandidatesFromScan( savedScanDetails, blacklist, mWifiInfo, false, true, false); + candidate = mWifiNetworkSelector.selectNetwork(candidates); // Saved networks are filtered out. assertTrue(mWifiNetworkSelector.getFilteredScanDetailsForOpenUnsavedNetworks().isEmpty()); } @@ -1103,7 +1128,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { HashSet<String> blacklist = new HashSet<>(); blacklist.add(bssids[0]); - mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); List<ScanDetail> expectedOpenUnsavedNetworks = new ArrayList<>(); expectedOpenUnsavedNetworks.add(scanDetails.get(1)); assertEquals("Expect open unsaved networks", @@ -1130,7 +1157,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { ssids, bssids, freqs, caps, levels, mClock); HashSet<String> blacklist = new HashSet<>(); - mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); assertTrue(mWifiNetworkSelector.getFilteredScanDetailsForOpenUnsavedNetworks().isEmpty()); } @@ -1168,7 +1197,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { ssids, bssids, freqs, caps, levels, mClock); HashSet<String> blacklist = new HashSet<>(); - mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); List<ScanDetail> expectedOpenUnsavedNetworks = new ArrayList<>(); expectedOpenUnsavedNetworks.add(scanDetails.get(1)); expectedOpenUnsavedNetworks.add(scanDetails.get(2)); @@ -1200,7 +1231,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { ssids, bssids, freqs, caps, levels, mClock); HashSet<String> blacklist = new HashSet<>(); - mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); List<ScanDetail> expectedOpenUnsavedNetworks = new ArrayList<>(); expectedOpenUnsavedNetworks.add(scanDetails.get(1)); assertEquals("Expect open unsaved networks", @@ -1225,9 +1258,10 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { mWifiNetworkSelector.registerCandidateScorer(mCandidateScorer); - WifiConfiguration selected = mWifiNetworkSelector.selectNetwork( + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( setUpTwoNetworks(-35, -40), EMPTY_BLACKLIST, mWifiInfo, false, true, true); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); verify(mCandidateScorer, atLeastOnce()).scoreCandidates(any()); } @@ -1344,7 +1378,7 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]"}; int[] levels = {mThresholdMinimumRssi2G + 1, mThresholdMinimumRssi5G + 1}; int[] securities = {SECURITY_EAP, SECURITY_EAP}; - HashSet<String> blackList = new HashSet<>(); + HashSet<String> blacklist = new HashSet<>(); ScanDetailsAndWifiConfigs scanDetailsAndConfigs = WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); @@ -1357,8 +1391,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { .thenReturn(existingConfig); mWifiNetworkSelector.registerNetworkNominator( new DummyNetworkNominator(0, DUMMY_NOMINATOR_ID_2)); - WifiConfiguration candidate = mWifiNetworkSelector - .selectNetwork(scanDetails, blackList, mWifiInfo, false, true, true); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, true); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); // Check if the wifiConfig is updated with the latest verify(mWifiConfigManager).addOrUpdateNetwork(existingConfig, existingConfig.creatorUid, existingConfig.creatorName); @@ -1395,8 +1430,9 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { freqs, caps, levels, securities, mWifiConfigManager, mClock, iesByteStream); List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); - WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, - blacklist, mWifiInfo, false, true, false); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blacklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); assertEquals("Expect null configuration", null, candidate); assertTrue(mWifiNetworkSelector.getConnectableScanDetails().isEmpty()); } |