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 com.android.internal.telephony.flags.Flags; 30 31 import java.util.ArrayList; 32 import java.util.List; 33 34 /** 35 * Specialized version of SimListDialogFragment that fetches a list of SIMs which support calls. 36 */ 37 public class CallsSimListDialogFragment extends SimListDialogFragment { 38 @Override getCurrentSubscriptions()39 protected List<SubscriptionInfo> getCurrentSubscriptions() { 40 final Context context = getContext(); 41 final SubscriptionManager subscriptionManager = context.getSystemService( 42 SubscriptionManager.class); 43 final TelecomManager telecomManager = context.getSystemService(TelecomManager.class); 44 final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class); 45 final List<PhoneAccountHandle> phoneAccounts = 46 telecomManager.getCallCapablePhoneAccounts(); 47 final List<SubscriptionInfo> result = new ArrayList<>(); 48 49 if (phoneAccounts == null) { 50 return result; 51 } 52 for (PhoneAccountHandle handle : phoneAccounts) { 53 final int subId = telephonyManager.getSubscriptionId(handle); 54 55 if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 56 continue; 57 } 58 59 SubscriptionInfo info = subscriptionManager.getActiveSubscriptionInfo(subId); 60 if (info == null || (info.isEmbedded() 61 && (info.getProfileClass() == PROFILE_CLASS_PROVISIONING 62 || (Flags.oemEnabledSatelliteFlag() 63 && info.isOnlyNonTerrestrialNetwork())))) { 64 continue; 65 } 66 result.add(subscriptionManager.getActiveSubscriptionInfo(subId)); 67 } 68 return result; 69 } 70 71 @Override getMetricsCategory()72 public int getMetricsCategory() { 73 return SettingsEnums.DIALOG_CALL_SIM_LIST; 74 } 75 } 76