1 /* 2 * Copyright (C) 2010 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.internal.telephony; 18 19 import android.annotation.NonNull; 20 import android.compat.annotation.UnsupportedAppUsage; 21 import android.os.Build; 22 import android.os.SystemProperties; 23 24 import com.android.internal.telephony.flags.FeatureFlags; 25 import com.android.telephony.Rlog; 26 27 /** 28 * Utilities that check if the phone supports specified capabilities. 29 */ 30 public class TelephonyCapabilities { 31 private static final String LOG_TAG = "TelephonyCapabilities"; 32 33 /** This class is never instantiated. */ TelephonyCapabilities()34 private TelephonyCapabilities() { 35 } 36 37 /** 38 * Return true if the current phone supports ECM ("Emergency Callback 39 * Mode"), which is a feature where the device goes into a special 40 * state for a short period of time after making an outgoing emergency 41 * call. 42 * 43 * (On current devices, that state lasts 5 minutes. It prevents data 44 * usage by other apps, to avoid conflicts with any possible incoming 45 * calls. It also puts up a notification in the status bar, showing a 46 * countdown while ECM is active, and allowing the user to exit ECM.) 47 * 48 * Currently this is assumed to be true for CDMA phones, and false 49 * otherwise. 50 */ supportsEcm(Phone phone)51 public static boolean supportsEcm(Phone phone) { 52 Rlog.d(LOG_TAG, "supportsEcm: Phone type = " + phone.getPhoneType() + 53 " Ims Phone = " + phone.getImsPhone()); 54 return (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA || 55 phone.getImsPhone() != null); 56 } 57 58 /** 59 * Return true if the current phone supports Over The Air Service 60 * Provisioning (OTASP) 61 * 62 * Currently this is assumed to be true for CDMA phones, and false 63 * otherwise. 64 * 65 * TODO: Watch out: this is also highly carrier-specific, since the 66 * OTASP procedure is different from one carrier to the next, *and* the 67 * different carriers may want very different onscreen UI as well. 68 * The procedure may even be different for different devices with the 69 * same carrier. 70 * 71 * So we eventually will need a much more flexible, pluggable design. 72 * This method here is just a placeholder to reduce hardcoded 73 * "if (CDMA)" checks sprinkled throughout the phone app. 74 */ supportsOtasp(Phone phone)75 public static boolean supportsOtasp(Phone phone) { 76 return (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA); 77 } 78 79 /** 80 * Return true if the current phone supports voice message count. 81 * and the count is available 82 * Both CDMA and GSM phones support voice message count 83 */ supportsVoiceMessageCount(Phone phone)84 public static boolean supportsVoiceMessageCount(Phone phone) { 85 return (phone.getVoiceMessageCount() != -1); 86 } 87 88 /** 89 * Return true if this phone allows the user to select which 90 * network to use. 91 * 92 * Currently this is assumed to be true only on GSM phones. 93 * 94 * TODO: Should CDMA phones allow this as well? 95 */ supportsNetworkSelection(Phone phone)96 public static boolean supportsNetworkSelection(Phone phone) { 97 return (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM); 98 } 99 100 /** 101 * Returns a resource ID for a label to use when displaying the 102 * "device id" of the current device. (This is currently used as the 103 * title of the "device id" dialog.) 104 * 105 * This is specific to the device's telephony technology: the device 106 * id is called "IMEI" on GSM phones and "MEID" on CDMA phones. 107 */ getDeviceIdLabel(Phone phone)108 public static int getDeviceIdLabel(Phone phone) { 109 if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM) { 110 return com.android.internal.R.string.imei; 111 } else if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { 112 return com.android.internal.R.string.meid; 113 } else { 114 Rlog.w(LOG_TAG, "getDeviceIdLabel: no known label for phone " 115 + phone.getPhoneName()); 116 return 0; 117 } 118 } 119 120 /** 121 * Return true if the current phone supports the ability to explicitly 122 * manage the state of a conference call (i.e. view the participants, 123 * and hangup or separate individual callers.) 124 * 125 * The in-call screen's "Manage conference" UI is available only on 126 * devices that support this feature. 127 * 128 * Currently this is assumed to be true on GSM phones and false otherwise. 129 */ supportsConferenceCallManagement(Phone phone)130 public static boolean supportsConferenceCallManagement(Phone phone) { 131 return ((phone.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM) 132 || (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_SIP)); 133 } 134 135 /** 136 * Return true if the current phone supports explicit "Hold" and 137 * "Unhold" actions for an active call. (If so, the in-call UI will 138 * provide onscreen "Hold" / "Unhold" buttons.) 139 * 140 * Currently this is assumed to be true on GSM phones and false 141 * otherwise. (In particular, CDMA has no concept of "putting a call 142 * on hold.") 143 */ supportsHoldAndUnhold(Phone phone)144 public static boolean supportsHoldAndUnhold(Phone phone) { 145 return ((phone.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM) 146 || (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_SIP) 147 || (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_IMS)); 148 } 149 150 /** 151 * Return true if the current phone supports distinct "Answer & Hold" 152 * and "Answer & End" behaviors in the call-waiting scenario. If so, 153 * the in-call UI may provide separate buttons or menu items for these 154 * two actions. 155 * 156 * Currently this is assumed to be true on GSM phones and false 157 * otherwise. (In particular, CDMA has no concept of explicitly 158 * managing the background call, or "putting a call on hold.") 159 * 160 * TODO: It might be better to expose this capability in a more 161 * generic form, like maybe "supportsExplicitMultipleLineManagement()" 162 * rather than focusing specifically on call-waiting behavior. 163 */ supportsAnswerAndHold(Phone phone)164 public static boolean supportsAnswerAndHold(Phone phone) { 165 return ((phone.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM) 166 || (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_SIP)); 167 } 168 169 /** 170 * Return true if phones with the given phone type support ADN 171 * (Abbreviated Dialing Numbers). 172 * 173 * Currently this returns true when the phone type is GSM 174 * ({@link PhoneConstants#PHONE_TYPE_GSM}). 175 * 176 * This is using int for an argument for letting apps outside 177 * Phone process access to it, while other methods in this class is 178 * using Phone object. 179 * 180 * TODO: Theoretically phones other than GSM may have the ADN capability. 181 * Consider having better check here, or have better capability as part 182 * of public API, with which the argument should be replaced with 183 * something more appropriate. 184 */ 185 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) supportsAdn(int phoneType)186 public static boolean supportsAdn(int phoneType) { 187 return phoneType == PhoneConstants.PHONE_TYPE_GSM; 188 } 189 190 /** 191 * Returns true if the device can distinguish the phone's dialing state 192 * (Call.State.DIALING/ALERTING) and connected state (Call.State.ACTIVE). 193 * 194 * Currently this returns true for GSM phones as we cannot know when a CDMA 195 * phone has transitioned from dialing/active to connected. 196 */ canDistinguishDialingAndConnected(int phoneType)197 public static boolean canDistinguishDialingAndConnected(int phoneType) { 198 return phoneType == PhoneConstants.PHONE_TYPE_GSM; 199 } 200 201 /** 202 * Returns true if Calling/Data/Messaging features should be checked on this device. 203 */ minimalTelephonyCdmCheck(@onNull FeatureFlags featureFlags)204 public static boolean minimalTelephonyCdmCheck(@NonNull FeatureFlags featureFlags) { 205 // Check SDK version of the vendor partition. 206 final int vendorApiLevel = SystemProperties.getInt( 207 "ro.vendor.api_level", Build.VERSION.DEVICE_INITIAL_SDK_INT); 208 if (vendorApiLevel < Build.VERSION_CODES.VANILLA_ICE_CREAM) return false; 209 210 return featureFlags.minimalTelephonyCdmCheck(); 211 } 212 } 213