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