• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * 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.ims
18 
19 import android.content.Context
20 import android.telephony.AccessNetworkConstants.TransportType
21 import android.telephony.ims.feature.MmTelFeature.MmTelCapabilities.MmTelCapability
22 import android.telephony.ims.stub.ImsRegistrationImplBase.ImsRegistrationTech
23 import com.android.settings.network.telephony.subscriptionsChangedFlow
24 import kotlinx.coroutines.ExperimentalCoroutinesApi
25 import kotlinx.coroutines.flow.Flow
26 import kotlinx.coroutines.flow.combine
27 import kotlinx.coroutines.flow.flatMapLatest
28 
29 /**
30  * A repository for the IMS feature.
31  *
32  * @throws IllegalArgumentException if the [subId] is invalid.
33  */
34 @OptIn(ExperimentalCoroutinesApi::class)
35 class ImsFeatureRepository(
36     private val context: Context,
37     private val subId: Int,
38     private val provisioningRepository: ProvisioningRepository = ProvisioningRepository(context),
39     private val imsMmTelRepository: ImsMmTelRepository = ImsMmTelRepositoryImpl(context, subId)
40 ) {
41     /**
42      * A cold flow that determines the provisioning status for the specified IMS MmTel capability,
43      * and whether or not the requested MmTel capability is supported by the carrier on the
44      * specified network transport.
45      *
46      * @return true if the feature is provisioned and supported, false otherwise.
47      */
48     fun isReadyFlow(
49         @MmTelCapability capability: Int,
50         @ImsRegistrationTech tech: Int,
51         @TransportType transportType: Int,
52     ): Flow<Boolean> =
53         context.subscriptionsChangedFlow().flatMapLatest {
54             combine(
55                 provisioningRepository.imsFeatureProvisionedFlow(subId, capability, tech),
56                 imsMmTelRepository.isSupportedFlow(capability, transportType),
57             ) { imsFeatureProvisioned, isSupported ->
58                 imsFeatureProvisioned && isSupported
59             }
60         }
61 }
62