summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorNate(Qiang) Jiang <qiangjiang@google.com>2019-12-17 11:20:10 -0800
committerNate Jiang <qiangjiang@google.com>2020-01-09 23:45:18 +0000
commita5c2de11acece13adc8f60edb8feb47a1f6baab0 (patch)
tree0f3327deb5b4870abe589e565f3d9d30c4e01a55 /service
parentd48bb2934fbf8edc80bad3b10471771d19c06f13 (diff)
show suggestion in Wifi picker
Add function to get suggestions which user approved and allow user manually connect, to show in the wifi picker Bug: 146423406 Test: atest com.android.server.wifi Change-Id: I650b0a45cff12aeec46433b72c589ca1c4ed59f3
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java62
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java30
-rw-r--r--service/java/com/android/server/wifi/hotspot2/PasspointManager.java12
3 files changed, 102 insertions, 2 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
index 082ed0883..51997594a 100644
--- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
+++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
@@ -1208,6 +1208,68 @@ public class WifiNetworkSuggestionsManager {
}
/**
+ * Retrieve the WifiConfigurations for all matched suggestions which allow user manually connect
+ * and user already approved for non-open networks.
+ */
+ public @NonNull List<WifiConfiguration> getWifiConfigForMatchedNetworkSuggestionsSharedWithUser(
+ List<ScanResult> scanResults) {
+ List<WifiConfiguration> sharedWifiConfigs = new ArrayList<>();
+ for (ScanResult scanResult : scanResults) {
+ ScanResultMatchInfo scanResultMatchInfo =
+ ScanResultMatchInfo.fromScanResult(scanResult);
+ if (scanResultMatchInfo.networkType == WifiConfiguration.SECURITY_TYPE_OPEN) {
+ continue;
+ }
+ Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestions =
+ getNetworkSuggestionsForScanResultMatchInfo(
+ scanResultMatchInfo, MacAddress.fromString(scanResult.BSSID));
+ if (extNetworkSuggestions == null || extNetworkSuggestions.isEmpty()) {
+ continue;
+ }
+ Set<ExtendedWifiNetworkSuggestion> sharedNetworkSuggestions = extNetworkSuggestions
+ .stream()
+ .filter(ewns -> ewns.perAppInfo.hasUserApproved
+ && ewns.wns.isUserAllowedToManuallyConnect)
+ .collect(Collectors.toSet());
+ if (sharedNetworkSuggestions.isEmpty()) {
+ continue;
+ }
+ ExtendedWifiNetworkSuggestion ewns =
+ sharedNetworkSuggestions.stream().findFirst().get();
+ if (mVerboseLoggingEnabled) {
+ Log.v(TAG, "getWifiConfigForMatchedNetworkSuggestionsSharedWithUser Found "
+ + ewns + " for " + scanResult.SSID + "[" + scanResult.capabilities + "]");
+ }
+ WifiConfiguration config = ewns.wns.wifiConfiguration;
+ WifiConfiguration existingConfig = mWifiConfigManager
+ .getConfiguredNetwork(config.getKey());
+ if (existingConfig == null || !existingConfig.fromWifiNetworkSuggestion) {
+ continue;
+ }
+ sharedWifiConfigs.add(existingConfig);
+ }
+ return sharedWifiConfigs;
+ }
+
+ /**
+ * Check if the given passpoint suggestion has user approval and allow user manually connect.
+ */
+ public boolean isPasspointSuggestionSharedWithUser(WifiConfiguration config) {
+ Set<ExtendedWifiNetworkSuggestion> matchedSuggestions =
+ getNetworkSuggestionsForFqdnMatch(config.FQDN)
+ .stream().filter(ewns -> ewns.perAppInfo.uid == config.creatorUid)
+ .collect(Collectors.toSet());
+ if (matchedSuggestions.isEmpty()) {
+ Log.e(TAG, "Matched network suggestion is missing for FQDN:" + config.FQDN);
+ return false;
+ }
+ ExtendedWifiNetworkSuggestion suggestion = matchedSuggestions
+ .stream().findAny().get();
+ return suggestion.wns.isUserAllowedToManuallyConnect
+ && suggestion.perAppInfo.hasUserApproved;
+ }
+
+ /**
* Get hidden network from active network suggestions.
* Todo(): Now limit by a fixed number, maybe we can try rotation?
* @return set of WifiConfigurations
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 2bf5f473e..adf488659 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -2137,6 +2137,36 @@ public class WifiServiceImpl extends BaseWifiService {
}
/**
+ * Returns a list of Wifi configurations for matched available WifiNetworkSuggestion
+ * corresponding to the given scan results.
+ *
+ * An empty list will be returned when no match is found or all matched suggestions is not
+ * available(not allow user manually connect, user not approved or open network).
+ *
+ * @param scanResults a list of {@link ScanResult}.
+ * @return a list of {@link WifiConfiguration} from matched {@link WifiNetworkSuggestion}.
+ */
+ @Override
+ public List<WifiConfiguration> getWifiConfigForMatchedNetworkSuggestionsSharedWithUser(
+ List<ScanResult> scanResults) {
+ if (!isSettingsOrSuw(Binder.getCallingPid(), Binder.getCallingUid())) {
+ throw new SecurityException(TAG + ": Permission denied");
+ }
+ if (mVerboseLoggingEnabled) {
+ mLog.info("getWifiConfigsForMatchedNetworkSuggestions uid=%").c(
+ Binder.getCallingUid()).flush();
+ }
+ if (scanResults == null) {
+ Log.e(TAG, "Attempt to retrieve WifiConfiguration with null scanResult List");
+ return new ArrayList<>();
+ }
+ return mWifiThreadRunner.call(
+ () -> mWifiNetworkSuggestionsManager
+ .getWifiConfigForMatchedNetworkSuggestionsSharedWithUser(scanResults),
+ Collections.emptyList());
+ }
+
+ /**
* see {@link android.net.wifi.WifiManager#addOrUpdateNetwork(WifiConfiguration)}
* @return the supplicant-assigned identifier for the new or updated
* network if the operation succeeds, or {@code -1} if it fails
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
index 33c0b052f..964ae1508 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java
@@ -858,9 +858,17 @@ public class PasspointManager {
List<WifiConfiguration> configs = new ArrayList<>();
for (String fqdn : fqdnSet) {
PasspointProvider provider = mProviders.get(fqdn);
- if (provider != null) {
- configs.add(provider.getWifiConfig());
+ if (provider == null) {
+ continue;
+ }
+ WifiConfiguration config = provider.getWifiConfig();
+ // If passpoint is from suggestion, check if app share this suggestion with user.
+ if (provider.isFromSuggestion()
+ && !mWifiInjector.getWifiNetworkSuggestionsManager()
+ .isPasspointSuggestionSharedWithUser(config)) {
+ continue;
}
+ configs.add(config);
}
return configs;
}