diff options
16 files changed, 892 insertions, 289 deletions
diff --git a/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java b/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java index 9627a9daa..5babd3830 100644 --- a/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java +++ b/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java @@ -19,6 +19,7 @@ package com.android.server.wifi; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiEnterpriseConfig; import android.net.wifi.WifiNetworkSuggestion; +import android.net.wifi.hotspot2.PasspointConfiguration; import android.os.Process; import android.util.Log; import android.util.Pair; @@ -26,6 +27,7 @@ import android.util.Pair; import com.android.internal.util.XmlUtils; import com.android.server.wifi.WifiNetworkSuggestionsManager.ExtendedWifiNetworkSuggestion; import com.android.server.wifi.WifiNetworkSuggestionsManager.PerAppInfo; +import com.android.server.wifi.hotspot2.PasspointXmlUtils; import com.android.server.wifi.util.XmlUtil; import com.android.server.wifi.util.XmlUtil.WifiConfigurationXmlUtil; @@ -61,6 +63,8 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData { private static final String XML_TAG_SUGGESTOR_PACKAGE_NAME = "SuggestorPackageName"; private static final String XML_TAG_SUGGESTOR_HAS_USER_APPROVED = "SuggestorHasUserApproved"; private static final String XML_TAG_SUGGESTOR_MAX_SIZE = "SuggestorMaxSize"; + private static final String XML_TAG_SECTION_HEADER_PASSPOINT_CONFIGURATION = + "PasspointConfiguration"; /** * Interface define the data source for the network suggestions store data. @@ -199,6 +203,12 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData { out, suggestion.wifiConfiguration.enterpriseConfig); XmlUtil.writeNextSectionEnd(out, XML_TAG_SECTION_HEADER_WIFI_ENTERPRISE_CONFIGURATION); } + if (suggestion.passpointConfiguration != null) { + XmlUtil.writeNextSectionStart(out, XML_TAG_SECTION_HEADER_PASSPOINT_CONFIGURATION); + PasspointXmlUtils.serializePasspointConfiguration(out, + suggestion.passpointConfiguration); + XmlUtil.writeNextSectionEnd(out, XML_TAG_SECTION_HEADER_PASSPOINT_CONFIGURATION); + } // Serialize other fields XmlUtil.writeNextValue(out, XML_TAG_IS_APP_INTERACTION_REQUIRED, @@ -283,6 +293,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData { throws XmlPullParserException, IOException { Pair<String, WifiConfiguration> parsedConfig = null; WifiEnterpriseConfig enterpriseConfig = null; + PasspointConfiguration passpointConfiguration = null; boolean isAppInteractionRequired = false; boolean isUserInteractionRequired = false; int suggestorUid = Process.INVALID_UID; @@ -334,6 +345,14 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData { enterpriseConfig = XmlUtil.WifiEnterpriseConfigXmlUtil.parseFromXml( in, outerTagDepth + 1); break; + case XML_TAG_SECTION_HEADER_PASSPOINT_CONFIGURATION: + if (passpointConfiguration != null) { + throw new XmlPullParserException("Detected duplicate tag for: " + + XML_TAG_SECTION_HEADER_PASSPOINT_CONFIGURATION); + } + passpointConfiguration = PasspointXmlUtils + .deserializePasspointConfiguration(in, outerTagDepth + 1); + break; default: throw new XmlPullParserException("Unknown tag under " + XML_TAG_SECTION_HEADER_NETWORK_SUGGESTION + ": " + in.getName()); @@ -354,8 +373,8 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData { wifiConfiguration.enterpriseConfig = enterpriseConfig; } return new WifiNetworkSuggestion( - wifiConfiguration, isAppInteractionRequired, isUserInteractionRequired, - suggestorUid, suggestorPackageName); + wifiConfiguration, passpointConfiguration, isAppInteractionRequired, + isUserInteractionRequired, suggestorUid, suggestorPackageName); } } diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java index b970330b7..2a264b37d 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java +++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java @@ -235,6 +235,9 @@ public class WifiNetworkSuggestionsManager { */ private Set<ExtendedWifiNetworkSuggestion> mActiveNetworkSuggestionsMatchingConnection; + private final Map<String, Set<ExtendedWifiNetworkSuggestion>> + mPasspointInfo = new HashMap<>(); + /** * Intent filter for processing notification actions. */ @@ -307,7 +310,6 @@ public class WifiNetworkSuggestionsManager { } @Override - public void fromDeserialized(Map<String, PerAppInfo> networkSuggestionsMap) { mActiveNetworkSuggestionsPerApp.putAll(networkSuggestionsMap); // Build the scan cache. @@ -320,7 +322,13 @@ public class WifiNetworkSuggestionsManager { startTrackingAppOpsChange(packageName, extNetworkSuggestions.iterator().next().wns.suggestorUid); } - addToScanResultMatchInfoMap(extNetworkSuggestions); + for (ExtendedWifiNetworkSuggestion ewns : extNetworkSuggestions) { + if (ewns.wns.wifiConfiguration.FQDN != null) { + addToPasspointInfoMap(ewns); + } else { + addToScanResultMatchInfoMap(ewns); + } + } } } @@ -329,6 +337,7 @@ public class WifiNetworkSuggestionsManager { mActiveNetworkSuggestionsPerApp.clear(); mActiveScanResultMatchInfoWithBssid.clear(); mActiveScanResultMatchInfoWithNoBssid.clear(); + mPasspointInfo.clear(); } @Override @@ -426,79 +435,102 @@ public class WifiNetworkSuggestionsManager { } private void addToScanResultMatchInfoMap( - @NonNull Collection<ExtendedWifiNetworkSuggestion> extNetworkSuggestions) { - for (ExtendedWifiNetworkSuggestion extNetworkSuggestion : extNetworkSuggestions) { - ScanResultMatchInfo scanResultMatchInfo = - ScanResultMatchInfo.fromWifiConfiguration( - extNetworkSuggestion.wns.wifiConfiguration); - Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestionsForScanResultMatchInfo; - if (!TextUtils.isEmpty(extNetworkSuggestion.wns.wifiConfiguration.BSSID)) { - Pair<ScanResultMatchInfo, MacAddress> lookupPair = - Pair.create(scanResultMatchInfo, - MacAddress.fromString( - extNetworkSuggestion.wns.wifiConfiguration.BSSID)); - extNetworkSuggestionsForScanResultMatchInfo = - mActiveScanResultMatchInfoWithBssid.get(lookupPair); - if (extNetworkSuggestionsForScanResultMatchInfo == null) { - extNetworkSuggestionsForScanResultMatchInfo = new HashSet<>(); - mActiveScanResultMatchInfoWithBssid.put( - lookupPair, extNetworkSuggestionsForScanResultMatchInfo); - } - } else { - extNetworkSuggestionsForScanResultMatchInfo = - mActiveScanResultMatchInfoWithNoBssid.get(scanResultMatchInfo); - if (extNetworkSuggestionsForScanResultMatchInfo == null) { - extNetworkSuggestionsForScanResultMatchInfo = new HashSet<>(); - mActiveScanResultMatchInfoWithNoBssid.put( - scanResultMatchInfo, extNetworkSuggestionsForScanResultMatchInfo); - } + @NonNull ExtendedWifiNetworkSuggestion extNetworkSuggestion) { + ScanResultMatchInfo scanResultMatchInfo = + ScanResultMatchInfo.fromWifiConfiguration( + extNetworkSuggestion.wns.wifiConfiguration); + Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestionsForScanResultMatchInfo; + if (!TextUtils.isEmpty(extNetworkSuggestion.wns.wifiConfiguration.BSSID)) { + Pair<ScanResultMatchInfo, MacAddress> lookupPair = + Pair.create(scanResultMatchInfo, + MacAddress.fromString( + extNetworkSuggestion.wns.wifiConfiguration.BSSID)); + extNetworkSuggestionsForScanResultMatchInfo = + mActiveScanResultMatchInfoWithBssid.get(lookupPair); + if (extNetworkSuggestionsForScanResultMatchInfo == null) { + extNetworkSuggestionsForScanResultMatchInfo = new HashSet<>(); + mActiveScanResultMatchInfoWithBssid.put( + lookupPair, extNetworkSuggestionsForScanResultMatchInfo); + } + } else { + extNetworkSuggestionsForScanResultMatchInfo = + mActiveScanResultMatchInfoWithNoBssid.get(scanResultMatchInfo); + if (extNetworkSuggestionsForScanResultMatchInfo == null) { + extNetworkSuggestionsForScanResultMatchInfo = new HashSet<>(); + mActiveScanResultMatchInfoWithNoBssid.put( + scanResultMatchInfo, extNetworkSuggestionsForScanResultMatchInfo); } - extNetworkSuggestionsForScanResultMatchInfo.remove(extNetworkSuggestion); - extNetworkSuggestionsForScanResultMatchInfo.add(extNetworkSuggestion); } + extNetworkSuggestionsForScanResultMatchInfo.remove(extNetworkSuggestion); + extNetworkSuggestionsForScanResultMatchInfo.add(extNetworkSuggestion); } private void removeFromScanResultMatchInfoMap( - @NonNull Collection<ExtendedWifiNetworkSuggestion> extNetworkSuggestions) { - for (ExtendedWifiNetworkSuggestion extNetworkSuggestion : extNetworkSuggestions) { - ScanResultMatchInfo scanResultMatchInfo = - ScanResultMatchInfo.fromWifiConfiguration( - extNetworkSuggestion.wns.wifiConfiguration); - Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestionsForScanResultMatchInfo; - if (!TextUtils.isEmpty(extNetworkSuggestion.wns.wifiConfiguration.BSSID)) { - Pair<ScanResultMatchInfo, MacAddress> lookupPair = - Pair.create(scanResultMatchInfo, - MacAddress.fromString( - extNetworkSuggestion.wns.wifiConfiguration.BSSID)); - extNetworkSuggestionsForScanResultMatchInfo = - mActiveScanResultMatchInfoWithBssid.get(lookupPair); - // This should never happen because we should have done necessary error checks in - // the parent method. - if (extNetworkSuggestionsForScanResultMatchInfo == null) { - Log.wtf(TAG, "No scan result match info found."); - } - extNetworkSuggestionsForScanResultMatchInfo.remove(extNetworkSuggestion); - // Remove the set from map if empty. - if (extNetworkSuggestionsForScanResultMatchInfo.isEmpty()) { - mActiveScanResultMatchInfoWithBssid.remove(lookupPair); - } - } else { - extNetworkSuggestionsForScanResultMatchInfo = - mActiveScanResultMatchInfoWithNoBssid.get(scanResultMatchInfo); - // This should never happen because we should have done necessary error checks in - // the parent method. - if (extNetworkSuggestionsForScanResultMatchInfo == null) { - Log.wtf(TAG, "No scan result match info found."); - } - extNetworkSuggestionsForScanResultMatchInfo.remove(extNetworkSuggestion); - // Remove the set from map if empty. - if (extNetworkSuggestionsForScanResultMatchInfo.isEmpty()) { - mActiveScanResultMatchInfoWithNoBssid.remove(scanResultMatchInfo); - } + @NonNull ExtendedWifiNetworkSuggestion extNetworkSuggestion) { + ScanResultMatchInfo scanResultMatchInfo = + ScanResultMatchInfo.fromWifiConfiguration( + extNetworkSuggestion.wns.wifiConfiguration); + Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestionsForScanResultMatchInfo; + if (!TextUtils.isEmpty(extNetworkSuggestion.wns.wifiConfiguration.BSSID)) { + Pair<ScanResultMatchInfo, MacAddress> lookupPair = + Pair.create(scanResultMatchInfo, + MacAddress.fromString( + extNetworkSuggestion.wns.wifiConfiguration.BSSID)); + extNetworkSuggestionsForScanResultMatchInfo = + mActiveScanResultMatchInfoWithBssid.get(lookupPair); + // This should never happen because we should have done necessary error checks in + // the parent method. + if (extNetworkSuggestionsForScanResultMatchInfo == null) { + Log.wtf(TAG, "No scan result match info found."); + return; + } + extNetworkSuggestionsForScanResultMatchInfo.remove(extNetworkSuggestion); + // Remove the set from map if empty. + if (extNetworkSuggestionsForScanResultMatchInfo.isEmpty()) { + mActiveScanResultMatchInfoWithBssid.remove(lookupPair); + } + } else { + extNetworkSuggestionsForScanResultMatchInfo = + mActiveScanResultMatchInfoWithNoBssid.get(scanResultMatchInfo); + // This should never happen because we should have done necessary error checks in + // the parent method. + if (extNetworkSuggestionsForScanResultMatchInfo == null) { + Log.wtf(TAG, "No scan result match info found."); + return; } + extNetworkSuggestionsForScanResultMatchInfo.remove(extNetworkSuggestion); + // Remove the set from map if empty. + if (extNetworkSuggestionsForScanResultMatchInfo.isEmpty()) { + mActiveScanResultMatchInfoWithNoBssid.remove(scanResultMatchInfo); + } + } + } + + private void addToPasspointInfoMap(ExtendedWifiNetworkSuggestion ewns) { + Set<ExtendedWifiNetworkSuggestion> extendedWifiNetworkSuggestions = + mPasspointInfo.get(ewns.wns.wifiConfiguration.FQDN); + if (extendedWifiNetworkSuggestions == null) { + extendedWifiNetworkSuggestions = new HashSet<>(); + } + extendedWifiNetworkSuggestions.add(ewns); + mPasspointInfo.put(ewns.wns.wifiConfiguration.FQDN, extendedWifiNetworkSuggestions); + } + + private void removeFromPassPointInfoMap(ExtendedWifiNetworkSuggestion ewns) { + Set<ExtendedWifiNetworkSuggestion> extendedWifiNetworkSuggestions = + mPasspointInfo.get(ewns.wns.wifiConfiguration.FQDN); + if (extendedWifiNetworkSuggestions == null + || !extendedWifiNetworkSuggestions.contains(ewns)) { + Log.wtf(TAG, "No Passpoint info found."); + return; + } + extendedWifiNetworkSuggestions.remove(ewns); + if (extendedWifiNetworkSuggestions.isEmpty()) { + mPasspointInfo.remove(ewns.wns.wifiConfiguration.FQDN); } } + // Issues a disconnect if the only serving network suggestion is removed. private void removeFromConfigManagerIfServingNetworkSuggestionRemoved( Collection<ExtendedWifiNetworkSuggestion> extNetworkSuggestionsRemoved) { @@ -598,11 +630,24 @@ public class WifiNetworkSuggestionsManager { // Start tracking app-op changes from the app if they have active suggestions. startTrackingAppOpsChange(packageName, uid); } - perAppInfo.extNetworkSuggestions.removeAll(extNetworkSuggestions); - perAppInfo.extNetworkSuggestions.addAll(extNetworkSuggestions); + for (ExtendedWifiNetworkSuggestion ewns: extNetworkSuggestions) { + if (ewns.wns.passpointConfiguration == null) { + addToScanResultMatchInfoMap(ewns); + } else { + // Install Passpoint config, if failure, ignore that suggestion + if (!mWifiInjector.getPasspointManager().addOrUpdateProvider( + ewns.wns.passpointConfiguration, uid, + packageName, true)) { + Log.e(TAG, "Passpoint profile install failure."); + continue; + } + addToPasspointInfoMap(ewns); + } + perAppInfo.extNetworkSuggestions.remove(ewns); + perAppInfo.extNetworkSuggestions.add(ewns); + } // Update the max size for this app. perAppInfo.maxSize = Math.max(perAppInfo.extNetworkSuggestions.size(), perAppInfo.maxSize); - addToScanResultMatchInfoMap(extNetworkSuggestions); saveToStore(); mWifiMetrics.incrementNetworkSuggestionApiNumModification(); mWifiMetrics.noteNetworkSuggestionApiListSizeHistogram(getAllMaxSizes()); @@ -642,10 +687,21 @@ public class WifiNetworkSuggestionsManager { // Stop tracking app-op changes from the app if they don't have active suggestions. stopTrackingAppOpsChange(packageName); } + // Clear the cache. + for (ExtendedWifiNetworkSuggestion ewns : extNetworkSuggestions) { + if (ewns.wns.wifiConfiguration.FQDN != null) { + // Clear the Passpoint config. + mWifiInjector.getPasspointManager().removeProvider( + ewns.wns.suggestorUid, + false, + ewns.wns.wifiConfiguration.FQDN); + removeFromPassPointInfoMap(ewns); + } else { + removeFromScanResultMatchInfoMap(ewns); + } + } // Disconnect suggested network if connected removeFromConfigManagerIfServingNetworkSuggestionRemoved(extNetworkSuggestions); - // Clear the scan cache. - removeFromScanResultMatchInfoMap(extNetworkSuggestions); } /** @@ -827,15 +883,26 @@ public class WifiNetworkSuggestionsManager { mUserApprovalNotificationPackageName = packageName; } - private boolean sendUserApprovalNotificationIfNotApproved( - @NonNull PerAppInfo perAppInfo, - @NonNull WifiNetworkSuggestion matchingSuggestion) { - if (perAppInfo.hasUserApproved) { + /** + * Send user approval notification if the app is not approved + * @param packageName app package name + * @param uid app UID + * @return true if app is not approved and send notification. + */ + public boolean sendUserApprovalNotificationIfNotApproved( + @NonNull String packageName, @NonNull int uid) { + if (!mActiveNetworkSuggestionsPerApp.containsKey(packageName)) { + Log.wtf(TAG, "AppInfo is missing for " + packageName); + return false; + } + if (mActiveNetworkSuggestionsPerApp.get(packageName).hasUserApproved) { return false; // already approved. } - Log.i(TAG, "Sending user approval notification for " + perAppInfo.packageName); - sendUserApprovalNotification(perAppInfo.packageName, matchingSuggestion.suggestorUid); + Log.i(TAG, "Sending user approval notification for " + packageName); + if (!mUserApprovalNotificationActive) { + sendUserApprovalNotification(packageName, uid); + } return true; } @@ -862,6 +929,14 @@ public class WifiNetworkSuggestionsManager { return extNetworkSuggestions; } + private @Nullable Set<ExtendedWifiNetworkSuggestion> getNetworkSuggestionsForFqdnMatch( + @Nullable String fqdn) { + if (TextUtils.isEmpty(fqdn)) { + return null; + } + return mPasspointInfo.get(fqdn); + } + /** * Returns a set of all network suggestions matching the provided scan detail. */ @@ -896,7 +971,8 @@ public class WifiNetworkSuggestionsManager { && approvedExtNetworkSuggestions.size() != extNetworkSuggestions.size()) { for (ExtendedWifiNetworkSuggestion extNetworkSuggestion : extNetworkSuggestions) { if (sendUserApprovalNotificationIfNotApproved( - extNetworkSuggestion.perAppInfo, extNetworkSuggestion.wns)) { + extNetworkSuggestion.perAppInfo.packageName, + extNetworkSuggestion.wns.suggestorUid)) { break; } } @@ -915,18 +991,22 @@ public class WifiNetworkSuggestionsManager { /** * Returns a set of all network suggestions matching the provided the WifiConfiguration. */ - private @Nullable Set<ExtendedWifiNetworkSuggestion> getNetworkSuggestionsForWifiConfiguration( + public @Nullable Set<ExtendedWifiNetworkSuggestion> getNetworkSuggestionsForWifiConfiguration( @NonNull WifiConfiguration wifiConfiguration, @Nullable String bssid) { Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestions = null; - try { - ScanResultMatchInfo scanResultMatchInfo = - ScanResultMatchInfo.fromWifiConfiguration(wifiConfiguration); - extNetworkSuggestions = getNetworkSuggestionsForScanResultMatchInfo( - scanResultMatchInfo, bssid == null ? null : MacAddress.fromString(bssid)); - } catch (IllegalArgumentException e) { - Log.e(TAG, "Failed to lookup network from scan result match info map", e); + if (wifiConfiguration.isPasspoint()) { + extNetworkSuggestions = getNetworkSuggestionsForFqdnMatch(wifiConfiguration.FQDN); + } else { + try { + ScanResultMatchInfo scanResultMatchInfo = + ScanResultMatchInfo.fromWifiConfiguration(wifiConfiguration); + extNetworkSuggestions = getNetworkSuggestionsForScanResultMatchInfo( + scanResultMatchInfo, bssid == null ? null : MacAddress.fromString(bssid)); + } catch (IllegalArgumentException e) { + Log.e(TAG, "Failed to lookup network from scan result match info map", e); + } } - if (extNetworkSuggestions == null) { + if (extNetworkSuggestions == null || extNetworkSuggestions.isEmpty()) { return null; } Set<ExtendedWifiNetworkSuggestion> approvedExtNetworkSuggestions = @@ -940,7 +1020,7 @@ public class WifiNetworkSuggestionsManager { if (mVerboseLoggingEnabled) { Log.v(TAG, "getNetworkSuggestionsFoWifiConfiguration Found " + approvedExtNetworkSuggestions + " for " + wifiConfiguration.SSID - + "[" + wifiConfiguration.allowedKeyManagement + "]"); + + wifiConfiguration.FQDN + "[" + wifiConfiguration.allowedKeyManagement + "]"); } return approvedExtNetworkSuggestions; } @@ -1007,7 +1087,8 @@ public class WifiNetworkSuggestionsManager { private void handleConnectionSuccess( @NonNull WifiConfiguration connectedNetwork, @NonNull String connectedBssid) { Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions = - getNetworkSuggestionsForWifiConfiguration(connectedNetwork, connectedBssid); + getNetworkSuggestionsForWifiConfiguration(connectedNetwork, connectedBssid); + if (mVerboseLoggingEnabled) { Log.v(TAG, "Network suggestions matching the connection " + matchingExtNetworkSuggestions); diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index d19159e7f..442e94c3d 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -2103,7 +2103,7 @@ public class WifiServiceImpl extends BaseWifiService { int callingUid = Binder.getCallingUid(); mLog.info("addorUpdatePasspointConfiguration uid=%").c(callingUid).flush(); return mWifiThreadRunner.call( - () -> mPasspointManager.addOrUpdateProvider(config, callingUid, packageName), + () -> mPasspointManager.addOrUpdateProvider(config, callingUid, packageName, false), false); } @@ -2148,7 +2148,7 @@ public class WifiServiceImpl extends BaseWifiService { final boolean privilegedFinal = privileged; return mWifiThreadRunner.call( () -> mPasspointManager.getProviderConfigs(uid, privilegedFinal), - Collections.emptyList()); + Collections.emptyList()); } /** diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java b/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java index 0114cfb21..f2d7388a0 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java @@ -71,6 +71,7 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData { "RemediationCaCertificateAlias"; private static final String XML_TAG_HAS_EVER_CONNECTED = "HasEverConnected"; + private static final String XML_TAG_IS_FROM_SUGGESTION = "IsFromSuggestion"; private final WifiKeyStore mKeyStore; private final SIMAccessor mSimAccessor; @@ -200,6 +201,7 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData { XmlUtil.writeNextValue(out, XML_TAG_CLIENT_PRIVATE_KEY_ALIAS, provider.getClientPrivateKeyAlias()); XmlUtil.writeNextValue(out, XML_TAG_HAS_EVER_CONNECTED, provider.getHasEverConnected()); + XmlUtil.writeNextValue(out, XML_TAG_IS_FROM_SUGGESTION, provider.isFromSuggestion()); if (provider.getConfig() != null) { XmlUtil.writeNextSectionStart(out, XML_TAG_SECTION_HEADER_PASSPOINT_CONFIGURATION); PasspointXmlUtils.serializePasspointConfiguration(out, provider.getConfig()); @@ -272,6 +274,7 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData { String remediationCaCertificateAlias = null; String packageName = null; boolean hasEverConnected = false; + boolean isFromSuggestion = false; boolean shared = false; PasspointConfiguration config = null; while (XmlUtils.nextElementWithin(in, outerTagDepth)) { @@ -309,6 +312,9 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData { case XML_TAG_HAS_EVER_CONNECTED: hasEverConnected = (boolean) value; break; + case XML_TAG_IS_FROM_SUGGESTION: + isFromSuggestion = (boolean) value; + break; } } else { if (!TextUtils.equals(in.getName(), @@ -338,8 +344,8 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData { throw new XmlPullParserException("Missing Passpoint configuration"); } return new PasspointProvider(config, mKeyStore, mSimAccessor, providerId, creatorUid, - packageName, caCertificateAliases, clientCertificateAlias, clientPrivateKeyAlias, - remediationCaCertificateAlias, hasEverConnected, shared); + packageName, isFromSuggestion, caCertificateAliases, clientCertificateAlias, + clientPrivateKeyAlias, remediationCaCertificateAlias, hasEverConnected, shared); } } diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java index 3deac1290..0c795dcb3 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java @@ -392,7 +392,8 @@ public class PasspointManager { * @param packageName Package name of the app adding/Updating {@code config} * @return true if provider is added, false otherwise */ - public boolean addOrUpdateProvider(PasspointConfiguration config, int uid, String packageName) { + public boolean addOrUpdateProvider(PasspointConfiguration config, int uid, + String packageName, boolean isFromSuggestion) { mWifiMetrics.incrementNumPasspointProviderInstallation(); if (config == null) { Log.e(TAG, "Configuration not provided"); @@ -421,8 +422,8 @@ public class PasspointManager { } // Create a provider and install the necessary certificates and keys. - PasspointProvider newProvider = mObjectFactory.makePasspointProvider( - config, mKeyStore, mSimAccessor, mProviderIndex++, uid, packageName); + PasspointProvider newProvider = mObjectFactory.makePasspointProvider(config, mKeyStore, + mSimAccessor, mProviderIndex++, uid, packageName, isFromSuggestion); if (!newProvider.installCertsAndKeys()) { Log.e(TAG, "Failed to install certificates and keys to keystore"); @@ -431,15 +432,26 @@ public class PasspointManager { // Remove existing provider with the same FQDN. if (mProviders.containsKey(config.getHomeSp().getFqdn())) { + PasspointProvider old = mProviders.get(config.getHomeSp().getFqdn()); + // If new profile is from suggestion and from a different App, ignore new profile, + // return true. + // If from same app, update it. + if (isFromSuggestion && !old.getPackageName().equals(packageName)) { + newProvider.uninstallCertsAndKeys(); + return false; + } Log.d(TAG, "Replacing configuration for " + config.getHomeSp().getFqdn()); - mProviders.get(config.getHomeSp().getFqdn()).uninstallCertsAndKeys(); + old.uninstallCertsAndKeys(); mProviders.remove(config.getHomeSp().getFqdn()); + // New profile changes the credential, remove the related WifiConfig. + if (!old.equals(newProvider)) { + mWifiConfigManager.removePasspointConfiguredNetwork( + newProvider.getWifiConfig().configKey()); + } } mProviders.put(config.getHomeSp().getFqdn(), newProvider); - mWifiConfigManager.removePasspointConfiguredNetwork( - newProvider.getWifiConfig().configKey()); mWifiConfigManager.saveToStore(true /* forceWrite */); - if (newProvider.getPackageName() != null) { + if (!isFromSuggestion && newProvider.getPackageName() != null) { startTrackingAppOpsChange(newProvider.getPackageName(), uid); } Log.d(TAG, "Added/updated Passpoint configuration: " + config.getHomeSp().getFqdn() @@ -650,7 +662,7 @@ public class PasspointManager { // Create a provider and install the necessary certificates and keys. PasspointProvider newProvider = mObjectFactory.makePasspointProvider( - config, mKeyStore, mSimAccessor, mProviderIndex++, Process.WIFI_UID, null); + config, mKeyStore, mSimAccessor, mProviderIndex++, Process.WIFI_UID, null, false); newProvider.setEphemeral(true); Log.d(TAG, "installed PasspointConfiguration for carrier : " + config.getHomeSp().getFriendlyName()); @@ -713,18 +725,21 @@ public class PasspointManager { /** * Return the installed Passpoint provider configurations. - * * An empty list will be returned when no provider is installed. * * @param callingUid Calling UID. * @param privileged Whether the caller is a privileged entity * @return A list of {@link PasspointConfiguration} */ - public List<PasspointConfiguration> getProviderConfigs(int callingUid, boolean privileged) { + public List<PasspointConfiguration> getProviderConfigs(int callingUid, + boolean privileged) { List<PasspointConfiguration> configs = new ArrayList<>(); for (Map.Entry<String, PasspointProvider> entry : mProviders.entrySet()) { PasspointProvider provider = entry.getValue(); if (privileged || callingUid == provider.getCreatorUid()) { + if (provider.isEphemeral() || provider.isFromSuggestion()) { + continue; + } configs.add(provider.getConfig()); } } @@ -814,6 +829,15 @@ public class PasspointManager { roamingConsortium); if (matchStatus == PasspointMatch.HomeProvider || matchStatus == PasspointMatch.RoamingProvider) { + // If provider is from network suggestion, check user approval. + // Send user approval notification if need. + // If not approved, will be ignored in this matching. + if (provider.isFromSuggestion() + && mWifiInjector.getWifiNetworkSuggestionsManager() + .sendUserApprovalNotificationIfNotApproved( + provider.getPackageName(), provider.getCreatorUid())) { + continue; + } allMatches.add(Pair.create(provider, matchStatus)); } } @@ -1026,13 +1050,12 @@ public class PasspointManager { public Map<OsuProvider, PasspointConfiguration> getMatchingPasspointConfigsForOsuProviders( List<OsuProvider> osuProviders) { Map<OsuProvider, PasspointConfiguration> matchingPasspointConfigs = new HashMap<>(); - List<PasspointConfiguration> passpointConfigurations = - getProviderConfigs(Process.WIFI_UID /* ignored */, true); for (OsuProvider osuProvider : osuProviders) { Map<String, String> friendlyNamesForOsuProvider = osuProvider.getFriendlyNameList(); if (friendlyNamesForOsuProvider == null) continue; - for (PasspointConfiguration passpointConfiguration : passpointConfigurations) { + for (PasspointProvider provider : mProviders.values()) { + PasspointConfiguration passpointConfiguration = provider.getConfig(); Map<String, String> serviceFriendlyNamesForPpsMo = passpointConfiguration.getServiceFriendlyNames(); if (serviceFriendlyNamesForPpsMo == null) continue; @@ -1167,7 +1190,7 @@ public class PasspointManager { // Note that for legacy configuration, the alias for client private key is the same as the // alias for the client certificate. PasspointProvider provider = new PasspointProvider(passpointConfig, mKeyStore, - mSimAccessor, mProviderIndex++, wifiConfig.creatorUid, null, + mSimAccessor, mProviderIndex++, wifiConfig.creatorUid, null, false, Arrays.asList(enterpriseConfig.getCaCertificateAlias()), enterpriseConfig.getClientCertificateAlias(), enterpriseConfig.getClientCertificateAlias(), null, false, false); diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java index 6c8c281f3..2d98a9d71 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java @@ -244,8 +244,13 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva } // Add the newly created WifiConfiguration to WifiConfigManager. - NetworkUpdateResult result = - mWifiConfigManager.addOrUpdateNetwork(config, Process.WIFI_UID); + NetworkUpdateResult result; + if (config.fromWifiNetworkSuggestion) { + result = mWifiConfigManager.addOrUpdateNetwork( + config, config.creatorUid, config.creatorName); + } else { + result = mWifiConfigManager.addOrUpdateNetwork(config, Process.WIFI_UID); + } if (!result.isSuccess()) { localLog("Failed to add passpoint network"); return null; diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java b/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java index c083b86cc..94be270e2 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointObjectFactory.java @@ -59,9 +59,9 @@ public class PasspointObjectFactory{ */ public PasspointProvider makePasspointProvider(PasspointConfiguration config, WifiKeyStore keyStore, SIMAccessor simAccessor, long providerId, int creatorUid, - String packageName) { + String packageName, boolean isFromSuggestion) { return new PasspointProvider(config, keyStore, simAccessor, providerId, creatorUid, - packageName); + packageName, isFromSuggestion); } /** diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java b/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java index 753b9a53e..70ea738ac 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointProvider.java @@ -98,6 +98,8 @@ public class PasspointProvider { private boolean mHasEverConnected; private boolean mIsShared; + private boolean mIsFromSuggestion; + /** * This is a flag to indicate if the Provider is created temporarily. @@ -106,14 +108,15 @@ public class PasspointProvider { private boolean mIsEphemeral = false; public PasspointProvider(PasspointConfiguration config, WifiKeyStore keyStore, - SIMAccessor simAccessor, long providerId, int creatorUid, String packageName) { - this(config, keyStore, simAccessor, providerId, creatorUid, packageName, null, null, null, - null, false, false); + SIMAccessor simAccessor, long providerId, int creatorUid, String packageName, + boolean isFromSuggestion) { + this(config, keyStore, simAccessor, providerId, creatorUid, packageName, isFromSuggestion, + null, null, null, null, false, false); } public PasspointProvider(PasspointConfiguration config, WifiKeyStore keyStore, SIMAccessor simAccessor, long providerId, int creatorUid, String packageName, - List<String> caCertificateAliases, + boolean isFromSuggestion, List<String> caCertificateAliases, String clientCertificateAlias, String clientPrivateKeyAlias, String remediationCaCertificateAlias, boolean hasEverConnected, boolean isShared) { @@ -129,6 +132,7 @@ public class PasspointProvider { mRemediationCaCertificateAlias = remediationCaCertificateAlias; mHasEverConnected = hasEverConnected; mIsShared = isShared; + mIsFromSuggestion = isFromSuggestion; // Setup EAP method and authentication parameter based on the credential. if (mConfig.getCredential().getUserCredential() != null) { @@ -205,6 +209,10 @@ public class PasspointProvider { return mImsiParameter; } + public boolean isFromSuggestion() { + return mIsFromSuggestion; + } + /** * Install certificates and key based on current configuration. * Note: the certificates and keys in the configuration will get cleared once @@ -426,6 +434,10 @@ public class PasspointProvider { wifiConfig.enterpriseConfig.setOcsp(WifiEnterpriseConfig.OCSP_REQUIRE_CERT_STATUS); } wifiConfig.shared = mIsShared; + wifiConfig.fromWifiNetworkSuggestion = mIsFromSuggestion; + wifiConfig.ephemeral = mIsFromSuggestion; + wifiConfig.creatorName = mPackageName; + wifiConfig.creatorUid = mCreatorUid; return wifiConfig; } diff --git a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionEvaluatorTest.java index dbca79c8d..d301d6b95 100644 --- a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionEvaluatorTest.java @@ -744,7 +744,7 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { configs[i].meteredOverride = meteredness[i] ? WifiConfiguration.METERED_OVERRIDE_METERED : WifiConfiguration.METERED_OVERRIDE_NONE; - suggestions[i] = new WifiNetworkSuggestion(configs[i], appInteractions[i], + suggestions[i] = new WifiNetworkSuggestion(configs[i], null, appInteractions[i], false, uids[i], packageNames[i]); } return suggestions; diff --git a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java index 7abcfa619..97e20fc95 100644 --- a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java +++ b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java @@ -156,7 +156,7 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { configuration.enterpriseConfig = WifiConfigurationTestUtil.createPEAPWifiEnterpriseConfigWithGTCPhase2(); WifiNetworkSuggestion networkSuggestion = - new WifiNetworkSuggestion(configuration, false, false, TEST_UID_1, + new WifiNetworkSuggestion(configuration, null, false, false, TEST_UID_1, TEST_PACKAGE_NAME_1); appInfo.hasUserApproved = false; appInfo.extNetworkSuggestions.add( @@ -186,7 +186,7 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { PerAppInfo appInfo1 = new PerAppInfo(TEST_PACKAGE_NAME_1); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_NAME_1); appInfo1.hasUserApproved = false; appInfo1.extNetworkSuggestions.add( @@ -195,7 +195,7 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { PerAppInfo appInfo2 = new PerAppInfo(TEST_PACKAGE_NAME_2); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_2, + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_2, TEST_PACKAGE_NAME_2); appInfo2.hasUserApproved = true; appInfo2.extNetworkSuggestions.add( @@ -214,10 +214,10 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { PerAppInfo appInfo1 = new PerAppInfo(TEST_PACKAGE_NAME_1); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, true, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, true, TEST_UID_1, TEST_PACKAGE_NAME_1); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_1, TEST_PACKAGE_NAME_1); appInfo1.hasUserApproved = true; appInfo1.extNetworkSuggestions.add( @@ -228,10 +228,10 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { PerAppInfo appInfo2 = new PerAppInfo(TEST_PACKAGE_NAME_2); WifiNetworkSuggestion networkSuggestion3 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_2, + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_2, TEST_PACKAGE_NAME_2); WifiNetworkSuggestion networkSuggestion4 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, true, TEST_UID_2, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, true, TEST_UID_2, TEST_PACKAGE_NAME_2); appInfo2.hasUserApproved = true; appInfo2.extNetworkSuggestions.add( diff --git a/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java b/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java index 5e13706f3..112d2fb74 100644 --- a/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java @@ -364,10 +364,10 @@ public class WakeupControllerTest extends WifiBaseTest { // suggestions WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork(quotedSsid); WifiNetworkSuggestion openNetworkSuggestion = - new WifiNetworkSuggestion(openNetwork, false, false, -1, ""); + new WifiNetworkSuggestion(openNetwork, null, false, false, -1, ""); WifiConfiguration wepNetwork = WifiConfigurationTestUtil.createWepNetwork(); WifiNetworkSuggestion wepNetworkSuggestion = - new WifiNetworkSuggestion(wepNetwork, false, false, -1, ""); + new WifiNetworkSuggestion(wepNetwork, null, false, false, -1, ""); when(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions()) .thenReturn(new HashSet<>(Arrays.asList( openNetworkSuggestion, wepNetworkSuggestion))); @@ -409,7 +409,7 @@ public class WakeupControllerTest extends WifiBaseTest { WifiConfiguration oweNetwork = WifiConfigurationTestUtil.createOweNetwork(quotedSsid2); WifiNetworkSuggestion oweNetworkSuggestion = - new WifiNetworkSuggestion(oweNetwork, false, false, -1, ""); + new WifiNetworkSuggestion(oweNetwork, null, false, false, -1, ""); when(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions()) .thenReturn(new HashSet<>(Arrays.asList(oweNetworkSuggestion))); @@ -507,7 +507,7 @@ public class WakeupControllerTest extends WifiBaseTest { WifiConfiguration openNetwork = WifiConfigurationTestUtil .createOpenNetwork(ScanResultUtil.createQuotedSSID(SAVED_SSID)); WifiNetworkSuggestion openNetworkSuggestion = - new WifiNetworkSuggestion(openNetwork, false, false, -1, ""); + new WifiNetworkSuggestion(openNetwork, null, false, false, -1, ""); when(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions()) .thenReturn(new HashSet<>(Collections.singletonList(openNetworkSuggestion))); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java index 6e9df30b3..3c9b0bc12 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java @@ -48,6 +48,8 @@ import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.net.wifi.WifiNetworkSuggestion; import android.net.wifi.WifiScanner; +import android.net.wifi.hotspot2.PasspointConfiguration; +import android.net.wifi.hotspot2.pps.HomeSp; import android.os.Handler; import android.os.UserHandle; import android.os.test.TestLooper; @@ -57,6 +59,7 @@ import com.android.internal.R; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.server.wifi.WifiNetworkSuggestionsManager.ExtendedWifiNetworkSuggestion; import com.android.server.wifi.WifiNetworkSuggestionsManager.PerAppInfo; +import com.android.server.wifi.hotspot2.PasspointManager; import com.android.server.wifi.util.WifiPermissionsUtil; import org.junit.Before; @@ -85,6 +88,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { private static final String TEST_APP_NAME_1 = "test12345"; private static final String TEST_APP_NAME_2 = "test54321"; private static final String TEST_BSSID = "00:11:22:33:44:55"; + private static final String TEST_FQDN = "FQDN"; private static final int TEST_UID_1 = 5667; private static final int TEST_UID_2 = 4537; @@ -100,6 +104,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { private @Mock WifiConfigManager mWifiConfigManager; private @Mock NetworkSuggestionStoreData mNetworkSuggestionStoreData; private @Mock WifiMetrics mWifiMetrics; + private @Mock PasspointManager mPasspointManager; private TestLooper mLooper; private ArgumentCaptor<AppOpsManager.OnOpChangedListener> mAppOpChangedListenerCaptor = ArgumentCaptor.forClass(AppOpsManager.OnOpChangedListener.class); @@ -124,6 +129,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { when(mWifiInjector.makeNetworkSuggestionStoreData(any())) .thenReturn(mNetworkSuggestionStoreData); when(mWifiInjector.getFrameworkFacade()).thenReturn(mFrameworkFacade); + when(mWifiInjector.getPasspointManager()).thenReturn(mPasspointManager); when(mFrameworkFacade.getBroadcast(any(), anyInt(), any(), anyInt())) .thenReturn(mock(PendingIntent.class)); when(mContext.getResources()).thenReturn(mResources); @@ -180,11 +186,17 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { */ @Test public void testAddNetworkSuggestionsSuccess() { + PasspointConfiguration passpointConfiguration = new PasspointConfiguration(); + HomeSp homeSp = new HomeSp(); + homeSp.setFqdn(TEST_FQDN); + passpointConfiguration.setHomeSp(homeSp); + WifiConfiguration dummyConfiguration = new WifiConfiguration(); + dummyConfiguration.FQDN = TEST_FQDN; WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_2, + dummyConfiguration, passpointConfiguration, false, false, TEST_UID_2, TEST_PACKAGE_2); List<WifiNetworkSuggestion> networkSuggestionList1 = @@ -195,13 +207,16 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion2); }}; - + when(mPasspointManager.addOrUpdateProvider(any(PasspointConfiguration.class), + anyInt(), anyString(), eq(true))).thenReturn(true); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, TEST_PACKAGE_1)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, TEST_PACKAGE_2)); + verify(mPasspointManager).addOrUpdateProvider( + passpointConfiguration, TEST_UID_2, TEST_PACKAGE_2, true); Set<WifiNetworkSuggestion> allNetworkSuggestions = mWifiNetworkSuggestionsManager.getAllNetworkSuggestions(); @@ -225,11 +240,17 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { */ @Test public void testRemoveNetworkSuggestionsSuccess() { + PasspointConfiguration passpointConfiguration = new PasspointConfiguration(); + HomeSp homeSp = new HomeSp(); + homeSp.setFqdn(TEST_FQDN); + passpointConfiguration.setHomeSp(homeSp); + WifiConfiguration dummyConfiguration = new WifiConfiguration(); + dummyConfiguration.FQDN = TEST_FQDN; WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_2, + dummyConfiguration, passpointConfiguration, false, false, TEST_UID_2, TEST_PACKAGE_2); List<WifiNetworkSuggestion> networkSuggestionList1 = @@ -240,7 +261,8 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion2); }}; - + when(mPasspointManager.addOrUpdateProvider(any(PasspointConfiguration.class), + anyInt(), anyString(), eq(true))).thenReturn(true); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, TEST_PACKAGE_1)); @@ -255,6 +277,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.remove(networkSuggestionList2, TEST_UID_1, TEST_PACKAGE_2)); + verify(mPasspointManager).removeProvider(TEST_UID_2, false, TEST_FQDN); assertTrue(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions().isEmpty()); @@ -271,13 +294,20 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { */ @Test public void testRemoveAllNetworkSuggestionsSuccess() { + PasspointConfiguration passpointConfiguration = new PasspointConfiguration(); + HomeSp homeSp = new HomeSp(); + homeSp.setFqdn(TEST_FQDN); + passpointConfiguration.setHomeSp(homeSp); + WifiConfiguration dummyConfiguration = new WifiConfiguration(); + dummyConfiguration.FQDN = TEST_FQDN; WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_2, + dummyConfiguration, passpointConfiguration, false, false, TEST_UID_2, TEST_PACKAGE_2); + List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion1); @@ -287,6 +317,8 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { add(networkSuggestion2); }}; + when(mPasspointManager.addOrUpdateProvider(any(PasspointConfiguration.class), + anyInt(), anyString(), eq(true))).thenReturn(true); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, TEST_PACKAGE_1)); @@ -301,6 +333,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.remove(new ArrayList<>(), TEST_UID_2, TEST_PACKAGE_2)); + verify(mPasspointManager).removeProvider(TEST_UID_2, false, TEST_FQDN); assertTrue(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions().isEmpty()); } @@ -311,7 +344,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testReplaceNetworkSuggestionsSuccess() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList1 = @@ -342,9 +375,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { * Verify that modify networks that are already active is allowed. */ @Test - public void testAddNetworkSuggestionsFailureOnInPlaceModification() { + public void testAddNetworkSuggestionsSuccessOnInPlaceModification() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -377,7 +410,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<>(); for (int i = 0; i < WifiManager.NETWORK_SUGGESTIONS_MAX_PER_APP; i++) { networkSuggestionList.add(new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1)); } // The first add should succeed. @@ -390,7 +423,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { networkSuggestionList = new ArrayList<>(); for (int i = 0; i < 3; i++) { networkSuggestionList.add(new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1)); } // The second add should fail. @@ -412,7 +445,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { networkSuggestionList = new ArrayList<>(); for (int i = 0; i < 2; i++) { networkSuggestionList.add(new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1)); } // This add should now succeed. @@ -427,10 +460,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testRemoveNetworkSuggestionsFailureOnInvalid() { WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList1 = @@ -457,7 +490,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testGetNetworkSuggestionsForScanDetailSuccessWithOneMatchForCarrierProvisioningApp() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -488,7 +521,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testGetNetworkSuggestionsForScanDetailSuccessWithOneMatch() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -517,11 +550,11 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testGetNetworkSuggestionsForScanDetailSuccessWithMultipleMatch() { WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.createOpenNetwork(); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration, false, false, TEST_UID_1, + wifiConfiguration, null, false, false, TEST_UID_1, TEST_PACKAGE_1); // Reuse the same network credentials to ensure they both match. WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration, false, false, TEST_UID_2, + wifiConfiguration, null, false, false, TEST_UID_2, TEST_PACKAGE_2); List<WifiNetworkSuggestion> networkSuggestionList1 = @@ -564,7 +597,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { wifiConfiguration.BSSID = scanDetail.getBSSIDString(); WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - wifiConfiguration, false, false, TEST_UID_1, + wifiConfiguration, null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -594,11 +627,11 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { wifiConfiguration.BSSID = scanDetail.getBSSIDString(); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration, false, false, TEST_UID_1, + wifiConfiguration, null, false, false, TEST_UID_1, TEST_PACKAGE_1); // Reuse the same network credentials to ensure they both match. WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration, false, false, TEST_UID_2, + wifiConfiguration, null, false, false, TEST_UID_2, TEST_PACKAGE_2); List<WifiNetworkSuggestion> networkSuggestionList1 = @@ -641,11 +674,11 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { wifiConfiguration.BSSID = scanDetail.getBSSIDString(); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration, false, false, TEST_UID_1, + wifiConfiguration, null, false, false, TEST_UID_1, TEST_PACKAGE_1); // Reuse the same network credentials to ensure they both match. WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration, false, false, TEST_UID_1, + wifiConfiguration, null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = @@ -681,11 +714,11 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { wifiConfiguration2.BSSID = scanDetail.getBSSIDString(); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration1, false, false, TEST_UID_1, + wifiConfiguration1, null, false, false, TEST_UID_1, TEST_PACKAGE_1); // Reuse the same network credentials to ensure they both match. WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration2, false, false, TEST_UID_2, + wifiConfiguration2, null, false, false, TEST_UID_2, TEST_PACKAGE_2); List<WifiNetworkSuggestion> networkSuggestionList1 = @@ -735,7 +768,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testGetNetworkSuggestionsForScanDetailFailureOnAppNotApproved() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -758,7 +791,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testGetNetworkSuggestionsForScanDetailFailureOnSuggestionRemoval() { WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.createOpenNetwork(); WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - wifiConfiguration, false, false, TEST_UID_1, + wifiConfiguration, null, false, false, TEST_UID_1, TEST_PACKAGE_1); ScanDetail scanDetail = createScanDetailForNetwork(wifiConfiguration); List<WifiNetworkSuggestion> networkSuggestionList1 = @@ -787,7 +820,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testGetNetworkSuggestionsForScanDetailFailureOnWrongNetwork() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -815,7 +848,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testOnNetworkConnectionSuccessWithOneMatch() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -827,9 +860,13 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); // Simulate connecting to the network. + WifiConfiguration connectNetwork = + new WifiConfiguration(networkSuggestion.wifiConfiguration); + connectNetwork.fromWifiNetworkSuggestion = true; + connectNetwork.ephemeral = true; + connectNetwork.creatorName = TEST_APP_NAME_1; mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( - WifiMetrics.ConnectionEvent.FAILURE_NONE, networkSuggestion.wifiConfiguration, - TEST_BSSID); + WifiMetrics.ConnectionEvent.FAILURE_NONE, connectNetwork, TEST_BSSID); verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectSuccess(); @@ -849,7 +886,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testOnNetworkConnectionFailureWithOneMatch() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -859,11 +896,14 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, TEST_PACKAGE_1)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); - + WifiConfiguration connectNetwork = + new WifiConfiguration(networkSuggestion.wifiConfiguration); + connectNetwork.fromWifiNetworkSuggestion = true; + connectNetwork.ephemeral = true; + connectNetwork.creatorName = TEST_APP_NAME_1; // Simulate connecting to the network. mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( - WifiMetrics.ConnectionEvent.FAILURE_DHCP, networkSuggestion.wifiConfiguration, - TEST_BSSID); + WifiMetrics.ConnectionEvent.FAILURE_DHCP, connectNetwork, TEST_BSSID); verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectFailure(); @@ -886,14 +926,14 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testOnNetworkConnectionSuccessWithMultipleMatch() { WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.createOpenNetwork(); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration, true, false, TEST_UID_1, + wifiConfiguration, null, true, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion1); }}; WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration, true, false, TEST_UID_2, + wifiConfiguration, null, true, false, TEST_UID_2, TEST_PACKAGE_2); List<WifiNetworkSuggestion> networkSuggestionList2 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -909,9 +949,15 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2); + WifiConfiguration connectNetwork = + new WifiConfiguration(networkSuggestion1.wifiConfiguration); + connectNetwork.fromWifiNetworkSuggestion = true; + connectNetwork.ephemeral = true; + connectNetwork.creatorName = TEST_APP_NAME_1; + // Simulate connecting to the network. mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( - WifiMetrics.ConnectionEvent.FAILURE_NONE, wifiConfiguration, TEST_BSSID); + WifiMetrics.ConnectionEvent.FAILURE_NONE, connectNetwork, TEST_BSSID); verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectSuccess(); @@ -948,14 +994,14 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.createOpenNetwork(); wifiConfiguration.BSSID = TEST_BSSID; WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration, true, false, TEST_UID_1, + wifiConfiguration, null, true, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion1); }}; WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration, true, false, TEST_UID_2, + wifiConfiguration, null, true, false, TEST_UID_2, TEST_PACKAGE_2); List<WifiNetworkSuggestion> networkSuggestionList2 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -970,10 +1016,14 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { TEST_PACKAGE_2)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2); - + WifiConfiguration connectNetwork = + new WifiConfiguration(networkSuggestion1.wifiConfiguration); + connectNetwork.fromWifiNetworkSuggestion = true; + connectNetwork.ephemeral = true; + connectNetwork.creatorName = TEST_APP_NAME_1; // Simulate connecting to the network. mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( - WifiMetrics.ConnectionEvent.FAILURE_NONE, wifiConfiguration, TEST_BSSID); + WifiMetrics.ConnectionEvent.FAILURE_NONE, connectNetwork, TEST_BSSID); verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectSuccess(); @@ -1011,14 +1061,14 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { WifiConfiguration wifiConfiguration2 = new WifiConfiguration(wifiConfiguration1); wifiConfiguration2.BSSID = TEST_BSSID; WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration1, true, false, TEST_UID_1, + wifiConfiguration1, null, true, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion1); }}; WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration2, true, false, TEST_UID_2, + wifiConfiguration2, null, true, false, TEST_UID_2, TEST_PACKAGE_2); List<WifiNetworkSuggestion> networkSuggestionList2 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1034,9 +1084,15 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2); + WifiConfiguration connectNetwork = + new WifiConfiguration(networkSuggestion1.wifiConfiguration); + connectNetwork.fromWifiNetworkSuggestion = true; + connectNetwork.ephemeral = true; + connectNetwork.creatorName = TEST_APP_NAME_1; + // Simulate connecting to the network. mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( - WifiMetrics.ConnectionEvent.FAILURE_NONE, wifiConfiguration1, TEST_BSSID); + WifiMetrics.ConnectionEvent.FAILURE_NONE, connectNetwork, TEST_BSSID); verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectSuccess(); @@ -1072,7 +1128,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testOnNetworkConnectionWhenAppNotApproved() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1084,10 +1140,15 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { verify(mWifiPermissionsUtil).checkNetworkCarrierProvisioningPermission(TEST_UID_1); assertFalse(mWifiNetworkSuggestionsManager.hasUserApprovedForApp(TEST_PACKAGE_1)); + WifiConfiguration connectNetwork = + new WifiConfiguration(networkSuggestion.wifiConfiguration); + connectNetwork.fromWifiNetworkSuggestion = true; + connectNetwork.ephemeral = true; + connectNetwork.creatorName = TEST_APP_NAME_1; + // Simulate connecting to the network. mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( - WifiMetrics.ConnectionEvent.FAILURE_NONE, networkSuggestion.wifiConfiguration, - TEST_BSSID); + WifiMetrics.ConnectionEvent.FAILURE_NONE, connectNetwork, TEST_BSSID); // Verify no broadcast was sent out. mInorder.verify(mWifiPermissionsUtil, never()).enforceCanAccessScanResults( @@ -1106,7 +1167,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testOnNetworkConnectionWhenIsAppInteractionRequiredNotSet() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1118,10 +1179,15 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { verify(mWifiPermissionsUtil).checkNetworkCarrierProvisioningPermission(TEST_UID_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); + WifiConfiguration connectNetwork = + new WifiConfiguration(networkSuggestion.wifiConfiguration); + connectNetwork.fromWifiNetworkSuggestion = true; + connectNetwork.ephemeral = true; + connectNetwork.creatorName = TEST_APP_NAME_1; + // Simulate connecting to the network. mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( - WifiMetrics.ConnectionEvent.FAILURE_NONE, networkSuggestion.wifiConfiguration, - TEST_BSSID); + WifiMetrics.ConnectionEvent.FAILURE_NONE, connectNetwork, TEST_BSSID); // Verify no broadcast was sent out. mInorder.verify(mWifiPermissionsUtil, never()).enforceCanAccessScanResults( @@ -1140,7 +1206,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testOnNetworkConnectionWhenAppDoesNotHoldLocationPermission() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1155,10 +1221,15 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { doThrow(new SecurityException()) .when(mWifiPermissionsUtil).enforceCanAccessScanResults(TEST_PACKAGE_1, TEST_UID_1); + WifiConfiguration connectNetwork = + new WifiConfiguration(networkSuggestion.wifiConfiguration); + connectNetwork.fromWifiNetworkSuggestion = true; + connectNetwork.ephemeral = true; + connectNetwork.creatorName = TEST_APP_NAME_1; + // Simulate connecting to the network. mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( - WifiMetrics.ConnectionEvent.FAILURE_NONE, networkSuggestion.wifiConfiguration, - TEST_BSSID); + WifiMetrics.ConnectionEvent.FAILURE_NONE, connectNetwork, TEST_BSSID); mInorder.verify(mWifiPermissionsUtil) .enforceCanAccessScanResults(TEST_PACKAGE_1, TEST_UID_1); @@ -1173,7 +1244,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testAddNetworkSuggestionsConfigStoreWrite() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = @@ -1215,7 +1286,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testRemoveNetworkSuggestionsConfigStoreWrite() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = @@ -1250,13 +1321,24 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { */ @Test public void testNetworkSuggestionsConfigStoreLoad() { + PasspointConfiguration passpointConfiguration = new PasspointConfiguration(); + HomeSp homeSp = new HomeSp(); + homeSp.setFqdn(TEST_FQDN); + passpointConfiguration.setHomeSp(homeSp); + WifiConfiguration dummyConfiguration = new WifiConfiguration(); + dummyConfiguration.FQDN = TEST_FQDN; PerAppInfo appInfo = new PerAppInfo(TEST_PACKAGE_1); appInfo.hasUserApproved = true; WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, + TEST_PACKAGE_1); + WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( + dummyConfiguration, passpointConfiguration, false, false, TEST_UID_1, TEST_PACKAGE_1); appInfo.extNetworkSuggestions.add( ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion, appInfo)); + appInfo.extNetworkSuggestions.add( + ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion1, appInfo)); mDataSource.fromDeserialized(new HashMap<String, PerAppInfo>() {{ put(TEST_PACKAGE_1, appInfo); }}); @@ -1266,6 +1348,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { Set<WifiNetworkSuggestion> expectedAllNetworkSuggestions = new HashSet<WifiNetworkSuggestion>() {{ add(networkSuggestion); + add(networkSuggestion1); }}; assertEquals(expectedAllNetworkSuggestions, allNetworkSuggestions); @@ -1278,6 +1361,18 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { add(networkSuggestion); }}; assertEquals(expectedMatchingNetworkSuggestions, matchingNetworkSuggestions); + + // Ensure we can lookup the passpoint network. + WifiConfiguration connectNetwork = WifiConfigurationTestUtil.createPasspointNetwork(); + connectNetwork.FQDN = TEST_FQDN; + Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions = + mWifiNetworkSuggestionsManager + .getNetworkSuggestionsForWifiConfiguration(connectNetwork, null); + Set<ExtendedWifiNetworkSuggestion> expectedMatchingExtNetworkSuggestions = + new HashSet<ExtendedWifiNetworkSuggestion>() {{ + add(ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion1, appInfo)); + }}; + assertEquals(expectedMatchingExtNetworkSuggestions, matchingExtNetworkSuggestions); } /** @@ -1289,7 +1384,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { PerAppInfo appInfo1 = new PerAppInfo(TEST_PACKAGE_1); appInfo1.hasUserApproved = true; WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); appInfo1.extNetworkSuggestions.add( ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion1, appInfo1)); @@ -1303,7 +1398,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { PerAppInfo appInfo2 = new PerAppInfo(TEST_PACKAGE_2); appInfo2.hasUserApproved = true; WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); appInfo2.extNetworkSuggestions.add( ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion2, appInfo2)); @@ -1342,7 +1437,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testRemoveNetworkSuggestionsMatchingConnectionSuccessWithOneMatch() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1352,11 +1447,14 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, TEST_PACKAGE_1)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); - // Simulate connecting to the network. + WifiConfiguration connectNetwork = + new WifiConfiguration(networkSuggestion.wifiConfiguration); + connectNetwork.fromWifiNetworkSuggestion = true; + connectNetwork.ephemeral = true; + connectNetwork.creatorName = TEST_APP_NAME_1; mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( - WifiMetrics.ConnectionEvent.FAILURE_NONE, networkSuggestion.wifiConfiguration, - TEST_BSSID); + WifiMetrics.ConnectionEvent.FAILURE_NONE, connectNetwork, TEST_BSSID); // Now remove the network suggestion and ensure we did trigger a disconnect. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, @@ -1374,7 +1472,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testRemoveAllNetworkSuggestionsMatchingConnectionSuccessWithOneMatch() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1384,11 +1482,14 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, TEST_PACKAGE_1)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); - // Simulate connecting to the network. + WifiConfiguration connectNetwork = + new WifiConfiguration(networkSuggestion.wifiConfiguration); + connectNetwork.fromWifiNetworkSuggestion = true; + connectNetwork.ephemeral = true; + connectNetwork.creatorName = TEST_APP_NAME_1; mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( - WifiMetrics.ConnectionEvent.FAILURE_NONE, networkSuggestion.wifiConfiguration, - TEST_BSSID); + WifiMetrics.ConnectionEvent.FAILURE_NONE, connectNetwork, TEST_BSSID); // Now remove all network suggestion and ensure we did trigger a disconnect. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, @@ -1407,14 +1508,14 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testRemoveAppMatchingConnectionSuccessWithMultipleMatch() { WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.createOpenNetwork(); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration, true, false, TEST_UID_1, + wifiConfiguration, null, true, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion1); }}; WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration, true, false, TEST_UID_2, + wifiConfiguration, null, true, false, TEST_UID_2, TEST_PACKAGE_2); List<WifiNetworkSuggestion> networkSuggestionList2 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1431,8 +1532,13 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2); // Simulate connecting to the network. + WifiConfiguration connectNetwork = + new WifiConfiguration(wifiConfiguration); + connectNetwork.fromWifiNetworkSuggestion = true; + connectNetwork.ephemeral = true; + connectNetwork.creatorName = TEST_APP_NAME_1; mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( - WifiMetrics.ConnectionEvent.FAILURE_NONE, wifiConfiguration, TEST_BSSID); + WifiMetrics.ConnectionEvent.FAILURE_NONE, connectNetwork, TEST_BSSID); // Now remove one of the apps and ensure we did not trigger a disconnect. mWifiNetworkSuggestionsManager.removeApp(TEST_PACKAGE_1); @@ -1451,7 +1557,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testRemoveAppNotMatchingConnectionSuccess() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1479,7 +1585,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testRemoveNetworkSuggestionsNotMatchingConnectionSuccessAfterConnectionFailure() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1489,11 +1595,14 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, TEST_PACKAGE_1)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); - + WifiConfiguration connectNetwork = + new WifiConfiguration(networkSuggestion.wifiConfiguration); + connectNetwork.fromWifiNetworkSuggestion = true; + connectNetwork.ephemeral = true; + connectNetwork.creatorName = TEST_APP_NAME_1; // Simulate failing connection to the network. mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( - WifiMetrics.ConnectionEvent.FAILURE_DHCP, networkSuggestion.wifiConfiguration, - TEST_BSSID); + WifiMetrics.ConnectionEvent.FAILURE_DHCP, connectNetwork, TEST_BSSID); // Simulate connecting to some other network. mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( @@ -1512,10 +1621,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testAddRemoveNetworkSuggestionsStartStopAppOpsWatch() { WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_2, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_2, TEST_PACKAGE_2); List<WifiNetworkSuggestion> networkSuggestionList1 = @@ -1561,7 +1670,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testAppOpsChangeAfterSuggestionsAdd() { WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1613,7 +1722,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testAppOpsChangeAfterConfigStoreLoad() { PerAppInfo appInfo = new PerAppInfo(TEST_PACKAGE_1); WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); appInfo.extNetworkSuggestions.add( ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion, appInfo)); @@ -1660,7 +1769,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testAppOpsChangeWrongUid() { WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1703,10 +1812,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testRemoveApp() { WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_2, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_2, TEST_PACKAGE_2); List<WifiNetworkSuggestion> networkSuggestionList1 = @@ -1769,10 +1878,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testClear() { WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_2, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_2, TEST_PACKAGE_2); List<WifiNetworkSuggestion> networkSuggestionList1 = @@ -1826,7 +1935,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testUserApprovalNotificationDismissalWhenGetScanResult() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1867,7 +1976,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testUserApprovalNotificationClickOnAllowWhenGetScanResult() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1913,7 +2022,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testUserApprovalNotificationClickOnDisallowWhenGetScanResult() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1982,7 +2091,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testUserApprovalNotificationWhilePreviousNotificationActive() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -2021,16 +2130,16 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // App add network suggestions then get stored suggestions. WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOweNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createOweNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); WifiNetworkSuggestion networkSuggestion3 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createSaeNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createSaeNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); WifiNetworkSuggestion networkSuggestion4 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createPskNetwork(), false, false, TEST_UID_1, + WifiConfigurationTestUtil.createPskNetwork(), null, false, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<>(); networkSuggestionList.add(networkSuggestion1); @@ -2062,13 +2171,13 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testGetHiddenNetworks() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_1, TEST_PACKAGE_1); WifiNetworkSuggestion hiddenNetworkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createPskHiddenNetwork(), true, false, TEST_UID_1, + WifiConfigurationTestUtil.createPskHiddenNetwork(), null, true, false, TEST_UID_1, TEST_PACKAGE_1); WifiNetworkSuggestion hiddenNetworkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createPskHiddenNetwork(), true, false, TEST_UID_2, + WifiConfigurationTestUtil.createPskHiddenNetwork(), null, true, false, TEST_UID_2, TEST_PACKAGE_2); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -2100,7 +2209,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testUserApprovalNotificationClickOnAllowDuringAddingSuggestions() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -2135,7 +2244,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testUserApprovalNotificationClickOnDisallowWhenAddSuggestions() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), true, false, TEST_UID_1, + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, TEST_UID_1, TEST_PACKAGE_1); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -2183,6 +2292,57 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { } /** + * Verify a successful lookup of a single passpoint network suggestion matching the + * connected network. + * a) The corresponding network suggestion has the + * {@link WifiNetworkSuggestion#isAppInteractionRequired} flag set. + * b) The app holds location permission. + * This should trigger a broadcast to the app. + */ + @Test + public void testOnPasspointNetworkConnectionSuccessWithOneMatch() { + PasspointConfiguration passpointConfiguration = new PasspointConfiguration(); + HomeSp homeSp = new HomeSp(); + homeSp.setFqdn(TEST_FQDN); + passpointConfiguration.setHomeSp(homeSp); + WifiConfiguration dummyConfiguration = new WifiConfiguration(); + dummyConfiguration.FQDN = TEST_FQDN; + WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( + dummyConfiguration, passpointConfiguration, true, false, TEST_UID_1, + TEST_PACKAGE_1); + List<WifiNetworkSuggestion> networkSuggestionList = + new ArrayList<WifiNetworkSuggestion>() {{ + add(networkSuggestion); + }}; + when(mPasspointManager.addOrUpdateProvider(any(), anyInt(), anyString(), anyBoolean())) + .thenReturn(true); + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, + TEST_PACKAGE_1)); + + mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); + + // Simulate connecting to the network. + WifiConfiguration connectNetwork = WifiConfigurationTestUtil.createPasspointNetwork(); + connectNetwork.FQDN = TEST_FQDN; + connectNetwork.fromWifiNetworkSuggestion = true; + connectNetwork.ephemeral = true; + connectNetwork.creatorName = TEST_APP_NAME_1; + mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( + WifiMetrics.ConnectionEvent.FAILURE_NONE, connectNetwork, TEST_BSSID); + + verify(mWifiMetrics).incrementNetworkSuggestionApiNumConnectSuccess(); + + // Verify that the correct broadcast was sent out. + mInorder.verify(mWifiPermissionsUtil) + .enforceCanAccessScanResults(TEST_PACKAGE_1, TEST_UID_1); + validatePostConnectionBroadcastSent(TEST_PACKAGE_1, networkSuggestion); + + // Verify no more broadcast were sent out. + mInorder.verifyNoMoreInteractions(); + } + + /** * Creates a scan detail corresponding to the provided network values. */ private ScanDetail createScanDetailForNetwork(WifiConfiguration configuration) { diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 62e88074a..456244d0f 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -2377,25 +2377,25 @@ public class WifiServiceImplTest extends WifiBaseTest { eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); when(mPasspointManager.addOrUpdateProvider( - any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME))) + any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME), eq(false))) .thenReturn(true); mLooper.startAutoDispatch(); assertEquals(0, mWifiServiceImpl.addOrUpdateNetwork(config, TEST_PACKAGE_NAME)); mLooper.stopAutoDispatch(); verifyCheckChangePermission(TEST_PACKAGE_NAME); verify(mPasspointManager).addOrUpdateProvider( - any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME)); + any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME), eq(false)); reset(mPasspointManager); when(mPasspointManager.addOrUpdateProvider( - any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME))) + any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME), anyBoolean())) .thenReturn(false); mLooper.startAutoDispatch(); assertEquals(-1, mWifiServiceImpl.addOrUpdateNetwork(config, TEST_PACKAGE_NAME)); mLooper.stopAutoDispatch(); verifyCheckChangePermission(TEST_PACKAGE_NAME); verify(mPasspointManager).addOrUpdateProvider( - any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME)); + any(PasspointConfiguration.class), anyInt(), eq(TEST_PACKAGE_NAME), anyBoolean()); } /** @@ -3988,7 +3988,7 @@ public class WifiServiceImplTest extends WifiBaseTest { config.setHomeSp(homeSp); when(mPasspointManager.addOrUpdateProvider( - config, Binder.getCallingUid(), TEST_PACKAGE_NAME)) + config, Binder.getCallingUid(), TEST_PACKAGE_NAME, false)) .thenReturn(true); mLooper.startAutoDispatch(); assertTrue(mWifiServiceImpl.addOrUpdatePasspointConfiguration(config, TEST_PACKAGE_NAME)); @@ -3996,7 +3996,7 @@ public class WifiServiceImplTest extends WifiBaseTest { reset(mPasspointManager); when(mPasspointManager.addOrUpdateProvider( - config, Binder.getCallingUid(), TEST_PACKAGE_NAME)) + config, Binder.getCallingUid(), TEST_PACKAGE_NAME, false)) .thenReturn(false); mLooper.startAutoDispatch(); assertFalse(mWifiServiceImpl.addOrUpdatePasspointConfiguration(config, TEST_PACKAGE_NAME)); diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigUserStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigUserStoreDataTest.java index 9943c4fb2..54a74978d 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigUserStoreDataTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointConfigUserStoreDataTest.java @@ -244,11 +244,11 @@ public class PasspointConfigUserStoreDataTest extends WifiBaseTest { List<PasspointProvider> providerList = new ArrayList<>(); providerList.add(new PasspointProvider(createFullPasspointConfiguration(), mKeyStore, mSimAccessor, TEST_PROVIDER_ID, TEST_CREATOR_UID, TEST_CREATOR_PACKAGE, - Arrays.asList(TEST_CA_CERTIFICATE_ALIAS), TEST_CLIENT_CERTIFICATE_ALIAS, + false, Arrays.asList(TEST_CA_CERTIFICATE_ALIAS), TEST_CLIENT_CERTIFICATE_ALIAS, TEST_CLIENT_PRIVATE_KEY_ALIAS, null, TEST_HAS_EVER_CONNECTED, TEST_SHARED)); providerList.add(new PasspointProvider(createFullPasspointConfiguration(), mKeyStore, mSimAccessor, TEST_PROVIDER_ID_2, TEST_CREATOR_UID, TEST_CREATOR_PACKAGE, - Arrays.asList(TEST_CA_CERTIFICATE_ALIAS, TEST_CA_CERTIFICATE_ALIAS_2), + true, Arrays.asList(TEST_CA_CERTIFICATE_ALIAS, TEST_CA_CERTIFICATE_ALIAS_2), TEST_CLIENT_CERTIFICATE_ALIAS, TEST_CLIENT_PRIVATE_KEY_ALIAS, TEST_REMEDIATION_CA_CERTIFICATE_ALIAS, TEST_HAS_EVER_CONNECTED, TEST_SHARED)); diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java index 27c23ecc7..a4288fb1b 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -48,6 +48,7 @@ import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; @@ -95,6 +96,7 @@ import com.android.server.wifi.WifiInjector; import com.android.server.wifi.WifiKeyStore; import com.android.server.wifi.WifiMetrics; import com.android.server.wifi.WifiNative; +import com.android.server.wifi.WifiNetworkSuggestionsManager; import com.android.server.wifi.hotspot2.anqp.ANQPElement; import com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType; import com.android.server.wifi.hotspot2.anqp.DomainNameElement; @@ -134,6 +136,7 @@ import java.util.Set; public class PasspointManagerTest extends WifiBaseTest { private static final long BSSID = 0x112233445566L; private static final String TEST_PACKAGE = "com.android.test"; + private static final String TEST_PACKAGE1 = "com.android.test1"; private static final String ICON_FILENAME = "test"; private static final String TEST_FQDN = "test1.test.com"; private static final String TEST_FQDN2 = "test2.test.com"; @@ -162,6 +165,7 @@ public class PasspointManagerTest extends WifiBaseTest { private static final ANQPNetworkKey TEST_ANQP_KEY2 = ANQPNetworkKey.buildKey( TEST_SSID, TEST_BSSID, TEST_HESSID, TEST_ANQP_DOMAIN_ID2); private static final int TEST_CREATOR_UID = 1234; + private static final int TEST_CREATOR_UID1 = 1235; private static final int TEST_UID = 1500; @Mock Context mContext; @@ -191,6 +195,7 @@ public class PasspointManagerTest extends WifiBaseTest { @Mock TelephonyManager mTelephonyManager; @Mock TelephonyManager mDataTelephonyManager; @Mock SubscriptionManager mSubscriptionManager; + @Mock WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager; Handler mHandler; TestLooper mLooper; @@ -217,6 +222,8 @@ public class PasspointManagerTest extends WifiBaseTest { .thenReturn(mPasspointProvisioner); when(mContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager); when(mWifiInjector.getClientModeImpl()).thenReturn(mClientModeImpl); + when(mWifiInjector.getWifiNetworkSuggestionsManager()) + .thenReturn(mWifiNetworkSuggestionsManager); mLooper = new TestLooper(); mHandler = new Handler(mLooper.getLooper()); mManager = new PasspointManager(mContext, mWifiInjector, mHandler, mWifiNative, @@ -370,10 +377,10 @@ public class PasspointManagerTest extends WifiBaseTest { PasspointConfiguration config = createTestConfigWithUserCredential(fqdn, friendlyName); PasspointProvider provider = createMockProvider(config, wifiConfig); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( - provider); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), + eq(false))).thenReturn(provider); when(provider.getPackageName()).thenReturn(packageName); - assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); + assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false)); return provider; } @@ -387,10 +394,10 @@ public class PasspointManagerTest extends WifiBaseTest { PasspointConfiguration config = createTestConfigWithSimCredential(fqdn, imsi, realm); PasspointProvider provider = createMockProvider(config); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( - provider); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), + eq(false))).thenReturn(provider); - assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); + assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false)); return provider; } @@ -606,7 +613,7 @@ public class PasspointManagerTest extends WifiBaseTest { */ @Test public void addProviderWithNullConfig() throws Exception { - assertFalse(mManager.addOrUpdateProvider(null, TEST_CREATOR_UID, TEST_PACKAGE)); + assertFalse(mManager.addOrUpdateProvider(null, TEST_CREATOR_UID, TEST_PACKAGE, false)); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } @@ -619,7 +626,7 @@ public class PasspointManagerTest extends WifiBaseTest { @Test public void addProviderWithEmptyConfig() throws Exception { assertFalse(mManager.addOrUpdateProvider(new PasspointConfiguration(), TEST_CREATOR_UID, - TEST_PACKAGE)); + TEST_PACKAGE, false)); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } @@ -636,34 +643,32 @@ public class PasspointManagerTest extends WifiBaseTest { TEST_FRIENDLY_NAME); // EAP-TLS not allowed for user credential. config.getCredential().getUserCredential().setEapType(EAPConstants.EAP_TLS); - assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); + assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false)); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } /** - * Verify that adding a provider with a valid configuration and user credential will succeed. + * Verify that adding a user saved provider with a valid configuration and user credential will + * succeed. * * @throws Exception */ @Test - public void addRemoveProviderWithValidUserCredential() throws Exception { + public void addRemoveSavedProviderWithValidUserCredential() throws Exception { PasspointConfiguration config = createTestConfigWithUserCredential(TEST_FQDN, TEST_FRIENDLY_NAME); PasspointProvider provider = createMockProvider(config); when(provider.getPackageName()).thenReturn(TEST_PACKAGE); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( - provider); - assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), + eq(false))).thenReturn(provider); + assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false)); verifyInstalledConfig(config); - verify(mWifiConfigManager).removePasspointConfiguredNetwork( - provider.getWifiConfig().configKey()); - verify(mWifiConfigManager).saveToStore(true); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); - verify(mAppOpsManager).startWatchingMode(eq(OPSTR_CHANGE_WIFI_STATE), eq(TEST_PACKAGE), any( - AppOpsManager.OnOpChangedListener.class)); + verify(mAppOpsManager).startWatchingMode(eq(OPSTR_CHANGE_WIFI_STATE), eq(TEST_PACKAGE), + any(AppOpsManager.OnOpChangedListener.class)); reset(mWifiMetrics); reset(mWifiConfigManager); @@ -692,22 +697,21 @@ public class PasspointManagerTest extends WifiBaseTest { } /** - * Verify that adding a provider with a valid configuration and SIM credential will succeed. + * Verify that adding a user saved provider with a valid configuration and SIM credential will + * succeed. * * @throws Exception */ @Test - public void addRemoveProviderWithValidSimCredential() throws Exception { + public void addRemoveSavedProviderWithValidSimCredential() throws Exception { PasspointConfiguration config = createTestConfigWithSimCredential(TEST_FQDN, TEST_IMSI, TEST_REALM); PasspointProvider provider = createMockProvider(config); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( - provider); - assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), + eq(false))).thenReturn(provider); + assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false)); verifyInstalledConfig(config); - verify(mWifiConfigManager).removePasspointConfiguredNetwork( - provider.getWifiConfig().configKey()); verify(mWifiConfigManager).saveToStore(true); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); @@ -738,25 +742,23 @@ public class PasspointManagerTest extends WifiBaseTest { } /** - * Verify that adding a provider with the same base domain as the existing provider will - * succeed, and verify that the existing provider is replaced by the new provider with + * Verify that adding a user saved provider with the same base domain as the existing provider + * will succeed, and verify that the existing provider is replaced by the new provider with * the new configuration. * * @throws Exception */ @Test - public void addProviderWithExistingConfig() throws Exception { + public void addSavedProviderWithExistingConfig() throws Exception { // Add a provider with the original configuration. PasspointConfiguration origConfig = createTestConfigWithSimCredential(TEST_FQDN, TEST_IMSI, TEST_REALM); PasspointProvider origProvider = createMockProvider(origConfig); when(mObjectFactory.makePasspointProvider(eq(origConfig), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( - origProvider); - assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE)); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), + eq(false))).thenReturn(origProvider); + assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE, false)); verifyInstalledConfig(origConfig); - verify(mWifiConfigManager).removePasspointConfiguredNetwork( - origProvider.getWifiConfig().configKey()); verify(mWifiConfigManager).saveToStore(true); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); @@ -775,9 +777,9 @@ public class PasspointManagerTest extends WifiBaseTest { TEST_FRIENDLY_NAME); PasspointProvider newProvider = createMockProvider(newConfig); when(mObjectFactory.makePasspointProvider(eq(newConfig), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( - newProvider); - assertTrue(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID, TEST_PACKAGE)); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), + eq(false))).thenReturn(newProvider); + assertTrue(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID, TEST_PACKAGE, false)); verifyInstalledConfig(newConfig); verify(mWifiConfigManager).removePasspointConfiguredNetwork( newProvider.getWifiConfig().configKey()); @@ -805,9 +807,9 @@ public class PasspointManagerTest extends WifiBaseTest { PasspointProvider provider = mock(PasspointProvider.class); when(provider.installCertsAndKeys()).thenReturn(false); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( - provider); - assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), eq(false))) + .thenReturn(provider); + assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false)); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } @@ -823,7 +825,7 @@ public class PasspointManagerTest extends WifiBaseTest { TEST_FRIENDLY_NAME); doThrow(new GeneralSecurityException()) .when(mCertVerifier).verifyCaCert(any(X509Certificate.class)); - assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); + assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false)); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); } @@ -841,9 +843,9 @@ public class PasspointManagerTest extends WifiBaseTest { config.setUpdateIdentifier(1); PasspointProvider provider = createMockProvider(config); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( - provider); - assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), + eq(false))).thenReturn(provider); + assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false)); verify(mCertVerifier, never()).verifyCaCert(any(X509Certificate.class)); verifyInstalledConfig(config); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); @@ -1324,11 +1326,10 @@ public class PasspointManagerTest extends WifiBaseTest { // Verify the provider ID used to create the new provider. when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), eq(mSimAccessor), eq(providerIndex), eq(TEST_CREATOR_UID), - eq(TEST_PACKAGE))).thenReturn(provider); + eq(TEST_PACKAGE), eq(false))).thenReturn(provider); - assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); + assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false)); verifyInstalledConfig(config); - verify(mWifiConfigManager).saveToStore(true); reset(mWifiConfigManager); } @@ -1688,7 +1689,7 @@ public class PasspointManagerTest extends WifiBaseTest { PasspointConfiguration config = createTestConfigWithUserCredential("abc.com", "test"); PasspointProvider provider = createMockProvider(config); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), anyInt(), isNull())).thenReturn(provider); + eq(mSimAccessor), anyLong(), anyInt(), isNull(), eq(false))).thenReturn(provider); assertFalse(mManager.installEphemeralPasspointConfigForCarrier(config)); } @@ -1705,7 +1706,7 @@ public class PasspointManagerTest extends WifiBaseTest { TEST_REALM); PasspointProvider provider = createMockProvider(config); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), anyInt(), isNull())).thenReturn(provider); + eq(mSimAccessor), anyLong(), anyInt(), isNull(), eq(false))).thenReturn(provider); assertTrue(mManager.installEphemeralPasspointConfigForCarrier(config)); verify(mAppOpsManager, never()).startWatchingMode(eq(OPSTR_CHANGE_WIFI_STATE), @@ -1848,9 +1849,9 @@ public class PasspointManagerTest extends WifiBaseTest { TEST_REALM); PasspointProvider provider = createMockProvider(config); when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), - eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE))).thenReturn( - provider); - assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE)); + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), + eq(false))).thenReturn(provider); + assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, false)); verifyInstalledConfig(config); verify(mWifiConfigManager).saveToStore(true); verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); @@ -1875,4 +1876,300 @@ public class PasspointManagerTest extends WifiBaseTest { // 1 profile available for TEST_CREATOR_UID assertFalse(mManager.getProviderConfigs(TEST_CREATOR_UID, false).isEmpty()); } + + /** + * Verify that adding a suggestion provider with a valid configuration and user credential will + * succeed. + * + * @throws Exception + */ + @Test + public void addRemoveSuggestionProvider() throws Exception { + PasspointConfiguration config = createTestConfigWithUserCredential(TEST_FQDN, + TEST_FRIENDLY_NAME); + PasspointProvider provider = createMockProvider(config); + when(provider.getPackageName()).thenReturn(TEST_PACKAGE); + when(provider.isFromSuggestion()).thenReturn(true); + when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), + eq(true))).thenReturn(provider); + assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, true)); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); + verify(mAppOpsManager, never()).startWatchingMode(eq(OPSTR_CHANGE_WIFI_STATE), + eq(TEST_PACKAGE), any(AppOpsManager.OnOpChangedListener.class)); + assertTrue(mManager.getProviderConfigs(TEST_CREATOR_UID, false).isEmpty()); + reset(mWifiMetrics); + reset(mWifiConfigManager); + + // Verify content in the data source. + List<PasspointProvider> providers = mUserDataSource.getProviders(); + assertEquals(1, providers.size()); + assertEquals(config, providers.get(0).getConfig()); + // Provider index start with 0, should be 1 after adding a provider. + assertEquals(1, mSharedDataSource.getProviderIndex()); + + // Remove from another Suggestor app, should fail. + assertFalse(mManager.removeProvider(TEST_UID, false, TEST_FQDN)); + verify(provider, never()).uninstallCertsAndKeys(); + verify(mWifiConfigManager, never()).removePasspointConfiguredNetwork( + provider.getWifiConfig().configKey()); + verify(mWifiConfigManager, never()).saveToStore(true); + verify(mWifiMetrics).incrementNumPasspointProviderUninstallation(); + verify(mWifiMetrics, never()).incrementNumPasspointProviderUninstallSuccess(); + verify(mAppOpsManager, never()).stopWatchingMode( + any(AppOpsManager.OnOpChangedListener.class)); + // Verify content in the data source. + providers = mUserDataSource.getProviders(); + assertEquals(1, providers.size()); + assertEquals(config, providers.get(0).getConfig()); + // Provider index start with 0, should be 1 after adding a provider. + assertEquals(1, mSharedDataSource.getProviderIndex()); + reset(mWifiMetrics); + reset(mWifiConfigManager); + + // Remove the provider from same app. + assertTrue(mManager.removeProvider(TEST_CREATOR_UID, false, TEST_FQDN)); + verify(provider).uninstallCertsAndKeys(); + verify(mWifiConfigManager).removePasspointConfiguredNetwork( + provider.getWifiConfig().configKey()); + verify(mWifiConfigManager).saveToStore(true); + verify(mWifiMetrics).incrementNumPasspointProviderUninstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderUninstallSuccess(); + verify(mAppOpsManager, never()).stopWatchingMode( + any(AppOpsManager.OnOpChangedListener.class)); + + // Verify content in the data source. + assertTrue(mUserDataSource.getProviders().isEmpty()); + // Removing a provider should not change the provider index. + assertEquals(1, mSharedDataSource.getProviderIndex()); + } + + /** + * Verify that adding a suggestion provider with the same base domain as the existing + * suggestion provider from same app will succeed, and verify that the existing provider is + * replaced by the new provider with the new configuration. + * + * @throws Exception + */ + @Test + public void addSuggestionProviderWithExistingConfig() throws Exception { + // Add a provider with the original configuration. + PasspointConfiguration origConfig = createTestConfigWithSimCredential(TEST_FQDN, TEST_IMSI, + TEST_REALM); + PasspointProvider origProvider = createMockProvider(origConfig); + when(origProvider.getPackageName()).thenReturn(TEST_PACKAGE); + when(mObjectFactory.makePasspointProvider(eq(origConfig), eq(mWifiKeyStore), + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), + eq(true))).thenReturn(origProvider); + assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE, true)); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); + reset(mWifiMetrics); + reset(mWifiConfigManager); + + // Verify data source content. + List<PasspointProvider> origProviders = mUserDataSource.getProviders(); + assertEquals(1, origProviders.size()); + assertEquals(origConfig, origProviders.get(0).getConfig()); + assertEquals(1, mSharedDataSource.getProviderIndex()); + + // Add same provider as existing suggestion provider + // This should be no WifiConfig deletion + assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE, true)); + verify(mWifiConfigManager, never()).removePasspointConfiguredNetwork( + origProvider.getWifiConfig().configKey()); + verify(mWifiConfigManager).saveToStore(true); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); + assertEquals(2, mSharedDataSource.getProviderIndex()); + reset(mWifiMetrics); + reset(mWifiConfigManager); + + // Add another provider with the same base domain as the existing saved provider. + // This should replace the existing provider with the new configuration. + PasspointConfiguration newConfig = createTestConfigWithUserCredential(TEST_FQDN, + TEST_FRIENDLY_NAME); + PasspointProvider newProvider = createMockProvider(newConfig); + when(newProvider.isFromSuggestion()).thenReturn(true); + when(newProvider.getPackageName()).thenReturn(TEST_PACKAGE); + when(mObjectFactory.makePasspointProvider(eq(newConfig), eq(mWifiKeyStore), + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), + eq(true))).thenReturn(newProvider); + assertTrue(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID, TEST_PACKAGE, true)); + verify(mWifiConfigManager).removePasspointConfiguredNetwork( + newProvider.getWifiConfig().configKey()); + verify(mWifiConfigManager).saveToStore(true); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); + + // Verify data source content. + List<PasspointProvider> newProviders = mUserDataSource.getProviders(); + assertEquals(1, newProviders.size()); + assertEquals(newConfig, newProviders.get(0).getConfig()); + assertEquals(3, mSharedDataSource.getProviderIndex()); + } + + /** + * Verify that adding a saved provider with the same base domain as the existing + * suggestion provider will succeed, and verify that the existing provider is + * replaced by the new provider with the new configuration. + * + * @throws Exception + */ + @Test + public void addSavedProviderWithExistingSuggestionConfig() throws Exception { + // Add a provider with the original configuration. + PasspointConfiguration origConfig = createTestConfigWithSimCredential(TEST_FQDN, TEST_IMSI, + TEST_REALM); + PasspointProvider origProvider = createMockProvider(origConfig); + when(origProvider.getPackageName()).thenReturn(TEST_PACKAGE); + when(mObjectFactory.makePasspointProvider(eq(origConfig), eq(mWifiKeyStore), + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), + eq(true))).thenReturn(origProvider); + assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE, true)); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); + reset(mWifiMetrics); + reset(mWifiConfigManager); + + // Verify data source content. + List<PasspointProvider> origProviders = mUserDataSource.getProviders(); + assertEquals(1, origProviders.size()); + assertEquals(origConfig, origProviders.get(0).getConfig()); + assertEquals(1, mSharedDataSource.getProviderIndex()); + + // Add another provider with the same base domain as the existing saved provider. + // This should replace the existing provider with the new configuration. + PasspointConfiguration newConfig = createTestConfigWithUserCredential(TEST_FQDN, + TEST_FRIENDLY_NAME); + PasspointProvider newProvider = createMockProvider(newConfig); + when(mObjectFactory.makePasspointProvider(eq(newConfig), eq(mWifiKeyStore), + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), + eq(false))).thenReturn(newProvider); + assertTrue(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID, TEST_PACKAGE, false)); + verify(mWifiConfigManager).removePasspointConfiguredNetwork( + newProvider.getWifiConfig().configKey()); + verify(mWifiConfigManager).saveToStore(true); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); + + // Verify data source content. + List<PasspointProvider> newProviders = mUserDataSource.getProviders(); + assertEquals(1, newProviders.size()); + assertEquals(newConfig, newProviders.get(0).getConfig()); + assertEquals(2, mSharedDataSource.getProviderIndex()); + } + + /** + * Verify that adding a suggestion provider with the same base domain as the existing provider + * from different apps will fail, and verify that the existing provider is not replaced by the + * new provider with the new configuration. + * + * @throws Exception + */ + @Test + public void addSuggestionProviderWithExistingConfigFromDifferentSource() throws Exception { + // Add a provider with the original configuration. + PasspointConfiguration origConfig = createTestConfigWithSimCredential(TEST_FQDN, TEST_IMSI, + TEST_REALM); + PasspointProvider origProvider = createMockProvider(origConfig); + when(origProvider.getPackageName()).thenReturn(TEST_PACKAGE); + when(mObjectFactory.makePasspointProvider(eq(origConfig), eq(mWifiKeyStore), + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE), + eq(false))).thenReturn(origProvider); + assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID, TEST_PACKAGE, false)); + verifyInstalledConfig(origConfig); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); + reset(mWifiMetrics); + reset(mWifiConfigManager); + + // Verify data source content. + List<PasspointProvider> origProviders = mUserDataSource.getProviders(); + assertEquals(1, origProviders.size()); + assertEquals(origConfig, origProviders.get(0).getConfig()); + assertEquals(1, mSharedDataSource.getProviderIndex()); + + // Add another provider with the same base domain as the existing saved provider but from + // different app. This should not replace the existing provider with the new configuration. + PasspointConfiguration newConfig = createTestConfigWithUserCredential(TEST_FQDN, + TEST_FRIENDLY_NAME); + PasspointProvider newProvider = createMockProvider(newConfig); + when(newProvider.isFromSuggestion()).thenReturn(true); + when(newProvider.getPackageName()).thenReturn(TEST_PACKAGE1); + when(mObjectFactory.makePasspointProvider(eq(newConfig), eq(mWifiKeyStore), + eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID), eq(TEST_PACKAGE1), + eq(true))).thenReturn(newProvider); + assertFalse(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID, TEST_PACKAGE1, true)); + verify(mWifiConfigManager, never()).removePasspointConfiguredNetwork( + newProvider.getWifiConfig().configKey()); + verify(mWifiConfigManager, never()).saveToStore(true); + verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); + verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); + + // Verify data source content. + List<PasspointProvider> newProviders = mUserDataSource.getProviders(); + assertEquals(1, newProviders.size()); + assertEquals(origConfig, newProviders.get(0).getConfig()); + assertEquals(2, mSharedDataSource.getProviderIndex()); + } + + /** + * Verify that an expected map of FQDN and a list of ScanResult will be returned when provided + * scanResults are matched to installed Passpoint profiles. If matched Passpoint profiles is + * from suggestion, will check if it is approved. If it is not approved, send the user approved + * notification, and not to add into the matched list. + */ + @Test + public void getAllMatchingFqdnsForScanResultsWithSuggestionProvider() { + // static mocking + MockitoSession session = + com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession().mockStatic( + InformationElementUtil.class).startMocking(); + try { + PasspointProvider providerApproved = addTestProvider(TEST_FQDN + 0, TEST_FRIENDLY_NAME, + TEST_PACKAGE); + providerApproved.getWifiConfig().isHomeProviderNetwork = true; + PasspointProvider providerNeedApprove = addTestProvider(TEST_FQDN + 1, + TEST_FRIENDLY_NAME, TEST_PACKAGE1); + providerNeedApprove.getWifiConfig().isHomeProviderNetwork = true; + + ANQPData entry = new ANQPData(mClock, null); + InformationElementUtil.Vsa vsa = new InformationElementUtil.Vsa(); + vsa.anqpDomainID = TEST_ANQP_DOMAIN_ID2; + + when(mAnqpCache.getEntry(TEST_ANQP_KEY2)).thenReturn(entry); + when(InformationElementUtil.getHS2VendorSpecificIE(isNull())).thenReturn(vsa); + when(providerApproved.match(anyMap(), isNull())) + .thenReturn(PasspointMatch.HomeProvider); + when(providerNeedApprove.match(anyMap(), isNull())) + .thenReturn(PasspointMatch.HomeProvider); + when(providerApproved.isFromSuggestion()).thenReturn(true); + when(providerNeedApprove.isFromSuggestion()).thenReturn(true); + when(mWifiNetworkSuggestionsManager + .sendUserApprovalNotificationIfNotApproved(eq(TEST_PACKAGE), anyInt())) + .thenReturn(false); + when(mWifiNetworkSuggestionsManager + .sendUserApprovalNotificationIfNotApproved(eq(TEST_PACKAGE1), anyInt())) + .thenReturn(true); + Map<String, Map<Integer, List<ScanResult>>> configs = + mManager.getAllMatchingFqdnsForScanResults( + createTestScanResults()); + verify(mWifiNetworkSuggestionsManager, times(2)) + .sendUserApprovalNotificationIfNotApproved(eq(TEST_PACKAGE), anyInt()); + verify(mWifiNetworkSuggestionsManager, times(2)) + .sendUserApprovalNotificationIfNotApproved(eq(TEST_PACKAGE1), anyInt()); + // Expects to be matched with home Provider for each AP (two APs). + assertEquals(2, configs.get(TEST_FQDN + 0).get( + WifiManager.PASSPOINT_HOME_NETWORK).size()); + assertFalse( + configs.get(TEST_FQDN + 0).containsKey(WifiManager.PASSPOINT_ROAMING_NETWORK)); + + // Expects there is no matched AP. + assertNull(configs.get(TEST_FQDN + 1)); + } finally { + session.finishMocking(); + } + } } diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java index 4ee91fa8d..ec0533214 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java @@ -154,7 +154,7 @@ public class PasspointProviderTest extends WifiBaseTest { */ private PasspointProvider createProvider(PasspointConfiguration config) { return new PasspointProvider(config, mKeyStore, mSimAccessor, PROVIDER_ID, CREATOR_UID, - CREATOR_PACKAGE); + CREATOR_PACKAGE, false); } /** |