Merge "[Mainline Migration] Migrate NetworkUtils" am: a086c295e7 am: c6218f7977 am: 006d043dfe
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1498168 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Id0749108e03d88af0b8c50a36f1a4ca28b9a40ce
This commit is contained in:
@@ -35,7 +35,6 @@ import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.TreeSet;
|
||||
|
||||
@@ -341,20 +340,6 @@ public class NetworkUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a string array of host addresses from a collection of InetAddresses
|
||||
* @param addrs a Collection of InetAddresses
|
||||
* @return an array of Strings containing their host addresses
|
||||
*/
|
||||
public static String[] makeStrings(Collection<InetAddress> addrs) {
|
||||
String[] result = new String[addrs.size()];
|
||||
int i = 0;
|
||||
for (InetAddress addr : addrs) {
|
||||
result[i++] = addr.getHostAddress();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim leading zeros from IPv4 address strings
|
||||
* Our base libraries will interpret that as octel..
|
||||
|
||||
@@ -205,7 +205,7 @@ public final class Proxy {
|
||||
if (host.equalsIgnoreCase("localhost")) {
|
||||
return true;
|
||||
}
|
||||
if (NetworkUtils.numericToInetAddress(host).isLoopbackAddress()) {
|
||||
if (InetAddresses.parseNumericAddress(host).isLoopbackAddress()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package android.media;
|
||||
import static android.media.MediaPlayer.MEDIA_ERROR_UNSUPPORTED;
|
||||
|
||||
import android.compat.annotation.UnsupportedAppUsage;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.InetAddresses;
|
||||
import android.os.IBinder;
|
||||
import android.os.StrictMode;
|
||||
import android.util.Log;
|
||||
@@ -214,7 +214,7 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
|
||||
if (host.equalsIgnoreCase("localhost")) {
|
||||
return true;
|
||||
}
|
||||
if (NetworkUtils.numericToInetAddress(host).isLoopbackAddress()) {
|
||||
if (InetAddresses.parseNumericAddress(host).isLoopbackAddress()) {
|
||||
return true;
|
||||
}
|
||||
} catch (IllegalArgumentException iex) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.IIpSecService;
|
||||
import android.net.INetd;
|
||||
import android.net.InetAddresses;
|
||||
import android.net.IpSecAlgorithm;
|
||||
import android.net.IpSecConfig;
|
||||
import android.net.IpSecManager;
|
||||
@@ -41,7 +42,6 @@ import android.net.IpSecTunnelInterfaceResponse;
|
||||
import android.net.IpSecUdpEncapResponse;
|
||||
import android.net.LinkAddress;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.TrafficStats;
|
||||
import android.net.util.NetdService;
|
||||
import android.os.Binder;
|
||||
@@ -1083,7 +1083,7 @@ public class IpSecService extends IIpSecService.Stub {
|
||||
throw new IllegalArgumentException("Unspecified address");
|
||||
}
|
||||
|
||||
InetAddress checkAddr = NetworkUtils.numericToInetAddress(inetAddress);
|
||||
InetAddress checkAddr = InetAddresses.parseNumericAddress(inetAddress);
|
||||
|
||||
if (checkAddr.isAnyLocalAddress()) {
|
||||
throw new IllegalArgumentException("Inappropriate wildcard address: " + inetAddress);
|
||||
@@ -1467,7 +1467,7 @@ public class IpSecService extends IIpSecService.Stub {
|
||||
|
||||
private int getFamily(String inetAddress) {
|
||||
int family = AF_UNSPEC;
|
||||
InetAddress checkAddress = NetworkUtils.numericToInetAddress(inetAddress);
|
||||
InetAddress checkAddress = InetAddresses.parseNumericAddress(inetAddress);
|
||||
if (checkAddress instanceof Inet4Address) {
|
||||
family = AF_INET;
|
||||
} else if (checkAddress instanceof Inet6Address) {
|
||||
|
||||
@@ -58,7 +58,6 @@ import android.net.Network;
|
||||
import android.net.NetworkPolicyManager;
|
||||
import android.net.NetworkStack;
|
||||
import android.net.NetworkStats;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.RouteInfo;
|
||||
import android.net.TetherStatsParcel;
|
||||
import android.net.UidRange;
|
||||
@@ -803,7 +802,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
||||
InterfaceConfiguration cfg = new InterfaceConfiguration();
|
||||
cfg.setHardwareAddress(p.hwAddr);
|
||||
|
||||
final InetAddress addr = NetworkUtils.numericToInetAddress(p.ipv4Addr);
|
||||
final InetAddress addr = InetAddresses.parseNumericAddress(p.ipv4Addr);
|
||||
cfg.setLinkAddress(new LinkAddress(addr, p.prefixLength));
|
||||
for (String flag : p.flags) {
|
||||
cfg.setFlag(flag);
|
||||
|
||||
@@ -34,7 +34,6 @@ import android.content.Intent;
|
||||
import android.net.IDnsResolver;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.ResolverOptionsParcel;
|
||||
import android.net.ResolverParamsParcel;
|
||||
import android.net.Uri;
|
||||
@@ -50,6 +49,7 @@ import android.util.Pair;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -364,12 +364,11 @@ public class DnsManager {
|
||||
paramsParcel.successThreshold = mSuccessThreshold;
|
||||
paramsParcel.minSamples = mMinSamples;
|
||||
paramsParcel.maxSamples = mMaxSamples;
|
||||
paramsParcel.servers =
|
||||
NetworkUtils.makeStrings(lp.getDnsServers());
|
||||
paramsParcel.servers = makeStrings(lp.getDnsServers());
|
||||
paramsParcel.domains = getDomainStrings(lp.getDomains());
|
||||
paramsParcel.tlsName = strictMode ? privateDnsCfg.hostname : "";
|
||||
paramsParcel.tlsServers =
|
||||
strictMode ? NetworkUtils.makeStrings(
|
||||
strictMode ? makeStrings(
|
||||
Arrays.stream(privateDnsCfg.ips)
|
||||
.filter((ip) -> lp.isReachable(ip))
|
||||
.collect(Collectors.toList()))
|
||||
@@ -460,6 +459,21 @@ public class DnsManager {
|
||||
return Settings.Global.getInt(mContentResolver, which, dflt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a string array of host addresses from a collection of InetAddresses
|
||||
*
|
||||
* @param addrs a Collection of InetAddresses
|
||||
* @return an array of Strings containing their host addresses
|
||||
*/
|
||||
private String[] makeStrings(Collection<InetAddress> addrs) {
|
||||
String[] result = new String[addrs.size()];
|
||||
int i = 0;
|
||||
for (InetAddress addr : addrs) {
|
||||
result[i++] = addr.getHostAddress();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String getPrivateDnsMode(ContentResolver cr) {
|
||||
String mode = getStringSetting(cr, PRIVATE_DNS_MODE);
|
||||
if (TextUtils.isEmpty(mode)) mode = getStringSetting(cr, PRIVATE_DNS_DEFAULT_MODE);
|
||||
|
||||
@@ -40,11 +40,11 @@ import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.net.ISocketKeepaliveCallback;
|
||||
import android.net.InetAddresses;
|
||||
import android.net.InvalidPacketException;
|
||||
import android.net.KeepalivePacketData;
|
||||
import android.net.NattKeepalivePacketData;
|
||||
import android.net.NetworkAgent;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.SocketKeepalive.InvalidSocketException;
|
||||
import android.net.TcpKeepalivePacketData;
|
||||
import android.net.util.KeepaliveUtils;
|
||||
@@ -625,8 +625,8 @@ public class KeepaliveTracker {
|
||||
|
||||
InetAddress srcAddress, dstAddress;
|
||||
try {
|
||||
srcAddress = NetworkUtils.numericToInetAddress(srcAddrString);
|
||||
dstAddress = NetworkUtils.numericToInetAddress(dstAddrString);
|
||||
srcAddress = InetAddresses.parseNumericAddress(srcAddrString);
|
||||
dstAddress = InetAddresses.parseNumericAddress(dstAddrString);
|
||||
} catch (IllegalArgumentException e) {
|
||||
notifyErrorCallback(cb, ERROR_INVALID_IP_ADDRESS);
|
||||
return;
|
||||
|
||||
@@ -20,10 +20,10 @@ import static android.system.OsConstants.*;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.net.InetAddresses;
|
||||
import android.net.LinkAddress;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.RouteInfo;
|
||||
import android.net.TrafficStats;
|
||||
import android.net.shared.PrivateDnsConfig;
|
||||
@@ -97,8 +97,8 @@ import javax.net.ssl.SSLSocketFactory;
|
||||
public class NetworkDiagnostics {
|
||||
private static final String TAG = "NetworkDiagnostics";
|
||||
|
||||
private static final InetAddress TEST_DNS4 = NetworkUtils.numericToInetAddress("8.8.8.8");
|
||||
private static final InetAddress TEST_DNS6 = NetworkUtils.numericToInetAddress(
|
||||
private static final InetAddress TEST_DNS4 = InetAddresses.parseNumericAddress("8.8.8.8");
|
||||
private static final InetAddress TEST_DNS6 = InetAddresses.parseNumericAddress(
|
||||
"2001:4860:4860::8888");
|
||||
|
||||
// For brevity elsewhere.
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package com.android.server.net;
|
||||
|
||||
import android.net.InetAddresses;
|
||||
import android.net.IpConfiguration;
|
||||
import android.net.IpConfiguration.IpAssignment;
|
||||
import android.net.IpConfiguration.ProxySettings;
|
||||
import android.net.LinkAddress;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.ProxyInfo;
|
||||
import android.net.RouteInfo;
|
||||
import android.net.StaticIpConfiguration;
|
||||
@@ -284,8 +284,10 @@ public class IpConfigStore {
|
||||
} 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());
|
||||
LinkAddress linkAddr =
|
||||
new LinkAddress(
|
||||
InetAddresses.parseNumericAddress(in.readUTF()),
|
||||
in.readInt());
|
||||
if (linkAddr.getAddress() instanceof Inet4Address &&
|
||||
staticIpConfiguration.ipAddress == null) {
|
||||
staticIpConfiguration.ipAddress = linkAddr;
|
||||
@@ -297,7 +299,7 @@ public class IpConfigStore {
|
||||
InetAddress gateway = null;
|
||||
if (version == 1) {
|
||||
// only supported default gateways - leave the dest/prefix empty
|
||||
gateway = NetworkUtils.numericToInetAddress(in.readUTF());
|
||||
gateway = InetAddresses.parseNumericAddress(in.readUTF());
|
||||
if (staticIpConfiguration.gateway == null) {
|
||||
staticIpConfiguration.gateway = gateway;
|
||||
} else {
|
||||
@@ -305,12 +307,13 @@ public class IpConfigStore {
|
||||
}
|
||||
} else {
|
||||
if (in.readInt() == 1) {
|
||||
dest = new LinkAddress(
|
||||
NetworkUtils.numericToInetAddress(in.readUTF()),
|
||||
in.readInt());
|
||||
dest =
|
||||
new LinkAddress(
|
||||
InetAddresses.parseNumericAddress(in.readUTF()),
|
||||
in.readInt());
|
||||
}
|
||||
if (in.readInt() == 1) {
|
||||
gateway = NetworkUtils.numericToInetAddress(in.readUTF());
|
||||
gateway = InetAddresses.parseNumericAddress(in.readUTF());
|
||||
}
|
||||
RouteInfo route = new RouteInfo(dest, gateway);
|
||||
if (route.isIPv4Default() &&
|
||||
@@ -322,7 +325,7 @@ public class IpConfigStore {
|
||||
}
|
||||
} else if (key.equals(DNS_KEY)) {
|
||||
staticIpConfiguration.dnsServers.add(
|
||||
NetworkUtils.numericToInetAddress(in.readUTF()));
|
||||
InetAddresses.parseNumericAddress(in.readUTF()));
|
||||
} else if (key.equals(PROXY_SETTINGS_KEY)) {
|
||||
proxySettings = ProxySettings.valueOf(in.readUTF());
|
||||
} else if (key.equals(PROXY_HOST_KEY)) {
|
||||
|
||||
@@ -20,11 +20,11 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import android.net.InetAddresses;
|
||||
import android.net.IpConfiguration;
|
||||
import android.net.IpConfiguration.IpAssignment;
|
||||
import android.net.IpConfiguration.ProxySettings;
|
||||
import android.net.LinkAddress;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.ProxyInfo;
|
||||
import android.net.StaticIpConfiguration;
|
||||
import android.util.ArrayMap;
|
||||
@@ -79,8 +79,8 @@ public class IpConfigStoreTest {
|
||||
|
||||
StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration();
|
||||
staticIpConfiguration.ipAddress = new LinkAddress(IP_ADDR_1);
|
||||
staticIpConfiguration.dnsServers.add(NetworkUtils.numericToInetAddress(DNS_IP_ADDR_1));
|
||||
staticIpConfiguration.dnsServers.add(NetworkUtils.numericToInetAddress(DNS_IP_ADDR_2));
|
||||
staticIpConfiguration.dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_1));
|
||||
staticIpConfiguration.dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_2));
|
||||
|
||||
ProxyInfo proxyInfo = new ProxyInfo("10.10.10.10", 88, "host1,host2");
|
||||
|
||||
|
||||
@@ -68,8 +68,8 @@ public class LinkAddressTest {
|
||||
|
||||
private static final String V4 = "192.0.2.1";
|
||||
private static final String V6 = "2001:db8::1";
|
||||
private static final InetAddress V4_ADDRESS = NetworkUtils.numericToInetAddress(V4);
|
||||
private static final InetAddress V6_ADDRESS = NetworkUtils.numericToInetAddress(V6);
|
||||
private static final InetAddress V4_ADDRESS = InetAddresses.parseNumericAddress(V4);
|
||||
private static final InetAddress V6_ADDRESS = InetAddresses.parseNumericAddress(V6);
|
||||
|
||||
@Test
|
||||
public void testConstants() {
|
||||
@@ -131,10 +131,10 @@ public class LinkAddressTest {
|
||||
ipv6Loopback = new LinkAddress(addrs.get(0));
|
||||
}
|
||||
|
||||
assertEquals(NetworkUtils.numericToInetAddress("127.0.0.1"), ipv4Loopback.getAddress());
|
||||
assertEquals(InetAddresses.parseNumericAddress("127.0.0.1"), ipv4Loopback.getAddress());
|
||||
assertEquals(8, ipv4Loopback.getPrefixLength());
|
||||
|
||||
assertEquals(NetworkUtils.numericToInetAddress("::1"), ipv6Loopback.getAddress());
|
||||
assertEquals(InetAddresses.parseNumericAddress("::1"), ipv6Loopback.getAddress());
|
||||
assertEquals(128, ipv6Loopback.getPrefixLength());
|
||||
|
||||
// Null addresses are rejected.
|
||||
|
||||
@@ -181,7 +181,6 @@ import android.net.NetworkStack;
|
||||
import android.net.NetworkStackClient;
|
||||
import android.net.NetworkState;
|
||||
import android.net.NetworkTestResultParcelable;
|
||||
import android.net.NetworkUtils;
|
||||
import android.net.ProxyInfo;
|
||||
import android.net.ResolverParamsParcel;
|
||||
import android.net.RouteInfo;
|
||||
@@ -4860,7 +4859,7 @@ public class ConnectivityServiceTest {
|
||||
lp.setInterfaceName(WIFI_IFNAME);
|
||||
LinkAddress myIpv4Address = new LinkAddress("192.168.12.3/24");
|
||||
RouteInfo myIpv4DefaultRoute = new RouteInfo((IpPrefix) null,
|
||||
NetworkUtils.numericToInetAddress("192.168.12.1"), lp.getInterfaceName());
|
||||
InetAddresses.parseNumericAddress("192.168.12.1"), lp.getInterfaceName());
|
||||
lp.addLinkAddress(myIpv4Address);
|
||||
lp.addRoute(myIpv4DefaultRoute);
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.INetd;
|
||||
import android.net.InetAddresses;
|
||||
import android.net.IpSecAlgorithm;
|
||||
import android.net.IpSecConfig;
|
||||
import android.net.IpSecManager;
|
||||
@@ -44,7 +45,6 @@ import android.net.IpSecTunnelInterfaceResponse;
|
||||
import android.net.IpSecUdpEncapResponse;
|
||||
import android.net.LinkAddress;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkUtils;
|
||||
import android.os.Binder;
|
||||
import android.os.INetworkManagementService;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
@@ -272,7 +272,7 @@ public class IpSecServiceParameterizedTest {
|
||||
|
||||
IpSecSpiResponse spi =
|
||||
mIpSecService.allocateSecurityParameterIndex(
|
||||
NetworkUtils.numericToInetAddress(remoteAddress).getHostAddress(),
|
||||
InetAddresses.parseNumericAddress(remoteAddress).getHostAddress(),
|
||||
IpSecManager.INVALID_SECURITY_PARAMETER_INDEX,
|
||||
new Binder());
|
||||
return spi.resourceId;
|
||||
|
||||
Reference in New Issue
Block a user