diff options
author | Roshan Pius <rpius@google.com> | 2019-12-05 12:07:05 -0800 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2019-12-06 08:07:05 -0800 |
commit | ef68460486aa6f77d4a737686098a820ec68549b (patch) | |
tree | 7ab00456b15d0b4a3d99cd90da2282e81d896814 | |
parent | 31b57a859783e6e604830ac189d27ebd69cda9c6 (diff) |
WifiNetworkSuggestionManager: Store the uid/package name for suggestion
Associate each incoming suggestion to the package name/uid of the
calling app. This avoid explicitly stamping the uid/package name inside
individual suggestion objects. This is to avoid using an @hide API
inside WifiNetworkSuggestion to stamp the uid/package name of the app
using a retrieved context.
Note: This also requires some code to handle the migration of existing
config store data from the old WifiNetworkSuggestion object to the new
one. There is some code refactor in NetworkSuggestionStoreData to handle
both the store formats gracefully.
Bug: 144102365
Test: atest com.android.server.wifi
Change-Id: I9f48a34b5dd49842b2e134b0d1bb4eb49959a173
7 files changed, 534 insertions, 416 deletions
diff --git a/service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java b/service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java index 81af4b8b4..c8f370bcc 100644 --- a/service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java +++ b/service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java @@ -19,10 +19,10 @@ package com.android.server.wifi; import android.annotation.NonNull; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; -import android.net.wifi.WifiNetworkSuggestion; import android.util.LocalLog; import android.util.Log; +import com.android.server.wifi.WifiNetworkSuggestionsManager.ExtendedWifiNetworkSuggestion; import com.android.server.wifi.util.ScanResultUtil; import java.util.ArrayList; @@ -90,22 +90,22 @@ public class NetworkSuggestionEvaluator implements WifiNetworkSelector.NetworkEv + WifiNetworkSelector.toScanId(scanResult)); continue; } - Set<WifiNetworkSuggestion> matchingNetworkSuggestions = + Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions = mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(scanDetail); - if (matchingNetworkSuggestions == null || matchingNetworkSuggestions.isEmpty()) { + if (matchingExtNetworkSuggestions == null || matchingExtNetworkSuggestions.isEmpty()) { continue; } // All matching suggestions have the same network credentials type. So, use any one of // them to lookup/add the credentials to WifiConfigManager. // Note: Apps could provide different credentials (password, ceritificate) for the same // network, need to handle that in the future. - WifiNetworkSuggestion matchingNetworkSuggestion = - matchingNetworkSuggestions.stream().findAny().get(); + ExtendedWifiNetworkSuggestion matchingExtNetworkSuggestion = + matchingExtNetworkSuggestions.stream().findAny().get(); // Check if we already have a network with the same credentials in WifiConfigManager // database. WifiConfiguration wCmConfiguredNetwork = mWifiConfigManager.getConfiguredNetwork( - matchingNetworkSuggestion.wifiConfiguration.getKey()); + matchingExtNetworkSuggestion.wns.wifiConfiguration.getKey()); if (wCmConfiguredNetwork != null) { // If existing network is not from suggestion, ignore. if (!wCmConfiguredNetwork.fromWifiNetworkSuggestion) { @@ -113,9 +113,9 @@ public class NetworkSuggestionEvaluator implements WifiNetworkSelector.NetworkEv } // Update the WifiConfigManager with the latest WifiConfig NetworkUpdateResult result = mWifiConfigManager.addOrUpdateNetwork( - matchingNetworkSuggestion.wifiConfiguration, - matchingNetworkSuggestion.suggestorUid, - matchingNetworkSuggestion.suggestorPackageName); + matchingExtNetworkSuggestion.wns.wifiConfiguration, + matchingExtNetworkSuggestion.perAppInfo.uid, + matchingExtNetworkSuggestion.perAppInfo.packageName); if (result.isSuccess()) { wCmConfiguredNetwork = mWifiConfigManager.getConfiguredNetwork( result.getNetworkId()); @@ -128,7 +128,7 @@ public class NetworkSuggestionEvaluator implements WifiNetworkSelector.NetworkEv continue; } } - matchMetaInfo.putAll(matchingNetworkSuggestions, wCmConfiguredNetwork, scanDetail); + matchMetaInfo.putAll(matchingExtNetworkSuggestions, wCmConfiguredNetwork, scanDetail); } // Return early on no match. if (matchMetaInfo.isEmpty()) { @@ -181,14 +181,15 @@ public class NetworkSuggestionEvaluator implements WifiNetworkSelector.NetworkEv // Container classes to handle book-keeping while we're iterating through the scan list. private class PerNetworkSuggestionMatchMetaInfo { - public final WifiNetworkSuggestion wifiNetworkSuggestion; + public final ExtendedWifiNetworkSuggestion extWifiNetworkSuggestion; public final ScanDetail matchingScanDetail; public WifiConfiguration wCmConfiguredNetwork; // Added to WifiConfigManager. - PerNetworkSuggestionMatchMetaInfo(@NonNull WifiNetworkSuggestion wifiNetworkSuggestion, - @Nullable WifiConfiguration wCmConfiguredNetwork, - @NonNull ScanDetail matchingScanDetail) { - this.wifiNetworkSuggestion = wifiNetworkSuggestion; + PerNetworkSuggestionMatchMetaInfo( + @NonNull ExtendedWifiNetworkSuggestion extWifiNetworkSuggestion, + @Nullable WifiConfiguration wCmConfiguredNetwork, + @NonNull ScanDetail matchingScanDetail) { + this.extWifiNetworkSuggestion = extWifiNetworkSuggestion; this.wCmConfiguredNetwork = wCmConfiguredNetwork; this.matchingScanDetail = matchingScanDetail; } @@ -200,7 +201,7 @@ public class NetworkSuggestionEvaluator implements WifiNetworkSelector.NetworkEv /** * Add the network suggestion & associated info to this package meta info. */ - public void put(WifiNetworkSuggestion wifiNetworkSuggestion, + public void put(ExtendedWifiNetworkSuggestion wifiNetworkSuggestion, WifiConfiguration matchingWifiConfiguration, ScanDetail matchingScanDetail) { networkInfos.add(new PerNetworkSuggestionMatchMetaInfo( @@ -217,7 +218,7 @@ public class NetworkSuggestionEvaluator implements WifiNetworkSelector.NetworkEv Map<Integer, List<PerNetworkSuggestionMatchMetaInfo>> matchedNetworkInfosPerPriority = networkInfos.stream() .collect(Collectors.toMap( - e -> e.wifiNetworkSuggestion.wifiConfiguration.priority, + e -> e.extWifiNetworkSuggestion.wns.wifiConfiguration.priority, e -> Arrays.asList(e), (v1, v2) -> { // concatenate networks with the same priority. List<PerNetworkSuggestionMatchMetaInfo> concatList = @@ -241,14 +242,15 @@ public class NetworkSuggestionEvaluator implements WifiNetworkSelector.NetworkEv /** * Add all the network suggestion & associated info. */ - public void putAll(Set<WifiNetworkSuggestion> wifiNetworkSuggestions, + public void putAll(Set<ExtendedWifiNetworkSuggestion> wifiNetworkSuggestions, WifiConfiguration wCmConfiguredNetwork, ScanDetail matchingScanDetail) { // Separate the suggestions into buckets for each app to allow sorting based on // priorities set by app. - for (WifiNetworkSuggestion wifiNetworkSuggestion : wifiNetworkSuggestions) { + for (ExtendedWifiNetworkSuggestion wifiNetworkSuggestion : wifiNetworkSuggestions) { PerAppMatchMetaInfo appInfo = mAppInfos.computeIfAbsent( - wifiNetworkSuggestion.suggestorPackageName, k -> new PerAppMatchMetaInfo()); + wifiNetworkSuggestion.perAppInfo.packageName, + k -> new PerAppMatchMetaInfo()); appInfo.put(wifiNetworkSuggestion, wCmConfiguredNetwork, matchingScanDetail); } } @@ -278,9 +280,9 @@ public class NetworkSuggestionEvaluator implements WifiNetworkSelector.NetworkEv // if the network does not already exist in WifiConfigManager, add now. if (matchedNetworkInfo.wCmConfiguredNetwork == null) { matchedNetworkInfo.wCmConfiguredNetwork = addCandidateToWifiConfigManager( - matchedNetworkInfo.wifiNetworkSuggestion.wifiConfiguration, - matchedNetworkInfo.wifiNetworkSuggestion.suggestorUid, - matchedNetworkInfo.wifiNetworkSuggestion.suggestorPackageName); + matchedNetworkInfo.extWifiNetworkSuggestion.wns.wifiConfiguration, + matchedNetworkInfo.extWifiNetworkSuggestion.perAppInfo.uid, + matchedNetworkInfo.extWifiNetworkSuggestion.perAppInfo.packageName); if (matchedNetworkInfo.wCmConfiguredNetwork == null) continue; mLocalLog.log(String.format("network suggestion candidate %s (new)", WifiNetworkSelector.toNetworkString( diff --git a/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java b/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java index 9641f5c16..eaa58709a 100644 --- a/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java +++ b/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java @@ -41,7 +41,6 @@ import org.xmlpull.v1.XmlSerializer; import java.io.IOException; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -162,10 +161,11 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData { return; } for (Entry<String, PerAppInfo> entry : networkSuggestionsMap.entrySet()) { - String packageName = entry.getKey(); + String packageName = entry.getValue().packageName; String featureId = entry.getValue().featureId; boolean hasUserApproved = entry.getValue().hasUserApproved; int maxSize = entry.getValue().maxSize; + int uid = entry.getValue().uid; Set<ExtendedWifiNetworkSuggestion> networkSuggestions = entry.getValue().extNetworkSuggestions; XmlUtil.writeNextSectionStart(out, XML_TAG_SECTION_HEADER_NETWORK_SUGGESTION_PER_APP); @@ -173,6 +173,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData { XmlUtil.writeNextValue(out, XML_TAG_SUGGESTOR_FEATURE_ID, featureId); XmlUtil.writeNextValue(out, XML_TAG_SUGGESTOR_HAS_USER_APPROVED, hasUserApproved); XmlUtil.writeNextValue(out, XML_TAG_SUGGESTOR_MAX_SIZE, maxSize); + XmlUtil.writeNextValue(out, XML_TAG_SUGGESTOR_UID, uid); serializeExtNetworkSuggestions(out, networkSuggestions, encryptionUtil); XmlUtil.writeNextSectionEnd(out, XML_TAG_SECTION_HEADER_NETWORK_SUGGESTION_PER_APP); } @@ -234,10 +235,6 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData { suggestion.isUserInteractionRequired); XmlUtil.writeNextValue(out, XML_TAG_IS_USER_ALLOWED_TO_MANUALLY_CONNECT, suggestion.isUserAllowedToManuallyConnect); - XmlUtil.writeNextValue(out, XML_TAG_SUGGESTOR_UID, suggestion.suggestorUid); - XmlUtil.writeNextValue(out, XML_TAG_SUGGESTOR_PACKAGE_NAME, - suggestion.suggestorPackageName); - XmlUtil.writeNextSectionEnd(out, XML_TAG_SECTION_HEADER_NETWORK_SUGGESTION); } @@ -257,20 +254,74 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData { // Try/catch only runtime exceptions (like illegal args), any XML/IO exceptions are // fatal and should abort the entire loading process. try { - String packageName = - (String) XmlUtil.readNextValueWithName(in, XML_TAG_SUGGESTOR_PACKAGE_NAME); - String featureId = - (String) XmlUtil.readNextValueWithName(in, XML_TAG_SUGGESTOR_FEATURE_ID); - boolean hasUserApproved = (boolean) XmlUtil.readNextValueWithName(in, - XML_TAG_SUGGESTOR_HAS_USER_APPROVED); - int maxSize = (int) XmlUtil.readNextValueWithName(in, XML_TAG_SUGGESTOR_MAX_SIZE); - PerAppInfo perAppInfo = new PerAppInfo(packageName, featureId); - Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestions = - parseExtNetworkSuggestions( - in, outerTagDepth + 1, version, encryptionUtil, perAppInfo); - perAppInfo.hasUserApproved = hasUserApproved; - perAppInfo.maxSize = maxSize; - perAppInfo.extNetworkSuggestions.addAll(extNetworkSuggestions); + PerAppInfo perAppInfo = null; + String packageName = null; + String featureId = null; + boolean hasUserApproved = false; + int maxSize = -1; + int uid = Process.INVALID_UID; + // Loop through and parse out all the elements from the stream within this section. + while (XmlUtils.nextElementWithin(in, outerTagDepth + 1)) { + if (in.getAttributeValue(null, "name") != null) { + // Value elements. + String[] valueName = new String[1]; + Object value = XmlUtil.readCurrentValue(in, valueName); + switch (valueName[0]) { + case XML_TAG_SUGGESTOR_PACKAGE_NAME: + packageName = (String) value; + break; + case XML_TAG_SUGGESTOR_FEATURE_ID: + featureId = (String) value; + break; + case XML_TAG_SUGGESTOR_HAS_USER_APPROVED: + hasUserApproved = (boolean) value; + break; + case XML_TAG_SUGGESTOR_MAX_SIZE: + maxSize = (int) value; + break; + case XML_TAG_SUGGESTOR_UID: + uid = (int) value; + break; + default: + Log.w(TAG, "Ignoring unknown value name found: " + valueName[0]); + break; + } + } else { + String tagName = in.getName(); + if (tagName == null) { + throw new XmlPullParserException("Unexpected null under " + + XML_TAG_SECTION_HEADER_NETWORK_SUGGESTION_PER_APP); + } + // Create the PerAppInfo struct before parsing individual network + // suggestions in the block. + if (perAppInfo == null) { + if (packageName == null) { + throw new XmlPullParserException( + "XML parsing of PerAppInfo failed"); + } + perAppInfo = new PerAppInfo(uid, packageName, featureId); + perAppInfo.hasUserApproved = hasUserApproved; + perAppInfo.maxSize = maxSize; + } + switch (tagName) { + case XML_TAG_SECTION_HEADER_NETWORK_SUGGESTION: + WifiNetworkSuggestion networkSuggestion = + parseNetworkSuggestion( + in, outerTagDepth + 2, version, encryptionUtil, + perAppInfo); + perAppInfo.extNetworkSuggestions.add( + ExtendedWifiNetworkSuggestion.fromWns( + networkSuggestion, perAppInfo)); + break; + default: + Log.w(TAG, "Ignoring unknown tag under " + + XML_TAG_SECTION_HEADER_NETWORK_SUGGESTION_PER_APP + ": " + + in.getName()); + break; + } + } + } + // Store this app info in the map. networkSuggestionsMap.put(packageName, perAppInfo); } catch (RuntimeException e) { // Failed to parse this network, skip it. @@ -281,34 +332,6 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData { } /** - * Parse a set of network suggestions from an input stream in XML format. - * - * @throws XmlPullParserException - * @throws IOException - */ - private Set<ExtendedWifiNetworkSuggestion> parseExtNetworkSuggestions( - XmlPullParser in, int outerTagDepth, @WifiConfigStore.Version int version, - @Nullable WifiConfigStoreEncryptionUtil encryptionUtil, PerAppInfo perAppInfo) - throws XmlPullParserException, IOException { - Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestions = new HashSet<>(); - while (XmlUtil.gotoNextSectionWithNameOrEnd( - in, XML_TAG_SECTION_HEADER_NETWORK_SUGGESTION, outerTagDepth)) { - // Try/catch only runtime exceptions (like illegal args), any XML/IO exceptions are - // fatal and should abort the entire loading process. - try { - WifiNetworkSuggestion networkSuggestion = - parseNetworkSuggestion(in, outerTagDepth + 1, version, encryptionUtil); - extNetworkSuggestions.add(ExtendedWifiNetworkSuggestion.fromWns( - networkSuggestion, perAppInfo)); - } catch (RuntimeException e) { - // Failed to parse this network, skip it. - Log.e(TAG, "Failed to parse network suggestion. Skipping...", e); - } - } - return extNetworkSuggestions; - } - - /** * Parse a {@link ExtendedWifiNetworkSuggestion} from an input stream in XML format. * * @throws XmlPullParserException @@ -316,7 +339,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData { */ private WifiNetworkSuggestion parseNetworkSuggestion(XmlPullParser in, int outerTagDepth, @WifiConfigStore.Version int version, - @Nullable WifiConfigStoreEncryptionUtil encryptionUtil) + @Nullable WifiConfigStoreEncryptionUtil encryptionUtil, PerAppInfo perAppInfo) throws XmlPullParserException, IOException { Pair<String, WifiConfiguration> parsedConfig = null; WifiEnterpriseConfig enterpriseConfig = null; @@ -325,7 +348,6 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData { boolean isUserInteractionRequired = false; boolean isUserAllowedToManuallyConnect = false; // Backward compatibility. int suggestorUid = Process.INVALID_UID; - String suggestorPackageName = null; // Loop through and parse out all the elements from the stream within this section. while (XmlUtils.nextElementWithin(in, outerTagDepth)) { @@ -344,11 +366,9 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData { isUserAllowedToManuallyConnect = (boolean) value; break; case XML_TAG_SUGGESTOR_UID: + // Only needed for migration of data from Q to R. suggestorUid = (int) value; break; - case XML_TAG_SUGGESTOR_PACKAGE_NAME: - suggestorPackageName = (String) value; - break; default: Log.w(TAG, "Ignoring unknown value name found: " + valueName[0]); break; @@ -398,20 +418,17 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData { if (parsedConfig == null || parsedConfig.second == null) { throw new XmlPullParserException("XML parsing of wifi configuration failed"); } - if (suggestorUid == -1) { - throw new XmlPullParserException("XML parsing of suggestor uid failed"); - } - if (suggestorPackageName == null) { - throw new XmlPullParserException("XML parsing of suggestor package name failed"); - } + // Note: In R, we migrated the uid/package name storage from individual + // ExtWifiNetworkSuggestion to the top level PerAppInfo. This block of code helps + // with migration of data for devices upgrading from Q to R. + perAppInfo.setUid(suggestorUid); WifiConfiguration wifiConfiguration = parsedConfig.second; if (enterpriseConfig != null) { wifiConfiguration.enterpriseConfig = enterpriseConfig; } return new WifiNetworkSuggestion( wifiConfiguration, passpointConfiguration, isAppInteractionRequired, - isUserInteractionRequired, isUserAllowedToManuallyConnect, - suggestorUid, suggestorPackageName); + isUserInteractionRequired, isUserAllowedToManuallyConnect); } } diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java index 6eb4c5930..70c30dd58 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java +++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java @@ -42,6 +42,7 @@ import android.net.wifi.WifiNetworkSuggestion; import android.net.wifi.WifiScanner; import android.os.Handler; import android.os.IBinder; +import android.os.Process; import android.os.RemoteException; import android.os.UserHandle; import android.telephony.TelephonyManager; @@ -122,6 +123,10 @@ public class WifiNetworkSuggestionsManager { */ public static class PerAppInfo { /** + * UID of the app. + */ + public int uid; + /** * Package Name of the app. */ public final String packageName; @@ -141,18 +146,30 @@ public class WifiNetworkSuggestionsManager { /** Stores the max size of the {@link #extNetworkSuggestions} list ever for this app */ public int maxSize = 0; - public PerAppInfo(@NonNull String packageName, @Nullable String featureId) { + public PerAppInfo(int uid, @NonNull String packageName, @Nullable String featureId) { + this.uid = uid; this.packageName = packageName; this.featureId = featureId; } + /** + * Needed for migration of config store data. + */ + public void setUid(int uid) { + if (this.uid == Process.INVALID_UID) { + this.uid = uid; + } + // else ignored. + } + // This is only needed for comparison in unit tests. @Override public boolean equals(Object other) { if (other == null) return false; if (!(other instanceof PerAppInfo)) return false; PerAppInfo otherPerAppInfo = (PerAppInfo) other; - return TextUtils.equals(packageName, otherPerAppInfo.packageName) + return uid == otherPerAppInfo.uid + && TextUtils.equals(packageName, otherPerAppInfo.packageName) && Objects.equals(extNetworkSuggestions, otherPerAppInfo.extNetworkSuggestions) && hasUserApproved == otherPerAppInfo.hasUserApproved; } @@ -160,7 +177,18 @@ public class WifiNetworkSuggestionsManager { // This is only needed for comparison in unit tests. @Override public int hashCode() { - return Objects.hash(packageName, extNetworkSuggestions, hasUserApproved); + return Objects.hash(uid, packageName, extNetworkSuggestions, hasUserApproved); + } + + @Override + public String toString() { + return new StringBuilder("PerAppInfo[ ") + .append("uid=").append(uid) + .append(", packageName=").append(packageName) + .append(", hasUserApproved=").append(hasUserApproved) + .append(", suggestions=").append(extNetworkSuggestions) + .append(" ]") + .toString(); } } @@ -182,7 +210,7 @@ public class WifiNetworkSuggestionsManager { @Override public int hashCode() { - return Objects.hash(wns); // perAppInfo not used for equals. + return Objects.hash(wns, perAppInfo.uid, perAppInfo.packageName); } @Override @@ -194,12 +222,14 @@ public class WifiNetworkSuggestionsManager { return false; } ExtendedWifiNetworkSuggestion other = (ExtendedWifiNetworkSuggestion) obj; - return wns.equals(other.wns); // perAppInfo not used for equals. + return wns.equals(other.wns) + && perAppInfo.uid == other.perAppInfo.uid + && TextUtils.equals(perAppInfo.packageName, other.perAppInfo.packageName); } @Override public String toString() { - return "Extended" + wns.toString(); + return wns.toString(); } /** @@ -335,7 +365,7 @@ public class WifiNetworkSuggestionsManager { if (!extNetworkSuggestions.isEmpty()) { // Start tracking app-op changes from the app if they have active suggestions. startTrackingAppOpsChange(packageName, - extNetworkSuggestions.iterator().next().wns.suggestorUid); + extNetworkSuggestions.iterator().next().perAppInfo.uid); } for (ExtendedWifiNetworkSuggestion ewns : extNetworkSuggestions) { if (ewns.wns.wifiConfiguration.FQDN != null) { @@ -622,7 +652,7 @@ public class WifiNetworkSuggestionsManager { } PerAppInfo perAppInfo = mActiveNetworkSuggestionsPerApp.get(packageName); if (perAppInfo == null) { - perAppInfo = new PerAppInfo(packageName, featureId); + perAppInfo = new PerAppInfo(uid, packageName, featureId); mActiveNetworkSuggestionsPerApp.put(packageName, perAppInfo); if (mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(uid)) { Log.i(TAG, "Setting the carrier provisioning app approved"); @@ -733,7 +763,7 @@ public class WifiNetworkSuggestionsManager { if (ewns.wns.wifiConfiguration.FQDN != null) { // Clear the Passpoint config. mWifiInjector.getPasspointManager().removeProvider( - ewns.wns.suggestorUid, + ewns.perAppInfo.uid, false, ewns.wns.wifiConfiguration.FQDN); removeFromPassPointInfoMap(ewns); @@ -985,7 +1015,7 @@ public class WifiNetworkSuggestionsManager { /** * Returns a set of all network suggestions matching the provided scan detail. */ - public @Nullable Set<WifiNetworkSuggestion> getNetworkSuggestionsForScanDetail( + public @Nullable Set<ExtendedWifiNetworkSuggestion> getNetworkSuggestionsForScanDetail( @NonNull ScanDetail scanDetail) { ScanResult scanResult = scanDetail.getScanResult(); if (scanResult == null) { @@ -1033,7 +1063,7 @@ public class WifiNetworkSuggestionsManager { for (ExtendedWifiNetworkSuggestion extNetworkSuggestion : extNetworkSuggestions) { if (sendUserApprovalNotificationIfNotApproved( extNetworkSuggestion.perAppInfo.packageName, - extNetworkSuggestion.wns.suggestorUid)) { + extNetworkSuggestion.perAppInfo.uid)) { break; } } @@ -1046,7 +1076,7 @@ public class WifiNetworkSuggestionsManager { + approvedExtNetworkSuggestions + " for " + scanResult.SSID + "[" + scanResult.capabilities + "]"); } - return convertToWnsSet(approvedExtNetworkSuggestions); + return approvedExtNetworkSuggestions; } /** @@ -1079,7 +1109,7 @@ public class WifiNetworkSuggestionsManager { return null; } if (mVerboseLoggingEnabled) { - Log.v(TAG, "getNetworkSuggestionsFoWifiConfiguration Found " + Log.v(TAG, "getNetworkSuggestionsForWifiConfiguration Found " + approvedExtNetworkSuggestions + " for " + wifiConfiguration.SSID + wifiConfiguration.FQDN + "[" + wifiConfiguration.allowedKeyManagement + "]"); } @@ -1112,32 +1142,35 @@ public class WifiNetworkSuggestionsManager { * Helper method to send the post connection broadcast to specified package. */ private void sendPostConnectionBroadcast( - String packageName, WifiNetworkSuggestion networkSuggestion) { + ExtendedWifiNetworkSuggestion extSuggestion) { Intent intent = new Intent(WifiManager.ACTION_WIFI_NETWORK_SUGGESTION_POST_CONNECTION); - intent.putExtra(WifiManager.EXTRA_NETWORK_SUGGESTION, networkSuggestion); + intent.putExtra(WifiManager.EXTRA_NETWORK_SUGGESTION, extSuggestion.wns); // Intended to wakeup the receiving app so set the specific package name. - intent.setPackage(packageName); + intent.setPackage(extSuggestion.perAppInfo.packageName); mContext.sendBroadcastAsUser( - intent, UserHandle.getUserHandleForUid(networkSuggestion.suggestorUid)); + intent, UserHandle.getUserHandleForUid(extSuggestion.perAppInfo.uid)); } /** * Helper method to send the post connection broadcast to specified package. */ private void sendPostConnectionBroadcastIfAllowed( - String packageName, String featureId, WifiNetworkSuggestion matchingSuggestion, - @NonNull String message) { + ExtendedWifiNetworkSuggestion matchingExtSuggestion, @NonNull String message) { try { mWifiPermissionsUtil.enforceCanAccessScanResults( - packageName, featureId, matchingSuggestion.suggestorUid, message); + matchingExtSuggestion.perAppInfo.packageName, + matchingExtSuggestion.perAppInfo.featureId, + matchingExtSuggestion.perAppInfo.uid, message); } catch (SecurityException se) { - Log.w(TAG, "Permission denied for sending post connection broadcast to " + packageName); + Log.w(TAG, "Permission denied for sending post connection broadcast to " + + matchingExtSuggestion.perAppInfo.packageName); return; } if (mVerboseLoggingEnabled) { - Log.v(TAG, "Sending post connection broadcast to " + packageName); + Log.v(TAG, "Sending post connection broadcast to " + + matchingExtSuggestion.perAppInfo.packageName); } - sendPostConnectionBroadcast(packageName, matchingSuggestion); + sendPostConnectionBroadcast(matchingExtSuggestion); } /** @@ -1170,7 +1203,7 @@ public class WifiNetworkSuggestionsManager { // Find subset of network suggestions from app suggested the connected network. matchingExtNetworkSuggestions = matchingExtNetworkSuggestions.stream() - .filter(x -> x.wns.suggestorUid == connectedNetwork.creatorUid) + .filter(x -> x.perAppInfo.uid == connectedNetwork.creatorUid) .collect(Collectors.toSet()); if (matchingExtNetworkSuggestions.isEmpty()) { Log.wtf(TAG, "Current connected network suggestion is missing!"); @@ -1197,9 +1230,7 @@ public class WifiNetworkSuggestionsManager { for (ExtendedWifiNetworkSuggestion matchingExtNetworkSuggestion : matchingExtNetworkSuggestionsWithReqAppInteraction) { sendPostConnectionBroadcastIfAllowed( - matchingExtNetworkSuggestion.perAppInfo.packageName, - matchingExtNetworkSuggestion.perAppInfo.featureId, - matchingExtNetworkSuggestion.wns, + matchingExtNetworkSuggestion, "Connected to " + matchingExtNetworkSuggestion.wns.wifiConfiguration.SSID + ". featureId is first feature of the app using network suggestions"); } @@ -1233,7 +1264,7 @@ public class WifiNetworkSuggestionsManager { // Find subset of network suggestions which suggested the connection failure network. Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestionsFromTargetApp = matchingExtNetworkSuggestions.stream() - .filter(x -> x.wns.suggestorUid == network.creatorUid) + .filter(x -> x.perAppInfo.uid == network.creatorUid) .collect(Collectors.toSet()); if (matchingExtNetworkSuggestionsFromTargetApp.isEmpty()) { Log.wtf(TAG, "Current connection failure network suggestion is missing!"); @@ -1244,6 +1275,7 @@ public class WifiNetworkSuggestionsManager { : matchingExtNetworkSuggestionsFromTargetApp) { sendConnectionFailureIfAllowed(matchingExtNetworkSuggestion.perAppInfo.packageName, matchingExtNetworkSuggestion.perAppInfo.featureId, + matchingExtNetworkSuggestion.perAppInfo.uid, matchingExtNetworkSuggestion.wns, failureCode); } } @@ -1286,11 +1318,12 @@ public class WifiNetworkSuggestionsManager { * Send network connection failure event to app when an connection attempt failure. * @param packageName package name to send event * @param featureId The feature in the package + * @param uid uid of the app. * @param matchingSuggestion suggestion on this connection failure * @param connectionEvent connection failure code */ private void sendConnectionFailureIfAllowed(String packageName, @Nullable String featureId, - @NonNull WifiNetworkSuggestion matchingSuggestion, int connectionEvent) { + int uid, @NonNull WifiNetworkSuggestion matchingSuggestion, int connectionEvent) { ExternalCallbackTracker<ISuggestionConnectionStatusListener> listenersTracker = mSuggestionStatusListenerPerApp.get(packageName); if (listenersTracker == null || listenersTracker.getNumCallbacks() == 0) { @@ -1298,8 +1331,7 @@ public class WifiNetworkSuggestionsManager { } try { mWifiPermissionsUtil.enforceCanAccessScanResults( - packageName, featureId, matchingSuggestion.suggestorUid, - "Connection failure"); + packageName, featureId, uid, "Connection failure"); } catch (SecurityException se) { Log.w(TAG, "Permission denied for sending connection failure event to " + packageName); return; diff --git a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionEvaluatorTest.java index 5df1fe97f..b130ca794 100644 --- a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionEvaluatorTest.java @@ -33,6 +33,9 @@ import android.util.Pair; import androidx.test.filters.SmallTest; +import com.android.server.wifi.WifiNetworkSuggestionsManager.ExtendedWifiNetworkSuggestion; +import com.android.server.wifi.WifiNetworkSuggestionsManager.PerAppInfo; + import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -93,8 +96,8 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { ScanDetail[] scanDetails = buildScanDetails(scanSsids, bssids, freqs, caps, levels, mClock); - WifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, securities, - appInteractions, meteredness, priorities, uids, packageNames); + ExtendedWifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, + securities, appInteractions, meteredness, priorities, uids, packageNames); // Link the scan result with suggestions. linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions); @@ -131,12 +134,12 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { ScanDetail[] scanDetails = buildScanDetails(scanSsids, bssids, freqs, caps, levels, mClock); - WifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, securities, - appInteractions, meteredness, priorities, uids, packageNames); + ExtendedWifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, + securities, appInteractions, meteredness, priorities, uids, packageNames); // Link the scan result with suggestions. linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions); // setup config manager interactions. - setupAddToWifiConfigManager(suggestions[0].wifiConfiguration); + setupAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration); List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>(); WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks( @@ -150,7 +153,7 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { validateConnectableNetworks(connectableNetworks, scanSsids[0]); - verifyAddToWifiConfigManager(suggestions[0].wifiConfiguration); + verifyAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration); } /** @@ -176,13 +179,13 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { ScanDetail[] scanDetails = buildScanDetails(scanSsids, bssids, freqs, caps, levels, mClock); - WifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, securities, - appInteractions, meteredness, priorities, uids, packageNames); + ExtendedWifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, + securities, appInteractions, meteredness, priorities, uids, packageNames); // Link the scan result with suggestions. linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions); // setup config manager interactions. - setupAddToWifiConfigManager(suggestions[0].wifiConfiguration, - suggestions[1].wifiConfiguration); + setupAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration, + suggestions[1].wns.wifiConfiguration); List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>(); WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks( @@ -196,8 +199,8 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { validateConnectableNetworks(connectableNetworks, scanSsids[0], scanSsids[1]); - verifyAddToWifiConfigManager(suggestions[1].wifiConfiguration, - suggestions[1].wifiConfiguration); + verifyAddToWifiConfigManager(suggestions[1].wns.wifiConfiguration, + suggestions[1].wns.wifiConfiguration); } /** @@ -223,13 +226,13 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { ScanDetail[] scanDetails = buildScanDetails(scanSsids, bssids, freqs, caps, levels, mClock); - WifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, securities, - appInteractions, meteredness, priorities, uids, packageNames); + ExtendedWifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, + securities, appInteractions, meteredness, priorities, uids, packageNames); // Link the scan result with suggestions. linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions); // setup config manager interactions. - setupAddToWifiConfigManager(suggestions[0].wifiConfiguration, - suggestions[1].wifiConfiguration); + setupAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration, + suggestions[1].wns.wifiConfiguration); List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>(); WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks( @@ -243,7 +246,7 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { validateConnectableNetworks(connectableNetworks, scanSsids[0]); - verifyAddToWifiConfigManager(suggestions[0].wifiConfiguration); + verifyAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration); } /** @@ -273,13 +276,13 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { ScanDetail[] scanDetails = buildScanDetails(scanSsids, bssids, freqs, caps, levels, mClock); - WifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, securities, - appInteractions, meteredness, priorities, uids, packageNames); + ExtendedWifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, + securities, appInteractions, meteredness, priorities, uids, packageNames); // Link the scan result with suggestions. linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions); // setup config manager interactions. - setupAddToWifiConfigManager(suggestions[0].wifiConfiguration, - suggestions[1].wifiConfiguration, suggestions[2].wifiConfiguration); + setupAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration, + suggestions[1].wns.wifiConfiguration, suggestions[2].wns.wifiConfiguration); List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>(); WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks( @@ -293,8 +296,8 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { validateConnectableNetworks(connectableNetworks, scanSsids); - verifyAddToWifiConfigManager(suggestions[0].wifiConfiguration, - suggestions[1].wifiConfiguration); + verifyAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration, + suggestions[1].wns.wifiConfiguration); } /** @@ -332,14 +335,14 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { ScanDetail[] scanDetails = buildScanDetails(scanSsids, bssids, freqs, caps, levels, mClock); - WifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, securities, - appInteractions, meteredness, priorities, uids, packageNames); + ExtendedWifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, + securities, appInteractions, meteredness, priorities, uids, packageNames); // Link the scan result with suggestions. linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions); // setup config manager interactions. - setupAddToWifiConfigManager(suggestions[0].wifiConfiguration, - suggestions[1].wifiConfiguration, suggestions[2].wifiConfiguration, - suggestions[3].wifiConfiguration); + setupAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration, + suggestions[1].wns.wifiConfiguration, suggestions[2].wns.wifiConfiguration, + suggestions[3].wns.wifiConfiguration); List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>(); WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks( @@ -353,8 +356,8 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { validateConnectableNetworks(connectableNetworks, scanSsids[1], scanSsids[2], scanSsids[3]); - verifyAddToWifiConfigManager(suggestions[1].wifiConfiguration, - suggestions[2].wifiConfiguration, suggestions[3].wifiConfiguration); + verifyAddToWifiConfigManager(suggestions[1].wns.wifiConfiguration, + suggestions[2].wns.wifiConfiguration, suggestions[3].wns.wifiConfiguration); } /** @@ -380,8 +383,8 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { ScanDetail[] scanDetails = buildScanDetails(scanSsids, bssids, freqs, caps, levels, mClock); - WifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, securities, - appInteractions, meteredness, priorities, uids, packageNames); + ExtendedWifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, + securities, appInteractions, meteredness, priorities, uids, packageNames); // Link the scan result with suggestions. linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions); // Fail add to WifiConfigManager @@ -401,7 +404,7 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { verify(mWifiConfigManager, times(scanSsids.length)) .wasEphemeralNetworkDeleted(anyString()); verify(mWifiConfigManager).getConfiguredNetwork(eq( - suggestions[0].wifiConfiguration.getKey())); + suggestions[0].wns.wifiConfiguration.getKey())); verify(mWifiConfigManager).addOrUpdateNetwork(any(), anyInt(), anyString()); // Verify we did not try to add any new networks or other interactions with // WifiConfigManager. @@ -431,17 +434,17 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { ScanDetail[] scanDetails = buildScanDetails(scanSsids, bssids, freqs, caps, levels, mClock); - WifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, securities, - appInteractions, meteredness, priorities, uids, packageNames); + ExtendedWifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, + securities, appInteractions, meteredness, priorities, uids, packageNames); // Link the scan result with suggestions. linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions); // setup config manager interactions. - suggestions[0].wifiConfiguration.fromWifiNetworkSuggestion = true; - suggestions[0].wifiConfiguration.ephemeral = true; - setupAddToWifiConfigManager(suggestions[0].wifiConfiguration); + suggestions[0].wns.wifiConfiguration.fromWifiNetworkSuggestion = true; + suggestions[0].wns.wifiConfiguration.ephemeral = true; + setupAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration); // Existing saved network matching the credentials. - when(mWifiConfigManager.getConfiguredNetwork(suggestions[0].wifiConfiguration.getKey())) - .thenReturn(suggestions[0].wifiConfiguration); + when(mWifiConfigManager.getConfiguredNetwork(suggestions[0].wns.wifiConfiguration.getKey())) + .thenReturn(suggestions[0].wns.wifiConfiguration); List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>(); WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks( @@ -459,9 +462,10 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { verify(mWifiConfigManager, times(scanSsids.length)) .wasEphemeralNetworkDeleted(anyString()); verify(mWifiConfigManager).getConfiguredNetwork(candidate.getKey()); - verify(mWifiConfigManager).addOrUpdateNetwork(eq(suggestions[0].wifiConfiguration), - eq(suggestions[0].suggestorUid), eq(suggestions[0].suggestorPackageName)); - verify(mWifiConfigManager).getConfiguredNetwork(suggestions[0].wifiConfiguration.networkId); + verify(mWifiConfigManager).addOrUpdateNetwork(eq(suggestions[0].wns.wifiConfiguration), + eq(suggestions[0].perAppInfo.uid), eq(suggestions[0].perAppInfo.packageName)); + verify(mWifiConfigManager).getConfiguredNetwork( + suggestions[0].wns.wifiConfiguration.networkId); // Verify we did not try to add any new networks or other interactions with // WifiConfigManager. verifyNoMoreInteractions(mWifiConfigManager); @@ -490,12 +494,12 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { ScanDetail[] scanDetails = buildScanDetails(scanSsids, bssids, freqs, caps, levels, mClock); - WifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, securities, - appInteractions, meteredness, priorities, uids, packageNames); + ExtendedWifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, + securities, appInteractions, meteredness, priorities, uids, packageNames); // Link the scan result with suggestions. linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions); // setup config manager interactions. - setupAddToWifiConfigManager(suggestions[0].wifiConfiguration); + setupAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration); // Network was disabled by the user. when(mWifiConfigManager.wasEphemeralNetworkDeleted(suggestionSsids[0])).thenReturn(true); @@ -540,20 +544,20 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { ScanDetail[] scanDetails = buildScanDetails(scanSsids, bssids, freqs, caps, levels, mClock); - WifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, securities, - appInteractions, meteredness, priorities, uids, packageNames); + ExtendedWifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, + securities, appInteractions, meteredness, priorities, uids, packageNames); // Link the scan result with suggestions. linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions); // setup config manager interactions. - suggestions[0].wifiConfiguration.fromWifiNetworkSuggestion = true; - suggestions[0].wifiConfiguration.ephemeral = true; - setupAddToWifiConfigManager(suggestions[0].wifiConfiguration); + suggestions[0].wns.wifiConfiguration.fromWifiNetworkSuggestion = true; + suggestions[0].wns.wifiConfiguration.ephemeral = true; + setupAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration); // Mark the network disabled. - suggestions[0].wifiConfiguration.getNetworkSelectionStatus().setNetworkSelectionStatus( + suggestions[0].wns.wifiConfiguration.getNetworkSelectionStatus().setNetworkSelectionStatus( NETWORK_SELECTION_TEMPORARY_DISABLED); // Existing network matching the credentials. - when(mWifiConfigManager.getConfiguredNetwork(suggestions[0].wifiConfiguration.getKey())) - .thenReturn(suggestions[0].wifiConfiguration); + when(mWifiConfigManager.getConfiguredNetwork(suggestions[0].wns.wifiConfiguration.getKey())) + .thenReturn(suggestions[0].wns.wifiConfiguration); List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>(); WifiConfiguration candidate = mNetworkSuggestionEvaluator.evaluateNetworks( @@ -568,12 +572,13 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { verify(mWifiConfigManager, times(scanSsids.length)) .wasEphemeralNetworkDeleted(anyString()); verify(mWifiConfigManager).getConfiguredNetwork(eq( - suggestions[0].wifiConfiguration.getKey())); - verify(mWifiConfigManager).addOrUpdateNetwork(eq(suggestions[0].wifiConfiguration), - eq(suggestions[0].suggestorUid), eq(suggestions[0].suggestorPackageName)); - verify(mWifiConfigManager).getConfiguredNetwork(suggestions[0].wifiConfiguration.networkId); + suggestions[0].wns.wifiConfiguration.getKey())); + verify(mWifiConfigManager).addOrUpdateNetwork(eq(suggestions[0].wns.wifiConfiguration), + eq(suggestions[0].perAppInfo.uid), eq(suggestions[0].perAppInfo.packageName)); + verify(mWifiConfigManager).getConfiguredNetwork( + suggestions[0].wns.wifiConfiguration.networkId); verify(mWifiConfigManager).tryEnableNetwork(eq( - suggestions[0].wifiConfiguration.networkId)); + suggestions[0].wns.wifiConfiguration.networkId)); // Verify we did not try to add any new networks or other interactions with // WifiConfigManager. verifyNoMoreInteractions(mWifiConfigManager); @@ -603,21 +608,21 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { ScanDetail[] scanDetails = buildScanDetails(scanSsids, bssids, freqs, caps, levels, mClock); - WifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, securities, - appInteractions, meteredness, priorities, uids, packageNames); + ExtendedWifiNetworkSuggestion[] suggestions = buildNetworkSuggestions(suggestionSsids, + securities, appInteractions, meteredness, priorities, uids, packageNames); // Link the scan result with suggestions. linkScanDetailsWithNetworkSuggestions(scanDetails, suggestions); // setup config manager interactions. - suggestions[0].wifiConfiguration.fromWifiNetworkSuggestion = true; - suggestions[0].wifiConfiguration.ephemeral = true; - setupAddToWifiConfigManager(suggestions[0].wifiConfiguration); + suggestions[0].wns.wifiConfiguration.fromWifiNetworkSuggestion = true; + suggestions[0].wns.wifiConfiguration.ephemeral = true; + setupAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration); // Mark the network disabled. - suggestions[0].wifiConfiguration.getNetworkSelectionStatus().setNetworkSelectionStatus( + suggestions[0].wns.wifiConfiguration.getNetworkSelectionStatus().setNetworkSelectionStatus( NETWORK_SELECTION_TEMPORARY_DISABLED); // Existing network matching the credentials. - when(mWifiConfigManager.getConfiguredNetwork(suggestions[0].wifiConfiguration.getKey())) - .thenReturn(suggestions[0].wifiConfiguration); - when(mWifiConfigManager.tryEnableNetwork(suggestions[0].wifiConfiguration.networkId)) + when(mWifiConfigManager.getConfiguredNetwork(suggestions[0].wns.wifiConfiguration.getKey())) + .thenReturn(suggestions[0].wns.wifiConfiguration); + when(mWifiConfigManager.tryEnableNetwork(suggestions[0].wns.wifiConfiguration.networkId)) .thenReturn(true); List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>(); @@ -635,12 +640,13 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { verify(mWifiConfigManager, times(scanSsids.length)) .wasEphemeralNetworkDeleted(anyString()); verify(mWifiConfigManager).getConfiguredNetwork(eq( - suggestions[0].wifiConfiguration.getKey())); - verify(mWifiConfigManager).addOrUpdateNetwork(eq(suggestions[0].wifiConfiguration), - eq(suggestions[0].suggestorUid), eq(suggestions[0].suggestorPackageName)); - verify(mWifiConfigManager).getConfiguredNetwork(suggestions[0].wifiConfiguration.networkId); + suggestions[0].wns.wifiConfiguration.getKey())); + verify(mWifiConfigManager).addOrUpdateNetwork(eq(suggestions[0].wns.wifiConfiguration), + eq(suggestions[0].perAppInfo.uid), eq(suggestions[0].perAppInfo.packageName)); + verify(mWifiConfigManager).getConfiguredNetwork( + suggestions[0].wns.wifiConfiguration.networkId); verify(mWifiConfigManager).tryEnableNetwork(eq( - suggestions[0].wifiConfiguration.networkId)); + suggestions[0].wns.wifiConfiguration.networkId)); // Verify we did not try to add any new networks or other interactions with // WifiConfigManager. verifyNoMoreInteractions(mWifiConfigManager); @@ -734,18 +740,21 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { return configs; } - private WifiNetworkSuggestion[] buildNetworkSuggestions( + private ExtendedWifiNetworkSuggestion[] buildNetworkSuggestions( String[] ssids, int[] securities, boolean[] appInteractions, boolean[] meteredness, int[] priorities, int[] uids, String[] packageNames) { WifiConfiguration[] configs = buildWifiConfigurations(ssids, securities); - WifiNetworkSuggestion[] suggestions = new WifiNetworkSuggestion[configs.length]; + ExtendedWifiNetworkSuggestion[] suggestions = + new ExtendedWifiNetworkSuggestion[configs.length]; for (int i = 0; i < configs.length; i++) { configs[i].priority = priorities[i]; configs[i].meteredOverride = meteredness[i] ? WifiConfiguration.METERED_OVERRIDE_METERED : WifiConfiguration.METERED_OVERRIDE_NONE; - suggestions[i] = new WifiNetworkSuggestion(configs[i], null, appInteractions[i], - false, true, uids[i], packageNames[i]); + PerAppInfo perAppInfo = new PerAppInfo(uids[i], packageNames[i], null); + WifiNetworkSuggestion suggestion = + new WifiNetworkSuggestion(configs[i], null, appInteractions[i], false, true); + suggestions[i] = new ExtendedWifiNetworkSuggestion(suggestion, perAppInfo); } return suggestions; } @@ -761,7 +770,7 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { * suggestions will be associated with the last scan detail. */ private void linkScanDetailsWithNetworkSuggestions( - ScanDetail[] scanDetails, WifiNetworkSuggestion[] suggestions) { + ScanDetail[] scanDetails, ExtendedWifiNetworkSuggestion[] suggestions) { if (suggestions == null || scanDetails == null) { return; } @@ -770,9 +779,9 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { // 1 to 1 mapping from scan detail to suggestion. for (int i = 0; i < minLength; i++) { ScanDetail scanDetail = scanDetails[i]; - final WifiNetworkSuggestion matchingSuggestion = suggestions[i]; - HashSet<WifiNetworkSuggestion> matchingSuggestions = - new HashSet<WifiNetworkSuggestion>() {{ + final ExtendedWifiNetworkSuggestion matchingSuggestion = suggestions[i]; + HashSet<ExtendedWifiNetworkSuggestion> matchingSuggestions = + new HashSet<ExtendedWifiNetworkSuggestion>() {{ add(matchingSuggestion); }}; when(mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(eq(scanDetail))) @@ -787,7 +796,7 @@ public class NetworkSuggestionEvaluatorTest extends WifiBaseTest { } } else if (suggestions.length > scanDetails.length) { // All the additional suggestions match the last scan detail. - HashSet<WifiNetworkSuggestion> matchingSuggestions = new HashSet<>(); + HashSet<ExtendedWifiNetworkSuggestion> matchingSuggestions = new HashSet<>(); for (int i = minLength; i < suggestions.length; i++) { matchingSuggestions.add(suggestions[i]); } diff --git a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java index 16c942cd2..1fb68faaf 100644 --- a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java +++ b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionStoreDataTest.java @@ -28,7 +28,6 @@ import androidx.test.filters.SmallTest; import com.android.internal.util.FastXmlSerializer; import com.android.server.wifi.WifiNetworkSuggestionsManager.ExtendedWifiNetworkSuggestion; import com.android.server.wifi.WifiNetworkSuggestionsManager.PerAppInfo; -import com.android.server.wifi.util.WifiConfigStoreEncryptionUtil; import org.junit.Before; import org.junit.Test; @@ -36,7 +35,6 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlSerializer; import java.io.ByteArrayInputStream; @@ -55,6 +53,119 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { private static final String TEST_PACKAGE_NAME_1 = "com.android.test.1"; private static final String TEST_PACKAGE_NAME_2 = "com.android.test.2"; private static final String TEST_FEATURE_ID = "com.android.feature.1"; + private static final String TEST_PRE_R_STORE_FORMAT_XML_STRING = + "<NetworkSuggestionPerApp>\n" + + "<string name=\"SuggestorPackageName\">%1$s</string>\n" + + "<string name=\"SuggestorFeatureId\">com.android.feature.1</string>\n" + + "<boolean name=\"SuggestorHasUserApproved\" value=\"false\" />\n" + + "<int name=\"SuggestorMaxSize\" value=\"100\" />\n" + + "<NetworkSuggestion>\n" + + "<WifiConfiguration>\n" + + "<string name=\"ConfigKey\">"WifiConfigurationTestSSID0"" + + "WPA_PSK</string>\n" + + "<string name=\"SSID\">"WifiConfigurationTestSSID0"</string>\n" + + "<null name=\"BSSID\" />\n" + + "<string name=\"PreSharedKey\">"WifiConfigurationTestUtilPsk"" + + "</string>\n" + + "<null name=\"SaePasswordId\" />\n" + + "<null name=\"WEPKeys\" />\n" + + "<int name=\"WEPTxKeyIndex\" value=\"0\" />\n" + + "<boolean name=\"HiddenSSID\" value=\"false\" />\n" + + "<boolean name=\"RequirePMF\" value=\"false\" />\n" + + "<byte-array name=\"AllowedKeyMgmt\" num=\"1\">02</byte-array>\n" + + "<byte-array name=\"AllowedProtocols\" num=\"0\"></byte-array>\n" + + "<byte-array name=\"AllowedAuthAlgos\" num=\"0\"></byte-array>\n" + + "<byte-array name=\"AllowedGroupCiphers\" num=\"0\"></byte-array>\n" + + "<byte-array name=\"AllowedPairwiseCiphers\" num=\"0\"></byte-array>\n" + + "<byte-array name=\"AllowedGroupMgmtCiphers\" num=\"0\"></byte-array>\n" + + "<byte-array name=\"AllowedSuiteBCiphers\" num=\"0\"></byte-array>\n" + + "<boolean name=\"Shared\" value=\"true\" />\n" + + "<int name=\"Status\" value=\"2\" />\n" + + "<null name=\"FQDN\" />\n" + + "<null name=\"ProviderFriendlyName\" />\n" + + "<null name=\"LinkedNetworksList\" />\n" + + "<null name=\"DefaultGwMacAddress\" />\n" + + "<boolean name=\"ValidatedInternetAccess\" value=\"false\" />\n" + + "<boolean name=\"NoInternetAccessExpected\" value=\"false\" />\n" + + "<boolean name=\"MeteredHint\" value=\"false\" />\n" + + "<int name=\"MeteredOverride\" value=\"0\" />\n" + + "<boolean name=\"UseExternalScores\" value=\"false\" />\n" + + "<int name=\"NumAssociation\" value=\"0\" />\n" + + "<int name=\"CreatorUid\" value=\"5\" />\n" + + "<null name=\"CreatorName\" />\n" + + "<null name=\"CreationTime\" />\n" + + "<int name=\"LastUpdateUid\" value=\"-1\" />\n" + + "<null name=\"LastUpdateName\" />\n" + + "<int name=\"LastConnectUid\" value=\"0\" />\n" + + "<boolean name=\"IsLegacyPasspointConfig\" value=\"false\" />\n" + + "<long-array name=\"RoamingConsortiumOIs\" num=\"0\" />\n" + + "<string name=\"RandomizedMacAddress\">02:00:00:00:00:00</string>\n" + + "<int name=\"MacRandomizationSetting\" value=\"1\" />\n" + + "<int name=\"CarrierId\" value=\"-1\" />\n" + + "</WifiConfiguration>\n" + + "<boolean name=\"IsAppInteractionRequired\" value=\"true\" />\n" + + "<boolean name=\"IsUserInteractionRequired\" value=\"false\" />\n" + + "<boolean name=\"IsUserAllowedToManuallyConnect\" value=\"true\" />\n" + + "<int name=\"SuggestorUid\" value=\"%2$d\" />\n" + + "<string name=\"SuggestorPackageName\">%1$s</string>\n" + + "</NetworkSuggestion>\n" + + "</NetworkSuggestionPerApp>"; + private static final String TEST_POST_R_STORE_FORMAT_XML_STRING = + "<NetworkSuggestionPerApp>\n" + + "<string name=\"SuggestorPackageName\">%1$s</string>\n" + + "<string name=\"SuggestorFeatureId\">com.android.feature.1</string>\n" + + "<boolean name=\"SuggestorHasUserApproved\" value=\"false\" />\n" + + "<int name=\"SuggestorMaxSize\" value=\"100\" />\n" + + "<int name=\"SuggestorUid\" value=\"%2$d\" />\n" + + "<NetworkSuggestion>\n" + + "<WifiConfiguration>\n" + + "<string name=\"ConfigKey\">"WifiConfigurationTestSSID0"" + + "WPA_PSK</string>\n" + + "<string name=\"SSID\">"WifiConfigurationTestSSID0"</string>\n" + + "<null name=\"BSSID\" />\n" + + "<string name=\"PreSharedKey\">"WifiConfigurationTestUtilPsk"" + + "</string>\n" + + "<null name=\"SaePasswordId\" />\n" + + "<null name=\"WEPKeys\" />\n" + + "<int name=\"WEPTxKeyIndex\" value=\"0\" />\n" + + "<boolean name=\"HiddenSSID\" value=\"false\" />\n" + + "<boolean name=\"RequirePMF\" value=\"false\" />\n" + + "<byte-array name=\"AllowedKeyMgmt\" num=\"1\">02</byte-array>\n" + + "<byte-array name=\"AllowedProtocols\" num=\"0\"></byte-array>\n" + + "<byte-array name=\"AllowedAuthAlgos\" num=\"0\"></byte-array>\n" + + "<byte-array name=\"AllowedGroupCiphers\" num=\"0\"></byte-array>\n" + + "<byte-array name=\"AllowedPairwiseCiphers\" num=\"0\"></byte-array>\n" + + "<byte-array name=\"AllowedGroupMgmtCiphers\" num=\"0\"></byte-array>\n" + + "<byte-array name=\"AllowedSuiteBCiphers\" num=\"0\"></byte-array>\n" + + "<boolean name=\"Shared\" value=\"true\" />\n" + + "<int name=\"Status\" value=\"2\" />\n" + + "<null name=\"FQDN\" />\n" + + "<null name=\"ProviderFriendlyName\" />\n" + + "<null name=\"LinkedNetworksList\" />\n" + + "<null name=\"DefaultGwMacAddress\" />\n" + + "<boolean name=\"ValidatedInternetAccess\" value=\"false\" />\n" + + "<boolean name=\"NoInternetAccessExpected\" value=\"false\" />\n" + + "<boolean name=\"MeteredHint\" value=\"false\" />\n" + + "<int name=\"MeteredOverride\" value=\"0\" />\n" + + "<boolean name=\"UseExternalScores\" value=\"false\" />\n" + + "<int name=\"NumAssociation\" value=\"0\" />\n" + + "<int name=\"CreatorUid\" value=\"5\" />\n" + + "<null name=\"CreatorName\" />\n" + + "<null name=\"CreationTime\" />\n" + + "<int name=\"LastUpdateUid\" value=\"-1\" />\n" + + "<null name=\"LastUpdateName\" />\n" + + "<int name=\"LastConnectUid\" value=\"0\" />\n" + + "<boolean name=\"IsLegacyPasspointConfig\" value=\"false\" />\n" + + "<long-array name=\"RoamingConsortiumOIs\" num=\"0\" />\n" + + "<string name=\"RandomizedMacAddress\">02:00:00:00:00:00</string>\n" + + "<int name=\"MacRandomizationSetting\" value=\"1\" />\n" + + "<int name=\"CarrierId\" value=\"-1\" />\n" + + "</WifiConfiguration>\n" + + "<boolean name=\"IsAppInteractionRequired\" value=\"true\" />\n" + + "<boolean name=\"IsUserInteractionRequired\" value=\"false\" />\n" + + "<boolean name=\"IsUserAllowedToManuallyConnect\" value=\"true\" />\n" + + "</NetworkSuggestion>\n" + + "</NetworkSuggestionPerApp>"; private static final String TEST_CORRUPT_DATA_INVALID_SSID = "<NetworkSuggestionPerApp>\n" + "<string name=\"SuggestorPackageName\">com.android.test.1</string>\n" @@ -84,7 +195,6 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { + "<null name=\"DefaultGwMacAddress\" />\n" + "<boolean name=\"ValidatedInternetAccess\" value=\"false\" />\n" + "<boolean name=\"NoInternetAccessExpected\" value=\"false\" />\n" - + "<int name=\"UserApproved\" value=\"0\" />\n" + "<boolean name=\"MeteredHint\" value=\"false\" />\n" + "<int name=\"MeteredOverride\" value=\"0\" />\n" + "<boolean name=\"UseExternalScores\" value=\"false\" />\n" @@ -121,7 +231,7 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { final XmlSerializer out = new FastXmlSerializer(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); out.setOutput(outputStream, StandardCharsets.UTF_8.name()); - mNetworkSuggestionStoreData.serializeData(out, mock(WifiConfigStoreEncryptionUtil.class)); + mNetworkSuggestionStoreData.serializeData(out, null); out.flush(); return outputStream.toByteArray(); } @@ -134,8 +244,7 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { final ByteArrayInputStream inputStream = new ByteArrayInputStream(data); in.setInput(inputStream, StandardCharsets.UTF_8.name()); mNetworkSuggestionStoreData.deserializeData(in, in.getDepth(), - WifiConfigStore.ENCRYPT_CREDENTIALS_CONFIG_STORE_DATA_VERSION, - mock(WifiConfigStoreEncryptionUtil.class)); + WifiConfigStore.ENCRYPT_CREDENTIALS_CONFIG_STORE_DATA_VERSION, null); } /** @@ -154,14 +263,13 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { public void serializeDeserializeSingleNetworkSuggestionFromSingleApp() throws Exception { Map<String, PerAppInfo> networkSuggestionsMap = new HashMap<>(); - PerAppInfo appInfo = new PerAppInfo(TEST_PACKAGE_NAME_1, TEST_FEATURE_ID); + PerAppInfo appInfo = new PerAppInfo(TEST_UID_1, TEST_PACKAGE_NAME_1, TEST_FEATURE_ID); WifiConfiguration configuration = WifiConfigurationTestUtil.createEapNetwork(); configuration.enterpriseConfig = WifiConfigurationTestUtil.createPEAPWifiEnterpriseConfigWithGTCPhase2(); WifiNetworkSuggestion networkSuggestion = - new WifiNetworkSuggestion(configuration, null, false, false, true, TEST_UID_1, - TEST_PACKAGE_NAME_1); + new WifiNetworkSuggestion(configuration, null, false, false, true); appInfo.hasUserApproved = false; appInfo.extNetworkSuggestions.add( ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion, appInfo)); @@ -188,19 +296,17 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { public void serializeDeserializeSingleNetworkSuggestionFromMultipleApps() throws Exception { Map<String, PerAppInfo> networkSuggestionsMap = new HashMap<>(); - PerAppInfo appInfo1 = new PerAppInfo(TEST_PACKAGE_NAME_1, TEST_FEATURE_ID); + PerAppInfo appInfo1 = new PerAppInfo(TEST_UID_1, TEST_PACKAGE_NAME_1, TEST_FEATURE_ID); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_NAME_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); appInfo1.hasUserApproved = false; appInfo1.extNetworkSuggestions.add( ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion1, appInfo1)); networkSuggestionsMap.put(TEST_PACKAGE_NAME_1, appInfo1); - PerAppInfo appInfo2 = new PerAppInfo(TEST_PACKAGE_NAME_2, TEST_FEATURE_ID); + PerAppInfo appInfo2 = new PerAppInfo(TEST_UID_2, TEST_PACKAGE_NAME_2, TEST_FEATURE_ID); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, TEST_UID_2, - TEST_PACKAGE_NAME_2); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); appInfo2.hasUserApproved = true; appInfo2.extNetworkSuggestions.add( ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion2, appInfo2)); @@ -216,13 +322,11 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { public void serializeDeserializeMultipleNetworkSuggestionFromMultipleApps() throws Exception { Map<String, PerAppInfo> networkSuggestionsMap = new HashMap<>(); - PerAppInfo appInfo1 = new PerAppInfo(TEST_PACKAGE_NAME_1, TEST_FEATURE_ID); + PerAppInfo appInfo1 = new PerAppInfo(TEST_UID_1, TEST_PACKAGE_NAME_1, TEST_FEATURE_ID); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, true, true, TEST_UID_1, - TEST_PACKAGE_NAME_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, true, true); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, TEST_UID_1, - TEST_PACKAGE_NAME_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); appInfo1.hasUserApproved = true; appInfo1.extNetworkSuggestions.add( ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion1, appInfo1)); @@ -230,13 +334,11 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion2, appInfo1)); networkSuggestionsMap.put(TEST_PACKAGE_NAME_1, appInfo1); - PerAppInfo appInfo2 = new PerAppInfo(TEST_PACKAGE_NAME_2, TEST_FEATURE_ID); + PerAppInfo appInfo2 = new PerAppInfo(TEST_UID_2, TEST_PACKAGE_NAME_2, TEST_FEATURE_ID); WifiNetworkSuggestion networkSuggestion3 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, TEST_UID_2, - TEST_PACKAGE_NAME_2); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); WifiNetworkSuggestion networkSuggestion4 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, true, true, TEST_UID_2, - TEST_PACKAGE_NAME_2); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, true, true); appInfo2.hasUserApproved = true; appInfo2.extNetworkSuggestions.add( ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion3, appInfo2)); @@ -249,14 +351,42 @@ public class NetworkSuggestionStoreDataTest extends WifiBaseTest { /** * Deserialize corrupt data and ensure that we gracefully handle any errors in the data. - * graceful == throw XmlPullParserException (which is handled in - * {@link WifiConfigManager#loadFromStore()}). */ - @Test(expected = XmlPullParserException.class) + @Test public void deserializeCorruptData() throws Exception { deserializeData(TEST_CORRUPT_DATA_INVALID_SSID.getBytes()); } + /** + * Deserialize a single network suggestion from a single app using a predefined string + * stored in the old/new XML format. + */ + @Test + public void deserializeFromPreRAndPostRFormat() throws Exception { + ArgumentCaptor<HashMap> deserializedNetworkSuggestionsMap = + ArgumentCaptor.forClass(HashMap.class); + + // Old format + String preRFormatXml = String.format( + TEST_PRE_R_STORE_FORMAT_XML_STRING, TEST_PACKAGE_NAME_1, TEST_UID_1); + deserializeData(preRFormatXml.getBytes()); + + // New format + String postRFormatXml = String.format( + TEST_POST_R_STORE_FORMAT_XML_STRING, TEST_PACKAGE_NAME_1, TEST_UID_1); + deserializeData(postRFormatXml.getBytes()); + + // Capture the deserialized data. + verify(mDataSource, times(2)).fromDeserialized(deserializedNetworkSuggestionsMap.capture()); + Map<String, PerAppInfo> deserializedPerAppInfoMapPreRFormat = + deserializedNetworkSuggestionsMap.getAllValues().get(0); + Map<String, PerAppInfo> deserializedPerAppInfoMapPostRFormat = + deserializedNetworkSuggestionsMap.getAllValues().get(1); + + // Ensure both formats produce the same parsed output. + assertEquals(deserializedPerAppInfoMapPreRFormat, deserializedPerAppInfoMapPostRFormat); + } + private Map<String, PerAppInfo> assertSerializeDeserialize( Map<String, PerAppInfo> networkSuggestionsMap) throws Exception { // Setup the data to serialize. diff --git a/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java b/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java index b7c793afc..d89fe1607 100644 --- a/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java @@ -368,10 +368,10 @@ public class WakeupControllerTest extends WifiBaseTest { // suggestions WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork(quotedSsid); WifiNetworkSuggestion openNetworkSuggestion = - new WifiNetworkSuggestion(openNetwork, null, false, false, true, -1, ""); + new WifiNetworkSuggestion(openNetwork, null, false, false, true); WifiConfiguration wepNetwork = WifiConfigurationTestUtil.createWepNetwork(); WifiNetworkSuggestion wepNetworkSuggestion = - new WifiNetworkSuggestion(wepNetwork, null, false, false, true, -1, ""); + new WifiNetworkSuggestion(wepNetwork, null, false, false, true); when(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions()) .thenReturn(new HashSet<>(Arrays.asList( openNetworkSuggestion, wepNetworkSuggestion))); @@ -413,7 +413,7 @@ public class WakeupControllerTest extends WifiBaseTest { WifiConfiguration oweNetwork = WifiConfigurationTestUtil.createOweNetwork(quotedSsid2); WifiNetworkSuggestion oweNetworkSuggestion = - new WifiNetworkSuggestion(oweNetwork, null, false, false, true, -1, ""); + new WifiNetworkSuggestion(oweNetwork, null, false, false, true); when(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions()) .thenReturn(new HashSet<>(Arrays.asList(oweNetworkSuggestion))); @@ -511,7 +511,7 @@ public class WakeupControllerTest extends WifiBaseTest { WifiConfiguration openNetwork = WifiConfigurationTestUtil .createOpenNetwork(ScanResultUtil.createQuotedSSID(SAVED_SSID)); WifiNetworkSuggestion openNetworkSuggestion = - new WifiNetworkSuggestion(openNetwork, null, false, false, true, -1, ""); + new WifiNetworkSuggestion(openNetwork, null, false, false, true); 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 f18d904fc..59f293885 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java @@ -207,11 +207,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { WifiConfiguration dummyConfiguration = new WifiConfiguration(); dummyConfiguration.FQDN = TEST_FQDN; WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - dummyConfiguration, passpointConfiguration, false, false, true, TEST_UID_2, - TEST_PACKAGE_2); + dummyConfiguration, passpointConfiguration, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -261,11 +259,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { WifiConfiguration dummyConfiguration = new WifiConfiguration(); dummyConfiguration.FQDN = TEST_FQDN; WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - dummyConfiguration, passpointConfiguration, false, false, true, TEST_UID_2, - TEST_PACKAGE_2); + dummyConfiguration, passpointConfiguration, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -281,7 +277,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1, TEST_PACKAGE_1, TEST_FEATURE)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, - mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_1, + mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2, TEST_PACKAGE_2, TEST_FEATURE)); // Now remove all of them. @@ -290,7 +286,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { TEST_UID_1, TEST_PACKAGE_1)); assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, mWifiNetworkSuggestionsManager.remove(networkSuggestionList2, - TEST_UID_1, TEST_PACKAGE_2)); + TEST_UID_2, TEST_PACKAGE_2)); verify(mPasspointManager).removeProvider(TEST_UID_2, false, TEST_FQDN); assertTrue(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions().isEmpty()); @@ -315,11 +311,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { WifiConfiguration dummyConfiguration = new WifiConfiguration(); dummyConfiguration.FQDN = TEST_FQDN; WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - dummyConfiguration, passpointConfiguration, false, false, true, TEST_UID_2, - TEST_PACKAGE_2); + dummyConfiguration, passpointConfiguration, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = @@ -358,8 +352,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testReplaceNetworkSuggestionsSuccess() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -391,8 +384,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testAddNetworkSuggestionsSuccessOnInPlaceModification() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -424,8 +416,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<>(); for (int i = 0; i < WifiManager.NETWORK_SUGGESTIONS_MAX_PER_APP_HIGH_RAM; i++) { networkSuggestionList.add(new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, - TEST_UID_1, TEST_PACKAGE_1)); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true)); } // The first add should succeed. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, @@ -437,8 +428,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { networkSuggestionList = new ArrayList<>(); for (int i = 0; i < 3; i++) { networkSuggestionList.add(new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, - TEST_UID_1, TEST_PACKAGE_1)); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true)); } // The second add should fail. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_ADD_EXCEEDS_MAX_PER_APP, @@ -459,8 +449,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { networkSuggestionList = new ArrayList<>(); for (int i = 0; i < 2; i++) { networkSuggestionList.add(new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, - TEST_UID_1, TEST_PACKAGE_1)); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true)); } // This add should now succeed. assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, @@ -474,11 +463,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testRemoveNetworkSuggestionsFailureOnInvalid() { WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -504,8 +491,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testGetNetworkSuggestionsForScanDetailSuccessWithOneMatchForCarrierProvisioningApp() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -520,13 +506,13 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { ScanDetail scanDetail = createScanDetailForNetwork(networkSuggestion.wifiConfiguration); - Set<WifiNetworkSuggestion> matchingNetworkSuggestions = + Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions = mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(scanDetail); Set<WifiNetworkSuggestion> expectedMatchingNetworkSuggestions = new HashSet<WifiNetworkSuggestion>() {{ add(networkSuggestion); }}; - assertEquals(expectedMatchingNetworkSuggestions, matchingNetworkSuggestions); + assertSuggestionsEquals(expectedMatchingNetworkSuggestions, matchingExtNetworkSuggestions); } /** @@ -538,8 +524,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { WifiEnterpriseConfig.Eap.SIM, WifiEnterpriseConfig.Phase2.NONE); config.carrierId = VALID_CARRIER_ID; WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - config, null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + config, null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -557,10 +542,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { .thenReturn(TEST_SUBID); when(mTelephonyUtil.isSimPresent(eq(TEST_SUBID))).thenReturn(false); - Set<WifiNetworkSuggestion> matchingNetworkSuggestions = + Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions = mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(scanDetail); - assertNull(matchingNetworkSuggestions); + assertNull(matchingExtNetworkSuggestions); } /** @@ -569,8 +554,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testGetNetworkSuggestionsForScanDetailSuccessWithOneMatch() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -582,13 +566,13 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { ScanDetail scanDetail = createScanDetailForNetwork(networkSuggestion.wifiConfiguration); - Set<WifiNetworkSuggestion> matchingNetworkSuggestions = + Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions = mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(scanDetail); Set<WifiNetworkSuggestion> expectedMatchingNetworkSuggestions = new HashSet<WifiNetworkSuggestion>() {{ add(networkSuggestion); }}; - assertEquals(expectedMatchingNetworkSuggestions, matchingNetworkSuggestions); + assertSuggestionsEquals(expectedMatchingNetworkSuggestions, matchingExtNetworkSuggestions); } /** @@ -598,12 +582,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testGetNetworkSuggestionsForScanDetailSuccessWithMultipleMatch() { WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.createOpenNetwork(); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration, null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + wifiConfiguration, null, false, false, true); // Reuse the same network credentials to ensure they both match. WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration, null, false, false, true, TEST_UID_2, - TEST_PACKAGE_2); + wifiConfiguration, null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -625,14 +607,14 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { ScanDetail scanDetail = createScanDetailForNetwork(networkSuggestion1.wifiConfiguration); - Set<WifiNetworkSuggestion> matchingNetworkSuggestions = + Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions = mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(scanDetail); Set<WifiNetworkSuggestion> expectedMatchingNetworkSuggestions = new HashSet<WifiNetworkSuggestion>() {{ add(networkSuggestion1); add(networkSuggestion2); }}; - assertEquals(expectedMatchingNetworkSuggestions, matchingNetworkSuggestions); + assertSuggestionsEquals(expectedMatchingNetworkSuggestions, matchingExtNetworkSuggestions); } /** @@ -645,8 +627,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { wifiConfiguration.BSSID = scanDetail.getBSSIDString(); WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - wifiConfiguration, null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + wifiConfiguration, null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -656,13 +637,13 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); - Set<WifiNetworkSuggestion> matchingNetworkSuggestions = + Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions = mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(scanDetail); Set<WifiNetworkSuggestion> expectedMatchingNetworkSuggestions = new HashSet<WifiNetworkSuggestion>() {{ add(networkSuggestion); }}; - assertEquals(expectedMatchingNetworkSuggestions, matchingNetworkSuggestions); + assertSuggestionsEquals(expectedMatchingNetworkSuggestions, matchingExtNetworkSuggestions); } /** @@ -675,12 +656,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { wifiConfiguration.BSSID = scanDetail.getBSSIDString(); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration, null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + wifiConfiguration, null, false, false, true); // Reuse the same network credentials to ensure they both match. WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration, null, false, false, true, TEST_UID_2, - TEST_PACKAGE_2); + wifiConfiguration, null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -700,15 +679,14 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2); - - Set<WifiNetworkSuggestion> matchingNetworkSuggestions = + Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions = mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(scanDetail); Set<WifiNetworkSuggestion> expectedMatchingNetworkSuggestions = new HashSet<WifiNetworkSuggestion>() {{ add(networkSuggestion1); add(networkSuggestion2); }}; - assertEquals(expectedMatchingNetworkSuggestions, matchingNetworkSuggestions); + assertSuggestionsEquals(expectedMatchingNetworkSuggestions, matchingExtNetworkSuggestions); } /** @@ -722,12 +700,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { wifiConfiguration.BSSID = scanDetail.getBSSIDString(); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration, null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + wifiConfiguration, null, false, false, true); // Reuse the same network credentials to ensure they both match. WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration, null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + wifiConfiguration, null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -740,14 +716,14 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { TEST_PACKAGE_1, TEST_FEATURE)); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); - Set<WifiNetworkSuggestion> matchingNetworkSuggestions = + Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions = mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(scanDetail); Set<WifiNetworkSuggestion> expectedMatchingNetworkSuggestions = new HashSet<WifiNetworkSuggestion>() {{ add(networkSuggestion1); add(networkSuggestion2); }}; - assertEquals(expectedMatchingNetworkSuggestions, matchingNetworkSuggestions); + assertSuggestionsEquals(expectedMatchingNetworkSuggestions, matchingExtNetworkSuggestions); } /** @@ -762,12 +738,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { wifiConfiguration2.BSSID = scanDetail.getBSSIDString(); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration1, null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + wifiConfiguration1, null, false, false, true); // Reuse the same network credentials to ensure they both match. WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration2, null, false, false, true, TEST_UID_2, - TEST_PACKAGE_2); + wifiConfiguration2, null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -787,26 +761,25 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2); - - Set<WifiNetworkSuggestion> matchingNetworkSuggestions = + Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions = mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(scanDetail); Set<WifiNetworkSuggestion> expectedMatchingNetworkSuggestions = new HashSet<WifiNetworkSuggestion>() {{ add(networkSuggestion1); add(networkSuggestion2); }}; - assertEquals(expectedMatchingNetworkSuggestions, matchingNetworkSuggestions); + assertSuggestionsEquals(expectedMatchingNetworkSuggestions, matchingExtNetworkSuggestions); // Now change the bssid of the scan result to a different value, now only the general // (without bssid) suggestion. scanDetail.getScanResult().BSSID = MacAddress.createRandomUnicastAddress().toString(); - matchingNetworkSuggestions = + matchingExtNetworkSuggestions = mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(scanDetail); expectedMatchingNetworkSuggestions = new HashSet<WifiNetworkSuggestion>() {{ add(networkSuggestion1); }}; - assertEquals(expectedMatchingNetworkSuggestions, matchingNetworkSuggestions); + assertSuggestionsEquals(expectedMatchingNetworkSuggestions, matchingExtNetworkSuggestions); } /** @@ -816,8 +789,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testGetNetworkSuggestionsForScanDetailFailureOnAppNotApproved() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -839,8 +811,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testGetNetworkSuggestionsForScanDetailFailureOnSuggestionRemoval() { WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.createOpenNetwork(); WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - wifiConfiguration, null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + wifiConfiguration, null, false, false, true); ScanDetail scanDetail = createScanDetailForNetwork(wifiConfiguration); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -868,8 +839,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testGetNetworkSuggestionsForScanDetailFailureOnWrongNetwork() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -900,8 +870,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { .registerSuggestionConnectionStatusListener(mBinder, mListener, NETWORK_CALLBACK_ID, TEST_PACKAGE_1)); WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -942,8 +911,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { NETWORK_CALLBACK_ID, TEST_PACKAGE_1)); verify(mBinder).linkToDeath(drCaptor.capture(), anyInt()); WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -992,8 +960,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { .registerSuggestionConnectionStatusListener(mBinder, mListener, NETWORK_CALLBACK_ID, TEST_PACKAGE_1)); WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -1036,15 +1003,13 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testOnNetworkConnectionSuccessWithMultipleMatch() { WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.createOpenNetwork(); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration, null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + wifiConfiguration, null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion1); }}; WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration, null, true, false, true, TEST_UID_2, - TEST_PACKAGE_2); + wifiConfiguration, null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList2 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion2); @@ -1099,15 +1064,13 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.createOpenNetwork(); wifiConfiguration.BSSID = TEST_BSSID; WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration, null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + wifiConfiguration, null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion1); }}; WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration, null, true, false, true, TEST_UID_2, - TEST_PACKAGE_2); + wifiConfiguration, null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList2 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion2); @@ -1162,15 +1125,13 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { WifiConfiguration wifiConfiguration2 = new WifiConfiguration(wifiConfiguration1); wifiConfiguration2.BSSID = TEST_BSSID; WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration1, null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + wifiConfiguration1, null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion1); }}; WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration2, null, true, false, true, TEST_UID_2, - TEST_PACKAGE_2); + wifiConfiguration2, null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList2 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion2); @@ -1225,8 +1186,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testOnNetworkConnectionWhenAppNotApproved() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -1266,8 +1226,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testOnNetworkConnectionWhenIsAppInteractionRequiredNotSet() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -1307,8 +1266,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testOnNetworkConnectionWhenAppDoesNotHoldLocationPermission() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -1347,8 +1305,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testAddNetworkSuggestionsConfigStoreWrite() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1389,8 +1346,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testRemoveNetworkSuggestionsConfigStoreWrite() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1430,14 +1386,12 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { passpointConfiguration.setHomeSp(homeSp); WifiConfiguration dummyConfiguration = new WifiConfiguration(); dummyConfiguration.FQDN = TEST_FQDN; - PerAppInfo appInfo = new PerAppInfo(TEST_PACKAGE_1, TEST_FEATURE); + PerAppInfo appInfo = new PerAppInfo(TEST_UID_1, TEST_PACKAGE_1, TEST_FEATURE); appInfo.hasUserApproved = true; WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - dummyConfiguration, passpointConfiguration, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + dummyConfiguration, passpointConfiguration, false, false, true); appInfo.extNetworkSuggestions.add( ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion, appInfo)); appInfo.extNetworkSuggestions.add( @@ -1457,18 +1411,18 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // Ensure we can lookup the network. ScanDetail scanDetail = createScanDetailForNetwork(networkSuggestion.wifiConfiguration); - Set<WifiNetworkSuggestion> matchingNetworkSuggestions = + Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions = mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(scanDetail); Set<WifiNetworkSuggestion> expectedMatchingNetworkSuggestions = new HashSet<WifiNetworkSuggestion>() {{ add(networkSuggestion); }}; - assertEquals(expectedMatchingNetworkSuggestions, matchingNetworkSuggestions); + assertSuggestionsEquals(expectedMatchingNetworkSuggestions, matchingExtNetworkSuggestions); // Ensure we can lookup the passpoint network. WifiConfiguration connectNetwork = WifiConfigurationTestUtil.createPasspointNetwork(); connectNetwork.FQDN = TEST_FQDN; - Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions = + matchingExtNetworkSuggestions = mWifiNetworkSuggestionsManager .getNetworkSuggestionsForWifiConfiguration(connectNetwork, null); Set<ExtendedWifiNetworkSuggestion> expectedMatchingExtNetworkSuggestions = @@ -1484,11 +1438,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testNetworkSuggestionsConfigStoreLoadAfterUserSwitch() { // Read the store initially. - PerAppInfo appInfo1 = new PerAppInfo(TEST_PACKAGE_1, TEST_FEATURE); + PerAppInfo appInfo1 = new PerAppInfo(TEST_UID_1, TEST_PACKAGE_1, TEST_FEATURE); appInfo1.hasUserApproved = true; WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); appInfo1.extNetworkSuggestions.add( ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion1, appInfo1)); mDataSource.fromDeserialized(new HashMap<String, PerAppInfo>() {{ @@ -1498,11 +1451,10 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // Now simulate user switch. mDataSource.reset(); - PerAppInfo appInfo2 = new PerAppInfo(TEST_PACKAGE_2, TEST_FEATURE); + PerAppInfo appInfo2 = new PerAppInfo(TEST_UID_2, TEST_PACKAGE_2, TEST_FEATURE); appInfo2.hasUserApproved = true; WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); appInfo2.extNetworkSuggestions.add( ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion2, appInfo2)); mDataSource.fromDeserialized(new HashMap<String, PerAppInfo>() {{ @@ -1519,13 +1471,13 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // Ensure we can lookup the new network. ScanDetail scanDetail2 = createScanDetailForNetwork(networkSuggestion2.wifiConfiguration); - Set<WifiNetworkSuggestion> matchingNetworkSuggestions = + Set<ExtendedWifiNetworkSuggestion> matchingExtNetworkSuggestions = mWifiNetworkSuggestionsManager.getNetworkSuggestionsForScanDetail(scanDetail2); Set<WifiNetworkSuggestion> expectedMatchingNetworkSuggestions = new HashSet<WifiNetworkSuggestion>() {{ add(networkSuggestion2); }}; - assertEquals(expectedMatchingNetworkSuggestions, matchingNetworkSuggestions); + assertSuggestionsEquals(expectedMatchingNetworkSuggestions, matchingExtNetworkSuggestions); // Ensure that the previous network can no longer be looked up. ScanDetail scanDetail1 = createScanDetailForNetwork(networkSuggestion1.wifiConfiguration); @@ -1540,8 +1492,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testRemoveNetworkSuggestionsMatchingConnectionSuccessWithOneMatch() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -1576,8 +1527,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testRemoveAllNetworkSuggestionsMatchingConnectionSuccessWithOneMatch() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -1614,15 +1564,13 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testRemoveAppMatchingConnectionSuccessWithMultipleMatch() { WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.createOpenNetwork(); WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - wifiConfiguration, null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + wifiConfiguration, null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion1); }}; WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - wifiConfiguration, null, true, false, true, TEST_UID_2, - TEST_PACKAGE_2); + wifiConfiguration, null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList2 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion2); @@ -1664,8 +1612,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testRemoveAppNotMatchingConnectionSuccess() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -1692,8 +1639,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testRemoveNetworkSuggestionsNotMatchingConnectionSuccessAfterConnectionFailure() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -1729,11 +1675,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testAddRemoveNetworkSuggestionsStartStopAppOpsWatch() { WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_2, - TEST_PACKAGE_2); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1778,8 +1722,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testAppOpsChangeAfterSuggestionsAdd() { WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion1); @@ -1828,10 +1771,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { */ @Test public void testAppOpsChangeAfterConfigStoreLoad() { - PerAppInfo appInfo = new PerAppInfo(TEST_PACKAGE_1, TEST_FEATURE); + PerAppInfo appInfo = new PerAppInfo(TEST_UID_1, TEST_PACKAGE_1, TEST_FEATURE); WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); appInfo.extNetworkSuggestions.add( ExtendedWifiNetworkSuggestion.fromWns(networkSuggestion, appInfo)); mDataSource.fromDeserialized(new HashMap<String, PerAppInfo>() {{ @@ -1877,8 +1819,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testAppOpsChangeWrongUid() { WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion1); @@ -1920,11 +1861,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testRemoveApp() { WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_2, - TEST_PACKAGE_2); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -1986,11 +1925,9 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testClear() { WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_2, - TEST_PACKAGE_2); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ @@ -2043,8 +1980,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testUserApprovalNotificationDismissalWhenGetScanResult() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -2084,8 +2020,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testUserApprovalNotificationClickOnAllowWhenGetScanResult() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -2130,8 +2065,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testUserApprovalNotificationClickOnDisallowWhenGetScanResult() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -2199,8 +2133,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testUserApprovalNotificationWhilePreviousNotificationActive() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -2238,17 +2171,13 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { // App add network suggestions then get stored suggestions. WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, false, false, true); WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOweNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOweNetwork(), null, false, false, true); WifiNetworkSuggestion networkSuggestion3 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createSaeNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createSaeNetwork(), null, false, false, true); WifiNetworkSuggestion networkSuggestion4 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createPskNetwork(), null, false, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createPskNetwork(), null, false, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<>(); networkSuggestionList.add(networkSuggestion1); networkSuggestionList.add(networkSuggestion2); @@ -2279,14 +2208,11 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testGetHiddenNetworks() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); WifiNetworkSuggestion hiddenNetworkSuggestion1 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createPskHiddenNetwork(), null, true, false, true, - TEST_UID_1, TEST_PACKAGE_1); + WifiConfigurationTestUtil.createPskHiddenNetwork(), null, true, false, true); WifiNetworkSuggestion hiddenNetworkSuggestion2 = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createPskHiddenNetwork(), null, true, false, true, - TEST_UID_2, TEST_PACKAGE_2); + WifiConfigurationTestUtil.createPskHiddenNetwork(), null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList1 = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -2317,8 +2243,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testUserApprovalNotificationClickOnAllowDuringAddingSuggestions() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, - TEST_UID_1, TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -2352,8 +2277,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { @Test public void testUserApprovalNotificationClickOnDisallowWhenAddSuggestions() { WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + WifiConfigurationTestUtil.createOpenNetwork(), null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -2416,8 +2340,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { WifiConfiguration dummyConfiguration = new WifiConfiguration(); dummyConfiguration.FQDN = TEST_FQDN; WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - dummyConfiguration, passpointConfiguration, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + dummyConfiguration, passpointConfiguration, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<WifiNetworkSuggestion>() {{ add(networkSuggestion); @@ -2515,8 +2438,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork(); config.carrierId = VALID_CARRIER_ID; WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - config, null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + config, null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<>(); networkSuggestionList.add(networkSuggestion); when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(TEST_UID_1)) @@ -2534,8 +2456,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork(); config.carrierId = VALID_CARRIER_ID; WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - config, null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + config, null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<>(); networkSuggestionList.add(networkSuggestion); when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(TEST_UID_1)) @@ -2552,8 +2473,7 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { public void testAddSuggestionWithDefaultCarrierIdWithoutCarrierProvisionPermission() { WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork(); WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( - config, null, true, false, true, TEST_UID_1, - TEST_PACKAGE_1); + config, null, true, false, true); List<WifiNetworkSuggestion> networkSuggestionList = new ArrayList<>(); networkSuggestionList.add(networkSuggestion); when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(TEST_UID_1)) @@ -2564,4 +2484,12 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { assertEquals(status, WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS); } + + private void assertSuggestionsEquals(Set<WifiNetworkSuggestion> expectedSuggestions, + Set<ExtendedWifiNetworkSuggestion> actualExtSuggestions) { + Set<WifiNetworkSuggestion> actualSuggestions = actualExtSuggestions.stream() + .map(ewns -> ewns.wns) + .collect(Collectors.toSet()); + assertEquals(expectedSuggestions, actualSuggestions); + } } |