Loading src/com/android/settings/network/telephony/VoNrRepository.kt +20 −5 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.settings.network.telephony import android.content.Context import android.telephony.CarrierConfigManager import android.telephony.SubscriptionManager import android.telephony.TelephonyManager import android.util.Log import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow Loading @@ -37,6 +38,7 @@ class VoNrRepository( fun isVoNrAvailable(subId: Int): Boolean { if (!nrRepository.isNrAvailable(subId)) return false data class Config(val isVoNrEnabled: Boolean, val isVoNrSettingVisibility: Boolean) val carrierConfig = carrierConfigRepository.transformConfig(subId) { Config( Loading @@ -52,7 +54,14 @@ class VoNrRepository( val telephonyManager = context.telephonyManager(subId) return context .subscriptionsChangedFlow() .map { telephonyManager.isVoNrEnabled } .map { try { telephonyManager.isVoNrEnabled } catch (e: IllegalStateException) { Log.e(TAG, "IllegalStateException - isVoNrEnabled : $e") false } } .conflate() .onEach { Log.d(TAG, "[$subId] isVoNrEnabled: $it") } .flowOn(Dispatchers.Default) Loading @@ -61,9 +70,15 @@ class VoNrRepository( suspend fun setVoNrEnabled(subId: Int, enabled: Boolean) = withContext(Dispatchers.Default) { if (!SubscriptionManager.isValidSubscriptionId(subId)) return@withContext val result = context.telephonyManager(subId).setVoNrEnabled(enabled) var result = TelephonyManager.ENABLE_VONR_RADIO_INVALID_STATE try { result = context.telephonyManager(subId).setVoNrEnabled(enabled) } catch (e: IllegalStateException) { Log.e(TAG, "IllegalStateException - setVoNrEnabled : $e") } finally { Log.d(TAG, "[$subId] setVoNrEnabled: $enabled, result: $result") } } private companion object { private const val TAG = "VoNrRepository" Loading tests/spa_unit/src/com/android/settings/network/telephony/VoNrRepositoryTest.kt +25 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,9 @@ import kotlinx.coroutines.runBlocking import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.doThrow import org.mockito.kotlin.mock import org.mockito.kotlin.spy import org.mockito.kotlin.stub Loading Loading @@ -134,6 +136,15 @@ class VoNrRepositoryTest { assertThat(isVoNrEnabled).isTrue() } @Test fun isVoNrEnabledFlow_noPhoneProcess_noCrash() = runBlocking { mockTelephonyManager.stub { on { isVoNrEnabled } doThrow IllegalStateException("no Phone") } val isVoNrEnabled = repository.isVoNrEnabledFlow(SUB_ID).firstWithTimeoutOrNull() assertThat(isVoNrEnabled).isFalse() } @Test fun setVoNrEnabled(): Unit = runBlocking { repository.setVoNrEnabled(SUB_ID, true) Loading @@ -141,6 +152,19 @@ class VoNrRepositoryTest { verify(mockTelephonyManager).setVoNrEnabled(true) } @Test fun setVoNrEnabled_noPhoneProcess_noCrash(): Unit = runBlocking { mockTelephonyManager.stub { on { setVoNrEnabled(any()) } doThrow IllegalStateException("no Phone") } repository.setVoNrEnabled(SUB_ID, true) verify(mockTelephonyManager).setVoNrEnabled(true) } private companion object { const val SUB_ID = 1 } Loading Loading
src/com/android/settings/network/telephony/VoNrRepository.kt +20 −5 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.settings.network.telephony import android.content.Context import android.telephony.CarrierConfigManager import android.telephony.SubscriptionManager import android.telephony.TelephonyManager import android.util.Log import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow Loading @@ -37,6 +38,7 @@ class VoNrRepository( fun isVoNrAvailable(subId: Int): Boolean { if (!nrRepository.isNrAvailable(subId)) return false data class Config(val isVoNrEnabled: Boolean, val isVoNrSettingVisibility: Boolean) val carrierConfig = carrierConfigRepository.transformConfig(subId) { Config( Loading @@ -52,7 +54,14 @@ class VoNrRepository( val telephonyManager = context.telephonyManager(subId) return context .subscriptionsChangedFlow() .map { telephonyManager.isVoNrEnabled } .map { try { telephonyManager.isVoNrEnabled } catch (e: IllegalStateException) { Log.e(TAG, "IllegalStateException - isVoNrEnabled : $e") false } } .conflate() .onEach { Log.d(TAG, "[$subId] isVoNrEnabled: $it") } .flowOn(Dispatchers.Default) Loading @@ -61,9 +70,15 @@ class VoNrRepository( suspend fun setVoNrEnabled(subId: Int, enabled: Boolean) = withContext(Dispatchers.Default) { if (!SubscriptionManager.isValidSubscriptionId(subId)) return@withContext val result = context.telephonyManager(subId).setVoNrEnabled(enabled) var result = TelephonyManager.ENABLE_VONR_RADIO_INVALID_STATE try { result = context.telephonyManager(subId).setVoNrEnabled(enabled) } catch (e: IllegalStateException) { Log.e(TAG, "IllegalStateException - setVoNrEnabled : $e") } finally { Log.d(TAG, "[$subId] setVoNrEnabled: $enabled, result: $result") } } private companion object { private const val TAG = "VoNrRepository" Loading
tests/spa_unit/src/com/android/settings/network/telephony/VoNrRepositoryTest.kt +25 −1 Original line number Diff line number Diff line Loading @@ -27,7 +27,9 @@ import kotlinx.coroutines.runBlocking import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.doThrow import org.mockito.kotlin.mock import org.mockito.kotlin.spy import org.mockito.kotlin.stub Loading Loading @@ -134,6 +136,15 @@ class VoNrRepositoryTest { assertThat(isVoNrEnabled).isTrue() } @Test fun isVoNrEnabledFlow_noPhoneProcess_noCrash() = runBlocking { mockTelephonyManager.stub { on { isVoNrEnabled } doThrow IllegalStateException("no Phone") } val isVoNrEnabled = repository.isVoNrEnabledFlow(SUB_ID).firstWithTimeoutOrNull() assertThat(isVoNrEnabled).isFalse() } @Test fun setVoNrEnabled(): Unit = runBlocking { repository.setVoNrEnabled(SUB_ID, true) Loading @@ -141,6 +152,19 @@ class VoNrRepositoryTest { verify(mockTelephonyManager).setVoNrEnabled(true) } @Test fun setVoNrEnabled_noPhoneProcess_noCrash(): Unit = runBlocking { mockTelephonyManager.stub { on { setVoNrEnabled(any()) } doThrow IllegalStateException("no Phone") } repository.setVoNrEnabled(SUB_ID, true) verify(mockTelephonyManager).setVoNrEnabled(true) } private companion object { const val SUB_ID = 1 } Loading