diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java | 36 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java | 260 |
2 files changed, 295 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java b/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java index 839b2e5fe..2a42c77e5 100644 --- a/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java @@ -54,12 +54,15 @@ public class SavedNetworkNominatorTest extends WifiBaseTest { mLocalLog = new LocalLog(512); mSavedNetworkNominator = new SavedNetworkNominator(mWifiConfigManager, mPasspointNetworkNominateHelper, mLocalLog, mWifiCarrierInfoManager, - mWifiPermissionsUtil); + mWifiPermissionsUtil, mWifiNetworkSuggestionsManager); when(mWifiCarrierInfoManager.isSimPresent(anyInt())).thenReturn(true); when(mWifiCarrierInfoManager.getBestMatchSubscriptionId(any())).thenReturn(VALID_SUBID); when(mWifiCarrierInfoManager.requiresImsiEncryption(VALID_SUBID)).thenReturn(true); when(mWifiCarrierInfoManager.isImsiEncryptionInfoAvailable(anyInt())).thenReturn(true); when(mWifiCarrierInfoManager.getMatchingSubId(TEST_CARRIER_ID)).thenReturn(VALID_SUBID); + when(mWifiNetworkSuggestionsManager + .shouldBeIgnoredBySecureSuggestionFromSameCarrier(any(), any())) + .thenReturn(false); } @@ -84,6 +87,7 @@ public class SavedNetworkNominatorTest extends WifiBaseTest { @Mock private WifiCarrierInfoManager mWifiCarrierInfoManager; @Mock private PasspointNetworkNominateHelper mPasspointNetworkNominateHelper; @Mock private WifiPermissionsUtil mWifiPermissionsUtil; + @Mock private WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager; private LocalLog mLocalLog; /** @@ -307,4 +311,34 @@ public class SavedNetworkNominatorTest extends WifiBaseTest { .thenReturn(false); when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true); } + + @Test + public void testIgnoreOpenNetworkWithSameNetworkSuggestionHasSecureNetworkFromSameCarrier() { + String[] ssids = {"\"test1\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3"}; + int[] freqs = {2470}; + String[] caps = {"[ESS]"}; + int[] levels = {RSSI_LEVEL}; + int[] securities = {SECURITY_NONE}; + + ScanDetailsAndWifiConfigs scanDetailsAndConfigs = + WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, + freqs, caps, levels, securities, mWifiConfigManager, mClock); + List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); + + when(mWifiNetworkSuggestionsManager + .shouldBeIgnoredBySecureSuggestionFromSameCarrier(any(), any())) + .thenReturn(true); + mSavedNetworkNominator.nominateNetworks(scanDetails, + null, null, true, false, mOnConnectableListener); + verify(mOnConnectableListener, never()).onConnectable(any(), any()); + + when(mWifiNetworkSuggestionsManager + .shouldBeIgnoredBySecureSuggestionFromSameCarrier(any(), any())) + .thenReturn(false); + mSavedNetworkNominator.nominateNetworks(scanDetails, + null, null, true, false, mOnConnectableListener); + verify(mOnConnectableListener).onConnectable(any(), any()); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java index 8fa2fa1aa..79c9c0a3e 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java @@ -3719,6 +3719,266 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { verify(listener).onSuggestionsRemoved(networkSuggestionList1); } + @Test + public void testShouldNotBeIgnoredBySecureSuggestionFromSameCarrierWithoutSameOpenSuggestion() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(true); + when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())) + .thenReturn(true); + WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); + ScanDetail scanDetail1 = createScanDetailForNetwork(network1); + network1.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion1 = new WifiNetworkSuggestion( + network1, null, false, false, true, true); + WifiConfiguration network2 = WifiConfigurationTestUtil.createPskNetwork(); + ScanDetail scanDetail2 = createScanDetailForNetwork(network2); + network2.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion2 = new WifiNetworkSuggestion( + network2, null, false, false, true, true); + + List<ScanDetail> scanDetails = Arrays.asList(scanDetail1, scanDetail2); + // Without same open suggestion in the framework, should not be ignored. + List<WifiNetworkSuggestion> suggestionList = Arrays.asList(suggestion2); + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.add(suggestionList, TEST_UID_1, + TEST_PACKAGE_1, TEST_FEATURE)); + assertFalse(mWifiNetworkSuggestionsManager + .shouldBeIgnoredBySecureSuggestionFromSameCarrier(network1, scanDetails)); + } + + @Test + public void testShouldNotBeIgnoredBySecureSuggestionFromSameCarrierWithoutSecureSuggestion() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(true); + when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())) + .thenReturn(true); + WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); + ScanDetail scanDetail1 = createScanDetailForNetwork(network1); + network1.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion1 = new WifiNetworkSuggestion( + network1, null, false, false, true, true); + WifiConfiguration network2 = WifiConfigurationTestUtil.createPskNetwork(); + ScanDetail scanDetail2 = createScanDetailForNetwork(network2); + network2.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion2 = new WifiNetworkSuggestion( + network2, null, false, false, true, true); + + List<ScanDetail> scanDetails = Arrays.asList(scanDetail1, scanDetail2); + // Without secure suggestion in the framework, should not be ignored. + List<WifiNetworkSuggestion> suggestionList = Arrays.asList(suggestion1); + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.add(suggestionList, TEST_UID_1, + TEST_PACKAGE_1, TEST_FEATURE)); + assertFalse(mWifiNetworkSuggestionsManager + .shouldBeIgnoredBySecureSuggestionFromSameCarrier(network1, scanDetails)); + } + + @Test + public void testShouldNotBeIgnoredWithoutCarrierProvisioningPermission() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(true); + when(mWifiCarrierInfoManager.getCarrierIdForPackageWithCarrierPrivileges(anyString())) + .thenReturn(TEST_CARRIER_ID); + WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); + ScanDetail scanDetail1 = createScanDetailForNetwork(network1); + network1.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion1 = new WifiNetworkSuggestion( + network1, null, false, false, true, true); + WifiConfiguration network2 = WifiConfigurationTestUtil.createPskNetwork(); + ScanDetail scanDetail2 = createScanDetailForNetwork(network2); + network2.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion2 = new WifiNetworkSuggestion( + network2, null, false, false, true, true); + + List<ScanDetail> scanDetails = Arrays.asList(scanDetail1, scanDetail2); + // Without CarrierProvisioningPermission, should not be ignored. + List<WifiNetworkSuggestion> suggestionList = Arrays.asList(suggestion1, suggestion2); + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.add(suggestionList, TEST_UID_1, + TEST_PACKAGE_1, TEST_FEATURE)); + assertFalse(mWifiNetworkSuggestionsManager + .shouldBeIgnoredBySecureSuggestionFromSameCarrier(network1, scanDetails)); + } + + @Test + public void testShouldNotBeIgnoredBySecureSuggestionFromDifferentCarrierId() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(true); + when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())) + .thenReturn(true); + WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); + ScanDetail scanDetail1 = createScanDetailForNetwork(network1); + network1.carrierId = VALID_CARRIER_ID; + WifiNetworkSuggestion suggestion1 = new WifiNetworkSuggestion( + network1, null, false, false, true, true); + WifiConfiguration network2 = WifiConfigurationTestUtil.createPskNetwork(); + ScanDetail scanDetail2 = createScanDetailForNetwork(network2); + network2.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion2 = new WifiNetworkSuggestion( + network2, null, false, false, true, true); + + List<ScanDetail> scanDetails = Arrays.asList(scanDetail1, scanDetail2); + // Open and secure suggestions have different carrierId, should not be ignored. + List<WifiNetworkSuggestion> suggestionList = Arrays.asList(suggestion1, suggestion2); + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.add(suggestionList, TEST_UID_1, + TEST_PACKAGE_1, TEST_FEATURE)); + assertFalse(mWifiNetworkSuggestionsManager + .shouldBeIgnoredBySecureSuggestionFromSameCarrier(network1, scanDetails)); + } + + @Test + public void testShouldNotBeIgnoredBySecureSuggestionFromSameCarrierWithAutojoinDisabled() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(true); + when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())) + .thenReturn(true); + WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); + ScanDetail scanDetail1 = createScanDetailForNetwork(network1); + network1.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion1 = new WifiNetworkSuggestion( + network1, null, false, false, true, true); + WifiConfiguration network2 = WifiConfigurationTestUtil.createPskNetwork(); + ScanDetail scanDetail2 = createScanDetailForNetwork(network2); + network2.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion2 = new WifiNetworkSuggestion( + network2, null, false, false, true, false); + + List<ScanDetail> scanDetails = Arrays.asList(scanDetail1, scanDetail2); + // Secure suggestions is auto-join disabled, should not be ignored. + List<WifiNetworkSuggestion> suggestionList = Arrays.asList(suggestion1, suggestion2); + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.add(suggestionList, TEST_UID_1, + TEST_PACKAGE_1, TEST_FEATURE)); + assertFalse(mWifiNetworkSuggestionsManager + .shouldBeIgnoredBySecureSuggestionFromSameCarrier(network1, scanDetails)); + } + + @Test + public void testShouldNotBeIgnoredBySecureSuggestionFromSameCarrierWithDifferentMeterness() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(true); + when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())) + .thenReturn(true); + WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); + ScanDetail scanDetail1 = createScanDetailForNetwork(network1); + network1.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion1 = new WifiNetworkSuggestion( + network1, null, false, false, true, true); + WifiConfiguration network2 = WifiConfigurationTestUtil.createPskNetwork(); + network2.meteredOverride = WifiConfiguration.METERED_OVERRIDE_METERED; + ScanDetail scanDetail2 = createScanDetailForNetwork(network2); + network2.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion2 = new WifiNetworkSuggestion( + network2, null, false, false, true, true); + + List<ScanDetail> scanDetails = Arrays.asList(scanDetail1, scanDetail2); + // Secure suggestions is auto-join disabled, should not be ignored. + List<WifiNetworkSuggestion> suggestionList = Arrays.asList(suggestion1, suggestion2); + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.add(suggestionList, TEST_UID_1, + TEST_PACKAGE_1, TEST_FEATURE)); + assertFalse(mWifiNetworkSuggestionsManager + .shouldBeIgnoredBySecureSuggestionFromSameCarrier(network1, scanDetails)); + } + + @Test + public void testShouldNotBeIgnoredBySecureSuggestionFromSameCarrierWithNetworkDisabled() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(true); + when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())) + .thenReturn(true); + WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); + ScanDetail scanDetail1 = createScanDetailForNetwork(network1); + network1.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion1 = new WifiNetworkSuggestion( + network1, null, false, false, true, true); + WifiConfiguration network2 = WifiConfigurationTestUtil.createPskNetwork(); + ScanDetail scanDetail2 = createScanDetailForNetwork(network2); + network2.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion2 = new WifiNetworkSuggestion( + network2, null, false, false, true, true); + + WifiConfiguration wcmConfig = new WifiConfiguration(network2); + WifiConfiguration.NetworkSelectionStatus status = + mock(WifiConfiguration.NetworkSelectionStatus.class); + when(status.isNetworkEnabled()).thenReturn(false); + wcmConfig.setNetworkSelectionStatus(status); + when(mWifiConfigManager.getConfiguredNetwork(network2.getKey())).thenReturn(wcmConfig); + + List<ScanDetail> scanDetails = Arrays.asList(scanDetail1, scanDetail2); + // Secure suggestions is auto-join disabled, should not be ignored. + List<WifiNetworkSuggestion> suggestionList = Arrays.asList(suggestion1, suggestion2); + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.add(suggestionList, TEST_UID_1, + TEST_PACKAGE_1, TEST_FEATURE)); + assertFalse(mWifiNetworkSuggestionsManager + .shouldBeIgnoredBySecureSuggestionFromSameCarrier(network1, scanDetails)); + } + + @Test + public void testShouldNotBeIgnoredBySecureSuggestionFromSameCarrierWithOverlayFalse() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(false); + when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())) + .thenReturn(true); + WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); + ScanDetail scanDetail1 = createScanDetailForNetwork(network1); + network1.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion1 = new WifiNetworkSuggestion( + network1, null, false, false, true, true); + WifiConfiguration network2 = WifiConfigurationTestUtil.createPskNetwork(); + ScanDetail scanDetail2 = createScanDetailForNetwork(network2); + network2.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion2 = new WifiNetworkSuggestion( + network2, null, false, false, true, true); + + List<ScanDetail> scanDetails = Arrays.asList(scanDetail1, scanDetail2); + // Both open and secure suggestions with same carrierId, + List<WifiNetworkSuggestion> suggestionList = Arrays.asList(suggestion1, suggestion2); + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.add(suggestionList, TEST_UID_1, + TEST_PACKAGE_1, TEST_FEATURE)); + assertFalse(mWifiNetworkSuggestionsManager + .shouldBeIgnoredBySecureSuggestionFromSameCarrier(network1, scanDetails)); + } + + @Test + public void testShouldBeIgnoredBySecureSuggestionFromSameCarrier() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(true); + when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())) + .thenReturn(true); + WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); + ScanDetail scanDetail1 = createScanDetailForNetwork(network1); + network1.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion1 = new WifiNetworkSuggestion( + network1, null, false, false, true, true); + WifiConfiguration network2 = WifiConfigurationTestUtil.createPskNetwork(); + ScanDetail scanDetail2 = createScanDetailForNetwork(network2); + network2.carrierId = TEST_CARRIER_ID; + WifiNetworkSuggestion suggestion2 = new WifiNetworkSuggestion( + network2, null, false, false, true, true); + + List<ScanDetail> scanDetails = Arrays.asList(scanDetail1, scanDetail2); + // Both open and secure suggestions with same carrierId, + List<WifiNetworkSuggestion> suggestionList = Arrays.asList(suggestion1, suggestion2); + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.add(suggestionList, TEST_UID_1, + TEST_PACKAGE_1, TEST_FEATURE)); + assertTrue(mWifiNetworkSuggestionsManager + .shouldBeIgnoredBySecureSuggestionFromSameCarrier(network1, scanDetails)); + } + /** * Helper function for creating a test configuration with user credential. * |