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