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