1 /* 2 * Copyright (C) 2021 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 android.net.NetworkIdentity.OEM_NONE 20 import android.net.NetworkIdentity.OEM_PAID 21 import android.net.NetworkIdentity.OEM_PRIVATE 22 import android.net.NetworkIdentity.getOemBitfield 23 import android.os.Build 24 import com.android.testutils.DevSdkIgnoreRule 25 import com.android.testutils.DevSdkIgnoreRunner 26 import org.junit.Test 27 import org.junit.runner.RunWith 28 import kotlin.test.assertEquals 29 30 @RunWith(DevSdkIgnoreRunner::class) 31 @DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.R) 32 class NetworkIdentityTest { 33 @Test 34 fun testGetOemBitfield() { 35 val oemNone = NetworkCapabilities().apply { 36 setCapability(NetworkCapabilities.NET_CAPABILITY_OEM_PAID, false) 37 setCapability(NetworkCapabilities.NET_CAPABILITY_OEM_PRIVATE, false) 38 } 39 val oemPaid = NetworkCapabilities().apply { 40 setCapability(NetworkCapabilities.NET_CAPABILITY_OEM_PAID, true) 41 setCapability(NetworkCapabilities.NET_CAPABILITY_OEM_PRIVATE, false) 42 } 43 val oemPrivate = NetworkCapabilities().apply { 44 setCapability(NetworkCapabilities.NET_CAPABILITY_OEM_PAID, false) 45 setCapability(NetworkCapabilities.NET_CAPABILITY_OEM_PRIVATE, true) 46 } 47 val oemAll = NetworkCapabilities().apply { 48 setCapability(NetworkCapabilities.NET_CAPABILITY_OEM_PAID, true) 49 setCapability(NetworkCapabilities.NET_CAPABILITY_OEM_PRIVATE, true) 50 } 51 52 assertEquals(getOemBitfield(oemNone), OEM_NONE) 53 assertEquals(getOemBitfield(oemPaid), OEM_PAID) 54 assertEquals(getOemBitfield(oemPrivate), OEM_PRIVATE) 55 assertEquals(getOemBitfield(oemAll), OEM_PAID or OEM_PRIVATE) 56 } 57 } 58