1 /* 2 * Copyright (C) 2008 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 android.telephony; 18 19 import static android.content.Context.TELECOM_SERVICE; 20 21 import static com.android.internal.util.Preconditions.checkNotNull; 22 23 import android.Manifest; 24 import android.annotation.CallbackExecutor; 25 import android.annotation.IntDef; 26 import android.annotation.LongDef; 27 import android.annotation.NonNull; 28 import android.annotation.Nullable; 29 import android.annotation.RequiresPermission; 30 import android.annotation.SdkConstant; 31 import android.annotation.SdkConstant.SdkConstantType; 32 import android.annotation.SuppressAutoDoc; 33 import android.annotation.SuppressLint; 34 import android.annotation.SystemApi; 35 import android.annotation.SystemService; 36 import android.annotation.TestApi; 37 import android.annotation.UnsupportedAppUsage; 38 import android.annotation.WorkerThread; 39 import android.app.ActivityThread; 40 import android.app.PendingIntent; 41 import android.content.Context; 42 import android.content.Intent; 43 import android.net.ConnectivityManager; 44 import android.net.NetworkStats; 45 import android.net.Uri; 46 import android.os.AsyncTask; 47 import android.os.BatteryStats; 48 import android.os.Binder; 49 import android.os.Build; 50 import android.os.Bundle; 51 import android.os.Handler; 52 import android.os.PersistableBundle; 53 import android.os.Process; 54 import android.os.RemoteException; 55 import android.os.ResultReceiver; 56 import android.os.ServiceManager; 57 import android.os.SystemProperties; 58 import android.os.WorkSource; 59 import android.provider.Settings.SettingNotFoundException; 60 import android.service.carrier.CarrierIdentifier; 61 import android.telecom.CallScreeningService; 62 import android.telecom.InCallService; 63 import android.telecom.PhoneAccount; 64 import android.telecom.PhoneAccountHandle; 65 import android.telecom.TelecomManager; 66 import android.telephony.VisualVoicemailService.VisualVoicemailTask; 67 import android.telephony.data.ApnSetting; 68 import android.telephony.emergency.EmergencyNumber; 69 import android.telephony.emergency.EmergencyNumber.EmergencyServiceCategories; 70 import android.telephony.ims.aidl.IImsConfig; 71 import android.telephony.ims.aidl.IImsMmTelFeature; 72 import android.telephony.ims.aidl.IImsRcsFeature; 73 import android.telephony.ims.aidl.IImsRegistration; 74 import android.telephony.ims.feature.MmTelFeature; 75 import android.telephony.ims.stub.ImsRegistrationImplBase; 76 import android.text.TextUtils; 77 import android.util.Log; 78 import android.util.Pair; 79 80 import com.android.ims.internal.IImsServiceFeatureCallback; 81 import com.android.internal.annotations.VisibleForTesting; 82 import com.android.internal.telecom.ITelecomService; 83 import com.android.internal.telephony.CellNetworkScanResult; 84 import com.android.internal.telephony.INumberVerificationCallback; 85 import com.android.internal.telephony.IOns; 86 import com.android.internal.telephony.IPhoneSubInfo; 87 import com.android.internal.telephony.ISetOpportunisticDataCallback; 88 import com.android.internal.telephony.ITelephony; 89 import com.android.internal.telephony.ITelephonyRegistry; 90 import com.android.internal.telephony.IUpdateAvailableNetworksCallback; 91 import com.android.internal.telephony.OperatorInfo; 92 import com.android.internal.telephony.PhoneConstants; 93 import com.android.internal.telephony.RILConstants; 94 import com.android.internal.telephony.TelephonyProperties; 95 96 import dalvik.system.VMRuntime; 97 98 import java.io.FileInputStream; 99 import java.io.IOException; 100 import java.lang.annotation.Retention; 101 import java.lang.annotation.RetentionPolicy; 102 import java.util.ArrayList; 103 import java.util.Collections; 104 import java.util.HashMap; 105 import java.util.List; 106 import java.util.Locale; 107 import java.util.Map; 108 import java.util.UUID; 109 import java.util.concurrent.Executor; 110 import java.util.function.Consumer; 111 import java.util.regex.Matcher; 112 import java.util.regex.Pattern; 113 114 /** 115 * Provides access to information about the telephony services on 116 * the device. Applications can use the methods in this class to 117 * determine telephony services and states, as well as to access some 118 * types of subscriber information. Applications can also register 119 * a listener to receive notification of telephony state changes. 120 * <p> 121 * The returned TelephonyManager will use the default subscription for all calls. 122 * To call an API for a specific subscription, use {@link #createForSubscriptionId(int)}. e.g. 123 * <code> 124 * telephonyManager = defaultSubTelephonyManager.createForSubscriptionId(subId); 125 * </code> 126 * <p> 127 * Note that access to some telephony information is 128 * permission-protected. Your application cannot access the protected 129 * information unless it has the appropriate permissions declared in 130 * its manifest file. Where permissions apply, they are noted in the 131 * the methods through which you access the protected information. 132 */ 133 @SystemService(Context.TELEPHONY_SERVICE) 134 public class TelephonyManager { 135 private static final String TAG = "TelephonyManager"; 136 137 /** 138 * The key to use when placing the result of {@link #requestModemActivityInfo(ResultReceiver)} 139 * into the ResultReceiver Bundle. 140 * @hide 141 */ 142 public static final String MODEM_ACTIVITY_RESULT_KEY = 143 BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY; 144 145 /** 146 * The process name of the Phone app as well as many other apps that use this process name, such 147 * as settings and vendor components. 148 * @hide 149 */ 150 public static final String PHONE_PROCESS_NAME = "com.android.phone"; 151 152 /** 153 * The allowed states of Wi-Fi calling. 154 * 155 * @hide 156 */ 157 public interface WifiCallingChoices { 158 /** Always use Wi-Fi calling */ 159 static final int ALWAYS_USE = 0; 160 /** Ask the user whether to use Wi-Fi on every call */ 161 static final int ASK_EVERY_TIME = 1; 162 /** Never use Wi-Fi calling */ 163 static final int NEVER_USE = 2; 164 } 165 166 /** @hide */ 167 @Retention(RetentionPolicy.SOURCE) 168 @IntDef(prefix = {"NETWORK_SELECTION_MODE_"}, 169 value = { 170 NETWORK_SELECTION_MODE_UNKNOWN, 171 NETWORK_SELECTION_MODE_AUTO, 172 NETWORK_SELECTION_MODE_MANUAL}) 173 public @interface NetworkSelectionMode {} 174 175 /** @hide */ 176 public static final int NETWORK_SELECTION_MODE_UNKNOWN = 0; 177 /** @hide */ 178 public static final int NETWORK_SELECTION_MODE_AUTO = 1; 179 /** @hide */ 180 public static final int NETWORK_SELECTION_MODE_MANUAL = 2; 181 182 /** The otaspMode passed to PhoneStateListener#onOtaspChanged */ 183 /** @hide */ 184 static public final int OTASP_UNINITIALIZED = 0; 185 /** @hide */ 186 static public final int OTASP_UNKNOWN = 1; 187 /** @hide */ 188 static public final int OTASP_NEEDED = 2; 189 /** @hide */ 190 static public final int OTASP_NOT_NEEDED = 3; 191 /* OtaUtil has conflict enum 4: OtaUtils.OTASP_FAILURE_SPC_RETRIES */ 192 /** @hide */ 193 static public final int OTASP_SIM_UNPROVISIONED = 5; 194 195 /** @hide */ 196 static public final int KEY_TYPE_EPDG = 1; 197 198 /** @hide */ 199 static public final int KEY_TYPE_WLAN = 2; 200 201 /** 202 * No Single Radio Voice Call Continuity (SRVCC) handover is active. 203 * See TS 23.216 for more information. 204 * @hide 205 */ 206 @SystemApi 207 public static final int SRVCC_STATE_HANDOVER_NONE = -1; 208 209 /** 210 * Single Radio Voice Call Continuity (SRVCC) handover has been started on the network. 211 * See TS 23.216 for more information. 212 * @hide 213 */ 214 @SystemApi 215 public static final int SRVCC_STATE_HANDOVER_STARTED = 0; 216 217 /** 218 * Ongoing Single Radio Voice Call Continuity (SRVCC) handover has successfully completed. 219 * See TS 23.216 for more information. 220 * @hide 221 */ 222 @SystemApi 223 public static final int SRVCC_STATE_HANDOVER_COMPLETED = 1; 224 225 /** 226 * Ongoing Single Radio Voice Call Continuity (SRVCC) handover has failed. 227 * See TS 23.216 for more information. 228 * @hide 229 */ 230 @SystemApi 231 public static final int SRVCC_STATE_HANDOVER_FAILED = 2; 232 233 /** 234 * Ongoing Single Radio Voice Call Continuity (SRVCC) handover has been canceled. 235 * See TS 23.216 for more information. 236 * @hide 237 */ 238 @SystemApi 239 public static final int SRVCC_STATE_HANDOVER_CANCELED = 3; 240 241 /** 242 * A UICC card identifier used if the device does not support the operation. 243 * For example, {@link #getCardIdForDefaultEuicc()} returns this value if the device has no 244 * eUICC, or the eUICC cannot be read. 245 */ 246 public static final int UNSUPPORTED_CARD_ID = -1; 247 248 /** 249 * A UICC card identifier used before the UICC card is loaded. See 250 * {@link #getCardIdForDefaultEuicc()} and {@link UiccCardInfo#getCardId()}. 251 * <p> 252 * Note that once the UICC card is loaded, the card ID may become {@link #UNSUPPORTED_CARD_ID}. 253 */ 254 public static final int UNINITIALIZED_CARD_ID = -2; 255 256 /** @hide */ 257 @Retention(RetentionPolicy.SOURCE) 258 @IntDef(prefix = {"SRVCC_STATE_"}, 259 value = { 260 SRVCC_STATE_HANDOVER_NONE, 261 SRVCC_STATE_HANDOVER_STARTED, 262 SRVCC_STATE_HANDOVER_COMPLETED, 263 SRVCC_STATE_HANDOVER_FAILED, 264 SRVCC_STATE_HANDOVER_CANCELED}) 265 public @interface SrvccState {} 266 267 private final Context mContext; 268 private final int mSubId; 269 @UnsupportedAppUsage 270 private SubscriptionManager mSubscriptionManager; 271 private TelephonyScanManager mTelephonyScanManager; 272 273 private static String multiSimConfig = 274 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 275 276 /** Enum indicating multisim variants 277 * DSDS - Dual SIM Dual Standby 278 * DSDA - Dual SIM Dual Active 279 * TSTS - Triple SIM Triple Standby 280 **/ 281 /** @hide */ 282 public enum MultiSimVariants { 283 @UnsupportedAppUsage 284 DSDS, 285 @UnsupportedAppUsage 286 DSDA, 287 @UnsupportedAppUsage 288 TSTS, 289 @UnsupportedAppUsage 290 UNKNOWN 291 }; 292 293 /** @hide */ 294 @UnsupportedAppUsage TelephonyManager(Context context)295 public TelephonyManager(Context context) { 296 this(context, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID); 297 } 298 299 /** @hide */ 300 @UnsupportedAppUsage TelephonyManager(Context context, int subId)301 public TelephonyManager(Context context, int subId) { 302 mSubId = subId; 303 Context appContext = context.getApplicationContext(); 304 if (appContext != null) { 305 mContext = appContext; 306 } else { 307 mContext = context; 308 } 309 mSubscriptionManager = SubscriptionManager.from(mContext); 310 } 311 312 /** @hide */ 313 @UnsupportedAppUsage TelephonyManager()314 private TelephonyManager() { 315 mContext = null; 316 mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 317 } 318 319 private static TelephonyManager sInstance = new TelephonyManager(); 320 321 /** @hide 322 /* @deprecated - use getSystemService as described above */ 323 @Deprecated 324 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getDefault()325 public static TelephonyManager getDefault() { 326 return sInstance; 327 } 328 getOpPackageName()329 private String getOpPackageName() { 330 // For legacy reasons the TelephonyManager has API for getting 331 // a static instance with no context set preventing us from 332 // getting the op package name. As a workaround we do a best 333 // effort and get the context from the current activity thread. 334 if (mContext != null) { 335 return mContext.getOpPackageName(); 336 } 337 return ActivityThread.currentOpPackageName(); 338 } 339 isSystemProcess()340 private boolean isSystemProcess() { 341 return Process.myUid() == Process.SYSTEM_UID; 342 } 343 344 /** 345 * Returns the multi SIM variant 346 * Returns DSDS for Dual SIM Dual Standby 347 * Returns DSDA for Dual SIM Dual Active 348 * Returns TSTS for Triple SIM Triple Standby 349 * Returns UNKNOWN for others 350 */ 351 /** {@hide} */ 352 @UnsupportedAppUsage getMultiSimConfiguration()353 public MultiSimVariants getMultiSimConfiguration() { 354 String mSimConfig = 355 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 356 if (mSimConfig.equals("dsds")) { 357 return MultiSimVariants.DSDS; 358 } else if (mSimConfig.equals("dsda")) { 359 return MultiSimVariants.DSDA; 360 } else if (mSimConfig.equals("tsts")) { 361 return MultiSimVariants.TSTS; 362 } else { 363 return MultiSimVariants.UNKNOWN; 364 } 365 } 366 367 368 /** 369 * Returns the number of phones available. 370 * Returns 0 if none of voice, sms, data is not supported 371 * Returns 1 for Single standby mode (Single SIM functionality) 372 * Returns 2 for Dual standby mode.(Dual SIM functionality) 373 * Returns 3 for Tri standby mode.(Tri SIM functionality) 374 */ getPhoneCount()375 public int getPhoneCount() { 376 int phoneCount = 1; 377 switch (getMultiSimConfiguration()) { 378 case UNKNOWN: 379 ConnectivityManager cm = mContext == null ? null : (ConnectivityManager) mContext 380 .getSystemService(Context.CONNECTIVITY_SERVICE); 381 // check for voice and data support, 0 if not supported 382 if (!isVoiceCapable() && !isSmsCapable() && cm != null 383 && !cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) { 384 phoneCount = 0; 385 } else { 386 phoneCount = 1; 387 } 388 break; 389 case DSDS: 390 case DSDA: 391 phoneCount = PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM; 392 break; 393 case TSTS: 394 phoneCount = PhoneConstants.MAX_PHONE_COUNT_TRI_SIM; 395 break; 396 } 397 return phoneCount; 398 } 399 400 /** {@hide} */ 401 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) from(Context context)402 public static TelephonyManager from(Context context) { 403 return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 404 } 405 406 /** 407 * Create a new TelephonyManager object pinned to the given subscription ID. 408 * 409 * @return a TelephonyManager that uses the given subId for all calls. 410 */ createForSubscriptionId(int subId)411 public TelephonyManager createForSubscriptionId(int subId) { 412 // Don't reuse any TelephonyManager objects. 413 return new TelephonyManager(mContext, subId); 414 } 415 416 /** 417 * Create a new TelephonyManager object pinned to the subscription ID associated with the given 418 * phone account. 419 * 420 * @return a TelephonyManager that uses the given phone account for all calls, or {@code null} 421 * if the phone account does not correspond to a valid subscription ID. 422 */ 423 @Nullable createForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle)424 public TelephonyManager createForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) { 425 int subId = getSubIdForPhoneAccountHandle(phoneAccountHandle); 426 if (!SubscriptionManager.isValidSubscriptionId(subId)) { 427 return null; 428 } 429 return new TelephonyManager(mContext, subId); 430 } 431 432 /** {@hide} */ 433 @UnsupportedAppUsage isMultiSimEnabled()434 public boolean isMultiSimEnabled() { 435 return (multiSimConfig.equals("dsds") || multiSimConfig.equals("dsda") || 436 multiSimConfig.equals("tsts")); 437 } 438 439 // 440 // Broadcast Intent actions 441 // 442 443 /** 444 * Broadcast intent action indicating that the call state 445 * on the device has changed. 446 * 447 * <p> 448 * The {@link #EXTRA_STATE} extra indicates the new call state. 449 * If a receiving app has {@link android.Manifest.permission#READ_CALL_LOG} permission, a second 450 * extra {@link #EXTRA_INCOMING_NUMBER} provides the phone number for incoming and outgoing 451 * calls as a String. 452 * <p> 453 * If the receiving app has 454 * {@link android.Manifest.permission#READ_CALL_LOG} and 455 * {@link android.Manifest.permission#READ_PHONE_STATE} permission, it will receive the 456 * broadcast twice; one with the {@link #EXTRA_INCOMING_NUMBER} populated with the phone number, 457 * and another with it blank. Due to the nature of broadcasts, you cannot assume the order 458 * in which these broadcasts will arrive, however you are guaranteed to receive two in this 459 * case. Apps which are interested in the {@link #EXTRA_INCOMING_NUMBER} can ignore the 460 * broadcasts where {@link #EXTRA_INCOMING_NUMBER} is not present in the extras (e.g. where 461 * {@link Intent#hasExtra(String)} returns {@code false}). 462 * <p class="note"> 463 * This was a {@link android.content.Context#sendStickyBroadcast sticky} 464 * broadcast in version 1.0, but it is no longer sticky. 465 * Instead, use {@link #getCallState} to synchronously query the current call state. 466 * 467 * @see #EXTRA_STATE 468 * @see #EXTRA_INCOMING_NUMBER 469 * @see #getCallState 470 */ 471 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 472 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 473 public static final String ACTION_PHONE_STATE_CHANGED = 474 "android.intent.action.PHONE_STATE"; 475 476 /** 477 * The Phone app sends this intent when a user opts to respond-via-message during an incoming 478 * call. By default, the device's default SMS app consumes this message and sends a text message 479 * to the caller. A third party app can also provide this functionality by consuming this Intent 480 * with a {@link android.app.Service} and sending the message using its own messaging system. 481 * <p>The intent contains a URI (available from {@link android.content.Intent#getData}) 482 * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:}, 483 * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the 484 * same way: the path part of the URI contains the recipient's phone number or a comma-separated 485 * set of phone numbers if there are multiple recipients. For example, {@code 486 * smsto:2065551234}.</p> 487 * 488 * <p>The intent may also contain extras for the message text (in {@link 489 * android.content.Intent#EXTRA_TEXT}) and a message subject 490 * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p> 491 * 492 * <p class="note"><strong>Note:</strong> 493 * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service} 494 * that requires the 495 * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p> 496 * <p>For example, the service that receives this intent can be declared in the manifest file 497 * with an intent filter like this:</p> 498 * <pre> 499 * <!-- Service that delivers SMS messages received from the phone "quick response" --> 500 * <service android:name=".HeadlessSmsSendService" 501 * android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" 502 * android:exported="true" > 503 * <intent-filter> 504 * <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /> 505 * <category android:name="android.intent.category.DEFAULT" /> 506 * <data android:scheme="sms" /> 507 * <data android:scheme="smsto" /> 508 * <data android:scheme="mms" /> 509 * <data android:scheme="mmsto" /> 510 * </intent-filter> 511 * </service></pre> 512 * <p> 513 * Output: nothing. 514 */ 515 @SdkConstant(SdkConstantType.SERVICE_ACTION) 516 public static final String ACTION_RESPOND_VIA_MESSAGE = 517 "android.intent.action.RESPOND_VIA_MESSAGE"; 518 519 /** 520 * The emergency dialer may choose to present activities with intent filters for this 521 * action as emergency assistance buttons that launch the activity when clicked. 522 * 523 * @hide 524 */ 525 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 526 public static final String ACTION_EMERGENCY_ASSISTANCE = 527 "android.telephony.action.EMERGENCY_ASSISTANCE"; 528 529 /** 530 * A boolean meta-data value indicating whether the voicemail settings should be hidden in the 531 * call settings page launched by 532 * {@link android.telecom.TelecomManager#ACTION_SHOW_CALL_SETTINGS}. 533 * Dialer implementations (see {@link android.telecom.TelecomManager#getDefaultDialerPackage()}) 534 * which would also like to manage voicemail settings should set this meta-data to {@code true} 535 * in the manifest registration of their application. 536 * 537 * @see android.telecom.TelecomManager#ACTION_SHOW_CALL_SETTINGS 538 * @see #ACTION_CONFIGURE_VOICEMAIL 539 * @see #EXTRA_HIDE_PUBLIC_SETTINGS 540 */ 541 public static final String METADATA_HIDE_VOICEMAIL_SETTINGS_MENU = 542 "android.telephony.HIDE_VOICEMAIL_SETTINGS_MENU"; 543 544 /** 545 * Open the voicemail settings activity to make changes to voicemail configuration. 546 * 547 * <p> 548 * The {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra indicates which {@link PhoneAccountHandle} to 549 * configure voicemail. 550 * The {@link #EXTRA_HIDE_PUBLIC_SETTINGS} hides settings the dialer will modify through public 551 * API if set. 552 * 553 * @see #EXTRA_PHONE_ACCOUNT_HANDLE 554 * @see #EXTRA_HIDE_PUBLIC_SETTINGS 555 */ 556 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 557 public static final String ACTION_CONFIGURE_VOICEMAIL = 558 "android.telephony.action.CONFIGURE_VOICEMAIL"; 559 560 /** 561 * The boolean value indicating whether the voicemail settings activity launched by {@link 562 * #ACTION_CONFIGURE_VOICEMAIL} should hide settings accessible through public API. This is 563 * used by dialer implementations which provides their own voicemail settings UI, but still 564 * needs to expose device specific voicemail settings to the user. 565 * 566 * @see #ACTION_CONFIGURE_VOICEMAIL 567 * @see #METADATA_HIDE_VOICEMAIL_SETTINGS_MENU 568 */ 569 public static final String EXTRA_HIDE_PUBLIC_SETTINGS = 570 "android.telephony.extra.HIDE_PUBLIC_SETTINGS"; 571 572 /** 573 * @hide 574 */ 575 public static final boolean EMERGENCY_ASSISTANCE_ENABLED = true; 576 577 /** 578 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 579 * for a String containing the new call state. 580 * 581 * <p class="note"> 582 * Retrieve with 583 * {@link android.content.Intent#getStringExtra(String)}. 584 * 585 * @see #EXTRA_STATE_IDLE 586 * @see #EXTRA_STATE_RINGING 587 * @see #EXTRA_STATE_OFFHOOK 588 */ 589 public static final String EXTRA_STATE = PhoneConstants.STATE_KEY; 590 591 /** 592 * Value used with {@link #EXTRA_STATE} corresponding to 593 * {@link #CALL_STATE_IDLE}. 594 */ 595 public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString(); 596 597 /** 598 * Value used with {@link #EXTRA_STATE} corresponding to 599 * {@link #CALL_STATE_RINGING}. 600 */ 601 public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString(); 602 603 /** 604 * Value used with {@link #EXTRA_STATE} corresponding to 605 * {@link #CALL_STATE_OFFHOOK}. 606 */ 607 public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString(); 608 609 /** 610 * Extra key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 611 * for a String containing the incoming or outgoing phone number. 612 * <p> 613 * This extra is only populated for receivers of the {@link #ACTION_PHONE_STATE_CHANGED} 614 * broadcast which have been granted the {@link android.Manifest.permission#READ_CALL_LOG} and 615 * {@link android.Manifest.permission#READ_PHONE_STATE} permissions. 616 * <p> 617 * For incoming calls, the phone number is only guaranteed to be populated when the 618 * {@link #EXTRA_STATE} changes from {@link #EXTRA_STATE_IDLE} to {@link #EXTRA_STATE_RINGING}. 619 * If the incoming caller is from an unknown number, the extra will be populated with an empty 620 * string. 621 * For outgoing calls, the phone number is only guaranteed to be populated when the 622 * {@link #EXTRA_STATE} changes from {@link #EXTRA_STATE_IDLE} to {@link #EXTRA_STATE_OFFHOOK}. 623 * <p class="note"> 624 * Retrieve with 625 * {@link android.content.Intent#getStringExtra(String)}. 626 * <p> 627 * 628 * @deprecated Companion apps for wearable devices should use the {@link InCallService} API 629 * to retrieve the phone number for calls instead. Apps performing call screening should use 630 * the {@link CallScreeningService} API instead. 631 */ 632 @Deprecated 633 public static final String EXTRA_INCOMING_NUMBER = "incoming_number"; 634 635 /** 636 * Broadcast intent action indicating that a precise call state 637 * (cellular) on the device has changed. 638 * 639 * <p> 640 * The {@link #EXTRA_RINGING_CALL_STATE} extra indicates the ringing call state. 641 * The {@link #EXTRA_FOREGROUND_CALL_STATE} extra indicates the foreground call state. 642 * The {@link #EXTRA_BACKGROUND_CALL_STATE} extra indicates the background call state. 643 * 644 * <p class="note"> 645 * Requires the READ_PRECISE_PHONE_STATE permission. 646 * 647 * @see #EXTRA_RINGING_CALL_STATE 648 * @see #EXTRA_FOREGROUND_CALL_STATE 649 * @see #EXTRA_BACKGROUND_CALL_STATE 650 * 651 * <p class="note"> 652 * Requires the READ_PRECISE_PHONE_STATE permission. 653 * @deprecated use {@link PhoneStateListener#LISTEN_PRECISE_CALL_STATE} instead 654 * @hide 655 */ 656 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 657 public static final String ACTION_PRECISE_CALL_STATE_CHANGED = 658 "android.intent.action.PRECISE_CALL_STATE"; 659 660 /** 661 * Broadcast intent action indicating that call disconnect cause has changed. 662 * 663 * <p> 664 * The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause. 665 * The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause. 666 * 667 * <p class="note"> 668 * Requires the READ_PRECISE_PHONE_STATE permission. 669 * 670 * @see #EXTRA_DISCONNECT_CAUSE 671 * @see #EXTRA_PRECISE_DISCONNECT_CAUSE 672 * 673 * @hide 674 */ 675 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 676 public static final String ACTION_CALL_DISCONNECT_CAUSE_CHANGED = 677 "android.intent.action.CALL_DISCONNECT_CAUSE"; 678 679 /** 680 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast and 681 * {@link PhoneStateListener#onPreciseCallStateChanged(PreciseCallState)} for an integer 682 * containing the state of the current ringing call. 683 * 684 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 685 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 686 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 687 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 688 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 689 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 690 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 691 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 692 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 693 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 694 * 695 * <p class="note"> 696 * Retrieve with 697 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 698 * 699 * @hide 700 */ 701 public static final String EXTRA_RINGING_CALL_STATE = "ringing_state"; 702 703 /** 704 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast and 705 * {@link PhoneStateListener#onPreciseCallStateChanged(PreciseCallState)} for an integer 706 * containing the state of the current foreground call. 707 * 708 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 709 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 710 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 711 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 712 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 713 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 714 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 715 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 716 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 717 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 718 * 719 * <p class="note"> 720 * Retrieve with 721 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 722 * 723 * @hide 724 */ 725 public static final String EXTRA_FOREGROUND_CALL_STATE = "foreground_state"; 726 727 /** 728 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast and 729 * {@link PhoneStateListener#onPreciseCallStateChanged(PreciseCallState)} for an integer 730 * containing the state of the current background call. 731 * 732 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 733 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 734 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 735 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 736 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 737 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 738 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 739 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 740 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 741 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 742 * 743 * <p class="note"> 744 * Retrieve with 745 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 746 * 747 * @hide 748 */ 749 public static final String EXTRA_BACKGROUND_CALL_STATE = "background_state"; 750 751 /** 752 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast and 753 * {@link PhoneStateListener#onPreciseCallStateChanged(PreciseCallState)} for an integer 754 * containing the disconnect cause. 755 * 756 * @see DisconnectCause 757 * 758 * <p class="note"> 759 * Retrieve with 760 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 761 * 762 * @hide 763 */ 764 public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause"; 765 766 /** 767 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast and 768 * {@link PhoneStateListener#onPreciseCallStateChanged(PreciseCallState)} for an integer 769 * containing the disconnect cause provided by the RIL. 770 * 771 * @see PreciseDisconnectCause 772 * 773 * <p class="note"> 774 * Retrieve with 775 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 776 * 777 * @hide 778 */ 779 public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause"; 780 781 /** 782 * Broadcast intent action indicating a data connection has changed, 783 * providing precise information about the connection. 784 * 785 * <p> 786 * The {@link #EXTRA_DATA_STATE} extra indicates the connection state. 787 * The {@link #EXTRA_DATA_NETWORK_TYPE} extra indicates the connection network type. 788 * The {@link #EXTRA_DATA_APN_TYPE} extra indicates the APN type. 789 * The {@link #EXTRA_DATA_APN} extra indicates the APN. 790 * The {@link #EXTRA_DATA_IFACE_PROPERTIES} extra indicates the connection interface. 791 * The {@link #EXTRA_DATA_FAILURE_CAUSE} extra indicates the connection fail cause. 792 * 793 * <p class="note"> 794 * Requires the READ_PRECISE_PHONE_STATE permission. 795 * 796 * @see #EXTRA_DATA_STATE 797 * @see #EXTRA_DATA_NETWORK_TYPE 798 * @see #EXTRA_DATA_APN_TYPE 799 * @see #EXTRA_DATA_APN 800 * @see #EXTRA_DATA_IFACE 801 * @see #EXTRA_DATA_FAILURE_CAUSE 802 * @hide 803 * 804 * @deprecated If the app is running in the background, it won't be able to receive this 805 * broadcast. Apps should use ConnectivityManager {@link #registerNetworkCallback( 806 * android.net.NetworkRequest, ConnectivityManager.NetworkCallback)} to listen for network 807 * changes. 808 */ 809 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 810 @Deprecated 811 @UnsupportedAppUsage 812 public static final String ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED = 813 "android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED"; 814 815 /** 816 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 817 * for an integer containing the state of the current data connection. 818 * 819 * @see TelephonyManager#DATA_UNKNOWN 820 * @see TelephonyManager#DATA_DISCONNECTED 821 * @see TelephonyManager#DATA_CONNECTING 822 * @see TelephonyManager#DATA_CONNECTED 823 * @see TelephonyManager#DATA_SUSPENDED 824 * 825 * <p class="note"> 826 * Retrieve with 827 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 828 * 829 * @hide 830 */ 831 public static final String EXTRA_DATA_STATE = PhoneConstants.STATE_KEY; 832 833 /** 834 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 835 * for an integer containing the network type. 836 * 837 * @see TelephonyManager#NETWORK_TYPE_UNKNOWN 838 * @see TelephonyManager#NETWORK_TYPE_GPRS 839 * @see TelephonyManager#NETWORK_TYPE_EDGE 840 * @see TelephonyManager#NETWORK_TYPE_UMTS 841 * @see TelephonyManager#NETWORK_TYPE_CDMA 842 * @see TelephonyManager#NETWORK_TYPE_EVDO_0 843 * @see TelephonyManager#NETWORK_TYPE_EVDO_A 844 * @see TelephonyManager#NETWORK_TYPE_1xRTT 845 * @see TelephonyManager#NETWORK_TYPE_HSDPA 846 * @see TelephonyManager#NETWORK_TYPE_HSUPA 847 * @see TelephonyManager#NETWORK_TYPE_HSPA 848 * @see TelephonyManager#NETWORK_TYPE_IDEN 849 * @see TelephonyManager#NETWORK_TYPE_EVDO_B 850 * @see TelephonyManager#NETWORK_TYPE_LTE 851 * @see TelephonyManager#NETWORK_TYPE_EHRPD 852 * @see TelephonyManager#NETWORK_TYPE_HSPAP 853 * @see TelephonyManager#NETWORK_TYPE_NR 854 * 855 * <p class="note"> 856 * Retrieve with 857 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 858 * 859 * @hide 860 */ 861 public static final String EXTRA_DATA_NETWORK_TYPE = PhoneConstants.DATA_NETWORK_TYPE_KEY; 862 863 /** 864 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 865 * for an String containing the data APN type. 866 * 867 * <p class="note"> 868 * Retrieve with 869 * {@link android.content.Intent#getStringExtra(String name)}. 870 * 871 * @hide 872 */ 873 public static final String EXTRA_DATA_APN_TYPE = PhoneConstants.DATA_APN_TYPE_KEY; 874 875 /** 876 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 877 * for an String containing the data APN. 878 * 879 * <p class="note"> 880 * Retrieve with 881 * {@link android.content.Intent#getStringExtra(String name)}. 882 * 883 * @hide 884 */ 885 public static final String EXTRA_DATA_APN = PhoneConstants.DATA_APN_KEY; 886 887 /** 888 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 889 * for an String representation of the data interface. 890 * 891 * <p class="note"> 892 * Retrieve with 893 * {@link android.content.Intent#getParcelableExtra(String name)}. 894 * 895 * @hide 896 */ 897 public static final String EXTRA_DATA_LINK_PROPERTIES_KEY = PhoneConstants.DATA_LINK_PROPERTIES_KEY; 898 899 /** 900 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 901 * for the data connection fail cause. 902 * 903 * <p class="note"> 904 * Retrieve with 905 * {@link android.content.Intent#getStringExtra(String name)}. 906 * 907 * @hide 908 */ 909 public static final String EXTRA_DATA_FAILURE_CAUSE = PhoneConstants.DATA_FAILURE_CAUSE_KEY; 910 911 /** 912 * Broadcast intent action for letting the default dialer to know to show voicemail 913 * notification. 914 * 915 * <p> 916 * The {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra indicates which {@link PhoneAccountHandle} the 917 * voicemail is received on. 918 * The {@link #EXTRA_NOTIFICATION_COUNT} extra indicates the total numbers of unheard 919 * voicemails. 920 * The {@link #EXTRA_VOICEMAIL_NUMBER} extra indicates the voicemail number if available. 921 * The {@link #EXTRA_CALL_VOICEMAIL_INTENT} extra is a {@link android.app.PendingIntent} that 922 * will call the voicemail number when sent. This extra will be empty if the voicemail number 923 * is not set, and {@link #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT} will be set instead. 924 * The {@link #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT} extra is a 925 * {@link android.app.PendingIntent} that will launch the voicemail settings. This extra is only 926 * available when the voicemail number is not set. 927 * The {@link #EXTRA_IS_REFRESH} extra indicates whether the notification is a refresh or a new 928 * notification. 929 * 930 * @see #EXTRA_PHONE_ACCOUNT_HANDLE 931 * @see #EXTRA_NOTIFICATION_COUNT 932 * @see #EXTRA_VOICEMAIL_NUMBER 933 * @see #EXTRA_CALL_VOICEMAIL_INTENT 934 * @see #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT 935 * @see #EXTRA_IS_REFRESH 936 */ 937 public static final String ACTION_SHOW_VOICEMAIL_NOTIFICATION = 938 "android.telephony.action.SHOW_VOICEMAIL_NOTIFICATION"; 939 940 /** 941 * The extra used with an {@link #ACTION_CONFIGURE_VOICEMAIL} and 942 * {@link #ACTION_SHOW_VOICEMAIL_NOTIFICATION} {@code Intent} to specify the 943 * {@link PhoneAccountHandle} the configuration or notification is for. 944 * <p class="note"> 945 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}. 946 */ 947 public static final String EXTRA_PHONE_ACCOUNT_HANDLE = 948 "android.telephony.extra.PHONE_ACCOUNT_HANDLE"; 949 950 /** 951 * The number of voice messages associated with the notification. 952 */ 953 public static final String EXTRA_NOTIFICATION_COUNT = 954 "android.telephony.extra.NOTIFICATION_COUNT"; 955 956 /** 957 * The voicemail number. 958 */ 959 public static final String EXTRA_VOICEMAIL_NUMBER = 960 "android.telephony.extra.VOICEMAIL_NUMBER"; 961 962 /** 963 * The intent to call voicemail. 964 */ 965 public static final String EXTRA_CALL_VOICEMAIL_INTENT = 966 "android.telephony.extra.CALL_VOICEMAIL_INTENT"; 967 968 /** 969 * The intent to launch voicemail settings. 970 */ 971 public static final String EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT = 972 "android.telephony.extra.LAUNCH_VOICEMAIL_SETTINGS_INTENT"; 973 974 /** 975 * Boolean value representing whether the {@link 976 * TelephonyManager#ACTION_SHOW_VOICEMAIL_NOTIFICATION} is new or a refresh of an existing 977 * notification. Notification refresh happens after reboot or connectivity changes. The user has 978 * already been notified for the voicemail so it should not alert the user, and should not be 979 * shown again if the user has dismissed it. 980 */ 981 public static final String EXTRA_IS_REFRESH = "android.telephony.extra.IS_REFRESH"; 982 983 /** 984 * {@link android.telecom.Connection} event used to indicate that an IMS call has be 985 * successfully handed over from WIFI to LTE. 986 * <p> 987 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 988 * The {@link Bundle} parameter is expected to be null when this connection event is used. 989 * @hide 990 */ 991 public static final String EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE = 992 "android.telephony.event.EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE"; 993 994 /** 995 * {@link android.telecom.Connection} event used to indicate that an IMS call has be 996 * successfully handed over from LTE to WIFI. 997 * <p> 998 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 999 * The {@link Bundle} parameter is expected to be null when this connection event is used. 1000 * @hide 1001 */ 1002 public static final String EVENT_HANDOVER_VIDEO_FROM_LTE_TO_WIFI = 1003 "android.telephony.event.EVENT_HANDOVER_VIDEO_FROM_LTE_TO_WIFI"; 1004 1005 /** 1006 * {@link android.telecom.Connection} event used to indicate that an IMS call failed to be 1007 * handed over from LTE to WIFI. 1008 * <p> 1009 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1010 * The {@link Bundle} parameter is expected to be null when this connection event is used. 1011 * @hide 1012 */ 1013 public static final String EVENT_HANDOVER_TO_WIFI_FAILED = 1014 "android.telephony.event.EVENT_HANDOVER_TO_WIFI_FAILED"; 1015 1016 /** 1017 * {@link android.telecom.Connection} event used to indicate that a video call was downgraded to 1018 * audio because the data limit was reached. 1019 * <p> 1020 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1021 * The {@link Bundle} parameter is expected to be null when this connection event is used. 1022 * @hide 1023 */ 1024 public static final String EVENT_DOWNGRADE_DATA_LIMIT_REACHED = 1025 "android.telephony.event.EVENT_DOWNGRADE_DATA_LIMIT_REACHED"; 1026 1027 /** 1028 * {@link android.telecom.Connection} event used to indicate that a video call was downgraded to 1029 * audio because the data was disabled. 1030 * <p> 1031 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1032 * The {@link Bundle} parameter is expected to be null when this connection event is used. 1033 * @hide 1034 */ 1035 public static final String EVENT_DOWNGRADE_DATA_DISABLED = 1036 "android.telephony.event.EVENT_DOWNGRADE_DATA_DISABLED"; 1037 1038 /** 1039 * {@link android.telecom.Connection} event used to indicate that the InCall UI should notify 1040 * the user when an international call is placed while on WFC only. 1041 * <p> 1042 * Used when the carrier config value 1043 * {@link CarrierConfigManager#KEY_NOTIFY_INTERNATIONAL_CALL_ON_WFC_BOOL} is true, the device 1044 * is on WFC (VoLTE not available) and an international number is dialed. 1045 * <p> 1046 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1047 * The {@link Bundle} parameter is expected to be null when this connection event is used. 1048 * @hide 1049 */ 1050 public static final String EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC = 1051 "android.telephony.event.EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC"; 1052 1053 /** 1054 * {@link android.telecom.Connection} event used to indicate that an outgoing call has been 1055 * forwarded to another number. 1056 * <p> 1057 * Sent in response to an IMS supplementary service notification indicating the call has been 1058 * forwarded. 1059 * <p> 1060 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1061 * The {@link Bundle} parameter is expected to be null when this connection event is used. 1062 * @hide 1063 */ 1064 public static final String EVENT_CALL_FORWARDED = 1065 "android.telephony.event.EVENT_CALL_FORWARDED"; 1066 1067 /** 1068 * {@link android.telecom.Connection} event used to indicate that a supplementary service 1069 * notification has been received. 1070 * <p> 1071 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1072 * The {@link Bundle} parameter is expected to include the following extras: 1073 * <ul> 1074 * <li>{@link #EXTRA_NOTIFICATION_TYPE} - the notification type.</li> 1075 * <li>{@link #EXTRA_NOTIFICATION_CODE} - the notification code.</li> 1076 * <li>{@link #EXTRA_NOTIFICATION_MESSAGE} - human-readable message associated with the 1077 * supplementary service notification.</li> 1078 * </ul> 1079 * @hide 1080 */ 1081 public static final String EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION = 1082 "android.telephony.event.EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION"; 1083 1084 /** 1085 * Integer extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} which indicates 1086 * the type of supplementary service notification which occurred. 1087 * Will be either 1088 * {@link com.android.internal.telephony.gsm.SuppServiceNotification#NOTIFICATION_TYPE_CODE_1} 1089 * or 1090 * {@link com.android.internal.telephony.gsm.SuppServiceNotification#NOTIFICATION_TYPE_CODE_2} 1091 * <p> 1092 * Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event. 1093 * @hide 1094 */ 1095 public static final String EXTRA_NOTIFICATION_TYPE = 1096 "android.telephony.extra.NOTIFICATION_TYPE"; 1097 1098 /** 1099 * Integer extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} which indicates 1100 * the supplementary service notification which occurred. 1101 * <p> 1102 * Depending on the {@link #EXTRA_NOTIFICATION_TYPE}, the code will be one of the {@code CODE_*} 1103 * codes defined in {@link com.android.internal.telephony.gsm.SuppServiceNotification}. 1104 * <p> 1105 * Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event. 1106 * @hide 1107 */ 1108 public static final String EXTRA_NOTIFICATION_CODE = 1109 "android.telephony.extra.NOTIFICATION_CODE"; 1110 1111 /** 1112 * {@link CharSequence} extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} 1113 * which contains a human-readable message which can be displayed to the user for the 1114 * supplementary service notification. 1115 * <p> 1116 * Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event. 1117 * @hide 1118 */ 1119 public static final String EXTRA_NOTIFICATION_MESSAGE = 1120 "android.telephony.extra.NOTIFICATION_MESSAGE"; 1121 1122 /* Visual voicemail protocols */ 1123 1124 /** 1125 * The OMTP protocol. 1126 */ 1127 public static final String VVM_TYPE_OMTP = "vvm_type_omtp"; 1128 1129 /** 1130 * A flavor of OMTP protocol with a different mobile originated (MO) format 1131 */ 1132 public static final String VVM_TYPE_CVVM = "vvm_type_cvvm"; 1133 1134 /** 1135 * Key in bundle returned by {@link #getVisualVoicemailPackageName()}, indicating whether visual 1136 * voicemail was enabled or disabled by the user. If the user never explicitly changed this 1137 * setting, this key will not exist. 1138 * 1139 * @see #getVisualVoicemailSettings() 1140 * @hide 1141 */ 1142 @SystemApi 1143 public static final String EXTRA_VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL = 1144 "android.telephony.extra.VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL"; 1145 1146 /** 1147 * Key in bundle returned by {@link #getVisualVoicemailPackageName()}, indicating the voicemail 1148 * access PIN scrambled during the auto provisioning process. The user is expected to reset 1149 * their PIN if this value is not {@code null}. 1150 * 1151 * @see #getVisualVoicemailSettings() 1152 * @hide 1153 */ 1154 @SystemApi 1155 public static final String EXTRA_VOICEMAIL_SCRAMBLED_PIN_STRING = 1156 "android.telephony.extra.VOICEMAIL_SCRAMBLED_PIN_STRING"; 1157 1158 /** 1159 * @hide 1160 */ 1161 public static final String USSD_RESPONSE = "USSD_RESPONSE"; 1162 1163 /** 1164 * USSD return code success. 1165 * @hide 1166 */ 1167 public static final int USSD_RETURN_SUCCESS = 100; 1168 1169 /** 1170 * Failed code returned when the mobile network has failed to complete a USSD request. 1171 * <p> 1172 * Returned via {@link TelephonyManager.UssdResponseCallback#onReceiveUssdResponseFailed( 1173 * TelephonyManager, String, int)}. 1174 */ 1175 public static final int USSD_RETURN_FAILURE = -1; 1176 1177 /** 1178 * Failure code returned when a USSD request has failed to execute because the Telephony 1179 * service is unavailable. 1180 * <p> 1181 * Returned via {@link TelephonyManager.UssdResponseCallback#onReceiveUssdResponseFailed( 1182 * TelephonyManager, String, int)}. 1183 */ 1184 public static final int USSD_ERROR_SERVICE_UNAVAIL = -2; 1185 1186 /** 1187 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which leaves the roaming 1188 * mode set to the radio default or to the user's preference if they've indicated one. 1189 */ 1190 public static final int CDMA_ROAMING_MODE_RADIO_DEFAULT = -1; 1191 /** 1192 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which only permits 1193 * connections on home networks. 1194 */ 1195 public static final int CDMA_ROAMING_MODE_HOME = 0; 1196 /** 1197 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which permits roaming on 1198 * affiliated networks. 1199 */ 1200 public static final int CDMA_ROAMING_MODE_AFFILIATED = 1; 1201 /** 1202 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which permits roaming on 1203 * any network. 1204 */ 1205 public static final int CDMA_ROAMING_MODE_ANY = 2; 1206 1207 /** 1208 * An unknown carrier id. It could either be subscription unavailable or the subscription 1209 * carrier cannot be recognized. Unrecognized carriers here means 1210 * {@link #getSimOperator() MCC+MNC} cannot be identified. 1211 */ 1212 public static final int UNKNOWN_CARRIER_ID = -1; 1213 1214 /** 1215 * An unknown carrier id list version. 1216 * @hide 1217 */ 1218 @TestApi 1219 public static final int UNKNOWN_CARRIER_ID_LIST_VERSION = -1; 1220 1221 /** 1222 * Broadcast Action: The subscription carrier identity has changed. 1223 * This intent could be sent on the following events: 1224 * <ul> 1225 * <li>Subscription absent. Carrier identity could change from a valid id to 1226 * {@link TelephonyManager#UNKNOWN_CARRIER_ID}.</li> 1227 * <li>Subscription loaded. Carrier identity could change from 1228 * {@link TelephonyManager#UNKNOWN_CARRIER_ID} to a valid id.</li> 1229 * <li>The subscription carrier is recognized after a remote update.</li> 1230 * </ul> 1231 * The intent will have the following extra values: 1232 * <ul> 1233 * <li>{@link #EXTRA_CARRIER_ID} The up-to-date carrier id of the current subscription id. 1234 * </li> 1235 * <li>{@link #EXTRA_CARRIER_NAME} The up-to-date carrier name of the current subscription. 1236 * </li> 1237 * <li>{@link #EXTRA_SUBSCRIPTION_ID} The subscription id associated with the changed carrier 1238 * identity. 1239 * </li> 1240 * </ul> 1241 * <p class="note">This is a protected intent that can only be sent by the system. 1242 */ 1243 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1244 public static final String ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED = 1245 "android.telephony.action.SUBSCRIPTION_CARRIER_IDENTITY_CHANGED"; 1246 1247 /** 1248 * An int extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} which indicates 1249 * the updated carrier id returned by {@link TelephonyManager#getSimCarrierId()}. 1250 * <p>Will be {@link TelephonyManager#UNKNOWN_CARRIER_ID} if the subscription is unavailable or 1251 * the carrier cannot be identified. 1252 */ 1253 public static final String EXTRA_CARRIER_ID = "android.telephony.extra.CARRIER_ID"; 1254 1255 /** 1256 * An string extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} which 1257 * indicates the updated carrier name of the current subscription. 1258 * @see TelephonyManager#getSimCarrierIdName() 1259 * <p>Carrier name is a user-facing name of the carrier id {@link #EXTRA_CARRIER_ID}, 1260 * usually the brand name of the subsidiary (e.g. T-Mobile). 1261 */ 1262 public static final String EXTRA_CARRIER_NAME = "android.telephony.extra.CARRIER_NAME"; 1263 1264 /** 1265 * Broadcast Action: The subscription specific carrier identity has changed. 1266 * 1267 * A specific carrier ID returns the fine-grained carrier ID of the current subscription. 1268 * It can represent the fact that a carrier may be in effect an aggregation of other carriers 1269 * (ie in an MVNO type scenario) where each of these specific carriers which are used to make 1270 * up the actual carrier service may have different carrier configurations. 1271 * A specific carrier ID could also be used, for example, in a scenario where a carrier requires 1272 * different carrier configuration for different service offering such as a prepaid plan. 1273 * 1274 * the specific carrier ID would be used for configuration purposes, but apps wishing to know 1275 * about the carrier itself should use the regular carrier ID returned by 1276 * {@link #getSimCarrierId()}. 1277 * 1278 * <p>Similar like {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED}, this intent will be 1279 * sent on the event of {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} while its also 1280 * possible to be sent without {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} when 1281 * specific carrier ID changes while carrier ID remains the same. 1282 * e.g, the same subscription switches to different IMSI could potentially change its 1283 * specific carrier ID while carrier id remains the same. 1284 * @see #getSimSpecificCarrierId() 1285 * @see #getSimCarrierId() 1286 * 1287 * The intent will have the following extra values: 1288 * <ul> 1289 * <li>{@link #EXTRA_SPECIFIC_CARRIER_ID} The up-to-date specific carrier id of the 1290 * current subscription. 1291 * </li> 1292 * <li>{@link #EXTRA_SPECIFIC_CARRIER_NAME} The up-to-date name of the specific carrier id. 1293 * </li> 1294 * <li>{@link #EXTRA_SUBSCRIPTION_ID} The subscription id associated with the changed carrier 1295 * identity. 1296 * </li> 1297 * </ul> 1298 * <p class="note">This is a protected intent that can only be sent by the system. 1299 */ 1300 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1301 public static final String ACTION_SUBSCRIPTION_SPECIFIC_CARRIER_IDENTITY_CHANGED = 1302 "android.telephony.action.SUBSCRIPTION_SPECIFIC_CARRIER_IDENTITY_CHANGED"; 1303 1304 /** 1305 * An int extra used with {@link #ACTION_SUBSCRIPTION_SPECIFIC_CARRIER_IDENTITY_CHANGED} which 1306 * indicates the updated specific carrier id returned by 1307 * {@link TelephonyManager#getSimSpecificCarrierId()}. Note, its possible specific carrier id 1308 * changes while {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} remains the same 1309 * e.g, when subscription switch to different IMSIs. 1310 * <p>Will be {@link TelephonyManager#UNKNOWN_CARRIER_ID} if the subscription is unavailable or 1311 * the carrier cannot be identified. 1312 */ 1313 public static final String EXTRA_SPECIFIC_CARRIER_ID = 1314 "android.telephony.extra.SPECIFIC_CARRIER_ID"; 1315 1316 /** 1317 * An string extra used with {@link #ACTION_SUBSCRIPTION_SPECIFIC_CARRIER_IDENTITY_CHANGED} 1318 * which indicates the updated specific carrier name returned by 1319 * {@link TelephonyManager#getSimSpecificCarrierIdName()}. 1320 * <p>it's a user-facing name of the specific carrier id {@link #EXTRA_SPECIFIC_CARRIER_ID} 1321 * e.g, Tracfone-AT&T 1322 */ 1323 public static final String EXTRA_SPECIFIC_CARRIER_NAME = 1324 "android.telephony.extra.SPECIFIC_CARRIER_NAME"; 1325 1326 /** 1327 * An int extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} to indicate the 1328 * subscription which has changed; or in general whenever a subscription ID needs specified. 1329 */ 1330 public static final String EXTRA_SUBSCRIPTION_ID = "android.telephony.extra.SUBSCRIPTION_ID"; 1331 1332 /** 1333 * Broadcast intent action indicating that when data stall recovery is attempted by Telephony, 1334 * intended for report every data stall recovery step attempted. 1335 * 1336 * <p> 1337 * The {@link #EXTRA_RECOVERY_ACTION} extra indicates the action associated with the data 1338 * stall recovery. 1339 * The phone id where the data stall recovery is attempted. 1340 * 1341 * <p class="note"> 1342 * Requires the READ_PHONE_STATE permission. 1343 * 1344 * <p class="note"> 1345 * This is a protected intent that can only be sent by the system. 1346 * 1347 * @see #EXTRA_RECOVERY_ACTION 1348 * 1349 * @hide 1350 */ 1351 // TODO(b/78370030) : Restrict this to system applications only 1352 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1353 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 1354 public static final String ACTION_DATA_STALL_DETECTED = 1355 "android.intent.action.DATA_STALL_DETECTED"; 1356 1357 /** 1358 * A service action that identifies 1359 * a {@link android.service.carrier.CarrierMessagingClientService} subclass in the 1360 * AndroidManifest.xml. 1361 * 1362 * <p>See {@link android.service.carrier.CarrierMessagingClientService} for the details. 1363 */ 1364 @SdkConstant(SdkConstantType.SERVICE_ACTION) 1365 public static final String ACTION_CARRIER_MESSAGING_CLIENT_SERVICE = 1366 "android.telephony.action.CARRIER_MESSAGING_CLIENT_SERVICE"; 1367 1368 /** 1369 * An int extra used with {@link #ACTION_DATA_STALL_DETECTED} to indicate the 1370 * action associated with the data stall recovery. 1371 * 1372 * @see #ACTION_DATA_STALL_DETECTED 1373 * 1374 * @hide 1375 */ 1376 public static final String EXTRA_RECOVERY_ACTION = "recoveryAction"; 1377 1378 private static final long MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS = 60000; 1379 1380 /** 1381 * Intent sent when an error occurs that debug tools should log and possibly take further 1382 * action such as capturing vendor-specific logs. 1383 * 1384 * A privileged application that reads these events should take appropriate vendor-specific 1385 * action to record the event and collect further information to assist in analysis, debugging, 1386 * and resolution of any associated issue. 1387 * 1388 * <p>This event should not be used for generic logging or diagnostic monitoring purposes and 1389 * should generally be sent at a low rate. Instead, this mechanism should be used for the 1390 * framework to notify a debugging application that an event (such as a bug) has occured 1391 * within the framework if that event should trigger the collection and preservation of other 1392 * more detailed device state for debugging. 1393 * 1394 * <p>At most one application can receive these events and should register a receiver in 1395 * in the application manifest. For performance reasons, if no application to receive these 1396 * events is detected at boot, then these events will not be sent. 1397 * 1398 * <p>Each event will include an {@link EXTRA_ANOMALY_ID} that will uniquely identify the 1399 * event that has occurred. Each event will be sent to the diagnostic monitor only once per 1400 * boot cycle (as another optimization). 1401 * 1402 * @see #EXTRA_ANOMALY_ID 1403 * @see #EXTRA_ANOMALY_DESCRIPTION 1404 * @hide 1405 */ 1406 @SystemApi 1407 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 1408 public static final String ACTION_ANOMALY_REPORTED = 1409 "android.telephony.action.ANOMALY_REPORTED"; 1410 1411 /** 1412 * An arbitrary ParcelUuid which should be consistent for each occurrence of a DebugEvent. 1413 * 1414 * This field must be included in all {@link ACTION_ANOMALY_REPORTED} events. 1415 * 1416 * @see #ACTION_ANOMALY_REPORTED 1417 * @hide 1418 */ 1419 @SystemApi 1420 public static final String EXTRA_ANOMALY_ID = "android.telephony.extra.ANOMALY_ID"; 1421 1422 /** 1423 * A freeform string description of the Anomaly. 1424 * 1425 * This field is optional for all {@link ACTION_ANOMALY_REPORTED}s, as a guideline should not 1426 * exceed 80 characters, and should be as short as possible to convey the essence of the event. 1427 * 1428 * @see #ACTION_ANOMALY_REPORTED 1429 * @hide 1430 */ 1431 @SystemApi 1432 public static final String EXTRA_ANOMALY_DESCRIPTION = 1433 "android.telephony.extra.ANOMALY_DESCRIPTION"; 1434 1435 /** 1436 * Broadcast intent sent to indicate primary (non-opportunistic) subscription list has changed. 1437 * 1438 * @hide 1439 */ 1440 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1441 public static final String ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED = 1442 "android.telephony.action.PRIMARY_SUBSCRIPTION_LIST_CHANGED"; 1443 1444 /** 1445 * Integer intent extra to be used with {@link #ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED} 1446 * to indicate what type of SIM selection is needed. 1447 * 1448 * @hide 1449 */ 1450 public static final String EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE = 1451 "android.telephony.extra.DEFAULT_SUBSCRIPTION_SELECT_TYPE"; 1452 1453 /** @hide */ 1454 @IntDef({ 1455 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_NONE, 1456 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA, 1457 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_VOICE, 1458 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_SMS, 1459 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_ALL 1460 }) 1461 @Retention(RetentionPolicy.SOURCE) 1462 public @interface DefaultSubscriptionSelectType{} 1463 1464 /** 1465 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1466 * to indicate there's no need to re-select any default subscription. 1467 * @hide 1468 */ 1469 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_NONE = 0; 1470 1471 /** 1472 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1473 * to indicate there's a need to select default data subscription. 1474 * @hide 1475 */ 1476 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA = 1; 1477 1478 /** 1479 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1480 * to indicate there's a need to select default voice call subscription. 1481 * @hide 1482 */ 1483 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_VOICE = 2; 1484 1485 /** 1486 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1487 * to indicate there's a need to select default sms subscription. 1488 * @hide 1489 */ 1490 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_SMS = 3; 1491 1492 /** 1493 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1494 * to indicate user to decide whether current SIM should be preferred for all 1495 * data / voice / sms. {@link #EXTRA_SUBSCRIPTION_ID} will specified to indicate 1496 * which subscription should be the default subscription. 1497 * @hide 1498 */ 1499 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_ALL = 4; 1500 1501 /** 1502 * Integer intent extra to be used with {@link #ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED} 1503 * to indicate if the SIM combination in DSDS has limitation or compatible issue. 1504 * e.g. two CDMA SIMs may disrupt each other's voice call in certain scenarios. 1505 * 1506 * @hide 1507 */ 1508 public static final String EXTRA_SIM_COMBINATION_WARNING_TYPE = 1509 "android.telephony.extra.SIM_COMBINATION_WARNING_TYPE"; 1510 1511 /** @hide */ 1512 @IntDef({ 1513 EXTRA_SIM_COMBINATION_WARNING_TYPE_NONE, 1514 EXTRA_SIM_COMBINATION_WARNING_TYPE_DUAL_CDMA 1515 }) 1516 @Retention(RetentionPolicy.SOURCE) 1517 public @interface SimCombinationWarningType{} 1518 1519 /** 1520 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1521 * to indicate there's no SIM combination warning. 1522 * @hide 1523 */ 1524 public static final int EXTRA_SIM_COMBINATION_WARNING_TYPE_NONE = 0; 1525 1526 /** 1527 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1528 * to indicate two active SIMs are both CDMA hence there might be functional limitation. 1529 * @hide 1530 */ 1531 public static final int EXTRA_SIM_COMBINATION_WARNING_TYPE_DUAL_CDMA = 1; 1532 1533 /** 1534 * String intent extra to be used with {@link #ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED} 1535 * to indicate what's the name of SIM combination it has limitation or compatible issue. 1536 * e.g. two CDMA SIMs may disrupt each other's voice call in certain scenarios, and the 1537 * name will be "operator1 & operator2". 1538 * 1539 * @hide 1540 */ 1541 public static final String EXTRA_SIM_COMBINATION_NAMES = 1542 "android.telephony.extra.SIM_COMBINATION_NAMES"; 1543 // 1544 // 1545 // Device Info 1546 // 1547 // 1548 1549 /** 1550 * Returns the software version number for the device, for example, 1551 * the IMEI/SV for GSM phones. Return null if the software version is 1552 * not available. 1553 * 1554 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1555 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 1556 */ 1557 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 1558 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getDeviceSoftwareVersion()1559 public String getDeviceSoftwareVersion() { 1560 return getDeviceSoftwareVersion(getSlotIndex()); 1561 } 1562 1563 /** 1564 * Returns the software version number for the device, for example, 1565 * the IMEI/SV for GSM phones. Return null if the software version is 1566 * not available. 1567 * 1568 * @param slotIndex of which deviceID is returned 1569 */ 1570 /** {@hide} */ 1571 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 1572 @UnsupportedAppUsage getDeviceSoftwareVersion(int slotIndex)1573 public String getDeviceSoftwareVersion(int slotIndex) { 1574 ITelephony telephony = getITelephony(); 1575 if (telephony == null) return null; 1576 1577 try { 1578 return telephony.getDeviceSoftwareVersionForSlot(slotIndex, getOpPackageName()); 1579 } catch (RemoteException ex) { 1580 return null; 1581 } catch (NullPointerException ex) { 1582 return null; 1583 } 1584 } 1585 1586 /** 1587 * Returns the unique device ID, for example, the IMEI for GSM and the MEID 1588 * or ESN for CDMA phones. Return null if device ID is not available. 1589 * 1590 * <p>Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or 1591 * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier 1592 * privileges (see {@link #hasCarrierPrivileges}). The profile owner is an app that owns a 1593 * managed profile on the device; for more details see <a 1594 * href="https://developer.android.com/work/managed-profiles">Work profiles</a>. Profile owner 1595 * access is deprecated and will be removed in a future release. 1596 * 1597 * <p>If the calling app does not meet one of these requirements then this method will behave 1598 * as follows: 1599 * 1600 * <ul> 1601 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 1602 * READ_PHONE_STATE permission then null is returned.</li> 1603 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 1604 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 1605 * higher, then a SecurityException is thrown.</li> 1606 * </ul> 1607 * 1608 * @deprecated Use {@link #getImei} which returns IMEI for GSM or {@link #getMeid} which returns 1609 * MEID for CDMA. 1610 */ 1611 @Deprecated 1612 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 1613 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getDeviceId()1614 public String getDeviceId() { 1615 try { 1616 ITelephony telephony = getITelephony(); 1617 if (telephony == null) 1618 return null; 1619 return telephony.getDeviceId(mContext.getOpPackageName()); 1620 } catch (RemoteException ex) { 1621 return null; 1622 } catch (NullPointerException ex) { 1623 return null; 1624 } 1625 } 1626 1627 /** 1628 * Returns the unique device ID of a subscription, for example, the IMEI for 1629 * GSM and the MEID for CDMA phones. Return null if device ID is not available. 1630 * 1631 * <p>Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or 1632 * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier 1633 * privileges (see {@link #hasCarrierPrivileges}). The profile owner is an app that owns a 1634 * managed profile on the device; for more details see <a 1635 * href="https://developer.android.com/work/managed-profiles">Work profiles</a>. Profile owner 1636 * access is deprecated and will be removed in a future release. 1637 * 1638 * <p>If the calling app does not meet one of these requirements then this method will behave 1639 * as follows: 1640 * 1641 * <ul> 1642 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 1643 * READ_PHONE_STATE permission then null is returned.</li> 1644 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 1645 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 1646 * higher, then a SecurityException is thrown.</li> 1647 * </ul> 1648 * 1649 * @param slotIndex of which deviceID is returned 1650 * 1651 * @deprecated Use {@link #getImei} which returns IMEI for GSM or {@link #getMeid} which returns 1652 * MEID for CDMA. 1653 */ 1654 @Deprecated 1655 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 1656 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getDeviceId(int slotIndex)1657 public String getDeviceId(int slotIndex) { 1658 // FIXME this assumes phoneId == slotIndex 1659 try { 1660 IPhoneSubInfo info = getSubscriberInfo(); 1661 if (info == null) 1662 return null; 1663 return info.getDeviceIdForPhone(slotIndex, mContext.getOpPackageName()); 1664 } catch (RemoteException ex) { 1665 return null; 1666 } catch (NullPointerException ex) { 1667 return null; 1668 } 1669 } 1670 1671 /** 1672 * Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not 1673 * available. 1674 * 1675 * See {@link #getImei(int)} for details on the required permissions and behavior 1676 * when the caller does not hold sufficient permissions. 1677 */ 1678 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 1679 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getImei()1680 public String getImei() { 1681 return getImei(getSlotIndex()); 1682 } 1683 1684 /** 1685 * Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not 1686 * available. 1687 * 1688 * <p>This API requires one of the following: 1689 * <ul> 1690 * <li>The caller holds the READ_PRIVILEGED_PHONE_STATE permission.</li> 1691 * <li>If the caller is the device or profile owner, the caller holds the 1692 * {@link Manifest.permission#READ_PHONE_STATE} permission.</li> 1693 * <li>The caller has carrier privileges (see {@link #hasCarrierPrivileges()}.</li> 1694 * <li>The caller is the default SMS app for the device.</li> 1695 * </ul> 1696 * <p>The profile owner is an app that owns a managed profile on the device; for more details 1697 * see <a href="https://developer.android.com/work/managed-profiles">Work profiles</a>. 1698 * Access by profile owners is deprecated and will be removed in a future release. 1699 * 1700 * <p>If the calling app does not meet one of these requirements then this method will behave 1701 * as follows: 1702 * 1703 * <ul> 1704 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 1705 * READ_PHONE_STATE permission then null is returned.</li> 1706 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 1707 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 1708 * higher, then a SecurityException is thrown.</li> 1709 * </ul> 1710 * 1711 * @param slotIndex of which IMEI is returned 1712 */ 1713 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 1714 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getImei(int slotIndex)1715 public String getImei(int slotIndex) { 1716 ITelephony telephony = getITelephony(); 1717 if (telephony == null) return null; 1718 1719 try { 1720 return telephony.getImeiForSlot(slotIndex, getOpPackageName()); 1721 } catch (RemoteException ex) { 1722 return null; 1723 } catch (NullPointerException ex) { 1724 return null; 1725 } 1726 } 1727 1728 /** 1729 * Returns the Type Allocation Code from the IMEI. Return null if Type Allocation Code is not 1730 * available. 1731 */ 1732 @Nullable getTypeAllocationCode()1733 public String getTypeAllocationCode() { 1734 return getTypeAllocationCode(getSlotIndex()); 1735 } 1736 1737 /** 1738 * Returns the Type Allocation Code from the IMEI. Return null if Type Allocation Code is not 1739 * available. 1740 * 1741 * @param slotIndex of which Type Allocation Code is returned 1742 */ 1743 @Nullable getTypeAllocationCode(int slotIndex)1744 public String getTypeAllocationCode(int slotIndex) { 1745 ITelephony telephony = getITelephony(); 1746 if (telephony == null) return null; 1747 1748 try { 1749 return telephony.getTypeAllocationCodeForSlot(slotIndex); 1750 } catch (RemoteException ex) { 1751 return null; 1752 } catch (NullPointerException ex) { 1753 return null; 1754 } 1755 } 1756 1757 /** 1758 * Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. 1759 * 1760 * <p>Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or 1761 * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier 1762 * privileges (see {@link #hasCarrierPrivileges}). The profile owner is an app that owns a 1763 * managed profile on the device; for more details see <a 1764 * href="https://developer.android.com/work/managed-profiles">Work profiles</a>. Profile owner 1765 * access is deprecated and will be removed in a future release. 1766 * 1767 * <p>If the calling app does not meet one of these requirements then this method will behave 1768 * as follows: 1769 * 1770 * <ul> 1771 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 1772 * READ_PHONE_STATE permission then null is returned.</li> 1773 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 1774 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 1775 * higher, then a SecurityException is thrown.</li> 1776 * </ul> 1777 */ 1778 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 1779 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getMeid()1780 public String getMeid() { 1781 return getMeid(getSlotIndex()); 1782 } 1783 1784 /** 1785 * Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. 1786 * 1787 * <p>Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or 1788 * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier 1789 * privileges (see {@link #hasCarrierPrivileges}). The profile owner is an app that owns a 1790 * managed profile on the device; for more details see <a 1791 * href="https://developer.android.com/work/managed-profiles">Work profiles</a>. Profile owner 1792 * access is deprecated and will be removed in a future release. 1793 * 1794 * <p>If the calling app does not meet one of these requirements then this method will behave 1795 * as follows: 1796 * 1797 * <ul> 1798 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 1799 * READ_PHONE_STATE permission then null is returned.</li> 1800 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 1801 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 1802 * higher, then a SecurityException is thrown.</li> 1803 * </ul> 1804 * 1805 * @param slotIndex of which MEID is returned 1806 */ 1807 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 1808 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getMeid(int slotIndex)1809 public String getMeid(int slotIndex) { 1810 ITelephony telephony = getITelephony(); 1811 if (telephony == null) return null; 1812 1813 try { 1814 return telephony.getMeidForSlot(slotIndex, getOpPackageName()); 1815 } catch (RemoteException ex) { 1816 return null; 1817 } catch (NullPointerException ex) { 1818 return null; 1819 } 1820 } 1821 1822 /** 1823 * Returns the Manufacturer Code from the MEID. Return null if Manufacturer Code is not 1824 * available. 1825 */ 1826 @Nullable getManufacturerCode()1827 public String getManufacturerCode() { 1828 return getManufacturerCode(getSlotIndex()); 1829 } 1830 1831 /** 1832 * Returns the Manufacturer Code from the MEID. Return null if Manufacturer Code is not 1833 * available. 1834 * 1835 * @param slotIndex of which Type Allocation Code is returned 1836 */ 1837 @Nullable getManufacturerCode(int slotIndex)1838 public String getManufacturerCode(int slotIndex) { 1839 ITelephony telephony = getITelephony(); 1840 if (telephony == null) return null; 1841 1842 try { 1843 return telephony.getManufacturerCodeForSlot(slotIndex); 1844 } catch (RemoteException ex) { 1845 return null; 1846 } catch (NullPointerException ex) { 1847 return null; 1848 } 1849 } 1850 1851 /** 1852 * Returns the Network Access Identifier (NAI). Return null if NAI is not available. 1853 * 1854 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1855 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 1856 */ 1857 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 1858 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getNai()1859 public String getNai() { 1860 return getNaiBySubscriberId(getSubId()); 1861 } 1862 1863 /** 1864 * Returns the NAI. Return null if NAI is not available. 1865 * 1866 * @param slotIndex of which Nai is returned 1867 */ 1868 /** {@hide}*/ 1869 @UnsupportedAppUsage getNai(int slotIndex)1870 public String getNai(int slotIndex) { 1871 int[] subId = SubscriptionManager.getSubId(slotIndex); 1872 if (subId == null) { 1873 return null; 1874 } 1875 return getNaiBySubscriberId(subId[0]); 1876 } 1877 getNaiBySubscriberId(int subId)1878 private String getNaiBySubscriberId(int subId) { 1879 try { 1880 IPhoneSubInfo info = getSubscriberInfo(); 1881 if (info == null) 1882 return null; 1883 String nai = info.getNaiForSubscriber(subId, mContext.getOpPackageName()); 1884 if (Log.isLoggable(TAG, Log.VERBOSE)) { 1885 Rlog.v(TAG, "Nai = " + nai); 1886 } 1887 return nai; 1888 } catch (RemoteException ex) { 1889 return null; 1890 } catch (NullPointerException ex) { 1891 return null; 1892 } 1893 } 1894 1895 /** 1896 * Returns the current location of the device. 1897 *<p> 1898 * If there is only one radio in the device and that radio has an LTE connection, 1899 * this method will return null. The implementation must not to try add LTE 1900 * identifiers into the existing cdma/gsm classes. 1901 *<p> 1902 * @return Current location of the device or null if not available. 1903 * 1904 * @deprecated use {@link #getAllCellInfo} instead, which returns a superset of this API. 1905 */ 1906 @Deprecated 1907 @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) getCellLocation()1908 public CellLocation getCellLocation() { 1909 try { 1910 ITelephony telephony = getITelephony(); 1911 if (telephony == null) { 1912 Rlog.d(TAG, "getCellLocation returning null because telephony is null"); 1913 return null; 1914 } 1915 1916 Bundle bundle = telephony.getCellLocation(mContext.getOpPackageName()); 1917 if (bundle == null || bundle.isEmpty()) { 1918 Rlog.d(TAG, "getCellLocation returning null because CellLocation is unavailable"); 1919 return null; 1920 } 1921 1922 CellLocation cl = CellLocation.newFromBundle(bundle); 1923 if (cl == null || cl.isEmpty()) { 1924 Rlog.d(TAG, "getCellLocation returning null because CellLocation is empty or" 1925 + " phone type doesn't match CellLocation type"); 1926 return null; 1927 } 1928 1929 return cl; 1930 } catch (RemoteException ex) { 1931 Rlog.d(TAG, "getCellLocation returning null due to RemoteException " + ex); 1932 return null; 1933 } 1934 } 1935 1936 /** 1937 * Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged 1938 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 1939 * 1940 * @hide 1941 */ 1942 @RequiresPermission(android.Manifest.permission.CONTROL_LOCATION_UPDATES) enableLocationUpdates()1943 public void enableLocationUpdates() { 1944 enableLocationUpdates(getSubId()); 1945 } 1946 1947 /** 1948 * Enables location update notifications for a subscription. 1949 * {@link PhoneStateListener#onCellLocationChanged 1950 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 1951 * 1952 * @param subId for which the location updates are enabled 1953 * @hide 1954 */ 1955 @RequiresPermission(android.Manifest.permission.CONTROL_LOCATION_UPDATES) enableLocationUpdates(int subId)1956 public void enableLocationUpdates(int subId) { 1957 try { 1958 ITelephony telephony = getITelephony(); 1959 if (telephony != null) 1960 telephony.enableLocationUpdatesForSubscriber(subId); 1961 } catch (RemoteException ex) { 1962 } catch (NullPointerException ex) { 1963 } 1964 } 1965 1966 /** 1967 * Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged 1968 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 1969 * 1970 * @hide 1971 */ 1972 @RequiresPermission(android.Manifest.permission.CONTROL_LOCATION_UPDATES) disableLocationUpdates()1973 public void disableLocationUpdates() { 1974 disableLocationUpdates(getSubId()); 1975 } 1976 1977 /** @hide */ disableLocationUpdates(int subId)1978 public void disableLocationUpdates(int subId) { 1979 try { 1980 ITelephony telephony = getITelephony(); 1981 if (telephony != null) 1982 telephony.disableLocationUpdatesForSubscriber(subId); 1983 } catch (RemoteException ex) { 1984 } catch (NullPointerException ex) { 1985 } 1986 } 1987 1988 /** 1989 * Returns the neighboring cell information of the device. 1990 * 1991 * @return List of NeighboringCellInfo or null if info unavailable. 1992 * 1993 * @removed 1994 * @deprecated Use {@link #getAllCellInfo} which returns a superset of the information 1995 * from NeighboringCellInfo, including LTE cell information. 1996 */ 1997 @Deprecated 1998 @RequiresPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) getNeighboringCellInfo()1999 public List<NeighboringCellInfo> getNeighboringCellInfo() { 2000 try { 2001 ITelephony telephony = getITelephony(); 2002 if (telephony == null) 2003 return null; 2004 return telephony.getNeighboringCellInfo(mContext.getOpPackageName()); 2005 } catch (RemoteException ex) { 2006 return null; 2007 } catch (NullPointerException ex) { 2008 return null; 2009 } 2010 } 2011 2012 /** No phone radio. */ 2013 public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE; 2014 /** Phone radio is GSM. */ 2015 public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM; 2016 /** Phone radio is CDMA. */ 2017 public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA; 2018 /** Phone is via SIP. */ 2019 public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP; 2020 2021 /** 2022 * Returns the current phone type. 2023 * TODO: This is a last minute change and hence hidden. 2024 * 2025 * @see #PHONE_TYPE_NONE 2026 * @see #PHONE_TYPE_GSM 2027 * @see #PHONE_TYPE_CDMA 2028 * @see #PHONE_TYPE_SIP 2029 * 2030 * {@hide} 2031 */ 2032 @SystemApi getCurrentPhoneType()2033 public int getCurrentPhoneType() { 2034 return getCurrentPhoneType(getSubId()); 2035 } 2036 2037 /** 2038 * Returns a constant indicating the device phone type for a subscription. 2039 * 2040 * @see #PHONE_TYPE_NONE 2041 * @see #PHONE_TYPE_GSM 2042 * @see #PHONE_TYPE_CDMA 2043 * 2044 * @param subId for which phone type is returned 2045 * @hide 2046 */ 2047 @SystemApi getCurrentPhoneType(int subId)2048 public int getCurrentPhoneType(int subId) { 2049 int phoneId; 2050 if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 2051 // if we don't have any sims, we don't have subscriptions, but we 2052 // still may want to know what type of phone we've got. 2053 phoneId = 0; 2054 } else { 2055 phoneId = SubscriptionManager.getPhoneId(subId); 2056 } 2057 2058 return getCurrentPhoneTypeForSlot(phoneId); 2059 } 2060 2061 /** 2062 * See getCurrentPhoneType. 2063 * 2064 * @hide 2065 */ getCurrentPhoneTypeForSlot(int slotIndex)2066 public int getCurrentPhoneTypeForSlot(int slotIndex) { 2067 try{ 2068 ITelephony telephony = getITelephony(); 2069 if (telephony != null) { 2070 return telephony.getActivePhoneTypeForSlot(slotIndex); 2071 } else { 2072 // This can happen when the ITelephony interface is not up yet. 2073 return getPhoneTypeFromProperty(slotIndex); 2074 } 2075 } catch (RemoteException ex) { 2076 // This shouldn't happen in the normal case, as a backup we 2077 // read from the system property. 2078 return getPhoneTypeFromProperty(slotIndex); 2079 } catch (NullPointerException ex) { 2080 // This shouldn't happen in the normal case, as a backup we 2081 // read from the system property. 2082 return getPhoneTypeFromProperty(slotIndex); 2083 } 2084 } 2085 2086 /** 2087 * Returns a constant indicating the device phone type. This 2088 * indicates the type of radio used to transmit voice calls. 2089 * 2090 * @see #PHONE_TYPE_NONE 2091 * @see #PHONE_TYPE_GSM 2092 * @see #PHONE_TYPE_CDMA 2093 * @see #PHONE_TYPE_SIP 2094 */ getPhoneType()2095 public int getPhoneType() { 2096 if (!isVoiceCapable()) { 2097 return PHONE_TYPE_NONE; 2098 } 2099 return getCurrentPhoneType(); 2100 } 2101 getPhoneTypeFromProperty()2102 private int getPhoneTypeFromProperty() { 2103 return getPhoneTypeFromProperty(getPhoneId()); 2104 } 2105 2106 /** {@hide} */ 2107 @UnsupportedAppUsage getPhoneTypeFromProperty(int phoneId)2108 private int getPhoneTypeFromProperty(int phoneId) { 2109 String type = getTelephonyProperty(phoneId, 2110 TelephonyProperties.CURRENT_ACTIVE_PHONE, null); 2111 if (type == null || type.isEmpty()) { 2112 return getPhoneTypeFromNetworkType(phoneId); 2113 } 2114 return Integer.parseInt(type); 2115 } 2116 getPhoneTypeFromNetworkType()2117 private int getPhoneTypeFromNetworkType() { 2118 return getPhoneTypeFromNetworkType(getPhoneId()); 2119 } 2120 2121 /** {@hide} */ getPhoneTypeFromNetworkType(int phoneId)2122 private int getPhoneTypeFromNetworkType(int phoneId) { 2123 // When the system property CURRENT_ACTIVE_PHONE, has not been set, 2124 // use the system property for default network type. 2125 // This is a fail safe, and can only happen at first boot. 2126 String mode = getTelephonyProperty(phoneId, "ro.telephony.default_network", null); 2127 if (mode != null && !mode.isEmpty()) { 2128 return TelephonyManager.getPhoneType(Integer.parseInt(mode)); 2129 } 2130 return TelephonyManager.PHONE_TYPE_NONE; 2131 } 2132 2133 /** 2134 * This function returns the type of the phone, depending 2135 * on the network mode. 2136 * 2137 * @param networkMode 2138 * @return Phone Type 2139 * 2140 * @hide 2141 */ 2142 @UnsupportedAppUsage getPhoneType(int networkMode)2143 public static int getPhoneType(int networkMode) { 2144 switch(networkMode) { 2145 case RILConstants.NETWORK_MODE_CDMA: 2146 case RILConstants.NETWORK_MODE_CDMA_NO_EVDO: 2147 case RILConstants.NETWORK_MODE_EVDO_NO_CDMA: 2148 return PhoneConstants.PHONE_TYPE_CDMA; 2149 2150 case RILConstants.NETWORK_MODE_WCDMA_PREF: 2151 case RILConstants.NETWORK_MODE_GSM_ONLY: 2152 case RILConstants.NETWORK_MODE_WCDMA_ONLY: 2153 case RILConstants.NETWORK_MODE_GSM_UMTS: 2154 case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA: 2155 case RILConstants.NETWORK_MODE_LTE_WCDMA: 2156 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA: 2157 case RILConstants.NETWORK_MODE_TDSCDMA_ONLY: 2158 case RILConstants.NETWORK_MODE_TDSCDMA_WCDMA: 2159 case RILConstants.NETWORK_MODE_LTE_TDSCDMA: 2160 case RILConstants.NETWORK_MODE_TDSCDMA_GSM: 2161 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM: 2162 case RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA: 2163 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA: 2164 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA: 2165 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA: 2166 return PhoneConstants.PHONE_TYPE_GSM; 2167 2168 // Use CDMA Phone for the global mode including CDMA 2169 case RILConstants.NETWORK_MODE_GLOBAL: 2170 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO: 2171 case RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA: 2172 return PhoneConstants.PHONE_TYPE_CDMA; 2173 2174 case RILConstants.NETWORK_MODE_LTE_ONLY: 2175 if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) { 2176 return PhoneConstants.PHONE_TYPE_CDMA; 2177 } else { 2178 return PhoneConstants.PHONE_TYPE_GSM; 2179 } 2180 default: 2181 return PhoneConstants.PHONE_TYPE_GSM; 2182 } 2183 } 2184 2185 /** 2186 * The contents of the /proc/cmdline file 2187 */ 2188 @UnsupportedAppUsage getProcCmdLine()2189 private static String getProcCmdLine() 2190 { 2191 String cmdline = ""; 2192 FileInputStream is = null; 2193 try { 2194 is = new FileInputStream("/proc/cmdline"); 2195 byte [] buffer = new byte[2048]; 2196 int count = is.read(buffer); 2197 if (count > 0) { 2198 cmdline = new String(buffer, 0, count); 2199 } 2200 } catch (IOException e) { 2201 Rlog.d(TAG, "No /proc/cmdline exception=" + e); 2202 } finally { 2203 if (is != null) { 2204 try { 2205 is.close(); 2206 } catch (IOException e) { 2207 } 2208 } 2209 } 2210 Rlog.d(TAG, "/proc/cmdline=" + cmdline); 2211 return cmdline; 2212 } 2213 2214 /** 2215 * @return The max value for the timeout passed in {@link #requestNumberVerification}. 2216 * @hide 2217 */ 2218 @SystemApi getMaxNumberVerificationTimeoutMillis()2219 public static long getMaxNumberVerificationTimeoutMillis() { 2220 return MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS; 2221 } 2222 2223 /** Kernel command line */ 2224 private static final String sKernelCmdLine = getProcCmdLine(); 2225 2226 /** Pattern for selecting the product type from the kernel command line */ 2227 private static final Pattern sProductTypePattern = 2228 Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)"); 2229 2230 /** The ProductType used for LTE on CDMA devices */ 2231 private static final String sLteOnCdmaProductType = 2232 SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, ""); 2233 2234 /** 2235 * Return if the current radio is LTE on CDMA. This 2236 * is a tri-state return value as for a period of time 2237 * the mode may be unknown. 2238 * 2239 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 2240 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 2241 * 2242 * @hide 2243 */ 2244 @UnsupportedAppUsage getLteOnCdmaModeStatic()2245 public static int getLteOnCdmaModeStatic() { 2246 int retVal; 2247 int curVal; 2248 String productType = ""; 2249 2250 curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE, 2251 PhoneConstants.LTE_ON_CDMA_UNKNOWN); 2252 retVal = curVal; 2253 if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) { 2254 Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine); 2255 if (matcher.find()) { 2256 productType = matcher.group(1); 2257 if (sLteOnCdmaProductType.equals(productType)) { 2258 retVal = PhoneConstants.LTE_ON_CDMA_TRUE; 2259 } else { 2260 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 2261 } 2262 } else { 2263 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 2264 } 2265 } 2266 2267 Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal + 2268 " product_type='" + productType + 2269 "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'"); 2270 return retVal; 2271 } 2272 2273 // 2274 // 2275 // Current Network 2276 // 2277 // 2278 2279 /** 2280 * Returns the alphabetic name of current registered operator. 2281 * <p> 2282 * Availability: Only when user is registered to a network. Result may be 2283 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2284 * on a CDMA network). 2285 */ getNetworkOperatorName()2286 public String getNetworkOperatorName() { 2287 return getNetworkOperatorName(getSubId()); 2288 } 2289 2290 /** 2291 * Returns the alphabetic name of current registered operator 2292 * for a particular subscription. 2293 * <p> 2294 * Availability: Only when user is registered to a network. Result may be 2295 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2296 * on a CDMA network). 2297 * @param subId 2298 * @hide 2299 */ 2300 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getNetworkOperatorName(int subId)2301 public String getNetworkOperatorName(int subId) { 2302 int phoneId = SubscriptionManager.getPhoneId(subId); 2303 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, ""); 2304 } 2305 2306 /** 2307 * Returns the numeric name (MCC+MNC) of current registered operator. 2308 * <p> 2309 * Availability: Only when user is registered to a network. Result may be 2310 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2311 * on a CDMA network). 2312 */ getNetworkOperator()2313 public String getNetworkOperator() { 2314 return getNetworkOperatorForPhone(getPhoneId()); 2315 } 2316 2317 /** 2318 * Returns the numeric name (MCC+MNC) of current registered operator 2319 * for a particular subscription. 2320 * <p> 2321 * Availability: Only when user is registered to a network. Result may be 2322 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2323 * on a CDMA network). 2324 * 2325 * @param subId 2326 * @hide 2327 */ 2328 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getNetworkOperator(int subId)2329 public String getNetworkOperator(int subId) { 2330 int phoneId = SubscriptionManager.getPhoneId(subId); 2331 return getNetworkOperatorForPhone(phoneId); 2332 } 2333 2334 /** 2335 * Returns the numeric name (MCC+MNC) of current registered operator 2336 * for a particular subscription. 2337 * <p> 2338 * Availability: Only when user is registered to a network. Result may be 2339 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2340 * on a CDMA network). 2341 * 2342 * @param phoneId 2343 * @hide 2344 **/ 2345 @UnsupportedAppUsage getNetworkOperatorForPhone(int phoneId)2346 public String getNetworkOperatorForPhone(int phoneId) { 2347 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, ""); 2348 } 2349 2350 2351 /** 2352 * Returns the network specifier of the subscription ID pinned to the TelephonyManager. The 2353 * network specifier is used by {@link 2354 * android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to create a {@link 2355 * android.net.NetworkRequest} that connects through the subscription. 2356 * 2357 * @see android.net.NetworkRequest.Builder#setNetworkSpecifier(String) 2358 * @see #createForSubscriptionId(int) 2359 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 2360 */ getNetworkSpecifier()2361 public String getNetworkSpecifier() { 2362 return String.valueOf(getSubId()); 2363 } 2364 2365 /** 2366 * Returns the carrier config of the subscription ID pinned to the TelephonyManager. If an 2367 * invalid subscription ID is pinned to the TelephonyManager, the returned config will contain 2368 * default values. 2369 * 2370 * <p>This method may take several seconds to complete, so it should only be called from a 2371 * worker thread. 2372 * 2373 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2374 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 2375 * 2376 * @see CarrierConfigManager#getConfigForSubId(int) 2377 * @see #createForSubscriptionId(int) 2378 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 2379 */ 2380 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 2381 @WorkerThread 2382 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCarrierConfig()2383 public PersistableBundle getCarrierConfig() { 2384 CarrierConfigManager carrierConfigManager = mContext 2385 .getSystemService(CarrierConfigManager.class); 2386 return carrierConfigManager.getConfigForSubId(getSubId()); 2387 } 2388 2389 /** 2390 * Returns true if the device is considered roaming on the current 2391 * network, for GSM purposes. 2392 * <p> 2393 * Availability: Only when user registered to a network. 2394 */ isNetworkRoaming()2395 public boolean isNetworkRoaming() { 2396 return isNetworkRoaming(getSubId()); 2397 } 2398 2399 /** 2400 * Returns true if the device is considered roaming on the current 2401 * network for a subscription. 2402 * <p> 2403 * Availability: Only when user registered to a network. 2404 * 2405 * @param subId 2406 * @hide 2407 */ 2408 @UnsupportedAppUsage isNetworkRoaming(int subId)2409 public boolean isNetworkRoaming(int subId) { 2410 int phoneId = SubscriptionManager.getPhoneId(subId); 2411 return Boolean.parseBoolean(getTelephonyProperty(phoneId, 2412 TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, null)); 2413 } 2414 2415 /** 2416 * Returns the ISO country code equivalent of the MCC (Mobile Country Code) of the current 2417 * registered operator or the cell nearby, if available. 2418 * . 2419 * <p> 2420 * Note: Result may be unreliable on CDMA networks (use {@link #getPhoneType()} to determine 2421 * if on a CDMA network). 2422 */ getNetworkCountryIso()2423 public String getNetworkCountryIso() { 2424 return getNetworkCountryIsoForPhone(getPhoneId()); 2425 } 2426 2427 /** 2428 * Returns the ISO country code equivalent of the MCC (Mobile Country Code) of the current 2429 * registered operator or the cell nearby, if available. 2430 * <p> 2431 * Note: Result may be unreliable on CDMA networks (use {@link #getPhoneType()} to determine 2432 * if on a CDMA network). 2433 * 2434 * @param subId for which Network CountryIso is returned 2435 * @hide 2436 */ 2437 @UnsupportedAppUsage getNetworkCountryIso(int subId)2438 public String getNetworkCountryIso(int subId) { 2439 return getNetworkCountryIsoForPhone(getPhoneId(subId)); 2440 } 2441 2442 /** 2443 * Returns the ISO country code equivalent of the current registered 2444 * operator's MCC (Mobile Country Code) of a subscription. 2445 * <p> 2446 * Availability: Only when user is registered to a network. Result may be 2447 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2448 * on a CDMA network). 2449 * 2450 * @param phoneId for which Network CountryIso is returned 2451 */ 2452 /** {@hide} */ 2453 @UnsupportedAppUsage getNetworkCountryIsoForPhone(int phoneId)2454 public String getNetworkCountryIsoForPhone(int phoneId) { 2455 try { 2456 ITelephony telephony = getITelephony(); 2457 if (telephony == null) return ""; 2458 return telephony.getNetworkCountryIsoForPhone(phoneId); 2459 } catch (RemoteException ex) { 2460 return ""; 2461 } 2462 } 2463 2464 /* 2465 * When adding a network type to the list below, make sure to add the correct icon to 2466 * MobileSignalController.mapIconSets(). 2467 * Do not add negative types. 2468 */ 2469 /** Network type is unknown */ 2470 public static final int NETWORK_TYPE_UNKNOWN = TelephonyProtoEnums.NETWORK_TYPE_UNKNOWN; // = 0. 2471 /** Current network is GPRS */ 2472 public static final int NETWORK_TYPE_GPRS = TelephonyProtoEnums.NETWORK_TYPE_GPRS; // = 1. 2473 /** Current network is EDGE */ 2474 public static final int NETWORK_TYPE_EDGE = TelephonyProtoEnums.NETWORK_TYPE_EDGE; // = 2. 2475 /** Current network is UMTS */ 2476 public static final int NETWORK_TYPE_UMTS = TelephonyProtoEnums.NETWORK_TYPE_UMTS; // = 3. 2477 /** Current network is CDMA: Either IS95A or IS95B*/ 2478 public static final int NETWORK_TYPE_CDMA = TelephonyProtoEnums.NETWORK_TYPE_CDMA; // = 4. 2479 /** Current network is EVDO revision 0*/ 2480 public static final int NETWORK_TYPE_EVDO_0 = TelephonyProtoEnums.NETWORK_TYPE_EVDO_0; // = 5. 2481 /** Current network is EVDO revision A*/ 2482 public static final int NETWORK_TYPE_EVDO_A = TelephonyProtoEnums.NETWORK_TYPE_EVDO_A; // = 6. 2483 /** Current network is 1xRTT*/ 2484 public static final int NETWORK_TYPE_1xRTT = TelephonyProtoEnums.NETWORK_TYPE_1XRTT; // = 7. 2485 /** Current network is HSDPA */ 2486 public static final int NETWORK_TYPE_HSDPA = TelephonyProtoEnums.NETWORK_TYPE_HSDPA; // = 8. 2487 /** Current network is HSUPA */ 2488 public static final int NETWORK_TYPE_HSUPA = TelephonyProtoEnums.NETWORK_TYPE_HSUPA; // = 9. 2489 /** Current network is HSPA */ 2490 public static final int NETWORK_TYPE_HSPA = TelephonyProtoEnums.NETWORK_TYPE_HSPA; // = 10. 2491 /** Current network is iDen */ 2492 public static final int NETWORK_TYPE_IDEN = TelephonyProtoEnums.NETWORK_TYPE_IDEN; // = 11. 2493 /** Current network is EVDO revision B*/ 2494 public static final int NETWORK_TYPE_EVDO_B = TelephonyProtoEnums.NETWORK_TYPE_EVDO_B; // = 12. 2495 /** Current network is LTE */ 2496 public static final int NETWORK_TYPE_LTE = TelephonyProtoEnums.NETWORK_TYPE_LTE; // = 13. 2497 /** Current network is eHRPD */ 2498 public static final int NETWORK_TYPE_EHRPD = TelephonyProtoEnums.NETWORK_TYPE_EHRPD; // = 14. 2499 /** Current network is HSPA+ */ 2500 public static final int NETWORK_TYPE_HSPAP = TelephonyProtoEnums.NETWORK_TYPE_HSPAP; // = 15. 2501 /** Current network is GSM */ 2502 public static final int NETWORK_TYPE_GSM = TelephonyProtoEnums.NETWORK_TYPE_GSM; // = 16. 2503 /** Current network is TD_SCDMA */ 2504 public static final int NETWORK_TYPE_TD_SCDMA = 2505 TelephonyProtoEnums.NETWORK_TYPE_TD_SCDMA; // = 17. 2506 /** Current network is IWLAN */ 2507 public static final int NETWORK_TYPE_IWLAN = TelephonyProtoEnums.NETWORK_TYPE_IWLAN; // = 18. 2508 /** Current network is LTE_CA {@hide} */ 2509 @UnsupportedAppUsage 2510 public static final int NETWORK_TYPE_LTE_CA = TelephonyProtoEnums.NETWORK_TYPE_LTE_CA; // = 19. 2511 /** Current network is NR(New Radio) 5G. */ 2512 public static final int NETWORK_TYPE_NR = TelephonyProtoEnums.NETWORK_TYPE_NR; // 20. 2513 2514 /** Max network type number. Update as new types are added. Don't add negative types. {@hide} */ 2515 public static final int MAX_NETWORK_TYPE = NETWORK_TYPE_NR; 2516 2517 /** @hide */ 2518 @IntDef({ 2519 NETWORK_TYPE_UNKNOWN, 2520 NETWORK_TYPE_GPRS, 2521 NETWORK_TYPE_EDGE, 2522 NETWORK_TYPE_UMTS, 2523 NETWORK_TYPE_CDMA, 2524 NETWORK_TYPE_EVDO_0, 2525 NETWORK_TYPE_EVDO_A, 2526 NETWORK_TYPE_1xRTT, 2527 NETWORK_TYPE_HSDPA, 2528 NETWORK_TYPE_HSUPA, 2529 NETWORK_TYPE_HSPA, 2530 NETWORK_TYPE_IDEN, 2531 NETWORK_TYPE_EVDO_B, 2532 NETWORK_TYPE_LTE, 2533 NETWORK_TYPE_EHRPD, 2534 NETWORK_TYPE_HSPAP, 2535 NETWORK_TYPE_GSM, 2536 NETWORK_TYPE_TD_SCDMA, 2537 NETWORK_TYPE_IWLAN, 2538 NETWORK_TYPE_LTE_CA, 2539 NETWORK_TYPE_NR, 2540 }) 2541 @Retention(RetentionPolicy.SOURCE) 2542 public @interface NetworkType{} 2543 2544 /** 2545 * @return the NETWORK_TYPE_xxxx for current data connection. 2546 */ getNetworkType()2547 public @NetworkType int getNetworkType() { 2548 return getNetworkType(getSubId(SubscriptionManager.getDefaultDataSubscriptionId())); 2549 } 2550 2551 /** 2552 * Returns a constant indicating the radio technology (network type) 2553 * currently in use on the device for a subscription. 2554 * @return the network type 2555 * 2556 * @param subId for which network type is returned 2557 * 2558 * @see #NETWORK_TYPE_UNKNOWN 2559 * @see #NETWORK_TYPE_GPRS 2560 * @see #NETWORK_TYPE_EDGE 2561 * @see #NETWORK_TYPE_UMTS 2562 * @see #NETWORK_TYPE_HSDPA 2563 * @see #NETWORK_TYPE_HSUPA 2564 * @see #NETWORK_TYPE_HSPA 2565 * @see #NETWORK_TYPE_CDMA 2566 * @see #NETWORK_TYPE_EVDO_0 2567 * @see #NETWORK_TYPE_EVDO_A 2568 * @see #NETWORK_TYPE_EVDO_B 2569 * @see #NETWORK_TYPE_1xRTT 2570 * @see #NETWORK_TYPE_IDEN 2571 * @see #NETWORK_TYPE_LTE 2572 * @see #NETWORK_TYPE_EHRPD 2573 * @see #NETWORK_TYPE_HSPAP 2574 * @see #NETWORK_TYPE_NR 2575 * 2576 * @hide 2577 */ 2578 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 2579 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getNetworkType(int subId)2580 public int getNetworkType(int subId) { 2581 try { 2582 ITelephony telephony = getITelephony(); 2583 if (telephony != null) { 2584 return telephony.getNetworkTypeForSubscriber(subId, getOpPackageName()); 2585 } else { 2586 // This can happen when the ITelephony interface is not up yet. 2587 return NETWORK_TYPE_UNKNOWN; 2588 } 2589 } catch (RemoteException ex) { 2590 // This shouldn't happen in the normal case 2591 return NETWORK_TYPE_UNKNOWN; 2592 } catch (NullPointerException ex) { 2593 // This could happen before phone restarts due to crashing 2594 return NETWORK_TYPE_UNKNOWN; 2595 } 2596 } 2597 2598 /** 2599 * Returns a constant indicating the radio technology (network type) 2600 * currently in use on the device for data transmission. 2601 * 2602 * If this object has been created with {@link #createForSubscriptionId}, applies to the given 2603 * subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 2604 * 2605 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2606 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 2607 * 2608 * @return the network type 2609 * 2610 * @see #NETWORK_TYPE_UNKNOWN 2611 * @see #NETWORK_TYPE_GPRS 2612 * @see #NETWORK_TYPE_EDGE 2613 * @see #NETWORK_TYPE_UMTS 2614 * @see #NETWORK_TYPE_HSDPA 2615 * @see #NETWORK_TYPE_HSUPA 2616 * @see #NETWORK_TYPE_HSPA 2617 * @see #NETWORK_TYPE_CDMA 2618 * @see #NETWORK_TYPE_EVDO_0 2619 * @see #NETWORK_TYPE_EVDO_A 2620 * @see #NETWORK_TYPE_EVDO_B 2621 * @see #NETWORK_TYPE_1xRTT 2622 * @see #NETWORK_TYPE_IDEN 2623 * @see #NETWORK_TYPE_LTE 2624 * @see #NETWORK_TYPE_EHRPD 2625 * @see #NETWORK_TYPE_HSPAP 2626 * @see #NETWORK_TYPE_NR 2627 */ 2628 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 2629 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getDataNetworkType()2630 public @NetworkType int getDataNetworkType() { 2631 return getDataNetworkType(getSubId(SubscriptionManager.getDefaultDataSubscriptionId())); 2632 } 2633 2634 /** 2635 * Returns a constant indicating the radio technology (network type) 2636 * currently in use on the device for data transmission for a subscription 2637 * @return the network type 2638 * 2639 * @param subId for which network type is returned 2640 * @hide 2641 */ 2642 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 2643 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getDataNetworkType(int subId)2644 public int getDataNetworkType(int subId) { 2645 try{ 2646 ITelephony telephony = getITelephony(); 2647 if (telephony != null) { 2648 return telephony.getDataNetworkTypeForSubscriber(subId, getOpPackageName()); 2649 } else { 2650 // This can happen when the ITelephony interface is not up yet. 2651 return NETWORK_TYPE_UNKNOWN; 2652 } 2653 } catch(RemoteException ex) { 2654 // This shouldn't happen in the normal case 2655 return NETWORK_TYPE_UNKNOWN; 2656 } catch (NullPointerException ex) { 2657 // This could happen before phone restarts due to crashing 2658 return NETWORK_TYPE_UNKNOWN; 2659 } 2660 } 2661 2662 /** 2663 * Returns the NETWORK_TYPE_xxxx for voice 2664 * 2665 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2666 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 2667 */ 2668 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 2669 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceNetworkType()2670 public @NetworkType int getVoiceNetworkType() { 2671 return getVoiceNetworkType(getSubId()); 2672 } 2673 2674 /** 2675 * Returns the NETWORK_TYPE_xxxx for voice for a subId 2676 * @hide 2677 */ 2678 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 2679 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getVoiceNetworkType(int subId)2680 public int getVoiceNetworkType(int subId) { 2681 try{ 2682 ITelephony telephony = getITelephony(); 2683 if (telephony != null) { 2684 return telephony.getVoiceNetworkTypeForSubscriber(subId, getOpPackageName()); 2685 } else { 2686 // This can happen when the ITelephony interface is not up yet. 2687 return NETWORK_TYPE_UNKNOWN; 2688 } 2689 } catch(RemoteException ex) { 2690 // This shouldn't happen in the normal case 2691 return NETWORK_TYPE_UNKNOWN; 2692 } catch (NullPointerException ex) { 2693 // This could happen before phone restarts due to crashing 2694 return NETWORK_TYPE_UNKNOWN; 2695 } 2696 } 2697 2698 /** 2699 * Network Class Definitions. 2700 * Do not change this order, it is used for sorting during emergency calling in 2701 * {@link TelephonyConnectionService#getFirstPhoneForEmergencyCall()}. Any newer technologies 2702 * should be added after the current definitions. 2703 */ 2704 /** Unknown network class. {@hide} */ 2705 public static final int NETWORK_CLASS_UNKNOWN = 0; 2706 /** Class of broadly defined "2G" networks. {@hide} */ 2707 @UnsupportedAppUsage 2708 public static final int NETWORK_CLASS_2_G = 1; 2709 /** Class of broadly defined "3G" networks. {@hide} */ 2710 @UnsupportedAppUsage 2711 public static final int NETWORK_CLASS_3_G = 2; 2712 /** Class of broadly defined "4G" networks. {@hide} */ 2713 @UnsupportedAppUsage 2714 public static final int NETWORK_CLASS_4_G = 3; 2715 2716 /** 2717 * Return general class of network type, such as "3G" or "4G". In cases 2718 * where classification is contentious, this method is conservative. 2719 * 2720 * @hide 2721 */ 2722 @UnsupportedAppUsage getNetworkClass(int networkType)2723 public static int getNetworkClass(int networkType) { 2724 switch (networkType) { 2725 case NETWORK_TYPE_GPRS: 2726 case NETWORK_TYPE_GSM: 2727 case NETWORK_TYPE_EDGE: 2728 case NETWORK_TYPE_CDMA: 2729 case NETWORK_TYPE_1xRTT: 2730 case NETWORK_TYPE_IDEN: 2731 return NETWORK_CLASS_2_G; 2732 case NETWORK_TYPE_UMTS: 2733 case NETWORK_TYPE_EVDO_0: 2734 case NETWORK_TYPE_EVDO_A: 2735 case NETWORK_TYPE_HSDPA: 2736 case NETWORK_TYPE_HSUPA: 2737 case NETWORK_TYPE_HSPA: 2738 case NETWORK_TYPE_EVDO_B: 2739 case NETWORK_TYPE_EHRPD: 2740 case NETWORK_TYPE_HSPAP: 2741 case NETWORK_TYPE_TD_SCDMA: 2742 return NETWORK_CLASS_3_G; 2743 case NETWORK_TYPE_LTE: 2744 case NETWORK_TYPE_IWLAN: 2745 case NETWORK_TYPE_LTE_CA: 2746 return NETWORK_CLASS_4_G; 2747 default: 2748 return NETWORK_CLASS_UNKNOWN; 2749 } 2750 } 2751 2752 /** 2753 * Returns a string representation of the radio technology (network type) 2754 * currently in use on the device. 2755 * @return the name of the radio technology 2756 * 2757 * @hide pending API council review 2758 */ 2759 @UnsupportedAppUsage getNetworkTypeName()2760 public String getNetworkTypeName() { 2761 return getNetworkTypeName(getNetworkType()); 2762 } 2763 2764 /** 2765 * Returns a string representation of the radio technology (network type) 2766 * currently in use on the device. 2767 * @param subId for which network type is returned 2768 * @return the name of the radio technology 2769 * 2770 */ 2771 /** {@hide} */ 2772 @UnsupportedAppUsage getNetworkTypeName(@etworkType int type)2773 public static String getNetworkTypeName(@NetworkType int type) { 2774 switch (type) { 2775 case NETWORK_TYPE_GPRS: 2776 return "GPRS"; 2777 case NETWORK_TYPE_EDGE: 2778 return "EDGE"; 2779 case NETWORK_TYPE_UMTS: 2780 return "UMTS"; 2781 case NETWORK_TYPE_HSDPA: 2782 return "HSDPA"; 2783 case NETWORK_TYPE_HSUPA: 2784 return "HSUPA"; 2785 case NETWORK_TYPE_HSPA: 2786 return "HSPA"; 2787 case NETWORK_TYPE_CDMA: 2788 return "CDMA"; 2789 case NETWORK_TYPE_EVDO_0: 2790 return "CDMA - EvDo rev. 0"; 2791 case NETWORK_TYPE_EVDO_A: 2792 return "CDMA - EvDo rev. A"; 2793 case NETWORK_TYPE_EVDO_B: 2794 return "CDMA - EvDo rev. B"; 2795 case NETWORK_TYPE_1xRTT: 2796 return "CDMA - 1xRTT"; 2797 case NETWORK_TYPE_LTE: 2798 return "LTE"; 2799 case NETWORK_TYPE_EHRPD: 2800 return "CDMA - eHRPD"; 2801 case NETWORK_TYPE_IDEN: 2802 return "iDEN"; 2803 case NETWORK_TYPE_HSPAP: 2804 return "HSPA+"; 2805 case NETWORK_TYPE_GSM: 2806 return "GSM"; 2807 case NETWORK_TYPE_TD_SCDMA: 2808 return "TD_SCDMA"; 2809 case NETWORK_TYPE_IWLAN: 2810 return "IWLAN"; 2811 case NETWORK_TYPE_LTE_CA: 2812 return "LTE_CA"; 2813 case NETWORK_TYPE_NR: 2814 return "NR"; 2815 default: 2816 return "UNKNOWN"; 2817 } 2818 } 2819 2820 // 2821 // 2822 // SIM Card 2823 // 2824 // 2825 2826 /** 2827 * SIM card state: Unknown. Signifies that the SIM is in transition 2828 * between states. For example, when the user inputs the SIM pin 2829 * under PIN_REQUIRED state, a query for sim status returns 2830 * this state before turning to SIM_STATE_READY. 2831 * 2832 * These are the ordinal value of IccCardConstants.State. 2833 */ 2834 2835 public static final int SIM_STATE_UNKNOWN = TelephonyProtoEnums.SIM_STATE_UNKNOWN; // 0 2836 /** SIM card state: no SIM card is available in the device */ 2837 public static final int SIM_STATE_ABSENT = TelephonyProtoEnums.SIM_STATE_ABSENT; // 1 2838 /** SIM card state: Locked: requires the user's SIM PIN to unlock */ 2839 public static final int SIM_STATE_PIN_REQUIRED = 2840 TelephonyProtoEnums.SIM_STATE_PIN_REQUIRED; // 2 2841 /** SIM card state: Locked: requires the user's SIM PUK to unlock */ 2842 public static final int SIM_STATE_PUK_REQUIRED = 2843 TelephonyProtoEnums.SIM_STATE_PUK_REQUIRED; // 3 2844 /** SIM card state: Locked: requires a network PIN to unlock */ 2845 public static final int SIM_STATE_NETWORK_LOCKED = 2846 TelephonyProtoEnums.SIM_STATE_NETWORK_LOCKED; // 4 2847 /** SIM card state: Ready */ 2848 public static final int SIM_STATE_READY = TelephonyProtoEnums.SIM_STATE_READY; // 5 2849 /** SIM card state: SIM Card is NOT READY */ 2850 public static final int SIM_STATE_NOT_READY = TelephonyProtoEnums.SIM_STATE_NOT_READY; // 6 2851 /** SIM card state: SIM Card Error, permanently disabled */ 2852 public static final int SIM_STATE_PERM_DISABLED = 2853 TelephonyProtoEnums.SIM_STATE_PERM_DISABLED; // 7 2854 /** SIM card state: SIM Card Error, present but faulty */ 2855 public static final int SIM_STATE_CARD_IO_ERROR = 2856 TelephonyProtoEnums.SIM_STATE_CARD_IO_ERROR; // 8 2857 /** SIM card state: SIM Card restricted, present but not usable due to 2858 * carrier restrictions. 2859 */ 2860 public static final int SIM_STATE_CARD_RESTRICTED = 2861 TelephonyProtoEnums.SIM_STATE_CARD_RESTRICTED; // 9 2862 /** 2863 * SIM card state: Loaded: SIM card applications have been loaded 2864 * @hide 2865 */ 2866 @SystemApi 2867 public static final int SIM_STATE_LOADED = TelephonyProtoEnums.SIM_STATE_LOADED; // 10 2868 /** 2869 * SIM card state: SIM Card is present 2870 * @hide 2871 */ 2872 @SystemApi 2873 public static final int SIM_STATE_PRESENT = TelephonyProtoEnums.SIM_STATE_PRESENT; // 11 2874 2875 /** 2876 * Extra included in {@link #ACTION_SIM_CARD_STATE_CHANGED} and 2877 * {@link #ACTION_SIM_APPLICATION_STATE_CHANGED} to indicate the card/application state. 2878 * 2879 * @hide 2880 */ 2881 @SystemApi 2882 public static final String EXTRA_SIM_STATE = "android.telephony.extra.SIM_STATE"; 2883 2884 /** 2885 * Broadcast Action: The sim card state has changed. 2886 * The intent will have the following extra values:</p> 2887 * <dl> 2888 * <dt>{@link #EXTRA_SIM_STATE}</dt> 2889 * <dd>The sim card state. One of: 2890 * <dl> 2891 * <dt>{@link #SIM_STATE_ABSENT}</dt> 2892 * <dd>SIM card not found</dd> 2893 * <dt>{@link #SIM_STATE_CARD_IO_ERROR}</dt> 2894 * <dd>SIM card IO error</dd> 2895 * <dt>{@link #SIM_STATE_CARD_RESTRICTED}</dt> 2896 * <dd>SIM card is restricted</dd> 2897 * <dt>{@link #SIM_STATE_PRESENT}</dt> 2898 * <dd>SIM card is present</dd> 2899 * </dl> 2900 * </dd> 2901 * </dl> 2902 * 2903 * <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission. 2904 * 2905 * <p class="note">The current state can also be queried using {@link #getSimCardState()}. 2906 * 2907 * <p class="note">This is a protected intent that can only be sent by the system. 2908 * @hide 2909 */ 2910 @SystemApi 2911 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 2912 public static final String ACTION_SIM_CARD_STATE_CHANGED = 2913 "android.telephony.action.SIM_CARD_STATE_CHANGED"; 2914 2915 /** 2916 * Broadcast Action: The sim application state has changed. 2917 * The intent will have the following extra values:</p> 2918 * <dl> 2919 * <dt>{@link #EXTRA_SIM_STATE}</dt> 2920 * <dd>The sim application state. One of: 2921 * <dl> 2922 * <dt>{@link #SIM_STATE_NOT_READY}</dt> 2923 * <dd>SIM card applications not ready</dd> 2924 * <dt>{@link #SIM_STATE_PIN_REQUIRED}</dt> 2925 * <dd>SIM card PIN locked</dd> 2926 * <dt>{@link #SIM_STATE_PUK_REQUIRED}</dt> 2927 * <dd>SIM card PUK locked</dd> 2928 * <dt>{@link #SIM_STATE_NETWORK_LOCKED}</dt> 2929 * <dd>SIM card network locked</dd> 2930 * <dt>{@link #SIM_STATE_PERM_DISABLED}</dt> 2931 * <dd>SIM card permanently disabled due to PUK failures</dd> 2932 * <dt>{@link #SIM_STATE_LOADED}</dt> 2933 * <dd>SIM card data loaded</dd> 2934 * </dl> 2935 * </dd> 2936 * </dl> 2937 * 2938 * <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission. 2939 * 2940 * <p class="note">The current state can also be queried using 2941 * {@link #getSimApplicationState()}. 2942 * 2943 * <p class="note">This is a protected intent that can only be sent by the system. 2944 * @hide 2945 */ 2946 @SystemApi 2947 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 2948 public static final String ACTION_SIM_APPLICATION_STATE_CHANGED = 2949 "android.telephony.action.SIM_APPLICATION_STATE_CHANGED"; 2950 2951 /** 2952 * Broadcast Action: Status of the SIM slots on the device has changed. 2953 * 2954 * <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission. 2955 * 2956 * <p class="note">The status can be queried using 2957 * {@link #getUiccSlotsInfo()} 2958 * 2959 * <p class="note">This is a protected intent that can only be sent by the system. 2960 * @hide 2961 */ 2962 @SystemApi 2963 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 2964 public static final String ACTION_SIM_SLOT_STATUS_CHANGED = 2965 "android.telephony.action.SIM_SLOT_STATUS_CHANGED"; 2966 2967 /** 2968 * Broadcast Action: A debug code has been entered in the dialer. 2969 * <p> 2970 * This intent is broadcast by the system and OEM telephony apps may need to receive these 2971 * broadcasts. And it requires the sender to be default dialer or has carrier privileges 2972 * (see {@link #hasCarrierPrivileges}). 2973 * <p> 2974 * These "secret codes" are used to activate developer menus by dialing certain codes. 2975 * And they are of the form {@code *#*#<code>#*#*}. The intent will have the data 2976 * URI: {@code android_secret_code://<code>}. It is possible that a manifest 2977 * receiver would be woken up even if it is not currently running. 2978 * <p> 2979 * It is supposed to replace {@link android.provider.Telephony.Sms.Intents#SECRET_CODE_ACTION} 2980 * in the next Android version. 2981 * Before that both of these two actions will be broadcast. 2982 */ 2983 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 2984 public static final String ACTION_SECRET_CODE = "android.telephony.action.SECRET_CODE"; 2985 2986 /** 2987 * @return true if a ICC card is present 2988 */ hasIccCard()2989 public boolean hasIccCard() { 2990 return hasIccCard(getSlotIndex()); 2991 } 2992 2993 /** 2994 * @return true if a ICC card is present for a subscription 2995 * 2996 * @param slotIndex for which icc card presence is checked 2997 */ 2998 /** {@hide} */ 2999 // FIXME Input argument slotIndex should be of type int 3000 @UnsupportedAppUsage hasIccCard(int slotIndex)3001 public boolean hasIccCard(int slotIndex) { 3002 3003 try { 3004 ITelephony telephony = getITelephony(); 3005 if (telephony == null) 3006 return false; 3007 return telephony.hasIccCardUsingSlotIndex(slotIndex); 3008 } catch (RemoteException ex) { 3009 // Assume no ICC card if remote exception which shouldn't happen 3010 return false; 3011 } catch (NullPointerException ex) { 3012 // This could happen before phone restarts due to crashing 3013 return false; 3014 } 3015 } 3016 3017 /** 3018 * Returns a constant indicating the state of the default SIM card. 3019 * 3020 * @see #SIM_STATE_UNKNOWN 3021 * @see #SIM_STATE_ABSENT 3022 * @see #SIM_STATE_PIN_REQUIRED 3023 * @see #SIM_STATE_PUK_REQUIRED 3024 * @see #SIM_STATE_NETWORK_LOCKED 3025 * @see #SIM_STATE_READY 3026 * @see #SIM_STATE_NOT_READY 3027 * @see #SIM_STATE_PERM_DISABLED 3028 * @see #SIM_STATE_CARD_IO_ERROR 3029 * @see #SIM_STATE_CARD_RESTRICTED 3030 */ getSimState()3031 public int getSimState() { 3032 int simState = getSimStateIncludingLoaded(); 3033 if (simState == SIM_STATE_LOADED) { 3034 simState = SIM_STATE_READY; 3035 } 3036 return simState; 3037 } 3038 getSimStateIncludingLoaded()3039 private int getSimStateIncludingLoaded() { 3040 int slotIndex = getSlotIndex(); 3041 // slotIndex may be invalid due to sim being absent. In that case query all slots to get 3042 // sim state 3043 if (slotIndex < 0) { 3044 // query for all slots and return absent if all sim states are absent, otherwise 3045 // return unknown 3046 for (int i = 0; i < getPhoneCount(); i++) { 3047 int simState = getSimState(i); 3048 if (simState != SIM_STATE_ABSENT) { 3049 Rlog.d(TAG, "getSimState: default sim:" + slotIndex + ", sim state for " + 3050 "slotIndex=" + i + " is " + simState + ", return state as unknown"); 3051 return SIM_STATE_UNKNOWN; 3052 } 3053 } 3054 Rlog.d(TAG, "getSimState: default sim:" + slotIndex + ", all SIMs absent, return " + 3055 "state as absent"); 3056 return SIM_STATE_ABSENT; 3057 } 3058 return SubscriptionManager.getSimStateForSlotIndex(slotIndex); 3059 } 3060 3061 /** 3062 * Returns a constant indicating the state of the default SIM card. 3063 * 3064 * @see #SIM_STATE_UNKNOWN 3065 * @see #SIM_STATE_ABSENT 3066 * @see #SIM_STATE_CARD_IO_ERROR 3067 * @see #SIM_STATE_CARD_RESTRICTED 3068 * @see #SIM_STATE_PRESENT 3069 * 3070 * @hide 3071 */ 3072 @SystemApi getSimCardState()3073 public int getSimCardState() { 3074 int simCardState = getSimState(); 3075 switch (simCardState) { 3076 case SIM_STATE_UNKNOWN: 3077 case SIM_STATE_ABSENT: 3078 case SIM_STATE_CARD_IO_ERROR: 3079 case SIM_STATE_CARD_RESTRICTED: 3080 return simCardState; 3081 default: 3082 return SIM_STATE_PRESENT; 3083 } 3084 } 3085 3086 /** 3087 * Returns a constant indicating the state of the card applications on the default SIM card. 3088 * 3089 * @see #SIM_STATE_UNKNOWN 3090 * @see #SIM_STATE_PIN_REQUIRED 3091 * @see #SIM_STATE_PUK_REQUIRED 3092 * @see #SIM_STATE_NETWORK_LOCKED 3093 * @see #SIM_STATE_NOT_READY 3094 * @see #SIM_STATE_PERM_DISABLED 3095 * @see #SIM_STATE_LOADED 3096 * 3097 * @hide 3098 */ 3099 @SystemApi getSimApplicationState()3100 public int getSimApplicationState() { 3101 int simApplicationState = getSimStateIncludingLoaded(); 3102 switch (simApplicationState) { 3103 case SIM_STATE_UNKNOWN: 3104 case SIM_STATE_ABSENT: 3105 case SIM_STATE_CARD_IO_ERROR: 3106 case SIM_STATE_CARD_RESTRICTED: 3107 return SIM_STATE_UNKNOWN; 3108 case SIM_STATE_READY: 3109 // Ready is not a valid state anymore. The state that is broadcast goes from 3110 // NOT_READY to either LOCKED or LOADED. 3111 return SIM_STATE_NOT_READY; 3112 default: 3113 return simApplicationState; 3114 } 3115 } 3116 3117 /** 3118 * Returns a constant indicating the state of the device SIM card in a slot. 3119 * 3120 * @param slotIndex 3121 * 3122 * @see #SIM_STATE_UNKNOWN 3123 * @see #SIM_STATE_ABSENT 3124 * @see #SIM_STATE_PIN_REQUIRED 3125 * @see #SIM_STATE_PUK_REQUIRED 3126 * @see #SIM_STATE_NETWORK_LOCKED 3127 * @see #SIM_STATE_READY 3128 * @see #SIM_STATE_NOT_READY 3129 * @see #SIM_STATE_PERM_DISABLED 3130 * @see #SIM_STATE_CARD_IO_ERROR 3131 * @see #SIM_STATE_CARD_RESTRICTED 3132 */ getSimState(int slotIndex)3133 public int getSimState(int slotIndex) { 3134 int simState = SubscriptionManager.getSimStateForSlotIndex(slotIndex); 3135 if (simState == SIM_STATE_LOADED) { 3136 simState = SIM_STATE_READY; 3137 } 3138 return simState; 3139 } 3140 3141 /** 3142 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3143 * provider of the SIM. 5 or 6 decimal digits. 3144 * <p> 3145 * Availability: SIM state must be {@link #SIM_STATE_READY} 3146 * 3147 * @see #getSimState 3148 */ getSimOperator()3149 public String getSimOperator() { 3150 return getSimOperatorNumeric(); 3151 } 3152 3153 /** 3154 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3155 * provider of the SIM. 5 or 6 decimal digits. 3156 * <p> 3157 * Availability: SIM state must be {@link #SIM_STATE_READY} 3158 * 3159 * @see #getSimState 3160 * 3161 * @param subId for which SimOperator is returned 3162 * @hide 3163 */ 3164 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperator(int subId)3165 public String getSimOperator(int subId) { 3166 return getSimOperatorNumeric(subId); 3167 } 3168 3169 /** 3170 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3171 * provider of the SIM. 5 or 6 decimal digits. 3172 * <p> 3173 * Availability: SIM state must be {@link #SIM_STATE_READY} 3174 * 3175 * @see #getSimState 3176 * @hide 3177 */ 3178 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperatorNumeric()3179 public String getSimOperatorNumeric() { 3180 int subId = mSubId; 3181 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 3182 subId = SubscriptionManager.getDefaultDataSubscriptionId(); 3183 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 3184 subId = SubscriptionManager.getDefaultSmsSubscriptionId(); 3185 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 3186 subId = SubscriptionManager.getDefaultVoiceSubscriptionId(); 3187 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 3188 subId = SubscriptionManager.getDefaultSubscriptionId(); 3189 } 3190 } 3191 } 3192 } 3193 return getSimOperatorNumeric(subId); 3194 } 3195 3196 /** 3197 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3198 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 3199 * <p> 3200 * Availability: SIM state must be {@link #SIM_STATE_READY} 3201 * 3202 * @see #getSimState 3203 * 3204 * @param subId for which SimOperator is returned 3205 * @hide 3206 */ 3207 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperatorNumeric(int subId)3208 public String getSimOperatorNumeric(int subId) { 3209 int phoneId = SubscriptionManager.getPhoneId(subId); 3210 return getSimOperatorNumericForPhone(phoneId); 3211 } 3212 3213 /** 3214 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3215 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 3216 * <p> 3217 * 3218 * @param phoneId for which SimOperator is returned 3219 * @hide 3220 */ 3221 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperatorNumericForPhone(int phoneId)3222 public String getSimOperatorNumericForPhone(int phoneId) { 3223 return getTelephonyProperty(phoneId, 3224 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, ""); 3225 } 3226 3227 /** 3228 * Returns the Service Provider Name (SPN). 3229 * <p> 3230 * Availability: SIM state must be {@link #SIM_STATE_READY} 3231 * 3232 * @see #getSimState 3233 */ getSimOperatorName()3234 public String getSimOperatorName() { 3235 return getSimOperatorNameForPhone(getPhoneId()); 3236 } 3237 3238 /** 3239 * Returns the Service Provider Name (SPN). 3240 * <p> 3241 * Availability: SIM state must be {@link #SIM_STATE_READY} 3242 * 3243 * @see #getSimState 3244 * 3245 * @param subId for which SimOperatorName is returned 3246 * @hide 3247 */ 3248 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperatorName(int subId)3249 public String getSimOperatorName(int subId) { 3250 int phoneId = SubscriptionManager.getPhoneId(subId); 3251 return getSimOperatorNameForPhone(phoneId); 3252 } 3253 3254 /** 3255 * Returns the Service Provider Name (SPN). 3256 * 3257 * @hide 3258 */ 3259 @UnsupportedAppUsage getSimOperatorNameForPhone(int phoneId)3260 public String getSimOperatorNameForPhone(int phoneId) { 3261 return getTelephonyProperty(phoneId, 3262 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, ""); 3263 } 3264 3265 /** 3266 * Returns the ISO country code equivalent for the SIM provider's country code. 3267 */ getSimCountryIso()3268 public String getSimCountryIso() { 3269 return getSimCountryIsoForPhone(getPhoneId()); 3270 } 3271 3272 /** 3273 * Returns the ISO country code equivalent for the SIM provider's country code. 3274 * 3275 * @param subId for which SimCountryIso is returned 3276 * @hide 3277 */ 3278 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimCountryIso(int subId)3279 public String getSimCountryIso(int subId) { 3280 int phoneId = SubscriptionManager.getPhoneId(subId); 3281 return getSimCountryIsoForPhone(phoneId); 3282 } 3283 3284 /** 3285 * Returns the ISO country code equivalent for the SIM provider's country code. 3286 * 3287 * @hide 3288 */ 3289 @UnsupportedAppUsage getSimCountryIsoForPhone(int phoneId)3290 public String getSimCountryIsoForPhone(int phoneId) { 3291 return getTelephonyProperty(phoneId, 3292 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, ""); 3293 } 3294 3295 /** 3296 * Returns the serial number of the SIM, if applicable. Return null if it is 3297 * unavailable. 3298 * 3299 * <p>Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or 3300 * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier 3301 * privileges (see {@link #hasCarrierPrivileges}). The profile owner is an app that owns a 3302 * managed profile on the device; for more details see <a 3303 * href="https://developer.android.com/work/managed-profiles">Work profiles</a>. Profile owner 3304 * access is deprecated and will be removed in a future release. 3305 * 3306 * <p>If the calling app does not meet one of these requirements then this method will behave 3307 * as follows: 3308 * 3309 * <ul> 3310 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 3311 * READ_PHONE_STATE permission then null is returned.</li> 3312 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 3313 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 3314 * higher, then a SecurityException is thrown.</li> 3315 * </ul> 3316 */ 3317 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 3318 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getSimSerialNumber()3319 public String getSimSerialNumber() { 3320 return getSimSerialNumber(getSubId()); 3321 } 3322 3323 /** 3324 * Returns the serial number for the given subscription, if applicable. Return null if it is 3325 * unavailable. 3326 * 3327 * <p>Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or 3328 * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier 3329 * privileges (see {@link #hasCarrierPrivileges}). The profile owner is an app that owns a 3330 * managed profile on the device; for more details see <a 3331 * href="https://developer.android.com/work/managed-profiles">Work profiles</a>. Profile owner 3332 * access is deprecated and will be removed in a future release. 3333 * 3334 * <p>If the calling app does not meet one of these requirements then this method will behave 3335 * as follows: 3336 * 3337 * <ul> 3338 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 3339 * READ_PHONE_STATE permission then null is returned.</li> 3340 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 3341 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 3342 * higher, then a SecurityException is thrown.</li> 3343 * </ul> 3344 * 3345 * @param subId for which Sim Serial number is returned 3346 * @hide 3347 */ 3348 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 3349 @UnsupportedAppUsage getSimSerialNumber(int subId)3350 public String getSimSerialNumber(int subId) { 3351 try { 3352 IPhoneSubInfo info = getSubscriberInfo(); 3353 if (info == null) 3354 return null; 3355 return info.getIccSerialNumberForSubscriber(subId, mContext.getOpPackageName()); 3356 } catch (RemoteException ex) { 3357 return null; 3358 } catch (NullPointerException ex) { 3359 // This could happen before phone restarts due to crashing 3360 return null; 3361 } 3362 } 3363 3364 /** 3365 * Return if the current radio is LTE on CDMA. This is a tri-state return value as for a period 3366 * of time the mode may be unknown. 3367 * 3368 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 3369 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 3370 * 3371 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 3372 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 3373 * 3374 * @hide 3375 */ 3376 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 3377 @UnsupportedAppUsage getLteOnCdmaMode()3378 public int getLteOnCdmaMode() { 3379 return getLteOnCdmaMode(getSubId()); 3380 } 3381 3382 /** 3383 * Return if the current radio is LTE on CDMA for Subscription. This 3384 * is a tri-state return value as for a period of time 3385 * the mode may be unknown. 3386 * 3387 * @param subId for which radio is LTE on CDMA is returned 3388 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 3389 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 3390 * @hide 3391 */ 3392 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 3393 @UnsupportedAppUsage getLteOnCdmaMode(int subId)3394 public int getLteOnCdmaMode(int subId) { 3395 try { 3396 ITelephony telephony = getITelephony(); 3397 if (telephony == null) 3398 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 3399 return telephony.getLteOnCdmaModeForSubscriber(subId, getOpPackageName()); 3400 } catch (RemoteException ex) { 3401 // Assume no ICC card if remote exception which shouldn't happen 3402 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 3403 } catch (NullPointerException ex) { 3404 // This could happen before phone restarts due to crashing 3405 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 3406 } 3407 } 3408 3409 /** 3410 * Get the card ID of the default eUICC card. If the eUICCs have not yet been loaded, returns 3411 * {@link #UNINITIALIZED_CARD_ID}. If there is no eUICC or the device does not support card IDs 3412 * for eUICCs, returns {@link #UNSUPPORTED_CARD_ID}. 3413 * 3414 * <p>The card ID is a unique identifier associated with a UICC or eUICC card. Card IDs are 3415 * unique to a device, and always refer to the same UICC or eUICC card unless the device goes 3416 * through a factory reset. 3417 * 3418 * @return card ID of the default eUICC card, if loaded. 3419 */ getCardIdForDefaultEuicc()3420 public int getCardIdForDefaultEuicc() { 3421 try { 3422 ITelephony telephony = getITelephony(); 3423 if (telephony == null) { 3424 return UNINITIALIZED_CARD_ID; 3425 } 3426 return telephony.getCardIdForDefaultEuicc(mSubId, mContext.getOpPackageName()); 3427 } catch (RemoteException e) { 3428 return UNINITIALIZED_CARD_ID; 3429 } 3430 } 3431 3432 /** 3433 * Gets information about currently inserted UICCs and eUICCs. 3434 * <p> 3435 * Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3436 * <p> 3437 * If the caller has carrier priviliges on any active subscription, then they have permission to 3438 * get simple information like the card ID ({@link UiccCardInfo#getCardId()}), whether the card 3439 * is an eUICC ({@link UiccCardInfo#isEuicc()}), and the slot index where the card is inserted 3440 * ({@link UiccCardInfo#getSlotIndex()}). 3441 * <p> 3442 * To get private information such as the EID ({@link UiccCardInfo#getEid()}) or ICCID 3443 * ({@link UiccCardInfo#getIccId()}), the caller must have carrier priviliges on that specific 3444 * UICC or eUICC card. 3445 * <p> 3446 * See {@link UiccCardInfo} for more details on the kind of information available. 3447 * 3448 * @return a list of UiccCardInfo objects, representing information on the currently inserted 3449 * UICCs and eUICCs. Each UiccCardInfo in the list will have private information filtered out if 3450 * the caller does not have adequate permissions for that card. 3451 */ 3452 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 3453 @NonNull getUiccCardsInfo()3454 public List<UiccCardInfo> getUiccCardsInfo() { 3455 try { 3456 ITelephony telephony = getITelephony(); 3457 if (telephony == null) { 3458 Log.e(TAG, "Error in getUiccCardsInfo: unable to connect to Telephony service."); 3459 return new ArrayList<UiccCardInfo>(); 3460 } 3461 return telephony.getUiccCardsInfo(mContext.getOpPackageName()); 3462 } catch (RemoteException e) { 3463 Log.e(TAG, "Error in getUiccCardsInfo: " + e); 3464 return new ArrayList<UiccCardInfo>(); 3465 } 3466 } 3467 3468 /** 3469 * Gets all the UICC slots. The objects in the array can be null if the slot info is not 3470 * available, which is possible between phone process starting and getting slot info from modem. 3471 * 3472 * @return UiccSlotInfo array. 3473 * 3474 * @hide 3475 */ 3476 @SystemApi 3477 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getUiccSlotsInfo()3478 public UiccSlotInfo[] getUiccSlotsInfo() { 3479 try { 3480 ITelephony telephony = getITelephony(); 3481 if (telephony == null) { 3482 return null; 3483 } 3484 return telephony.getUiccSlotsInfo(); 3485 } catch (RemoteException e) { 3486 return null; 3487 } 3488 } 3489 3490 /** 3491 * Test method to reload the UICC profile. 3492 * 3493 * @hide 3494 */ 3495 @TestApi 3496 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) refreshUiccProfile()3497 public void refreshUiccProfile() { 3498 try { 3499 ITelephony telephony = getITelephony(); 3500 telephony.refreshUiccProfile(mSubId); 3501 } catch (RemoteException ex) { 3502 Rlog.w(TAG, "RemoteException", ex); 3503 } 3504 } 3505 3506 /** 3507 * Map logicalSlot to physicalSlot, and activate the physicalSlot if it is inactive. For 3508 * example, passing the physicalSlots array [1, 0] means mapping the first item 1, which is 3509 * physical slot index 1, to the logical slot 0; and mapping the second item 0, which is 3510 * physical slot index 0, to the logical slot 1. The index of the array means the index of the 3511 * logical slots. 3512 * 3513 * @param physicalSlots The content of the array represents the physical slot index. The array 3514 * size should be same as {@link #getUiccSlotsInfo()}. 3515 * @return boolean Return true if the switch succeeds, false if the switch fails. 3516 * @hide 3517 */ 3518 @SystemApi 3519 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) switchSlots(int[] physicalSlots)3520 public boolean switchSlots(int[] physicalSlots) { 3521 try { 3522 ITelephony telephony = getITelephony(); 3523 if (telephony == null) { 3524 return false; 3525 } 3526 return telephony.switchSlots(physicalSlots); 3527 } catch (RemoteException e) { 3528 return false; 3529 } 3530 } 3531 3532 /** 3533 * Get the mapping from logical slots to physical slots. The key of the map is the logical slot 3534 * id and the value is the physical slots id mapped to this logical slot id. 3535 * 3536 * @return a map indicates the mapping from logical slots to physical slots. The size of the map 3537 * should be {@link #getPhoneCount()} if success, otherwise return an empty map. 3538 * 3539 * @hide 3540 */ 3541 @SystemApi 3542 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 3543 @NonNull getLogicalToPhysicalSlotMapping()3544 public Map<Integer, Integer> getLogicalToPhysicalSlotMapping() { 3545 Map<Integer, Integer> slotMapping = new HashMap<>(); 3546 try { 3547 ITelephony telephony = getITelephony(); 3548 if (telephony != null) { 3549 int[] slotMappingArray = telephony.getSlotsMapping(); 3550 for (int i = 0; i < slotMappingArray.length; i++) { 3551 slotMapping.put(i, slotMappingArray[i]); 3552 } 3553 } 3554 } catch (RemoteException e) { 3555 Log.e(TAG, "getSlotsMapping RemoteException", e); 3556 } 3557 return slotMapping; 3558 } 3559 3560 // 3561 // 3562 // Subscriber Info 3563 // 3564 // 3565 3566 /** 3567 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 3568 * Return null if it is unavailable. 3569 * 3570 * <p>Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or 3571 * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier 3572 * privileges (see {@link #hasCarrierPrivileges}). The profile owner is an app that owns a 3573 * managed profile on the device; for more details see <a 3574 * href="https://developer.android.com/work/managed-profiles">Work profiles</a>. Profile owner 3575 * access is deprecated and will be removed in a future release. 3576 * 3577 * <p>If the calling app does not meet one of these requirements then this method will behave 3578 * as follows: 3579 * 3580 * <ul> 3581 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 3582 * READ_PHONE_STATE permission then null is returned.</li> 3583 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 3584 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 3585 * higher, then a SecurityException is thrown.</li> 3586 * </ul> 3587 */ 3588 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 3589 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getSubscriberId()3590 public String getSubscriberId() { 3591 return getSubscriberId(getSubId()); 3592 } 3593 3594 /** 3595 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone 3596 * for a subscription. 3597 * Return null if it is unavailable. 3598 * 3599 * <p>Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or 3600 * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier 3601 * privileges (see {@link #hasCarrierPrivileges}). The profile owner is an app that owns a 3602 * managed profile on the device; for more details see <a 3603 * href="https://developer.android.com/work/managed-profiles">Work profiles</a>. Profile owner 3604 * access is deprecated and will be removed in a future release. 3605 * 3606 * <p>If the calling app does not meet one of these requirements then this method will behave 3607 * as follows: 3608 * 3609 * <ul> 3610 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 3611 * READ_PHONE_STATE permission then null is returned.</li> 3612 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 3613 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 3614 * higher, then a SecurityException is thrown.</li> 3615 * </ul> 3616 * 3617 * @param subId whose subscriber id is returned 3618 * @hide 3619 */ 3620 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 3621 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSubscriberId(int subId)3622 public String getSubscriberId(int subId) { 3623 try { 3624 IPhoneSubInfo info = getSubscriberInfo(); 3625 if (info == null) 3626 return null; 3627 return info.getSubscriberIdForSubscriber(subId, mContext.getOpPackageName()); 3628 } catch (RemoteException ex) { 3629 return null; 3630 } catch (NullPointerException ex) { 3631 // This could happen before phone restarts due to crashing 3632 return null; 3633 } 3634 } 3635 3636 /** 3637 * Returns Carrier specific information that will be used to encrypt the IMSI and IMPI. 3638 * This includes the public key and the key identifier. For multi-sim devices, if no subId 3639 * has been specified, we will return the value for the dafault data sim. 3640 * Return null if it is unavailable. 3641 * <p> 3642 * Requires Permission: 3643 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3644 * @param keyType whether the key is being used for wlan or epdg. Valid key types are 3645 * {@link TelephonyManager#KEY_TYPE_EPDG} or 3646 * {@link TelephonyManager#KEY_TYPE_WLAN}. 3647 * @return ImsiEncryptionInfo Carrier specific information that will be used to encrypt the 3648 * IMSI and IMPI. This includes the public key and the key identifier. This information 3649 * will be stored in the device keystore. The system will return a null when no key was 3650 * found, and the carrier does not require a key. The system will throw 3651 * IllegalArgumentException when an invalid key is sent or when key is required but 3652 * not found. 3653 * @hide 3654 */ getCarrierInfoForImsiEncryption(int keyType)3655 public ImsiEncryptionInfo getCarrierInfoForImsiEncryption(int keyType) { 3656 try { 3657 IPhoneSubInfo info = getSubscriberInfo(); 3658 if (info == null) { 3659 Rlog.e(TAG,"IMSI error: Subscriber Info is null"); 3660 return null; 3661 } 3662 int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId()); 3663 if (keyType != KEY_TYPE_EPDG && keyType != KEY_TYPE_WLAN) { 3664 throw new IllegalArgumentException("IMSI error: Invalid key type"); 3665 } 3666 ImsiEncryptionInfo imsiEncryptionInfo = info.getCarrierInfoForImsiEncryption( 3667 subId, keyType, mContext.getOpPackageName()); 3668 if (imsiEncryptionInfo == null && isImsiEncryptionRequired(subId, keyType)) { 3669 Rlog.e(TAG, "IMSI error: key is required but not found"); 3670 throw new IllegalArgumentException("IMSI error: key is required but not found"); 3671 } 3672 return imsiEncryptionInfo; 3673 } catch (RemoteException ex) { 3674 Rlog.e(TAG, "getCarrierInfoForImsiEncryption RemoteException" + ex); 3675 } catch (NullPointerException ex) { 3676 // This could happen before phone restarts due to crashing 3677 Rlog.e(TAG, "getCarrierInfoForImsiEncryption NullPointerException" + ex); 3678 } 3679 return null; 3680 } 3681 3682 /** 3683 * Resets the Carrier Keys in the database. This involves 2 steps: 3684 * 1. Delete the keys from the database. 3685 * 2. Send an intent to download new Certificates. 3686 * <p> 3687 * Requires Permission: 3688 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3689 * @hide 3690 */ resetCarrierKeysForImsiEncryption()3691 public void resetCarrierKeysForImsiEncryption() { 3692 try { 3693 IPhoneSubInfo info = getSubscriberInfo(); 3694 if (info == null) { 3695 Rlog.e(TAG, "IMSI error: Subscriber Info is null"); 3696 if (!isSystemProcess()) { 3697 throw new RuntimeException("IMSI error: Subscriber Info is null"); 3698 } 3699 return; 3700 } 3701 int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId()); 3702 info.resetCarrierKeysForImsiEncryption(subId, mContext.getOpPackageName()); 3703 } catch (RemoteException ex) { 3704 Rlog.e(TAG, "getCarrierInfoForImsiEncryption RemoteException" + ex); 3705 if (!isSystemProcess()) { 3706 ex.rethrowAsRuntimeException(); 3707 } 3708 } 3709 } 3710 3711 /** 3712 * @param keyAvailability bitmask that defines the availabilty of keys for a type. 3713 * @param keyType the key type which is being checked. (WLAN, EPDG) 3714 * @return true if the digit at position keyType is 1, else false. 3715 * @hide 3716 */ isKeyEnabled(int keyAvailability, int keyType)3717 private static boolean isKeyEnabled(int keyAvailability, int keyType) { 3718 int returnValue = (keyAvailability >> (keyType - 1)) & 1; 3719 return (returnValue == 1) ? true : false; 3720 } 3721 3722 /** 3723 * If Carrier requires Imsi to be encrypted. 3724 * @hide 3725 */ isImsiEncryptionRequired(int subId, int keyType)3726 private boolean isImsiEncryptionRequired(int subId, int keyType) { 3727 CarrierConfigManager configManager = 3728 (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE); 3729 if (configManager == null) { 3730 return false; 3731 } 3732 PersistableBundle pb = configManager.getConfigForSubId(subId); 3733 if (pb == null) { 3734 return false; 3735 } 3736 int keyAvailability = pb.getInt(CarrierConfigManager.IMSI_KEY_AVAILABILITY_INT); 3737 return isKeyEnabled(keyAvailability, keyType); 3738 } 3739 3740 /** 3741 * Sets the Carrier specific information that will be used to encrypt the IMSI and IMPI. 3742 * This includes the public key and the key identifier. This information will be stored in the 3743 * device keystore. 3744 * <p> 3745 * Requires Permission: 3746 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3747 * @param imsiEncryptionInfo which includes the Key Type, the Public Key 3748 * (java.security.PublicKey) and the Key Identifier.and the Key Identifier. 3749 * The keyIdentifier Attribute value pair that helps a server locate 3750 * the private key to decrypt the permanent identity. This field is 3751 * optional and if it is present then it’s always separated from encrypted 3752 * permanent identity with “,”. Key identifier AVP is presented in ASCII string 3753 * with “name=value” format. 3754 * @hide 3755 */ setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo)3756 public void setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo) { 3757 try { 3758 IPhoneSubInfo info = getSubscriberInfo(); 3759 if (info == null) return; 3760 info.setCarrierInfoForImsiEncryption(mSubId, mContext.getOpPackageName(), 3761 imsiEncryptionInfo); 3762 } catch (NullPointerException ex) { 3763 // This could happen before phone restarts due to crashing 3764 return; 3765 } catch (RemoteException ex) { 3766 Rlog.e(TAG, "setCarrierInfoForImsiEncryption RemoteException", ex); 3767 return; 3768 } 3769 } 3770 3771 /** 3772 * Returns the Group Identifier Level1 for a GSM phone. 3773 * Return null if it is unavailable. 3774 * 3775 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3776 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3777 */ 3778 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 3779 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getGroupIdLevel1()3780 public String getGroupIdLevel1() { 3781 try { 3782 IPhoneSubInfo info = getSubscriberInfo(); 3783 if (info == null) 3784 return null; 3785 return info.getGroupIdLevel1ForSubscriber(getSubId(), mContext.getOpPackageName()); 3786 } catch (RemoteException ex) { 3787 return null; 3788 } catch (NullPointerException ex) { 3789 // This could happen before phone restarts due to crashing 3790 return null; 3791 } 3792 } 3793 3794 /** 3795 * Returns the Group Identifier Level1 for a GSM phone for a particular subscription. 3796 * Return null if it is unavailable. 3797 * 3798 * @param subId whose subscriber id is returned 3799 * @hide 3800 */ 3801 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 3802 @UnsupportedAppUsage getGroupIdLevel1(int subId)3803 public String getGroupIdLevel1(int subId) { 3804 try { 3805 IPhoneSubInfo info = getSubscriberInfo(); 3806 if (info == null) 3807 return null; 3808 return info.getGroupIdLevel1ForSubscriber(subId, mContext.getOpPackageName()); 3809 } catch (RemoteException ex) { 3810 return null; 3811 } catch (NullPointerException ex) { 3812 // This could happen before phone restarts due to crashing 3813 return null; 3814 } 3815 } 3816 3817 /** 3818 * Returns the phone number string for line 1, for example, the MSISDN 3819 * for a GSM phone. Return null if it is unavailable. 3820 * 3821 * <p>Requires Permission: 3822 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}, 3823 * {@link android.Manifest.permission#READ_SMS READ_SMS}, 3824 * {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS}, 3825 * that the caller is the default SMS app, 3826 * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}). 3827 */ 3828 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges or default SMS app 3829 @RequiresPermission(anyOf = { 3830 android.Manifest.permission.READ_PHONE_STATE, 3831 android.Manifest.permission.READ_SMS, 3832 android.Manifest.permission.READ_PHONE_NUMBERS 3833 }) getLine1Number()3834 public String getLine1Number() { 3835 return getLine1Number(getSubId()); 3836 } 3837 3838 /** 3839 * Returns the phone number string for line 1, for example, the MSISDN 3840 * for a GSM phone for a particular subscription. Return null if it is unavailable. 3841 * <p> 3842 * The default SMS app can also use this. 3843 * 3844 * @param subId whose phone number for line 1 is returned 3845 * @hide 3846 */ 3847 @RequiresPermission(anyOf = { 3848 android.Manifest.permission.READ_PHONE_STATE, 3849 android.Manifest.permission.READ_SMS, 3850 android.Manifest.permission.READ_PHONE_NUMBERS 3851 }) 3852 @UnsupportedAppUsage getLine1Number(int subId)3853 public String getLine1Number(int subId) { 3854 String number = null; 3855 try { 3856 ITelephony telephony = getITelephony(); 3857 if (telephony != null) 3858 number = telephony.getLine1NumberForDisplay(subId, mContext.getOpPackageName()); 3859 } catch (RemoteException ex) { 3860 } catch (NullPointerException ex) { 3861 } 3862 if (number != null) { 3863 return number; 3864 } 3865 try { 3866 IPhoneSubInfo info = getSubscriberInfo(); 3867 if (info == null) 3868 return null; 3869 return info.getLine1NumberForSubscriber(subId, mContext.getOpPackageName()); 3870 } catch (RemoteException ex) { 3871 return null; 3872 } catch (NullPointerException ex) { 3873 // This could happen before phone restarts due to crashing 3874 return null; 3875 } 3876 } 3877 3878 /** 3879 * Set the line 1 phone number string and its alphatag for the current ICCID 3880 * for display purpose only, for example, displayed in Phone Status. It won't 3881 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 3882 * value. 3883 * 3884 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3885 * 3886 * @param alphaTag alpha-tagging of the dailing nubmer 3887 * @param number The dialing number 3888 * @return true if the operation was executed correctly. 3889 */ setLine1NumberForDisplay(String alphaTag, String number)3890 public boolean setLine1NumberForDisplay(String alphaTag, String number) { 3891 return setLine1NumberForDisplay(getSubId(), alphaTag, number); 3892 } 3893 3894 /** 3895 * Set the line 1 phone number string and its alphatag for the current ICCID 3896 * for display purpose only, for example, displayed in Phone Status. It won't 3897 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 3898 * value. 3899 * 3900 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3901 * 3902 * @param subId the subscriber that the alphatag and dialing number belongs to. 3903 * @param alphaTag alpha-tagging of the dailing nubmer 3904 * @param number The dialing number 3905 * @return true if the operation was executed correctly. 3906 * @hide 3907 */ setLine1NumberForDisplay(int subId, String alphaTag, String number)3908 public boolean setLine1NumberForDisplay(int subId, String alphaTag, String number) { 3909 try { 3910 ITelephony telephony = getITelephony(); 3911 if (telephony != null) 3912 return telephony.setLine1NumberForDisplayForSubscriber(subId, alphaTag, number); 3913 } catch (RemoteException ex) { 3914 } catch (NullPointerException ex) { 3915 } 3916 return false; 3917 } 3918 3919 /** 3920 * Returns the alphabetic identifier associated with the line 1 number. 3921 * Return null if it is unavailable. 3922 * @hide 3923 * nobody seems to call this. 3924 */ 3925 @TestApi 3926 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getLine1AlphaTag()3927 public String getLine1AlphaTag() { 3928 return getLine1AlphaTag(getSubId()); 3929 } 3930 3931 /** 3932 * Returns the alphabetic identifier associated with the line 1 number 3933 * for a subscription. 3934 * Return null if it is unavailable. 3935 * @param subId whose alphabetic identifier associated with line 1 is returned 3936 * nobody seems to call this. 3937 * @hide 3938 */ 3939 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 3940 @UnsupportedAppUsage getLine1AlphaTag(int subId)3941 public String getLine1AlphaTag(int subId) { 3942 String alphaTag = null; 3943 try { 3944 ITelephony telephony = getITelephony(); 3945 if (telephony != null) 3946 alphaTag = telephony.getLine1AlphaTagForDisplay(subId, 3947 getOpPackageName()); 3948 } catch (RemoteException ex) { 3949 } catch (NullPointerException ex) { 3950 } 3951 if (alphaTag != null) { 3952 return alphaTag; 3953 } 3954 try { 3955 IPhoneSubInfo info = getSubscriberInfo(); 3956 if (info == null) 3957 return null; 3958 return info.getLine1AlphaTagForSubscriber(subId, getOpPackageName()); 3959 } catch (RemoteException ex) { 3960 return null; 3961 } catch (NullPointerException ex) { 3962 // This could happen before phone restarts due to crashing 3963 return null; 3964 } 3965 } 3966 3967 /** 3968 * Return the set of subscriber IDs that should be considered "merged together" for data usage 3969 * purposes. This is commonly {@code null} to indicate no merging is required. Any returned 3970 * subscribers are sorted in a deterministic order. 3971 * <p> 3972 * The returned set of subscriber IDs will include the subscriber ID corresponding to this 3973 * TelephonyManager's subId. 3974 * 3975 * @hide 3976 */ 3977 @UnsupportedAppUsage getMergedSubscriberIds()3978 public @Nullable String[] getMergedSubscriberIds() { 3979 try { 3980 ITelephony telephony = getITelephony(); 3981 if (telephony != null) 3982 return telephony.getMergedSubscriberIds(getSubId(), getOpPackageName()); 3983 } catch (RemoteException ex) { 3984 } catch (NullPointerException ex) { 3985 } 3986 return null; 3987 } 3988 3989 /** 3990 * Returns the MSISDN string. 3991 * for a GSM phone. Return null if it is unavailable. 3992 * 3993 * @hide 3994 */ 3995 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 3996 @UnsupportedAppUsage getMsisdn()3997 public String getMsisdn() { 3998 return getMsisdn(getSubId()); 3999 } 4000 4001 /** 4002 * Returns the MSISDN string. 4003 * for a GSM phone. Return null if it is unavailable. 4004 * 4005 * @param subId for which msisdn is returned 4006 * @hide 4007 */ 4008 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 4009 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getMsisdn(int subId)4010 public String getMsisdn(int subId) { 4011 try { 4012 IPhoneSubInfo info = getSubscriberInfo(); 4013 if (info == null) 4014 return null; 4015 return info.getMsisdnForSubscriber(subId, getOpPackageName()); 4016 } catch (RemoteException ex) { 4017 return null; 4018 } catch (NullPointerException ex) { 4019 // This could happen before phone restarts due to crashing 4020 return null; 4021 } 4022 } 4023 4024 /** 4025 * Returns the voice mail number. Return null if it is unavailable. 4026 * 4027 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 4028 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4029 */ 4030 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 4031 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceMailNumber()4032 public String getVoiceMailNumber() { 4033 return getVoiceMailNumber(getSubId()); 4034 } 4035 4036 /** 4037 * Returns the voice mail number for a subscription. 4038 * Return null if it is unavailable. 4039 * @param subId whose voice mail number is returned 4040 * @hide 4041 */ 4042 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 4043 @UnsupportedAppUsage getVoiceMailNumber(int subId)4044 public String getVoiceMailNumber(int subId) { 4045 try { 4046 IPhoneSubInfo info = getSubscriberInfo(); 4047 if (info == null) 4048 return null; 4049 return info.getVoiceMailNumberForSubscriber(subId, getOpPackageName()); 4050 } catch (RemoteException ex) { 4051 return null; 4052 } catch (NullPointerException ex) { 4053 // This could happen before phone restarts due to crashing 4054 return null; 4055 } 4056 } 4057 4058 /** 4059 * Sets the voice mail number. 4060 * 4061 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4062 * 4063 * @param alphaTag The alpha tag to display. 4064 * @param number The voicemail number. 4065 */ setVoiceMailNumber(String alphaTag, String number)4066 public boolean setVoiceMailNumber(String alphaTag, String number) { 4067 return setVoiceMailNumber(getSubId(), alphaTag, number); 4068 } 4069 4070 /** 4071 * Sets the voicemail number for the given subscriber. 4072 * 4073 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4074 * 4075 * @param subId The subscription id. 4076 * @param alphaTag The alpha tag to display. 4077 * @param number The voicemail number. 4078 * @hide 4079 */ setVoiceMailNumber(int subId, String alphaTag, String number)4080 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { 4081 try { 4082 ITelephony telephony = getITelephony(); 4083 if (telephony != null) 4084 return telephony.setVoiceMailNumber(subId, alphaTag, number); 4085 } catch (RemoteException ex) { 4086 } catch (NullPointerException ex) { 4087 } 4088 return false; 4089 } 4090 4091 /** 4092 * Enables or disables the visual voicemail client for a phone account. 4093 * 4094 * <p>Requires that the calling app is the default dialer, or has carrier privileges (see 4095 * {@link #hasCarrierPrivileges}), or has permission 4096 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 4097 * 4098 * @param phoneAccountHandle the phone account to change the client state 4099 * @param enabled the new state of the client 4100 * @hide 4101 * @deprecated Visual voicemail no longer in telephony. {@link VisualVoicemailService} should 4102 * be implemented instead. 4103 */ 4104 @SystemApi 4105 @SuppressLint("Doclava125") setVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled)4106 public void setVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled){ 4107 } 4108 4109 /** 4110 * Returns whether the visual voicemail client is enabled. 4111 * 4112 * @param phoneAccountHandle the phone account to check for. 4113 * @return {@code true} when the visual voicemail client is enabled for this client 4114 * @hide 4115 * @deprecated Visual voicemail no longer in telephony. {@link VisualVoicemailService} should 4116 * be implemented instead. 4117 */ 4118 @SystemApi 4119 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 4120 @SuppressLint("Doclava125") isVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle)4121 public boolean isVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle){ 4122 return false; 4123 } 4124 4125 /** 4126 * Returns an opaque bundle of settings formerly used by the visual voicemail client for the 4127 * subscription ID pinned to the TelephonyManager, or {@code null} if the subscription ID is 4128 * invalid. This method allows the system dialer to migrate settings out of the pre-O visual 4129 * voicemail client in telephony. 4130 * 4131 * <p>Requires the caller to be the system dialer. 4132 * 4133 * @see #KEY_VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL 4134 * @see #KEY_VOICEMAIL_SCRAMBLED_PIN_STRING 4135 * 4136 * @hide 4137 */ 4138 @SystemApi 4139 @SuppressLint("Doclava125") 4140 @Nullable getVisualVoicemailSettings()4141 public Bundle getVisualVoicemailSettings(){ 4142 try { 4143 ITelephony telephony = getITelephony(); 4144 if (telephony != null) { 4145 return telephony 4146 .getVisualVoicemailSettings(mContext.getOpPackageName(), mSubId); 4147 } 4148 } catch (RemoteException ex) { 4149 } catch (NullPointerException ex) { 4150 } 4151 return null; 4152 } 4153 4154 /** 4155 * Returns the package responsible of processing visual voicemail for the subscription ID pinned 4156 * to the TelephonyManager. Returns {@code null} when there is no package responsible for 4157 * processing visual voicemail for the subscription. 4158 * 4159 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 4160 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4161 * 4162 * @see #createForSubscriptionId(int) 4163 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 4164 * @see VisualVoicemailService 4165 */ 4166 @Nullable 4167 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 4168 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVisualVoicemailPackageName()4169 public String getVisualVoicemailPackageName() { 4170 try { 4171 ITelephony telephony = getITelephony(); 4172 if (telephony != null) { 4173 return telephony 4174 .getVisualVoicemailPackageName(mContext.getOpPackageName(), getSubId()); 4175 } 4176 } catch (RemoteException ex) { 4177 } catch (NullPointerException ex) { 4178 } 4179 return null; 4180 } 4181 4182 /** 4183 * Set the visual voicemail SMS filter settings for the subscription ID pinned 4184 * to the TelephonyManager. 4185 * When the filter is enabled, {@link 4186 * VisualVoicemailService#onSmsReceived(VisualVoicemailTask, VisualVoicemailSms)} will be 4187 * called when a SMS matching the settings is received. Caller must be the default dialer, 4188 * system dialer, or carrier visual voicemail app. 4189 * 4190 * @param settings The settings for the filter, or {@code null} to disable the filter. 4191 * 4192 * @see TelecomManager#getDefaultDialerPackage() 4193 * @see CarrierConfigManager#KEY_CARRIER_VVM_PACKAGE_NAME_STRING_ARRAY 4194 */ setVisualVoicemailSmsFilterSettings(VisualVoicemailSmsFilterSettings settings)4195 public void setVisualVoicemailSmsFilterSettings(VisualVoicemailSmsFilterSettings settings) { 4196 if (settings == null) { 4197 disableVisualVoicemailSmsFilter(mSubId); 4198 } else { 4199 enableVisualVoicemailSmsFilter(mSubId, settings); 4200 } 4201 } 4202 4203 /** 4204 * Send a visual voicemail SMS. The caller must be the current default dialer. 4205 * A {@link VisualVoicemailService} uses this method to send a command via SMS to the carrier's 4206 * visual voicemail server. Some examples for carriers using the OMTP standard include 4207 * activating and deactivating visual voicemail, or requesting the current visual voicemail 4208 * provisioning status. See the OMTP Visual Voicemail specification for more information on the 4209 * format of these SMS messages. 4210 * 4211 * <p>Requires Permission: 4212 * {@link android.Manifest.permission#SEND_SMS SEND_SMS} 4213 * 4214 * @param number The destination number. 4215 * @param port The destination port for data SMS, or 0 for text SMS. 4216 * @param text The message content. For data sms, it will be encoded as a UTF-8 byte stream. 4217 * @param sentIntent The sent intent passed to the {@link SmsManager} 4218 * 4219 * @throws SecurityException if the caller is not the current default dialer 4220 * 4221 * @see SmsManager#sendDataMessage(String, String, short, byte[], PendingIntent, PendingIntent) 4222 * @see SmsManager#sendTextMessage(String, String, String, PendingIntent, PendingIntent) 4223 */ sendVisualVoicemailSms(String number, int port, String text, PendingIntent sentIntent)4224 public void sendVisualVoicemailSms(String number, int port, String text, 4225 PendingIntent sentIntent) { 4226 sendVisualVoicemailSmsForSubscriber(mSubId, number, port, text, sentIntent); 4227 } 4228 4229 /** 4230 * Enables the visual voicemail SMS filter for a phone account. When the filter is 4231 * enabled, Incoming SMS messages matching the OMTP VVM SMS interface will be redirected to the 4232 * visual voicemail client with 4233 * {@link android.provider.VoicemailContract.ACTION_VOICEMAIL_SMS_RECEIVED}. 4234 * 4235 * <p>This takes effect only when the caller is the default dialer. The enabled status and 4236 * settings persist through default dialer changes, but the filter will only honor the setting 4237 * set by the current default dialer. 4238 * 4239 * 4240 * @param subId The subscription id of the phone account. 4241 * @param settings The settings for the filter. 4242 */ 4243 /** @hide */ enableVisualVoicemailSmsFilter(int subId, VisualVoicemailSmsFilterSettings settings)4244 public void enableVisualVoicemailSmsFilter(int subId, 4245 VisualVoicemailSmsFilterSettings settings) { 4246 if(settings == null){ 4247 throw new IllegalArgumentException("Settings cannot be null"); 4248 } 4249 try { 4250 ITelephony telephony = getITelephony(); 4251 if (telephony != null) { 4252 telephony.enableVisualVoicemailSmsFilter(mContext.getOpPackageName(), subId, 4253 settings); 4254 } 4255 } catch (RemoteException ex) { 4256 } catch (NullPointerException ex) { 4257 } 4258 } 4259 4260 /** 4261 * Disables the visual voicemail SMS filter for a phone account. 4262 * 4263 * <p>This takes effect only when the caller is the default dialer. The enabled status and 4264 * settings persist through default dialer changes, but the filter will only honor the setting 4265 * set by the current default dialer. 4266 */ 4267 /** @hide */ disableVisualVoicemailSmsFilter(int subId)4268 public void disableVisualVoicemailSmsFilter(int subId) { 4269 try { 4270 ITelephony telephony = getITelephony(); 4271 if (telephony != null) { 4272 telephony.disableVisualVoicemailSmsFilter(mContext.getOpPackageName(), subId); 4273 } 4274 } catch (RemoteException ex) { 4275 } catch (NullPointerException ex) { 4276 } 4277 } 4278 4279 /** 4280 * @returns the settings of the visual voicemail SMS filter for a phone account, or {@code null} 4281 * if the filter is disabled. 4282 * 4283 * <p>This takes effect only when the caller is the default dialer. The enabled status and 4284 * settings persist through default dialer changes, but the filter will only honor the setting 4285 * set by the current default dialer. 4286 */ 4287 /** @hide */ 4288 @Nullable getVisualVoicemailSmsFilterSettings(int subId)4289 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(int subId) { 4290 try { 4291 ITelephony telephony = getITelephony(); 4292 if (telephony != null) { 4293 return telephony 4294 .getVisualVoicemailSmsFilterSettings(mContext.getOpPackageName(), subId); 4295 } 4296 } catch (RemoteException ex) { 4297 } catch (NullPointerException ex) { 4298 } 4299 4300 return null; 4301 } 4302 4303 /** 4304 * @returns the settings of the visual voicemail SMS filter for a phone account set by the 4305 * current active visual voicemail client, or {@code null} if the filter is disabled. 4306 * 4307 * <p>Requires the calling app to have READ_PRIVILEGED_PHONE_STATE permission. 4308 */ 4309 /** @hide */ 4310 @Nullable getActiveVisualVoicemailSmsFilterSettings(int subId)4311 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { 4312 try { 4313 ITelephony telephony = getITelephony(); 4314 if (telephony != null) { 4315 return telephony.getActiveVisualVoicemailSmsFilterSettings(subId); 4316 } 4317 } catch (RemoteException ex) { 4318 } catch (NullPointerException ex) { 4319 } 4320 4321 return null; 4322 } 4323 4324 /** 4325 * Send a visual voicemail SMS. The IPC caller must be the current default dialer. 4326 * 4327 * @param phoneAccountHandle The account to send the SMS with. 4328 * @param number The destination number. 4329 * @param port The destination port for data SMS, or 0 for text SMS. 4330 * @param text The message content. For data sms, it will be encoded as a UTF-8 byte stream. 4331 * @param sentIntent The sent intent passed to the {@link SmsManager} 4332 * 4333 * @see SmsManager#sendDataMessage(String, String, short, byte[], PendingIntent, PendingIntent) 4334 * @see SmsManager#sendTextMessage(String, String, String, PendingIntent, PendingIntent) 4335 * 4336 * @hide 4337 */ 4338 @RequiresPermission(android.Manifest.permission.SEND_SMS) sendVisualVoicemailSmsForSubscriber(int subId, String number, int port, String text, PendingIntent sentIntent)4339 public void sendVisualVoicemailSmsForSubscriber(int subId, String number, int port, 4340 String text, PendingIntent sentIntent) { 4341 try { 4342 ITelephony telephony = getITelephony(); 4343 if (telephony != null) { 4344 telephony.sendVisualVoicemailSmsForSubscriber( 4345 mContext.getOpPackageName(), subId, number, port, text, sentIntent); 4346 } 4347 } catch (RemoteException ex) { 4348 } 4349 } 4350 4351 /** 4352 * Initial SIM activation state, unknown. Not set by any carrier apps. 4353 * @hide 4354 */ 4355 @SystemApi 4356 public static final int SIM_ACTIVATION_STATE_UNKNOWN = 0; 4357 4358 /** 4359 * indicate SIM is under activation procedure now. 4360 * intermediate state followed by another state update with activation procedure result: 4361 * @see #SIM_ACTIVATION_STATE_ACTIVATED 4362 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 4363 * @see #SIM_ACTIVATION_STATE_RESTRICTED 4364 * @hide 4365 */ 4366 @SystemApi 4367 public static final int SIM_ACTIVATION_STATE_ACTIVATING = 1; 4368 4369 /** 4370 * Indicate SIM has been successfully activated with full service 4371 * @hide 4372 */ 4373 @SystemApi 4374 public static final int SIM_ACTIVATION_STATE_ACTIVATED = 2; 4375 4376 /** 4377 * Indicate SIM has been deactivated by the carrier so that service is not available 4378 * and requires activation service to enable services. 4379 * Carrier apps could be signalled to set activation state to deactivated if detected 4380 * deactivated sim state and set it back to activated after successfully run activation service. 4381 * @hide 4382 */ 4383 @SystemApi 4384 public static final int SIM_ACTIVATION_STATE_DEACTIVATED = 3; 4385 4386 /** 4387 * Restricted state indicate SIM has been activated but service are restricted. 4388 * note this is currently available for data activation state. For example out of byte sim. 4389 * @hide 4390 */ 4391 @SystemApi 4392 public static final int SIM_ACTIVATION_STATE_RESTRICTED = 4; 4393 4394 /** @hide */ 4395 @IntDef({ 4396 SIM_ACTIVATION_STATE_UNKNOWN, 4397 SIM_ACTIVATION_STATE_ACTIVATING, 4398 SIM_ACTIVATION_STATE_ACTIVATED, 4399 SIM_ACTIVATION_STATE_DEACTIVATED, 4400 SIM_ACTIVATION_STATE_RESTRICTED 4401 }) 4402 @Retention(RetentionPolicy.SOURCE) 4403 public @interface SimActivationState{} 4404 4405 /** 4406 * Sets the voice activation state 4407 * 4408 * <p>Requires Permission: 4409 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 4410 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4411 * 4412 * @param activationState The voice activation state 4413 * @see #SIM_ACTIVATION_STATE_UNKNOWN 4414 * @see #SIM_ACTIVATION_STATE_ACTIVATING 4415 * @see #SIM_ACTIVATION_STATE_ACTIVATED 4416 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 4417 * @hide 4418 */ 4419 @SystemApi 4420 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setVoiceActivationState(@imActivationState int activationState)4421 public void setVoiceActivationState(@SimActivationState int activationState) { 4422 setVoiceActivationState(getSubId(), activationState); 4423 } 4424 4425 /** 4426 * Sets the voice activation state for the given subscriber. 4427 * 4428 * <p>Requires Permission: 4429 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 4430 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4431 * 4432 * @param subId The subscription id. 4433 * @param activationState The voice activation state of the given subscriber. 4434 * @see #SIM_ACTIVATION_STATE_UNKNOWN 4435 * @see #SIM_ACTIVATION_STATE_ACTIVATING 4436 * @see #SIM_ACTIVATION_STATE_ACTIVATED 4437 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 4438 * @hide 4439 */ 4440 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setVoiceActivationState(int subId, @SimActivationState int activationState)4441 public void setVoiceActivationState(int subId, @SimActivationState int activationState) { 4442 try { 4443 ITelephony telephony = getITelephony(); 4444 if (telephony != null) 4445 telephony.setVoiceActivationState(subId, activationState); 4446 } catch (RemoteException ex) { 4447 } catch (NullPointerException ex) { 4448 } 4449 } 4450 4451 /** 4452 * Sets the data activation state 4453 * 4454 * <p>Requires Permission: 4455 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 4456 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4457 * 4458 * @param activationState The data activation state 4459 * @see #SIM_ACTIVATION_STATE_UNKNOWN 4460 * @see #SIM_ACTIVATION_STATE_ACTIVATING 4461 * @see #SIM_ACTIVATION_STATE_ACTIVATED 4462 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 4463 * @see #SIM_ACTIVATION_STATE_RESTRICTED 4464 * @hide 4465 */ 4466 @SystemApi 4467 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataActivationState(@imActivationState int activationState)4468 public void setDataActivationState(@SimActivationState int activationState) { 4469 setDataActivationState(getSubId(), activationState); 4470 } 4471 4472 /** 4473 * Sets the data activation state for the given subscriber. 4474 * 4475 * <p>Requires Permission: 4476 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 4477 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4478 * 4479 * @param subId The subscription id. 4480 * @param activationState The data activation state of the given subscriber. 4481 * @see #SIM_ACTIVATION_STATE_UNKNOWN 4482 * @see #SIM_ACTIVATION_STATE_ACTIVATING 4483 * @see #SIM_ACTIVATION_STATE_ACTIVATED 4484 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 4485 * @see #SIM_ACTIVATION_STATE_RESTRICTED 4486 * @hide 4487 */ 4488 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataActivationState(int subId, @SimActivationState int activationState)4489 public void setDataActivationState(int subId, @SimActivationState int activationState) { 4490 try { 4491 ITelephony telephony = getITelephony(); 4492 if (telephony != null) 4493 telephony.setDataActivationState(subId, activationState); 4494 } catch (RemoteException ex) { 4495 } catch (NullPointerException ex) { 4496 } 4497 } 4498 4499 /** 4500 * Returns the voice activation state 4501 * 4502 * <p>Requires Permission: 4503 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 4504 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4505 * 4506 * @return voiceActivationState 4507 * @see #SIM_ACTIVATION_STATE_UNKNOWN 4508 * @see #SIM_ACTIVATION_STATE_ACTIVATING 4509 * @see #SIM_ACTIVATION_STATE_ACTIVATED 4510 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 4511 * @hide 4512 */ 4513 @SystemApi 4514 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getVoiceActivationState()4515 public @SimActivationState int getVoiceActivationState() { 4516 return getVoiceActivationState(getSubId()); 4517 } 4518 4519 /** 4520 * Returns the voice activation state for the given subscriber. 4521 * 4522 * <p>Requires Permission: 4523 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 4524 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4525 * 4526 * @param subId The subscription id. 4527 * 4528 * @return voiceActivationState for the given subscriber 4529 * @see #SIM_ACTIVATION_STATE_UNKNOWN 4530 * @see #SIM_ACTIVATION_STATE_ACTIVATING 4531 * @see #SIM_ACTIVATION_STATE_ACTIVATED 4532 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 4533 * @hide 4534 */ 4535 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getVoiceActivationState(int subId)4536 public @SimActivationState int getVoiceActivationState(int subId) { 4537 try { 4538 ITelephony telephony = getITelephony(); 4539 if (telephony != null) 4540 return telephony.getVoiceActivationState(subId, getOpPackageName()); 4541 } catch (RemoteException ex) { 4542 } catch (NullPointerException ex) { 4543 } 4544 return SIM_ACTIVATION_STATE_UNKNOWN; 4545 } 4546 4547 /** 4548 * Returns the data activation state 4549 * 4550 * <p>Requires Permission: 4551 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 4552 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4553 * 4554 * @return dataActivationState for the given subscriber 4555 * @see #SIM_ACTIVATION_STATE_UNKNOWN 4556 * @see #SIM_ACTIVATION_STATE_ACTIVATING 4557 * @see #SIM_ACTIVATION_STATE_ACTIVATED 4558 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 4559 * @see #SIM_ACTIVATION_STATE_RESTRICTED 4560 * @hide 4561 */ 4562 @SystemApi 4563 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getDataActivationState()4564 public @SimActivationState int getDataActivationState() { 4565 return getDataActivationState(getSubId()); 4566 } 4567 4568 /** 4569 * Returns the data activation state for the given subscriber. 4570 * 4571 * <p>Requires Permission: 4572 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 4573 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4574 * 4575 * @param subId The subscription id. 4576 * 4577 * @return dataActivationState for the given subscriber 4578 * @see #SIM_ACTIVATION_STATE_UNKNOWN 4579 * @see #SIM_ACTIVATION_STATE_ACTIVATING 4580 * @see #SIM_ACTIVATION_STATE_ACTIVATED 4581 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 4582 * @see #SIM_ACTIVATION_STATE_RESTRICTED 4583 * @hide 4584 */ 4585 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getDataActivationState(int subId)4586 public @SimActivationState int getDataActivationState(int subId) { 4587 try { 4588 ITelephony telephony = getITelephony(); 4589 if (telephony != null) 4590 return telephony.getDataActivationState(subId, getOpPackageName()); 4591 } catch (RemoteException ex) { 4592 } catch (NullPointerException ex) { 4593 } 4594 return SIM_ACTIVATION_STATE_UNKNOWN; 4595 } 4596 4597 /** 4598 * Returns the voice mail count. Return 0 if unavailable, -1 if there are unread voice messages 4599 * but the count is unknown. 4600 * @hide 4601 */ 4602 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 4603 @UnsupportedAppUsage getVoiceMessageCount()4604 public int getVoiceMessageCount() { 4605 return getVoiceMessageCount(getSubId()); 4606 } 4607 4608 /** 4609 * Returns the voice mail count for a subscription. Return 0 if unavailable or the caller does 4610 * not have the READ_PHONE_STATE permission. 4611 * @param subId whose voice message count is returned 4612 * @hide 4613 */ 4614 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 4615 @UnsupportedAppUsage getVoiceMessageCount(int subId)4616 public int getVoiceMessageCount(int subId) { 4617 try { 4618 ITelephony telephony = getITelephony(); 4619 if (telephony == null) 4620 return 0; 4621 return telephony.getVoiceMessageCountForSubscriber(subId, getOpPackageName()); 4622 } catch (RemoteException ex) { 4623 return 0; 4624 } catch (NullPointerException ex) { 4625 // This could happen before phone restarts due to crashing 4626 return 0; 4627 } 4628 } 4629 4630 /** 4631 * Retrieves the alphabetic identifier associated with the voice 4632 * mail number. 4633 * 4634 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 4635 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4636 */ 4637 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 4638 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceMailAlphaTag()4639 public String getVoiceMailAlphaTag() { 4640 return getVoiceMailAlphaTag(getSubId()); 4641 } 4642 4643 /** 4644 * Retrieves the alphabetic identifier associated with the voice 4645 * mail number for a subscription. 4646 * @param subId whose alphabetic identifier associated with the 4647 * voice mail number is returned 4648 * @hide 4649 */ 4650 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 4651 @UnsupportedAppUsage getVoiceMailAlphaTag(int subId)4652 public String getVoiceMailAlphaTag(int subId) { 4653 try { 4654 IPhoneSubInfo info = getSubscriberInfo(); 4655 if (info == null) 4656 return null; 4657 return info.getVoiceMailAlphaTagForSubscriber(subId, getOpPackageName()); 4658 } catch (RemoteException ex) { 4659 return null; 4660 } catch (NullPointerException ex) { 4661 // This could happen before phone restarts due to crashing 4662 return null; 4663 } 4664 } 4665 4666 /** 4667 * Send the special dialer code. The IPC caller must be the current default dialer or have 4668 * carrier privileges (see {@link #hasCarrierPrivileges}). 4669 * 4670 * @param inputCode The special dialer code to send 4671 * 4672 * @throws SecurityException if the caller does not have carrier privileges or is not the 4673 * current default dialer 4674 */ sendDialerSpecialCode(String inputCode)4675 public void sendDialerSpecialCode(String inputCode) { 4676 try { 4677 final ITelephony telephony = getITelephony(); 4678 if (telephony == null) { 4679 if (!isSystemProcess()) { 4680 throw new RuntimeException("Telephony service unavailable"); 4681 } 4682 return; 4683 } 4684 telephony.sendDialerSpecialCode(mContext.getOpPackageName(), inputCode); 4685 } catch (RemoteException ex) { 4686 // This could happen if binder process crashes. 4687 if (!isSystemProcess()) { 4688 ex.rethrowAsRuntimeException(); 4689 } 4690 } 4691 } 4692 4693 /** 4694 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 4695 * @return the IMPI, or null if not present or not loaded 4696 * @hide 4697 */ 4698 @UnsupportedAppUsage getIsimImpi()4699 public String getIsimImpi() { 4700 try { 4701 IPhoneSubInfo info = getSubscriberInfo(); 4702 if (info == null) 4703 return null; 4704 //get the Isim Impi based on subId 4705 return info.getIsimImpi(getSubId()); 4706 } catch (RemoteException ex) { 4707 return null; 4708 } catch (NullPointerException ex) { 4709 // This could happen before phone restarts due to crashing 4710 return null; 4711 } 4712 } 4713 4714 /** 4715 * Returns the IMS home network domain name that was loaded from the ISIM {@see #APPTYPE_ISIM}. 4716 * @return the IMS domain name. Returns {@code null} if ISIM hasn't been loaded or IMS domain 4717 * hasn't been loaded or isn't present on the ISIM. 4718 * 4719 * <p>Requires Permission: 4720 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 4721 * @hide 4722 */ 4723 @Nullable 4724 @SystemApi 4725 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getIsimDomain()4726 public String getIsimDomain() { 4727 try { 4728 IPhoneSubInfo info = getSubscriberInfo(); 4729 if (info == null) 4730 return null; 4731 //get the Isim Domain based on subId 4732 return info.getIsimDomain(getSubId()); 4733 } catch (RemoteException ex) { 4734 return null; 4735 } catch (NullPointerException ex) { 4736 // This could happen before phone restarts due to crashing 4737 return null; 4738 } 4739 } 4740 4741 /** 4742 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 4743 * @return an array of IMPU strings, with one IMPU per string, or null if 4744 * not present or not loaded 4745 * @hide 4746 */ 4747 @UnsupportedAppUsage getIsimImpu()4748 public String[] getIsimImpu() { 4749 try { 4750 IPhoneSubInfo info = getSubscriberInfo(); 4751 if (info == null) 4752 return null; 4753 //get the Isim Impu based on subId 4754 return info.getIsimImpu(getSubId()); 4755 } catch (RemoteException ex) { 4756 return null; 4757 } catch (NullPointerException ex) { 4758 // This could happen before phone restarts due to crashing 4759 return null; 4760 } 4761 } 4762 4763 /** 4764 * @hide 4765 */ 4766 @UnsupportedAppUsage getSubscriberInfo()4767 private IPhoneSubInfo getSubscriberInfo() { 4768 // get it each time because that process crashes a lot 4769 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 4770 } 4771 4772 /** 4773 * Device call state: No activity. 4774 */ 4775 public static final int CALL_STATE_IDLE = 0; 4776 /** 4777 * Device call state: Ringing. A new call arrived and is 4778 * ringing or waiting. In the latter case, another call is 4779 * already active. 4780 */ 4781 public static final int CALL_STATE_RINGING = 1; 4782 /** 4783 * Device call state: Off-hook. At least one call exists 4784 * that is dialing, active, or on hold, and no calls are ringing 4785 * or waiting. 4786 */ 4787 public static final int CALL_STATE_OFFHOOK = 2; 4788 4789 /** @hide */ 4790 @IntDef(prefix = { "CALL_STATE_" }, value = { 4791 CALL_STATE_IDLE, 4792 CALL_STATE_RINGING, 4793 CALL_STATE_OFFHOOK 4794 }) 4795 @Retention(RetentionPolicy.SOURCE) 4796 public @interface CallState{} 4797 4798 /** 4799 * Returns the state of all calls on the device. 4800 * <p> 4801 * This method considers not only calls in the Telephony stack, but also calls via other 4802 * {@link android.telecom.ConnectionService} implementations. 4803 * <p> 4804 * Note: The call state returned via this method may differ from what is reported by 4805 * {@link PhoneStateListener#onCallStateChanged(int, String)}, as that callback only considers 4806 * Telephony (mobile) calls. 4807 * 4808 * @return the current call state. 4809 */ getCallState()4810 public @CallState int getCallState() { 4811 try { 4812 ITelecomService telecom = getTelecomService(); 4813 if (telecom != null) { 4814 return telecom.getCallState(); 4815 } 4816 } catch (RemoteException e) { 4817 Log.e(TAG, "Error calling ITelecomService#getCallState", e); 4818 } 4819 return CALL_STATE_IDLE; 4820 } 4821 4822 /** 4823 * Returns the Telephony call state for calls on a specific subscription. 4824 * <p> 4825 * Note: This method considers ONLY telephony/mobile calls, where {@link #getCallState()} 4826 * considers the state of calls from other {@link android.telecom.ConnectionService} 4827 * implementations. 4828 * 4829 * @param subId the subscription to check call state for. 4830 * @hide 4831 */ 4832 @UnsupportedAppUsage getCallState(int subId)4833 public @CallState int getCallState(int subId) { 4834 int phoneId = SubscriptionManager.getPhoneId(subId); 4835 return getCallStateForSlot(phoneId); 4836 } 4837 4838 /** 4839 * Returns the Telephony call state for calls on a specific SIM slot. 4840 * <p> 4841 * Note: This method considers ONLY telephony/mobile calls, where {@link #getCallState()} 4842 * considers the state of calls from other {@link android.telecom.ConnectionService} 4843 * implementations. 4844 * 4845 * @param slotIndex the SIM slot index to check call state for. 4846 * @hide 4847 */ getCallStateForSlot(int slotIndex)4848 public @CallState int getCallStateForSlot(int slotIndex) { 4849 try { 4850 ITelephony telephony = getITelephony(); 4851 if (telephony == null) 4852 return CALL_STATE_IDLE; 4853 return telephony.getCallStateForSlot(slotIndex); 4854 } catch (RemoteException ex) { 4855 // the phone process is restarting. 4856 return CALL_STATE_IDLE; 4857 } catch (NullPointerException ex) { 4858 // the phone process is restarting. 4859 return CALL_STATE_IDLE; 4860 } 4861 } 4862 4863 4864 /** Data connection activity: No traffic. */ 4865 public static final int DATA_ACTIVITY_NONE = 0x00000000; 4866 /** Data connection activity: Currently receiving IP PPP traffic. */ 4867 public static final int DATA_ACTIVITY_IN = 0x00000001; 4868 /** Data connection activity: Currently sending IP PPP traffic. */ 4869 public static final int DATA_ACTIVITY_OUT = 0x00000002; 4870 /** Data connection activity: Currently both sending and receiving 4871 * IP PPP traffic. */ 4872 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 4873 /** 4874 * Data connection is active, but physical link is down 4875 */ 4876 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 4877 4878 /** 4879 * Returns a constant indicating the type of activity on a data connection 4880 * (cellular). 4881 * 4882 * @see #DATA_ACTIVITY_NONE 4883 * @see #DATA_ACTIVITY_IN 4884 * @see #DATA_ACTIVITY_OUT 4885 * @see #DATA_ACTIVITY_INOUT 4886 * @see #DATA_ACTIVITY_DORMANT 4887 */ getDataActivity()4888 public int getDataActivity() { 4889 try { 4890 ITelephony telephony = getITelephony(); 4891 if (telephony == null) 4892 return DATA_ACTIVITY_NONE; 4893 return telephony.getDataActivity(); 4894 } catch (RemoteException ex) { 4895 // the phone process is restarting. 4896 return DATA_ACTIVITY_NONE; 4897 } catch (NullPointerException ex) { 4898 // the phone process is restarting. 4899 return DATA_ACTIVITY_NONE; 4900 } 4901 } 4902 4903 /** @hide */ 4904 @IntDef(prefix = {"DATA_"}, value = { 4905 DATA_UNKNOWN, 4906 DATA_DISCONNECTED, 4907 DATA_CONNECTING, 4908 DATA_CONNECTED, 4909 DATA_SUSPENDED, 4910 }) 4911 @Retention(RetentionPolicy.SOURCE) 4912 public @interface DataState{} 4913 4914 /** Data connection state: Unknown. Used before we know the state. */ 4915 public static final int DATA_UNKNOWN = -1; 4916 /** Data connection state: Disconnected. IP traffic not available. */ 4917 public static final int DATA_DISCONNECTED = 0; 4918 /** Data connection state: Currently setting up a data connection. */ 4919 public static final int DATA_CONNECTING = 1; 4920 /** Data connection state: Connected. IP traffic should be available. */ 4921 public static final int DATA_CONNECTED = 2; 4922 /** Data connection state: Suspended. The connection is up, but IP 4923 * traffic is temporarily unavailable. For example, in a 2G network, 4924 * data activity may be suspended when a voice call arrives. */ 4925 public static final int DATA_SUSPENDED = 3; 4926 4927 /** 4928 * Returns a constant indicating the current data connection state 4929 * (cellular). 4930 * 4931 * @see #DATA_DISCONNECTED 4932 * @see #DATA_CONNECTING 4933 * @see #DATA_CONNECTED 4934 * @see #DATA_SUSPENDED 4935 */ getDataState()4936 public int getDataState() { 4937 try { 4938 ITelephony telephony = getITelephony(); 4939 if (telephony == null) 4940 return DATA_DISCONNECTED; 4941 return telephony.getDataState(); 4942 } catch (RemoteException ex) { 4943 // the phone process is restarting. 4944 return DATA_DISCONNECTED; 4945 } catch (NullPointerException ex) { 4946 return DATA_DISCONNECTED; 4947 } 4948 } 4949 4950 /** 4951 * Convert data state to string 4952 * 4953 * @return The data state in string format. 4954 * @hide 4955 */ dataStateToString(@ataState int state)4956 public static String dataStateToString(@DataState int state) { 4957 switch (state) { 4958 case DATA_DISCONNECTED: return "DISCONNECTED"; 4959 case DATA_CONNECTING: return "CONNECTING"; 4960 case DATA_CONNECTED: return "CONNECTED"; 4961 case DATA_SUSPENDED: return "SUSPENDED"; 4962 } 4963 return "UNKNOWN(" + state + ")"; 4964 } 4965 4966 /** 4967 * @hide 4968 */ 4969 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getITelephony()4970 private ITelephony getITelephony() { 4971 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 4972 } 4973 4974 /** 4975 * @hide 4976 */ getTelecomService()4977 private ITelecomService getTelecomService() { 4978 return ITelecomService.Stub.asInterface(ServiceManager.getService(TELECOM_SERVICE)); 4979 } 4980 getTelephonyRegistry()4981 private ITelephonyRegistry getTelephonyRegistry() { 4982 return ITelephonyRegistry.Stub.asInterface(ServiceManager.getService("telephony.registry")); 4983 } 4984 getIOns()4985 private IOns getIOns() { 4986 return IOns.Stub.asInterface(ServiceManager.getService("ions")); 4987 } 4988 4989 // 4990 // 4991 // PhoneStateListener 4992 // 4993 // 4994 4995 /** 4996 * Registers a listener object to receive notification of changes 4997 * in specified telephony states. 4998 * <p> 4999 * To register a listener, pass a {@link PhoneStateListener} and specify at least one telephony 5000 * state of interest in the events argument. 5001 * 5002 * At registration, and when a specified telephony state changes, the telephony manager invokes 5003 * the appropriate callback method on the listener object and passes the current (updated) 5004 * values. 5005 * <p> 5006 * To un-register a listener, pass the listener object and set the events argument to 5007 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 5008 * 5009 * If this TelephonyManager object has been created with {@link #createForSubscriptionId}, 5010 * applies to the given subId. Otherwise, applies to 5011 * {@link SubscriptionManager#getDefaultSubscriptionId()}. To listen events for multiple subIds, 5012 * pass a separate listener object to each TelephonyManager object created with 5013 * {@link #createForSubscriptionId}. 5014 * 5015 * Note: if you call this method while in the middle of a binder transaction, you <b>must</b> 5016 * call {@link android.os.Binder#clearCallingIdentity()} before calling this method. A 5017 * {@link SecurityException} will be thrown otherwise. 5018 * 5019 * @param listener The {@link PhoneStateListener} object to register 5020 * (or unregister) 5021 * @param events The telephony state(s) of interest to the listener, 5022 * as a bitwise-OR combination of {@link PhoneStateListener} 5023 * LISTEN_ flags. 5024 */ listen(PhoneStateListener listener, int events)5025 public void listen(PhoneStateListener listener, int events) { 5026 if (mContext == null) return; 5027 try { 5028 boolean notifyNow = (getITelephony() != null); 5029 ITelephonyRegistry registry = getTelephonyRegistry(); 5030 if (registry != null) { 5031 // subId from PhoneStateListener is deprecated Q on forward, use the subId from 5032 // TelephonyManager instance. keep using subId from PhoneStateListener for pre-Q. 5033 int subId = mSubId; 5034 if (VMRuntime.getRuntime().getTargetSdkVersion() >= Build.VERSION_CODES.Q) { 5035 // since mSubId in PhoneStateListener is deprecated from Q on forward, this is 5036 // the only place to set mSubId and its for "informational" only. 5037 // TODO: remove this once we completely get rid of mSubId in PhoneStateListener 5038 listener.mSubId = (events == PhoneStateListener.LISTEN_NONE) 5039 ? SubscriptionManager.INVALID_SUBSCRIPTION_ID : subId; 5040 } else if (listener.mSubId != null) { 5041 subId = listener.mSubId; 5042 } 5043 registry.listenForSubscriber(subId, getOpPackageName(), 5044 listener.callback, events, notifyNow); 5045 } else { 5046 Rlog.w(TAG, "telephony registry not ready."); 5047 } 5048 } catch (RemoteException ex) { 5049 // system process dead 5050 } 5051 } 5052 5053 /** 5054 * Returns the CDMA ERI icon index to display 5055 * @hide 5056 */ 5057 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCdmaEriIconIndex()5058 public int getCdmaEriIconIndex() { 5059 return getCdmaEriIconIndex(getSubId()); 5060 } 5061 5062 /** 5063 * Returns the CDMA ERI icon index to display for a subscription 5064 * @hide 5065 */ 5066 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5067 @UnsupportedAppUsage getCdmaEriIconIndex(int subId)5068 public int getCdmaEriIconIndex(int subId) { 5069 try { 5070 ITelephony telephony = getITelephony(); 5071 if (telephony == null) 5072 return -1; 5073 return telephony.getCdmaEriIconIndexForSubscriber(subId, getOpPackageName()); 5074 } catch (RemoteException ex) { 5075 // the phone process is restarting. 5076 return -1; 5077 } catch (NullPointerException ex) { 5078 return -1; 5079 } 5080 } 5081 5082 /** 5083 * Returns the CDMA ERI icon mode, 5084 * 0 - ON 5085 * 1 - FLASHING 5086 * 5087 * @hide 5088 */ 5089 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCdmaEriIconMode()5090 public int getCdmaEriIconMode() { 5091 return getCdmaEriIconMode(getSubId()); 5092 } 5093 5094 /** 5095 * Returns the CDMA ERI icon mode for a subscription. 5096 * 0 - ON 5097 * 1 - FLASHING 5098 * 5099 * @hide 5100 */ 5101 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5102 @UnsupportedAppUsage getCdmaEriIconMode(int subId)5103 public int getCdmaEriIconMode(int subId) { 5104 try { 5105 ITelephony telephony = getITelephony(); 5106 if (telephony == null) 5107 return -1; 5108 return telephony.getCdmaEriIconModeForSubscriber(subId, getOpPackageName()); 5109 } catch (RemoteException ex) { 5110 // the phone process is restarting. 5111 return -1; 5112 } catch (NullPointerException ex) { 5113 return -1; 5114 } 5115 } 5116 5117 /** 5118 * Returns the CDMA ERI text, 5119 * 5120 * @hide 5121 */ 5122 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCdmaEriText()5123 public String getCdmaEriText() { 5124 return getCdmaEriText(getSubId()); 5125 } 5126 5127 /** 5128 * Returns the CDMA ERI text, of a subscription 5129 * 5130 * @hide 5131 */ 5132 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5133 @UnsupportedAppUsage getCdmaEriText(int subId)5134 public String getCdmaEriText(int subId) { 5135 try { 5136 ITelephony telephony = getITelephony(); 5137 if (telephony == null) 5138 return null; 5139 return telephony.getCdmaEriTextForSubscriber(subId, getOpPackageName()); 5140 } catch (RemoteException ex) { 5141 // the phone process is restarting. 5142 return null; 5143 } catch (NullPointerException ex) { 5144 return null; 5145 } 5146 } 5147 5148 /** 5149 * @return true if the current device is "voice capable". 5150 * <p> 5151 * "Voice capable" means that this device supports circuit-switched 5152 * (i.e. voice) phone calls over the telephony network, and is allowed 5153 * to display the in-call UI while a cellular voice call is active. 5154 * This will be false on "data only" devices which can't make voice 5155 * calls and don't support any in-call UI. 5156 * <p> 5157 * Note: the meaning of this flag is subtly different from the 5158 * PackageManager.FEATURE_TELEPHONY system feature, which is available 5159 * on any device with a telephony radio, even if the device is 5160 * data-only. 5161 */ isVoiceCapable()5162 public boolean isVoiceCapable() { 5163 if (mContext == null) return true; 5164 return mContext.getResources().getBoolean( 5165 com.android.internal.R.bool.config_voice_capable); 5166 } 5167 5168 /** 5169 * @return true if the current device supports sms service. 5170 * <p> 5171 * If true, this means that the device supports both sending and 5172 * receiving sms via the telephony network. 5173 * <p> 5174 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 5175 * disabled when device doesn't support sms. 5176 */ isSmsCapable()5177 public boolean isSmsCapable() { 5178 if (mContext == null) return true; 5179 return mContext.getResources().getBoolean( 5180 com.android.internal.R.bool.config_sms_capable); 5181 } 5182 5183 /** 5184 * Requests all available cell information from all radios on the device including the 5185 * camped/registered, serving, and neighboring cells. 5186 * 5187 * <p>The response can include one or more {@link android.telephony.CellInfoGsm CellInfoGsm}, 5188 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 5189 * {@link android.telephony.CellInfoTdscdma CellInfoTdscdma}, 5190 * {@link android.telephony.CellInfoLte CellInfoLte}, and 5191 * {@link android.telephony.CellInfoWcdma CellInfoWcdma} objects, in any combination. 5192 * It is typical to see instances of one or more of any these in the list. In addition, zero 5193 * or more of the returned objects may be considered registered; that is, their 5194 * {@link android.telephony.CellInfo#isRegistered CellInfo.isRegistered()} 5195 * methods may return true, indicating that the cell is being used or would be used for 5196 * signaling communication if necessary. 5197 * 5198 * <p>Beginning with {@link android.os.Build.VERSION_CODES#Q Android Q}, 5199 * if this API results in a change of the cached CellInfo, that change will be reported via 5200 * {@link android.telephony.PhoneStateListener#onCellInfoChanged onCellInfoChanged()}. 5201 * 5202 * <p>Apps targeting {@link android.os.Build.VERSION_CODES#Q Android Q} or higher will no 5203 * longer trigger a refresh of the cached CellInfo by invoking this API. Instead, those apps 5204 * will receive the latest cached results, which may not be current. Apps targeting 5205 * {@link android.os.Build.VERSION_CODES#Q Android Q} or higher that wish to request updated 5206 * CellInfo should call 5207 * {@link android.telephony.TelephonyManager#requestCellInfoUpdate requestCellInfoUpdate()}; 5208 * however, in all cases, updates will be rate-limited and are not guaranteed. To determine the 5209 * recency of CellInfo data, callers should check 5210 * {@link android.telephony.CellInfo#getTimeStamp CellInfo#getTimeStamp()}. 5211 * 5212 * <p>This method returns valid data for devices with 5213 * {@link android.content.pm.PackageManager#FEATURE_TELEPHONY FEATURE_TELEPHONY}. In cases 5214 * where only partial information is available for a particular CellInfo entry, unavailable 5215 * fields will be reported as {@link android.telephony.CellInfo#UNAVAILABLE}. All reported 5216 * cells will include at least a valid set of technology-specific identification info and a 5217 * power level measurement. 5218 * 5219 * <p>This method is preferred over using {@link 5220 * android.telephony.TelephonyManager#getCellLocation getCellLocation()}. 5221 * 5222 * @return List of {@link android.telephony.CellInfo}; null if cell 5223 * information is unavailable. 5224 */ 5225 @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) getAllCellInfo()5226 public List<CellInfo> getAllCellInfo() { 5227 try { 5228 ITelephony telephony = getITelephony(); 5229 if (telephony == null) 5230 return null; 5231 return telephony.getAllCellInfo( 5232 getOpPackageName()); 5233 } catch (RemoteException ex) { 5234 } catch (NullPointerException ex) { 5235 } 5236 return null; 5237 } 5238 5239 /** Callback for providing asynchronous {@link CellInfo} on request */ 5240 public abstract static class CellInfoCallback { 5241 /** 5242 * Success response to 5243 * {@link android.telephony.TelephonyManager#requestCellInfoUpdate requestCellInfoUpdate()}. 5244 * 5245 * Invoked when there is a response to 5246 * {@link android.telephony.TelephonyManager#requestCellInfoUpdate requestCellInfoUpdate()} 5247 * to provide a list of {@link CellInfo}. If no {@link CellInfo} is available then an empty 5248 * list will be provided. If an error occurs, null will be provided unless the onError 5249 * callback is overridden. 5250 * 5251 * @param cellInfo a list of {@link CellInfo}, an empty list, or null. 5252 * 5253 * {@see android.telephony.TelephonyManager#getAllCellInfo getAllCellInfo()} 5254 */ onCellInfo(@onNull List<CellInfo> cellInfo)5255 public abstract void onCellInfo(@NonNull List<CellInfo> cellInfo); 5256 5257 /** @hide */ 5258 @Retention(RetentionPolicy.SOURCE) 5259 @IntDef(prefix = {"ERROR_"}, value = {ERROR_TIMEOUT, ERROR_MODEM_ERROR}) 5260 public @interface CellInfoCallbackError {} 5261 5262 /** 5263 * The system timed out waiting for a response from the Radio. 5264 */ 5265 public static final int ERROR_TIMEOUT = 1; 5266 5267 /** 5268 * The modem returned a failure. 5269 */ 5270 public static final int ERROR_MODEM_ERROR = 2; 5271 5272 /** 5273 * Error response to 5274 * {@link android.telephony.TelephonyManager#requestCellInfoUpdate requestCellInfoUpdate()}. 5275 * 5276 * Invoked when an error condition prevents updated {@link CellInfo} from being fetched 5277 * and returned from the modem. Callers of requestCellInfoUpdate() should override this 5278 * function to receive detailed status information in the event of an error. By default, 5279 * this function will invoke onCellInfo() with null. 5280 * 5281 * @param errorCode an error code indicating the type of failure. 5282 * @param detail a Throwable object with additional detail regarding the failure if 5283 * available, otherwise null. 5284 */ onError(@ellInfoCallbackError int errorCode, @Nullable Throwable detail)5285 public void onError(@CellInfoCallbackError int errorCode, @Nullable Throwable detail) { 5286 // By default, simply invoke the success callback with an empty list. 5287 onCellInfo(new ArrayList<CellInfo>()); 5288 } 5289 }; 5290 5291 /** 5292 * Requests all available cell information from the current subscription for observed 5293 * camped/registered, serving, and neighboring cells. 5294 * 5295 * <p>Any available results from this request will be provided by calls to 5296 * {@link android.telephony.PhoneStateListener#onCellInfoChanged onCellInfoChanged()} 5297 * for each active subscription. 5298 * 5299 * @param executor the executor on which callback will be invoked. 5300 * @param callback a callback to receive CellInfo. 5301 */ 5302 @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) requestCellInfoUpdate( @onNull @allbackExecutor Executor executor, @NonNull CellInfoCallback callback)5303 public void requestCellInfoUpdate( 5304 @NonNull @CallbackExecutor Executor executor, @NonNull CellInfoCallback callback) { 5305 try { 5306 ITelephony telephony = getITelephony(); 5307 if (telephony == null) return; 5308 telephony.requestCellInfoUpdate( 5309 getSubId(), 5310 new ICellInfoCallback.Stub() { 5311 public void onCellInfo(List<CellInfo> cellInfo) { 5312 Binder.withCleanCallingIdentity(() -> 5313 executor.execute(() -> callback.onCellInfo(cellInfo))); 5314 } 5315 5316 public void onError(int errorCode, android.os.ParcelableException detail) { 5317 Binder.withCleanCallingIdentity(() -> 5318 executor.execute(() -> callback.onError( 5319 errorCode, detail.getCause()))); 5320 } 5321 }, getOpPackageName()); 5322 5323 } catch (RemoteException ex) { 5324 } 5325 } 5326 5327 /** 5328 * Requests all available cell information from the current subscription for observed 5329 * camped/registered, serving, and neighboring cells. 5330 * 5331 * <p>Any available results from this request will be provided by calls to 5332 * {@link android.telephony.PhoneStateListener#onCellInfoChanged onCellInfoChanged()} 5333 * for each active subscription. 5334 * 5335 * @param workSource the requestor to whom the power consumption for this should be attributed. 5336 * @param executor the executor on which callback will be invoked. 5337 * @param callback a callback to receive CellInfo. 5338 * @hide 5339 */ 5340 @SystemApi 5341 @RequiresPermission(allOf = {android.Manifest.permission.ACCESS_FINE_LOCATION, 5342 android.Manifest.permission.MODIFY_PHONE_STATE}) requestCellInfoUpdate(@onNull WorkSource workSource, @NonNull @CallbackExecutor Executor executor, @NonNull CellInfoCallback callback)5343 public void requestCellInfoUpdate(@NonNull WorkSource workSource, 5344 @NonNull @CallbackExecutor Executor executor, @NonNull CellInfoCallback callback) { 5345 try { 5346 ITelephony telephony = getITelephony(); 5347 if (telephony == null) return; 5348 telephony.requestCellInfoUpdateWithWorkSource( 5349 getSubId(), 5350 new ICellInfoCallback.Stub() { 5351 public void onCellInfo(List<CellInfo> cellInfo) { 5352 Binder.withCleanCallingIdentity(() -> 5353 executor.execute(() -> callback.onCellInfo(cellInfo))); 5354 } 5355 5356 public void onError(int errorCode, android.os.ParcelableException detail) { 5357 Binder.withCleanCallingIdentity(() -> 5358 executor.execute(() -> callback.onError( 5359 errorCode, detail.getCause()))); 5360 } 5361 }, getOpPackageName(), workSource); 5362 } catch (RemoteException ex) { 5363 } 5364 } 5365 5366 /** 5367 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 5368 * PhoneStateListener.onCellInfoChanged} will be invoked. 5369 *<p> 5370 * The default, 0, means invoke onCellInfoChanged when any of the reported 5371 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 5372 * A onCellInfoChanged. 5373 *<p> 5374 * @param rateInMillis the rate 5375 * 5376 * @hide 5377 */ setCellInfoListRate(int rateInMillis)5378 public void setCellInfoListRate(int rateInMillis) { 5379 try { 5380 ITelephony telephony = getITelephony(); 5381 if (telephony != null) 5382 telephony.setCellInfoListRate(rateInMillis); 5383 } catch (RemoteException ex) { 5384 } catch (NullPointerException ex) { 5385 } 5386 } 5387 5388 /** 5389 * Returns the MMS user agent. 5390 */ getMmsUserAgent()5391 public String getMmsUserAgent() { 5392 try { 5393 ITelephony telephony = getITelephony(); 5394 if (telephony != null) { 5395 return telephony.getMmsUserAgent(getSubId()); 5396 } 5397 } catch (RemoteException ex) { 5398 } catch (NullPointerException ex) { 5399 } 5400 return null; 5401 } 5402 5403 /** 5404 * Returns the MMS user agent profile URL. 5405 */ getMmsUAProfUrl()5406 public String getMmsUAProfUrl() { 5407 try { 5408 ITelephony telephony = getITelephony(); 5409 if (telephony != null) { 5410 return telephony.getMmsUAProfUrl(getSubId()); 5411 } 5412 } catch (RemoteException ex) { 5413 } catch (NullPointerException ex) { 5414 } 5415 return null; 5416 } 5417 5418 /** 5419 * Opens a logical channel to the ICC card. 5420 * 5421 * Input parameters equivalent to TS 27.007 AT+CCHO command. 5422 * 5423 * <p>Requires Permission: 5424 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5425 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5426 * 5427 * @param AID Application id. See ETSI 102.221 and 101.220. 5428 * @return an IccOpenLogicalChannelResponse object. 5429 * @deprecated Replaced by {@link #iccOpenLogicalChannel(String, int)} 5430 */ 5431 @Deprecated iccOpenLogicalChannel(String AID)5432 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { 5433 return iccOpenLogicalChannel(getSubId(), AID, -1); 5434 } 5435 5436 /** 5437 * Opens a logical channel to the ICC card using the physical slot index. 5438 * 5439 * Use this method when no subscriptions are available on the SIM and the operation must be 5440 * performed using the physical slot index. 5441 * 5442 * Input parameters equivalent to TS 27.007 AT+CCHO command. 5443 * 5444 * <p>Requires Permission: 5445 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 5446 * 5447 * @param slotIndex the physical slot index of the ICC card 5448 * @param aid Application id. See ETSI 102.221 and 101.220. 5449 * @param p2 P2 parameter (described in ISO 7816-4). 5450 * @return an IccOpenLogicalChannelResponse object. 5451 * @hide 5452 */ 5453 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 5454 @SystemApi 5455 @Nullable iccOpenLogicalChannelBySlot(int slotIndex, @Nullable String aid, int p2)5456 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(int slotIndex, 5457 @Nullable String aid, int p2) { 5458 try { 5459 ITelephony telephony = getITelephony(); 5460 if (telephony != null) { 5461 return telephony.iccOpenLogicalChannelBySlot(slotIndex, getOpPackageName(), aid, 5462 p2); 5463 } 5464 } catch (RemoteException ex) { 5465 } catch (NullPointerException ex) { 5466 } 5467 return null; 5468 } 5469 5470 /** 5471 * Opens a logical channel to the ICC card. 5472 * 5473 * Input parameters equivalent to TS 27.007 AT+CCHO command. 5474 * 5475 * <p>Requires Permission: 5476 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5477 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5478 * 5479 * @param AID Application id. See ETSI 102.221 and 101.220. 5480 * @param p2 P2 parameter (described in ISO 7816-4). 5481 * @return an IccOpenLogicalChannelResponse object. 5482 */ iccOpenLogicalChannel(String AID, int p2)5483 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID, int p2) { 5484 return iccOpenLogicalChannel(getSubId(), AID, p2); 5485 } 5486 5487 /** 5488 * Opens a logical channel to the ICC card. 5489 * 5490 * Input parameters equivalent to TS 27.007 AT+CCHO command. 5491 * 5492 * <p>Requires Permission: 5493 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5494 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5495 * 5496 * @param subId The subscription to use. 5497 * @param AID Application id. See ETSI 102.221 and 101.220. 5498 * @param p2 P2 parameter (described in ISO 7816-4). 5499 * @return an IccOpenLogicalChannelResponse object. 5500 * @hide 5501 */ iccOpenLogicalChannel(int subId, String AID, int p2)5502 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID, int p2) { 5503 try { 5504 ITelephony telephony = getITelephony(); 5505 if (telephony != null) 5506 return telephony.iccOpenLogicalChannel(subId, getOpPackageName(), AID, p2); 5507 } catch (RemoteException ex) { 5508 } catch (NullPointerException ex) { 5509 } 5510 return null; 5511 } 5512 5513 /** 5514 * Closes a previously opened logical channel to the ICC card using the physical slot index. 5515 * 5516 * Use this method when no subscriptions are available on the SIM and the operation must be 5517 * performed using the physical slot index. 5518 * 5519 * Input parameters equivalent to TS 27.007 AT+CCHC command. 5520 * 5521 * <p>Requires Permission: 5522 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 5523 * 5524 * @param slotIndex the physical slot index of the ICC card 5525 * @param channel is the channel id to be closed as returned by a successful 5526 * iccOpenLogicalChannel. 5527 * @return true if the channel was closed successfully. 5528 * @hide 5529 */ 5530 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 5531 @SystemApi iccCloseLogicalChannelBySlot(int slotIndex, int channel)5532 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { 5533 try { 5534 ITelephony telephony = getITelephony(); 5535 if (telephony != null) { 5536 return telephony.iccCloseLogicalChannelBySlot(slotIndex, channel); 5537 } 5538 } catch (RemoteException ex) { 5539 } catch (NullPointerException ex) { 5540 } 5541 return false; 5542 } 5543 5544 /** 5545 * Closes a previously opened logical channel to the ICC card. 5546 * 5547 * Input parameters equivalent to TS 27.007 AT+CCHC command. 5548 * 5549 * <p>Requires Permission: 5550 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5551 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5552 * 5553 * @param channel is the channel id to be closed as returned by a successful 5554 * iccOpenLogicalChannel. 5555 * @return true if the channel was closed successfully. 5556 */ iccCloseLogicalChannel(int channel)5557 public boolean iccCloseLogicalChannel(int channel) { 5558 return iccCloseLogicalChannel(getSubId(), channel); 5559 } 5560 5561 /** 5562 * Closes a previously opened logical channel to the ICC card. 5563 * 5564 * Input parameters equivalent to TS 27.007 AT+CCHC command. 5565 * 5566 * <p>Requires Permission: 5567 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5568 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5569 * 5570 * @param subId The subscription to use. 5571 * @param channel is the channel id to be closed as returned by a successful 5572 * iccOpenLogicalChannel. 5573 * @return true if the channel was closed successfully. 5574 * @hide 5575 */ iccCloseLogicalChannel(int subId, int channel)5576 public boolean iccCloseLogicalChannel(int subId, int channel) { 5577 try { 5578 ITelephony telephony = getITelephony(); 5579 if (telephony != null) 5580 return telephony.iccCloseLogicalChannel(subId, channel); 5581 } catch (RemoteException ex) { 5582 } catch (NullPointerException ex) { 5583 } 5584 return false; 5585 } 5586 5587 /** 5588 * Transmit an APDU to the ICC card over a logical channel using the physical slot index. 5589 * 5590 * Use this method when no subscriptions are available on the SIM and the operation must be 5591 * performed using the physical slot index. 5592 * 5593 * Input parameters equivalent to TS 27.007 AT+CGLA command. 5594 * 5595 * <p>Requires Permission: 5596 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 5597 * 5598 * @param slotIndex the physical slot index of the ICC card 5599 * @param channel is the channel id to be closed as returned by a successful 5600 * iccOpenLogicalChannel. 5601 * @param cla Class of the APDU command. 5602 * @param instruction Instruction of the APDU command. 5603 * @param p1 P1 value of the APDU command. 5604 * @param p2 P2 value of the APDU command. 5605 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 5606 * is sent to the SIM. 5607 * @param data Data to be sent with the APDU. 5608 * @return The APDU response from the ICC card with the status appended at the end, or null if 5609 * there is an issue connecting to the Telephony service. 5610 * @hide 5611 */ 5612 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 5613 @SystemApi 5614 @Nullable iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, int instruction, int p1, int p2, int p3, @Nullable String data)5615 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, 5616 int instruction, int p1, int p2, int p3, @Nullable String data) { 5617 try { 5618 ITelephony telephony = getITelephony(); 5619 if (telephony != null) { 5620 return telephony.iccTransmitApduLogicalChannelBySlot(slotIndex, channel, cla, 5621 instruction, p1, p2, p3, data); 5622 } 5623 } catch (RemoteException ex) { 5624 } catch (NullPointerException ex) { 5625 } 5626 return null; 5627 } 5628 5629 /** 5630 * Transmit an APDU to the ICC card over a logical channel. 5631 * 5632 * Input parameters equivalent to TS 27.007 AT+CGLA command. 5633 * 5634 * <p>Requires Permission: 5635 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5636 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5637 * 5638 * @param channel is the channel id to be closed as returned by a successful 5639 * iccOpenLogicalChannel. 5640 * @param cla Class of the APDU command. 5641 * @param instruction Instruction of the APDU command. 5642 * @param p1 P1 value of the APDU command. 5643 * @param p2 P2 value of the APDU command. 5644 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 5645 * is sent to the SIM. 5646 * @param data Data to be sent with the APDU. 5647 * @return The APDU response from the ICC card with the status appended at 5648 * the end. 5649 */ iccTransmitApduLogicalChannel(int channel, int cla, int instruction, int p1, int p2, int p3, String data)5650 public String iccTransmitApduLogicalChannel(int channel, int cla, 5651 int instruction, int p1, int p2, int p3, String data) { 5652 return iccTransmitApduLogicalChannel(getSubId(), channel, cla, 5653 instruction, p1, p2, p3, data); 5654 } 5655 5656 /** 5657 * Transmit an APDU to the ICC card over a logical channel. 5658 * 5659 * Input parameters equivalent to TS 27.007 AT+CGLA command. 5660 * 5661 * <p>Requires Permission: 5662 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5663 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5664 * 5665 * @param subId The subscription to use. 5666 * @param channel is the channel id to be closed as returned by a successful 5667 * iccOpenLogicalChannel. 5668 * @param cla Class of the APDU command. 5669 * @param instruction Instruction of the APDU command. 5670 * @param p1 P1 value of the APDU command. 5671 * @param p2 P2 value of the APDU command. 5672 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 5673 * is sent to the SIM. 5674 * @param data Data to be sent with the APDU. 5675 * @return The APDU response from the ICC card with the status appended at 5676 * the end. 5677 * @hide 5678 */ iccTransmitApduLogicalChannel(int subId, int channel, int cla, int instruction, int p1, int p2, int p3, String data)5679 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, 5680 int instruction, int p1, int p2, int p3, String data) { 5681 try { 5682 ITelephony telephony = getITelephony(); 5683 if (telephony != null) 5684 return telephony.iccTransmitApduLogicalChannel(subId, channel, cla, 5685 instruction, p1, p2, p3, data); 5686 } catch (RemoteException ex) { 5687 } catch (NullPointerException ex) { 5688 } 5689 return ""; 5690 } 5691 5692 /** 5693 * Transmit an APDU to the ICC card over the basic channel using the physical slot index. 5694 * 5695 * Use this method when no subscriptions are available on the SIM and the operation must be 5696 * performed using the physical slot index. 5697 * 5698 * Input parameters equivalent to TS 27.007 AT+CSIM command. 5699 * 5700 * <p>Requires Permission: 5701 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 5702 * 5703 * @param slotIndex the physical slot index of the ICC card to target 5704 * @param cla Class of the APDU command. 5705 * @param instruction Instruction of the APDU command. 5706 * @param p1 P1 value of the APDU command. 5707 * @param p2 P2 value of the APDU command. 5708 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 5709 * is sent to the SIM. 5710 * @param data Data to be sent with the APDU. 5711 * @return The APDU response from the ICC card with the status appended at 5712 * the end. 5713 * @hide 5714 */ 5715 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 5716 @SystemApi 5717 @NonNull iccTransmitApduBasicChannelBySlot(int slotIndex, int cla, int instruction, int p1, int p2, int p3, @Nullable String data)5718 public String iccTransmitApduBasicChannelBySlot(int slotIndex, int cla, int instruction, int p1, 5719 int p2, int p3, @Nullable String data) { 5720 try { 5721 ITelephony telephony = getITelephony(); 5722 if (telephony != null) { 5723 return telephony.iccTransmitApduBasicChannelBySlot(slotIndex, getOpPackageName(), 5724 cla, instruction, p1, p2, p3, data); 5725 } 5726 } catch (RemoteException ex) { 5727 } catch (NullPointerException ex) { 5728 } 5729 return null; 5730 } 5731 5732 /** 5733 * Transmit an APDU to the ICC card over the basic channel. 5734 * 5735 * Input parameters equivalent to TS 27.007 AT+CSIM command. 5736 * 5737 * <p>Requires Permission: 5738 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5739 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5740 * 5741 * @param cla Class of the APDU command. 5742 * @param instruction Instruction of the APDU command. 5743 * @param p1 P1 value of the APDU command. 5744 * @param p2 P2 value of the APDU command. 5745 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 5746 * is sent to the SIM. 5747 * @param data Data to be sent with the APDU. 5748 * @return The APDU response from the ICC card with the status appended at 5749 * the end. 5750 */ iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2, int p3, String data)5751 public String iccTransmitApduBasicChannel(int cla, 5752 int instruction, int p1, int p2, int p3, String data) { 5753 return iccTransmitApduBasicChannel(getSubId(), cla, 5754 instruction, p1, p2, p3, data); 5755 } 5756 5757 /** 5758 * Transmit an APDU to the ICC card over the basic channel. 5759 * 5760 * Input parameters equivalent to TS 27.007 AT+CSIM command. 5761 * 5762 * <p>Requires Permission: 5763 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5764 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5765 * 5766 * @param subId The subscription to use. 5767 * @param cla Class of the APDU command. 5768 * @param instruction Instruction of the APDU command. 5769 * @param p1 P1 value of the APDU command. 5770 * @param p2 P2 value of the APDU command. 5771 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 5772 * is sent to the SIM. 5773 * @param data Data to be sent with the APDU. 5774 * @return The APDU response from the ICC card with the status appended at 5775 * the end. 5776 * @hide 5777 */ iccTransmitApduBasicChannel(int subId, int cla, int instruction, int p1, int p2, int p3, String data)5778 public String iccTransmitApduBasicChannel(int subId, int cla, 5779 int instruction, int p1, int p2, int p3, String data) { 5780 try { 5781 ITelephony telephony = getITelephony(); 5782 if (telephony != null) 5783 return telephony.iccTransmitApduBasicChannel(subId, getOpPackageName(), cla, 5784 instruction, p1, p2, p3, data); 5785 } catch (RemoteException ex) { 5786 } catch (NullPointerException ex) { 5787 } 5788 return ""; 5789 } 5790 5791 /** 5792 * Returns the response APDU for a command APDU sent through SIM_IO. 5793 * 5794 * <p>Requires Permission: 5795 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5796 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5797 * 5798 * @param fileID 5799 * @param command 5800 * @param p1 P1 value of the APDU command. 5801 * @param p2 P2 value of the APDU command. 5802 * @param p3 P3 value of the APDU command. 5803 * @param filePath 5804 * @return The APDU response. 5805 */ iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, String filePath)5806 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 5807 String filePath) { 5808 return iccExchangeSimIO(getSubId(), fileID, command, p1, p2, p3, filePath); 5809 } 5810 5811 /** 5812 * Returns the response APDU for a command APDU sent through SIM_IO. 5813 * 5814 * <p>Requires Permission: 5815 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5816 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5817 * 5818 * @param subId The subscription to use. 5819 * @param fileID 5820 * @param command 5821 * @param p1 P1 value of the APDU command. 5822 * @param p2 P2 value of the APDU command. 5823 * @param p3 P3 value of the APDU command. 5824 * @param filePath 5825 * @return The APDU response. 5826 * @hide 5827 */ iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3, String filePath)5828 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, 5829 int p3, String filePath) { 5830 try { 5831 ITelephony telephony = getITelephony(); 5832 if (telephony != null) 5833 return telephony.iccExchangeSimIO(subId, fileID, command, p1, p2, p3, filePath); 5834 } catch (RemoteException ex) { 5835 } catch (NullPointerException ex) { 5836 } 5837 return null; 5838 } 5839 5840 /** 5841 * Send ENVELOPE to the SIM and return the response. 5842 * 5843 * <p>Requires Permission: 5844 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5845 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5846 * 5847 * @param content String containing SAT/USAT response in hexadecimal 5848 * format starting with command tag. See TS 102 223 for 5849 * details. 5850 * @return The APDU response from the ICC card in hexadecimal format 5851 * with the last 4 bytes being the status word. If the command fails, 5852 * returns an empty string. 5853 */ sendEnvelopeWithStatus(String content)5854 public String sendEnvelopeWithStatus(String content) { 5855 return sendEnvelopeWithStatus(getSubId(), content); 5856 } 5857 5858 /** 5859 * Send ENVELOPE to the SIM and return the response. 5860 * 5861 * <p>Requires Permission: 5862 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5863 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5864 * 5865 * @param subId The subscription to use. 5866 * @param content String containing SAT/USAT response in hexadecimal 5867 * format starting with command tag. See TS 102 223 for 5868 * details. 5869 * @return The APDU response from the ICC card in hexadecimal format 5870 * with the last 4 bytes being the status word. If the command fails, 5871 * returns an empty string. 5872 * @hide 5873 */ sendEnvelopeWithStatus(int subId, String content)5874 public String sendEnvelopeWithStatus(int subId, String content) { 5875 try { 5876 ITelephony telephony = getITelephony(); 5877 if (telephony != null) 5878 return telephony.sendEnvelopeWithStatus(subId, content); 5879 } catch (RemoteException ex) { 5880 } catch (NullPointerException ex) { 5881 } 5882 return ""; 5883 } 5884 5885 /** 5886 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 5887 * Used for device configuration by some CDMA operators. 5888 * 5889 * <p>Requires Permission: 5890 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5891 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5892 * 5893 * @param itemID the ID of the item to read. 5894 * @return the NV item as a String, or null on any failure. 5895 * 5896 * @hide 5897 */ 5898 @UnsupportedAppUsage nvReadItem(int itemID)5899 public String nvReadItem(int itemID) { 5900 try { 5901 ITelephony telephony = getITelephony(); 5902 if (telephony != null) 5903 return telephony.nvReadItem(itemID); 5904 } catch (RemoteException ex) { 5905 Rlog.e(TAG, "nvReadItem RemoteException", ex); 5906 } catch (NullPointerException ex) { 5907 Rlog.e(TAG, "nvReadItem NPE", ex); 5908 } 5909 return ""; 5910 } 5911 5912 /** 5913 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 5914 * Used for device configuration by some CDMA operators. 5915 * 5916 * <p>Requires Permission: 5917 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5918 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5919 * 5920 * @param itemID the ID of the item to read. 5921 * @param itemValue the value to write, as a String. 5922 * @return true on success; false on any failure. 5923 * 5924 * @hide 5925 */ nvWriteItem(int itemID, String itemValue)5926 public boolean nvWriteItem(int itemID, String itemValue) { 5927 try { 5928 ITelephony telephony = getITelephony(); 5929 if (telephony != null) 5930 return telephony.nvWriteItem(itemID, itemValue); 5931 } catch (RemoteException ex) { 5932 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 5933 } catch (NullPointerException ex) { 5934 Rlog.e(TAG, "nvWriteItem NPE", ex); 5935 } 5936 return false; 5937 } 5938 5939 /** 5940 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 5941 * Used for device configuration by some CDMA operators. 5942 * 5943 * <p>Requires Permission: 5944 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5945 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5946 * 5947 * @param preferredRoamingList byte array containing the new PRL. 5948 * @return true on success; false on any failure. 5949 * 5950 * @hide 5951 */ nvWriteCdmaPrl(byte[] preferredRoamingList)5952 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 5953 try { 5954 ITelephony telephony = getITelephony(); 5955 if (telephony != null) 5956 return telephony.nvWriteCdmaPrl(preferredRoamingList); 5957 } catch (RemoteException ex) { 5958 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 5959 } catch (NullPointerException ex) { 5960 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 5961 } 5962 return false; 5963 } 5964 5965 /** 5966 * Perform the specified type of NV config reset. The radio will be taken offline 5967 * and the device must be rebooted after the operation. Used for device 5968 * configuration by some CDMA operators. 5969 * 5970 * <p>Requires Permission: 5971 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5972 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5973 * 5974 * TODO: remove this one. use {@link #rebootRadio()} for reset type 1 and 5975 * {@link #resetRadioConfig()} for reset type 3 5976 * 5977 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 5978 * @return true on success; false on any failure. 5979 * 5980 * @hide 5981 */ 5982 @UnsupportedAppUsage nvResetConfig(int resetType)5983 public boolean nvResetConfig(int resetType) { 5984 try { 5985 ITelephony telephony = getITelephony(); 5986 if (telephony != null) { 5987 if (resetType == 1 /*1: reload NV reset */) { 5988 return telephony.rebootModem(getSlotIndex()); 5989 } else if (resetType == 3 /*3: factory NV reset */) { 5990 return telephony.resetModemConfig(getSlotIndex()); 5991 } else { 5992 Rlog.e(TAG, "nvResetConfig unsupported reset type"); 5993 } 5994 } 5995 } catch (RemoteException ex) { 5996 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 5997 } catch (NullPointerException ex) { 5998 Rlog.e(TAG, "nvResetConfig NPE", ex); 5999 } 6000 return false; 6001 } 6002 6003 /** 6004 * Rollback modem configurations to factory default except some config which are in whitelist. 6005 * Used for device configuration by some carriers. 6006 * 6007 * <p>Requires Permission: 6008 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 6009 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6010 * 6011 * @return {@code true} on success; {@code false} on any failure. 6012 * 6013 * @hide 6014 */ 6015 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 6016 @SystemApi resetRadioConfig()6017 public boolean resetRadioConfig() { 6018 try { 6019 ITelephony telephony = getITelephony(); 6020 if (telephony != null) { 6021 return telephony.resetModemConfig(getSlotIndex()); 6022 } 6023 } catch (RemoteException ex) { 6024 Rlog.e(TAG, "resetRadioConfig RemoteException", ex); 6025 } catch (NullPointerException ex) { 6026 Rlog.e(TAG, "resetRadioConfig NPE", ex); 6027 } 6028 return false; 6029 } 6030 6031 /** 6032 * Generate a radio modem reset. Used for device configuration by some carriers. 6033 * 6034 * <p>Requires Permission: 6035 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 6036 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6037 * 6038 * @return {@code true} on success; {@code false} on any failure. 6039 * 6040 * @hide 6041 */ 6042 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 6043 @SystemApi rebootRadio()6044 public boolean rebootRadio() { 6045 try { 6046 ITelephony telephony = getITelephony(); 6047 if (telephony != null) { 6048 return telephony.rebootModem(getSlotIndex()); 6049 } 6050 } catch (RemoteException ex) { 6051 Rlog.e(TAG, "rebootRadio RemoteException", ex); 6052 } catch (NullPointerException ex) { 6053 Rlog.e(TAG, "rebootRadio NPE", ex); 6054 } 6055 return false; 6056 } 6057 6058 /** 6059 * Return an appropriate subscription ID for any situation. 6060 * 6061 * If this object has been created with {@link #createForSubscriptionId}, then the provided 6062 * subId is returned. Otherwise, the default subId will be returned. 6063 */ getSubId()6064 private int getSubId() { 6065 if (SubscriptionManager.isUsableSubIdValue(mSubId)) { 6066 return mSubId; 6067 } 6068 return SubscriptionManager.getDefaultSubscriptionId(); 6069 } 6070 6071 /** 6072 * Return an appropriate subscription ID for any situation. 6073 * 6074 * If this object has been created with {@link #createForSubscriptionId}, then the provided 6075 * subId is returned. Otherwise, the preferred subId which is based on caller's context is 6076 * returned. 6077 * {@see SubscriptionManager#getDefaultDataSubscriptionId()} 6078 * {@see SubscriptionManager#getDefaultVoiceSubscriptionId()} 6079 * {@see SubscriptionManager#getDefaultSmsSubscriptionId()} 6080 */ 6081 @UnsupportedAppUsage getSubId(int preferredSubId)6082 private int getSubId(int preferredSubId) { 6083 if (SubscriptionManager.isUsableSubIdValue(mSubId)) { 6084 return mSubId; 6085 } 6086 return preferredSubId; 6087 } 6088 6089 /** 6090 * Return an appropriate phone ID for any situation. 6091 * 6092 * If this object has been created with {@link #createForSubscriptionId}, then the phoneId 6093 * associated with the provided subId is returned. Otherwise, the default phoneId associated 6094 * with the default subId will be returned. 6095 */ getPhoneId()6096 private int getPhoneId() { 6097 return SubscriptionManager.getPhoneId(getSubId()); 6098 } 6099 6100 /** 6101 * Return an appropriate phone ID for any situation. 6102 * 6103 * If this object has been created with {@link #createForSubscriptionId}, then the phoneId 6104 * associated with the provided subId is returned. Otherwise, return the phoneId associated 6105 * with the preferred subId based on caller's context. 6106 * {@see SubscriptionManager#getDefaultDataSubscriptionId()} 6107 * {@see SubscriptionManager#getDefaultVoiceSubscriptionId()} 6108 * {@see SubscriptionManager#getDefaultSmsSubscriptionId()} 6109 */ 6110 @UnsupportedAppUsage getPhoneId(int preferredSubId)6111 private int getPhoneId(int preferredSubId) { 6112 return SubscriptionManager.getPhoneId(getSubId(preferredSubId)); 6113 } 6114 6115 /** 6116 * Return an appropriate slot index for any situation. 6117 * 6118 * if this object has been created with {@link #createForSubscriptionId}, then the slot index 6119 * associated with the provided subId is returned. Otherwise, return the slot index associated 6120 * with the default subId. 6121 * If SIM is not inserted, return default SIM slot index. 6122 * 6123 * {@hide} 6124 */ 6125 @VisibleForTesting 6126 @UnsupportedAppUsage getSlotIndex()6127 public int getSlotIndex() { 6128 int slotIndex = SubscriptionManager.getSlotIndex(getSubId()); 6129 if (slotIndex == SubscriptionManager.SIM_NOT_INSERTED) { 6130 slotIndex = SubscriptionManager.DEFAULT_SIM_SLOT_INDEX; 6131 } 6132 return slotIndex; 6133 } 6134 6135 /** 6136 * Request that the next incoming call from a number matching {@code range} be intercepted. 6137 * 6138 * This API is intended for OEMs to provide a service for apps to verify the device's phone 6139 * number. When called, the Telephony stack will store the provided {@link PhoneNumberRange} and 6140 * intercept the next incoming call from a number that lies within the range, within a timeout 6141 * specified by {@code timeoutMillis}. 6142 * 6143 * If such a phone call is received, the caller will be notified via 6144 * {@link NumberVerificationCallback#onCallReceived(String)} on the provided {@link Executor}. 6145 * If verification fails for any reason, the caller will be notified via 6146 * {@link NumberVerificationCallback#onVerificationFailed(int)} 6147 * on the provided {@link Executor}. 6148 * 6149 * In addition to the {@link Manifest.permission#MODIFY_PHONE_STATE} permission, callers of this 6150 * API must also be listed in the device configuration as an authorized app in 6151 * {@code packages/services/Telephony/res/values/config.xml} under the 6152 * {@code config_number_verification_package_name} key. 6153 * 6154 * @hide 6155 * @param range The range of phone numbers the caller expects a phone call from. 6156 * @param timeoutMillis The amount of time to wait for such a call, or the value of 6157 * {@link #getMaxNumberVerificationTimeoutMillis()}, whichever is lesser. 6158 * @param executor The {@link Executor} that callbacks should be executed on. 6159 * @param callback The callback to use for delivering results. 6160 */ 6161 @SystemApi 6162 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) requestNumberVerification(@onNull PhoneNumberRange range, long timeoutMillis, @NonNull @CallbackExecutor Executor executor, @NonNull NumberVerificationCallback callback)6163 public void requestNumberVerification(@NonNull PhoneNumberRange range, long timeoutMillis, 6164 @NonNull @CallbackExecutor Executor executor, 6165 @NonNull NumberVerificationCallback callback) { 6166 if (executor == null) { 6167 throw new NullPointerException("Executor must be non-null"); 6168 } 6169 if (callback == null) { 6170 throw new NullPointerException("Callback must be non-null"); 6171 } 6172 6173 INumberVerificationCallback internalCallback = new INumberVerificationCallback.Stub() { 6174 @Override 6175 public void onCallReceived(String phoneNumber) { 6176 Binder.withCleanCallingIdentity(() -> 6177 executor.execute(() -> 6178 callback.onCallReceived(phoneNumber))); 6179 } 6180 6181 @Override 6182 public void onVerificationFailed(int reason) { 6183 Binder.withCleanCallingIdentity(() -> 6184 executor.execute(() -> 6185 callback.onVerificationFailed(reason))); 6186 } 6187 }; 6188 6189 try { 6190 ITelephony telephony = getITelephony(); 6191 if (telephony != null) { 6192 telephony.requestNumberVerification(range, timeoutMillis, internalCallback, 6193 getOpPackageName()); 6194 } 6195 } catch (RemoteException ex) { 6196 Rlog.e(TAG, "requestNumberVerification RemoteException", ex); 6197 executor.execute(() -> 6198 callback.onVerificationFailed(NumberVerificationCallback.REASON_UNSPECIFIED)); 6199 } 6200 } 6201 6202 /** 6203 * Sets a per-phone telephony property with the value specified. 6204 * 6205 * @hide 6206 */ 6207 @UnsupportedAppUsage setTelephonyProperty(int phoneId, String property, String value)6208 public static void setTelephonyProperty(int phoneId, String property, String value) { 6209 String propVal = ""; 6210 String p[] = null; 6211 String prop = SystemProperties.get(property); 6212 6213 if (value == null) { 6214 value = ""; 6215 } 6216 value.replace(',', ' '); 6217 if (prop != null) { 6218 p = prop.split(","); 6219 } 6220 6221 if (!SubscriptionManager.isValidPhoneId(phoneId)) { 6222 Rlog.d(TAG, "setTelephonyProperty: invalid phoneId=" + phoneId + 6223 " property=" + property + " value: " + value + " prop=" + prop); 6224 return; 6225 } 6226 6227 for (int i = 0; i < phoneId; i++) { 6228 String str = ""; 6229 if ((p != null) && (i < p.length)) { 6230 str = p[i]; 6231 } 6232 propVal = propVal + str + ","; 6233 } 6234 6235 propVal = propVal + value; 6236 if (p != null) { 6237 for (int i = phoneId + 1; i < p.length; i++) { 6238 propVal = propVal + "," + p[i]; 6239 } 6240 } 6241 6242 int propValLen = propVal.length(); 6243 try { 6244 propValLen = propVal.getBytes("utf-8").length; 6245 } catch (java.io.UnsupportedEncodingException e) { 6246 Rlog.d(TAG, "setTelephonyProperty: utf-8 not supported"); 6247 } 6248 if (propValLen > SystemProperties.PROP_VALUE_MAX) { 6249 Rlog.d(TAG, "setTelephonyProperty: property too long phoneId=" + phoneId + 6250 " property=" + property + " value: " + value + " propVal=" + propVal); 6251 return; 6252 } 6253 6254 SystemProperties.set(property, propVal); 6255 } 6256 6257 /** 6258 * Sets a global telephony property with the value specified. 6259 * 6260 * @hide 6261 */ setTelephonyProperty(String property, String value)6262 public static void setTelephonyProperty(String property, String value) { 6263 if (value == null) { 6264 value = ""; 6265 } 6266 Rlog.d(TAG, "setTelephonyProperty: success" + " property=" + 6267 property + " value: " + value); 6268 SystemProperties.set(property, value); 6269 } 6270 6271 /** 6272 * Convenience function for retrieving a value from the secure settings 6273 * value list as an integer. Note that internally setting values are 6274 * always stored as strings; this function converts the string to an 6275 * integer for you. 6276 * <p> 6277 * This version does not take a default value. If the setting has not 6278 * been set, or the string value is not a number, 6279 * it throws {@link SettingNotFoundException}. 6280 * 6281 * @param cr The ContentResolver to access. 6282 * @param name The name of the setting to retrieve. 6283 * @param index The index of the list 6284 * 6285 * @throws SettingNotFoundException Thrown if a setting by the given 6286 * name can't be found or the setting value is not an integer. 6287 * 6288 * @return The value at the given index of settings. 6289 * @hide 6290 */ 6291 @UnsupportedAppUsage getIntAtIndex(android.content.ContentResolver cr, String name, int index)6292 public static int getIntAtIndex(android.content.ContentResolver cr, 6293 String name, int index) 6294 throws android.provider.Settings.SettingNotFoundException { 6295 String v = android.provider.Settings.Global.getString(cr, name); 6296 if (v != null) { 6297 String valArray[] = v.split(","); 6298 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 6299 try { 6300 return Integer.parseInt(valArray[index]); 6301 } catch (NumberFormatException e) { 6302 //Log.e(TAG, "Exception while parsing Integer: ", e); 6303 } 6304 } 6305 } 6306 throw new android.provider.Settings.SettingNotFoundException(name); 6307 } 6308 6309 /** 6310 * Convenience function for updating settings value as coma separated 6311 * integer values. This will either create a new entry in the table if the 6312 * given name does not exist, or modify the value of the existing row 6313 * with that name. Note that internally setting values are always 6314 * stored as strings, so this function converts the given value to a 6315 * string before storing it. 6316 * 6317 * @param cr The ContentResolver to access. 6318 * @param name The name of the setting to modify. 6319 * @param index The index of the list 6320 * @param value The new value for the setting to be added to the list. 6321 * @return true if the value was set, false on database errors 6322 * @hide 6323 */ 6324 @UnsupportedAppUsage putIntAtIndex(android.content.ContentResolver cr, String name, int index, int value)6325 public static boolean putIntAtIndex(android.content.ContentResolver cr, 6326 String name, int index, int value) { 6327 String data = ""; 6328 String valArray[] = null; 6329 String v = android.provider.Settings.Global.getString(cr, name); 6330 6331 if (index == Integer.MAX_VALUE) { 6332 throw new IllegalArgumentException("putIntAtIndex index == MAX_VALUE index=" + index); 6333 } 6334 if (index < 0) { 6335 throw new IllegalArgumentException("putIntAtIndex index < 0 index=" + index); 6336 } 6337 if (v != null) { 6338 valArray = v.split(","); 6339 } 6340 6341 // Copy the elements from valArray till index 6342 for (int i = 0; i < index; i++) { 6343 String str = ""; 6344 if ((valArray != null) && (i < valArray.length)) { 6345 str = valArray[i]; 6346 } 6347 data = data + str + ","; 6348 } 6349 6350 data = data + value; 6351 6352 // Copy the remaining elements from valArray if any. 6353 if (valArray != null) { 6354 for (int i = index+1; i < valArray.length; i++) { 6355 data = data + "," + valArray[i]; 6356 } 6357 } 6358 return android.provider.Settings.Global.putString(cr, name, data); 6359 } 6360 6361 /** 6362 * Gets a per-phone telephony property. 6363 * 6364 * @hide 6365 */ 6366 @UnsupportedAppUsage getTelephonyProperty(int phoneId, String property, String defaultVal)6367 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 6368 String propVal = null; 6369 String prop = SystemProperties.get(property); 6370 if ((prop != null) && (prop.length() > 0)) { 6371 String values[] = prop.split(","); 6372 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 6373 propVal = values[phoneId]; 6374 } 6375 } 6376 return propVal == null ? defaultVal : propVal; 6377 } 6378 6379 /** 6380 * Gets a global telephony property. 6381 * 6382 * See also getTelephonyProperty(phoneId, property, defaultVal). Most telephony properties are 6383 * per-phone. 6384 * 6385 * @hide 6386 */ 6387 @UnsupportedAppUsage getTelephonyProperty(String property, String defaultVal)6388 public static String getTelephonyProperty(String property, String defaultVal) { 6389 String propVal = SystemProperties.get(property); 6390 return TextUtils.isEmpty(propVal) ? defaultVal : propVal; 6391 } 6392 6393 /** @hide */ 6394 @UnsupportedAppUsage getSimCount()6395 public int getSimCount() { 6396 // FIXME Need to get it from Telephony Dev Controller when that gets implemented! 6397 // and then this method shouldn't be used at all! 6398 if(isMultiSimEnabled()) { 6399 return getPhoneCount(); 6400 } else { 6401 return 1; 6402 } 6403 } 6404 6405 /** 6406 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 6407 * 6408 * See 3GPP TS 31.103 (Section 4.2.7) for the definition and more information on this table. 6409 * 6410 * @return IMS Service Table or null if not present or not loaded 6411 * @hide 6412 */ 6413 @Nullable 6414 @SystemApi 6415 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getIsimIst()6416 public String getIsimIst() { 6417 try { 6418 IPhoneSubInfo info = getSubscriberInfo(); 6419 if (info == null) 6420 return null; 6421 //get the Isim Ist based on subId 6422 return info.getIsimIst(getSubId()); 6423 } catch (RemoteException ex) { 6424 return null; 6425 } catch (NullPointerException ex) { 6426 // This could happen before phone restarts due to crashing 6427 return null; 6428 } 6429 } 6430 6431 /** 6432 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 6433 * @return an array of PCSCF strings with one PCSCF per string, or null if 6434 * not present or not loaded 6435 * @hide 6436 */ 6437 @UnsupportedAppUsage getIsimPcscf()6438 public String[] getIsimPcscf() { 6439 try { 6440 IPhoneSubInfo info = getSubscriberInfo(); 6441 if (info == null) 6442 return null; 6443 //get the Isim Pcscf based on subId 6444 return info.getIsimPcscf(getSubId()); 6445 } catch (RemoteException ex) { 6446 return null; 6447 } catch (NullPointerException ex) { 6448 // This could happen before phone restarts due to crashing 6449 return null; 6450 } 6451 } 6452 6453 /** 6454 * UICC SIM Application Types 6455 * @hide 6456 */ 6457 @IntDef(prefix = { "APPTYPE_" }, value = { 6458 APPTYPE_SIM, 6459 APPTYPE_USIM, 6460 APPTYPE_RUIM, 6461 APPTYPE_CSIM, 6462 APPTYPE_ISIM 6463 }) 6464 @Retention(RetentionPolicy.SOURCE) 6465 public @interface UiccAppType{} 6466 /** UICC application type is SIM */ 6467 public static final int APPTYPE_SIM = PhoneConstants.APPTYPE_SIM; 6468 /** UICC application type is USIM */ 6469 public static final int APPTYPE_USIM = PhoneConstants.APPTYPE_USIM; 6470 /** UICC application type is RUIM */ 6471 public static final int APPTYPE_RUIM = PhoneConstants.APPTYPE_RUIM; 6472 /** UICC application type is CSIM */ 6473 public static final int APPTYPE_CSIM = PhoneConstants.APPTYPE_CSIM; 6474 /** UICC application type is ISIM */ 6475 public static final int APPTYPE_ISIM = PhoneConstants.APPTYPE_ISIM; 6476 6477 // authContext (parameter P2) when doing UICC challenge, 6478 // per 3GPP TS 31.102 (Section 7.1.2) 6479 /** Authentication type for UICC challenge is EAP SIM. See RFC 4186 for details. */ 6480 public static final int AUTHTYPE_EAP_SIM = PhoneConstants.AUTH_CONTEXT_EAP_SIM; 6481 /** Authentication type for UICC challenge is EAP AKA. See RFC 4187 for details. */ 6482 public static final int AUTHTYPE_EAP_AKA = PhoneConstants.AUTH_CONTEXT_EAP_AKA; 6483 6484 /** 6485 * Returns the response of authentication for the default subscription. 6486 * Returns null if the authentication hasn't been successful 6487 * 6488 * <p>Requires Permission: READ_PRIVILEGED_PHONE_STATE or that the calling 6489 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6490 * 6491 * @param appType the icc application type, like {@link #APPTYPE_USIM} 6492 * @param authType the authentication type, {@link #AUTHTYPE_EAP_AKA} or 6493 * {@link #AUTHTYPE_EAP_SIM} 6494 * @param data authentication challenge data, base64 encoded. 6495 * See 3GPP TS 31.102 7.1.2 for more details. 6496 * @return the response of authentication. This value will be null in the following cases: 6497 * Authentication error, incorrect MAC 6498 * Authentication error, security context not supported 6499 * Key freshness failure 6500 * Authentication error, no memory space available 6501 * Authentication error, no memory space available in EFMUK 6502 */ 6503 // TODO(b/73660190): This should probably require MODIFY_PHONE_STATE, not 6504 // READ_PRIVILEGED_PHONE_STATE. It certainly shouldn't reference the permission in Javadoc since 6505 // it's not public API. getIccAuthentication(int appType, int authType, String data)6506 public String getIccAuthentication(int appType, int authType, String data) { 6507 return getIccAuthentication(getSubId(), appType, authType, data); 6508 } 6509 6510 /** 6511 * Returns the response of USIM Authentication for specified subId. 6512 * Returns null if the authentication hasn't been successful 6513 * 6514 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 6515 * 6516 * @param subId subscription ID used for authentication 6517 * @param appType the icc application type, like {@link #APPTYPE_USIM} 6518 * @param authType the authentication type, {@link #AUTHTYPE_EAP_AKA} or 6519 * {@link #AUTHTYPE_EAP_SIM} 6520 * @param data authentication challenge data, base64 encoded. 6521 * See 3GPP TS 31.102 7.1.2 for more details. 6522 * @return the response of authentication. This value will be null in the following cases only 6523 * (see 3GPP TS 31.102 7.3.1): 6524 * Authentication error, incorrect MAC 6525 * Authentication error, security context not supported 6526 * Key freshness failure 6527 * Authentication error, no memory space available 6528 * Authentication error, no memory space available in EFMUK 6529 * @hide 6530 */ 6531 @UnsupportedAppUsage getIccAuthentication(int subId, int appType, int authType, String data)6532 public String getIccAuthentication(int subId, int appType, int authType, String data) { 6533 try { 6534 IPhoneSubInfo info = getSubscriberInfo(); 6535 if (info == null) 6536 return null; 6537 return info.getIccSimChallengeResponse(subId, appType, authType, data); 6538 } catch (RemoteException ex) { 6539 return null; 6540 } catch (NullPointerException ex) { 6541 // This could happen before phone starts 6542 return null; 6543 } 6544 } 6545 6546 /** 6547 * Returns an array of Forbidden PLMNs from the USIM App 6548 * Returns null if the query fails. 6549 * 6550 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 6551 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 6552 * 6553 * @return an array of forbidden PLMNs or null if not available 6554 */ 6555 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 6556 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getForbiddenPlmns()6557 public String[] getForbiddenPlmns() { 6558 return getForbiddenPlmns(getSubId(), APPTYPE_USIM); 6559 } 6560 6561 /** 6562 * Returns an array of Forbidden PLMNs from the specified SIM App 6563 * Returns null if the query fails. 6564 * 6565 * @param subId subscription ID used for authentication 6566 * @param appType the icc application type, like {@link #APPTYPE_USIM} 6567 * @return fplmns an array of forbidden PLMNs 6568 * @hide 6569 */ 6570 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getForbiddenPlmns(int subId, int appType)6571 public String[] getForbiddenPlmns(int subId, int appType) { 6572 try { 6573 ITelephony telephony = getITelephony(); 6574 if (telephony == null) 6575 return null; 6576 return telephony.getForbiddenPlmns(subId, appType, mContext.getOpPackageName()); 6577 } catch (RemoteException ex) { 6578 return null; 6579 } catch (NullPointerException ex) { 6580 // This could happen before phone starts 6581 return null; 6582 } 6583 } 6584 6585 /** 6586 * Get P-CSCF address from PCO after data connection is established or modified. 6587 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 6588 * @return array of P-CSCF address 6589 * @hide 6590 */ getPcscfAddress(String apnType)6591 public String[] getPcscfAddress(String apnType) { 6592 try { 6593 ITelephony telephony = getITelephony(); 6594 if (telephony == null) 6595 return new String[0]; 6596 return telephony.getPcscfAddress(apnType, getOpPackageName()); 6597 } catch (RemoteException e) { 6598 return new String[0]; 6599 } 6600 } 6601 6602 /** 6603 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability 6604 * status updates, if not already enabled. 6605 * @hide 6606 */ enableIms(int slotId)6607 public void enableIms(int slotId) { 6608 try { 6609 ITelephony telephony = getITelephony(); 6610 if (telephony != null) { 6611 telephony.enableIms(slotId); 6612 } 6613 } catch (RemoteException e) { 6614 Rlog.e(TAG, "enableIms, RemoteException: " 6615 + e.getMessage()); 6616 } 6617 } 6618 6619 /** 6620 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature 6621 * status updates to disabled. 6622 * @hide 6623 */ disableIms(int slotId)6624 public void disableIms(int slotId) { 6625 try { 6626 ITelephony telephony = getITelephony(); 6627 if (telephony != null) { 6628 telephony.disableIms(slotId); 6629 } 6630 } catch (RemoteException e) { 6631 Rlog.e(TAG, "disableIms, RemoteException: " 6632 + e.getMessage()); 6633 } 6634 } 6635 6636 /** 6637 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id and MMTel 6638 * feature or {@link null} if the service is not available. If an MMTelFeature is available, the 6639 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. 6640 * @param slotIndex The SIM slot that we are requesting the {@link IImsMmTelFeature} for. 6641 * @param callback Listener that will send updates to ImsManager when there are updates to 6642 * ImsServiceController. 6643 * @return {@link IImsMmTelFeature} interface for the feature specified or {@code null} if 6644 * it is unavailable. 6645 * @hide 6646 */ getImsMmTelFeatureAndListen(int slotIndex, IImsServiceFeatureCallback callback)6647 public @Nullable IImsMmTelFeature getImsMmTelFeatureAndListen(int slotIndex, 6648 IImsServiceFeatureCallback callback) { 6649 try { 6650 ITelephony telephony = getITelephony(); 6651 if (telephony != null) { 6652 return telephony.getMmTelFeatureAndListen(slotIndex, callback); 6653 } 6654 } catch (RemoteException e) { 6655 Rlog.e(TAG, "getImsMmTelFeatureAndListen, RemoteException: " 6656 + e.getMessage()); 6657 } 6658 return null; 6659 } 6660 6661 /** 6662 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id and RCS 6663 * feature for emergency calling or {@link null} if the service is not available. If an 6664 * RcsFeature is available, the {@link IImsServiceFeatureCallback} callback is registered as a 6665 * listener for feature updates. 6666 * @param slotIndex The SIM slot that we are requesting the {@link IImsRcsFeature} for. 6667 * @param callback Listener that will send updates to ImsManager when there are updates to 6668 * ImsServiceController. 6669 * @return {@link IImsRcsFeature} interface for the feature specified or {@code null} if 6670 * it is unavailable. 6671 * @hide 6672 */ getImsRcsFeatureAndListen(int slotIndex, IImsServiceFeatureCallback callback)6673 public @Nullable IImsRcsFeature getImsRcsFeatureAndListen(int slotIndex, 6674 IImsServiceFeatureCallback callback) { 6675 try { 6676 ITelephony telephony = getITelephony(); 6677 if (telephony != null) { 6678 return telephony.getRcsFeatureAndListen(slotIndex, callback); 6679 } 6680 } catch (RemoteException e) { 6681 Rlog.e(TAG, "getImsRcsFeatureAndListen, RemoteException: " 6682 + e.getMessage()); 6683 } 6684 return null; 6685 } 6686 6687 /** 6688 * @return the {@IImsRegistration} interface that corresponds with the slot index and feature. 6689 * @param slotIndex The SIM slot corresponding to the ImsService ImsRegistration is active for. 6690 * @param feature An integer indicating the feature that we wish to get the ImsRegistration for. 6691 * Corresponds to features defined in ImsFeature. 6692 * @hide 6693 */ 6694 @UnsupportedAppUsage getImsRegistration(int slotIndex, int feature)6695 public @Nullable IImsRegistration getImsRegistration(int slotIndex, int feature) { 6696 try { 6697 ITelephony telephony = getITelephony(); 6698 if (telephony != null) { 6699 return telephony.getImsRegistration(slotIndex, feature); 6700 } 6701 } catch (RemoteException e) { 6702 Rlog.e(TAG, "getImsRegistration, RemoteException: " + e.getMessage()); 6703 } 6704 return null; 6705 } 6706 6707 /** 6708 * @return the {@IImsConfig} interface that corresponds with the slot index and feature. 6709 * @param slotIndex The SIM slot corresponding to the ImsService ImsConfig is active for. 6710 * @param feature An integer indicating the feature that we wish to get the ImsConfig for. 6711 * Corresponds to features defined in ImsFeature. 6712 * @hide 6713 */ 6714 @UnsupportedAppUsage getImsConfig(int slotIndex, int feature)6715 public @Nullable IImsConfig getImsConfig(int slotIndex, int feature) { 6716 try { 6717 ITelephony telephony = getITelephony(); 6718 if (telephony != null) { 6719 return telephony.getImsConfig(slotIndex, feature); 6720 } 6721 } catch (RemoteException e) { 6722 Rlog.e(TAG, "getImsRegistration, RemoteException: " + e.getMessage()); 6723 } 6724 return null; 6725 } 6726 6727 /** 6728 * Set IMS registration state 6729 * 6730 * @param Registration state 6731 * @hide 6732 */ 6733 @UnsupportedAppUsage setImsRegistrationState(boolean registered)6734 public void setImsRegistrationState(boolean registered) { 6735 try { 6736 ITelephony telephony = getITelephony(); 6737 if (telephony != null) 6738 telephony.setImsRegistrationState(registered); 6739 } catch (RemoteException e) { 6740 } 6741 } 6742 6743 /** @hide */ 6744 @IntDef(prefix = { "NETWORK_MODE_" }, value = { 6745 NETWORK_MODE_WCDMA_PREF, 6746 NETWORK_MODE_GSM_ONLY, 6747 NETWORK_MODE_WCDMA_ONLY, 6748 NETWORK_MODE_GSM_UMTS, 6749 NETWORK_MODE_CDMA_EVDO, 6750 NETWORK_MODE_CDMA_NO_EVDO, 6751 NETWORK_MODE_EVDO_NO_CDMA, 6752 NETWORK_MODE_GLOBAL, 6753 NETWORK_MODE_LTE_CDMA_EVDO, 6754 NETWORK_MODE_LTE_GSM_WCDMA, 6755 NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA, 6756 NETWORK_MODE_LTE_ONLY, 6757 NETWORK_MODE_LTE_WCDMA, 6758 NETWORK_MODE_TDSCDMA_ONLY, 6759 NETWORK_MODE_TDSCDMA_WCDMA, 6760 NETWORK_MODE_LTE_TDSCDMA, 6761 NETWORK_MODE_TDSCDMA_GSM, 6762 NETWORK_MODE_LTE_TDSCDMA_GSM, 6763 NETWORK_MODE_TDSCDMA_GSM_WCDMA, 6764 NETWORK_MODE_LTE_TDSCDMA_WCDMA, 6765 NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA, 6766 NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA, 6767 NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA, 6768 NETWORK_MODE_NR_ONLY, 6769 NETWORK_MODE_NR_LTE, 6770 NETWORK_MODE_NR_LTE_CDMA_EVDO, 6771 NETWORK_MODE_NR_LTE_GSM_WCDMA, 6772 NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA, 6773 NETWORK_MODE_NR_LTE_WCDMA, 6774 NETWORK_MODE_NR_LTE_TDSCDMA, 6775 NETWORK_MODE_NR_LTE_TDSCDMA_GSM, 6776 NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA, 6777 NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA, 6778 NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA 6779 }) 6780 @Retention(RetentionPolicy.SOURCE) 6781 public @interface PrefNetworkMode{} 6782 6783 /** 6784 * Preferred network mode is GSM/WCDMA (WCDMA preferred). 6785 * @hide 6786 */ 6787 public static final int NETWORK_MODE_WCDMA_PREF = RILConstants.NETWORK_MODE_WCDMA_PREF; 6788 6789 /** 6790 * Preferred network mode is GSM only. 6791 * @hide 6792 */ 6793 public static final int NETWORK_MODE_GSM_ONLY = RILConstants.NETWORK_MODE_GSM_ONLY; 6794 6795 /** 6796 * Preferred network mode is WCDMA only. 6797 * @hide 6798 */ 6799 public static final int NETWORK_MODE_WCDMA_ONLY = RILConstants.NETWORK_MODE_WCDMA_ONLY; 6800 6801 /** 6802 * Preferred network mode is GSM/WCDMA (auto mode, according to PRL). 6803 * @hide 6804 */ 6805 public static final int NETWORK_MODE_GSM_UMTS = RILConstants.NETWORK_MODE_GSM_UMTS; 6806 6807 /** 6808 * Preferred network mode is CDMA and EvDo (auto mode, according to PRL). 6809 * @hide 6810 */ 6811 public static final int NETWORK_MODE_CDMA_EVDO = RILConstants.NETWORK_MODE_CDMA; 6812 6813 /** 6814 * Preferred network mode is CDMA only. 6815 * @hide 6816 */ 6817 public static final int NETWORK_MODE_CDMA_NO_EVDO = RILConstants.NETWORK_MODE_CDMA_NO_EVDO; 6818 6819 /** 6820 * Preferred network mode is EvDo only. 6821 * @hide 6822 */ 6823 public static final int NETWORK_MODE_EVDO_NO_CDMA = RILConstants.NETWORK_MODE_EVDO_NO_CDMA; 6824 6825 /** 6826 * Preferred network mode is GSM/WCDMA, CDMA, and EvDo (auto mode, according to PRL). 6827 * @hide 6828 */ 6829 public static final int NETWORK_MODE_GLOBAL = RILConstants.NETWORK_MODE_GLOBAL; 6830 6831 /** 6832 * Preferred network mode is LTE, CDMA and EvDo. 6833 * @hide 6834 */ 6835 public static final int NETWORK_MODE_LTE_CDMA_EVDO = RILConstants.NETWORK_MODE_LTE_CDMA_EVDO; 6836 6837 /** 6838 * Preferred network mode is LTE, GSM/WCDMA. 6839 * @hide 6840 */ 6841 public static final int NETWORK_MODE_LTE_GSM_WCDMA = RILConstants.NETWORK_MODE_LTE_GSM_WCDMA; 6842 6843 /** 6844 * Preferred network mode is LTE, CDMA, EvDo, GSM/WCDMA. 6845 * @hide 6846 */ 6847 public static final int NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA = 6848 RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA; 6849 6850 /** 6851 * Preferred network mode is LTE Only. 6852 * @hide 6853 */ 6854 public static final int NETWORK_MODE_LTE_ONLY = RILConstants.NETWORK_MODE_LTE_ONLY; 6855 6856 /** 6857 * Preferred network mode is LTE/WCDMA. 6858 * @hide 6859 */ 6860 public static final int NETWORK_MODE_LTE_WCDMA = RILConstants.NETWORK_MODE_LTE_WCDMA; 6861 6862 /** 6863 * Preferred network mode is TD-SCDMA only. 6864 * @hide 6865 */ 6866 public static final int NETWORK_MODE_TDSCDMA_ONLY = RILConstants.NETWORK_MODE_TDSCDMA_ONLY; 6867 6868 /** 6869 * Preferred network mode is TD-SCDMA and WCDMA. 6870 * @hide 6871 */ 6872 public static final int NETWORK_MODE_TDSCDMA_WCDMA = RILConstants.NETWORK_MODE_TDSCDMA_WCDMA; 6873 6874 /** 6875 * Preferred network mode is TD-SCDMA and LTE. 6876 * @hide 6877 */ 6878 public static final int NETWORK_MODE_LTE_TDSCDMA = RILConstants.NETWORK_MODE_LTE_TDSCDMA; 6879 6880 /** 6881 * Preferred network mode is TD-SCDMA and GSM. 6882 * @hide 6883 */ 6884 public static final int NETWORK_MODE_TDSCDMA_GSM = RILConstants.NETWORK_MODE_TDSCDMA_GSM; 6885 6886 /** 6887 * Preferred network mode is TD-SCDMA,GSM and LTE. 6888 * @hide 6889 */ 6890 public static final int NETWORK_MODE_LTE_TDSCDMA_GSM = 6891 RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM; 6892 6893 /** 6894 * Preferred network mode is TD-SCDMA, GSM/WCDMA. 6895 * @hide 6896 */ 6897 public static final int NETWORK_MODE_TDSCDMA_GSM_WCDMA = 6898 RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA; 6899 6900 /** 6901 * Preferred network mode is TD-SCDMA, WCDMA and LTE. 6902 * @hide 6903 */ 6904 public static final int NETWORK_MODE_LTE_TDSCDMA_WCDMA = 6905 RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA; 6906 6907 /** 6908 * Preferred network mode is TD-SCDMA, GSM/WCDMA and LTE. 6909 * @hide 6910 */ 6911 public static final int NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA = 6912 RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA; 6913 6914 /** 6915 * Preferred network mode is TD-SCDMA,EvDo,CDMA,GSM/WCDMA. 6916 * @hide 6917 */ 6918 public static final int NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 6919 RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA; 6920 /** 6921 * Preferred network mode is TD-SCDMA/LTE/GSM/WCDMA, CDMA, and EvDo. 6922 * @hide 6923 */ 6924 public static final int NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 6925 RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA; 6926 6927 /** 6928 * Preferred network mode is NR 5G only. 6929 * @hide 6930 */ 6931 public static final int NETWORK_MODE_NR_ONLY = RILConstants.NETWORK_MODE_NR_ONLY; 6932 6933 /** 6934 * Preferred network mode is NR 5G, LTE. 6935 * @hide 6936 */ 6937 public static final int NETWORK_MODE_NR_LTE = RILConstants.NETWORK_MODE_NR_LTE; 6938 6939 /** 6940 * Preferred network mode is NR 5G, LTE, CDMA and EvDo. 6941 * @hide 6942 */ 6943 public static final int NETWORK_MODE_NR_LTE_CDMA_EVDO = 6944 RILConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO; 6945 6946 /** 6947 * Preferred network mode is NR 5G, LTE, GSM and WCDMA. 6948 * @hide 6949 */ 6950 public static final int NETWORK_MODE_NR_LTE_GSM_WCDMA = 6951 RILConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA; 6952 6953 /** 6954 * Preferred network mode is NR 5G, LTE, CDMA, EvDo, GSM and WCDMA. 6955 * @hide 6956 */ 6957 public static final int NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA = 6958 RILConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA; 6959 6960 /** 6961 * Preferred network mode is NR 5G, LTE and WCDMA. 6962 * @hide 6963 */ 6964 public static final int NETWORK_MODE_NR_LTE_WCDMA = RILConstants.NETWORK_MODE_NR_LTE_WCDMA; 6965 6966 /** 6967 * Preferred network mode is NR 5G, LTE and TDSCDMA. 6968 * @hide 6969 */ 6970 public static final int NETWORK_MODE_NR_LTE_TDSCDMA = RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA; 6971 6972 /** 6973 * Preferred network mode is NR 5G, LTE, TD-SCDMA and GSM. 6974 * @hide 6975 */ 6976 public static final int NETWORK_MODE_NR_LTE_TDSCDMA_GSM = 6977 RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM; 6978 6979 /** 6980 * Preferred network mode is NR 5G, LTE, TD-SCDMA, WCDMA. 6981 * @hide 6982 */ 6983 public static final int NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA = 6984 RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA; 6985 6986 /** 6987 * Preferred network mode is NR 5G, LTE, TD-SCDMA, GSM and WCDMA. 6988 * @hide 6989 */ 6990 public static final int NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA = 6991 RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA; 6992 6993 /** 6994 * Preferred network mode is NR 5G, LTE, TD-SCDMA, CDMA, EVDO, GSM and WCDMA. 6995 * @hide 6996 */ 6997 public static final int NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 6998 RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA; 6999 7000 /** 7001 * Get the preferred network type. 7002 * Used for device configuration by some CDMA operators. 7003 * 7004 * <p>Requires Permission: 7005 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 7006 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7007 * 7008 * @return the preferred network type. 7009 * @hide 7010 */ 7011 @RequiresPermission((android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)) 7012 @UnsupportedAppUsage getPreferredNetworkType(int subId)7013 public @PrefNetworkMode int getPreferredNetworkType(int subId) { 7014 try { 7015 ITelephony telephony = getITelephony(); 7016 if (telephony != null) { 7017 return telephony.getPreferredNetworkType(subId); 7018 } 7019 } catch (RemoteException ex) { 7020 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 7021 } 7022 return -1; 7023 } 7024 7025 /** 7026 * Get the preferred network type bitmask. 7027 * 7028 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 7029 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 7030 * 7031 * <p>Requires Permission: 7032 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 7033 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 7034 * 7035 * @return The bitmask of preferred network types. 7036 * 7037 * @hide 7038 */ 7039 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 7040 @SystemApi getPreferredNetworkTypeBitmask()7041 public @NetworkTypeBitMask long getPreferredNetworkTypeBitmask() { 7042 try { 7043 ITelephony telephony = getITelephony(); 7044 if (telephony != null) { 7045 return (long) RadioAccessFamily.getRafFromNetworkType( 7046 telephony.getPreferredNetworkType(getSubId())); 7047 } 7048 } catch (RemoteException ex) { 7049 Rlog.e(TAG, "getPreferredNetworkTypeBitmask RemoteException", ex); 7050 } 7051 return 0; 7052 } 7053 7054 /** 7055 * Sets the network selection mode to automatic. 7056 * 7057 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 7058 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 7059 * 7060 * <p>Requires Permission: 7061 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7062 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7063 */ 7064 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 7065 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setNetworkSelectionModeAutomatic()7066 public void setNetworkSelectionModeAutomatic() { 7067 try { 7068 ITelephony telephony = getITelephony(); 7069 if (telephony != null) { 7070 telephony.setNetworkSelectionModeAutomatic(getSubId()); 7071 } 7072 } catch (RemoteException ex) { 7073 Rlog.e(TAG, "setNetworkSelectionModeAutomatic RemoteException", ex); 7074 } catch (NullPointerException ex) { 7075 Rlog.e(TAG, "setNetworkSelectionModeAutomatic NPE", ex); 7076 } 7077 } 7078 7079 /** 7080 * Perform a radio scan and return the list of available networks. 7081 * 7082 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 7083 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 7084 * 7085 * <p> Note that this scan can take a long time (sometimes minutes) to happen. 7086 * 7087 * <p>Requires Permissions: 7088 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier 7089 * privileges (see {@link #hasCarrierPrivileges}) 7090 * and {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 7091 * 7092 * @return {@link CellNetworkScanResult} with the status 7093 * {@link CellNetworkScanResult#STATUS_SUCCESS} and a list of 7094 * {@link com.android.internal.telephony.OperatorInfo} if it's available. Otherwise, the failure 7095 * caused will be included in the result. 7096 * 7097 * @hide 7098 */ 7099 @RequiresPermission(allOf = { 7100 android.Manifest.permission.MODIFY_PHONE_STATE, 7101 Manifest.permission.ACCESS_COARSE_LOCATION 7102 }) getAvailableNetworks()7103 public CellNetworkScanResult getAvailableNetworks() { 7104 try { 7105 ITelephony telephony = getITelephony(); 7106 if (telephony != null) { 7107 return telephony.getCellNetworkScanResults(getSubId(), getOpPackageName()); 7108 } 7109 } catch (RemoteException ex) { 7110 Rlog.e(TAG, "getAvailableNetworks RemoteException", ex); 7111 } catch (NullPointerException ex) { 7112 Rlog.e(TAG, "getAvailableNetworks NPE", ex); 7113 } 7114 return new CellNetworkScanResult( 7115 CellNetworkScanResult.STATUS_UNKNOWN_ERROR, null /* OperatorInfo */); 7116 } 7117 7118 /** 7119 * Request a network scan. 7120 * 7121 * This method is asynchronous, so the network scan results will be returned by callback. 7122 * The returned NetworkScan will contain a callback method which can be used to stop the scan. 7123 * 7124 * <p>Requires Permission: 7125 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7126 * app has carrier privileges (see {@link #hasCarrierPrivileges}) 7127 * and {@link android.Manifest.permission#ACCESS_FINE_LOCATION}. 7128 * 7129 * If the system-wide location switch is off, apps may still call this API, with the 7130 * following constraints: 7131 * <ol> 7132 * <li>The app must hold the {@code android.permission.NETWORK_SCAN} permission.</li> 7133 * <li>The app must not supply any specific bands or channels to scan.</li> 7134 * <li>The app must only specify MCC/MNC pairs that are 7135 * associated to a SIM in the device.</li> 7136 * <li>Returned results will have no meaningful info other than signal strength 7137 * and MCC/MNC info.</li> 7138 * </ol> 7139 * 7140 * @param request Contains all the RAT with bands/channels that need to be scanned. 7141 * @param executor The executor through which the callback should be invoked. Since the scan 7142 * request may trigger multiple callbacks and they must be invoked in the same order as 7143 * they are received by the platform, the user should provide an executor which executes 7144 * tasks one at a time in serial order. For example AsyncTask.SERIAL_EXECUTOR. 7145 * @param callback Returns network scan results or errors. 7146 * @return A NetworkScan obj which contains a callback which can be used to stop the scan. 7147 */ 7148 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 7149 @RequiresPermission(allOf = { 7150 android.Manifest.permission.MODIFY_PHONE_STATE, 7151 Manifest.permission.ACCESS_FINE_LOCATION 7152 }) requestNetworkScan( NetworkScanRequest request, Executor executor, TelephonyScanManager.NetworkScanCallback callback)7153 public NetworkScan requestNetworkScan( 7154 NetworkScanRequest request, Executor executor, 7155 TelephonyScanManager.NetworkScanCallback callback) { 7156 synchronized (this) { 7157 if (mTelephonyScanManager == null) { 7158 mTelephonyScanManager = new TelephonyScanManager(); 7159 } 7160 } 7161 return mTelephonyScanManager.requestNetworkScan(getSubId(), request, executor, callback, 7162 getOpPackageName()); 7163 } 7164 7165 /** 7166 * @deprecated 7167 * Use {@link 7168 * #requestNetworkScan(NetworkScanRequest, Executor, TelephonyScanManager.NetworkScanCallback)} 7169 * @removed 7170 */ 7171 @Deprecated 7172 @RequiresPermission(allOf = { 7173 android.Manifest.permission.MODIFY_PHONE_STATE, 7174 Manifest.permission.ACCESS_FINE_LOCATION 7175 }) requestNetworkScan( NetworkScanRequest request, TelephonyScanManager.NetworkScanCallback callback)7176 public NetworkScan requestNetworkScan( 7177 NetworkScanRequest request, TelephonyScanManager.NetworkScanCallback callback) { 7178 return requestNetworkScan(request, AsyncTask.SERIAL_EXECUTOR, callback); 7179 } 7180 7181 /** 7182 * Ask the radio to connect to the input network and change selection mode to manual. 7183 * 7184 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 7185 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 7186 * 7187 * <p>Requires Permission: 7188 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7189 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7190 * 7191 * @param operatorNumeric the PLMN ID of the network to select. 7192 * @param persistSelection whether the selection will persist until reboot. If true, only allows 7193 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume 7194 * normal network selection next time. 7195 * @return {@code true} on success; {@code false} on any failure. 7196 */ 7197 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 7198 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setNetworkSelectionModeManual(String operatorNumeric, boolean persistSelection)7199 public boolean setNetworkSelectionModeManual(String operatorNumeric, boolean persistSelection) { 7200 return setNetworkSelectionModeManual( 7201 new OperatorInfo( 7202 "" /* operatorAlphaLong */, "" /* operatorAlphaShort */, operatorNumeric), 7203 persistSelection); 7204 } 7205 7206 /** 7207 * Ask the radio to connect to the input network and change selection mode to manual. 7208 * 7209 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 7210 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 7211 * 7212 * <p>Requires Permission: 7213 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7214 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7215 * 7216 * @param operatorInfo included the PLMN id, long name, short name of the operator to attach to. 7217 * @param persistSelection whether the selection will persist until reboot. If true, only allows 7218 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume 7219 * normal network selection next time. 7220 * @return {@code true} on success; {@code true} on any failure. 7221 * 7222 * @hide 7223 */ 7224 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setNetworkSelectionModeManual( OperatorInfo operatorInfo, boolean persistSelection)7225 public boolean setNetworkSelectionModeManual( 7226 OperatorInfo operatorInfo, boolean persistSelection) { 7227 try { 7228 ITelephony telephony = getITelephony(); 7229 if (telephony != null) { 7230 return telephony.setNetworkSelectionModeManual( 7231 getSubId(), operatorInfo, persistSelection); 7232 } 7233 } catch (RemoteException ex) { 7234 Rlog.e(TAG, "setNetworkSelectionModeManual RemoteException", ex); 7235 } 7236 return false; 7237 } 7238 7239 /** 7240 * Get the network selection mode. 7241 * 7242 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 7243 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 7244 7245 * @return the network selection mode. 7246 * 7247 * @hide 7248 */ 7249 @NetworkSelectionMode 7250 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getNetworkSelectionMode()7251 public int getNetworkSelectionMode() { 7252 int mode = NETWORK_SELECTION_MODE_UNKNOWN; 7253 try { 7254 ITelephony telephony = getITelephony(); 7255 if (telephony != null) { 7256 mode = telephony.getNetworkSelectionMode(getSubId()); 7257 } 7258 } catch (RemoteException ex) { 7259 Rlog.e(TAG, "getNetworkSelectionMode RemoteException", ex); 7260 } 7261 return mode; 7262 } 7263 7264 /** 7265 * Query Telephony to see if there has recently been an emergency SMS sent to the network by the 7266 * user and we are still within the time interval after the emergency SMS was sent that we are 7267 * considered in Emergency SMS mode. 7268 * 7269 * <p>This mode is used by other applications to allow them to perform special functionality, 7270 * such as allow the GNSS service to provide user location to the carrier network for emergency 7271 * when an emergency SMS is sent. This interval is set by 7272 * {@link CarrierConfigManager#KEY_EMERGENCY_SMS_MODE_TIMER_MS_INT}. If 7273 * the carrier does not support this mode, this function will always return false. 7274 * 7275 * @return true if this device is in emergency SMS mode, false otherwise. 7276 * 7277 * @hide 7278 */ 7279 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) isInEmergencySmsMode()7280 public boolean isInEmergencySmsMode() { 7281 7282 try { 7283 ITelephony telephony = getITelephony(); 7284 if (telephony != null) { 7285 return telephony.isInEmergencySmsMode(); 7286 } 7287 } catch (RemoteException ex) { 7288 Rlog.e(TAG, "getNetworkSelectionMode RemoteException", ex); 7289 } 7290 return false; 7291 } 7292 7293 /** 7294 * Set the preferred network type. 7295 * 7296 * <p>Requires Permission: 7297 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7298 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7299 * 7300 * @param subId the id of the subscription to set the preferred network type for. 7301 * @param networkType the preferred network type 7302 * @return true on success; false on any failure. 7303 * @hide 7304 */ 7305 @UnsupportedAppUsage setPreferredNetworkType(int subId, @PrefNetworkMode int networkType)7306 public boolean setPreferredNetworkType(int subId, @PrefNetworkMode int networkType) { 7307 try { 7308 ITelephony telephony = getITelephony(); 7309 if (telephony != null) { 7310 return telephony.setPreferredNetworkType(subId, networkType); 7311 } 7312 } catch (RemoteException ex) { 7313 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 7314 } 7315 return false; 7316 } 7317 7318 /** 7319 * Set the preferred network type bitmask. 7320 * 7321 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 7322 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 7323 * 7324 * <p>Requires Permission: 7325 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7326 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7327 * 7328 * @param networkTypeBitmask The bitmask of preferred network types. 7329 * @return true on success; false on any failure. 7330 * @hide 7331 */ 7332 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 7333 @SystemApi setPreferredNetworkTypeBitmask(@etworkTypeBitMask long networkTypeBitmask)7334 public boolean setPreferredNetworkTypeBitmask(@NetworkTypeBitMask long networkTypeBitmask) { 7335 try { 7336 ITelephony telephony = getITelephony(); 7337 if (telephony != null) { 7338 return telephony.setPreferredNetworkType( 7339 getSubId(), RadioAccessFamily.getNetworkTypeFromRaf( 7340 (int) networkTypeBitmask)); 7341 } 7342 } catch (RemoteException ex) { 7343 Rlog.e(TAG, "setPreferredNetworkTypeBitmask RemoteException", ex); 7344 } 7345 return false; 7346 } 7347 7348 /** 7349 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 7350 * 7351 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 7352 * 7353 * @return true on success; false on any failure. 7354 */ setPreferredNetworkTypeToGlobal()7355 public boolean setPreferredNetworkTypeToGlobal() { 7356 return setPreferredNetworkTypeToGlobal(getSubId()); 7357 } 7358 7359 /** 7360 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 7361 * 7362 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 7363 * 7364 * @return true on success; false on any failure. 7365 * @hide 7366 */ setPreferredNetworkTypeToGlobal(int subId)7367 public boolean setPreferredNetworkTypeToGlobal(int subId) { 7368 return setPreferredNetworkType(subId, RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); 7369 } 7370 7371 /** 7372 * Check whether DUN APN is required for tethering. 7373 * 7374 * @return {@code true} if DUN APN is required for tethering. 7375 * @hide 7376 */ getTetherApnRequired()7377 public boolean getTetherApnRequired() { 7378 return getTetherApnRequired(getSubId(SubscriptionManager.getDefaultDataSubscriptionId())); 7379 } 7380 7381 /** 7382 * Check whether DUN APN is required for tethering with subId. 7383 * 7384 * @param subId the id of the subscription to require tethering. 7385 * @return {@code true} if DUN APN is required for tethering. 7386 * @hide 7387 */ getTetherApnRequired(int subId)7388 public boolean getTetherApnRequired(int subId) { 7389 try { 7390 ITelephony telephony = getITelephony(); 7391 if (telephony != null) 7392 return telephony.getTetherApnRequiredForSubscriber(subId); 7393 } catch (RemoteException ex) { 7394 Rlog.e(TAG, "hasMatchedTetherApnSetting RemoteException", ex); 7395 } catch (NullPointerException ex) { 7396 Rlog.e(TAG, "hasMatchedTetherApnSetting NPE", ex); 7397 } 7398 return false; 7399 } 7400 7401 7402 /** 7403 * Values used to return status for hasCarrierPrivileges call. 7404 */ 7405 /** @hide */ @SystemApi @TestApi 7406 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 7407 /** @hide */ @SystemApi @TestApi 7408 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 7409 /** @hide */ @SystemApi @TestApi 7410 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 7411 /** @hide */ @SystemApi @TestApi 7412 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 7413 7414 /** 7415 * Has the calling application been granted carrier privileges by the carrier. 7416 * 7417 * If any of the packages in the calling UID has carrier privileges, the 7418 * call will return true. This access is granted by the owner of the UICC 7419 * card and does not depend on the registered carrier. 7420 * 7421 * @return true if the app has carrier privileges. 7422 */ hasCarrierPrivileges()7423 public boolean hasCarrierPrivileges() { 7424 return hasCarrierPrivileges(getSubId()); 7425 } 7426 7427 /** 7428 * Has the calling application been granted carrier privileges by the carrier. 7429 * 7430 * If any of the packages in the calling UID has carrier privileges, the 7431 * call will return true. This access is granted by the owner of the UICC 7432 * card and does not depend on the registered carrier. 7433 * 7434 * @param subId The subscription to use. 7435 * @return true if the app has carrier privileges. 7436 * @hide 7437 */ hasCarrierPrivileges(int subId)7438 public boolean hasCarrierPrivileges(int subId) { 7439 try { 7440 ITelephony telephony = getITelephony(); 7441 if (telephony != null) { 7442 return telephony.getCarrierPrivilegeStatus(subId) 7443 == CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; 7444 } 7445 } catch (RemoteException ex) { 7446 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 7447 } catch (NullPointerException ex) { 7448 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 7449 } 7450 return false; 7451 } 7452 7453 /** 7454 * Override the branding for the current ICCID. 7455 * 7456 * Once set, whenever the SIM is present in the device, the service 7457 * provider name (SPN) and the operator name will both be replaced by the 7458 * brand value input. To unset the value, the same function should be 7459 * called with a null brand value. 7460 * 7461 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 7462 * 7463 * @param brand The brand name to display/set. 7464 * @return true if the operation was executed correctly. 7465 */ setOperatorBrandOverride(String brand)7466 public boolean setOperatorBrandOverride(String brand) { 7467 return setOperatorBrandOverride(getSubId(), brand); 7468 } 7469 7470 /** 7471 * Override the branding for the current ICCID. 7472 * 7473 * Once set, whenever the SIM is present in the device, the service 7474 * provider name (SPN) and the operator name will both be replaced by the 7475 * brand value input. To unset the value, the same function should be 7476 * called with a null brand value. 7477 * 7478 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 7479 * 7480 * @param subId The subscription to use. 7481 * @param brand The brand name to display/set. 7482 * @return true if the operation was executed correctly. 7483 * @hide 7484 */ setOperatorBrandOverride(int subId, String brand)7485 public boolean setOperatorBrandOverride(int subId, String brand) { 7486 try { 7487 ITelephony telephony = getITelephony(); 7488 if (telephony != null) 7489 return telephony.setOperatorBrandOverride(subId, brand); 7490 } catch (RemoteException ex) { 7491 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 7492 } catch (NullPointerException ex) { 7493 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 7494 } 7495 return false; 7496 } 7497 7498 /** 7499 * Override the roaming preference for the current ICCID. 7500 * 7501 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 7502 * the platform's notion of a network operator being considered roaming or not. 7503 * The change only affects the ICCID that was active when this call was made. 7504 * 7505 * If null is passed as any of the input, the corresponding value is deleted. 7506 * 7507 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 7508 * 7509 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 7510 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 7511 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 7512 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 7513 * @return true if the operation was executed correctly. 7514 * 7515 * @hide 7516 */ 7517 @UnsupportedAppUsage setRoamingOverride(List<String> gsmRoamingList, List<String> gsmNonRoamingList, List<String> cdmaRoamingList, List<String> cdmaNonRoamingList)7518 public boolean setRoamingOverride(List<String> gsmRoamingList, 7519 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 7520 List<String> cdmaNonRoamingList) { 7521 return setRoamingOverride(getSubId(), gsmRoamingList, gsmNonRoamingList, 7522 cdmaRoamingList, cdmaNonRoamingList); 7523 } 7524 7525 /** 7526 * Override the roaming preference for the current ICCID. 7527 * 7528 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 7529 * the platform's notion of a network operator being considered roaming or not. 7530 * The change only affects the ICCID that was active when this call was made. 7531 * 7532 * If null is passed as any of the input, the corresponding value is deleted. 7533 * 7534 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 7535 * 7536 * @param subId for which the roaming overrides apply. 7537 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 7538 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 7539 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 7540 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 7541 * @return true if the operation was executed correctly. 7542 * 7543 * @hide 7544 */ setRoamingOverride(int subId, List<String> gsmRoamingList, List<String> gsmNonRoamingList, List<String> cdmaRoamingList, List<String> cdmaNonRoamingList)7545 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, 7546 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 7547 List<String> cdmaNonRoamingList) { 7548 try { 7549 ITelephony telephony = getITelephony(); 7550 if (telephony != null) 7551 return telephony.setRoamingOverride(subId, gsmRoamingList, gsmNonRoamingList, 7552 cdmaRoamingList, cdmaNonRoamingList); 7553 } catch (RemoteException ex) { 7554 Rlog.e(TAG, "setRoamingOverride RemoteException", ex); 7555 } catch (NullPointerException ex) { 7556 Rlog.e(TAG, "setRoamingOverride NPE", ex); 7557 } 7558 return false; 7559 } 7560 7561 /** 7562 * Expose the rest of ITelephony to @SystemApi 7563 */ 7564 7565 /** @hide */ 7566 @SystemApi 7567 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getCdmaMdn()7568 public String getCdmaMdn() { 7569 return getCdmaMdn(getSubId()); 7570 } 7571 7572 /** @hide */ 7573 @SystemApi 7574 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getCdmaMdn(int subId)7575 public String getCdmaMdn(int subId) { 7576 try { 7577 ITelephony telephony = getITelephony(); 7578 if (telephony == null) 7579 return null; 7580 return telephony.getCdmaMdn(subId); 7581 } catch (RemoteException ex) { 7582 return null; 7583 } catch (NullPointerException ex) { 7584 return null; 7585 } 7586 } 7587 7588 /** @hide */ 7589 @SystemApi 7590 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getCdmaMin()7591 public String getCdmaMin() { 7592 return getCdmaMin(getSubId()); 7593 } 7594 7595 /** @hide */ 7596 @SystemApi 7597 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getCdmaMin(int subId)7598 public String getCdmaMin(int subId) { 7599 try { 7600 ITelephony telephony = getITelephony(); 7601 if (telephony == null) 7602 return null; 7603 return telephony.getCdmaMin(subId); 7604 } catch (RemoteException ex) { 7605 return null; 7606 } catch (NullPointerException ex) { 7607 return null; 7608 } 7609 } 7610 7611 /** @hide */ 7612 @SystemApi 7613 @TestApi 7614 @SuppressLint("Doclava125") checkCarrierPrivilegesForPackage(String pkgName)7615 public int checkCarrierPrivilegesForPackage(String pkgName) { 7616 try { 7617 ITelephony telephony = getITelephony(); 7618 if (telephony != null) 7619 return telephony.checkCarrierPrivilegesForPackage(getSubId(), pkgName); 7620 } catch (RemoteException ex) { 7621 Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex); 7622 } catch (NullPointerException ex) { 7623 Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex); 7624 } 7625 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 7626 } 7627 7628 /** @hide */ 7629 @SystemApi 7630 @SuppressLint("Doclava125") checkCarrierPrivilegesForPackageAnyPhone(String pkgName)7631 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { 7632 try { 7633 ITelephony telephony = getITelephony(); 7634 if (telephony != null) 7635 return telephony.checkCarrierPrivilegesForPackageAnyPhone(pkgName); 7636 } catch (RemoteException ex) { 7637 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone RemoteException", ex); 7638 } catch (NullPointerException ex) { 7639 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone NPE", ex); 7640 } 7641 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 7642 } 7643 7644 /** @hide */ 7645 @SystemApi getCarrierPackageNamesForIntent(Intent intent)7646 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 7647 return getCarrierPackageNamesForIntentAndPhone(intent, getPhoneId()); 7648 } 7649 7650 /** @hide */ 7651 @SystemApi getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId)7652 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { 7653 try { 7654 ITelephony telephony = getITelephony(); 7655 if (telephony != null) 7656 return telephony.getCarrierPackageNamesForIntentAndPhone(intent, phoneId); 7657 } catch (RemoteException ex) { 7658 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone RemoteException", ex); 7659 } catch (NullPointerException ex) { 7660 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone NPE", ex); 7661 } 7662 return null; 7663 } 7664 7665 /** @hide */ getPackagesWithCarrierPrivileges()7666 public List<String> getPackagesWithCarrierPrivileges() { 7667 try { 7668 ITelephony telephony = getITelephony(); 7669 if (telephony != null) { 7670 return telephony.getPackagesWithCarrierPrivileges(getPhoneId()); 7671 } 7672 } catch (RemoteException ex) { 7673 Rlog.e(TAG, "getPackagesWithCarrierPrivileges RemoteException", ex); 7674 } catch (NullPointerException ex) { 7675 Rlog.e(TAG, "getPackagesWithCarrierPrivileges NPE", ex); 7676 } 7677 return Collections.EMPTY_LIST; 7678 } 7679 7680 /** @hide */ getPackagesWithCarrierPrivilegesForAllPhones()7681 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { 7682 try { 7683 ITelephony telephony = getITelephony(); 7684 if (telephony != null) { 7685 return telephony.getPackagesWithCarrierPrivilegesForAllPhones(); 7686 } 7687 } catch (RemoteException ex) { 7688 Rlog.e(TAG, "getPackagesWithCarrierPrivilegesForAllPhones RemoteException", ex); 7689 } catch (NullPointerException ex) { 7690 Rlog.e(TAG, "getPackagesWithCarrierPrivilegesForAllPhones NPE", ex); 7691 } 7692 return Collections.EMPTY_LIST; 7693 } 7694 7695 7696 /** @hide */ 7697 @SystemApi 7698 @SuppressLint("Doclava125") dial(String number)7699 public void dial(String number) { 7700 try { 7701 ITelephony telephony = getITelephony(); 7702 if (telephony != null) 7703 telephony.dial(number); 7704 } catch (RemoteException e) { 7705 Log.e(TAG, "Error calling ITelephony#dial", e); 7706 } 7707 } 7708 7709 /** 7710 * @deprecated Use {@link android.telecom.TelecomManager#placeCall(Uri address, 7711 * Bundle extras)} instead. 7712 * @hide 7713 */ 7714 @Deprecated 7715 @SystemApi 7716 @RequiresPermission(android.Manifest.permission.CALL_PHONE) call(String callingPackage, String number)7717 public void call(String callingPackage, String number) { 7718 try { 7719 ITelephony telephony = getITelephony(); 7720 if (telephony != null) 7721 telephony.call(callingPackage, number); 7722 } catch (RemoteException e) { 7723 Log.e(TAG, "Error calling ITelephony#call", e); 7724 } 7725 } 7726 7727 /** 7728 * @removed Use {@link android.telecom.TelecomManager#endCall()} instead. 7729 * @hide 7730 * @removed 7731 */ 7732 @Deprecated 7733 @SystemApi 7734 @RequiresPermission(android.Manifest.permission.CALL_PHONE) endCall()7735 public boolean endCall() { 7736 return false; 7737 } 7738 7739 /** 7740 * @removed Use {@link android.telecom.TelecomManager#acceptRingingCall} instead 7741 * @hide 7742 * @removed 7743 */ 7744 @Deprecated 7745 @SystemApi 7746 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) answerRingingCall()7747 public void answerRingingCall() { 7748 // No-op 7749 } 7750 7751 /** 7752 * @removed Use {@link android.telecom.TelecomManager#silenceRinger} instead 7753 * @hide 7754 */ 7755 @Deprecated 7756 @SystemApi 7757 @SuppressLint("Doclava125") silenceRinger()7758 public void silenceRinger() { 7759 // No-op 7760 } 7761 7762 /** 7763 * @deprecated Use {@link android.telecom.TelecomManager#isInCall} instead 7764 * @hide 7765 */ 7766 @Deprecated 7767 @SystemApi 7768 @RequiresPermission(anyOf = { 7769 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 7770 android.Manifest.permission.READ_PHONE_STATE 7771 }) isOffhook()7772 public boolean isOffhook() { 7773 TelecomManager tm = (TelecomManager) mContext.getSystemService(TELECOM_SERVICE); 7774 return tm.isInCall(); 7775 } 7776 7777 /** 7778 * @deprecated Use {@link android.telecom.TelecomManager#isRinging} instead 7779 * @hide 7780 */ 7781 @Deprecated 7782 @SystemApi 7783 @RequiresPermission(anyOf = { 7784 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 7785 android.Manifest.permission.READ_PHONE_STATE 7786 }) isRinging()7787 public boolean isRinging() { 7788 TelecomManager tm = (TelecomManager) mContext.getSystemService(TELECOM_SERVICE); 7789 return tm.isRinging(); 7790 } 7791 7792 /** 7793 * @deprecated Use {@link android.telecom.TelecomManager#isInCall} instead 7794 * @hide 7795 */ 7796 @Deprecated 7797 @SystemApi 7798 @RequiresPermission(anyOf = { 7799 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 7800 android.Manifest.permission.READ_PHONE_STATE 7801 }) isIdle()7802 public boolean isIdle() { 7803 TelecomManager tm = (TelecomManager) mContext.getSystemService(TELECOM_SERVICE); 7804 return !tm.isInCall(); 7805 } 7806 7807 /** 7808 * @deprecated Use {@link android.telephony.TelephonyManager#getServiceState} instead 7809 * @hide 7810 */ 7811 @Deprecated 7812 @SystemApi 7813 @RequiresPermission(anyOf = { 7814 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 7815 android.Manifest.permission.READ_PHONE_STATE 7816 }) isRadioOn()7817 public boolean isRadioOn() { 7818 try { 7819 ITelephony telephony = getITelephony(); 7820 if (telephony != null) 7821 return telephony.isRadioOn(getOpPackageName()); 7822 } catch (RemoteException e) { 7823 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 7824 } 7825 return false; 7826 } 7827 7828 /** @hide */ 7829 @SystemApi 7830 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) supplyPin(String pin)7831 public boolean supplyPin(String pin) { 7832 try { 7833 ITelephony telephony = getITelephony(); 7834 if (telephony != null) 7835 return telephony.supplyPin(pin); 7836 } catch (RemoteException e) { 7837 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 7838 } 7839 return false; 7840 } 7841 7842 /** @hide */ 7843 @SystemApi 7844 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) supplyPuk(String puk, String pin)7845 public boolean supplyPuk(String puk, String pin) { 7846 try { 7847 ITelephony telephony = getITelephony(); 7848 if (telephony != null) 7849 return telephony.supplyPuk(puk, pin); 7850 } catch (RemoteException e) { 7851 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 7852 } 7853 return false; 7854 } 7855 7856 /** @hide */ 7857 @SystemApi 7858 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) supplyPinReportResult(String pin)7859 public int[] supplyPinReportResult(String pin) { 7860 try { 7861 ITelephony telephony = getITelephony(); 7862 if (telephony != null) 7863 return telephony.supplyPinReportResult(pin); 7864 } catch (RemoteException e) { 7865 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 7866 } 7867 return new int[0]; 7868 } 7869 7870 /** @hide */ 7871 @SystemApi 7872 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) supplyPukReportResult(String puk, String pin)7873 public int[] supplyPukReportResult(String puk, String pin) { 7874 try { 7875 ITelephony telephony = getITelephony(); 7876 if (telephony != null) 7877 return telephony.supplyPukReportResult(puk, pin); 7878 } catch (RemoteException e) { 7879 Log.e(TAG, "Error calling ITelephony#]", e); 7880 } 7881 return new int[0]; 7882 } 7883 7884 /** 7885 * Used to notify callers of 7886 * {@link TelephonyManager#sendUssdRequest(String, UssdResponseCallback, Handler)} when the 7887 * network either successfully executes a USSD request, or if there was a failure while 7888 * executing the request. 7889 * <p> 7890 * {@link #onReceiveUssdResponse(TelephonyManager, String, CharSequence)} will be called if the 7891 * USSD request has succeeded. 7892 * {@link #onReceiveUssdResponseFailed(TelephonyManager, String, int)} will be called if the 7893 * USSD request has failed. 7894 */ 7895 public static abstract class UssdResponseCallback { 7896 /** 7897 * Called when a USSD request has succeeded. The {@code response} contains the USSD 7898 * response received from the network. The calling app can choose to either display the 7899 * response to the user or perform some operation based on the response. 7900 * <p> 7901 * USSD responses are unstructured text and their content is determined by the mobile network 7902 * operator. 7903 * 7904 * @param telephonyManager the TelephonyManager the callback is registered to. 7905 * @param request the USSD request sent to the mobile network. 7906 * @param response the response to the USSD request provided by the mobile network. 7907 **/ onReceiveUssdResponse(final TelephonyManager telephonyManager, String request, CharSequence response)7908 public void onReceiveUssdResponse(final TelephonyManager telephonyManager, 7909 String request, CharSequence response) {}; 7910 7911 /** 7912 * Called when a USSD request has failed to complete. 7913 * 7914 * @param telephonyManager the TelephonyManager the callback is registered to. 7915 * @param request the USSD request sent to the mobile network. 7916 * @param failureCode failure code indicating why the request failed. Will be either 7917 * {@link TelephonyManager#USSD_RETURN_FAILURE} or 7918 * {@link TelephonyManager#USSD_ERROR_SERVICE_UNAVAIL}. 7919 **/ onReceiveUssdResponseFailed(final TelephonyManager telephonyManager, String request, int failureCode)7920 public void onReceiveUssdResponseFailed(final TelephonyManager telephonyManager, 7921 String request, int failureCode) {}; 7922 } 7923 7924 /** 7925 * Sends an Unstructured Supplementary Service Data (USSD) request to the mobile network and 7926 * informs the caller of the response via the supplied {@code callback}. 7927 * <p>Carriers define USSD codes which can be sent by the user to request information such as 7928 * the user's current data balance or minutes balance. 7929 * <p>Requires permission: 7930 * {@link android.Manifest.permission#CALL_PHONE} 7931 * @param ussdRequest the USSD command to be executed. 7932 * @param callback called by the framework to inform the caller of the result of executing the 7933 * USSD request (see {@link UssdResponseCallback}). 7934 * @param handler the {@link Handler} to run the request on. 7935 */ 7936 @RequiresPermission(android.Manifest.permission.CALL_PHONE) sendUssdRequest(String ussdRequest, final UssdResponseCallback callback, Handler handler)7937 public void sendUssdRequest(String ussdRequest, 7938 final UssdResponseCallback callback, Handler handler) { 7939 checkNotNull(callback, "UssdResponseCallback cannot be null."); 7940 final TelephonyManager telephonyManager = this; 7941 7942 ResultReceiver wrappedCallback = new ResultReceiver(handler) { 7943 @Override 7944 protected void onReceiveResult(int resultCode, Bundle ussdResponse) { 7945 Rlog.d(TAG, "USSD:" + resultCode); 7946 checkNotNull(ussdResponse, "ussdResponse cannot be null."); 7947 UssdResponse response = ussdResponse.getParcelable(USSD_RESPONSE); 7948 7949 if (resultCode == USSD_RETURN_SUCCESS) { 7950 callback.onReceiveUssdResponse(telephonyManager, response.getUssdRequest(), 7951 response.getReturnMessage()); 7952 } else { 7953 callback.onReceiveUssdResponseFailed(telephonyManager, 7954 response.getUssdRequest(), resultCode); 7955 } 7956 } 7957 }; 7958 7959 try { 7960 ITelephony telephony = getITelephony(); 7961 if (telephony != null) { 7962 telephony.handleUssdRequest(getSubId(), ussdRequest, wrappedCallback); 7963 } 7964 } catch (RemoteException e) { 7965 Log.e(TAG, "Error calling ITelephony#sendUSSDCode", e); 7966 UssdResponse response = new UssdResponse(ussdRequest, ""); 7967 Bundle returnData = new Bundle(); 7968 returnData.putParcelable(USSD_RESPONSE, response); 7969 wrappedCallback.send(USSD_ERROR_SERVICE_UNAVAIL, returnData); 7970 } 7971 } 7972 7973 /** 7974 * Whether the device is currently on a technology (e.g. UMTS or LTE) which can support 7975 * voice and data simultaneously. This can change based on location or network condition. 7976 * 7977 * @return {@code true} if simultaneous voice and data supported, and {@code false} otherwise. 7978 */ isConcurrentVoiceAndDataSupported()7979 public boolean isConcurrentVoiceAndDataSupported() { 7980 try { 7981 ITelephony telephony = getITelephony(); 7982 return (telephony == null ? false : telephony.isConcurrentVoiceAndDataAllowed( 7983 getSubId())); 7984 } catch (RemoteException e) { 7985 Log.e(TAG, "Error calling ITelephony#isConcurrentVoiceAndDataAllowed", e); 7986 } 7987 return false; 7988 } 7989 7990 /** @hide */ 7991 @SystemApi 7992 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) handlePinMmi(String dialString)7993 public boolean handlePinMmi(String dialString) { 7994 try { 7995 ITelephony telephony = getITelephony(); 7996 if (telephony != null) 7997 return telephony.handlePinMmi(dialString); 7998 } catch (RemoteException e) { 7999 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 8000 } 8001 return false; 8002 } 8003 8004 /** @hide */ 8005 @SystemApi 8006 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) handlePinMmiForSubscriber(int subId, String dialString)8007 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 8008 try { 8009 ITelephony telephony = getITelephony(); 8010 if (telephony != null) 8011 return telephony.handlePinMmiForSubscriber(subId, dialString); 8012 } catch (RemoteException e) { 8013 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 8014 } 8015 return false; 8016 } 8017 8018 /** @hide */ 8019 @SystemApi 8020 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) toggleRadioOnOff()8021 public void toggleRadioOnOff() { 8022 try { 8023 ITelephony telephony = getITelephony(); 8024 if (telephony != null) 8025 telephony.toggleRadioOnOff(); 8026 } catch (RemoteException e) { 8027 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 8028 } 8029 } 8030 8031 /** @hide */ 8032 @SystemApi 8033 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setRadio(boolean turnOn)8034 public boolean setRadio(boolean turnOn) { 8035 try { 8036 ITelephony telephony = getITelephony(); 8037 if (telephony != null) 8038 return telephony.setRadio(turnOn); 8039 } catch (RemoteException e) { 8040 Log.e(TAG, "Error calling ITelephony#setRadio", e); 8041 } 8042 return false; 8043 } 8044 8045 /** @hide */ 8046 @SystemApi 8047 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setRadioPower(boolean turnOn)8048 public boolean setRadioPower(boolean turnOn) { 8049 try { 8050 ITelephony telephony = getITelephony(); 8051 if (telephony != null) 8052 return telephony.setRadioPower(turnOn); 8053 } catch (RemoteException e) { 8054 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 8055 } 8056 return false; 8057 } 8058 8059 /** @hide */ 8060 @Retention(RetentionPolicy.SOURCE) 8061 @IntDef(prefix = {"RADIO_POWER_"}, 8062 value = {RADIO_POWER_OFF, 8063 RADIO_POWER_ON, 8064 RADIO_POWER_UNAVAILABLE, 8065 }) 8066 public @interface RadioPowerState {} 8067 8068 /** 8069 * Radio explicitly powered off (e.g, airplane mode). 8070 * @hide 8071 */ 8072 @SystemApi 8073 public static final int RADIO_POWER_OFF = 0; 8074 8075 /** 8076 * Radio power is on. 8077 * @hide 8078 */ 8079 @SystemApi 8080 public static final int RADIO_POWER_ON = 1; 8081 8082 /** 8083 * Radio power unavailable (eg, modem resetting or not booted). 8084 * @hide 8085 */ 8086 @SystemApi 8087 public static final int RADIO_POWER_UNAVAILABLE = 2; 8088 8089 /** 8090 * @return current modem radio state. 8091 * 8092 * <p>Requires permission: {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} or 8093 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling 8094 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 8095 * 8096 * @hide 8097 */ 8098 @SystemApi 8099 @RequiresPermission(anyOf = {android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 8100 android.Manifest.permission.READ_PHONE_STATE}) getRadioPowerState()8101 public @RadioPowerState int getRadioPowerState() { 8102 try { 8103 ITelephony telephony = getITelephony(); 8104 if (telephony != null) { 8105 return telephony.getRadioPowerState(getSlotIndex(), mContext.getOpPackageName()); 8106 } 8107 } catch (RemoteException ex) { 8108 // This could happen if binder process crashes. 8109 } 8110 return RADIO_POWER_UNAVAILABLE; 8111 } 8112 8113 /** @hide */ 8114 @SystemApi 8115 @SuppressLint("Doclava125") updateServiceLocation()8116 public void updateServiceLocation() { 8117 try { 8118 ITelephony telephony = getITelephony(); 8119 if (telephony != null) 8120 telephony.updateServiceLocation(); 8121 } catch (RemoteException e) { 8122 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 8123 } 8124 } 8125 8126 /** @hide */ 8127 @SystemApi 8128 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) enableDataConnectivity()8129 public boolean enableDataConnectivity() { 8130 try { 8131 ITelephony telephony = getITelephony(); 8132 if (telephony != null) 8133 return telephony.enableDataConnectivity(); 8134 } catch (RemoteException e) { 8135 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 8136 } 8137 return false; 8138 } 8139 8140 /** @hide */ 8141 @SystemApi 8142 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) disableDataConnectivity()8143 public boolean disableDataConnectivity() { 8144 try { 8145 ITelephony telephony = getITelephony(); 8146 if (telephony != null) 8147 return telephony.disableDataConnectivity(); 8148 } catch (RemoteException e) { 8149 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 8150 } 8151 return false; 8152 } 8153 8154 /** @hide */ 8155 @SystemApi isDataConnectivityPossible()8156 public boolean isDataConnectivityPossible() { 8157 try { 8158 ITelephony telephony = getITelephony(); 8159 if (telephony != null) 8160 return telephony.isDataConnectivityPossible(getSubId(SubscriptionManager 8161 .getDefaultDataSubscriptionId())); 8162 } catch (RemoteException e) { 8163 Log.e(TAG, "Error calling ITelephony#isDataAllowed", e); 8164 } 8165 return false; 8166 } 8167 8168 /** @hide */ 8169 @SystemApi needsOtaServiceProvisioning()8170 public boolean needsOtaServiceProvisioning() { 8171 try { 8172 ITelephony telephony = getITelephony(); 8173 if (telephony != null) 8174 return telephony.needsOtaServiceProvisioning(); 8175 } catch (RemoteException e) { 8176 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 8177 } 8178 return false; 8179 } 8180 8181 /** 8182 * Turns mobile data on or off. 8183 * If this object has been created with {@link #createForSubscriptionId}, applies to the given 8184 * subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 8185 * 8186 * <p>Requires Permission: 8187 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 8188 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 8189 * 8190 * @param enable Whether to enable mobile data. 8191 * 8192 */ 8193 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 8194 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataEnabled(boolean enable)8195 public void setDataEnabled(boolean enable) { 8196 setDataEnabled(getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), enable); 8197 } 8198 8199 /** 8200 * @hide 8201 * @deprecated use {@link #setDataEnabled(boolean)} instead. 8202 */ 8203 @SystemApi 8204 @Deprecated 8205 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataEnabled(int subId, boolean enable)8206 public void setDataEnabled(int subId, boolean enable) { 8207 try { 8208 Log.d(TAG, "setDataEnabled: enabled=" + enable); 8209 ITelephony telephony = getITelephony(); 8210 if (telephony != null) 8211 telephony.setUserDataEnabled(subId, enable); 8212 } catch (RemoteException e) { 8213 Log.e(TAG, "Error calling ITelephony#setUserDataEnabled", e); 8214 } 8215 } 8216 8217 /** 8218 * @deprecated use {@link #isDataEnabled()} instead. 8219 * @hide 8220 */ 8221 @SystemApi 8222 @Deprecated getDataEnabled()8223 public boolean getDataEnabled() { 8224 return isDataEnabled(); 8225 } 8226 8227 /** 8228 * Returns whether mobile data is enabled or not per user setting. There are other factors 8229 * that could disable mobile data, but they are not considered here. 8230 * 8231 * If this object has been created with {@link #createForSubscriptionId}, applies to the given 8232 * subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 8233 * 8234 * <p>Requires one of the following permissions: 8235 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, 8236 * {@link android.Manifest.permission#MODIFY_PHONE_STATE}, or that the calling app has carrier 8237 * privileges (see {@link #hasCarrierPrivileges}). 8238 * 8239 * <p>Note that this does not take into account any data restrictions that may be present on the 8240 * calling app. Such restrictions may be inspected with 8241 * {@link ConnectivityManager#getRestrictBackgroundStatus}. 8242 * 8243 * @return true if mobile data is enabled. 8244 */ 8245 @RequiresPermission(anyOf = {android.Manifest.permission.ACCESS_NETWORK_STATE, 8246 android.Manifest.permission.MODIFY_PHONE_STATE}) isDataEnabled()8247 public boolean isDataEnabled() { 8248 return getDataEnabled(getSubId(SubscriptionManager.getDefaultDataSubscriptionId())); 8249 } 8250 8251 /** 8252 * Returns whether mobile data roaming is enabled on the subscription. 8253 * 8254 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8255 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 8256 * 8257 * <p>Requires one of the following permissions: 8258 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, 8259 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app 8260 * has carrier privileges (see {@link #hasCarrierPrivileges}). 8261 * 8262 * @return {@code true} if the data roaming is enabled on the subscription, otherwise return 8263 * {@code false}. 8264 */ 8265 @RequiresPermission(anyOf = {android.Manifest.permission.ACCESS_NETWORK_STATE, 8266 android.Manifest.permission.READ_PHONE_STATE}) isDataRoamingEnabled()8267 public boolean isDataRoamingEnabled() { 8268 boolean isDataRoamingEnabled = false; 8269 try { 8270 ITelephony telephony = getITelephony(); 8271 if (telephony != null) { 8272 isDataRoamingEnabled = telephony.isDataRoamingEnabled( 8273 getSubId(SubscriptionManager.getDefaultDataSubscriptionId())); 8274 } 8275 } catch (RemoteException e) { 8276 Log.e(TAG, "Error calling ITelephony#isDataRoamingEnabled", e); 8277 } 8278 return isDataRoamingEnabled; 8279 } 8280 8281 /** 8282 * Gets the roaming mode for CDMA phone. 8283 * 8284 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8285 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8286 * 8287 * @return one of {@link #CDMA_ROAMING_MODE_RADIO_DEFAULT}, {@link #CDMA_ROAMING_MODE_HOME}, 8288 * {@link #CDMA_ROAMING_MODE_AFFILIATED}, {@link #CDMA_ROAMING_MODE_ANY}. 8289 * 8290 * @hide 8291 */ 8292 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCdmaRoamingMode()8293 public int getCdmaRoamingMode() { 8294 int mode = CDMA_ROAMING_MODE_RADIO_DEFAULT; 8295 try { 8296 ITelephony telephony = getITelephony(); 8297 if (telephony != null) { 8298 mode = telephony.getCdmaRoamingMode(getSubId()); 8299 } 8300 } catch (RemoteException ex) { 8301 Log.e(TAG, "Error calling ITelephony#getCdmaRoamingMode", ex); 8302 } 8303 return mode; 8304 } 8305 8306 /** 8307 * Sets the roaming mode for CDMA phone to the given mode {@code mode}. 8308 * 8309 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8310 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8311 * 8312 * @param mode should be one of {@link #CDMA_ROAMING_MODE_RADIO_DEFAULT}, 8313 * {@link #CDMA_ROAMING_MODE_HOME}, {@link #CDMA_ROAMING_MODE_AFFILIATED}, 8314 * {@link #CDMA_ROAMING_MODE_ANY}. 8315 * 8316 * @return {@code true} if successed. 8317 * 8318 * @hide 8319 */ 8320 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setCdmaRoamingMode(int mode)8321 public boolean setCdmaRoamingMode(int mode) { 8322 try { 8323 ITelephony telephony = getITelephony(); 8324 if (telephony != null) { 8325 return telephony.setCdmaRoamingMode(getSubId(), mode); 8326 } 8327 } catch (RemoteException ex) { 8328 Log.e(TAG, "Error calling ITelephony#setCdmaRoamingMode", ex); 8329 } 8330 return false; 8331 } 8332 8333 /** 8334 * Sets the subscription mode for CDMA phone to the given mode {@code mode}. 8335 * 8336 * @param mode CDMA subscription mode 8337 * 8338 * @return {@code true} if successed. 8339 * 8340 * @see Phone#CDMA_SUBSCRIPTION_UNKNOWN 8341 * @see Phone#CDMA_SUBSCRIPTION_RUIM_SIM 8342 * @see Phone#CDMA_SUBSCRIPTION_NV 8343 * 8344 * @hide 8345 */ 8346 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setCdmaSubscriptionMode(int mode)8347 public boolean setCdmaSubscriptionMode(int mode) { 8348 try { 8349 ITelephony telephony = getITelephony(); 8350 if (telephony != null) { 8351 return telephony.setCdmaSubscriptionMode(getSubId(), mode); 8352 } 8353 } catch (RemoteException ex) { 8354 Log.e(TAG, "Error calling ITelephony#setCdmaSubscriptionMode", ex); 8355 } 8356 return false; 8357 } 8358 8359 /** 8360 * Enables/Disables the data roaming on the subscription. 8361 * 8362 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8363 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 8364 * 8365 * <p> Requires permission: 8366 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier 8367 * privileges (see {@link #hasCarrierPrivileges}). 8368 * 8369 * @param isEnabled {@code true} to enable mobile data roaming, otherwise disable it. 8370 * 8371 * @hide 8372 */ 8373 @SystemApi 8374 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataRoamingEnabled(boolean isEnabled)8375 public void setDataRoamingEnabled(boolean isEnabled) { 8376 try { 8377 ITelephony telephony = getITelephony(); 8378 if (telephony != null) { 8379 telephony.setDataRoamingEnabled( 8380 getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), isEnabled); 8381 } 8382 } catch (RemoteException e) { 8383 Log.e(TAG, "Error calling ITelephony#setDataRoamingEnabled", e); 8384 } 8385 } 8386 8387 /** 8388 * @deprecated use {@link #isDataEnabled()} instead. 8389 * @hide 8390 */ 8391 @Deprecated 8392 @SystemApi getDataEnabled(int subId)8393 public boolean getDataEnabled(int subId) { 8394 boolean retVal = false; 8395 try { 8396 ITelephony telephony = getITelephony(); 8397 if (telephony != null) 8398 retVal = telephony.isUserDataEnabled(subId); 8399 } catch (RemoteException e) { 8400 Log.e(TAG, "Error calling ITelephony#isUserDataEnabled", e); 8401 } catch (NullPointerException e) { 8402 } 8403 return retVal; 8404 } 8405 8406 /** 8407 * Returns the result and response from RIL for oem request 8408 * 8409 * @param oemReq the data is sent to ril. 8410 * @param oemResp the respose data from RIL. 8411 * @return negative value request was not handled or get error 8412 * 0 request was handled succesfully, but no response data 8413 * positive value success, data length of response 8414 * @hide 8415 * @deprecated OEM needs a vendor-extension hal and their apps should use that instead 8416 */ 8417 @Deprecated invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp)8418 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 8419 try { 8420 ITelephony telephony = getITelephony(); 8421 if (telephony != null) 8422 return telephony.invokeOemRilRequestRaw(oemReq, oemResp); 8423 } catch (RemoteException ex) { 8424 } catch (NullPointerException ex) { 8425 } 8426 return -1; 8427 } 8428 8429 /** @hide */ 8430 @SystemApi 8431 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) enableVideoCalling(boolean enable)8432 public void enableVideoCalling(boolean enable) { 8433 try { 8434 ITelephony telephony = getITelephony(); 8435 if (telephony != null) 8436 telephony.enableVideoCalling(enable); 8437 } catch (RemoteException e) { 8438 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 8439 } 8440 } 8441 8442 /** @hide */ 8443 @SystemApi 8444 @RequiresPermission(anyOf = { 8445 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 8446 android.Manifest.permission.READ_PHONE_STATE 8447 }) isVideoCallingEnabled()8448 public boolean isVideoCallingEnabled() { 8449 try { 8450 ITelephony telephony = getITelephony(); 8451 if (telephony != null) 8452 return telephony.isVideoCallingEnabled(getOpPackageName()); 8453 } catch (RemoteException e) { 8454 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 8455 } 8456 return false; 8457 } 8458 8459 /** 8460 * Whether the device supports configuring the DTMF tone length. 8461 * 8462 * @return {@code true} if the DTMF tone length can be changed, and {@code false} otherwise. 8463 */ canChangeDtmfToneLength()8464 public boolean canChangeDtmfToneLength() { 8465 try { 8466 ITelephony telephony = getITelephony(); 8467 if (telephony != null) { 8468 return telephony.canChangeDtmfToneLength(mSubId, getOpPackageName()); 8469 } 8470 } catch (RemoteException e) { 8471 Log.e(TAG, "Error calling ITelephony#canChangeDtmfToneLength", e); 8472 } catch (SecurityException e) { 8473 Log.e(TAG, "Permission error calling ITelephony#canChangeDtmfToneLength", e); 8474 } 8475 return false; 8476 } 8477 8478 /** 8479 * Whether the device is a world phone. 8480 * 8481 * @return {@code true} if the device is a world phone, and {@code false} otherwise. 8482 */ isWorldPhone()8483 public boolean isWorldPhone() { 8484 try { 8485 ITelephony telephony = getITelephony(); 8486 if (telephony != null) { 8487 return telephony.isWorldPhone(mSubId, getOpPackageName()); 8488 } 8489 } catch (RemoteException e) { 8490 Log.e(TAG, "Error calling ITelephony#isWorldPhone", e); 8491 } catch (SecurityException e) { 8492 Log.e(TAG, "Permission error calling ITelephony#isWorldPhone", e); 8493 } 8494 return false; 8495 } 8496 8497 /** 8498 * @deprecated Use {@link TelecomManager#isTtySupported()} instead 8499 * Whether the phone supports TTY mode. 8500 * 8501 * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. 8502 * 8503 */ 8504 @Deprecated isTtyModeSupported()8505 public boolean isTtyModeSupported() { 8506 try { 8507 TelecomManager telecomManager = TelecomManager.from(mContext); 8508 if (telecomManager != null) { 8509 return telecomManager.isTtySupported(); 8510 } 8511 } catch (SecurityException e) { 8512 Log.e(TAG, "Permission error calling TelecomManager#isTtySupported", e); 8513 } 8514 return false; 8515 } 8516 8517 /** 8518 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier 8519 * support for the feature and device firmware support. 8520 * 8521 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. 8522 */ isRttSupported()8523 public boolean isRttSupported() { 8524 try { 8525 ITelephony telephony = getITelephony(); 8526 if (telephony != null) { 8527 return telephony.isRttSupported(mSubId); 8528 } 8529 } catch (RemoteException e) { 8530 Log.e(TAG, "Error calling ITelephony#isRttSupported", e); 8531 } catch (SecurityException e) { 8532 Log.e(TAG, "Permission error calling ITelephony#isWorldPhone", e); 8533 } 8534 return false; 8535 } 8536 /** 8537 * Whether the phone supports hearing aid compatibility. 8538 * 8539 * @return {@code true} if the device supports hearing aid compatibility, and {@code false} 8540 * otherwise. 8541 */ isHearingAidCompatibilitySupported()8542 public boolean isHearingAidCompatibilitySupported() { 8543 try { 8544 ITelephony telephony = getITelephony(); 8545 if (telephony != null) { 8546 return telephony.isHearingAidCompatibilitySupported(); 8547 } 8548 } catch (RemoteException e) { 8549 Log.e(TAG, "Error calling ITelephony#isHearingAidCompatibilitySupported", e); 8550 } catch (SecurityException e) { 8551 Log.e(TAG, "Permission error calling ITelephony#isHearingAidCompatibilitySupported", e); 8552 } 8553 return false; 8554 } 8555 8556 /** 8557 * Returns the IMS Registration Status for a particular Subscription ID. 8558 * 8559 * @param subId Subscription ID 8560 * @return true if IMS status is registered, false if the IMS status is not registered or a 8561 * RemoteException occurred. 8562 * @hide 8563 */ isImsRegistered(int subId)8564 public boolean isImsRegistered(int subId) { 8565 try { 8566 return getITelephony().isImsRegistered(subId); 8567 } catch (RemoteException | NullPointerException ex) { 8568 return false; 8569 } 8570 } 8571 8572 /** 8573 * Returns the IMS Registration Status for a particular Subscription ID, which is determined 8574 * when the TelephonyManager is created using {@link #createForSubscriptionId(int)}. If an 8575 * invalid subscription ID is used during creation, will the default subscription ID will be 8576 * used. 8577 * 8578 * @return true if IMS status is registered, false if the IMS status is not registered or a 8579 * RemoteException occurred. 8580 * @see SubscriptionManager#getDefaultSubscriptionId() 8581 * @hide 8582 */ 8583 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) isImsRegistered()8584 public boolean isImsRegistered() { 8585 try { 8586 return getITelephony().isImsRegistered(getSubId()); 8587 } catch (RemoteException | NullPointerException ex) { 8588 return false; 8589 } 8590 } 8591 8592 /** 8593 * The current status of Voice over LTE for the subscription associated with this instance when 8594 * it was created using {@link #createForSubscriptionId(int)}. If an invalid subscription ID was 8595 * used during creation, the default subscription ID will be used. 8596 * @return true if Voice over LTE is available or false if it is unavailable or unknown. 8597 * @see SubscriptionManager#getDefaultSubscriptionId() 8598 * @hide 8599 */ 8600 @UnsupportedAppUsage isVolteAvailable()8601 public boolean isVolteAvailable() { 8602 try { 8603 return getITelephony().isAvailable(getSubId(), 8604 MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE, 8605 ImsRegistrationImplBase.REGISTRATION_TECH_LTE); 8606 } catch (RemoteException | NullPointerException ex) { 8607 return false; 8608 } 8609 } 8610 8611 /** 8612 * The availability of Video Telephony (VT) for the subscription ID specified when this instance 8613 * was created using {@link #createForSubscriptionId(int)}. If an invalid subscription ID was 8614 * used during creation, the default subscription ID will be used. To query the 8615 * underlying technology that VT is available on, use {@link #getImsRegTechnologyForMmTel}. 8616 * @return true if VT is available, or false if it is unavailable or unknown. 8617 * @hide 8618 */ 8619 @UnsupportedAppUsage isVideoTelephonyAvailable()8620 public boolean isVideoTelephonyAvailable() { 8621 try { 8622 return getITelephony().isVideoTelephonyAvailable(getSubId()); 8623 } catch (RemoteException | NullPointerException ex) { 8624 return false; 8625 } 8626 } 8627 8628 /** 8629 * Returns the Status of Wi-Fi calling (Voice over WiFi) for the subscription ID specified. 8630 * @param subId the subscription ID. 8631 * @return true if VoWiFi is available, or false if it is unavailable or unknown. 8632 * @hide 8633 */ 8634 @UnsupportedAppUsage isWifiCallingAvailable()8635 public boolean isWifiCallingAvailable() { 8636 try { 8637 return getITelephony().isWifiCallingAvailable(getSubId()); 8638 } catch (RemoteException | NullPointerException ex) { 8639 return false; 8640 } 8641 } 8642 8643 /** 8644 * The technology that IMS is registered for for the MMTEL feature. 8645 * @param subId subscription ID to get IMS registration technology for. 8646 * @return The IMS registration technology that IMS is registered to for the MMTEL feature. 8647 * Valid return results are: 8648 * - {@link ImsRegistrationImplBase#REGISTRATION_TECH_LTE} for LTE registration, 8649 * - {@link ImsRegistrationImplBase#REGISTRATION_TECH_IWLAN} for IWLAN registration, or 8650 * - {@link ImsRegistrationImplBase#REGISTRATION_TECH_NONE} if we are not registered or the 8651 * result is unavailable. 8652 * @hide 8653 */ getImsRegTechnologyForMmTel()8654 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel() { 8655 try { 8656 return getITelephony().getImsRegTechnologyForMmTel(getSubId()); 8657 } catch (RemoteException ex) { 8658 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; 8659 } 8660 } 8661 8662 /** 8663 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 8664 * 8665 * @hide 8666 */ setSimOperatorNumeric(String numeric)8667 public void setSimOperatorNumeric(String numeric) { 8668 int phoneId = getPhoneId(); 8669 setSimOperatorNumericForPhone(phoneId, numeric); 8670 } 8671 8672 /** 8673 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 8674 * 8675 * @hide 8676 */ 8677 @UnsupportedAppUsage setSimOperatorNumericForPhone(int phoneId, String numeric)8678 public void setSimOperatorNumericForPhone(int phoneId, String numeric) { 8679 setTelephonyProperty(phoneId, 8680 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, numeric); 8681 } 8682 8683 /** 8684 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 8685 * 8686 * @hide 8687 */ setSimOperatorName(String name)8688 public void setSimOperatorName(String name) { 8689 int phoneId = getPhoneId(); 8690 setSimOperatorNameForPhone(phoneId, name); 8691 } 8692 8693 /** 8694 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 8695 * 8696 * @hide 8697 */ 8698 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setSimOperatorNameForPhone(int phoneId, String name)8699 public void setSimOperatorNameForPhone(int phoneId, String name) { 8700 setTelephonyProperty(phoneId, 8701 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, name); 8702 } 8703 8704 /** 8705 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the default phone. 8706 * 8707 * @hide 8708 */ setSimCountryIso(String iso)8709 public void setSimCountryIso(String iso) { 8710 int phoneId = getPhoneId(); 8711 setSimCountryIsoForPhone(phoneId, iso); 8712 } 8713 8714 /** 8715 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the given phone. 8716 * 8717 * @hide 8718 */ 8719 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setSimCountryIsoForPhone(int phoneId, String iso)8720 public void setSimCountryIsoForPhone(int phoneId, String iso) { 8721 setTelephonyProperty(phoneId, 8722 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso); 8723 } 8724 8725 /** 8726 * Set TelephonyProperties.PROPERTY_SIM_STATE for the default phone. 8727 * 8728 * @hide 8729 */ setSimState(String state)8730 public void setSimState(String state) { 8731 int phoneId = getPhoneId(); 8732 setSimStateForPhone(phoneId, state); 8733 } 8734 8735 /** 8736 * Set TelephonyProperties.PROPERTY_SIM_STATE for the given phone. 8737 * 8738 * @hide 8739 */ 8740 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setSimStateForPhone(int phoneId, String state)8741 public void setSimStateForPhone(int phoneId, String state) { 8742 setTelephonyProperty(phoneId, 8743 TelephonyProperties.PROPERTY_SIM_STATE, state); 8744 } 8745 8746 /** 8747 * Requested state of SIM 8748 * 8749 * CARD_POWER_DOWN 8750 * Powers down the SIM. SIM must be up prior. 8751 * 8752 * CARD_POWER_UP 8753 * Powers up the SIM normally. SIM must be down prior. 8754 * 8755 * CARD_POWER_UP_PASS_THROUGH 8756 * Powers up the SIM in PASS_THROUGH mode. SIM must be down prior. 8757 * When SIM is powered up in PASS_THOUGH mode, the modem does not send 8758 * any command to it (for example SELECT of MF, or TERMINAL CAPABILITY), 8759 * and the SIM card is controlled completely by Telephony sending APDUs 8760 * directly. The SIM card state will be RIL_CARDSTATE_PRESENT and the 8761 * number of card apps will be 0. 8762 * No new error code is generated. Emergency calls are supported in the 8763 * same way as if the SIM card is absent. 8764 * The PASS_THROUGH mode is valid only for the specific card session where it 8765 * is activated, and normal behavior occurs at the next SIM initialization, 8766 * unless PASS_THROUGH mode is requested again. Hence, the last power-up mode 8767 * is NOT persistent across boots. On reboot, SIM will power up normally. 8768 */ 8769 /** @hide */ 8770 public static final int CARD_POWER_DOWN = 0; 8771 /** @hide */ 8772 public static final int CARD_POWER_UP = 1; 8773 /** @hide */ 8774 public static final int CARD_POWER_UP_PASS_THROUGH = 2; 8775 8776 /** 8777 * Set SIM card power state. 8778 * 8779 * @param state State of SIM (power down, power up, pass through) 8780 * @see #CARD_POWER_DOWN 8781 * @see #CARD_POWER_UP 8782 * @see #CARD_POWER_UP_PASS_THROUGH 8783 * Callers should monitor for {@link TelephonyIntents#ACTION_SIM_STATE_CHANGED} 8784 * broadcasts to determine success or failure and timeout if needed. 8785 * 8786 * <p>Requires Permission: 8787 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 8788 * 8789 * {@hide} 8790 **/ 8791 @SystemApi 8792 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setSimPowerState(int state)8793 public void setSimPowerState(int state) { 8794 setSimPowerStateForSlot(getSlotIndex(), state); 8795 } 8796 8797 /** 8798 * Set SIM card power state. 8799 * 8800 * @param slotIndex SIM slot id 8801 * @param state State of SIM (power down, power up, pass through) 8802 * @see #CARD_POWER_DOWN 8803 * @see #CARD_POWER_UP 8804 * @see #CARD_POWER_UP_PASS_THROUGH 8805 * Callers should monitor for {@link TelephonyIntents#ACTION_SIM_STATE_CHANGED} 8806 * broadcasts to determine success or failure and timeout if needed. 8807 * 8808 * <p>Requires Permission: 8809 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 8810 * 8811 * {@hide} 8812 **/ 8813 @SystemApi 8814 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setSimPowerStateForSlot(int slotIndex, int state)8815 public void setSimPowerStateForSlot(int slotIndex, int state) { 8816 try { 8817 ITelephony telephony = getITelephony(); 8818 if (telephony != null) { 8819 telephony.setSimPowerStateForSlot(slotIndex, state); 8820 } 8821 } catch (RemoteException e) { 8822 Log.e(TAG, "Error calling ITelephony#setSimPowerStateForSlot", e); 8823 } catch (SecurityException e) { 8824 Log.e(TAG, "Permission error calling ITelephony#setSimPowerStateForSlot", e); 8825 } 8826 } 8827 8828 /** 8829 * Set baseband version for the default phone. 8830 * 8831 * @param version baseband version 8832 * @hide 8833 */ setBasebandVersion(String version)8834 public void setBasebandVersion(String version) { 8835 int phoneId = getPhoneId(); 8836 setBasebandVersionForPhone(phoneId, version); 8837 } 8838 8839 /** 8840 * Set baseband version by phone id. 8841 * 8842 * @param phoneId for which baseband version is set 8843 * @param version baseband version 8844 * @hide 8845 */ 8846 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setBasebandVersionForPhone(int phoneId, String version)8847 public void setBasebandVersionForPhone(int phoneId, String version) { 8848 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_BASEBAND_VERSION, version); 8849 } 8850 8851 /** 8852 * Get baseband version for the default phone. 8853 * 8854 * @return baseband version. 8855 * @hide 8856 */ getBasebandVersion()8857 public String getBasebandVersion() { 8858 int phoneId = getPhoneId(); 8859 return getBasebandVersionForPhone(phoneId); 8860 } 8861 8862 /** 8863 * Get baseband version for the default phone using the legacy approach. 8864 * This change was added in P, to ensure backward compatiblity. 8865 * 8866 * @return baseband version. 8867 * @hide 8868 */ getBasebandVersionLegacy(int phoneId)8869 private String getBasebandVersionLegacy(int phoneId) { 8870 if (SubscriptionManager.isValidPhoneId(phoneId)) { 8871 String prop = TelephonyProperties.PROPERTY_BASEBAND_VERSION + 8872 ((phoneId == 0) ? "" : Integer.toString(phoneId)); 8873 return SystemProperties.get(prop); 8874 } 8875 return null; 8876 } 8877 8878 /** 8879 * Get baseband version by phone id. 8880 * 8881 * @return baseband version. 8882 * @hide 8883 */ getBasebandVersionForPhone(int phoneId)8884 public String getBasebandVersionForPhone(int phoneId) { 8885 String version = getBasebandVersionLegacy(phoneId); 8886 if (version != null && !version.isEmpty()) { 8887 setBasebandVersionForPhone(phoneId, version); 8888 } 8889 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_BASEBAND_VERSION, ""); 8890 } 8891 8892 /** 8893 * Set phone type for the default phone. 8894 * 8895 * @param type phone type 8896 * 8897 * @hide 8898 */ setPhoneType(int type)8899 public void setPhoneType(int type) { 8900 int phoneId = getPhoneId(); 8901 setPhoneType(phoneId, type); 8902 } 8903 8904 /** 8905 * Set phone type by phone id. 8906 * 8907 * @param phoneId for which phone type is set 8908 * @param type phone type 8909 * 8910 * @hide 8911 */ 8912 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setPhoneType(int phoneId, int type)8913 public void setPhoneType(int phoneId, int type) { 8914 if (SubscriptionManager.isValidPhoneId(phoneId)) { 8915 TelephonyManager.setTelephonyProperty(phoneId, 8916 TelephonyProperties.CURRENT_ACTIVE_PHONE, String.valueOf(type)); 8917 } 8918 } 8919 8920 /** 8921 * Get OTASP number schema for the default phone. 8922 * 8923 * @param defaultValue default value 8924 * @return OTA SP number schema 8925 * 8926 * @hide 8927 */ getOtaSpNumberSchema(String defaultValue)8928 public String getOtaSpNumberSchema(String defaultValue) { 8929 int phoneId = getPhoneId(); 8930 return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); 8931 } 8932 8933 /** 8934 * Get OTASP number schema by phone id. 8935 * 8936 * @param phoneId for which OTA SP number schema is get 8937 * @param defaultValue default value 8938 * @return OTA SP number schema 8939 * 8940 * @hide 8941 */ 8942 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue)8943 public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) { 8944 if (SubscriptionManager.isValidPhoneId(phoneId)) { 8945 return TelephonyManager.getTelephonyProperty(phoneId, 8946 TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA, defaultValue); 8947 } 8948 8949 return defaultValue; 8950 } 8951 8952 /** 8953 * Get SMS receive capable from system property for the default phone. 8954 * 8955 * @param defaultValue default value 8956 * @return SMS receive capable 8957 * 8958 * @hide 8959 */ getSmsReceiveCapable(boolean defaultValue)8960 public boolean getSmsReceiveCapable(boolean defaultValue) { 8961 int phoneId = getPhoneId(); 8962 return getSmsReceiveCapableForPhone(phoneId, defaultValue); 8963 } 8964 8965 /** 8966 * Get SMS receive capable from system property by phone id. 8967 * 8968 * @param phoneId for which SMS receive capable is get 8969 * @param defaultValue default value 8970 * @return SMS receive capable 8971 * 8972 * @hide 8973 */ getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue)8974 public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) { 8975 if (SubscriptionManager.isValidPhoneId(phoneId)) { 8976 return Boolean.parseBoolean(TelephonyManager.getTelephonyProperty(phoneId, 8977 TelephonyProperties.PROPERTY_SMS_RECEIVE, String.valueOf(defaultValue))); 8978 } 8979 8980 return defaultValue; 8981 } 8982 8983 /** 8984 * Get SMS send capable from system property for the default phone. 8985 * 8986 * @param defaultValue default value 8987 * @return SMS send capable 8988 * 8989 * @hide 8990 */ getSmsSendCapable(boolean defaultValue)8991 public boolean getSmsSendCapable(boolean defaultValue) { 8992 int phoneId = getPhoneId(); 8993 return getSmsSendCapableForPhone(phoneId, defaultValue); 8994 } 8995 8996 /** 8997 * Get SMS send capable from system property by phone id. 8998 * 8999 * @param phoneId for which SMS send capable is get 9000 * @param defaultValue default value 9001 * @return SMS send capable 9002 * 9003 * @hide 9004 */ getSmsSendCapableForPhone(int phoneId, boolean defaultValue)9005 public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) { 9006 if (SubscriptionManager.isValidPhoneId(phoneId)) { 9007 return Boolean.parseBoolean(TelephonyManager.getTelephonyProperty(phoneId, 9008 TelephonyProperties.PROPERTY_SMS_SEND, String.valueOf(defaultValue))); 9009 } 9010 9011 return defaultValue; 9012 } 9013 9014 /** 9015 * Set the alphabetic name of current registered operator. 9016 * @param name the alphabetic name of current registered operator. 9017 * @hide 9018 */ setNetworkOperatorName(String name)9019 public void setNetworkOperatorName(String name) { 9020 int phoneId = getPhoneId(); 9021 setNetworkOperatorNameForPhone(phoneId, name); 9022 } 9023 9024 /** 9025 * Set the alphabetic name of current registered operator. 9026 * @param phoneId which phone you want to set 9027 * @param name the alphabetic name of current registered operator. 9028 * @hide 9029 */ 9030 @UnsupportedAppUsage setNetworkOperatorNameForPhone(int phoneId, String name)9031 public void setNetworkOperatorNameForPhone(int phoneId, String name) { 9032 if (SubscriptionManager.isValidPhoneId(phoneId)) { 9033 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, name); 9034 } 9035 } 9036 9037 /** 9038 * Set the numeric name (MCC+MNC) of current registered operator. 9039 * @param operator the numeric name (MCC+MNC) of current registered operator 9040 * @hide 9041 */ setNetworkOperatorNumeric(String numeric)9042 public void setNetworkOperatorNumeric(String numeric) { 9043 int phoneId = getPhoneId(); 9044 setNetworkOperatorNumericForPhone(phoneId, numeric); 9045 } 9046 9047 /** 9048 * Set the numeric name (MCC+MNC) of current registered operator. 9049 * @param phoneId for which phone type is set 9050 * @param operator the numeric name (MCC+MNC) of current registered operator 9051 * @hide 9052 */ 9053 @UnsupportedAppUsage setNetworkOperatorNumericForPhone(int phoneId, String numeric)9054 public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) { 9055 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, numeric); 9056 } 9057 9058 /** 9059 * Set roaming state of the current network, for GSM purposes. 9060 * @param isRoaming is network in romaing state or not 9061 * @hide 9062 */ setNetworkRoaming(boolean isRoaming)9063 public void setNetworkRoaming(boolean isRoaming) { 9064 int phoneId = getPhoneId(); 9065 setNetworkRoamingForPhone(phoneId, isRoaming); 9066 } 9067 9068 /** 9069 * Set roaming state of the current network, for GSM purposes. 9070 * @param phoneId which phone you want to set 9071 * @param isRoaming is network in romaing state or not 9072 * @hide 9073 */ 9074 @UnsupportedAppUsage setNetworkRoamingForPhone(int phoneId, boolean isRoaming)9075 public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) { 9076 if (SubscriptionManager.isValidPhoneId(phoneId)) { 9077 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, 9078 isRoaming ? "true" : "false"); 9079 } 9080 } 9081 9082 /** 9083 * Set the network type currently in use on the device for data transmission. 9084 * 9085 * If this object has been created with {@link #createForSubscriptionId}, applies to the 9086 * phoneId associated with the given subId. Otherwise, applies to the phoneId associated with 9087 * {@link SubscriptionManager#getDefaultDataSubscriptionId()} 9088 * @param type the network type currently in use on the device for data transmission 9089 * @hide 9090 */ setDataNetworkType(int type)9091 public void setDataNetworkType(int type) { 9092 int phoneId = getPhoneId(SubscriptionManager.getDefaultDataSubscriptionId()); 9093 setDataNetworkTypeForPhone(phoneId, type); 9094 } 9095 9096 /** 9097 * Set the network type currently in use on the device for data transmission. 9098 * @param phoneId which phone you want to set 9099 * @param type the network type currently in use on the device for data transmission 9100 * @hide 9101 */ 9102 @UnsupportedAppUsage setDataNetworkTypeForPhone(int phoneId, int type)9103 public void setDataNetworkTypeForPhone(int phoneId, int type) { 9104 if (SubscriptionManager.isValidPhoneId(phoneId)) { 9105 setTelephonyProperty(phoneId, 9106 TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, 9107 ServiceState.rilRadioTechnologyToString(type)); 9108 } 9109 } 9110 9111 /** 9112 * Returns the subscription ID for the given phone account. 9113 * @hide 9114 */ 9115 @UnsupportedAppUsage getSubIdForPhoneAccount(PhoneAccount phoneAccount)9116 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { 9117 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 9118 try { 9119 ITelephony service = getITelephony(); 9120 if (service != null) { 9121 retval = service.getSubIdForPhoneAccount(phoneAccount); 9122 } 9123 } catch (RemoteException e) { 9124 } 9125 9126 return retval; 9127 } 9128 9129 /** 9130 * Determines the {@link PhoneAccountHandle} associated with a subscription Id. 9131 * 9132 * @param subscriptionId The subscription Id to check. 9133 * @return The {@link PhoneAccountHandle} associated with a subscription Id, or {@code null} if 9134 * there is no associated {@link PhoneAccountHandle}. 9135 * @hide 9136 */ getPhoneAccountHandleForSubscriptionId(int subscriptionId)9137 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { 9138 PhoneAccountHandle returnValue = null; 9139 try { 9140 ITelephony service = getITelephony(); 9141 if (service != null) { 9142 returnValue = service.getPhoneAccountHandleForSubscriptionId(subscriptionId); 9143 } 9144 } catch (RemoteException e) { 9145 } 9146 9147 return returnValue; 9148 } 9149 getSubIdForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle)9150 private int getSubIdForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) { 9151 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 9152 try { 9153 ITelecomService service = getTelecomService(); 9154 if (service != null) { 9155 retval = getSubIdForPhoneAccount(service.getPhoneAccount(phoneAccountHandle)); 9156 } 9157 } catch (RemoteException e) { 9158 } 9159 9160 return retval; 9161 } 9162 9163 /** 9164 * Resets telephony manager settings back to factory defaults. 9165 * 9166 * @hide 9167 */ factoryReset(int subId)9168 public void factoryReset(int subId) { 9169 try { 9170 Log.d(TAG, "factoryReset: subId=" + subId); 9171 ITelephony telephony = getITelephony(); 9172 if (telephony != null) 9173 telephony.factoryReset(subId); 9174 } catch (RemoteException e) { 9175 } 9176 } 9177 9178 9179 /** 9180 * Returns a locale based on the country and language from the SIM. Returns {@code null} if 9181 * no locale could be derived from subscriptions. 9182 * 9183 * <p>Requires Permission: 9184 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 9185 * 9186 * @see Locale#toLanguageTag() 9187 * 9188 * @hide 9189 */ 9190 @SystemApi 9191 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getSimLocale()9192 @Nullable public Locale getSimLocale() { 9193 try { 9194 final ITelephony telephony = getITelephony(); 9195 if (telephony != null) { 9196 String languageTag = telephony.getSimLocaleForSubscriber(getSubId()); 9197 if (!TextUtils.isEmpty(languageTag)) { 9198 return Locale.forLanguageTag(languageTag); 9199 } 9200 } 9201 } catch (RemoteException ex) { 9202 } 9203 return null; 9204 } 9205 9206 /** 9207 * TODO delete after SuW migrates to new API. 9208 * @hide 9209 */ getLocaleFromDefaultSim()9210 public String getLocaleFromDefaultSim() { 9211 try { 9212 final ITelephony telephony = getITelephony(); 9213 if (telephony != null) { 9214 return telephony.getSimLocaleForSubscriber(getSubId()); 9215 } 9216 } catch (RemoteException ex) { 9217 } 9218 return null; 9219 } 9220 9221 9222 /** 9223 * Requests the modem activity info. The recipient will place the result 9224 * in `result`. 9225 * @param result The object on which the recipient will send the resulting 9226 * {@link android.telephony.ModemActivityInfo} object. 9227 * @hide 9228 */ requestModemActivityInfo(ResultReceiver result)9229 public void requestModemActivityInfo(ResultReceiver result) { 9230 try { 9231 ITelephony service = getITelephony(); 9232 if (service != null) { 9233 service.requestModemActivityInfo(result); 9234 return; 9235 } 9236 } catch (RemoteException e) { 9237 Log.e(TAG, "Error calling ITelephony#getModemActivityInfo", e); 9238 } 9239 result.send(0, null); 9240 } 9241 9242 /** 9243 * Returns the current {@link ServiceState} information. 9244 * 9245 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 9246 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 9247 * 9248 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 9249 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) 9250 * and {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 9251 */ 9252 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 9253 @RequiresPermission(allOf = { 9254 Manifest.permission.READ_PHONE_STATE, 9255 Manifest.permission.ACCESS_COARSE_LOCATION 9256 }) getServiceState()9257 public ServiceState getServiceState() { 9258 return getServiceStateForSubscriber(getSubId()); 9259 } 9260 9261 /** 9262 * Returns the service state information on specified subscription. Callers require 9263 * either READ_PRIVILEGED_PHONE_STATE or READ_PHONE_STATE to retrieve the information. 9264 * @hide 9265 */ 9266 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getServiceStateForSubscriber(int subId)9267 public ServiceState getServiceStateForSubscriber(int subId) { 9268 try { 9269 ITelephony service = getITelephony(); 9270 if (service != null) { 9271 return service.getServiceStateForSubscriber(subId, getOpPackageName()); 9272 } 9273 } catch (RemoteException e) { 9274 Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e); 9275 } catch (NullPointerException e) { 9276 AnomalyReporter.reportAnomaly( 9277 UUID.fromString("a3ab0b9d-f2aa-4baf-911d-7096c0d4645a"), 9278 "getServiceStateForSubscriber " + subId + " NPE"); 9279 } 9280 return null; 9281 } 9282 9283 /** 9284 * Returns the URI for the per-account voicemail ringtone set in Phone settings. 9285 * 9286 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the 9287 * voicemail ringtone. 9288 * @return The URI for the ringtone to play when receiving a voicemail from a specific 9289 * PhoneAccount. 9290 */ getVoicemailRingtoneUri(PhoneAccountHandle accountHandle)9291 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { 9292 try { 9293 ITelephony service = getITelephony(); 9294 if (service != null) { 9295 return service.getVoicemailRingtoneUri(accountHandle); 9296 } 9297 } catch (RemoteException e) { 9298 Log.e(TAG, "Error calling ITelephony#getVoicemailRingtoneUri", e); 9299 } 9300 return null; 9301 } 9302 9303 /** 9304 * Sets the per-account voicemail ringtone. 9305 * 9306 * <p>Requires that the calling app is the default dialer, or has carrier privileges (see 9307 * {@link #hasCarrierPrivileges}, or has permission 9308 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 9309 * 9310 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the 9311 * voicemail ringtone. 9312 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific 9313 * PhoneAccount. 9314 * 9315 * @deprecated Use {@link android.provider.Settings#ACTION_CHANNEL_NOTIFICATION_SETTINGS} 9316 * instead. 9317 */ setVoicemailRingtoneUri(PhoneAccountHandle phoneAccountHandle, Uri uri)9318 public void setVoicemailRingtoneUri(PhoneAccountHandle phoneAccountHandle, Uri uri) { 9319 try { 9320 ITelephony service = getITelephony(); 9321 if (service != null) { 9322 service.setVoicemailRingtoneUri(getOpPackageName(), phoneAccountHandle, uri); 9323 } 9324 } catch (RemoteException e) { 9325 Log.e(TAG, "Error calling ITelephony#setVoicemailRingtoneUri", e); 9326 } 9327 } 9328 9329 /** 9330 * Returns whether vibration is set for voicemail notification in Phone settings. 9331 * 9332 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the 9333 * voicemail vibration setting. 9334 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. 9335 */ isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle)9336 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { 9337 try { 9338 ITelephony service = getITelephony(); 9339 if (service != null) { 9340 return service.isVoicemailVibrationEnabled(accountHandle); 9341 } 9342 } catch (RemoteException e) { 9343 Log.e(TAG, "Error calling ITelephony#isVoicemailVibrationEnabled", e); 9344 } 9345 return false; 9346 } 9347 9348 /** 9349 * Sets the per-account preference whether vibration is enabled for voicemail notifications. 9350 * 9351 * <p>Requires that the calling app is the default dialer, or has carrier privileges (see 9352 * {@link #hasCarrierPrivileges}, or has permission 9353 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 9354 * 9355 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the 9356 * voicemail vibration setting. 9357 * @param enabled Whether to enable or disable vibration for voicemail notifications from a 9358 * specific PhoneAccount. 9359 * 9360 * @deprecated Use {@link android.provider.Settings#ACTION_CHANNEL_NOTIFICATION_SETTINGS} 9361 * instead. 9362 */ setVoicemailVibrationEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled)9363 public void setVoicemailVibrationEnabled(PhoneAccountHandle phoneAccountHandle, 9364 boolean enabled) { 9365 try { 9366 ITelephony service = getITelephony(); 9367 if (service != null) { 9368 service.setVoicemailVibrationEnabled(getOpPackageName(), phoneAccountHandle, 9369 enabled); 9370 } 9371 } catch (RemoteException e) { 9372 Log.e(TAG, "Error calling ITelephony#isVoicemailVibrationEnabled", e); 9373 } 9374 } 9375 9376 /** 9377 * Returns carrier id of the current subscription. 9378 * <p>To recognize a carrier (including MVNO) as a first-class identity, Android assigns each 9379 * carrier with a canonical integer a.k.a. carrier id. The carrier ID is an Android 9380 * platform-wide identifier for a carrier. AOSP maintains carrier ID assignments in 9381 * <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/carrier_list.textpb">here</a> 9382 * 9383 * <p>Apps which have carrier-specific configurations or business logic can use the carrier id 9384 * as an Android platform-wide identifier for carriers. 9385 * 9386 * @return Carrier id of the current subscription. Return {@link #UNKNOWN_CARRIER_ID} if the 9387 * subscription is unavailable or the carrier cannot be identified. 9388 */ getSimCarrierId()9389 public int getSimCarrierId() { 9390 try { 9391 ITelephony service = getITelephony(); 9392 if (service != null) { 9393 return service.getSubscriptionCarrierId(getSubId()); 9394 } 9395 } catch (RemoteException ex) { 9396 // This could happen if binder process crashes. 9397 } 9398 return UNKNOWN_CARRIER_ID; 9399 } 9400 9401 /** 9402 * Returns carrier id name of the current subscription. 9403 * <p>Carrier id name is a user-facing name of carrier id returned by 9404 * {@link #getSimCarrierId()}, usually the brand name of the subsidiary 9405 * (e.g. T-Mobile). Each carrier could configure multiple {@link #getSimOperatorName() SPN} but 9406 * should have a single carrier name. Carrier name is not a canonical identity, 9407 * use {@link #getSimCarrierId()} instead. 9408 * <p>The returned carrier name is unlocalized. 9409 * 9410 * @return Carrier name of the current subscription. Return {@code null} if the subscription is 9411 * unavailable or the carrier cannot be identified. 9412 */ getSimCarrierIdName()9413 public @Nullable CharSequence getSimCarrierIdName() { 9414 try { 9415 ITelephony service = getITelephony(); 9416 if (service != null) { 9417 return service.getSubscriptionCarrierName(getSubId()); 9418 } 9419 } catch (RemoteException ex) { 9420 // This could happen if binder process crashes. 9421 } 9422 return null; 9423 } 9424 9425 /** 9426 * Returns fine-grained carrier ID of the current subscription. 9427 * 9428 * A specific carrier ID can represent the fact that a carrier may be in effect an aggregation 9429 * of other carriers (ie in an MVNO type scenario) where each of these specific carriers which 9430 * are used to make up the actual carrier service may have different carrier configurations. 9431 * A specific carrier ID could also be used, for example, in a scenario where a carrier requires 9432 * different carrier configuration for different service offering such as a prepaid plan. 9433 * 9434 * the specific carrier ID would be used for configuration purposes, but apps wishing to know 9435 * about the carrier itself should use the regular carrier ID returned by 9436 * {@link #getSimCarrierId()}. 9437 * 9438 * e.g, Tracfone SIMs could return different specific carrier ID based on IMSI from current 9439 * subscription while carrier ID remains the same. 9440 * 9441 * <p>For carriers without fine-grained specific carrier ids, return {@link #getSimCarrierId()} 9442 * <p>Specific carrier ids are defined in the same way as carrier id 9443 * <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/carrier_list.textpb">here</a> 9444 * except each with a "parent" id linking to its top-level carrier id. 9445 * 9446 * @return Returns fine-grained carrier id of the current subscription. 9447 * Return {@link #UNKNOWN_CARRIER_ID} if the subscription is unavailable or the carrier cannot 9448 * be identified. 9449 */ getSimSpecificCarrierId()9450 public int getSimSpecificCarrierId() { 9451 try { 9452 ITelephony service = getITelephony(); 9453 if (service != null) { 9454 return service.getSubscriptionSpecificCarrierId(getSubId()); 9455 } 9456 } catch (RemoteException ex) { 9457 // This could happen if binder process crashes. 9458 } 9459 return UNKNOWN_CARRIER_ID; 9460 } 9461 9462 /** 9463 * Similar like {@link #getSimCarrierIdName()}, returns user-facing name of the 9464 * specific carrier id returned by {@link #getSimSpecificCarrierId()}. 9465 * 9466 * The specific carrier ID would be used for configuration purposes, but apps wishing to know 9467 * about the carrier itself should use the regular carrier ID returned by 9468 * {@link #getSimCarrierIdName()}. 9469 * 9470 * <p>The returned name is unlocalized. 9471 * 9472 * @return user-facing name of the subscription specific carrier id. Return {@code null} if the 9473 * subscription is unavailable or the carrier cannot be identified. 9474 */ getSimSpecificCarrierIdName()9475 public @Nullable CharSequence getSimSpecificCarrierIdName() { 9476 try { 9477 ITelephony service = getITelephony(); 9478 if (service != null) { 9479 return service.getSubscriptionSpecificCarrierName(getSubId()); 9480 } 9481 } catch (RemoteException ex) { 9482 // This could happen if binder process crashes. 9483 } 9484 return null; 9485 } 9486 9487 /** 9488 * Returns carrier id based on sim MCCMNC (returned by {@link #getSimOperator()}) only. 9489 * This is used for fallback when configurations/logic for exact carrier id 9490 * {@link #getSimCarrierId()} are not found. 9491 * 9492 * Android carrier id table <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/carrier_list.textpb">here</a> 9493 * can be updated out-of-band, its possible a MVNO (Mobile Virtual Network Operator) carrier 9494 * was not fully recognized and assigned to its MNO (Mobile Network Operator) carrier id 9495 * by default. After carrier id table update, a new carrier id was assigned. If apps don't 9496 * take the update with the new id, it might be helpful to always fallback by using carrier 9497 * id based on MCCMNC if there is no match. 9498 * 9499 * @return matching carrier id from sim MCCMNC. Return {@link #UNKNOWN_CARRIER_ID} if the 9500 * subscription is unavailable or the carrier cannot be identified. 9501 */ getCarrierIdFromSimMccMnc()9502 public int getCarrierIdFromSimMccMnc() { 9503 try { 9504 ITelephony service = getITelephony(); 9505 if (service != null) { 9506 return service.getCarrierIdFromMccMnc(getSlotIndex(), getSimOperator(), true); 9507 } 9508 } catch (RemoteException ex) { 9509 // This could happen if binder process crashes. 9510 } 9511 return UNKNOWN_CARRIER_ID; 9512 } 9513 9514 /** 9515 * Returns carrier id based on MCCMNC (returned by {@link #getSimOperator()}) only. This is 9516 * used for fallback when configurations/logic for exact carrier id {@link #getSimCarrierId()} 9517 * are not found. 9518 * 9519 * Android carrier id table <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/carrier_list.textpb">here</a> 9520 * can be updated out-of-band, its possible a MVNO (Mobile Virtual Network Operator) carrier 9521 * was not fully recognized and assigned to its MNO (Mobile Network Operator) carrier id 9522 * by default. After carrier id table update, a new carrier id was assigned. If apps don't 9523 * take the update with the new id, it might be helpful to always fallback by using carrier 9524 * id based on MCCMNC if there is no match. 9525 * 9526 * @return matching carrier id from passing MCCMNC. Return {@link #UNKNOWN_CARRIER_ID} if the 9527 * subscription is unavailable or the carrier cannot be identified. 9528 * @hide 9529 */ 9530 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getCarrierIdFromMccMnc(String mccmnc)9531 public int getCarrierIdFromMccMnc(String mccmnc) { 9532 try { 9533 ITelephony service = getITelephony(); 9534 if (service != null) { 9535 return service.getCarrierIdFromMccMnc(getSlotIndex(), mccmnc, false); 9536 } 9537 } catch (RemoteException ex) { 9538 // This could happen if binder process crashes. 9539 } 9540 return UNKNOWN_CARRIER_ID; 9541 } 9542 9543 /** 9544 * Return a list of certs in hex string from loaded carrier privileges access rules. 9545 * 9546 * @return a list of certificate in hex string. return {@code null} if there is no certs 9547 * or privilege rules are not loaded yet. 9548 * 9549 * <p>Requires Permission: 9550 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} 9551 * @hide 9552 */ 9553 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getCertsFromCarrierPrivilegeAccessRules()9554 public List<String> getCertsFromCarrierPrivilegeAccessRules() { 9555 try { 9556 ITelephony service = getITelephony(); 9557 if (service != null) { 9558 return service.getCertsFromCarrierPrivilegeAccessRules(getSubId()); 9559 } 9560 } catch (RemoteException ex) { 9561 // This could happen if binder process crashes. 9562 } 9563 return null; 9564 } 9565 9566 /** 9567 * Return the application ID for the uicc application type like {@link #APPTYPE_CSIM}. 9568 * All uicc applications are uniquely identified by application ID, represented by the hex 9569 * string. e.g, A00000015141434C00. See ETSI 102.221 and 101.220 9570 * <p>Requires Permission: 9571 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} 9572 * 9573 * @param appType the uicc app type. 9574 * @return Application ID for specified app type or {@code null} if no uicc or error. 9575 * @hide 9576 */ 9577 @Nullable 9578 @SystemApi 9579 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getAidForAppType(@iccAppType int appType)9580 public String getAidForAppType(@UiccAppType int appType) { 9581 return getAidForAppType(getSubId(), appType); 9582 } 9583 9584 /** 9585 * same as {@link #getAidForAppType(int)} 9586 * @hide 9587 */ getAidForAppType(int subId, int appType)9588 public String getAidForAppType(int subId, int appType) { 9589 try { 9590 ITelephony service = getITelephony(); 9591 if (service != null) { 9592 return service.getAidForAppType(subId, appType); 9593 } 9594 } catch (RemoteException e) { 9595 Log.e(TAG, "Error calling ITelephony#getAidForAppType", e); 9596 } 9597 return null; 9598 } 9599 9600 /** 9601 * Return the Electronic Serial Number. 9602 * 9603 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 9604 * 9605 * @return ESN or null if error. 9606 * @hide 9607 */ getEsn()9608 public String getEsn() { 9609 return getEsn(getSubId()); 9610 } 9611 9612 /** 9613 * Return the Electronic Serial Number. 9614 * 9615 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 9616 * 9617 * @param subId the subscription ID that this request applies to. 9618 * @return ESN or null if error. 9619 * @hide 9620 */ getEsn(int subId)9621 public String getEsn(int subId) { 9622 try { 9623 ITelephony service = getITelephony(); 9624 if (service != null) { 9625 return service.getEsn(subId); 9626 } 9627 } catch (RemoteException e) { 9628 Log.e(TAG, "Error calling ITelephony#getEsn", e); 9629 } 9630 return null; 9631 } 9632 9633 /** 9634 * Return the Preferred Roaming List Version 9635 * 9636 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 9637 * 9638 * @return PRLVersion or null if error. 9639 * @hide 9640 */ 9641 @SystemApi getCdmaPrlVersion()9642 public String getCdmaPrlVersion() { 9643 return getCdmaPrlVersion(getSubId()); 9644 } 9645 9646 /** 9647 * Return the Preferred Roaming List Version 9648 * 9649 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 9650 * 9651 * @param subId the subscription ID that this request applies to. 9652 * @return PRLVersion or null if error. 9653 * @hide 9654 */ getCdmaPrlVersion(int subId)9655 public String getCdmaPrlVersion(int subId) { 9656 try { 9657 ITelephony service = getITelephony(); 9658 if (service != null) { 9659 return service.getCdmaPrlVersion(subId); 9660 } 9661 } catch (RemoteException e) { 9662 Log.e(TAG, "Error calling ITelephony#getCdmaPrlVersion", e); 9663 } 9664 return null; 9665 } 9666 9667 /** 9668 * Get snapshot of Telephony histograms 9669 * @return List of Telephony histograms 9670 * Requires Permission: 9671 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 9672 * Or the calling app has carrier privileges. 9673 * @hide 9674 */ 9675 @SystemApi 9676 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getTelephonyHistograms()9677 public List<TelephonyHistogram> getTelephonyHistograms() { 9678 try { 9679 ITelephony service = getITelephony(); 9680 if (service != null) { 9681 return service.getTelephonyHistograms(); 9682 } 9683 } catch (RemoteException e) { 9684 Log.e(TAG, "Error calling ITelephony#getTelephonyHistograms", e); 9685 } 9686 return null; 9687 } 9688 9689 /** 9690 * Set the allowed carrier list for slotIndex 9691 * Require system privileges. In the future we may add this to carrier APIs. 9692 * 9693 * <p>Requires Permission: 9694 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} 9695 * 9696 * <p>This method works only on devices with {@link 9697 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 9698 * 9699 * @deprecated use setCarrierRestrictionRules instead 9700 * 9701 * @return The number of carriers set successfully. Should be length of 9702 * carrierList on success; -1 if carrierList null or on error. 9703 * @hide 9704 */ 9705 @SystemApi 9706 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers)9707 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) { 9708 if (carriers == null || !SubscriptionManager.isValidPhoneId(slotIndex)) { 9709 return -1; 9710 } 9711 // Execute the method setCarrierRestrictionRules with an empty excluded list and 9712 // indicating priority for the allowed list. 9713 CarrierRestrictionRules carrierRestrictionRules = CarrierRestrictionRules.newBuilder() 9714 .setAllowedCarriers(carriers) 9715 .setDefaultCarrierRestriction( 9716 CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED) 9717 .build(); 9718 9719 int result = setCarrierRestrictionRules(carrierRestrictionRules); 9720 9721 // Convert result into int, as required by this method. 9722 if (result == SET_CARRIER_RESTRICTION_SUCCESS) { 9723 return carriers.size(); 9724 } else { 9725 return -1; 9726 } 9727 } 9728 9729 /** 9730 * The carrier restrictions were successfully set. 9731 * @hide 9732 */ 9733 @SystemApi 9734 public static final int SET_CARRIER_RESTRICTION_SUCCESS = 0; 9735 9736 /** 9737 * The carrier restrictions were not set due to lack of support in the modem. This can happen 9738 * if the modem does not support setting the carrier restrictions or if the configuration 9739 * passed in the {@code setCarrierRestrictionRules} is not supported by the modem. 9740 * @hide 9741 */ 9742 @SystemApi 9743 public static final int SET_CARRIER_RESTRICTION_NOT_SUPPORTED = 1; 9744 9745 /** 9746 * The setting of carrier restrictions failed. 9747 * @hide 9748 */ 9749 @SystemApi 9750 public static final int SET_CARRIER_RESTRICTION_ERROR = 2; 9751 9752 /** @hide */ 9753 @Retention(RetentionPolicy.SOURCE) 9754 @IntDef(prefix = {"SET_CARRIER_RESTRICTION_"}, 9755 value = { 9756 SET_CARRIER_RESTRICTION_SUCCESS, 9757 SET_CARRIER_RESTRICTION_NOT_SUPPORTED, 9758 SET_CARRIER_RESTRICTION_ERROR 9759 }) 9760 public @interface SetCarrierRestrictionResult {} 9761 9762 /** 9763 * Set the allowed carrier list and the excluded carrier list indicating the priority between 9764 * the two lists. 9765 * Requires system privileges. 9766 * 9767 * <p>Requires Permission: 9768 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} 9769 * 9770 * <p>This method works only on devices with {@link 9771 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 9772 * 9773 * @return {@link #SET_CARRIER_RESTRICTION_SUCCESS} in case of success. 9774 * {@link #SET_CARRIER_RESTRICTION_NOT_SUPPORTED} if the modem does not support the 9775 * configuration. {@link #SET_CARRIER_RESTRICTION_ERROR} in all other error cases. 9776 * @hide 9777 */ 9778 @SystemApi 9779 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 9780 @SetCarrierRestrictionResult setCarrierRestrictionRules(@onNull CarrierRestrictionRules rules)9781 public int setCarrierRestrictionRules(@NonNull CarrierRestrictionRules rules) { 9782 try { 9783 ITelephony service = getITelephony(); 9784 if (service != null) { 9785 return service.setAllowedCarriers(rules); 9786 } 9787 } catch (RemoteException e) { 9788 Log.e(TAG, "Error calling ITelephony#setAllowedCarriers", e); 9789 } catch (NullPointerException e) { 9790 Log.e(TAG, "Error calling ITelephony#setAllowedCarriers", e); 9791 } 9792 return SET_CARRIER_RESTRICTION_ERROR; 9793 } 9794 9795 /** 9796 * Get the allowed carrier list for slotIndex. 9797 * Requires system privileges. 9798 * 9799 * <p>This method returns valid data on devices with {@link 9800 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 9801 * 9802 * @deprecated Apps should use {@link getCarriersRestrictionRules} to retrieve the list of 9803 * allowed and excliuded carriers, as the result of this API is valid only when the excluded 9804 * list is empty. This API could return an empty list, even if some restrictions are present. 9805 * 9806 * @return List of {@link android.telephony.CarrierIdentifier}; empty list 9807 * means all carriers are allowed. 9808 * @hide 9809 */ 9810 @Deprecated 9811 @SystemApi 9812 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getAllowedCarriers(int slotIndex)9813 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) { 9814 if (SubscriptionManager.isValidPhoneId(slotIndex)) { 9815 CarrierRestrictionRules carrierRestrictionRule = getCarrierRestrictionRules(); 9816 if (carrierRestrictionRule != null) { 9817 return carrierRestrictionRule.getAllowedCarriers(); 9818 } 9819 } 9820 return new ArrayList<CarrierIdentifier>(0); 9821 } 9822 9823 /** 9824 * Get the allowed carrier list and the excluded carrier list indicating the priority between 9825 * the two lists. 9826 * Require system privileges. In the future we may add this to carrier APIs. 9827 * 9828 * <p>This method returns valid data on devices with {@link 9829 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 9830 * 9831 * @return {@link CarrierRestrictionRules} which contains the allowed carrier list and the 9832 * excluded carrier list with the priority between the two lists. Returns {@code null} 9833 * in case of error. 9834 * @hide 9835 */ 9836 @SystemApi 9837 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 9838 @Nullable getCarrierRestrictionRules()9839 public CarrierRestrictionRules getCarrierRestrictionRules() { 9840 try { 9841 ITelephony service = getITelephony(); 9842 if (service != null) { 9843 return service.getAllowedCarriers(); 9844 } 9845 } catch (RemoteException e) { 9846 Log.e(TAG, "Error calling ITelephony#getAllowedCarriers", e); 9847 } catch (NullPointerException e) { 9848 Log.e(TAG, "Error calling ITelephony#getAllowedCarriers", e); 9849 } 9850 return null; 9851 } 9852 9853 /** 9854 * Used to enable or disable carrier data by the system based on carrier signalling or 9855 * carrier privileged apps. Different from {@link #setDataEnabled(boolean)} which is linked to 9856 * user settings, carrier data on/off won't affect user settings but will bypass the 9857 * settings and turns off data internally if set to {@code false}. 9858 * 9859 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 9860 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 9861 * 9862 * <p>Requires Permission: 9863 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 9864 * 9865 * @param enabled control enable or disable carrier data. 9866 * @hide 9867 */ 9868 @SystemApi 9869 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setCarrierDataEnabled(boolean enabled)9870 public void setCarrierDataEnabled(boolean enabled) { 9871 try { 9872 ITelephony service = getITelephony(); 9873 if (service != null) { 9874 service.carrierActionSetMeteredApnsEnabled( 9875 getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), enabled); 9876 } 9877 } catch (RemoteException e) { 9878 Log.e(TAG, "Error calling ITelephony#setCarrierDataEnabled", e); 9879 } 9880 } 9881 9882 /** 9883 * Action set from carrier signalling broadcast receivers to enable/disable radio 9884 * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required 9885 * @param subId the subscription ID that this action applies to. 9886 * @param enabled control enable or disable radio. 9887 * @hide 9888 */ carrierActionSetRadioEnabled(int subId, boolean enabled)9889 public void carrierActionSetRadioEnabled(int subId, boolean enabled) { 9890 try { 9891 ITelephony service = getITelephony(); 9892 if (service != null) { 9893 service.carrierActionSetRadioEnabled(subId, enabled); 9894 } 9895 } catch (RemoteException e) { 9896 Log.e(TAG, "Error calling ITelephony#carrierActionSetRadioEnabled", e); 9897 } 9898 } 9899 9900 /** 9901 * Action set from carrier signalling broadcast receivers to start/stop reporting default 9902 * network available events 9903 * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required 9904 * @param subId the subscription ID that this action applies to. 9905 * @param report control start/stop reporting network status. 9906 * @hide 9907 */ carrierActionReportDefaultNetworkStatus(int subId, boolean report)9908 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { 9909 try { 9910 ITelephony service = getITelephony(); 9911 if (service != null) { 9912 service.carrierActionReportDefaultNetworkStatus(subId, report); 9913 } 9914 } catch (RemoteException e) { 9915 Log.e(TAG, "Error calling ITelephony#carrierActionReportDefaultNetworkStatus", e); 9916 } 9917 } 9918 9919 /** 9920 * Action set from carrier signalling broadcast receivers to reset all carrier actions 9921 * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required 9922 * @param subId the subscription ID that this action applies to. 9923 * @hide 9924 */ carrierActionResetAll(int subId)9925 public void carrierActionResetAll(int subId) { 9926 try { 9927 ITelephony service = getITelephony(); 9928 if (service != null) { 9929 service.carrierActionResetAll(subId); 9930 } 9931 } catch (RemoteException e) { 9932 Log.e(TAG, "Error calling ITelephony#carrierActionResetAll", e); 9933 } 9934 } 9935 9936 /** 9937 * Get aggregated video call data usage since boot. 9938 * Permissions android.Manifest.permission.READ_NETWORK_USAGE_HISTORY is required. 9939 * 9940 * @param how one of the NetworkStats.STATS_PER_* constants depending on whether the request is 9941 * for data usage per uid or overall usage. 9942 * @return Snapshot of video call data usage 9943 * @hide 9944 */ getVtDataUsage(int how)9945 public NetworkStats getVtDataUsage(int how) { 9946 boolean perUidStats = (how == NetworkStats.STATS_PER_UID); 9947 try { 9948 ITelephony service = getITelephony(); 9949 if (service != null) { 9950 return service.getVtDataUsage(getSubId(), perUidStats); 9951 } 9952 } catch (RemoteException e) { 9953 Log.e(TAG, "Error calling ITelephony#getVtDataUsage", e); 9954 } 9955 return null; 9956 } 9957 9958 /** 9959 * Policy control of data connection. Usually used when data limit is passed. 9960 * @param enabled True if enabling the data, otherwise disabling. 9961 * @param subId sub id 9962 * @hide 9963 */ setPolicyDataEnabled(boolean enabled, int subId)9964 public void setPolicyDataEnabled(boolean enabled, int subId) { 9965 try { 9966 ITelephony service = getITelephony(); 9967 if (service != null) { 9968 service.setPolicyDataEnabled(enabled, subId); 9969 } 9970 } catch (RemoteException e) { 9971 Log.e(TAG, "Error calling ITelephony#setPolicyDataEnabled", e); 9972 } 9973 } 9974 9975 /** 9976 * Get Client request stats which will contain statistical information 9977 * on each request made by client. 9978 * Callers require either READ_PRIVILEGED_PHONE_STATE or 9979 * READ_PHONE_STATE to retrieve the information. 9980 * @param subId sub id 9981 * @return List of Client Request Stats 9982 * @hide 9983 */ getClientRequestStats(int subId)9984 public List<ClientRequestStats> getClientRequestStats(int subId) { 9985 try { 9986 ITelephony service = getITelephony(); 9987 if (service != null) { 9988 return service.getClientRequestStats(getOpPackageName(), subId); 9989 } 9990 } catch (RemoteException e) { 9991 Log.e(TAG, "Error calling ITelephony#getClientRequestStats", e); 9992 } 9993 9994 return null; 9995 } 9996 9997 /** 9998 * Checks if phone is in emergency callback mode. 9999 * 10000 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 10001 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 10002 * 10003 * @return true if phone is in emergency callback mode. 10004 * @hide 10005 */ 10006 @SystemApi 10007 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getEmergencyCallbackMode()10008 public boolean getEmergencyCallbackMode() { 10009 return getEmergencyCallbackMode(getSubId()); 10010 } 10011 10012 /** 10013 * Check if phone is in emergency callback mode 10014 * @return true if phone is in emergency callback mode 10015 * @param subId the subscription ID that this action applies to. 10016 * @hide 10017 */ getEmergencyCallbackMode(int subId)10018 public boolean getEmergencyCallbackMode(int subId) { 10019 try { 10020 ITelephony telephony = getITelephony(); 10021 if (telephony == null) { 10022 return false; 10023 } 10024 return telephony.getEmergencyCallbackMode(subId); 10025 } catch (RemoteException e) { 10026 Log.e(TAG, "Error calling ITelephony#getEmergencyCallbackMode", e); 10027 } 10028 return false; 10029 } 10030 10031 /** 10032 * Checks if manual network selection is allowed. 10033 * 10034 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 10035 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()}. 10036 * 10037 * @return {@code true} if manual network selection is allowed, otherwise return {@code false}. 10038 * 10039 * @hide 10040 */ 10041 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) isManualNetworkSelectionAllowed()10042 public boolean isManualNetworkSelectionAllowed() { 10043 try { 10044 ITelephony telephony = getITelephony(); 10045 if (telephony != null) { 10046 return telephony.isManualNetworkSelectionAllowed(getSubId()); 10047 } 10048 } catch (RemoteException e) { 10049 Log.e(TAG, "Error calling ITelephony#isManualNetworkSelectionAllowed", e); 10050 } 10051 return true; 10052 } 10053 10054 /** 10055 * Get the most recently available signal strength information. 10056 * 10057 * Get the most recent SignalStrength information reported by the modem. Due 10058 * to power saving this information may not always be current. 10059 * @return the most recent cached signal strength info from the modem 10060 */ 10061 @Nullable getSignalStrength()10062 public SignalStrength getSignalStrength() { 10063 try { 10064 ITelephony service = getITelephony(); 10065 if (service != null) { 10066 return service.getSignalStrength(getSubId()); 10067 } 10068 } catch (RemoteException e) { 10069 Log.e(TAG, "Error calling ITelephony#getSignalStrength", e); 10070 } 10071 return null; 10072 } 10073 10074 /** 10075 * @hide 10076 * It's similar to isDataEnabled, but unlike isDataEnabled, this API also evaluates 10077 * carrierDataEnabled, policyDataEnabled etc to give a final decision of whether mobile data is 10078 * capable of using. 10079 */ isDataCapable()10080 public boolean isDataCapable() { 10081 boolean retVal = false; 10082 try { 10083 int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId()); 10084 ITelephony telephony = getITelephony(); 10085 if (telephony != null) 10086 retVal = telephony.isDataEnabled(subId); 10087 } catch (RemoteException e) { 10088 Log.e(TAG, "Error calling ITelephony#isDataEnabled", e); 10089 } catch (NullPointerException e) { 10090 } 10091 return retVal; 10092 } 10093 10094 /** 10095 * In this mode, modem will not send specified indications when screen is off. 10096 * @hide 10097 */ 10098 public static final int INDICATION_UPDATE_MODE_NORMAL = 1; 10099 10100 /** 10101 * In this mode, modem will still send specified indications when screen is off. 10102 * @hide 10103 */ 10104 public static final int INDICATION_UPDATE_MODE_IGNORE_SCREEN_OFF = 2; 10105 10106 /** @hide */ 10107 @IntDef(prefix = { "INDICATION_UPDATE_MODE_" }, value = { 10108 INDICATION_UPDATE_MODE_NORMAL, 10109 INDICATION_UPDATE_MODE_IGNORE_SCREEN_OFF 10110 }) 10111 @Retention(RetentionPolicy.SOURCE) 10112 public @interface IndicationUpdateMode{} 10113 10114 /** 10115 * The indication for signal strength update. 10116 * @hide 10117 */ 10118 public static final int INDICATION_FILTER_SIGNAL_STRENGTH = 0x1; 10119 10120 /** 10121 * The indication for full network state update. 10122 * @hide 10123 */ 10124 public static final int INDICATION_FILTER_FULL_NETWORK_STATE = 0x2; 10125 10126 /** 10127 * The indication for data call dormancy changed update. 10128 * @hide 10129 */ 10130 public static final int INDICATION_FILTER_DATA_CALL_DORMANCY_CHANGED = 0x4; 10131 10132 /** 10133 * The indication for link capacity estimate update. 10134 * @hide 10135 */ 10136 public static final int INDICATION_FILTER_LINK_CAPACITY_ESTIMATE = 0x8; 10137 10138 /** 10139 * The indication for physical channel config update. 10140 * @hide 10141 */ 10142 public static final int INDICATION_FILTER_PHYSICAL_CHANNEL_CONFIG = 0x10; 10143 10144 /** @hide */ 10145 @IntDef(flag = true, prefix = { "INDICATION_FILTER_" }, value = { 10146 INDICATION_FILTER_SIGNAL_STRENGTH, 10147 INDICATION_FILTER_FULL_NETWORK_STATE, 10148 INDICATION_FILTER_DATA_CALL_DORMANCY_CHANGED, 10149 INDICATION_FILTER_LINK_CAPACITY_ESTIMATE, 10150 INDICATION_FILTER_PHYSICAL_CHANNEL_CONFIG 10151 }) 10152 @Retention(RetentionPolicy.SOURCE) 10153 public @interface IndicationFilters{} 10154 10155 /** 10156 * Sets radio indication update mode. This can be used to control the behavior of indication 10157 * update from modem to Android frameworks. For example, by default several indication updates 10158 * are turned off when screen is off, but in some special cases (e.g. carkit is connected but 10159 * screen is off) we want to turn on those indications even when the screen is off. 10160 * 10161 * <p>Requires Permission: 10162 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 10163 * 10164 * @param filters Indication filters. Should be a bitmask of INDICATION_FILTER_XXX. 10165 * @see #INDICATION_FILTER_SIGNAL_STRENGTH 10166 * @see #INDICATION_FILTER_FULL_NETWORK_STATE 10167 * @see #INDICATION_FILTER_DATA_CALL_DORMANCY_CHANGED 10168 * @param updateMode The voice activation state 10169 * @see #INDICATION_UPDATE_MODE_NORMAL 10170 * @see #INDICATION_UPDATE_MODE_IGNORE_SCREEN_OFF 10171 * @hide 10172 */ 10173 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setRadioIndicationUpdateMode(@ndicationFilters int filters, @IndicationUpdateMode int updateMode)10174 public void setRadioIndicationUpdateMode(@IndicationFilters int filters, 10175 @IndicationUpdateMode int updateMode) { 10176 try { 10177 ITelephony telephony = getITelephony(); 10178 if (telephony != null) { 10179 telephony.setRadioIndicationUpdateMode(getSubId(), filters, updateMode); 10180 } 10181 } catch (RemoteException ex) { 10182 // This could happen if binder process crashes. 10183 if (!isSystemProcess()) { 10184 ex.rethrowAsRuntimeException(); 10185 } 10186 } 10187 } 10188 10189 /** 10190 * A test API to override carrier information including mccmnc, imsi, iccid, gid1, gid2, 10191 * plmn and spn. This would be handy for, eg, forcing a particular carrier id, carrier's config 10192 * (also any country or carrier overlays) to be loaded when using a test SIM with a call box. 10193 * 10194 * <p>Requires Permission: 10195 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 10196 * 10197 * 10198 * @deprecated 10199 * @hide 10200 */ 10201 @Deprecated 10202 @TestApi setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, String gid2, String plmn, String spn)10203 public void setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, 10204 String gid2, String plmn, String spn) { 10205 try { 10206 ITelephony telephony = getITelephony(); 10207 if (telephony != null) { 10208 telephony.setCarrierTestOverride( 10209 getSubId(), mccmnc, imsi, iccid, gid1, gid2, plmn, spn, 10210 null, null); 10211 } 10212 } catch (RemoteException ex) { 10213 // This could happen if binder process crashes. 10214 } 10215 } 10216 10217 /** 10218 * A test API to override carrier information including mccmnc, imsi, iccid, gid1, gid2, 10219 * plmn, spn, apn and carrier priviledge. This would be handy for, eg, forcing a particular 10220 * carrier id, carrier's config (also any country or carrier overlays) to be loaded when using 10221 * a test SIM with a call box. 10222 * 10223 * <p>Requires Permission: 10224 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 10225 * 10226 * @hide 10227 */ 10228 @TestApi setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, String gid2, String plmn, String spn, String carrierPriviledgeRules, String apn)10229 public void setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, 10230 String gid2, String plmn, String spn, 10231 String carrierPriviledgeRules, String apn) { 10232 try { 10233 ITelephony telephony = getITelephony(); 10234 if (telephony != null) { 10235 telephony.setCarrierTestOverride( 10236 getSubId(), mccmnc, imsi, iccid, gid1, gid2, plmn, spn, 10237 carrierPriviledgeRules, apn); 10238 } 10239 } catch (RemoteException ex) { 10240 // This could happen if binder process crashes. 10241 } 10242 } 10243 10244 /** 10245 * A test API to return installed carrier id list version 10246 * 10247 * <p>Requires Permission: 10248 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 10249 * 10250 * @hide 10251 */ 10252 @TestApi getCarrierIdListVersion()10253 public int getCarrierIdListVersion() { 10254 try { 10255 ITelephony telephony = getITelephony(); 10256 if (telephony != null) { 10257 return telephony.getCarrierIdListVersion(getSubId()); 10258 } 10259 } catch (RemoteException ex) { 10260 // This could happen if binder process crashes. 10261 } 10262 return UNKNOWN_CARRIER_ID_LIST_VERSION; 10263 } 10264 10265 /** 10266 * How many modems can have simultaneous data connections. 10267 * @hide 10268 */ 10269 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getNumberOfModemsWithSimultaneousDataConnections()10270 public int getNumberOfModemsWithSimultaneousDataConnections() { 10271 try { 10272 ITelephony telephony = getITelephony(); 10273 if (telephony != null) { 10274 return telephony.getNumberOfModemsWithSimultaneousDataConnections( 10275 getSubId(), getOpPackageName()); 10276 } 10277 } catch (RemoteException ex) { 10278 // This could happen if binder process crashes. 10279 } 10280 return 0; 10281 } 10282 10283 /** 10284 * Enable or disable OpportunisticNetworkService. 10285 * 10286 * This method should be called to enable or disable 10287 * OpportunisticNetwork service on the device. 10288 * 10289 * <p> 10290 * Requires Permission: 10291 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 10292 * 10293 * @param enable enable(True) or disable(False) 10294 * @return returns true if successfully set. 10295 * @hide 10296 */ 10297 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setOpportunisticNetworkState(boolean enable)10298 public boolean setOpportunisticNetworkState(boolean enable) { 10299 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 10300 boolean ret = false; 10301 try { 10302 IOns iOpportunisticNetworkService = getIOns(); 10303 if (iOpportunisticNetworkService != null) { 10304 ret = iOpportunisticNetworkService.setEnable(enable, pkgForDebug); 10305 } 10306 } catch (RemoteException ex) { 10307 Rlog.e(TAG, "enableOpportunisticNetwork RemoteException", ex); 10308 } 10309 10310 return ret; 10311 } 10312 10313 /** 10314 * is OpportunisticNetworkService enabled 10315 * 10316 * This method should be called to determine if the OpportunisticNetworkService is 10317 * enabled 10318 * 10319 * <p> 10320 * Requires Permission: 10321 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 10322 * @hide 10323 */ 10324 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) isOpportunisticNetworkEnabled()10325 public boolean isOpportunisticNetworkEnabled() { 10326 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 10327 boolean isEnabled = false; 10328 10329 try { 10330 IOns iOpportunisticNetworkService = getIOns(); 10331 if (iOpportunisticNetworkService != null) { 10332 isEnabled = iOpportunisticNetworkService.isEnabled(pkgForDebug); 10333 } 10334 } catch (RemoteException ex) { 10335 Rlog.e(TAG, "enableOpportunisticNetwork RemoteException", ex); 10336 } 10337 10338 return isEnabled; 10339 } 10340 10341 /** @hide */ 10342 @Retention(RetentionPolicy.SOURCE) 10343 @LongDef(flag = true, prefix = {"NETWORK_TYPE_BITMASK_"}, 10344 value = {NETWORK_TYPE_BITMASK_UNKNOWN, 10345 NETWORK_TYPE_BITMASK_GSM, 10346 NETWORK_TYPE_BITMASK_GPRS, 10347 NETWORK_TYPE_BITMASK_EDGE, 10348 NETWORK_TYPE_BITMASK_CDMA, 10349 NETWORK_TYPE_BITMASK_1xRTT, 10350 NETWORK_TYPE_BITMASK_EVDO_0, 10351 NETWORK_TYPE_BITMASK_EVDO_A, 10352 NETWORK_TYPE_BITMASK_EVDO_B, 10353 NETWORK_TYPE_BITMASK_EHRPD, 10354 NETWORK_TYPE_BITMASK_HSUPA, 10355 NETWORK_TYPE_BITMASK_HSDPA, 10356 NETWORK_TYPE_BITMASK_HSPA, 10357 NETWORK_TYPE_BITMASK_HSPAP, 10358 NETWORK_TYPE_BITMASK_UMTS, 10359 NETWORK_TYPE_BITMASK_TD_SCDMA, 10360 NETWORK_TYPE_BITMASK_LTE, 10361 NETWORK_TYPE_BITMASK_LTE_CA, 10362 NETWORK_TYPE_BITMASK_NR, 10363 }) 10364 public @interface NetworkTypeBitMask {} 10365 10366 // 2G 10367 /** 10368 * network type bitmask unknown. 10369 * @hide 10370 */ 10371 @SystemApi 10372 public static final long NETWORK_TYPE_BITMASK_UNKNOWN = 0L; 10373 /** 10374 * network type bitmask indicating the support of radio tech GSM. 10375 * @hide 10376 */ 10377 @SystemApi 10378 public static final long NETWORK_TYPE_BITMASK_GSM = (1 << (NETWORK_TYPE_GSM -1)); 10379 /** 10380 * network type bitmask indicating the support of radio tech GPRS. 10381 * @hide 10382 */ 10383 @SystemApi 10384 public static final long NETWORK_TYPE_BITMASK_GPRS = (1 << (NETWORK_TYPE_GPRS -1)); 10385 /** 10386 * network type bitmask indicating the support of radio tech EDGE. 10387 * @hide 10388 */ 10389 @SystemApi 10390 public static final long NETWORK_TYPE_BITMASK_EDGE = (1 << (NETWORK_TYPE_EDGE -1)); 10391 /** 10392 * network type bitmask indicating the support of radio tech CDMA(IS95A/IS95B). 10393 * @hide 10394 */ 10395 @SystemApi 10396 public static final long NETWORK_TYPE_BITMASK_CDMA = (1 << (NETWORK_TYPE_CDMA -1)); 10397 /** 10398 * network type bitmask indicating the support of radio tech 1xRTT. 10399 * @hide 10400 */ 10401 @SystemApi 10402 public static final long NETWORK_TYPE_BITMASK_1xRTT = (1 << (NETWORK_TYPE_1xRTT - 1)); 10403 // 3G 10404 /** 10405 * network type bitmask indicating the support of radio tech EVDO 0. 10406 * @hide 10407 */ 10408 @SystemApi 10409 public static final long NETWORK_TYPE_BITMASK_EVDO_0 = (1 << (NETWORK_TYPE_EVDO_0 -1)); 10410 /** 10411 * network type bitmask indicating the support of radio tech EVDO A. 10412 * @hide 10413 */ 10414 @SystemApi 10415 public static final long NETWORK_TYPE_BITMASK_EVDO_A = (1 << (NETWORK_TYPE_EVDO_A - 1)); 10416 /** 10417 * network type bitmask indicating the support of radio tech EVDO B. 10418 * @hide 10419 */ 10420 @SystemApi 10421 public static final long NETWORK_TYPE_BITMASK_EVDO_B = (1 << (NETWORK_TYPE_EVDO_B -1)); 10422 /** 10423 * network type bitmask indicating the support of radio tech EHRPD. 10424 * @hide 10425 */ 10426 @SystemApi 10427 public static final long NETWORK_TYPE_BITMASK_EHRPD = (1 << (NETWORK_TYPE_EHRPD -1)); 10428 /** 10429 * network type bitmask indicating the support of radio tech HSUPA. 10430 * @hide 10431 */ 10432 @SystemApi 10433 public static final long NETWORK_TYPE_BITMASK_HSUPA = (1 << (NETWORK_TYPE_HSUPA -1)); 10434 /** 10435 * network type bitmask indicating the support of radio tech HSDPA. 10436 * @hide 10437 */ 10438 @SystemApi 10439 public static final long NETWORK_TYPE_BITMASK_HSDPA = (1 << (NETWORK_TYPE_HSDPA -1)); 10440 /** 10441 * network type bitmask indicating the support of radio tech HSPA. 10442 * @hide 10443 */ 10444 @SystemApi 10445 public static final long NETWORK_TYPE_BITMASK_HSPA = (1 << (NETWORK_TYPE_HSPA -1)); 10446 /** 10447 * network type bitmask indicating the support of radio tech HSPAP. 10448 * @hide 10449 */ 10450 @SystemApi 10451 public static final long NETWORK_TYPE_BITMASK_HSPAP = (1 << (NETWORK_TYPE_HSPAP -1)); 10452 /** 10453 * network type bitmask indicating the support of radio tech UMTS. 10454 * @hide 10455 */ 10456 @SystemApi 10457 public static final long NETWORK_TYPE_BITMASK_UMTS = (1 << (NETWORK_TYPE_UMTS -1)); 10458 /** 10459 * network type bitmask indicating the support of radio tech TD_SCDMA. 10460 * @hide 10461 */ 10462 @SystemApi 10463 public static final long NETWORK_TYPE_BITMASK_TD_SCDMA = (1 << (NETWORK_TYPE_TD_SCDMA -1)); 10464 // 4G 10465 /** 10466 * network type bitmask indicating the support of radio tech LTE. 10467 * @hide 10468 */ 10469 @SystemApi 10470 public static final long NETWORK_TYPE_BITMASK_LTE = (1 << (NETWORK_TYPE_LTE -1)); 10471 /** 10472 * network type bitmask indicating the support of radio tech LTE CA (carrier aggregation). 10473 * @hide 10474 */ 10475 @SystemApi 10476 public static final long NETWORK_TYPE_BITMASK_LTE_CA = (1 << (NETWORK_TYPE_LTE_CA -1)); 10477 10478 /** 10479 * network type bitmask indicating the support of radio tech NR(New Radio) 5G. 10480 * @hide 10481 */ 10482 @SystemApi 10483 public static final long NETWORK_TYPE_BITMASK_NR = (1 << (NETWORK_TYPE_NR -1)); 10484 10485 /** 10486 * network type bitmask indicating the support of radio tech IWLAN. 10487 * @hide 10488 */ 10489 @SystemApi 10490 public static final long NETWORK_TYPE_BITMASK_IWLAN = (1 << (NETWORK_TYPE_IWLAN -1)); 10491 10492 /** 10493 * @return Modem supported radio access family bitmask 10494 * 10495 * <p>Requires permission: {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} or 10496 * that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 10497 * @hide 10498 */ 10499 @SystemApi 10500 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getSupportedRadioAccessFamily()10501 public @NetworkTypeBitMask long getSupportedRadioAccessFamily() { 10502 try { 10503 ITelephony telephony = getITelephony(); 10504 if (telephony != null) { 10505 return (long) telephony.getRadioAccessFamily(getSlotIndex(), getOpPackageName()); 10506 } else { 10507 // This can happen when the ITelephony interface is not up yet. 10508 return NETWORK_TYPE_BITMASK_UNKNOWN; 10509 } 10510 } catch (RemoteException ex) { 10511 // This shouldn't happen in the normal case 10512 return NETWORK_TYPE_BITMASK_UNKNOWN; 10513 } catch (NullPointerException ex) { 10514 // This could happen before phone restarts due to crashing 10515 return NETWORK_TYPE_BITMASK_UNKNOWN; 10516 } 10517 } 10518 10519 /** 10520 * Returns whether {@link TelephonyManager#ACTION_EMERGENCY_ASSISTANCE emergency assistance} is 10521 * available on the device. 10522 * <p> 10523 * Requires permission: {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} 10524 * 10525 * @return {@code true} if emergency assistance is available, {@code false} otherwise 10526 * 10527 * @hide 10528 */ 10529 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 10530 @SystemApi isEmergencyAssistanceEnabled()10531 public boolean isEmergencyAssistanceEnabled() { 10532 mContext.enforceCallingOrSelfPermission( 10533 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 10534 "isEmergencyAssistanceEnabled"); 10535 return EMERGENCY_ASSISTANCE_ENABLED; 10536 } 10537 10538 /** 10539 * Get the emergency number list based on current locale, sim, default, modem and network. 10540 * 10541 * <p>In each returned list, the emergency number {@link EmergencyNumber} coming from higher 10542 * priority sources will be located at the smaller index; the priority order of sources are: 10543 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_NETWORK_SIGNALING} > 10544 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_SIM} > 10545 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_DATABASE} > 10546 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_DEFAULT} > 10547 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_MODEM_CONFIG} 10548 * 10549 * <p>The subscriptions which the returned list would be based on, are all the active 10550 * subscriptions, no matter which subscription could be used to create TelephonyManager. 10551 * 10552 * <p>Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling 10553 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 10554 * 10555 * @return Map including the keys as the active subscription IDs (Note: if there is no active 10556 * subscription, the key is {@link SubscriptionManager#getDefaultSubscriptionId}) and the value 10557 * as the list of {@link EmergencyNumber}; empty Map if this information is not available; 10558 * or throw a SecurityException if the caller does not have the permission. 10559 */ 10560 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 10561 @NonNull getEmergencyNumberList()10562 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList() { 10563 Map<Integer, List<EmergencyNumber>> emergencyNumberList = new HashMap<>(); 10564 try { 10565 ITelephony telephony = getITelephony(); 10566 if (telephony != null) { 10567 return telephony.getEmergencyNumberList(mContext.getOpPackageName()); 10568 } else { 10569 throw new IllegalStateException("telephony service is null."); 10570 } 10571 } catch (RemoteException ex) { 10572 Log.e(TAG, "getEmergencyNumberList RemoteException", ex); 10573 ex.rethrowAsRuntimeException(); 10574 } 10575 return emergencyNumberList; 10576 } 10577 10578 /** 10579 * Get the per-category emergency number list based on current locale, sim, default, modem 10580 * and network. 10581 * 10582 * <p>In each returned list, the emergency number {@link EmergencyNumber} coming from higher 10583 * priority sources will be located at the smaller index; the priority order of sources are: 10584 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_NETWORK_SIGNALING} > 10585 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_SIM} > 10586 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_DATABASE} > 10587 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_DEFAULT} > 10588 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_MODEM_CONFIG} 10589 * 10590 * <p>The subscriptions which the returned list would be based on, are all the active 10591 * subscriptions, no matter which subscription could be used to create TelephonyManager. 10592 * 10593 * <p>Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling 10594 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 10595 * 10596 * @param categories the emergency service categories which are the bitwise-OR combination of 10597 * the following constants: 10598 * <ol> 10599 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED} </li> 10600 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_POLICE} </li> 10601 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_AMBULANCE} </li> 10602 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_FIRE_BRIGADE} </li> 10603 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_MARINE_GUARD} </li> 10604 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_MOUNTAIN_RESCUE} </li> 10605 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_MIEC} </li> 10606 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_AIEC} </li> 10607 * </ol> 10608 * @return Map including the keys as the active subscription IDs (Note: if there is no active 10609 * subscription, the key is {@link SubscriptionManager#getDefaultSubscriptionId}) and the value 10610 * as the list of {@link EmergencyNumber}; empty Map if this information is not available; 10611 * or throw a SecurityException if the caller does not have the permission. 10612 */ 10613 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 10614 @NonNull getEmergencyNumberList( @mergencyServiceCategories int categories)10615 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( 10616 @EmergencyServiceCategories int categories) { 10617 Map<Integer, List<EmergencyNumber>> emergencyNumberList = new HashMap<>(); 10618 try { 10619 ITelephony telephony = getITelephony(); 10620 if (telephony != null) { 10621 emergencyNumberList = telephony.getEmergencyNumberList( 10622 mContext.getOpPackageName()); 10623 if (emergencyNumberList != null) { 10624 for (Integer subscriptionId : emergencyNumberList.keySet()) { 10625 List<EmergencyNumber> numberList = emergencyNumberList.get(subscriptionId); 10626 for (EmergencyNumber number : numberList) { 10627 if (!number.isInEmergencyServiceCategories(categories)) { 10628 numberList.remove(number); 10629 } 10630 } 10631 } 10632 } 10633 return emergencyNumberList; 10634 } else { 10635 throw new IllegalStateException("telephony service is null."); 10636 } 10637 } catch (RemoteException ex) { 10638 Log.e(TAG, "getEmergencyNumberList with Categories RemoteException", ex); 10639 ex.rethrowAsRuntimeException(); 10640 } 10641 return emergencyNumberList; 10642 } 10643 10644 /** 10645 * Identifies if the supplied phone number is an emergency number that matches a known 10646 * emergency number based on current locale, SIM card(s), Android database, modem, network, 10647 * or defaults. 10648 * 10649 * <p>This method assumes that only dialable phone numbers are passed in; non-dialable 10650 * numbers are not considered emergency numbers. A dialable phone number consists only 10651 * of characters/digits identified by {@link PhoneNumberUtils#isDialable(char)}. 10652 * 10653 * <p>The subscriptions which the identification would be based on, are all the active 10654 * subscriptions, no matter which subscription could be used to create TelephonyManager. 10655 * 10656 * @param number - the number to look up 10657 * @return {@code true} if the given number is an emergency number based on current locale, 10658 * SIM card(s), Android database, modem, network or defaults; {@code false} otherwise. 10659 */ isEmergencyNumber(@onNull String number)10660 public boolean isEmergencyNumber(@NonNull String number) { 10661 try { 10662 ITelephony telephony = getITelephony(); 10663 if (telephony != null) { 10664 return telephony.isEmergencyNumber(number, true); 10665 } else { 10666 throw new IllegalStateException("telephony service is null."); 10667 } 10668 } catch (RemoteException ex) { 10669 Log.e(TAG, "isEmergencyNumber RemoteException", ex); 10670 ex.rethrowAsRuntimeException(); 10671 } 10672 return false; 10673 } 10674 10675 /** 10676 * Checks if the supplied number is an emergency number based on current locale, sim, default, 10677 * modem and network. 10678 * 10679 * <p> Specifically, this method will return {@code true} if the specified number is an 10680 * emergency number, *or* if the number simply starts with the same digits as any current 10681 * emergency number. 10682 * 10683 * <p>The subscriptions which the identification would be based on, are all the active 10684 * subscriptions, no matter which subscription could be used to create TelephonyManager. 10685 * 10686 * <p>Requires permission: {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} or 10687 * that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 10688 * 10689 * @param number - the number to look up 10690 * @return {@code true} if the given number is an emergency number or it simply starts with 10691 * the same digits of any current emergency number based on current locale, sim, modem and 10692 * network; {@code false} if it is not; or throw an SecurityException if the caller does not 10693 * have the required permission/privileges 10694 * 10695 * @hide 10696 */ 10697 @SystemApi 10698 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) isPotentialEmergencyNumber(@onNull String number)10699 public boolean isPotentialEmergencyNumber(@NonNull String number) { 10700 try { 10701 ITelephony telephony = getITelephony(); 10702 if (telephony != null) { 10703 return telephony.isEmergencyNumber(number, false); 10704 } else { 10705 throw new IllegalStateException("telephony service is null."); 10706 } 10707 } catch (RemoteException ex) { 10708 Log.e(TAG, "isEmergencyNumber RemoteException", ex); 10709 ex.rethrowAsRuntimeException(); 10710 } 10711 return false; 10712 } 10713 10714 /** @hide */ 10715 @Retention(RetentionPolicy.SOURCE) 10716 @IntDef(prefix = {"SET_OPPORTUNISTIC_SUB"}, value = { 10717 SET_OPPORTUNISTIC_SUB_SUCCESS, 10718 SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED, 10719 SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION}) 10720 public @interface SetOpportunisticSubscriptionResult {} 10721 10722 /** 10723 * No error. Operation succeeded. 10724 */ 10725 public static final int SET_OPPORTUNISTIC_SUB_SUCCESS = 0; 10726 10727 /** 10728 * Validation failed when trying to switch to preferred subscription. 10729 */ 10730 public static final int SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED = 1; 10731 10732 /** 10733 * The subscription is not valid. It must be an active opportunistic subscription. 10734 */ 10735 public static final int SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION = 2; 10736 10737 /** @hide */ 10738 @Retention(RetentionPolicy.SOURCE) 10739 @IntDef(prefix = {"UPDATE_AVAILABLE_NETWORKS"}, value = { 10740 UPDATE_AVAILABLE_NETWORKS_SUCCESS, 10741 UPDATE_AVAILABLE_NETWORKS_UNKNOWN_FAILURE, 10742 UPDATE_AVAILABLE_NETWORKS_ABORTED, 10743 UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS, 10744 UPDATE_AVAILABLE_NETWORKS_NO_CARRIER_PRIVILEGE}) 10745 public @interface UpdateAvailableNetworksResult {} 10746 10747 /** 10748 * No error. Operation succeeded. 10749 */ 10750 public static final int UPDATE_AVAILABLE_NETWORKS_SUCCESS = 0; 10751 10752 /** 10753 * There is a unknown failure happened. 10754 */ 10755 public static final int UPDATE_AVAILABLE_NETWORKS_UNKNOWN_FAILURE = 1; 10756 10757 /** 10758 * The request is aborted. 10759 */ 10760 public static final int UPDATE_AVAILABLE_NETWORKS_ABORTED = 2; 10761 10762 /** 10763 * The parameter passed in is invalid. 10764 */ 10765 public static final int UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS = 3; 10766 10767 /** 10768 * No carrier privilege. 10769 */ 10770 public static final int UPDATE_AVAILABLE_NETWORKS_NO_CARRIER_PRIVILEGE = 4; 10771 10772 /** 10773 * Set preferred opportunistic data subscription id. 10774 * 10775 * Switch internet data to preferred opportunistic data subscription id. This api 10776 * can result in lose of internet connectivity for short period of time while internet data 10777 * is handed over. 10778 * <p>Requires that the calling app has carrier privileges on both primary and 10779 * secondary subscriptions (see 10780 * {@link #hasCarrierPrivileges}), or has permission 10781 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 10782 * 10783 * @param subId which opportunistic subscription 10784 * {@link SubscriptionManager#getOpportunisticSubscriptions} is preferred for cellular data. 10785 * Pass {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} to unset the preference 10786 * @param needValidation whether validation is needed before switch happens. 10787 * @param executor The executor of where the callback will execute. 10788 * @param callback Callback will be triggered once it succeeds or failed. 10789 * See {@link TelephonyManager.SetOpportunisticSubscriptionResult} 10790 * for more details. Pass null if don't care about the result. 10791 * 10792 */ setPreferredOpportunisticDataSubscription(int subId, boolean needValidation, @Nullable @CallbackExecutor Executor executor, @Nullable Consumer<Integer> callback)10793 public void setPreferredOpportunisticDataSubscription(int subId, boolean needValidation, 10794 @Nullable @CallbackExecutor Executor executor, @Nullable Consumer<Integer> callback) { 10795 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 10796 try { 10797 IOns iOpportunisticNetworkService = getIOns(); 10798 if (iOpportunisticNetworkService == null) { 10799 return; 10800 } 10801 ISetOpportunisticDataCallback callbackStub = new ISetOpportunisticDataCallback.Stub() { 10802 @Override 10803 public void onComplete(int result) { 10804 if (executor == null || callback == null) { 10805 return; 10806 } 10807 Binder.withCleanCallingIdentity(() -> executor.execute(() -> { 10808 callback.accept(result); 10809 })); 10810 } 10811 }; 10812 10813 iOpportunisticNetworkService 10814 .setPreferredDataSubscriptionId(subId, needValidation, callbackStub, 10815 pkgForDebug); 10816 } catch (RemoteException ex) { 10817 Rlog.e(TAG, "setPreferredDataSubscriptionId RemoteException", ex); 10818 } 10819 return; 10820 } 10821 10822 /** 10823 * Get preferred opportunistic data subscription Id 10824 * 10825 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}), 10826 * or has either READ_PRIVILEGED_PHONE_STATE 10827 * or {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} permission. 10828 * @return subId preferred opportunistic subscription id or 10829 * {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} if there are no preferred 10830 * subscription id 10831 * 10832 */ 10833 @RequiresPermission(anyOf = { 10834 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 10835 android.Manifest.permission.READ_PHONE_STATE 10836 }) getPreferredOpportunisticDataSubscription()10837 public int getPreferredOpportunisticDataSubscription() { 10838 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 10839 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 10840 try { 10841 IOns iOpportunisticNetworkService = getIOns(); 10842 if (iOpportunisticNetworkService != null) { 10843 subId = iOpportunisticNetworkService.getPreferredDataSubscriptionId(pkgForDebug); 10844 } 10845 } catch (RemoteException ex) { 10846 Rlog.e(TAG, "getPreferredDataSubscriptionId RemoteException", ex); 10847 } 10848 return subId; 10849 } 10850 10851 /** 10852 * Update availability of a list of networks in the current location. 10853 * 10854 * This api should be called to inform OpportunisticNetwork Service about the availability 10855 * of a network at the current location. This information will be used by OpportunisticNetwork 10856 * service to enable modem stack and to attach to the network. If an empty list is passed, 10857 * it is assumed that no network is available and will result in disabling the modem stack 10858 * to save power. This api do not switch internet data once network attach is completed. 10859 * Use {@link TelephonyManager#setPreferredOpportunisticDataSubscription} 10860 * to switch internet data after network attach is complete. 10861 * Requires that the calling app has carrier privileges on both primary and 10862 * secondary subscriptions (see {@link #hasCarrierPrivileges}), or has permission 10863 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 10864 * @param availableNetworks is a list of available network information. 10865 * @param executor The executor of where the callback will execute. 10866 * @param callback Callback will be triggered once it succeeds or failed. 10867 * 10868 */ 10869 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges updateAvailableNetworks(@onNull List<AvailableNetworkInfo> availableNetworks, @Nullable @CallbackExecutor Executor executor, @UpdateAvailableNetworksResult @Nullable Consumer<Integer> callback)10870 public void updateAvailableNetworks(@NonNull List<AvailableNetworkInfo> availableNetworks, 10871 @Nullable @CallbackExecutor Executor executor, 10872 @UpdateAvailableNetworksResult @Nullable Consumer<Integer> callback) { 10873 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 10874 try { 10875 IOns iOpportunisticNetworkService = getIOns(); 10876 if (iOpportunisticNetworkService == null || availableNetworks == null) { 10877 Binder.withCleanCallingIdentity(() -> executor.execute(() -> { 10878 callback.accept(UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS); 10879 })); 10880 return; 10881 } 10882 IUpdateAvailableNetworksCallback callbackStub = 10883 new IUpdateAvailableNetworksCallback.Stub() { 10884 @Override 10885 public void onComplete(int result) { 10886 if (executor == null || callback == null) { 10887 return; 10888 } 10889 Binder.withCleanCallingIdentity(() -> executor.execute(() -> { 10890 callback.accept(result); 10891 })); 10892 } 10893 }; 10894 iOpportunisticNetworkService.updateAvailableNetworks(availableNetworks, callbackStub, 10895 pkgForDebug); 10896 } catch (RemoteException ex) { 10897 Rlog.e(TAG, "updateAvailableNetworks RemoteException", ex); 10898 } 10899 } 10900 10901 /** 10902 * Enable or disable a logical modem stack. When a logical modem is disabled, the corresponding 10903 * SIM will still be visible to the user but its mapping modem will not have any radio activity. 10904 * For example, we will disable a modem when user or system believes the corresponding SIM 10905 * is temporarily not needed (e.g. out of coverage), and will enable it back on when needed. 10906 * 10907 * Requires that the calling app has permission 10908 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 10909 * @param slotIndex which corresponding modem will operate on. 10910 * @param enable whether to enable or disable the modem stack. 10911 * @return whether the operation is successful. 10912 * 10913 * @hide 10914 */ 10915 @SystemApi 10916 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) enableModemForSlot(int slotIndex, boolean enable)10917 public boolean enableModemForSlot(int slotIndex, boolean enable) { 10918 boolean ret = false; 10919 try { 10920 ITelephony telephony = getITelephony(); 10921 if (telephony != null) { 10922 ret = telephony.enableModemForSlot(slotIndex, enable); 10923 } 10924 } catch (RemoteException ex) { 10925 Log.e(TAG, "enableModem RemoteException", ex); 10926 } 10927 return ret; 10928 } 10929 10930 /** 10931 * It indicates whether modem is enabled or not per slot. 10932 * It's the corresponding status of {@link #enableModemForSlot}. 10933 * 10934 * @param slotIndex which slot it's checking. 10935 * @hide 10936 */ isModemEnabledForSlot(int slotIndex)10937 public boolean isModemEnabledForSlot(int slotIndex) { 10938 try { 10939 ITelephony telephony = getITelephony(); 10940 if (telephony != null) { 10941 return telephony.isModemEnabledForSlot(slotIndex, mContext.getOpPackageName()); 10942 } 10943 } catch (RemoteException ex) { 10944 Log.e(TAG, "enableModem RemoteException", ex); 10945 } 10946 return false; 10947 } 10948 10949 /** 10950 * Broadcast intent action for network country code changes. 10951 * 10952 * <p> 10953 * The {@link #EXTRA_NETWORK_COUNTRY} extra indicates the country code of the current 10954 * network returned by {@link #getNetworkCountryIso()}. 10955 * 10956 * @see #EXTRA_NETWORK_COUNTRY 10957 * @see #getNetworkCountryIso() 10958 */ 10959 public static final String ACTION_NETWORK_COUNTRY_CHANGED = 10960 "android.telephony.action.NETWORK_COUNTRY_CHANGED"; 10961 10962 /** 10963 * The extra used with an {@link #ACTION_NETWORK_COUNTRY_CHANGED} to specify the 10964 * the country code in ISO 3166 format. 10965 * <p class="note"> 10966 * Retrieve with {@link android.content.Intent#getStringExtra(String)}. 10967 */ 10968 public static final String EXTRA_NETWORK_COUNTRY = 10969 "android.telephony.extra.NETWORK_COUNTRY"; 10970 10971 /** 10972 * Indicate if the user is allowed to use multiple SIM cards at the same time to register 10973 * on the network (e.g. Dual Standby or Dual Active) when the device supports it, or if the 10974 * usage is restricted. This API is used to prevent usage of multiple SIM card, based on 10975 * policies of the carrier. 10976 * <p>Note: the API does not prevent access to the SIM cards for operations that don't require 10977 * access to the network. 10978 * 10979 * @param isMultiSimCarrierRestricted true if usage of multiple SIMs is restricted, false 10980 * otherwise. 10981 * 10982 * @hide 10983 */ 10984 @SystemApi 10985 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted)10986 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { 10987 try { 10988 ITelephony service = getITelephony(); 10989 if (service != null) { 10990 service.setMultiSimCarrierRestriction(isMultiSimCarrierRestricted); 10991 } 10992 } catch (RemoteException e) { 10993 Log.e(TAG, "setMultiSimCarrierRestriction RemoteException", e); 10994 } 10995 } 10996 10997 /** 10998 * The usage of multiple SIM cards at the same time to register on the network (e.g. Dual 10999 * Standby or Dual Active) is supported. 11000 */ 11001 public static final int MULTISIM_ALLOWED = 0; 11002 11003 /** 11004 * The usage of multiple SIM cards at the same time to register on the network (e.g. Dual 11005 * Standby or Dual Active) is not supported by the hardware. 11006 */ 11007 public static final int MULTISIM_NOT_SUPPORTED_BY_HARDWARE = 1; 11008 11009 /** 11010 * The usage of multiple SIM cards at the same time to register on the network (e.g. Dual 11011 * Standby or Dual Active) is supported by the hardware, but restricted by the carrier. 11012 */ 11013 public static final int MULTISIM_NOT_SUPPORTED_BY_CARRIER = 2; 11014 11015 /** @hide */ 11016 @Retention(RetentionPolicy.SOURCE) 11017 @IntDef(prefix = {"MULTISIM_"}, 11018 value = { 11019 MULTISIM_ALLOWED, 11020 MULTISIM_NOT_SUPPORTED_BY_HARDWARE, 11021 MULTISIM_NOT_SUPPORTED_BY_CARRIER 11022 }) 11023 public @interface IsMultiSimSupportedResult {} 11024 11025 /** 11026 * Returns if the usage of multiple SIM cards at the same time to register on the network 11027 * (e.g. Dual Standby or Dual Active) is supported by the device and by the carrier. 11028 * 11029 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 11030 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 11031 * 11032 * @return {@link #MULTISIM_ALLOWED} if the device supports multiple SIMs. 11033 * {@link #MULTISIM_NOT_SUPPORTED_BY_HARDWARE} if the device does not support multiple SIMs. 11034 * {@link #MULTISIM_NOT_SUPPORTED_BY_CARRIER} in the device supports multiple SIMs, but the 11035 * functionality is restricted by the carrier. 11036 */ 11037 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 11038 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 11039 @IsMultiSimSupportedResult isMultiSimSupported()11040 public int isMultiSimSupported() { 11041 try { 11042 ITelephony service = getITelephony(); 11043 if (service != null) { 11044 return service.isMultiSimSupported(getOpPackageName()); 11045 } 11046 } catch (RemoteException e) { 11047 Log.e(TAG, "isMultiSimSupported RemoteException", e); 11048 } 11049 return MULTISIM_NOT_SUPPORTED_BY_HARDWARE; 11050 } 11051 11052 /** 11053 * Switch configs to enable multi-sim or switch back to single-sim 11054 * <p>Requires Permission: 11055 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 11056 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 11057 * 11058 * Note: with only carrier privileges, it is not allowed to switch from multi-sim 11059 * to single-sim 11060 * 11061 * @param numOfSims number of live SIMs we want to switch to 11062 * @throws android.os.RemoteException 11063 */ 11064 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 11065 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) switchMultiSimConfig(int numOfSims)11066 public void switchMultiSimConfig(int numOfSims) { 11067 try { 11068 ITelephony telephony = getITelephony(); 11069 if (telephony != null) { 11070 telephony.switchMultiSimConfig(numOfSims); 11071 } 11072 } catch (RemoteException ex) { 11073 Rlog.e(TAG, "switchMultiSimConfig RemoteException", ex); 11074 } 11075 } 11076 11077 /** 11078 * Get whether making changes to modem configurations by {@link #switchMultiSimConfig(int)} will 11079 * trigger device reboot. 11080 * The modem configuration change refers to switching from single SIM configuration to DSDS 11081 * or the other way around. 11082 * 11083 * <p>Requires Permission: 11084 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} or that the 11085 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 11086 * 11087 * @return {@code true} if reboot will be triggered after making changes to modem 11088 * configurations, otherwise return {@code false}. 11089 */ 11090 @RequiresPermission(Manifest.permission.READ_PHONE_STATE) doesSwitchMultiSimConfigTriggerReboot()11091 public boolean doesSwitchMultiSimConfigTriggerReboot() { 11092 try { 11093 ITelephony service = getITelephony(); 11094 if (service != null) { 11095 return service.doesSwitchMultiSimConfigTriggerReboot(getSubId(), 11096 getOpPackageName()); 11097 } 11098 } catch (RemoteException e) { 11099 Log.e(TAG, "doesSwitchMultiSimConfigTriggerReboot RemoteException", e); 11100 } 11101 return false; 11102 } 11103 11104 /** 11105 * Retrieve the Radio HAL Version for this device. 11106 * 11107 * Get the HAL version for the IRadio interface for test purposes. 11108 * 11109 * @return a Pair of (major version, minor version) or (-1,-1) if unknown. 11110 * 11111 * @hide 11112 */ 11113 @TestApi getRadioHalVersion()11114 public Pair<Integer, Integer> getRadioHalVersion() { 11115 try { 11116 ITelephony service = getITelephony(); 11117 if (service != null) { 11118 int version = service.getRadioHalVersion(); 11119 if (version == -1) return new Pair<Integer, Integer>(-1, -1); 11120 return new Pair<Integer, Integer>(version / 100, version % 100); 11121 } 11122 } catch (RemoteException e) { 11123 Log.e(TAG, "getRadioHalVersion() RemoteException", e); 11124 } 11125 return new Pair<Integer, Integer>(-1, -1); 11126 } 11127 11128 /** 11129 * Return whether data is enabled for certain APN type. This will tell if framework will accept 11130 * corresponding network requests on a subId. 11131 * 11132 * {@link #isDataEnabled()} is directly associated with users' Mobile data toggle on / off. If 11133 * {@link #isDataEnabled()} returns false, it means in general all meter-ed data are disabled. 11134 * 11135 * This per APN type API gives a better idea whether data is allowed on a specific APN type. 11136 * It will return true if: 11137 * 11138 * 1) User data is turned on, or 11139 * 2) APN is un-metered for this subscription, or 11140 * 3) APN type is whitelisted. E.g. MMS is whitelisted if 11141 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on. 11142 * 11143 * @return whether data is enabled for a apn type. 11144 * 11145 * @hide 11146 */ isDataEnabledForApn(@pnSetting.ApnType int apnType)11147 public boolean isDataEnabledForApn(@ApnSetting.ApnType int apnType) { 11148 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 11149 try { 11150 ITelephony service = getITelephony(); 11151 if (service != null) { 11152 return service.isDataEnabledForApn(apnType, getSubId(), pkgForDebug); 11153 } 11154 } catch (RemoteException ex) { 11155 if (!isSystemProcess()) { 11156 ex.rethrowAsRuntimeException(); 11157 } 11158 } 11159 return false; 11160 } 11161 11162 /** 11163 * Whether an APN type is metered or not. It will be evaluated with the subId associated 11164 * with the TelephonyManager instance. 11165 * 11166 * @hide 11167 */ isApnMetered(@pnSetting.ApnType int apnType)11168 public boolean isApnMetered(@ApnSetting.ApnType int apnType) { 11169 try { 11170 ITelephony service = getITelephony(); 11171 if (service != null) { 11172 return service.isApnMetered(apnType, getSubId()); 11173 } 11174 } catch (RemoteException ex) { 11175 if (!isSystemProcess()) { 11176 ex.rethrowAsRuntimeException(); 11177 } 11178 } 11179 return true; 11180 } 11181 11182 /** 11183 * Set allowing mobile data during voice call. 11184 * 11185 * @param allow {@code true} if allowing using data during voice call, {@code false} if 11186 * disallowed 11187 * 11188 * @return {@code false} if the setting is changed. 11189 * 11190 * @hide 11191 */ 11192 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataAllowedDuringVoiceCall(boolean allow)11193 public boolean setDataAllowedDuringVoiceCall(boolean allow) { 11194 try { 11195 ITelephony service = getITelephony(); 11196 if (service != null) { 11197 return service.setDataAllowedDuringVoiceCall(getSubId(), allow); 11198 } 11199 } catch (RemoteException ex) { 11200 if (!isSystemProcess()) { 11201 ex.rethrowAsRuntimeException(); 11202 } 11203 } 11204 return false; 11205 } 11206 11207 /** 11208 * Check whether data is allowed during voice call. Note this is for dual sim device that 11209 * data might be disabled on non-default data subscription but explicitly turned on by settings. 11210 * 11211 * @return {@code true} if data is allowed during voice call. 11212 * 11213 * @hide 11214 */ 11215 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) isDataAllowedInVoiceCall()11216 public boolean isDataAllowedInVoiceCall() { 11217 try { 11218 ITelephony service = getITelephony(); 11219 if (service != null) { 11220 return service.isDataAllowedInVoiceCall(getSubId()); 11221 } 11222 } catch (RemoteException ex) { 11223 if (!isSystemProcess()) { 11224 ex.rethrowAsRuntimeException(); 11225 } 11226 } 11227 return false; 11228 } 11229 } 11230