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

Commit 0d08b449 authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

Add a ShimUtils.isAtLeastR() and use it in tests.

Bug: 152723363
Test: atest NetworkStackTests NetworkStackIntegrationTests
Test: atest NetworkStackNextTests NetworkStackNextIntegrationTests
Change-Id: I88c33a48a627008f5ad7f880bd09c568866b1c5b
parent b2ff3e8c
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -42,4 +42,11 @@ public final class ShimUtils {
                + ("REL".equals(Build.VERSION.CODENAME) ? 0 : 1);
        return devApiLevel > apiLevel;
    }

    /**
     * Check whether the device supports in-development or final R networking APIs.
     */
    public static boolean isAtLeastR() {
        return isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -654,7 +654,7 @@ public class IpClientIntegrationTest {
    }

    private void assertNoHostname(String hostname) {
        if (ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) {
        if (ShimUtils.isAtLeastR()) {
            assertNull(hostname);
        } else {
            // Until Q, if no hostname is set, the device falls back to the hostname set via
@@ -1809,7 +1809,7 @@ public class IpClientIntegrationTest {

        // Ensure that the URL was set as expected in the callbacks.
        // Can't verify the URL up to Q as there is no such attribute in LinkProperties.
        if (!ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) return;
        if (!ShimUtils.isAtLeastR()) return;
        verify(mCb).onLinkPropertiesChange(captor.capture());
        assertTrue(captor.getAllValues().stream().anyMatch(
                lp -> Objects.equals(expectedUrl, lp.getCaptivePortalApiUrl())));
+2 −3
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ import android.app.Instrumentation;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.netlink.StructNlMsgHdr;
import android.os.Build;
import android.os.Process;
import android.system.Os;

@@ -196,7 +195,7 @@ public class InetDiagSocketTest {
    @Test
    public void testGetConnectionOwnerUid() throws Exception {
        // Skip the test for API <= Q, as b/141603906 this was only fixed in Q-QPR2
        assumeTrue(ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q));
        assumeTrue(ShimUtils.isAtLeastR());
        checkGetConnectionOwnerUid("::", null);
        checkGetConnectionOwnerUid("::", "::");
        checkGetConnectionOwnerUid("0.0.0.0", null);
@@ -211,7 +210,7 @@ public class InetDiagSocketTest {
    @Test
    public void testB141603906() throws Exception {
        // Skip the test for API <= Q, as b/141603906 this was only fixed in Q-QPR2
        assumeTrue(ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q));
        assumeTrue(ShimUtils.isAtLeastR());
        final InetSocketAddress src = new InetSocketAddress(0);
        final InetSocketAddress dst = new InetSocketAddress(0);
        final int numThreads = 8;
+4 −4
Original line number Diff line number Diff line
@@ -795,7 +795,7 @@ public class NetworkMonitorTest {
    private static CellIdentityGsm makeCellIdentityGsm(int lac, int cid, int arfcn, int bsic,
            String mccStr, String mncStr, String alphal, String alphas)
            throws ReflectiveOperationException {
        if (ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) {
        if (ShimUtils.isAtLeastR()) {
            return new CellIdentityGsm(lac, cid, arfcn, bsic, mccStr, mncStr, alphal, alphas,
                    Collections.emptyList() /* additionalPlmns */);
        } else {
@@ -810,7 +810,7 @@ public class NetworkMonitorTest {
    private static CellIdentityLte makeCellIdentityLte(int ci, int pci, int tac, int earfcn,
            int bandwidth, String mccStr, String mncStr, String alphal, String alphas)
            throws ReflectiveOperationException {
        if (ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) {
        if (ShimUtils.isAtLeastR()) {
            return new CellIdentityLte(ci, pci, tac, earfcn, new int[] {} /* bands */,
                    bandwidth, mccStr, mncStr, alphal, alphas,
                    Collections.emptyList() /* additionalPlmns */, null /* csgInfo */);
@@ -1707,13 +1707,13 @@ public class NetworkMonitorTest {

    @Test
    public void testDismissPortalInValidatedNetworkEnabledOsSupported() throws Exception {
        assumeTrue(ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q));
        assumeTrue(ShimUtils.isAtLeastR());
        testDismissPortalInValidatedNetworkEnabled(TEST_LOGIN_URL);
    }

    @Test
    public void testDismissPortalInValidatedNetworkEnabledOsNotSupported() throws Exception {
        assumeFalse(ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q));
        assumeFalse(ShimUtils.isAtLeastR());
        testDismissPortalInValidatedNetworkEnabled(TEST_HTTP_URL);
    }