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

Commit 12d2de64 authored by Rubin Xu's avatar Rubin Xu Committed by android-build-merger
Browse files

Merge "Skip unreachable route when estimating VPN destinations" am: 21078b1e

am: e000de90

Change-Id: Ia9301b3bf52b42a742f1f6b3a02499a1404ed3f1
parents 94dbe8d0 e000de90
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -917,6 +917,7 @@ public class Vpn {
        TreeSet<IpPrefix> ipv4Prefixes = new TreeSet<>(prefixLengthComparator);
        TreeSet<IpPrefix> ipv4Prefixes = new TreeSet<>(prefixLengthComparator);
        TreeSet<IpPrefix> ipv6Prefixes = new TreeSet<>(prefixLengthComparator);
        TreeSet<IpPrefix> ipv6Prefixes = new TreeSet<>(prefixLengthComparator);
        for (final RouteInfo route : routes) {
        for (final RouteInfo route : routes) {
            if (route.getType() == RouteInfo.RTN_UNREACHABLE) continue;
            IpPrefix destination = route.getDestination();
            IpPrefix destination = route.getDestination();
            if (destination.isIPv4()) {
            if (destination.isIPv4()) {
                ipv4Prefixes.add(destination);
                ipv4Prefixes.add(destination);
+12 −0
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING;
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
import static android.net.NetworkCapabilities.TRANSPORT_VPN;
import static android.net.NetworkCapabilities.TRANSPORT_VPN;
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
import static android.net.RouteInfo.RTN_UNREACHABLE;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertFalse;
@@ -89,6 +90,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoAnnotations;


import java.net.Inet4Address;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.UnknownHostException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
@@ -775,6 +777,16 @@ public class VpnTest {
        // V4 does not, but V6 has sufficient coverage again
        // V4 does not, but V6 has sufficient coverage again
        lp.addRoute(new RouteInfo(new IpPrefix("::/1")));
        lp.addRoute(new RouteInfo(new IpPrefix("::/1")));
        assertTrue(Vpn.providesRoutesToMostDestinations(lp));
        assertTrue(Vpn.providesRoutesToMostDestinations(lp));

        lp.clear();
        // V4-unreachable route should not be treated as sufficient coverage
        lp.addRoute(new RouteInfo(new IpPrefix(Inet4Address.ANY, 0), RTN_UNREACHABLE));
        assertFalse(Vpn.providesRoutesToMostDestinations(lp));

        lp.clear();
        // V6-unreachable route should not be treated as sufficient coverage
        lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), RTN_UNREACHABLE));
        assertFalse(Vpn.providesRoutesToMostDestinations(lp));
    }
    }


    @Test
    @Test