1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.net 18 19 import androidx.test.filters.SmallTest 20 import androidx.test.runner.AndroidJUnit4 21 import com.android.modules.utils.build.SdkLevel.isAtLeastS 22 import com.android.modules.utils.build.SdkLevel.isAtLeastT 23 import com.android.testutils.ConnectivityModuleTest 24 import com.android.testutils.assertParcelingIsLossless 25 import org.junit.Assert.assertEquals 26 import org.junit.Assert.assertFalse 27 import org.junit.Assert.assertTrue 28 import org.junit.Test 29 import org.junit.runner.RunWith 30 31 @RunWith(AndroidJUnit4::class) 32 @SmallTest 33 @ConnectivityModuleTest 34 class NetworkAgentConfigTest { 35 @Test testParcelNetworkAgentConfignull36 fun testParcelNetworkAgentConfig() { 37 val config = NetworkAgentConfig.Builder().apply { 38 setExplicitlySelected(true) 39 setLegacyType(ConnectivityManager.TYPE_ETHERNET) 40 setSubscriberId("MySubId") 41 setPartialConnectivityAcceptable(false) 42 setUnvalidatedConnectivityAcceptable(true) 43 if (isAtLeastS()) { 44 setBypassableVpn(true) 45 } 46 if (isAtLeastT()) { 47 setLocalRoutesExcludedForVpn(true) 48 setVpnRequiresValidation(true) 49 } 50 }.build() 51 assertParcelingIsLossless(config) 52 } 53 54 @Test testBuildernull55 fun testBuilder() { 56 val testExtraInfo = "mylegacyExtraInfo" 57 val config = NetworkAgentConfig.Builder().apply { 58 setExplicitlySelected(true) 59 setLegacyType(ConnectivityManager.TYPE_ETHERNET) 60 setSubscriberId("MySubId") 61 setPartialConnectivityAcceptable(false) 62 setUnvalidatedConnectivityAcceptable(true) 63 setLegacyTypeName("TEST_NETWORK") 64 if (isAtLeastS()) { 65 setLegacyExtraInfo(testExtraInfo) 66 setNat64DetectionEnabled(false) 67 setProvisioningNotificationEnabled(false) 68 setBypassableVpn(true) 69 } 70 if (isAtLeastT()) { 71 setLocalRoutesExcludedForVpn(true) 72 setVpnRequiresValidation(true) 73 } 74 }.build() 75 76 assertTrue(config.isExplicitlySelected()) 77 assertEquals(ConnectivityManager.TYPE_ETHERNET, config.getLegacyType()) 78 assertEquals("MySubId", config.getSubscriberId()) 79 assertFalse(config.isPartialConnectivityAcceptable()) 80 assertTrue(config.isUnvalidatedConnectivityAcceptable()) 81 assertEquals("TEST_NETWORK", config.getLegacyTypeName()) 82 if (isAtLeastT()) { 83 assertTrue(config.areLocalRoutesExcludedForVpn()) 84 assertTrue(config.isVpnValidationRequired()) 85 } 86 if (isAtLeastS()) { 87 assertEquals(testExtraInfo, config.getLegacyExtraInfo()) 88 assertFalse(config.isNat64DetectionEnabled()) 89 assertFalse(config.isProvisioningNotificationEnabled()) 90 assertTrue(config.isBypassableVpn()) 91 } else { 92 assertTrue(config.isNat64DetectionEnabled()) 93 assertTrue(config.isProvisioningNotificationEnabled()) 94 } 95 } 96 } 97