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

Commit 241b2c6c authored by Lucas Lin's avatar Lucas Lin Committed by Automerger Merge Worker
Browse files

Merge "Add version check to prevent test fail on Android Q" into rvc-dev am: 3d02325f

Change-Id: I817fdcddbcd48eb39771c23bce815328dd24ff02
parents d7d494f1 3d02325f
Loading
Loading
Loading
Loading
+25 −5
Original line number Diff line number Diff line
@@ -48,9 +48,11 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import android.os.Build;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.ArraySet;

import androidx.core.os.BuildCompat;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
@@ -64,6 +66,13 @@ public class NetworkCapabilitiesTest {
    private static final String TEST_SSID = "TEST_SSID";
    private static final String DIFFERENT_TEST_SSID = "DIFFERENT_TEST_SSID";

    private boolean isAtLeastR() {
        // BuildCompat.isAtLeastR() is used to check the Android version before releasing Android R.
        // Build.VERSION.SDK_INT > Build.VERSION_CODES.Q is used to check the Android version after
        // releasing Android R.
        return BuildCompat.isAtLeastR() || Build.VERSION.SDK_INT > Build.VERSION_CODES.Q;
    }

    @Test
    public void testMaybeMarkCapabilitiesRestricted() {
        // verify EIMS is restricted
@@ -269,25 +278,36 @@ public class NetworkCapabilitiesTest {
            .setUids(uids)
            .addCapability(NET_CAPABILITY_EIMS)
            .addCapability(NET_CAPABILITY_NOT_METERED);
        if (isAtLeastR()) {
            netCap.setOwnerUid(123);
        }
        assertParcelingIsLossless(netCap);
        netCap.setSSID(TEST_SSID);
        assertParcelSane(netCap, 15);
        testParcelSane(netCap);
    }

    @Test
    public void testParcelNetworkCapabilitiesWithRequestorUidAndPackageName() {
        final NetworkCapabilities netCap = new NetworkCapabilities()
                .addCapability(NET_CAPABILITY_INTERNET)
                .setRequestorUid(9304)
                .setRequestorPackageName("com.android.test")
                .addCapability(NET_CAPABILITY_EIMS)
                .addCapability(NET_CAPABILITY_NOT_METERED);
        if (isAtLeastR()) {
            netCap.setRequestorPackageName("com.android.test");
            netCap.setRequestorUid(9304);
        }
        assertParcelingIsLossless(netCap);
        netCap.setSSID(TEST_SSID);
        assertParcelSane(netCap, 15);
        testParcelSane(netCap);
    }

    private void testParcelSane(NetworkCapabilities cap) {
        if (isAtLeastR()) {
            assertParcelSane(cap, 15);
        } else {
            assertParcelSane(cap, 11);
        }
    }

    @Test
    public void testOemPaid() {