wifi: update connectable networks for user selected networks
Network selection is run based on connectable networks, but they are
not updated properly.
As connectable networks are stored internally, moving getCandidatesForUserSelection()
to WifiNetworkSector to update connectable networks.
Bug: 225259099
Test: atest FrameworksWifiTests
connect to a network manually and check network selection is run
Change-Id: I9e3fa9cedf60638c0c15c6d884ea6728c997d85b
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java
index b88ebe6..fa4e4b6 100644
--- a/service/java/com/android/server/wifi/ClientModeImpl.java
+++ b/service/java/com/android/server/wifi/ClientModeImpl.java
@@ -6781,36 +6781,6 @@
}
}
- // Just add all results as candidates and let network selection chooses the proper one.
- private List<WifiCandidates.Candidate> getCandidatesForUserSelection(
- WifiConfiguration config, @NonNull List<ScanDetail> scanDetails) {
- if (scanDetails.size() == 0) {
- if (mVerboseLoggingEnabled) {
- Log.d(getTag(), "No scan result for the user selected network.");
- return null;
- }
- }
-
- WifiCandidates wifiCandidates = new WifiCandidates(mWifiScoreCard, mContext);
- for (ScanDetail scanDetail: scanDetails) {
- WifiCandidates.Key key = wifiCandidates.keyFromScanDetailAndConfig(
- scanDetail, config);
- if (key != null) {
- wifiCandidates.add(key, config,
- WifiNetworkSelector.NetworkNominator.NOMINATOR_ID_CURRENT,
- scanDetail.getScanResult().level,
- scanDetail.getScanResult().frequency,
- scanDetail.getScanResult().channelWidth,
- 0.0 /* lastSelectionWeightBetweenZeroAndOne */,
- false /* isMetered */,
- WifiNetworkSelector.isFromCarrierOrPrivilegedApp(config),
- 0 /* predictedThroughputMbps */);
- }
- }
- return wifiCandidates.getCandidates();
- }
-
-
private void selectCandidateSecurityParamsIfNecessary(
WifiConfiguration config,
List<ScanResult> scanResults) {
@@ -6826,8 +6796,8 @@
ScanResultUtil.createQuotedSsid(scanResult.SSID)))
.map(ScanDetail::new)
.collect(Collectors.toList());
- List<WifiCandidates.Candidate> candidates = getCandidatesForUserSelection(
- config, scanDetailsList);
+ List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector
+ .getCandidatesForUserSelection(config, scanDetailsList);
mWifiNetworkSelector.selectNetwork(candidates);
// Get the fresh copy again to retrieve the candidate security params.
WifiConfiguration freshConfig = mWifiConfigManager.getConfiguredNetwork(config.networkId);
diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java
index 5def05c..1ee5815 100644
--- a/service/java/com/android/server/wifi/WifiNetworkSelector.java
+++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java
@@ -1022,6 +1022,47 @@
}
/**
+ * Add all results as candidates for the user selected network and let network selection
+ * chooses the proper one for the user selected network.
+ * @param config The configuration for the user selected network.
+ * @param scanDetails List of ScanDetail for the user selected network.
+ * @return list of valid Candidate(s)
+ */
+ public List<WifiCandidates.Candidate> getCandidatesForUserSelection(
+ WifiConfiguration config, @NonNull List<ScanDetail> scanDetails) {
+ if (scanDetails.size() == 0) {
+ if (mVerboseLoggingEnabled) {
+ Log.d(TAG, "No scan result for the user selected network.");
+ return null;
+ }
+ }
+
+ mConnectableNetworks.clear();
+ WifiCandidates wifiCandidates = new WifiCandidates(mWifiScoreCard, mContext);
+ for (ScanDetail scanDetail: scanDetails) {
+ WifiCandidates.Key key = wifiCandidates.keyFromScanDetailAndConfig(
+ scanDetail, config);
+ if (null == key) continue;
+
+ boolean added = wifiCandidates.add(key, config,
+ WifiNetworkSelector.NetworkNominator.NOMINATOR_ID_CURRENT,
+ scanDetail.getScanResult().level,
+ scanDetail.getScanResult().frequency,
+ scanDetail.getScanResult().channelWidth,
+ 0.0 /* lastSelectionWeightBetweenZeroAndOne */,
+ false /* isMetered */,
+ WifiNetworkSelector.isFromCarrierOrPrivilegedApp(config),
+ 0 /* predictedThroughputMbps */);
+ if (!added) continue;
+
+ mConnectableNetworks.add(Pair.create(scanDetail, config));
+ mWifiConfigManager.updateScanDetailForNetwork(
+ config.networkId, scanDetail);
+ }
+ return wifiCandidates.getCandidates();
+ }
+
+ /**
* For transition networks with only legacy networks,
* remove auto-upgrade type to use the legacy type to
* avoid roaming issues between two types.
diff --git a/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
index 973678c..14fb3dd 100644
--- a/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
+++ b/service/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java
@@ -36,6 +36,7 @@
import android.app.admin.WifiSsidPolicy;
import android.content.Context;
import android.net.wifi.ScanResult;
+import android.net.wifi.SecurityParams;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
@@ -2856,4 +2857,29 @@
assertTrue(networkSelectorChoice.getNetworkSelectionStatus().getCandidateSecurityParams()
.isSecurityType(WifiConfiguration.SECURITY_TYPE_PSK));
}
+
+ /**
+ * Verify network selection for the user selected network.
+ */
+ @Test
+ public void testNetworkSelectionForUserSelectedNetwork() {
+ when(mClientModeManager.getSupportedFeatures()).thenReturn(WIFI_FEATURE_WPA3_SAE);
+ when(mWifiGlobals.isWpa3SaeUpgradeEnabled()).thenReturn(true);
+
+ ScanDetailsAndWifiConfigs scanDetailsAndConfigs = setupAutoUpgradeNetworks(
+ WifiConfigurationTestUtil.createPskSaeNetwork(TEST_AUTO_UPGRADE_SSID),
+ new String[] {"[RSN-PSK+SAE-CCMP][ESS]", "[RSN-PSK+SAE-CCMP][ESS]"});
+ List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails();
+ WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs();
+ WifiConfiguration userSelectedConfig = savedConfigs[0];
+ List<WifiCandidates.Candidate> candidates = mWifiNetworkSelector
+ .getCandidatesForUserSelection(userSelectedConfig, scanDetails);
+ WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(candidates);
+
+ ArgumentCaptor<SecurityParams> paramsCaptor =
+ ArgumentCaptor.forClass(SecurityParams.class);
+ verify(mWifiConfigManager).setNetworkCandidateScanResult(
+ eq(userSelectedConfig.networkId), any(), eq(0), paramsCaptor.capture());
+ assertTrue(paramsCaptor.getValue().isSecurityType(WifiConfiguration.SECURITY_TYPE_SAE));
+ }
}