• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.sim;
18 
19 import static android.telephony.SubscriptionManager.PROFILE_CLASS_PROVISIONING;
20 
21 import android.app.settings.SettingsEnums;
22 import android.content.Context;
23 import android.telecom.PhoneAccountHandle;
24 import android.telecom.TelecomManager;
25 import android.telephony.SubscriptionInfo;
26 import android.telephony.SubscriptionManager;
27 import android.telephony.TelephonyManager;
28 
29 import java.util.ArrayList;
30 import java.util.List;
31 
32 /**
33  * Specialized version of SimListDialogFragment that fetches a list of SIMs which support calls.
34  */
35 public class CallsSimListDialogFragment extends SimListDialogFragment {
36     @Override
getCurrentSubscriptions()37     protected List<SubscriptionInfo> getCurrentSubscriptions() {
38         final Context context = getContext();
39         final SubscriptionManager subscriptionManager = context.getSystemService(
40                 SubscriptionManager.class);
41         final TelecomManager telecomManager = context.getSystemService(TelecomManager.class);
42         final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class);
43         final List<PhoneAccountHandle> phoneAccounts =
44                 telecomManager.getCallCapablePhoneAccounts();
45         final List<SubscriptionInfo> result = new ArrayList<>();
46 
47         if (phoneAccounts == null) {
48             return result;
49         }
50         for (PhoneAccountHandle handle : phoneAccounts) {
51             final int subId = telephonyManager.getSubscriptionId(handle);
52 
53             if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
54                 continue;
55             }
56 
57             SubscriptionInfo info = subscriptionManager.getActiveSubscriptionInfo(subId);
58             if (info == null || (info.isEmbedded()
59                 && (info.getProfileClass() == PROFILE_CLASS_PROVISIONING
60                     || info.isOnlyNonTerrestrialNetwork()))) {
61                 continue;
62             }
63             result.add(subscriptionManager.getActiveSubscriptionInfo(subId));
64         }
65         return result;
66     }
67 
68     @Override
getMetricsCategory()69     public int getMetricsCategory() {
70         return SettingsEnums.DIALOG_CALL_SIM_LIST;
71     }
72 }
73