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 android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.telecom.PhoneAccount; 22 import android.telecom.PhoneAccountHandle; 23 import android.telecom.TelecomManager; 24 import android.telephony.SubscriptionInfo; 25 import android.telephony.SubscriptionManager; 26 import android.telephony.TelephonyManager; 27 28 import java.util.ArrayList; 29 import java.util.List; 30 31 /** 32 * Specialized version of SimListDialogFragment that fetches a list of SIMs which support calls. 33 */ 34 public class CallsSimListDialogFragment extends SimListDialogFragment { 35 @Override getCurrentSubscriptions()36 protected List<SubscriptionInfo> getCurrentSubscriptions() { 37 final Context context = getContext(); 38 final SubscriptionManager subscriptionManager = context.getSystemService( 39 SubscriptionManager.class); 40 final TelecomManager telecomManager = context.getSystemService(TelecomManager.class); 41 final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class); 42 final List<PhoneAccountHandle> phoneAccounts = 43 telecomManager.getCallCapablePhoneAccounts(); 44 final List<SubscriptionInfo> result = new ArrayList<>(); 45 46 if (phoneAccounts == null) { 47 return result; 48 } 49 for (PhoneAccountHandle handle : phoneAccounts) { 50 final PhoneAccount phoneAccount = telecomManager.getPhoneAccount(handle); 51 final int subId = telephonyManager.getSubIdForPhoneAccount(phoneAccount); 52 53 if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 54 continue; 55 } 56 result.add(subscriptionManager.getActiveSubscriptionInfo(subId)); 57 } 58 return result; 59 } 60 61 @Override getMetricsCategory()62 public int getMetricsCategory() { 63 return SettingsEnums.DIALOG_CALL_SIM_LIST; 64 } 65 } 66