TelephonyManager.java revision 829c097761e39b608b8b965a2c03f11ce5a95d2b
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 17package android.telephony; 18 19import android.annotation.Nullable; 20import android.annotation.SystemApi; 21import android.annotation.SdkConstant; 22import android.annotation.SdkConstant.SdkConstantType; 23import android.content.ContentResolver; 24import android.content.Context; 25import android.content.Intent; 26import android.provider.Settings; 27import android.provider.Settings.SettingNotFoundException; 28import android.os.Bundle; 29import android.os.RemoteException; 30import android.os.ServiceManager; 31import android.os.SystemProperties; 32import android.telecom.PhoneAccount; 33import android.util.Log; 34 35import com.android.internal.telecom.ITelecomService; 36import com.android.internal.telephony.IPhoneSubInfo; 37import com.android.internal.telephony.ITelephony; 38import com.android.internal.telephony.ITelephonyRegistry; 39import com.android.internal.telephony.PhoneConstants; 40import com.android.internal.telephony.RILConstants; 41import com.android.internal.telephony.TelephonyProperties; 42 43import java.io.FileInputStream; 44import java.io.IOException; 45import java.util.List; 46import java.util.regex.Matcher; 47import java.util.regex.Pattern; 48 49/** 50 * Provides access to information about the telephony services on 51 * the device. Applications can use the methods in this class to 52 * determine telephony services and states, as well as to access some 53 * types of subscriber information. Applications can also register 54 * a listener to receive notification of telephony state changes. 55 * <p> 56 * You do not instantiate this class directly; instead, you retrieve 57 * a reference to an instance through 58 * {@link android.content.Context#getSystemService 59 * Context.getSystemService(Context.TELEPHONY_SERVICE)}. 60 * <p> 61 * Note that access to some telephony information is 62 * permission-protected. Your application cannot access the protected 63 * information unless it has the appropriate permissions declared in 64 * its manifest file. Where permissions apply, they are noted in the 65 * the methods through which you access the protected information. 66 */ 67public class TelephonyManager { 68 private static final String TAG = "TelephonyManager"; 69 70 private static ITelephonyRegistry sRegistry; 71 72 /** 73 * The allowed states of Wi-Fi calling. 74 * 75 * @hide 76 */ 77 public interface WifiCallingChoices { 78 /** Always use Wi-Fi calling */ 79 static final int ALWAYS_USE = 0; 80 /** Ask the user whether to use Wi-Fi on every call */ 81 static final int ASK_EVERY_TIME = 1; 82 /** Never use Wi-Fi calling */ 83 static final int NEVER_USE = 2; 84 } 85 86 private final Context mContext; 87 private SubscriptionManager mSubscriptionManager; 88 89 private static String multiSimConfig = 90 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 91 92 /** Enum indicating multisim variants 93 * DSDS - Dual SIM Dual Standby 94 * DSDA - Dual SIM Dual Active 95 * TSTS - Triple SIM Triple Standby 96 **/ 97 /** @hide */ 98 public enum MultiSimVariants { 99 DSDS, 100 DSDA, 101 TSTS, 102 UNKNOWN 103 }; 104 105 /** @hide */ 106 public TelephonyManager(Context context) { 107 Context appContext = context.getApplicationContext(); 108 if (appContext != null) { 109 mContext = appContext; 110 } else { 111 mContext = context; 112 } 113 mSubscriptionManager = SubscriptionManager.from(mContext); 114 115 if (sRegistry == null) { 116 sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService( 117 "telephony.registry")); 118 } 119 } 120 121 /** @hide */ 122 private TelephonyManager() { 123 mContext = null; 124 } 125 126 private static TelephonyManager sInstance = new TelephonyManager(); 127 128 /** @hide 129 /* @deprecated - use getSystemService as described above */ 130 public static TelephonyManager getDefault() { 131 return sInstance; 132 } 133 134 135 /** 136 * Returns the multi SIM variant 137 * Returns DSDS for Dual SIM Dual Standby 138 * Returns DSDA for Dual SIM Dual Active 139 * Returns TSTS for Triple SIM Triple Standby 140 * Returns UNKNOWN for others 141 */ 142 /** {@hide} */ 143 public MultiSimVariants getMultiSimConfiguration() { 144 String mSimConfig = 145 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 146 if (mSimConfig.equals("dsds")) { 147 return MultiSimVariants.DSDS; 148 } else if (mSimConfig.equals("dsda")) { 149 return MultiSimVariants.DSDA; 150 } else if (mSimConfig.equals("tsts")) { 151 return MultiSimVariants.TSTS; 152 } else { 153 return MultiSimVariants.UNKNOWN; 154 } 155 } 156 157 158 /** 159 * Returns the number of phones available. 160 * Returns 1 for Single standby mode (Single SIM functionality) 161 * Returns 2 for Dual standby mode.(Dual SIM functionality) 162 */ 163 public int getPhoneCount() { 164 int phoneCount = 1; 165 switch (getMultiSimConfiguration()) { 166 case UNKNOWN: 167 phoneCount = 1; 168 break; 169 case DSDS: 170 case DSDA: 171 phoneCount = PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM; 172 break; 173 case TSTS: 174 phoneCount = PhoneConstants.MAX_PHONE_COUNT_TRI_SIM; 175 break; 176 } 177 return phoneCount; 178 } 179 180 /** {@hide} */ 181 public static TelephonyManager from(Context context) { 182 return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 183 } 184 185 /** {@hide} */ 186 public boolean isMultiSimEnabled() { 187 return (multiSimConfig.equals("dsds") || multiSimConfig.equals("dsda") || 188 multiSimConfig.equals("tsts")); 189 } 190 191 // 192 // Broadcast Intent actions 193 // 194 195 /** 196 * Broadcast intent action indicating that the call state (cellular) 197 * on the device has changed. 198 * 199 * <p> 200 * The {@link #EXTRA_STATE} extra indicates the new call state. 201 * If the new state is RINGING, a second extra 202 * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as 203 * a String. 204 * 205 * <p class="note"> 206 * Requires the READ_PHONE_STATE permission. 207 * 208 * <p class="note"> 209 * This was a {@link android.content.Context#sendStickyBroadcast sticky} 210 * broadcast in version 1.0, but it is no longer sticky. 211 * Instead, use {@link #getCallState} to synchronously query the current call state. 212 * 213 * @see #EXTRA_STATE 214 * @see #EXTRA_INCOMING_NUMBER 215 * @see #getCallState 216 */ 217 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 218 public static final String ACTION_PHONE_STATE_CHANGED = 219 "android.intent.action.PHONE_STATE"; 220 221 /** 222 * The Phone app sends this intent when a user opts to respond-via-message during an incoming 223 * call. By default, the device's default SMS app consumes this message and sends a text message 224 * to the caller. A third party app can also provide this functionality by consuming this Intent 225 * with a {@link android.app.Service} and sending the message using its own messaging system. 226 * <p>The intent contains a URI (available from {@link android.content.Intent#getData}) 227 * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:}, 228 * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the 229 * same way: the path part of the URI contains the recipient's phone number or a comma-separated 230 * set of phone numbers if there are multiple recipients. For example, {@code 231 * smsto:2065551234}.</p> 232 * 233 * <p>The intent may also contain extras for the message text (in {@link 234 * android.content.Intent#EXTRA_TEXT}) and a message subject 235 * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p> 236 * 237 * <p class="note"><strong>Note:</strong> 238 * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service} 239 * that requires the 240 * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p> 241 * <p>For example, the service that receives this intent can be declared in the manifest file 242 * with an intent filter like this:</p> 243 * <pre> 244 * <!-- Service that delivers SMS messages received from the phone "quick response" --> 245 * <service android:name=".HeadlessSmsSendService" 246 * android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" 247 * android:exported="true" > 248 * <intent-filter> 249 * <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /> 250 * <category android:name="android.intent.category.DEFAULT" /> 251 * <data android:scheme="sms" /> 252 * <data android:scheme="smsto" /> 253 * <data android:scheme="mms" /> 254 * <data android:scheme="mmsto" /> 255 * </intent-filter> 256 * </service></pre> 257 * <p> 258 * Output: nothing. 259 */ 260 @SdkConstant(SdkConstantType.SERVICE_ACTION) 261 public static final String ACTION_RESPOND_VIA_MESSAGE = 262 "android.intent.action.RESPOND_VIA_MESSAGE"; 263 264 /** 265 * The emergency dialer may choose to present activities with intent filters for this 266 * action as emergency assistance buttons that launch the activity when clicked. 267 * 268 * @hide 269 */ 270 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 271 public static final String ACTION_EMERGENCY_ASSISTANCE = 272 "android.telephony.action.EMERGENCY_ASSISTANCE"; 273 274 /** 275 * @hide 276 */ 277 public static final boolean EMERGENCY_ASSISTANCE_ENABLED = false; 278 279 /** 280 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 281 * for a String containing the new call state. 282 * 283 * @see #EXTRA_STATE_IDLE 284 * @see #EXTRA_STATE_RINGING 285 * @see #EXTRA_STATE_OFFHOOK 286 * 287 * <p class="note"> 288 * Retrieve with 289 * {@link android.content.Intent#getStringExtra(String)}. 290 */ 291 public static final String EXTRA_STATE = PhoneConstants.STATE_KEY; 292 293 /** 294 * Value used with {@link #EXTRA_STATE} corresponding to 295 * {@link #CALL_STATE_IDLE}. 296 */ 297 public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString(); 298 299 /** 300 * Value used with {@link #EXTRA_STATE} corresponding to 301 * {@link #CALL_STATE_RINGING}. 302 */ 303 public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString(); 304 305 /** 306 * Value used with {@link #EXTRA_STATE} corresponding to 307 * {@link #CALL_STATE_OFFHOOK}. 308 */ 309 public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString(); 310 311 /** 312 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 313 * for a String containing the incoming phone number. 314 * Only valid when the new call state is RINGING. 315 * 316 * <p class="note"> 317 * Retrieve with 318 * {@link android.content.Intent#getStringExtra(String)}. 319 */ 320 public static final String EXTRA_INCOMING_NUMBER = "incoming_number"; 321 322 /** 323 * Broadcast intent action indicating that a precise call state 324 * (cellular) on the device has changed. 325 * 326 * <p> 327 * The {@link #EXTRA_RINGING_CALL_STATE} extra indicates the ringing call state. 328 * The {@link #EXTRA_FOREGROUND_CALL_STATE} extra indicates the foreground call state. 329 * The {@link #EXTRA_BACKGROUND_CALL_STATE} extra indicates the background call state. 330 * The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause. 331 * The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause. 332 * 333 * <p class="note"> 334 * Requires the READ_PRECISE_PHONE_STATE permission. 335 * 336 * @see #EXTRA_RINGING_CALL_STATE 337 * @see #EXTRA_FOREGROUND_CALL_STATE 338 * @see #EXTRA_BACKGROUND_CALL_STATE 339 * @see #EXTRA_DISCONNECT_CAUSE 340 * @see #EXTRA_PRECISE_DISCONNECT_CAUSE 341 * 342 * <p class="note"> 343 * Requires the READ_PRECISE_PHONE_STATE permission. 344 * 345 * @hide 346 */ 347 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 348 public static final String ACTION_PRECISE_CALL_STATE_CHANGED = 349 "android.intent.action.PRECISE_CALL_STATE"; 350 351 /** 352 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 353 * for an integer containing the state of the current ringing call. 354 * 355 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 356 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 357 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 358 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 359 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 360 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 361 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 362 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 363 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 364 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 365 * 366 * <p class="note"> 367 * Retrieve with 368 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 369 * 370 * @hide 371 */ 372 public static final String EXTRA_RINGING_CALL_STATE = "ringing_state"; 373 374 /** 375 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 376 * for an integer containing the state of the current foreground call. 377 * 378 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 379 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 380 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 381 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 382 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 383 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 384 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 385 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 386 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 387 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 388 * 389 * <p class="note"> 390 * Retrieve with 391 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 392 * 393 * @hide 394 */ 395 public static final String EXTRA_FOREGROUND_CALL_STATE = "foreground_state"; 396 397 /** 398 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 399 * for an integer containing the state of the current background call. 400 * 401 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 402 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 403 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 404 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 405 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 406 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 407 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 408 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 409 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 410 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 411 * 412 * <p class="note"> 413 * Retrieve with 414 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 415 * 416 * @hide 417 */ 418 public static final String EXTRA_BACKGROUND_CALL_STATE = "background_state"; 419 420 /** 421 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 422 * for an integer containing the disconnect cause. 423 * 424 * @see DisconnectCause 425 * 426 * <p class="note"> 427 * Retrieve with 428 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 429 * 430 * @hide 431 */ 432 public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause"; 433 434 /** 435 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 436 * for an integer containing the disconnect cause provided by the RIL. 437 * 438 * @see PreciseDisconnectCause 439 * 440 * <p class="note"> 441 * Retrieve with 442 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 443 * 444 * @hide 445 */ 446 public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause"; 447 448 /** 449 * Broadcast intent action indicating a data connection has changed, 450 * providing precise information about the connection. 451 * 452 * <p> 453 * The {@link #EXTRA_DATA_STATE} extra indicates the connection state. 454 * The {@link #EXTRA_DATA_NETWORK_TYPE} extra indicates the connection network type. 455 * The {@link #EXTRA_DATA_APN_TYPE} extra indicates the APN type. 456 * The {@link #EXTRA_DATA_APN} extra indicates the APN. 457 * The {@link #EXTRA_DATA_CHANGE_REASON} extra indicates the connection change reason. 458 * The {@link #EXTRA_DATA_IFACE_PROPERTIES} extra indicates the connection interface. 459 * The {@link #EXTRA_DATA_FAILURE_CAUSE} extra indicates the connection fail cause. 460 * 461 * <p class="note"> 462 * Requires the READ_PRECISE_PHONE_STATE permission. 463 * 464 * @see #EXTRA_DATA_STATE 465 * @see #EXTRA_DATA_NETWORK_TYPE 466 * @see #EXTRA_DATA_APN_TYPE 467 * @see #EXTRA_DATA_APN 468 * @see #EXTRA_DATA_CHANGE_REASON 469 * @see #EXTRA_DATA_IFACE 470 * @see #EXTRA_DATA_FAILURE_CAUSE 471 * @hide 472 */ 473 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 474 public static final String ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED = 475 "android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED"; 476 477 /** 478 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 479 * for an integer containing the state of the current data connection. 480 * 481 * @see TelephonyManager#DATA_UNKNOWN 482 * @see TelephonyManager#DATA_DISCONNECTED 483 * @see TelephonyManager#DATA_CONNECTING 484 * @see TelephonyManager#DATA_CONNECTED 485 * @see TelephonyManager#DATA_SUSPENDED 486 * 487 * <p class="note"> 488 * Retrieve with 489 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 490 * 491 * @hide 492 */ 493 public static final String EXTRA_DATA_STATE = PhoneConstants.STATE_KEY; 494 495 /** 496 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 497 * for an integer containing the network type. 498 * 499 * @see TelephonyManager#NETWORK_TYPE_UNKNOWN 500 * @see TelephonyManager#NETWORK_TYPE_GPRS 501 * @see TelephonyManager#NETWORK_TYPE_EDGE 502 * @see TelephonyManager#NETWORK_TYPE_UMTS 503 * @see TelephonyManager#NETWORK_TYPE_CDMA 504 * @see TelephonyManager#NETWORK_TYPE_EVDO_0 505 * @see TelephonyManager#NETWORK_TYPE_EVDO_A 506 * @see TelephonyManager#NETWORK_TYPE_1xRTT 507 * @see TelephonyManager#NETWORK_TYPE_HSDPA 508 * @see TelephonyManager#NETWORK_TYPE_HSUPA 509 * @see TelephonyManager#NETWORK_TYPE_HSPA 510 * @see TelephonyManager#NETWORK_TYPE_IDEN 511 * @see TelephonyManager#NETWORK_TYPE_EVDO_B 512 * @see TelephonyManager#NETWORK_TYPE_LTE 513 * @see TelephonyManager#NETWORK_TYPE_EHRPD 514 * @see TelephonyManager#NETWORK_TYPE_HSPAP 515 * 516 * <p class="note"> 517 * Retrieve with 518 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 519 * 520 * @hide 521 */ 522 public static final String EXTRA_DATA_NETWORK_TYPE = PhoneConstants.DATA_NETWORK_TYPE_KEY; 523 524 /** 525 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 526 * for an String containing the data APN type. 527 * 528 * <p class="note"> 529 * Retrieve with 530 * {@link android.content.Intent#getStringExtra(String name)}. 531 * 532 * @hide 533 */ 534 public static final String EXTRA_DATA_APN_TYPE = PhoneConstants.DATA_APN_TYPE_KEY; 535 536 /** 537 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 538 * for an String containing the data APN. 539 * 540 * <p class="note"> 541 * Retrieve with 542 * {@link android.content.Intent#getStringExtra(String name)}. 543 * 544 * @hide 545 */ 546 public static final String EXTRA_DATA_APN = PhoneConstants.DATA_APN_KEY; 547 548 /** 549 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 550 * for an String representation of the change reason. 551 * 552 * <p class="note"> 553 * Retrieve with 554 * {@link android.content.Intent#getStringExtra(String name)}. 555 * 556 * @hide 557 */ 558 public static final String EXTRA_DATA_CHANGE_REASON = PhoneConstants.STATE_CHANGE_REASON_KEY; 559 560 /** 561 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 562 * for an String representation of the data interface. 563 * 564 * <p class="note"> 565 * Retrieve with 566 * {@link android.content.Intent#getParcelableExtra(String name)}. 567 * 568 * @hide 569 */ 570 public static final String EXTRA_DATA_LINK_PROPERTIES_KEY = PhoneConstants.DATA_LINK_PROPERTIES_KEY; 571 572 /** 573 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 574 * for the data connection fail cause. 575 * 576 * <p class="note"> 577 * Retrieve with 578 * {@link android.content.Intent#getStringExtra(String name)}. 579 * 580 * @hide 581 */ 582 public static final String EXTRA_DATA_FAILURE_CAUSE = PhoneConstants.DATA_FAILURE_CAUSE_KEY; 583 584 /** 585 * Response codes for sim activation. Activation completed successfully. 586 * @hide 587 */ 588 @SystemApi 589 public static final int SIM_ACTIVATION_RESULT_COMPLETE = 0; 590 /** 591 * Response codes for sim activation. Activation not supported (device has no SIM). 592 * @hide 593 */ 594 @SystemApi 595 public static final int SIM_ACTIVATION_RESULT_NOT_SUPPORTED = 1; 596 /** 597 * Response codes for sim activation. Activation is in progress. 598 * @hide 599 */ 600 @SystemApi 601 public static final int SIM_ACTIVATION_RESULT_IN_PROGRESS = 2; 602 /** 603 * Response codes for sim activation. Activation failed to complete. 604 * @hide 605 */ 606 @SystemApi 607 public static final int SIM_ACTIVATION_RESULT_FAILED = 3; 608 /** 609 * Response codes for sim activation. Activation canceled by user. 610 * @hide 611 */ 612 @SystemApi 613 public static final int SIM_ACTIVATION_RESULT_CANCELED = 4; 614 615 /* Visual voicemail protocols */ 616 617 /** 618 * The OMTP protocol. 619 * 620 * @hide 621 */ 622 public static final String VVM_TYPE_OMTP = "vvm_type_omtp"; 623 624 /** 625 * A flavor of OMTP protocol for Comverse. 626 * 627 * @hide 628 */ 629 public static final String VVM_TYPE_CVVM = "vvm_type_cvvm"; 630 631 // 632 // 633 // Device Info 634 // 635 // 636 637 /** 638 * Returns the software version number for the device, for example, 639 * the IMEI/SV for GSM phones. Return null if the software version is 640 * not available. 641 * 642 * <p>Requires Permission: 643 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 644 */ 645 public String getDeviceSoftwareVersion() { 646 return getDeviceSoftwareVersion(getDefaultSim()); 647 } 648 649 /** 650 * Returns the software version number for the device, for example, 651 * the IMEI/SV for GSM phones. Return null if the software version is 652 * not available. 653 * 654 * <p>Requires Permission: 655 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 656 * 657 * @param slotId of which deviceID is returned 658 */ 659 /** {@hide} */ 660 public String getDeviceSoftwareVersion(int slotId) { 661 // FIXME methods taking slot id should not use subscription, instead us Uicc directly 662 int[] subId = SubscriptionManager.getSubId(slotId); 663 if (subId == null || subId.length == 0) { 664 return null; 665 } 666 try { 667 IPhoneSubInfo info = getSubscriberInfo(); 668 if (info == null) 669 return null; 670 return info.getDeviceSvnUsingSubId(subId[0]); 671 } catch (RemoteException ex) { 672 return null; 673 } catch (NullPointerException ex) { 674 return null; 675 } 676 } 677 678 /** 679 * Returns the unique device ID, for example, the IMEI for GSM and the MEID 680 * or ESN for CDMA phones. Return null if device ID is not available. 681 * 682 * <p>Requires Permission: 683 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 684 */ 685 public String getDeviceId() { 686 try { 687 ITelephony telephony = getITelephony(); 688 if (telephony == null) 689 return null; 690 return telephony.getDeviceId(mContext.getOpPackageName()); 691 } catch (RemoteException ex) { 692 return null; 693 } catch (NullPointerException ex) { 694 return null; 695 } 696 } 697 698 /** 699 * Returns the unique device ID of a subscription, for example, the IMEI for 700 * GSM and the MEID for CDMA phones. Return null if device ID is not available. 701 * 702 * <p>Requires Permission: 703 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 704 * 705 * @param slotId of which deviceID is returned 706 */ 707 public String getDeviceId(int slotId) { 708 // FIXME this assumes phoneId == slotId 709 try { 710 IPhoneSubInfo info = getSubscriberInfo(); 711 if (info == null) 712 return null; 713 return info.getDeviceIdForPhone(slotId); 714 } catch (RemoteException ex) { 715 return null; 716 } catch (NullPointerException ex) { 717 return null; 718 } 719 } 720 721 /** 722 * Returns the IMEI. Return null if IMEI is not available. 723 * 724 * <p>Requires Permission: 725 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 726 */ 727 /** {@hide} */ 728 public String getImei() { 729 return getImei(getDefaultSim()); 730 } 731 732 /** 733 * Returns the IMEI. Return null if IMEI is not available. 734 * 735 * <p>Requires Permission: 736 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 737 * 738 * @param slotId of which deviceID is returned 739 */ 740 /** {@hide} */ 741 public String getImei(int slotId) { 742 int[] subId = SubscriptionManager.getSubId(slotId); 743 try { 744 IPhoneSubInfo info = getSubscriberInfo(); 745 if (info == null) 746 return null; 747 return info.getImeiForSubscriber(subId[0]); 748 } catch (RemoteException ex) { 749 return null; 750 } catch (NullPointerException ex) { 751 return null; 752 } 753 } 754 755 /** 756 * Returns the NAI. Return null if NAI is not available. 757 * 758 */ 759 /** {@hide}*/ 760 public String getNai() { 761 return getNai(getDefaultSim()); 762 } 763 764 /** 765 * Returns the NAI. Return null if NAI is not available. 766 * 767 * @param slotId of which Nai is returned 768 */ 769 /** {@hide}*/ 770 public String getNai(int slotId) { 771 int[] subId = SubscriptionManager.getSubId(slotId); 772 try { 773 IPhoneSubInfo info = getSubscriberInfo(); 774 if (info == null) 775 return null; 776 String nai = info.getNaiForSubscriber(subId[0]); 777 if (Log.isLoggable(TAG, Log.VERBOSE)) { 778 Rlog.v(TAG, "Nai = " + nai); 779 } 780 return nai; 781 } catch (RemoteException ex) { 782 return null; 783 } catch (NullPointerException ex) { 784 return null; 785 } 786 } 787 788 /** 789 * Returns the current location of the device. 790 *<p> 791 * If there is only one radio in the device and that radio has an LTE connection, 792 * this method will return null. The implementation must not to try add LTE 793 * identifiers into the existing cdma/gsm classes. 794 *<p> 795 * In the future this call will be deprecated. 796 *<p> 797 * @return Current location of the device or null if not available. 798 * 799 * <p>Requires Permission: 800 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or 801 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}. 802 */ 803 public CellLocation getCellLocation() { 804 try { 805 ITelephony telephony = getITelephony(); 806 if (telephony == null) { 807 Rlog.d(TAG, "getCellLocation returning null because telephony is null"); 808 return null; 809 } 810 Bundle bundle = telephony.getCellLocation(mContext.getOpPackageName()); 811 if (bundle.isEmpty()) { 812 Rlog.d(TAG, "getCellLocation returning null because bundle is empty"); 813 return null; 814 } 815 CellLocation cl = CellLocation.newFromBundle(bundle); 816 if (cl.isEmpty()) { 817 Rlog.d(TAG, "getCellLocation returning null because CellLocation is empty"); 818 return null; 819 } 820 return cl; 821 } catch (RemoteException ex) { 822 Rlog.d(TAG, "getCellLocation returning null due to RemoteException " + ex); 823 return null; 824 } catch (NullPointerException ex) { 825 Rlog.d(TAG, "getCellLocation returning null due to NullPointerException " + ex); 826 return null; 827 } 828 } 829 830 /** 831 * Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged 832 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 833 * 834 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 835 * CONTROL_LOCATION_UPDATES} 836 * 837 * @hide 838 */ 839 public void enableLocationUpdates() { 840 enableLocationUpdates(getDefaultSubscription()); 841 } 842 843 /** 844 * Enables location update notifications for a subscription. 845 * {@link PhoneStateListener#onCellLocationChanged 846 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 847 * 848 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 849 * CONTROL_LOCATION_UPDATES} 850 * 851 * @param subId for which the location updates are enabled 852 */ 853 /** @hide */ 854 public void enableLocationUpdates(int subId) { 855 try { 856 ITelephony telephony = getITelephony(); 857 if (telephony != null) 858 telephony.enableLocationUpdatesForSubscriber(subId); 859 } catch (RemoteException ex) { 860 } catch (NullPointerException ex) { 861 } 862 } 863 864 /** 865 * Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged 866 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 867 * 868 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 869 * CONTROL_LOCATION_UPDATES} 870 * 871 * @hide 872 */ 873 public void disableLocationUpdates() { 874 disableLocationUpdates(getDefaultSubscription()); 875 } 876 877 /** @hide */ 878 public void disableLocationUpdates(int subId) { 879 try { 880 ITelephony telephony = getITelephony(); 881 if (telephony != null) 882 telephony.disableLocationUpdatesForSubscriber(subId); 883 } catch (RemoteException ex) { 884 } catch (NullPointerException ex) { 885 } 886 } 887 888 /** 889 * Returns the neighboring cell information of the device. The getAllCellInfo is preferred 890 * and use this only if getAllCellInfo return nulls or an empty list. 891 *<p> 892 * In the future this call will be deprecated. 893 *<p> 894 * @return List of NeighboringCellInfo or null if info unavailable. 895 * 896 * <p>Requires Permission: 897 * (@link android.Manifest.permission#ACCESS_COARSE_UPDATES} 898 */ 899 public List<NeighboringCellInfo> getNeighboringCellInfo() { 900 try { 901 ITelephony telephony = getITelephony(); 902 if (telephony == null) 903 return null; 904 return telephony.getNeighboringCellInfo(mContext.getOpPackageName()); 905 } catch (RemoteException ex) { 906 return null; 907 } catch (NullPointerException ex) { 908 return null; 909 } 910 } 911 912 /** No phone radio. */ 913 public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE; 914 /** Phone radio is GSM. */ 915 public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM; 916 /** Phone radio is CDMA. */ 917 public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA; 918 /** Phone is via SIP. */ 919 public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP; 920 921 /** 922 * Returns the current phone type. 923 * TODO: This is a last minute change and hence hidden. 924 * 925 * @see #PHONE_TYPE_NONE 926 * @see #PHONE_TYPE_GSM 927 * @see #PHONE_TYPE_CDMA 928 * @see #PHONE_TYPE_SIP 929 * 930 * {@hide} 931 */ 932 @SystemApi 933 public int getCurrentPhoneType() { 934 return getCurrentPhoneType(getDefaultSubscription()); 935 } 936 937 /** 938 * Returns a constant indicating the device phone type for a subscription. 939 * 940 * @see #PHONE_TYPE_NONE 941 * @see #PHONE_TYPE_GSM 942 * @see #PHONE_TYPE_CDMA 943 * 944 * @param subId for which phone type is returned 945 */ 946 /** {@hide} */ 947 @SystemApi 948 public int getCurrentPhoneType(int subId) { 949 int phoneId = SubscriptionManager.getPhoneId(subId); 950 try{ 951 ITelephony telephony = getITelephony(); 952 if (telephony != null) { 953 return telephony.getActivePhoneTypeForSubscriber(subId); 954 } else { 955 // This can happen when the ITelephony interface is not up yet. 956 return getPhoneTypeFromProperty(phoneId); 957 } 958 } catch (RemoteException ex) { 959 // This shouldn't happen in the normal case, as a backup we 960 // read from the system property. 961 return getPhoneTypeFromProperty(phoneId); 962 } catch (NullPointerException ex) { 963 // This shouldn't happen in the normal case, as a backup we 964 // read from the system property. 965 return getPhoneTypeFromProperty(phoneId); 966 } 967 } 968 969 /** 970 * Returns a constant indicating the device phone type. This 971 * indicates the type of radio used to transmit voice calls. 972 * 973 * @see #PHONE_TYPE_NONE 974 * @see #PHONE_TYPE_GSM 975 * @see #PHONE_TYPE_CDMA 976 * @see #PHONE_TYPE_SIP 977 */ 978 public int getPhoneType() { 979 if (!isVoiceCapable()) { 980 return PHONE_TYPE_NONE; 981 } 982 return getCurrentPhoneType(); 983 } 984 985 private int getPhoneTypeFromProperty() { 986 return getPhoneTypeFromProperty(getDefaultPhone()); 987 } 988 989 /** {@hide} */ 990 private int getPhoneTypeFromProperty(int phoneId) { 991 String type = getTelephonyProperty(phoneId, 992 TelephonyProperties.CURRENT_ACTIVE_PHONE, null); 993 if (type == null || type.equals("")) { 994 return getPhoneTypeFromNetworkType(phoneId); 995 } 996 return Integer.parseInt(type); 997 } 998 999 private int getPhoneTypeFromNetworkType() { 1000 return getPhoneTypeFromNetworkType(getDefaultPhone()); 1001 } 1002 1003 /** {@hide} */ 1004 private int getPhoneTypeFromNetworkType(int phoneId) { 1005 // When the system property CURRENT_ACTIVE_PHONE, has not been set, 1006 // use the system property for default network type. 1007 // This is a fail safe, and can only happen at first boot. 1008 String mode = getTelephonyProperty(phoneId, "ro.telephony.default_network", null); 1009 if (mode != null) { 1010 return TelephonyManager.getPhoneType(Integer.parseInt(mode)); 1011 } 1012 return TelephonyManager.PHONE_TYPE_NONE; 1013 } 1014 1015 /** 1016 * This function returns the type of the phone, depending 1017 * on the network mode. 1018 * 1019 * @param networkMode 1020 * @return Phone Type 1021 * 1022 * @hide 1023 */ 1024 public static int getPhoneType(int networkMode) { 1025 switch(networkMode) { 1026 case RILConstants.NETWORK_MODE_CDMA: 1027 case RILConstants.NETWORK_MODE_CDMA_NO_EVDO: 1028 case RILConstants.NETWORK_MODE_EVDO_NO_CDMA: 1029 return PhoneConstants.PHONE_TYPE_CDMA; 1030 1031 case RILConstants.NETWORK_MODE_WCDMA_PREF: 1032 case RILConstants.NETWORK_MODE_GSM_ONLY: 1033 case RILConstants.NETWORK_MODE_WCDMA_ONLY: 1034 case RILConstants.NETWORK_MODE_GSM_UMTS: 1035 case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA: 1036 case RILConstants.NETWORK_MODE_LTE_WCDMA: 1037 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA: 1038 return PhoneConstants.PHONE_TYPE_GSM; 1039 1040 // Use CDMA Phone for the global mode including CDMA 1041 case RILConstants.NETWORK_MODE_GLOBAL: 1042 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO: 1043 return PhoneConstants.PHONE_TYPE_CDMA; 1044 1045 case RILConstants.NETWORK_MODE_LTE_ONLY: 1046 if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) { 1047 return PhoneConstants.PHONE_TYPE_CDMA; 1048 } else { 1049 return PhoneConstants.PHONE_TYPE_GSM; 1050 } 1051 default: 1052 return PhoneConstants.PHONE_TYPE_GSM; 1053 } 1054 } 1055 1056 /** 1057 * The contents of the /proc/cmdline file 1058 */ 1059 private static String getProcCmdLine() 1060 { 1061 String cmdline = ""; 1062 FileInputStream is = null; 1063 try { 1064 is = new FileInputStream("/proc/cmdline"); 1065 byte [] buffer = new byte[2048]; 1066 int count = is.read(buffer); 1067 if (count > 0) { 1068 cmdline = new String(buffer, 0, count); 1069 } 1070 } catch (IOException e) { 1071 Rlog.d(TAG, "No /proc/cmdline exception=" + e); 1072 } finally { 1073 if (is != null) { 1074 try { 1075 is.close(); 1076 } catch (IOException e) { 1077 } 1078 } 1079 } 1080 Rlog.d(TAG, "/proc/cmdline=" + cmdline); 1081 return cmdline; 1082 } 1083 1084 /** Kernel command line */ 1085 private static final String sKernelCmdLine = getProcCmdLine(); 1086 1087 /** Pattern for selecting the product type from the kernel command line */ 1088 private static final Pattern sProductTypePattern = 1089 Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)"); 1090 1091 /** The ProductType used for LTE on CDMA devices */ 1092 private static final String sLteOnCdmaProductType = 1093 SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, ""); 1094 1095 /** 1096 * Return if the current radio is LTE on CDMA. This 1097 * is a tri-state return value as for a period of time 1098 * the mode may be unknown. 1099 * 1100 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1101 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1102 * 1103 * @hide 1104 */ 1105 public static int getLteOnCdmaModeStatic() { 1106 int retVal; 1107 int curVal; 1108 String productType = ""; 1109 1110 curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE, 1111 PhoneConstants.LTE_ON_CDMA_UNKNOWN); 1112 retVal = curVal; 1113 if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) { 1114 Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine); 1115 if (matcher.find()) { 1116 productType = matcher.group(1); 1117 if (sLteOnCdmaProductType.equals(productType)) { 1118 retVal = PhoneConstants.LTE_ON_CDMA_TRUE; 1119 } else { 1120 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 1121 } 1122 } else { 1123 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 1124 } 1125 } 1126 1127 Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal + 1128 " product_type='" + productType + 1129 "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'"); 1130 return retVal; 1131 } 1132 1133 // 1134 // 1135 // Current Network 1136 // 1137 // 1138 1139 /** 1140 * Returns the alphabetic name of current registered operator. 1141 * <p> 1142 * Availability: Only when user is registered to a network. Result may be 1143 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1144 * on a CDMA network). 1145 */ 1146 public String getNetworkOperatorName() { 1147 return getNetworkOperatorName(getDefaultSubscription()); 1148 } 1149 1150 /** 1151 * Returns the alphabetic name of current registered operator 1152 * for a particular subscription. 1153 * <p> 1154 * Availability: Only when user is registered to a network. Result may be 1155 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1156 * on a CDMA network). 1157 * @param subId 1158 */ 1159 /** {@hide} */ 1160 public String getNetworkOperatorName(int subId) { 1161 int phoneId = SubscriptionManager.getPhoneId(subId); 1162 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, ""); 1163 } 1164 1165 /** 1166 * Returns the numeric name (MCC+MNC) of current registered operator. 1167 * <p> 1168 * Availability: Only when user is registered to a network. Result may be 1169 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1170 * on a CDMA network). 1171 */ 1172 public String getNetworkOperator() { 1173 return getNetworkOperatorForPhone(getDefaultPhone()); 1174 } 1175 1176 /** 1177 * Returns the numeric name (MCC+MNC) of current registered operator 1178 * for a particular subscription. 1179 * <p> 1180 * Availability: Only when user is registered to a network. Result may be 1181 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1182 * on a CDMA network). 1183 * 1184 * @param subId 1185 */ 1186 /** {@hide} */ 1187 public String getNetworkOperatorForSubscription(int subId) { 1188 int phoneId = SubscriptionManager.getPhoneId(subId); 1189 return getNetworkOperatorForPhone(phoneId); 1190 } 1191 1192 /** 1193 * Returns the numeric name (MCC+MNC) of current registered operator 1194 * for a particular subscription. 1195 * <p> 1196 * Availability: Only when user is registered to a network. Result may be 1197 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1198 * on a CDMA network). 1199 * 1200 * @param phoneId 1201 * @hide 1202 **/ 1203 public String getNetworkOperatorForPhone(int phoneId) { 1204 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, ""); 1205 } 1206 1207 /** 1208 * Returns true if the device is considered roaming on the current 1209 * network, for GSM purposes. 1210 * <p> 1211 * Availability: Only when user registered to a network. 1212 */ 1213 public boolean isNetworkRoaming() { 1214 return isNetworkRoaming(getDefaultSubscription()); 1215 } 1216 1217 /** 1218 * Returns true if the device is considered roaming on the current 1219 * network for a subscription. 1220 * <p> 1221 * Availability: Only when user registered to a network. 1222 * 1223 * @param subId 1224 */ 1225 /** {@hide} */ 1226 public boolean isNetworkRoaming(int subId) { 1227 int phoneId = SubscriptionManager.getPhoneId(subId); 1228 return Boolean.parseBoolean(getTelephonyProperty(phoneId, 1229 TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, null)); 1230 } 1231 1232 /** 1233 * Returns the ISO country code equivalent of the current registered 1234 * operator's MCC (Mobile Country Code). 1235 * <p> 1236 * Availability: Only when user is registered to a network. Result may be 1237 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1238 * on a CDMA network). 1239 */ 1240 public String getNetworkCountryIso() { 1241 return getNetworkCountryIsoForPhone(getDefaultPhone()); 1242 } 1243 1244 /** 1245 * Returns the ISO country code equivalent of the current registered 1246 * operator's MCC (Mobile Country Code) of a subscription. 1247 * <p> 1248 * Availability: Only when user is registered to a network. Result may be 1249 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1250 * on a CDMA network). 1251 * 1252 * @param subId for which Network CountryIso is returned 1253 */ 1254 /** {@hide} */ 1255 public String getNetworkCountryIsoForSubscription(int subId) { 1256 int phoneId = SubscriptionManager.getPhoneId(subId); 1257 return getNetworkCountryIsoForPhone(phoneId); 1258 } 1259 1260 /** 1261 * Returns the ISO country code equivalent of the current registered 1262 * operator's MCC (Mobile Country Code) of a subscription. 1263 * <p> 1264 * Availability: Only when user is registered to a network. Result may be 1265 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1266 * on a CDMA network). 1267 * 1268 * @param phoneId for which Network CountryIso is returned 1269 */ 1270 /** {@hide} */ 1271 public String getNetworkCountryIsoForPhone(int phoneId) { 1272 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, ""); 1273 } 1274 1275 /** Network type is unknown */ 1276 public static final int NETWORK_TYPE_UNKNOWN = 0; 1277 /** Current network is GPRS */ 1278 public static final int NETWORK_TYPE_GPRS = 1; 1279 /** Current network is EDGE */ 1280 public static final int NETWORK_TYPE_EDGE = 2; 1281 /** Current network is UMTS */ 1282 public static final int NETWORK_TYPE_UMTS = 3; 1283 /** Current network is CDMA: Either IS95A or IS95B*/ 1284 public static final int NETWORK_TYPE_CDMA = 4; 1285 /** Current network is EVDO revision 0*/ 1286 public static final int NETWORK_TYPE_EVDO_0 = 5; 1287 /** Current network is EVDO revision A*/ 1288 public static final int NETWORK_TYPE_EVDO_A = 6; 1289 /** Current network is 1xRTT*/ 1290 public static final int NETWORK_TYPE_1xRTT = 7; 1291 /** Current network is HSDPA */ 1292 public static final int NETWORK_TYPE_HSDPA = 8; 1293 /** Current network is HSUPA */ 1294 public static final int NETWORK_TYPE_HSUPA = 9; 1295 /** Current network is HSPA */ 1296 public static final int NETWORK_TYPE_HSPA = 10; 1297 /** Current network is iDen */ 1298 public static final int NETWORK_TYPE_IDEN = 11; 1299 /** Current network is EVDO revision B*/ 1300 public static final int NETWORK_TYPE_EVDO_B = 12; 1301 /** Current network is LTE */ 1302 public static final int NETWORK_TYPE_LTE = 13; 1303 /** Current network is eHRPD */ 1304 public static final int NETWORK_TYPE_EHRPD = 14; 1305 /** Current network is HSPA+ */ 1306 public static final int NETWORK_TYPE_HSPAP = 15; 1307 /** Current network is GSM {@hide} */ 1308 public static final int NETWORK_TYPE_GSM = 16; 1309 /** Current network is TD_SCDMA {@hide} */ 1310 public static final int NETWORK_TYPE_TD_SCDMA = 17; 1311 /** Current network is IWLAN {@hide} */ 1312 public static final int NETWORK_TYPE_IWLAN = 18; 1313 1314 /** 1315 * @return the NETWORK_TYPE_xxxx for current data connection. 1316 */ 1317 public int getNetworkType() { 1318 return getDataNetworkType(); 1319 } 1320 1321 /** 1322 * Returns a constant indicating the radio technology (network type) 1323 * currently in use on the device for a subscription. 1324 * @return the network type 1325 * 1326 * @param subId for which network type is returned 1327 * 1328 * @see #NETWORK_TYPE_UNKNOWN 1329 * @see #NETWORK_TYPE_GPRS 1330 * @see #NETWORK_TYPE_EDGE 1331 * @see #NETWORK_TYPE_UMTS 1332 * @see #NETWORK_TYPE_HSDPA 1333 * @see #NETWORK_TYPE_HSUPA 1334 * @see #NETWORK_TYPE_HSPA 1335 * @see #NETWORK_TYPE_CDMA 1336 * @see #NETWORK_TYPE_EVDO_0 1337 * @see #NETWORK_TYPE_EVDO_A 1338 * @see #NETWORK_TYPE_EVDO_B 1339 * @see #NETWORK_TYPE_1xRTT 1340 * @see #NETWORK_TYPE_IDEN 1341 * @see #NETWORK_TYPE_LTE 1342 * @see #NETWORK_TYPE_EHRPD 1343 * @see #NETWORK_TYPE_HSPAP 1344 */ 1345 /** {@hide} */ 1346 public int getNetworkType(int subId) { 1347 try { 1348 ITelephony telephony = getITelephony(); 1349 if (telephony != null) { 1350 return telephony.getNetworkTypeForSubscriber(subId); 1351 } else { 1352 // This can happen when the ITelephony interface is not up yet. 1353 return NETWORK_TYPE_UNKNOWN; 1354 } 1355 } catch(RemoteException ex) { 1356 // This shouldn't happen in the normal case 1357 return NETWORK_TYPE_UNKNOWN; 1358 } catch (NullPointerException ex) { 1359 // This could happen before phone restarts due to crashing 1360 return NETWORK_TYPE_UNKNOWN; 1361 } 1362 } 1363 1364 /** 1365 * Returns a constant indicating the radio technology (network type) 1366 * currently in use on the device for data transmission. 1367 * @return the network type 1368 * 1369 * @see #NETWORK_TYPE_UNKNOWN 1370 * @see #NETWORK_TYPE_GPRS 1371 * @see #NETWORK_TYPE_EDGE 1372 * @see #NETWORK_TYPE_UMTS 1373 * @see #NETWORK_TYPE_HSDPA 1374 * @see #NETWORK_TYPE_HSUPA 1375 * @see #NETWORK_TYPE_HSPA 1376 * @see #NETWORK_TYPE_CDMA 1377 * @see #NETWORK_TYPE_EVDO_0 1378 * @see #NETWORK_TYPE_EVDO_A 1379 * @see #NETWORK_TYPE_EVDO_B 1380 * @see #NETWORK_TYPE_1xRTT 1381 * @see #NETWORK_TYPE_IDEN 1382 * @see #NETWORK_TYPE_LTE 1383 * @see #NETWORK_TYPE_EHRPD 1384 * @see #NETWORK_TYPE_HSPAP 1385 * 1386 * @hide 1387 */ 1388 public int getDataNetworkType() { 1389 return getDataNetworkType(getDefaultSubscription()); 1390 } 1391 1392 /** 1393 * Returns a constant indicating the radio technology (network type) 1394 * currently in use on the device for data transmission for a subscription 1395 * @return the network type 1396 * 1397 * @param subId for which network type is returned 1398 */ 1399 /** {@hide} */ 1400 public int getDataNetworkType(int subId) { 1401 try{ 1402 ITelephony telephony = getITelephony(); 1403 if (telephony != null) { 1404 return telephony.getDataNetworkTypeForSubscriber(subId); 1405 } else { 1406 // This can happen when the ITelephony interface is not up yet. 1407 return NETWORK_TYPE_UNKNOWN; 1408 } 1409 } catch(RemoteException ex) { 1410 // This shouldn't happen in the normal case 1411 return NETWORK_TYPE_UNKNOWN; 1412 } catch (NullPointerException ex) { 1413 // This could happen before phone restarts due to crashing 1414 return NETWORK_TYPE_UNKNOWN; 1415 } 1416 } 1417 1418 /** 1419 * Returns the NETWORK_TYPE_xxxx for voice 1420 * 1421 * @hide 1422 */ 1423 public int getVoiceNetworkType() { 1424 return getVoiceNetworkType(getDefaultSubscription()); 1425 } 1426 1427 /** 1428 * Returns the NETWORK_TYPE_xxxx for voice for a subId 1429 * 1430 */ 1431 /** {@hide} */ 1432 public int getVoiceNetworkType(int subId) { 1433 try{ 1434 ITelephony telephony = getITelephony(); 1435 if (telephony != null) { 1436 return telephony.getVoiceNetworkTypeForSubscriber(subId); 1437 } else { 1438 // This can happen when the ITelephony interface is not up yet. 1439 return NETWORK_TYPE_UNKNOWN; 1440 } 1441 } catch(RemoteException ex) { 1442 // This shouldn't happen in the normal case 1443 return NETWORK_TYPE_UNKNOWN; 1444 } catch (NullPointerException ex) { 1445 // This could happen before phone restarts due to crashing 1446 return NETWORK_TYPE_UNKNOWN; 1447 } 1448 } 1449 1450 /** Unknown network class. {@hide} */ 1451 public static final int NETWORK_CLASS_UNKNOWN = 0; 1452 /** Class of broadly defined "2G" networks. {@hide} */ 1453 public static final int NETWORK_CLASS_2_G = 1; 1454 /** Class of broadly defined "3G" networks. {@hide} */ 1455 public static final int NETWORK_CLASS_3_G = 2; 1456 /** Class of broadly defined "4G" networks. {@hide} */ 1457 public static final int NETWORK_CLASS_4_G = 3; 1458 1459 /** 1460 * Return general class of network type, such as "3G" or "4G". In cases 1461 * where classification is contentious, this method is conservative. 1462 * 1463 * @hide 1464 */ 1465 public static int getNetworkClass(int networkType) { 1466 switch (networkType) { 1467 case NETWORK_TYPE_GPRS: 1468 case NETWORK_TYPE_GSM: 1469 case NETWORK_TYPE_EDGE: 1470 case NETWORK_TYPE_CDMA: 1471 case NETWORK_TYPE_1xRTT: 1472 case NETWORK_TYPE_IDEN: 1473 return NETWORK_CLASS_2_G; 1474 case NETWORK_TYPE_UMTS: 1475 case NETWORK_TYPE_EVDO_0: 1476 case NETWORK_TYPE_EVDO_A: 1477 case NETWORK_TYPE_HSDPA: 1478 case NETWORK_TYPE_HSUPA: 1479 case NETWORK_TYPE_HSPA: 1480 case NETWORK_TYPE_EVDO_B: 1481 case NETWORK_TYPE_EHRPD: 1482 case NETWORK_TYPE_HSPAP: 1483 case NETWORK_TYPE_TD_SCDMA: 1484 return NETWORK_CLASS_3_G; 1485 case NETWORK_TYPE_LTE: 1486 case NETWORK_TYPE_IWLAN: 1487 return NETWORK_CLASS_4_G; 1488 default: 1489 return NETWORK_CLASS_UNKNOWN; 1490 } 1491 } 1492 1493 /** 1494 * Returns a string representation of the radio technology (network type) 1495 * currently in use on the device. 1496 * @return the name of the radio technology 1497 * 1498 * @hide pending API council review 1499 */ 1500 public String getNetworkTypeName() { 1501 return getNetworkTypeName(getNetworkType()); 1502 } 1503 1504 /** 1505 * Returns a string representation of the radio technology (network type) 1506 * currently in use on the device. 1507 * @param subId for which network type is returned 1508 * @return the name of the radio technology 1509 * 1510 */ 1511 /** {@hide} */ 1512 public static String getNetworkTypeName(int type) { 1513 switch (type) { 1514 case NETWORK_TYPE_GPRS: 1515 return "GPRS"; 1516 case NETWORK_TYPE_EDGE: 1517 return "EDGE"; 1518 case NETWORK_TYPE_UMTS: 1519 return "UMTS"; 1520 case NETWORK_TYPE_HSDPA: 1521 return "HSDPA"; 1522 case NETWORK_TYPE_HSUPA: 1523 return "HSUPA"; 1524 case NETWORK_TYPE_HSPA: 1525 return "HSPA"; 1526 case NETWORK_TYPE_CDMA: 1527 return "CDMA"; 1528 case NETWORK_TYPE_EVDO_0: 1529 return "CDMA - EvDo rev. 0"; 1530 case NETWORK_TYPE_EVDO_A: 1531 return "CDMA - EvDo rev. A"; 1532 case NETWORK_TYPE_EVDO_B: 1533 return "CDMA - EvDo rev. B"; 1534 case NETWORK_TYPE_1xRTT: 1535 return "CDMA - 1xRTT"; 1536 case NETWORK_TYPE_LTE: 1537 return "LTE"; 1538 case NETWORK_TYPE_EHRPD: 1539 return "CDMA - eHRPD"; 1540 case NETWORK_TYPE_IDEN: 1541 return "iDEN"; 1542 case NETWORK_TYPE_HSPAP: 1543 return "HSPA+"; 1544 case NETWORK_TYPE_GSM: 1545 return "GSM"; 1546 case NETWORK_TYPE_TD_SCDMA: 1547 return "TD_SCDMA"; 1548 case NETWORK_TYPE_IWLAN: 1549 return "IWLAN"; 1550 default: 1551 return "UNKNOWN"; 1552 } 1553 } 1554 1555 // 1556 // 1557 // SIM Card 1558 // 1559 // 1560 1561 /** 1562 * SIM card state: Unknown. Signifies that the SIM is in transition 1563 * between states. For example, when the user inputs the SIM pin 1564 * under PIN_REQUIRED state, a query for sim status returns 1565 * this state before turning to SIM_STATE_READY. 1566 * 1567 * These are the ordinal value of IccCardConstants.State. 1568 */ 1569 public static final int SIM_STATE_UNKNOWN = 0; 1570 /** SIM card state: no SIM card is available in the device */ 1571 public static final int SIM_STATE_ABSENT = 1; 1572 /** SIM card state: Locked: requires the user's SIM PIN to unlock */ 1573 public static final int SIM_STATE_PIN_REQUIRED = 2; 1574 /** SIM card state: Locked: requires the user's SIM PUK to unlock */ 1575 public static final int SIM_STATE_PUK_REQUIRED = 3; 1576 /** SIM card state: Locked: requires a network PIN to unlock */ 1577 public static final int SIM_STATE_NETWORK_LOCKED = 4; 1578 /** SIM card state: Ready */ 1579 public static final int SIM_STATE_READY = 5; 1580 /** SIM card state: SIM Card is NOT READY 1581 *@hide 1582 */ 1583 public static final int SIM_STATE_NOT_READY = 6; 1584 /** SIM card state: SIM Card Error, permanently disabled 1585 *@hide 1586 */ 1587 public static final int SIM_STATE_PERM_DISABLED = 7; 1588 /** SIM card state: SIM Card Error, present but faulty 1589 *@hide 1590 */ 1591 public static final int SIM_STATE_CARD_IO_ERROR = 8; 1592 1593 /** 1594 * @return true if a ICC card is present 1595 */ 1596 public boolean hasIccCard() { 1597 return hasIccCard(getDefaultSim()); 1598 } 1599 1600 /** 1601 * @return true if a ICC card is present for a subscription 1602 * 1603 * @param slotId for which icc card presence is checked 1604 */ 1605 /** {@hide} */ 1606 // FIXME Input argument slotId should be of type int 1607 public boolean hasIccCard(int slotId) { 1608 1609 try { 1610 ITelephony telephony = getITelephony(); 1611 if (telephony == null) 1612 return false; 1613 return telephony.hasIccCardUsingSlotId(slotId); 1614 } catch (RemoteException ex) { 1615 // Assume no ICC card if remote exception which shouldn't happen 1616 return false; 1617 } catch (NullPointerException ex) { 1618 // This could happen before phone restarts due to crashing 1619 return false; 1620 } 1621 } 1622 1623 /** 1624 * Returns a constant indicating the state of the default SIM card. 1625 * 1626 * @see #SIM_STATE_UNKNOWN 1627 * @see #SIM_STATE_ABSENT 1628 * @see #SIM_STATE_PIN_REQUIRED 1629 * @see #SIM_STATE_PUK_REQUIRED 1630 * @see #SIM_STATE_NETWORK_LOCKED 1631 * @see #SIM_STATE_READY 1632 * @see #SIM_STATE_NOT_READY 1633 * @see #SIM_STATE_PERM_DISABLED 1634 * @see #SIM_STATE_CARD_IO_ERROR 1635 */ 1636 public int getSimState() { 1637 int slotIdx = getDefaultSim(); 1638 // slotIdx may be invalid due to sim being absent. In that case query all slots to get 1639 // sim state 1640 if (slotIdx < 0) { 1641 // query for all slots and return absent if all sim states are absent, otherwise 1642 // return unknown 1643 for (int i = 0; i < getPhoneCount(); i++) { 1644 int simState = getSimState(i); 1645 if (simState != SIM_STATE_ABSENT) { 1646 Rlog.d(TAG, "getSimState: default sim:" + slotIdx + ", sim state for " + 1647 "slotIdx=" + i + " is " + simState + ", return state as unknown"); 1648 return SIM_STATE_UNKNOWN; 1649 } 1650 } 1651 Rlog.d(TAG, "getSimState: default sim:" + slotIdx + ", all SIMs absent, return " + 1652 "state as absent"); 1653 return SIM_STATE_ABSENT; 1654 } 1655 return getSimState(slotIdx); 1656 } 1657 1658 /** 1659 * Returns a constant indicating the state of the device SIM card in a slot. 1660 * 1661 * @param slotIdx 1662 * 1663 * @see #SIM_STATE_UNKNOWN 1664 * @see #SIM_STATE_ABSENT 1665 * @see #SIM_STATE_PIN_REQUIRED 1666 * @see #SIM_STATE_PUK_REQUIRED 1667 * @see #SIM_STATE_NETWORK_LOCKED 1668 * @see #SIM_STATE_READY 1669 * @see #SIM_STATE_NOT_READY 1670 * @see #SIM_STATE_PERM_DISABLED 1671 * @see #SIM_STATE_CARD_IO_ERROR 1672 */ 1673 /** {@hide} */ 1674 public int getSimState(int slotIdx) { 1675 int simState = SubscriptionManager.getSimStateForSlotIdx(slotIdx); 1676 return simState; 1677 } 1678 1679 /** 1680 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1681 * provider of the SIM. 5 or 6 decimal digits. 1682 * <p> 1683 * Availability: SIM state must be {@link #SIM_STATE_READY} 1684 * 1685 * @see #getSimState 1686 */ 1687 public String getSimOperator() { 1688 return getSimOperatorNumeric(); 1689 } 1690 1691 /** 1692 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1693 * provider of the SIM. 5 or 6 decimal digits. 1694 * <p> 1695 * Availability: SIM state must be {@link #SIM_STATE_READY} 1696 * 1697 * @see #getSimState 1698 * 1699 * @param subId for which SimOperator is returned 1700 * @hide 1701 */ 1702 public String getSimOperator(int subId) { 1703 return getSimOperatorNumericForSubscription(subId); 1704 } 1705 1706 /** 1707 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1708 * provider of the SIM. 5 or 6 decimal digits. 1709 * <p> 1710 * Availability: SIM state must be {@link #SIM_STATE_READY} 1711 * 1712 * @see #getSimState 1713 * @hide 1714 */ 1715 public String getSimOperatorNumeric() { 1716 int subId = SubscriptionManager.getDefaultDataSubId(); 1717 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1718 subId = SubscriptionManager.getDefaultSmsSubId(); 1719 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1720 subId = SubscriptionManager.getDefaultVoiceSubId(); 1721 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1722 subId = SubscriptionManager.getDefaultSubId(); 1723 } 1724 } 1725 } 1726 return getSimOperatorNumericForSubscription(subId); 1727 } 1728 1729 /** 1730 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1731 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 1732 * <p> 1733 * Availability: SIM state must be {@link #SIM_STATE_READY} 1734 * 1735 * @see #getSimState 1736 * 1737 * @param subId for which SimOperator is returned 1738 * @hide 1739 */ 1740 public String getSimOperatorNumericForSubscription(int subId) { 1741 int phoneId = SubscriptionManager.getPhoneId(subId); 1742 return getSimOperatorNumericForPhone(phoneId); 1743 } 1744 1745 /** 1746 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1747 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 1748 * <p> 1749 * 1750 * @param phoneId for which SimOperator is returned 1751 * @hide 1752 */ 1753 public String getSimOperatorNumericForPhone(int phoneId) { 1754 return getTelephonyProperty(phoneId, 1755 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, ""); 1756 } 1757 1758 /** 1759 * Returns the Service Provider Name (SPN). 1760 * <p> 1761 * Availability: SIM state must be {@link #SIM_STATE_READY} 1762 * 1763 * @see #getSimState 1764 */ 1765 public String getSimOperatorName() { 1766 return getSimOperatorNameForPhone(getDefaultPhone()); 1767 } 1768 1769 /** 1770 * Returns the Service Provider Name (SPN). 1771 * <p> 1772 * Availability: SIM state must be {@link #SIM_STATE_READY} 1773 * 1774 * @see #getSimState 1775 * 1776 * @param subId for which SimOperatorName is returned 1777 * @hide 1778 */ 1779 public String getSimOperatorNameForSubscription(int subId) { 1780 int phoneId = SubscriptionManager.getPhoneId(subId); 1781 return getSimOperatorNameForPhone(phoneId); 1782 } 1783 1784 /** 1785 * Returns the Service Provider Name (SPN). 1786 * 1787 * @hide 1788 */ 1789 public String getSimOperatorNameForPhone(int phoneId) { 1790 return getTelephonyProperty(phoneId, 1791 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, ""); 1792 } 1793 1794 /** 1795 * Returns the ISO country code equivalent for the SIM provider's country code. 1796 */ 1797 public String getSimCountryIso() { 1798 return getSimCountryIsoForPhone(getDefaultPhone()); 1799 } 1800 1801 /** 1802 * Returns the ISO country code equivalent for the SIM provider's country code. 1803 * 1804 * @param subId for which SimCountryIso is returned 1805 * 1806 * @hide 1807 */ 1808 public String getSimCountryIso(int subId) { 1809 return getSimCountryIsoForSubscription(subId); 1810 } 1811 1812 /** 1813 * Returns the ISO country code equivalent for the SIM provider's country code. 1814 * 1815 * @param subId for which SimCountryIso is returned 1816 * 1817 * @hide 1818 */ 1819 public String getSimCountryIsoForSubscription(int subId) { 1820 int phoneId = SubscriptionManager.getPhoneId(subId); 1821 return getSimCountryIsoForPhone(phoneId); 1822 } 1823 1824 /** 1825 * Returns the ISO country code equivalent for the SIM provider's country code. 1826 * 1827 * @hide 1828 */ 1829 public String getSimCountryIsoForPhone(int phoneId) { 1830 return getTelephonyProperty(phoneId, 1831 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, ""); 1832 } 1833 1834 /** 1835 * Returns the serial number of the SIM, if applicable. Return null if it is 1836 * unavailable. 1837 * <p> 1838 * Requires Permission: 1839 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1840 */ 1841 public String getSimSerialNumber() { 1842 return getSimSerialNumber(getDefaultSubscription()); 1843 } 1844 1845 /** 1846 * Returns the serial number for the given subscription, if applicable. Return null if it is 1847 * unavailable. 1848 * <p> 1849 * @param subId for which Sim Serial number is returned 1850 * Requires Permission: 1851 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1852 */ 1853 /** {@hide} */ 1854 public String getSimSerialNumber(int subId) { 1855 try { 1856 IPhoneSubInfo info = getSubscriberInfo(); 1857 if (info == null) 1858 return null; 1859 return info.getIccSerialNumberForSubscriber(subId); 1860 } catch (RemoteException ex) { 1861 return null; 1862 } catch (NullPointerException ex) { 1863 // This could happen before phone restarts due to crashing 1864 return null; 1865 } 1866 } 1867 1868 /** 1869 * Return if the current radio is LTE on CDMA. This 1870 * is a tri-state return value as for a period of time 1871 * the mode may be unknown. 1872 * 1873 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1874 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1875 * 1876 * @hide 1877 */ 1878 public int getLteOnCdmaMode() { 1879 return getLteOnCdmaMode(getDefaultSubscription()); 1880 } 1881 1882 /** 1883 * Return if the current radio is LTE on CDMA for Subscription. This 1884 * is a tri-state return value as for a period of time 1885 * the mode may be unknown. 1886 * 1887 * @param subId for which radio is LTE on CDMA is returned 1888 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1889 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1890 * 1891 */ 1892 /** {@hide} */ 1893 public int getLteOnCdmaMode(int subId) { 1894 try { 1895 ITelephony telephony = getITelephony(); 1896 if (telephony == null) 1897 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1898 return telephony.getLteOnCdmaModeForSubscriber(subId); 1899 } catch (RemoteException ex) { 1900 // Assume no ICC card if remote exception which shouldn't happen 1901 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1902 } catch (NullPointerException ex) { 1903 // This could happen before phone restarts due to crashing 1904 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1905 } 1906 } 1907 1908 // 1909 // 1910 // Subscriber Info 1911 // 1912 // 1913 1914 /** 1915 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 1916 * Return null if it is unavailable. 1917 * <p> 1918 * Requires Permission: 1919 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1920 */ 1921 public String getSubscriberId() { 1922 return getSubscriberId(getDefaultSubscription()); 1923 } 1924 1925 /** 1926 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone 1927 * for a subscription. 1928 * Return null if it is unavailable. 1929 * <p> 1930 * Requires Permission: 1931 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1932 * 1933 * @param subId whose subscriber id is returned 1934 */ 1935 /** {@hide} */ 1936 public String getSubscriberId(int subId) { 1937 try { 1938 IPhoneSubInfo info = getSubscriberInfo(); 1939 if (info == null) 1940 return null; 1941 return info.getSubscriberIdForSubscriber(subId); 1942 } catch (RemoteException ex) { 1943 return null; 1944 } catch (NullPointerException ex) { 1945 // This could happen before phone restarts due to crashing 1946 return null; 1947 } 1948 } 1949 1950 /** 1951 * Returns the Group Identifier Level1 for a GSM phone. 1952 * Return null if it is unavailable. 1953 * <p> 1954 * Requires Permission: 1955 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1956 */ 1957 public String getGroupIdLevel1() { 1958 try { 1959 IPhoneSubInfo info = getSubscriberInfo(); 1960 if (info == null) 1961 return null; 1962 return info.getGroupIdLevel1(); 1963 } catch (RemoteException ex) { 1964 return null; 1965 } catch (NullPointerException ex) { 1966 // This could happen before phone restarts due to crashing 1967 return null; 1968 } 1969 } 1970 1971 /** 1972 * Returns the Group Identifier Level1 for a GSM phone for a particular subscription. 1973 * Return null if it is unavailable. 1974 * <p> 1975 * Requires Permission: 1976 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1977 * 1978 * @param subscription whose subscriber id is returned 1979 */ 1980 /** {@hide} */ 1981 public String getGroupIdLevel1(int subId) { 1982 try { 1983 IPhoneSubInfo info = getSubscriberInfo(); 1984 if (info == null) 1985 return null; 1986 return info.getGroupIdLevel1ForSubscriber(subId); 1987 } catch (RemoteException ex) { 1988 return null; 1989 } catch (NullPointerException ex) { 1990 // This could happen before phone restarts due to crashing 1991 return null; 1992 } 1993 } 1994 1995 /** 1996 * Returns the phone number string for line 1, for example, the MSISDN 1997 * for a GSM phone. Return null if it is unavailable. 1998 * <p> 1999 * Requires Permission: 2000 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2001 */ 2002 public String getLine1Number() { 2003 return getLine1NumberForSubscriber(getDefaultSubscription()); 2004 } 2005 2006 /** 2007 * Returns the phone number string for line 1, for example, the MSISDN 2008 * for a GSM phone for a particular subscription. Return null if it is unavailable. 2009 * <p> 2010 * Requires Permission: 2011 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2012 * 2013 * @param subId whose phone number for line 1 is returned 2014 */ 2015 /** {@hide} */ 2016 public String getLine1NumberForSubscriber(int subId) { 2017 String number = null; 2018 try { 2019 ITelephony telephony = getITelephony(); 2020 if (telephony != null) 2021 number = telephony.getLine1NumberForDisplay(subId, mContext.getOpPackageName()); 2022 } catch (RemoteException ex) { 2023 } catch (NullPointerException ex) { 2024 } 2025 if (number != null) { 2026 return number; 2027 } 2028 try { 2029 IPhoneSubInfo info = getSubscriberInfo(); 2030 if (info == null) 2031 return null; 2032 return info.getLine1NumberForSubscriber(subId); 2033 } catch (RemoteException ex) { 2034 return null; 2035 } catch (NullPointerException ex) { 2036 // This could happen before phone restarts due to crashing 2037 return null; 2038 } 2039 } 2040 2041 /** 2042 * Set the line 1 phone number string and its alphatag for the current ICCID 2043 * for display purpose only, for example, displayed in Phone Status. It won't 2044 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 2045 * value. 2046 * 2047 * <p>Requires that the calling app has carrier privileges. 2048 * @see #hasCarrierPrivileges 2049 * 2050 * @param alphaTag alpha-tagging of the dailing nubmer 2051 * @param number The dialing number 2052 * @return true if the operation was executed correctly. 2053 */ 2054 public boolean setLine1NumberForDisplay(String alphaTag, String number) { 2055 return setLine1NumberForDisplayForSubscriber(getDefaultSubscription(), alphaTag, number); 2056 } 2057 2058 /** 2059 * Set the line 1 phone number string and its alphatag for the current ICCID 2060 * for display purpose only, for example, displayed in Phone Status. It won't 2061 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 2062 * value. 2063 * 2064 * <p>Requires that the calling app has carrier privileges. 2065 * @see #hasCarrierPrivileges 2066 * 2067 * @param subId the subscriber that the alphatag and dialing number belongs to. 2068 * @param alphaTag alpha-tagging of the dailing nubmer 2069 * @param number The dialing number 2070 * @return true if the operation was executed correctly. 2071 * @hide 2072 */ 2073 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, String number) { 2074 try { 2075 ITelephony telephony = getITelephony(); 2076 if (telephony != null) 2077 return telephony.setLine1NumberForDisplayForSubscriber(subId, alphaTag, number); 2078 } catch (RemoteException ex) { 2079 } catch (NullPointerException ex) { 2080 } 2081 return false; 2082 } 2083 2084 /** 2085 * Returns the alphabetic identifier associated with the line 1 number. 2086 * Return null if it is unavailable. 2087 * <p> 2088 * Requires Permission: 2089 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2090 * @hide 2091 * nobody seems to call this. 2092 */ 2093 public String getLine1AlphaTag() { 2094 return getLine1AlphaTagForSubscriber(getDefaultSubscription()); 2095 } 2096 2097 /** 2098 * Returns the alphabetic identifier associated with the line 1 number 2099 * for a subscription. 2100 * Return null if it is unavailable. 2101 * <p> 2102 * Requires Permission: 2103 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2104 * @param subId whose alphabetic identifier associated with line 1 is returned 2105 * nobody seems to call this. 2106 */ 2107 /** {@hide} */ 2108 public String getLine1AlphaTagForSubscriber(int subId) { 2109 String alphaTag = null; 2110 try { 2111 ITelephony telephony = getITelephony(); 2112 if (telephony != null) 2113 alphaTag = telephony.getLine1AlphaTagForDisplay(subId, 2114 mContext.getOpPackageName()); 2115 } catch (RemoteException ex) { 2116 } catch (NullPointerException ex) { 2117 } 2118 if (alphaTag != null) { 2119 return alphaTag; 2120 } 2121 try { 2122 IPhoneSubInfo info = getSubscriberInfo(); 2123 if (info == null) 2124 return null; 2125 return info.getLine1AlphaTagForSubscriber(subId); 2126 } catch (RemoteException ex) { 2127 return null; 2128 } catch (NullPointerException ex) { 2129 // This could happen before phone restarts due to crashing 2130 return null; 2131 } 2132 } 2133 2134 /** 2135 * Return the set of subscriber IDs that should be considered as "merged 2136 * together" for data usage purposes. This is commonly {@code null} to 2137 * indicate no merging is required. Any returned subscribers are sorted in a 2138 * deterministic order. 2139 * 2140 * @hide 2141 */ 2142 public @Nullable String[] getMergedSubscriberIds() { 2143 try { 2144 ITelephony telephony = getITelephony(); 2145 if (telephony != null) 2146 return telephony.getMergedSubscriberIds(); 2147 } catch (RemoteException ex) { 2148 } catch (NullPointerException ex) { 2149 } 2150 return null; 2151 } 2152 2153 /** 2154 * Returns the MSISDN string. 2155 * for a GSM phone. Return null if it is unavailable. 2156 * <p> 2157 * Requires Permission: 2158 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2159 * 2160 * @hide 2161 */ 2162 public String getMsisdn() { 2163 return getMsisdn(getDefaultSubscription()); 2164 } 2165 2166 /** 2167 * Returns the MSISDN string. 2168 * for a GSM phone. Return null if it is unavailable. 2169 * <p> 2170 * Requires Permission: 2171 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2172 * 2173 * @param subId for which msisdn is returned 2174 */ 2175 /** {@hide} */ 2176 public String getMsisdn(int subId) { 2177 try { 2178 IPhoneSubInfo info = getSubscriberInfo(); 2179 if (info == null) 2180 return null; 2181 return info.getMsisdnForSubscriber(subId); 2182 } catch (RemoteException ex) { 2183 return null; 2184 } catch (NullPointerException ex) { 2185 // This could happen before phone restarts due to crashing 2186 return null; 2187 } 2188 } 2189 2190 /** 2191 * Returns the voice mail number. Return null if it is unavailable. 2192 * <p> 2193 * Requires Permission: 2194 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2195 */ 2196 public String getVoiceMailNumber() { 2197 return getVoiceMailNumber(getDefaultSubscription()); 2198 } 2199 2200 /** 2201 * Returns the voice mail number for a subscription. 2202 * Return null if it is unavailable. 2203 * <p> 2204 * Requires Permission: 2205 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2206 * @param subId whose voice mail number is returned 2207 */ 2208 /** {@hide} */ 2209 public String getVoiceMailNumber(int subId) { 2210 try { 2211 IPhoneSubInfo info = getSubscriberInfo(); 2212 if (info == null) 2213 return null; 2214 return info.getVoiceMailNumberForSubscriber(subId); 2215 } catch (RemoteException ex) { 2216 return null; 2217 } catch (NullPointerException ex) { 2218 // This could happen before phone restarts due to crashing 2219 return null; 2220 } 2221 } 2222 2223 /** 2224 * Returns the complete voice mail number. Return null if it is unavailable. 2225 * <p> 2226 * Requires Permission: 2227 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 2228 * 2229 * @hide 2230 */ 2231 public String getCompleteVoiceMailNumber() { 2232 return getCompleteVoiceMailNumber(getDefaultSubscription()); 2233 } 2234 2235 /** 2236 * Returns the complete voice mail number. Return null if it is unavailable. 2237 * <p> 2238 * Requires Permission: 2239 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 2240 * 2241 * @param subId 2242 */ 2243 /** {@hide} */ 2244 public String getCompleteVoiceMailNumber(int subId) { 2245 try { 2246 IPhoneSubInfo info = getSubscriberInfo(); 2247 if (info == null) 2248 return null; 2249 return info.getCompleteVoiceMailNumberForSubscriber(subId); 2250 } catch (RemoteException ex) { 2251 return null; 2252 } catch (NullPointerException ex) { 2253 // This could happen before phone restarts due to crashing 2254 return null; 2255 } 2256 } 2257 2258 /** 2259 * Sets the voice mail number. 2260 * 2261 * <p>Requires that the calling app has carrier privileges. 2262 * @see #hasCarrierPrivileges 2263 * 2264 * @param alphaTag The alpha tag to display. 2265 * @param number The voicemail number. 2266 */ 2267 public boolean setVoiceMailNumber(String alphaTag, String number) { 2268 return setVoiceMailNumber(getDefaultSubscription(), alphaTag, number); 2269 } 2270 2271 /** 2272 * Sets the voicemail number for the given subscriber. 2273 * 2274 * <p>Requires that the calling app has carrier privileges. 2275 * @see #hasCarrierPrivileges 2276 * 2277 * @param subId The subscription id. 2278 * @param alphaTag The alpha tag to display. 2279 * @param number The voicemail number. 2280 */ 2281 /** {@hide} */ 2282 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { 2283 try { 2284 ITelephony telephony = getITelephony(); 2285 if (telephony != null) 2286 return telephony.setVoiceMailNumber(subId, alphaTag, number); 2287 } catch (RemoteException ex) { 2288 } catch (NullPointerException ex) { 2289 } 2290 return false; 2291 } 2292 2293 /** 2294 * Returns the voice mail count. Return 0 if unavailable, -1 if there are unread voice messages 2295 * but the count is unknown. 2296 * <p> 2297 * Requires Permission: 2298 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2299 * @hide 2300 */ 2301 public int getVoiceMessageCount() { 2302 return getVoiceMessageCount(getDefaultSubscription()); 2303 } 2304 2305 /** 2306 * Returns the voice mail count for a subscription. Return 0 if unavailable. 2307 * <p> 2308 * Requires Permission: 2309 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2310 * @param subId whose voice message count is returned 2311 */ 2312 /** {@hide} */ 2313 public int getVoiceMessageCount(int subId) { 2314 try { 2315 ITelephony telephony = getITelephony(); 2316 if (telephony == null) 2317 return 0; 2318 return telephony.getVoiceMessageCountForSubscriber(subId); 2319 } catch (RemoteException ex) { 2320 return 0; 2321 } catch (NullPointerException ex) { 2322 // This could happen before phone restarts due to crashing 2323 return 0; 2324 } 2325 } 2326 2327 /** 2328 * Retrieves the alphabetic identifier associated with the voice 2329 * mail number. 2330 * <p> 2331 * Requires Permission: 2332 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2333 */ 2334 public String getVoiceMailAlphaTag() { 2335 return getVoiceMailAlphaTag(getDefaultSubscription()); 2336 } 2337 2338 /** 2339 * Retrieves the alphabetic identifier associated with the voice 2340 * mail number for a subscription. 2341 * <p> 2342 * Requires Permission: 2343 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2344 * @param subId whose alphabetic identifier associated with the 2345 * voice mail number is returned 2346 */ 2347 /** {@hide} */ 2348 public String getVoiceMailAlphaTag(int subId) { 2349 try { 2350 IPhoneSubInfo info = getSubscriberInfo(); 2351 if (info == null) 2352 return null; 2353 return info.getVoiceMailAlphaTagForSubscriber(subId); 2354 } catch (RemoteException ex) { 2355 return null; 2356 } catch (NullPointerException ex) { 2357 // This could happen before phone restarts due to crashing 2358 return null; 2359 } 2360 } 2361 2362 /** 2363 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 2364 * @return the IMPI, or null if not present or not loaded 2365 * @hide 2366 */ 2367 public String getIsimImpi() { 2368 try { 2369 IPhoneSubInfo info = getSubscriberInfo(); 2370 if (info == null) 2371 return null; 2372 return info.getIsimImpi(); 2373 } catch (RemoteException ex) { 2374 return null; 2375 } catch (NullPointerException ex) { 2376 // This could happen before phone restarts due to crashing 2377 return null; 2378 } 2379 } 2380 2381 /** 2382 * Returns the IMS home network domain name that was loaded from the ISIM. 2383 * @return the IMS domain name, or null if not present or not loaded 2384 * @hide 2385 */ 2386 public String getIsimDomain() { 2387 try { 2388 IPhoneSubInfo info = getSubscriberInfo(); 2389 if (info == null) 2390 return null; 2391 return info.getIsimDomain(); 2392 } catch (RemoteException ex) { 2393 return null; 2394 } catch (NullPointerException ex) { 2395 // This could happen before phone restarts due to crashing 2396 return null; 2397 } 2398 } 2399 2400 /** 2401 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 2402 * @return an array of IMPU strings, with one IMPU per string, or null if 2403 * not present or not loaded 2404 * @hide 2405 */ 2406 public String[] getIsimImpu() { 2407 try { 2408 IPhoneSubInfo info = getSubscriberInfo(); 2409 if (info == null) 2410 return null; 2411 return info.getIsimImpu(); 2412 } catch (RemoteException ex) { 2413 return null; 2414 } catch (NullPointerException ex) { 2415 // This could happen before phone restarts due to crashing 2416 return null; 2417 } 2418 } 2419 2420 /** 2421 * @hide 2422 */ 2423 private IPhoneSubInfo getSubscriberInfo() { 2424 // get it each time because that process crashes a lot 2425 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 2426 } 2427 2428 /** Device call state: No activity. */ 2429 public static final int CALL_STATE_IDLE = 0; 2430 /** Device call state: Ringing. A new call arrived and is 2431 * ringing or waiting. In the latter case, another call is 2432 * already active. */ 2433 public static final int CALL_STATE_RINGING = 1; 2434 /** Device call state: Off-hook. At least one call exists 2435 * that is dialing, active, or on hold, and no calls are ringing 2436 * or waiting. */ 2437 public static final int CALL_STATE_OFFHOOK = 2; 2438 2439 /** 2440 * Returns a constant indicating the call state (cellular) on the device. 2441 */ 2442 public int getCallState() { 2443 return getCallState(getDefaultSubscription()); 2444 } 2445 2446 /** 2447 * Returns a constant indicating the call state (cellular) on the device 2448 * for a subscription. 2449 * 2450 * @param subId whose call state is returned 2451 */ 2452 /** {@hide} */ 2453 public int getCallState(int subId) { 2454 try { 2455 ITelephony telephony = getITelephony(); 2456 if (telephony == null) 2457 return CALL_STATE_IDLE; 2458 return telephony.getCallStateForSubscriber(subId); 2459 } catch (RemoteException ex) { 2460 // the phone process is restarting. 2461 return CALL_STATE_IDLE; 2462 } catch (NullPointerException ex) { 2463 // the phone process is restarting. 2464 return CALL_STATE_IDLE; 2465 } 2466 } 2467 2468 /** Data connection activity: No traffic. */ 2469 public static final int DATA_ACTIVITY_NONE = 0x00000000; 2470 /** Data connection activity: Currently receiving IP PPP traffic. */ 2471 public static final int DATA_ACTIVITY_IN = 0x00000001; 2472 /** Data connection activity: Currently sending IP PPP traffic. */ 2473 public static final int DATA_ACTIVITY_OUT = 0x00000002; 2474 /** Data connection activity: Currently both sending and receiving 2475 * IP PPP traffic. */ 2476 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 2477 /** 2478 * Data connection is active, but physical link is down 2479 */ 2480 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 2481 2482 /** 2483 * Returns a constant indicating the type of activity on a data connection 2484 * (cellular). 2485 * 2486 * @see #DATA_ACTIVITY_NONE 2487 * @see #DATA_ACTIVITY_IN 2488 * @see #DATA_ACTIVITY_OUT 2489 * @see #DATA_ACTIVITY_INOUT 2490 * @see #DATA_ACTIVITY_DORMANT 2491 */ 2492 public int getDataActivity() { 2493 try { 2494 ITelephony telephony = getITelephony(); 2495 if (telephony == null) 2496 return DATA_ACTIVITY_NONE; 2497 return telephony.getDataActivity(); 2498 } catch (RemoteException ex) { 2499 // the phone process is restarting. 2500 return DATA_ACTIVITY_NONE; 2501 } catch (NullPointerException ex) { 2502 // the phone process is restarting. 2503 return DATA_ACTIVITY_NONE; 2504 } 2505 } 2506 2507 /** Data connection state: Unknown. Used before we know the state. 2508 * @hide 2509 */ 2510 public static final int DATA_UNKNOWN = -1; 2511 /** Data connection state: Disconnected. IP traffic not available. */ 2512 public static final int DATA_DISCONNECTED = 0; 2513 /** Data connection state: Currently setting up a data connection. */ 2514 public static final int DATA_CONNECTING = 1; 2515 /** Data connection state: Connected. IP traffic should be available. */ 2516 public static final int DATA_CONNECTED = 2; 2517 /** Data connection state: Suspended. The connection is up, but IP 2518 * traffic is temporarily unavailable. For example, in a 2G network, 2519 * data activity may be suspended when a voice call arrives. */ 2520 public static final int DATA_SUSPENDED = 3; 2521 2522 /** 2523 * Returns a constant indicating the current data connection state 2524 * (cellular). 2525 * 2526 * @see #DATA_DISCONNECTED 2527 * @see #DATA_CONNECTING 2528 * @see #DATA_CONNECTED 2529 * @see #DATA_SUSPENDED 2530 */ 2531 public int getDataState() { 2532 try { 2533 ITelephony telephony = getITelephony(); 2534 if (telephony == null) 2535 return DATA_DISCONNECTED; 2536 return telephony.getDataState(); 2537 } catch (RemoteException ex) { 2538 // the phone process is restarting. 2539 return DATA_DISCONNECTED; 2540 } catch (NullPointerException ex) { 2541 return DATA_DISCONNECTED; 2542 } 2543 } 2544 2545 /** 2546 * @hide 2547 */ 2548 private ITelephony getITelephony() { 2549 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 2550 } 2551 2552 /** 2553 * @hide 2554 */ 2555 private ITelecomService getTelecomService() { 2556 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); 2557 } 2558 2559 // 2560 // 2561 // PhoneStateListener 2562 // 2563 // 2564 2565 /** 2566 * Registers a listener object to receive notification of changes 2567 * in specified telephony states. 2568 * <p> 2569 * To register a listener, pass a {@link PhoneStateListener} 2570 * and specify at least one telephony state of interest in 2571 * the events argument. 2572 * 2573 * At registration, and when a specified telephony state 2574 * changes, the telephony manager invokes the appropriate 2575 * callback method on the listener object and passes the 2576 * current (updated) values. 2577 * <p> 2578 * To unregister a listener, pass the listener object and set the 2579 * events argument to 2580 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 2581 * 2582 * @param listener The {@link PhoneStateListener} object to register 2583 * (or unregister) 2584 * @param events The telephony state(s) of interest to the listener, 2585 * as a bitwise-OR combination of {@link PhoneStateListener} 2586 * LISTEN_ flags. 2587 */ 2588 public void listen(PhoneStateListener listener, int events) { 2589 if (mContext == null) return; 2590 try { 2591 Boolean notifyNow = (getITelephony() != null); 2592 sRegistry.listenForSubscriber(listener.mSubId, mContext.getOpPackageName(), 2593 listener.callback, events, notifyNow); 2594 } catch (RemoteException ex) { 2595 // system process dead 2596 } catch (NullPointerException ex) { 2597 // system process dead 2598 } 2599 } 2600 2601 /** 2602 * Returns the CDMA ERI icon index to display 2603 * 2604 * @hide 2605 */ 2606 public int getCdmaEriIconIndex() { 2607 return getCdmaEriIconIndex(getDefaultSubscription()); 2608 } 2609 2610 /** 2611 * Returns the CDMA ERI icon index to display for a subscription 2612 */ 2613 /** {@hide} */ 2614 public int getCdmaEriIconIndex(int subId) { 2615 try { 2616 ITelephony telephony = getITelephony(); 2617 if (telephony == null) 2618 return -1; 2619 return telephony.getCdmaEriIconIndexForSubscriber(subId); 2620 } catch (RemoteException ex) { 2621 // the phone process is restarting. 2622 return -1; 2623 } catch (NullPointerException ex) { 2624 return -1; 2625 } 2626 } 2627 2628 /** 2629 * Returns the CDMA ERI icon mode, 2630 * 0 - ON 2631 * 1 - FLASHING 2632 * 2633 * @hide 2634 */ 2635 public int getCdmaEriIconMode() { 2636 return getCdmaEriIconMode(getDefaultSubscription()); 2637 } 2638 2639 /** 2640 * Returns the CDMA ERI icon mode for a subscription. 2641 * 0 - ON 2642 * 1 - FLASHING 2643 */ 2644 /** {@hide} */ 2645 public int getCdmaEriIconMode(int subId) { 2646 try { 2647 ITelephony telephony = getITelephony(); 2648 if (telephony == null) 2649 return -1; 2650 return telephony.getCdmaEriIconModeForSubscriber(subId); 2651 } catch (RemoteException ex) { 2652 // the phone process is restarting. 2653 return -1; 2654 } catch (NullPointerException ex) { 2655 return -1; 2656 } 2657 } 2658 2659 /** 2660 * Returns the CDMA ERI text, 2661 * 2662 * @hide 2663 */ 2664 public String getCdmaEriText() { 2665 return getCdmaEriText(getDefaultSubscription()); 2666 } 2667 2668 /** 2669 * Returns the CDMA ERI text, of a subscription 2670 * 2671 */ 2672 /** {@hide} */ 2673 public String getCdmaEriText(int subId) { 2674 try { 2675 ITelephony telephony = getITelephony(); 2676 if (telephony == null) 2677 return null; 2678 return telephony.getCdmaEriTextForSubscriber(subId); 2679 } catch (RemoteException ex) { 2680 // the phone process is restarting. 2681 return null; 2682 } catch (NullPointerException ex) { 2683 return null; 2684 } 2685 } 2686 2687 /** 2688 * @return true if the current device is "voice capable". 2689 * <p> 2690 * "Voice capable" means that this device supports circuit-switched 2691 * (i.e. voice) phone calls over the telephony network, and is allowed 2692 * to display the in-call UI while a cellular voice call is active. 2693 * This will be false on "data only" devices which can't make voice 2694 * calls and don't support any in-call UI. 2695 * <p> 2696 * Note: the meaning of this flag is subtly different from the 2697 * PackageManager.FEATURE_TELEPHONY system feature, which is available 2698 * on any device with a telephony radio, even if the device is 2699 * data-only. 2700 */ 2701 public boolean isVoiceCapable() { 2702 if (mContext == null) return true; 2703 return mContext.getResources().getBoolean( 2704 com.android.internal.R.bool.config_voice_capable); 2705 } 2706 2707 /** 2708 * @return true if the current device supports sms service. 2709 * <p> 2710 * If true, this means that the device supports both sending and 2711 * receiving sms via the telephony network. 2712 * <p> 2713 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 2714 * disabled when device doesn't support sms. 2715 */ 2716 public boolean isSmsCapable() { 2717 if (mContext == null) return true; 2718 return mContext.getResources().getBoolean( 2719 com.android.internal.R.bool.config_sms_capable); 2720 } 2721 2722 /** 2723 * Returns all observed cell information from all radios on the 2724 * device including the primary and neighboring cells. This does 2725 * not cause or change the rate of PhoneStateListner#onCellInfoChanged. 2726 *<p> 2727 * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm}, 2728 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 2729 * {@link android.telephony.CellInfoLte CellInfoLte} and 2730 * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination. 2731 * Specifically on devices with multiple radios it is typical to see instances of 2732 * one or more of any these in the list. In addition 0, 1 or more CellInfo 2733 * objects may return isRegistered() true. 2734 *<p> 2735 * This is preferred over using getCellLocation although for older 2736 * devices this may return null in which case getCellLocation should 2737 * be called. 2738 *<p> 2739 * @return List of CellInfo or null if info unavailable. 2740 * 2741 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 2742 */ 2743 public List<CellInfo> getAllCellInfo() { 2744 try { 2745 ITelephony telephony = getITelephony(); 2746 if (telephony == null) 2747 return null; 2748 return telephony.getAllCellInfo(mContext.getOpPackageName()); 2749 } catch (RemoteException ex) { 2750 return null; 2751 } catch (NullPointerException ex) { 2752 return null; 2753 } 2754 } 2755 2756 /** 2757 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 2758 * PhoneStateListener.onCellInfoChanged} will be invoked. 2759 *<p> 2760 * The default, 0, means invoke onCellInfoChanged when any of the reported 2761 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 2762 * A onCellInfoChanged. 2763 *<p> 2764 * @param rateInMillis the rate 2765 * 2766 * @hide 2767 */ 2768 public void setCellInfoListRate(int rateInMillis) { 2769 try { 2770 ITelephony telephony = getITelephony(); 2771 if (telephony != null) 2772 telephony.setCellInfoListRate(rateInMillis); 2773 } catch (RemoteException ex) { 2774 } catch (NullPointerException ex) { 2775 } 2776 } 2777 2778 /** 2779 * Returns the MMS user agent. 2780 */ 2781 public String getMmsUserAgent() { 2782 if (mContext == null) return null; 2783 return mContext.getResources().getString( 2784 com.android.internal.R.string.config_mms_user_agent); 2785 } 2786 2787 /** 2788 * Returns the MMS user agent profile URL. 2789 */ 2790 public String getMmsUAProfUrl() { 2791 if (mContext == null) return null; 2792 return mContext.getResources().getString( 2793 com.android.internal.R.string.config_mms_user_agent_profile_url); 2794 } 2795 2796 /** 2797 * Opens a logical channel to the ICC card. 2798 * 2799 * Input parameters equivalent to TS 27.007 AT+CCHO command. 2800 * 2801 * <p>Requires Permission: 2802 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2803 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2804 * 2805 * @param AID Application id. See ETSI 102.221 and 101.220. 2806 * @return an IccOpenLogicalChannelResponse object. 2807 */ 2808 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { 2809 try { 2810 ITelephony telephony = getITelephony(); 2811 if (telephony != null) 2812 return telephony.iccOpenLogicalChannel(AID); 2813 } catch (RemoteException ex) { 2814 } catch (NullPointerException ex) { 2815 } 2816 return null; 2817 } 2818 2819 /** 2820 * Closes a previously opened logical channel to the ICC card. 2821 * 2822 * Input parameters equivalent to TS 27.007 AT+CCHC command. 2823 * 2824 * <p>Requires Permission: 2825 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2826 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2827 * 2828 * @param channel is the channel id to be closed as retruned by a successful 2829 * iccOpenLogicalChannel. 2830 * @return true if the channel was closed successfully. 2831 */ 2832 public boolean iccCloseLogicalChannel(int channel) { 2833 try { 2834 ITelephony telephony = getITelephony(); 2835 if (telephony != null) 2836 return telephony.iccCloseLogicalChannel(channel); 2837 } catch (RemoteException ex) { 2838 } catch (NullPointerException ex) { 2839 } 2840 return false; 2841 } 2842 2843 /** 2844 * Transmit an APDU to the ICC card over a logical channel. 2845 * 2846 * Input parameters equivalent to TS 27.007 AT+CGLA command. 2847 * 2848 * <p>Requires Permission: 2849 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2850 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2851 * 2852 * @param channel is the channel id to be closed as returned by a successful 2853 * iccOpenLogicalChannel. 2854 * @param cla Class of the APDU command. 2855 * @param instruction Instruction of the APDU command. 2856 * @param p1 P1 value of the APDU command. 2857 * @param p2 P2 value of the APDU command. 2858 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2859 * is sent to the SIM. 2860 * @param data Data to be sent with the APDU. 2861 * @return The APDU response from the ICC card with the status appended at 2862 * the end. 2863 */ 2864 public String iccTransmitApduLogicalChannel(int channel, int cla, 2865 int instruction, int p1, int p2, int p3, String data) { 2866 try { 2867 ITelephony telephony = getITelephony(); 2868 if (telephony != null) 2869 return telephony.iccTransmitApduLogicalChannel(channel, cla, 2870 instruction, p1, p2, p3, data); 2871 } catch (RemoteException ex) { 2872 } catch (NullPointerException ex) { 2873 } 2874 return ""; 2875 } 2876 2877 /** 2878 * Transmit an APDU to the ICC card over the basic channel. 2879 * 2880 * Input parameters equivalent to TS 27.007 AT+CSIM command. 2881 * 2882 * <p>Requires Permission: 2883 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2884 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2885 * 2886 * @param cla Class of the APDU command. 2887 * @param instruction Instruction of the APDU command. 2888 * @param p1 P1 value of the APDU command. 2889 * @param p2 P2 value of the APDU command. 2890 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2891 * is sent to the SIM. 2892 * @param data Data to be sent with the APDU. 2893 * @return The APDU response from the ICC card with the status appended at 2894 * the end. 2895 */ 2896 public String iccTransmitApduBasicChannel(int cla, 2897 int instruction, int p1, int p2, int p3, String data) { 2898 try { 2899 ITelephony telephony = getITelephony(); 2900 if (telephony != null) 2901 return telephony.iccTransmitApduBasicChannel(cla, 2902 instruction, p1, p2, p3, data); 2903 } catch (RemoteException ex) { 2904 } catch (NullPointerException ex) { 2905 } 2906 return ""; 2907 } 2908 2909 /** 2910 * Returns the response APDU for a command APDU sent through SIM_IO. 2911 * 2912 * <p>Requires Permission: 2913 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2914 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2915 * 2916 * @param fileID 2917 * @param command 2918 * @param p1 P1 value of the APDU command. 2919 * @param p2 P2 value of the APDU command. 2920 * @param p3 P3 value of the APDU command. 2921 * @param filePath 2922 * @return The APDU response. 2923 */ 2924 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 2925 String filePath) { 2926 try { 2927 ITelephony telephony = getITelephony(); 2928 if (telephony != null) 2929 return telephony.iccExchangeSimIO(fileID, command, p1, p2, p3, filePath); 2930 } catch (RemoteException ex) { 2931 } catch (NullPointerException ex) { 2932 } 2933 return null; 2934 } 2935 2936 /** 2937 * Send ENVELOPE to the SIM and return the response. 2938 * 2939 * <p>Requires Permission: 2940 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2941 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2942 * 2943 * @param content String containing SAT/USAT response in hexadecimal 2944 * format starting with command tag. See TS 102 223 for 2945 * details. 2946 * @return The APDU response from the ICC card in hexadecimal format 2947 * with the last 4 bytes being the status word. If the command fails, 2948 * returns an empty string. 2949 */ 2950 public String sendEnvelopeWithStatus(String content) { 2951 try { 2952 ITelephony telephony = getITelephony(); 2953 if (telephony != null) 2954 return telephony.sendEnvelopeWithStatus(content); 2955 } catch (RemoteException ex) { 2956 } catch (NullPointerException ex) { 2957 } 2958 return ""; 2959 } 2960 2961 /** 2962 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 2963 * Used for device configuration by some CDMA operators. 2964 * <p> 2965 * Requires Permission: 2966 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2967 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2968 * 2969 * @param itemID the ID of the item to read. 2970 * @return the NV item as a String, or null on any failure. 2971 * 2972 * @hide 2973 */ 2974 public String nvReadItem(int itemID) { 2975 try { 2976 ITelephony telephony = getITelephony(); 2977 if (telephony != null) 2978 return telephony.nvReadItem(itemID); 2979 } catch (RemoteException ex) { 2980 Rlog.e(TAG, "nvReadItem RemoteException", ex); 2981 } catch (NullPointerException ex) { 2982 Rlog.e(TAG, "nvReadItem NPE", ex); 2983 } 2984 return ""; 2985 } 2986 2987 /** 2988 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 2989 * Used for device configuration by some CDMA operators. 2990 * <p> 2991 * Requires Permission: 2992 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2993 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2994 * 2995 * @param itemID the ID of the item to read. 2996 * @param itemValue the value to write, as a String. 2997 * @return true on success; false on any failure. 2998 * 2999 * @hide 3000 */ 3001 public boolean nvWriteItem(int itemID, String itemValue) { 3002 try { 3003 ITelephony telephony = getITelephony(); 3004 if (telephony != null) 3005 return telephony.nvWriteItem(itemID, itemValue); 3006 } catch (RemoteException ex) { 3007 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 3008 } catch (NullPointerException ex) { 3009 Rlog.e(TAG, "nvWriteItem NPE", ex); 3010 } 3011 return false; 3012 } 3013 3014 /** 3015 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 3016 * Used for device configuration by some CDMA operators. 3017 * <p> 3018 * Requires Permission: 3019 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3020 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3021 * 3022 * @param preferredRoamingList byte array containing the new PRL. 3023 * @return true on success; false on any failure. 3024 * 3025 * @hide 3026 */ 3027 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 3028 try { 3029 ITelephony telephony = getITelephony(); 3030 if (telephony != null) 3031 return telephony.nvWriteCdmaPrl(preferredRoamingList); 3032 } catch (RemoteException ex) { 3033 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 3034 } catch (NullPointerException ex) { 3035 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 3036 } 3037 return false; 3038 } 3039 3040 /** 3041 * Perform the specified type of NV config reset. The radio will be taken offline 3042 * and the device must be rebooted after the operation. Used for device 3043 * configuration by some CDMA operators. 3044 * <p> 3045 * Requires Permission: 3046 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3047 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3048 * 3049 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 3050 * @return true on success; false on any failure. 3051 * 3052 * @hide 3053 */ 3054 public boolean nvResetConfig(int resetType) { 3055 try { 3056 ITelephony telephony = getITelephony(); 3057 if (telephony != null) 3058 return telephony.nvResetConfig(resetType); 3059 } catch (RemoteException ex) { 3060 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 3061 } catch (NullPointerException ex) { 3062 Rlog.e(TAG, "nvResetConfig NPE", ex); 3063 } 3064 return false; 3065 } 3066 3067 /** 3068 * Returns Default subscription. 3069 */ 3070 private static int getDefaultSubscription() { 3071 return SubscriptionManager.getDefaultSubId(); 3072 } 3073 3074 /** 3075 * Returns Default phone. 3076 */ 3077 private static int getDefaultPhone() { 3078 return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubId()); 3079 } 3080 3081 /** {@hide} */ 3082 public int getDefaultSim() { 3083 return SubscriptionManager.getSlotId(SubscriptionManager.getDefaultSubId()); 3084 } 3085 3086 /** 3087 * Sets the telephony property with the value specified. 3088 * 3089 * @hide 3090 */ 3091 public static void setTelephonyProperty(int phoneId, String property, String value) { 3092 String propVal = ""; 3093 String p[] = null; 3094 String prop = SystemProperties.get(property); 3095 3096 if (value == null) { 3097 value = ""; 3098 } 3099 3100 if (prop != null) { 3101 p = prop.split(","); 3102 } 3103 3104 if (!SubscriptionManager.isValidPhoneId(phoneId)) { 3105 Rlog.d(TAG, "setTelephonyProperty: invalid phoneId=" + phoneId + 3106 " property=" + property + " value: " + value + " prop=" + prop); 3107 return; 3108 } 3109 3110 for (int i = 0; i < phoneId; i++) { 3111 String str = ""; 3112 if ((p != null) && (i < p.length)) { 3113 str = p[i]; 3114 } 3115 propVal = propVal + str + ","; 3116 } 3117 3118 propVal = propVal + value; 3119 if (p != null) { 3120 for (int i = phoneId + 1; i < p.length; i++) { 3121 propVal = propVal + "," + p[i]; 3122 } 3123 } 3124 3125 if (property.length() > SystemProperties.PROP_NAME_MAX 3126 || propVal.length() > SystemProperties.PROP_VALUE_MAX) { 3127 Rlog.d(TAG, "setTelephonyProperty: property to long phoneId=" + phoneId + 3128 " property=" + property + " value: " + value + " propVal=" + propVal); 3129 return; 3130 } 3131 3132 Rlog.d(TAG, "setTelephonyProperty: success phoneId=" + phoneId + 3133 " property=" + property + " value: " + value + " propVal=" + propVal); 3134 SystemProperties.set(property, propVal); 3135 } 3136 3137 /** 3138 * Convenience function for retrieving a value from the secure settings 3139 * value list as an integer. Note that internally setting values are 3140 * always stored as strings; this function converts the string to an 3141 * integer for you. 3142 * <p> 3143 * This version does not take a default value. If the setting has not 3144 * been set, or the string value is not a number, 3145 * it throws {@link SettingNotFoundException}. 3146 * 3147 * @param cr The ContentResolver to access. 3148 * @param name The name of the setting to retrieve. 3149 * @param index The index of the list 3150 * 3151 * @throws SettingNotFoundException Thrown if a setting by the given 3152 * name can't be found or the setting value is not an integer. 3153 * 3154 * @return The value at the given index of settings. 3155 * @hide 3156 */ 3157 public static int getIntAtIndex(android.content.ContentResolver cr, 3158 String name, int index) 3159 throws android.provider.Settings.SettingNotFoundException { 3160 String v = android.provider.Settings.Global.getString(cr, name); 3161 if (v != null) { 3162 String valArray[] = v.split(","); 3163 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 3164 try { 3165 return Integer.parseInt(valArray[index]); 3166 } catch (NumberFormatException e) { 3167 //Log.e(TAG, "Exception while parsing Integer: ", e); 3168 } 3169 } 3170 } 3171 throw new android.provider.Settings.SettingNotFoundException(name); 3172 } 3173 3174 /** 3175 * Convenience function for updating settings value as coma separated 3176 * integer values. This will either create a new entry in the table if the 3177 * given name does not exist, or modify the value of the existing row 3178 * with that name. Note that internally setting values are always 3179 * stored as strings, so this function converts the given value to a 3180 * string before storing it. 3181 * 3182 * @param cr The ContentResolver to access. 3183 * @param name The name of the setting to modify. 3184 * @param index The index of the list 3185 * @param value The new value for the setting to be added to the list. 3186 * @return true if the value was set, false on database errors 3187 * @hide 3188 */ 3189 public static boolean putIntAtIndex(android.content.ContentResolver cr, 3190 String name, int index, int value) { 3191 String data = ""; 3192 String valArray[] = null; 3193 String v = android.provider.Settings.Global.getString(cr, name); 3194 3195 if (index == Integer.MAX_VALUE) { 3196 throw new RuntimeException("putIntAtIndex index == MAX_VALUE index=" + index); 3197 } 3198 if (index < 0) { 3199 throw new RuntimeException("putIntAtIndex index < 0 index=" + index); 3200 } 3201 if (v != null) { 3202 valArray = v.split(","); 3203 } 3204 3205 // Copy the elements from valArray till index 3206 for (int i = 0; i < index; i++) { 3207 String str = ""; 3208 if ((valArray != null) && (i < valArray.length)) { 3209 str = valArray[i]; 3210 } 3211 data = data + str + ","; 3212 } 3213 3214 data = data + value; 3215 3216 // Copy the remaining elements from valArray if any. 3217 if (valArray != null) { 3218 for (int i = index+1; i < valArray.length; i++) { 3219 data = data + "," + valArray[i]; 3220 } 3221 } 3222 return android.provider.Settings.Global.putString(cr, name, data); 3223 } 3224 3225 /** 3226 * Gets the telephony property. 3227 * 3228 * @hide 3229 */ 3230 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 3231 String propVal = null; 3232 String prop = SystemProperties.get(property); 3233 if ((prop != null) && (prop.length() > 0)) { 3234 String values[] = prop.split(","); 3235 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 3236 propVal = values[phoneId]; 3237 } 3238 } 3239 return propVal == null ? defaultVal : propVal; 3240 } 3241 3242 /** @hide */ 3243 public int getSimCount() { 3244 // FIXME Need to get it from Telephony Dev Controller when that gets implemented! 3245 // and then this method shouldn't be used at all! 3246 if(isMultiSimEnabled()) { 3247 return 2; 3248 } else { 3249 return 1; 3250 } 3251 } 3252 3253 /** 3254 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 3255 * @return IMS Service Table or null if not present or not loaded 3256 * @hide 3257 */ 3258 public String getIsimIst() { 3259 try { 3260 IPhoneSubInfo info = getSubscriberInfo(); 3261 if (info == null) 3262 return null; 3263 return info.getIsimIst(); 3264 } catch (RemoteException ex) { 3265 return null; 3266 } catch (NullPointerException ex) { 3267 // This could happen before phone restarts due to crashing 3268 return null; 3269 } 3270 } 3271 3272 /** 3273 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 3274 * @return an array of PCSCF strings with one PCSCF per string, or null if 3275 * not present or not loaded 3276 * @hide 3277 */ 3278 public String[] getIsimPcscf() { 3279 try { 3280 IPhoneSubInfo info = getSubscriberInfo(); 3281 if (info == null) 3282 return null; 3283 return info.getIsimPcscf(); 3284 } catch (RemoteException ex) { 3285 return null; 3286 } catch (NullPointerException ex) { 3287 // This could happen before phone restarts due to crashing 3288 return null; 3289 } 3290 } 3291 3292 /** 3293 * Returns the response of ISIM Authetification through RIL. 3294 * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo. 3295 * @return the response of ISIM Authetification, or null if not available 3296 * @hide 3297 * @deprecated 3298 * @see getIccSimChallengeResponse with appType=PhoneConstants.APPTYPE_ISIM 3299 */ 3300 public String getIsimChallengeResponse(String nonce){ 3301 try { 3302 IPhoneSubInfo info = getSubscriberInfo(); 3303 if (info == null) 3304 return null; 3305 return info.getIsimChallengeResponse(nonce); 3306 } catch (RemoteException ex) { 3307 return null; 3308 } catch (NullPointerException ex) { 3309 // This could happen before phone restarts due to crashing 3310 return null; 3311 } 3312 } 3313 3314 /** 3315 * Returns the response of SIM Authentication through RIL. 3316 * Returns null if the Authentication hasn't been successful 3317 * @param subId subscription ID to be queried 3318 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3319 * @param data authentication challenge data 3320 * @return the response of SIM Authentication, or null if not available 3321 * @hide 3322 */ 3323 public String getIccSimChallengeResponse(int subId, int appType, String data) { 3324 try { 3325 IPhoneSubInfo info = getSubscriberInfo(); 3326 if (info == null) 3327 return null; 3328 return info.getIccSimChallengeResponse(subId, appType, data); 3329 } catch (RemoteException ex) { 3330 return null; 3331 } catch (NullPointerException ex) { 3332 // This could happen before phone starts 3333 return null; 3334 } 3335 } 3336 3337 /** 3338 * Returns the response of SIM Authentication through RIL for the default subscription. 3339 * Returns null if the Authentication hasn't been successful 3340 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3341 * @param data authentication challenge data 3342 * @return the response of SIM Authentication, or null if not available 3343 * @hide 3344 */ 3345 public String getIccSimChallengeResponse(int appType, String data) { 3346 return getIccSimChallengeResponse(getDefaultSubscription(), appType, data); 3347 } 3348 3349 /** 3350 * Get P-CSCF address from PCO after data connection is established or modified. 3351 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 3352 * @return array of P-CSCF address 3353 * @hide 3354 */ 3355 public String[] getPcscfAddress(String apnType) { 3356 try { 3357 ITelephony telephony = getITelephony(); 3358 if (telephony == null) 3359 return new String[0]; 3360 return telephony.getPcscfAddress(apnType, mContext.getOpPackageName()); 3361 } catch (RemoteException e) { 3362 return new String[0]; 3363 } 3364 } 3365 3366 /** 3367 * Set IMS registration state 3368 * 3369 * @param Registration state 3370 * @hide 3371 */ 3372 public void setImsRegistrationState(boolean registered) { 3373 try { 3374 ITelephony telephony = getITelephony(); 3375 if (telephony != null) 3376 telephony.setImsRegistrationState(registered); 3377 } catch (RemoteException e) { 3378 } 3379 } 3380 3381 /** 3382 * Get the preferred network type. 3383 * Used for device configuration by some CDMA operators. 3384 * <p> 3385 * Requires Permission: 3386 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3387 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3388 * 3389 * @return the preferred network type, defined in RILConstants.java. 3390 * @hide 3391 */ 3392 public int getPreferredNetworkType(int subId) { 3393 try { 3394 ITelephony telephony = getITelephony(); 3395 if (telephony != null) 3396 return telephony.getPreferredNetworkType(subId); 3397 } catch (RemoteException ex) { 3398 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 3399 } catch (NullPointerException ex) { 3400 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 3401 } 3402 return -1; 3403 } 3404 3405 /** 3406 * Sets the network selection mode to automatic. 3407 * <p> 3408 * Requires Permission: 3409 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3410 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3411 * 3412 * @hide 3413 */ 3414 public void setNetworkSelectionModeAutomatic(int subId) { 3415 try { 3416 ITelephony telephony = getITelephony(); 3417 if (telephony != null) 3418 telephony.setNetworkSelectionModeAutomatic(subId); 3419 } catch (RemoteException ex) { 3420 Rlog.e(TAG, "setNetworkSelectionModeAutomatic RemoteException", ex); 3421 } catch (NullPointerException ex) { 3422 Rlog.e(TAG, "setNetworkSelectionModeAutomatic NPE", ex); 3423 } 3424 } 3425 3426 /** 3427 * Set the preferred network type. 3428 * Used for device configuration by some CDMA operators. 3429 * <p> 3430 * Requires Permission: 3431 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3432 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3433 * 3434 * @param subId the id of the subscription to set the preferred network type for. 3435 * @param networkType the preferred network type, defined in RILConstants.java. 3436 * @return true on success; false on any failure. 3437 * @hide 3438 */ 3439 public boolean setPreferredNetworkType(int subId, int networkType) { 3440 try { 3441 ITelephony telephony = getITelephony(); 3442 if (telephony != null) 3443 return telephony.setPreferredNetworkType(subId, networkType); 3444 } catch (RemoteException ex) { 3445 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 3446 } catch (NullPointerException ex) { 3447 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 3448 } 3449 return false; 3450 } 3451 3452 /** 3453 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 3454 * 3455 * <p> 3456 * Requires that the calling app has carrier privileges. 3457 * @see #hasCarrierPrivileges 3458 * 3459 * @return true on success; false on any failure. 3460 */ 3461 public boolean setPreferredNetworkTypeToGlobal() { 3462 return setPreferredNetworkType(getDefaultSubscription(), 3463 RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); 3464 } 3465 3466 /** 3467 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning 3468 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for 3469 * tethering. 3470 * 3471 * @return 0: Not required. 1: required. 2: Not set. 3472 * @hide 3473 */ 3474 public int getTetherApnRequired() { 3475 try { 3476 ITelephony telephony = getITelephony(); 3477 if (telephony != null) 3478 return telephony.getTetherApnRequired(); 3479 } catch (RemoteException ex) { 3480 Rlog.e(TAG, "hasMatchedTetherApnSetting RemoteException", ex); 3481 } catch (NullPointerException ex) { 3482 Rlog.e(TAG, "hasMatchedTetherApnSetting NPE", ex); 3483 } 3484 return 2; 3485 } 3486 3487 3488 /** 3489 * Values used to return status for hasCarrierPrivileges call. 3490 */ 3491 /** @hide */ 3492 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 3493 /** @hide */ 3494 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 3495 /** @hide */ 3496 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 3497 /** @hide */ 3498 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 3499 3500 /** 3501 * Has the calling application been granted carrier privileges by the carrier. 3502 * 3503 * If any of the packages in the calling UID has carrier privileges, the 3504 * call will return true. This access is granted by the owner of the UICC 3505 * card and does not depend on the registered carrier. 3506 * 3507 * @return true if the app has carrier privileges. 3508 */ 3509 public boolean hasCarrierPrivileges() { 3510 try { 3511 ITelephony telephony = getITelephony(); 3512 if (telephony != null) 3513 return telephony.getCarrierPrivilegeStatus() == CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; 3514 } catch (RemoteException ex) { 3515 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3516 } catch (NullPointerException ex) { 3517 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3518 } 3519 return false; 3520 } 3521 3522 /** 3523 * Override the branding for the current ICCID. 3524 * 3525 * Once set, whenever the SIM is present in the device, the service 3526 * provider name (SPN) and the operator name will both be replaced by the 3527 * brand value input. To unset the value, the same function should be 3528 * called with a null brand value. 3529 * 3530 * <p>Requires that the calling app has carrier privileges. 3531 * @see #hasCarrierPrivileges 3532 * 3533 * @param brand The brand name to display/set. 3534 * @return true if the operation was executed correctly. 3535 */ 3536 public boolean setOperatorBrandOverride(String brand) { 3537 try { 3538 ITelephony telephony = getITelephony(); 3539 if (telephony != null) 3540 return telephony.setOperatorBrandOverride(brand); 3541 } catch (RemoteException ex) { 3542 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 3543 } catch (NullPointerException ex) { 3544 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 3545 } 3546 return false; 3547 } 3548 3549 /** 3550 * Override the roaming preference for the current ICCID. 3551 * 3552 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 3553 * the platform's notion of a network operator being considered roaming or not. 3554 * The change only affects the ICCID that was active when this call was made. 3555 * 3556 * If null is passed as any of the input, the corresponding value is deleted. 3557 * 3558 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 3559 * 3560 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 3561 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 3562 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 3563 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 3564 * @return true if the operation was executed correctly. 3565 * 3566 * @hide 3567 */ 3568 public boolean setRoamingOverride(List<String> gsmRoamingList, 3569 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 3570 List<String> cdmaNonRoamingList) { 3571 try { 3572 ITelephony telephony = getITelephony(); 3573 if (telephony != null) 3574 return telephony.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, 3575 cdmaRoamingList, cdmaNonRoamingList); 3576 } catch (RemoteException ex) { 3577 Rlog.e(TAG, "setRoamingOverride RemoteException", ex); 3578 } catch (NullPointerException ex) { 3579 Rlog.e(TAG, "setRoamingOverride NPE", ex); 3580 } 3581 return false; 3582 } 3583 3584 /** 3585 * Expose the rest of ITelephony to @SystemApi 3586 */ 3587 3588 /** @hide */ 3589 @SystemApi 3590 public String getCdmaMdn() { 3591 return getCdmaMdn(getDefaultSubscription()); 3592 } 3593 3594 /** @hide */ 3595 @SystemApi 3596 public String getCdmaMdn(int subId) { 3597 try { 3598 ITelephony telephony = getITelephony(); 3599 if (telephony == null) 3600 return null; 3601 return telephony.getCdmaMdn(subId); 3602 } catch (RemoteException ex) { 3603 return null; 3604 } catch (NullPointerException ex) { 3605 return null; 3606 } 3607 } 3608 3609 /** @hide */ 3610 @SystemApi 3611 public String getCdmaMin() { 3612 return getCdmaMin(getDefaultSubscription()); 3613 } 3614 3615 /** @hide */ 3616 @SystemApi 3617 public String getCdmaMin(int subId) { 3618 try { 3619 ITelephony telephony = getITelephony(); 3620 if (telephony == null) 3621 return null; 3622 return telephony.getCdmaMin(subId); 3623 } catch (RemoteException ex) { 3624 return null; 3625 } catch (NullPointerException ex) { 3626 return null; 3627 } 3628 } 3629 3630 /** @hide */ 3631 @SystemApi 3632 public int checkCarrierPrivilegesForPackage(String pkgname) { 3633 try { 3634 ITelephony telephony = getITelephony(); 3635 if (telephony != null) 3636 return telephony.checkCarrierPrivilegesForPackage(pkgname); 3637 } catch (RemoteException ex) { 3638 Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex); 3639 } catch (NullPointerException ex) { 3640 Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex); 3641 } 3642 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3643 } 3644 3645 /** @hide */ 3646 @SystemApi 3647 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 3648 return getCarrierPackageNamesForIntentAndPhone(intent, getDefaultPhone()); 3649 } 3650 3651 /** @hide */ 3652 @SystemApi 3653 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { 3654 try { 3655 ITelephony telephony = getITelephony(); 3656 if (telephony != null) 3657 return telephony.getCarrierPackageNamesForIntentAndPhone(intent, phoneId); 3658 } catch (RemoteException ex) { 3659 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone RemoteException", ex); 3660 } catch (NullPointerException ex) { 3661 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone NPE", ex); 3662 } 3663 return null; 3664 } 3665 3666 /** @hide */ 3667 @SystemApi 3668 public void dial(String number) { 3669 try { 3670 ITelephony telephony = getITelephony(); 3671 if (telephony != null) 3672 telephony.dial(number); 3673 } catch (RemoteException e) { 3674 Log.e(TAG, "Error calling ITelephony#dial", e); 3675 } 3676 } 3677 3678 /** @hide */ 3679 @SystemApi 3680 public void call(String callingPackage, String number) { 3681 try { 3682 ITelephony telephony = getITelephony(); 3683 if (telephony != null) 3684 telephony.call(callingPackage, number); 3685 } catch (RemoteException e) { 3686 Log.e(TAG, "Error calling ITelephony#call", e); 3687 } 3688 } 3689 3690 /** @hide */ 3691 @SystemApi 3692 public boolean endCall() { 3693 try { 3694 ITelephony telephony = getITelephony(); 3695 if (telephony != null) 3696 return telephony.endCall(); 3697 } catch (RemoteException e) { 3698 Log.e(TAG, "Error calling ITelephony#endCall", e); 3699 } 3700 return false; 3701 } 3702 3703 /** @hide */ 3704 @SystemApi 3705 public void answerRingingCall() { 3706 try { 3707 ITelephony telephony = getITelephony(); 3708 if (telephony != null) 3709 telephony.answerRingingCall(); 3710 } catch (RemoteException e) { 3711 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 3712 } 3713 } 3714 3715 /** @hide */ 3716 @SystemApi 3717 public void silenceRinger() { 3718 try { 3719 getTelecomService().silenceRinger(mContext.getOpPackageName()); 3720 } catch (RemoteException e) { 3721 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); 3722 } 3723 } 3724 3725 /** @hide */ 3726 @SystemApi 3727 public boolean isOffhook() { 3728 try { 3729 ITelephony telephony = getITelephony(); 3730 if (telephony != null) 3731 return telephony.isOffhook(); 3732 } catch (RemoteException e) { 3733 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 3734 } 3735 return false; 3736 } 3737 3738 /** @hide */ 3739 @SystemApi 3740 public boolean isRinging() { 3741 try { 3742 ITelephony telephony = getITelephony(); 3743 if (telephony != null) 3744 return telephony.isRinging(); 3745 } catch (RemoteException e) { 3746 Log.e(TAG, "Error calling ITelephony#isRinging", e); 3747 } 3748 return false; 3749 } 3750 3751 /** @hide */ 3752 @SystemApi 3753 public boolean isIdle() { 3754 try { 3755 ITelephony telephony = getITelephony(); 3756 if (telephony != null) 3757 return telephony.isIdle(); 3758 } catch (RemoteException e) { 3759 Log.e(TAG, "Error calling ITelephony#isIdle", e); 3760 } 3761 return true; 3762 } 3763 3764 /** @hide */ 3765 @SystemApi 3766 public boolean isRadioOn() { 3767 try { 3768 ITelephony telephony = getITelephony(); 3769 if (telephony != null) 3770 return telephony.isRadioOn(); 3771 } catch (RemoteException e) { 3772 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 3773 } 3774 return false; 3775 } 3776 3777 /** @hide */ 3778 @SystemApi 3779 public boolean isSimPinEnabled() { 3780 try { 3781 ITelephony telephony = getITelephony(); 3782 if (telephony != null) 3783 return telephony.isSimPinEnabled(mContext.getOpPackageName()); 3784 } catch (RemoteException e) { 3785 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 3786 } 3787 return false; 3788 } 3789 3790 /** @hide */ 3791 @SystemApi 3792 public boolean supplyPin(String pin) { 3793 try { 3794 ITelephony telephony = getITelephony(); 3795 if (telephony != null) 3796 return telephony.supplyPin(pin); 3797 } catch (RemoteException e) { 3798 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 3799 } 3800 return false; 3801 } 3802 3803 /** @hide */ 3804 @SystemApi 3805 public boolean supplyPuk(String puk, String pin) { 3806 try { 3807 ITelephony telephony = getITelephony(); 3808 if (telephony != null) 3809 return telephony.supplyPuk(puk, pin); 3810 } catch (RemoteException e) { 3811 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 3812 } 3813 return false; 3814 } 3815 3816 /** @hide */ 3817 @SystemApi 3818 public int[] supplyPinReportResult(String pin) { 3819 try { 3820 ITelephony telephony = getITelephony(); 3821 if (telephony != null) 3822 return telephony.supplyPinReportResult(pin); 3823 } catch (RemoteException e) { 3824 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 3825 } 3826 return new int[0]; 3827 } 3828 3829 /** @hide */ 3830 @SystemApi 3831 public int[] supplyPukReportResult(String puk, String pin) { 3832 try { 3833 ITelephony telephony = getITelephony(); 3834 if (telephony != null) 3835 return telephony.supplyPukReportResult(puk, pin); 3836 } catch (RemoteException e) { 3837 Log.e(TAG, "Error calling ITelephony#]", e); 3838 } 3839 return new int[0]; 3840 } 3841 3842 /** @hide */ 3843 @SystemApi 3844 public boolean handlePinMmi(String dialString) { 3845 try { 3846 ITelephony telephony = getITelephony(); 3847 if (telephony != null) 3848 return telephony.handlePinMmi(dialString); 3849 } catch (RemoteException e) { 3850 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3851 } 3852 return false; 3853 } 3854 3855 /** @hide */ 3856 @SystemApi 3857 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 3858 try { 3859 ITelephony telephony = getITelephony(); 3860 if (telephony != null) 3861 return telephony.handlePinMmiForSubscriber(subId, dialString); 3862 } catch (RemoteException e) { 3863 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3864 } 3865 return false; 3866 } 3867 3868 /** @hide */ 3869 @SystemApi 3870 public void toggleRadioOnOff() { 3871 try { 3872 ITelephony telephony = getITelephony(); 3873 if (telephony != null) 3874 telephony.toggleRadioOnOff(); 3875 } catch (RemoteException e) { 3876 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 3877 } 3878 } 3879 3880 /** @hide */ 3881 @SystemApi 3882 public boolean setRadio(boolean turnOn) { 3883 try { 3884 ITelephony telephony = getITelephony(); 3885 if (telephony != null) 3886 return telephony.setRadio(turnOn); 3887 } catch (RemoteException e) { 3888 Log.e(TAG, "Error calling ITelephony#setRadio", e); 3889 } 3890 return false; 3891 } 3892 3893 /** @hide */ 3894 @SystemApi 3895 public boolean setRadioPower(boolean turnOn) { 3896 try { 3897 ITelephony telephony = getITelephony(); 3898 if (telephony != null) 3899 return telephony.setRadioPower(turnOn); 3900 } catch (RemoteException e) { 3901 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 3902 } 3903 return false; 3904 } 3905 3906 /** @hide */ 3907 @SystemApi 3908 public void updateServiceLocation() { 3909 try { 3910 ITelephony telephony = getITelephony(); 3911 if (telephony != null) 3912 telephony.updateServiceLocation(); 3913 } catch (RemoteException e) { 3914 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 3915 } 3916 } 3917 3918 /** @hide */ 3919 @SystemApi 3920 public boolean enableDataConnectivity() { 3921 try { 3922 ITelephony telephony = getITelephony(); 3923 if (telephony != null) 3924 return telephony.enableDataConnectivity(); 3925 } catch (RemoteException e) { 3926 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 3927 } 3928 return false; 3929 } 3930 3931 /** @hide */ 3932 @SystemApi 3933 public boolean disableDataConnectivity() { 3934 try { 3935 ITelephony telephony = getITelephony(); 3936 if (telephony != null) 3937 return telephony.disableDataConnectivity(); 3938 } catch (RemoteException e) { 3939 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 3940 } 3941 return false; 3942 } 3943 3944 /** @hide */ 3945 @SystemApi 3946 public boolean isDataConnectivityPossible() { 3947 try { 3948 ITelephony telephony = getITelephony(); 3949 if (telephony != null) 3950 return telephony.isDataConnectivityPossible(); 3951 } catch (RemoteException e) { 3952 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 3953 } 3954 return false; 3955 } 3956 3957 /** @hide */ 3958 @SystemApi 3959 public boolean needsOtaServiceProvisioning() { 3960 try { 3961 ITelephony telephony = getITelephony(); 3962 if (telephony != null) 3963 return telephony.needsOtaServiceProvisioning(); 3964 } catch (RemoteException e) { 3965 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 3966 } 3967 return false; 3968 } 3969 3970 /** @hide */ 3971 @SystemApi 3972 public void setDataEnabled(boolean enable) { 3973 setDataEnabled(SubscriptionManager.getDefaultDataSubId(), enable); 3974 } 3975 3976 /** @hide */ 3977 @SystemApi 3978 public void setDataEnabled(int subId, boolean enable) { 3979 try { 3980 Log.d(TAG, "setDataEnabled: enabled=" + enable); 3981 ITelephony telephony = getITelephony(); 3982 if (telephony != null) 3983 telephony.setDataEnabled(subId, enable); 3984 } catch (RemoteException e) { 3985 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 3986 } 3987 } 3988 3989 /** @hide */ 3990 @SystemApi 3991 public boolean getDataEnabled() { 3992 return getDataEnabled(SubscriptionManager.getDefaultDataSubId()); 3993 } 3994 3995 /** @hide */ 3996 @SystemApi 3997 public boolean getDataEnabled(int subId) { 3998 boolean retVal = false; 3999 try { 4000 ITelephony telephony = getITelephony(); 4001 if (telephony != null) 4002 retVal = telephony.getDataEnabled(subId); 4003 } catch (RemoteException e) { 4004 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 4005 } catch (NullPointerException e) { 4006 } 4007 Log.d(TAG, "getDataEnabled: retVal=" + retVal); 4008 return retVal; 4009 } 4010 4011 /** 4012 * Returns the result and response from RIL for oem request 4013 * 4014 * @param oemReq the data is sent to ril. 4015 * @param oemResp the respose data from RIL. 4016 * @return negative value request was not handled or get error 4017 * 0 request was handled succesfully, but no response data 4018 * positive value success, data length of response 4019 * @hide 4020 */ 4021 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 4022 try { 4023 ITelephony telephony = getITelephony(); 4024 if (telephony != null) 4025 return telephony.invokeOemRilRequestRaw(oemReq, oemResp); 4026 } catch (RemoteException ex) { 4027 } catch (NullPointerException ex) { 4028 } 4029 return -1; 4030 } 4031 4032 /** @hide */ 4033 @SystemApi 4034 public void enableVideoCalling(boolean enable) { 4035 try { 4036 ITelephony telephony = getITelephony(); 4037 if (telephony != null) 4038 telephony.enableVideoCalling(enable); 4039 } catch (RemoteException e) { 4040 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 4041 } 4042 } 4043 4044 /** @hide */ 4045 @SystemApi 4046 public boolean isVideoCallingEnabled() { 4047 try { 4048 ITelephony telephony = getITelephony(); 4049 if (telephony != null) 4050 return telephony.isVideoCallingEnabled(mContext.getOpPackageName()); 4051 } catch (RemoteException e) { 4052 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 4053 } 4054 return false; 4055 } 4056 4057 /** 4058 * Whether the device supports configuring the DTMF tone length. 4059 * 4060 * @return {@code true} if the DTMF tone length can be changed, and {@code false} otherwise. 4061 */ 4062 public boolean canChangeDtmfToneLength() { 4063 try { 4064 ITelephony telephony = getITelephony(); 4065 if (telephony != null) { 4066 return telephony.canChangeDtmfToneLength(); 4067 } 4068 } catch (RemoteException e) { 4069 Log.e(TAG, "Error calling ITelephony#canChangeDtmfToneLength", e); 4070 } 4071 return false; 4072 } 4073 4074 /** 4075 * Whether the device is a world phone. 4076 * 4077 * @return {@code true} if the device is a world phone, and {@code false} otherwise. 4078 */ 4079 public boolean isWorldPhone() { 4080 try { 4081 ITelephony telephony = getITelephony(); 4082 if (telephony != null) { 4083 return telephony.isWorldPhone(); 4084 } 4085 } catch (RemoteException e) { 4086 Log.e(TAG, "Error calling ITelephony#isWorldPhone", e); 4087 } 4088 return false; 4089 } 4090 4091 /** 4092 * Whether the phone supports TTY mode. 4093 * 4094 * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. 4095 */ 4096 public boolean isTtyModeSupported() { 4097 try { 4098 ITelephony telephony = getITelephony(); 4099 if (telephony != null) { 4100 return telephony.isTtyModeSupported(); 4101 } 4102 } catch (RemoteException e) { 4103 Log.e(TAG, "Error calling ITelephony#isTtyModeSupported", e); 4104 } 4105 return false; 4106 } 4107 4108 /** 4109 * Whether the phone supports hearing aid compatibility. 4110 * 4111 * @return {@code true} if the device supports hearing aid compatibility, and {@code false} 4112 * otherwise. 4113 */ 4114 public boolean isHearingAidCompatibilitySupported() { 4115 try { 4116 ITelephony telephony = getITelephony(); 4117 if (telephony != null) { 4118 return telephony.isHearingAidCompatibilitySupported(); 4119 } 4120 } catch (RemoteException e) { 4121 Log.e(TAG, "Error calling ITelephony#isHearingAidCompatibilitySupported", e); 4122 } 4123 return false; 4124 } 4125 4126 /** 4127 * This function retrieves value for setting "name+subId", and if that is not found 4128 * retrieves value for setting "name", and if that is not found throws 4129 * SettingNotFoundException 4130 * 4131 * @hide */ 4132 public static int getIntWithSubId(ContentResolver cr, String name, int subId) 4133 throws SettingNotFoundException { 4134 try { 4135 return Settings.Global.getInt(cr, name + subId); 4136 } catch (SettingNotFoundException e) { 4137 try { 4138 int val = Settings.Global.getInt(cr, name); 4139 Settings.Global.putInt(cr, name + subId, val); 4140 4141 /* We are now moving from 'setting' to 'setting+subId', and using the value stored 4142 * for 'setting' as default. Reset the default (since it may have a user set 4143 * value). */ 4144 int default_val = val; 4145 if (name.equals(Settings.Global.MOBILE_DATA)) { 4146 default_val = "true".equalsIgnoreCase( 4147 SystemProperties.get("ro.com.android.mobiledata", "true")) ? 1 : 0; 4148 } else if (name.equals(Settings.Global.DATA_ROAMING)) { 4149 default_val = "true".equalsIgnoreCase( 4150 SystemProperties.get("ro.com.android.dataroaming", "false")) ? 1 : 0; 4151 } 4152 4153 if (default_val != val) { 4154 Settings.Global.putInt(cr, name, default_val); 4155 } 4156 4157 return val; 4158 } catch (SettingNotFoundException exc) { 4159 throw new SettingNotFoundException(name); 4160 } 4161 } 4162 } 4163 4164 /** 4165 * Returns the IMS Registration Status 4166 * @hide 4167 */ 4168 public boolean isImsRegistered() { 4169 try { 4170 ITelephony telephony = getITelephony(); 4171 if (telephony == null) 4172 return false; 4173 return telephony.isImsRegistered(); 4174 } catch (RemoteException ex) { 4175 return false; 4176 } catch (NullPointerException ex) { 4177 return false; 4178 } 4179 } 4180 4181 /** 4182 * Returns the Status of Volte 4183 *@hide 4184 */ 4185 public boolean isVolteEnabled() { 4186 try { 4187 return getITelephony().isVolteEnabled(); 4188 } catch (RemoteException ex) { 4189 return false; 4190 } catch (NullPointerException ex) { 4191 return false; 4192 } 4193 } 4194 4195 /** 4196 * Returns the Status of Wi-Fi Calling 4197 *@hide 4198 */ 4199 public boolean isWifiCallingEnabled() { 4200 try { 4201 return getITelephony().isWifiCallingEnabled(); 4202 } catch (RemoteException ex) { 4203 return false; 4204 } catch (NullPointerException ex) { 4205 return false; 4206 } 4207 } 4208 4209 /** 4210 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 4211 * 4212 * @hide 4213 */ 4214 public void setSimOperatorNumeric(String numeric) { 4215 int phoneId = getDefaultPhone(); 4216 setSimOperatorNumericForPhone(phoneId, numeric); 4217 } 4218 4219 /** 4220 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 4221 * 4222 * @hide 4223 */ 4224 public void setSimOperatorNumericForPhone(int phoneId, String numeric) { 4225 setTelephonyProperty(phoneId, 4226 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, numeric); 4227 } 4228 4229 /** 4230 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 4231 * 4232 * @hide 4233 */ 4234 public void setSimOperatorName(String name) { 4235 int phoneId = getDefaultPhone(); 4236 setSimOperatorNameForPhone(phoneId, name); 4237 } 4238 4239 /** 4240 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 4241 * 4242 * @hide 4243 */ 4244 public void setSimOperatorNameForPhone(int phoneId, String name) { 4245 setTelephonyProperty(phoneId, 4246 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, name); 4247 } 4248 4249 /** 4250 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the default phone. 4251 * 4252 * @hide 4253 */ 4254 public void setSimCountryIso(String iso) { 4255 int phoneId = getDefaultPhone(); 4256 setSimCountryIsoForPhone(phoneId, iso); 4257 } 4258 4259 /** 4260 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the given phone. 4261 * 4262 * @hide 4263 */ 4264 public void setSimCountryIsoForPhone(int phoneId, String iso) { 4265 setTelephonyProperty(phoneId, 4266 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso); 4267 } 4268 4269 /** 4270 * Set TelephonyProperties.PROPERTY_SIM_STATE for the default phone. 4271 * 4272 * @hide 4273 */ 4274 public void setSimState(String state) { 4275 int phoneId = getDefaultPhone(); 4276 setSimStateForPhone(phoneId, state); 4277 } 4278 4279 /** 4280 * Set TelephonyProperties.PROPERTY_SIM_STATE for the given phone. 4281 * 4282 * @hide 4283 */ 4284 public void setSimStateForPhone(int phoneId, String state) { 4285 setTelephonyProperty(phoneId, 4286 TelephonyProperties.PROPERTY_SIM_STATE, state); 4287 } 4288 4289 /** 4290 * Set baseband version for the default phone. 4291 * 4292 * @param version baseband version 4293 * @hide 4294 */ 4295 public void setBasebandVersion(String version) { 4296 int phoneId = getDefaultPhone(); 4297 setBasebandVersionForPhone(phoneId, version); 4298 } 4299 4300 /** 4301 * Set baseband version by phone id. 4302 * 4303 * @param phoneId for which baseband version is set 4304 * @param version baseband version 4305 * @hide 4306 */ 4307 public void setBasebandVersionForPhone(int phoneId, String version) { 4308 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4309 String prop = TelephonyProperties.PROPERTY_BASEBAND_VERSION + 4310 ((phoneId == 0) ? "" : Integer.toString(phoneId)); 4311 SystemProperties.set(prop, version); 4312 } 4313 } 4314 4315 /** 4316 * Set phone type for the default phone. 4317 * 4318 * @param type phone type 4319 * 4320 * @hide 4321 */ 4322 public void setPhoneType(int type) { 4323 int phoneId = getDefaultPhone(); 4324 setPhoneType(phoneId, type); 4325 } 4326 4327 /** 4328 * Set phone type by phone id. 4329 * 4330 * @param phoneId for which phone type is set 4331 * @param type phone type 4332 * 4333 * @hide 4334 */ 4335 public void setPhoneType(int phoneId, int type) { 4336 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4337 TelephonyManager.setTelephonyProperty(phoneId, 4338 TelephonyProperties.CURRENT_ACTIVE_PHONE, String.valueOf(type)); 4339 } 4340 } 4341 4342 /** 4343 * Get OTASP number schema for the default phone. 4344 * 4345 * @param defaultValue default value 4346 * @return OTA SP number schema 4347 * 4348 * @hide 4349 */ 4350 public String getOtaSpNumberSchema(String defaultValue) { 4351 int phoneId = getDefaultPhone(); 4352 return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); 4353 } 4354 4355 /** 4356 * Get OTASP number schema by phone id. 4357 * 4358 * @param phoneId for which OTA SP number schema is get 4359 * @param defaultValue default value 4360 * @return OTA SP number schema 4361 * 4362 * @hide 4363 */ 4364 public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) { 4365 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4366 return TelephonyManager.getTelephonyProperty(phoneId, 4367 TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA, defaultValue); 4368 } 4369 4370 return defaultValue; 4371 } 4372 4373 /** 4374 * Get SMS receive capable from system property for the default phone. 4375 * 4376 * @param defaultValue default value 4377 * @return SMS receive capable 4378 * 4379 * @hide 4380 */ 4381 public boolean getSmsReceiveCapable(boolean defaultValue) { 4382 int phoneId = getDefaultPhone(); 4383 return getSmsReceiveCapableForPhone(phoneId, defaultValue); 4384 } 4385 4386 /** 4387 * Get SMS receive capable from system property by phone id. 4388 * 4389 * @param phoneId for which SMS receive capable is get 4390 * @param defaultValue default value 4391 * @return SMS receive capable 4392 * 4393 * @hide 4394 */ 4395 public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) { 4396 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4397 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 4398 TelephonyProperties.PROPERTY_SMS_RECEIVE, String.valueOf(defaultValue))); 4399 } 4400 4401 return defaultValue; 4402 } 4403 4404 /** 4405 * Get SMS send capable from system property for the default phone. 4406 * 4407 * @param defaultValue default value 4408 * @return SMS send capable 4409 * 4410 * @hide 4411 */ 4412 public boolean getSmsSendCapable(boolean defaultValue) { 4413 int phoneId = getDefaultPhone(); 4414 return getSmsSendCapableForPhone(phoneId, defaultValue); 4415 } 4416 4417 /** 4418 * Get SMS send capable from system property by phone id. 4419 * 4420 * @param phoneId for which SMS send capable is get 4421 * @param defaultValue default value 4422 * @return SMS send capable 4423 * 4424 * @hide 4425 */ 4426 public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) { 4427 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4428 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 4429 TelephonyProperties.PROPERTY_SMS_SEND, String.valueOf(defaultValue))); 4430 } 4431 4432 return defaultValue; 4433 } 4434 4435 /** 4436 * Set the alphabetic name of current registered operator. 4437 * @param name the alphabetic name of current registered operator. 4438 * @hide 4439 */ 4440 public void setNetworkOperatorName(String name) { 4441 int phoneId = getDefaultPhone(); 4442 setNetworkOperatorNameForPhone(phoneId, name); 4443 } 4444 4445 /** 4446 * Set the alphabetic name of current registered operator. 4447 * @param phoneId which phone you want to set 4448 * @param name the alphabetic name of current registered operator. 4449 * @hide 4450 */ 4451 public void setNetworkOperatorNameForPhone(int phoneId, String name) { 4452 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4453 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, name); 4454 } 4455 } 4456 4457 /** 4458 * Set the numeric name (MCC+MNC) of current registered operator. 4459 * @param operator the numeric name (MCC+MNC) of current registered operator 4460 * @hide 4461 */ 4462 public void setNetworkOperatorNumeric(String numeric) { 4463 int phoneId = getDefaultPhone(); 4464 setNetworkOperatorNumericForPhone(phoneId, numeric); 4465 } 4466 4467 /** 4468 * Set the numeric name (MCC+MNC) of current registered operator. 4469 * @param phoneId for which phone type is set 4470 * @param operator the numeric name (MCC+MNC) of current registered operator 4471 * @hide 4472 */ 4473 public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) { 4474 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, numeric); 4475 } 4476 4477 /** 4478 * Set roaming state of the current network, for GSM purposes. 4479 * @param isRoaming is network in romaing state or not 4480 * @hide 4481 */ 4482 public void setNetworkRoaming(boolean isRoaming) { 4483 int phoneId = getDefaultPhone(); 4484 setNetworkRoamingForPhone(phoneId, isRoaming); 4485 } 4486 4487 /** 4488 * Set roaming state of the current network, for GSM purposes. 4489 * @param phoneId which phone you want to set 4490 * @param isRoaming is network in romaing state or not 4491 * @hide 4492 */ 4493 public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) { 4494 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4495 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, 4496 isRoaming ? "true" : "false"); 4497 } 4498 } 4499 4500 /** 4501 * Set the ISO country code equivalent of the current registered 4502 * operator's MCC (Mobile Country Code). 4503 * @param iso the ISO country code equivalent of the current registered 4504 * @hide 4505 */ 4506 public void setNetworkCountryIso(String iso) { 4507 int phoneId = getDefaultPhone(); 4508 setNetworkCountryIsoForPhone(phoneId, iso); 4509 } 4510 4511 /** 4512 * Set the ISO country code equivalent of the current registered 4513 * operator's MCC (Mobile Country Code). 4514 * @param phoneId which phone you want to set 4515 * @param iso the ISO country code equivalent of the current registered 4516 * @hide 4517 */ 4518 public void setNetworkCountryIsoForPhone(int phoneId, String iso) { 4519 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4520 setTelephonyProperty(phoneId, 4521 TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso); 4522 } 4523 } 4524 4525 /** 4526 * Set the network type currently in use on the device for data transmission. 4527 * @param type the network type currently in use on the device for data transmission 4528 * @hide 4529 */ 4530 public void setDataNetworkType(int type) { 4531 int phoneId = getDefaultPhone(); 4532 setDataNetworkTypeForPhone(phoneId, type); 4533 } 4534 4535 /** 4536 * Set the network type currently in use on the device for data transmission. 4537 * @param phoneId which phone you want to set 4538 * @param type the network type currently in use on the device for data transmission 4539 * @hide 4540 */ 4541 public void setDataNetworkTypeForPhone(int phoneId, int type) { 4542 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4543 setTelephonyProperty(phoneId, 4544 TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, 4545 ServiceState.rilRadioTechnologyToString(type)); 4546 } 4547 } 4548 4549 /** 4550 * Returns the subscription ID for the given phone account. 4551 * @hide 4552 */ 4553 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { 4554 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 4555 try { 4556 ITelephony service = getITelephony(); 4557 if (service != null) { 4558 retval = service.getSubIdForPhoneAccount(phoneAccount); 4559 } 4560 } catch (RemoteException e) { 4561 } 4562 4563 return retval; 4564 } 4565 4566 /** 4567 * Resets telephony manager settings back to factory defaults. 4568 * 4569 * @hide 4570 */ 4571 public void factoryReset(int subId) { 4572 try { 4573 Log.d(TAG, "factoryReset: subId=" + subId); 4574 ITelephony telephony = getITelephony(); 4575 if (telephony != null) 4576 telephony.factoryReset(subId); 4577 } catch (RemoteException e) { 4578 } 4579 } 4580 4581 4582 /** @hide */ 4583 public String getLocaleFromDefaultSim() { 4584 try { 4585 final ITelephony telephony = getITelephony(); 4586 if (telephony != null) { 4587 return telephony.getLocaleFromDefaultSim(); 4588 } 4589 } catch (RemoteException ex) { 4590 } 4591 4592 return null; 4593 } 4594} 4595