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

Commit 94df39ac authored by Aaron Huang's avatar Aaron Huang Committed by Chalard Jean
Browse files

Remove framework code that has moved to frameworks/libs/net

Add srcs to framework and change import path.
Remove the codes which are moved to frameworks/libs/net.

Bug: 139268426
Bug: 135998869
Bug: 138306002
Bug: 143925787
Test: atest FrameworksNetTests
      atest FrameworksTelephonyTests
      atest ./frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: Ieb8927f9af7f87a5ae038bd6c7daeb3d70117fef
parent f41a9d00
Loading
Loading
Loading
Loading
+7 −69
Original line number Original line Diff line number Diff line
@@ -21,6 +21,8 @@ import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.net.util.LinkPropertiesUtils;
import android.net.util.LinkPropertiesUtils.CompareResult;
import android.os.Build;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
@@ -81,36 +83,6 @@ public final class LinkProperties implements Parcelable {
    // Indexed by interface name to allow modification and to prevent duplicates being added.
    // Indexed by interface name to allow modification and to prevent duplicates being added.
    private Hashtable<String, LinkProperties> mStackedLinks = new Hashtable<>();
    private Hashtable<String, LinkProperties> mStackedLinks = new Hashtable<>();


    /**
     * @hide
     */
    public static class CompareResult<T> {
        public final List<T> removed = new ArrayList<>();
        public final List<T> added = new ArrayList<>();

        public CompareResult() {}

        public CompareResult(Collection<T> oldItems, Collection<T> newItems) {
            if (oldItems != null) {
                removed.addAll(oldItems);
            }
            if (newItems != null) {
                for (T newItem : newItems) {
                    if (!removed.remove(newItem)) {
                        added.add(newItem);
                    }
                }
            }
        }

        @Override
        public String toString() {
            return "removed=[" + TextUtils.join(",", removed)
                    + "] added=[" + TextUtils.join(",", added)
                    + "]";
        }
    }

    /**
    /**
     * @hide
     * @hide
     */
     */
@@ -1295,7 +1267,7 @@ public final class LinkProperties implements Parcelable {
     */
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    public boolean isIdenticalInterfaceName(@NonNull LinkProperties target) {
    public boolean isIdenticalInterfaceName(@NonNull LinkProperties target) {
        return TextUtils.equals(getInterfaceName(), target.getInterfaceName());
        return LinkPropertiesUtils.isIdenticalInterfaceName(target, this);
    }
    }


    /**
    /**
@@ -1318,10 +1290,7 @@ public final class LinkProperties implements Parcelable {
     */
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    public boolean isIdenticalAddresses(@NonNull LinkProperties target) {
    public boolean isIdenticalAddresses(@NonNull LinkProperties target) {
        Collection<InetAddress> targetAddresses = target.getAddresses();
        return LinkPropertiesUtils.isIdenticalAddresses(target, this);
        Collection<InetAddress> sourceAddresses = getAddresses();
        return (sourceAddresses.size() == targetAddresses.size()) ?
                    sourceAddresses.containsAll(targetAddresses) : false;
    }
    }


    /**
    /**
@@ -1333,15 +1302,7 @@ public final class LinkProperties implements Parcelable {
     */
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    public boolean isIdenticalDnses(@NonNull LinkProperties target) {
    public boolean isIdenticalDnses(@NonNull LinkProperties target) {
        Collection<InetAddress> targetDnses = target.getDnsServers();
        return LinkPropertiesUtils.isIdenticalDnses(target, this);
        String targetDomains = target.getDomains();
        if (mDomains == null) {
            if (targetDomains != null) return false;
        } else {
            if (!mDomains.equals(targetDomains)) return false;
        }
        return (mDnses.size() == targetDnses.size()) ?
                mDnses.containsAll(targetDnses) : false;
    }
    }


    /**
    /**
@@ -1394,9 +1355,7 @@ public final class LinkProperties implements Parcelable {
     */
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    public boolean isIdenticalRoutes(@NonNull LinkProperties target) {
    public boolean isIdenticalRoutes(@NonNull LinkProperties target) {
        Collection<RouteInfo> targetRoutes = target.getRoutes();
        return LinkPropertiesUtils.isIdenticalRoutes(target, this);
        return (mRoutes.size() == targetRoutes.size()) ?
                mRoutes.containsAll(targetRoutes) : false;
    }
    }


    /**
    /**
@@ -1408,8 +1367,7 @@ public final class LinkProperties implements Parcelable {
     */
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    public boolean isIdenticalHttpProxy(@NonNull LinkProperties target) {
    public boolean isIdenticalHttpProxy(@NonNull LinkProperties target) {
        return getHttpProxy() == null ? target.getHttpProxy() == null :
        return LinkPropertiesUtils.isIdenticalHttpProxy(target, this);
                getHttpProxy().equals(target.getHttpProxy());
    }
    }


    /**
    /**
@@ -1540,26 +1498,6 @@ public final class LinkProperties implements Parcelable {
                && isIdenticalWakeOnLan(target);
                && isIdenticalWakeOnLan(target);
    }
    }


    /**
     * Compares the addresses in this LinkProperties with another
     * LinkProperties, examining only addresses on the base link.
     *
     * @param target a LinkProperties with the new list of addresses
     * @return the differences between the addresses.
     * @hide
     */
    public @NonNull CompareResult<LinkAddress> compareAddresses(@Nullable LinkProperties target) {
        /*
         * Duplicate the LinkAddresses into removed, we will be removing
         * address which are common between mLinkAddresses and target
         * leaving the addresses that are different. And address which
         * are in target but not in mLinkAddresses are placed in the
         * addedAddresses.
         */
        return new CompareResult<>(mLinkAddresses,
                target != null ? target.getLinkAddresses() : null);
    }

    /**
    /**
     * Compares the DNS addresses in this LinkProperties with another
     * Compares the DNS addresses in this LinkProperties with another
     * LinkProperties, examining only DNS addresses on the base link.
     * LinkProperties, examining only DNS addresses on the base link.
+6 −73
Original line number Original line Diff line number Diff line
@@ -20,11 +20,11 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.net.util.MacAddressUtils;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiInfo;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;


import com.android.internal.util.BitUtils;
import com.android.internal.util.Preconditions;
import com.android.internal.util.Preconditions;


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
@@ -33,7 +33,6 @@ import java.net.Inet6Address;
import java.net.UnknownHostException;
import java.net.UnknownHostException;
import java.security.SecureRandom;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Random;


/**
/**
 * Representation of a MAC address.
 * Representation of a MAC address.
@@ -109,20 +108,12 @@ public final class MacAddress implements Parcelable {
        if (equals(BROADCAST_ADDRESS)) {
        if (equals(BROADCAST_ADDRESS)) {
            return TYPE_BROADCAST;
            return TYPE_BROADCAST;
        }
        }
        if (isMulticastAddress()) {
        if ((mAddr & MULTICAST_MASK) != 0) {
            return TYPE_MULTICAST;
            return TYPE_MULTICAST;
        }
        }
        return TYPE_UNICAST;
        return TYPE_UNICAST;
    }
    }


    /**
     * @return true if this MacAddress is a multicast address.
     * @hide
     */
    public boolean isMulticastAddress() {
        return (mAddr & MULTICAST_MASK) != 0;
    }

    /**
    /**
     * @return true if this MacAddress is a locally assigned address.
     * @return true if this MacAddress is a locally assigned address.
     */
     */
@@ -192,7 +183,7 @@ public final class MacAddress implements Parcelable {
     * @hide
     * @hide
     */
     */
    public static boolean isMacAddress(byte[] addr) {
    public static boolean isMacAddress(byte[] addr) {
        return addr != null && addr.length == ETHER_ADDR_LEN;
        return MacAddressUtils.isMacAddress(addr);
    }
    }


    /**
    /**
@@ -261,26 +252,11 @@ public final class MacAddress implements Parcelable {
    }
    }


    private static byte[] byteAddrFromLongAddr(long addr) {
    private static byte[] byteAddrFromLongAddr(long addr) {
        byte[] bytes = new byte[ETHER_ADDR_LEN];
        return MacAddressUtils.byteAddrFromLongAddr(addr);
        int index = ETHER_ADDR_LEN;
        while (index-- > 0) {
            bytes[index] = (byte) addr;
            addr = addr >> 8;
        }
        return bytes;
    }
    }


    private static long longAddrFromByteAddr(byte[] addr) {
    private static long longAddrFromByteAddr(byte[] addr) {
        Preconditions.checkNotNull(addr);
        return MacAddressUtils.longAddrFromByteAddr(addr);
        if (!isMacAddress(addr)) {
            throw new IllegalArgumentException(
                    Arrays.toString(addr) + " was not a valid MAC address");
        }
        long longAddr = 0;
        for (byte b : addr) {
            longAddr = (longAddr << 8) + BitUtils.uint8(b);
        }
        return longAddr;
    }
    }


    // Internal conversion function equivalent to longAddrFromByteAddr(byteAddrFromStringAddr(addr))
    // Internal conversion function equivalent to longAddrFromByteAddr(byteAddrFromStringAddr(addr))
@@ -350,50 +326,7 @@ public final class MacAddress implements Parcelable {
     * @hide
     * @hide
     */
     */
    public static @NonNull MacAddress createRandomUnicastAddressWithGoogleBase() {
    public static @NonNull MacAddress createRandomUnicastAddressWithGoogleBase() {
        return createRandomUnicastAddress(BASE_GOOGLE_MAC, new SecureRandom());
        return MacAddressUtils.createRandomUnicastAddress(BASE_GOOGLE_MAC, new SecureRandom());
    }

    /**
     * Returns a generated MAC address whose 46 bits, excluding the locally assigned bit and the
     * unicast bit, are randomly selected.
     *
     * The locally assigned bit is always set to 1. The multicast bit is always set to 0.
     *
     * @return a random locally assigned, unicast MacAddress.
     *
     * @hide
     */
    public static @NonNull MacAddress createRandomUnicastAddress() {
        return createRandomUnicastAddress(null, new SecureRandom());
    }

    /**
     * Returns a randomly generated MAC address using the given Random object and the same
     * OUI values as the given MacAddress.
     *
     * The locally assigned bit is always set to 1. The multicast bit is always set to 0.
     *
     * @param base a base MacAddress whose OUI is used for generating the random address.
     *             If base == null then the OUI will also be randomized.
     * @param r a standard Java Random object used for generating the random address.
     * @return a random locally assigned MacAddress.
     *
     * @hide
     */
    public static @NonNull MacAddress createRandomUnicastAddress(MacAddress base, Random r) {
        long addr;
        if (base == null) {
            addr = r.nextLong() & VALID_LONG_MASK;
        } else {
            addr = (base.mAddr & OUI_MASK) | (NIC_MASK & r.nextLong());
        }
        addr |= LOCALLY_ASSIGNED_MASK;
        addr &= ~MULTICAST_MASK;
        MacAddress mac = new MacAddress(addr);
        if (mac.equals(DEFAULT_MAC_ADDRESS)) {
            return createRandomUnicastAddress(base, r);
        }
        return mac;
    }
    }


    // Convenience function for working around the lack of byte literals.
    // Convenience function for working around the lack of byte literals.
+0 −10
Original line number Original line Diff line number Diff line
@@ -31,7 +31,6 @@ import android.util.Pair;
import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.math.BigInteger;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.net.UnknownHostException;
@@ -312,15 +311,6 @@ public class NetworkUtils {
        return new Pair<InetAddress, Integer>(address, prefixLength);
        return new Pair<InetAddress, Integer>(address, prefixLength);
    }
    }


    /**
     * Check if IP address type is consistent between two InetAddress.
     * @return true if both are the same type.  False otherwise.
     */
    public static boolean addressTypeMatches(InetAddress left, InetAddress right) {
        return (((left instanceof Inet4Address) && (right instanceof Inet4Address)) ||
                ((left instanceof Inet6Address) && (right instanceof Inet6Address)));
    }

    /**
    /**
     * Convert a 32 char hex string into a Inet6Address.
     * Convert a 32 char hex string into a Inet6Address.
     * throws a runtime exception if the string isn't 32 chars, isn't hex or can't be
     * throws a runtime exception if the string isn't 32 chars, isn't hex or can't be
+2 −15
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.TestApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
import android.net.util.NetUtils;
import android.os.Build;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
@@ -441,21 +442,7 @@ public final class RouteInfo implements Parcelable {
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    @Nullable
    @Nullable
    public static RouteInfo selectBestRoute(Collection<RouteInfo> routes, InetAddress dest) {
    public static RouteInfo selectBestRoute(Collection<RouteInfo> routes, InetAddress dest) {
        if ((routes == null) || (dest == null)) return null;
        return NetUtils.selectBestRoute(routes, dest);

        RouteInfo bestRoute = null;
        // pick a longest prefix match under same address type
        for (RouteInfo route : routes) {
            if (NetworkUtils.addressTypeMatches(route.mDestination.getAddress(), dest)) {
                if ((bestRoute != null) &&
                        (bestRoute.mDestination.getPrefixLength() >=
                        route.mDestination.getPrefixLength())) {
                    continue;
                }
                if (route.matches(dest)) bestRoute = route;
            }
        }
        return bestRoute;
    }
    }


    /**
    /**
+1 −1
Original line number Original line Diff line number Diff line
@@ -79,7 +79,6 @@ import android.net.InetAddresses;
import android.net.IpMemoryStore;
import android.net.IpMemoryStore;
import android.net.IpPrefix;
import android.net.IpPrefix;
import android.net.LinkProperties;
import android.net.LinkProperties;
import android.net.LinkProperties.CompareResult;
import android.net.MatchAllNetworkSpecifier;
import android.net.MatchAllNetworkSpecifier;
import android.net.NattSocketKeepalive;
import android.net.NattSocketKeepalive;
import android.net.Network;
import android.net.Network;
@@ -114,6 +113,7 @@ import android.net.metrics.IpConnectivityLog;
import android.net.metrics.NetworkEvent;
import android.net.metrics.NetworkEvent;
import android.net.netlink.InetDiagMessage;
import android.net.netlink.InetDiagMessage;
import android.net.shared.PrivateDnsConfig;
import android.net.shared.PrivateDnsConfig;
import android.net.util.LinkPropertiesUtils.CompareResult;
import android.net.util.MultinetworkPolicyTracker;
import android.net.util.MultinetworkPolicyTracker;
import android.net.util.NetdService;
import android.net.util.NetdService;
import android.os.Binder;
import android.os.Binder;
Loading