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 com.android.internal.util.Preconditions.checkNotNull; 20 21 import android.annotation.IntDef; 22 import android.annotation.Nullable; 23 import android.annotation.RequiresPermission; 24 import android.annotation.SdkConstant; 25 import android.annotation.SdkConstant.SdkConstantType; 26 import android.annotation.SuppressAutoDoc; 27 import android.annotation.SuppressLint; 28 import android.annotation.SystemApi; 29 import android.annotation.SystemService; 30 import android.annotation.TestApi; 31 import android.annotation.WorkerThread; 32 import android.app.ActivityThread; 33 import android.app.PendingIntent; 34 import android.content.Context; 35 import android.content.Intent; 36 import android.net.ConnectivityManager; 37 import android.net.NetworkStats; 38 import android.net.Uri; 39 import android.os.AsyncTask; 40 import android.os.BatteryStats; 41 import android.os.Bundle; 42 import android.os.Handler; 43 import android.os.PersistableBundle; 44 import android.os.Process; 45 import android.os.RemoteException; 46 import android.os.ResultReceiver; 47 import android.os.ServiceManager; 48 import android.os.SystemProperties; 49 import android.provider.Settings.SettingNotFoundException; 50 import android.service.carrier.CarrierIdentifier; 51 import android.telecom.PhoneAccount; 52 import android.telecom.PhoneAccountHandle; 53 import android.telecom.TelecomManager; 54 import android.telephony.VisualVoicemailService.VisualVoicemailTask; 55 import android.telephony.ims.aidl.IImsConfig; 56 import android.telephony.ims.aidl.IImsMmTelFeature; 57 import android.telephony.ims.aidl.IImsRcsFeature; 58 import android.telephony.ims.aidl.IImsRegistration; 59 import android.telephony.ims.stub.ImsRegistrationImplBase; 60 import android.util.Log; 61 62 import com.android.ims.internal.IImsServiceFeatureCallback; 63 import com.android.internal.annotations.VisibleForTesting; 64 import com.android.internal.telecom.ITelecomService; 65 import com.android.internal.telephony.CellNetworkScanResult; 66 import com.android.internal.telephony.IPhoneSubInfo; 67 import com.android.internal.telephony.ITelephony; 68 import com.android.internal.telephony.ITelephonyRegistry; 69 import com.android.internal.telephony.PhoneConstants; 70 import com.android.internal.telephony.RILConstants; 71 import com.android.internal.telephony.TelephonyProperties; 72 73 import java.io.FileInputStream; 74 import java.io.IOException; 75 import java.lang.annotation.Retention; 76 import java.lang.annotation.RetentionPolicy; 77 import java.util.ArrayList; 78 import java.util.Collections; 79 import java.util.List; 80 import java.util.concurrent.Executor; 81 import java.util.regex.Matcher; 82 import java.util.regex.Pattern; 83 84 /** 85 * Provides access to information about the telephony services on 86 * the device. Applications can use the methods in this class to 87 * determine telephony services and states, as well as to access some 88 * types of subscriber information. Applications can also register 89 * a listener to receive notification of telephony state changes. 90 * <p> 91 * The returned TelephonyManager will use the default subscription for all calls. 92 * To call an API for a specific subscription, use {@link #createForSubscriptionId(int)}. e.g. 93 * <code> 94 * telephonyManager = defaultSubTelephonyManager.createForSubscriptionId(subId); 95 * </code> 96 * <p> 97 * Note that access to some telephony information is 98 * permission-protected. Your application cannot access the protected 99 * information unless it has the appropriate permissions declared in 100 * its manifest file. Where permissions apply, they are noted in the 101 * the methods through which you access the protected information. 102 */ 103 @SystemService(Context.TELEPHONY_SERVICE) 104 public class TelephonyManager { 105 private static final String TAG = "TelephonyManager"; 106 107 /** 108 * The key to use when placing the result of {@link #requestModemActivityInfo(ResultReceiver)} 109 * into the ResultReceiver Bundle. 110 * @hide 111 */ 112 public static final String MODEM_ACTIVITY_RESULT_KEY = 113 BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY; 114 115 /** 116 * The process name of the Phone app as well as many other apps that use this process name, such 117 * as settings and vendor components. 118 * @hide 119 */ 120 public static final String PHONE_PROCESS_NAME = "com.android.phone"; 121 122 /** 123 * The allowed states of Wi-Fi calling. 124 * 125 * @hide 126 */ 127 public interface WifiCallingChoices { 128 /** Always use Wi-Fi calling */ 129 static final int ALWAYS_USE = 0; 130 /** Ask the user whether to use Wi-Fi on every call */ 131 static final int ASK_EVERY_TIME = 1; 132 /** Never use Wi-Fi calling */ 133 static final int NEVER_USE = 2; 134 } 135 136 /** The otaspMode passed to PhoneStateListener#onOtaspChanged */ 137 /** @hide */ 138 static public final int OTASP_UNINITIALIZED = 0; 139 /** @hide */ 140 static public final int OTASP_UNKNOWN = 1; 141 /** @hide */ 142 static public final int OTASP_NEEDED = 2; 143 /** @hide */ 144 static public final int OTASP_NOT_NEEDED = 3; 145 /* OtaUtil has conflict enum 4: OtaUtils.OTASP_FAILURE_SPC_RETRIES */ 146 /** @hide */ 147 static public final int OTASP_SIM_UNPROVISIONED = 5; 148 149 150 /** @hide */ 151 static public final int KEY_TYPE_EPDG = 1; 152 153 /** @hide */ 154 static public final int KEY_TYPE_WLAN = 2; 155 156 private final Context mContext; 157 private final int mSubId; 158 private SubscriptionManager mSubscriptionManager; 159 private TelephonyScanManager mTelephonyScanManager; 160 161 private static String multiSimConfig = 162 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 163 164 /** Enum indicating multisim variants 165 * DSDS - Dual SIM Dual Standby 166 * DSDA - Dual SIM Dual Active 167 * TSTS - Triple SIM Triple Standby 168 **/ 169 /** @hide */ 170 public enum MultiSimVariants { 171 DSDS, 172 DSDA, 173 TSTS, 174 UNKNOWN 175 }; 176 177 /** @hide */ TelephonyManager(Context context)178 public TelephonyManager(Context context) { 179 this(context, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID); 180 } 181 182 /** @hide */ TelephonyManager(Context context, int subId)183 public TelephonyManager(Context context, int subId) { 184 mSubId = subId; 185 Context appContext = context.getApplicationContext(); 186 if (appContext != null) { 187 mContext = appContext; 188 } else { 189 mContext = context; 190 } 191 mSubscriptionManager = SubscriptionManager.from(mContext); 192 } 193 194 /** @hide */ TelephonyManager()195 private TelephonyManager() { 196 mContext = null; 197 mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 198 } 199 200 private static TelephonyManager sInstance = new TelephonyManager(); 201 202 /** @hide 203 /* @deprecated - use getSystemService as described above */ getDefault()204 public static TelephonyManager getDefault() { 205 return sInstance; 206 } 207 getOpPackageName()208 private String getOpPackageName() { 209 // For legacy reasons the TelephonyManager has API for getting 210 // a static instance with no context set preventing us from 211 // getting the op package name. As a workaround we do a best 212 // effort and get the context from the current activity thread. 213 if (mContext != null) { 214 return mContext.getOpPackageName(); 215 } 216 return ActivityThread.currentOpPackageName(); 217 } 218 isSystemProcess()219 private boolean isSystemProcess() { 220 return Process.myUid() == Process.SYSTEM_UID; 221 } 222 223 /** 224 * Returns the multi SIM variant 225 * Returns DSDS for Dual SIM Dual Standby 226 * Returns DSDA for Dual SIM Dual Active 227 * Returns TSTS for Triple SIM Triple Standby 228 * Returns UNKNOWN for others 229 */ 230 /** {@hide} */ getMultiSimConfiguration()231 public MultiSimVariants getMultiSimConfiguration() { 232 String mSimConfig = 233 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 234 if (mSimConfig.equals("dsds")) { 235 return MultiSimVariants.DSDS; 236 } else if (mSimConfig.equals("dsda")) { 237 return MultiSimVariants.DSDA; 238 } else if (mSimConfig.equals("tsts")) { 239 return MultiSimVariants.TSTS; 240 } else { 241 return MultiSimVariants.UNKNOWN; 242 } 243 } 244 245 246 /** 247 * Returns the number of phones available. 248 * Returns 0 if none of voice, sms, data is not supported 249 * Returns 1 for Single standby mode (Single SIM functionality) 250 * Returns 2 for Dual standby mode.(Dual SIM functionality) 251 */ getPhoneCount()252 public int getPhoneCount() { 253 int phoneCount = 1; 254 switch (getMultiSimConfiguration()) { 255 case UNKNOWN: 256 // if voice or sms or data is supported, return 1 otherwise 0 257 if (isVoiceCapable() || isSmsCapable()) { 258 phoneCount = 1; 259 } else { 260 // todo: try to clean this up further by getting rid of the nested conditions 261 if (mContext == null) { 262 phoneCount = 1; 263 } else { 264 // check for data support 265 ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService( 266 Context.CONNECTIVITY_SERVICE); 267 if (cm == null) { 268 phoneCount = 1; 269 } else { 270 if (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) { 271 phoneCount = 1; 272 } else { 273 phoneCount = 0; 274 } 275 } 276 } 277 } 278 break; 279 case DSDS: 280 case DSDA: 281 phoneCount = PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM; 282 break; 283 case TSTS: 284 phoneCount = PhoneConstants.MAX_PHONE_COUNT_TRI_SIM; 285 break; 286 } 287 return phoneCount; 288 } 289 290 /** {@hide} */ from(Context context)291 public static TelephonyManager from(Context context) { 292 return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 293 } 294 295 /** 296 * Create a new TelephonyManager object pinned to the given subscription ID. 297 * 298 * @return a TelephonyManager that uses the given subId for all calls. 299 */ createForSubscriptionId(int subId)300 public TelephonyManager createForSubscriptionId(int subId) { 301 // Don't reuse any TelephonyManager objects. 302 return new TelephonyManager(mContext, subId); 303 } 304 305 /** 306 * Create a new TelephonyManager object pinned to the subscription ID associated with the given 307 * phone account. 308 * 309 * @return a TelephonyManager that uses the given phone account for all calls, or {@code null} 310 * if the phone account does not correspond to a valid subscription ID. 311 */ 312 @Nullable createForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle)313 public TelephonyManager createForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) { 314 int subId = getSubIdForPhoneAccountHandle(phoneAccountHandle); 315 if (!SubscriptionManager.isValidSubscriptionId(subId)) { 316 return null; 317 } 318 return new TelephonyManager(mContext, subId); 319 } 320 321 /** {@hide} */ isMultiSimEnabled()322 public boolean isMultiSimEnabled() { 323 return (multiSimConfig.equals("dsds") || multiSimConfig.equals("dsda") || 324 multiSimConfig.equals("tsts")); 325 } 326 327 // 328 // Broadcast Intent actions 329 // 330 331 /** 332 * Broadcast intent action indicating that the call state 333 * on the device has changed. 334 * 335 * <p> 336 * The {@link #EXTRA_STATE} extra indicates the new call state. 337 * If a receiving app has {@link android.Manifest.permission#READ_CALL_LOG} permission, a second 338 * extra {@link #EXTRA_INCOMING_NUMBER} provides the phone number for incoming and outoing calls 339 * as a String. Note: If the receiving app has 340 * {@link android.Manifest.permission#READ_CALL_LOG} and 341 * {@link android.Manifest.permission#READ_PHONE_STATE} permission, it will receive the 342 * broadcast twice; one with the phone number and another without it. 343 * <p class="note"> 344 * This was a {@link android.content.Context#sendStickyBroadcast sticky} 345 * broadcast in version 1.0, but it is no longer sticky. 346 * Instead, use {@link #getCallState} to synchronously query the current call state. 347 * 348 * @see #EXTRA_STATE 349 * @see #EXTRA_INCOMING_NUMBER 350 * @see #getCallState 351 */ 352 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 353 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 354 public static final String ACTION_PHONE_STATE_CHANGED = 355 "android.intent.action.PHONE_STATE"; 356 357 /** 358 * The Phone app sends this intent when a user opts to respond-via-message during an incoming 359 * call. By default, the device's default SMS app consumes this message and sends a text message 360 * to the caller. A third party app can also provide this functionality by consuming this Intent 361 * with a {@link android.app.Service} and sending the message using its own messaging system. 362 * <p>The intent contains a URI (available from {@link android.content.Intent#getData}) 363 * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:}, 364 * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the 365 * same way: the path part of the URI contains the recipient's phone number or a comma-separated 366 * set of phone numbers if there are multiple recipients. For example, {@code 367 * smsto:2065551234}.</p> 368 * 369 * <p>The intent may also contain extras for the message text (in {@link 370 * android.content.Intent#EXTRA_TEXT}) and a message subject 371 * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p> 372 * 373 * <p class="note"><strong>Note:</strong> 374 * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service} 375 * that requires the 376 * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p> 377 * <p>For example, the service that receives this intent can be declared in the manifest file 378 * with an intent filter like this:</p> 379 * <pre> 380 * <!-- Service that delivers SMS messages received from the phone "quick response" --> 381 * <service android:name=".HeadlessSmsSendService" 382 * android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" 383 * android:exported="true" > 384 * <intent-filter> 385 * <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /> 386 * <category android:name="android.intent.category.DEFAULT" /> 387 * <data android:scheme="sms" /> 388 * <data android:scheme="smsto" /> 389 * <data android:scheme="mms" /> 390 * <data android:scheme="mmsto" /> 391 * </intent-filter> 392 * </service></pre> 393 * <p> 394 * Output: nothing. 395 */ 396 @SdkConstant(SdkConstantType.SERVICE_ACTION) 397 public static final String ACTION_RESPOND_VIA_MESSAGE = 398 "android.intent.action.RESPOND_VIA_MESSAGE"; 399 400 /** 401 * The emergency dialer may choose to present activities with intent filters for this 402 * action as emergency assistance buttons that launch the activity when clicked. 403 * 404 * @hide 405 */ 406 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 407 public static final String ACTION_EMERGENCY_ASSISTANCE = 408 "android.telephony.action.EMERGENCY_ASSISTANCE"; 409 410 /** 411 * A boolean meta-data value indicating whether the voicemail settings should be hidden in the 412 * call settings page launched by 413 * {@link android.telecom.TelecomManager#ACTION_SHOW_CALL_SETTINGS}. 414 * Dialer implementations (see {@link android.telecom.TelecomManager#getDefaultDialerPackage()}) 415 * which would also like to manage voicemail settings should set this meta-data to {@code true} 416 * in the manifest registration of their application. 417 * 418 * @see android.telecom.TelecomManager#ACTION_SHOW_CALL_SETTINGS 419 * @see #ACTION_CONFIGURE_VOICEMAIL 420 * @see #EXTRA_HIDE_PUBLIC_SETTINGS 421 */ 422 public static final String METADATA_HIDE_VOICEMAIL_SETTINGS_MENU = 423 "android.telephony.HIDE_VOICEMAIL_SETTINGS_MENU"; 424 425 /** 426 * Open the voicemail settings activity to make changes to voicemail configuration. 427 * 428 * <p> 429 * The {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra indicates which {@link PhoneAccountHandle} to 430 * configure voicemail. 431 * The {@link #EXTRA_HIDE_PUBLIC_SETTINGS} hides settings the dialer will modify through public 432 * API if set. 433 * 434 * @see #EXTRA_PHONE_ACCOUNT_HANDLE 435 * @see #EXTRA_HIDE_PUBLIC_SETTINGS 436 */ 437 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 438 public static final String ACTION_CONFIGURE_VOICEMAIL = 439 "android.telephony.action.CONFIGURE_VOICEMAIL"; 440 441 /** 442 * The boolean value indicating whether the voicemail settings activity launched by {@link 443 * #ACTION_CONFIGURE_VOICEMAIL} should hide settings accessible through public API. This is 444 * used by dialer implementations which provides their own voicemail settings UI, but still 445 * needs to expose device specific voicemail settings to the user. 446 * 447 * @see #ACTION_CONFIGURE_VOICEMAIL 448 * @see #METADATA_HIDE_VOICEMAIL_SETTINGS_MENU 449 */ 450 public static final String EXTRA_HIDE_PUBLIC_SETTINGS = 451 "android.telephony.extra.HIDE_PUBLIC_SETTINGS"; 452 453 /** 454 * @hide 455 */ 456 public static final boolean EMERGENCY_ASSISTANCE_ENABLED = true; 457 458 /** 459 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 460 * for a String containing the new call state. 461 * 462 * <p class="note"> 463 * Retrieve with 464 * {@link android.content.Intent#getStringExtra(String)}. 465 * 466 * @see #EXTRA_STATE_IDLE 467 * @see #EXTRA_STATE_RINGING 468 * @see #EXTRA_STATE_OFFHOOK 469 */ 470 public static final String EXTRA_STATE = PhoneConstants.STATE_KEY; 471 472 /** 473 * Value used with {@link #EXTRA_STATE} corresponding to 474 * {@link #CALL_STATE_IDLE}. 475 */ 476 public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString(); 477 478 /** 479 * Value used with {@link #EXTRA_STATE} corresponding to 480 * {@link #CALL_STATE_RINGING}. 481 */ 482 public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString(); 483 484 /** 485 * Value used with {@link #EXTRA_STATE} corresponding to 486 * {@link #CALL_STATE_OFFHOOK}. 487 */ 488 public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString(); 489 490 /** 491 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 492 * for a String containing the incoming phone number. 493 * Only valid when the new call state is RINGING. 494 * 495 * <p class="note"> 496 * Retrieve with 497 * {@link android.content.Intent#getStringExtra(String)}. 498 */ 499 public static final String EXTRA_INCOMING_NUMBER = "incoming_number"; 500 501 /** 502 * Broadcast intent action indicating that a precise call state 503 * (cellular) on the device has changed. 504 * 505 * <p> 506 * The {@link #EXTRA_RINGING_CALL_STATE} extra indicates the ringing call state. 507 * The {@link #EXTRA_FOREGROUND_CALL_STATE} extra indicates the foreground call state. 508 * The {@link #EXTRA_BACKGROUND_CALL_STATE} extra indicates the background call state. 509 * The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause. 510 * The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause. 511 * 512 * <p class="note"> 513 * Requires the READ_PRECISE_PHONE_STATE permission. 514 * 515 * @see #EXTRA_RINGING_CALL_STATE 516 * @see #EXTRA_FOREGROUND_CALL_STATE 517 * @see #EXTRA_BACKGROUND_CALL_STATE 518 * @see #EXTRA_DISCONNECT_CAUSE 519 * @see #EXTRA_PRECISE_DISCONNECT_CAUSE 520 * 521 * <p class="note"> 522 * Requires the READ_PRECISE_PHONE_STATE permission. 523 * 524 * @hide 525 */ 526 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 527 public static final String ACTION_PRECISE_CALL_STATE_CHANGED = 528 "android.intent.action.PRECISE_CALL_STATE"; 529 530 /** 531 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 532 * for an integer containing the state of the current ringing call. 533 * 534 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 535 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 536 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 537 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 538 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 539 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 540 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 541 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 542 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 543 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 544 * 545 * <p class="note"> 546 * Retrieve with 547 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 548 * 549 * @hide 550 */ 551 public static final String EXTRA_RINGING_CALL_STATE = "ringing_state"; 552 553 /** 554 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 555 * for an integer containing the state of the current foreground call. 556 * 557 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 558 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 559 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 560 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 561 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 562 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 563 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 564 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 565 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 566 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 567 * 568 * <p class="note"> 569 * Retrieve with 570 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 571 * 572 * @hide 573 */ 574 public static final String EXTRA_FOREGROUND_CALL_STATE = "foreground_state"; 575 576 /** 577 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 578 * for an integer containing the state of the current background call. 579 * 580 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 581 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 582 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 583 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 584 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 585 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 586 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 587 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 588 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 589 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 590 * 591 * <p class="note"> 592 * Retrieve with 593 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 594 * 595 * @hide 596 */ 597 public static final String EXTRA_BACKGROUND_CALL_STATE = "background_state"; 598 599 /** 600 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 601 * for an integer containing the disconnect cause. 602 * 603 * @see DisconnectCause 604 * 605 * <p class="note"> 606 * Retrieve with 607 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 608 * 609 * @hide 610 */ 611 public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause"; 612 613 /** 614 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 615 * for an integer containing the disconnect cause provided by the RIL. 616 * 617 * @see PreciseDisconnectCause 618 * 619 * <p class="note"> 620 * Retrieve with 621 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 622 * 623 * @hide 624 */ 625 public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause"; 626 627 /** 628 * Broadcast intent action indicating a data connection has changed, 629 * providing precise information about the connection. 630 * 631 * <p> 632 * The {@link #EXTRA_DATA_STATE} extra indicates the connection state. 633 * The {@link #EXTRA_DATA_NETWORK_TYPE} extra indicates the connection network type. 634 * The {@link #EXTRA_DATA_APN_TYPE} extra indicates the APN type. 635 * The {@link #EXTRA_DATA_APN} extra indicates the APN. 636 * The {@link #EXTRA_DATA_CHANGE_REASON} extra indicates the connection change reason. 637 * The {@link #EXTRA_DATA_IFACE_PROPERTIES} extra indicates the connection interface. 638 * The {@link #EXTRA_DATA_FAILURE_CAUSE} extra indicates the connection fail cause. 639 * 640 * <p class="note"> 641 * Requires the READ_PRECISE_PHONE_STATE permission. 642 * 643 * @see #EXTRA_DATA_STATE 644 * @see #EXTRA_DATA_NETWORK_TYPE 645 * @see #EXTRA_DATA_APN_TYPE 646 * @see #EXTRA_DATA_APN 647 * @see #EXTRA_DATA_CHANGE_REASON 648 * @see #EXTRA_DATA_IFACE 649 * @see #EXTRA_DATA_FAILURE_CAUSE 650 * @hide 651 * 652 * @deprecated If the app is running in the background, it won't be able to receive this 653 * broadcast. Apps should use ConnectivityManager {@link #registerNetworkCallback( 654 * android.net.NetworkRequest, ConnectivityManager.NetworkCallback)} to listen for network 655 * changes. 656 */ 657 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 658 @Deprecated 659 public static final String ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED = 660 "android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED"; 661 662 /** 663 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 664 * for an integer containing the state of the current data connection. 665 * 666 * @see TelephonyManager#DATA_UNKNOWN 667 * @see TelephonyManager#DATA_DISCONNECTED 668 * @see TelephonyManager#DATA_CONNECTING 669 * @see TelephonyManager#DATA_CONNECTED 670 * @see TelephonyManager#DATA_SUSPENDED 671 * 672 * <p class="note"> 673 * Retrieve with 674 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 675 * 676 * @hide 677 */ 678 public static final String EXTRA_DATA_STATE = PhoneConstants.STATE_KEY; 679 680 /** 681 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 682 * for an integer containing the network type. 683 * 684 * @see TelephonyManager#NETWORK_TYPE_UNKNOWN 685 * @see TelephonyManager#NETWORK_TYPE_GPRS 686 * @see TelephonyManager#NETWORK_TYPE_EDGE 687 * @see TelephonyManager#NETWORK_TYPE_UMTS 688 * @see TelephonyManager#NETWORK_TYPE_CDMA 689 * @see TelephonyManager#NETWORK_TYPE_EVDO_0 690 * @see TelephonyManager#NETWORK_TYPE_EVDO_A 691 * @see TelephonyManager#NETWORK_TYPE_1xRTT 692 * @see TelephonyManager#NETWORK_TYPE_HSDPA 693 * @see TelephonyManager#NETWORK_TYPE_HSUPA 694 * @see TelephonyManager#NETWORK_TYPE_HSPA 695 * @see TelephonyManager#NETWORK_TYPE_IDEN 696 * @see TelephonyManager#NETWORK_TYPE_EVDO_B 697 * @see TelephonyManager#NETWORK_TYPE_LTE 698 * @see TelephonyManager#NETWORK_TYPE_EHRPD 699 * @see TelephonyManager#NETWORK_TYPE_HSPAP 700 * 701 * <p class="note"> 702 * Retrieve with 703 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 704 * 705 * @hide 706 */ 707 public static final String EXTRA_DATA_NETWORK_TYPE = PhoneConstants.DATA_NETWORK_TYPE_KEY; 708 709 /** 710 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 711 * for an String containing the data APN type. 712 * 713 * <p class="note"> 714 * Retrieve with 715 * {@link android.content.Intent#getStringExtra(String name)}. 716 * 717 * @hide 718 */ 719 public static final String EXTRA_DATA_APN_TYPE = PhoneConstants.DATA_APN_TYPE_KEY; 720 721 /** 722 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 723 * for an String containing the data APN. 724 * 725 * <p class="note"> 726 * Retrieve with 727 * {@link android.content.Intent#getStringExtra(String name)}. 728 * 729 * @hide 730 */ 731 public static final String EXTRA_DATA_APN = PhoneConstants.DATA_APN_KEY; 732 733 /** 734 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 735 * for an String representation of the change reason. 736 * 737 * <p class="note"> 738 * Retrieve with 739 * {@link android.content.Intent#getStringExtra(String name)}. 740 * 741 * @hide 742 */ 743 public static final String EXTRA_DATA_CHANGE_REASON = PhoneConstants.STATE_CHANGE_REASON_KEY; 744 745 /** 746 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 747 * for an String representation of the data interface. 748 * 749 * <p class="note"> 750 * Retrieve with 751 * {@link android.content.Intent#getParcelableExtra(String name)}. 752 * 753 * @hide 754 */ 755 public static final String EXTRA_DATA_LINK_PROPERTIES_KEY = PhoneConstants.DATA_LINK_PROPERTIES_KEY; 756 757 /** 758 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 759 * for the data connection fail cause. 760 * 761 * <p class="note"> 762 * Retrieve with 763 * {@link android.content.Intent#getStringExtra(String name)}. 764 * 765 * @hide 766 */ 767 public static final String EXTRA_DATA_FAILURE_CAUSE = PhoneConstants.DATA_FAILURE_CAUSE_KEY; 768 769 /** 770 * Broadcast intent action for letting the default dialer to know to show voicemail 771 * notification. 772 * 773 * <p> 774 * The {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra indicates which {@link PhoneAccountHandle} the 775 * voicemail is received on. 776 * The {@link #EXTRA_NOTIFICATION_COUNT} extra indicates the total numbers of unheard 777 * voicemails. 778 * The {@link #EXTRA_VOICEMAIL_NUMBER} extra indicates the voicemail number if available. 779 * The {@link #EXTRA_CALL_VOICEMAIL_INTENT} extra is a {@link android.app.PendingIntent} that 780 * will call the voicemail number when sent. This extra will be empty if the voicemail number 781 * is not set, and {@link #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT} will be set instead. 782 * The {@link #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT} extra is a 783 * {@link android.app.PendingIntent} that will launch the voicemail settings. This extra is only 784 * available when the voicemail number is not set. 785 * The {@link #EXTRA_IS_REFRESH} extra indicates whether the notification is a refresh or a new 786 * notification. 787 * 788 * @see #EXTRA_PHONE_ACCOUNT_HANDLE 789 * @see #EXTRA_NOTIFICATION_COUNT 790 * @see #EXTRA_VOICEMAIL_NUMBER 791 * @see #EXTRA_CALL_VOICEMAIL_INTENT 792 * @see #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT 793 * @see #EXTRA_IS_REFRESH 794 */ 795 public static final String ACTION_SHOW_VOICEMAIL_NOTIFICATION = 796 "android.telephony.action.SHOW_VOICEMAIL_NOTIFICATION"; 797 798 /** 799 * The extra used with an {@link #ACTION_CONFIGURE_VOICEMAIL} and 800 * {@link #ACTION_SHOW_VOICEMAIL_NOTIFICATION} {@code Intent} to specify the 801 * {@link PhoneAccountHandle} the configuration or notification is for. 802 * <p class="note"> 803 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}. 804 */ 805 public static final String EXTRA_PHONE_ACCOUNT_HANDLE = 806 "android.telephony.extra.PHONE_ACCOUNT_HANDLE"; 807 808 /** 809 * The number of voice messages associated with the notification. 810 */ 811 public static final String EXTRA_NOTIFICATION_COUNT = 812 "android.telephony.extra.NOTIFICATION_COUNT"; 813 814 /** 815 * The voicemail number. 816 */ 817 public static final String EXTRA_VOICEMAIL_NUMBER = 818 "android.telephony.extra.VOICEMAIL_NUMBER"; 819 820 /** 821 * The intent to call voicemail. 822 */ 823 public static final String EXTRA_CALL_VOICEMAIL_INTENT = 824 "android.telephony.extra.CALL_VOICEMAIL_INTENT"; 825 826 /** 827 * The intent to launch voicemail settings. 828 */ 829 public static final String EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT = 830 "android.telephony.extra.LAUNCH_VOICEMAIL_SETTINGS_INTENT"; 831 832 /** 833 * Boolean value representing whether the {@link 834 * TelephonyManager#ACTION_SHOW_VOICEMAIL_NOTIFICATION} is new or a refresh of an existing 835 * notification. Notification refresh happens after reboot or connectivity changes. The user has 836 * already been notified for the voicemail so it should not alert the user, and should not be 837 * shown again if the user has dismissed it. 838 */ 839 public static final String EXTRA_IS_REFRESH = "android.telephony.extra.IS_REFRESH"; 840 841 /** 842 * {@link android.telecom.Connection} event used to indicate that an IMS call has be 843 * successfully handed over from WIFI to LTE. 844 * <p> 845 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 846 * The {@link Bundle} parameter is expected to be null when this connection event is used. 847 * @hide 848 */ 849 public static final String EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE = 850 "android.telephony.event.EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE"; 851 852 /** 853 * {@link android.telecom.Connection} event used to indicate that an IMS call has be 854 * successfully handed over from LTE to WIFI. 855 * <p> 856 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 857 * The {@link Bundle} parameter is expected to be null when this connection event is used. 858 * @hide 859 */ 860 public static final String EVENT_HANDOVER_VIDEO_FROM_LTE_TO_WIFI = 861 "android.telephony.event.EVENT_HANDOVER_VIDEO_FROM_LTE_TO_WIFI"; 862 863 /** 864 * {@link android.telecom.Connection} event used to indicate that an IMS call failed to be 865 * handed over from LTE to WIFI. 866 * <p> 867 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 868 * The {@link Bundle} parameter is expected to be null when this connection event is used. 869 * @hide 870 */ 871 public static final String EVENT_HANDOVER_TO_WIFI_FAILED = 872 "android.telephony.event.EVENT_HANDOVER_TO_WIFI_FAILED"; 873 874 /** 875 * {@link android.telecom.Connection} event used to indicate that a video call was downgraded to 876 * audio because the data limit was reached. 877 * <p> 878 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 879 * The {@link Bundle} parameter is expected to be null when this connection event is used. 880 * @hide 881 */ 882 public static final String EVENT_DOWNGRADE_DATA_LIMIT_REACHED = 883 "android.telephony.event.EVENT_DOWNGRADE_DATA_LIMIT_REACHED"; 884 885 /** 886 * {@link android.telecom.Connection} event used to indicate that a video call was downgraded to 887 * audio because the data was disabled. 888 * <p> 889 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 890 * The {@link Bundle} parameter is expected to be null when this connection event is used. 891 * @hide 892 */ 893 public static final String EVENT_DOWNGRADE_DATA_DISABLED = 894 "android.telephony.event.EVENT_DOWNGRADE_DATA_DISABLED"; 895 896 /** 897 * {@link android.telecom.Connection} event used to indicate that the InCall UI should notify 898 * the user when an international call is placed while on WFC only. 899 * <p> 900 * Used when the carrier config value 901 * {@link CarrierConfigManager#KEY_NOTIFY_INTERNATIONAL_CALL_ON_WFC_BOOL} is true, the device 902 * is on WFC (VoLTE not available) and an international number is dialed. 903 * <p> 904 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 905 * The {@link Bundle} parameter is expected to be null when this connection event is used. 906 * @hide 907 */ 908 public static final String EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC = 909 "android.telephony.event.EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC"; 910 911 /** 912 * {@link android.telecom.Connection} event used to indicate that an outgoing call has been 913 * forwarded to another number. 914 * <p> 915 * Sent in response to an IMS supplementary service notification indicating the call has been 916 * forwarded. 917 * <p> 918 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 919 * The {@link Bundle} parameter is expected to be null when this connection event is used. 920 * @hide 921 */ 922 public static final String EVENT_CALL_FORWARDED = 923 "android.telephony.event.EVENT_CALL_FORWARDED"; 924 925 /** 926 * {@link android.telecom.Connection} event used to indicate that a supplementary service 927 * notification has been received. 928 * <p> 929 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 930 * The {@link Bundle} parameter is expected to include the following extras: 931 * <ul> 932 * <li>{@link #EXTRA_NOTIFICATION_TYPE} - the notification type.</li> 933 * <li>{@link #EXTRA_NOTIFICATION_CODE} - the notification code.</li> 934 * <li>{@link #EXTRA_NOTIFICATION_MESSAGE} - human-readable message associated with the 935 * supplementary service notification.</li> 936 * </ul> 937 * @hide 938 */ 939 public static final String EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION = 940 "android.telephony.event.EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION"; 941 942 /** 943 * Integer extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} which indicates 944 * the type of supplementary service notification which occurred. 945 * Will be either 946 * {@link com.android.internal.telephony.gsm.SuppServiceNotification#NOTIFICATION_TYPE_CODE_1} 947 * or 948 * {@link com.android.internal.telephony.gsm.SuppServiceNotification#NOTIFICATION_TYPE_CODE_2} 949 * <p> 950 * Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event. 951 * @hide 952 */ 953 public static final String EXTRA_NOTIFICATION_TYPE = 954 "android.telephony.extra.NOTIFICATION_TYPE"; 955 956 /** 957 * Integer extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} which indicates 958 * the supplementary service notification which occurred. 959 * <p> 960 * Depending on the {@link #EXTRA_NOTIFICATION_TYPE}, the code will be one of the {@code CODE_*} 961 * codes defined in {@link com.android.internal.telephony.gsm.SuppServiceNotification}. 962 * <p> 963 * Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event. 964 * @hide 965 */ 966 public static final String EXTRA_NOTIFICATION_CODE = 967 "android.telephony.extra.NOTIFICATION_CODE"; 968 969 /** 970 * {@link CharSequence} extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} 971 * which contains a human-readable message which can be displayed to the user for the 972 * supplementary service notification. 973 * <p> 974 * Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event. 975 * @hide 976 */ 977 public static final String EXTRA_NOTIFICATION_MESSAGE = 978 "android.telephony.extra.NOTIFICATION_MESSAGE"; 979 980 /* Visual voicemail protocols */ 981 982 /** 983 * The OMTP protocol. 984 */ 985 public static final String VVM_TYPE_OMTP = "vvm_type_omtp"; 986 987 /** 988 * A flavor of OMTP protocol with a different mobile originated (MO) format 989 */ 990 public static final String VVM_TYPE_CVVM = "vvm_type_cvvm"; 991 992 /** 993 * Key in bundle returned by {@link #getVisualVoicemailPackageName()}, indicating whether visual 994 * voicemail was enabled or disabled by the user. If the user never explicitly changed this 995 * setting, this key will not exist. 996 * 997 * @see #getVisualVoicemailSettings() 998 * @hide 999 */ 1000 @SystemApi 1001 public static final String EXTRA_VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL = 1002 "android.telephony.extra.VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL"; 1003 1004 /** 1005 * Key in bundle returned by {@link #getVisualVoicemailPackageName()}, indicating the voicemail 1006 * access PIN scrambled during the auto provisioning process. The user is expected to reset 1007 * their PIN if this value is not {@code null}. 1008 * 1009 * @see #getVisualVoicemailSettings() 1010 * @hide 1011 */ 1012 @SystemApi 1013 public static final String EXTRA_VOICEMAIL_SCRAMBLED_PIN_STRING = 1014 "android.telephony.extra.VOICEMAIL_SCRAMBLED_PIN_STRING"; 1015 1016 /** 1017 * @hide 1018 */ 1019 public static final String USSD_RESPONSE = "USSD_RESPONSE"; 1020 1021 /** 1022 * USSD return code success. 1023 * @hide 1024 */ 1025 public static final int USSD_RETURN_SUCCESS = 100; 1026 1027 /** 1028 * Failed code returned when the mobile network has failed to complete a USSD request. 1029 * <p> 1030 * Returned via {@link TelephonyManager.UssdResponseCallback#onReceiveUssdResponseFailed( 1031 * TelephonyManager, String, int)}. 1032 */ 1033 public static final int USSD_RETURN_FAILURE = -1; 1034 1035 /** 1036 * Failure code returned when a USSD request has failed to execute because the Telephony 1037 * service is unavailable. 1038 * <p> 1039 * Returned via {@link TelephonyManager.UssdResponseCallback#onReceiveUssdResponseFailed( 1040 * TelephonyManager, String, int)}. 1041 */ 1042 public static final int USSD_ERROR_SERVICE_UNAVAIL = -2; 1043 1044 /** 1045 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which leaves the roaming 1046 * mode set to the radio default or to the user's preference if they've indicated one. 1047 */ 1048 public static final int CDMA_ROAMING_MODE_RADIO_DEFAULT = -1; 1049 /** 1050 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which only permits 1051 * connections on home networks. 1052 */ 1053 public static final int CDMA_ROAMING_MODE_HOME = 0; 1054 /** 1055 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which permits roaming on 1056 * affiliated networks. 1057 */ 1058 public static final int CDMA_ROAMING_MODE_AFFILIATED = 1; 1059 /** 1060 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which permits roaming on 1061 * any network. 1062 */ 1063 public static final int CDMA_ROAMING_MODE_ANY = 2; 1064 1065 /** 1066 * An unknown carrier id. It could either be subscription unavailable or the subscription 1067 * carrier cannot be recognized. Unrecognized carriers here means 1068 * {@link #getSimOperator() MCC+MNC} cannot be identified. 1069 */ 1070 public static final int UNKNOWN_CARRIER_ID = -1; 1071 1072 /** 1073 * An unknown carrier id list version. 1074 * @hide 1075 */ 1076 @TestApi 1077 public static final int UNKNOWN_CARRIER_ID_LIST_VERSION = -1; 1078 1079 /** 1080 * Broadcast Action: The subscription carrier identity has changed. 1081 * This intent could be sent on the following events: 1082 * <ul> 1083 * <li>Subscription absent. Carrier identity could change from a valid id to 1084 * {@link TelephonyManager#UNKNOWN_CARRIER_ID}.</li> 1085 * <li>Subscription loaded. Carrier identity could change from 1086 * {@link TelephonyManager#UNKNOWN_CARRIER_ID} to a valid id.</li> 1087 * <li>The subscription carrier is recognized after a remote update.</li> 1088 * </ul> 1089 * The intent will have the following extra values: 1090 * <ul> 1091 * <li>{@link #EXTRA_CARRIER_ID} The up-to-date carrier id of the current subscription id. 1092 * </li> 1093 * <li>{@link #EXTRA_CARRIER_NAME} The up-to-date carrier name of the current subscription. 1094 * </li> 1095 * <li>{@link #EXTRA_SUBSCRIPTION_ID} The subscription id associated with the changed carrier 1096 * identity. 1097 * </li> 1098 * </ul> 1099 * <p class="note">This is a protected intent that can only be sent by the system. 1100 */ 1101 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1102 public static final String ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED = 1103 "android.telephony.action.SUBSCRIPTION_CARRIER_IDENTITY_CHANGED"; 1104 1105 /** 1106 * An int extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} which indicates 1107 * the updated carrier id {@link TelephonyManager#getSimCarrierId()} of 1108 * the current subscription. 1109 * <p>Will be {@link TelephonyManager#UNKNOWN_CARRIER_ID} if the subscription is unavailable or 1110 * the carrier cannot be identified. 1111 */ 1112 public static final String EXTRA_CARRIER_ID = "android.telephony.extra.CARRIER_ID"; 1113 1114 /** 1115 * An string extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} which 1116 * indicates the updated carrier name of the current subscription. 1117 * {@see TelephonyManager#getSimCarrierIdName()} 1118 * <p>Carrier name is a user-facing name of the carrier id {@link #EXTRA_CARRIER_ID}, 1119 * usually the brand name of the subsidiary (e.g. T-Mobile). 1120 */ 1121 public static final String EXTRA_CARRIER_NAME = "android.telephony.extra.CARRIER_NAME"; 1122 1123 /** 1124 * An int extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} to indicate the 1125 * subscription which has changed. 1126 */ 1127 public static final String EXTRA_SUBSCRIPTION_ID = "android.telephony.extra.SUBSCRIPTION_ID"; 1128 1129 /** 1130 * Broadcast intent action indicating that when data stall recovery is attempted by Telephony, 1131 * intended for report every data stall recovery step attempted. 1132 * 1133 * <p> 1134 * The {@link #EXTRA_RECOVERY_ACTION} extra indicates the action associated with the data 1135 * stall recovery. 1136 * The phone id where the data stall recovery is attempted. 1137 * 1138 * <p class="note"> 1139 * Requires the READ_PHONE_STATE permission. 1140 * 1141 * <p class="note"> 1142 * This is a protected intent that can only be sent by the system. 1143 * 1144 * @see #EXTRA_RECOVERY_ACTION 1145 * 1146 * @hide 1147 */ 1148 // TODO(b/78370030) : Restrict this to system applications only 1149 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1150 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 1151 public static final String ACTION_DATA_STALL_DETECTED = 1152 "android.intent.action.DATA_STALL_DETECTED"; 1153 1154 /** 1155 * An int extra used with {@link #ACTION_DATA_STALL_DETECTED} to indicate the 1156 * action associated with the data stall recovery. 1157 * 1158 * @see #ACTION_DATA_STALL_DETECTED 1159 * 1160 * @hide 1161 */ 1162 public static final String EXTRA_RECOVERY_ACTION = "recoveryAction"; 1163 1164 // 1165 // 1166 // Device Info 1167 // 1168 // 1169 1170 /** 1171 * Returns the software version number for the device, for example, 1172 * the IMEI/SV for GSM phones. Return null if the software version is 1173 * not available. 1174 * 1175 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1176 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 1177 */ 1178 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 1179 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getDeviceSoftwareVersion()1180 public String getDeviceSoftwareVersion() { 1181 return getDeviceSoftwareVersion(getSlotIndex()); 1182 } 1183 1184 /** 1185 * Returns the software version number for the device, for example, 1186 * the IMEI/SV for GSM phones. Return null if the software version is 1187 * not available. 1188 * 1189 * @param slotIndex of which deviceID is returned 1190 */ 1191 /** {@hide} */ 1192 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getDeviceSoftwareVersion(int slotIndex)1193 public String getDeviceSoftwareVersion(int slotIndex) { 1194 ITelephony telephony = getITelephony(); 1195 if (telephony == null) return null; 1196 1197 try { 1198 return telephony.getDeviceSoftwareVersionForSlot(slotIndex, getOpPackageName()); 1199 } catch (RemoteException ex) { 1200 return null; 1201 } catch (NullPointerException ex) { 1202 return null; 1203 } 1204 } 1205 1206 /** 1207 * Returns the unique device ID, for example, the IMEI for GSM and the MEID 1208 * or ESN for CDMA phones. Return null if device ID is not available. 1209 * 1210 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1211 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 1212 * 1213 * @deprecated Use (@link getImei} which returns IMEI for GSM or (@link getMeid} which returns 1214 * MEID for CDMA. 1215 */ 1216 @Deprecated 1217 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 1218 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getDeviceId()1219 public String getDeviceId() { 1220 try { 1221 ITelephony telephony = getITelephony(); 1222 if (telephony == null) 1223 return null; 1224 return telephony.getDeviceId(mContext.getOpPackageName()); 1225 } catch (RemoteException ex) { 1226 return null; 1227 } catch (NullPointerException ex) { 1228 return null; 1229 } 1230 } 1231 1232 /** 1233 * Returns the unique device ID of a subscription, for example, the IMEI for 1234 * GSM and the MEID for CDMA phones. Return null if device ID is not available. 1235 * 1236 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1237 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 1238 * 1239 * @param slotIndex of which deviceID is returned 1240 * 1241 * @deprecated Use (@link getImei} which returns IMEI for GSM or (@link getMeid} which returns 1242 * MEID for CDMA. 1243 */ 1244 @Deprecated 1245 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 1246 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getDeviceId(int slotIndex)1247 public String getDeviceId(int slotIndex) { 1248 // FIXME this assumes phoneId == slotIndex 1249 try { 1250 IPhoneSubInfo info = getSubscriberInfo(); 1251 if (info == null) 1252 return null; 1253 return info.getDeviceIdForPhone(slotIndex, mContext.getOpPackageName()); 1254 } catch (RemoteException ex) { 1255 return null; 1256 } catch (NullPointerException ex) { 1257 return null; 1258 } 1259 } 1260 1261 /** 1262 * Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not 1263 * available. 1264 * 1265 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1266 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 1267 */ 1268 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 1269 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getImei()1270 public String getImei() { 1271 return getImei(getSlotIndex()); 1272 } 1273 1274 /** 1275 * Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not 1276 * available. 1277 * 1278 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1279 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 1280 * 1281 * @param slotIndex of which IMEI is returned 1282 */ 1283 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 1284 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getImei(int slotIndex)1285 public String getImei(int slotIndex) { 1286 ITelephony telephony = getITelephony(); 1287 if (telephony == null) return null; 1288 1289 try { 1290 return telephony.getImeiForSlot(slotIndex, getOpPackageName()); 1291 } catch (RemoteException ex) { 1292 return null; 1293 } catch (NullPointerException ex) { 1294 return null; 1295 } 1296 } 1297 1298 /** 1299 * Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. 1300 * 1301 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1302 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 1303 */ 1304 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 1305 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getMeid()1306 public String getMeid() { 1307 return getMeid(getSlotIndex()); 1308 } 1309 1310 /** 1311 * Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. 1312 * 1313 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1314 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 1315 * 1316 * @param slotIndex of which MEID is returned 1317 */ 1318 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 1319 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getMeid(int slotIndex)1320 public String getMeid(int slotIndex) { 1321 ITelephony telephony = getITelephony(); 1322 if (telephony == null) return null; 1323 1324 try { 1325 return telephony.getMeidForSlot(slotIndex, getOpPackageName()); 1326 } catch (RemoteException ex) { 1327 return null; 1328 } catch (NullPointerException ex) { 1329 return null; 1330 } 1331 } 1332 1333 /** 1334 * Returns the Network Access Identifier (NAI). Return null if NAI is not available. 1335 * 1336 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1337 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 1338 */ 1339 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 1340 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getNai()1341 public String getNai() { 1342 return getNaiBySubscriberId(getSubId()); 1343 } 1344 1345 /** 1346 * Returns the NAI. Return null if NAI is not available. 1347 * 1348 * @param slotIndex of which Nai is returned 1349 */ 1350 /** {@hide}*/ getNai(int slotIndex)1351 public String getNai(int slotIndex) { 1352 int[] subId = SubscriptionManager.getSubId(slotIndex); 1353 if (subId == null) { 1354 return null; 1355 } 1356 return getNaiBySubscriberId(subId[0]); 1357 } 1358 getNaiBySubscriberId(int subId)1359 private String getNaiBySubscriberId(int subId) { 1360 try { 1361 IPhoneSubInfo info = getSubscriberInfo(); 1362 if (info == null) 1363 return null; 1364 String nai = info.getNaiForSubscriber(subId, mContext.getOpPackageName()); 1365 if (Log.isLoggable(TAG, Log.VERBOSE)) { 1366 Rlog.v(TAG, "Nai = " + nai); 1367 } 1368 return nai; 1369 } catch (RemoteException ex) { 1370 return null; 1371 } catch (NullPointerException ex) { 1372 return null; 1373 } 1374 } 1375 1376 /** 1377 * Returns the current location of the device. 1378 *<p> 1379 * If there is only one radio in the device and that radio has an LTE connection, 1380 * this method will return null. The implementation must not to try add LTE 1381 * identifiers into the existing cdma/gsm classes. 1382 *<p> 1383 * @return Current location of the device or null if not available. 1384 * 1385 * @deprecated use {@link #getAllCellInfo} instead, which returns a superset of this API. 1386 */ 1387 @Deprecated 1388 @RequiresPermission(anyOf = { 1389 android.Manifest.permission.ACCESS_COARSE_LOCATION, 1390 android.Manifest.permission.ACCESS_FINE_LOCATION 1391 }) getCellLocation()1392 public CellLocation getCellLocation() { 1393 try { 1394 ITelephony telephony = getITelephony(); 1395 if (telephony == null) { 1396 Rlog.d(TAG, "getCellLocation returning null because telephony is null"); 1397 return null; 1398 } 1399 Bundle bundle = telephony.getCellLocation(mContext.getOpPackageName()); 1400 if (bundle.isEmpty()) { 1401 Rlog.d(TAG, "getCellLocation returning null because bundle is empty"); 1402 return null; 1403 } 1404 CellLocation cl = CellLocation.newFromBundle(bundle); 1405 if (cl.isEmpty()) { 1406 Rlog.d(TAG, "getCellLocation returning null because CellLocation is empty"); 1407 return null; 1408 } 1409 return cl; 1410 } catch (RemoteException ex) { 1411 Rlog.d(TAG, "getCellLocation returning null due to RemoteException " + ex); 1412 return null; 1413 } catch (NullPointerException ex) { 1414 Rlog.d(TAG, "getCellLocation returning null due to NullPointerException " + ex); 1415 return null; 1416 } 1417 } 1418 1419 /** 1420 * Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged 1421 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 1422 * 1423 * @hide 1424 */ 1425 @RequiresPermission(android.Manifest.permission.CONTROL_LOCATION_UPDATES) enableLocationUpdates()1426 public void enableLocationUpdates() { 1427 enableLocationUpdates(getSubId()); 1428 } 1429 1430 /** 1431 * Enables location update notifications for a subscription. 1432 * {@link PhoneStateListener#onCellLocationChanged 1433 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 1434 * 1435 * @param subId for which the location updates are enabled 1436 * @hide 1437 */ 1438 @RequiresPermission(android.Manifest.permission.CONTROL_LOCATION_UPDATES) enableLocationUpdates(int subId)1439 public void enableLocationUpdates(int subId) { 1440 try { 1441 ITelephony telephony = getITelephony(); 1442 if (telephony != null) 1443 telephony.enableLocationUpdatesForSubscriber(subId); 1444 } catch (RemoteException ex) { 1445 } catch (NullPointerException ex) { 1446 } 1447 } 1448 1449 /** 1450 * Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged 1451 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 1452 * 1453 * @hide 1454 */ 1455 @RequiresPermission(android.Manifest.permission.CONTROL_LOCATION_UPDATES) disableLocationUpdates()1456 public void disableLocationUpdates() { 1457 disableLocationUpdates(getSubId()); 1458 } 1459 1460 /** @hide */ disableLocationUpdates(int subId)1461 public void disableLocationUpdates(int subId) { 1462 try { 1463 ITelephony telephony = getITelephony(); 1464 if (telephony != null) 1465 telephony.disableLocationUpdatesForSubscriber(subId); 1466 } catch (RemoteException ex) { 1467 } catch (NullPointerException ex) { 1468 } 1469 } 1470 1471 /** 1472 * Returns the neighboring cell information of the device. 1473 * 1474 * @return List of NeighboringCellInfo or null if info unavailable. 1475 * 1476 * @deprecated Use {@link #getAllCellInfo} which returns a superset of the information 1477 * from NeighboringCellInfo. 1478 */ 1479 @Deprecated 1480 @RequiresPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) getNeighboringCellInfo()1481 public List<NeighboringCellInfo> getNeighboringCellInfo() { 1482 try { 1483 ITelephony telephony = getITelephony(); 1484 if (telephony == null) 1485 return null; 1486 return telephony.getNeighboringCellInfo(mContext.getOpPackageName()); 1487 } catch (RemoteException ex) { 1488 return null; 1489 } catch (NullPointerException ex) { 1490 return null; 1491 } 1492 } 1493 1494 /** No phone radio. */ 1495 public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE; 1496 /** Phone radio is GSM. */ 1497 public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM; 1498 /** Phone radio is CDMA. */ 1499 public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA; 1500 /** Phone is via SIP. */ 1501 public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP; 1502 1503 /** 1504 * Returns the current phone type. 1505 * TODO: This is a last minute change and hence hidden. 1506 * 1507 * @see #PHONE_TYPE_NONE 1508 * @see #PHONE_TYPE_GSM 1509 * @see #PHONE_TYPE_CDMA 1510 * @see #PHONE_TYPE_SIP 1511 * 1512 * {@hide} 1513 */ 1514 @SystemApi getCurrentPhoneType()1515 public int getCurrentPhoneType() { 1516 return getCurrentPhoneType(getSubId()); 1517 } 1518 1519 /** 1520 * Returns a constant indicating the device phone type for a subscription. 1521 * 1522 * @see #PHONE_TYPE_NONE 1523 * @see #PHONE_TYPE_GSM 1524 * @see #PHONE_TYPE_CDMA 1525 * 1526 * @param subId for which phone type is returned 1527 * @hide 1528 */ 1529 @SystemApi getCurrentPhoneType(int subId)1530 public int getCurrentPhoneType(int subId) { 1531 int phoneId; 1532 if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 1533 // if we don't have any sims, we don't have subscriptions, but we 1534 // still may want to know what type of phone we've got. 1535 phoneId = 0; 1536 } else { 1537 phoneId = SubscriptionManager.getPhoneId(subId); 1538 } 1539 1540 return getCurrentPhoneTypeForSlot(phoneId); 1541 } 1542 1543 /** 1544 * See getCurrentPhoneType. 1545 * 1546 * @hide 1547 */ getCurrentPhoneTypeForSlot(int slotIndex)1548 public int getCurrentPhoneTypeForSlot(int slotIndex) { 1549 try{ 1550 ITelephony telephony = getITelephony(); 1551 if (telephony != null) { 1552 return telephony.getActivePhoneTypeForSlot(slotIndex); 1553 } else { 1554 // This can happen when the ITelephony interface is not up yet. 1555 return getPhoneTypeFromProperty(slotIndex); 1556 } 1557 } catch (RemoteException ex) { 1558 // This shouldn't happen in the normal case, as a backup we 1559 // read from the system property. 1560 return getPhoneTypeFromProperty(slotIndex); 1561 } catch (NullPointerException ex) { 1562 // This shouldn't happen in the normal case, as a backup we 1563 // read from the system property. 1564 return getPhoneTypeFromProperty(slotIndex); 1565 } 1566 } 1567 1568 /** 1569 * Returns a constant indicating the device phone type. This 1570 * indicates the type of radio used to transmit voice calls. 1571 * 1572 * @see #PHONE_TYPE_NONE 1573 * @see #PHONE_TYPE_GSM 1574 * @see #PHONE_TYPE_CDMA 1575 * @see #PHONE_TYPE_SIP 1576 */ getPhoneType()1577 public int getPhoneType() { 1578 if (!isVoiceCapable()) { 1579 return PHONE_TYPE_NONE; 1580 } 1581 return getCurrentPhoneType(); 1582 } 1583 getPhoneTypeFromProperty()1584 private int getPhoneTypeFromProperty() { 1585 return getPhoneTypeFromProperty(getPhoneId()); 1586 } 1587 1588 /** {@hide} */ getPhoneTypeFromProperty(int phoneId)1589 private int getPhoneTypeFromProperty(int phoneId) { 1590 String type = getTelephonyProperty(phoneId, 1591 TelephonyProperties.CURRENT_ACTIVE_PHONE, null); 1592 if (type == null || type.isEmpty()) { 1593 return getPhoneTypeFromNetworkType(phoneId); 1594 } 1595 return Integer.parseInt(type); 1596 } 1597 getPhoneTypeFromNetworkType()1598 private int getPhoneTypeFromNetworkType() { 1599 return getPhoneTypeFromNetworkType(getPhoneId()); 1600 } 1601 1602 /** {@hide} */ getPhoneTypeFromNetworkType(int phoneId)1603 private int getPhoneTypeFromNetworkType(int phoneId) { 1604 // When the system property CURRENT_ACTIVE_PHONE, has not been set, 1605 // use the system property for default network type. 1606 // This is a fail safe, and can only happen at first boot. 1607 String mode = getTelephonyProperty(phoneId, "ro.telephony.default_network", null); 1608 if (mode != null && !mode.isEmpty()) { 1609 return TelephonyManager.getPhoneType(Integer.parseInt(mode)); 1610 } 1611 return TelephonyManager.PHONE_TYPE_NONE; 1612 } 1613 1614 /** 1615 * This function returns the type of the phone, depending 1616 * on the network mode. 1617 * 1618 * @param networkMode 1619 * @return Phone Type 1620 * 1621 * @hide 1622 */ getPhoneType(int networkMode)1623 public static int getPhoneType(int networkMode) { 1624 switch(networkMode) { 1625 case RILConstants.NETWORK_MODE_CDMA: 1626 case RILConstants.NETWORK_MODE_CDMA_NO_EVDO: 1627 case RILConstants.NETWORK_MODE_EVDO_NO_CDMA: 1628 return PhoneConstants.PHONE_TYPE_CDMA; 1629 1630 case RILConstants.NETWORK_MODE_WCDMA_PREF: 1631 case RILConstants.NETWORK_MODE_GSM_ONLY: 1632 case RILConstants.NETWORK_MODE_WCDMA_ONLY: 1633 case RILConstants.NETWORK_MODE_GSM_UMTS: 1634 case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA: 1635 case RILConstants.NETWORK_MODE_LTE_WCDMA: 1636 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA: 1637 case RILConstants.NETWORK_MODE_TDSCDMA_ONLY: 1638 case RILConstants.NETWORK_MODE_TDSCDMA_WCDMA: 1639 case RILConstants.NETWORK_MODE_LTE_TDSCDMA: 1640 case RILConstants.NETWORK_MODE_TDSCDMA_GSM: 1641 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM: 1642 case RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA: 1643 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA: 1644 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA: 1645 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA: 1646 return PhoneConstants.PHONE_TYPE_GSM; 1647 1648 // Use CDMA Phone for the global mode including CDMA 1649 case RILConstants.NETWORK_MODE_GLOBAL: 1650 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO: 1651 case RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA: 1652 return PhoneConstants.PHONE_TYPE_CDMA; 1653 1654 case RILConstants.NETWORK_MODE_LTE_ONLY: 1655 if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) { 1656 return PhoneConstants.PHONE_TYPE_CDMA; 1657 } else { 1658 return PhoneConstants.PHONE_TYPE_GSM; 1659 } 1660 default: 1661 return PhoneConstants.PHONE_TYPE_GSM; 1662 } 1663 } 1664 1665 /** 1666 * The contents of the /proc/cmdline file 1667 */ getProcCmdLine()1668 private static String getProcCmdLine() 1669 { 1670 String cmdline = ""; 1671 FileInputStream is = null; 1672 try { 1673 is = new FileInputStream("/proc/cmdline"); 1674 byte [] buffer = new byte[2048]; 1675 int count = is.read(buffer); 1676 if (count > 0) { 1677 cmdline = new String(buffer, 0, count); 1678 } 1679 } catch (IOException e) { 1680 Rlog.d(TAG, "No /proc/cmdline exception=" + e); 1681 } finally { 1682 if (is != null) { 1683 try { 1684 is.close(); 1685 } catch (IOException e) { 1686 } 1687 } 1688 } 1689 Rlog.d(TAG, "/proc/cmdline=" + cmdline); 1690 return cmdline; 1691 } 1692 1693 /** Kernel command line */ 1694 private static final String sKernelCmdLine = getProcCmdLine(); 1695 1696 /** Pattern for selecting the product type from the kernel command line */ 1697 private static final Pattern sProductTypePattern = 1698 Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)"); 1699 1700 /** The ProductType used for LTE on CDMA devices */ 1701 private static final String sLteOnCdmaProductType = 1702 SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, ""); 1703 1704 /** 1705 * Return if the current radio is LTE on CDMA. This 1706 * is a tri-state return value as for a period of time 1707 * the mode may be unknown. 1708 * 1709 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1710 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1711 * 1712 * @hide 1713 */ getLteOnCdmaModeStatic()1714 public static int getLteOnCdmaModeStatic() { 1715 int retVal; 1716 int curVal; 1717 String productType = ""; 1718 1719 curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE, 1720 PhoneConstants.LTE_ON_CDMA_UNKNOWN); 1721 retVal = curVal; 1722 if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) { 1723 Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine); 1724 if (matcher.find()) { 1725 productType = matcher.group(1); 1726 if (sLteOnCdmaProductType.equals(productType)) { 1727 retVal = PhoneConstants.LTE_ON_CDMA_TRUE; 1728 } else { 1729 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 1730 } 1731 } else { 1732 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 1733 } 1734 } 1735 1736 Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal + 1737 " product_type='" + productType + 1738 "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'"); 1739 return retVal; 1740 } 1741 1742 // 1743 // 1744 // Current Network 1745 // 1746 // 1747 1748 /** 1749 * Returns the alphabetic name of current registered operator. 1750 * <p> 1751 * Availability: Only when user is registered to a network. Result may be 1752 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1753 * on a CDMA network). 1754 */ getNetworkOperatorName()1755 public String getNetworkOperatorName() { 1756 return getNetworkOperatorName(getSubId()); 1757 } 1758 1759 /** 1760 * Returns the alphabetic name of current registered operator 1761 * for a particular subscription. 1762 * <p> 1763 * Availability: Only when user is registered to a network. Result may be 1764 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1765 * on a CDMA network). 1766 * @param subId 1767 * @hide 1768 */ getNetworkOperatorName(int subId)1769 public String getNetworkOperatorName(int subId) { 1770 int phoneId = SubscriptionManager.getPhoneId(subId); 1771 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, ""); 1772 } 1773 1774 /** 1775 * Returns the numeric name (MCC+MNC) of current registered operator. 1776 * <p> 1777 * Availability: Only when user is registered to a network. Result may be 1778 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1779 * on a CDMA network). 1780 */ getNetworkOperator()1781 public String getNetworkOperator() { 1782 return getNetworkOperatorForPhone(getPhoneId()); 1783 } 1784 1785 /** 1786 * Returns the numeric name (MCC+MNC) of current registered operator 1787 * for a particular subscription. 1788 * <p> 1789 * Availability: Only when user is registered to a network. Result may be 1790 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1791 * on a CDMA network). 1792 * 1793 * @param subId 1794 * @hide 1795 */ getNetworkOperator(int subId)1796 public String getNetworkOperator(int subId) { 1797 int phoneId = SubscriptionManager.getPhoneId(subId); 1798 return getNetworkOperatorForPhone(phoneId); 1799 } 1800 1801 /** 1802 * Returns the numeric name (MCC+MNC) of current registered operator 1803 * for a particular subscription. 1804 * <p> 1805 * Availability: Only when user is registered to a network. Result may be 1806 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1807 * on a CDMA network). 1808 * 1809 * @param phoneId 1810 * @hide 1811 **/ getNetworkOperatorForPhone(int phoneId)1812 public String getNetworkOperatorForPhone(int phoneId) { 1813 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, ""); 1814 } 1815 1816 1817 /** 1818 * Returns the network specifier of the subscription ID pinned to the TelephonyManager. The 1819 * network specifier is used by {@link 1820 * android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to create a {@link 1821 * android.net.NetworkRequest} that connects through the subscription. 1822 * 1823 * @see android.net.NetworkRequest.Builder#setNetworkSpecifier(String) 1824 * @see #createForSubscriptionId(int) 1825 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 1826 */ getNetworkSpecifier()1827 public String getNetworkSpecifier() { 1828 return String.valueOf(getSubId()); 1829 } 1830 1831 /** 1832 * Returns the carrier config of the subscription ID pinned to the TelephonyManager. If an 1833 * invalid subscription ID is pinned to the TelephonyManager, the returned config will contain 1834 * default values. 1835 * 1836 * <p>This method may take several seconds to complete, so it should only be called from a 1837 * worker thread. 1838 * 1839 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1840 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 1841 * 1842 * @see CarrierConfigManager#getConfigForSubId(int) 1843 * @see #createForSubscriptionId(int) 1844 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 1845 */ 1846 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 1847 @WorkerThread 1848 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCarrierConfig()1849 public PersistableBundle getCarrierConfig() { 1850 CarrierConfigManager carrierConfigManager = mContext 1851 .getSystemService(CarrierConfigManager.class); 1852 return carrierConfigManager.getConfigForSubId(getSubId()); 1853 } 1854 1855 /** 1856 * Returns true if the device is considered roaming on the current 1857 * network, for GSM purposes. 1858 * <p> 1859 * Availability: Only when user registered to a network. 1860 */ isNetworkRoaming()1861 public boolean isNetworkRoaming() { 1862 return isNetworkRoaming(getSubId()); 1863 } 1864 1865 /** 1866 * Returns true if the device is considered roaming on the current 1867 * network for a subscription. 1868 * <p> 1869 * Availability: Only when user registered to a network. 1870 * 1871 * @param subId 1872 * @hide 1873 */ isNetworkRoaming(int subId)1874 public boolean isNetworkRoaming(int subId) { 1875 int phoneId = SubscriptionManager.getPhoneId(subId); 1876 return Boolean.parseBoolean(getTelephonyProperty(phoneId, 1877 TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, null)); 1878 } 1879 1880 /** 1881 * Returns the ISO country code equivalent of the MCC (Mobile Country Code) of the current 1882 * registered operator, or nearby cell information if not registered. 1883 * . 1884 * <p> 1885 * Note: Result may be unreliable on CDMA networks (use {@link #getPhoneType()} to determine 1886 * if on a CDMA network). 1887 */ getNetworkCountryIso()1888 public String getNetworkCountryIso() { 1889 return getNetworkCountryIsoForPhone(getPhoneId()); 1890 } 1891 1892 /** 1893 * Returns the ISO country code equivalent of the MCC (Mobile Country Code) of the current 1894 * registered operator, or nearby cell information if not registered. 1895 * <p> 1896 * Note: Result may be unreliable on CDMA networks (use {@link #getPhoneType()} to determine 1897 * if on a CDMA network). 1898 * 1899 * @param subId for which Network CountryIso is returned 1900 * @hide 1901 */ getNetworkCountryIso(int subId)1902 public String getNetworkCountryIso(int subId) { 1903 return getNetworkCountryIsoForPhone(getPhoneId(subId)); 1904 } 1905 1906 /** 1907 * Returns the ISO country code equivalent of the current registered 1908 * operator's MCC (Mobile Country Code) of a subscription. 1909 * <p> 1910 * Availability: Only when user is registered to a network. Result may be 1911 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1912 * on a CDMA network). 1913 * 1914 * @param phoneId for which Network CountryIso is returned 1915 */ 1916 /** {@hide} */ getNetworkCountryIsoForPhone(int phoneId)1917 public String getNetworkCountryIsoForPhone(int phoneId) { 1918 try { 1919 ITelephony telephony = getITelephony(); 1920 if (telephony == null) return ""; 1921 return telephony.getNetworkCountryIsoForPhone(phoneId); 1922 } catch (RemoteException ex) { 1923 return ""; 1924 } 1925 } 1926 1927 /* 1928 * When adding a network type to the list below, make sure to add the correct icon to 1929 * MobileSignalController.mapIconSets(). 1930 * Do not add negative types. 1931 */ 1932 /** Network type is unknown */ 1933 public static final int NETWORK_TYPE_UNKNOWN = TelephonyProtoEnums.NETWORK_TYPE_UNKNOWN; // = 0. 1934 /** Current network is GPRS */ 1935 public static final int NETWORK_TYPE_GPRS = TelephonyProtoEnums.NETWORK_TYPE_GPRS; // = 1. 1936 /** Current network is EDGE */ 1937 public static final int NETWORK_TYPE_EDGE = TelephonyProtoEnums.NETWORK_TYPE_EDGE; // = 2. 1938 /** Current network is UMTS */ 1939 public static final int NETWORK_TYPE_UMTS = TelephonyProtoEnums.NETWORK_TYPE_UMTS; // = 3. 1940 /** Current network is CDMA: Either IS95A or IS95B*/ 1941 public static final int NETWORK_TYPE_CDMA = TelephonyProtoEnums.NETWORK_TYPE_CDMA; // = 4. 1942 /** Current network is EVDO revision 0*/ 1943 public static final int NETWORK_TYPE_EVDO_0 = TelephonyProtoEnums.NETWORK_TYPE_EVDO_0; // = 5. 1944 /** Current network is EVDO revision A*/ 1945 public static final int NETWORK_TYPE_EVDO_A = TelephonyProtoEnums.NETWORK_TYPE_EVDO_A; // = 6. 1946 /** Current network is 1xRTT*/ 1947 public static final int NETWORK_TYPE_1xRTT = TelephonyProtoEnums.NETWORK_TYPE_1XRTT; // = 7. 1948 /** Current network is HSDPA */ 1949 public static final int NETWORK_TYPE_HSDPA = TelephonyProtoEnums.NETWORK_TYPE_HSDPA; // = 8. 1950 /** Current network is HSUPA */ 1951 public static final int NETWORK_TYPE_HSUPA = TelephonyProtoEnums.NETWORK_TYPE_HSUPA; // = 9. 1952 /** Current network is HSPA */ 1953 public static final int NETWORK_TYPE_HSPA = TelephonyProtoEnums.NETWORK_TYPE_HSPA; // = 10. 1954 /** Current network is iDen */ 1955 public static final int NETWORK_TYPE_IDEN = TelephonyProtoEnums.NETWORK_TYPE_IDEN; // = 11. 1956 /** Current network is EVDO revision B*/ 1957 public static final int NETWORK_TYPE_EVDO_B = TelephonyProtoEnums.NETWORK_TYPE_EVDO_B; // = 12. 1958 /** Current network is LTE */ 1959 public static final int NETWORK_TYPE_LTE = TelephonyProtoEnums.NETWORK_TYPE_LTE; // = 13. 1960 /** Current network is eHRPD */ 1961 public static final int NETWORK_TYPE_EHRPD = TelephonyProtoEnums.NETWORK_TYPE_EHRPD; // = 14. 1962 /** Current network is HSPA+ */ 1963 public static final int NETWORK_TYPE_HSPAP = TelephonyProtoEnums.NETWORK_TYPE_HSPAP; // = 15. 1964 /** Current network is GSM */ 1965 public static final int NETWORK_TYPE_GSM = TelephonyProtoEnums.NETWORK_TYPE_GSM; // = 16. 1966 /** Current network is TD_SCDMA */ 1967 public static final int NETWORK_TYPE_TD_SCDMA = 1968 TelephonyProtoEnums.NETWORK_TYPE_TD_SCDMA; // = 17. 1969 /** Current network is IWLAN */ 1970 public static final int NETWORK_TYPE_IWLAN = TelephonyProtoEnums.NETWORK_TYPE_IWLAN; // = 18. 1971 /** Current network is LTE_CA {@hide} */ 1972 public static final int NETWORK_TYPE_LTE_CA = TelephonyProtoEnums.NETWORK_TYPE_LTE_CA; // = 19. 1973 1974 /** Max network type number. Update as new types are added. Don't add negative types. {@hide} */ 1975 public static final int MAX_NETWORK_TYPE = NETWORK_TYPE_LTE_CA; 1976 /** 1977 * @return the NETWORK_TYPE_xxxx for current data connection. 1978 */ getNetworkType()1979 public int getNetworkType() { 1980 try { 1981 ITelephony telephony = getITelephony(); 1982 if (telephony != null) { 1983 return telephony.getNetworkType(); 1984 } else { 1985 // This can happen when the ITelephony interface is not up yet. 1986 return NETWORK_TYPE_UNKNOWN; 1987 } 1988 } catch(RemoteException ex) { 1989 // This shouldn't happen in the normal case 1990 return NETWORK_TYPE_UNKNOWN; 1991 } catch (NullPointerException ex) { 1992 // This could happen before phone restarts due to crashing 1993 return NETWORK_TYPE_UNKNOWN; 1994 } 1995 } 1996 1997 /** 1998 * Returns a constant indicating the radio technology (network type) 1999 * currently in use on the device for a subscription. 2000 * @return the network type 2001 * 2002 * @param subId for which network type is returned 2003 * 2004 * @see #NETWORK_TYPE_UNKNOWN 2005 * @see #NETWORK_TYPE_GPRS 2006 * @see #NETWORK_TYPE_EDGE 2007 * @see #NETWORK_TYPE_UMTS 2008 * @see #NETWORK_TYPE_HSDPA 2009 * @see #NETWORK_TYPE_HSUPA 2010 * @see #NETWORK_TYPE_HSPA 2011 * @see #NETWORK_TYPE_CDMA 2012 * @see #NETWORK_TYPE_EVDO_0 2013 * @see #NETWORK_TYPE_EVDO_A 2014 * @see #NETWORK_TYPE_EVDO_B 2015 * @see #NETWORK_TYPE_1xRTT 2016 * @see #NETWORK_TYPE_IDEN 2017 * @see #NETWORK_TYPE_LTE 2018 * @see #NETWORK_TYPE_EHRPD 2019 * @see #NETWORK_TYPE_HSPAP 2020 * 2021 * @hide 2022 */ 2023 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getNetworkType(int subId)2024 public int getNetworkType(int subId) { 2025 try { 2026 ITelephony telephony = getITelephony(); 2027 if (telephony != null) { 2028 return telephony.getNetworkTypeForSubscriber(subId, getOpPackageName()); 2029 } else { 2030 // This can happen when the ITelephony interface is not up yet. 2031 return NETWORK_TYPE_UNKNOWN; 2032 } 2033 } catch(RemoteException ex) { 2034 // This shouldn't happen in the normal case 2035 return NETWORK_TYPE_UNKNOWN; 2036 } catch (NullPointerException ex) { 2037 // This could happen before phone restarts due to crashing 2038 return NETWORK_TYPE_UNKNOWN; 2039 } 2040 } 2041 2042 /** 2043 * Returns a constant indicating the radio technology (network type) 2044 * currently in use on the device for data transmission. 2045 * 2046 * If this object has been created with {@link #createForSubscriptionId}, applies to the given 2047 * subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 2048 * 2049 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2050 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 2051 * 2052 * @return the network type 2053 * 2054 * @see #NETWORK_TYPE_UNKNOWN 2055 * @see #NETWORK_TYPE_GPRS 2056 * @see #NETWORK_TYPE_EDGE 2057 * @see #NETWORK_TYPE_UMTS 2058 * @see #NETWORK_TYPE_HSDPA 2059 * @see #NETWORK_TYPE_HSUPA 2060 * @see #NETWORK_TYPE_HSPA 2061 * @see #NETWORK_TYPE_CDMA 2062 * @see #NETWORK_TYPE_EVDO_0 2063 * @see #NETWORK_TYPE_EVDO_A 2064 * @see #NETWORK_TYPE_EVDO_B 2065 * @see #NETWORK_TYPE_1xRTT 2066 * @see #NETWORK_TYPE_IDEN 2067 * @see #NETWORK_TYPE_LTE 2068 * @see #NETWORK_TYPE_EHRPD 2069 * @see #NETWORK_TYPE_HSPAP 2070 */ 2071 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 2072 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getDataNetworkType()2073 public int getDataNetworkType() { 2074 return getDataNetworkType(getSubId(SubscriptionManager.getDefaultDataSubscriptionId())); 2075 } 2076 2077 /** 2078 * Returns a constant indicating the radio technology (network type) 2079 * currently in use on the device for data transmission for a subscription 2080 * @return the network type 2081 * 2082 * @param subId for which network type is returned 2083 * @hide 2084 */ 2085 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getDataNetworkType(int subId)2086 public int getDataNetworkType(int subId) { 2087 try{ 2088 ITelephony telephony = getITelephony(); 2089 if (telephony != null) { 2090 return telephony.getDataNetworkTypeForSubscriber(subId, getOpPackageName()); 2091 } else { 2092 // This can happen when the ITelephony interface is not up yet. 2093 return NETWORK_TYPE_UNKNOWN; 2094 } 2095 } catch(RemoteException ex) { 2096 // This shouldn't happen in the normal case 2097 return NETWORK_TYPE_UNKNOWN; 2098 } catch (NullPointerException ex) { 2099 // This could happen before phone restarts due to crashing 2100 return NETWORK_TYPE_UNKNOWN; 2101 } 2102 } 2103 2104 /** 2105 * Returns the NETWORK_TYPE_xxxx for voice 2106 * 2107 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2108 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 2109 */ 2110 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 2111 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceNetworkType()2112 public int getVoiceNetworkType() { 2113 return getVoiceNetworkType(getSubId()); 2114 } 2115 2116 /** 2117 * Returns the NETWORK_TYPE_xxxx for voice for a subId 2118 * @hide 2119 */ 2120 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceNetworkType(int subId)2121 public int getVoiceNetworkType(int subId) { 2122 try{ 2123 ITelephony telephony = getITelephony(); 2124 if (telephony != null) { 2125 return telephony.getVoiceNetworkTypeForSubscriber(subId, getOpPackageName()); 2126 } else { 2127 // This can happen when the ITelephony interface is not up yet. 2128 return NETWORK_TYPE_UNKNOWN; 2129 } 2130 } catch(RemoteException ex) { 2131 // This shouldn't happen in the normal case 2132 return NETWORK_TYPE_UNKNOWN; 2133 } catch (NullPointerException ex) { 2134 // This could happen before phone restarts due to crashing 2135 return NETWORK_TYPE_UNKNOWN; 2136 } 2137 } 2138 2139 /** 2140 * Network Class Definitions. 2141 * Do not change this order, it is used for sorting during emergency calling in 2142 * {@link TelephonyConnectionService#getFirstPhoneForEmergencyCall()}. Any newer technologies 2143 * should be added after the current definitions. 2144 */ 2145 /** Unknown network class. {@hide} */ 2146 public static final int NETWORK_CLASS_UNKNOWN = 0; 2147 /** Class of broadly defined "2G" networks. {@hide} */ 2148 public static final int NETWORK_CLASS_2_G = 1; 2149 /** Class of broadly defined "3G" networks. {@hide} */ 2150 public static final int NETWORK_CLASS_3_G = 2; 2151 /** Class of broadly defined "4G" networks. {@hide} */ 2152 public static final int NETWORK_CLASS_4_G = 3; 2153 2154 /** 2155 * Return general class of network type, such as "3G" or "4G". In cases 2156 * where classification is contentious, this method is conservative. 2157 * 2158 * @hide 2159 */ getNetworkClass(int networkType)2160 public static int getNetworkClass(int networkType) { 2161 switch (networkType) { 2162 case NETWORK_TYPE_GPRS: 2163 case NETWORK_TYPE_GSM: 2164 case NETWORK_TYPE_EDGE: 2165 case NETWORK_TYPE_CDMA: 2166 case NETWORK_TYPE_1xRTT: 2167 case NETWORK_TYPE_IDEN: 2168 return NETWORK_CLASS_2_G; 2169 case NETWORK_TYPE_UMTS: 2170 case NETWORK_TYPE_EVDO_0: 2171 case NETWORK_TYPE_EVDO_A: 2172 case NETWORK_TYPE_HSDPA: 2173 case NETWORK_TYPE_HSUPA: 2174 case NETWORK_TYPE_HSPA: 2175 case NETWORK_TYPE_EVDO_B: 2176 case NETWORK_TYPE_EHRPD: 2177 case NETWORK_TYPE_HSPAP: 2178 case NETWORK_TYPE_TD_SCDMA: 2179 return NETWORK_CLASS_3_G; 2180 case NETWORK_TYPE_LTE: 2181 case NETWORK_TYPE_IWLAN: 2182 case NETWORK_TYPE_LTE_CA: 2183 return NETWORK_CLASS_4_G; 2184 default: 2185 return NETWORK_CLASS_UNKNOWN; 2186 } 2187 } 2188 2189 /** 2190 * Returns a string representation of the radio technology (network type) 2191 * currently in use on the device. 2192 * @return the name of the radio technology 2193 * 2194 * @hide pending API council review 2195 */ getNetworkTypeName()2196 public String getNetworkTypeName() { 2197 return getNetworkTypeName(getNetworkType()); 2198 } 2199 2200 /** 2201 * Returns a string representation of the radio technology (network type) 2202 * currently in use on the device. 2203 * @param subId for which network type is returned 2204 * @return the name of the radio technology 2205 * 2206 */ 2207 /** {@hide} */ getNetworkTypeName(int type)2208 public static String getNetworkTypeName(int type) { 2209 switch (type) { 2210 case NETWORK_TYPE_GPRS: 2211 return "GPRS"; 2212 case NETWORK_TYPE_EDGE: 2213 return "EDGE"; 2214 case NETWORK_TYPE_UMTS: 2215 return "UMTS"; 2216 case NETWORK_TYPE_HSDPA: 2217 return "HSDPA"; 2218 case NETWORK_TYPE_HSUPA: 2219 return "HSUPA"; 2220 case NETWORK_TYPE_HSPA: 2221 return "HSPA"; 2222 case NETWORK_TYPE_CDMA: 2223 return "CDMA"; 2224 case NETWORK_TYPE_EVDO_0: 2225 return "CDMA - EvDo rev. 0"; 2226 case NETWORK_TYPE_EVDO_A: 2227 return "CDMA - EvDo rev. A"; 2228 case NETWORK_TYPE_EVDO_B: 2229 return "CDMA - EvDo rev. B"; 2230 case NETWORK_TYPE_1xRTT: 2231 return "CDMA - 1xRTT"; 2232 case NETWORK_TYPE_LTE: 2233 return "LTE"; 2234 case NETWORK_TYPE_EHRPD: 2235 return "CDMA - eHRPD"; 2236 case NETWORK_TYPE_IDEN: 2237 return "iDEN"; 2238 case NETWORK_TYPE_HSPAP: 2239 return "HSPA+"; 2240 case NETWORK_TYPE_GSM: 2241 return "GSM"; 2242 case NETWORK_TYPE_TD_SCDMA: 2243 return "TD_SCDMA"; 2244 case NETWORK_TYPE_IWLAN: 2245 return "IWLAN"; 2246 case NETWORK_TYPE_LTE_CA: 2247 return "LTE_CA"; 2248 default: 2249 return "UNKNOWN"; 2250 } 2251 } 2252 2253 // 2254 // 2255 // SIM Card 2256 // 2257 // 2258 2259 /** 2260 * SIM card state: Unknown. Signifies that the SIM is in transition 2261 * between states. For example, when the user inputs the SIM pin 2262 * under PIN_REQUIRED state, a query for sim status returns 2263 * this state before turning to SIM_STATE_READY. 2264 * 2265 * These are the ordinal value of IccCardConstants.State. 2266 */ 2267 public static final int SIM_STATE_UNKNOWN = 0; 2268 /** SIM card state: no SIM card is available in the device */ 2269 public static final int SIM_STATE_ABSENT = 1; 2270 /** SIM card state: Locked: requires the user's SIM PIN to unlock */ 2271 public static final int SIM_STATE_PIN_REQUIRED = 2; 2272 /** SIM card state: Locked: requires the user's SIM PUK to unlock */ 2273 public static final int SIM_STATE_PUK_REQUIRED = 3; 2274 /** SIM card state: Locked: requires a network PIN to unlock */ 2275 public static final int SIM_STATE_NETWORK_LOCKED = 4; 2276 /** SIM card state: Ready */ 2277 public static final int SIM_STATE_READY = 5; 2278 /** SIM card state: SIM Card is NOT READY */ 2279 public static final int SIM_STATE_NOT_READY = 6; 2280 /** SIM card state: SIM Card Error, permanently disabled */ 2281 public static final int SIM_STATE_PERM_DISABLED = 7; 2282 /** SIM card state: SIM Card Error, present but faulty */ 2283 public static final int SIM_STATE_CARD_IO_ERROR = 8; 2284 /** SIM card state: SIM Card restricted, present but not usable due to 2285 * carrier restrictions. 2286 */ 2287 public static final int SIM_STATE_CARD_RESTRICTED = 9; 2288 /** 2289 * SIM card state: Loaded: SIM card applications have been loaded 2290 * @hide 2291 */ 2292 @SystemApi 2293 public static final int SIM_STATE_LOADED = 10; 2294 /** 2295 * SIM card state: SIM Card is present 2296 * @hide 2297 */ 2298 @SystemApi 2299 public static final int SIM_STATE_PRESENT = 11; 2300 2301 /** 2302 * Extra included in {@link #ACTION_SIM_CARD_STATE_CHANGED} and 2303 * {@link #ACTION_SIM_APPLICATION_STATE_CHANGED} to indicate the card/application state. 2304 * 2305 * @hide 2306 */ 2307 @SystemApi 2308 public static final String EXTRA_SIM_STATE = "android.telephony.extra.SIM_STATE"; 2309 2310 /** 2311 * Broadcast Action: The sim card state has changed. 2312 * The intent will have the following extra values:</p> 2313 * <dl> 2314 * <dt>{@link #EXTRA_SIM_STATE}</dt> 2315 * <dd>The sim card state. One of: 2316 * <dl> 2317 * <dt>{@link #SIM_STATE_ABSENT}</dt> 2318 * <dd>SIM card not found</dd> 2319 * <dt>{@link #SIM_STATE_CARD_IO_ERROR}</dt> 2320 * <dd>SIM card IO error</dd> 2321 * <dt>{@link #SIM_STATE_CARD_RESTRICTED}</dt> 2322 * <dd>SIM card is restricted</dd> 2323 * <dt>{@link #SIM_STATE_PRESENT}</dt> 2324 * <dd>SIM card is present</dd> 2325 * </dl> 2326 * </dd> 2327 * </dl> 2328 * 2329 * <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission. 2330 * 2331 * <p class="note">The current state can also be queried using {@link #getSimCardState()}. 2332 * 2333 * <p class="note">This is a protected intent that can only be sent by the system. 2334 * @hide 2335 */ 2336 @SystemApi 2337 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 2338 public static final String ACTION_SIM_CARD_STATE_CHANGED = 2339 "android.telephony.action.SIM_CARD_STATE_CHANGED"; 2340 2341 /** 2342 * Broadcast Action: The sim application state has changed. 2343 * The intent will have the following extra values:</p> 2344 * <dl> 2345 * <dt>{@link #EXTRA_SIM_STATE}</dt> 2346 * <dd>The sim application state. One of: 2347 * <dl> 2348 * <dt>{@link #SIM_STATE_NOT_READY}</dt> 2349 * <dd>SIM card applications not ready</dd> 2350 * <dt>{@link #SIM_STATE_PIN_REQUIRED}</dt> 2351 * <dd>SIM card PIN locked</dd> 2352 * <dt>{@link #SIM_STATE_PUK_REQUIRED}</dt> 2353 * <dd>SIM card PUK locked</dd> 2354 * <dt>{@link #SIM_STATE_NETWORK_LOCKED}</dt> 2355 * <dd>SIM card network locked</dd> 2356 * <dt>{@link #SIM_STATE_PERM_DISABLED}</dt> 2357 * <dd>SIM card permanently disabled due to PUK failures</dd> 2358 * <dt>{@link #SIM_STATE_LOADED}</dt> 2359 * <dd>SIM card data loaded</dd> 2360 * </dl> 2361 * </dd> 2362 * </dl> 2363 * 2364 * <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission. 2365 * 2366 * <p class="note">The current state can also be queried using 2367 * {@link #getSimApplicationState()}. 2368 * 2369 * <p class="note">This is a protected intent that can only be sent by the system. 2370 * @hide 2371 */ 2372 @SystemApi 2373 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 2374 public static final String ACTION_SIM_APPLICATION_STATE_CHANGED = 2375 "android.telephony.action.SIM_APPLICATION_STATE_CHANGED"; 2376 2377 /** 2378 * Broadcast Action: Status of the SIM slots on the device has changed. 2379 * 2380 * <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission. 2381 * 2382 * <p class="note">The status can be queried using 2383 * {@link #getUiccSlotsInfo()} 2384 * 2385 * <p class="note">This is a protected intent that can only be sent by the system. 2386 * @hide 2387 */ 2388 @SystemApi 2389 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 2390 public static final String ACTION_SIM_SLOT_STATUS_CHANGED = 2391 "android.telephony.action.SIM_SLOT_STATUS_CHANGED"; 2392 2393 /** 2394 * @return true if a ICC card is present 2395 */ hasIccCard()2396 public boolean hasIccCard() { 2397 return hasIccCard(getSlotIndex()); 2398 } 2399 2400 /** 2401 * @return true if a ICC card is present for a subscription 2402 * 2403 * @param slotIndex for which icc card presence is checked 2404 */ 2405 /** {@hide} */ 2406 // FIXME Input argument slotIndex should be of type int hasIccCard(int slotIndex)2407 public boolean hasIccCard(int slotIndex) { 2408 2409 try { 2410 ITelephony telephony = getITelephony(); 2411 if (telephony == null) 2412 return false; 2413 return telephony.hasIccCardUsingSlotIndex(slotIndex); 2414 } catch (RemoteException ex) { 2415 // Assume no ICC card if remote exception which shouldn't happen 2416 return false; 2417 } catch (NullPointerException ex) { 2418 // This could happen before phone restarts due to crashing 2419 return false; 2420 } 2421 } 2422 2423 /** 2424 * Returns a constant indicating the state of the default SIM card. 2425 * 2426 * @see #SIM_STATE_UNKNOWN 2427 * @see #SIM_STATE_ABSENT 2428 * @see #SIM_STATE_PIN_REQUIRED 2429 * @see #SIM_STATE_PUK_REQUIRED 2430 * @see #SIM_STATE_NETWORK_LOCKED 2431 * @see #SIM_STATE_READY 2432 * @see #SIM_STATE_NOT_READY 2433 * @see #SIM_STATE_PERM_DISABLED 2434 * @see #SIM_STATE_CARD_IO_ERROR 2435 * @see #SIM_STATE_CARD_RESTRICTED 2436 */ getSimState()2437 public int getSimState() { 2438 int simState = getSimStateIncludingLoaded(); 2439 if (simState == SIM_STATE_LOADED) { 2440 simState = SIM_STATE_READY; 2441 } 2442 return simState; 2443 } 2444 getSimStateIncludingLoaded()2445 private int getSimStateIncludingLoaded() { 2446 int slotIndex = getSlotIndex(); 2447 // slotIndex may be invalid due to sim being absent. In that case query all slots to get 2448 // sim state 2449 if (slotIndex < 0) { 2450 // query for all slots and return absent if all sim states are absent, otherwise 2451 // return unknown 2452 for (int i = 0; i < getPhoneCount(); i++) { 2453 int simState = getSimState(i); 2454 if (simState != SIM_STATE_ABSENT) { 2455 Rlog.d(TAG, "getSimState: default sim:" + slotIndex + ", sim state for " + 2456 "slotIndex=" + i + " is " + simState + ", return state as unknown"); 2457 return SIM_STATE_UNKNOWN; 2458 } 2459 } 2460 Rlog.d(TAG, "getSimState: default sim:" + slotIndex + ", all SIMs absent, return " + 2461 "state as absent"); 2462 return SIM_STATE_ABSENT; 2463 } 2464 return SubscriptionManager.getSimStateForSlotIndex(slotIndex); 2465 } 2466 2467 /** 2468 * Returns a constant indicating the state of the default SIM card. 2469 * 2470 * @see #SIM_STATE_UNKNOWN 2471 * @see #SIM_STATE_ABSENT 2472 * @see #SIM_STATE_CARD_IO_ERROR 2473 * @see #SIM_STATE_CARD_RESTRICTED 2474 * @see #SIM_STATE_PRESENT 2475 * 2476 * @hide 2477 */ 2478 @SystemApi getSimCardState()2479 public int getSimCardState() { 2480 int simCardState = getSimState(); 2481 switch (simCardState) { 2482 case SIM_STATE_UNKNOWN: 2483 case SIM_STATE_ABSENT: 2484 case SIM_STATE_CARD_IO_ERROR: 2485 case SIM_STATE_CARD_RESTRICTED: 2486 return simCardState; 2487 default: 2488 return SIM_STATE_PRESENT; 2489 } 2490 } 2491 2492 /** 2493 * Returns a constant indicating the state of the card applications on the default SIM card. 2494 * 2495 * @see #SIM_STATE_UNKNOWN 2496 * @see #SIM_STATE_PIN_REQUIRED 2497 * @see #SIM_STATE_PUK_REQUIRED 2498 * @see #SIM_STATE_NETWORK_LOCKED 2499 * @see #SIM_STATE_NOT_READY 2500 * @see #SIM_STATE_PERM_DISABLED 2501 * @see #SIM_STATE_LOADED 2502 * 2503 * @hide 2504 */ 2505 @SystemApi getSimApplicationState()2506 public int getSimApplicationState() { 2507 int simApplicationState = getSimStateIncludingLoaded(); 2508 switch (simApplicationState) { 2509 case SIM_STATE_UNKNOWN: 2510 case SIM_STATE_ABSENT: 2511 case SIM_STATE_CARD_IO_ERROR: 2512 case SIM_STATE_CARD_RESTRICTED: 2513 return SIM_STATE_UNKNOWN; 2514 case SIM_STATE_READY: 2515 // Ready is not a valid state anymore. The state that is broadcast goes from 2516 // NOT_READY to either LOCKED or LOADED. 2517 return SIM_STATE_NOT_READY; 2518 default: 2519 return simApplicationState; 2520 } 2521 } 2522 2523 /** 2524 * Returns a constant indicating the state of the device SIM card in a slot. 2525 * 2526 * @param slotIndex 2527 * 2528 * @see #SIM_STATE_UNKNOWN 2529 * @see #SIM_STATE_ABSENT 2530 * @see #SIM_STATE_PIN_REQUIRED 2531 * @see #SIM_STATE_PUK_REQUIRED 2532 * @see #SIM_STATE_NETWORK_LOCKED 2533 * @see #SIM_STATE_READY 2534 * @see #SIM_STATE_NOT_READY 2535 * @see #SIM_STATE_PERM_DISABLED 2536 * @see #SIM_STATE_CARD_IO_ERROR 2537 * @see #SIM_STATE_CARD_RESTRICTED 2538 */ getSimState(int slotIndex)2539 public int getSimState(int slotIndex) { 2540 int simState = SubscriptionManager.getSimStateForSlotIndex(slotIndex); 2541 if (simState == SIM_STATE_LOADED) { 2542 simState = SIM_STATE_READY; 2543 } 2544 return simState; 2545 } 2546 2547 /** 2548 * Returns the MCC+MNC (mobile country code + mobile network code) of the 2549 * provider of the SIM. 5 or 6 decimal digits. 2550 * <p> 2551 * Availability: SIM state must be {@link #SIM_STATE_READY} 2552 * 2553 * @see #getSimState 2554 */ getSimOperator()2555 public String getSimOperator() { 2556 return getSimOperatorNumeric(); 2557 } 2558 2559 /** 2560 * Returns the MCC+MNC (mobile country code + mobile network code) of the 2561 * provider of the SIM. 5 or 6 decimal digits. 2562 * <p> 2563 * Availability: SIM state must be {@link #SIM_STATE_READY} 2564 * 2565 * @see #getSimState 2566 * 2567 * @param subId for which SimOperator is returned 2568 * @hide 2569 */ getSimOperator(int subId)2570 public String getSimOperator(int subId) { 2571 return getSimOperatorNumeric(subId); 2572 } 2573 2574 /** 2575 * Returns the MCC+MNC (mobile country code + mobile network code) of the 2576 * provider of the SIM. 5 or 6 decimal digits. 2577 * <p> 2578 * Availability: SIM state must be {@link #SIM_STATE_READY} 2579 * 2580 * @see #getSimState 2581 * @hide 2582 */ getSimOperatorNumeric()2583 public String getSimOperatorNumeric() { 2584 int subId = mSubId; 2585 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 2586 subId = SubscriptionManager.getDefaultDataSubscriptionId(); 2587 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 2588 subId = SubscriptionManager.getDefaultSmsSubscriptionId(); 2589 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 2590 subId = SubscriptionManager.getDefaultVoiceSubscriptionId(); 2591 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 2592 subId = SubscriptionManager.getDefaultSubscriptionId(); 2593 } 2594 } 2595 } 2596 } 2597 return getSimOperatorNumeric(subId); 2598 } 2599 2600 /** 2601 * Returns the MCC+MNC (mobile country code + mobile network code) of the 2602 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 2603 * <p> 2604 * Availability: SIM state must be {@link #SIM_STATE_READY} 2605 * 2606 * @see #getSimState 2607 * 2608 * @param subId for which SimOperator is returned 2609 * @hide 2610 */ getSimOperatorNumeric(int subId)2611 public String getSimOperatorNumeric(int subId) { 2612 int phoneId = SubscriptionManager.getPhoneId(subId); 2613 return getSimOperatorNumericForPhone(phoneId); 2614 } 2615 2616 /** 2617 * Returns the MCC+MNC (mobile country code + mobile network code) of the 2618 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 2619 * <p> 2620 * 2621 * @param phoneId for which SimOperator is returned 2622 * @hide 2623 */ getSimOperatorNumericForPhone(int phoneId)2624 public String getSimOperatorNumericForPhone(int phoneId) { 2625 return getTelephonyProperty(phoneId, 2626 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, ""); 2627 } 2628 2629 /** 2630 * Returns the Service Provider Name (SPN). 2631 * <p> 2632 * Availability: SIM state must be {@link #SIM_STATE_READY} 2633 * 2634 * @see #getSimState 2635 */ getSimOperatorName()2636 public String getSimOperatorName() { 2637 return getSimOperatorNameForPhone(getPhoneId()); 2638 } 2639 2640 /** 2641 * Returns the Service Provider Name (SPN). 2642 * <p> 2643 * Availability: SIM state must be {@link #SIM_STATE_READY} 2644 * 2645 * @see #getSimState 2646 * 2647 * @param subId for which SimOperatorName is returned 2648 * @hide 2649 */ getSimOperatorName(int subId)2650 public String getSimOperatorName(int subId) { 2651 int phoneId = SubscriptionManager.getPhoneId(subId); 2652 return getSimOperatorNameForPhone(phoneId); 2653 } 2654 2655 /** 2656 * Returns the Service Provider Name (SPN). 2657 * 2658 * @hide 2659 */ getSimOperatorNameForPhone(int phoneId)2660 public String getSimOperatorNameForPhone(int phoneId) { 2661 return getTelephonyProperty(phoneId, 2662 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, ""); 2663 } 2664 2665 /** 2666 * Returns the ISO country code equivalent for the SIM provider's country code. 2667 */ getSimCountryIso()2668 public String getSimCountryIso() { 2669 return getSimCountryIsoForPhone(getPhoneId()); 2670 } 2671 2672 /** 2673 * Returns the ISO country code equivalent for the SIM provider's country code. 2674 * 2675 * @param subId for which SimCountryIso is returned 2676 * @hide 2677 */ getSimCountryIso(int subId)2678 public String getSimCountryIso(int subId) { 2679 int phoneId = SubscriptionManager.getPhoneId(subId); 2680 return getSimCountryIsoForPhone(phoneId); 2681 } 2682 2683 /** 2684 * Returns the ISO country code equivalent for the SIM provider's country code. 2685 * 2686 * @hide 2687 */ getSimCountryIsoForPhone(int phoneId)2688 public String getSimCountryIsoForPhone(int phoneId) { 2689 return getTelephonyProperty(phoneId, 2690 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, ""); 2691 } 2692 2693 /** 2694 * Returns the serial number of the SIM, if applicable. Return null if it is 2695 * unavailable. 2696 * 2697 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2698 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 2699 */ 2700 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 2701 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getSimSerialNumber()2702 public String getSimSerialNumber() { 2703 return getSimSerialNumber(getSubId()); 2704 } 2705 2706 /** 2707 * Returns the serial number for the given subscription, if applicable. Return null if it is 2708 * unavailable. 2709 * <p> 2710 * @param subId for which Sim Serial number is returned 2711 * @hide 2712 */ 2713 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getSimSerialNumber(int subId)2714 public String getSimSerialNumber(int subId) { 2715 try { 2716 IPhoneSubInfo info = getSubscriberInfo(); 2717 if (info == null) 2718 return null; 2719 return info.getIccSerialNumberForSubscriber(subId, mContext.getOpPackageName()); 2720 } catch (RemoteException ex) { 2721 return null; 2722 } catch (NullPointerException ex) { 2723 // This could happen before phone restarts due to crashing 2724 return null; 2725 } 2726 } 2727 2728 /** 2729 * Return if the current radio is LTE on CDMA. This 2730 * is a tri-state return value as for a period of time 2731 * the mode may be unknown. 2732 * 2733 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 2734 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 2735 * 2736 * @hide 2737 */ 2738 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getLteOnCdmaMode()2739 public int getLteOnCdmaMode() { 2740 return getLteOnCdmaMode(getSubId()); 2741 } 2742 2743 /** 2744 * Return if the current radio is LTE on CDMA for Subscription. This 2745 * is a tri-state return value as for a period of time 2746 * the mode may be unknown. 2747 * 2748 * @param subId for which radio is LTE on CDMA is returned 2749 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 2750 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 2751 * @hide 2752 */ 2753 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getLteOnCdmaMode(int subId)2754 public int getLteOnCdmaMode(int subId) { 2755 try { 2756 ITelephony telephony = getITelephony(); 2757 if (telephony == null) 2758 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 2759 return telephony.getLteOnCdmaModeForSubscriber(subId, getOpPackageName()); 2760 } catch (RemoteException ex) { 2761 // Assume no ICC card if remote exception which shouldn't happen 2762 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 2763 } catch (NullPointerException ex) { 2764 // This could happen before phone restarts due to crashing 2765 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 2766 } 2767 } 2768 2769 /** 2770 * Gets all the UICC slots. 2771 * 2772 * @return UiccSlotInfo array. 2773 * 2774 * @hide 2775 */ 2776 @SystemApi 2777 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getUiccSlotsInfo()2778 public UiccSlotInfo[] getUiccSlotsInfo() { 2779 try { 2780 ITelephony telephony = getITelephony(); 2781 if (telephony == null) { 2782 return null; 2783 } 2784 return telephony.getUiccSlotsInfo(); 2785 } catch (RemoteException e) { 2786 return null; 2787 } 2788 } 2789 2790 /** 2791 * Test method to reload the UICC profile. 2792 * 2793 * @hide 2794 */ 2795 @TestApi 2796 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) refreshUiccProfile()2797 public void refreshUiccProfile() { 2798 try { 2799 ITelephony telephony = getITelephony(); 2800 telephony.refreshUiccProfile(mSubId); 2801 } catch (RemoteException ex) { 2802 Rlog.w(TAG, "RemoteException", ex); 2803 } 2804 } 2805 2806 /** 2807 * Map logicalSlot to physicalSlot, and activate the physicalSlot if it is inactive. For 2808 * example, passing the physicalSlots array [1, 0] means mapping the first item 1, which is 2809 * physical slot index 1, to the logical slot 0; and mapping the second item 0, which is 2810 * physical slot index 0, to the logical slot 1. The index of the array means the index of the 2811 * logical slots. 2812 * 2813 * @param physicalSlots The content of the array represents the physical slot index. The array 2814 * size should be same as {@link #getUiccSlotsInfo()}. 2815 * @return boolean Return true if the switch succeeds, false if the switch fails. 2816 * @hide 2817 */ 2818 @SystemApi 2819 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) switchSlots(int[] physicalSlots)2820 public boolean switchSlots(int[] physicalSlots) { 2821 try { 2822 ITelephony telephony = getITelephony(); 2823 if (telephony == null) { 2824 return false; 2825 } 2826 return telephony.switchSlots(physicalSlots); 2827 } catch (RemoteException e) { 2828 return false; 2829 } 2830 } 2831 2832 // 2833 // 2834 // Subscriber Info 2835 // 2836 // 2837 2838 /** 2839 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 2840 * Return null if it is unavailable. 2841 * 2842 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2843 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 2844 */ 2845 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 2846 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getSubscriberId()2847 public String getSubscriberId() { 2848 return getSubscriberId(getSubId()); 2849 } 2850 2851 /** 2852 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone 2853 * for a subscription. 2854 * Return null if it is unavailable. 2855 * 2856 * @param subId whose subscriber id is returned 2857 * @hide 2858 */ 2859 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getSubscriberId(int subId)2860 public String getSubscriberId(int subId) { 2861 try { 2862 IPhoneSubInfo info = getSubscriberInfo(); 2863 if (info == null) 2864 return null; 2865 return info.getSubscriberIdForSubscriber(subId, mContext.getOpPackageName()); 2866 } catch (RemoteException ex) { 2867 return null; 2868 } catch (NullPointerException ex) { 2869 // This could happen before phone restarts due to crashing 2870 return null; 2871 } 2872 } 2873 2874 /** 2875 * Returns Carrier specific information that will be used to encrypt the IMSI and IMPI. 2876 * This includes the public key and the key identifier. For multi-sim devices, if no subId 2877 * has been specified, we will return the value for the dafault data sim. 2878 * Return null if it is unavailable. 2879 * <p> 2880 * Requires Permission: 2881 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2882 * @param keyType whether the key is being used for wlan or epdg. Valid key types are 2883 * {@link TelephonyManager#KEY_TYPE_EPDG} or 2884 * {@link TelephonyManager#KEY_TYPE_WLAN}. 2885 * @return ImsiEncryptionInfo Carrier specific information that will be used to encrypt the 2886 * IMSI and IMPI. This includes the public key and the key identifier. This information 2887 * will be stored in the device keystore. The system will return a null when no key was 2888 * found, and the carrier does not require a key. The system will throw 2889 * IllegalArgumentException when an invalid key is sent or when key is required but 2890 * not found. 2891 * @hide 2892 */ getCarrierInfoForImsiEncryption(int keyType)2893 public ImsiEncryptionInfo getCarrierInfoForImsiEncryption(int keyType) { 2894 try { 2895 IPhoneSubInfo info = getSubscriberInfo(); 2896 if (info == null) { 2897 Rlog.e(TAG,"IMSI error: Subscriber Info is null"); 2898 return null; 2899 } 2900 int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId()); 2901 if (keyType != KEY_TYPE_EPDG && keyType != KEY_TYPE_WLAN) { 2902 throw new IllegalArgumentException("IMSI error: Invalid key type"); 2903 } 2904 ImsiEncryptionInfo imsiEncryptionInfo = info.getCarrierInfoForImsiEncryption( 2905 subId, keyType, mContext.getOpPackageName()); 2906 if (imsiEncryptionInfo == null && isImsiEncryptionRequired(subId, keyType)) { 2907 Rlog.e(TAG, "IMSI error: key is required but not found"); 2908 throw new IllegalArgumentException("IMSI error: key is required but not found"); 2909 } 2910 return imsiEncryptionInfo; 2911 } catch (RemoteException ex) { 2912 Rlog.e(TAG, "getCarrierInfoForImsiEncryption RemoteException" + ex); 2913 } catch (NullPointerException ex) { 2914 // This could happen before phone restarts due to crashing 2915 Rlog.e(TAG, "getCarrierInfoForImsiEncryption NullPointerException" + ex); 2916 } 2917 return null; 2918 } 2919 2920 /** 2921 * Resets the Carrier Keys in the database. This involves 2 steps: 2922 * 1. Delete the keys from the database. 2923 * 2. Send an intent to download new Certificates. 2924 * <p> 2925 * Requires Permission: 2926 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2927 * @hide 2928 */ resetCarrierKeysForImsiEncryption()2929 public void resetCarrierKeysForImsiEncryption() { 2930 try { 2931 IPhoneSubInfo info = getSubscriberInfo(); 2932 if (info == null) { 2933 Rlog.e(TAG, "IMSI error: Subscriber Info is null"); 2934 if (!isSystemProcess()) { 2935 throw new RuntimeException("IMSI error: Subscriber Info is null"); 2936 } 2937 return; 2938 } 2939 int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId()); 2940 info.resetCarrierKeysForImsiEncryption(subId, mContext.getOpPackageName()); 2941 } catch (RemoteException ex) { 2942 Rlog.e(TAG, "getCarrierInfoForImsiEncryption RemoteException" + ex); 2943 if (!isSystemProcess()) { 2944 ex.rethrowAsRuntimeException(); 2945 } 2946 } 2947 } 2948 2949 /** 2950 * @param keyAvailability bitmask that defines the availabilty of keys for a type. 2951 * @param keyType the key type which is being checked. (WLAN, EPDG) 2952 * @return true if the digit at position keyType is 1, else false. 2953 * @hide 2954 */ isKeyEnabled(int keyAvailability, int keyType)2955 private static boolean isKeyEnabled(int keyAvailability, int keyType) { 2956 int returnValue = (keyAvailability >> (keyType - 1)) & 1; 2957 return (returnValue == 1) ? true : false; 2958 } 2959 2960 /** 2961 * If Carrier requires Imsi to be encrypted. 2962 * @hide 2963 */ isImsiEncryptionRequired(int subId, int keyType)2964 private boolean isImsiEncryptionRequired(int subId, int keyType) { 2965 CarrierConfigManager configManager = 2966 (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE); 2967 if (configManager == null) { 2968 return false; 2969 } 2970 PersistableBundle pb = configManager.getConfigForSubId(subId); 2971 if (pb == null) { 2972 return false; 2973 } 2974 int keyAvailability = pb.getInt(CarrierConfigManager.IMSI_KEY_AVAILABILITY_INT); 2975 return isKeyEnabled(keyAvailability, keyType); 2976 } 2977 2978 /** 2979 * Sets the Carrier specific information that will be used to encrypt the IMSI and IMPI. 2980 * This includes the public key and the key identifier. This information will be stored in the 2981 * device keystore. 2982 * <p> 2983 * Requires Permission: 2984 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2985 * @param imsiEncryptionInfo which includes the Key Type, the Public Key 2986 * (java.security.PublicKey) and the Key Identifier.and the Key Identifier. 2987 * The keyIdentifier Attribute value pair that helps a server locate 2988 * the private key to decrypt the permanent identity. This field is 2989 * optional and if it is present then it’s always separated from encrypted 2990 * permanent identity with “,”. Key identifier AVP is presented in ASCII string 2991 * with “name=value” format. 2992 * @hide 2993 */ setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo)2994 public void setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo) { 2995 try { 2996 IPhoneSubInfo info = getSubscriberInfo(); 2997 if (info == null) return; 2998 info.setCarrierInfoForImsiEncryption(mSubId, mContext.getOpPackageName(), 2999 imsiEncryptionInfo); 3000 } catch (NullPointerException ex) { 3001 // This could happen before phone restarts due to crashing 3002 return; 3003 } catch (RemoteException ex) { 3004 Rlog.e(TAG, "setCarrierInfoForImsiEncryption RemoteException", ex); 3005 return; 3006 } 3007 } 3008 3009 /** 3010 * Returns the Group Identifier Level1 for a GSM phone. 3011 * Return null if it is unavailable. 3012 * 3013 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3014 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3015 */ 3016 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 3017 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getGroupIdLevel1()3018 public String getGroupIdLevel1() { 3019 try { 3020 IPhoneSubInfo info = getSubscriberInfo(); 3021 if (info == null) 3022 return null; 3023 return info.getGroupIdLevel1ForSubscriber(getSubId(), mContext.getOpPackageName()); 3024 } catch (RemoteException ex) { 3025 return null; 3026 } catch (NullPointerException ex) { 3027 // This could happen before phone restarts due to crashing 3028 return null; 3029 } 3030 } 3031 3032 /** 3033 * Returns the Group Identifier Level1 for a GSM phone for a particular subscription. 3034 * Return null if it is unavailable. 3035 * 3036 * @param subId whose subscriber id is returned 3037 * @hide 3038 */ 3039 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getGroupIdLevel1(int subId)3040 public String getGroupIdLevel1(int subId) { 3041 try { 3042 IPhoneSubInfo info = getSubscriberInfo(); 3043 if (info == null) 3044 return null; 3045 return info.getGroupIdLevel1ForSubscriber(subId, mContext.getOpPackageName()); 3046 } catch (RemoteException ex) { 3047 return null; 3048 } catch (NullPointerException ex) { 3049 // This could happen before phone restarts due to crashing 3050 return null; 3051 } 3052 } 3053 3054 /** 3055 * Returns the phone number string for line 1, for example, the MSISDN 3056 * for a GSM phone. Return null if it is unavailable. 3057 * 3058 * <p>Requires Permission: 3059 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}, 3060 * {@link android.Manifest.permission#READ_SMS READ_SMS}, 3061 * {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS}, 3062 * that the caller is the default SMS app, 3063 * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}). 3064 */ 3065 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges or default SMS app 3066 @RequiresPermission(anyOf = { 3067 android.Manifest.permission.READ_PHONE_STATE, 3068 android.Manifest.permission.READ_SMS, 3069 android.Manifest.permission.READ_PHONE_NUMBERS 3070 }) getLine1Number()3071 public String getLine1Number() { 3072 return getLine1Number(getSubId()); 3073 } 3074 3075 /** 3076 * Returns the phone number string for line 1, for example, the MSISDN 3077 * for a GSM phone for a particular subscription. Return null if it is unavailable. 3078 * <p> 3079 * The default SMS app can also use this. 3080 * 3081 * @param subId whose phone number for line 1 is returned 3082 * @hide 3083 */ 3084 @RequiresPermission(anyOf = { 3085 android.Manifest.permission.READ_PHONE_STATE, 3086 android.Manifest.permission.READ_SMS, 3087 android.Manifest.permission.READ_PHONE_NUMBERS 3088 }) getLine1Number(int subId)3089 public String getLine1Number(int subId) { 3090 String number = null; 3091 try { 3092 ITelephony telephony = getITelephony(); 3093 if (telephony != null) 3094 number = telephony.getLine1NumberForDisplay(subId, mContext.getOpPackageName()); 3095 } catch (RemoteException ex) { 3096 } catch (NullPointerException ex) { 3097 } 3098 if (number != null) { 3099 return number; 3100 } 3101 try { 3102 IPhoneSubInfo info = getSubscriberInfo(); 3103 if (info == null) 3104 return null; 3105 return info.getLine1NumberForSubscriber(subId, mContext.getOpPackageName()); 3106 } catch (RemoteException ex) { 3107 return null; 3108 } catch (NullPointerException ex) { 3109 // This could happen before phone restarts due to crashing 3110 return null; 3111 } 3112 } 3113 3114 /** 3115 * Set the line 1 phone number string and its alphatag for the current ICCID 3116 * for display purpose only, for example, displayed in Phone Status. It won't 3117 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 3118 * value. 3119 * 3120 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3121 * 3122 * @param alphaTag alpha-tagging of the dailing nubmer 3123 * @param number The dialing number 3124 * @return true if the operation was executed correctly. 3125 */ setLine1NumberForDisplay(String alphaTag, String number)3126 public boolean setLine1NumberForDisplay(String alphaTag, String number) { 3127 return setLine1NumberForDisplay(getSubId(), alphaTag, number); 3128 } 3129 3130 /** 3131 * Set the line 1 phone number string and its alphatag for the current ICCID 3132 * for display purpose only, for example, displayed in Phone Status. It won't 3133 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 3134 * value. 3135 * 3136 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3137 * 3138 * @param subId the subscriber that the alphatag and dialing number belongs to. 3139 * @param alphaTag alpha-tagging of the dailing nubmer 3140 * @param number The dialing number 3141 * @return true if the operation was executed correctly. 3142 * @hide 3143 */ setLine1NumberForDisplay(int subId, String alphaTag, String number)3144 public boolean setLine1NumberForDisplay(int subId, String alphaTag, String number) { 3145 try { 3146 ITelephony telephony = getITelephony(); 3147 if (telephony != null) 3148 return telephony.setLine1NumberForDisplayForSubscriber(subId, alphaTag, number); 3149 } catch (RemoteException ex) { 3150 } catch (NullPointerException ex) { 3151 } 3152 return false; 3153 } 3154 3155 /** 3156 * Returns the alphabetic identifier associated with the line 1 number. 3157 * Return null if it is unavailable. 3158 * @hide 3159 * nobody seems to call this. 3160 */ 3161 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getLine1AlphaTag()3162 public String getLine1AlphaTag() { 3163 return getLine1AlphaTag(getSubId()); 3164 } 3165 3166 /** 3167 * Returns the alphabetic identifier associated with the line 1 number 3168 * for a subscription. 3169 * Return null if it is unavailable. 3170 * @param subId whose alphabetic identifier associated with line 1 is returned 3171 * nobody seems to call this. 3172 * @hide 3173 */ 3174 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getLine1AlphaTag(int subId)3175 public String getLine1AlphaTag(int subId) { 3176 String alphaTag = null; 3177 try { 3178 ITelephony telephony = getITelephony(); 3179 if (telephony != null) 3180 alphaTag = telephony.getLine1AlphaTagForDisplay(subId, 3181 getOpPackageName()); 3182 } catch (RemoteException ex) { 3183 } catch (NullPointerException ex) { 3184 } 3185 if (alphaTag != null) { 3186 return alphaTag; 3187 } 3188 try { 3189 IPhoneSubInfo info = getSubscriberInfo(); 3190 if (info == null) 3191 return null; 3192 return info.getLine1AlphaTagForSubscriber(subId, getOpPackageName()); 3193 } catch (RemoteException ex) { 3194 return null; 3195 } catch (NullPointerException ex) { 3196 // This could happen before phone restarts due to crashing 3197 return null; 3198 } 3199 } 3200 3201 /** 3202 * Return the set of subscriber IDs that should be considered as "merged 3203 * together" for data usage purposes. This is commonly {@code null} to 3204 * indicate no merging is required. Any returned subscribers are sorted in a 3205 * deterministic order. 3206 * 3207 * @hide 3208 */ getMergedSubscriberIds()3209 public @Nullable String[] getMergedSubscriberIds() { 3210 try { 3211 ITelephony telephony = getITelephony(); 3212 if (telephony != null) 3213 return telephony.getMergedSubscriberIds(getOpPackageName()); 3214 } catch (RemoteException ex) { 3215 } catch (NullPointerException ex) { 3216 } 3217 return null; 3218 } 3219 3220 /** 3221 * Returns the MSISDN string. 3222 * for a GSM phone. Return null if it is unavailable. 3223 * 3224 * @hide 3225 */ 3226 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getMsisdn()3227 public String getMsisdn() { 3228 return getMsisdn(getSubId()); 3229 } 3230 3231 /** 3232 * Returns the MSISDN string. 3233 * for a GSM phone. Return null if it is unavailable. 3234 * 3235 * @param subId for which msisdn is returned 3236 * @hide 3237 */ 3238 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getMsisdn(int subId)3239 public String getMsisdn(int subId) { 3240 try { 3241 IPhoneSubInfo info = getSubscriberInfo(); 3242 if (info == null) 3243 return null; 3244 return info.getMsisdnForSubscriber(subId, getOpPackageName()); 3245 } catch (RemoteException ex) { 3246 return null; 3247 } catch (NullPointerException ex) { 3248 // This could happen before phone restarts due to crashing 3249 return null; 3250 } 3251 } 3252 3253 /** 3254 * Returns the voice mail number. Return null if it is unavailable. 3255 * 3256 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3257 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3258 */ 3259 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 3260 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceMailNumber()3261 public String getVoiceMailNumber() { 3262 return getVoiceMailNumber(getSubId()); 3263 } 3264 3265 /** 3266 * Returns the voice mail number for a subscription. 3267 * Return null if it is unavailable. 3268 * @param subId whose voice mail number is returned 3269 * @hide 3270 */ 3271 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceMailNumber(int subId)3272 public String getVoiceMailNumber(int subId) { 3273 try { 3274 IPhoneSubInfo info = getSubscriberInfo(); 3275 if (info == null) 3276 return null; 3277 return info.getVoiceMailNumberForSubscriber(subId, getOpPackageName()); 3278 } catch (RemoteException ex) { 3279 return null; 3280 } catch (NullPointerException ex) { 3281 // This could happen before phone restarts due to crashing 3282 return null; 3283 } 3284 } 3285 3286 /** 3287 * Returns the complete voice mail number. Return null if it is unavailable. 3288 * 3289 * @hide 3290 */ 3291 @RequiresPermission(android.Manifest.permission.CALL_PRIVILEGED) getCompleteVoiceMailNumber()3292 public String getCompleteVoiceMailNumber() { 3293 return getCompleteVoiceMailNumber(getSubId()); 3294 } 3295 3296 /** 3297 * Returns the complete voice mail number. Return null if it is unavailable. 3298 * 3299 * @param subId 3300 * @hide 3301 */ 3302 @RequiresPermission(android.Manifest.permission.CALL_PRIVILEGED) getCompleteVoiceMailNumber(int subId)3303 public String getCompleteVoiceMailNumber(int subId) { 3304 try { 3305 IPhoneSubInfo info = getSubscriberInfo(); 3306 if (info == null) 3307 return null; 3308 return info.getCompleteVoiceMailNumberForSubscriber(subId); 3309 } catch (RemoteException ex) { 3310 return null; 3311 } catch (NullPointerException ex) { 3312 // This could happen before phone restarts due to crashing 3313 return null; 3314 } 3315 } 3316 3317 /** 3318 * Sets the voice mail number. 3319 * 3320 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3321 * 3322 * @param alphaTag The alpha tag to display. 3323 * @param number The voicemail number. 3324 */ setVoiceMailNumber(String alphaTag, String number)3325 public boolean setVoiceMailNumber(String alphaTag, String number) { 3326 return setVoiceMailNumber(getSubId(), alphaTag, number); 3327 } 3328 3329 /** 3330 * Sets the voicemail number for the given subscriber. 3331 * 3332 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3333 * 3334 * @param subId The subscription id. 3335 * @param alphaTag The alpha tag to display. 3336 * @param number The voicemail number. 3337 * @hide 3338 */ setVoiceMailNumber(int subId, String alphaTag, String number)3339 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { 3340 try { 3341 ITelephony telephony = getITelephony(); 3342 if (telephony != null) 3343 return telephony.setVoiceMailNumber(subId, alphaTag, number); 3344 } catch (RemoteException ex) { 3345 } catch (NullPointerException ex) { 3346 } 3347 return false; 3348 } 3349 3350 /** 3351 * Enables or disables the visual voicemail client for a phone account. 3352 * 3353 * <p>Requires that the calling app is the default dialer, or has carrier privileges (see 3354 * {@link #hasCarrierPrivileges}), or has permission 3355 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 3356 * 3357 * @param phoneAccountHandle the phone account to change the client state 3358 * @param enabled the new state of the client 3359 * @hide 3360 * @deprecated Visual voicemail no longer in telephony. {@link VisualVoicemailService} should 3361 * be implemented instead. 3362 */ 3363 @SystemApi 3364 @SuppressLint("Doclava125") setVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled)3365 public void setVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled){ 3366 } 3367 3368 /** 3369 * Returns whether the visual voicemail client is enabled. 3370 * 3371 * @param phoneAccountHandle the phone account to check for. 3372 * @return {@code true} when the visual voicemail client is enabled for this client 3373 * @hide 3374 * @deprecated Visual voicemail no longer in telephony. {@link VisualVoicemailService} should 3375 * be implemented instead. 3376 */ 3377 @SystemApi 3378 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 3379 @SuppressLint("Doclava125") isVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle)3380 public boolean isVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle){ 3381 return false; 3382 } 3383 3384 /** 3385 * Returns an opaque bundle of settings formerly used by the visual voicemail client for the 3386 * subscription ID pinned to the TelephonyManager, or {@code null} if the subscription ID is 3387 * invalid. This method allows the system dialer to migrate settings out of the pre-O visual 3388 * voicemail client in telephony. 3389 * 3390 * <p>Requires the caller to be the system dialer. 3391 * 3392 * @see #KEY_VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL 3393 * @see #KEY_VOICEMAIL_SCRAMBLED_PIN_STRING 3394 * 3395 * @hide 3396 */ 3397 @SystemApi 3398 @SuppressLint("Doclava125") 3399 @Nullable getVisualVoicemailSettings()3400 public Bundle getVisualVoicemailSettings(){ 3401 try { 3402 ITelephony telephony = getITelephony(); 3403 if (telephony != null) { 3404 return telephony 3405 .getVisualVoicemailSettings(mContext.getOpPackageName(), mSubId); 3406 } 3407 } catch (RemoteException ex) { 3408 } catch (NullPointerException ex) { 3409 } 3410 return null; 3411 } 3412 3413 /** 3414 * Returns the package responsible of processing visual voicemail for the subscription ID pinned 3415 * to the TelephonyManager. Returns {@code null} when there is no package responsible for 3416 * processing visual voicemail for the subscription. 3417 * 3418 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3419 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3420 * 3421 * @see #createForSubscriptionId(int) 3422 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 3423 * @see VisualVoicemailService 3424 */ 3425 @Nullable 3426 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 3427 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVisualVoicemailPackageName()3428 public String getVisualVoicemailPackageName() { 3429 try { 3430 ITelephony telephony = getITelephony(); 3431 if (telephony != null) { 3432 return telephony 3433 .getVisualVoicemailPackageName(mContext.getOpPackageName(), getSubId()); 3434 } 3435 } catch (RemoteException ex) { 3436 } catch (NullPointerException ex) { 3437 } 3438 return null; 3439 } 3440 3441 /** 3442 * Set the visual voicemail SMS filter settings for the subscription ID pinned 3443 * to the TelephonyManager. 3444 * When the filter is enabled, {@link 3445 * VisualVoicemailService#onSmsReceived(VisualVoicemailTask, VisualVoicemailSms)} will be 3446 * called when a SMS matching the settings is received. Caller must be the default dialer, 3447 * system dialer, or carrier visual voicemail app. 3448 * 3449 * @param settings The settings for the filter, or {@code null} to disable the filter. 3450 * 3451 * @see {@link TelecomManager#getDefaultDialerPackage()} 3452 * @see {@link CarrierConfigManager#KEY_CARRIER_VVM_PACKAGE_NAME_STRING_ARRAY} 3453 */ setVisualVoicemailSmsFilterSettings(VisualVoicemailSmsFilterSettings settings)3454 public void setVisualVoicemailSmsFilterSettings(VisualVoicemailSmsFilterSettings settings) { 3455 if (settings == null) { 3456 disableVisualVoicemailSmsFilter(mSubId); 3457 } else { 3458 enableVisualVoicemailSmsFilter(mSubId, settings); 3459 } 3460 } 3461 3462 /** 3463 * Send a visual voicemail SMS. The caller must be the current default dialer. 3464 * A {@link VisualVoicemailService} uses this method to send a command via SMS to the carrier's 3465 * visual voicemail server. Some examples for carriers using the OMTP standard include 3466 * activating and deactivating visual voicemail, or requesting the current visual voicemail 3467 * provisioning status. See the OMTP Visual Voicemail specification for more information on the 3468 * format of these SMS messages. 3469 * 3470 * <p>Requires Permission: 3471 * {@link android.Manifest.permission#SEND_SMS SEND_SMS} 3472 * 3473 * @param number The destination number. 3474 * @param port The destination port for data SMS, or 0 for text SMS. 3475 * @param text The message content. For data sms, it will be encoded as a UTF-8 byte stream. 3476 * @param sentIntent The sent intent passed to the {@link SmsManager} 3477 * 3478 * @throws SecurityException if the caller is not the current default dialer 3479 * 3480 * @see SmsManager#sendDataMessage(String, String, short, byte[], PendingIntent, PendingIntent) 3481 * @see SmsManager#sendTextMessage(String, String, String, PendingIntent, PendingIntent) 3482 */ sendVisualVoicemailSms(String number, int port, String text, PendingIntent sentIntent)3483 public void sendVisualVoicemailSms(String number, int port, String text, 3484 PendingIntent sentIntent) { 3485 sendVisualVoicemailSmsForSubscriber(mSubId, number, port, text, sentIntent); 3486 } 3487 3488 /** 3489 * Enables the visual voicemail SMS filter for a phone account. When the filter is 3490 * enabled, Incoming SMS messages matching the OMTP VVM SMS interface will be redirected to the 3491 * visual voicemail client with 3492 * {@link android.provider.VoicemailContract.ACTION_VOICEMAIL_SMS_RECEIVED}. 3493 * 3494 * <p>This takes effect only when the caller is the default dialer. The enabled status and 3495 * settings persist through default dialer changes, but the filter will only honor the setting 3496 * set by the current default dialer. 3497 * 3498 * 3499 * @param subId The subscription id of the phone account. 3500 * @param settings The settings for the filter. 3501 */ 3502 /** @hide */ enableVisualVoicemailSmsFilter(int subId, VisualVoicemailSmsFilterSettings settings)3503 public void enableVisualVoicemailSmsFilter(int subId, 3504 VisualVoicemailSmsFilterSettings settings) { 3505 if(settings == null){ 3506 throw new IllegalArgumentException("Settings cannot be null"); 3507 } 3508 try { 3509 ITelephony telephony = getITelephony(); 3510 if (telephony != null) { 3511 telephony.enableVisualVoicemailSmsFilter(mContext.getOpPackageName(), subId, 3512 settings); 3513 } 3514 } catch (RemoteException ex) { 3515 } catch (NullPointerException ex) { 3516 } 3517 } 3518 3519 /** 3520 * Disables the visual voicemail SMS filter for a phone account. 3521 * 3522 * <p>This takes effect only when the caller is the default dialer. The enabled status and 3523 * settings persist through default dialer changes, but the filter will only honor the setting 3524 * set by the current default dialer. 3525 */ 3526 /** @hide */ disableVisualVoicemailSmsFilter(int subId)3527 public void disableVisualVoicemailSmsFilter(int subId) { 3528 try { 3529 ITelephony telephony = getITelephony(); 3530 if (telephony != null) { 3531 telephony.disableVisualVoicemailSmsFilter(mContext.getOpPackageName(), subId); 3532 } 3533 } catch (RemoteException ex) { 3534 } catch (NullPointerException ex) { 3535 } 3536 } 3537 3538 /** 3539 * @returns the settings of the visual voicemail SMS filter for a phone account, or {@code null} 3540 * if the filter is disabled. 3541 * 3542 * <p>This takes effect only when the caller is the default dialer. The enabled status and 3543 * settings persist through default dialer changes, but the filter will only honor the setting 3544 * set by the current default dialer. 3545 */ 3546 /** @hide */ 3547 @Nullable getVisualVoicemailSmsFilterSettings(int subId)3548 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(int subId) { 3549 try { 3550 ITelephony telephony = getITelephony(); 3551 if (telephony != null) { 3552 return telephony 3553 .getVisualVoicemailSmsFilterSettings(mContext.getOpPackageName(), subId); 3554 } 3555 } catch (RemoteException ex) { 3556 } catch (NullPointerException ex) { 3557 } 3558 3559 return null; 3560 } 3561 3562 /** 3563 * @returns the settings of the visual voicemail SMS filter for a phone account set by the 3564 * current active visual voicemail client, or {@code null} if the filter is disabled. 3565 * 3566 * <p>Requires the calling app to have READ_PRIVILEGED_PHONE_STATE permission. 3567 */ 3568 /** @hide */ 3569 @Nullable getActiveVisualVoicemailSmsFilterSettings(int subId)3570 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { 3571 try { 3572 ITelephony telephony = getITelephony(); 3573 if (telephony != null) { 3574 return telephony.getActiveVisualVoicemailSmsFilterSettings(subId); 3575 } 3576 } catch (RemoteException ex) { 3577 } catch (NullPointerException ex) { 3578 } 3579 3580 return null; 3581 } 3582 3583 /** 3584 * Send a visual voicemail SMS. The IPC caller must be the current default dialer. 3585 * 3586 * @param phoneAccountHandle The account to send the SMS with. 3587 * @param number The destination number. 3588 * @param port The destination port for data SMS, or 0 for text SMS. 3589 * @param text The message content. For data sms, it will be encoded as a UTF-8 byte stream. 3590 * @param sentIntent The sent intent passed to the {@link SmsManager} 3591 * 3592 * @see SmsManager#sendDataMessage(String, String, short, byte[], PendingIntent, PendingIntent) 3593 * @see SmsManager#sendTextMessage(String, String, String, PendingIntent, PendingIntent) 3594 * 3595 * @hide 3596 */ 3597 @RequiresPermission(android.Manifest.permission.SEND_SMS) sendVisualVoicemailSmsForSubscriber(int subId, String number, int port, String text, PendingIntent sentIntent)3598 public void sendVisualVoicemailSmsForSubscriber(int subId, String number, int port, 3599 String text, PendingIntent sentIntent) { 3600 try { 3601 ITelephony telephony = getITelephony(); 3602 if (telephony != null) { 3603 telephony.sendVisualVoicemailSmsForSubscriber( 3604 mContext.getOpPackageName(), subId, number, port, text, sentIntent); 3605 } 3606 } catch (RemoteException ex) { 3607 } 3608 } 3609 3610 /** 3611 * Initial SIM activation state, unknown. Not set by any carrier apps. 3612 * @hide 3613 */ 3614 @SystemApi 3615 public static final int SIM_ACTIVATION_STATE_UNKNOWN = 0; 3616 3617 /** 3618 * indicate SIM is under activation procedure now. 3619 * intermediate state followed by another state update with activation procedure result: 3620 * @see #SIM_ACTIVATION_STATE_ACTIVATED 3621 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 3622 * @see #SIM_ACTIVATION_STATE_RESTRICTED 3623 * @hide 3624 */ 3625 @SystemApi 3626 public static final int SIM_ACTIVATION_STATE_ACTIVATING = 1; 3627 3628 /** 3629 * Indicate SIM has been successfully activated with full service 3630 * @hide 3631 */ 3632 @SystemApi 3633 public static final int SIM_ACTIVATION_STATE_ACTIVATED = 2; 3634 3635 /** 3636 * Indicate SIM has been deactivated by the carrier so that service is not available 3637 * and requires activation service to enable services. 3638 * Carrier apps could be signalled to set activation state to deactivated if detected 3639 * deactivated sim state and set it back to activated after successfully run activation service. 3640 * @hide 3641 */ 3642 @SystemApi 3643 public static final int SIM_ACTIVATION_STATE_DEACTIVATED = 3; 3644 3645 /** 3646 * Restricted state indicate SIM has been activated but service are restricted. 3647 * note this is currently available for data activation state. For example out of byte sim. 3648 * @hide 3649 */ 3650 @SystemApi 3651 public static final int SIM_ACTIVATION_STATE_RESTRICTED = 4; 3652 3653 /** @hide */ 3654 @IntDef({ 3655 SIM_ACTIVATION_STATE_UNKNOWN, 3656 SIM_ACTIVATION_STATE_ACTIVATING, 3657 SIM_ACTIVATION_STATE_ACTIVATED, 3658 SIM_ACTIVATION_STATE_DEACTIVATED, 3659 SIM_ACTIVATION_STATE_RESTRICTED 3660 }) 3661 @Retention(RetentionPolicy.SOURCE) 3662 public @interface SimActivationState{} 3663 3664 /** 3665 * Sets the voice activation state 3666 * 3667 * <p>Requires Permission: 3668 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 3669 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3670 * 3671 * @param activationState The voice activation state 3672 * @see #SIM_ACTIVATION_STATE_UNKNOWN 3673 * @see #SIM_ACTIVATION_STATE_ACTIVATING 3674 * @see #SIM_ACTIVATION_STATE_ACTIVATED 3675 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 3676 * @hide 3677 */ 3678 @SystemApi 3679 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setVoiceActivationState(@imActivationState int activationState)3680 public void setVoiceActivationState(@SimActivationState int activationState) { 3681 setVoiceActivationState(getSubId(), activationState); 3682 } 3683 3684 /** 3685 * Sets the voice activation state for the given subscriber. 3686 * 3687 * <p>Requires Permission: 3688 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 3689 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3690 * 3691 * @param subId The subscription id. 3692 * @param activationState The voice activation state of the given subscriber. 3693 * @see #SIM_ACTIVATION_STATE_UNKNOWN 3694 * @see #SIM_ACTIVATION_STATE_ACTIVATING 3695 * @see #SIM_ACTIVATION_STATE_ACTIVATED 3696 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 3697 * @hide 3698 */ 3699 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setVoiceActivationState(int subId, @SimActivationState int activationState)3700 public void setVoiceActivationState(int subId, @SimActivationState int activationState) { 3701 try { 3702 ITelephony telephony = getITelephony(); 3703 if (telephony != null) 3704 telephony.setVoiceActivationState(subId, activationState); 3705 } catch (RemoteException ex) { 3706 } catch (NullPointerException ex) { 3707 } 3708 } 3709 3710 /** 3711 * Sets the data activation state 3712 * 3713 * <p>Requires Permission: 3714 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 3715 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3716 * 3717 * @param activationState The data activation state 3718 * @see #SIM_ACTIVATION_STATE_UNKNOWN 3719 * @see #SIM_ACTIVATION_STATE_ACTIVATING 3720 * @see #SIM_ACTIVATION_STATE_ACTIVATED 3721 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 3722 * @see #SIM_ACTIVATION_STATE_RESTRICTED 3723 * @hide 3724 */ 3725 @SystemApi 3726 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataActivationState(@imActivationState int activationState)3727 public void setDataActivationState(@SimActivationState int activationState) { 3728 setDataActivationState(getSubId(), activationState); 3729 } 3730 3731 /** 3732 * Sets the data activation state for the given subscriber. 3733 * 3734 * <p>Requires Permission: 3735 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 3736 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3737 * 3738 * @param subId The subscription id. 3739 * @param activationState The data activation state of the given subscriber. 3740 * @see #SIM_ACTIVATION_STATE_UNKNOWN 3741 * @see #SIM_ACTIVATION_STATE_ACTIVATING 3742 * @see #SIM_ACTIVATION_STATE_ACTIVATED 3743 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 3744 * @see #SIM_ACTIVATION_STATE_RESTRICTED 3745 * @hide 3746 */ 3747 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataActivationState(int subId, @SimActivationState int activationState)3748 public void setDataActivationState(int subId, @SimActivationState int activationState) { 3749 try { 3750 ITelephony telephony = getITelephony(); 3751 if (telephony != null) 3752 telephony.setDataActivationState(subId, activationState); 3753 } catch (RemoteException ex) { 3754 } catch (NullPointerException ex) { 3755 } 3756 } 3757 3758 /** 3759 * Returns the voice activation state 3760 * 3761 * <p>Requires Permission: 3762 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 3763 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3764 * 3765 * @return voiceActivationState 3766 * @see #SIM_ACTIVATION_STATE_UNKNOWN 3767 * @see #SIM_ACTIVATION_STATE_ACTIVATING 3768 * @see #SIM_ACTIVATION_STATE_ACTIVATED 3769 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 3770 * @hide 3771 */ 3772 @SystemApi 3773 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getVoiceActivationState()3774 public @SimActivationState int getVoiceActivationState() { 3775 return getVoiceActivationState(getSubId()); 3776 } 3777 3778 /** 3779 * Returns the voice activation state for the given subscriber. 3780 * 3781 * <p>Requires Permission: 3782 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 3783 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3784 * 3785 * @param subId The subscription id. 3786 * 3787 * @return voiceActivationState for the given subscriber 3788 * @see #SIM_ACTIVATION_STATE_UNKNOWN 3789 * @see #SIM_ACTIVATION_STATE_ACTIVATING 3790 * @see #SIM_ACTIVATION_STATE_ACTIVATED 3791 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 3792 * @hide 3793 */ 3794 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getVoiceActivationState(int subId)3795 public @SimActivationState int getVoiceActivationState(int subId) { 3796 try { 3797 ITelephony telephony = getITelephony(); 3798 if (telephony != null) 3799 return telephony.getVoiceActivationState(subId, getOpPackageName()); 3800 } catch (RemoteException ex) { 3801 } catch (NullPointerException ex) { 3802 } 3803 return SIM_ACTIVATION_STATE_UNKNOWN; 3804 } 3805 3806 /** 3807 * Returns the data activation state 3808 * 3809 * <p>Requires Permission: 3810 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 3811 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3812 * 3813 * @return dataActivationState for the given subscriber 3814 * @see #SIM_ACTIVATION_STATE_UNKNOWN 3815 * @see #SIM_ACTIVATION_STATE_ACTIVATING 3816 * @see #SIM_ACTIVATION_STATE_ACTIVATED 3817 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 3818 * @see #SIM_ACTIVATION_STATE_RESTRICTED 3819 * @hide 3820 */ 3821 @SystemApi 3822 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getDataActivationState()3823 public @SimActivationState int getDataActivationState() { 3824 return getDataActivationState(getSubId()); 3825 } 3826 3827 /** 3828 * Returns the data activation state for the given subscriber. 3829 * 3830 * <p>Requires Permission: 3831 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 3832 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3833 * 3834 * @param subId The subscription id. 3835 * 3836 * @return dataActivationState for the given subscriber 3837 * @see #SIM_ACTIVATION_STATE_UNKNOWN 3838 * @see #SIM_ACTIVATION_STATE_ACTIVATING 3839 * @see #SIM_ACTIVATION_STATE_ACTIVATED 3840 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 3841 * @see #SIM_ACTIVATION_STATE_RESTRICTED 3842 * @hide 3843 */ 3844 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getDataActivationState(int subId)3845 public @SimActivationState int getDataActivationState(int subId) { 3846 try { 3847 ITelephony telephony = getITelephony(); 3848 if (telephony != null) 3849 return telephony.getDataActivationState(subId, getOpPackageName()); 3850 } catch (RemoteException ex) { 3851 } catch (NullPointerException ex) { 3852 } 3853 return SIM_ACTIVATION_STATE_UNKNOWN; 3854 } 3855 3856 /** 3857 * Returns the voice mail count. Return 0 if unavailable, -1 if there are unread voice messages 3858 * but the count is unknown. 3859 * @hide 3860 */ 3861 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceMessageCount()3862 public int getVoiceMessageCount() { 3863 return getVoiceMessageCount(getSubId()); 3864 } 3865 3866 /** 3867 * Returns the voice mail count for a subscription. Return 0 if unavailable. 3868 * @param subId whose voice message count is returned 3869 * @hide 3870 */ 3871 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceMessageCount(int subId)3872 public int getVoiceMessageCount(int subId) { 3873 try { 3874 ITelephony telephony = getITelephony(); 3875 if (telephony == null) 3876 return 0; 3877 return telephony.getVoiceMessageCountForSubscriber(subId); 3878 } catch (RemoteException ex) { 3879 return 0; 3880 } catch (NullPointerException ex) { 3881 // This could happen before phone restarts due to crashing 3882 return 0; 3883 } 3884 } 3885 3886 /** 3887 * Retrieves the alphabetic identifier associated with the voice 3888 * mail number. 3889 * 3890 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3891 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3892 */ 3893 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 3894 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceMailAlphaTag()3895 public String getVoiceMailAlphaTag() { 3896 return getVoiceMailAlphaTag(getSubId()); 3897 } 3898 3899 /** 3900 * Retrieves the alphabetic identifier associated with the voice 3901 * mail number for a subscription. 3902 * @param subId whose alphabetic identifier associated with the 3903 * voice mail number is returned 3904 * @hide 3905 */ 3906 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceMailAlphaTag(int subId)3907 public String getVoiceMailAlphaTag(int subId) { 3908 try { 3909 IPhoneSubInfo info = getSubscriberInfo(); 3910 if (info == null) 3911 return null; 3912 return info.getVoiceMailAlphaTagForSubscriber(subId, getOpPackageName()); 3913 } catch (RemoteException ex) { 3914 return null; 3915 } catch (NullPointerException ex) { 3916 // This could happen before phone restarts due to crashing 3917 return null; 3918 } 3919 } 3920 3921 /** 3922 * Send the special dialer code. The IPC caller must be the current default dialer or have 3923 * carrier privileges (see {@link #hasCarrierPrivileges}). 3924 * 3925 * @param inputCode The special dialer code to send 3926 * 3927 * @throws SecurityException if the caller does not have carrier privileges or is not the 3928 * current default dialer 3929 */ sendDialerSpecialCode(String inputCode)3930 public void sendDialerSpecialCode(String inputCode) { 3931 try { 3932 final ITelephony telephony = getITelephony(); 3933 if (telephony == null) { 3934 if (!isSystemProcess()) { 3935 throw new RuntimeException("Telephony service unavailable"); 3936 } 3937 return; 3938 } 3939 telephony.sendDialerSpecialCode(mContext.getOpPackageName(), inputCode); 3940 } catch (RemoteException ex) { 3941 // This could happen if binder process crashes. 3942 if (!isSystemProcess()) { 3943 ex.rethrowAsRuntimeException(); 3944 } 3945 } 3946 } 3947 3948 /** 3949 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 3950 * @return the IMPI, or null if not present or not loaded 3951 * @hide 3952 */ getIsimImpi()3953 public String getIsimImpi() { 3954 try { 3955 IPhoneSubInfo info = getSubscriberInfo(); 3956 if (info == null) 3957 return null; 3958 //get the Isim Impi based on subId 3959 return info.getIsimImpi(getSubId()); 3960 } catch (RemoteException ex) { 3961 return null; 3962 } catch (NullPointerException ex) { 3963 // This could happen before phone restarts due to crashing 3964 return null; 3965 } 3966 } 3967 3968 /** 3969 * Returns the IMS home network domain name that was loaded from the ISIM. 3970 * @return the IMS domain name, or null if not present or not loaded 3971 * @hide 3972 */ getIsimDomain()3973 public String getIsimDomain() { 3974 try { 3975 IPhoneSubInfo info = getSubscriberInfo(); 3976 if (info == null) 3977 return null; 3978 //get the Isim Domain based on subId 3979 return info.getIsimDomain(getSubId()); 3980 } catch (RemoteException ex) { 3981 return null; 3982 } catch (NullPointerException ex) { 3983 // This could happen before phone restarts due to crashing 3984 return null; 3985 } 3986 } 3987 3988 /** 3989 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 3990 * @return an array of IMPU strings, with one IMPU per string, or null if 3991 * not present or not loaded 3992 * @hide 3993 */ getIsimImpu()3994 public String[] getIsimImpu() { 3995 try { 3996 IPhoneSubInfo info = getSubscriberInfo(); 3997 if (info == null) 3998 return null; 3999 //get the Isim Impu based on subId 4000 return info.getIsimImpu(getSubId()); 4001 } catch (RemoteException ex) { 4002 return null; 4003 } catch (NullPointerException ex) { 4004 // This could happen before phone restarts due to crashing 4005 return null; 4006 } 4007 } 4008 4009 /** 4010 * @hide 4011 */ getSubscriberInfo()4012 private IPhoneSubInfo getSubscriberInfo() { 4013 // get it each time because that process crashes a lot 4014 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 4015 } 4016 4017 /** Device call state: No activity. */ 4018 public static final int CALL_STATE_IDLE = 0; 4019 /** Device call state: Ringing. A new call arrived and is 4020 * ringing or waiting. In the latter case, another call is 4021 * already active. */ 4022 public static final int CALL_STATE_RINGING = 1; 4023 /** Device call state: Off-hook. At least one call exists 4024 * that is dialing, active, or on hold, and no calls are ringing 4025 * or waiting. */ 4026 public static final int CALL_STATE_OFFHOOK = 2; 4027 4028 /** 4029 * Returns one of the following constants that represents the current state of all 4030 * phone calls. 4031 * 4032 * {@link TelephonyManager#CALL_STATE_RINGING} 4033 * {@link TelephonyManager#CALL_STATE_OFFHOOK} 4034 * {@link TelephonyManager#CALL_STATE_IDLE} 4035 */ getCallState()4036 public int getCallState() { 4037 try { 4038 ITelecomService telecom = getTelecomService(); 4039 if (telecom != null) { 4040 return telecom.getCallState(); 4041 } 4042 } catch (RemoteException e) { 4043 Log.e(TAG, "Error calling ITelecomService#getCallState", e); 4044 } 4045 return CALL_STATE_IDLE; 4046 } 4047 4048 /** 4049 * Returns a constant indicating the call state (cellular) on the device 4050 * for a subscription. 4051 * 4052 * @param subId whose call state is returned 4053 * @hide 4054 */ getCallState(int subId)4055 public int getCallState(int subId) { 4056 int phoneId = SubscriptionManager.getPhoneId(subId); 4057 return getCallStateForSlot(phoneId); 4058 } 4059 4060 /** 4061 * See getCallState. 4062 * 4063 * @hide 4064 */ getCallStateForSlot(int slotIndex)4065 public int getCallStateForSlot(int slotIndex) { 4066 try { 4067 ITelephony telephony = getITelephony(); 4068 if (telephony == null) 4069 return CALL_STATE_IDLE; 4070 return telephony.getCallStateForSlot(slotIndex); 4071 } catch (RemoteException ex) { 4072 // the phone process is restarting. 4073 return CALL_STATE_IDLE; 4074 } catch (NullPointerException ex) { 4075 // the phone process is restarting. 4076 return CALL_STATE_IDLE; 4077 } 4078 } 4079 4080 4081 /** Data connection activity: No traffic. */ 4082 public static final int DATA_ACTIVITY_NONE = 0x00000000; 4083 /** Data connection activity: Currently receiving IP PPP traffic. */ 4084 public static final int DATA_ACTIVITY_IN = 0x00000001; 4085 /** Data connection activity: Currently sending IP PPP traffic. */ 4086 public static final int DATA_ACTIVITY_OUT = 0x00000002; 4087 /** Data connection activity: Currently both sending and receiving 4088 * IP PPP traffic. */ 4089 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 4090 /** 4091 * Data connection is active, but physical link is down 4092 */ 4093 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 4094 4095 /** 4096 * Returns a constant indicating the type of activity on a data connection 4097 * (cellular). 4098 * 4099 * @see #DATA_ACTIVITY_NONE 4100 * @see #DATA_ACTIVITY_IN 4101 * @see #DATA_ACTIVITY_OUT 4102 * @see #DATA_ACTIVITY_INOUT 4103 * @see #DATA_ACTIVITY_DORMANT 4104 */ getDataActivity()4105 public int getDataActivity() { 4106 try { 4107 ITelephony telephony = getITelephony(); 4108 if (telephony == null) 4109 return DATA_ACTIVITY_NONE; 4110 return telephony.getDataActivity(); 4111 } catch (RemoteException ex) { 4112 // the phone process is restarting. 4113 return DATA_ACTIVITY_NONE; 4114 } catch (NullPointerException ex) { 4115 // the phone process is restarting. 4116 return DATA_ACTIVITY_NONE; 4117 } 4118 } 4119 4120 /** Data connection state: Unknown. Used before we know the state. 4121 * @hide 4122 */ 4123 public static final int DATA_UNKNOWN = -1; 4124 /** Data connection state: Disconnected. IP traffic not available. */ 4125 public static final int DATA_DISCONNECTED = 0; 4126 /** Data connection state: Currently setting up a data connection. */ 4127 public static final int DATA_CONNECTING = 1; 4128 /** Data connection state: Connected. IP traffic should be available. */ 4129 public static final int DATA_CONNECTED = 2; 4130 /** Data connection state: Suspended. The connection is up, but IP 4131 * traffic is temporarily unavailable. For example, in a 2G network, 4132 * data activity may be suspended when a voice call arrives. */ 4133 public static final int DATA_SUSPENDED = 3; 4134 4135 /** 4136 * Returns a constant indicating the current data connection state 4137 * (cellular). 4138 * 4139 * @see #DATA_DISCONNECTED 4140 * @see #DATA_CONNECTING 4141 * @see #DATA_CONNECTED 4142 * @see #DATA_SUSPENDED 4143 */ getDataState()4144 public int getDataState() { 4145 try { 4146 ITelephony telephony = getITelephony(); 4147 if (telephony == null) 4148 return DATA_DISCONNECTED; 4149 return telephony.getDataState(); 4150 } catch (RemoteException ex) { 4151 // the phone process is restarting. 4152 return DATA_DISCONNECTED; 4153 } catch (NullPointerException ex) { 4154 return DATA_DISCONNECTED; 4155 } 4156 } 4157 4158 /** 4159 * @hide 4160 */ getITelephony()4161 private ITelephony getITelephony() { 4162 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 4163 } 4164 4165 /** 4166 * @hide 4167 */ getTelecomService()4168 private ITelecomService getTelecomService() { 4169 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); 4170 } 4171 getTelephonyRegistry()4172 private ITelephonyRegistry getTelephonyRegistry() { 4173 return ITelephonyRegistry.Stub.asInterface(ServiceManager.getService("telephony.registry")); 4174 } 4175 4176 // 4177 // 4178 // PhoneStateListener 4179 // 4180 // 4181 4182 /** 4183 * Registers a listener object to receive notification of changes 4184 * in specified telephony states. 4185 * <p> 4186 * To register a listener, pass a {@link PhoneStateListener} 4187 * and specify at least one telephony state of interest in 4188 * the events argument. 4189 * 4190 * At registration, and when a specified telephony state 4191 * changes, the telephony manager invokes the appropriate 4192 * callback method on the listener object and passes the 4193 * current (updated) values. 4194 * <p> 4195 * To unregister a listener, pass the listener object and set the 4196 * events argument to 4197 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 4198 * Note: if you call this method while in the middle of a binder transaction, you <b>must</b> 4199 * call {@link android.os.Binder#clearCallingIdentity()} before calling this method. A 4200 * {@link SecurityException} will be thrown otherwise. 4201 * 4202 * @param listener The {@link PhoneStateListener} object to register 4203 * (or unregister) 4204 * @param events The telephony state(s) of interest to the listener, 4205 * as a bitwise-OR combination of {@link PhoneStateListener} 4206 * LISTEN_ flags. 4207 */ listen(PhoneStateListener listener, int events)4208 public void listen(PhoneStateListener listener, int events) { 4209 if (mContext == null) return; 4210 try { 4211 boolean notifyNow = (getITelephony() != null); 4212 // If the listener has not explicitly set the subId (for example, created with the 4213 // default constructor), replace the subId so it will listen to the account the 4214 // telephony manager is created with. 4215 if (listener.mSubId == null) { 4216 listener.mSubId = mSubId; 4217 } 4218 4219 ITelephonyRegistry registry = getTelephonyRegistry(); 4220 if (registry != null) { 4221 registry.listenForSubscriber(listener.mSubId, getOpPackageName(), 4222 listener.callback, events, notifyNow); 4223 } else { 4224 Rlog.w(TAG, "telephony registry not ready."); 4225 } 4226 } catch (RemoteException ex) { 4227 // system process dead 4228 } 4229 } 4230 4231 /** 4232 * Returns the CDMA ERI icon index to display 4233 * @hide 4234 */ 4235 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCdmaEriIconIndex()4236 public int getCdmaEriIconIndex() { 4237 return getCdmaEriIconIndex(getSubId()); 4238 } 4239 4240 /** 4241 * Returns the CDMA ERI icon index to display for a subscription 4242 * @hide 4243 */ 4244 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCdmaEriIconIndex(int subId)4245 public int getCdmaEriIconIndex(int subId) { 4246 try { 4247 ITelephony telephony = getITelephony(); 4248 if (telephony == null) 4249 return -1; 4250 return telephony.getCdmaEriIconIndexForSubscriber(subId, getOpPackageName()); 4251 } catch (RemoteException ex) { 4252 // the phone process is restarting. 4253 return -1; 4254 } catch (NullPointerException ex) { 4255 return -1; 4256 } 4257 } 4258 4259 /** 4260 * Returns the CDMA ERI icon mode, 4261 * 0 - ON 4262 * 1 - FLASHING 4263 * 4264 * @hide 4265 */ 4266 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCdmaEriIconMode()4267 public int getCdmaEriIconMode() { 4268 return getCdmaEriIconMode(getSubId()); 4269 } 4270 4271 /** 4272 * Returns the CDMA ERI icon mode for a subscription. 4273 * 0 - ON 4274 * 1 - FLASHING 4275 * 4276 * @hide 4277 */ 4278 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCdmaEriIconMode(int subId)4279 public int getCdmaEriIconMode(int subId) { 4280 try { 4281 ITelephony telephony = getITelephony(); 4282 if (telephony == null) 4283 return -1; 4284 return telephony.getCdmaEriIconModeForSubscriber(subId, getOpPackageName()); 4285 } catch (RemoteException ex) { 4286 // the phone process is restarting. 4287 return -1; 4288 } catch (NullPointerException ex) { 4289 return -1; 4290 } 4291 } 4292 4293 /** 4294 * Returns the CDMA ERI text, 4295 * 4296 * @hide 4297 */ 4298 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCdmaEriText()4299 public String getCdmaEriText() { 4300 return getCdmaEriText(getSubId()); 4301 } 4302 4303 /** 4304 * Returns the CDMA ERI text, of a subscription 4305 * 4306 * @hide 4307 */ 4308 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCdmaEriText(int subId)4309 public String getCdmaEriText(int subId) { 4310 try { 4311 ITelephony telephony = getITelephony(); 4312 if (telephony == null) 4313 return null; 4314 return telephony.getCdmaEriTextForSubscriber(subId, getOpPackageName()); 4315 } catch (RemoteException ex) { 4316 // the phone process is restarting. 4317 return null; 4318 } catch (NullPointerException ex) { 4319 return null; 4320 } 4321 } 4322 4323 /** 4324 * @return true if the current device is "voice capable". 4325 * <p> 4326 * "Voice capable" means that this device supports circuit-switched 4327 * (i.e. voice) phone calls over the telephony network, and is allowed 4328 * to display the in-call UI while a cellular voice call is active. 4329 * This will be false on "data only" devices which can't make voice 4330 * calls and don't support any in-call UI. 4331 * <p> 4332 * Note: the meaning of this flag is subtly different from the 4333 * PackageManager.FEATURE_TELEPHONY system feature, which is available 4334 * on any device with a telephony radio, even if the device is 4335 * data-only. 4336 */ isVoiceCapable()4337 public boolean isVoiceCapable() { 4338 if (mContext == null) return true; 4339 return mContext.getResources().getBoolean( 4340 com.android.internal.R.bool.config_voice_capable); 4341 } 4342 4343 /** 4344 * @return true if the current device supports sms service. 4345 * <p> 4346 * If true, this means that the device supports both sending and 4347 * receiving sms via the telephony network. 4348 * <p> 4349 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 4350 * disabled when device doesn't support sms. 4351 */ isSmsCapable()4352 public boolean isSmsCapable() { 4353 if (mContext == null) return true; 4354 return mContext.getResources().getBoolean( 4355 com.android.internal.R.bool.config_sms_capable); 4356 } 4357 4358 /** 4359 * Returns all observed cell information from all radios on the 4360 * device including the primary and neighboring cells. Calling this method does 4361 * not trigger a call to {@link android.telephony.PhoneStateListener#onCellInfoChanged 4362 * onCellInfoChanged()}, or change the rate at which 4363 * {@link android.telephony.PhoneStateListener#onCellInfoChanged 4364 * onCellInfoChanged()} is called. 4365 * 4366 *<p> 4367 * The list can include one or more {@link android.telephony.CellInfoGsm CellInfoGsm}, 4368 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 4369 * {@link android.telephony.CellInfoLte CellInfoLte}, and 4370 * {@link android.telephony.CellInfoWcdma CellInfoWcdma} objects, in any combination. 4371 * On devices with multiple radios it is typical to see instances of 4372 * one or more of any these in the list. In addition, zero, one, or more 4373 * of the returned objects may be considered registered; that is, their 4374 * {@link android.telephony.CellInfo#isRegistered CellInfo.isRegistered()} 4375 * methods may return true. 4376 * 4377 * <p>This method returns valid data for registered cells on devices with 4378 * {@link android.content.pm.PackageManager#FEATURE_TELEPHONY}. In cases where only 4379 * partial information is available for a particular CellInfo entry, unavailable fields 4380 * will be reported as Integer.MAX_VALUE. All reported cells will include at least a 4381 * valid set of technology-specific identification info and a power level measurement. 4382 * 4383 *<p> 4384 * This method is preferred over using {@link 4385 * android.telephony.TelephonyManager#getCellLocation getCellLocation()}. 4386 * However, for older devices, <code>getAllCellInfo()</code> may return 4387 * null. In these cases, you should call {@link 4388 * android.telephony.TelephonyManager#getCellLocation getCellLocation()} 4389 * instead. 4390 * 4391 * @return List of {@link android.telephony.CellInfo}; null if cell 4392 * information is unavailable. 4393 */ 4394 @RequiresPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) getAllCellInfo()4395 public List<CellInfo> getAllCellInfo() { 4396 try { 4397 ITelephony telephony = getITelephony(); 4398 if (telephony == null) 4399 return null; 4400 return telephony.getAllCellInfo(getOpPackageName()); 4401 } catch (RemoteException ex) { 4402 return null; 4403 } catch (NullPointerException ex) { 4404 return null; 4405 } 4406 } 4407 4408 /** 4409 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 4410 * PhoneStateListener.onCellInfoChanged} will be invoked. 4411 *<p> 4412 * The default, 0, means invoke onCellInfoChanged when any of the reported 4413 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 4414 * A onCellInfoChanged. 4415 *<p> 4416 * @param rateInMillis the rate 4417 * 4418 * @hide 4419 */ setCellInfoListRate(int rateInMillis)4420 public void setCellInfoListRate(int rateInMillis) { 4421 try { 4422 ITelephony telephony = getITelephony(); 4423 if (telephony != null) 4424 telephony.setCellInfoListRate(rateInMillis); 4425 } catch (RemoteException ex) { 4426 } catch (NullPointerException ex) { 4427 } 4428 } 4429 4430 /** 4431 * Returns the MMS user agent. 4432 */ getMmsUserAgent()4433 public String getMmsUserAgent() { 4434 if (mContext == null) return null; 4435 return mContext.getResources().getString( 4436 com.android.internal.R.string.config_mms_user_agent); 4437 } 4438 4439 /** 4440 * Returns the MMS user agent profile URL. 4441 */ getMmsUAProfUrl()4442 public String getMmsUAProfUrl() { 4443 if (mContext == null) return null; 4444 return mContext.getResources().getString( 4445 com.android.internal.R.string.config_mms_user_agent_profile_url); 4446 } 4447 4448 /** 4449 * Opens a logical channel to the ICC card. 4450 * 4451 * Input parameters equivalent to TS 27.007 AT+CCHO command. 4452 * 4453 * <p>Requires Permission: 4454 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4455 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4456 * 4457 * @param AID Application id. See ETSI 102.221 and 101.220. 4458 * @return an IccOpenLogicalChannelResponse object. 4459 * @deprecated Replaced by {@link #iccOpenLogicalChannel(String, int)} 4460 */ 4461 @Deprecated iccOpenLogicalChannel(String AID)4462 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { 4463 return iccOpenLogicalChannel(getSubId(), AID, -1); 4464 } 4465 4466 /** 4467 * Opens a logical channel to the ICC card. 4468 * 4469 * Input parameters equivalent to TS 27.007 AT+CCHO command. 4470 * 4471 * <p>Requires Permission: 4472 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4473 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4474 * 4475 * @param AID Application id. See ETSI 102.221 and 101.220. 4476 * @param p2 P2 parameter (described in ISO 7816-4). 4477 * @return an IccOpenLogicalChannelResponse object. 4478 */ iccOpenLogicalChannel(String AID, int p2)4479 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID, int p2) { 4480 return iccOpenLogicalChannel(getSubId(), AID, p2); 4481 } 4482 4483 /** 4484 * Opens a logical channel to the ICC card. 4485 * 4486 * Input parameters equivalent to TS 27.007 AT+CCHO command. 4487 * 4488 * <p>Requires Permission: 4489 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4490 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4491 * 4492 * @param subId The subscription to use. 4493 * @param AID Application id. See ETSI 102.221 and 101.220. 4494 * @param p2 P2 parameter (described in ISO 7816-4). 4495 * @return an IccOpenLogicalChannelResponse object. 4496 * @hide 4497 */ iccOpenLogicalChannel(int subId, String AID, int p2)4498 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID, int p2) { 4499 try { 4500 ITelephony telephony = getITelephony(); 4501 if (telephony != null) 4502 return telephony.iccOpenLogicalChannel(subId, getOpPackageName(), AID, p2); 4503 } catch (RemoteException ex) { 4504 } catch (NullPointerException ex) { 4505 } 4506 return null; 4507 } 4508 4509 /** 4510 * Closes a previously opened logical channel to the ICC card. 4511 * 4512 * Input parameters equivalent to TS 27.007 AT+CCHC command. 4513 * 4514 * <p>Requires Permission: 4515 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4516 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4517 * 4518 * @param channel is the channel id to be closed as retruned by a successful 4519 * iccOpenLogicalChannel. 4520 * @return true if the channel was closed successfully. 4521 */ iccCloseLogicalChannel(int channel)4522 public boolean iccCloseLogicalChannel(int channel) { 4523 return iccCloseLogicalChannel(getSubId(), channel); 4524 } 4525 4526 /** 4527 * Closes a previously opened logical channel to the ICC card. 4528 * 4529 * Input parameters equivalent to TS 27.007 AT+CCHC command. 4530 * 4531 * <p>Requires Permission: 4532 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4533 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4534 * 4535 * @param subId The subscription to use. 4536 * @param channel is the channel id to be closed as retruned by a successful 4537 * iccOpenLogicalChannel. 4538 * @return true if the channel was closed successfully. 4539 * @hide 4540 */ iccCloseLogicalChannel(int subId, int channel)4541 public boolean iccCloseLogicalChannel(int subId, int channel) { 4542 try { 4543 ITelephony telephony = getITelephony(); 4544 if (telephony != null) 4545 return telephony.iccCloseLogicalChannel(subId, channel); 4546 } catch (RemoteException ex) { 4547 } catch (NullPointerException ex) { 4548 } 4549 return false; 4550 } 4551 4552 /** 4553 * Transmit an APDU to the ICC card over a logical channel. 4554 * 4555 * Input parameters equivalent to TS 27.007 AT+CGLA command. 4556 * 4557 * <p>Requires Permission: 4558 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4559 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4560 * 4561 * @param channel is the channel id to be closed as returned by a successful 4562 * iccOpenLogicalChannel. 4563 * @param cla Class of the APDU command. 4564 * @param instruction Instruction of the APDU command. 4565 * @param p1 P1 value of the APDU command. 4566 * @param p2 P2 value of the APDU command. 4567 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 4568 * is sent to the SIM. 4569 * @param data Data to be sent with the APDU. 4570 * @return The APDU response from the ICC card with the status appended at 4571 * the end. 4572 */ iccTransmitApduLogicalChannel(int channel, int cla, int instruction, int p1, int p2, int p3, String data)4573 public String iccTransmitApduLogicalChannel(int channel, int cla, 4574 int instruction, int p1, int p2, int p3, String data) { 4575 return iccTransmitApduLogicalChannel(getSubId(), channel, cla, 4576 instruction, p1, p2, p3, data); 4577 } 4578 4579 /** 4580 * Transmit an APDU to the ICC card over a logical channel. 4581 * 4582 * Input parameters equivalent to TS 27.007 AT+CGLA command. 4583 * 4584 * <p>Requires Permission: 4585 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4586 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4587 * 4588 * @param subId The subscription to use. 4589 * @param channel is the channel id to be closed as returned by a successful 4590 * iccOpenLogicalChannel. 4591 * @param cla Class of the APDU command. 4592 * @param instruction Instruction of the APDU command. 4593 * @param p1 P1 value of the APDU command. 4594 * @param p2 P2 value of the APDU command. 4595 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 4596 * is sent to the SIM. 4597 * @param data Data to be sent with the APDU. 4598 * @return The APDU response from the ICC card with the status appended at 4599 * the end. 4600 * @hide 4601 */ iccTransmitApduLogicalChannel(int subId, int channel, int cla, int instruction, int p1, int p2, int p3, String data)4602 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, 4603 int instruction, int p1, int p2, int p3, String data) { 4604 try { 4605 ITelephony telephony = getITelephony(); 4606 if (telephony != null) 4607 return telephony.iccTransmitApduLogicalChannel(subId, channel, cla, 4608 instruction, p1, p2, p3, data); 4609 } catch (RemoteException ex) { 4610 } catch (NullPointerException ex) { 4611 } 4612 return ""; 4613 } 4614 4615 /** 4616 * Transmit an APDU to the ICC card over the basic channel. 4617 * 4618 * Input parameters equivalent to TS 27.007 AT+CSIM command. 4619 * 4620 * <p>Requires Permission: 4621 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4622 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4623 * 4624 * @param cla Class of the APDU command. 4625 * @param instruction Instruction of the APDU command. 4626 * @param p1 P1 value of the APDU command. 4627 * @param p2 P2 value of the APDU command. 4628 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 4629 * is sent to the SIM. 4630 * @param data Data to be sent with the APDU. 4631 * @return The APDU response from the ICC card with the status appended at 4632 * the end. 4633 */ iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2, int p3, String data)4634 public String iccTransmitApduBasicChannel(int cla, 4635 int instruction, int p1, int p2, int p3, String data) { 4636 return iccTransmitApduBasicChannel(getSubId(), cla, 4637 instruction, p1, p2, p3, data); 4638 } 4639 4640 /** 4641 * Transmit an APDU to the ICC card over the basic channel. 4642 * 4643 * Input parameters equivalent to TS 27.007 AT+CSIM command. 4644 * 4645 * <p>Requires Permission: 4646 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4647 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4648 * 4649 * @param subId The subscription to use. 4650 * @param cla Class of the APDU command. 4651 * @param instruction Instruction of the APDU command. 4652 * @param p1 P1 value of the APDU command. 4653 * @param p2 P2 value of the APDU command. 4654 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 4655 * is sent to the SIM. 4656 * @param data Data to be sent with the APDU. 4657 * @return The APDU response from the ICC card with the status appended at 4658 * the end. 4659 * @hide 4660 */ iccTransmitApduBasicChannel(int subId, int cla, int instruction, int p1, int p2, int p3, String data)4661 public String iccTransmitApduBasicChannel(int subId, int cla, 4662 int instruction, int p1, int p2, int p3, String data) { 4663 try { 4664 ITelephony telephony = getITelephony(); 4665 if (telephony != null) 4666 return telephony.iccTransmitApduBasicChannel(subId, getOpPackageName(), cla, 4667 instruction, p1, p2, p3, data); 4668 } catch (RemoteException ex) { 4669 } catch (NullPointerException ex) { 4670 } 4671 return ""; 4672 } 4673 4674 /** 4675 * Returns the response APDU for a command APDU sent through SIM_IO. 4676 * 4677 * <p>Requires Permission: 4678 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4679 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4680 * 4681 * @param fileID 4682 * @param command 4683 * @param p1 P1 value of the APDU command. 4684 * @param p2 P2 value of the APDU command. 4685 * @param p3 P3 value of the APDU command. 4686 * @param filePath 4687 * @return The APDU response. 4688 */ iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, String filePath)4689 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 4690 String filePath) { 4691 return iccExchangeSimIO(getSubId(), fileID, command, p1, p2, p3, filePath); 4692 } 4693 4694 /** 4695 * Returns the response APDU for a command APDU sent through SIM_IO. 4696 * 4697 * <p>Requires Permission: 4698 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4699 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4700 * 4701 * @param subId The subscription to use. 4702 * @param fileID 4703 * @param command 4704 * @param p1 P1 value of the APDU command. 4705 * @param p2 P2 value of the APDU command. 4706 * @param p3 P3 value of the APDU command. 4707 * @param filePath 4708 * @return The APDU response. 4709 * @hide 4710 */ iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3, String filePath)4711 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, 4712 int p3, String filePath) { 4713 try { 4714 ITelephony telephony = getITelephony(); 4715 if (telephony != null) 4716 return telephony.iccExchangeSimIO(subId, fileID, command, p1, p2, p3, filePath); 4717 } catch (RemoteException ex) { 4718 } catch (NullPointerException ex) { 4719 } 4720 return null; 4721 } 4722 4723 /** 4724 * Send ENVELOPE to the SIM and return the response. 4725 * 4726 * <p>Requires Permission: 4727 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4728 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4729 * 4730 * @param content String containing SAT/USAT response in hexadecimal 4731 * format starting with command tag. See TS 102 223 for 4732 * details. 4733 * @return The APDU response from the ICC card in hexadecimal format 4734 * with the last 4 bytes being the status word. If the command fails, 4735 * returns an empty string. 4736 */ sendEnvelopeWithStatus(String content)4737 public String sendEnvelopeWithStatus(String content) { 4738 return sendEnvelopeWithStatus(getSubId(), content); 4739 } 4740 4741 /** 4742 * Send ENVELOPE to the SIM and return the response. 4743 * 4744 * <p>Requires Permission: 4745 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4746 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4747 * 4748 * @param subId The subscription to use. 4749 * @param content String containing SAT/USAT response in hexadecimal 4750 * format starting with command tag. See TS 102 223 for 4751 * details. 4752 * @return The APDU response from the ICC card in hexadecimal format 4753 * with the last 4 bytes being the status word. If the command fails, 4754 * returns an empty string. 4755 * @hide 4756 */ sendEnvelopeWithStatus(int subId, String content)4757 public String sendEnvelopeWithStatus(int subId, String content) { 4758 try { 4759 ITelephony telephony = getITelephony(); 4760 if (telephony != null) 4761 return telephony.sendEnvelopeWithStatus(subId, content); 4762 } catch (RemoteException ex) { 4763 } catch (NullPointerException ex) { 4764 } 4765 return ""; 4766 } 4767 4768 /** 4769 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 4770 * Used for device configuration by some CDMA operators. 4771 * 4772 * <p>Requires Permission: 4773 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4774 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4775 * 4776 * @param itemID the ID of the item to read. 4777 * @return the NV item as a String, or null on any failure. 4778 * 4779 * @hide 4780 */ nvReadItem(int itemID)4781 public String nvReadItem(int itemID) { 4782 try { 4783 ITelephony telephony = getITelephony(); 4784 if (telephony != null) 4785 return telephony.nvReadItem(itemID); 4786 } catch (RemoteException ex) { 4787 Rlog.e(TAG, "nvReadItem RemoteException", ex); 4788 } catch (NullPointerException ex) { 4789 Rlog.e(TAG, "nvReadItem NPE", ex); 4790 } 4791 return ""; 4792 } 4793 4794 /** 4795 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 4796 * Used for device configuration by some CDMA operators. 4797 * 4798 * <p>Requires Permission: 4799 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4800 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4801 * 4802 * @param itemID the ID of the item to read. 4803 * @param itemValue the value to write, as a String. 4804 * @return true on success; false on any failure. 4805 * 4806 * @hide 4807 */ nvWriteItem(int itemID, String itemValue)4808 public boolean nvWriteItem(int itemID, String itemValue) { 4809 try { 4810 ITelephony telephony = getITelephony(); 4811 if (telephony != null) 4812 return telephony.nvWriteItem(itemID, itemValue); 4813 } catch (RemoteException ex) { 4814 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 4815 } catch (NullPointerException ex) { 4816 Rlog.e(TAG, "nvWriteItem NPE", ex); 4817 } 4818 return false; 4819 } 4820 4821 /** 4822 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 4823 * Used for device configuration by some CDMA operators. 4824 * 4825 * <p>Requires Permission: 4826 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4827 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4828 * 4829 * @param preferredRoamingList byte array containing the new PRL. 4830 * @return true on success; false on any failure. 4831 * 4832 * @hide 4833 */ nvWriteCdmaPrl(byte[] preferredRoamingList)4834 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 4835 try { 4836 ITelephony telephony = getITelephony(); 4837 if (telephony != null) 4838 return telephony.nvWriteCdmaPrl(preferredRoamingList); 4839 } catch (RemoteException ex) { 4840 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 4841 } catch (NullPointerException ex) { 4842 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 4843 } 4844 return false; 4845 } 4846 4847 /** 4848 * Perform the specified type of NV config reset. The radio will be taken offline 4849 * and the device must be rebooted after the operation. Used for device 4850 * configuration by some CDMA operators. 4851 * 4852 * <p>Requires Permission: 4853 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 4854 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 4855 * 4856 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 4857 * @return true on success; false on any failure. 4858 * 4859 * @hide 4860 */ nvResetConfig(int resetType)4861 public boolean nvResetConfig(int resetType) { 4862 try { 4863 ITelephony telephony = getITelephony(); 4864 if (telephony != null) 4865 return telephony.nvResetConfig(resetType); 4866 } catch (RemoteException ex) { 4867 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 4868 } catch (NullPointerException ex) { 4869 Rlog.e(TAG, "nvResetConfig NPE", ex); 4870 } 4871 return false; 4872 } 4873 4874 /** 4875 * Return an appropriate subscription ID for any situation. 4876 * 4877 * If this object has been created with {@link #createForSubscriptionId}, then the provided 4878 * subId is returned. Otherwise, the default subId will be returned. 4879 */ getSubId()4880 private int getSubId() { 4881 if (SubscriptionManager.isUsableSubIdValue(mSubId)) { 4882 return mSubId; 4883 } 4884 return SubscriptionManager.getDefaultSubscriptionId(); 4885 } 4886 4887 /** 4888 * Return an appropriate subscription ID for any situation. 4889 * 4890 * If this object has been created with {@link #createForSubscriptionId}, then the provided 4891 * subId is returned. Otherwise, the preferred subId which is based on caller's context is 4892 * returned. 4893 * {@see SubscriptionManager#getDefaultDataSubscriptionId()} 4894 * {@see SubscriptionManager#getDefaultVoiceSubscriptionId()} 4895 * {@see SubscriptionManager#getDefaultSmsSubscriptionId()} 4896 */ getSubId(int preferredSubId)4897 private int getSubId(int preferredSubId) { 4898 if (SubscriptionManager.isUsableSubIdValue(mSubId)) { 4899 return mSubId; 4900 } 4901 return preferredSubId; 4902 } 4903 4904 /** 4905 * Return an appropriate phone ID for any situation. 4906 * 4907 * If this object has been created with {@link #createForSubscriptionId}, then the phoneId 4908 * associated with the provided subId is returned. Otherwise, the default phoneId associated 4909 * with the default subId will be returned. 4910 */ getPhoneId()4911 private int getPhoneId() { 4912 return SubscriptionManager.getPhoneId(getSubId()); 4913 } 4914 4915 /** 4916 * Return an appropriate phone ID for any situation. 4917 * 4918 * If this object has been created with {@link #createForSubscriptionId}, then the phoneId 4919 * associated with the provided subId is returned. Otherwise, return the phoneId associated 4920 * with the preferred subId based on caller's context. 4921 * {@see SubscriptionManager#getDefaultDataSubscriptionId()} 4922 * {@see SubscriptionManager#getDefaultVoiceSubscriptionId()} 4923 * {@see SubscriptionManager#getDefaultSmsSubscriptionId()} 4924 */ getPhoneId(int preferredSubId)4925 private int getPhoneId(int preferredSubId) { 4926 return SubscriptionManager.getPhoneId(getSubId(preferredSubId)); 4927 } 4928 4929 /** 4930 * Return an appropriate slot index for any situation. 4931 * 4932 * if this object has been created with {@link #createForSubscriptionId}, then the slot index 4933 * associated with the provided subId is returned. Otherwise, return the slot index associated 4934 * with the default subId. 4935 * If SIM is not inserted, return default SIM slot index. 4936 * 4937 * {@hide} 4938 */ 4939 @VisibleForTesting getSlotIndex()4940 public int getSlotIndex() { 4941 int slotIndex = SubscriptionManager.getSlotIndex(getSubId()); 4942 if (slotIndex == SubscriptionManager.SIM_NOT_INSERTED) { 4943 slotIndex = SubscriptionManager.DEFAULT_SIM_SLOT_INDEX; 4944 } 4945 return slotIndex; 4946 } 4947 4948 /** 4949 * Sets a per-phone telephony property with the value specified. 4950 * 4951 * @hide 4952 */ setTelephonyProperty(int phoneId, String property, String value)4953 public static void setTelephonyProperty(int phoneId, String property, String value) { 4954 String propVal = ""; 4955 String p[] = null; 4956 String prop = SystemProperties.get(property); 4957 4958 if (value == null) { 4959 value = ""; 4960 } 4961 4962 if (prop != null) { 4963 p = prop.split(","); 4964 } 4965 4966 if (!SubscriptionManager.isValidPhoneId(phoneId)) { 4967 Rlog.d(TAG, "setTelephonyProperty: invalid phoneId=" + phoneId + 4968 " property=" + property + " value: " + value + " prop=" + prop); 4969 return; 4970 } 4971 4972 for (int i = 0; i < phoneId; i++) { 4973 String str = ""; 4974 if ((p != null) && (i < p.length)) { 4975 str = p[i]; 4976 } 4977 propVal = propVal + str + ","; 4978 } 4979 4980 propVal = propVal + value; 4981 if (p != null) { 4982 for (int i = phoneId + 1; i < p.length; i++) { 4983 propVal = propVal + "," + p[i]; 4984 } 4985 } 4986 4987 if (propVal.length() > SystemProperties.PROP_VALUE_MAX) { 4988 Rlog.d(TAG, "setTelephonyProperty: property too long phoneId=" + phoneId + 4989 " property=" + property + " value: " + value + " propVal=" + propVal); 4990 return; 4991 } 4992 4993 SystemProperties.set(property, propVal); 4994 } 4995 4996 /** 4997 * Sets a global telephony property with the value specified. 4998 * 4999 * @hide 5000 */ setTelephonyProperty(String property, String value)5001 public static void setTelephonyProperty(String property, String value) { 5002 if (value == null) { 5003 value = ""; 5004 } 5005 Rlog.d(TAG, "setTelephonyProperty: success" + " property=" + 5006 property + " value: " + value); 5007 SystemProperties.set(property, value); 5008 } 5009 5010 /** 5011 * Convenience function for retrieving a value from the secure settings 5012 * value list as an integer. Note that internally setting values are 5013 * always stored as strings; this function converts the string to an 5014 * integer for you. 5015 * <p> 5016 * This version does not take a default value. If the setting has not 5017 * been set, or the string value is not a number, 5018 * it throws {@link SettingNotFoundException}. 5019 * 5020 * @param cr The ContentResolver to access. 5021 * @param name The name of the setting to retrieve. 5022 * @param index The index of the list 5023 * 5024 * @throws SettingNotFoundException Thrown if a setting by the given 5025 * name can't be found or the setting value is not an integer. 5026 * 5027 * @return The value at the given index of settings. 5028 * @hide 5029 */ getIntAtIndex(android.content.ContentResolver cr, String name, int index)5030 public static int getIntAtIndex(android.content.ContentResolver cr, 5031 String name, int index) 5032 throws android.provider.Settings.SettingNotFoundException { 5033 String v = android.provider.Settings.Global.getString(cr, name); 5034 if (v != null) { 5035 String valArray[] = v.split(","); 5036 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 5037 try { 5038 return Integer.parseInt(valArray[index]); 5039 } catch (NumberFormatException e) { 5040 //Log.e(TAG, "Exception while parsing Integer: ", e); 5041 } 5042 } 5043 } 5044 throw new android.provider.Settings.SettingNotFoundException(name); 5045 } 5046 5047 /** 5048 * Convenience function for updating settings value as coma separated 5049 * integer values. This will either create a new entry in the table if the 5050 * given name does not exist, or modify the value of the existing row 5051 * with that name. Note that internally setting values are always 5052 * stored as strings, so this function converts the given value to a 5053 * string before storing it. 5054 * 5055 * @param cr The ContentResolver to access. 5056 * @param name The name of the setting to modify. 5057 * @param index The index of the list 5058 * @param value The new value for the setting to be added to the list. 5059 * @return true if the value was set, false on database errors 5060 * @hide 5061 */ putIntAtIndex(android.content.ContentResolver cr, String name, int index, int value)5062 public static boolean putIntAtIndex(android.content.ContentResolver cr, 5063 String name, int index, int value) { 5064 String data = ""; 5065 String valArray[] = null; 5066 String v = android.provider.Settings.Global.getString(cr, name); 5067 5068 if (index == Integer.MAX_VALUE) { 5069 throw new IllegalArgumentException("putIntAtIndex index == MAX_VALUE index=" + index); 5070 } 5071 if (index < 0) { 5072 throw new IllegalArgumentException("putIntAtIndex index < 0 index=" + index); 5073 } 5074 if (v != null) { 5075 valArray = v.split(","); 5076 } 5077 5078 // Copy the elements from valArray till index 5079 for (int i = 0; i < index; i++) { 5080 String str = ""; 5081 if ((valArray != null) && (i < valArray.length)) { 5082 str = valArray[i]; 5083 } 5084 data = data + str + ","; 5085 } 5086 5087 data = data + value; 5088 5089 // Copy the remaining elements from valArray if any. 5090 if (valArray != null) { 5091 for (int i = index+1; i < valArray.length; i++) { 5092 data = data + "," + valArray[i]; 5093 } 5094 } 5095 return android.provider.Settings.Global.putString(cr, name, data); 5096 } 5097 5098 /** 5099 * Gets a per-phone telephony property. 5100 * 5101 * @hide 5102 */ getTelephonyProperty(int phoneId, String property, String defaultVal)5103 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 5104 String propVal = null; 5105 String prop = SystemProperties.get(property); 5106 if ((prop != null) && (prop.length() > 0)) { 5107 String values[] = prop.split(","); 5108 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 5109 propVal = values[phoneId]; 5110 } 5111 } 5112 return propVal == null ? defaultVal : propVal; 5113 } 5114 5115 /** 5116 * Gets a global telephony property. 5117 * 5118 * See also getTelephonyProperty(phoneId, property, defaultVal). Most telephony properties are 5119 * per-phone. 5120 * 5121 * @hide 5122 */ getTelephonyProperty(String property, String defaultVal)5123 public static String getTelephonyProperty(String property, String defaultVal) { 5124 String propVal = SystemProperties.get(property); 5125 return propVal == null ? defaultVal : propVal; 5126 } 5127 5128 /** @hide */ getSimCount()5129 public int getSimCount() { 5130 // FIXME Need to get it from Telephony Dev Controller when that gets implemented! 5131 // and then this method shouldn't be used at all! 5132 if(isMultiSimEnabled()) { 5133 return 2; 5134 } else { 5135 return 1; 5136 } 5137 } 5138 5139 /** 5140 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 5141 * @return IMS Service Table or null if not present or not loaded 5142 * @hide 5143 */ getIsimIst()5144 public String getIsimIst() { 5145 try { 5146 IPhoneSubInfo info = getSubscriberInfo(); 5147 if (info == null) 5148 return null; 5149 //get the Isim Ist based on subId 5150 return info.getIsimIst(getSubId()); 5151 } catch (RemoteException ex) { 5152 return null; 5153 } catch (NullPointerException ex) { 5154 // This could happen before phone restarts due to crashing 5155 return null; 5156 } 5157 } 5158 5159 /** 5160 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 5161 * @return an array of PCSCF strings with one PCSCF per string, or null if 5162 * not present or not loaded 5163 * @hide 5164 */ getIsimPcscf()5165 public String[] getIsimPcscf() { 5166 try { 5167 IPhoneSubInfo info = getSubscriberInfo(); 5168 if (info == null) 5169 return null; 5170 //get the Isim Pcscf based on subId 5171 return info.getIsimPcscf(getSubId()); 5172 } catch (RemoteException ex) { 5173 return null; 5174 } catch (NullPointerException ex) { 5175 // This could happen before phone restarts due to crashing 5176 return null; 5177 } 5178 } 5179 5180 // ICC SIM Application Types 5181 /** UICC application type is SIM */ 5182 public static final int APPTYPE_SIM = PhoneConstants.APPTYPE_SIM; 5183 /** UICC application type is USIM */ 5184 public static final int APPTYPE_USIM = PhoneConstants.APPTYPE_USIM; 5185 /** UICC application type is RUIM */ 5186 public static final int APPTYPE_RUIM = PhoneConstants.APPTYPE_RUIM; 5187 /** UICC application type is CSIM */ 5188 public static final int APPTYPE_CSIM = PhoneConstants.APPTYPE_CSIM; 5189 /** UICC application type is ISIM */ 5190 public static final int APPTYPE_ISIM = PhoneConstants.APPTYPE_ISIM; 5191 // authContext (parameter P2) when doing UICC challenge, 5192 // per 3GPP TS 31.102 (Section 7.1.2) 5193 /** Authentication type for UICC challenge is EAP SIM. See RFC 4186 for details. */ 5194 public static final int AUTHTYPE_EAP_SIM = PhoneConstants.AUTH_CONTEXT_EAP_SIM; 5195 /** Authentication type for UICC challenge is EAP AKA. See RFC 4187 for details. */ 5196 public static final int AUTHTYPE_EAP_AKA = PhoneConstants.AUTH_CONTEXT_EAP_AKA; 5197 5198 /** 5199 * Returns the response of authentication for the default subscription. 5200 * Returns null if the authentication hasn't been successful 5201 * 5202 * <p>Requires Permission: READ_PRIVILEGED_PHONE_STATE or that the calling 5203 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5204 * 5205 * @param appType the icc application type, like {@link #APPTYPE_USIM} 5206 * @param authType the authentication type, {@link #AUTHTYPE_EAP_AKA} or 5207 * {@link #AUTHTYPE_EAP_SIM} 5208 * @param data authentication challenge data, base64 encoded. 5209 * See 3GPP TS 31.102 7.1.2 for more details. 5210 * @return the response of authentication. This value will be null in the following cases: 5211 * Authentication error, incorrect MAC 5212 * Authentication error, security context not supported 5213 * Key freshness failure 5214 * Authentication error, no memory space available 5215 * Authentication error, no memory space available in EFMUK 5216 */ 5217 // TODO(b/73660190): This should probably require MODIFY_PHONE_STATE, not 5218 // READ_PRIVILEGED_PHONE_STATE. It certainly shouldn't reference the permission in Javadoc since 5219 // it's not public API. getIccAuthentication(int appType, int authType, String data)5220 public String getIccAuthentication(int appType, int authType, String data) { 5221 return getIccAuthentication(getSubId(), appType, authType, data); 5222 } 5223 5224 /** 5225 * Returns the response of USIM Authentication for specified subId. 5226 * Returns null if the authentication hasn't been successful 5227 * 5228 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5229 * 5230 * @param subId subscription ID used for authentication 5231 * @param appType the icc application type, like {@link #APPTYPE_USIM} 5232 * @param authType the authentication type, {@link #AUTHTYPE_EAP_AKA} or 5233 * {@link #AUTHTYPE_EAP_SIM} 5234 * @param data authentication challenge data, base64 encoded. 5235 * See 3GPP TS 31.102 7.1.2 for more details. 5236 * @return the response of authentication. This value will be null in the following cases only 5237 * (see 3GPP TS 31.102 7.3.1): 5238 * Authentication error, incorrect MAC 5239 * Authentication error, security context not supported 5240 * Key freshness failure 5241 * Authentication error, no memory space available 5242 * Authentication error, no memory space available in EFMUK 5243 * @hide 5244 */ getIccAuthentication(int subId, int appType, int authType, String data)5245 public String getIccAuthentication(int subId, int appType, int authType, String data) { 5246 try { 5247 IPhoneSubInfo info = getSubscriberInfo(); 5248 if (info == null) 5249 return null; 5250 return info.getIccSimChallengeResponse(subId, appType, authType, data); 5251 } catch (RemoteException ex) { 5252 return null; 5253 } catch (NullPointerException ex) { 5254 // This could happen before phone starts 5255 return null; 5256 } 5257 } 5258 5259 /** 5260 * Returns an array of Forbidden PLMNs from the USIM App 5261 * Returns null if the query fails. 5262 * 5263 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 5264 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5265 * 5266 * @return an array of forbidden PLMNs or null if not available 5267 */ 5268 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 5269 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getForbiddenPlmns()5270 public String[] getForbiddenPlmns() { 5271 return getForbiddenPlmns(getSubId(), APPTYPE_USIM); 5272 } 5273 5274 /** 5275 * Returns an array of Forbidden PLMNs from the specified SIM App 5276 * Returns null if the query fails. 5277 * 5278 * @param subId subscription ID used for authentication 5279 * @param appType the icc application type, like {@link #APPTYPE_USIM} 5280 * @return fplmns an array of forbidden PLMNs 5281 * @hide 5282 */ 5283 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getForbiddenPlmns(int subId, int appType)5284 public String[] getForbiddenPlmns(int subId, int appType) { 5285 try { 5286 ITelephony telephony = getITelephony(); 5287 if (telephony == null) 5288 return null; 5289 return telephony.getForbiddenPlmns(subId, appType, mContext.getOpPackageName()); 5290 } catch (RemoteException ex) { 5291 return null; 5292 } catch (NullPointerException ex) { 5293 // This could happen before phone starts 5294 return null; 5295 } 5296 } 5297 5298 /** 5299 * Get P-CSCF address from PCO after data connection is established or modified. 5300 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 5301 * @return array of P-CSCF address 5302 * @hide 5303 */ getPcscfAddress(String apnType)5304 public String[] getPcscfAddress(String apnType) { 5305 try { 5306 ITelephony telephony = getITelephony(); 5307 if (telephony == null) 5308 return new String[0]; 5309 return telephony.getPcscfAddress(apnType, getOpPackageName()); 5310 } catch (RemoteException e) { 5311 return new String[0]; 5312 } 5313 } 5314 5315 /** 5316 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability 5317 * status updates, if not already enabled. 5318 * @hide 5319 */ enableIms(int slotId)5320 public void enableIms(int slotId) { 5321 try { 5322 ITelephony telephony = getITelephony(); 5323 if (telephony != null) { 5324 telephony.enableIms(slotId); 5325 } 5326 } catch (RemoteException e) { 5327 Rlog.e(TAG, "enableIms, RemoteException: " 5328 + e.getMessage()); 5329 } 5330 } 5331 5332 /** 5333 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature 5334 * status updates to disabled. 5335 * @hide 5336 */ disableIms(int slotId)5337 public void disableIms(int slotId) { 5338 try { 5339 ITelephony telephony = getITelephony(); 5340 if (telephony != null) { 5341 telephony.disableIms(slotId); 5342 } 5343 } catch (RemoteException e) { 5344 Rlog.e(TAG, "disableIms, RemoteException: " 5345 + e.getMessage()); 5346 } 5347 } 5348 5349 /** 5350 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id and MMTel 5351 * feature or {@link null} if the service is not available. If an MMTelFeature is available, the 5352 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. 5353 * @param slotIndex The SIM slot that we are requesting the {@link IImsMmTelFeature} for. 5354 * @param callback Listener that will send updates to ImsManager when there are updates to 5355 * ImsServiceController. 5356 * @return {@link IImsMmTelFeature} interface for the feature specified or {@code null} if 5357 * it is unavailable. 5358 * @hide 5359 */ getImsMmTelFeatureAndListen(int slotIndex, IImsServiceFeatureCallback callback)5360 public @Nullable IImsMmTelFeature getImsMmTelFeatureAndListen(int slotIndex, 5361 IImsServiceFeatureCallback callback) { 5362 try { 5363 ITelephony telephony = getITelephony(); 5364 if (telephony != null) { 5365 return telephony.getMmTelFeatureAndListen(slotIndex, callback); 5366 } 5367 } catch (RemoteException e) { 5368 Rlog.e(TAG, "getImsMmTelFeatureAndListen, RemoteException: " 5369 + e.getMessage()); 5370 } 5371 return null; 5372 } 5373 5374 /** 5375 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id and RCS 5376 * feature for emergency calling or {@link null} if the service is not available. If an 5377 * RcsFeature is available, the {@link IImsServiceFeatureCallback} callback is registered as a 5378 * listener for feature updates. 5379 * @param slotIndex The SIM slot that we are requesting the {@link IImsRcsFeature} for. 5380 * @param callback Listener that will send updates to ImsManager when there are updates to 5381 * ImsServiceController. 5382 * @return {@link IImsRcsFeature} interface for the feature specified or {@code null} if 5383 * it is unavailable. 5384 * @hide 5385 */ getImsRcsFeatureAndListen(int slotIndex, IImsServiceFeatureCallback callback)5386 public @Nullable IImsRcsFeature getImsRcsFeatureAndListen(int slotIndex, 5387 IImsServiceFeatureCallback callback) { 5388 try { 5389 ITelephony telephony = getITelephony(); 5390 if (telephony != null) { 5391 return telephony.getRcsFeatureAndListen(slotIndex, callback); 5392 } 5393 } catch (RemoteException e) { 5394 Rlog.e(TAG, "getImsRcsFeatureAndListen, RemoteException: " 5395 + e.getMessage()); 5396 } 5397 return null; 5398 } 5399 5400 /** 5401 * @return the {@IImsRegistration} interface that corresponds with the slot index and feature. 5402 * @param slotIndex The SIM slot corresponding to the ImsService ImsRegistration is active for. 5403 * @param feature An integer indicating the feature that we wish to get the ImsRegistration for. 5404 * Corresponds to features defined in ImsFeature. 5405 * @hide 5406 */ getImsRegistration(int slotIndex, int feature)5407 public @Nullable IImsRegistration getImsRegistration(int slotIndex, int feature) { 5408 try { 5409 ITelephony telephony = getITelephony(); 5410 if (telephony != null) { 5411 return telephony.getImsRegistration(slotIndex, feature); 5412 } 5413 } catch (RemoteException e) { 5414 Rlog.e(TAG, "getImsRegistration, RemoteException: " + e.getMessage()); 5415 } 5416 return null; 5417 } 5418 5419 /** 5420 * @return the {@IImsConfig} interface that corresponds with the slot index and feature. 5421 * @param slotIndex The SIM slot corresponding to the ImsService ImsConfig is active for. 5422 * @param feature An integer indicating the feature that we wish to get the ImsConfig for. 5423 * Corresponds to features defined in ImsFeature. 5424 * @hide 5425 */ getImsConfig(int slotIndex, int feature)5426 public @Nullable IImsConfig getImsConfig(int slotIndex, int feature) { 5427 try { 5428 ITelephony telephony = getITelephony(); 5429 if (telephony != null) { 5430 return telephony.getImsConfig(slotIndex, feature); 5431 } 5432 } catch (RemoteException e) { 5433 Rlog.e(TAG, "getImsRegistration, RemoteException: " + e.getMessage()); 5434 } 5435 return null; 5436 } 5437 5438 /** 5439 * @return true if the IMS resolver is busy resolving a binding and should not be considered 5440 * available, false if the IMS resolver is idle. 5441 * @hide 5442 */ isResolvingImsBinding()5443 public boolean isResolvingImsBinding() { 5444 try { 5445 ITelephony telephony = getITelephony(); 5446 if (telephony != null) { 5447 return telephony.isResolvingImsBinding(); 5448 } 5449 } catch (RemoteException e) { 5450 Rlog.e(TAG, "isResolvingImsBinding, RemoteException: " + e.getMessage()); 5451 } 5452 return false; 5453 } 5454 5455 /** 5456 * Set IMS registration state 5457 * 5458 * @param Registration state 5459 * @hide 5460 */ setImsRegistrationState(boolean registered)5461 public void setImsRegistrationState(boolean registered) { 5462 try { 5463 ITelephony telephony = getITelephony(); 5464 if (telephony != null) 5465 telephony.setImsRegistrationState(registered); 5466 } catch (RemoteException e) { 5467 } 5468 } 5469 5470 /** 5471 * Get the preferred network type. 5472 * Used for device configuration by some CDMA operators. 5473 * 5474 * <p>Requires Permission: 5475 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5476 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5477 * 5478 * @return the preferred network type, defined in RILConstants.java. 5479 * @hide 5480 */ getPreferredNetworkType(int subId)5481 public int getPreferredNetworkType(int subId) { 5482 try { 5483 ITelephony telephony = getITelephony(); 5484 if (telephony != null) 5485 return telephony.getPreferredNetworkType(subId); 5486 } catch (RemoteException ex) { 5487 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 5488 } catch (NullPointerException ex) { 5489 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 5490 } 5491 return -1; 5492 } 5493 5494 /** 5495 * Sets the network selection mode to automatic. 5496 * 5497 * <p>Requires Permission: 5498 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5499 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5500 */ 5501 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 5502 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setNetworkSelectionModeAutomatic()5503 public void setNetworkSelectionModeAutomatic() { 5504 try { 5505 ITelephony telephony = getITelephony(); 5506 if (telephony != null) { 5507 telephony.setNetworkSelectionModeAutomatic(getSubId()); 5508 } 5509 } catch (RemoteException ex) { 5510 Rlog.e(TAG, "setNetworkSelectionModeAutomatic RemoteException", ex); 5511 } catch (NullPointerException ex) { 5512 Rlog.e(TAG, "setNetworkSelectionModeAutomatic NPE", ex); 5513 } 5514 } 5515 5516 /** 5517 * Perform a radio scan and return the list of available networks. 5518 * 5519 * The return value is a list of the OperatorInfo of the networks found. Note that this 5520 * scan can take a long time (sometimes minutes) to happen. 5521 * 5522 * <p>Requires Permission: 5523 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5524 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5525 * 5526 * @hide 5527 * TODO: Add an overload that takes no args. 5528 */ getCellNetworkScanResults(int subId)5529 public CellNetworkScanResult getCellNetworkScanResults(int subId) { 5530 try { 5531 ITelephony telephony = getITelephony(); 5532 if (telephony != null) 5533 return telephony.getCellNetworkScanResults(subId); 5534 } catch (RemoteException ex) { 5535 Rlog.e(TAG, "getCellNetworkScanResults RemoteException", ex); 5536 } catch (NullPointerException ex) { 5537 Rlog.e(TAG, "getCellNetworkScanResults NPE", ex); 5538 } 5539 return null; 5540 } 5541 5542 /** 5543 * Request a network scan. 5544 * 5545 * This method is asynchronous, so the network scan results will be returned by callback. 5546 * The returned NetworkScan will contain a callback method which can be used to stop the scan. 5547 * 5548 * <p>Requires Permission: 5549 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5550 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5551 * 5552 * @param request Contains all the RAT with bands/channels that need to be scanned. 5553 * @param executor The executor through which the callback should be invoked. Since the scan 5554 * request may trigger multiple callbacks and they must be invoked in the same order as 5555 * they are received by the platform, the user should provide an executor which executes 5556 * tasks one at a time in serial order. For example AsyncTask.SERIAL_EXECUTOR. 5557 * @param callback Returns network scan results or errors. 5558 * @return A NetworkScan obj which contains a callback which can be used to stop the scan. 5559 */ 5560 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 5561 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) requestNetworkScan( NetworkScanRequest request, Executor executor, TelephonyScanManager.NetworkScanCallback callback)5562 public NetworkScan requestNetworkScan( 5563 NetworkScanRequest request, Executor executor, 5564 TelephonyScanManager.NetworkScanCallback callback) { 5565 synchronized (this) { 5566 if (mTelephonyScanManager == null) { 5567 mTelephonyScanManager = new TelephonyScanManager(); 5568 } 5569 } 5570 return mTelephonyScanManager.requestNetworkScan(getSubId(), request, executor, callback); 5571 } 5572 5573 /** 5574 * @deprecated 5575 * Use {@link 5576 * #requestNetworkScan(NetworkScanRequest, Executor, TelephonyScanManager.NetworkScanCallback)} 5577 * @removed 5578 */ 5579 @Deprecated 5580 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) requestNetworkScan( NetworkScanRequest request, TelephonyScanManager.NetworkScanCallback callback)5581 public NetworkScan requestNetworkScan( 5582 NetworkScanRequest request, TelephonyScanManager.NetworkScanCallback callback) { 5583 return requestNetworkScan(request, AsyncTask.SERIAL_EXECUTOR, callback); 5584 } 5585 5586 /** 5587 * Ask the radio to connect to the input network and change selection mode to manual. 5588 * 5589 * <p>Requires Permission: 5590 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5591 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5592 * 5593 * @param operatorNumeric the PLMN ID of the network to select. 5594 * @param persistSelection whether the selection will persist until reboot. If true, only allows 5595 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume 5596 * normal network selection next time. 5597 * @return true on success; false on any failure. 5598 */ 5599 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 5600 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setNetworkSelectionModeManual(String operatorNumeric, boolean persistSelection)5601 public boolean setNetworkSelectionModeManual(String operatorNumeric, boolean persistSelection) { 5602 try { 5603 ITelephony telephony = getITelephony(); 5604 if (telephony != null) { 5605 return telephony.setNetworkSelectionModeManual( 5606 getSubId(), operatorNumeric, persistSelection); 5607 } 5608 } catch (RemoteException ex) { 5609 Rlog.e(TAG, "setNetworkSelectionModeManual RemoteException", ex); 5610 } catch (NullPointerException ex) { 5611 Rlog.e(TAG, "setNetworkSelectionModeManual NPE", ex); 5612 } 5613 return false; 5614 } 5615 5616 /** 5617 * Set the preferred network type. 5618 * Used for device configuration by some CDMA operators. 5619 * 5620 * <p>Requires Permission: 5621 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 5622 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 5623 * 5624 * @param subId the id of the subscription to set the preferred network type for. 5625 * @param networkType the preferred network type, defined in RILConstants.java. 5626 * @return true on success; false on any failure. 5627 * @hide 5628 */ setPreferredNetworkType(int subId, int networkType)5629 public boolean setPreferredNetworkType(int subId, int networkType) { 5630 try { 5631 ITelephony telephony = getITelephony(); 5632 if (telephony != null) { 5633 return telephony.setPreferredNetworkType(subId, networkType); 5634 } 5635 } catch (RemoteException ex) { 5636 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 5637 } catch (NullPointerException ex) { 5638 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 5639 } 5640 return false; 5641 } 5642 5643 /** 5644 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 5645 * 5646 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5647 * 5648 * @return true on success; false on any failure. 5649 */ setPreferredNetworkTypeToGlobal()5650 public boolean setPreferredNetworkTypeToGlobal() { 5651 return setPreferredNetworkTypeToGlobal(getSubId()); 5652 } 5653 5654 /** 5655 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 5656 * 5657 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5658 * 5659 * @return true on success; false on any failure. 5660 * @hide 5661 */ setPreferredNetworkTypeToGlobal(int subId)5662 public boolean setPreferredNetworkTypeToGlobal(int subId) { 5663 return setPreferredNetworkType(subId, RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); 5664 } 5665 5666 /** 5667 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning 5668 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for 5669 * tethering. 5670 * 5671 * @return 0: Not required. 1: required. 2: Not set. 5672 * @hide 5673 */ getTetherApnRequired()5674 public int getTetherApnRequired() { 5675 try { 5676 ITelephony telephony = getITelephony(); 5677 if (telephony != null) 5678 return telephony.getTetherApnRequired(); 5679 } catch (RemoteException ex) { 5680 Rlog.e(TAG, "hasMatchedTetherApnSetting RemoteException", ex); 5681 } catch (NullPointerException ex) { 5682 Rlog.e(TAG, "hasMatchedTetherApnSetting NPE", ex); 5683 } 5684 return 2; 5685 } 5686 5687 5688 /** 5689 * Values used to return status for hasCarrierPrivileges call. 5690 */ 5691 /** @hide */ @SystemApi 5692 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 5693 /** @hide */ @SystemApi 5694 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 5695 /** @hide */ @SystemApi 5696 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 5697 /** @hide */ @SystemApi 5698 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 5699 5700 /** 5701 * Has the calling application been granted carrier privileges by the carrier. 5702 * 5703 * If any of the packages in the calling UID has carrier privileges, the 5704 * call will return true. This access is granted by the owner of the UICC 5705 * card and does not depend on the registered carrier. 5706 * 5707 * @return true if the app has carrier privileges. 5708 */ hasCarrierPrivileges()5709 public boolean hasCarrierPrivileges() { 5710 return hasCarrierPrivileges(getSubId()); 5711 } 5712 5713 /** 5714 * Has the calling application been granted carrier privileges by the carrier. 5715 * 5716 * If any of the packages in the calling UID has carrier privileges, the 5717 * call will return true. This access is granted by the owner of the UICC 5718 * card and does not depend on the registered carrier. 5719 * 5720 * @param subId The subscription to use. 5721 * @return true if the app has carrier privileges. 5722 * @hide 5723 */ hasCarrierPrivileges(int subId)5724 public boolean hasCarrierPrivileges(int subId) { 5725 try { 5726 ITelephony telephony = getITelephony(); 5727 if (telephony != null) { 5728 return telephony.getCarrierPrivilegeStatus(mSubId) == 5729 CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; 5730 } 5731 } catch (RemoteException ex) { 5732 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 5733 } catch (NullPointerException ex) { 5734 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 5735 } 5736 return false; 5737 } 5738 5739 /** 5740 * Override the branding for the current ICCID. 5741 * 5742 * Once set, whenever the SIM is present in the device, the service 5743 * provider name (SPN) and the operator name will both be replaced by the 5744 * brand value input. To unset the value, the same function should be 5745 * called with a null brand value. 5746 * 5747 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5748 * 5749 * @param brand The brand name to display/set. 5750 * @return true if the operation was executed correctly. 5751 */ setOperatorBrandOverride(String brand)5752 public boolean setOperatorBrandOverride(String brand) { 5753 return setOperatorBrandOverride(getSubId(), brand); 5754 } 5755 5756 /** 5757 * Override the branding for the current ICCID. 5758 * 5759 * Once set, whenever the SIM is present in the device, the service 5760 * provider name (SPN) and the operator name will both be replaced by the 5761 * brand value input. To unset the value, the same function should be 5762 * called with a null brand value. 5763 * 5764 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5765 * 5766 * @param subId The subscription to use. 5767 * @param brand The brand name to display/set. 5768 * @return true if the operation was executed correctly. 5769 * @hide 5770 */ setOperatorBrandOverride(int subId, String brand)5771 public boolean setOperatorBrandOverride(int subId, String brand) { 5772 try { 5773 ITelephony telephony = getITelephony(); 5774 if (telephony != null) 5775 return telephony.setOperatorBrandOverride(subId, brand); 5776 } catch (RemoteException ex) { 5777 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 5778 } catch (NullPointerException ex) { 5779 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 5780 } 5781 return false; 5782 } 5783 5784 /** 5785 * Override the roaming preference for the current ICCID. 5786 * 5787 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 5788 * the platform's notion of a network operator being considered roaming or not. 5789 * The change only affects the ICCID that was active when this call was made. 5790 * 5791 * If null is passed as any of the input, the corresponding value is deleted. 5792 * 5793 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 5794 * 5795 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 5796 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 5797 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 5798 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 5799 * @return true if the operation was executed correctly. 5800 * 5801 * @hide 5802 */ setRoamingOverride(List<String> gsmRoamingList, List<String> gsmNonRoamingList, List<String> cdmaRoamingList, List<String> cdmaNonRoamingList)5803 public boolean setRoamingOverride(List<String> gsmRoamingList, 5804 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 5805 List<String> cdmaNonRoamingList) { 5806 return setRoamingOverride(getSubId(), gsmRoamingList, gsmNonRoamingList, 5807 cdmaRoamingList, cdmaNonRoamingList); 5808 } 5809 5810 /** 5811 * Override the roaming preference for the current ICCID. 5812 * 5813 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 5814 * the platform's notion of a network operator being considered roaming or not. 5815 * The change only affects the ICCID that was active when this call was made. 5816 * 5817 * If null is passed as any of the input, the corresponding value is deleted. 5818 * 5819 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 5820 * 5821 * @param subId for which the roaming overrides apply. 5822 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 5823 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 5824 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 5825 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 5826 * @return true if the operation was executed correctly. 5827 * 5828 * @hide 5829 */ setRoamingOverride(int subId, List<String> gsmRoamingList, List<String> gsmNonRoamingList, List<String> cdmaRoamingList, List<String> cdmaNonRoamingList)5830 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, 5831 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 5832 List<String> cdmaNonRoamingList) { 5833 try { 5834 ITelephony telephony = getITelephony(); 5835 if (telephony != null) 5836 return telephony.setRoamingOverride(subId, gsmRoamingList, gsmNonRoamingList, 5837 cdmaRoamingList, cdmaNonRoamingList); 5838 } catch (RemoteException ex) { 5839 Rlog.e(TAG, "setRoamingOverride RemoteException", ex); 5840 } catch (NullPointerException ex) { 5841 Rlog.e(TAG, "setRoamingOverride NPE", ex); 5842 } 5843 return false; 5844 } 5845 5846 /** 5847 * Expose the rest of ITelephony to @SystemApi 5848 */ 5849 5850 /** @hide */ 5851 @SystemApi 5852 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getCdmaMdn()5853 public String getCdmaMdn() { 5854 return getCdmaMdn(getSubId()); 5855 } 5856 5857 /** @hide */ 5858 @SystemApi 5859 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getCdmaMdn(int subId)5860 public String getCdmaMdn(int subId) { 5861 try { 5862 ITelephony telephony = getITelephony(); 5863 if (telephony == null) 5864 return null; 5865 return telephony.getCdmaMdn(subId); 5866 } catch (RemoteException ex) { 5867 return null; 5868 } catch (NullPointerException ex) { 5869 return null; 5870 } 5871 } 5872 5873 /** @hide */ 5874 @SystemApi 5875 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getCdmaMin()5876 public String getCdmaMin() { 5877 return getCdmaMin(getSubId()); 5878 } 5879 5880 /** @hide */ 5881 @SystemApi 5882 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getCdmaMin(int subId)5883 public String getCdmaMin(int subId) { 5884 try { 5885 ITelephony telephony = getITelephony(); 5886 if (telephony == null) 5887 return null; 5888 return telephony.getCdmaMin(subId); 5889 } catch (RemoteException ex) { 5890 return null; 5891 } catch (NullPointerException ex) { 5892 return null; 5893 } 5894 } 5895 5896 /** @hide */ 5897 @SystemApi 5898 @SuppressLint("Doclava125") checkCarrierPrivilegesForPackage(String pkgName)5899 public int checkCarrierPrivilegesForPackage(String pkgName) { 5900 try { 5901 ITelephony telephony = getITelephony(); 5902 if (telephony != null) 5903 return telephony.checkCarrierPrivilegesForPackage(pkgName); 5904 } catch (RemoteException ex) { 5905 Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex); 5906 } catch (NullPointerException ex) { 5907 Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex); 5908 } 5909 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 5910 } 5911 5912 /** @hide */ 5913 @SystemApi 5914 @SuppressLint("Doclava125") checkCarrierPrivilegesForPackageAnyPhone(String pkgName)5915 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { 5916 try { 5917 ITelephony telephony = getITelephony(); 5918 if (telephony != null) 5919 return telephony.checkCarrierPrivilegesForPackageAnyPhone(pkgName); 5920 } catch (RemoteException ex) { 5921 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone RemoteException", ex); 5922 } catch (NullPointerException ex) { 5923 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone NPE", ex); 5924 } 5925 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 5926 } 5927 5928 /** @hide */ 5929 @SystemApi getCarrierPackageNamesForIntent(Intent intent)5930 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 5931 return getCarrierPackageNamesForIntentAndPhone(intent, getPhoneId()); 5932 } 5933 5934 /** @hide */ 5935 @SystemApi getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId)5936 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { 5937 try { 5938 ITelephony telephony = getITelephony(); 5939 if (telephony != null) 5940 return telephony.getCarrierPackageNamesForIntentAndPhone(intent, phoneId); 5941 } catch (RemoteException ex) { 5942 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone RemoteException", ex); 5943 } catch (NullPointerException ex) { 5944 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone NPE", ex); 5945 } 5946 return null; 5947 } 5948 5949 /** @hide */ getPackagesWithCarrierPrivileges()5950 public List<String> getPackagesWithCarrierPrivileges() { 5951 try { 5952 ITelephony telephony = getITelephony(); 5953 if (telephony != null) { 5954 return telephony.getPackagesWithCarrierPrivileges(); 5955 } 5956 } catch (RemoteException ex) { 5957 Rlog.e(TAG, "getPackagesWithCarrierPrivileges RemoteException", ex); 5958 } catch (NullPointerException ex) { 5959 Rlog.e(TAG, "getPackagesWithCarrierPrivileges NPE", ex); 5960 } 5961 return Collections.EMPTY_LIST; 5962 } 5963 5964 /** @hide */ 5965 @SystemApi 5966 @SuppressLint("Doclava125") dial(String number)5967 public void dial(String number) { 5968 try { 5969 ITelephony telephony = getITelephony(); 5970 if (telephony != null) 5971 telephony.dial(number); 5972 } catch (RemoteException e) { 5973 Log.e(TAG, "Error calling ITelephony#dial", e); 5974 } 5975 } 5976 5977 /** 5978 * @deprecated Use {@link android.telecom.TelecomManager#placeCall(Uri address, 5979 * Bundle extras)} instead. 5980 * @hide 5981 */ 5982 @Deprecated 5983 @SystemApi 5984 @RequiresPermission(android.Manifest.permission.CALL_PHONE) call(String callingPackage, String number)5985 public void call(String callingPackage, String number) { 5986 try { 5987 ITelephony telephony = getITelephony(); 5988 if (telephony != null) 5989 telephony.call(callingPackage, number); 5990 } catch (RemoteException e) { 5991 Log.e(TAG, "Error calling ITelephony#call", e); 5992 } 5993 } 5994 5995 /** 5996 * @deprecated Use {@link android.telecom.TelecomManager#endCall()} instead. 5997 * @hide 5998 */ 5999 @Deprecated 6000 @SystemApi 6001 @RequiresPermission(android.Manifest.permission.CALL_PHONE) endCall()6002 public boolean endCall() { 6003 try { 6004 ITelephony telephony = getITelephony(); 6005 if (telephony != null) 6006 return telephony.endCall(); 6007 } catch (RemoteException e) { 6008 Log.e(TAG, "Error calling ITelephony#endCall", e); 6009 } 6010 return false; 6011 } 6012 6013 /** 6014 * @deprecated Use {@link android.telecom.TelecomManager#acceptRingingCall} instead 6015 * @hide 6016 */ 6017 @Deprecated 6018 @SystemApi 6019 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) answerRingingCall()6020 public void answerRingingCall() { 6021 try { 6022 ITelephony telephony = getITelephony(); 6023 if (telephony != null) 6024 telephony.answerRingingCall(); 6025 } catch (RemoteException e) { 6026 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 6027 } 6028 } 6029 6030 /** 6031 * @deprecated Use {@link android.telecom.TelecomManager#silenceRinger} instead 6032 * @hide 6033 */ 6034 @Deprecated 6035 @SystemApi 6036 @SuppressLint("Doclava125") silenceRinger()6037 public void silenceRinger() { 6038 try { 6039 getTelecomService().silenceRinger(getOpPackageName()); 6040 } catch (RemoteException e) { 6041 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); 6042 } 6043 } 6044 6045 /** @hide */ 6046 @SystemApi 6047 @RequiresPermission(anyOf = { 6048 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 6049 android.Manifest.permission.READ_PHONE_STATE 6050 }) isOffhook()6051 public boolean isOffhook() { 6052 try { 6053 ITelephony telephony = getITelephony(); 6054 if (telephony != null) 6055 return telephony.isOffhook(getOpPackageName()); 6056 } catch (RemoteException e) { 6057 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 6058 } 6059 return false; 6060 } 6061 6062 /** @hide */ 6063 @SystemApi 6064 @RequiresPermission(anyOf = { 6065 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 6066 android.Manifest.permission.READ_PHONE_STATE 6067 }) isRinging()6068 public boolean isRinging() { 6069 try { 6070 ITelephony telephony = getITelephony(); 6071 if (telephony != null) 6072 return telephony.isRinging(getOpPackageName()); 6073 } catch (RemoteException e) { 6074 Log.e(TAG, "Error calling ITelephony#isRinging", e); 6075 } 6076 return false; 6077 } 6078 6079 /** @hide */ 6080 @SystemApi 6081 @RequiresPermission(anyOf = { 6082 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 6083 android.Manifest.permission.READ_PHONE_STATE 6084 }) isIdle()6085 public boolean isIdle() { 6086 try { 6087 ITelephony telephony = getITelephony(); 6088 if (telephony != null) 6089 return telephony.isIdle(getOpPackageName()); 6090 } catch (RemoteException e) { 6091 Log.e(TAG, "Error calling ITelephony#isIdle", e); 6092 } 6093 return true; 6094 } 6095 6096 /** @hide */ 6097 @SystemApi 6098 @RequiresPermission(anyOf = { 6099 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 6100 android.Manifest.permission.READ_PHONE_STATE 6101 }) isRadioOn()6102 public boolean isRadioOn() { 6103 try { 6104 ITelephony telephony = getITelephony(); 6105 if (telephony != null) 6106 return telephony.isRadioOn(getOpPackageName()); 6107 } catch (RemoteException e) { 6108 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 6109 } 6110 return false; 6111 } 6112 6113 /** @hide */ 6114 @SystemApi 6115 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) supplyPin(String pin)6116 public boolean supplyPin(String pin) { 6117 try { 6118 ITelephony telephony = getITelephony(); 6119 if (telephony != null) 6120 return telephony.supplyPin(pin); 6121 } catch (RemoteException e) { 6122 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 6123 } 6124 return false; 6125 } 6126 6127 /** @hide */ 6128 @SystemApi 6129 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) supplyPuk(String puk, String pin)6130 public boolean supplyPuk(String puk, String pin) { 6131 try { 6132 ITelephony telephony = getITelephony(); 6133 if (telephony != null) 6134 return telephony.supplyPuk(puk, pin); 6135 } catch (RemoteException e) { 6136 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 6137 } 6138 return false; 6139 } 6140 6141 /** @hide */ 6142 @SystemApi 6143 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) supplyPinReportResult(String pin)6144 public int[] supplyPinReportResult(String pin) { 6145 try { 6146 ITelephony telephony = getITelephony(); 6147 if (telephony != null) 6148 return telephony.supplyPinReportResult(pin); 6149 } catch (RemoteException e) { 6150 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 6151 } 6152 return new int[0]; 6153 } 6154 6155 /** @hide */ 6156 @SystemApi 6157 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) supplyPukReportResult(String puk, String pin)6158 public int[] supplyPukReportResult(String puk, String pin) { 6159 try { 6160 ITelephony telephony = getITelephony(); 6161 if (telephony != null) 6162 return telephony.supplyPukReportResult(puk, pin); 6163 } catch (RemoteException e) { 6164 Log.e(TAG, "Error calling ITelephony#]", e); 6165 } 6166 return new int[0]; 6167 } 6168 6169 /** 6170 * Used to notify callers of 6171 * {@link TelephonyManager#sendUssdRequest(String, UssdResponseCallback, Handler)} when the 6172 * network either successfully executes a USSD request, or if there was a failure while 6173 * executing the request. 6174 * <p> 6175 * {@link #onReceiveUssdResponse(TelephonyManager, String, CharSequence)} will be called if the 6176 * USSD request has succeeded. 6177 * {@link #onReceiveUssdResponseFailed(TelephonyManager, String, int)} will be called if the 6178 * USSD request has failed. 6179 */ 6180 public static abstract class UssdResponseCallback { 6181 /** 6182 * Called when a USSD request has succeeded. The {@code response} contains the USSD 6183 * response received from the network. The calling app can choose to either display the 6184 * response to the user or perform some operation based on the response. 6185 * <p> 6186 * USSD responses are unstructured text and their content is determined by the mobile network 6187 * operator. 6188 * 6189 * @param telephonyManager the TelephonyManager the callback is registered to. 6190 * @param request the USSD request sent to the mobile network. 6191 * @param response the response to the USSD request provided by the mobile network. 6192 **/ onReceiveUssdResponse(final TelephonyManager telephonyManager, String request, CharSequence response)6193 public void onReceiveUssdResponse(final TelephonyManager telephonyManager, 6194 String request, CharSequence response) {}; 6195 6196 /** 6197 * Called when a USSD request has failed to complete. 6198 * 6199 * @param telephonyManager the TelephonyManager the callback is registered to. 6200 * @param request the USSD request sent to the mobile network. 6201 * @param failureCode failure code indicating why the request failed. Will be either 6202 * {@link TelephonyManager#USSD_RETURN_FAILURE} or 6203 * {@link TelephonyManager#USSD_ERROR_SERVICE_UNAVAIL}. 6204 **/ onReceiveUssdResponseFailed(final TelephonyManager telephonyManager, String request, int failureCode)6205 public void onReceiveUssdResponseFailed(final TelephonyManager telephonyManager, 6206 String request, int failureCode) {}; 6207 } 6208 6209 /** 6210 * Sends an Unstructured Supplementary Service Data (USSD) request to the mobile network and 6211 * informs the caller of the response via the supplied {@code callback}. 6212 * <p>Carriers define USSD codes which can be sent by the user to request information such as 6213 * the user's current data balance or minutes balance. 6214 * <p>Requires permission: 6215 * {@link android.Manifest.permission#CALL_PHONE} 6216 * @param ussdRequest the USSD command to be executed. 6217 * @param callback called by the framework to inform the caller of the result of executing the 6218 * USSD request (see {@link UssdResponseCallback}). 6219 * @param handler the {@link Handler} to run the request on. 6220 */ 6221 @RequiresPermission(android.Manifest.permission.CALL_PHONE) sendUssdRequest(String ussdRequest, final UssdResponseCallback callback, Handler handler)6222 public void sendUssdRequest(String ussdRequest, 6223 final UssdResponseCallback callback, Handler handler) { 6224 checkNotNull(callback, "UssdResponseCallback cannot be null."); 6225 final TelephonyManager telephonyManager = this; 6226 6227 ResultReceiver wrappedCallback = new ResultReceiver(handler) { 6228 @Override 6229 protected void onReceiveResult(int resultCode, Bundle ussdResponse) { 6230 Rlog.d(TAG, "USSD:" + resultCode); 6231 checkNotNull(ussdResponse, "ussdResponse cannot be null."); 6232 UssdResponse response = ussdResponse.getParcelable(USSD_RESPONSE); 6233 6234 if (resultCode == USSD_RETURN_SUCCESS) { 6235 callback.onReceiveUssdResponse(telephonyManager, response.getUssdRequest(), 6236 response.getReturnMessage()); 6237 } else { 6238 callback.onReceiveUssdResponseFailed(telephonyManager, 6239 response.getUssdRequest(), resultCode); 6240 } 6241 } 6242 }; 6243 6244 try { 6245 ITelephony telephony = getITelephony(); 6246 if (telephony != null) { 6247 telephony.handleUssdRequest(getSubId(), ussdRequest, wrappedCallback); 6248 } 6249 } catch (RemoteException e) { 6250 Log.e(TAG, "Error calling ITelephony#sendUSSDCode", e); 6251 UssdResponse response = new UssdResponse(ussdRequest, ""); 6252 Bundle returnData = new Bundle(); 6253 returnData.putParcelable(USSD_RESPONSE, response); 6254 wrappedCallback.send(USSD_ERROR_SERVICE_UNAVAIL, returnData); 6255 } 6256 } 6257 6258 /** 6259 * Whether the device is currently on a technology (e.g. UMTS or LTE) which can support 6260 * voice and data simultaneously. This can change based on location or network condition. 6261 * 6262 * @return {@code true} if simultaneous voice and data supported, and {@code false} otherwise. 6263 */ isConcurrentVoiceAndDataSupported()6264 public boolean isConcurrentVoiceAndDataSupported() { 6265 try { 6266 ITelephony telephony = getITelephony(); 6267 return (telephony == null ? false : telephony.isConcurrentVoiceAndDataAllowed( 6268 getSubId())); 6269 } catch (RemoteException e) { 6270 Log.e(TAG, "Error calling ITelephony#isConcurrentVoiceAndDataAllowed", e); 6271 } 6272 return false; 6273 } 6274 6275 /** @hide */ 6276 @SystemApi 6277 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) handlePinMmi(String dialString)6278 public boolean handlePinMmi(String dialString) { 6279 try { 6280 ITelephony telephony = getITelephony(); 6281 if (telephony != null) 6282 return telephony.handlePinMmi(dialString); 6283 } catch (RemoteException e) { 6284 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 6285 } 6286 return false; 6287 } 6288 6289 /** @hide */ 6290 @SystemApi 6291 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) handlePinMmiForSubscriber(int subId, String dialString)6292 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 6293 try { 6294 ITelephony telephony = getITelephony(); 6295 if (telephony != null) 6296 return telephony.handlePinMmiForSubscriber(subId, dialString); 6297 } catch (RemoteException e) { 6298 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 6299 } 6300 return false; 6301 } 6302 6303 /** @hide */ 6304 @SystemApi 6305 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) toggleRadioOnOff()6306 public void toggleRadioOnOff() { 6307 try { 6308 ITelephony telephony = getITelephony(); 6309 if (telephony != null) 6310 telephony.toggleRadioOnOff(); 6311 } catch (RemoteException e) { 6312 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 6313 } 6314 } 6315 6316 /** @hide */ 6317 @SystemApi 6318 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setRadio(boolean turnOn)6319 public boolean setRadio(boolean turnOn) { 6320 try { 6321 ITelephony telephony = getITelephony(); 6322 if (telephony != null) 6323 return telephony.setRadio(turnOn); 6324 } catch (RemoteException e) { 6325 Log.e(TAG, "Error calling ITelephony#setRadio", e); 6326 } 6327 return false; 6328 } 6329 6330 /** @hide */ 6331 @SystemApi 6332 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setRadioPower(boolean turnOn)6333 public boolean setRadioPower(boolean turnOn) { 6334 try { 6335 ITelephony telephony = getITelephony(); 6336 if (telephony != null) 6337 return telephony.setRadioPower(turnOn); 6338 } catch (RemoteException e) { 6339 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 6340 } 6341 return false; 6342 } 6343 6344 /** @hide */ 6345 @SystemApi 6346 @SuppressLint("Doclava125") updateServiceLocation()6347 public void updateServiceLocation() { 6348 try { 6349 ITelephony telephony = getITelephony(); 6350 if (telephony != null) 6351 telephony.updateServiceLocation(); 6352 } catch (RemoteException e) { 6353 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 6354 } 6355 } 6356 6357 /** @hide */ 6358 @SystemApi 6359 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) enableDataConnectivity()6360 public boolean enableDataConnectivity() { 6361 try { 6362 ITelephony telephony = getITelephony(); 6363 if (telephony != null) 6364 return telephony.enableDataConnectivity(); 6365 } catch (RemoteException e) { 6366 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 6367 } 6368 return false; 6369 } 6370 6371 /** @hide */ 6372 @SystemApi 6373 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) disableDataConnectivity()6374 public boolean disableDataConnectivity() { 6375 try { 6376 ITelephony telephony = getITelephony(); 6377 if (telephony != null) 6378 return telephony.disableDataConnectivity(); 6379 } catch (RemoteException e) { 6380 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 6381 } 6382 return false; 6383 } 6384 6385 /** @hide */ 6386 @SystemApi isDataConnectivityPossible()6387 public boolean isDataConnectivityPossible() { 6388 try { 6389 ITelephony telephony = getITelephony(); 6390 if (telephony != null) 6391 return telephony.isDataConnectivityPossible(getSubId(SubscriptionManager 6392 .getDefaultDataSubscriptionId())); 6393 } catch (RemoteException e) { 6394 Log.e(TAG, "Error calling ITelephony#isDataAllowed", e); 6395 } 6396 return false; 6397 } 6398 6399 /** @hide */ 6400 @SystemApi needsOtaServiceProvisioning()6401 public boolean needsOtaServiceProvisioning() { 6402 try { 6403 ITelephony telephony = getITelephony(); 6404 if (telephony != null) 6405 return telephony.needsOtaServiceProvisioning(); 6406 } catch (RemoteException e) { 6407 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 6408 } 6409 return false; 6410 } 6411 6412 /** 6413 * Turns mobile data on or off. 6414 * If this object has been created with {@link #createForSubscriptionId}, applies to the given 6415 * subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 6416 * 6417 * <p>Requires Permission: 6418 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 6419 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6420 * 6421 * @param enable Whether to enable mobile data. 6422 * 6423 */ 6424 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 6425 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataEnabled(boolean enable)6426 public void setDataEnabled(boolean enable) { 6427 setDataEnabled(getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), enable); 6428 } 6429 6430 /** 6431 * @hide 6432 * @deprecated use {@link #setDataEnabled(boolean)} instead. 6433 */ 6434 @SystemApi 6435 @Deprecated 6436 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataEnabled(int subId, boolean enable)6437 public void setDataEnabled(int subId, boolean enable) { 6438 try { 6439 Log.d(TAG, "setDataEnabled: enabled=" + enable); 6440 ITelephony telephony = getITelephony(); 6441 if (telephony != null) 6442 telephony.setUserDataEnabled(subId, enable); 6443 } catch (RemoteException e) { 6444 Log.e(TAG, "Error calling ITelephony#setUserDataEnabled", e); 6445 } 6446 } 6447 6448 /** 6449 * @deprecated use {@link #isDataEnabled()} instead. 6450 * @hide 6451 */ 6452 @SystemApi 6453 @Deprecated getDataEnabled()6454 public boolean getDataEnabled() { 6455 return isDataEnabled(); 6456 } 6457 6458 /** 6459 * Returns whether mobile data is enabled or not per user setting. There are other factors 6460 * that could disable mobile data, but they are not considered here. 6461 * 6462 * If this object has been created with {@link #createForSubscriptionId}, applies to the given 6463 * subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 6464 * 6465 * <p>Requires one of the following permissions: 6466 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE ACCESS_NETWORK_STATE}, 6467 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}, or that the 6468 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 6469 * 6470 * <p>Note that this does not take into account any data restrictions that may be present on the 6471 * calling app. Such restrictions may be inspected with 6472 * {@link ConnectivityManager#getRestrictBackgroundStatus}. 6473 * 6474 * @return true if mobile data is enabled. 6475 */ isDataEnabled()6476 public boolean isDataEnabled() { 6477 return getDataEnabled(getSubId(SubscriptionManager.getDefaultDataSubscriptionId())); 6478 } 6479 6480 /** 6481 * @deprecated use {@link #isDataEnabled()} instead. 6482 * @hide 6483 */ 6484 @Deprecated 6485 @SystemApi getDataEnabled(int subId)6486 public boolean getDataEnabled(int subId) { 6487 boolean retVal = false; 6488 try { 6489 ITelephony telephony = getITelephony(); 6490 if (telephony != null) 6491 retVal = telephony.isUserDataEnabled(subId); 6492 } catch (RemoteException e) { 6493 Log.e(TAG, "Error calling ITelephony#isUserDataEnabled", e); 6494 } catch (NullPointerException e) { 6495 } 6496 return retVal; 6497 } 6498 6499 /** 6500 * Returns the result and response from RIL for oem request 6501 * 6502 * @param oemReq the data is sent to ril. 6503 * @param oemResp the respose data from RIL. 6504 * @return negative value request was not handled or get error 6505 * 0 request was handled succesfully, but no response data 6506 * positive value success, data length of response 6507 * @hide 6508 * @deprecated OEM needs a vendor-extension hal and their apps should use that instead 6509 */ 6510 @Deprecated invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp)6511 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 6512 try { 6513 ITelephony telephony = getITelephony(); 6514 if (telephony != null) 6515 return telephony.invokeOemRilRequestRaw(oemReq, oemResp); 6516 } catch (RemoteException ex) { 6517 } catch (NullPointerException ex) { 6518 } 6519 return -1; 6520 } 6521 6522 /** @hide */ 6523 @SystemApi 6524 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) enableVideoCalling(boolean enable)6525 public void enableVideoCalling(boolean enable) { 6526 try { 6527 ITelephony telephony = getITelephony(); 6528 if (telephony != null) 6529 telephony.enableVideoCalling(enable); 6530 } catch (RemoteException e) { 6531 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 6532 } 6533 } 6534 6535 /** @hide */ 6536 @SystemApi 6537 @RequiresPermission(anyOf = { 6538 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 6539 android.Manifest.permission.READ_PHONE_STATE 6540 }) isVideoCallingEnabled()6541 public boolean isVideoCallingEnabled() { 6542 try { 6543 ITelephony telephony = getITelephony(); 6544 if (telephony != null) 6545 return telephony.isVideoCallingEnabled(getOpPackageName()); 6546 } catch (RemoteException e) { 6547 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 6548 } 6549 return false; 6550 } 6551 6552 /** 6553 * Whether the device supports configuring the DTMF tone length. 6554 * 6555 * @return {@code true} if the DTMF tone length can be changed, and {@code false} otherwise. 6556 */ canChangeDtmfToneLength()6557 public boolean canChangeDtmfToneLength() { 6558 try { 6559 ITelephony telephony = getITelephony(); 6560 if (telephony != null) { 6561 return telephony.canChangeDtmfToneLength(); 6562 } 6563 } catch (RemoteException e) { 6564 Log.e(TAG, "Error calling ITelephony#canChangeDtmfToneLength", e); 6565 } catch (SecurityException e) { 6566 Log.e(TAG, "Permission error calling ITelephony#canChangeDtmfToneLength", e); 6567 } 6568 return false; 6569 } 6570 6571 /** 6572 * Whether the device is a world phone. 6573 * 6574 * @return {@code true} if the device is a world phone, and {@code false} otherwise. 6575 */ isWorldPhone()6576 public boolean isWorldPhone() { 6577 try { 6578 ITelephony telephony = getITelephony(); 6579 if (telephony != null) { 6580 return telephony.isWorldPhone(); 6581 } 6582 } catch (RemoteException e) { 6583 Log.e(TAG, "Error calling ITelephony#isWorldPhone", e); 6584 } catch (SecurityException e) { 6585 Log.e(TAG, "Permission error calling ITelephony#isWorldPhone", e); 6586 } 6587 return false; 6588 } 6589 6590 /** 6591 * @deprecated Use {@link TelecomManager#isTtySupported()} instead 6592 * Whether the phone supports TTY mode. 6593 * 6594 * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. 6595 * 6596 */ 6597 @Deprecated isTtyModeSupported()6598 public boolean isTtyModeSupported() { 6599 try { 6600 ITelephony telephony = getITelephony(); 6601 if (telephony != null) { 6602 return telephony.isTtyModeSupported(); 6603 } 6604 } catch (RemoteException e) { 6605 Log.e(TAG, "Error calling ITelephony#isTtyModeSupported", e); 6606 } catch (SecurityException e) { 6607 Log.e(TAG, "Permission error calling ITelephony#isTtyModeSupported", e); 6608 } 6609 return false; 6610 } 6611 6612 /** 6613 * Whether the phone supports hearing aid compatibility. 6614 * 6615 * @return {@code true} if the device supports hearing aid compatibility, and {@code false} 6616 * otherwise. 6617 */ isHearingAidCompatibilitySupported()6618 public boolean isHearingAidCompatibilitySupported() { 6619 try { 6620 ITelephony telephony = getITelephony(); 6621 if (telephony != null) { 6622 return telephony.isHearingAidCompatibilitySupported(); 6623 } 6624 } catch (RemoteException e) { 6625 Log.e(TAG, "Error calling ITelephony#isHearingAidCompatibilitySupported", e); 6626 } catch (SecurityException e) { 6627 Log.e(TAG, "Permission error calling ITelephony#isHearingAidCompatibilitySupported", e); 6628 } 6629 return false; 6630 } 6631 6632 /** 6633 * Returns the IMS Registration Status for a particular Subscription ID. 6634 * 6635 * @param subId Subscription ID 6636 * @return true if IMS status is registered, false if the IMS status is not registered or a 6637 * RemoteException occurred. 6638 * @hide 6639 */ isImsRegistered(int subId)6640 public boolean isImsRegistered(int subId) { 6641 try { 6642 return getITelephony().isImsRegistered(subId); 6643 } catch (RemoteException | NullPointerException ex) { 6644 return false; 6645 } 6646 } 6647 6648 /** 6649 * Returns the IMS Registration Status for a particular Subscription ID, which is determined 6650 * when the TelephonyManager is created using {@link #createForSubscriptionId(int)}. If an 6651 * invalid subscription ID is used during creation, will the default subscription ID will be 6652 * used. 6653 * 6654 * @return true if IMS status is registered, false if the IMS status is not registered or a 6655 * RemoteException occurred. 6656 * @see SubscriptionManager#getDefaultSubscriptionId() 6657 * @hide 6658 */ isImsRegistered()6659 public boolean isImsRegistered() { 6660 try { 6661 return getITelephony().isImsRegistered(getSubId()); 6662 } catch (RemoteException | NullPointerException ex) { 6663 return false; 6664 } 6665 } 6666 6667 /** 6668 * The current status of Voice over LTE for the subscription associated with this instance when 6669 * it was created using {@link #createForSubscriptionId(int)}. If an invalid subscription ID was 6670 * used during creation, the default subscription ID will be used. 6671 * @return true if Voice over LTE is available or false if it is unavailable or unknown. 6672 * @see SubscriptionManager#getDefaultSubscriptionId() 6673 * @hide 6674 */ isVolteAvailable()6675 public boolean isVolteAvailable() { 6676 try { 6677 return getITelephony().isVolteAvailable(getSubId()); 6678 } catch (RemoteException | NullPointerException ex) { 6679 return false; 6680 } 6681 } 6682 6683 /** 6684 * The availability of Video Telephony (VT) for the subscription ID specified when this instance 6685 * was created using {@link #createForSubscriptionId(int)}. If an invalid subscription ID was 6686 * used during creation, the default subscription ID will be used. To query the 6687 * underlying technology that VT is available on, use {@link #getImsRegTechnologyForMmTel}. 6688 * @return true if VT is available, or false if it is unavailable or unknown. 6689 * @hide 6690 */ isVideoTelephonyAvailable()6691 public boolean isVideoTelephonyAvailable() { 6692 try { 6693 return getITelephony().isVideoTelephonyAvailable(getSubId()); 6694 } catch (RemoteException | NullPointerException ex) { 6695 return false; 6696 } 6697 } 6698 6699 /** 6700 * Returns the Status of Wi-Fi calling (Voice over WiFi) for the subscription ID specified. 6701 * @param subId the subscription ID. 6702 * @return true if VoWiFi is available, or false if it is unavailable or unknown. 6703 * @hide 6704 */ isWifiCallingAvailable()6705 public boolean isWifiCallingAvailable() { 6706 try { 6707 return getITelephony().isWifiCallingAvailable(getSubId()); 6708 } catch (RemoteException | NullPointerException ex) { 6709 return false; 6710 } 6711 } 6712 6713 /** 6714 * The technology that IMS is registered for for the MMTEL feature. 6715 * @param subId subscription ID to get IMS registration technology for. 6716 * @return The IMS registration technology that IMS is registered to for the MMTEL feature. 6717 * Valid return results are: 6718 * - {@link ImsRegistrationImplBase#REGISTRATION_TECH_LTE} for LTE registration, 6719 * - {@link ImsRegistrationImplBase#REGISTRATION_TECH_IWLAN} for IWLAN registration, or 6720 * - {@link ImsRegistrationImplBase#REGISTRATION_TECH_NONE} if we are not registered or the 6721 * result is unavailable. 6722 * @hide 6723 */ getImsRegTechnologyForMmTel()6724 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel() { 6725 try { 6726 return getITelephony().getImsRegTechnologyForMmTel(getSubId()); 6727 } catch (RemoteException ex) { 6728 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; 6729 } 6730 } 6731 6732 /** 6733 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 6734 * 6735 * @hide 6736 */ setSimOperatorNumeric(String numeric)6737 public void setSimOperatorNumeric(String numeric) { 6738 int phoneId = getPhoneId(); 6739 setSimOperatorNumericForPhone(phoneId, numeric); 6740 } 6741 6742 /** 6743 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 6744 * 6745 * @hide 6746 */ setSimOperatorNumericForPhone(int phoneId, String numeric)6747 public void setSimOperatorNumericForPhone(int phoneId, String numeric) { 6748 setTelephonyProperty(phoneId, 6749 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, numeric); 6750 } 6751 6752 /** 6753 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 6754 * 6755 * @hide 6756 */ setSimOperatorName(String name)6757 public void setSimOperatorName(String name) { 6758 int phoneId = getPhoneId(); 6759 setSimOperatorNameForPhone(phoneId, name); 6760 } 6761 6762 /** 6763 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 6764 * 6765 * @hide 6766 */ setSimOperatorNameForPhone(int phoneId, String name)6767 public void setSimOperatorNameForPhone(int phoneId, String name) { 6768 setTelephonyProperty(phoneId, 6769 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, name); 6770 } 6771 6772 /** 6773 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the default phone. 6774 * 6775 * @hide 6776 */ setSimCountryIso(String iso)6777 public void setSimCountryIso(String iso) { 6778 int phoneId = getPhoneId(); 6779 setSimCountryIsoForPhone(phoneId, iso); 6780 } 6781 6782 /** 6783 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the given phone. 6784 * 6785 * @hide 6786 */ setSimCountryIsoForPhone(int phoneId, String iso)6787 public void setSimCountryIsoForPhone(int phoneId, String iso) { 6788 setTelephonyProperty(phoneId, 6789 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso); 6790 } 6791 6792 /** 6793 * Set TelephonyProperties.PROPERTY_SIM_STATE for the default phone. 6794 * 6795 * @hide 6796 */ setSimState(String state)6797 public void setSimState(String state) { 6798 int phoneId = getPhoneId(); 6799 setSimStateForPhone(phoneId, state); 6800 } 6801 6802 /** 6803 * Set TelephonyProperties.PROPERTY_SIM_STATE for the given phone. 6804 * 6805 * @hide 6806 */ setSimStateForPhone(int phoneId, String state)6807 public void setSimStateForPhone(int phoneId, String state) { 6808 setTelephonyProperty(phoneId, 6809 TelephonyProperties.PROPERTY_SIM_STATE, state); 6810 } 6811 6812 /** 6813 * Requested state of SIM 6814 * 6815 * CARD_POWER_DOWN 6816 * Powers down the SIM. SIM must be up prior. 6817 * 6818 * CARD_POWER_UP 6819 * Powers up the SIM normally. SIM must be down prior. 6820 * 6821 * CARD_POWER_UP_PASS_THROUGH 6822 * Powers up the SIM in PASS_THROUGH mode. SIM must be down prior. 6823 * When SIM is powered up in PASS_THOUGH mode, the modem does not send 6824 * any command to it (for example SELECT of MF, or TERMINAL CAPABILITY), 6825 * and the SIM card is controlled completely by Telephony sending APDUs 6826 * directly. The SIM card state will be RIL_CARDSTATE_PRESENT and the 6827 * number of card apps will be 0. 6828 * No new error code is generated. Emergency calls are supported in the 6829 * same way as if the SIM card is absent. 6830 * The PASS_THROUGH mode is valid only for the specific card session where it 6831 * is activated, and normal behavior occurs at the next SIM initialization, 6832 * unless PASS_THROUGH mode is requested again. Hence, the last power-up mode 6833 * is NOT persistent across boots. On reboot, SIM will power up normally. 6834 */ 6835 /** @hide */ 6836 public static final int CARD_POWER_DOWN = 0; 6837 /** @hide */ 6838 public static final int CARD_POWER_UP = 1; 6839 /** @hide */ 6840 public static final int CARD_POWER_UP_PASS_THROUGH = 2; 6841 6842 /** 6843 * Set SIM card power state. 6844 * 6845 * @param state State of SIM (power down, power up, pass through) 6846 * @see #CARD_POWER_DOWN 6847 * @see #CARD_POWER_UP 6848 * @see #CARD_POWER_UP_PASS_THROUGH 6849 * Callers should monitor for {@link TelephonyIntents#ACTION_SIM_STATE_CHANGED} 6850 * broadcasts to determine success or failure and timeout if needed. 6851 * 6852 * <p>Requires Permission: 6853 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 6854 * 6855 * {@hide} 6856 **/ 6857 @SystemApi 6858 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setSimPowerState(int state)6859 public void setSimPowerState(int state) { 6860 setSimPowerStateForSlot(getSlotIndex(), state); 6861 } 6862 6863 /** 6864 * Set SIM card power state. 6865 * 6866 * @param slotIndex SIM slot id 6867 * @param state State of SIM (power down, power up, pass through) 6868 * @see #CARD_POWER_DOWN 6869 * @see #CARD_POWER_UP 6870 * @see #CARD_POWER_UP_PASS_THROUGH 6871 * Callers should monitor for {@link TelephonyIntents#ACTION_SIM_STATE_CHANGED} 6872 * broadcasts to determine success or failure and timeout if needed. 6873 * 6874 * <p>Requires Permission: 6875 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 6876 * 6877 * {@hide} 6878 **/ 6879 @SystemApi 6880 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setSimPowerStateForSlot(int slotIndex, int state)6881 public void setSimPowerStateForSlot(int slotIndex, int state) { 6882 try { 6883 ITelephony telephony = getITelephony(); 6884 if (telephony != null) { 6885 telephony.setSimPowerStateForSlot(slotIndex, state); 6886 } 6887 } catch (RemoteException e) { 6888 Log.e(TAG, "Error calling ITelephony#setSimPowerStateForSlot", e); 6889 } catch (SecurityException e) { 6890 Log.e(TAG, "Permission error calling ITelephony#setSimPowerStateForSlot", e); 6891 } 6892 } 6893 6894 /** 6895 * Set baseband version for the default phone. 6896 * 6897 * @param version baseband version 6898 * @hide 6899 */ setBasebandVersion(String version)6900 public void setBasebandVersion(String version) { 6901 int phoneId = getPhoneId(); 6902 setBasebandVersionForPhone(phoneId, version); 6903 } 6904 6905 /** 6906 * Set baseband version by phone id. 6907 * 6908 * @param phoneId for which baseband version is set 6909 * @param version baseband version 6910 * @hide 6911 */ setBasebandVersionForPhone(int phoneId, String version)6912 public void setBasebandVersionForPhone(int phoneId, String version) { 6913 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_BASEBAND_VERSION, version); 6914 } 6915 6916 /** 6917 * Get baseband version for the default phone. 6918 * 6919 * @return baseband version. 6920 * @hide 6921 */ getBasebandVersion()6922 public String getBasebandVersion() { 6923 int phoneId = getPhoneId(); 6924 return getBasebandVersionForPhone(phoneId); 6925 } 6926 6927 /** 6928 * Get baseband version for the default phone using the legacy approach. 6929 * This change was added in P, to ensure backward compatiblity. 6930 * 6931 * @return baseband version. 6932 * @hide 6933 */ getBasebandVersionLegacy(int phoneId)6934 private String getBasebandVersionLegacy(int phoneId) { 6935 if (SubscriptionManager.isValidPhoneId(phoneId)) { 6936 String prop = TelephonyProperties.PROPERTY_BASEBAND_VERSION + 6937 ((phoneId == 0) ? "" : Integer.toString(phoneId)); 6938 return SystemProperties.get(prop); 6939 } 6940 return null; 6941 } 6942 6943 /** 6944 * Get baseband version by phone id. 6945 * 6946 * @return baseband version. 6947 * @hide 6948 */ getBasebandVersionForPhone(int phoneId)6949 public String getBasebandVersionForPhone(int phoneId) { 6950 String version = getBasebandVersionLegacy(phoneId); 6951 if (version != null && !version.isEmpty()) { 6952 setBasebandVersionForPhone(phoneId, version); 6953 } 6954 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_BASEBAND_VERSION, ""); 6955 } 6956 6957 /** 6958 * Set phone type for the default phone. 6959 * 6960 * @param type phone type 6961 * 6962 * @hide 6963 */ setPhoneType(int type)6964 public void setPhoneType(int type) { 6965 int phoneId = getPhoneId(); 6966 setPhoneType(phoneId, type); 6967 } 6968 6969 /** 6970 * Set phone type by phone id. 6971 * 6972 * @param phoneId for which phone type is set 6973 * @param type phone type 6974 * 6975 * @hide 6976 */ setPhoneType(int phoneId, int type)6977 public void setPhoneType(int phoneId, int type) { 6978 if (SubscriptionManager.isValidPhoneId(phoneId)) { 6979 TelephonyManager.setTelephonyProperty(phoneId, 6980 TelephonyProperties.CURRENT_ACTIVE_PHONE, String.valueOf(type)); 6981 } 6982 } 6983 6984 /** 6985 * Get OTASP number schema for the default phone. 6986 * 6987 * @param defaultValue default value 6988 * @return OTA SP number schema 6989 * 6990 * @hide 6991 */ getOtaSpNumberSchema(String defaultValue)6992 public String getOtaSpNumberSchema(String defaultValue) { 6993 int phoneId = getPhoneId(); 6994 return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); 6995 } 6996 6997 /** 6998 * Get OTASP number schema by phone id. 6999 * 7000 * @param phoneId for which OTA SP number schema is get 7001 * @param defaultValue default value 7002 * @return OTA SP number schema 7003 * 7004 * @hide 7005 */ getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue)7006 public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) { 7007 if (SubscriptionManager.isValidPhoneId(phoneId)) { 7008 return TelephonyManager.getTelephonyProperty(phoneId, 7009 TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA, defaultValue); 7010 } 7011 7012 return defaultValue; 7013 } 7014 7015 /** 7016 * Get SMS receive capable from system property for the default phone. 7017 * 7018 * @param defaultValue default value 7019 * @return SMS receive capable 7020 * 7021 * @hide 7022 */ getSmsReceiveCapable(boolean defaultValue)7023 public boolean getSmsReceiveCapable(boolean defaultValue) { 7024 int phoneId = getPhoneId(); 7025 return getSmsReceiveCapableForPhone(phoneId, defaultValue); 7026 } 7027 7028 /** 7029 * Get SMS receive capable from system property by phone id. 7030 * 7031 * @param phoneId for which SMS receive capable is get 7032 * @param defaultValue default value 7033 * @return SMS receive capable 7034 * 7035 * @hide 7036 */ getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue)7037 public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) { 7038 if (SubscriptionManager.isValidPhoneId(phoneId)) { 7039 return Boolean.parseBoolean(TelephonyManager.getTelephonyProperty(phoneId, 7040 TelephonyProperties.PROPERTY_SMS_RECEIVE, String.valueOf(defaultValue))); 7041 } 7042 7043 return defaultValue; 7044 } 7045 7046 /** 7047 * Get SMS send capable from system property for the default phone. 7048 * 7049 * @param defaultValue default value 7050 * @return SMS send capable 7051 * 7052 * @hide 7053 */ getSmsSendCapable(boolean defaultValue)7054 public boolean getSmsSendCapable(boolean defaultValue) { 7055 int phoneId = getPhoneId(); 7056 return getSmsSendCapableForPhone(phoneId, defaultValue); 7057 } 7058 7059 /** 7060 * Get SMS send capable from system property by phone id. 7061 * 7062 * @param phoneId for which SMS send capable is get 7063 * @param defaultValue default value 7064 * @return SMS send capable 7065 * 7066 * @hide 7067 */ getSmsSendCapableForPhone(int phoneId, boolean defaultValue)7068 public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) { 7069 if (SubscriptionManager.isValidPhoneId(phoneId)) { 7070 return Boolean.parseBoolean(TelephonyManager.getTelephonyProperty(phoneId, 7071 TelephonyProperties.PROPERTY_SMS_SEND, String.valueOf(defaultValue))); 7072 } 7073 7074 return defaultValue; 7075 } 7076 7077 /** 7078 * Set the alphabetic name of current registered operator. 7079 * @param name the alphabetic name of current registered operator. 7080 * @hide 7081 */ setNetworkOperatorName(String name)7082 public void setNetworkOperatorName(String name) { 7083 int phoneId = getPhoneId(); 7084 setNetworkOperatorNameForPhone(phoneId, name); 7085 } 7086 7087 /** 7088 * Set the alphabetic name of current registered operator. 7089 * @param phoneId which phone you want to set 7090 * @param name the alphabetic name of current registered operator. 7091 * @hide 7092 */ setNetworkOperatorNameForPhone(int phoneId, String name)7093 public void setNetworkOperatorNameForPhone(int phoneId, String name) { 7094 if (SubscriptionManager.isValidPhoneId(phoneId)) { 7095 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, name); 7096 } 7097 } 7098 7099 /** 7100 * Set the numeric name (MCC+MNC) of current registered operator. 7101 * @param operator the numeric name (MCC+MNC) of current registered operator 7102 * @hide 7103 */ setNetworkOperatorNumeric(String numeric)7104 public void setNetworkOperatorNumeric(String numeric) { 7105 int phoneId = getPhoneId(); 7106 setNetworkOperatorNumericForPhone(phoneId, numeric); 7107 } 7108 7109 /** 7110 * Set the numeric name (MCC+MNC) of current registered operator. 7111 * @param phoneId for which phone type is set 7112 * @param operator the numeric name (MCC+MNC) of current registered operator 7113 * @hide 7114 */ setNetworkOperatorNumericForPhone(int phoneId, String numeric)7115 public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) { 7116 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, numeric); 7117 } 7118 7119 /** 7120 * Set roaming state of the current network, for GSM purposes. 7121 * @param isRoaming is network in romaing state or not 7122 * @hide 7123 */ setNetworkRoaming(boolean isRoaming)7124 public void setNetworkRoaming(boolean isRoaming) { 7125 int phoneId = getPhoneId(); 7126 setNetworkRoamingForPhone(phoneId, isRoaming); 7127 } 7128 7129 /** 7130 * Set roaming state of the current network, for GSM purposes. 7131 * @param phoneId which phone you want to set 7132 * @param isRoaming is network in romaing state or not 7133 * @hide 7134 */ setNetworkRoamingForPhone(int phoneId, boolean isRoaming)7135 public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) { 7136 if (SubscriptionManager.isValidPhoneId(phoneId)) { 7137 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, 7138 isRoaming ? "true" : "false"); 7139 } 7140 } 7141 7142 /** 7143 * Set the ISO country code equivalent of the current registered 7144 * operator's MCC (Mobile Country Code). 7145 * @param iso the ISO country code equivalent of the current registered 7146 * @hide 7147 */ setNetworkCountryIso(String iso)7148 public void setNetworkCountryIso(String iso) { 7149 int phoneId = getPhoneId(); 7150 setNetworkCountryIsoForPhone(phoneId, iso); 7151 } 7152 7153 /** 7154 * Set the ISO country code equivalent of the current registered 7155 * operator's MCC (Mobile Country Code). 7156 * @param phoneId which phone you want to set 7157 * @param iso the ISO country code equivalent of the current registered 7158 * @hide 7159 */ setNetworkCountryIsoForPhone(int phoneId, String iso)7160 public void setNetworkCountryIsoForPhone(int phoneId, String iso) { 7161 if (SubscriptionManager.isValidPhoneId(phoneId)) { 7162 setTelephonyProperty(phoneId, 7163 TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso); 7164 } 7165 } 7166 7167 /** 7168 * Set the network type currently in use on the device for data transmission. 7169 * 7170 * If this object has been created with {@link #createForSubscriptionId}, applies to the 7171 * phoneId associated with the given subId. Otherwise, applies to the phoneId associated with 7172 * {@link SubscriptionManager#getDefaultDataSubscriptionId()} 7173 * @param type the network type currently in use on the device for data transmission 7174 * @hide 7175 */ setDataNetworkType(int type)7176 public void setDataNetworkType(int type) { 7177 int phoneId = getPhoneId(SubscriptionManager.getDefaultDataSubscriptionId()); 7178 setDataNetworkTypeForPhone(phoneId, type); 7179 } 7180 7181 /** 7182 * Set the network type currently in use on the device for data transmission. 7183 * @param phoneId which phone you want to set 7184 * @param type the network type currently in use on the device for data transmission 7185 * @hide 7186 */ setDataNetworkTypeForPhone(int phoneId, int type)7187 public void setDataNetworkTypeForPhone(int phoneId, int type) { 7188 if (SubscriptionManager.isValidPhoneId(phoneId)) { 7189 setTelephonyProperty(phoneId, 7190 TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, 7191 ServiceState.rilRadioTechnologyToString(type)); 7192 } 7193 } 7194 7195 /** 7196 * Returns the subscription ID for the given phone account. 7197 * @hide 7198 */ getSubIdForPhoneAccount(PhoneAccount phoneAccount)7199 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { 7200 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 7201 try { 7202 ITelephony service = getITelephony(); 7203 if (service != null) { 7204 retval = service.getSubIdForPhoneAccount(phoneAccount); 7205 } 7206 } catch (RemoteException e) { 7207 } 7208 7209 return retval; 7210 } 7211 getSubIdForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle)7212 private int getSubIdForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) { 7213 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 7214 try { 7215 ITelecomService service = getTelecomService(); 7216 if (service != null) { 7217 retval = getSubIdForPhoneAccount(service.getPhoneAccount(phoneAccountHandle)); 7218 } 7219 } catch (RemoteException e) { 7220 } 7221 7222 return retval; 7223 } 7224 7225 /** 7226 * Resets telephony manager settings back to factory defaults. 7227 * 7228 * @hide 7229 */ factoryReset(int subId)7230 public void factoryReset(int subId) { 7231 try { 7232 Log.d(TAG, "factoryReset: subId=" + subId); 7233 ITelephony telephony = getITelephony(); 7234 if (telephony != null) 7235 telephony.factoryReset(subId); 7236 } catch (RemoteException e) { 7237 } 7238 } 7239 7240 7241 /** @hide */ getLocaleFromDefaultSim()7242 public String getLocaleFromDefaultSim() { 7243 try { 7244 final ITelephony telephony = getITelephony(); 7245 if (telephony != null) { 7246 return telephony.getLocaleFromDefaultSim(); 7247 } 7248 } catch (RemoteException ex) { 7249 } 7250 return null; 7251 } 7252 7253 /** 7254 * Requests the modem activity info. The recipient will place the result 7255 * in `result`. 7256 * @param result The object on which the recipient will send the resulting 7257 * {@link android.telephony.ModemActivityInfo} object. 7258 * @hide 7259 */ requestModemActivityInfo(ResultReceiver result)7260 public void requestModemActivityInfo(ResultReceiver result) { 7261 try { 7262 ITelephony service = getITelephony(); 7263 if (service != null) { 7264 service.requestModemActivityInfo(result); 7265 return; 7266 } 7267 } catch (RemoteException e) { 7268 Log.e(TAG, "Error calling ITelephony#getModemActivityInfo", e); 7269 } 7270 result.send(0, null); 7271 } 7272 7273 /** 7274 * Returns the current {@link ServiceState} information. 7275 * 7276 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 7277 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 7278 */ 7279 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 7280 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getServiceState()7281 public ServiceState getServiceState() { 7282 return getServiceStateForSubscriber(getSubId()); 7283 } 7284 7285 /** 7286 * Returns the service state information on specified subscription. Callers require 7287 * either READ_PRIVILEGED_PHONE_STATE or READ_PHONE_STATE to retrieve the information. 7288 * @hide 7289 */ getServiceStateForSubscriber(int subId)7290 public ServiceState getServiceStateForSubscriber(int subId) { 7291 try { 7292 ITelephony service = getITelephony(); 7293 if (service != null) { 7294 return service.getServiceStateForSubscriber(subId, getOpPackageName()); 7295 } 7296 } catch (RemoteException e) { 7297 Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e); 7298 } 7299 return null; 7300 } 7301 7302 /** 7303 * Returns the URI for the per-account voicemail ringtone set in Phone settings. 7304 * 7305 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the 7306 * voicemail ringtone. 7307 * @return The URI for the ringtone to play when receiving a voicemail from a specific 7308 * PhoneAccount. 7309 */ getVoicemailRingtoneUri(PhoneAccountHandle accountHandle)7310 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { 7311 try { 7312 ITelephony service = getITelephony(); 7313 if (service != null) { 7314 return service.getVoicemailRingtoneUri(accountHandle); 7315 } 7316 } catch (RemoteException e) { 7317 Log.e(TAG, "Error calling ITelephony#getVoicemailRingtoneUri", e); 7318 } 7319 return null; 7320 } 7321 7322 /** 7323 * Sets the per-account voicemail ringtone. 7324 * 7325 * <p>Requires that the calling app is the default dialer, or has carrier privileges (see 7326 * {@link #hasCarrierPrivileges}, or has permission 7327 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 7328 * 7329 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the 7330 * voicemail ringtone. 7331 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific 7332 * PhoneAccount. 7333 * 7334 * @deprecated Use {@link android.provider.Settings#ACTION_CHANNEL_NOTIFICATION_SETTINGS} 7335 * instead. 7336 */ setVoicemailRingtoneUri(PhoneAccountHandle phoneAccountHandle, Uri uri)7337 public void setVoicemailRingtoneUri(PhoneAccountHandle phoneAccountHandle, Uri uri) { 7338 try { 7339 ITelephony service = getITelephony(); 7340 if (service != null) { 7341 service.setVoicemailRingtoneUri(getOpPackageName(), phoneAccountHandle, uri); 7342 } 7343 } catch (RemoteException e) { 7344 Log.e(TAG, "Error calling ITelephony#setVoicemailRingtoneUri", e); 7345 } 7346 } 7347 7348 /** 7349 * Returns whether vibration is set for voicemail notification in Phone settings. 7350 * 7351 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the 7352 * voicemail vibration setting. 7353 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. 7354 */ isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle)7355 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { 7356 try { 7357 ITelephony service = getITelephony(); 7358 if (service != null) { 7359 return service.isVoicemailVibrationEnabled(accountHandle); 7360 } 7361 } catch (RemoteException e) { 7362 Log.e(TAG, "Error calling ITelephony#isVoicemailVibrationEnabled", e); 7363 } 7364 return false; 7365 } 7366 7367 /** 7368 * Sets the per-account preference whether vibration is enabled for voicemail notifications. 7369 * 7370 * <p>Requires that the calling app is the default dialer, or has carrier privileges (see 7371 * {@link #hasCarrierPrivileges}, or has permission 7372 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 7373 * 7374 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the 7375 * voicemail vibration setting. 7376 * @param enabled Whether to enable or disable vibration for voicemail notifications from a 7377 * specific PhoneAccount. 7378 * 7379 * @deprecated Use {@link android.provider.Settings#ACTION_CHANNEL_NOTIFICATION_SETTINGS} 7380 * instead. 7381 */ setVoicemailVibrationEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled)7382 public void setVoicemailVibrationEnabled(PhoneAccountHandle phoneAccountHandle, 7383 boolean enabled) { 7384 try { 7385 ITelephony service = getITelephony(); 7386 if (service != null) { 7387 service.setVoicemailVibrationEnabled(getOpPackageName(), phoneAccountHandle, 7388 enabled); 7389 } 7390 } catch (RemoteException e) { 7391 Log.e(TAG, "Error calling ITelephony#isVoicemailVibrationEnabled", e); 7392 } 7393 } 7394 7395 /** 7396 * Returns carrier id of the current subscription. 7397 * <p>To recognize a carrier (including MVNO) as a first-class identity, Android assigns each 7398 * carrier with a canonical integer a.k.a. carrier id. The carrier ID is an Android 7399 * platform-wide identifier for a carrier. AOSP maintains carrier ID assignments in 7400 * <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/carrier_list.textpb">here</a> 7401 * 7402 * <p>Apps which have carrier-specific configurations or business logic can use the carrier id 7403 * as an Android platform-wide identifier for carriers. 7404 * 7405 * @return Carrier id of the current subscription. Return {@link #UNKNOWN_CARRIER_ID} if the 7406 * subscription is unavailable or the carrier cannot be identified. 7407 */ getSimCarrierId()7408 public int getSimCarrierId() { 7409 try { 7410 ITelephony service = getITelephony(); 7411 if (service != null) { 7412 return service.getSubscriptionCarrierId(getSubId()); 7413 } 7414 } catch (RemoteException ex) { 7415 // This could happen if binder process crashes. 7416 } 7417 return UNKNOWN_CARRIER_ID; 7418 } 7419 7420 /** 7421 * Returns carrier id name of the current subscription. 7422 * <p>Carrier id name is a user-facing name of carrier id 7423 * {@link #getSimCarrierId()}, usually the brand name of the subsidiary 7424 * (e.g. T-Mobile). Each carrier could configure multiple {@link #getSimOperatorName() SPN} but 7425 * should have a single carrier name. Carrier name is not a canonical identity, 7426 * use {@link #getSimCarrierId()} instead. 7427 * <p>The returned carrier name is unlocalized. 7428 * 7429 * @return Carrier name of the current subscription. Return {@code null} if the subscription is 7430 * unavailable or the carrier cannot be identified. 7431 */ getSimCarrierIdName()7432 public CharSequence getSimCarrierIdName() { 7433 try { 7434 ITelephony service = getITelephony(); 7435 if (service != null) { 7436 return service.getSubscriptionCarrierName(getSubId()); 7437 } 7438 } catch (RemoteException ex) { 7439 // This could happen if binder process crashes. 7440 } 7441 return null; 7442 } 7443 7444 /** 7445 * Return the application ID for the app type like {@link APPTYPE_CSIM}. 7446 * 7447 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 7448 * 7449 * @param appType the uicc app type like {@link APPTYPE_CSIM} 7450 * @return Application ID for specificied app type or null if no uicc or error. 7451 * @hide 7452 */ getAidForAppType(int appType)7453 public String getAidForAppType(int appType) { 7454 return getAidForAppType(getSubId(), appType); 7455 } 7456 7457 /** 7458 * Return the application ID for the app type like {@link APPTYPE_CSIM}. 7459 * 7460 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 7461 * 7462 * @param subId the subscription ID that this request applies to. 7463 * @param appType the uicc app type, like {@link APPTYPE_CSIM} 7464 * @return Application ID for specificied app type or null if no uicc or error. 7465 * @hide 7466 */ getAidForAppType(int subId, int appType)7467 public String getAidForAppType(int subId, int appType) { 7468 try { 7469 ITelephony service = getITelephony(); 7470 if (service != null) { 7471 return service.getAidForAppType(subId, appType); 7472 } 7473 } catch (RemoteException e) { 7474 Log.e(TAG, "Error calling ITelephony#getAidForAppType", e); 7475 } 7476 return null; 7477 } 7478 7479 /** 7480 * Return the Electronic Serial Number. 7481 * 7482 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 7483 * 7484 * @return ESN or null if error. 7485 * @hide 7486 */ getEsn()7487 public String getEsn() { 7488 return getEsn(getSubId()); 7489 } 7490 7491 /** 7492 * Return the Electronic Serial Number. 7493 * 7494 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 7495 * 7496 * @param subId the subscription ID that this request applies to. 7497 * @return ESN or null if error. 7498 * @hide 7499 */ getEsn(int subId)7500 public String getEsn(int subId) { 7501 try { 7502 ITelephony service = getITelephony(); 7503 if (service != null) { 7504 return service.getEsn(subId); 7505 } 7506 } catch (RemoteException e) { 7507 Log.e(TAG, "Error calling ITelephony#getEsn", e); 7508 } 7509 return null; 7510 } 7511 7512 /** 7513 * Return the Preferred Roaming List Version 7514 * 7515 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 7516 * 7517 * @return PRLVersion or null if error. 7518 * @hide 7519 */ 7520 @SystemApi getCdmaPrlVersion()7521 public String getCdmaPrlVersion() { 7522 return getCdmaPrlVersion(getSubId()); 7523 } 7524 7525 /** 7526 * Return the Preferred Roaming List Version 7527 * 7528 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 7529 * 7530 * @param subId the subscription ID that this request applies to. 7531 * @return PRLVersion or null if error. 7532 * @hide 7533 */ getCdmaPrlVersion(int subId)7534 public String getCdmaPrlVersion(int subId) { 7535 try { 7536 ITelephony service = getITelephony(); 7537 if (service != null) { 7538 return service.getCdmaPrlVersion(subId); 7539 } 7540 } catch (RemoteException e) { 7541 Log.e(TAG, "Error calling ITelephony#getCdmaPrlVersion", e); 7542 } 7543 return null; 7544 } 7545 7546 /** 7547 * Get snapshot of Telephony histograms 7548 * @return List of Telephony histograms 7549 * Requires Permission: 7550 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 7551 * Or the calling app has carrier privileges. 7552 * @hide 7553 */ 7554 @SystemApi 7555 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getTelephonyHistograms()7556 public List<TelephonyHistogram> getTelephonyHistograms() { 7557 try { 7558 ITelephony service = getITelephony(); 7559 if (service != null) { 7560 return service.getTelephonyHistograms(); 7561 } 7562 } catch (RemoteException e) { 7563 Log.e(TAG, "Error calling ITelephony#getTelephonyHistograms", e); 7564 } 7565 return null; 7566 } 7567 7568 /** 7569 * Set the allowed carrier list for slotIndex 7570 * Require system privileges. In the future we may add this to carrier APIs. 7571 * 7572 * <p>Requires Permission: 7573 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} 7574 * 7575 * <p>This method works only on devices with {@link 7576 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 7577 * 7578 * @return The number of carriers set successfully. Should be length of 7579 * carrierList on success; -1 if carrierList null or on error. 7580 * @hide 7581 */ 7582 @SystemApi 7583 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers)7584 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) { 7585 try { 7586 ITelephony service = getITelephony(); 7587 if (service != null) { 7588 return service.setAllowedCarriers(slotIndex, carriers); 7589 } 7590 } catch (RemoteException e) { 7591 Log.e(TAG, "Error calling ITelephony#setAllowedCarriers", e); 7592 } catch (NullPointerException e) { 7593 Log.e(TAG, "Error calling ITelephony#setAllowedCarriers", e); 7594 } 7595 return -1; 7596 } 7597 7598 /** 7599 * Get the allowed carrier list for slotIndex. 7600 * Require system privileges. In the future we may add this to carrier APIs. 7601 * 7602 * <p>This method returns valid data on devices with {@link 7603 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 7604 * 7605 * @return List of {@link android.telephony.CarrierIdentifier}; empty list 7606 * means all carriers are allowed. 7607 * @hide 7608 */ 7609 @SystemApi 7610 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getAllowedCarriers(int slotIndex)7611 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) { 7612 try { 7613 ITelephony service = getITelephony(); 7614 if (service != null) { 7615 return service.getAllowedCarriers(slotIndex); 7616 } 7617 } catch (RemoteException e) { 7618 Log.e(TAG, "Error calling ITelephony#getAllowedCarriers", e); 7619 } catch (NullPointerException e) { 7620 Log.e(TAG, "Error calling ITelephony#getAllowedCarriers", e); 7621 } 7622 return new ArrayList<CarrierIdentifier>(0); 7623 } 7624 7625 /** 7626 * Action set from carrier signalling broadcast receivers to enable/disable metered apns 7627 * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required 7628 * @param subId the subscription ID that this action applies to. 7629 * @param enabled control enable or disable metered apns. 7630 * @hide 7631 */ carrierActionSetMeteredApnsEnabled(int subId, boolean enabled)7632 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { 7633 try { 7634 ITelephony service = getITelephony(); 7635 if (service != null) { 7636 service.carrierActionSetMeteredApnsEnabled(subId, enabled); 7637 } 7638 } catch (RemoteException e) { 7639 Log.e(TAG, "Error calling ITelephony#carrierActionSetMeteredApnsEnabled", e); 7640 } 7641 } 7642 7643 /** 7644 * Action set from carrier signalling broadcast receivers to enable/disable radio 7645 * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required 7646 * @param subId the subscription ID that this action applies to. 7647 * @param enabled control enable or disable radio. 7648 * @hide 7649 */ carrierActionSetRadioEnabled(int subId, boolean enabled)7650 public void carrierActionSetRadioEnabled(int subId, boolean enabled) { 7651 try { 7652 ITelephony service = getITelephony(); 7653 if (service != null) { 7654 service.carrierActionSetRadioEnabled(subId, enabled); 7655 } 7656 } catch (RemoteException e) { 7657 Log.e(TAG, "Error calling ITelephony#carrierActionSetRadioEnabled", e); 7658 } 7659 } 7660 7661 /** 7662 * Action set from carrier signalling broadcast receivers to start/stop reporting default 7663 * network available events 7664 * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required 7665 * @param subId the subscription ID that this action applies to. 7666 * @param report control start/stop reporting network status. 7667 * @hide 7668 */ carrierActionReportDefaultNetworkStatus(int subId, boolean report)7669 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { 7670 try { 7671 ITelephony service = getITelephony(); 7672 if (service != null) { 7673 service.carrierActionReportDefaultNetworkStatus(subId, report); 7674 } 7675 } catch (RemoteException e) { 7676 Log.e(TAG, "Error calling ITelephony#carrierActionReportDefaultNetworkStatus", e); 7677 } 7678 } 7679 7680 /** 7681 * Get aggregated video call data usage since boot. 7682 * Permissions android.Manifest.permission.READ_NETWORK_USAGE_HISTORY is required. 7683 * 7684 * @param how one of the NetworkStats.STATS_PER_* constants depending on whether the request is 7685 * for data usage per uid or overall usage. 7686 * @return Snapshot of video call data usage 7687 * @hide 7688 */ getVtDataUsage(int how)7689 public NetworkStats getVtDataUsage(int how) { 7690 boolean perUidStats = (how == NetworkStats.STATS_PER_UID); 7691 try { 7692 ITelephony service = getITelephony(); 7693 if (service != null) { 7694 return service.getVtDataUsage(getSubId(), perUidStats); 7695 } 7696 } catch (RemoteException e) { 7697 Log.e(TAG, "Error calling ITelephony#getVtDataUsage", e); 7698 } 7699 return null; 7700 } 7701 7702 /** 7703 * Policy control of data connection. Usually used when data limit is passed. 7704 * @param enabled True if enabling the data, otherwise disabling. 7705 * @param subId sub id 7706 * @hide 7707 */ setPolicyDataEnabled(boolean enabled, int subId)7708 public void setPolicyDataEnabled(boolean enabled, int subId) { 7709 try { 7710 ITelephony service = getITelephony(); 7711 if (service != null) { 7712 service.setPolicyDataEnabled(enabled, subId); 7713 } 7714 } catch (RemoteException e) { 7715 Log.e(TAG, "Error calling ITelephony#setPolicyDataEnabled", e); 7716 } 7717 } 7718 7719 /** 7720 * Get Client request stats which will contain statistical information 7721 * on each request made by client. 7722 * Callers require either READ_PRIVILEGED_PHONE_STATE or 7723 * READ_PHONE_STATE to retrieve the information. 7724 * @param subId sub id 7725 * @return List of Client Request Stats 7726 * @hide 7727 */ getClientRequestStats(int subId)7728 public List<ClientRequestStats> getClientRequestStats(int subId) { 7729 try { 7730 ITelephony service = getITelephony(); 7731 if (service != null) { 7732 return service.getClientRequestStats(getOpPackageName(), subId); 7733 } 7734 } catch (RemoteException e) { 7735 Log.e(TAG, "Error calling ITelephony#getClientRequestStats", e); 7736 } 7737 7738 return null; 7739 } 7740 7741 /** 7742 * Check if phone is in emergency callback mode 7743 * @return true if phone is in emergency callback mode 7744 * @hide 7745 */ 7746 @SystemApi 7747 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getEmergencyCallbackMode()7748 public boolean getEmergencyCallbackMode() { 7749 return getEmergencyCallbackMode(getSubId()); 7750 } 7751 7752 /** 7753 * Check if phone is in emergency callback mode 7754 * @return true if phone is in emergency callback mode 7755 * @param subId the subscription ID that this action applies to. 7756 * @hide 7757 */ getEmergencyCallbackMode(int subId)7758 public boolean getEmergencyCallbackMode(int subId) { 7759 try { 7760 ITelephony telephony = getITelephony(); 7761 if (telephony == null) { 7762 return false; 7763 } 7764 return telephony.getEmergencyCallbackMode(subId); 7765 } catch (RemoteException e) { 7766 Log.e(TAG, "Error calling ITelephony#getEmergencyCallbackMode", e); 7767 } 7768 return false; 7769 } 7770 7771 /** 7772 * Get the most recently available signal strength information. 7773 * 7774 * Get the most recent SignalStrength information reported by the modem. Due 7775 * to power saving this information may not always be current. 7776 * @return the most recent cached signal strength info from the modem 7777 */ 7778 @Nullable getSignalStrength()7779 public SignalStrength getSignalStrength() { 7780 try { 7781 ITelephony service = getITelephony(); 7782 if (service != null) { 7783 return service.getSignalStrength(getSubId()); 7784 } 7785 } catch (RemoteException e) { 7786 Log.e(TAG, "Error calling ITelephony#getSignalStrength", e); 7787 } 7788 return null; 7789 } 7790 7791 /** 7792 * @hide 7793 * It's similar to isDataEnabled, but unlike isDataEnabled, this API also evaluates 7794 * carrierDataEnabled, policyDataEnabled etc to give a final decision of whether mobile data is 7795 * capable of using. 7796 */ isDataCapable()7797 public boolean isDataCapable() { 7798 boolean retVal = false; 7799 try { 7800 int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId()); 7801 ITelephony telephony = getITelephony(); 7802 if (telephony != null) 7803 retVal = telephony.isDataEnabled(subId); 7804 } catch (RemoteException e) { 7805 Log.e(TAG, "Error calling ITelephony#isDataEnabled", e); 7806 } catch (NullPointerException e) { 7807 } 7808 return retVal; 7809 } 7810 7811 /** 7812 * In this mode, modem will not send specified indications when screen is off. 7813 * @hide 7814 */ 7815 public static final int INDICATION_UPDATE_MODE_NORMAL = 1; 7816 7817 /** 7818 * In this mode, modem will still send specified indications when screen is off. 7819 * @hide 7820 */ 7821 public static final int INDICATION_UPDATE_MODE_IGNORE_SCREEN_OFF = 2; 7822 7823 /** @hide */ 7824 @IntDef(prefix = { "INDICATION_UPDATE_MODE_" }, value = { 7825 INDICATION_UPDATE_MODE_NORMAL, 7826 INDICATION_UPDATE_MODE_IGNORE_SCREEN_OFF 7827 }) 7828 @Retention(RetentionPolicy.SOURCE) 7829 public @interface IndicationUpdateMode{} 7830 7831 /** 7832 * The indication for signal strength update. 7833 * @hide 7834 */ 7835 public static final int INDICATION_FILTER_SIGNAL_STRENGTH = 0x1; 7836 7837 /** 7838 * The indication for full network state update. 7839 * @hide 7840 */ 7841 public static final int INDICATION_FILTER_FULL_NETWORK_STATE = 0x2; 7842 7843 /** 7844 * The indication for data call dormancy changed update. 7845 * @hide 7846 */ 7847 public static final int INDICATION_FILTER_DATA_CALL_DORMANCY_CHANGED = 0x4; 7848 7849 /** 7850 * The indication for link capacity estimate update. 7851 * @hide 7852 */ 7853 public static final int INDICATION_FILTER_LINK_CAPACITY_ESTIMATE = 0x8; 7854 7855 /** 7856 * The indication for physical channel config update. 7857 * @hide 7858 */ 7859 public static final int INDICATION_FILTER_PHYSICAL_CHANNEL_CONFIG = 0x10; 7860 7861 /** @hide */ 7862 @IntDef(flag = true, prefix = { "INDICATION_FILTER_" }, value = { 7863 INDICATION_FILTER_SIGNAL_STRENGTH, 7864 INDICATION_FILTER_FULL_NETWORK_STATE, 7865 INDICATION_FILTER_DATA_CALL_DORMANCY_CHANGED, 7866 INDICATION_FILTER_LINK_CAPACITY_ESTIMATE, 7867 INDICATION_FILTER_PHYSICAL_CHANNEL_CONFIG 7868 }) 7869 @Retention(RetentionPolicy.SOURCE) 7870 public @interface IndicationFilters{} 7871 7872 /** 7873 * Sets radio indication update mode. This can be used to control the behavior of indication 7874 * update from modem to Android frameworks. For example, by default several indication updates 7875 * are turned off when screen is off, but in some special cases (e.g. carkit is connected but 7876 * screen is off) we want to turn on those indications even when the screen is off. 7877 * 7878 * <p>Requires Permission: 7879 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 7880 * 7881 * @param filters Indication filters. Should be a bitmask of INDICATION_FILTER_XXX. 7882 * @see #INDICATION_FILTER_SIGNAL_STRENGTH 7883 * @see #INDICATION_FILTER_FULL_NETWORK_STATE 7884 * @see #INDICATION_FILTER_DATA_CALL_DORMANCY_CHANGED 7885 * @param updateMode The voice activation state 7886 * @see #INDICATION_UPDATE_MODE_NORMAL 7887 * @see #INDICATION_UPDATE_MODE_IGNORE_SCREEN_OFF 7888 * @hide 7889 */ 7890 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setRadioIndicationUpdateMode(@ndicationFilters int filters, @IndicationUpdateMode int updateMode)7891 public void setRadioIndicationUpdateMode(@IndicationFilters int filters, 7892 @IndicationUpdateMode int updateMode) { 7893 try { 7894 ITelephony telephony = getITelephony(); 7895 if (telephony != null) { 7896 telephony.setRadioIndicationUpdateMode(getSubId(), filters, updateMode); 7897 } 7898 } catch (RemoteException ex) { 7899 // This could happen if binder process crashes. 7900 if (!isSystemProcess()) { 7901 ex.rethrowAsRuntimeException(); 7902 } 7903 } 7904 } 7905 7906 /** 7907 * A test API to override carrier information including mccmnc, imsi, iccid, gid1, gid2, 7908 * plmn and spn. This would be handy for, eg, forcing a particular carrier id, carrier's config 7909 * (also any country or carrier overlays) to be loaded when using a test SIM with a call box. 7910 * 7911 * <p>Requires Permission: 7912 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 7913 * 7914 * @hide 7915 */ 7916 @TestApi setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, String gid2, String plmn, String spn)7917 public void setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, 7918 String gid2, String plmn, String spn) { 7919 try { 7920 ITelephony telephony = getITelephony(); 7921 if (telephony != null) { 7922 telephony.setCarrierTestOverride( 7923 getSubId(), mccmnc, imsi, iccid, gid1, gid2, plmn, spn); 7924 } 7925 } catch (RemoteException ex) { 7926 // This could happen if binder process crashes. 7927 } 7928 } 7929 7930 /** 7931 * A test API to return installed carrier id list version 7932 * 7933 * <p>Requires Permission: 7934 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 7935 * 7936 * @hide 7937 */ 7938 @TestApi getCarrierIdListVersion()7939 public int getCarrierIdListVersion() { 7940 try { 7941 ITelephony telephony = getITelephony(); 7942 if (telephony != null) { 7943 return telephony.getCarrierIdListVersion(getSubId()); 7944 } 7945 } catch (RemoteException ex) { 7946 // This could happen if binder process crashes. 7947 } 7948 return UNKNOWN_CARRIER_ID_LIST_VERSION; 7949 } 7950 } 7951