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