summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-12-05 12:07:05 -0800
committerRoshan Pius <rpius@google.com>2019-12-06 08:07:05 -0800
commitef68460486aa6f77d4a737686098a820ec68549b (patch)
tree7ab00456b15d0b4a3d99cd90da2282e81d896814 /service
parent31b57a859783e6e604830ac189d27ebd69cda9c6 (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
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java48
-rw-r--r--service/java/com/android/server/wifi/NetworkSuggestionStoreData.java139
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java94
3 files changed, 166 insertions, 115 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;