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
18 
19 import android.content.Context
20 import android.telephony.SubscriptionManager
21 
22 /**
23  * Shows information about disable a physical SIM.
24  */
25 class DisableSimFooterPreferenceController @JvmOverloads constructor(
26     context: Context,
27     preferenceKey: String,
28     private val subscriptionRepository: SubscriptionRepository = SubscriptionRepository(context),
29 ) : TelephonyBasePreferenceController(context, preferenceKey) {
30 
31     /**
32      * Re-init for SIM based on given subscription ID.
33      *
34      * @param subId is the given subscription ID
35      */
36     fun init(subId: Int) {
37         mSubId = subId
38     }
39 
40     override fun getAvailabilityStatus(subId: Int): Int {
41         if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID ||
42             subscriptionRepository.canDisablePhysicalSubscription()
43         ) {
44             return CONDITIONALLY_UNAVAILABLE
45         }
46 
47         val isAvailable =
48             subscriptionRepository.getSelectableSubscriptionInfoList().any { subInfo ->
49                 subInfo.subscriptionId == subId && !subInfo.isEmbedded
50             }
51 
52         return if (isAvailable) AVAILABLE else CONDITIONALLY_UNAVAILABLE
53     }
54 }
55