TelephonyManager.java revision 46fa08d66483bf041fdc0a4eace63f9addf8e629
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 Rlog.d(TAG, "getSimState: simState=" + simState + " slotIdx=" + slotIdx); 1655 return simState; 1656 } 1657 1658 /** 1659 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1660 * provider of the SIM. 5 or 6 decimal digits. 1661 * <p> 1662 * Availability: SIM state must be {@link #SIM_STATE_READY} 1663 * 1664 * @see #getSimState 1665 */ 1666 public String getSimOperator() { 1667 return getSimOperatorNumeric(); 1668 } 1669 1670 /** 1671 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1672 * provider of the SIM. 5 or 6 decimal digits. 1673 * <p> 1674 * Availability: SIM state must be {@link #SIM_STATE_READY} 1675 * 1676 * @see #getSimState 1677 * 1678 * @param subId for which SimOperator is returned 1679 * @hide 1680 */ 1681 public String getSimOperator(int subId) { 1682 return getSimOperatorNumericForSubscription(subId); 1683 } 1684 1685 /** 1686 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1687 * provider of the SIM. 5 or 6 decimal digits. 1688 * <p> 1689 * Availability: SIM state must be {@link #SIM_STATE_READY} 1690 * 1691 * @see #getSimState 1692 * @hide 1693 */ 1694 public String getSimOperatorNumeric() { 1695 int subId = SubscriptionManager.getDefaultDataSubId(); 1696 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1697 subId = SubscriptionManager.getDefaultSmsSubId(); 1698 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1699 subId = SubscriptionManager.getDefaultVoiceSubId(); 1700 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1701 subId = SubscriptionManager.getDefaultSubId(); 1702 } 1703 } 1704 } 1705 Rlog.d(TAG, "getSimOperatorNumeric(): default subId=" + subId); 1706 return getSimOperatorNumericForSubscription(subId); 1707 } 1708 1709 /** 1710 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1711 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 1712 * <p> 1713 * Availability: SIM state must be {@link #SIM_STATE_READY} 1714 * 1715 * @see #getSimState 1716 * 1717 * @param subId for which SimOperator is returned 1718 * @hide 1719 */ 1720 public String getSimOperatorNumericForSubscription(int subId) { 1721 int phoneId = SubscriptionManager.getPhoneId(subId); 1722 return getSimOperatorNumericForPhone(phoneId); 1723 } 1724 1725 /** 1726 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1727 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 1728 * <p> 1729 * 1730 * @param phoneId for which SimOperator is returned 1731 * @hide 1732 */ 1733 public String getSimOperatorNumericForPhone(int phoneId) { 1734 return getTelephonyProperty(phoneId, 1735 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, ""); 1736 } 1737 1738 /** 1739 * Returns the Service Provider Name (SPN). 1740 * <p> 1741 * Availability: SIM state must be {@link #SIM_STATE_READY} 1742 * 1743 * @see #getSimState 1744 */ 1745 public String getSimOperatorName() { 1746 return getSimOperatorNameForPhone(getDefaultPhone()); 1747 } 1748 1749 /** 1750 * Returns the Service Provider Name (SPN). 1751 * <p> 1752 * Availability: SIM state must be {@link #SIM_STATE_READY} 1753 * 1754 * @see #getSimState 1755 * 1756 * @param subId for which SimOperatorName is returned 1757 * @hide 1758 */ 1759 public String getSimOperatorNameForSubscription(int subId) { 1760 int phoneId = SubscriptionManager.getPhoneId(subId); 1761 return getSimOperatorNameForPhone(phoneId); 1762 } 1763 1764 /** 1765 * Returns the Service Provider Name (SPN). 1766 * 1767 * @hide 1768 */ 1769 public String getSimOperatorNameForPhone(int phoneId) { 1770 return getTelephonyProperty(phoneId, 1771 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, ""); 1772 } 1773 1774 /** 1775 * Returns the ISO country code equivalent for the SIM provider's country code. 1776 */ 1777 public String getSimCountryIso() { 1778 return getSimCountryIsoForPhone(getDefaultPhone()); 1779 } 1780 1781 /** 1782 * Returns the ISO country code equivalent for the SIM provider's country code. 1783 * 1784 * @param subId for which SimCountryIso is returned 1785 * 1786 * @hide 1787 */ 1788 public String getSimCountryIso(int subId) { 1789 return getSimCountryIsoForSubscription(subId); 1790 } 1791 1792 /** 1793 * Returns the ISO country code equivalent for the SIM provider's country code. 1794 * 1795 * @param subId for which SimCountryIso is returned 1796 * 1797 * @hide 1798 */ 1799 public String getSimCountryIsoForSubscription(int subId) { 1800 int phoneId = SubscriptionManager.getPhoneId(subId); 1801 return getSimCountryIsoForPhone(phoneId); 1802 } 1803 1804 /** 1805 * Returns the ISO country code equivalent for the SIM provider's country code. 1806 * 1807 * @hide 1808 */ 1809 public String getSimCountryIsoForPhone(int phoneId) { 1810 return getTelephonyProperty(phoneId, 1811 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, ""); 1812 } 1813 1814 /** 1815 * Returns the serial number of the SIM, if applicable. Return null if it is 1816 * unavailable. 1817 * <p> 1818 * Requires Permission: 1819 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1820 */ 1821 public String getSimSerialNumber() { 1822 return getSimSerialNumber(getDefaultSubscription()); 1823 } 1824 1825 /** 1826 * Returns the serial number for the given subscription, if applicable. Return null if it is 1827 * unavailable. 1828 * <p> 1829 * @param subId for which Sim Serial number is returned 1830 * Requires Permission: 1831 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1832 */ 1833 /** {@hide} */ 1834 public String getSimSerialNumber(int subId) { 1835 try { 1836 IPhoneSubInfo info = getSubscriberInfo(); 1837 if (info == null) 1838 return null; 1839 return info.getIccSerialNumberForSubscriber(subId); 1840 } catch (RemoteException ex) { 1841 return null; 1842 } catch (NullPointerException ex) { 1843 // This could happen before phone restarts due to crashing 1844 return null; 1845 } 1846 } 1847 1848 /** 1849 * Return if the current radio is LTE on CDMA. This 1850 * is a tri-state return value as for a period of time 1851 * the mode may be unknown. 1852 * 1853 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1854 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1855 * 1856 * @hide 1857 */ 1858 public int getLteOnCdmaMode() { 1859 return getLteOnCdmaMode(getDefaultSubscription()); 1860 } 1861 1862 /** 1863 * Return if the current radio is LTE on CDMA for Subscription. This 1864 * is a tri-state return value as for a period of time 1865 * the mode may be unknown. 1866 * 1867 * @param subId for which radio is LTE on CDMA is returned 1868 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1869 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1870 * 1871 */ 1872 /** {@hide} */ 1873 public int getLteOnCdmaMode(int subId) { 1874 try { 1875 ITelephony telephony = getITelephony(); 1876 if (telephony == null) 1877 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1878 return telephony.getLteOnCdmaModeForSubscriber(subId); 1879 } catch (RemoteException ex) { 1880 // Assume no ICC card if remote exception which shouldn't happen 1881 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1882 } catch (NullPointerException ex) { 1883 // This could happen before phone restarts due to crashing 1884 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1885 } 1886 } 1887 1888 // 1889 // 1890 // Subscriber Info 1891 // 1892 // 1893 1894 /** 1895 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 1896 * Return null if it is unavailable. 1897 * <p> 1898 * Requires Permission: 1899 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1900 */ 1901 public String getSubscriberId() { 1902 return getSubscriberId(getDefaultSubscription()); 1903 } 1904 1905 /** 1906 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone 1907 * for a subscription. 1908 * Return null if it is unavailable. 1909 * <p> 1910 * Requires Permission: 1911 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1912 * 1913 * @param subId whose subscriber id is returned 1914 */ 1915 /** {@hide} */ 1916 public String getSubscriberId(int subId) { 1917 try { 1918 IPhoneSubInfo info = getSubscriberInfo(); 1919 if (info == null) 1920 return null; 1921 return info.getSubscriberIdForSubscriber(subId); 1922 } catch (RemoteException ex) { 1923 return null; 1924 } catch (NullPointerException ex) { 1925 // This could happen before phone restarts due to crashing 1926 return null; 1927 } 1928 } 1929 1930 /** 1931 * Returns the Group Identifier Level1 for a GSM phone. 1932 * Return null if it is unavailable. 1933 * <p> 1934 * Requires Permission: 1935 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1936 */ 1937 public String getGroupIdLevel1() { 1938 try { 1939 IPhoneSubInfo info = getSubscriberInfo(); 1940 if (info == null) 1941 return null; 1942 return info.getGroupIdLevel1(); 1943 } catch (RemoteException ex) { 1944 return null; 1945 } catch (NullPointerException ex) { 1946 // This could happen before phone restarts due to crashing 1947 return null; 1948 } 1949 } 1950 1951 /** 1952 * Returns the Group Identifier Level1 for a GSM phone for a particular subscription. 1953 * Return null if it is unavailable. 1954 * <p> 1955 * Requires Permission: 1956 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1957 * 1958 * @param subscription whose subscriber id is returned 1959 */ 1960 /** {@hide} */ 1961 public String getGroupIdLevel1(int subId) { 1962 try { 1963 IPhoneSubInfo info = getSubscriberInfo(); 1964 if (info == null) 1965 return null; 1966 return info.getGroupIdLevel1ForSubscriber(subId); 1967 } catch (RemoteException ex) { 1968 return null; 1969 } catch (NullPointerException ex) { 1970 // This could happen before phone restarts due to crashing 1971 return null; 1972 } 1973 } 1974 1975 /** 1976 * Returns the phone number string for line 1, for example, the MSISDN 1977 * for a GSM phone. Return null if it is unavailable. 1978 * <p> 1979 * Requires Permission: 1980 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1981 */ 1982 public String getLine1Number() { 1983 return getLine1NumberForSubscriber(getDefaultSubscription()); 1984 } 1985 1986 /** 1987 * Returns the phone number string for line 1, for example, the MSISDN 1988 * for a GSM phone for a particular subscription. Return null if it is unavailable. 1989 * <p> 1990 * Requires Permission: 1991 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1992 * 1993 * @param subId whose phone number for line 1 is returned 1994 */ 1995 /** {@hide} */ 1996 public String getLine1NumberForSubscriber(int subId) { 1997 String number = null; 1998 try { 1999 ITelephony telephony = getITelephony(); 2000 if (telephony != null) 2001 number = telephony.getLine1NumberForDisplay(subId, mContext.getOpPackageName()); 2002 } catch (RemoteException ex) { 2003 } catch (NullPointerException ex) { 2004 } 2005 if (number != null) { 2006 return number; 2007 } 2008 try { 2009 IPhoneSubInfo info = getSubscriberInfo(); 2010 if (info == null) 2011 return null; 2012 return info.getLine1NumberForSubscriber(subId); 2013 } catch (RemoteException ex) { 2014 return null; 2015 } catch (NullPointerException ex) { 2016 // This could happen before phone restarts due to crashing 2017 return null; 2018 } 2019 } 2020 2021 /** 2022 * Set the line 1 phone number string and its alphatag for the current ICCID 2023 * for display purpose only, for example, displayed in Phone Status. It won't 2024 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 2025 * value. 2026 * 2027 * <p>Requires that the calling app has carrier privileges. 2028 * @see #hasCarrierPrivileges 2029 * 2030 * @param alphaTag alpha-tagging of the dailing nubmer 2031 * @param number The dialing number 2032 * @return true if the operation was executed correctly. 2033 */ 2034 public boolean setLine1NumberForDisplay(String alphaTag, String number) { 2035 return setLine1NumberForDisplayForSubscriber(getDefaultSubscription(), alphaTag, number); 2036 } 2037 2038 /** 2039 * Set the line 1 phone number string and its alphatag for the current ICCID 2040 * for display purpose only, for example, displayed in Phone Status. It won't 2041 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 2042 * value. 2043 * 2044 * <p>Requires that the calling app has carrier privileges. 2045 * @see #hasCarrierPrivileges 2046 * 2047 * @param subId the subscriber that the alphatag and dialing number belongs to. 2048 * @param alphaTag alpha-tagging of the dailing nubmer 2049 * @param number The dialing number 2050 * @return true if the operation was executed correctly. 2051 * @hide 2052 */ 2053 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, String number) { 2054 try { 2055 ITelephony telephony = getITelephony(); 2056 if (telephony != null) 2057 return telephony.setLine1NumberForDisplayForSubscriber(subId, alphaTag, number); 2058 } catch (RemoteException ex) { 2059 } catch (NullPointerException ex) { 2060 } 2061 return false; 2062 } 2063 2064 /** 2065 * Informs the system of an intentional upcoming carrier network change by 2066 * a carrier app. This call is optional and is only used to allow the 2067 * system to provide alternative UI while telephony is performing an action 2068 * that may result in intentional, temporary network lack of connectivity. 2069 * <p> 2070 * Based on the active parameter passed in, this method will either show or 2071 * hide the alternative UI. There is no timeout associated with showing 2072 * this UX, so a carrier app must be sure to call with active set to false 2073 * sometime after calling with it set to true. 2074 * <p> 2075 * Requires Permission: 2076 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2077 * Or the calling app has carrier privileges. 2078 * @see #hasCarrierPrivileges 2079 * 2080 * @param active Whether the carrier network change is or shortly will be 2081 * active. Set this value to true to begin showing 2082 * alternative UI and false to stop. 2083 */ 2084 public void notifyCarrierNetworkChange(boolean active) { 2085 try { 2086 if (sRegistry != null) 2087 sRegistry.notifyCarrierNetworkChange(active); 2088 } catch (RemoteException ex) { 2089 } catch (NullPointerException ex) { 2090 } 2091 } 2092 2093 /** 2094 * Returns the alphabetic identifier associated with the line 1 number. 2095 * Return null if it is unavailable. 2096 * <p> 2097 * Requires Permission: 2098 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2099 * @hide 2100 * nobody seems to call this. 2101 */ 2102 public String getLine1AlphaTag() { 2103 return getLine1AlphaTagForSubscriber(getDefaultSubscription()); 2104 } 2105 2106 /** 2107 * Returns the alphabetic identifier associated with the line 1 number 2108 * for a subscription. 2109 * Return null if it is unavailable. 2110 * <p> 2111 * Requires Permission: 2112 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2113 * @param subId whose alphabetic identifier associated with line 1 is returned 2114 * nobody seems to call this. 2115 */ 2116 /** {@hide} */ 2117 public String getLine1AlphaTagForSubscriber(int subId) { 2118 String alphaTag = null; 2119 try { 2120 ITelephony telephony = getITelephony(); 2121 if (telephony != null) 2122 alphaTag = telephony.getLine1AlphaTagForDisplay(subId, 2123 mContext.getOpPackageName()); 2124 } catch (RemoteException ex) { 2125 } catch (NullPointerException ex) { 2126 } 2127 if (alphaTag != null) { 2128 return alphaTag; 2129 } 2130 try { 2131 IPhoneSubInfo info = getSubscriberInfo(); 2132 if (info == null) 2133 return null; 2134 return info.getLine1AlphaTagForSubscriber(subId); 2135 } catch (RemoteException ex) { 2136 return null; 2137 } catch (NullPointerException ex) { 2138 // This could happen before phone restarts due to crashing 2139 return null; 2140 } 2141 } 2142 2143 /** 2144 * Return the set of subscriber IDs that should be considered as "merged 2145 * together" for data usage purposes. This is commonly {@code null} to 2146 * indicate no merging is required. Any returned subscribers are sorted in a 2147 * deterministic order. 2148 * 2149 * @hide 2150 */ 2151 public @Nullable String[] getMergedSubscriberIds() { 2152 try { 2153 ITelephony telephony = getITelephony(); 2154 if (telephony != null) 2155 return telephony.getMergedSubscriberIds(); 2156 } catch (RemoteException ex) { 2157 } catch (NullPointerException ex) { 2158 } 2159 return null; 2160 } 2161 2162 /** 2163 * Returns the MSISDN string. 2164 * for a GSM phone. Return null if it is unavailable. 2165 * <p> 2166 * Requires Permission: 2167 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2168 * 2169 * @hide 2170 */ 2171 public String getMsisdn() { 2172 return getMsisdn(getDefaultSubscription()); 2173 } 2174 2175 /** 2176 * Returns the MSISDN string. 2177 * for a GSM phone. Return null if it is unavailable. 2178 * <p> 2179 * Requires Permission: 2180 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2181 * 2182 * @param subId for which msisdn is returned 2183 */ 2184 /** {@hide} */ 2185 public String getMsisdn(int subId) { 2186 try { 2187 IPhoneSubInfo info = getSubscriberInfo(); 2188 if (info == null) 2189 return null; 2190 return info.getMsisdnForSubscriber(subId); 2191 } catch (RemoteException ex) { 2192 return null; 2193 } catch (NullPointerException ex) { 2194 // This could happen before phone restarts due to crashing 2195 return null; 2196 } 2197 } 2198 2199 /** 2200 * Returns the voice mail number. Return null if it is unavailable. 2201 * <p> 2202 * Requires Permission: 2203 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2204 */ 2205 public String getVoiceMailNumber() { 2206 return getVoiceMailNumber(getDefaultSubscription()); 2207 } 2208 2209 /** 2210 * Returns the voice mail number for a subscription. 2211 * Return null if it is unavailable. 2212 * <p> 2213 * Requires Permission: 2214 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2215 * @param subId whose voice mail number is returned 2216 */ 2217 /** {@hide} */ 2218 public String getVoiceMailNumber(int subId) { 2219 try { 2220 IPhoneSubInfo info = getSubscriberInfo(); 2221 if (info == null) 2222 return null; 2223 return info.getVoiceMailNumberForSubscriber(subId); 2224 } catch (RemoteException ex) { 2225 return null; 2226 } catch (NullPointerException ex) { 2227 // This could happen before phone restarts due to crashing 2228 return null; 2229 } 2230 } 2231 2232 /** 2233 * Returns the complete voice mail number. Return null if it is unavailable. 2234 * <p> 2235 * Requires Permission: 2236 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 2237 * 2238 * @hide 2239 */ 2240 public String getCompleteVoiceMailNumber() { 2241 return getCompleteVoiceMailNumber(getDefaultSubscription()); 2242 } 2243 2244 /** 2245 * Returns the complete voice mail number. Return null if it is unavailable. 2246 * <p> 2247 * Requires Permission: 2248 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 2249 * 2250 * @param subId 2251 */ 2252 /** {@hide} */ 2253 public String getCompleteVoiceMailNumber(int subId) { 2254 try { 2255 IPhoneSubInfo info = getSubscriberInfo(); 2256 if (info == null) 2257 return null; 2258 return info.getCompleteVoiceMailNumberForSubscriber(subId); 2259 } catch (RemoteException ex) { 2260 return null; 2261 } catch (NullPointerException ex) { 2262 // This could happen before phone restarts due to crashing 2263 return null; 2264 } 2265 } 2266 2267 /** 2268 * Sets the voice mail number. 2269 * 2270 * <p>Requires that the calling app has carrier privileges. 2271 * @see #hasCarrierPrivileges 2272 * 2273 * @param alphaTag The alpha tag to display. 2274 * @param number The voicemail number. 2275 */ 2276 public boolean setVoiceMailNumber(String alphaTag, String number) { 2277 return setVoiceMailNumber(getDefaultSubscription(), alphaTag, number); 2278 } 2279 2280 /** 2281 * Sets the voicemail number for the given subscriber. 2282 * 2283 * <p>Requires that the calling app has carrier privileges. 2284 * @see #hasCarrierPrivileges 2285 * 2286 * @param subId The subscription id. 2287 * @param alphaTag The alpha tag to display. 2288 * @param number The voicemail number. 2289 */ 2290 /** {@hide} */ 2291 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { 2292 try { 2293 ITelephony telephony = getITelephony(); 2294 if (telephony != null) 2295 return telephony.setVoiceMailNumber(subId, alphaTag, number); 2296 } catch (RemoteException ex) { 2297 } catch (NullPointerException ex) { 2298 } 2299 return false; 2300 } 2301 2302 /** 2303 * Returns the voice mail count. Return 0 if unavailable. 2304 * <p> 2305 * Requires Permission: 2306 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2307 * @hide 2308 */ 2309 public int getVoiceMessageCount() { 2310 return getVoiceMessageCount(getDefaultSubscription()); 2311 } 2312 2313 /** 2314 * Returns the voice mail count for a subscription. Return 0 if unavailable. 2315 * <p> 2316 * Requires Permission: 2317 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2318 * @param subId whose voice message count is returned 2319 */ 2320 /** {@hide} */ 2321 public int getVoiceMessageCount(int subId) { 2322 try { 2323 ITelephony telephony = getITelephony(); 2324 if (telephony == null) 2325 return 0; 2326 return telephony.getVoiceMessageCountForSubscriber(subId); 2327 } catch (RemoteException ex) { 2328 return 0; 2329 } catch (NullPointerException ex) { 2330 // This could happen before phone restarts due to crashing 2331 return 0; 2332 } 2333 } 2334 2335 /** 2336 * Retrieves the alphabetic identifier associated with the voice 2337 * mail number. 2338 * <p> 2339 * Requires Permission: 2340 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2341 */ 2342 public String getVoiceMailAlphaTag() { 2343 return getVoiceMailAlphaTag(getDefaultSubscription()); 2344 } 2345 2346 /** 2347 * Retrieves the alphabetic identifier associated with the voice 2348 * mail number for a subscription. 2349 * <p> 2350 * Requires Permission: 2351 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2352 * @param subId whose alphabetic identifier associated with the 2353 * voice mail number is returned 2354 */ 2355 /** {@hide} */ 2356 public String getVoiceMailAlphaTag(int subId) { 2357 try { 2358 IPhoneSubInfo info = getSubscriberInfo(); 2359 if (info == null) 2360 return null; 2361 return info.getVoiceMailAlphaTagForSubscriber(subId); 2362 } catch (RemoteException ex) { 2363 return null; 2364 } catch (NullPointerException ex) { 2365 // This could happen before phone restarts due to crashing 2366 return null; 2367 } 2368 } 2369 2370 /** 2371 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 2372 * @return the IMPI, or null if not present or not loaded 2373 * @hide 2374 */ 2375 public String getIsimImpi() { 2376 try { 2377 IPhoneSubInfo info = getSubscriberInfo(); 2378 if (info == null) 2379 return null; 2380 return info.getIsimImpi(); 2381 } catch (RemoteException ex) { 2382 return null; 2383 } catch (NullPointerException ex) { 2384 // This could happen before phone restarts due to crashing 2385 return null; 2386 } 2387 } 2388 2389 /** 2390 * Returns the IMS home network domain name that was loaded from the ISIM. 2391 * @return the IMS domain name, or null if not present or not loaded 2392 * @hide 2393 */ 2394 public String getIsimDomain() { 2395 try { 2396 IPhoneSubInfo info = getSubscriberInfo(); 2397 if (info == null) 2398 return null; 2399 return info.getIsimDomain(); 2400 } catch (RemoteException ex) { 2401 return null; 2402 } catch (NullPointerException ex) { 2403 // This could happen before phone restarts due to crashing 2404 return null; 2405 } 2406 } 2407 2408 /** 2409 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 2410 * @return an array of IMPU strings, with one IMPU per string, or null if 2411 * not present or not loaded 2412 * @hide 2413 */ 2414 public String[] getIsimImpu() { 2415 try { 2416 IPhoneSubInfo info = getSubscriberInfo(); 2417 if (info == null) 2418 return null; 2419 return info.getIsimImpu(); 2420 } catch (RemoteException ex) { 2421 return null; 2422 } catch (NullPointerException ex) { 2423 // This could happen before phone restarts due to crashing 2424 return null; 2425 } 2426 } 2427 2428 /** 2429 * @hide 2430 */ 2431 private IPhoneSubInfo getSubscriberInfo() { 2432 // get it each time because that process crashes a lot 2433 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 2434 } 2435 2436 /** Device call state: No activity. */ 2437 public static final int CALL_STATE_IDLE = 0; 2438 /** Device call state: Ringing. A new call arrived and is 2439 * ringing or waiting. In the latter case, another call is 2440 * already active. */ 2441 public static final int CALL_STATE_RINGING = 1; 2442 /** Device call state: Off-hook. At least one call exists 2443 * that is dialing, active, or on hold, and no calls are ringing 2444 * or waiting. */ 2445 public static final int CALL_STATE_OFFHOOK = 2; 2446 2447 /** 2448 * Returns a constant indicating the call state (cellular) on the device. 2449 */ 2450 public int getCallState() { 2451 return getCallState(getDefaultSubscription()); 2452 } 2453 2454 /** 2455 * Returns a constant indicating the call state (cellular) on the device 2456 * for a subscription. 2457 * 2458 * @param subId whose call state is returned 2459 */ 2460 /** {@hide} */ 2461 public int getCallState(int subId) { 2462 try { 2463 ITelephony telephony = getITelephony(); 2464 if (telephony == null) 2465 return CALL_STATE_IDLE; 2466 return telephony.getCallStateForSubscriber(subId); 2467 } catch (RemoteException ex) { 2468 // the phone process is restarting. 2469 return CALL_STATE_IDLE; 2470 } catch (NullPointerException ex) { 2471 // the phone process is restarting. 2472 return CALL_STATE_IDLE; 2473 } 2474 } 2475 2476 /** Data connection activity: No traffic. */ 2477 public static final int DATA_ACTIVITY_NONE = 0x00000000; 2478 /** Data connection activity: Currently receiving IP PPP traffic. */ 2479 public static final int DATA_ACTIVITY_IN = 0x00000001; 2480 /** Data connection activity: Currently sending IP PPP traffic. */ 2481 public static final int DATA_ACTIVITY_OUT = 0x00000002; 2482 /** Data connection activity: Currently both sending and receiving 2483 * IP PPP traffic. */ 2484 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 2485 /** 2486 * Data connection is active, but physical link is down 2487 */ 2488 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 2489 2490 /** 2491 * Returns a constant indicating the type of activity on a data connection 2492 * (cellular). 2493 * 2494 * @see #DATA_ACTIVITY_NONE 2495 * @see #DATA_ACTIVITY_IN 2496 * @see #DATA_ACTIVITY_OUT 2497 * @see #DATA_ACTIVITY_INOUT 2498 * @see #DATA_ACTIVITY_DORMANT 2499 */ 2500 public int getDataActivity() { 2501 try { 2502 ITelephony telephony = getITelephony(); 2503 if (telephony == null) 2504 return DATA_ACTIVITY_NONE; 2505 return telephony.getDataActivity(); 2506 } catch (RemoteException ex) { 2507 // the phone process is restarting. 2508 return DATA_ACTIVITY_NONE; 2509 } catch (NullPointerException ex) { 2510 // the phone process is restarting. 2511 return DATA_ACTIVITY_NONE; 2512 } 2513 } 2514 2515 /** Data connection state: Unknown. Used before we know the state. 2516 * @hide 2517 */ 2518 public static final int DATA_UNKNOWN = -1; 2519 /** Data connection state: Disconnected. IP traffic not available. */ 2520 public static final int DATA_DISCONNECTED = 0; 2521 /** Data connection state: Currently setting up a data connection. */ 2522 public static final int DATA_CONNECTING = 1; 2523 /** Data connection state: Connected. IP traffic should be available. */ 2524 public static final int DATA_CONNECTED = 2; 2525 /** Data connection state: Suspended. The connection is up, but IP 2526 * traffic is temporarily unavailable. For example, in a 2G network, 2527 * data activity may be suspended when a voice call arrives. */ 2528 public static final int DATA_SUSPENDED = 3; 2529 2530 /** 2531 * Returns a constant indicating the current data connection state 2532 * (cellular). 2533 * 2534 * @see #DATA_DISCONNECTED 2535 * @see #DATA_CONNECTING 2536 * @see #DATA_CONNECTED 2537 * @see #DATA_SUSPENDED 2538 */ 2539 public int getDataState() { 2540 try { 2541 ITelephony telephony = getITelephony(); 2542 if (telephony == null) 2543 return DATA_DISCONNECTED; 2544 return telephony.getDataState(); 2545 } catch (RemoteException ex) { 2546 // the phone process is restarting. 2547 return DATA_DISCONNECTED; 2548 } catch (NullPointerException ex) { 2549 return DATA_DISCONNECTED; 2550 } 2551 } 2552 2553 /** 2554 * @hide 2555 */ 2556 private ITelephony getITelephony() { 2557 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 2558 } 2559 2560 /** 2561 * @hide 2562 */ 2563 private ITelecomService getTelecomService() { 2564 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); 2565 } 2566 2567 // 2568 // 2569 // PhoneStateListener 2570 // 2571 // 2572 2573 /** 2574 * Registers a listener object to receive notification of changes 2575 * in specified telephony states. 2576 * <p> 2577 * To register a listener, pass a {@link PhoneStateListener} 2578 * and specify at least one telephony state of interest in 2579 * the events argument. 2580 * 2581 * At registration, and when a specified telephony state 2582 * changes, the telephony manager invokes the appropriate 2583 * callback method on the listener object and passes the 2584 * current (updated) values. 2585 * <p> 2586 * To unregister a listener, pass the listener object and set the 2587 * events argument to 2588 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 2589 * 2590 * @param listener The {@link PhoneStateListener} object to register 2591 * (or unregister) 2592 * @param events The telephony state(s) of interest to the listener, 2593 * as a bitwise-OR combination of {@link PhoneStateListener} 2594 * LISTEN_ flags. 2595 */ 2596 public void listen(PhoneStateListener listener, int events) { 2597 if (mContext == null) return; 2598 try { 2599 Boolean notifyNow = (getITelephony() != null); 2600 sRegistry.listenForSubscriber(listener.mSubId, mContext.getOpPackageName(), 2601 listener.callback, events, notifyNow); 2602 } catch (RemoteException ex) { 2603 // system process dead 2604 } catch (NullPointerException ex) { 2605 // system process dead 2606 } 2607 } 2608 2609 /** 2610 * Returns the CDMA ERI icon index to display 2611 * 2612 * @hide 2613 */ 2614 public int getCdmaEriIconIndex() { 2615 return getCdmaEriIconIndex(getDefaultSubscription()); 2616 } 2617 2618 /** 2619 * Returns the CDMA ERI icon index to display for a subscription 2620 */ 2621 /** {@hide} */ 2622 public int getCdmaEriIconIndex(int subId) { 2623 try { 2624 ITelephony telephony = getITelephony(); 2625 if (telephony == null) 2626 return -1; 2627 return telephony.getCdmaEriIconIndexForSubscriber(subId); 2628 } catch (RemoteException ex) { 2629 // the phone process is restarting. 2630 return -1; 2631 } catch (NullPointerException ex) { 2632 return -1; 2633 } 2634 } 2635 2636 /** 2637 * Returns the CDMA ERI icon mode, 2638 * 0 - ON 2639 * 1 - FLASHING 2640 * 2641 * @hide 2642 */ 2643 public int getCdmaEriIconMode() { 2644 return getCdmaEriIconMode(getDefaultSubscription()); 2645 } 2646 2647 /** 2648 * Returns the CDMA ERI icon mode for a subscription. 2649 * 0 - ON 2650 * 1 - FLASHING 2651 */ 2652 /** {@hide} */ 2653 public int getCdmaEriIconMode(int subId) { 2654 try { 2655 ITelephony telephony = getITelephony(); 2656 if (telephony == null) 2657 return -1; 2658 return telephony.getCdmaEriIconModeForSubscriber(subId); 2659 } catch (RemoteException ex) { 2660 // the phone process is restarting. 2661 return -1; 2662 } catch (NullPointerException ex) { 2663 return -1; 2664 } 2665 } 2666 2667 /** 2668 * Returns the CDMA ERI text, 2669 * 2670 * @hide 2671 */ 2672 public String getCdmaEriText() { 2673 return getCdmaEriText(getDefaultSubscription()); 2674 } 2675 2676 /** 2677 * Returns the CDMA ERI text, of a subscription 2678 * 2679 */ 2680 /** {@hide} */ 2681 public String getCdmaEriText(int subId) { 2682 try { 2683 ITelephony telephony = getITelephony(); 2684 if (telephony == null) 2685 return null; 2686 return telephony.getCdmaEriTextForSubscriber(subId); 2687 } catch (RemoteException ex) { 2688 // the phone process is restarting. 2689 return null; 2690 } catch (NullPointerException ex) { 2691 return null; 2692 } 2693 } 2694 2695 /** 2696 * @return true if the current device is "voice capable". 2697 * <p> 2698 * "Voice capable" means that this device supports circuit-switched 2699 * (i.e. voice) phone calls over the telephony network, and is allowed 2700 * to display the in-call UI while a cellular voice call is active. 2701 * This will be false on "data only" devices which can't make voice 2702 * calls and don't support any in-call UI. 2703 * <p> 2704 * Note: the meaning of this flag is subtly different from the 2705 * PackageManager.FEATURE_TELEPHONY system feature, which is available 2706 * on any device with a telephony radio, even if the device is 2707 * data-only. 2708 */ 2709 public boolean isVoiceCapable() { 2710 if (mContext == null) return true; 2711 return mContext.getResources().getBoolean( 2712 com.android.internal.R.bool.config_voice_capable); 2713 } 2714 2715 /** 2716 * @return true if the current device supports sms service. 2717 * <p> 2718 * If true, this means that the device supports both sending and 2719 * receiving sms via the telephony network. 2720 * <p> 2721 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 2722 * disabled when device doesn't support sms. 2723 */ 2724 public boolean isSmsCapable() { 2725 if (mContext == null) return true; 2726 return mContext.getResources().getBoolean( 2727 com.android.internal.R.bool.config_sms_capable); 2728 } 2729 2730 /** 2731 * Returns all observed cell information from all radios on the 2732 * device including the primary and neighboring cells. This does 2733 * not cause or change the rate of PhoneStateListner#onCellInfoChanged. 2734 *<p> 2735 * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm}, 2736 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 2737 * {@link android.telephony.CellInfoLte CellInfoLte} and 2738 * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination. 2739 * Specifically on devices with multiple radios it is typical to see instances of 2740 * one or more of any these in the list. In addition 0, 1 or more CellInfo 2741 * objects may return isRegistered() true. 2742 *<p> 2743 * This is preferred over using getCellLocation although for older 2744 * devices this may return null in which case getCellLocation should 2745 * be called. 2746 *<p> 2747 * @return List of CellInfo or null if info unavailable. 2748 * 2749 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 2750 */ 2751 public List<CellInfo> getAllCellInfo() { 2752 try { 2753 ITelephony telephony = getITelephony(); 2754 if (telephony == null) 2755 return null; 2756 return telephony.getAllCellInfo(mContext.getOpPackageName()); 2757 } catch (RemoteException ex) { 2758 return null; 2759 } catch (NullPointerException ex) { 2760 return null; 2761 } 2762 } 2763 2764 /** 2765 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 2766 * PhoneStateListener.onCellInfoChanged} will be invoked. 2767 *<p> 2768 * The default, 0, means invoke onCellInfoChanged when any of the reported 2769 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 2770 * A onCellInfoChanged. 2771 *<p> 2772 * @param rateInMillis the rate 2773 * 2774 * @hide 2775 */ 2776 public void setCellInfoListRate(int rateInMillis) { 2777 try { 2778 ITelephony telephony = getITelephony(); 2779 if (telephony != null) 2780 telephony.setCellInfoListRate(rateInMillis); 2781 } catch (RemoteException ex) { 2782 } catch (NullPointerException ex) { 2783 } 2784 } 2785 2786 /** 2787 * Returns the MMS user agent. 2788 */ 2789 public String getMmsUserAgent() { 2790 if (mContext == null) return null; 2791 return mContext.getResources().getString( 2792 com.android.internal.R.string.config_mms_user_agent); 2793 } 2794 2795 /** 2796 * Returns the MMS user agent profile URL. 2797 */ 2798 public String getMmsUAProfUrl() { 2799 if (mContext == null) return null; 2800 return mContext.getResources().getString( 2801 com.android.internal.R.string.config_mms_user_agent_profile_url); 2802 } 2803 2804 /** 2805 * Opens a logical channel to the ICC card. 2806 * 2807 * Input parameters equivalent to TS 27.007 AT+CCHO command. 2808 * 2809 * <p>Requires Permission: 2810 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2811 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2812 * 2813 * @param AID Application id. See ETSI 102.221 and 101.220. 2814 * @return an IccOpenLogicalChannelResponse object. 2815 */ 2816 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { 2817 try { 2818 ITelephony telephony = getITelephony(); 2819 if (telephony != null) 2820 return telephony.iccOpenLogicalChannel(AID); 2821 } catch (RemoteException ex) { 2822 } catch (NullPointerException ex) { 2823 } 2824 return null; 2825 } 2826 2827 /** 2828 * Closes a previously opened logical channel to the ICC card. 2829 * 2830 * Input parameters equivalent to TS 27.007 AT+CCHC command. 2831 * 2832 * <p>Requires Permission: 2833 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2834 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2835 * 2836 * @param channel is the channel id to be closed as retruned by a successful 2837 * iccOpenLogicalChannel. 2838 * @return true if the channel was closed successfully. 2839 */ 2840 public boolean iccCloseLogicalChannel(int channel) { 2841 try { 2842 ITelephony telephony = getITelephony(); 2843 if (telephony != null) 2844 return telephony.iccCloseLogicalChannel(channel); 2845 } catch (RemoteException ex) { 2846 } catch (NullPointerException ex) { 2847 } 2848 return false; 2849 } 2850 2851 /** 2852 * Transmit an APDU to the ICC card over a logical channel. 2853 * 2854 * Input parameters equivalent to TS 27.007 AT+CGLA command. 2855 * 2856 * <p>Requires Permission: 2857 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2858 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2859 * 2860 * @param channel is the channel id to be closed as returned by a successful 2861 * iccOpenLogicalChannel. 2862 * @param cla Class of the APDU command. 2863 * @param instruction Instruction of the APDU command. 2864 * @param p1 P1 value of the APDU command. 2865 * @param p2 P2 value of the APDU command. 2866 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2867 * is sent to the SIM. 2868 * @param data Data to be sent with the APDU. 2869 * @return The APDU response from the ICC card with the status appended at 2870 * the end. 2871 */ 2872 public String iccTransmitApduLogicalChannel(int channel, int cla, 2873 int instruction, int p1, int p2, int p3, String data) { 2874 try { 2875 ITelephony telephony = getITelephony(); 2876 if (telephony != null) 2877 return telephony.iccTransmitApduLogicalChannel(channel, cla, 2878 instruction, p1, p2, p3, data); 2879 } catch (RemoteException ex) { 2880 } catch (NullPointerException ex) { 2881 } 2882 return ""; 2883 } 2884 2885 /** 2886 * Transmit an APDU to the ICC card over the basic channel. 2887 * 2888 * Input parameters equivalent to TS 27.007 AT+CSIM command. 2889 * 2890 * <p>Requires Permission: 2891 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2892 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2893 * 2894 * @param cla Class of the APDU command. 2895 * @param instruction Instruction of the APDU command. 2896 * @param p1 P1 value of the APDU command. 2897 * @param p2 P2 value of the APDU command. 2898 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2899 * is sent to the SIM. 2900 * @param data Data to be sent with the APDU. 2901 * @return The APDU response from the ICC card with the status appended at 2902 * the end. 2903 */ 2904 public String iccTransmitApduBasicChannel(int cla, 2905 int instruction, int p1, int p2, int p3, String data) { 2906 try { 2907 ITelephony telephony = getITelephony(); 2908 if (telephony != null) 2909 return telephony.iccTransmitApduBasicChannel(cla, 2910 instruction, p1, p2, p3, data); 2911 } catch (RemoteException ex) { 2912 } catch (NullPointerException ex) { 2913 } 2914 return ""; 2915 } 2916 2917 /** 2918 * Returns the response APDU for a command APDU sent through SIM_IO. 2919 * 2920 * <p>Requires Permission: 2921 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2922 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2923 * 2924 * @param fileID 2925 * @param command 2926 * @param p1 P1 value of the APDU command. 2927 * @param p2 P2 value of the APDU command. 2928 * @param p3 P3 value of the APDU command. 2929 * @param filePath 2930 * @return The APDU response. 2931 */ 2932 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 2933 String filePath) { 2934 try { 2935 ITelephony telephony = getITelephony(); 2936 if (telephony != null) 2937 return telephony.iccExchangeSimIO(fileID, command, p1, p2, p3, filePath); 2938 } catch (RemoteException ex) { 2939 } catch (NullPointerException ex) { 2940 } 2941 return null; 2942 } 2943 2944 /** 2945 * Send ENVELOPE to the SIM and return the response. 2946 * 2947 * <p>Requires Permission: 2948 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2949 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2950 * 2951 * @param content String containing SAT/USAT response in hexadecimal 2952 * format starting with command tag. See TS 102 223 for 2953 * details. 2954 * @return The APDU response from the ICC card in hexadecimal format 2955 * with the last 4 bytes being the status word. If the command fails, 2956 * returns an empty string. 2957 */ 2958 public String sendEnvelopeWithStatus(String content) { 2959 try { 2960 ITelephony telephony = getITelephony(); 2961 if (telephony != null) 2962 return telephony.sendEnvelopeWithStatus(content); 2963 } catch (RemoteException ex) { 2964 } catch (NullPointerException ex) { 2965 } 2966 return ""; 2967 } 2968 2969 /** 2970 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 2971 * Used for device configuration by some CDMA operators. 2972 * <p> 2973 * Requires Permission: 2974 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2975 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2976 * 2977 * @param itemID the ID of the item to read. 2978 * @return the NV item as a String, or null on any failure. 2979 * 2980 * @hide 2981 */ 2982 public String nvReadItem(int itemID) { 2983 try { 2984 ITelephony telephony = getITelephony(); 2985 if (telephony != null) 2986 return telephony.nvReadItem(itemID); 2987 } catch (RemoteException ex) { 2988 Rlog.e(TAG, "nvReadItem RemoteException", ex); 2989 } catch (NullPointerException ex) { 2990 Rlog.e(TAG, "nvReadItem NPE", ex); 2991 } 2992 return ""; 2993 } 2994 2995 /** 2996 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 2997 * Used for device configuration by some CDMA operators. 2998 * <p> 2999 * Requires Permission: 3000 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3001 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3002 * 3003 * @param itemID the ID of the item to read. 3004 * @param itemValue the value to write, as a String. 3005 * @return true on success; false on any failure. 3006 * 3007 * @hide 3008 */ 3009 public boolean nvWriteItem(int itemID, String itemValue) { 3010 try { 3011 ITelephony telephony = getITelephony(); 3012 if (telephony != null) 3013 return telephony.nvWriteItem(itemID, itemValue); 3014 } catch (RemoteException ex) { 3015 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 3016 } catch (NullPointerException ex) { 3017 Rlog.e(TAG, "nvWriteItem NPE", ex); 3018 } 3019 return false; 3020 } 3021 3022 /** 3023 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 3024 * Used for device configuration by some CDMA operators. 3025 * <p> 3026 * Requires Permission: 3027 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3028 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3029 * 3030 * @param preferredRoamingList byte array containing the new PRL. 3031 * @return true on success; false on any failure. 3032 * 3033 * @hide 3034 */ 3035 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 3036 try { 3037 ITelephony telephony = getITelephony(); 3038 if (telephony != null) 3039 return telephony.nvWriteCdmaPrl(preferredRoamingList); 3040 } catch (RemoteException ex) { 3041 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 3042 } catch (NullPointerException ex) { 3043 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 3044 } 3045 return false; 3046 } 3047 3048 /** 3049 * Perform the specified type of NV config reset. The radio will be taken offline 3050 * and the device must be rebooted after the operation. Used for device 3051 * configuration by some CDMA operators. 3052 * <p> 3053 * Requires Permission: 3054 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3055 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3056 * 3057 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 3058 * @return true on success; false on any failure. 3059 * 3060 * @hide 3061 */ 3062 public boolean nvResetConfig(int resetType) { 3063 try { 3064 ITelephony telephony = getITelephony(); 3065 if (telephony != null) 3066 return telephony.nvResetConfig(resetType); 3067 } catch (RemoteException ex) { 3068 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 3069 } catch (NullPointerException ex) { 3070 Rlog.e(TAG, "nvResetConfig NPE", ex); 3071 } 3072 return false; 3073 } 3074 3075 /** 3076 * Returns Default subscription. 3077 */ 3078 private static int getDefaultSubscription() { 3079 return SubscriptionManager.getDefaultSubId(); 3080 } 3081 3082 /** 3083 * Returns Default phone. 3084 */ 3085 private static int getDefaultPhone() { 3086 return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubId()); 3087 } 3088 3089 /** {@hide} */ 3090 public int getDefaultSim() { 3091 return SubscriptionManager.getSlotId(SubscriptionManager.getDefaultSubId()); 3092 } 3093 3094 /** 3095 * Sets the telephony property with the value specified. 3096 * 3097 * @hide 3098 */ 3099 public static void setTelephonyProperty(int phoneId, String property, String value) { 3100 String propVal = ""; 3101 String p[] = null; 3102 String prop = SystemProperties.get(property); 3103 3104 if (value == null) { 3105 value = ""; 3106 } 3107 3108 if (prop != null) { 3109 p = prop.split(","); 3110 } 3111 3112 if (!SubscriptionManager.isValidPhoneId(phoneId)) { 3113 Rlog.d(TAG, "setTelephonyProperty: invalid phoneId=" + phoneId + 3114 " property=" + property + " value: " + value + " prop=" + prop); 3115 return; 3116 } 3117 3118 for (int i = 0; i < phoneId; i++) { 3119 String str = ""; 3120 if ((p != null) && (i < p.length)) { 3121 str = p[i]; 3122 } 3123 propVal = propVal + str + ","; 3124 } 3125 3126 propVal = propVal + value; 3127 if (p != null) { 3128 for (int i = phoneId + 1; i < p.length; i++) { 3129 propVal = propVal + "," + p[i]; 3130 } 3131 } 3132 3133 if (property.length() > SystemProperties.PROP_NAME_MAX 3134 || propVal.length() > SystemProperties.PROP_VALUE_MAX) { 3135 Rlog.d(TAG, "setTelephonyProperty: property to long phoneId=" + phoneId + 3136 " property=" + property + " value: " + value + " propVal=" + propVal); 3137 return; 3138 } 3139 3140 Rlog.d(TAG, "setTelephonyProperty: success phoneId=" + phoneId + 3141 " property=" + property + " value: " + value + " propVal=" + propVal); 3142 SystemProperties.set(property, propVal); 3143 } 3144 3145 /** 3146 * Convenience function for retrieving a value from the secure settings 3147 * value list as an integer. Note that internally setting values are 3148 * always stored as strings; this function converts the string to an 3149 * integer for you. 3150 * <p> 3151 * This version does not take a default value. If the setting has not 3152 * been set, or the string value is not a number, 3153 * it throws {@link SettingNotFoundException}. 3154 * 3155 * @param cr The ContentResolver to access. 3156 * @param name The name of the setting to retrieve. 3157 * @param index The index of the list 3158 * 3159 * @throws SettingNotFoundException Thrown if a setting by the given 3160 * name can't be found or the setting value is not an integer. 3161 * 3162 * @return The value at the given index of settings. 3163 * @hide 3164 */ 3165 public static int getIntAtIndex(android.content.ContentResolver cr, 3166 String name, int index) 3167 throws android.provider.Settings.SettingNotFoundException { 3168 String v = android.provider.Settings.Global.getString(cr, name); 3169 if (v != null) { 3170 String valArray[] = v.split(","); 3171 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 3172 try { 3173 return Integer.parseInt(valArray[index]); 3174 } catch (NumberFormatException e) { 3175 //Log.e(TAG, "Exception while parsing Integer: ", e); 3176 } 3177 } 3178 } 3179 throw new android.provider.Settings.SettingNotFoundException(name); 3180 } 3181 3182 /** 3183 * Convenience function for updating settings value as coma separated 3184 * integer values. This will either create a new entry in the table if the 3185 * given name does not exist, or modify the value of the existing row 3186 * with that name. Note that internally setting values are always 3187 * stored as strings, so this function converts the given value to a 3188 * string before storing it. 3189 * 3190 * @param cr The ContentResolver to access. 3191 * @param name The name of the setting to modify. 3192 * @param index The index of the list 3193 * @param value The new value for the setting to be added to the list. 3194 * @return true if the value was set, false on database errors 3195 * @hide 3196 */ 3197 public static boolean putIntAtIndex(android.content.ContentResolver cr, 3198 String name, int index, int value) { 3199 String data = ""; 3200 String valArray[] = null; 3201 String v = android.provider.Settings.Global.getString(cr, name); 3202 3203 if (index == Integer.MAX_VALUE) { 3204 throw new RuntimeException("putIntAtIndex index == MAX_VALUE index=" + index); 3205 } 3206 if (index < 0) { 3207 throw new RuntimeException("putIntAtIndex index < 0 index=" + index); 3208 } 3209 if (v != null) { 3210 valArray = v.split(","); 3211 } 3212 3213 // Copy the elements from valArray till index 3214 for (int i = 0; i < index; i++) { 3215 String str = ""; 3216 if ((valArray != null) && (i < valArray.length)) { 3217 str = valArray[i]; 3218 } 3219 data = data + str + ","; 3220 } 3221 3222 data = data + value; 3223 3224 // Copy the remaining elements from valArray if any. 3225 if (valArray != null) { 3226 for (int i = index+1; i < valArray.length; i++) { 3227 data = data + "," + valArray[i]; 3228 } 3229 } 3230 return android.provider.Settings.Global.putString(cr, name, data); 3231 } 3232 3233 /** 3234 * Gets the telephony property. 3235 * 3236 * @hide 3237 */ 3238 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 3239 String propVal = null; 3240 String prop = SystemProperties.get(property); 3241 if ((prop != null) && (prop.length() > 0)) { 3242 String values[] = prop.split(","); 3243 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 3244 propVal = values[phoneId]; 3245 } 3246 } 3247 Rlog.d(TAG, "getTelephonyProperty: return propVal='" + propVal + "' phoneId=" + phoneId 3248 + " property='" + property + "' defaultVal='" + defaultVal + "' prop=" + prop); 3249 return propVal == null ? defaultVal : propVal; 3250 } 3251 3252 /** @hide */ 3253 public int getSimCount() { 3254 // FIXME Need to get it from Telephony Dev Controller when that gets implemented! 3255 // and then this method shouldn't be used at all! 3256 if(isMultiSimEnabled()) { 3257 return 2; 3258 } else { 3259 return 1; 3260 } 3261 } 3262 3263 /** 3264 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 3265 * @return IMS Service Table or null if not present or not loaded 3266 * @hide 3267 */ 3268 public String getIsimIst() { 3269 try { 3270 IPhoneSubInfo info = getSubscriberInfo(); 3271 if (info == null) 3272 return null; 3273 return info.getIsimIst(); 3274 } catch (RemoteException ex) { 3275 return null; 3276 } catch (NullPointerException ex) { 3277 // This could happen before phone restarts due to crashing 3278 return null; 3279 } 3280 } 3281 3282 /** 3283 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 3284 * @return an array of PCSCF strings with one PCSCF per string, or null if 3285 * not present or not loaded 3286 * @hide 3287 */ 3288 public String[] getIsimPcscf() { 3289 try { 3290 IPhoneSubInfo info = getSubscriberInfo(); 3291 if (info == null) 3292 return null; 3293 return info.getIsimPcscf(); 3294 } catch (RemoteException ex) { 3295 return null; 3296 } catch (NullPointerException ex) { 3297 // This could happen before phone restarts due to crashing 3298 return null; 3299 } 3300 } 3301 3302 /** 3303 * Returns the response of ISIM Authetification through RIL. 3304 * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo. 3305 * @return the response of ISIM Authetification, or null if not available 3306 * @hide 3307 * @deprecated 3308 * @see getIccSimChallengeResponse with appType=PhoneConstants.APPTYPE_ISIM 3309 */ 3310 public String getIsimChallengeResponse(String nonce){ 3311 try { 3312 IPhoneSubInfo info = getSubscriberInfo(); 3313 if (info == null) 3314 return null; 3315 return info.getIsimChallengeResponse(nonce); 3316 } catch (RemoteException ex) { 3317 return null; 3318 } catch (NullPointerException ex) { 3319 // This could happen before phone restarts due to crashing 3320 return null; 3321 } 3322 } 3323 3324 /** 3325 * Returns the response of SIM Authentication through RIL. 3326 * Returns null if the Authentication hasn't been successful 3327 * @param subId subscription ID to be queried 3328 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3329 * @param data authentication challenge data 3330 * @return the response of SIM Authentication, or null if not available 3331 * @hide 3332 */ 3333 public String getIccSimChallengeResponse(int subId, int appType, String data) { 3334 try { 3335 IPhoneSubInfo info = getSubscriberInfo(); 3336 if (info == null) 3337 return null; 3338 return info.getIccSimChallengeResponse(subId, appType, data); 3339 } catch (RemoteException ex) { 3340 return null; 3341 } catch (NullPointerException ex) { 3342 // This could happen before phone starts 3343 return null; 3344 } 3345 } 3346 3347 /** 3348 * Returns the response of SIM Authentication through RIL for the default subscription. 3349 * Returns null if the Authentication hasn't been successful 3350 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3351 * @param data authentication challenge data 3352 * @return the response of SIM Authentication, or null if not available 3353 * @hide 3354 */ 3355 public String getIccSimChallengeResponse(int appType, String data) { 3356 return getIccSimChallengeResponse(getDefaultSubscription(), appType, data); 3357 } 3358 3359 /** 3360 * Get P-CSCF address from PCO after data connection is established or modified. 3361 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 3362 * @return array of P-CSCF address 3363 * @hide 3364 */ 3365 public String[] getPcscfAddress(String apnType) { 3366 try { 3367 ITelephony telephony = getITelephony(); 3368 if (telephony == null) 3369 return new String[0]; 3370 return telephony.getPcscfAddress(apnType, mContext.getOpPackageName()); 3371 } catch (RemoteException e) { 3372 return new String[0]; 3373 } 3374 } 3375 3376 /** 3377 * Set IMS registration state 3378 * 3379 * @param Registration state 3380 * @hide 3381 */ 3382 public void setImsRegistrationState(boolean registered) { 3383 try { 3384 ITelephony telephony = getITelephony(); 3385 if (telephony != null) 3386 telephony.setImsRegistrationState(registered); 3387 } catch (RemoteException e) { 3388 } 3389 } 3390 3391 /** 3392 * Get the preferred network type. 3393 * Used for device configuration by some CDMA operators. 3394 * <p> 3395 * Requires Permission: 3396 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3397 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3398 * 3399 * @return the preferred network type, defined in RILConstants.java. 3400 * @hide 3401 */ 3402 public int getPreferredNetworkType(int subId) { 3403 try { 3404 ITelephony telephony = getITelephony(); 3405 if (telephony != null) 3406 return telephony.getPreferredNetworkType(subId); 3407 } catch (RemoteException ex) { 3408 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 3409 } catch (NullPointerException ex) { 3410 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 3411 } 3412 return -1; 3413 } 3414 3415 /** 3416 * Sets the network selection mode to automatic. 3417 * <p> 3418 * Requires Permission: 3419 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3420 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3421 * 3422 * @hide 3423 */ 3424 public void setNetworkSelectionModeAutomatic(int subId) { 3425 try { 3426 ITelephony telephony = getITelephony(); 3427 if (telephony != null) 3428 telephony.setNetworkSelectionModeAutomatic(subId); 3429 } catch (RemoteException ex) { 3430 Rlog.e(TAG, "setNetworkSelectionModeAutomatic RemoteException", ex); 3431 } catch (NullPointerException ex) { 3432 Rlog.e(TAG, "setNetworkSelectionModeAutomatic NPE", ex); 3433 } 3434 } 3435 3436 /** 3437 * Set the preferred network type. 3438 * Used for device configuration by some CDMA operators. 3439 * <p> 3440 * Requires Permission: 3441 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3442 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3443 * 3444 * @param subId the id of the subscription to set the preferred network type for. 3445 * @param networkType the preferred network type, defined in RILConstants.java. 3446 * @return true on success; false on any failure. 3447 * @hide 3448 */ 3449 public boolean setPreferredNetworkType(int subId, int networkType) { 3450 try { 3451 ITelephony telephony = getITelephony(); 3452 if (telephony != null) 3453 return telephony.setPreferredNetworkType(subId, networkType); 3454 } catch (RemoteException ex) { 3455 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 3456 } catch (NullPointerException ex) { 3457 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 3458 } 3459 return false; 3460 } 3461 3462 /** 3463 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 3464 * 3465 * <p> 3466 * Requires that the calling app has carrier privileges. 3467 * @see #hasCarrierPrivileges 3468 * 3469 * @return true on success; false on any failure. 3470 */ 3471 public boolean setPreferredNetworkTypeToGlobal() { 3472 return setPreferredNetworkType(getDefaultSubscription(), 3473 RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); 3474 } 3475 3476 /** 3477 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning 3478 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for 3479 * tethering. 3480 * 3481 * @return 0: Not required. 1: required. 2: Not set. 3482 * @hide 3483 */ 3484 public int getTetherApnRequired() { 3485 try { 3486 ITelephony telephony = getITelephony(); 3487 if (telephony != null) 3488 return telephony.getTetherApnRequired(); 3489 } catch (RemoteException ex) { 3490 Rlog.e(TAG, "hasMatchedTetherApnSetting RemoteException", ex); 3491 } catch (NullPointerException ex) { 3492 Rlog.e(TAG, "hasMatchedTetherApnSetting NPE", ex); 3493 } 3494 return 2; 3495 } 3496 3497 3498 /** 3499 * Values used to return status for hasCarrierPrivileges call. 3500 */ 3501 /** @hide */ 3502 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 3503 /** @hide */ 3504 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 3505 /** @hide */ 3506 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 3507 /** @hide */ 3508 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 3509 3510 /** 3511 * Has the calling application been granted carrier privileges by the carrier. 3512 * 3513 * If any of the packages in the calling UID has carrier privileges, the 3514 * call will return true. This access is granted by the owner of the UICC 3515 * card and does not depend on the registered carrier. 3516 * 3517 * @return true if the app has carrier privileges. 3518 */ 3519 public boolean hasCarrierPrivileges() { 3520 try { 3521 ITelephony telephony = getITelephony(); 3522 if (telephony != null) 3523 return telephony.getCarrierPrivilegeStatus() == CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; 3524 } catch (RemoteException ex) { 3525 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3526 } catch (NullPointerException ex) { 3527 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3528 } 3529 return false; 3530 } 3531 3532 /** 3533 * Override the branding for the current ICCID. 3534 * 3535 * Once set, whenever the SIM is present in the device, the service 3536 * provider name (SPN) and the operator name will both be replaced by the 3537 * brand value input. To unset the value, the same function should be 3538 * called with a null brand value. 3539 * 3540 * <p>Requires that the calling app has carrier privileges. 3541 * @see #hasCarrierPrivileges 3542 * 3543 * @param brand The brand name to display/set. 3544 * @return true if the operation was executed correctly. 3545 */ 3546 public boolean setOperatorBrandOverride(String brand) { 3547 try { 3548 ITelephony telephony = getITelephony(); 3549 if (telephony != null) 3550 return telephony.setOperatorBrandOverride(brand); 3551 } catch (RemoteException ex) { 3552 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 3553 } catch (NullPointerException ex) { 3554 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 3555 } 3556 return false; 3557 } 3558 3559 /** 3560 * Override the roaming preference for the current ICCID. 3561 * 3562 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 3563 * the platform's notion of a network operator being considered roaming or not. 3564 * The change only affects the ICCID that was active when this call was made. 3565 * 3566 * If null is passed as any of the input, the corresponding value is deleted. 3567 * 3568 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 3569 * 3570 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 3571 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 3572 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 3573 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 3574 * @return true if the operation was executed correctly. 3575 * 3576 * @hide 3577 */ 3578 public boolean setRoamingOverride(List<String> gsmRoamingList, 3579 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 3580 List<String> cdmaNonRoamingList) { 3581 try { 3582 ITelephony telephony = getITelephony(); 3583 if (telephony != null) 3584 return telephony.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, 3585 cdmaRoamingList, cdmaNonRoamingList); 3586 } catch (RemoteException ex) { 3587 Rlog.e(TAG, "setRoamingOverride RemoteException", ex); 3588 } catch (NullPointerException ex) { 3589 Rlog.e(TAG, "setRoamingOverride NPE", ex); 3590 } 3591 return false; 3592 } 3593 3594 /** 3595 * Expose the rest of ITelephony to @SystemApi 3596 */ 3597 3598 /** @hide */ 3599 @SystemApi 3600 public String getCdmaMdn() { 3601 return getCdmaMdn(getDefaultSubscription()); 3602 } 3603 3604 /** @hide */ 3605 @SystemApi 3606 public String getCdmaMdn(int subId) { 3607 try { 3608 ITelephony telephony = getITelephony(); 3609 if (telephony == null) 3610 return null; 3611 return telephony.getCdmaMdn(subId); 3612 } catch (RemoteException ex) { 3613 return null; 3614 } catch (NullPointerException ex) { 3615 return null; 3616 } 3617 } 3618 3619 /** @hide */ 3620 @SystemApi 3621 public String getCdmaMin() { 3622 return getCdmaMin(getDefaultSubscription()); 3623 } 3624 3625 /** @hide */ 3626 @SystemApi 3627 public String getCdmaMin(int subId) { 3628 try { 3629 ITelephony telephony = getITelephony(); 3630 if (telephony == null) 3631 return null; 3632 return telephony.getCdmaMin(subId); 3633 } catch (RemoteException ex) { 3634 return null; 3635 } catch (NullPointerException ex) { 3636 return null; 3637 } 3638 } 3639 3640 /** @hide */ 3641 @SystemApi 3642 public int checkCarrierPrivilegesForPackage(String pkgname) { 3643 try { 3644 ITelephony telephony = getITelephony(); 3645 if (telephony != null) 3646 return telephony.checkCarrierPrivilegesForPackage(pkgname); 3647 } catch (RemoteException ex) { 3648 Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex); 3649 } catch (NullPointerException ex) { 3650 Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex); 3651 } 3652 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3653 } 3654 3655 /** @hide */ 3656 @SystemApi 3657 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 3658 return getCarrierPackageNamesForIntentAndPhone(intent, getDefaultPhone()); 3659 } 3660 3661 /** @hide */ 3662 @SystemApi 3663 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { 3664 try { 3665 ITelephony telephony = getITelephony(); 3666 if (telephony != null) 3667 return telephony.getCarrierPackageNamesForIntentAndPhone(intent, phoneId); 3668 } catch (RemoteException ex) { 3669 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone RemoteException", ex); 3670 } catch (NullPointerException ex) { 3671 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone NPE", ex); 3672 } 3673 return null; 3674 } 3675 3676 /** @hide */ 3677 @SystemApi 3678 public void dial(String number) { 3679 try { 3680 ITelephony telephony = getITelephony(); 3681 if (telephony != null) 3682 telephony.dial(number); 3683 } catch (RemoteException e) { 3684 Log.e(TAG, "Error calling ITelephony#dial", e); 3685 } 3686 } 3687 3688 /** @hide */ 3689 @SystemApi 3690 public void call(String callingPackage, String number) { 3691 try { 3692 ITelephony telephony = getITelephony(); 3693 if (telephony != null) 3694 telephony.call(callingPackage, number); 3695 } catch (RemoteException e) { 3696 Log.e(TAG, "Error calling ITelephony#call", e); 3697 } 3698 } 3699 3700 /** @hide */ 3701 @SystemApi 3702 public boolean endCall() { 3703 try { 3704 ITelephony telephony = getITelephony(); 3705 if (telephony != null) 3706 return telephony.endCall(); 3707 } catch (RemoteException e) { 3708 Log.e(TAG, "Error calling ITelephony#endCall", e); 3709 } 3710 return false; 3711 } 3712 3713 /** @hide */ 3714 @SystemApi 3715 public void answerRingingCall() { 3716 try { 3717 ITelephony telephony = getITelephony(); 3718 if (telephony != null) 3719 telephony.answerRingingCall(); 3720 } catch (RemoteException e) { 3721 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 3722 } 3723 } 3724 3725 /** @hide */ 3726 @SystemApi 3727 public void silenceRinger() { 3728 try { 3729 getTelecomService().silenceRinger(mContext.getOpPackageName()); 3730 } catch (RemoteException e) { 3731 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); 3732 } 3733 } 3734 3735 /** @hide */ 3736 @SystemApi 3737 public boolean isOffhook() { 3738 try { 3739 ITelephony telephony = getITelephony(); 3740 if (telephony != null) 3741 return telephony.isOffhook(); 3742 } catch (RemoteException e) { 3743 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 3744 } 3745 return false; 3746 } 3747 3748 /** @hide */ 3749 @SystemApi 3750 public boolean isRinging() { 3751 try { 3752 ITelephony telephony = getITelephony(); 3753 if (telephony != null) 3754 return telephony.isRinging(); 3755 } catch (RemoteException e) { 3756 Log.e(TAG, "Error calling ITelephony#isRinging", e); 3757 } 3758 return false; 3759 } 3760 3761 /** @hide */ 3762 @SystemApi 3763 public boolean isIdle() { 3764 try { 3765 ITelephony telephony = getITelephony(); 3766 if (telephony != null) 3767 return telephony.isIdle(); 3768 } catch (RemoteException e) { 3769 Log.e(TAG, "Error calling ITelephony#isIdle", e); 3770 } 3771 return true; 3772 } 3773 3774 /** @hide */ 3775 @SystemApi 3776 public boolean isRadioOn() { 3777 try { 3778 ITelephony telephony = getITelephony(); 3779 if (telephony != null) 3780 return telephony.isRadioOn(); 3781 } catch (RemoteException e) { 3782 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 3783 } 3784 return false; 3785 } 3786 3787 /** @hide */ 3788 @SystemApi 3789 public boolean isSimPinEnabled() { 3790 try { 3791 ITelephony telephony = getITelephony(); 3792 if (telephony != null) 3793 return telephony.isSimPinEnabled(mContext.getOpPackageName()); 3794 } catch (RemoteException e) { 3795 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 3796 } 3797 return false; 3798 } 3799 3800 /** @hide */ 3801 @SystemApi 3802 public boolean supplyPin(String pin) { 3803 try { 3804 ITelephony telephony = getITelephony(); 3805 if (telephony != null) 3806 return telephony.supplyPin(pin); 3807 } catch (RemoteException e) { 3808 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 3809 } 3810 return false; 3811 } 3812 3813 /** @hide */ 3814 @SystemApi 3815 public boolean supplyPuk(String puk, String pin) { 3816 try { 3817 ITelephony telephony = getITelephony(); 3818 if (telephony != null) 3819 return telephony.supplyPuk(puk, pin); 3820 } catch (RemoteException e) { 3821 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 3822 } 3823 return false; 3824 } 3825 3826 /** @hide */ 3827 @SystemApi 3828 public int[] supplyPinReportResult(String pin) { 3829 try { 3830 ITelephony telephony = getITelephony(); 3831 if (telephony != null) 3832 return telephony.supplyPinReportResult(pin); 3833 } catch (RemoteException e) { 3834 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 3835 } 3836 return new int[0]; 3837 } 3838 3839 /** @hide */ 3840 @SystemApi 3841 public int[] supplyPukReportResult(String puk, String pin) { 3842 try { 3843 ITelephony telephony = getITelephony(); 3844 if (telephony != null) 3845 return telephony.supplyPukReportResult(puk, pin); 3846 } catch (RemoteException e) { 3847 Log.e(TAG, "Error calling ITelephony#]", e); 3848 } 3849 return new int[0]; 3850 } 3851 3852 /** @hide */ 3853 @SystemApi 3854 public boolean handlePinMmi(String dialString) { 3855 try { 3856 ITelephony telephony = getITelephony(); 3857 if (telephony != null) 3858 return telephony.handlePinMmi(dialString); 3859 } catch (RemoteException e) { 3860 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3861 } 3862 return false; 3863 } 3864 3865 /** @hide */ 3866 @SystemApi 3867 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 3868 try { 3869 ITelephony telephony = getITelephony(); 3870 if (telephony != null) 3871 return telephony.handlePinMmiForSubscriber(subId, dialString); 3872 } catch (RemoteException e) { 3873 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3874 } 3875 return false; 3876 } 3877 3878 /** @hide */ 3879 @SystemApi 3880 public void toggleRadioOnOff() { 3881 try { 3882 ITelephony telephony = getITelephony(); 3883 if (telephony != null) 3884 telephony.toggleRadioOnOff(); 3885 } catch (RemoteException e) { 3886 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 3887 } 3888 } 3889 3890 /** @hide */ 3891 @SystemApi 3892 public boolean setRadio(boolean turnOn) { 3893 try { 3894 ITelephony telephony = getITelephony(); 3895 if (telephony != null) 3896 return telephony.setRadio(turnOn); 3897 } catch (RemoteException e) { 3898 Log.e(TAG, "Error calling ITelephony#setRadio", e); 3899 } 3900 return false; 3901 } 3902 3903 /** @hide */ 3904 @SystemApi 3905 public boolean setRadioPower(boolean turnOn) { 3906 try { 3907 ITelephony telephony = getITelephony(); 3908 if (telephony != null) 3909 return telephony.setRadioPower(turnOn); 3910 } catch (RemoteException e) { 3911 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 3912 } 3913 return false; 3914 } 3915 3916 /** @hide */ 3917 @SystemApi 3918 public void updateServiceLocation() { 3919 try { 3920 ITelephony telephony = getITelephony(); 3921 if (telephony != null) 3922 telephony.updateServiceLocation(); 3923 } catch (RemoteException e) { 3924 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 3925 } 3926 } 3927 3928 /** @hide */ 3929 @SystemApi 3930 public boolean enableDataConnectivity() { 3931 try { 3932 ITelephony telephony = getITelephony(); 3933 if (telephony != null) 3934 return telephony.enableDataConnectivity(); 3935 } catch (RemoteException e) { 3936 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 3937 } 3938 return false; 3939 } 3940 3941 /** @hide */ 3942 @SystemApi 3943 public boolean disableDataConnectivity() { 3944 try { 3945 ITelephony telephony = getITelephony(); 3946 if (telephony != null) 3947 return telephony.disableDataConnectivity(); 3948 } catch (RemoteException e) { 3949 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 3950 } 3951 return false; 3952 } 3953 3954 /** @hide */ 3955 @SystemApi 3956 public boolean isDataConnectivityPossible() { 3957 try { 3958 ITelephony telephony = getITelephony(); 3959 if (telephony != null) 3960 return telephony.isDataConnectivityPossible(); 3961 } catch (RemoteException e) { 3962 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 3963 } 3964 return false; 3965 } 3966 3967 /** @hide */ 3968 @SystemApi 3969 public boolean needsOtaServiceProvisioning() { 3970 try { 3971 ITelephony telephony = getITelephony(); 3972 if (telephony != null) 3973 return telephony.needsOtaServiceProvisioning(); 3974 } catch (RemoteException e) { 3975 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 3976 } 3977 return false; 3978 } 3979 3980 /** @hide */ 3981 @SystemApi 3982 public void setDataEnabled(boolean enable) { 3983 setDataEnabled(SubscriptionManager.getDefaultDataSubId(), enable); 3984 } 3985 3986 /** @hide */ 3987 @SystemApi 3988 public void setDataEnabled(int subId, boolean enable) { 3989 try { 3990 Log.d(TAG, "setDataEnabled: enabled=" + enable); 3991 ITelephony telephony = getITelephony(); 3992 if (telephony != null) 3993 telephony.setDataEnabled(subId, enable); 3994 } catch (RemoteException e) { 3995 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 3996 } 3997 } 3998 3999 /** @hide */ 4000 @SystemApi 4001 public boolean getDataEnabled() { 4002 return getDataEnabled(SubscriptionManager.getDefaultDataSubId()); 4003 } 4004 4005 /** @hide */ 4006 @SystemApi 4007 public boolean getDataEnabled(int subId) { 4008 boolean retVal = false; 4009 try { 4010 ITelephony telephony = getITelephony(); 4011 if (telephony != null) 4012 retVal = telephony.getDataEnabled(subId); 4013 } catch (RemoteException e) { 4014 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 4015 } catch (NullPointerException e) { 4016 } 4017 Log.d(TAG, "getDataEnabled: retVal=" + retVal); 4018 return retVal; 4019 } 4020 4021 /** 4022 * Returns the result and response from RIL for oem request 4023 * 4024 * @param oemReq the data is sent to ril. 4025 * @param oemResp the respose data from RIL. 4026 * @return negative value request was not handled or get error 4027 * 0 request was handled succesfully, but no response data 4028 * positive value success, data length of response 4029 * @hide 4030 */ 4031 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 4032 try { 4033 ITelephony telephony = getITelephony(); 4034 if (telephony != null) 4035 return telephony.invokeOemRilRequestRaw(oemReq, oemResp); 4036 } catch (RemoteException ex) { 4037 } catch (NullPointerException ex) { 4038 } 4039 return -1; 4040 } 4041 4042 /** @hide */ 4043 @SystemApi 4044 public void enableVideoCalling(boolean enable) { 4045 try { 4046 ITelephony telephony = getITelephony(); 4047 if (telephony != null) 4048 telephony.enableVideoCalling(enable); 4049 } catch (RemoteException e) { 4050 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 4051 } 4052 } 4053 4054 /** @hide */ 4055 @SystemApi 4056 public boolean isVideoCallingEnabled() { 4057 try { 4058 ITelephony telephony = getITelephony(); 4059 if (telephony != null) 4060 return telephony.isVideoCallingEnabled(mContext.getOpPackageName()); 4061 } catch (RemoteException e) { 4062 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 4063 } 4064 return false; 4065 } 4066 4067 /** 4068 * Whether the device supports configuring the DTMF tone length. 4069 * 4070 * @return {@code true} if the DTMF tone length can be changed, and {@code false} otherwise. 4071 */ 4072 public boolean canChangeDtmfToneLength() { 4073 try { 4074 ITelephony telephony = getITelephony(); 4075 if (telephony != null) { 4076 return telephony.canChangeDtmfToneLength(); 4077 } 4078 } catch (RemoteException e) { 4079 Log.e(TAG, "Error calling ITelephony#canChangeDtmfToneLength", e); 4080 } 4081 return false; 4082 } 4083 4084 /** 4085 * Whether the device is a world phone. 4086 * 4087 * @return {@code true} if the device is a world phone, and {@code false} otherwise. 4088 */ 4089 public boolean isWorldPhone() { 4090 try { 4091 ITelephony telephony = getITelephony(); 4092 if (telephony != null) { 4093 return telephony.isWorldPhone(); 4094 } 4095 } catch (RemoteException e) { 4096 Log.e(TAG, "Error calling ITelephony#isWorldPhone", e); 4097 } 4098 return false; 4099 } 4100 4101 /** 4102 * Whether the phone supports TTY mode. 4103 * 4104 * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. 4105 */ 4106 public boolean isTtyModeSupported() { 4107 try { 4108 ITelephony telephony = getITelephony(); 4109 if (telephony != null) { 4110 return telephony.isTtyModeSupported(); 4111 } 4112 } catch (RemoteException e) { 4113 Log.e(TAG, "Error calling ITelephony#isTtyModeSupported", e); 4114 } 4115 return false; 4116 } 4117 4118 /** 4119 * Whether the phone supports hearing aid compatibility. 4120 * 4121 * @return {@code true} if the device supports hearing aid compatibility, and {@code false} 4122 * otherwise. 4123 */ 4124 public boolean isHearingAidCompatibilitySupported() { 4125 try { 4126 ITelephony telephony = getITelephony(); 4127 if (telephony != null) { 4128 return telephony.isHearingAidCompatibilitySupported(); 4129 } 4130 } catch (RemoteException e) { 4131 Log.e(TAG, "Error calling ITelephony#isHearingAidCompatibilitySupported", e); 4132 } 4133 return false; 4134 } 4135 4136 /** 4137 * This function retrieves value for setting "name+subId", and if that is not found 4138 * retrieves value for setting "name", and if that is not found throws 4139 * SettingNotFoundException 4140 * 4141 * @hide */ 4142 public static int getIntWithSubId(ContentResolver cr, String name, int subId) 4143 throws SettingNotFoundException { 4144 try { 4145 return Settings.Global.getInt(cr, name + subId); 4146 } catch (SettingNotFoundException e) { 4147 try { 4148 int val = Settings.Global.getInt(cr, name); 4149 Settings.Global.putInt(cr, name + subId, val); 4150 4151 /* We are now moving from 'setting' to 'setting+subId', and using the value stored 4152 * for 'setting' as default. Reset the default (since it may have a user set 4153 * value). */ 4154 int default_val = val; 4155 if (name.equals(Settings.Global.MOBILE_DATA)) { 4156 default_val = "true".equalsIgnoreCase( 4157 SystemProperties.get("ro.com.android.mobiledata", "true")) ? 1 : 0; 4158 } else if (name.equals(Settings.Global.DATA_ROAMING)) { 4159 default_val = "true".equalsIgnoreCase( 4160 SystemProperties.get("ro.com.android.dataroaming", "false")) ? 1 : 0; 4161 } 4162 4163 if (default_val != val) { 4164 Settings.Global.putInt(cr, name, default_val); 4165 } 4166 4167 return val; 4168 } catch (SettingNotFoundException exc) { 4169 throw new SettingNotFoundException(name); 4170 } 4171 } 4172 } 4173 4174 /** 4175 * Returns the IMS Registration Status 4176 * @hide 4177 */ 4178 public boolean isImsRegistered() { 4179 try { 4180 ITelephony telephony = getITelephony(); 4181 if (telephony == null) 4182 return false; 4183 return telephony.isImsRegistered(); 4184 } catch (RemoteException ex) { 4185 return false; 4186 } catch (NullPointerException ex) { 4187 return false; 4188 } 4189 } 4190 4191 /** 4192 * Returns the Status of Volte 4193 *@hide 4194 */ 4195 public boolean isVolteEnabled() { 4196 try { 4197 return getITelephony().isVolteEnabled(); 4198 } catch (RemoteException ex) { 4199 return false; 4200 } catch (NullPointerException ex) { 4201 return false; 4202 } 4203 } 4204 4205 /** 4206 * Returns the Status of Wi-Fi Calling 4207 *@hide 4208 */ 4209 public boolean isWifiCallingEnabled() { 4210 try { 4211 return getITelephony().isWifiCallingEnabled(); 4212 } catch (RemoteException ex) { 4213 return false; 4214 } catch (NullPointerException ex) { 4215 return false; 4216 } 4217 } 4218 4219 /** 4220 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 4221 * 4222 * @hide 4223 */ 4224 public void setSimOperatorNumeric(String numeric) { 4225 int phoneId = getDefaultPhone(); 4226 setSimOperatorNumericForPhone(phoneId, numeric); 4227 } 4228 4229 /** 4230 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 4231 * 4232 * @hide 4233 */ 4234 public void setSimOperatorNumericForPhone(int phoneId, String numeric) { 4235 setTelephonyProperty(phoneId, 4236 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, numeric); 4237 } 4238 4239 /** 4240 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 4241 * 4242 * @hide 4243 */ 4244 public void setSimOperatorName(String name) { 4245 int phoneId = getDefaultPhone(); 4246 setSimOperatorNameForPhone(phoneId, name); 4247 } 4248 4249 /** 4250 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 4251 * 4252 * @hide 4253 */ 4254 public void setSimOperatorNameForPhone(int phoneId, String name) { 4255 setTelephonyProperty(phoneId, 4256 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, name); 4257 } 4258 4259 /** 4260 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the default phone. 4261 * 4262 * @hide 4263 */ 4264 public void setSimCountryIso(String iso) { 4265 int phoneId = getDefaultPhone(); 4266 setSimCountryIsoForPhone(phoneId, iso); 4267 } 4268 4269 /** 4270 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the given phone. 4271 * 4272 * @hide 4273 */ 4274 public void setSimCountryIsoForPhone(int phoneId, String iso) { 4275 setTelephonyProperty(phoneId, 4276 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso); 4277 } 4278 4279 /** 4280 * Set TelephonyProperties.PROPERTY_SIM_STATE for the default phone. 4281 * 4282 * @hide 4283 */ 4284 public void setSimState(String state) { 4285 int phoneId = getDefaultPhone(); 4286 setSimStateForPhone(phoneId, state); 4287 } 4288 4289 /** 4290 * Set TelephonyProperties.PROPERTY_SIM_STATE for the given phone. 4291 * 4292 * @hide 4293 */ 4294 public void setSimStateForPhone(int phoneId, String state) { 4295 setTelephonyProperty(phoneId, 4296 TelephonyProperties.PROPERTY_SIM_STATE, state); 4297 } 4298 4299 /** 4300 * Set baseband version for the default phone. 4301 * 4302 * @param version baseband version 4303 * @hide 4304 */ 4305 public void setBasebandVersion(String version) { 4306 int phoneId = getDefaultPhone(); 4307 setBasebandVersionForPhone(phoneId, version); 4308 } 4309 4310 /** 4311 * Set baseband version by phone id. 4312 * 4313 * @param phoneId for which baseband version is set 4314 * @param version baseband version 4315 * @hide 4316 */ 4317 public void setBasebandVersionForPhone(int phoneId, String version) { 4318 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4319 String prop = TelephonyProperties.PROPERTY_BASEBAND_VERSION + 4320 ((phoneId == 0) ? "" : Integer.toString(phoneId)); 4321 SystemProperties.set(prop, version); 4322 } 4323 } 4324 4325 /** 4326 * Set phone type for the default phone. 4327 * 4328 * @param type phone type 4329 * 4330 * @hide 4331 */ 4332 public void setPhoneType(int type) { 4333 int phoneId = getDefaultPhone(); 4334 setPhoneType(phoneId, type); 4335 } 4336 4337 /** 4338 * Set phone type by phone id. 4339 * 4340 * @param phoneId for which phone type is set 4341 * @param type phone type 4342 * 4343 * @hide 4344 */ 4345 public void setPhoneType(int phoneId, int type) { 4346 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4347 TelephonyManager.setTelephonyProperty(phoneId, 4348 TelephonyProperties.CURRENT_ACTIVE_PHONE, String.valueOf(type)); 4349 } 4350 } 4351 4352 /** 4353 * Get OTASP number schema for the default phone. 4354 * 4355 * @param defaultValue default value 4356 * @return OTA SP number schema 4357 * 4358 * @hide 4359 */ 4360 public String getOtaSpNumberSchema(String defaultValue) { 4361 int phoneId = getDefaultPhone(); 4362 return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); 4363 } 4364 4365 /** 4366 * Get OTASP number schema by phone id. 4367 * 4368 * @param phoneId for which OTA SP number schema is get 4369 * @param defaultValue default value 4370 * @return OTA SP number schema 4371 * 4372 * @hide 4373 */ 4374 public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) { 4375 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4376 return TelephonyManager.getTelephonyProperty(phoneId, 4377 TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA, defaultValue); 4378 } 4379 4380 return defaultValue; 4381 } 4382 4383 /** 4384 * Get SMS receive capable from system property for the default phone. 4385 * 4386 * @param defaultValue default value 4387 * @return SMS receive capable 4388 * 4389 * @hide 4390 */ 4391 public boolean getSmsReceiveCapable(boolean defaultValue) { 4392 int phoneId = getDefaultPhone(); 4393 return getSmsReceiveCapableForPhone(phoneId, defaultValue); 4394 } 4395 4396 /** 4397 * Get SMS receive capable from system property by phone id. 4398 * 4399 * @param phoneId for which SMS receive capable is get 4400 * @param defaultValue default value 4401 * @return SMS receive capable 4402 * 4403 * @hide 4404 */ 4405 public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) { 4406 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4407 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 4408 TelephonyProperties.PROPERTY_SMS_RECEIVE, String.valueOf(defaultValue))); 4409 } 4410 4411 return defaultValue; 4412 } 4413 4414 /** 4415 * Get SMS send capable from system property for the default phone. 4416 * 4417 * @param defaultValue default value 4418 * @return SMS send capable 4419 * 4420 * @hide 4421 */ 4422 public boolean getSmsSendCapable(boolean defaultValue) { 4423 int phoneId = getDefaultPhone(); 4424 return getSmsSendCapableForPhone(phoneId, defaultValue); 4425 } 4426 4427 /** 4428 * Get SMS send capable from system property by phone id. 4429 * 4430 * @param phoneId for which SMS send capable is get 4431 * @param defaultValue default value 4432 * @return SMS send capable 4433 * 4434 * @hide 4435 */ 4436 public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) { 4437 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4438 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 4439 TelephonyProperties.PROPERTY_SMS_SEND, String.valueOf(defaultValue))); 4440 } 4441 4442 return defaultValue; 4443 } 4444 4445 /** 4446 * Set the alphabetic name of current registered operator. 4447 * @param name the alphabetic name of current registered operator. 4448 * @hide 4449 */ 4450 public void setNetworkOperatorName(String name) { 4451 int phoneId = getDefaultPhone(); 4452 setNetworkOperatorNameForPhone(phoneId, name); 4453 } 4454 4455 /** 4456 * Set the alphabetic name of current registered operator. 4457 * @param phoneId which phone you want to set 4458 * @param name the alphabetic name of current registered operator. 4459 * @hide 4460 */ 4461 public void setNetworkOperatorNameForPhone(int phoneId, String name) { 4462 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4463 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, name); 4464 } 4465 } 4466 4467 /** 4468 * Set the numeric name (MCC+MNC) of current registered operator. 4469 * @param operator the numeric name (MCC+MNC) of current registered operator 4470 * @hide 4471 */ 4472 public void setNetworkOperatorNumeric(String numeric) { 4473 int phoneId = getDefaultPhone(); 4474 setNetworkOperatorNumericForPhone(phoneId, numeric); 4475 } 4476 4477 /** 4478 * Set the numeric name (MCC+MNC) of current registered operator. 4479 * @param phoneId for which phone type is set 4480 * @param operator the numeric name (MCC+MNC) of current registered operator 4481 * @hide 4482 */ 4483 public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) { 4484 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, numeric); 4485 } 4486 4487 /** 4488 * Set roaming state of the current network, for GSM purposes. 4489 * @param isRoaming is network in romaing state or not 4490 * @hide 4491 */ 4492 public void setNetworkRoaming(boolean isRoaming) { 4493 int phoneId = getDefaultPhone(); 4494 setNetworkRoamingForPhone(phoneId, isRoaming); 4495 } 4496 4497 /** 4498 * Set roaming state of the current network, for GSM purposes. 4499 * @param phoneId which phone you want to set 4500 * @param isRoaming is network in romaing state or not 4501 * @hide 4502 */ 4503 public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) { 4504 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4505 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, 4506 isRoaming ? "true" : "false"); 4507 } 4508 } 4509 4510 /** 4511 * Set the ISO country code equivalent of the current registered 4512 * operator's MCC (Mobile Country Code). 4513 * @param iso the ISO country code equivalent of the current registered 4514 * @hide 4515 */ 4516 public void setNetworkCountryIso(String iso) { 4517 int phoneId = getDefaultPhone(); 4518 setNetworkCountryIsoForPhone(phoneId, iso); 4519 } 4520 4521 /** 4522 * Set the ISO country code equivalent of the current registered 4523 * operator's MCC (Mobile Country Code). 4524 * @param phoneId which phone you want to set 4525 * @param iso the ISO country code equivalent of the current registered 4526 * @hide 4527 */ 4528 public void setNetworkCountryIsoForPhone(int phoneId, String iso) { 4529 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4530 setTelephonyProperty(phoneId, 4531 TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso); 4532 } 4533 } 4534 4535 /** 4536 * Set the network type currently in use on the device for data transmission. 4537 * @param type the network type currently in use on the device for data transmission 4538 * @hide 4539 */ 4540 public void setDataNetworkType(int type) { 4541 int phoneId = getDefaultPhone(); 4542 setDataNetworkTypeForPhone(phoneId, type); 4543 } 4544 4545 /** 4546 * Set the network type currently in use on the device for data transmission. 4547 * @param phoneId which phone you want to set 4548 * @param type the network type currently in use on the device for data transmission 4549 * @hide 4550 */ 4551 public void setDataNetworkTypeForPhone(int phoneId, int type) { 4552 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4553 setTelephonyProperty(phoneId, 4554 TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, 4555 ServiceState.rilRadioTechnologyToString(type)); 4556 } 4557 } 4558 4559 /** 4560 * Returns the subscription ID for the given phone account. 4561 * @hide 4562 */ 4563 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { 4564 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 4565 try { 4566 ITelephony service = getITelephony(); 4567 if (service != null) { 4568 retval = service.getSubIdForPhoneAccount(phoneAccount); 4569 } 4570 } catch (RemoteException e) { 4571 } 4572 4573 return retval; 4574 } 4575 4576 /** 4577 * Resets telephony manager settings back to factory defaults. 4578 * 4579 * @hide 4580 */ 4581 public void factoryReset(int subId) { 4582 try { 4583 Log.d(TAG, "factoryReset: subId=" + subId); 4584 ITelephony telephony = getITelephony(); 4585 if (telephony != null) 4586 telephony.factoryReset(subId); 4587 } catch (RemoteException e) { 4588 } 4589 } 4590} 4591