diff options
author | Nate(Qiang) Jiang <qiangjiang@google.com> | 2019-11-26 15:48:59 -0800 |
---|---|---|
committer | Nate(Qiang) Jiang <qiangjiang@google.com> | 2019-12-09 10:23:20 -0800 |
commit | 669e0d67313f07fc5ad512857997a3717936d8bc (patch) | |
tree | 46031c4f9864e78021d4f06caa874c588f71e095 | |
parent | c87604e710b643b49da55b6e515ba239e003fca3 (diff) |
allows multiple passpoint candidates
Make WifiCandidates allows multiple passpoint candidates with same
provider but different scanDetails.
Bug: 144715355
Test: atest android.net.wifi
Test: atest com.android.server.wifi
Change-Id: Ic40a0e39b33478dd141edbee7bed480389ab5219
4 files changed, 78 insertions, 11 deletions
diff --git a/service/java/com/android/server/wifi/WifiCandidates.java b/service/java/com/android/server/wifi/WifiCandidates.java index 3553e4b63..1f6ed8dee 100644 --- a/service/java/com/android/server/wifi/WifiCandidates.java +++ b/service/java/com/android/server/wifi/WifiCandidates.java @@ -384,9 +384,13 @@ public class WifiCandidates { } catch (RuntimeException e) { return failWithException(e); } - ScanResultMatchInfo key1 = ScanResultMatchInfo.fromWifiConfiguration(config); - ScanResultMatchInfo key2 = ScanResultMatchInfo.fromScanResult(scanResult); - if (!key1.equals(key2)) return failure(key1, key2); + ScanResultMatchInfo key1 = ScanResultMatchInfo.fromScanResult(scanResult); + if (!config.isPasspoint()) { + ScanResultMatchInfo key2 = ScanResultMatchInfo.fromWifiConfiguration(config); + if (!key1.equals(key2)) { + return failure(key1, key2); + } + } Key key = new Key(key1, bssid, config.networkId); CandidateImpl old = mCandidates.get(key); if (old != null) { diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java index d1868872a..e794ef7bc 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSelector.java +++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java @@ -803,6 +803,7 @@ public class WifiNetworkSelector { chooses = " chooses "; legacyOverrideWanted = choice.userConnectChoiceOverride; selectedNetworkId = networkId; + updateChosenPasspointNetwork(choice); } String id = candidateScorer.getIdentifier(); int expid = experimentIdFromIdentifier(id); @@ -834,6 +835,18 @@ public class WifiNetworkSelector { return selectedNetwork; } + private void updateChosenPasspointNetwork(WifiCandidates.ScoredCandidate choice) { + if (choice.candidateKey == null) { + return; + } + WifiConfiguration config = + mWifiConfigManager.getConfiguredNetwork(choice.candidateKey.networkId); + if (config.isPasspoint()) { + config.SSID = choice.candidateKey.matchInfo.networkSsid; + mWifiConfigManager.addOrUpdateNetwork(config, config.creatorUid, config.creatorName); + } + } + private static int toProtoNominatorId(@NetworkNominator.NominatorId int nominatorId) { switch (nominatorId) { case NetworkNominator.NOMINATOR_ID_SAVED: diff --git a/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java b/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java index 386a83115..336bdbe24 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiCandidatesTest.java @@ -282,4 +282,21 @@ public class WifiCandidatesTest extends WifiBaseTest { assertEquals(90, c.getPredictedThroughputMbps()); assertEquals(15, c.getNominatorScore()); } + + /** + * Tests passpiont network from same provider(FQDN) can have multiple candidates with different + * scanDetails. + */ + @Test + public void testMultiplePasspointCandidatesWithSameFQDN() { + // Create a Passpoint WifiConfig + WifiConfiguration config1 = WifiConfigurationTestUtil.createPasspointNetwork(); + mScanResult2.BSSID = mScanResult1.BSSID.replace('1', '2'); + // Add candidates with different scanDetail for same passpoint WifiConfig. + assertTrue(mWifiCandidates.add(mScanDetail1, config1, 2, 0, 0.0, false, 100)); + assertTrue(mWifiCandidates.add(mScanDetail2, config1, 2, 0, 0.0, false, 100)); + // Both should survive and no faults. + assertEquals(2, mWifiCandidates.size()); + assertEquals(0, mWifiCandidates.getFaultCount()); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java index 039fb9920..a4744ff79 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java @@ -116,14 +116,14 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { public class DummyNetworkNominator implements WifiNetworkSelector.NetworkNominator { private static final String NAME = "DummyNetworkEvaluator"; - private boolean mEvaluatorShouldSelectCandidate = true; + private boolean mNominatorShouldSelectCandidate = true; private int mNetworkIndexToReturn; - private int mEvaluatorIdToReturn; + private int mNominatorIdToReturn; - public DummyNetworkNominator(int networkIndexToReturn, int evaluatorIdToReturn) { + public DummyNetworkNominator(int networkIndexToReturn, int nominatorIdToReturn) { mNetworkIndexToReturn = networkIndexToReturn; - mEvaluatorIdToReturn = evaluatorIdToReturn; + mNominatorIdToReturn = nominatorIdToReturn; } public DummyNetworkNominator() { @@ -140,7 +140,7 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { @Override public @NominatorId int getId() { - return mEvaluatorIdToReturn; + return mNominatorIdToReturn; } @Override @@ -152,10 +152,10 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { public void update(List<ScanDetail> scanDetails) {} /** - * Sets whether the evaluator should return a candidate for connection or null. + * Sets whether the nominator should return a candidate for connection or null. */ public void setEvaluatorToSelectCandidate(boolean shouldSelectCandidate) { - mEvaluatorShouldSelectCandidate = shouldSelectCandidate; + mNominatorShouldSelectCandidate = shouldSelectCandidate; } /** @@ -170,7 +170,7 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { WifiConfiguration currentNetwork, String currentBssid, boolean connected, boolean untrustedNetworkAllowed, @NonNull OnConnectableListener onConnectableListener) { - if (!mEvaluatorShouldSelectCandidate) { + if (!mNominatorShouldSelectCandidate) { return; } for (ScanDetail scanDetail : scanDetails) { @@ -198,6 +198,7 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { @Mock private WifiCandidates.CandidateScorer mCandidateScorer; @Mock private WifiMetrics mWifiMetrics; @Mock private WifiNative mWifiNative; + @Mock private WifiNetworkSelector.NetworkNominator mNetworkNominator; // For simulating the resources, we use a Spy on a MockResource // (which is really more of a stub than a mock, in spite if its name). @@ -1504,6 +1505,38 @@ public class WifiNetworkSelectorTest extends WifiBaseTest { } /** + * Tests that passpoint network candidate will update SSID with the latest scanDetail. + */ + @Test + public void testPasspointCandidateUpdateWithLatestScanDetail() { + String[] ssids = {"\"test1\"", "\"test2\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; + int[] freqs = {2437, 5180}; + 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<>(); + ScanDetailsAndWifiConfigs scanDetailsAndConfigs = + WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, + freqs, caps, levels, securities, mWifiConfigManager, mClock); + List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + WifiConfiguration[] configs = scanDetailsAndConfigs.getWifiConfigs(); + WifiConfiguration existingConfig = WifiConfigurationTestUtil.createPasspointNetwork(); + existingConfig.SSID = ssids[1]; + // Matched wifiConfig is an passpoint network with SSID from last scan. + when(mWifiConfigManager.getConfiguredNetwork(configs[0].networkId)) + .thenReturn(existingConfig); + mWifiNetworkSelector.registerNetworkNominator( + new DummyNetworkNominator(0, DUMMY_EVALUATOR_ID_2)); + WifiConfiguration candidate = mWifiNetworkSelector + .selectNetwork(scanDetails, blackList, mWifiInfo, false, true, true); + // Check if the wifiConfig is updated with the latest + verify(mWifiConfigManager).addOrUpdateNetwork(existingConfig, + existingConfig.creatorUid, existingConfig.creatorName); + assertEquals(ssids[0], candidate.SSID); + } + + /** * Test that network which are not accepting new connections(MBO * association disallowed attribute in beacons/probe responses) * are filtered out from network selection. |