diff options
author | Kai Shi <kaishi@google.com> | 2020-09-09 23:27:11 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-09-09 23:27:11 +0000 |
commit | 2a2fc39e77bf780fbb2e98255738c818c5927392 (patch) | |
tree | 21a2b4979a2acb45769fb02b7e228c7ac4ca3944 | |
parent | 22f265e77b3c293c1a9ef2c15aae06e6b8a9e27d (diff) | |
parent | e9cfb8f54b276b3b5afc72a9fb239aab48f4d86f (diff) |
Merge "wifi: bug fix of network selection when autoConnect == false" into rvc-qpr-dev
-rw-r--r-- | service/java/com/android/server/wifi/WifiNetworkSelector.java | 15 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java | 50 |
2 files changed, 64 insertions, 1 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java index 50078b628..fbbcb3174 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSelector.java +++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java @@ -462,6 +462,17 @@ public class WifiNetworkSelector { return validScanDetails; } + private ScanDetail findScanDetailForBssid(List<ScanDetail> scanDetails, + String currentBssid) { + for (ScanDetail scanDetail : scanDetails) { + ScanResult scanResult = scanDetail.getScanResult(); + if (scanResult.BSSID.equals(currentBssid)) { + return scanDetail; + } + } + return null; + } + private boolean isEnhancedOpenSupported() { if (mIsEnhancedOpenSupportedInitialized) { return mIsEnhancedOpenSupported; @@ -790,6 +801,8 @@ public class WifiNetworkSelector { WifiCandidates.Key key = new WifiCandidates.Key( ScanResultMatchInfo.fromWifiConfiguration(currentNetwork), bssid, currentNetwork.networkId); + ScanDetail scanDetail = findScanDetailForBssid(mFilteredNetworks, currentBssid); + int predictedTputMbps = (scanDetail == null) ? 0 : predictThroughput(scanDetail); wifiCandidates.add(key, currentNetwork, NetworkNominator.NOMINATOR_ID_CURRENT, wifiInfo.getRssi(), @@ -797,7 +810,7 @@ public class WifiNetworkSelector { calculateLastSelectionWeight(currentNetwork.networkId), WifiConfiguration.isMetered(currentNetwork, wifiInfo), isFromCarrierOrPrivilegedApp(currentNetwork), - 0 /* Mbps */); + predictedTputMbps); } for (NetworkNominator registeredNominator : mNominators) { localLog("About to run " + registeredNominator.getName() + " :"); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java index 0bd14a470..1507e9c55 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java @@ -741,6 +741,56 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { } /** + * Wifi network selector stays with current network if current network is not nominated + * but has the higher score + */ + @Test + public void includeCurrentNetworkWhenCurrentNetworkNotNominated() { + String[] ssids = {"\"test1\"", "\"test2\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; + int[] freqs = {2437, 5120}; + String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-PSK][ESS]"}; + int[] levels = {mThresholdMinimumRssi2G + 10, mThresholdMinimumRssi2G + 20}; + int[] securities = {SECURITY_EAP, SECURITY_PSK}; + // VHT cap IE + byte[] iesBytes = {(byte) 0x92, (byte) 0x01, (byte) 0x80, (byte) 0x33, (byte) 0xaa, + (byte) 0xff, (byte) 0x00, (byte) 0x00, (byte) 0xaa, (byte) 0xff, (byte) 0x00, + (byte) 0x00}; + byte[][] iesByteStream = {iesBytes, iesBytes}; + // Make a network selection to connect to test1. + ScanDetailsAndWifiConfigs scanDetailsAndConfigs = + WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, + freqs, caps, levels, securities, mWifiConfigManager, mClock, iesByteStream); + List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + assertEquals(2, scanDetails.size()); + HashSet<String> blocklist = new HashSet<String>(); + List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blocklist, mWifiInfo, false, true, false); + WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates); + + when(mWifiInfo.getSupplicantState()).thenReturn(SupplicantState.COMPLETED); + when(mWifiInfo.getNetworkId()).thenReturn(0); // 0 is current network + when(mWifiInfo.getBSSID()).thenReturn(bssids[0]); + when(mWifiInfo.is24GHz()).thenReturn(true); + when(mWifiInfo.getScore()).thenReturn(ConnectedScore.WIFI_TRANSITION_SCORE); + when(mWifiInfo.is5GHz()).thenReturn(false); + when(mWifiInfo.getFrequency()).thenReturn(2400); + when(mWifiInfo.getRssi()).thenReturn(levels[0]); + when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime() + + WifiNetworkSelector.MINIMUM_NETWORK_SELECTION_INTERVAL_MS + 2000); + + when(mThroughputPredictor.predictThroughput(any(), anyInt(), anyInt(), anyInt(), + anyInt(), anyInt(), anyInt(), anyInt(), anyBoolean())).thenReturn(100); + // Force to return 2nd network in the network nominator + mDummyNominator.setNetworkIndexToReturn(1); + + candidates = mWifiNetworkSelector.getCandidatesFromScan( + scanDetails, blocklist, mWifiInfo, true, false, false); + assertEquals(2, candidates.size()); + assertEquals(100, candidates.get(0).getPredictedThroughputMbps()); + } + + /** * If two qualified networks, test1 and test2, are in range when the user selects test2 over * test1, WifiNetworkSelector will override the NetworkSelector's choice to connect to test1 * with test2. |