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