summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-11-26 14:11:24 -0800
committerRoshan Pius <rpius@google.com>2019-11-26 14:14:51 -0800
commit4f9c93704c0fad56afcbe8bf86f8200d38aa32cf (patch)
treee9fa17bce95347d0dae713d6f0156cf0d78caba9
parent8bcd6509133a733c410a8112736c5d5245274295 (diff)
wifi: Use public alternatives for NetworkUtils
Bug: 145232020 Test: Connect to wifi networks Test: Ensured that NetworkUtils no longer shows up in the wifi-service extenal hidden API dependency list. Test: atest com.android.server.wifi Change-Id: Ib481f47f0ba11ba2a6419a6ab27d7fc068a72ad4
-rw-r--r--service/java/com/android/server/wifi/ClientModeImpl.java4
-rw-r--r--service/java/com/android/server/wifi/WifiBackupDataV1Parser.java8
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java13
-rw-r--r--service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java6
-rw-r--r--service/java/com/android/server/wifi/util/XmlUtil.java8
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java8
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/OsuNetworkConnectionTest.java8
7 files changed, 28 insertions, 27 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java
index cc859ebe1..f3a59b14b 100644
--- a/service/java/com/android/server/wifi/ClientModeImpl.java
+++ b/service/java/com/android/server/wifi/ClientModeImpl.java
@@ -48,7 +48,6 @@ import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
import android.net.NetworkMisc;
-import android.net.NetworkUtils;
import android.net.RouteInfo;
import android.net.SocketKeepalive;
import android.net.SocketKeepalive.InvalidPacketException;
@@ -57,6 +56,7 @@ import android.net.TcpKeepalivePacketData;
import android.net.ip.IIpClient;
import android.net.ip.IpClientCallbacks;
import android.net.ip.IpClientManager;
+import android.net.shared.Inet4AddressUtils;
import android.net.shared.ProvisioningConfiguration;
import android.net.wifi.IActionListener;
import android.net.wifi.INetworkRequestMatchCallback;
@@ -2791,7 +2791,7 @@ public class ClientModeImpl extends StateMachine {
if (mIsAutoRoaming) {
int previousAddress = mWifiInfo.getIpAddress();
- int newAddress = NetworkUtils.inetAddressToInt(addr);
+ int newAddress = Inet4AddressUtils.inet4AddressToIntHTL(addr);
if (previousAddress != newAddress) {
logd("handleIPv4Success, roaming and address changed"
+ mWifiInfo + " got: " + addr);
diff --git a/service/java/com/android/server/wifi/WifiBackupDataV1Parser.java b/service/java/com/android/server/wifi/WifiBackupDataV1Parser.java
index 13352f7e1..7519a2490 100644
--- a/service/java/com/android/server/wifi/WifiBackupDataV1Parser.java
+++ b/service/java/com/android/server/wifi/WifiBackupDataV1Parser.java
@@ -17,11 +17,11 @@
package com.android.server.wifi;
import android.annotation.Nullable;
+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;
@@ -506,7 +506,7 @@ class WifiBackupDataV1Parser implements WifiBackupDataParser {
StaticIpConfiguration.Builder builder = new StaticIpConfiguration.Builder();
if (linkAddressString != null && linkPrefixLength != null) {
LinkAddress linkAddress = new LinkAddress(
- NetworkUtils.numericToInetAddress(linkAddressString), linkPrefixLength);
+ InetAddresses.parseNumericAddress(linkAddressString), linkPrefixLength);
if (linkAddress.getAddress() instanceof Inet4Address) {
builder.setIpAddress(linkAddress);
} else {
@@ -514,7 +514,7 @@ class WifiBackupDataV1Parser implements WifiBackupDataParser {
}
}
if (gatewayAddressString != null) {
- InetAddress gateway = NetworkUtils.numericToInetAddress(gatewayAddressString);
+ InetAddress gateway = InetAddresses.parseNumericAddress(gatewayAddressString);
RouteInfo route = new RouteInfo(null, gateway, null, RouteInfo.RTN_UNICAST);
if (route.isDefaultRoute()
&& route.getDestination().getAddress() instanceof Inet4Address) {
@@ -527,7 +527,7 @@ class WifiBackupDataV1Parser implements WifiBackupDataParser {
List<InetAddress> dnsServerAddresses = new ArrayList<>();
for (String dnsServerAddressString : dnsServerAddressesString) {
InetAddress dnsServerAddress =
- NetworkUtils.numericToInetAddress(dnsServerAddressString);
+ InetAddresses.parseNumericAddress(dnsServerAddressString);
dnsServerAddresses.add(dnsServerAddress);
}
builder.setDnsServers(dnsServerAddresses);
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 46f76a76d..18cd2f906 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -45,9 +45,9 @@ import android.net.DhcpInfo;
import android.net.DhcpResults;
import android.net.Network;
import android.net.NetworkStack;
-import android.net.NetworkUtils;
import android.net.Uri;
import android.net.ip.IpClientUtil;
+import android.net.shared.Inet4AddressUtils;
import android.net.wifi.IActionListener;
import android.net.wifi.IDppCallback;
import android.net.wifi.ILocalOnlyHotspotCallback;
@@ -2375,28 +2375,29 @@ public class WifiServiceImpl extends BaseWifiService {
if (dhcpResults.ipAddress != null &&
dhcpResults.ipAddress.getAddress() instanceof Inet4Address) {
- info.ipAddress = NetworkUtils.inetAddressToInt(
+ info.ipAddress = Inet4AddressUtils.inet4AddressToIntHTL(
(Inet4Address) dhcpResults.ipAddress.getAddress());
}
if (dhcpResults.gateway != null) {
- info.gateway = NetworkUtils.inetAddressToInt((Inet4Address) dhcpResults.gateway);
+ info.gateway = Inet4AddressUtils.inet4AddressToIntHTL(
+ (Inet4Address) dhcpResults.gateway);
}
int dnsFound = 0;
for (InetAddress dns : dhcpResults.dnsServers) {
if (dns instanceof Inet4Address) {
if (dnsFound == 0) {
- info.dns1 = NetworkUtils.inetAddressToInt((Inet4Address)dns);
+ info.dns1 = Inet4AddressUtils.inet4AddressToIntHTL((Inet4Address) dns);
} else {
- info.dns2 = NetworkUtils.inetAddressToInt((Inet4Address)dns);
+ info.dns2 = Inet4AddressUtils.inet4AddressToIntHTL((Inet4Address) dns);
}
if (++dnsFound > 1) break;
}
}
Inet4Address serverAddress = dhcpResults.serverAddress;
if (serverAddress != null) {
- info.serverAddress = NetworkUtils.inetAddressToInt(serverAddress);
+ info.serverAddress = Inet4AddressUtils.inet4AddressToIntHTL(serverAddress);
}
info.leaseDuration = dhcpResults.leaseDuration;
diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
index 571444a47..1176ee7b5 100644
--- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
+++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java
@@ -31,11 +31,11 @@ import android.database.ContentObserver;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.DhcpResults;
+import android.net.InetAddresses;
import android.net.InterfaceConfiguration;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.NetworkInfo;
-import android.net.NetworkUtils;
import android.net.ip.IIpClient;
import android.net.ip.IpClientCallbacks;
import android.net.ip.IpClientUtil;
@@ -2633,7 +2633,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
// DHCP server has already been started if I am a group owner
if (mGroup.isGroupOwner()) {
setWifiP2pInfoOnGroupFormation(
- NetworkUtils.numericToInetAddress(SERVER_ADDRESS));
+ InetAddresses.parseNumericAddress(SERVER_ADDRESS));
}
// In case of a negotiation group, connection changed is sent
@@ -3096,7 +3096,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub {
InterfaceConfiguration ifcg = null;
try {
ifcg = mNwService.getInterfaceConfig(intf);
- ifcg.setLinkAddress(new LinkAddress(NetworkUtils.numericToInetAddress(
+ ifcg.setLinkAddress(new LinkAddress(InetAddresses.parseNumericAddress(
SERVER_ADDRESS), 24));
ifcg.setInterfaceUp();
mNwService.setInterfaceConfig(intf, ifcg);
diff --git a/service/java/com/android/server/wifi/util/XmlUtil.java b/service/java/com/android/server/wifi/util/XmlUtil.java
index 1093a9612..9ff6554be 100644
--- a/service/java/com/android/server/wifi/util/XmlUtil.java
+++ b/service/java/com/android/server/wifi/util/XmlUtil.java
@@ -18,12 +18,12 @@ package com.android.server.wifi.util;
import android.annotation.NonNull;
import android.annotation.Nullable;
+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.MacAddress;
-import android.net.NetworkUtils;
import android.net.ProxyInfo;
import android.net.RouteInfo;
import android.net.StaticIpConfiguration;
@@ -888,7 +888,7 @@ public class XmlUtil {
(Integer) XmlUtil.readNextValueWithName(in, XML_TAG_LINK_PREFIX_LENGTH);
if (linkAddressString != null && linkPrefixLength != null) {
LinkAddress linkAddress = new LinkAddress(
- NetworkUtils.numericToInetAddress(linkAddressString),
+ InetAddresses.parseNumericAddress(linkAddressString),
linkPrefixLength);
if (linkAddress.getAddress() instanceof Inet4Address) {
builder.setIpAddress(linkAddress);
@@ -900,7 +900,7 @@ public class XmlUtil {
(String) XmlUtil.readNextValueWithName(in, XML_TAG_GATEWAY_ADDRESS);
if (gatewayAddressString != null) {
InetAddress gateway =
- NetworkUtils.numericToInetAddress(gatewayAddressString);
+ InetAddresses.parseNumericAddress(gatewayAddressString);
RouteInfo route = new RouteInfo(null, gateway, null, RouteInfo.RTN_UNICAST);
if (route.isDefaultRoute()
&& route.getDestination().getAddress() instanceof Inet4Address) {
@@ -915,7 +915,7 @@ public class XmlUtil {
List<InetAddress> dnsServerAddresses = new ArrayList<>();
for (String dnsServerAddressString : dnsServerAddressesString) {
InetAddress dnsServerAddress =
- NetworkUtils.numericToInetAddress(dnsServerAddressString);
+ InetAddresses.parseNumericAddress(dnsServerAddressString);
dnsServerAddresses.add(dnsServerAddress);
}
builder.setDnsServers(dnsServerAddresses);
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
index 3450f8f0d..e5bb6b390 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java
@@ -18,9 +18,9 @@ package com.android.server.wifi;
import static org.junit.Assert.*;
+import android.net.InetAddresses;
import android.net.IpConfiguration;
import android.net.LinkAddress;
-import android.net.NetworkUtils;
import android.net.ProxyInfo;
import android.net.StaticIpConfiguration;
import android.net.wifi.WifiConfiguration;
@@ -195,20 +195,20 @@ public class WifiConfigurationTestUtil {
if (!TextUtils.isEmpty(linkAddress)) {
LinkAddress linkAddr =
new LinkAddress(
- NetworkUtils.numericToInetAddress(linkAddress), linkPrefixLength);
+ InetAddresses.parseNumericAddress(linkAddress), linkPrefixLength);
staticIpConfiguration.ipAddress = linkAddr;
}
if (!TextUtils.isEmpty(gatewayAddress)) {
InetAddress gatewayAddr =
- NetworkUtils.numericToInetAddress(gatewayAddress);
+ InetAddresses.parseNumericAddress(gatewayAddress);
staticIpConfiguration.gateway = gatewayAddr;
}
if (dnsServerAddresses != null) {
for (String dnsServerAddress : dnsServerAddresses) {
if (!TextUtils.isEmpty(dnsServerAddress)) {
staticIpConfiguration.dnsServers.add(
- NetworkUtils.numericToInetAddress(dnsServerAddress));
+ InetAddresses.parseNumericAddress(dnsServerAddress));
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuNetworkConnectionTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuNetworkConnectionTest.java
index 8f3daa243..8ada4b54e 100644
--- a/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuNetworkConnectionTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/OsuNetworkConnectionTest.java
@@ -32,11 +32,11 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
+import android.net.InetAddresses;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkRequest;
-import android.net.NetworkUtils;
import android.net.RouteInfo;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
@@ -104,10 +104,10 @@ public class OsuNetworkConnectionTest extends WifiBaseTest {
}
private LinkProperties createProvisionedLinkProperties() {
- InetAddress addrV4 = NetworkUtils.numericToInetAddress("75.208.6.1");
- InetAddress dns1 = NetworkUtils.numericToInetAddress("75.208.7.1");
+ InetAddress addrV4 = InetAddresses.parseNumericAddress("75.208.6.1");
+ InetAddress dns1 = InetAddresses.parseNumericAddress("75.208.7.1");
LinkAddress linkAddrV4 = new LinkAddress(addrV4, 32);
- InetAddress gateway1 = NetworkUtils.numericToInetAddress("75.208.8.1");
+ InetAddress gateway1 = InetAddresses.parseNumericAddress("75.208.8.1");
LinkProperties lp4 = new LinkProperties();
lp4.addLinkAddress(linkAddrV4);
lp4.addDnsServer(dns1);