diff --git a/Tethering/src/android/net/ip/IpServer.java b/Tethering/src/android/net/ip/IpServer.java index a8c840803b..5ec4d15518 100644 --- a/Tethering/src/android/net/ip/IpServer.java +++ b/Tethering/src/android/net/ip/IpServer.java @@ -59,6 +59,7 @@ import android.os.Handler; import android.os.Message; import android.os.RemoteException; import android.os.ServiceSpecificException; +import android.util.ArraySet; import android.util.Log; import android.util.SparseArray; @@ -900,7 +901,7 @@ public class IpServer extends StateMachineShim { } private void configureLocalIPv6Routes( - HashSet deprecatedPrefixes, HashSet newPrefixes) { + ArraySet deprecatedPrefixes, ArraySet newPrefixes) { // [1] Remove the routes that are deprecated. if (!deprecatedPrefixes.isEmpty()) { removeRoutesFromLocalNetwork(getLocalRoutesFor(mIfaceName, deprecatedPrefixes)); @@ -908,7 +909,7 @@ public class IpServer extends StateMachineShim { // [2] Add only the routes that have not previously been added. if (newPrefixes != null && !newPrefixes.isEmpty()) { - HashSet addedPrefixes = (HashSet) newPrefixes.clone(); + ArraySet addedPrefixes = new ArraySet(newPrefixes); if (mLastRaParams != null) { addedPrefixes.removeAll(mLastRaParams.prefixes); } @@ -920,7 +921,7 @@ public class IpServer extends StateMachineShim { } private void configureLocalIPv6Dns( - HashSet deprecatedDnses, HashSet newDnses) { + ArraySet deprecatedDnses, ArraySet newDnses) { // TODO: Is this really necessary? Can we not fail earlier if INetd cannot be located? if (mNetd == null) { if (newDnses != null) newDnses.clear(); @@ -941,7 +942,7 @@ public class IpServer extends StateMachineShim { // [2] Add only the local DNS IP addresses that have not previously been added. if (newDnses != null && !newDnses.isEmpty()) { - final HashSet addedDnses = (HashSet) newDnses.clone(); + final ArraySet addedDnses = new ArraySet(newDnses); if (mLastRaParams != null) { addedDnses.removeAll(mLastRaParams.dnses); } @@ -1548,7 +1549,7 @@ public class IpServer extends StateMachineShim { // Accumulate routes representing "prefixes to be assigned to the local // interface", for subsequent modification of local_network routing. private static ArrayList getLocalRoutesFor( - String ifname, HashSet prefixes) { + String ifname, ArraySet prefixes) { final ArrayList localRoutes = new ArrayList(); for (IpPrefix ipp : prefixes) { localRoutes.add(new RouteInfo(ipp, null, ifname, RTN_UNICAST)); @@ -1579,8 +1580,8 @@ public class IpServer extends StateMachineShim { /** Get IPv6 prefixes from LinkProperties */ @NonNull @VisibleForTesting - static HashSet getTetherableIpv6Prefixes(@NonNull Collection addrs) { - final HashSet prefixes = new HashSet<>(); + static ArraySet getTetherableIpv6Prefixes(@NonNull Collection addrs) { + final ArraySet prefixes = new ArraySet<>(); for (LinkAddress linkAddr : addrs) { if (linkAddr.getPrefixLength() != RFC7421_PREFIX_LENGTH) continue; prefixes.add(new IpPrefix(linkAddr.getAddress(), RFC7421_PREFIX_LENGTH)); @@ -1589,7 +1590,7 @@ public class IpServer extends StateMachineShim { } @NonNull - private HashSet getTetherableIpv6Prefixes(@NonNull LinkProperties lp) { + private ArraySet getTetherableIpv6Prefixes(@NonNull LinkProperties lp) { return getTetherableIpv6Prefixes(lp.getLinkAddresses()); } } diff --git a/Tethering/src/android/net/ip/RouterAdvertisementDaemon.java b/Tethering/src/android/net/ip/RouterAdvertisementDaemon.java index 50d6c4b18d..d848ea8a63 100644 --- a/Tethering/src/android/net/ip/RouterAdvertisementDaemon.java +++ b/Tethering/src/android/net/ip/RouterAdvertisementDaemon.java @@ -41,6 +41,7 @@ import android.net.util.SocketUtils; import android.system.ErrnoException; import android.system.Os; import android.system.StructTimeval; +import android.util.ArraySet; import android.util.Log; import com.android.internal.annotations.GuardedBy; @@ -134,23 +135,23 @@ public class RouterAdvertisementDaemon { public boolean hasDefaultRoute; public byte hopLimit; public int mtu; - public HashSet prefixes; - public HashSet dnses; + public ArraySet prefixes; + public ArraySet dnses; public RaParams() { hasDefaultRoute = false; hopLimit = DEFAULT_HOPLIMIT; mtu = IPV6_MIN_MTU; - prefixes = new HashSet(); - dnses = new HashSet(); + prefixes = new ArraySet(); + dnses = new ArraySet(); } public RaParams(RaParams other) { hasDefaultRoute = other.hasDefaultRoute; hopLimit = other.hopLimit; mtu = other.mtu; - prefixes = (HashSet) other.prefixes.clone(); - dnses = (HashSet) other.dnses.clone(); + prefixes = new ArraySet(other.prefixes); + dnses = new ArraySet(other.dnses); } /** diff --git a/Tethering/tests/privileged/src/android/net/ip/RouterAdvertisementDaemonTest.java b/Tethering/tests/privileged/src/android/net/ip/RouterAdvertisementDaemonTest.java index dac5b63fe2..90ceaa1c85 100644 --- a/Tethering/tests/privileged/src/android/net/ip/RouterAdvertisementDaemonTest.java +++ b/Tethering/tests/privileged/src/android/net/ip/RouterAdvertisementDaemonTest.java @@ -47,6 +47,7 @@ import android.os.IBinder; import android.os.Looper; import android.os.RemoteException; import android.os.ServiceSpecificException; +import android.util.ArraySet; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; @@ -77,7 +78,6 @@ import org.mockito.MockitoAnnotations; import java.net.Inet6Address; import java.net.InetAddress; import java.nio.ByteBuffer; -import java.util.HashSet; @RunWith(AndroidJUnit4.class) @SmallTest @@ -236,7 +236,7 @@ public final class RouterAdvertisementDaemonTest { final RdnssOption rdnss = Struct.parse(RdnssOption.class, RdnssBuf); final String msg = rdnss.lifetime > 0 ? "Unknown dns" : "Unknown deprecated dns"; - final HashSet dnses = + final ArraySet dnses = rdnss.lifetime > 0 ? mNewParams.dnses : mOldParams.dnses; assertNotNull(msg, dnses);