use of android.net.wifi.WifiConfiguration in project android_frameworks_base by AOSPA.
the class WifiConfigurationHelper method createGenericConfig.
/**
* Create a generic {@link WifiConfiguration} used by the other create methods.
*/
private static WifiConfiguration createGenericConfig(String ssid) {
WifiConfiguration config = new WifiConfiguration();
config.SSID = quotedString(ssid);
config.setIpAssignment(IpAssignment.DHCP);
config.setProxySettings(ProxySettings.NONE);
return config;
}
use of android.net.wifi.WifiConfiguration in project android_frameworks_base by AOSPA.
the class WifiConfigurationHelper method parseJson.
/**
* Parse a JSON string for WiFi configurations stored as a JSON string.
* <p>
* This json string should be a list of dictionaries, with each dictionary containing a single
* wifi configuration. The wifi configuration requires the fields "ssid" and "security" with
* security being one of NONE, WEP, PSK, or EAP. If WEP, PSK, or EAP are selected, the field
* "password" must also be provided. If EAP is selected, then the fiels "eap", "phase2",
* "identity", "ananymous_identity", "ca_cert", and "client_cert" are also required. Lastly,
* static IP settings are also supported. If the field "ip" is set, then the fields "gateway",
* "prefix_length", "dns1", and "dns2" are required.
* </p>
* @throws IllegalArgumentException if the input string was not valid JSON or if any mandatory
* fields are missing.
*/
public static List<WifiConfiguration> parseJson(String in) {
try {
JSONArray jsonConfigs = new JSONArray(in);
List<WifiConfiguration> wifiConfigs = new ArrayList<>(jsonConfigs.length());
for (int i = 0; i < jsonConfigs.length(); i++) {
JSONObject jsonConfig = jsonConfigs.getJSONObject(i);
wifiConfigs.add(getWifiConfiguration(jsonConfig));
}
return wifiConfigs;
} catch (JSONException e) {
throw new IllegalArgumentException(e);
}
}
use of android.net.wifi.WifiConfiguration in project android_frameworks_base by AOSPA.
the class WifiConfigurationHelper method getWifiConfiguration.
/**
* Parse a {@link JSONObject} and return the wifi configuration.
*
* @throws IllegalArgumentException if any mandatory fields are missing.
*/
private static WifiConfiguration getWifiConfiguration(JSONObject jsonConfig) throws JSONException {
String ssid = jsonConfig.getString("ssid");
String password = null;
WifiConfiguration config;
int securityType = getSecurityType(jsonConfig.getString("security"));
switch(securityType) {
case NONE:
config = createOpenConfig(ssid);
break;
case WEP:
password = jsonConfig.getString("password");
config = createWepConfig(ssid, password);
break;
case PSK:
password = jsonConfig.getString("password");
config = createPskConfig(ssid, password);
break;
case EAP:
password = jsonConfig.getString("password");
int eapMethod = getEapMethod(jsonConfig.getString("eap"));
Integer phase2 = null;
if (jsonConfig.has("phase2")) {
phase2 = getPhase2(jsonConfig.getString("phase2"));
}
String identity = null;
if (jsonConfig.has("identity")) {
identity = jsonConfig.getString("identity");
}
String anonymousIdentity = null;
if (jsonConfig.has("anonymous_identity")) {
anonymousIdentity = jsonConfig.getString("anonymous_identity");
}
String caCert = null;
if (jsonConfig.has("ca_cert")) {
caCert = (jsonConfig.getString("ca_cert"));
}
String clientCert = null;
if (jsonConfig.has("client_cert")) {
clientCert = jsonConfig.getString("client_cert");
}
config = createEapConfig(ssid, password, eapMethod, phase2, identity, anonymousIdentity, caCert, clientCert);
break;
default:
// Should never reach here as getSecurityType will already throw an exception
throw new IllegalArgumentException();
}
if (jsonConfig.has("ip")) {
StaticIpConfiguration staticIpConfig = new StaticIpConfiguration();
InetAddress ipAddress = getInetAddress(jsonConfig.getString("ip"));
int prefixLength = getPrefixLength(jsonConfig.getInt("prefix_length"));
staticIpConfig.ipAddress = new LinkAddress(ipAddress, prefixLength);
staticIpConfig.gateway = getInetAddress(jsonConfig.getString("gateway"));
staticIpConfig.dnsServers.add(getInetAddress(jsonConfig.getString("dns1")));
staticIpConfig.dnsServers.add(getInetAddress(jsonConfig.getString("dns2")));
config.setIpAssignment(IpAssignment.STATIC);
config.setStaticIpConfiguration(staticIpConfig);
} else {
config.setIpAssignment(IpAssignment.DHCP);
}
config.setProxySettings(ProxySettings.NONE);
return config;
}
use of android.net.wifi.WifiConfiguration in project android_frameworks_base by AOSPA.
the class WifiConfigurationHelper method createWepConfig.
/**
* Create a {@link WifiConfiguration} for a WEP secured network
*
* @param ssid The SSID of the wifi network
* @param password Either a 10, 26, or 58 character hex string or the plain text password
* @return The {@link WifiConfiguration}
*/
public static WifiConfiguration createWepConfig(String ssid, String password) {
WifiConfiguration config = createGenericConfig(ssid);
if (isHex(password, 10) || isHex(password, 26) || isHex(password, 58)) {
config.wepKeys[0] = password;
} else {
config.wepKeys[0] = quotedString(password);
}
config.allowedKeyManagement.set(KeyMgmt.NONE);
config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
return config;
}
use of android.net.wifi.WifiConfiguration in project android_frameworks_base by AOSPA.
the class WifiConfigurationHelper method createPskConfig.
/**
* Create a {@link WifiConfiguration} for a PSK secured network
*
* @param ssid The SSID of the wifi network
* @param password Either a 64 character hex string or the plain text password
* @return The {@link WifiConfiguration}
*/
public static WifiConfiguration createPskConfig(String ssid, String password) {
WifiConfiguration config = createGenericConfig(ssid);
if (isHex(password, 64)) {
config.preSharedKey = password;
} else {
config.preSharedKey = quotedString(password);
}
config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
return config;
}
Aggregations