From 7f507337a7243224b272f579c84ea411037a95b5 Mon Sep 17 00:00:00 2001 From: Serik Beketayev Date: Sun, 6 Dec 2020 22:31:23 -0800 Subject: [PATCH] [Mainline Migration] Migrate NetworkUtils Migrating makeStrings(), numericToInetAddress() APIs Bug: 173089079 Test: atest FrameworksNetTests Change-Id: Ie914fd41bc3ce16d07f5d2768b89ce805b9245a9 --- .../java/com/android/server/IpSecService.java | 6 +++--- .../com/android/server/net/IpConfigStore.java | 21 +++++++++++-------- .../android/server/net/IpConfigStoreTest.java | 6 +++--- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/services/core/java/com/android/server/IpSecService.java b/services/core/java/com/android/server/IpSecService.java index b2f0c8376d..f648c3e146 100644 --- a/services/core/java/com/android/server/IpSecService.java +++ b/services/core/java/com/android/server/IpSecService.java @@ -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) { diff --git a/services/core/java/com/android/server/net/IpConfigStore.java b/services/core/java/com/android/server/net/IpConfigStore.java index f0bf5c0975..9c5abd4706 100644 --- a/services/core/java/com/android/server/net/IpConfigStore.java +++ b/services/core/java/com/android/server/net/IpConfigStore.java @@ -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)) { diff --git a/services/tests/servicestests/src/com/android/server/net/IpConfigStoreTest.java b/services/tests/servicestests/src/com/android/server/net/IpConfigStoreTest.java index 7767a2810a..9d300a6113 100644 --- a/services/tests/servicestests/src/com/android/server/net/IpConfigStoreTest.java +++ b/services/tests/servicestests/src/com/android/server/net/IpConfigStoreTest.java @@ -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");