Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c169da9 authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge "Fix Wi-Fi calling option does not appear" into main

parents 57e70a75 daa50987
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import android.util.Log;

import androidx.annotation.VisibleForTesting;

import com.android.settings.network.telephony.wificalling.WifiCallingRepository;

/**
 * Controller class for querying Wifi calling status
 */
@@ -92,7 +94,9 @@ public class WifiCallingQueryImsState extends ImsQueryController {
     * Check whether Wifi Calling can be perform or not on this subscription
     *
     * @return true when Wifi Calling can be performed, otherwise false
     * @deprecated Use {@link WifiCallingRepository#wifiCallingReadyFlow()} instead.
     */
    @Deprecated
    public boolean isReadyToWifiCalling() {
        if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
            return false;
+4 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ import com.android.settings.network.CarrierConfigCache;
import com.android.settings.network.SubscriptionUtil;
import com.android.settings.network.ims.WifiCallingQueryImsState;
import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants;
import com.android.settings.network.telephony.wificalling.WifiCallingRepository;
import com.android.settingslib.core.instrumentation.Instrumentable;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
import com.android.settingslib.graph.SignalDrawable;
@@ -928,7 +929,10 @@ public class MobileNetworkUtils {

    /**
     * Copied from WifiCallingPreferenceController#isWifiCallingEnabled()
     *
     * @deprecated Use {@link WifiCallingRepository#wifiCallingReadyFlow()} instead.
     */
    @Deprecated
    public static boolean isWifiCallingEnabled(Context context, int subId,
            @Nullable WifiCallingQueryImsState queryImsState) {
        if (queryImsState == null) {
+5 −1
Original line number Diff line number Diff line
@@ -18,12 +18,16 @@ package com.android.settings.network.telephony

import android.content.Context
import android.telephony.SubscriptionManager
import android.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asExecutor
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onEach

private const val TAG = "SubscriptionRepository"

fun Context.subscriptionsChangedFlow() = callbackFlow {
    val subscriptionManager = getSystemService(SubscriptionManager::class.java)!!
@@ -40,4 +44,4 @@ fun Context.subscriptionsChangedFlow() = callbackFlow {
    )

    awaitClose { subscriptionManager.removeOnSubscriptionsChangedListener(listener) }
}.conflate().flowOn(Dispatchers.Default)
}.conflate().onEach { Log.d(TAG, "subscriptions changed") }.flowOn(Dispatchers.Default)
+6 −10
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ open class WifiCallingPreferenceController @JvmOverloads constructor(
    context: Context,
    key: String,
    private val callStateFlowFactory: (subId: Int) -> Flow<Int> = context::callStateFlow,
    private val wifiCallingRepository: (subId: Int) -> WifiCallingRepository = { subId ->
    private val wifiCallingRepositoryFactory: (subId: Int) -> WifiCallingRepository = { subId ->
        WifiCallingRepository(context, subId)
    },
) : TelephonyBasePreferenceController(context, key) {
@@ -80,14 +80,10 @@ open class WifiCallingPreferenceController @JvmOverloads constructor(
    }

    override fun onViewCreated(viewLifecycleOwner: LifecycleOwner) {
        viewLifecycleOwner.lifecycleScope.launch {
            viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
                val isVisible = withContext(Dispatchers.Default) {
                    MobileNetworkUtils.isWifiCallingEnabled(mContext, mSubId, null)
                }
                preference.isVisible = isVisible
                callingPreferenceCategoryController.updateChildVisible(preferenceKey, isVisible)
            }
        wifiCallingRepositoryFactory(mSubId).wifiCallingReadyFlow()
            .collectLatestWithLifecycle(viewLifecycleOwner) {
                preference.isVisible = it
                callingPreferenceCategoryController.updateChildVisible(preferenceKey, it)
            }

        viewLifecycleOwner.lifecycleScope.launch {
@@ -122,7 +118,7 @@ open class WifiCallingPreferenceController @JvmOverloads constructor(
    }

    private fun getSummaryForWfcMode(): String {
        val resId = when (wifiCallingRepository(mSubId).getWiFiCallingMode()) {
        val resId = when (wifiCallingRepositoryFactory(mSubId).getWiFiCallingMode()) {
            ImsMmTelManager.WIFI_MODE_WIFI_ONLY ->
                com.android.internal.R.string.wfc_mode_wifi_only_summary

+83 −0
Original line number Diff line number Diff line
/*
 * 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.ims

import android.telephony.ims.ProvisioningManager
import android.telephony.ims.ProvisioningManager.FeatureProvisioningCallback
import android.telephony.ims.feature.MmTelFeature.MmTelCapabilities.MmTelCapability
import android.telephony.ims.stub.ImsRegistrationImplBase.ImsRegistrationTech
import android.util.Log
import androidx.annotation.VisibleForTesting
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asExecutor
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onEach

private const val TAG = "ImsFeatureProvisioned"

fun imsFeatureProvisionedFlow(
    subId: Int,
    @MmTelCapability capability: Int,
    @ImsRegistrationTech tech: Int,
): Flow<Boolean> = imsFeatureProvisionedFlow(
    subId = subId,
    capability = capability,
    tech = tech,
    provisioningManager = ProvisioningManager.createForSubscriptionId(subId),
)

@VisibleForTesting
fun imsFeatureProvisionedFlow(
    subId: Int,
    @MmTelCapability capability: Int,
    @ImsRegistrationTech tech: Int,
    provisioningManager : ProvisioningManager,
): Flow<Boolean> = callbackFlow {
    val callback = object : FeatureProvisioningCallback() {
        override fun onFeatureProvisioningChanged(
            receivedCapability: Int,
            receivedTech: Int,
            isProvisioned: Boolean,
        ) {
            if (capability == receivedCapability && tech == receivedTech) trySend(isProvisioned)
        }

        override fun onRcsFeatureProvisioningChanged(
            capability: Int,
            tech: Int,
            isProvisioned: Boolean,
        ) {
        }
    }

    provisioningManager.registerFeatureProvisioningChangedCallback(
        Dispatchers.Default.asExecutor(),
        callback,
    )
    trySend(provisioningManager.getProvisioningStatusForCapability(capability, tech))

    awaitClose { provisioningManager.unregisterFeatureProvisioningChangedCallback(callback) }
}.catch { e ->
    Log.w(TAG, "[$subId] error while imsFeatureProvisionedFlow", e)
}.conflate().onEach {
    Log.d(TAG, "[$subId] changed: capability=$capability tech=$tech isProvisioned=$it")
}.flowOn(Dispatchers.Default)
Loading