Merge "Settings search for W-Fi calling" into main

This commit is contained in:
Chaohui Wang
2024-08-06 08:32:18 +00:00
committed by Android (Google) Code Review
3 changed files with 32 additions and 18 deletions

View File

@@ -202,10 +202,12 @@
android:title="@string/call_category" android:title="@string/call_category"
settings:controller="com.android.settings.network.telephony.CallingPreferenceCategoryController"> settings:controller="com.android.settings.network.telephony.CallingPreferenceCategoryController">
<!-- Settings search is handled by WifiCallingSearchItem. -->
<Preference <Preference
android:key="wifi_calling" android:key="wifi_calling"
android:title="@string/wifi_calling_settings_title" android:title="@string/wifi_calling_settings_title"
android:summary="@string/wifi_calling_summary" android:summary="@string/wifi_calling_summary"
settings:searchable="false"
settings:controller="com.android.settings.network.telephony.WifiCallingPreferenceController"> settings:controller="com.android.settings.network.telephony.WifiCallingPreferenceController">
<intent android:action="android.intent.action.MAIN" <intent android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings" android:targetPackage="com.android.settings"

View File

@@ -24,6 +24,7 @@ import com.android.settings.network.SubscriptionUtil
import com.android.settings.network.telephony.MmsMessagePreferenceController.Companion.MmsMessageSearchItem import com.android.settings.network.telephony.MmsMessagePreferenceController.Companion.MmsMessageSearchItem
import com.android.settings.network.telephony.NrAdvancedCallingPreferenceController.Companion.NrAdvancedCallingSearchItem import com.android.settings.network.telephony.NrAdvancedCallingPreferenceController.Companion.NrAdvancedCallingSearchItem
import com.android.settings.network.telephony.RoamingPreferenceController.Companion.RoamingSearchItem import com.android.settings.network.telephony.RoamingPreferenceController.Companion.RoamingSearchItem
import com.android.settings.network.telephony.WifiCallingPreferenceController.Companion.WifiCallingSearchItem
import com.android.settings.spa.SpaSearchLanding.BundleValue import com.android.settings.spa.SpaSearchLanding.BundleValue
import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingFragment import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingFragment
import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingKey import com.android.settings.spa.SpaSearchLanding.SpaSearchLandingKey
@@ -112,9 +113,10 @@ class MobileNetworkSettingsSearchIndex(
fun createSearchItems(context: Context): List<MobileNetworkSettingsSearchItem> = fun createSearchItems(context: Context): List<MobileNetworkSettingsSearchItem> =
listOf( listOf(
RoamingSearchItem(context),
MmsMessageSearchItem(context), MmsMessageSearchItem(context),
NrAdvancedCallingSearchItem(context), NrAdvancedCallingSearchItem(context),
RoamingSearchItem(context),
WifiCallingSearchItem(context),
) )
} }
} }

View File

