Skip to content
Snippets Groups Projects
Commit 86b8bf03 authored by Yuyang Huang's avatar Yuyang Huang Committed by Gerrit Code Review
Browse files

Merge "Replace HashSet with ArraySet in RaParams" into main

parents 52113d6a ff1400be
No related branches found
No related tags found
No related merge requests found
......@@ -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<IpPrefix> deprecatedPrefixes, HashSet<IpPrefix> newPrefixes) {
ArraySet<IpPrefix> deprecatedPrefixes, ArraySet<IpPrefix> 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<IpPrefix> addedPrefixes = (HashSet) newPrefixes.clone();
ArraySet<IpPrefix> addedPrefixes = new ArraySet<IpPrefix>(newPrefixes);
if (mLastRaParams != null) {
addedPrefixes.removeAll(mLastRaParams.prefixes);
}
......@@ -920,7 +921,7 @@ public class IpServer extends StateMachineShim {
}
private void configureLocalIPv6Dns(
HashSet<Inet6Address> deprecatedDnses, HashSet<Inet6Address> newDnses) {
ArraySet<Inet6Address> deprecatedDnses, ArraySet<Inet6Address> 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<Inet6Address> addedDnses = (HashSet) newDnses.clone();
final ArraySet<Inet6Address> addedDnses = new ArraySet<Inet6Address>(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<RouteInfo> getLocalRoutesFor(
String ifname, HashSet<IpPrefix> prefixes) {
String ifname, ArraySet<IpPrefix> prefixes) {
final ArrayList<RouteInfo> localRoutes = new ArrayList<RouteInfo>();
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<IpPrefix> getTetherableIpv6Prefixes(@NonNull Collection<LinkAddress> addrs) {
final HashSet<IpPrefix> prefixes = new HashSet<>();
static ArraySet<IpPrefix> getTetherableIpv6Prefixes(@NonNull Collection<LinkAddress> addrs) {
final ArraySet<IpPrefix> 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<IpPrefix> getTetherableIpv6Prefixes(@NonNull LinkProperties lp) {
private ArraySet<IpPrefix> getTetherableIpv6Prefixes(@NonNull LinkProperties lp) {
return getTetherableIpv6Prefixes(lp.getLinkAddresses());
}
}
......@@ -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<IpPrefix> prefixes;
public HashSet<Inet6Address> dnses;
public ArraySet<IpPrefix> prefixes;
public ArraySet<Inet6Address> dnses;
public RaParams() {
hasDefaultRoute = false;
hopLimit = DEFAULT_HOPLIMIT;
mtu = IPV6_MIN_MTU;
prefixes = new HashSet<IpPrefix>();
dnses = new HashSet<Inet6Address>();
prefixes = new ArraySet<IpPrefix>();
dnses = new ArraySet<Inet6Address>();
}
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<IpPrefix>(other.prefixes);
dnses = new ArraySet<Inet6Address>(other.dnses);
}
/**
......
......@@ -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<Inet6Address> dnses =
final ArraySet<Inet6Address> dnses =
rdnss.lifetime > 0 ? mNewParams.dnses : mOldParams.dnses;
assertNotNull(msg, dnses);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment