diff --git a/src/com/android/settings/network/telephony/DataSubscriptionRepository.kt b/src/com/android/settings/network/telephony/DataSubscriptionRepository.kt index 99f639b77c9..62e7e98df3c 100644 --- a/src/com/android/settings/network/telephony/DataSubscriptionRepository.kt +++ b/src/com/android/settings/network/telephony/DataSubscriptionRepository.kt @@ -51,46 +51,41 @@ class DataSubscriptionRepository( ) .map { it.getIntExtra(SUBSCRIPTION_KEY, SubscriptionManager.INVALID_SUBSCRIPTION_ID) } .onStart { emit(SubscriptionManager.getDefaultDataSubscriptionId()) } + .distinctUntilChanged() .conflate() .flowOn(Dispatchers.Default) fun activeDataSubscriptionIdFlow(): Flow = - telephonyManager.telephonyCallbackFlow { - object : TelephonyCallback(), TelephonyCallback.ActiveDataSubscriptionIdListener { - override fun onActiveDataSubscriptionIdChanged(subId: Int) { - trySend(subId) - Log.d(TAG, "activeDataSubscriptionIdFlow: $subId") + telephonyManager + .telephonyCallbackFlow { + object : TelephonyCallback(), TelephonyCallback.ActiveDataSubscriptionIdListener { + override fun onActiveDataSubscriptionIdChanged(subId: Int) { + trySend(subId) + Log.d(TAG, "activeDataSubscriptionIdFlow: $subId") + } } } - } + .distinctUntilChanged() fun dataSummaryFlow(): Flow = combine(defaultDataSubscriptionIdFlow(), activeDataSubscriptionIdFlow()) { - defaultSubId, - activeSubId -> - DataSubscriptionIds(defaultSubId, activeSubId) + defaultDataSubId, + activeDataSubId -> + getDataSummary(defaultDataSubId, activeDataSubId) } - .distinctUntilChanged() - .map { it.getDataSummary() } .conflate() .flowOn(Dispatchers.Default) - private data class DataSubscriptionIds( - val defaultSubId: Int, - val activeSubId: Int, - ) - - private fun DataSubscriptionIds.getDataSummary(): String { - val activeSubInfo = subscriptionManager.getActiveSubscriptionInfo(activeSubId) ?: return "" + private fun getDataSummary(defaultDataSubId: Int, activeDataSubId: Int): String { + if (defaultDataSubId == activeDataSubId) return getDisplayName(defaultDataSubId) + val activeSubInfo = + subscriptionManager.getActiveSubscriptionInfo(activeDataSubId) + ?: return getDisplayName(defaultDataSubId) if (!SubscriptionUtil.isSubscriptionVisible(subscriptionManager, context, activeSubInfo)) { - return getDisplayName(defaultSubId) - } - val uniqueName = getDisplayName(activeSubId) - return if (activeSubId == defaultSubId) { - uniqueName - } else { - context.getString(R.string.mobile_data_temp_using, uniqueName) + return getDisplayName(defaultDataSubId) } + // non-DDS is active + return context.getString(R.string.mobile_data_temp_using, getDisplayName(activeDataSubId)) } companion object {