summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2017-06-05 22:30:55 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-06-05 22:30:57 +0000
commit5096b161da96dd77ca8f0b5d4f80d08c6c4aff36 (patch)
treec239c4342611c19a4eef9e4c1fa97b745c90f5f8 /service
parent8a59eab5e32e37da1962119b5c3afe216f63021d (diff)
parentd4c567a0b6e6270c19c29a1296a6bfe4c6790ccf (diff)
Merge changes Ib119e6f9,I73e312fd
* changes: ConfigurationMap: Remove unused elements and methods WifiConfigManager: Optimize scan result to config lookup
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/ConfigurationMap.java138
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManager.java39
-rw-r--r--service/java/com/android/server/wifi/util/ScanResultUtil.java31
3 files changed, 129 insertions, 79 deletions
diff --git a/service/java/com/android/server/wifi/ConfigurationMap.java b/service/java/com/android/server/wifi/ConfigurationMap.java
index fc85f6419..d377f0f34 100644
--- a/service/java/com/android/server/wifi/ConfigurationMap.java
+++ b/service/java/com/android/server/wifi/ConfigurationMap.java
@@ -1,24 +1,24 @@
package com.android.server.wifi;
-import android.content.pm.UserInfo;
+import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.os.UserHandle;
import android.os.UserManager;
-import java.util.ArrayList;
+import com.android.server.wifi.util.ScanResultUtil;
+
import java.util.Collection;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
-import java.util.Set;
+import java.util.Objects;
public class ConfigurationMap {
private final Map<Integer, WifiConfiguration> mPerID = new HashMap<>();
private final Map<Integer, WifiConfiguration> mPerIDForCurrentUser = new HashMap<>();
- private final Map<String, WifiConfiguration> mPerFQDNForCurrentUser = new HashMap<>();
+ private final Map<ScanResultMatchInfo, WifiConfiguration>
+ mScanResultMatchInfoMapForCurrentUser = new HashMap<>();
private final UserManager mUserManager;
@@ -34,9 +34,8 @@ public class ConfigurationMap {
if (WifiConfigurationUtil.isVisibleToAnyProfile(config,
mUserManager.getProfiles(mCurrentUserId))) {
mPerIDForCurrentUser.put(config.networkId, config);
- if (config.FQDN != null && config.FQDN.length() > 0) {
- mPerFQDNForCurrentUser.put(config.FQDN, config);
- }
+ mScanResultMatchInfoMapForCurrentUser.put(
+ ScanResultMatchInfo.fromWifiConfiguration(config), config);
}
return current;
}
@@ -48,11 +47,12 @@ public class ConfigurationMap {
}
mPerIDForCurrentUser.remove(netID);
- Iterator<Map.Entry<String, WifiConfiguration>> entries =
- mPerFQDNForCurrentUser.entrySet().iterator();
- while (entries.hasNext()) {
- if (entries.next().getValue().networkId == netID) {
- entries.remove();
+
+ Iterator<Map.Entry<ScanResultMatchInfo, WifiConfiguration>> scanResultMatchInfoEntries =
+ mScanResultMatchInfoMapForCurrentUser.entrySet().iterator();
+ while (scanResultMatchInfoEntries.hasNext()) {
+ if (scanResultMatchInfoEntries.next().getValue().networkId == netID) {
+ scanResultMatchInfoEntries.remove();
break;
}
}
@@ -62,7 +62,7 @@ public class ConfigurationMap {
public void clear() {
mPerID.clear();
mPerIDForCurrentUser.clear();
- mPerFQDNForCurrentUser.clear();
+ mScanResultMatchInfoMapForCurrentUser.clear();
}
/**
@@ -91,10 +91,6 @@ public class ConfigurationMap {
return mPerIDForCurrentUser.size();
}
- public WifiConfiguration getByFQDNForCurrentUser(String fqdn) {
- return mPerFQDNForCurrentUser.get(fqdn);
- }
-
public WifiConfiguration getByConfigKeyForCurrentUser(String key) {
if (key == null) {
return null;
@@ -107,23 +103,14 @@ public class ConfigurationMap {
return null;
}
- public Collection<WifiConfiguration> getEnabledNetworksForCurrentUser() {
- List<WifiConfiguration> list = new ArrayList<>();
- for (WifiConfiguration config : mPerIDForCurrentUser.values()) {
- if (config.status != WifiConfiguration.Status.DISABLED) {
- list.add(config);
- }
- }
- return list;
- }
-
- public WifiConfiguration getEphemeralForCurrentUser(String ssid) {
- for (WifiConfiguration config : mPerIDForCurrentUser.values()) {
- if (ssid.equals(config.SSID) && config.ephemeral) {
- return config;
- }
- }
- return null;
+ /**
+ * Retrieves the |WifiConfiguration| object matching the provided |scanResult| from the internal
+ * map.
+ * Essentially checks if network config and scan result have the same SSID and encryption type.
+ */
+ public WifiConfiguration getByScanResultForCurrentUser(ScanResult scanResult) {
+ return mScanResultMatchInfoMapForCurrentUser.get(
+ ScanResultMatchInfo.fromScanResult(scanResult));
}
public Collection<WifiConfiguration> valuesForAllUsers() {
@@ -133,4 +120,83 @@ public class ConfigurationMap {
public Collection<WifiConfiguration> valuesForCurrentUser() {
return mPerIDForCurrentUser.values();
}
+
+ /**
+ * Class to store the info needed to match a scan result to the provided network configuration.
+ */
+ private static class ScanResultMatchInfo {
+ private static final int NETWORK_TYPE_OPEN = 0;
+ private static final int NETWORK_TYPE_WEP = 1;
+ private static final int NETWORK_TYPE_PSK = 2;
+ private static final int NETWORK_TYPE_EAP = 3;
+
+ /**
+ * SSID of the network.
+ */
+ public String networkSsid;
+ /**
+ * Security Type of the network.
+ */
+ public int networkType;
+
+ public static ScanResultMatchInfo fromWifiConfiguration(WifiConfiguration config) {
+ ScanResultMatchInfo info = new ScanResultMatchInfo();
+ info.networkSsid = config.SSID;
+ if (WifiConfigurationUtil.isConfigForPskNetwork(config)) {
+ info.networkType = NETWORK_TYPE_PSK;
+ } else if (WifiConfigurationUtil.isConfigForEapNetwork(config)) {
+ info.networkType = NETWORK_TYPE_EAP;
+ } else if (WifiConfigurationUtil.isConfigForWepNetwork(config)) {
+ info.networkType = NETWORK_TYPE_WEP;
+ } else if (WifiConfigurationUtil.isConfigForOpenNetwork(config)) {
+ info.networkType = NETWORK_TYPE_OPEN;
+ } else {
+ throw new IllegalArgumentException("Invalid WifiConfiguration: " + config);
+ }
+ return info;
+ }
+
+ public static ScanResultMatchInfo fromScanResult(ScanResult scanResult) {
+ ScanResultMatchInfo info = new ScanResultMatchInfo();
+ // Scan result ssid's are not quoted, hence add quotes.
+ // TODO: This matching algo works only if the scan result contains a string SSID.
+ // However, according to our public documentation ths {@link WifiConfiguration#SSID} can
+ // either have a hex string or quoted ASCII string SSID.
+ info.networkSsid = ScanResultUtil.createQuotedSSID(scanResult.SSID);
+ if (ScanResultUtil.isScanResultForPskNetwork(scanResult)) {
+ info.networkType = NETWORK_TYPE_PSK;
+ } else if (ScanResultUtil.isScanResultForEapNetwork(scanResult)) {
+ info.networkType = NETWORK_TYPE_EAP;
+ } else if (ScanResultUtil.isScanResultForWepNetwork(scanResult)) {
+ info.networkType = NETWORK_TYPE_WEP;
+ } else if (ScanResultUtil.isScanResultForOpenNetwork(scanResult)) {
+ info.networkType = NETWORK_TYPE_OPEN;
+ } else {
+ throw new IllegalArgumentException("Invalid ScanResult: " + scanResult);
+ }
+ return info;
+ }
+
+ @Override
+ public boolean equals(Object otherObj) {
+ if (this == otherObj) {
+ return true;
+ } else if (!(otherObj instanceof ScanResultMatchInfo)) {
+ return false;
+ }
+ ScanResultMatchInfo other = (ScanResultMatchInfo) otherObj;
+ return Objects.equals(networkSsid, other.networkSsid)
+ && networkType == other.networkType;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(networkSsid, networkType);
+ }
+
+ @Override
+ public String toString() {
+ return "ScanResultMatchInfo: " + networkSsid + ", type: " + networkType;
+ }
+ }
}
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
index d06bf76f6..94aa14b9c 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -49,7 +49,6 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.server.LocalServices;
import com.android.server.wifi.WifiConfigStoreLegacy.WifiConfigStoreDataLegacy;
import com.android.server.wifi.hotspot2.PasspointManager;
-import com.android.server.wifi.util.ScanResultUtil;
import com.android.server.wifi.util.TelephonyUtil;
import com.android.server.wifi.util.WifiPermissionsUtil;
import com.android.server.wifi.util.WifiPermissionsWrapper;
@@ -1002,7 +1001,12 @@ public class WifiConfigManager {
// Add it to our internal map. This will replace any existing network configuration for
// updates.
- mConfiguredNetworks.put(newInternalConfig);
+ try {
+ mConfiguredNetworks.put(newInternalConfig);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Failed to add network to config map", e);
+ return new NetworkUpdateResult(WifiConfiguration.INVALID_NETWORK_ID);
+ }
if (mDeletedEphemeralSSIDs.remove(config.SSID)) {
if (mVerboseLoggingEnabled) {
@@ -1901,16 +1905,19 @@ public class WifiConfigManager {
Log.e(TAG, "No scan result found in scan detail");
return null;
}
- for (WifiConfiguration config : getInternalConfiguredNetworks()) {
- if (ScanResultUtil.doesScanResultMatchWithNetwork(scanResult, config)) {
- if (mVerboseLoggingEnabled) {
- Log.v(TAG, "getSavedNetworkFromScanDetail Found " + config.configKey()
- + " for " + scanResult.SSID + "[" + scanResult.capabilities + "]");
- }
- return config;
+ WifiConfiguration config = null;
+ try {
+ config = mConfiguredNetworks.getByScanResultForCurrentUser(scanResult);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Failed to lookup network from config map", e);
+ }
+ if (config != null) {
+ if (mVerboseLoggingEnabled) {
+ Log.v(TAG, "getSavedNetworkFromScanDetail Found " + config.configKey()
+ + " for " + scanResult.SSID + "[" + scanResult.capabilities + "]");
}
}
- return null;
+ return config;
}
/**
@@ -2571,7 +2578,11 @@ public class WifiConfigManager {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "Adding network from shared store " + configuration.configKey());
}
- mConfiguredNetworks.put(configuration);
+ try {
+ mConfiguredNetworks.put(configuration);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Failed to add network to config map", e);
+ }
}
}
@@ -2590,7 +2601,11 @@ public class WifiConfigManager {
if (mVerboseLoggingEnabled) {
Log.v(TAG, "Adding network from user store " + configuration.configKey());
}
- mConfiguredNetworks.put(configuration);
+ try {
+ mConfiguredNetworks.put(configuration);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Failed to add network to config map", e);
+ }
}
for (String ssid : deletedEphemeralSSIDs) {
mDeletedEphemeralSSIDs.add(ssid);
diff --git a/service/java/com/android/server/wifi/util/ScanResultUtil.java b/service/java/com/android/server/wifi/util/ScanResultUtil.java
index 0e08701a7..4fcafb8bc 100644
--- a/service/java/com/android/server/wifi/util/ScanResultUtil.java
+++ b/service/java/com/android/server/wifi/util/ScanResultUtil.java
@@ -18,11 +18,9 @@ package com.android.server.wifi.util;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
-import android.text.TextUtils;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.wifi.ScanDetail;
-import com.android.server.wifi.WifiConfigurationUtil;
import com.android.server.wifi.hotspot2.NetworkDetail;
/**
@@ -89,35 +87,6 @@ public class ScanResultUtil {
}
/**
- * Checks if the provided |scanResult| match with the provided |config|. Essentially checks
- * if the network config and scan result have the same SSID and encryption type.
- */
- public static boolean doesScanResultMatchWithNetwork(
- ScanResult scanResult, WifiConfiguration config) {
- // Add the double quotes to the scan result SSID for comparison with the network configs.
- String configSSID = createQuotedSSID(scanResult.SSID);
- if (TextUtils.equals(config.SSID, configSSID)) {
- if (ScanResultUtil.isScanResultForPskNetwork(scanResult)
- && WifiConfigurationUtil.isConfigForPskNetwork(config)) {
- return true;
- }
- if (ScanResultUtil.isScanResultForEapNetwork(scanResult)
- && WifiConfigurationUtil.isConfigForEapNetwork(config)) {
- return true;
- }
- if (ScanResultUtil.isScanResultForWepNetwork(scanResult)
- && WifiConfigurationUtil.isConfigForWepNetwork(config)) {
- return true;
- }
- if (ScanResultUtil.isScanResultForOpenNetwork(scanResult)
- && WifiConfigurationUtil.isConfigForOpenNetwork(config)) {
- return true;
- }
- }
- return false;
- }
-
- /**
* Creates a network configuration object using the provided |scanResult|.
* This is used to create ephemeral network configurations.
*/