1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.network.telephony.wificalling 18 19 import android.content.Context 20 import android.telephony.AccessNetworkConstants 21 import android.telephony.CarrierConfigManager 22 import android.telephony.CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL 23 import android.telephony.ims.ImsMmTelManager.WiFiCallingMode 24 import android.telephony.ims.feature.MmTelFeature 25 import android.telephony.ims.stub.ImsRegistrationImplBase 26 import androidx.lifecycle.LifecycleOwner 27 import com.android.settings.network.telephony.ims.ImsFeatureRepository 28 import com.android.settings.network.telephony.ims.ImsMmTelRepository 29 import com.android.settings.network.telephony.ims.ImsMmTelRepositoryImpl 30 import com.android.settings.network.telephony.telephonyManager 31 import com.android.settingslib.spa.framework.util.collectLatestWithLifecycle 32 import kotlinx.coroutines.flow.Flow 33 34 interface IWifiCallingRepository { 35 /** TODO: Move this to UI layer, when UI layer migrated to Kotlin. */ collectIsWifiCallingReadyFlownull36 fun collectIsWifiCallingReadyFlow(lifecycleOwner: LifecycleOwner, action: (Boolean) -> Unit) 37 } 38 39 class WifiCallingRepository 40 @JvmOverloads 41 constructor( 42 private val context: Context, 43 private val subId: Int, 44 private val imsFeatureRepository: ImsFeatureRepository = ImsFeatureRepository(context, subId), 45 private val imsMmTelRepository: ImsMmTelRepository = ImsMmTelRepositoryImpl(context, subId), 46 ) : IWifiCallingRepository { 47 private val telephonyManager = context.telephonyManager(subId) 48 49 private val carrierConfigManager = context.getSystemService(CarrierConfigManager::class.java)!! 50 51 @WiFiCallingMode 52 fun getWiFiCallingMode(): Int { 53 val useRoamingMode = telephonyManager.isNetworkRoaming && !useWfcHomeModeForRoaming() 54 return imsMmTelRepository.getWiFiCallingMode(useRoamingMode) 55 } 56 57 private fun useWfcHomeModeForRoaming(): Boolean = 58 carrierConfigManager 59 .getConfigForSubId(subId, KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL) 60 .getBoolean(KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL) 61 62 /** TODO: Move this to UI layer, when UI layer migrated to Kotlin. */ 63 override fun collectIsWifiCallingReadyFlow( 64 lifecycleOwner: LifecycleOwner, 65 action: (Boolean) -> Unit, 66 ) { 67 wifiCallingReadyFlow().collectLatestWithLifecycle(lifecycleOwner, action = action) 68 } 69 70 fun wifiCallingReadyFlow(): Flow<Boolean> = 71 imsFeatureRepository.isReadyFlow( 72 capability = MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE, 73 tech = ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN, 74 transportType = AccessNetworkConstants.TRANSPORT_TYPE_WLAN, 75 ) 76 } 77