1 /* 2 * Copyright (C) 2023 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 @file:Suppress("DEPRECATION") // This file tests a bunch of deprecated methods : don't warn about it 18 19 package com.android.server 20 21 import android.net.ConnectivityManager 22 import android.os.Build 23 import androidx.test.filters.SmallTest 24 import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo 25 import com.android.testutils.DevSdkIgnoreRunner 26 import kotlin.test.assertFalse 27 import kotlin.test.assertTrue 28 import org.junit.Test 29 import org.junit.runner.RunWith 30 31 @DevSdkIgnoreRunner.MonitorThreadLeak 32 @RunWith(DevSdkIgnoreRunner::class) 33 @SmallTest 34 @IgnoreUpTo(Build.VERSION_CODES.R) 35 class CSBasicMethodsTest : CSTest() { 36 @Test testNetworkTypesnull37 fun testNetworkTypes() { 38 // Ensure that mocks for the networkAttributes config variable work as expected. If they 39 // don't, then tests that depend on CONNECTIVITY_ACTION broadcasts for these network types 40 // will fail. Failing here is much easier to debug. 41 assertTrue(cm.isNetworkSupported(ConnectivityManager.TYPE_WIFI)) 42 assertTrue(cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) 43 assertTrue(cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE_MMS)) 44 assertTrue(cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE_FOTA)) 45 assertFalse(cm.isNetworkSupported(ConnectivityManager.TYPE_PROXY)) 46 47 // Check that TYPE_ETHERNET is supported. Unlike the asserts above, which only validate our 48 // mocks, this assert exercises the ConnectivityService code path that ensures that 49 // TYPE_ETHERNET is supported if the ethernet service is running. 50 assertTrue(cm.isNetworkSupported(ConnectivityManager.TYPE_ETHERNET)) 51 } 52 } 53