Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9817226d authored by Serik Beketayev's avatar Serik Beketayev
Browse files

[Mainline Migration] Migrate NetworkUtils

Migrating makeStrings(), numericToInetAddress() APIs

Bug: 173089079
Test: atest FrameworksNetTests
Change-Id: Ie914fd41bc3ce16d07f5d2768b89ce805b9245a9
parent a7e74b30
Loading
Loading
Loading
Loading
+0 −15
Original line number Original line Diff line number Diff line
@@ -35,7 +35,6 @@ import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.net.UnknownHostException;
import java.util.Collection;
import java.util.Locale;
import java.util.Locale;
import java.util.TreeSet;
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
     * Trim leading zeros from IPv4 address strings
     * Our base libraries will interpret that as octel..
     * Our base libraries will interpret that as octel..
+1 −1
Original line number Original line Diff line number Diff line
@@ -205,7 +205,7 @@ public final class Proxy {
                if (host.equalsIgnoreCase("localhost")) {
                if (host.equalsIgnoreCase("localhost")) {
                    return true;
                    return true;
                }
                }
                if (NetworkUtils.numericToInetAddress(host).isLoopbackAddress()) {
                if (InetAddresses.parseNumericAddress(host).isLoopbackAddress()) {
                    return true;
                    return true;
                }
                }
            }
            }
+2 −2
Original line number Original line Diff line number Diff line
@@ -19,7 +19,7 @@ package android.media;
import static android.media.MediaPlayer.MEDIA_ERROR_UNSUPPORTED;
import static android.media.MediaPlayer.MEDIA_ERROR_UNSUPPORTED;


import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.net.NetworkUtils;
import android.net.InetAddresses;
import android.os.IBinder;
import android.os.IBinder;
import android.os.StrictMode;
import android.os.StrictMode;
import android.util.Log;
import android.util.Log;
@@ -214,7 +214,7 @@ public class MediaHTTPConnection extends IMediaHTTPConnection.Stub {
            if (host.equalsIgnoreCase("localhost")) {
            if (host.equalsIgnoreCase("localhost")) {
                return true;
                return true;
            }
            }
            if (NetworkUtils.numericToInetAddress(host).isLoopbackAddress()) {
            if (InetAddresses.parseNumericAddress(host).isLoopbackAddress()) {
                return true;
                return true;
            }
            }
        } catch (IllegalArgumentException iex) {
        } catch (IllegalArgumentException iex) {
+3 −3
Original line number Original line Diff line number Diff line
@@ -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) {
+1 −2
Original line number Original line Diff line number Diff line
@@ -58,7 +58,6 @@ import android.net.Network;
import android.net.NetworkPolicyManager;
import android.net.NetworkPolicyManager;
import android.net.NetworkStack;
import android.net.NetworkStack;
import android.net.NetworkStats;
import android.net.NetworkStats;
import android.net.NetworkUtils;
import android.net.RouteInfo;
import android.net.RouteInfo;
import android.net.TetherStatsParcel;
import android.net.TetherStatsParcel;
import android.net.UidRange;
import android.net.UidRange;
@@ -803,7 +802,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
        InterfaceConfiguration cfg = new InterfaceConfiguration();
        InterfaceConfiguration cfg = new InterfaceConfiguration();
        cfg.setHardwareAddress(p.hwAddr);
        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));
        cfg.setLinkAddress(new LinkAddress(addr, p.prefixLength));
        for (String flag : p.flags) {
        for (String flag : p.flags) {
            cfg.setFlag(flag);
            cfg.setFlag(flag);
Loading