use of android.net.StaticIpConfiguration in project android_frameworks_base by crdroidandroid.
the class StaticIpConfigurationTest method passThroughParcel.
private StaticIpConfiguration passThroughParcel(StaticIpConfiguration s) {
Parcel p = Parcel.obtain();
StaticIpConfiguration s2 = null;
try {
s.writeToParcel(p, 0);
p.setDataPosition(0);
s2 = StaticIpConfiguration.CREATOR.createFromParcel(p);
} finally {
p.recycle();
}
assertNotNull(s2);
return s2;
}
use of android.net.StaticIpConfiguration in project android_frameworks_base by crdroidandroid.
the class StaticIpConfigurationTest method makeTestObject.
private StaticIpConfiguration makeTestObject() {
StaticIpConfiguration s = new StaticIpConfiguration();
s.ipAddress = ADDR;
s.gateway = GATEWAY;
s.dnsServers.add(DNS1);
s.dnsServers.add(DNS2);
s.dnsServers.add(DNS3);
s.domains = "google.com";
return s;
}
use of android.net.StaticIpConfiguration in project platform_frameworks_base by android.
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.StaticIpConfiguration in project platform_frameworks_base by android.
the class StaticIpConfigurationTest method testConstructor.
@SmallTest
public void testConstructor() {
StaticIpConfiguration s = new StaticIpConfiguration();
checkEmpty(s);
}
use of android.net.StaticIpConfiguration in project platform_frameworks_base by android.
the class StaticIpConfigurationTest method testHashCodeAndEquals.
@SmallTest
public void testHashCodeAndEquals() {
HashSet<Integer> hashCodes = new HashSet();
hashCodes.add(0);
StaticIpConfiguration s = new StaticIpConfiguration();
// Check that this hash code is nonzero and different from all the ones seen so far.
assertTrue(hashCodes.add(s.hashCode()));
s.ipAddress = ADDR;
assertTrue(hashCodes.add(s.hashCode()));
s.gateway = GATEWAY;
assertTrue(hashCodes.add(s.hashCode()));
s.dnsServers.add(DNS1);
assertTrue(hashCodes.add(s.hashCode()));
s.dnsServers.add(DNS2);
assertTrue(hashCodes.add(s.hashCode()));
s.dnsServers.add(DNS3);
assertTrue(hashCodes.add(s.hashCode()));
s.domains = "example.com";
assertTrue(hashCodes.add(s.hashCode()));
assertFalse(s.equals(null));
assertEquals(s, s);
StaticIpConfiguration s2 = new StaticIpConfiguration(s);
assertEquals(s, s2);
s.ipAddress = new LinkAddress(DNS1, 32);
assertNotEquals(s, s2);
s2 = new StaticIpConfiguration(s);
s.domains = "foo";
assertNotEquals(s, s2);
s2 = new StaticIpConfiguration(s);
s.gateway = DNS2;
assertNotEquals(s, s2);
s2 = new StaticIpConfiguration(s);
s.dnsServers.add(DNS3);
assertNotEquals(s, s2);
}
Aggregations