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