Migrate hidden API in IpConfigStore to formal API am: 481a85d41f am: e9a8490c15
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1577123 Change-Id: I7ef352c7213864ee2ff99c5a2517fb1b9e68d1d2
This commit is contained in:
@@ -42,6 +42,8 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class IpConfigStore {
|
public class IpConfigStore {
|
||||||
private static final String TAG = "IpConfigStore";
|
private static final String TAG = "IpConfigStore";
|
||||||
@@ -83,25 +85,25 @@ public class IpConfigStore {
|
|||||||
boolean written = false;
|
boolean written = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (config.ipAssignment) {
|
switch (config.getIpAssignment()) {
|
||||||
case STATIC:
|
case STATIC:
|
||||||
out.writeUTF(IP_ASSIGNMENT_KEY);
|
out.writeUTF(IP_ASSIGNMENT_KEY);
|
||||||
out.writeUTF(config.ipAssignment.toString());
|
out.writeUTF(config.getIpAssignment().toString());
|
||||||
StaticIpConfiguration staticIpConfiguration = config.staticIpConfiguration;
|
StaticIpConfiguration staticIpConfiguration = config.getStaticIpConfiguration();
|
||||||
if (staticIpConfiguration != null) {
|
if (staticIpConfiguration != null) {
|
||||||
if (staticIpConfiguration.ipAddress != null) {
|
if (staticIpConfiguration.getIpAddress() != null) {
|
||||||
LinkAddress ipAddress = staticIpConfiguration.ipAddress;
|
LinkAddress ipAddress = staticIpConfiguration.getIpAddress();
|
||||||
out.writeUTF(LINK_ADDRESS_KEY);
|
out.writeUTF(LINK_ADDRESS_KEY);
|
||||||
out.writeUTF(ipAddress.getAddress().getHostAddress());
|
out.writeUTF(ipAddress.getAddress().getHostAddress());
|
||||||
out.writeInt(ipAddress.getPrefixLength());
|
out.writeInt(ipAddress.getPrefixLength());
|
||||||
}
|
}
|
||||||
if (staticIpConfiguration.gateway != null) {
|
if (staticIpConfiguration.getGateway() != null) {
|
||||||
out.writeUTF(GATEWAY_KEY);
|
out.writeUTF(GATEWAY_KEY);
|
||||||
out.writeInt(0); // Default route.
|
out.writeInt(0); // Default route.
|
||||||
out.writeInt(1); // Have a gateway.
|
out.writeInt(1); // Have a gateway.
|
||||||
out.writeUTF(staticIpConfiguration.gateway.getHostAddress());
|
out.writeUTF(staticIpConfiguration.getGateway().getHostAddress());
|
||||||
}
|
}
|
||||||
for (InetAddress inetAddr : staticIpConfiguration.dnsServers) {
|
for (InetAddress inetAddr : staticIpConfiguration.getDnsServers()) {
|
||||||
out.writeUTF(DNS_KEY);
|
out.writeUTF(DNS_KEY);
|
||||||
out.writeUTF(inetAddr.getHostAddress());
|
out.writeUTF(inetAddr.getHostAddress());
|
||||||
}
|
}
|
||||||
@@ -110,7 +112,7 @@ public class IpConfigStore {
|
|||||||
break;
|
break;
|
||||||
case DHCP:
|
case DHCP:
|
||||||
out.writeUTF(IP_ASSIGNMENT_KEY);
|
out.writeUTF(IP_ASSIGNMENT_KEY);
|
||||||
out.writeUTF(config.ipAssignment.toString());
|
out.writeUTF(config.getIpAssignment().toString());
|
||||||
written = true;
|
written = true;
|
||||||
break;
|
break;
|
||||||
case UNASSIGNED:
|
case UNASSIGNED:
|
||||||
@@ -121,13 +123,13 @@ public class IpConfigStore {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (config.proxySettings) {
|
switch (config.getProxySettings()) {
|
||||||
case STATIC:
|
case STATIC:
|
||||||
ProxyInfo proxyProperties = config.httpProxy;
|
ProxyInfo proxyProperties = config.getHttpProxy();
|
||||||
String exclusionList = ProxyUtils.exclusionListAsString(
|
String exclusionList = ProxyUtils.exclusionListAsString(
|
||||||
proxyProperties.getExclusionList());
|
proxyProperties.getExclusionList());
|
||||||
out.writeUTF(PROXY_SETTINGS_KEY);
|
out.writeUTF(PROXY_SETTINGS_KEY);
|
||||||
out.writeUTF(config.proxySettings.toString());
|
out.writeUTF(config.getProxySettings().toString());
|
||||||
out.writeUTF(PROXY_HOST_KEY);
|
out.writeUTF(PROXY_HOST_KEY);
|
||||||
out.writeUTF(proxyProperties.getHost());
|
out.writeUTF(proxyProperties.getHost());
|
||||||
out.writeUTF(PROXY_PORT_KEY);
|
out.writeUTF(PROXY_PORT_KEY);
|
||||||
@@ -139,16 +141,16 @@ public class IpConfigStore {
|
|||||||
written = true;
|
written = true;
|
||||||
break;
|
break;
|
||||||
case PAC:
|
case PAC:
|
||||||
ProxyInfo proxyPacProperties = config.httpProxy;
|
ProxyInfo proxyPacProperties = config.getHttpProxy();
|
||||||
out.writeUTF(PROXY_SETTINGS_KEY);
|
out.writeUTF(PROXY_SETTINGS_KEY);
|
||||||
out.writeUTF(config.proxySettings.toString());
|
out.writeUTF(config.getProxySettings().toString());
|
||||||
out.writeUTF(PROXY_PAC_FILE);
|
out.writeUTF(PROXY_PAC_FILE);
|
||||||
out.writeUTF(proxyPacProperties.getPacFileUrl().toString());
|
out.writeUTF(proxyPacProperties.getPacFileUrl().toString());
|
||||||
written = true;
|
written = true;
|
||||||
break;
|
break;
|
||||||
case NONE:
|
case NONE:
|
||||||
out.writeUTF(PROXY_SETTINGS_KEY);
|
out.writeUTF(PROXY_SETTINGS_KEY);
|
||||||
out.writeUTF(config.proxySettings.toString());
|
out.writeUTF(config.getProxySettings().toString());
|
||||||
written = true;
|
written = true;
|
||||||
break;
|
break;
|
||||||
case UNASSIGNED:
|
case UNASSIGNED:
|
||||||
@@ -267,11 +269,14 @@ public class IpConfigStore {
|
|||||||
IpAssignment ipAssignment = IpAssignment.DHCP;
|
IpAssignment ipAssignment = IpAssignment.DHCP;
|
||||||
ProxySettings proxySettings = ProxySettings.NONE;
|
ProxySettings proxySettings = ProxySettings.NONE;
|
||||||
StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration();
|
StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration();
|
||||||
|
LinkAddress linkAddress = null;
|
||||||
|
InetAddress gatewayAddress = null;
|
||||||
String proxyHost = null;
|
String proxyHost = null;
|
||||||
String pacFileUrl = null;
|
String pacFileUrl = null;
|
||||||
int proxyPort = -1;
|
int proxyPort = -1;
|
||||||
String exclusionList = null;
|
String exclusionList = null;
|
||||||
String key;
|
String key;
|
||||||
|
final List<InetAddress> dnsServers = new ArrayList<>();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
key = in.readUTF();
|
key = in.readUTF();
|
||||||
@@ -286,15 +291,15 @@ public class IpConfigStore {
|
|||||||
} else if (key.equals(IP_ASSIGNMENT_KEY)) {
|
} else if (key.equals(IP_ASSIGNMENT_KEY)) {
|
||||||
ipAssignment = IpAssignment.valueOf(in.readUTF());
|
ipAssignment = IpAssignment.valueOf(in.readUTF());
|
||||||
} else if (key.equals(LINK_ADDRESS_KEY)) {
|
} else if (key.equals(LINK_ADDRESS_KEY)) {
|
||||||
LinkAddress linkAddr =
|
LinkAddress parsedLinkAddress =
|
||||||
new LinkAddress(
|
new LinkAddress(
|
||||||
InetAddresses.parseNumericAddress(in.readUTF()),
|
InetAddresses.parseNumericAddress(in.readUTF()),
|
||||||
in.readInt());
|
in.readInt());
|
||||||
if (linkAddr.getAddress() instanceof Inet4Address &&
|
if (parsedLinkAddress.getAddress() instanceof Inet4Address
|
||||||
staticIpConfiguration.ipAddress == null) {
|
&& linkAddress == null) {
|
||||||
staticIpConfiguration.ipAddress = linkAddr;
|
linkAddress = parsedLinkAddress;
|
||||||
} else {
|
} else {
|
||||||
loge("Non-IPv4 or duplicate address: " + linkAddr);
|
loge("Non-IPv4 or duplicate address: " + parsedLinkAddress);
|
||||||
}
|
}
|
||||||
} else if (key.equals(GATEWAY_KEY)) {
|
} else if (key.equals(GATEWAY_KEY)) {
|
||||||
LinkAddress dest = null;
|
LinkAddress dest = null;
|
||||||
@@ -302,8 +307,8 @@ public class IpConfigStore {
|
|||||||
if (version == 1) {
|
if (version == 1) {
|
||||||
// only supported default gateways - leave the dest/prefix empty
|
// only supported default gateways - leave the dest/prefix empty
|
||||||
gateway = InetAddresses.parseNumericAddress(in.readUTF());
|
gateway = InetAddresses.parseNumericAddress(in.readUTF());
|
||||||
if (staticIpConfiguration.gateway == null) {
|
if (gatewayAddress == null) {
|
||||||
staticIpConfiguration.gateway = gateway;
|
gatewayAddress = gateway;
|
||||||
} else {
|
} else {
|
||||||
loge("Duplicate gateway: " + gateway.getHostAddress());
|
loge("Duplicate gateway: " + gateway.getHostAddress());
|
||||||
}
|
}
|
||||||
@@ -318,16 +323,14 @@ public class IpConfigStore {
|
|||||||
gateway = InetAddresses.parseNumericAddress(in.readUTF());
|
gateway = InetAddresses.parseNumericAddress(in.readUTF());
|
||||||
}
|
}
|
||||||
RouteInfo route = new RouteInfo(dest, gateway);
|
RouteInfo route = new RouteInfo(dest, gateway);
|
||||||
if (route.isIPv4Default() &&
|
if (route.isIPv4Default() && gatewayAddress == null) {
|
||||||
staticIpConfiguration.gateway == null) {
|
gatewayAddress = gateway;
|
||||||
staticIpConfiguration.gateway = gateway;
|
|
||||||
} else {
|
} else {
|
||||||
loge("Non-IPv4 default or duplicate route: " + route);
|
loge("Non-IPv4 default or duplicate route: " + route);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (key.equals(DNS_KEY)) {
|
} else if (key.equals(DNS_KEY)) {
|
||||||
staticIpConfiguration.dnsServers.add(
|
dnsServers.add(InetAddresses.parseNumericAddress(in.readUTF()));
|
||||||
InetAddresses.parseNumericAddress(in.readUTF()));
|
|
||||||
} else if (key.equals(PROXY_SETTINGS_KEY)) {
|
} else if (key.equals(PROXY_SETTINGS_KEY)) {
|
||||||
proxySettings = ProxySettings.valueOf(in.readUTF());
|
proxySettings = ProxySettings.valueOf(in.readUTF());
|
||||||
} else if (key.equals(PROXY_HOST_KEY)) {
|
} else if (key.equals(PROXY_HOST_KEY)) {
|
||||||
@@ -348,25 +351,31 @@ public class IpConfigStore {
|
|||||||
}
|
}
|
||||||
} while (true);
|
} while (true);
|
||||||
|
|
||||||
|
staticIpConfiguration = new StaticIpConfiguration.Builder()
|
||||||
|
.setIpAddress(linkAddress)
|
||||||
|
.setGateway(gatewayAddress)
|
||||||
|
.setDnsServers(dnsServers)
|
||||||
|
.build();
|
||||||
|
|
||||||
if (uniqueToken != null) {
|
if (uniqueToken != null) {
|
||||||
IpConfiguration config = new IpConfiguration();
|
IpConfiguration config = new IpConfiguration();
|
||||||
networks.put(uniqueToken, config);
|
networks.put(uniqueToken, config);
|
||||||
|
|
||||||
switch (ipAssignment) {
|
switch (ipAssignment) {
|
||||||
case STATIC:
|
case STATIC:
|
||||||
config.staticIpConfiguration = staticIpConfiguration;
|
config.setStaticIpConfiguration(staticIpConfiguration);
|
||||||
config.ipAssignment = ipAssignment;
|
config.setIpAssignment(ipAssignment);
|
||||||
break;
|
break;
|
||||||
case DHCP:
|
case DHCP:
|
||||||
config.ipAssignment = ipAssignment;
|
config.setIpAssignment(ipAssignment);
|
||||||
break;
|
break;
|
||||||
case UNASSIGNED:
|
case UNASSIGNED:
|
||||||
loge("BUG: Found UNASSIGNED IP on file, use DHCP");
|
loge("BUG: Found UNASSIGNED IP on file, use DHCP");
|
||||||
config.ipAssignment = IpAssignment.DHCP;
|
config.setIpAssignment(IpAssignment.DHCP);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
loge("Ignore invalid ip assignment while reading.");
|
loge("Ignore invalid ip assignment while reading.");
|
||||||
config.ipAssignment = IpAssignment.UNASSIGNED;
|
config.setIpAssignment(IpAssignment.UNASSIGNED);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,25 +383,25 @@ public class IpConfigStore {
|
|||||||
case STATIC:
|
case STATIC:
|
||||||
ProxyInfo proxyInfo = ProxyInfo.buildDirectProxy(proxyHost, proxyPort,
|
ProxyInfo proxyInfo = ProxyInfo.buildDirectProxy(proxyHost, proxyPort,
|
||||||
ProxyUtils.exclusionStringAsList(exclusionList));
|
ProxyUtils.exclusionStringAsList(exclusionList));
|
||||||
config.proxySettings = proxySettings;
|
config.setProxySettings(proxySettings);
|
||||||
config.httpProxy = proxyInfo;
|
config.setHttpProxy(proxyInfo);
|
||||||
break;
|
break;
|
||||||
case PAC:
|
case PAC:
|
||||||
ProxyInfo proxyPacProperties =
|
ProxyInfo proxyPacProperties =
|
||||||
ProxyInfo.buildPacProxy(Uri.parse(pacFileUrl));
|
ProxyInfo.buildPacProxy(Uri.parse(pacFileUrl));
|
||||||
config.proxySettings = proxySettings;
|
config.setProxySettings(proxySettings);
|
||||||
config.httpProxy = proxyPacProperties;
|
config.setHttpProxy(proxyPacProperties);
|
||||||
break;
|
break;
|
||||||
case NONE:
|
case NONE:
|
||||||
config.proxySettings = proxySettings;
|
config.setProxySettings(proxySettings);
|
||||||
break;
|
break;
|
||||||
case UNASSIGNED:
|
case UNASSIGNED:
|
||||||
loge("BUG: Found UNASSIGNED proxy on file, use NONE");
|
loge("BUG: Found UNASSIGNED proxy on file, use NONE");
|
||||||
config.proxySettings = ProxySettings.NONE;
|
config.setProxySettings(ProxySettings.NONE);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
loge("Ignore invalid proxy settings while reading");
|
loge("Ignore invalid proxy settings while reading");
|
||||||
config.proxySettings = ProxySettings.UNASSIGNED;
|
config.setProxySettings(ProxySettings.UNASSIGNED);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user