Loading src/com/android/settings/network/telephony/SubscriptionRepository.kt +2 −1 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import kotlinx.coroutines.asExecutor import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.filterNot import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach Loading Loading @@ -55,7 +56,7 @@ fun Context.isSubscriptionEnabledFlow(subId: Int) = subscriptionsChangedFlow().m fun Context.phoneNumberFlow(subscriptionInfo: SubscriptionInfo) = subscriptionsChangedFlow().map { SubscriptionUtil.getFormattedPhoneNumber(this, subscriptionInfo) }.flowOn(Dispatchers.Default) }.filterNot { it.isNullOrEmpty() }.flowOn(Dispatchers.Default) fun Context.subscriptionsChangedFlow() = callbackFlow { val subscriptionManager = requireSubscriptionManager() Loading tests/spa_unit/src/com/android/settings/network/telephony/SubscriptionRepositoryTest.kt +17 −0 Original line number Diff line number Diff line Loading @@ -141,10 +141,27 @@ class SubscriptionRepositoryTest { assertThat(subInfos.map { it.subscriptionId }).containsExactly(SUB_ID_1) } @Test fun phoneNumberFlow() = runBlocking { mockSubscriptionManager.stub { on { getPhoneNumber(SUB_ID_1) } doReturn NUMBER_1 } val subInfo = SubscriptionInfo.Builder().apply { setId(SUB_ID_1) setMcc(MCC) }.build() val phoneNumber = context.phoneNumberFlow(subInfo).firstWithTimeoutOrNull() assertThat(phoneNumber).isEqualTo(NUMBER_1) } private companion object { const val SUB_ID_1 = 1 const val SUB_ID_2 = 2 val GROUP_UUID = UUID.randomUUID().toString() const val SIM_SLOT_INDEX = 1 const val NUMBER_1 = "000000001" const val MCC = "310" } } Loading
src/com/android/settings/network/telephony/SubscriptionRepository.kt +2 −1 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import kotlinx.coroutines.asExecutor import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.filterNot import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach Loading Loading @@ -55,7 +56,7 @@ fun Context.isSubscriptionEnabledFlow(subId: Int) = subscriptionsChangedFlow().m fun Context.phoneNumberFlow(subscriptionInfo: SubscriptionInfo) = subscriptionsChangedFlow().map { SubscriptionUtil.getFormattedPhoneNumber(this, subscriptionInfo) }.flowOn(Dispatchers.Default) }.filterNot { it.isNullOrEmpty() }.flowOn(Dispatchers.Default) fun Context.subscriptionsChangedFlow() = callbackFlow { val subscriptionManager = requireSubscriptionManager() Loading
tests/spa_unit/src/com/android/settings/network/telephony/SubscriptionRepositoryTest.kt +17 −0 Original line number Diff line number Diff line Loading @@ -141,10 +141,27 @@ class SubscriptionRepositoryTest { assertThat(subInfos.map { it.subscriptionId }).containsExactly(SUB_ID_1) } @Test fun phoneNumberFlow() = runBlocking { mockSubscriptionManager.stub { on { getPhoneNumber(SUB_ID_1) } doReturn NUMBER_1 } val subInfo = SubscriptionInfo.Builder().apply { setId(SUB_ID_1) setMcc(MCC) }.build() val phoneNumber = context.phoneNumberFlow(subInfo).firstWithTimeoutOrNull() assertThat(phoneNumber).isEqualTo(NUMBER_1) } private companion object { const val SUB_ID_1 = 1 const val SUB_ID_2 = 2 val GROUP_UUID = UUID.randomUUID().toString() const val SIM_SLOT_INDEX = 1 const val NUMBER_1 = "000000001" const val MCC = "310" } }