[Mainline Migration] Migrate NetworkUtils

Migrating makeStrings(), numericToInetAddress() APIs

Bug: 173089079
Test: atest FrameworksNetTests
Change-Id: Ie914fd41bc3ce16d07f5d2768b89ce805b9245a9
This commit is contained in:
Serik Beketayev
2020-12-06 22:31:23 -08:00
parent ef8a605c6f
commit 7f507337a7
3 changed files with 18 additions and 15 deletions

View File

@@ -31,6 +31,7 @@ import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.IIpSecService; import android.net.IIpSecService;
import android.net.INetd; import android.net.INetd;
import android.net.InetAddresses;
import android.net.IpSecAlgorithm; import android.net.IpSecAlgorithm;
import android.net.IpSecConfig; import android.net.IpSecConfig;
import android.net.IpSecManager; import android.net.IpSecManager;
@@ -41,7 +42,6 @@ import android.net.IpSecTunnelInterfaceResponse;
import android.net.IpSecUdpEncapResponse; import android.net.IpSecUdpEncapResponse;
import android.net.LinkAddress; import android.net.LinkAddress;
import android.net.Network; import android.net.Network;
import android.net.NetworkUtils;
import android.net.TrafficStats; import android.net.TrafficStats;
import android.net.util.NetdService; import android.net.util.NetdService;
import android.os.Binder; import android.os.Binder;
@@ -1083,7 +1083,7 @@ public class IpSecService extends IIpSecService.Stub {
throw new IllegalArgumentException("Unspecified address"); throw new IllegalArgumentException("Unspecified address");
} }
InetAddress checkAddr = NetworkUtils.numericToInetAddress(inetAddress); InetAddress checkAddr = InetAddresses.parseNumericAddress(inetAddress);
if (checkAddr.isAnyLocalAddress()) { if (checkAddr.isAnyLocalAddress()) {
throw new IllegalArgumentException("Inappropriate wildcard address: " + inetAddress); throw new IllegalArgumentException("Inappropriate wildcard address: " + inetAddress);
@@ -1467,7 +1467,7 @@ public class IpSecService extends IIpSecService.Stub {
private int getFamily(String inetAddress) { private int getFamily(String inetAddress) {
int family = AF_UNSPEC; int family = AF_UNSPEC;
InetAddress checkAddress = NetworkUtils.numericToInetAddress(inetAddress); InetAddress checkAddress = InetAddresses.parseNumericAddress(inetAddress);
if (checkAddress instanceof Inet4Address) { if (checkAddress instanceof Inet4Address) {
family = AF_INET; family = AF_INET;
} else if (checkAddress instanceof Inet6Address) { } else if (checkAddress instanceof Inet6Address) {

View File

@@ -16,11 +16,11 @@
package com.android.server.net; package com.android.server.net;
import android.net.InetAddresses;
import android.net.IpConfiguration; import android.net.IpConfiguration;
import android.net.IpConfiguration.IpAssignment; import android.net.IpConfiguration.IpAssignment;
import android.net.IpConfiguration.ProxySettings; import android.net.IpConfiguration.ProxySettings;
import android.net.LinkAddress; import android.net.LinkAddress;
import android.net.NetworkUtils;
import android.net.ProxyInfo; import android.net.ProxyInfo;
import android.net.RouteInfo; import android.net.RouteInfo;
import android.net.StaticIpConfiguration; import android.net.StaticIpConfiguration;
@@ -284,8 +284,10 @@ 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 = new LinkAddress( LinkAddress linkAddr =
NetworkUtils.numericToInetAddress(in.readUTF()), in.readInt()); new LinkAddress(
InetAddresses.parseNumericAddress(in.readUTF()),
in.readInt());
if (linkAddr.getAddress() instanceof Inet4Address && if (linkAddr.getAddress() instanceof Inet4Address &&
staticIpConfiguration.ipAddress == null) { staticIpConfiguration.ipAddress == null) {
staticIpConfiguration.ipAddress = linkAddr; staticIpConfiguration.ipAddress = linkAddr;
@@ -297,7 +299,7 @@ public class IpConfigStore {
InetAddress gateway = null; InetAddress gateway = null;
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 = NetworkUtils.numericToInetAddress(in.readUTF()); gateway = InetAddresses.parseNumericAddress(in.readUTF());
if (staticIpConfiguration.gateway == null) { if (staticIpConfiguration.gateway == null) {
staticIpConfiguration.gateway = gateway; staticIpConfiguration.gateway = gateway;
} else { } else {
@@ -305,12 +307,13 @@ public class IpConfigStore {
} }
} else { } else {
if (in.readInt() == 1) { if (in.readInt() == 1) {
dest = new LinkAddress( dest =
NetworkUtils.numericToInetAddress(in.readUTF()), new LinkAddress(
InetAddresses.parseNumericAddress(in.readUTF()),
in.readInt()); in.readInt());
} }
if (in.readInt() == 1) { if (in.readInt() == 1) {
gateway = NetworkUtils.numericToInetAddress(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() &&
@@ -322,7 +325,7 @@ public class IpConfigStore {
} }
} else if (key.equals(DNS_KEY)) { } else if (key.equals(DNS_KEY)) {
staticIpConfiguration.dnsServers.add( staticIpConfiguration.dnsServers.add(
NetworkUtils.numericToInetAddress(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)) {

View File

@@ -20,11 +20,11 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import android.net.InetAddresses;
import android.net.IpConfiguration; import android.net.IpConfiguration;
import android.net.IpConfiguration.IpAssignment; import android.net.IpConfiguration.IpAssignment;
import android.net.IpConfiguration.ProxySettings; import android.net.IpConfiguration.ProxySettings;
import android.net.LinkAddress; import android.net.LinkAddress;
import android.net.NetworkUtils;
import android.net.ProxyInfo; import android.net.ProxyInfo;
import android.net.StaticIpConfiguration; import android.net.StaticIpConfiguration;
import android.util.ArrayMap; import android.util.ArrayMap;
@@ -79,8 +79,8 @@ public class IpConfigStoreTest {
StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration(); StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration();
staticIpConfiguration.ipAddress = new LinkAddress(IP_ADDR_1); staticIpConfiguration.ipAddress = new LinkAddress(IP_ADDR_1);
staticIpConfiguration.dnsServers.add(NetworkUtils.numericToInetAddress(DNS_IP_ADDR_1)); staticIpConfiguration.dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_1));
staticIpConfiguration.dnsServers.add(NetworkUtils.numericToInetAddress(DNS_IP_ADDR_2)); staticIpConfiguration.dnsServers.add(InetAddresses.parseNumericAddress(DNS_IP_ADDR_2));
ProxyInfo proxyInfo = new ProxyInfo("10.10.10.10", 88, "host1,host2"); ProxyInfo proxyInfo = new ProxyInfo("10.10.10.10", 88, "host1,host2");