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

Commit bf8bf735 authored by Ken Chen's avatar Ken Chen
Browse files

Add testVpnTypesEqual to verify consistency

VPN types are defined in both VpnManager.java and NativeVpnType.aidl.
The definitions on both sides should match (except TYPE_VPN_NONE).

VpnManager.java:
TYPE_VPN_NONE = -1
TYPE_VPN_SERVICE = 1
TYPE_VPN_PLATFORM = 2
TYPE_VPN_LEGACY = 3
TYPE_VPN_OEM = 4

NativeVpnType.aidl:
SERVICE = 1
PLATFORM = 2
LEGACY = 3
OEM = 4

Bug: N/A
Test: atest android.net.VpnManagerTest#testVpnTypesEqual
Change-Id: Ie618e227d861100c5318da696140e486af1093a0
parent f9183a71
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -58,7 +58,6 @@ import java.util.List;
 * @see Ikev2VpnProfile
 */
public class VpnManager {
    // TODO: add a unit test to ensure that TYPE_VPN_xxx matches android.net.NativeVpnType.
    /** Type representing a lack of VPN @hide */
    @SystemApi(client = MODULE_LIBRARIES)
    public static final int TYPE_VPN_NONE = -1;
+16 −0
Original line number Diff line number Diff line
@@ -28,11 +28,13 @@ import static org.mockito.Mockito.when;
import android.content.ComponentName;
import android.content.Intent;
import android.test.mock.MockContext;
import android.util.SparseArray;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.internal.net.VpnProfile;
import com.android.internal.util.MessageUtils;

import org.junit.Before;
import org.junit.Test;
@@ -119,4 +121,18 @@ public class VpnManagerTest {
                .setAuthPsk(PSK_BYTES)
                .build();
    }

    @Test
    public void testVpnTypesEqual() throws Exception {
        SparseArray<String> vmVpnTypes = MessageUtils.findMessageNames(
                new Class[] { VpnManager.class }, new String[]{ "TYPE_VPN_" });
        SparseArray<String> nativeVpnType = MessageUtils.findMessageNames(
                new Class[] { NativeVpnType.class }, new String[]{ "" });

        // TYPE_VPN_NONE = -1 is only defined in VpnManager.
        assertEquals(vmVpnTypes.size() - 1, nativeVpnType.size());
        for (int i = VpnManager.TYPE_VPN_SERVICE; i < vmVpnTypes.size(); i++) {
            assertEquals(vmVpnTypes.get(i), "TYPE_VPN_" + nativeVpnType.get(i));
        }
    }
}