summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SavedNetworkNominatorTest.java36
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java208
2 files changed, 243 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..5018337d9 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -3719,6 +3719,214 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
verify(listener).onSuggestionsRemoved(networkSuggestionList1);
}
+ @Test
+ public void testShouldNotBeIgnoredBySecureSuggestionFromSameCarrierWithoutSameOpenSuggestion() {
+ 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(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(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(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(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(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(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 testShouldBeIgnoredBySecureSuggestionFromSameCarrier() {
+ 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.
*