@@ -22,14 +22,17 @@ import android.telecom.TelecomManager
import android.telephony.SubscriptionManager import android.telephony.SubscriptionManager
import android.telephony.TelephonyManager import android.telephony.TelephonyManager
import android.telephony.ims.ImsMmTelManager import android.telephony.ims.ImsMmTelManager
import android.util.Log
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import com.android.settings.R import com.android.settings.R
import com.android.settings.core.BasePreferenceController
import com.android.settings.network.telephony.MobileNetworkSettingsSearchIndex.MobileNetworkSettingsSearchItem
import com.android.settings.network.telephony.wificalling.WifiCallingRepository import com.android.settings.network.telephony.wificalling.WifiCallingRepository
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
/** /**
@@ -44,20 +47,21 @@ open class WifiCallingPreferenceController @JvmOverloads constructor(
private val wifiCallingRepositoryFactory: (subId: Int) -> WifiCallingRepository = { subId -> private val wifiCallingRepositoryFactory: (subId: Int) -> WifiCallingRepository = { subId ->
WifiCallingRepository(context, subId) WifiCallingRepository(context, subId)
}, },
) : TelephonyBasePreferenceController(context, key) { ) : BasePreferenceController(context, key) {
private var subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID
private lateinit var preference: Preference private lateinit var preference: Preference
private lateinit var callingPreferenceCategoryController: CallingPreferenceCategoryController private lateinit var callingPreferenceCategoryController: CallingPreferenceCategoryController
private val resourcesForSub by lazy { private val resourcesForSub by lazy {
SubscriptionManager.getResourcesForSubId(mContext, mSubId) SubscriptionManager.getResourcesForSubId(mContext, subId)
} }
fun init( fun init(
subId: Int, subId: Int,
callingPreferenceCategoryController: CallingPreferenceCategoryController, callingPreferenceCategoryController: CallingPreferenceCategoryController,
): WifiCallingPreferenceController { ): WifiCallingPreferenceController {
mSubId = subId this.subId = subId
this.callingPreferenceCategoryController = callingPreferenceCategoryController this.callingPreferenceCategoryController = callingPreferenceCategoryController
return this return this
} }
@@ -65,39 +69,32 @@ open class WifiCallingPreferenceController @JvmOverloads constructor(
/** /**
* Note: Visibility also controlled by [onViewCreated]. * Note: Visibility also controlled by [onViewCreated].
*/ */
override fun getAvailabilityStatus(subId: Int) = override fun getAvailabilityStatus() =
if (SubscriptionManager.isValidSubscriptionId(subId)) AVAILABLE if (SubscriptionManager.isValidSubscriptionId(subId)) AVAILABLE
else CONDITIONALLY_UNAVAILABLE else CONDITIONALLY_UNAVAILABLE
override fun displayPreference(screen: PreferenceScreen) { override fun displayPreference(screen: PreferenceScreen) {
// Not call super here, to avoid preference.isVisible changed unexpectedly // Not call super here, to avoid preference.isVisible changed unexpectedly
preference = screen.findPreference(preferenceKey)!! preference = screen.findPreference(preferenceKey)!!
preference.intent?.putExtra(Settings.EXTRA_SUB_ID, mSubId) preference.intent?.putExtra(Settings.EXTRA_SUB_ID, subId)
} }
override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) { override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
if(mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID){ wifiCallingRepositoryFactory(subId).wifiCallingReadyFlow()
Log.e(
this.javaClass.simpleName,
"mSubId is INVALID_SUBSCRIPTION_ID"
)
return
}
wifiCallingRepositoryFactory(mSubId).wifiCallingReadyFlow()
.collectLatestWithLifecycle(viewLifecycleOwner) { isReady -> .collectLatestWithLifecycle(viewLifecycleOwner) { isReady ->
preference.isVisible = isReady preference.isVisible = isReady
callingPreferenceCategoryController.updateChildVisible(preferenceKey, isReady) callingPreferenceCategoryController.updateChildVisible(preferenceKey, isReady)
if (isReady) update() if (isReady) update()
} }
callStateRepository.callStateFlow(mSubId).collectLatestWithLifecycle(viewLifecycleOwner) { callStateRepository.callStateFlow(subId).collectLatestWithLifecycle(viewLifecycleOwner) {
preference.isEnabled = (it == TelephonyManager.CALL_STATE_IDLE) preference.isEnabled = (it == TelephonyManager.CALL_STATE_IDLE)
} }
} }
private suspend fun update() { private suspend fun update() {
val simCallManager = mContext.getSystemService(TelecomManager::class.java) val simCallManager = mContext.getSystemService(TelecomManager::class.java)
?.getSimCallManagerForSubscription(mSubId) ?.getSimCallManagerForSubscription(subId)
if (simCallManager != null) { if (simCallManager != null) {
val intent = withContext(Dispatchers.Default) { val intent = withContext(Dispatchers.Default) {
MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext, simCallManager) MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext, simCallManager)
@@ -116,7 +113,7 @@ open class WifiCallingPreferenceController @JvmOverloads constructor(
} }
private fun getSummaryForWfcMode(): String { private fun getSummaryForWfcMode(): String {
val resId = when (wifiCallingRepositoryFactory(mSubId).getWiFiCallingMode()) { val resId = when (wifiCallingRepositoryFactory(subId).getWiFiCallingMode()) {
ImsMmTelManager.WIFI_MODE_WIFI_ONLY -> ImsMmTelManager.WIFI_MODE_WIFI_ONLY ->
com.android.internal.R.string.wfc_mode_wifi_only_summary com.android.internal.R.string.wfc_mode_wifi_only_summary
@@ -130,4 +127,17 @@ open class WifiCallingPreferenceController @JvmOverloads constructor(
} }
return resourcesForSub.getString(resId) return resourcesForSub.getString(resId)
} }
companion object {
class WifiCallingSearchItem(
private val context: Context,
) : MobileNetworkSettingsSearchItem {
override val key: String = "wifi_calling"
override val title: String = context.getString(R.string.wifi_calling_settings_title)
override fun isAvailable(subId: Int): Boolean = runBlocking {
WifiCallingRepository(context, subId).wifiCallingReadyFlow().first()
}
}
}
} }