From 07b8d667df82fa5ffda9cf7527cf910a25e00c8a Mon Sep 17 00:00:00 2001 From: Nate Jiang Date: Wed, 29 Apr 2020 14:20:34 -0700 Subject: Add overlay to control if ignore saved open network Bug: 154654080 Test: atest com.android.server.wifi Change-Id: I0e41dc95c1b6a2e0e9a0ab79aacab7fa7a846154 --- .../server/wifi/WifiNetworkSuggestionsManager.java | 4 ++ service/res/values/config.xml | 2 + service/res/values/overlayable.xml | 1 + .../wifi/WifiNetworkSuggestionsManagerTest.java | 52 ++++++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java index fc1b32d05..b83af52f2 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java +++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java @@ -2028,6 +2028,10 @@ public class WifiNetworkSuggestionsManager { */ public boolean shouldBeIgnoredBySecureSuggestionFromSameCarrier( @NonNull WifiConfiguration configuration, List scanDetails) { + if (!mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) { + return false; + } if (configuration == null || scanDetails == null || !configuration.isOpenNetwork()) { return false; } diff --git a/service/res/values/config.xml b/service/res/values/config.xml index c58ab196b..5d8a47ca9 100644 --- a/service/res/values/config.xml +++ b/service/res/values/config.xml @@ -412,4 +412,6 @@ cause the wifi stack to turn wifi off and wait for user input. Set to 0 to turn off recovery attempts and always turn off wifi on failures --> 2 + + true diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml index 687b6b9e8..60454728d 100644 --- a/service/res/values/overlayable.xml +++ b/service/res/values/overlayable.xml @@ -129,6 +129,7 @@ + diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java index 5018337d9..79c9c0a3e 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java @@ -3721,6 +3721,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testShouldNotBeIgnoredBySecureSuggestionFromSameCarrierWithoutSameOpenSuggestion() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(true); when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())) .thenReturn(true); WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); @@ -3746,6 +3749,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testShouldNotBeIgnoredBySecureSuggestionFromSameCarrierWithoutSecureSuggestion() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(true); when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())) .thenReturn(true); WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); @@ -3771,6 +3777,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @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(); @@ -3796,6 +3805,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testShouldNotBeIgnoredBySecureSuggestionFromDifferentCarrierId() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(true); when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())) .thenReturn(true); WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); @@ -3821,6 +3833,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testShouldNotBeIgnoredBySecureSuggestionFromSameCarrierWithAutojoinDisabled() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(true); when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())) .thenReturn(true); WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); @@ -3846,6 +3861,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testShouldNotBeIgnoredBySecureSuggestionFromSameCarrierWithDifferentMeterness() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(true); when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())) .thenReturn(true); WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); @@ -3872,6 +3890,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testShouldNotBeIgnoredBySecureSuggestionFromSameCarrierWithNetworkDisabled() { + when(mResources.getBoolean( + R.bool.config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable)) + .thenReturn(true); when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(anyInt())) .thenReturn(true); WifiConfiguration network1 = WifiConfigurationTestUtil.createOpenNetwork(); @@ -3902,8 +3923,39 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { .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 scanDetails = Arrays.asList(scanDetail1, scanDetail2); + // Both open and secure suggestions with same carrierId, + List 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(); -- cgit v1.2.3