From 0f40c023f648befe090a8b16abc25dbe8df18c2c Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Wed, 3 Feb 2021 18:08:59 +0800 Subject: [PATCH] Replace NetworkUtils methods NetworkUtils is moved to connectivity mainline module which is not accessible for module outside. getNetworkPart() method is used by wifi lib and Settings but no usage inside the module, so move the method to framework lib to share with wifi lib and Settings. Also, NetworkUtils.numericToInetAddress() method is also hidden and deprecated. It should be replaced by InetAddresses.parseNumericAddress(). Update the corresponding usage to refer to these methods. Bug: 172183305 Test: atest SettingsRoboTests Change-Id: I8240b1c74b53d5d66850d9a3ec7d5e5c11558e6a Merged-In: I2fb674e0d7da0b11ba70177853fd6259bce372a3 --- src/com/android/settings/wifi/WifiConfigController.java | 7 ++++--- src/com/android/settings/wifi/WifiConfigController2.java | 7 ++++--- .../wifi/details/WifiDetailPreferenceController.java | 4 ++-- .../wifi/details2/WifiDetailPreferenceController2.java | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java index 29e4fb73f48..d0b5a4094b2 100644 --- a/src/com/android/settings/wifi/WifiConfigController.java +++ b/src/com/android/settings/wifi/WifiConfigController.java @@ -18,12 +18,12 @@ package com.android.settings.wifi; import android.content.Context; import android.content.res.Resources; +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.NetworkInfo.DetailedState; -import android.net.NetworkUtils; import android.net.ProxyInfo; import android.net.StaticIpConfiguration; import android.net.Uri; @@ -69,6 +69,7 @@ import android.widget.TextView; import androidx.annotation.VisibleForTesting; +import com.android.net.module.util.NetUtils; import com.android.net.module.util.ProxyUtils; import com.android.settings.ProxySelector; import com.android.settings.R; @@ -898,7 +899,7 @@ public class WifiConfigController implements TextWatcher, private Inet4Address getIPv4Address(String text) { try { - return (Inet4Address) NetworkUtils.numericToInetAddress(text); + return (Inet4Address) InetAddresses.parseNumericAddress(text); } catch (IllegalArgumentException | ClassCastException e) { return null; } @@ -934,7 +935,7 @@ public class WifiConfigController implements TextWatcher, if (TextUtils.isEmpty(gateway)) { try { //Extract a default gateway from IP address - InetAddress netPart = NetworkUtils.getNetworkPart(inetAddr, networkPrefixLength); + InetAddress netPart = NetUtils.getNetworkPart(inetAddr, networkPrefixLength); byte[] addr = netPart.getAddress(); addr[addr.length - 1] = 1; mGatewayView.setText(InetAddress.getByAddress(addr).getHostAddress()); diff --git a/src/com/android/settings/wifi/WifiConfigController2.java b/src/com/android/settings/wifi/WifiConfigController2.java index 4d31105cd62..6b7505f16f0 100644 --- a/src/com/android/settings/wifi/WifiConfigController2.java +++ b/src/com/android/settings/wifi/WifiConfigController2.java @@ -18,11 +18,11 @@ package com.android.settings.wifi; import android.content.Context; import android.content.res.Resources; +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.net.Uri; @@ -67,6 +67,7 @@ import android.widget.TextView; import androidx.annotation.VisibleForTesting; +import com.android.net.module.util.NetUtils; import com.android.net.module.util.ProxyUtils; import com.android.settings.ProxySelector; import com.android.settings.R; @@ -879,7 +880,7 @@ public class WifiConfigController2 implements TextWatcher, private Inet4Address getIPv4Address(String text) { try { - return (Inet4Address) NetworkUtils.numericToInetAddress(text); + return (Inet4Address) InetAddresses.parseNumericAddress(text); } catch (IllegalArgumentException | ClassCastException e) { return null; } @@ -915,7 +916,7 @@ public class WifiConfigController2 implements TextWatcher, if (TextUtils.isEmpty(gateway)) { try { //Extract a default gateway from IP address - InetAddress netPart = NetworkUtils.getNetworkPart(inetAddr, networkPrefixLength); + InetAddress netPart = NetUtils.getNetworkPart(inetAddr, networkPrefixLength); byte[] addr = netPart.getAddress(); addr[addr.length - 1] = 1; mGatewayView.setText(InetAddress.getByAddress(addr).getHostAddress()); diff --git a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java index 8dd8d7ad6a4..d5a647a834f 100644 --- a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java +++ b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java @@ -40,7 +40,6 @@ import android.net.Network; import android.net.NetworkCapabilities; import android.net.NetworkInfo; import android.net.NetworkRequest; -import android.net.NetworkUtils; import android.net.RouteInfo; import android.net.Uri; import android.net.wifi.WifiConfiguration; @@ -61,6 +60,7 @@ import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceScreen; +import com.android.net.module.util.NetUtils; import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.core.FeatureFlags; @@ -932,7 +932,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController try { InetAddress all = InetAddress.getByAddress( new byte[]{(byte) 255, (byte) 255, (byte) 255, (byte) 255}); - return NetworkUtils.getNetworkPart(all, prefixLength).getHostAddress(); + return NetUtils.getNetworkPart(all, prefixLength).getHostAddress(); } catch (UnknownHostException e) { return null; } diff --git a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java index 7ef950f0a02..7776c9e8867 100644 --- a/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java +++ b/src/com/android/settings/wifi/details2/WifiDetailPreferenceController2.java @@ -40,7 +40,6 @@ import android.net.Network; import android.net.NetworkCapabilities; import android.net.NetworkInfo; import android.net.NetworkRequest; -import android.net.NetworkUtils; import android.net.RouteInfo; import android.net.Uri; import android.net.wifi.WifiConfiguration; @@ -64,6 +63,7 @@ import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceScreen; +import com.android.net.module.util.NetUtils; import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.core.FeatureFlags; @@ -869,7 +869,7 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle try { InetAddress all = InetAddress.getByAddress( new byte[]{(byte) 255, (byte) 255, (byte) 255, (byte) 255}); - return NetworkUtils.getNetworkPart(all, prefixLength).getHostAddress(); + return NetUtils.getNetworkPart(all, prefixLength).getHostAddress(); } catch (UnknownHostException e) { return null; }