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