summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2018-10-09 15:34:35 -0700
committerRoshan Pius <rpius@google.com>2018-11-01 10:48:57 -0700
commitd621b88f1b65d31e542d8de602706b4261e993b2 (patch)
tree4b7e10c79358accccc681307ba8c2e502b324997 /service
parentaed69f8dabc5a719c9dbc5c5f52774e573315b4a (diff)
ScanResultMatchInfo: Refactor network type retrieval
Expose static methods to retrieve the network type from ScanResult & WifiConfiguration. Will be used in the network matching logic in WifiNetworkFactory. Bug: 113878056 Test: Existing unit tests. Change-Id: If79812d423020868a7e12cece67be18cec39ac30
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/ScanResultMatchInfo.java69
1 files changed, 47 insertions, 22 deletions
diff --git a/service/java/com/android/server/wifi/ScanResultMatchInfo.java b/service/java/com/android/server/wifi/ScanResultMatchInfo.java
index ad29c2312..72fab6bc0 100644
--- a/service/java/com/android/server/wifi/ScanResultMatchInfo.java
+++ b/service/java/com/android/server/wifi/ScanResultMatchInfo.java
@@ -15,11 +15,15 @@
*/
package com.android.server.wifi;
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
+import android.annotation.IntDef;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import com.android.server.wifi.util.ScanResultUtil;
+import java.lang.annotation.Retention;
import java.util.Objects;
/**
@@ -31,6 +35,15 @@ public class ScanResultMatchInfo {
public static final int NETWORK_TYPE_PSK = 2;
public static final int NETWORK_TYPE_EAP = 3;
+ @Retention(SOURCE)
+ @IntDef(prefix = { "NETWORK_TYPE_" }, value = {
+ NETWORK_TYPE_OPEN,
+ NETWORK_TYPE_WEP,
+ NETWORK_TYPE_PSK,
+ NETWORK_TYPE_EAP
+ })
+ public @interface NetworkType {}
+
/**
* SSID of the network.
*/
@@ -38,29 +51,51 @@ public class ScanResultMatchInfo {
/**
* Security Type of the network.
*/
- public int networkType;
+ public @NetworkType int networkType;
/**
- * Get the ScanResultMatchInfo for the given WifiConfiguration
+ * Fetch network type from network configuration.
*/
- public static ScanResultMatchInfo fromWifiConfiguration(WifiConfiguration config) {
- ScanResultMatchInfo info = new ScanResultMatchInfo();
- info.networkSsid = config.SSID;
+ public static @NetworkType int getNetworkType(WifiConfiguration config) {
if (WifiConfigurationUtil.isConfigForPskNetwork(config)) {
- info.networkType = NETWORK_TYPE_PSK;
+ return NETWORK_TYPE_PSK;
} else if (WifiConfigurationUtil.isConfigForEapNetwork(config)) {
- info.networkType = NETWORK_TYPE_EAP;
+ return NETWORK_TYPE_EAP;
} else if (WifiConfigurationUtil.isConfigForWepNetwork(config)) {
- info.networkType = NETWORK_TYPE_WEP;
+ return NETWORK_TYPE_WEP;
} else if (WifiConfigurationUtil.isConfigForOpenNetwork(config)) {
- info.networkType = NETWORK_TYPE_OPEN;
- } else {
- throw new IllegalArgumentException("Invalid WifiConfiguration: " + config);
+ return NETWORK_TYPE_OPEN;
}
+ throw new IllegalArgumentException("Invalid WifiConfiguration: " + config);
+ }
+
+ /**
+ * Get the ScanResultMatchInfo for the given WifiConfiguration
+ */
+ public static ScanResultMatchInfo fromWifiConfiguration(WifiConfiguration config) {
+ ScanResultMatchInfo info = new ScanResultMatchInfo();
+ info.networkSsid = config.SSID;
+ info.networkType = getNetworkType(config);
return info;
}
/**
+ * Fetch network type from scan result.
+ */
+ public static @NetworkType int getNetworkType(ScanResult scanResult) {
+ if (ScanResultUtil.isScanResultForPskNetwork(scanResult)) {
+ return NETWORK_TYPE_PSK;
+ } else if (ScanResultUtil.isScanResultForEapNetwork(scanResult)) {
+ return NETWORK_TYPE_EAP;
+ } else if (ScanResultUtil.isScanResultForWepNetwork(scanResult)) {
+ return NETWORK_TYPE_WEP;
+ } else if (ScanResultUtil.isScanResultForOpenNetwork(scanResult)) {
+ return NETWORK_TYPE_OPEN;
+ }
+ throw new IllegalArgumentException("Invalid ScanResult: " + scanResult);
+ }
+
+ /**
* Get the ScanResultMatchInfo for the given ScanResult
*/
public static ScanResultMatchInfo fromScanResult(ScanResult scanResult) {
@@ -70,17 +105,7 @@ public class ScanResultMatchInfo {
// 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);
- }
+ info.networkType = getNetworkType(scanResult);
return info;
}