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