From 564f3f8861c44011f73de533cc6c4372fed49e90 Mon Sep 17 00:00:00 2001 From: Nate Jiang Date: Thu, 30 Apr 2020 16:14:01 -0700 Subject: Remove auto-join check PasspointNetworkNominateHelper Move auto-join check to saved and suggestion nominator Bug: 155434194 Test: atest com.android.server.wifi Change-Id: I41e4d3d46a7a59e4f2201e1044f6bb514494f721 --- .../android/server/wifi/SavedNetworkNominator.java | 3 + .../hotspot2/PasspointNetworkNominateHelper.java | 3 - .../server/wifi/SavedNetworkNominatorTest.java | 25 ++++---- .../PasspointNetworkNominateHelperTest.java | 68 ---------------------- 4 files changed, 18 insertions(+), 81 deletions(-) diff --git a/service/java/com/android/server/wifi/SavedNetworkNominator.java b/service/java/com/android/server/wifi/SavedNetworkNominator.java index a3039096e..3070f09c8 100644 --- a/service/java/com/android/server/wifi/SavedNetworkNominator.java +++ b/service/java/com/android/server/wifi/SavedNetworkNominator.java @@ -166,6 +166,9 @@ public class SavedNetworkNominator implements WifiNetworkSelector.NetworkNominat mPasspointNetworkNominateHelper.getPasspointNetworkCandidates(scanDetails, false); for (Pair candidate : candidates) { WifiConfiguration config = candidate.second; + if (!config.allowAutojoin) { + continue; + } if (isNetworkSimBasedCredential(config) && !isSimBasedNetworkAbleToAutoJoin(config)) { continue; } diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelper.java b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelper.java index 0a5da1f7c..e1491aa7a 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelper.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelper.java @@ -146,9 +146,6 @@ public class PasspointNetworkNominateHelper { if (matchedProvider.first.isFromSuggestion() != isFromSuggestion) { continue; } - if (!matchedProvider.first.isAutojoinEnabled()) { - continue; - } List candidates = candidatesPerProvider .computeIfAbsent(matchedProvider.first, k -> new ArrayList<>()); candidates.add(new PasspointNetworkCandidate(matchedProvider.first, diff --git a/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java b/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java index 839b2e5fe..1fbb0f5be 100644 --- a/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java @@ -38,7 +38,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -225,21 +225,26 @@ public class SavedNetworkNominatorTest extends WifiBaseTest { } /** - * Ensure that we do nominate the only matching saved passponit network . + * Ensure that we do nominate the only matching saved passponit network with auto-join enabled . */ @Test - public void returnCandidatesIfPasspointNetworksAvailable() { - ScanDetail scanDetail = mock(ScanDetail.class); - List scanDetails = new ArrayList<>(); - scanDetails.add(scanDetail); - WifiConfiguration configuration = mock(WifiConfiguration.class); - List> passpointCandidates = new ArrayList<>(); - passpointCandidates.add(Pair.create(scanDetail, configuration)); + public void returnCandidatesIfPasspointNetworksAvailableWithAutojoinEnabled() { + ScanDetail scanDetail1 = mock(ScanDetail.class); + ScanDetail scanDetail2 = mock(ScanDetail.class); + List scanDetails = Arrays.asList(scanDetail1, scanDetail2); + WifiConfiguration configuration1 = mock(WifiConfiguration.class); + configuration1.allowAutojoin = true; + WifiConfiguration configuration2 = mock(WifiConfiguration.class); + configuration2.allowAutojoin = false; + List> passpointCandidates = + Arrays.asList(Pair.create(scanDetail1, configuration1), Pair.create(scanDetail2, + configuration2)); when(mPasspointNetworkNominateHelper.getPasspointNetworkCandidates(scanDetails, false)) .thenReturn(passpointCandidates); mSavedNetworkNominator.nominateNetworks(scanDetails, null, null, false, false, mOnConnectableListener); - verify(mOnConnectableListener).onConnectable(scanDetail, configuration); + verify(mOnConnectableListener).onConnectable(scanDetail1, configuration1); + verify(mOnConnectableListener, never()).onConnectable(scanDetail2, configuration2); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelperTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelperTest.java index 32fcb7093..a361a19bc 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelperTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelperTest.java @@ -319,74 +319,6 @@ public class PasspointNetworkNominateHelperTest { .addOrUpdateNetwork(any(), anyInt(), any()); } - /** - * Verify that when a network matches a roaming provider is found for different scanDetails, - * will nominate only the candidate with auto-join enabled. - */ - @Test - public void evaluateScansWithHomeProviderNetworkAndRoamingProviderNetworkAutoJoinSomeoff() { - List scanDetails = Arrays.asList(generateScanDetail(TEST_SSID1, TEST_BSSID1), - generateScanDetail(TEST_SSID2, TEST_BSSID2)); - - // Setup matching providers for ScanDetail with TEST_SSID1. - when(sTestProvider1.isAutojoinEnabled()).thenReturn(false); // disable auto-join on provider - List> homeProvider = new ArrayList<>(); - homeProvider.add(Pair.create(sTestProvider1, PasspointMatch.HomeProvider)); - List> roamingProvider = new ArrayList<>(); - roamingProvider.add(Pair.create(sTestProvider2, PasspointMatch.RoamingProvider)); - - // Return homeProvider for the first ScanDetail (TEST_SSID1) and - // roamingProvider for the second (TEST_SSID2); - when(mPasspointManager.matchProvider(any(ScanResult.class))) - .thenReturn(homeProvider).thenReturn(roamingProvider); - when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt(), - any())).thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID + 1)); - when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1); - when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID + 1)) - .thenReturn(TEST_CONFIG2); - List> candidates = mNominateHelper - .getPasspointNetworkCandidates(scanDetails, false); - assertEquals(1, candidates.size()); - assertEquals(TEST_FQDN2, candidates.get(0).second.FQDN); - - verify(mWifiConfigManager).addOrUpdateNetwork(any(), anyInt(), any()); - } - - /** - * Verify that when a network matches a roaming provider is found for different scanDetails, - * and if all have auto-join disabled - will nominate no candidates. - */ - @Test - public void evaluateScansWithHomeProviderNetworkAndRoamingProviderNetworkAutoJoinAllOff() { - List scanDetails = Arrays.asList(generateScanDetail(TEST_SSID1, TEST_BSSID1), - generateScanDetail(TEST_SSID2, TEST_BSSID2)); - - // Setup matching providers for ScanDetail with TEST_SSID1. - when(sTestProvider1.isAutojoinEnabled()).thenReturn(false); // disable auto-join on provider - when(sTestProvider2.isAutojoinEnabled()).thenReturn(false); // disable auto-join on provider - List> homeProvider = new ArrayList<>(); - homeProvider.add(Pair.create(sTestProvider1, PasspointMatch.HomeProvider)); - List> roamingProvider = new ArrayList<>(); - roamingProvider.add(Pair.create(sTestProvider2, PasspointMatch.RoamingProvider)); - - // Return homeProvider for the first ScanDetail (TEST_SSID1) and - // roamingProvider for the second (TEST_SSID2); - when(mPasspointManager.matchProvider(any(ScanResult.class))) - .thenReturn(homeProvider).thenReturn(roamingProvider); - when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt(), - any())).thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID)) - .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID + 1)); - when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1); - when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID + 1)) - .thenReturn(TEST_CONFIG2); - List> candidates = mNominateHelper - .getPasspointNetworkCandidates(scanDetails, false); - assertEquals(0, candidates.size()); - - verify(mWifiConfigManager, never()).addOrUpdateNetwork(any(), anyInt(), any()); - } - - /** * Verify that anonymous identity is empty when matching a SIM credential provider with a * network that supports encrypted IMSI and anonymous identity. The anonymous identity will be -- cgit v1.2.3