Create WifiCallingRepository
Move Wi-Fi calling related feature into it. Which simplifies the ImsMmTelRepository, so we can put more ImsMmTelManager related features into ImsMmTelRepository in the future cl. Bug: 325414275 Test: manual - on Mobile Settings Test: unit tests Change-Id: I391f43cfa3a79e0c44865050c357ac54346c2fb1
This commit is contained in:
@@ -29,8 +29,7 @@ import androidx.lifecycle.repeatOnLifecycle
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceScreen
|
||||
import com.android.settings.R
|
||||
import com.android.settings.network.telephony.ims.ImsMmTelRepository
|
||||
import com.android.settings.network.telephony.ims.ImsMmTelRepositoryImpl
|
||||
import com.android.settings.network.telephony.wificalling.WifiCallingRepository
|
||||
import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@@ -46,8 +45,8 @@ open class WifiCallingPreferenceController @JvmOverloads constructor(
|
||||
context: Context,
|
||||
key: String,
|
||||
private val callStateFlowFactory: (subId: Int) -> Flow<Int> = context::callStateFlow,
|
||||
private val imsMmTelRepositoryFactory: (subId: Int) -> ImsMmTelRepository = { subId ->
|
||||
ImsMmTelRepositoryImpl(context, subId)
|
||||
private val wifiCallingRepository: (subId: Int) -> WifiCallingRepository = { subId ->
|
||||
WifiCallingRepository(context, subId)
|
||||
},
|
||||
) : TelephonyBasePreferenceController(context, key) {
|
||||
|
||||
@@ -123,7 +122,7 @@ open class WifiCallingPreferenceController @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
private fun getSummaryForWfcMode(): String {
|
||||
val resId = when (imsMmTelRepositoryFactory(mSubId).getWiFiCallingMode()) {
|
||||
val resId = when (wifiCallingRepository(mSubId).getWiFiCallingMode()) {
|
||||
ImsMmTelManager.WIFI_MODE_WIFI_ONLY ->
|
||||
com.android.internal.R.string.wfc_mode_wifi_only_summary
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
* Copyright (C) 2024 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.
|
||||
@@ -17,9 +17,6 @@
|
||||
package com.android.settings.network.telephony.ims
|
||||
|
||||
import android.content.Context
|
||||
import android.telephony.CarrierConfigManager
|
||||
import android.telephony.CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL
|
||||
import android.telephony.TelephonyManager
|
||||
import android.telephony.ims.ImsManager
|
||||
import android.telephony.ims.ImsMmTelManager
|
||||
import android.telephony.ims.ImsMmTelManager.WiFiCallingMode
|
||||
@@ -27,7 +24,7 @@ import android.util.Log
|
||||
|
||||
interface ImsMmTelRepository {
|
||||
@WiFiCallingMode
|
||||
fun getWiFiCallingMode(): Int
|
||||
fun getWiFiCallingMode(useRoamingMode: Boolean): Int
|
||||
}
|
||||
|
||||
class ImsMmTelRepositoryImpl(
|
||||
@@ -36,31 +33,18 @@ class ImsMmTelRepositoryImpl(
|
||||
private val imsMmTelManager: ImsMmTelManager = ImsManager(context).getImsMmTelManager(subId),
|
||||
) : ImsMmTelRepository {
|
||||
|
||||
private val telephonyManager = context.getSystemService(TelephonyManager::class.java)!!
|
||||
.createForSubscriptionId(subId)
|
||||
|
||||
private val carrierConfigManager = context.getSystemService(CarrierConfigManager::class.java)!!
|
||||
|
||||
@WiFiCallingMode
|
||||
override fun getWiFiCallingMode(): Int = try {
|
||||
override fun getWiFiCallingMode(useRoamingMode: Boolean): Int = try {
|
||||
when {
|
||||
!imsMmTelManager.isVoWiFiSettingEnabled -> ImsMmTelManager.WIFI_MODE_UNKNOWN
|
||||
|
||||
telephonyManager.isNetworkRoaming && !useWfcHomeModeForRoaming() ->
|
||||
imsMmTelManager.getVoWiFiRoamingModeSetting()
|
||||
|
||||
useRoamingMode -> imsMmTelManager.getVoWiFiRoamingModeSetting()
|
||||
else -> imsMmTelManager.getVoWiFiModeSetting()
|
||||
}
|
||||
} catch (e: IllegalArgumentException) {
|
||||
Log.w(TAG, "getWiFiCallingMode failed subId=$subId", e)
|
||||
Log.w(TAG, "[$subId] getWiFiCallingMode failed useRoamingMode=$useRoamingMode", e)
|
||||
ImsMmTelManager.WIFI_MODE_UNKNOWN
|
||||
}
|
||||
|
||||
private fun useWfcHomeModeForRoaming(): Boolean =
|
||||
carrierConfigManager
|
||||
.getConfigForSubId(subId, KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL)
|
||||
.getBoolean(KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL)
|
||||
|
||||
private companion object {
|
||||
private const val TAG = "ImsMmTelRepository"
|
||||
}
|
||||
|
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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.telephony.wificalling
|
||||
|
||||
import android.content.Context
|
||||
import android.telephony.CarrierConfigManager
|
||||
import android.telephony.CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL
|
||||
import android.telephony.TelephonyManager
|
||||
import android.telephony.ims.ImsMmTelManager.WiFiCallingMode
|
||||
import com.android.settings.network.telephony.ims.ImsMmTelRepository
|
||||
import com.android.settings.network.telephony.ims.ImsMmTelRepositoryImpl
|
||||
|
||||
class WifiCallingRepository(
|
||||
private val context: Context,
|
||||
private val subId: Int,
|
||||
private val imsMmTelRepository : ImsMmTelRepository = ImsMmTelRepositoryImpl(context, subId)
|
||||
) {
|
||||
private val telephonyManager = context.getSystemService(TelephonyManager::class.java)!!
|
||||
.createForSubscriptionId(subId)
|
||||
|
||||
private val carrierConfigManager = context.getSystemService(CarrierConfigManager::class.java)!!
|
||||
|
||||
@WiFiCallingMode
|
||||
fun getWiFiCallingMode(): Int {
|
||||
val useRoamingMode = telephonyManager.isNetworkRoaming && !useWfcHomeModeForRoaming()
|
||||
return imsMmTelRepository.getWiFiCallingMode(useRoamingMode)
|
||||
}
|
||||
|
||||
private fun useWfcHomeModeForRoaming(): Boolean =
|
||||
carrierConfigManager
|
||||
.getConfigForSubId(subId, KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL)
|
||||
.getBoolean(KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL)
|
||||
}
|
Reference in New Issue
Block a user