use of android.net.wifi.WifiConfiguration.ProxySettings in project android_frameworks_base by ParanoidAndroid.
the class WifiConfigStore method readIpAndProxyConfigurations.
private void readIpAndProxyConfigurations() {
DataInputStream in = null;
try {
in = new DataInputStream(new BufferedInputStream(new FileInputStream(ipConfigFile)));
int version = in.readInt();
if (version != 2 && version != 1) {
loge("Bad version on IP configuration file, ignore read");
return;
}
while (true) {
int id = -1;
// Default is DHCP with no proxy
IpAssignment ipAssignment = IpAssignment.DHCP;
ProxySettings proxySettings = ProxySettings.NONE;
LinkProperties linkProperties = new LinkProperties();
String proxyHost = null;
int proxyPort = -1;
String exclusionList = null;
String key;
do {
key = in.readUTF();
try {
if (key.equals(ID_KEY)) {
id = in.readInt();
} else if (key.equals(IP_ASSIGNMENT_KEY)) {
ipAssignment = IpAssignment.valueOf(in.readUTF());
} else if (key.equals(LINK_ADDRESS_KEY)) {
LinkAddress linkAddr = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
linkProperties.addLinkAddress(linkAddr);
} else if (key.equals(GATEWAY_KEY)) {
LinkAddress dest = null;
InetAddress gateway = null;
if (version == 1) {
// only supported default gateways - leave the dest/prefix empty
gateway = NetworkUtils.numericToInetAddress(in.readUTF());
} else {
if (in.readInt() == 1) {
dest = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
}
if (in.readInt() == 1) {
gateway = NetworkUtils.numericToInetAddress(in.readUTF());
}
}
linkProperties.addRoute(new RouteInfo(dest, gateway));
} else if (key.equals(DNS_KEY)) {
linkProperties.addDns(NetworkUtils.numericToInetAddress(in.readUTF()));
} else if (key.equals(PROXY_SETTINGS_KEY)) {
proxySettings = ProxySettings.valueOf(in.readUTF());
} else if (key.equals(PROXY_HOST_KEY)) {
proxyHost = in.readUTF();
} else if (key.equals(PROXY_PORT_KEY)) {
proxyPort = in.readInt();
} else if (key.equals(EXCLUSION_LIST_KEY)) {
exclusionList = in.readUTF();
} else if (key.equals(EOS)) {
break;
} else {
loge("Ignore unknown key " + key + "while reading");
}
} catch (IllegalArgumentException e) {
loge("Ignore invalid address while reading" + e);
}
} while (true);
if (id != -1) {
WifiConfiguration config = mConfiguredNetworks.get(mNetworkIds.get(id));
if (config == null) {
loge("configuration found for missing network, ignored");
} else {
config.linkProperties = linkProperties;
switch(ipAssignment) {
case STATIC:
case DHCP:
config.ipAssignment = ipAssignment;
break;
case UNASSIGNED:
loge("BUG: Found UNASSIGNED IP on file, use DHCP");
config.ipAssignment = IpAssignment.DHCP;
break;
default:
loge("Ignore invalid ip assignment while reading");
break;
}
switch(proxySettings) {
case STATIC:
config.proxySettings = proxySettings;
ProxyProperties proxyProperties = new ProxyProperties(proxyHost, proxyPort, exclusionList);
linkProperties.setHttpProxy(proxyProperties);
break;
case NONE:
config.proxySettings = proxySettings;
break;
case UNASSIGNED:
loge("BUG: Found UNASSIGNED proxy on file, use NONE");
config.proxySettings = ProxySettings.NONE;
break;
default:
loge("Ignore invalid proxy settings while reading");
break;
}
}
} else {
if (DBG)
log("Missing id while parsing configuration");
}
}
} catch (EOFException ignore) {
} catch (IOException e) {
loge("Error parsing configuration" + e);
} finally {
if (in != null) {
try {
in.close();
} catch (Exception e) {
}
}
}
}
use of android.net.wifi.WifiConfiguration.ProxySettings in project XobotOS by xamarin.
the class WifiConfigStore method readIpAndProxyConfigurations.
private static void readIpAndProxyConfigurations() {
DataInputStream in = null;
try {
in = new DataInputStream(new BufferedInputStream(new FileInputStream(ipConfigFile)));
int version = in.readInt();
if (version != 2 && version != 1) {
loge("Bad version on IP configuration file, ignore read");
return;
}
while (true) {
int id = -1;
IpAssignment ipAssignment = IpAssignment.UNASSIGNED;
ProxySettings proxySettings = ProxySettings.UNASSIGNED;
LinkProperties linkProperties = new LinkProperties();
String proxyHost = null;
int proxyPort = -1;
String exclusionList = null;
String key;
do {
key = in.readUTF();
try {
if (key.equals(ID_KEY)) {
id = in.readInt();
} else if (key.equals(IP_ASSIGNMENT_KEY)) {
ipAssignment = IpAssignment.valueOf(in.readUTF());
} else if (key.equals(LINK_ADDRESS_KEY)) {
LinkAddress linkAddr = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
linkProperties.addLinkAddress(linkAddr);
} else if (key.equals(GATEWAY_KEY)) {
LinkAddress dest = null;
InetAddress gateway = null;
if (version == 1) {
// only supported default gateways - leave the dest/prefix empty
gateway = NetworkUtils.numericToInetAddress(in.readUTF());
} else {
if (in.readInt() == 1) {
dest = new LinkAddress(NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt());
}
if (in.readInt() == 1) {
gateway = NetworkUtils.numericToInetAddress(in.readUTF());
}
}
linkProperties.addRoute(new RouteInfo(dest, gateway));
} else if (key.equals(DNS_KEY)) {
linkProperties.addDns(NetworkUtils.numericToInetAddress(in.readUTF()));
} else if (key.equals(PROXY_SETTINGS_KEY)) {
proxySettings = ProxySettings.valueOf(in.readUTF());
} else if (key.equals(PROXY_HOST_KEY)) {
proxyHost = in.readUTF();
} else if (key.equals(PROXY_PORT_KEY)) {
proxyPort = in.readInt();
} else if (key.equals(EXCLUSION_LIST_KEY)) {
exclusionList = in.readUTF();
} else if (key.equals(EOS)) {
break;
} else {
loge("Ignore unknown key " + key + "while reading");
}
} catch (IllegalArgumentException e) {
loge("Ignore invalid address while reading" + e);
}
} while (true);
if (id != -1) {
synchronized (sConfiguredNetworks) {
WifiConfiguration config = sConfiguredNetworks.get(sNetworkIds.get(id));
if (config == null) {
loge("configuration found for missing network, ignored");
} else {
config.linkProperties = linkProperties;
switch(ipAssignment) {
case STATIC:
case DHCP:
config.ipAssignment = ipAssignment;
break;
case UNASSIGNED:
//Ignore
break;
default:
loge("Ignore invalid ip assignment while reading");
break;
}
switch(proxySettings) {
case STATIC:
config.proxySettings = proxySettings;
ProxyProperties proxyProperties = new ProxyProperties(proxyHost, proxyPort, exclusionList);
linkProperties.setHttpProxy(proxyProperties);
break;
case NONE:
config.proxySettings = proxySettings;
break;
case UNASSIGNED:
//Ignore
break;
default:
loge("Ignore invalid proxy settings while reading");
break;
}
}
}
} else {
loge("Missing id while parsing configuration");
}
}
} catch (EOFException ignore) {
} catch (IOException e) {
loge("Error parsing configuration" + e);
} finally {
if (in != null) {
try {
in.close();
} catch (Exception e) {
}
}
}
}
Aggregations