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

Commit c041bf13 authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by Automerger Merge Worker
Browse files

Merge "Add a ShimUtils.isAtLeastR() and use it in tests." into rvc-dev am: 7dd51c66

Change-Id: Ibb9e6eeabeaca06b139e9a3e5038204fd456389f
parents 3a9c1baf 7dd51c66
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -42,4 +42,11 @@ public final class ShimUtils {
                + ("REL".equals(Build.VERSION.CODENAME) ? 0 : 1);
                + ("REL".equals(Build.VERSION.CODENAME) ? 0 : 1);
        return devApiLevel > apiLevel;
        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 Original line Diff line number Diff line
@@ -653,7 +653,7 @@ public class IpClientIntegrationTest {
    }
    }


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


        // Ensure that the URL was set as expected in the callbacks.
        // 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.
        // 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());
        verify(mCb).onLinkPropertiesChange(captor.capture());
        assertTrue(captor.getAllValues().stream().anyMatch(
        assertTrue(captor.getAllValues().stream().anyMatch(
                lp -> Objects.equals(expectedUrl, lp.getCaptivePortalApiUrl())));
                lp -> Objects.equals(expectedUrl, lp.getCaptivePortalApiUrl())));
+2 −3
Original line number Original line Diff line number Diff line
@@ -37,7 +37,6 @@ import android.app.Instrumentation;
import android.content.Context;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager;
import android.net.netlink.StructNlMsgHdr;
import android.net.netlink.StructNlMsgHdr;
import android.os.Build;
import android.os.Process;
import android.os.Process;
import android.system.Os;
import android.system.Os;


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


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


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