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

Commit d3b9fd33 authored by Erik Kline's avatar Erik Kline
Browse files

(re)define the definition of "provisioned"

Specifically:

    [1] provide a hasIPv4(), and
    [2] a hasIPv6()

each of which requires an IP address, a default route, and
address-family-specific DNS servers to evaluate to true.

Additionally:

    [3] redefine isProvisioned() to return the logical OR
        of [1] and [2] above.

Any external caller can still use any of the has*() methods to
construct its own, different definition of "provisioned".

Bug: 17769720
Change-Id: Ia692fb8508484ff403d3920c94d0e1db4563f807
parent d1cbf9a8
Loading
Loading
Loading
Loading
+27 −6
Original line number Original line Diff line number Diff line
@@ -675,17 +675,38 @@ public final class LinkProperties implements Parcelable {
    }
    }


    /**
    /**
     * Returns true if this link is provisioned for global connectivity. For IPv6, this requires an
     * Returns true if this link is provisioned for global IPv4 connectivity.
     * IP address, default route, and DNS server. For IPv4, this requires only an IPv4 address,
     * This requires an IP address, default route, and DNS server.
     * because WifiStateMachine accepts static configurations that only specify an address but not
     *
     * DNS servers or a default route.
     * @return {@code true} if the link is provisioned, {@code false} otherwise.
     */
    private boolean hasIPv4() {
        return (hasIPv4Address() &&
                hasIPv4DefaultRoute() &&
                hasIPv4DnsServer());
    }

    /**
     * Returns true if this link is provisioned for global IPv6 connectivity.
     * This requires an IP address, default route, and DNS server.
     *
     * @return {@code true} if the link is provisioned, {@code false} otherwise.
     */
    private boolean hasIPv6() {
        return (hasGlobalIPv6Address() &&
                hasIPv6DefaultRoute() &&
                hasIPv6DnsServer());
    }

    /**
     * Returns true if this link is provisioned for global connectivity,
     * for at least one Internet Protocol family.
     *
     *
     * @return {@code true} if the link is provisioned, {@code false} otherwise.
     * @return {@code true} if the link is provisioned, {@code false} otherwise.
     * @hide
     * @hide
     */
     */
    public boolean isProvisioned() {
    public boolean isProvisioned() {
        return (hasIPv4Address() ||
        return (hasIPv4() || hasIPv6());
                (hasGlobalIPv6Address() && hasIPv6DefaultRoute() && hasIPv6DnsServer()));
    }
    }


    /**
    /**
+45 −0
Original line number Original line Diff line number Diff line
@@ -31,8 +31,10 @@ public class LinkPropertiesTest extends TestCase {
            "2001:0db8:85a3:0000:0000:8a2e:0370:7334");
            "2001:0db8:85a3:0000:0000:8a2e:0370:7334");
    private static InetAddress DNS1 = NetworkUtils.numericToInetAddress("75.208.7.1");
    private static InetAddress DNS1 = NetworkUtils.numericToInetAddress("75.208.7.1");
    private static InetAddress DNS2 = NetworkUtils.numericToInetAddress("69.78.7.1");
    private static InetAddress DNS2 = NetworkUtils.numericToInetAddress("69.78.7.1");
    private static InetAddress DNS6 = NetworkUtils.numericToInetAddress("2001:4860:4860::8888");
    private static InetAddress GATEWAY1 = NetworkUtils.numericToInetAddress("75.208.8.1");
    private static InetAddress GATEWAY1 = NetworkUtils.numericToInetAddress("75.208.8.1");
    private static InetAddress GATEWAY2 = NetworkUtils.numericToInetAddress("69.78.8.1");
    private static InetAddress GATEWAY2 = NetworkUtils.numericToInetAddress("69.78.8.1");
    private static InetAddress GATEWAY6 = NetworkUtils.numericToInetAddress("fe80::6:0000:613");
    private static String NAME = "qmi0";
    private static String NAME = "qmi0";
    private static int MTU = 1500;
    private static int MTU = 1500;


@@ -453,4 +455,47 @@ public class LinkPropertiesTest extends TestCase {
        lp2.setLinkAddresses(lp.getLinkAddresses());
        lp2.setLinkAddresses(lp.getLinkAddresses());
        assertTrue(lp.equals(lp));
        assertTrue(lp.equals(lp));
    }
    }

    @SmallTest
    public void testIsProvisioned() {
        LinkProperties lp4 = new LinkProperties();
        assertFalse("v4only:empty", lp4.isProvisioned());
        lp4.addLinkAddress(LINKADDRV4);
        assertFalse("v4only:addr-only", lp4.isProvisioned());
        lp4.addDnsServer(DNS1);
        assertFalse("v4only:addr+dns", lp4.isProvisioned());
        lp4.addRoute(new RouteInfo(GATEWAY1));
        assertTrue("v4only:addr+dns+route", lp4.isProvisioned());

        LinkProperties lp6 = new LinkProperties();
        assertFalse("v6only:empty", lp6.isProvisioned());
        lp6.addLinkAddress(LINKADDRV6LINKLOCAL);
        assertFalse("v6only:fe80-only", lp6.isProvisioned());
        lp6.addDnsServer(DNS6);
        assertFalse("v6only:fe80+dns", lp6.isProvisioned());
        lp6.addRoute(new RouteInfo(GATEWAY6));
        assertFalse("v6only:fe80+dns+route", lp6.isProvisioned());
        lp6.addLinkAddress(LINKADDRV6);
        assertTrue("v6only:fe80+global+dns+route", lp6.isProvisioned());
        lp6.removeLinkAddress(LINKADDRV6LINKLOCAL);
        assertTrue("v6only:global+dns+route", lp6.isProvisioned());

        LinkProperties lp46 = new LinkProperties();
        lp46.addLinkAddress(LINKADDRV4);
        lp46.addLinkAddress(LINKADDRV6);
        lp46.addDnsServer(DNS1);
        lp46.addDnsServer(DNS6);
        assertFalse("dualstack:missing-routes", lp46.isProvisioned());
        lp46.addRoute(new RouteInfo(GATEWAY1));
        assertTrue("dualstack:v4-provisioned", lp46.isProvisioned());
        lp6.addRoute(new RouteInfo(GATEWAY6));
        assertTrue("dualstack:both-provisioned", lp46.isProvisioned());

        // A link with an IPv6 address and default route, but IPv4 DNS server.
        LinkProperties mixed = new LinkProperties();
        mixed.addLinkAddress(LINKADDRV6);
        mixed.addDnsServer(DNS1);
        mixed.addRoute(new RouteInfo(GATEWAY6));
        assertFalse("mixed:addr6+route6+dns4", mixed.isProvisioned());
    }
}
}