Add ApnDataInit.

Fix: 298906796
Test: Unit Test
Change-Id: Ibf9e12e4f9c4ee033ad6dc2ca1f2267bf1f21912
This commit is contained in:
Charlotte Lu
2023-10-08 14:23:37 +08:00
parent 4188a571aa
commit 93fb316f01
6 changed files with 445 additions and 25 deletions

View File

@@ -256,9 +256,9 @@ class ApnEditPageProviderTest {
.performScrollToNode(hasText(passwordTitle, true))
composeTestRule.onNodeWithText(passwordTitle, true).assertIsDisplayed()
}
private companion object {
const val NETWORK_TYPE_UNSPECIFIED = "Unspecified"
const val NETWORK_TYPE_LTE = "LTE"
}
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.network.apn
import android.content.ContentResolver
import android.content.Context
import android.database.MatrixCursor
import android.net.Uri
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
@RunWith(AndroidJUnit4::class)
class ApnRepositoryTest {
private val context: Context = ApplicationProvider.getApplicationContext()
private val mContentResolver = mock<ContentResolver> {}
private val uri = mock<Uri> {}
@Test
fun getApnDataFromUri() {
// mock out resources and the feature provider
val cursor = MatrixCursor(sProjection)
cursor.addRow(
arrayOf<Any?>(
0, "name", "apn", "proxy", "port",
"userName", "server", "passWord", "mmsc", "mcc", "mnc", "numeric",
"mmsProxy", "mmsPort", 0, "apnType", "apnProtocol", 0,
0, "apnRoaming", "mvnoType", "mvnoValue", 0, 1, 0
)
)
val context = Mockito.spy(context)
whenever(context.contentResolver).thenReturn(mContentResolver)
whenever(mContentResolver.query(uri, sProjection, null, null, null)).thenReturn(cursor)
assert(getApnDataFromUri(uri, context).name == "name")
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.network.apn
import android.os.PersistableBundle
import android.telephony.CarrierConfigManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
@RunWith(AndroidJUnit4::class)
class ApnStatusTest {
private val subId = 1
private val configManager = mock<CarrierConfigManager> {
val p = PersistableBundle()
p.putBoolean(CarrierConfigManager.KEY_ALLOW_ADDING_APNS_BOOL, true)
on {
getConfigForSubId(
subId,
CarrierConfigManager.KEY_READ_ONLY_APN_TYPES_STRING_ARRAY,
CarrierConfigManager.KEY_READ_ONLY_APN_FIELDS_STRING_ARRAY,
CarrierConfigManager.KEY_APN_SETTINGS_DEFAULT_APN_TYPES_STRING_ARRAY,
CarrierConfigManager.Apn.KEY_SETTINGS_DEFAULT_PROTOCOL_STRING,
CarrierConfigManager.Apn.KEY_SETTINGS_DEFAULT_ROAMING_PROTOCOL_STRING,
CarrierConfigManager.KEY_ALLOW_ADDING_APNS_BOOL
)
} doReturn p
}
@Test
fun getCarrierCustomizedConfig_test() {
assert(getCarrierCustomizedConfig(configManager, subId).isAddApnAllowed)
}
}