summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorAmin Shaikh <ashaikh@google.com>2016-12-20 14:02:02 -0800
committerAmin Shaikh <ashaikh@google.com>2016-12-23 14:58:28 -0800
commit3872e4cd3900c7b179371028dbe0e94d9b0a7380 (patch)
treeb61458aaa6d6f2d41c7a0e1470d30d8e8396a24c /service
parent64acb4210ced1920fc29caa98a353b2968fd33b5 (diff)
Populate fields in RecommendedNetworkEvaluator.
- Find corresponding ScanResult for recommended WifiConfiguration - Set WifiConfiguration#{allowedKeyManagment,ephemeral} bits - Add new WifiConfiguration for ephemeral networks Test: runtest frameworks-wifi Bug: 33702806 Change-Id: I4aaeabe626c68b13bb7aa75b89adc4cb2663508c
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/RecommendedNetworkEvaluator.java60
-rw-r--r--service/java/com/android/server/wifi/WifiSupplicantControl.java12
-rw-r--r--service/java/com/android/server/wifi/util/ScanResultUtil.java12
3 files changed, 65 insertions, 19 deletions
diff --git a/service/java/com/android/server/wifi/RecommendedNetworkEvaluator.java b/service/java/com/android/server/wifi/RecommendedNetworkEvaluator.java
index 95f17b364..2d481ec45 100644
--- a/service/java/com/android/server/wifi/RecommendedNetworkEvaluator.java
+++ b/service/java/com/android/server/wifi/RecommendedNetworkEvaluator.java
@@ -23,9 +23,12 @@ import android.net.RecommendationResult;
import android.net.WifiKey;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiInfo;
import android.net.wifi.WifiNetworkScoreCache;
+import android.os.Process;
import android.util.LocalLog;
import android.util.Pair;
+import android.util.Slog;
import com.android.server.wifi.util.ScanResultUtil;
@@ -37,6 +40,7 @@ import java.util.List;
* {@link NetworkScoreManager#requestRecommendation(RecommendationRequest)}.
*/
public class RecommendedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluator {
+ private static final String TAG = "RecNetEvaluator";
private final NetworkScoreManager mNetworkScoreManager;
private final WifiNetworkScoreCache mNetworkScoreCache;
private final WifiConfigManager mWifiConfigManager;
@@ -107,22 +111,64 @@ public class RecommendedNetworkEvaluator implements WifiNetworkSelector.NetworkE
return null;
}
+ ScanResult[] scanResultArray = scanResults.toArray(new ScanResult[scanResults.size()]);
RecommendationRequest request = new RecommendationRequest.Builder()
- .setScanResults(scanResults.toArray(new ScanResult[scanResults.size()]))
+ .setScanResults(scanResultArray)
// TODO: pass in currently recommended network
.build();
RecommendationResult result = mNetworkScoreManager.requestRecommendation(request);
- if (result != null && result.getWifiConfiguration() != null) {
- WifiConfiguration wifiConfiguration = result.getWifiConfiguration();
- // TODO(b/33490132): Get recommended ScanResult and optionally create a
- // WifiConfiguration for untrusted networks. Also call setNetworkCandidateScanResult.
- return wifiConfiguration;
+ if (result == null || result.getWifiConfiguration() == null) {
+ return null;
+ }
+
+ WifiConfiguration wifiConfiguration = result.getWifiConfiguration();
+ ScanResult scanResult = findMatchingScanResult(scanResultArray, wifiConfiguration);
+ if (scanResult == null) {
+ Slog.e(TAG, "Could not match WifiConfiguration to a ScanResult.");
+ return null;
+ }
+
+ int networkId = wifiConfiguration.networkId;
+ if (networkId == WifiConfiguration.INVALID_NETWORK_ID) {
+ networkId = addEphemeralNetwork(wifiConfiguration, scanResult);
+ if (networkId == WifiConfiguration.INVALID_NETWORK_ID) {
+ return null;
+ }
+ }
+ mWifiConfigManager.setNetworkCandidateScanResult(networkId, scanResult, 0 /* score */);
+ return mWifiConfigManager.getConfiguredNetwork(networkId);
+ }
+
+ private ScanResult findMatchingScanResult(ScanResult[] scanResults,
+ WifiConfiguration wifiConfiguration) {
+ String ssid = WifiInfo.removeDoubleQuotes(wifiConfiguration.SSID);
+ String bssid = wifiConfiguration.BSSID;
+ for (int i = 0; i < scanResults.length; i++) {
+ if (ssid.equals(scanResults[i].SSID) && bssid.equals(scanResults[i].BSSID)) {
+ return scanResults[i];
+ }
}
return null;
}
+ private int addEphemeralNetwork(WifiConfiguration wifiConfiguration, ScanResult scanResult) {
+ if (wifiConfiguration.allowedKeyManagement.isEmpty()) {
+ ScanResultUtil.setAllowedKeyManagementFromScanResult(scanResult,
+ wifiConfiguration);
+ }
+ wifiConfiguration.ephemeral = true;
+ NetworkUpdateResult networkUpdateResult = mWifiConfigManager
+ .addOrUpdateNetwork(wifiConfiguration, Process.WIFI_UID);
+ if (networkUpdateResult.isSuccess()) {
+ return networkUpdateResult.getNetworkId();
+ }
+ mLocalLog.log("Failed to add ephemeral network for networkId: "
+ + WifiNetworkSelector.toScanId(scanResult));
+ return WifiConfiguration.INVALID_NETWORK_ID;
+ }
+
@Override
public String getName() {
- return "RecommendedNetworkEvaluator";
+ return TAG;
}
}
diff --git a/service/java/com/android/server/wifi/WifiSupplicantControl.java b/service/java/com/android/server/wifi/WifiSupplicantControl.java
index 138126999..1acc4ae5e 100644
--- a/service/java/com/android/server/wifi/WifiSupplicantControl.java
+++ b/service/java/com/android/server/wifi/WifiSupplicantControl.java
@@ -20,6 +20,7 @@ import android.net.IpConfiguration.IpAssignment;
import android.net.IpConfiguration.ProxySettings;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
+import android.net.wifi.WifiInfo;
import android.net.wifi.WifiSsid;
import android.net.wifi.WpsInfo;
import android.net.wifi.WpsResult;
@@ -91,15 +92,6 @@ public class WifiSupplicantControl {
mFileObserver.startWatching();
}
- private static String removeDoubleQuotes(String string) {
- int length = string.length();
- if ((length > 1) && (string.charAt(0) == '"')
- && (string.charAt(length - 1) == '"')) {
- return string.substring(1, length - 1);
- }
- return string;
- }
-
/**
* Generate a string to be used as a key value by wpa_supplicant from
* 'set', within the set of strings from 'strings' for the variable concatenated.
@@ -963,7 +955,7 @@ public class WifiSupplicantControl {
String value = mWifiNative.getNetworkVariable(mNetId, key);
if (!TextUtils.isEmpty(value)) {
if (!enterpriseConfigKeyShouldBeQuoted(key)) {
- value = removeDoubleQuotes(value);
+ value = WifiInfo.removeDoubleQuotes(value);
}
return value;
} else {
diff --git a/service/java/com/android/server/wifi/util/ScanResultUtil.java b/service/java/com/android/server/wifi/util/ScanResultUtil.java
index 9ba54bb32..0e08701a7 100644
--- a/service/java/com/android/server/wifi/util/ScanResultUtil.java
+++ b/service/java/com/android/server/wifi/util/ScanResultUtil.java
@@ -124,6 +124,16 @@ public class ScanResultUtil {
public static WifiConfiguration createNetworkFromScanResult(ScanResult scanResult) {
WifiConfiguration config = new WifiConfiguration();
config.SSID = createQuotedSSID(scanResult.SSID);
+ setAllowedKeyManagementFromScanResult(scanResult, config);
+ return config;
+ }
+
+ /**
+ * Sets the {@link WifiConfiguration#allowedKeyManagement} field on the given
+ * {@link WifiConfiguration} based on its corresponding {@link ScanResult}.
+ */
+ public static void setAllowedKeyManagementFromScanResult(ScanResult scanResult,
+ WifiConfiguration config) {
if (isScanResultForPskNetwork(scanResult)) {
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
} else if (isScanResultForEapNetwork(scanResult)) {
@@ -136,7 +146,5 @@ public class ScanResultUtil {
} else {
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
}
- return config;
}
-
}