Filter out excluded routes in LinkProperties
Gate presence of excluded routes in LinkProperties on target sdk T. Bug: 186082280 Test: atest LinkPropertiesTest Change-Id: If8fdb468a0a4968c5f2a878b7aacfeb4f7d9a9e5
This commit is contained in:
@@ -20,6 +20,7 @@ import static android.net.RouteInfo.RTN_THROW;
|
||||
import static android.net.RouteInfo.RTN_UNICAST;
|
||||
import static android.net.RouteInfo.RTN_UNREACHABLE;
|
||||
|
||||
import static com.android.testutils.DevSdkIgnoreRuleKt.SC_V2;
|
||||
import static com.android.testutils.ParcelUtils.assertParcelingIsLossless;
|
||||
import static com.android.testutils.ParcelUtils.parcelingRoundTrip;
|
||||
|
||||
@@ -30,6 +31,7 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import android.compat.testing.PlatformCompatChangeRule;
|
||||
import android.net.LinkProperties.ProvisioningChange;
|
||||
import android.os.Build;
|
||||
import android.system.OsConstants;
|
||||
@@ -45,6 +47,9 @@ import com.android.testutils.DevSdkIgnoreRule;
|
||||
import com.android.testutils.DevSdkIgnoreRule.IgnoreAfter;
|
||||
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
|
||||
|
||||
import libcore.junit.util.compat.CoreCompatChangeRule.DisableCompatChanges;
|
||||
import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -65,6 +70,9 @@ public class LinkPropertiesTest {
|
||||
@Rule
|
||||
public final DevSdkIgnoreRule ignoreRule = new DevSdkIgnoreRule();
|
||||
|
||||
@Rule
|
||||
public final PlatformCompatChangeRule compatChangeRule = new PlatformCompatChangeRule();
|
||||
|
||||
private static final InetAddress ADDRV4 = address("75.208.6.1");
|
||||
private static final InetAddress ADDRV6 = address("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
|
||||
private static final InetAddress DNS1 = address("75.208.7.1");
|
||||
@@ -1254,6 +1262,7 @@ public class LinkPropertiesTest {
|
||||
}
|
||||
|
||||
@Test @IgnoreUpTo(Build.VERSION_CODES.Q)
|
||||
@EnableCompatChanges({LinkProperties.EXCLUDED_ROUTES})
|
||||
public void testRouteAddWithSameKey() throws Exception {
|
||||
LinkProperties lp = new LinkProperties();
|
||||
lp.setInterfaceName("wlan0");
|
||||
@@ -1268,4 +1277,36 @@ public class LinkPropertiesTest {
|
||||
lp.addRoute(new RouteInfo(v4, address("192.0.2.1"), "wlan0", RTN_THROW, 1460));
|
||||
assertEquals(2, lp.getRoutes().size());
|
||||
}
|
||||
|
||||
@Test @IgnoreUpTo(SC_V2)
|
||||
@EnableCompatChanges({LinkProperties.EXCLUDED_ROUTES})
|
||||
public void testExcludedRoutesEnabled() {
|
||||
final LinkProperties lp = new LinkProperties();
|
||||
assertEquals(0, lp.getRoutes().size());
|
||||
|
||||
lp.addRoute(new RouteInfo(new IpPrefix(ADDRV4, 0), RTN_UNREACHABLE));
|
||||
assertEquals(1, lp.getRoutes().size());
|
||||
|
||||
lp.addRoute(new RouteInfo(new IpPrefix(ADDRV6, 0), RTN_THROW));
|
||||
assertEquals(2, lp.getRoutes().size());
|
||||
|
||||
lp.addRoute(new RouteInfo(GATEWAY1));
|
||||
assertEquals(3, lp.getRoutes().size());
|
||||
}
|
||||
|
||||
@Test @IgnoreUpTo(SC_V2)
|
||||
@DisableCompatChanges({LinkProperties.EXCLUDED_ROUTES})
|
||||
public void testExcludedRoutesDisabled() {
|
||||
final LinkProperties lp = new LinkProperties();
|
||||
assertEquals(0, lp.getRoutes().size());
|
||||
|
||||
lp.addRoute(new RouteInfo(new IpPrefix(ADDRV4, 0), RTN_UNREACHABLE));
|
||||
assertEquals(0, lp.getRoutes().size());
|
||||
|
||||
lp.addRoute(new RouteInfo(new IpPrefix(ADDRV6, 5), RTN_THROW));
|
||||
assertEquals(0, lp.getRoutes().size());
|
||||
|
||||
lp.addRoute(new RouteInfo(new IpPrefix(ADDRV6, 2), RTN_UNICAST));
|
||||
assertEquals(1, lp.getRoutes().size());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user