From 9f756c8e97656f1edbb744de5b74a8ca693ae755 Mon Sep 17 00:00:00 2001 From: Nate Jiang Date: Tue, 21 Apr 2020 17:28:22 -0700 Subject: [Suggestion] Ignore open saved network When saved open network has a same network suggestion which is from an app with NETWORK_CARRIER_PROVISIONING permission, also that app suggested a secure network suggestion with same carrierId and a higher or equal priority is available to connect. The saved open network will be ignored during the network selection. Bug: 154654080 Test: atest com.android.server.wifi Change-Id: If170fd4ef23d049453b28e655b8305b95307fa01 --- .../android/server/wifi/SavedNetworkNominator.java | 13 ++- .../java/com/android/server/wifi/WifiInjector.java | 2 +- .../server/wifi/WifiNetworkSuggestionsManager.java | 111 +++++++++++++++++++-- 3 files changed, 116 insertions(+), 10 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/SavedNetworkNominator.java b/service/java/com/android/server/wifi/SavedNetworkNominator.java index a3039096e..6480237ef 100644 --- a/service/java/com/android/server/wifi/SavedNetworkNominator.java +++ b/service/java/com/android/server/wifi/SavedNetworkNominator.java @@ -39,16 +39,19 @@ public class SavedNetworkNominator implements WifiNetworkSelector.NetworkNominat private final WifiCarrierInfoManager mWifiCarrierInfoManager; private final PasspointNetworkNominateHelper mPasspointNetworkNominateHelper; private final WifiPermissionsUtil mWifiPermissionsUtil; + private final WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager; SavedNetworkNominator(WifiConfigManager configManager, PasspointNetworkNominateHelper nominateHelper, LocalLog localLog, WifiCarrierInfoManager wifiCarrierInfoManager, - WifiPermissionsUtil wifiPermissionsUtil) { + WifiPermissionsUtil wifiPermissionsUtil, + WifiNetworkSuggestionsManager wifiNetworkSuggestionsManager) { mWifiConfigManager = configManager; mPasspointNetworkNominateHelper = nominateHelper; mLocalLog = localLog; mWifiCarrierInfoManager = wifiCarrierInfoManager; mWifiPermissionsUtil = wifiPermissionsUtil; + mWifiNetworkSuggestionsManager = wifiNetworkSuggestionsManager; } private void localLog(String log) { @@ -155,6 +158,14 @@ public class SavedNetworkNominator implements WifiNetworkSelector.NetworkNominat continue; } + if (mWifiNetworkSuggestionsManager + .shouldBeIgnoredBySecureSuggestionFromSameCarrier(network, + scanDetails)) { + localLog("Open Network " + WifiNetworkSelector.toNetworkString(network) + + " has a secure network suggestion from same carrier."); + continue; + } + onConnectableListener.onConnectable(scanDetail, mWifiConfigManager.getConfiguredNetwork(network.networkId)); } diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index b56d37a2c..5dc3296c9 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -310,7 +310,7 @@ public class WifiInjector { mConnectivityLocalLog); mSavedNetworkNominator = new SavedNetworkNominator( mWifiConfigManager, nominateHelper, mConnectivityLocalLog, mWifiCarrierInfoManager, - mWifiPermissionsUtil); + mWifiPermissionsUtil, mWifiNetworkSuggestionsManager); mNetworkSuggestionNominator = new NetworkSuggestionNominator(mWifiNetworkSuggestionsManager, mWifiConfigManager, nominateHelper, mConnectivityLocalLog, mWifiCarrierInfoManager); mScoredNetworkNominator = new ScoredNetworkNominator(mContext, wifiHandler, diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java index 685df0757..fc1b32d05 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java +++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java @@ -1967,19 +1967,23 @@ public class WifiNetworkSuggestionsManager { if (suggestion == null || suggestion.wifiConfiguration == null) { continue; } - if (suggestion.passpointConfiguration != null) { - filteredScanResults.put(suggestion, - mWifiInjector.getPasspointManager().getMatchingScanResults( - suggestion.passpointConfiguration, scanResults)); - } else { - filteredScanResults.put(suggestion, - getMatchingScanResults(suggestion.wifiConfiguration, scanResults)); - } + filteredScanResults.put(suggestion, + getMatchingScanResultsForSuggestion(suggestion, scanResults)); } return filteredScanResults; } + private List getMatchingScanResultsForSuggestion(WifiNetworkSuggestion suggestion, + List scanResults) { + if (suggestion.passpointConfiguration != null) { + return mWifiInjector.getPasspointManager().getMatchingScanResults( + suggestion.passpointConfiguration, scanResults); + } else { + return getMatchingScanResults(suggestion.wifiConfiguration, scanResults); + } + } + /** * Get the filtered ScanResults which may be authenticated by the {@link WifiConfiguration}. * @param wifiConfiguration The instance of {@link WifiConfiguration} @@ -2012,6 +2016,97 @@ public class WifiNetworkSuggestionsManager { mListeners.add(listener); } + /** + * When a saved open network has a same network suggestion which is from app has + * NETWORK_CARRIER_PROVISIONING permission, also that app suggested secure network suggestion + * for same carrier with higher or equal priority and Auto-Join enabled, also that secure + * network is in the range. The saved open network will be ignored during the network selection. + * TODO (b/142035508): revert all these changes once we build infra needed to solve this. + * @param configuration Saved open network to check if it should be ignored. + * @param scanDetails Available ScanDetail nearby. + * @return True if the open network should be ignored, false otherwise. + */ + public boolean shouldBeIgnoredBySecureSuggestionFromSameCarrier( + @NonNull WifiConfiguration configuration, List scanDetails) { + if (configuration == null || scanDetails == null || !configuration.isOpenNetwork()) { + return false; + } + Set matchedExtSuggestions = + getNetworkSuggestionsForWifiConfiguration(configuration, null); + if (matchedExtSuggestions == null || matchedExtSuggestions.isEmpty()) { + return false; + } + matchedExtSuggestions = matchedExtSuggestions.stream().filter(ewns -> + mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(ewns.perAppInfo.uid)) + .collect(Collectors.toSet()); + if (matchedExtSuggestions.isEmpty()) { + return false; + } + for (ExtendedWifiNetworkSuggestion ewns : matchedExtSuggestions) { + if (hasSecureSuggestionFromSameCarrierAvailable(ewns, scanDetails)) { + return true; + } + } + return false; + } + + private boolean hasSecureSuggestionFromSameCarrierAvailable( + ExtendedWifiNetworkSuggestion extendedWifiNetworkSuggestion, + List scanDetails) { + boolean isOpenSuggestionMetered = WifiConfiguration.isMetered( + extendedWifiNetworkSuggestion.wns.wifiConfiguration, null); + Set secureExtSuggestions = new HashSet<>(); + for (ExtendedWifiNetworkSuggestion ewns : extendedWifiNetworkSuggestion.perAppInfo + .extNetworkSuggestions) { + // Open network and auto-join disable suggestion, ignore. + if (isOpenSuggestion(ewns) || !ewns.isAutojoinEnabled) { + continue; + } + // From different carrier as open suggestion, ignore. + if (getCarrierIdFromSuggestion(ewns) + != getCarrierIdFromSuggestion(extendedWifiNetworkSuggestion)) { + continue; + } + // Secure and open has different meterness, ignore + if (WifiConfiguration.isMetered(ewns.wns.wifiConfiguration, null) + != isOpenSuggestionMetered) { + continue; + } + // Low priority than open suggestion, ignore. + if (ewns.wns.wifiConfiguration.priority + < extendedWifiNetworkSuggestion.wns.wifiConfiguration.priority) { + continue; + } + WifiConfiguration wcmConfig = mWifiConfigManager + .getConfiguredNetwork(ewns.wns.wifiConfiguration.getKey()); + // Network selection is disabled, ignore. + if (wcmConfig != null && !wcmConfig.getNetworkSelectionStatus().isNetworkEnabled()) { + continue; + } + secureExtSuggestions.add(ewns); + } + + if (secureExtSuggestions.isEmpty()) { + return false; + } + List scanResults = scanDetails.stream().map(ScanDetail::getScanResult) + .collect(Collectors.toList()); + // Check if the secure suggestion is in the range. + for (ExtendedWifiNetworkSuggestion ewns : secureExtSuggestions) { + if (!getMatchingScanResultsForSuggestion(ewns.wns, scanResults).isEmpty()) { + return true; + } + } + return false; + } + + private boolean isOpenSuggestion(ExtendedWifiNetworkSuggestion extendedWifiNetworkSuggestion) { + if (extendedWifiNetworkSuggestion.wns.passpointConfiguration != null) { + return false; + } + return extendedWifiNetworkSuggestion.wns.wifiConfiguration.isOpenNetwork(); + } + /** * Dump of {@link WifiNetworkSuggestionsManager}. */ -- cgit v1.2.3 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 --- .../java/com/android/server/wifi/WifiNetworkSuggestionsManager.java | 4 ++++ service/res/values/config.xml | 2 ++ service/res/values/overlayable.xml | 1 + 3 files changed, 7 insertions(+) (limited to 'service') 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 @@ + -- cgit v1.2.3