TelephonyManager.java revision bbdc1c0e044a505d5a200963319a683e4ef1f967
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.SystemApi; 20import android.annotation.SdkConstant; 21import android.annotation.SdkConstant.SdkConstantType; 22import android.content.Context; 23import android.content.Intent; 24import android.os.Bundle; 25import android.os.RemoteException; 26import android.os.ServiceManager; 27import android.os.SystemProperties; 28import android.util.Log; 29 30import com.android.internal.telecom.ITelecomService; 31import com.android.internal.telephony.IPhoneSubInfo; 32import com.android.internal.telephony.ITelephony; 33import com.android.internal.telephony.ITelephonyRegistry; 34import com.android.internal.telephony.PhoneConstants; 35import com.android.internal.telephony.RILConstants; 36import com.android.internal.telephony.TelephonyProperties; 37 38import java.io.FileInputStream; 39import java.io.IOException; 40import java.util.List; 41import java.util.regex.Matcher; 42import java.util.regex.Pattern; 43 44/** 45 * Provides access to information about the telephony services on 46 * the device. Applications can use the methods in this class to 47 * determine telephony services and states, as well as to access some 48 * types of subscriber information. Applications can also register 49 * a listener to receive notification of telephony state changes. 50 * <p> 51 * You do not instantiate this class directly; instead, you retrieve 52 * a reference to an instance through 53 * {@link android.content.Context#getSystemService 54 * Context.getSystemService(Context.TELEPHONY_SERVICE)}. 55 * <p> 56 * Note that access to some telephony information is 57 * permission-protected. Your application cannot access the protected 58 * information unless it has the appropriate permissions declared in 59 * its manifest file. Where permissions apply, they are noted in the 60 * the methods through which you access the protected information. 61 */ 62public class TelephonyManager { 63 private static final String TAG = "TelephonyManager"; 64 65 private static ITelephonyRegistry sRegistry; 66 67 /** 68 * The allowed states of Wi-Fi calling. 69 * 70 * @hide 71 */ 72 public interface WifiCallingChoices { 73 /** Always use Wi-Fi calling */ 74 static final int ALWAYS_USE = 0; 75 /** Ask the user whether to use Wi-Fi on every call */ 76 static final int ASK_EVERY_TIME = 1; 77 /** Never use Wi-Fi calling */ 78 static final int NEVER_USE = 2; 79 } 80 81 private final Context mContext; 82 83 private static String multiSimConfig = 84 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 85 86 /** Enum indicating multisim variants 87 * DSDS - Dual SIM Dual Standby 88 * DSDA - Dual SIM Dual Active 89 * TSTS - Triple SIM Triple Standby 90 **/ 91 /** @hide */ 92 public enum MultiSimVariants { 93 DSDS, 94 DSDA, 95 TSTS, 96 UNKNOWN 97 }; 98 99 /** @hide */ 100 public TelephonyManager(Context context) { 101 Context appContext = context.getApplicationContext(); 102 if (appContext != null) { 103 mContext = appContext; 104 } else { 105 mContext = context; 106 } 107 108 if (sRegistry == null) { 109 sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService( 110 "telephony.registry")); 111 } 112 } 113 114 /** @hide */ 115 private TelephonyManager() { 116 mContext = null; 117 } 118 119 private static TelephonyManager sInstance = new TelephonyManager(); 120 121 /** @hide 122 /* @deprecated - use getSystemService as described above */ 123 public static TelephonyManager getDefault() { 124 return sInstance; 125 } 126 127 128 /** 129 * Returns the multi SIM variant 130 * Returns DSDS for Dual SIM Dual Standby 131 * Returns DSDA for Dual SIM Dual Active 132 * Returns TSTS for Triple SIM Triple Standby 133 * Returns UNKNOWN for others 134 */ 135 /** {@hide} */ 136 public MultiSimVariants getMultiSimConfiguration() { 137 String mSimConfig = 138 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 139 if (mSimConfig.equals("dsds")) { 140 return MultiSimVariants.DSDS; 141 } else if (mSimConfig.equals("dsda")) { 142 return MultiSimVariants.DSDA; 143 } else if (mSimConfig.equals("tsts")) { 144 return MultiSimVariants.TSTS; 145 } else { 146 return MultiSimVariants.UNKNOWN; 147 } 148 } 149 150 151 /** 152 * Returns the number of phones available. 153 * Returns 1 for Single standby mode (Single SIM functionality) 154 * Returns 2 for Dual standby mode.(Dual SIM functionality) 155 */ 156 /** {@hide} */ 157 public int getPhoneCount() { 158 int phoneCount = 1; 159 switch (getMultiSimConfiguration()) { 160 case DSDS: 161 case DSDA: 162 phoneCount = PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM; 163 break; 164 case TSTS: 165 phoneCount = PhoneConstants.MAX_PHONE_COUNT_TRI_SIM; 166 break; 167 } 168 return phoneCount; 169 } 170 171 /** {@hide} */ 172 public static TelephonyManager from(Context context) { 173 return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 174 } 175 176 /** {@hide} */ 177 public boolean isMultiSimEnabled() { 178 return (multiSimConfig.equals("dsds") || multiSimConfig.equals("dsda") || 179 multiSimConfig.equals("tsts")); 180 } 181 182 // 183 // Broadcast Intent actions 184 // 185 186 /** 187 * Broadcast intent action indicating that the call state (cellular) 188 * on the device has changed. 189 * 190 * <p> 191 * The {@link #EXTRA_STATE} extra indicates the new call state. 192 * If the new state is RINGING, a second extra 193 * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as 194 * a String. 195 * 196 * <p class="note"> 197 * Requires the READ_PHONE_STATE permission. 198 * 199 * <p class="note"> 200 * This was a {@link android.content.Context#sendStickyBroadcast sticky} 201 * broadcast in version 1.0, but it is no longer sticky. 202 * Instead, use {@link #getCallState} to synchronously query the current call state. 203 * 204 * @see #EXTRA_STATE 205 * @see #EXTRA_INCOMING_NUMBER 206 * @see #getCallState 207 */ 208 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 209 public static final String ACTION_PHONE_STATE_CHANGED = 210 "android.intent.action.PHONE_STATE"; 211 212 /** 213 * The Phone app sends this intent when a user opts to respond-via-message during an incoming 214 * call. By default, the device's default SMS app consumes this message and sends a text message 215 * to the caller. A third party app can also provide this functionality by consuming this Intent 216 * with a {@link android.app.Service} and sending the message using its own messaging system. 217 * <p>The intent contains a URI (available from {@link android.content.Intent#getData}) 218 * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:}, 219 * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the 220 * same way: the path part of the URI contains the recipient's phone number or a comma-separated 221 * set of phone numbers if there are multiple recipients. For example, {@code 222 * smsto:2065551234}.</p> 223 * 224 * <p>The intent may also contain extras for the message text (in {@link 225 * android.content.Intent#EXTRA_TEXT}) and a message subject 226 * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p> 227 * 228 * <p class="note"><strong>Note:</strong> 229 * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service} 230 * that requires the 231 * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p> 232 * <p>For example, the service that receives this intent can be declared in the manifest file 233 * with an intent filter like this:</p> 234 * <pre> 235 * <!-- Service that delivers SMS messages received from the phone "quick response" --> 236 * <service android:name=".HeadlessSmsSendService" 237 * android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" 238 * android:exported="true" > 239 * <intent-filter> 240 * <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /> 241 * <category android:name="android.intent.category.DEFAULT" /> 242 * <data android:scheme="sms" /> 243 * <data android:scheme="smsto" /> 244 * <data android:scheme="mms" /> 245 * <data android:scheme="mmsto" /> 246 * </intent-filter> 247 * </service></pre> 248 * <p> 249 * Output: nothing. 250 */ 251 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 252 public static final String ACTION_RESPOND_VIA_MESSAGE = 253 "android.intent.action.RESPOND_VIA_MESSAGE"; 254 255 /** 256 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 257 * for a String containing the new call state. 258 * 259 * @see #EXTRA_STATE_IDLE 260 * @see #EXTRA_STATE_RINGING 261 * @see #EXTRA_STATE_OFFHOOK 262 * 263 * <p class="note"> 264 * Retrieve with 265 * {@link android.content.Intent#getStringExtra(String)}. 266 */ 267 public static final String EXTRA_STATE = PhoneConstants.STATE_KEY; 268 269 /** 270 * Value used with {@link #EXTRA_STATE} corresponding to 271 * {@link #CALL_STATE_IDLE}. 272 */ 273 public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString(); 274 275 /** 276 * Value used with {@link #EXTRA_STATE} corresponding to 277 * {@link #CALL_STATE_RINGING}. 278 */ 279 public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString(); 280 281 /** 282 * Value used with {@link #EXTRA_STATE} corresponding to 283 * {@link #CALL_STATE_OFFHOOK}. 284 */ 285 public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString(); 286 287 /** 288 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 289 * for a String containing the incoming phone number. 290 * Only valid when the new call state is RINGING. 291 * 292 * <p class="note"> 293 * Retrieve with 294 * {@link android.content.Intent#getStringExtra(String)}. 295 */ 296 public static final String EXTRA_INCOMING_NUMBER = "incoming_number"; 297 298 /** 299 * Broadcast intent action indicating that a precise call state 300 * (cellular) on the device has changed. 301 * 302 * <p> 303 * The {@link #EXTRA_RINGING_CALL_STATE} extra indicates the ringing call state. 304 * The {@link #EXTRA_FOREGROUND_CALL_STATE} extra indicates the foreground call state. 305 * The {@link #EXTRA_BACKGROUND_CALL_STATE} extra indicates the background call state. 306 * The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause. 307 * The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause. 308 * 309 * <p class="note"> 310 * Requires the READ_PRECISE_PHONE_STATE permission. 311 * 312 * @see #EXTRA_RINGING_CALL_STATE 313 * @see #EXTRA_FOREGROUND_CALL_STATE 314 * @see #EXTRA_BACKGROUND_CALL_STATE 315 * @see #EXTRA_DISCONNECT_CAUSE 316 * @see #EXTRA_PRECISE_DISCONNECT_CAUSE 317 * 318 * <p class="note"> 319 * Requires the READ_PRECISE_PHONE_STATE permission. 320 * 321 * @hide 322 */ 323 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 324 public static final String ACTION_PRECISE_CALL_STATE_CHANGED = 325 "android.intent.action.PRECISE_CALL_STATE"; 326 327 /** 328 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 329 * for an integer containing the state of the current ringing call. 330 * 331 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 332 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 333 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 334 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 335 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 336 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 337 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 338 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 339 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 340 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 341 * 342 * <p class="note"> 343 * Retrieve with 344 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 345 * 346 * @hide 347 */ 348 public static final String EXTRA_RINGING_CALL_STATE = "ringing_state"; 349 350 /** 351 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 352 * for an integer containing the state of the current foreground call. 353 * 354 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 355 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 356 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 357 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 358 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 359 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 360 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 361 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 362 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 363 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 364 * 365 * <p class="note"> 366 * Retrieve with 367 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 368 * 369 * @hide 370 */ 371 public static final String EXTRA_FOREGROUND_CALL_STATE = "foreground_state"; 372 373 /** 374 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 375 * for an integer containing the state of the current background call. 376 * 377 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 378 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 379 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 380 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 381 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 382 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 383 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 384 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 385 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 386 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 387 * 388 * <p class="note"> 389 * Retrieve with 390 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 391 * 392 * @hide 393 */ 394 public static final String EXTRA_BACKGROUND_CALL_STATE = "background_state"; 395 396 /** 397 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 398 * for an integer containing the disconnect cause. 399 * 400 * @see DisconnectCause 401 * 402 * <p class="note"> 403 * Retrieve with 404 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 405 * 406 * @hide 407 */ 408 public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause"; 409 410 /** 411 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 412 * for an integer containing the disconnect cause provided by the RIL. 413 * 414 * @see PreciseDisconnectCause 415 * 416 * <p class="note"> 417 * Retrieve with 418 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 419 * 420 * @hide 421 */ 422 public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause"; 423 424 /** 425 * Broadcast intent action indicating a data connection has changed, 426 * providing precise information about the connection. 427 * 428 * <p> 429 * The {@link #EXTRA_DATA_STATE} extra indicates the connection state. 430 * The {@link #EXTRA_DATA_NETWORK_TYPE} extra indicates the connection network type. 431 * The {@link #EXTRA_DATA_APN_TYPE} extra indicates the APN type. 432 * The {@link #EXTRA_DATA_APN} extra indicates the APN. 433 * The {@link #EXTRA_DATA_CHANGE_REASON} extra indicates the connection change reason. 434 * The {@link #EXTRA_DATA_IFACE_PROPERTIES} extra indicates the connection interface. 435 * The {@link #EXTRA_DATA_FAILURE_CAUSE} extra indicates the connection fail cause. 436 * 437 * <p class="note"> 438 * Requires the READ_PRECISE_PHONE_STATE permission. 439 * 440 * @see #EXTRA_DATA_STATE 441 * @see #EXTRA_DATA_NETWORK_TYPE 442 * @see #EXTRA_DATA_APN_TYPE 443 * @see #EXTRA_DATA_APN 444 * @see #EXTRA_DATA_CHANGE_REASON 445 * @see #EXTRA_DATA_IFACE 446 * @see #EXTRA_DATA_FAILURE_CAUSE 447 * @hide 448 */ 449 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 450 public static final String ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED = 451 "android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED"; 452 453 /** 454 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 455 * for an integer containing the state of the current data connection. 456 * 457 * @see TelephonyManager#DATA_UNKNOWN 458 * @see TelephonyManager#DATA_DISCONNECTED 459 * @see TelephonyManager#DATA_CONNECTING 460 * @see TelephonyManager#DATA_CONNECTED 461 * @see TelephonyManager#DATA_SUSPENDED 462 * 463 * <p class="note"> 464 * Retrieve with 465 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 466 * 467 * @hide 468 */ 469 public static final String EXTRA_DATA_STATE = PhoneConstants.STATE_KEY; 470 471 /** 472 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 473 * for an integer containing the network type. 474 * 475 * @see TelephonyManager#NETWORK_TYPE_UNKNOWN 476 * @see TelephonyManager#NETWORK_TYPE_GPRS 477 * @see TelephonyManager#NETWORK_TYPE_EDGE 478 * @see TelephonyManager#NETWORK_TYPE_UMTS 479 * @see TelephonyManager#NETWORK_TYPE_CDMA 480 * @see TelephonyManager#NETWORK_TYPE_EVDO_0 481 * @see TelephonyManager#NETWORK_TYPE_EVDO_A 482 * @see TelephonyManager#NETWORK_TYPE_1xRTT 483 * @see TelephonyManager#NETWORK_TYPE_HSDPA 484 * @see TelephonyManager#NETWORK_TYPE_HSUPA 485 * @see TelephonyManager#NETWORK_TYPE_HSPA 486 * @see TelephonyManager#NETWORK_TYPE_IDEN 487 * @see TelephonyManager#NETWORK_TYPE_EVDO_B 488 * @see TelephonyManager#NETWORK_TYPE_LTE 489 * @see TelephonyManager#NETWORK_TYPE_EHRPD 490 * @see TelephonyManager#NETWORK_TYPE_HSPAP 491 * 492 * <p class="note"> 493 * Retrieve with 494 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 495 * 496 * @hide 497 */ 498 public static final String EXTRA_DATA_NETWORK_TYPE = PhoneConstants.DATA_NETWORK_TYPE_KEY; 499 500 /** 501 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 502 * for an String containing the data APN type. 503 * 504 * <p class="note"> 505 * Retrieve with 506 * {@link android.content.Intent#getStringExtra(String name)}. 507 * 508 * @hide 509 */ 510 public static final String EXTRA_DATA_APN_TYPE = PhoneConstants.DATA_APN_TYPE_KEY; 511 512 /** 513 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 514 * for an String containing the data APN. 515 * 516 * <p class="note"> 517 * Retrieve with 518 * {@link android.content.Intent#getStringExtra(String name)}. 519 * 520 * @hide 521 */ 522 public static final String EXTRA_DATA_APN = PhoneConstants.DATA_APN_KEY; 523 524 /** 525 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 526 * for an String representation of the change reason. 527 * 528 * <p class="note"> 529 * Retrieve with 530 * {@link android.content.Intent#getStringExtra(String name)}. 531 * 532 * @hide 533 */ 534 public static final String EXTRA_DATA_CHANGE_REASON = PhoneConstants.STATE_CHANGE_REASON_KEY; 535 536 /** 537 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 538 * for an String representation of the data interface. 539 * 540 * <p class="note"> 541 * Retrieve with 542 * {@link android.content.Intent#getParcelableExtra(String name)}. 543 * 544 * @hide 545 */ 546 public static final String EXTRA_DATA_LINK_PROPERTIES_KEY = PhoneConstants.DATA_LINK_PROPERTIES_KEY; 547 548 /** 549 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 550 * for the data connection fail cause. 551 * 552 * <p class="note"> 553 * Retrieve with 554 * {@link android.content.Intent#getStringExtra(String name)}. 555 * 556 * @hide 557 */ 558 public static final String EXTRA_DATA_FAILURE_CAUSE = PhoneConstants.DATA_FAILURE_CAUSE_KEY; 559 560 // 561 // 562 // Device Info 563 // 564 // 565 566 /** 567 * Returns the software version number for the device, for example, 568 * the IMEI/SV for GSM phones. Return null if the software version is 569 * not available. 570 * 571 * <p>Requires Permission: 572 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 573 */ 574 public String getDeviceSoftwareVersion() { 575 return getDeviceSoftwareVersion(getDefaultSim()); 576 } 577 578 /** 579 * Returns the software version number for the device, for example, 580 * the IMEI/SV for GSM phones. Return null if the software version is 581 * not available. 582 * 583 * <p>Requires Permission: 584 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 585 * 586 * @param slotId of which deviceID is returned 587 */ 588 /** {@hide} */ 589 public String getDeviceSoftwareVersion(int slotId) { 590 // FIXME methods taking slot id should not use subscription, instead us Uicc directly 591 int[] subId = SubscriptionManager.getSubId(slotId); 592 if (subId == null || subId.length == 0) { 593 return null; 594 } 595 try { 596 return getSubscriberInfo().getDeviceSvnUsingSubId(subId[0]); 597 } catch (RemoteException ex) { 598 return null; 599 } catch (NullPointerException ex) { 600 return null; 601 } 602 } 603 604 /** 605 * Returns the unique device ID, for example, the IMEI for GSM and the MEID 606 * or ESN for CDMA phones. Return null if device ID is not available. 607 * 608 * <p>Requires Permission: 609 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 610 */ 611 public String getDeviceId() { 612 return getDeviceId(getDefaultSim()); 613 } 614 615 /** 616 * Returns the unique device ID of a subscription, for example, the IMEI for 617 * GSM and the MEID for CDMA phones. Return null if device ID is not available. 618 * 619 * <p>Requires Permission: 620 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 621 * 622 * @param slotId of which deviceID is returned 623 */ 624 /** {@hide} */ 625 public String getDeviceId(int slotId) { 626 // FIXME methods taking slot id should not use subscription, instead us Uicc directly 627 int[] subId = SubscriptionManager.getSubId(slotId); 628 if (subId == null || subId.length == 0) { 629 return null; 630 } 631 try { 632 return getSubscriberInfo().getDeviceIdForSubscriber(subId[0]); 633 } catch (RemoteException ex) { 634 return null; 635 } catch (NullPointerException ex) { 636 return null; 637 } 638 } 639 640 /** 641 * Returns the IMEI. Return null if IMEI is not available. 642 * 643 * <p>Requires Permission: 644 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 645 */ 646 /** {@hide} */ 647 public String getImei() { 648 return getImei(getDefaultSim()); 649 } 650 651 /** 652 * Returns the IMEI. Return null if IMEI is not available. 653 * 654 * <p>Requires Permission: 655 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 656 * 657 * @param slotId of which deviceID is returned 658 */ 659 /** {@hide} */ 660 public String getImei(int slotId) { 661 int[] subId = SubscriptionManager.getSubId(slotId); 662 try { 663 return getSubscriberInfo().getImeiForSubscriber(subId[0]); 664 } catch (RemoteException ex) { 665 return null; 666 } catch (NullPointerException ex) { 667 return null; 668 } 669 } 670 671 /** 672 * Returns the NAI. Return null if NAI is not available. 673 * 674 */ 675 /** {@hide}*/ 676 public String getNai() { 677 return getNai(getDefaultSim()); 678 } 679 680 /** 681 * Returns the NAI. Return null if NAI is not available. 682 * 683 * @param slotId of which Nai is returned 684 */ 685 /** {@hide}*/ 686 public String getNai(int slotId) { 687 int[] subId = SubscriptionManager.getSubId(slotId); 688 try { 689 return getSubscriberInfo().getNaiForSubscriber(subId[0]); 690 } catch (RemoteException ex) { 691 return null; 692 } catch (NullPointerException ex) { 693 return null; 694 } 695 } 696 697 /** 698 * Returns the current location of the device. 699 *<p> 700 * If there is only one radio in the device and that radio has an LTE connection, 701 * this method will return null. The implementation must not to try add LTE 702 * identifiers into the existing cdma/gsm classes. 703 *<p> 704 * In the future this call will be deprecated. 705 *<p> 706 * @return Current location of the device or null if not available. 707 * 708 * <p>Requires Permission: 709 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or 710 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}. 711 */ 712 public CellLocation getCellLocation() { 713 try { 714 Bundle bundle = getITelephony().getCellLocation(); 715 if (bundle.isEmpty()) return null; 716 CellLocation cl = CellLocation.newFromBundle(bundle); 717 if (cl.isEmpty()) 718 return null; 719 return cl; 720 } catch (RemoteException ex) { 721 return null; 722 } catch (NullPointerException ex) { 723 return null; 724 } 725 } 726 727 /** 728 * Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged 729 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 730 * 731 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 732 * CONTROL_LOCATION_UPDATES} 733 * 734 * @hide 735 */ 736 public void enableLocationUpdates() { 737 enableLocationUpdates(getDefaultSubscription()); 738 } 739 740 /** 741 * Enables location update notifications for a subscription. 742 * {@link PhoneStateListener#onCellLocationChanged 743 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 744 * 745 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 746 * CONTROL_LOCATION_UPDATES} 747 * 748 * @param subId for which the location updates are enabled 749 */ 750 /** @hide */ 751 public void enableLocationUpdates(int subId) { 752 try { 753 getITelephony().enableLocationUpdatesForSubscriber(subId); 754 } catch (RemoteException ex) { 755 } catch (NullPointerException ex) { 756 } 757 } 758 759 /** 760 * Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged 761 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 762 * 763 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 764 * CONTROL_LOCATION_UPDATES} 765 * 766 * @hide 767 */ 768 public void disableLocationUpdates() { 769 disableLocationUpdates(getDefaultSubscription()); 770 } 771 772 /** @hide */ 773 public void disableLocationUpdates(int subId) { 774 try { 775 getITelephony().disableLocationUpdatesForSubscriber(subId); 776 } catch (RemoteException ex) { 777 } catch (NullPointerException ex) { 778 } 779 } 780 781 /** 782 * Returns the neighboring cell information of the device. The getAllCellInfo is preferred 783 * and use this only if getAllCellInfo return nulls or an empty list. 784 *<p> 785 * In the future this call will be deprecated. 786 *<p> 787 * @return List of NeighboringCellInfo or null if info unavailable. 788 * 789 * <p>Requires Permission: 790 * (@link android.Manifest.permission#ACCESS_COARSE_UPDATES} 791 */ 792 public List<NeighboringCellInfo> getNeighboringCellInfo() { 793 try { 794 return getITelephony().getNeighboringCellInfo(mContext.getOpPackageName()); 795 } catch (RemoteException ex) { 796 return null; 797 } catch (NullPointerException ex) { 798 return null; 799 } 800 } 801 802 /** No phone radio. */ 803 public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE; 804 /** Phone radio is GSM. */ 805 public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM; 806 /** Phone radio is CDMA. */ 807 public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA; 808 /** Phone is via SIP. */ 809 public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP; 810 811 /** 812 * Returns the current phone type. 813 * TODO: This is a last minute change and hence hidden. 814 * 815 * @see #PHONE_TYPE_NONE 816 * @see #PHONE_TYPE_GSM 817 * @see #PHONE_TYPE_CDMA 818 * @see #PHONE_TYPE_SIP 819 * 820 * {@hide} 821 */ 822 @SystemApi 823 public int getCurrentPhoneType() { 824 return getCurrentPhoneType(getDefaultSubscription()); 825 } 826 827 /** 828 * Returns a constant indicating the device phone type for a subscription. 829 * 830 * @see #PHONE_TYPE_NONE 831 * @see #PHONE_TYPE_GSM 832 * @see #PHONE_TYPE_CDMA 833 * 834 * @param subId for which phone type is returned 835 */ 836 /** {@hide} */ 837 @SystemApi 838 public int getCurrentPhoneType(int subId) { 839 int phoneId = SubscriptionManager.getPhoneId(subId); 840 try{ 841 ITelephony telephony = getITelephony(); 842 if (telephony != null) { 843 return telephony.getActivePhoneTypeForSubscriber(subId); 844 } else { 845 // This can happen when the ITelephony interface is not up yet. 846 return getPhoneTypeFromProperty(phoneId); 847 } 848 } catch (RemoteException ex) { 849 // This shouldn't happen in the normal case, as a backup we 850 // read from the system property. 851 return getPhoneTypeFromProperty(phoneId); 852 } catch (NullPointerException ex) { 853 // This shouldn't happen in the normal case, as a backup we 854 // read from the system property. 855 return getPhoneTypeFromProperty(phoneId); 856 } 857 } 858 859 /** 860 * Returns a constant indicating the device phone type. This 861 * indicates the type of radio used to transmit voice calls. 862 * 863 * @see #PHONE_TYPE_NONE 864 * @see #PHONE_TYPE_GSM 865 * @see #PHONE_TYPE_CDMA 866 * @see #PHONE_TYPE_SIP 867 */ 868 public int getPhoneType() { 869 if (!isVoiceCapable()) { 870 return PHONE_TYPE_NONE; 871 } 872 return getCurrentPhoneType(); 873 } 874 875 private int getPhoneTypeFromProperty() { 876 return getPhoneTypeFromProperty(getDefaultPhone()); 877 } 878 879 /** {@hide} */ 880 private int getPhoneTypeFromProperty(int phoneId) { 881 String type = getTelephonyProperty(phoneId, 882 TelephonyProperties.CURRENT_ACTIVE_PHONE, null); 883 if (type == null || type.equals("")) { 884 return getPhoneTypeFromNetworkType(phoneId); 885 } 886 return Integer.parseInt(type); 887 } 888 889 private int getPhoneTypeFromNetworkType() { 890 return getPhoneTypeFromNetworkType(getDefaultPhone()); 891 } 892 893 /** {@hide} */ 894 private int getPhoneTypeFromNetworkType(int phoneId) { 895 // When the system property CURRENT_ACTIVE_PHONE, has not been set, 896 // use the system property for default network type. 897 // This is a fail safe, and can only happen at first boot. 898 String mode = getTelephonyProperty(phoneId, "ro.telephony.default_network", null); 899 if (mode != null) { 900 return TelephonyManager.getPhoneType(Integer.parseInt(mode)); 901 } 902 return TelephonyManager.PHONE_TYPE_NONE; 903 } 904 905 /** 906 * This function returns the type of the phone, depending 907 * on the network mode. 908 * 909 * @param networkMode 910 * @return Phone Type 911 * 912 * @hide 913 */ 914 public static int getPhoneType(int networkMode) { 915 switch(networkMode) { 916 case RILConstants.NETWORK_MODE_CDMA: 917 case RILConstants.NETWORK_MODE_CDMA_NO_EVDO: 918 case RILConstants.NETWORK_MODE_EVDO_NO_CDMA: 919 return PhoneConstants.PHONE_TYPE_CDMA; 920 921 case RILConstants.NETWORK_MODE_WCDMA_PREF: 922 case RILConstants.NETWORK_MODE_GSM_ONLY: 923 case RILConstants.NETWORK_MODE_WCDMA_ONLY: 924 case RILConstants.NETWORK_MODE_GSM_UMTS: 925 case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA: 926 case RILConstants.NETWORK_MODE_LTE_WCDMA: 927 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA: 928 return PhoneConstants.PHONE_TYPE_GSM; 929 930 // Use CDMA Phone for the global mode including CDMA 931 case RILConstants.NETWORK_MODE_GLOBAL: 932 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO: 933 return PhoneConstants.PHONE_TYPE_CDMA; 934 935 case RILConstants.NETWORK_MODE_LTE_ONLY: 936 if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) { 937 return PhoneConstants.PHONE_TYPE_CDMA; 938 } else { 939 return PhoneConstants.PHONE_TYPE_GSM; 940 } 941 default: 942 return PhoneConstants.PHONE_TYPE_GSM; 943 } 944 } 945 946 /** 947 * The contents of the /proc/cmdline file 948 */ 949 private static String getProcCmdLine() 950 { 951 String cmdline = ""; 952 FileInputStream is = null; 953 try { 954 is = new FileInputStream("/proc/cmdline"); 955 byte [] buffer = new byte[2048]; 956 int count = is.read(buffer); 957 if (count > 0) { 958 cmdline = new String(buffer, 0, count); 959 } 960 } catch (IOException e) { 961 Rlog.d(TAG, "No /proc/cmdline exception=" + e); 962 } finally { 963 if (is != null) { 964 try { 965 is.close(); 966 } catch (IOException e) { 967 } 968 } 969 } 970 Rlog.d(TAG, "/proc/cmdline=" + cmdline); 971 return cmdline; 972 } 973 974 /** Kernel command line */ 975 private static final String sKernelCmdLine = getProcCmdLine(); 976 977 /** Pattern for selecting the product type from the kernel command line */ 978 private static final Pattern sProductTypePattern = 979 Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)"); 980 981 /** The ProductType used for LTE on CDMA devices */ 982 private static final String sLteOnCdmaProductType = 983 SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, ""); 984 985 /** 986 * Return if the current radio is LTE on CDMA. This 987 * is a tri-state return value as for a period of time 988 * the mode may be unknown. 989 * 990 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 991 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 992 * 993 * @hide 994 */ 995 public static int getLteOnCdmaModeStatic() { 996 int retVal; 997 int curVal; 998 String productType = ""; 999 1000 curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE, 1001 PhoneConstants.LTE_ON_CDMA_UNKNOWN); 1002 retVal = curVal; 1003 if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) { 1004 Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine); 1005 if (matcher.find()) { 1006 productType = matcher.group(1); 1007 if (sLteOnCdmaProductType.equals(productType)) { 1008 retVal = PhoneConstants.LTE_ON_CDMA_TRUE; 1009 } else { 1010 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 1011 } 1012 } else { 1013 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 1014 } 1015 } 1016 1017 Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal + 1018 " product_type='" + productType + 1019 "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'"); 1020 return retVal; 1021 } 1022 1023 // 1024 // 1025 // Current Network 1026 // 1027 // 1028 1029 /** 1030 * Returns the alphabetic name of current registered operator. 1031 * <p> 1032 * Availability: Only when user is registered to a network. Result may be 1033 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1034 * on a CDMA network). 1035 */ 1036 public String getNetworkOperatorName() { 1037 return getNetworkOperatorName(getDefaultSubscription()); 1038 } 1039 1040 /** 1041 * Returns the alphabetic name of current registered operator 1042 * for a particular subscription. 1043 * <p> 1044 * Availability: Only when user is registered to a network. Result may be 1045 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1046 * on a CDMA network). 1047 * @param subId 1048 */ 1049 /** {@hide} */ 1050 public String getNetworkOperatorName(int subId) { 1051 int phoneId = SubscriptionManager.getPhoneId(subId); 1052 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, ""); 1053 } 1054 1055 /** 1056 * Returns the numeric name (MCC+MNC) of current registered operator. 1057 * <p> 1058 * Availability: Only when user is registered to a network. Result may be 1059 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1060 * on a CDMA network). 1061 */ 1062 public String getNetworkOperator() { 1063 return getNetworkOperator(getDefaultSubscription()); 1064 } 1065 1066 /** 1067 * Returns the numeric name (MCC+MNC) of current registered operator 1068 * for a particular subscription. 1069 * <p> 1070 * Availability: Only when user is registered to a network. Result may be 1071 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1072 * on a CDMA network). 1073 * 1074 * @param subId 1075 */ 1076 /** {@hide} */ 1077 public String getNetworkOperator(int subId) { 1078 int phoneId = SubscriptionManager.getPhoneId(subId); 1079 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, ""); 1080 } 1081 1082 /** 1083 * Returns true if the device is considered roaming on the current 1084 * network, for GSM purposes. 1085 * <p> 1086 * Availability: Only when user registered to a network. 1087 */ 1088 public boolean isNetworkRoaming() { 1089 return isNetworkRoaming(getDefaultSubscription()); 1090 } 1091 1092 /** 1093 * Returns true if the device is considered roaming on the current 1094 * network for a subscription. 1095 * <p> 1096 * Availability: Only when user registered to a network. 1097 * 1098 * @param subId 1099 */ 1100 /** {@hide} */ 1101 public boolean isNetworkRoaming(int subId) { 1102 int phoneId = SubscriptionManager.getPhoneId(subId); 1103 return Boolean.parseBoolean(getTelephonyProperty(phoneId, 1104 TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, null)); 1105 } 1106 1107 /** 1108 * Returns the ISO country code equivalent of the current registered 1109 * operator's MCC (Mobile Country Code). 1110 * <p> 1111 * Availability: Only when user is registered to a network. Result may be 1112 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1113 * on a CDMA network). 1114 */ 1115 public String getNetworkCountryIso() { 1116 return getNetworkCountryIso(getDefaultSubscription()); 1117 } 1118 1119 /** 1120 * Returns the ISO country code equivalent of the current registered 1121 * operator's MCC (Mobile Country Code) of a subscription. 1122 * <p> 1123 * Availability: Only when user is registered to a network. Result may be 1124 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1125 * on a CDMA network). 1126 * 1127 * @param subId for which Network CountryIso is returned 1128 */ 1129 /** {@hide} */ 1130 public String getNetworkCountryIso(int subId) { 1131 int phoneId = SubscriptionManager.getPhoneId(subId); 1132 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, ""); 1133 } 1134 1135 /** Network type is unknown */ 1136 public static final int NETWORK_TYPE_UNKNOWN = 0; 1137 /** Current network is GPRS */ 1138 public static final int NETWORK_TYPE_GPRS = 1; 1139 /** Current network is EDGE */ 1140 public static final int NETWORK_TYPE_EDGE = 2; 1141 /** Current network is UMTS */ 1142 public static final int NETWORK_TYPE_UMTS = 3; 1143 /** Current network is CDMA: Either IS95A or IS95B*/ 1144 public static final int NETWORK_TYPE_CDMA = 4; 1145 /** Current network is EVDO revision 0*/ 1146 public static final int NETWORK_TYPE_EVDO_0 = 5; 1147 /** Current network is EVDO revision A*/ 1148 public static final int NETWORK_TYPE_EVDO_A = 6; 1149 /** Current network is 1xRTT*/ 1150 public static final int NETWORK_TYPE_1xRTT = 7; 1151 /** Current network is HSDPA */ 1152 public static final int NETWORK_TYPE_HSDPA = 8; 1153 /** Current network is HSUPA */ 1154 public static final int NETWORK_TYPE_HSUPA = 9; 1155 /** Current network is HSPA */ 1156 public static final int NETWORK_TYPE_HSPA = 10; 1157 /** Current network is iDen */ 1158 public static final int NETWORK_TYPE_IDEN = 11; 1159 /** Current network is EVDO revision B*/ 1160 public static final int NETWORK_TYPE_EVDO_B = 12; 1161 /** Current network is LTE */ 1162 public static final int NETWORK_TYPE_LTE = 13; 1163 /** Current network is eHRPD */ 1164 public static final int NETWORK_TYPE_EHRPD = 14; 1165 /** Current network is HSPA+ */ 1166 public static final int NETWORK_TYPE_HSPAP = 15; 1167 /** Current network is GSM {@hide} */ 1168 public static final int NETWORK_TYPE_GSM = 16; 1169 1170 /** 1171 * @return the NETWORK_TYPE_xxxx for current data connection. 1172 */ 1173 public int getNetworkType() { 1174 return getDataNetworkType(); 1175 } 1176 1177 /** 1178 * Returns a constant indicating the radio technology (network type) 1179 * currently in use on the device for a subscription. 1180 * @return the network type 1181 * 1182 * @param subId for which network type is returned 1183 * 1184 * @see #NETWORK_TYPE_UNKNOWN 1185 * @see #NETWORK_TYPE_GPRS 1186 * @see #NETWORK_TYPE_EDGE 1187 * @see #NETWORK_TYPE_UMTS 1188 * @see #NETWORK_TYPE_HSDPA 1189 * @see #NETWORK_TYPE_HSUPA 1190 * @see #NETWORK_TYPE_HSPA 1191 * @see #NETWORK_TYPE_CDMA 1192 * @see #NETWORK_TYPE_EVDO_0 1193 * @see #NETWORK_TYPE_EVDO_A 1194 * @see #NETWORK_TYPE_EVDO_B 1195 * @see #NETWORK_TYPE_1xRTT 1196 * @see #NETWORK_TYPE_IDEN 1197 * @see #NETWORK_TYPE_LTE 1198 * @see #NETWORK_TYPE_EHRPD 1199 * @see #NETWORK_TYPE_HSPAP 1200 */ 1201 /** {@hide} */ 1202 public int getNetworkType(int subId) { 1203 try { 1204 ITelephony telephony = getITelephony(); 1205 if (telephony != null) { 1206 return telephony.getNetworkTypeForSubscriber(subId); 1207 } else { 1208 // This can happen when the ITelephony interface is not up yet. 1209 return NETWORK_TYPE_UNKNOWN; 1210 } 1211 } catch(RemoteException ex) { 1212 // This shouldn't happen in the normal case 1213 return NETWORK_TYPE_UNKNOWN; 1214 } catch (NullPointerException ex) { 1215 // This could happen before phone restarts due to crashing 1216 return NETWORK_TYPE_UNKNOWN; 1217 } 1218 } 1219 1220 /** 1221 * Returns a constant indicating the radio technology (network type) 1222 * currently in use on the device for data transmission. 1223 * @return the network type 1224 * 1225 * @see #NETWORK_TYPE_UNKNOWN 1226 * @see #NETWORK_TYPE_GPRS 1227 * @see #NETWORK_TYPE_EDGE 1228 * @see #NETWORK_TYPE_UMTS 1229 * @see #NETWORK_TYPE_HSDPA 1230 * @see #NETWORK_TYPE_HSUPA 1231 * @see #NETWORK_TYPE_HSPA 1232 * @see #NETWORK_TYPE_CDMA 1233 * @see #NETWORK_TYPE_EVDO_0 1234 * @see #NETWORK_TYPE_EVDO_A 1235 * @see #NETWORK_TYPE_EVDO_B 1236 * @see #NETWORK_TYPE_1xRTT 1237 * @see #NETWORK_TYPE_IDEN 1238 * @see #NETWORK_TYPE_LTE 1239 * @see #NETWORK_TYPE_EHRPD 1240 * @see #NETWORK_TYPE_HSPAP 1241 * 1242 * @hide 1243 */ 1244 public int getDataNetworkType() { 1245 return getDataNetworkType(getDefaultSubscription()); 1246 } 1247 1248 /** 1249 * Returns a constant indicating the radio technology (network type) 1250 * currently in use on the device for data transmission for a subscription 1251 * @return the network type 1252 * 1253 * @param subId for which network type is returned 1254 */ 1255 /** {@hide} */ 1256 public int getDataNetworkType(int subId) { 1257 try{ 1258 ITelephony telephony = getITelephony(); 1259 if (telephony != null) { 1260 return telephony.getDataNetworkTypeForSubscriber(subId); 1261 } else { 1262 // This can happen when the ITelephony interface is not up yet. 1263 return NETWORK_TYPE_UNKNOWN; 1264 } 1265 } catch(RemoteException ex) { 1266 // This shouldn't happen in the normal case 1267 return NETWORK_TYPE_UNKNOWN; 1268 } catch (NullPointerException ex) { 1269 // This could happen before phone restarts due to crashing 1270 return NETWORK_TYPE_UNKNOWN; 1271 } 1272 } 1273 1274 /** 1275 * Returns the NETWORK_TYPE_xxxx for voice 1276 * 1277 * @hide 1278 */ 1279 public int getVoiceNetworkType() { 1280 return getVoiceNetworkType(getDefaultSubscription()); 1281 } 1282 1283 /** 1284 * Returns the NETWORK_TYPE_xxxx for voice for a subId 1285 * 1286 */ 1287 /** {@hide} */ 1288 public int getVoiceNetworkType(int subId) { 1289 try{ 1290 ITelephony telephony = getITelephony(); 1291 if (telephony != null) { 1292 return telephony.getVoiceNetworkTypeForSubscriber(subId); 1293 } else { 1294 // This can happen when the ITelephony interface is not up yet. 1295 return NETWORK_TYPE_UNKNOWN; 1296 } 1297 } catch(RemoteException ex) { 1298 // This shouldn't happen in the normal case 1299 return NETWORK_TYPE_UNKNOWN; 1300 } catch (NullPointerException ex) { 1301 // This could happen before phone restarts due to crashing 1302 return NETWORK_TYPE_UNKNOWN; 1303 } 1304 } 1305 1306 /** Unknown network class. {@hide} */ 1307 public static final int NETWORK_CLASS_UNKNOWN = 0; 1308 /** Class of broadly defined "2G" networks. {@hide} */ 1309 public static final int NETWORK_CLASS_2_G = 1; 1310 /** Class of broadly defined "3G" networks. {@hide} */ 1311 public static final int NETWORK_CLASS_3_G = 2; 1312 /** Class of broadly defined "4G" networks. {@hide} */ 1313 public static final int NETWORK_CLASS_4_G = 3; 1314 1315 /** 1316 * Return general class of network type, such as "3G" or "4G". In cases 1317 * where classification is contentious, this method is conservative. 1318 * 1319 * @hide 1320 */ 1321 public static int getNetworkClass(int networkType) { 1322 switch (networkType) { 1323 case NETWORK_TYPE_GPRS: 1324 case NETWORK_TYPE_GSM: 1325 case NETWORK_TYPE_EDGE: 1326 case NETWORK_TYPE_CDMA: 1327 case NETWORK_TYPE_1xRTT: 1328 case NETWORK_TYPE_IDEN: 1329 return NETWORK_CLASS_2_G; 1330 case NETWORK_TYPE_UMTS: 1331 case NETWORK_TYPE_EVDO_0: 1332 case NETWORK_TYPE_EVDO_A: 1333 case NETWORK_TYPE_HSDPA: 1334 case NETWORK_TYPE_HSUPA: 1335 case NETWORK_TYPE_HSPA: 1336 case NETWORK_TYPE_EVDO_B: 1337 case NETWORK_TYPE_EHRPD: 1338 case NETWORK_TYPE_HSPAP: 1339 return NETWORK_CLASS_3_G; 1340 case NETWORK_TYPE_LTE: 1341 return NETWORK_CLASS_4_G; 1342 default: 1343 return NETWORK_CLASS_UNKNOWN; 1344 } 1345 } 1346 1347 /** 1348 * Returns a string representation of the radio technology (network type) 1349 * currently in use on the device. 1350 * @return the name of the radio technology 1351 * 1352 * @hide pending API council review 1353 */ 1354 public String getNetworkTypeName() { 1355 return getNetworkTypeName(getNetworkType()); 1356 } 1357 1358 /** 1359 * Returns a string representation of the radio technology (network type) 1360 * currently in use on the device. 1361 * @param subId for which network type is returned 1362 * @return the name of the radio technology 1363 * 1364 */ 1365 /** {@hide} */ 1366 public static String getNetworkTypeName(int type) { 1367 switch (type) { 1368 case NETWORK_TYPE_GPRS: 1369 return "GPRS"; 1370 case NETWORK_TYPE_EDGE: 1371 return "EDGE"; 1372 case NETWORK_TYPE_UMTS: 1373 return "UMTS"; 1374 case NETWORK_TYPE_HSDPA: 1375 return "HSDPA"; 1376 case NETWORK_TYPE_HSUPA: 1377 return "HSUPA"; 1378 case NETWORK_TYPE_HSPA: 1379 return "HSPA"; 1380 case NETWORK_TYPE_CDMA: 1381 return "CDMA"; 1382 case NETWORK_TYPE_EVDO_0: 1383 return "CDMA - EvDo rev. 0"; 1384 case NETWORK_TYPE_EVDO_A: 1385 return "CDMA - EvDo rev. A"; 1386 case NETWORK_TYPE_EVDO_B: 1387 return "CDMA - EvDo rev. B"; 1388 case NETWORK_TYPE_1xRTT: 1389 return "CDMA - 1xRTT"; 1390 case NETWORK_TYPE_LTE: 1391 return "LTE"; 1392 case NETWORK_TYPE_EHRPD: 1393 return "CDMA - eHRPD"; 1394 case NETWORK_TYPE_IDEN: 1395 return "iDEN"; 1396 case NETWORK_TYPE_HSPAP: 1397 return "HSPA+"; 1398 case NETWORK_TYPE_GSM: 1399 return "GSM"; 1400 default: 1401 return "UNKNOWN"; 1402 } 1403 } 1404 1405 // 1406 // 1407 // SIM Card 1408 // 1409 // 1410 1411 /** SIM card state: Unknown. Signifies that the SIM is in transition 1412 * between states. For example, when the user inputs the SIM pin 1413 * under PIN_REQUIRED state, a query for sim status returns 1414 * this state before turning to SIM_STATE_READY. */ 1415 public static final int SIM_STATE_UNKNOWN = 0; 1416 /** SIM card state: no SIM card is available in the device */ 1417 public static final int SIM_STATE_ABSENT = 1; 1418 /** SIM card state: Locked: requires the user's SIM PIN to unlock */ 1419 public static final int SIM_STATE_PIN_REQUIRED = 2; 1420 /** SIM card state: Locked: requires the user's SIM PUK to unlock */ 1421 public static final int SIM_STATE_PUK_REQUIRED = 3; 1422 /** SIM card state: Locked: requries a network PIN to unlock */ 1423 public static final int SIM_STATE_NETWORK_LOCKED = 4; 1424 /** SIM card state: Ready */ 1425 public static final int SIM_STATE_READY = 5; 1426 /** SIM card state: SIM Card Error, Sim Card is present but faulty 1427 *@hide 1428 */ 1429 public static final int SIM_STATE_CARD_IO_ERROR = 6; 1430 1431 /** 1432 * @return true if a ICC card is present 1433 */ 1434 public boolean hasIccCard() { 1435 return hasIccCard(getDefaultSim()); 1436 } 1437 1438 /** 1439 * @return true if a ICC card is present for a subscription 1440 * 1441 * @param slotId for which icc card presence is checked 1442 */ 1443 /** {@hide} */ 1444 // FIXME Input argument slotId should be of type int 1445 public boolean hasIccCard(int slotId) { 1446 1447 try { 1448 return getITelephony().hasIccCardUsingSlotId(slotId); 1449 } catch (RemoteException ex) { 1450 // Assume no ICC card if remote exception which shouldn't happen 1451 return false; 1452 } catch (NullPointerException ex) { 1453 // This could happen before phone restarts due to crashing 1454 return false; 1455 } 1456 } 1457 1458 /** 1459 * Returns a constant indicating the state of the 1460 * device SIM card. 1461 * 1462 * @see #SIM_STATE_UNKNOWN 1463 * @see #SIM_STATE_ABSENT 1464 * @see #SIM_STATE_PIN_REQUIRED 1465 * @see #SIM_STATE_PUK_REQUIRED 1466 * @see #SIM_STATE_NETWORK_LOCKED 1467 * @see #SIM_STATE_READY 1468 * @see #SIM_STATE_CARD_IO_ERROR 1469 */ 1470 public int getSimState() { 1471 return getSimState(getDefaultSim()); 1472 } 1473 1474 /** 1475 * Returns a constant indicating the state of the 1476 * device SIM card in a slot. 1477 * 1478 * @param slotId 1479 * 1480 * @see #SIM_STATE_UNKNOWN 1481 * @see #SIM_STATE_ABSENT 1482 * @see #SIM_STATE_PIN_REQUIRED 1483 * @see #SIM_STATE_PUK_REQUIRED 1484 * @see #SIM_STATE_NETWORK_LOCKED 1485 * @see #SIM_STATE_READY 1486 */ 1487 /** {@hide} */ 1488 // FIXME the argument to pass is subId ?? 1489 public int getSimState(int slotId) { 1490 int[] subId = SubscriptionManager.getSubId(slotId); 1491 if (subId == null || subId.length == 0) { 1492 return SIM_STATE_ABSENT; 1493 } 1494 // FIXME Do not use a property to determine SIM_STATE, call 1495 // appropriate method on some object. 1496 int phoneId = SubscriptionManager.getPhoneId(subId[0]); 1497 String prop = getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_SIM_STATE, ""); 1498 if ("ABSENT".equals(prop)) { 1499 return SIM_STATE_ABSENT; 1500 } 1501 else if ("PIN_REQUIRED".equals(prop)) { 1502 return SIM_STATE_PIN_REQUIRED; 1503 } 1504 else if ("PUK_REQUIRED".equals(prop)) { 1505 return SIM_STATE_PUK_REQUIRED; 1506 } 1507 else if ("NETWORK_LOCKED".equals(prop)) { 1508 return SIM_STATE_NETWORK_LOCKED; 1509 } 1510 else if ("READY".equals(prop)) { 1511 return SIM_STATE_READY; 1512 } 1513 else if ("CARD_IO_ERROR".equals(prop)) { 1514 return SIM_STATE_CARD_IO_ERROR; 1515 } 1516 else { 1517 return SIM_STATE_UNKNOWN; 1518 } 1519 } 1520 1521 /** 1522 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1523 * provider of the SIM. 5 or 6 decimal digits. 1524 * <p> 1525 * Availability: SIM state must be {@link #SIM_STATE_READY} 1526 * 1527 * @see #getSimState 1528 */ 1529 public String getSimOperator() { 1530 int subId = SubscriptionManager.getDefaultDataSubId(); 1531 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1532 subId = SubscriptionManager.getDefaultSmsSubId(); 1533 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1534 subId = SubscriptionManager.getDefaultVoiceSubId(); 1535 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 1536 subId = SubscriptionManager.getDefaultSubId(); 1537 } 1538 } 1539 } 1540 Rlog.d(TAG, "getSimOperator(): default subId=" + subId); 1541 return getSimOperator(subId); 1542 } 1543 1544 /** 1545 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1546 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 1547 * <p> 1548 * Availability: SIM state must be {@link #SIM_STATE_READY} 1549 * 1550 * @see #getSimState 1551 * 1552 * @param subId for which SimOperator is returned 1553 */ 1554 /** {@hide} */ 1555 public String getSimOperator(int subId) { 1556 int phoneId = SubscriptionManager.getPhoneId(subId); 1557 String operator = getTelephonyProperty(phoneId, 1558 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, ""); 1559 Rlog.d(TAG, "getSimOperator: subId=" + subId + " operator=" + operator); 1560 return operator; 1561 } 1562 1563 /** 1564 * Returns the Service Provider Name (SPN). 1565 * <p> 1566 * Availability: SIM state must be {@link #SIM_STATE_READY} 1567 * 1568 * @see #getSimState 1569 */ 1570 public String getSimOperatorName() { 1571 return getSimOperatorName(getDefaultSubscription()); 1572 } 1573 1574 /** 1575 * Returns the Service Provider Name (SPN). 1576 * <p> 1577 * Availability: SIM state must be {@link #SIM_STATE_READY} 1578 * 1579 * @see #getSimState 1580 * 1581 * @param subId for which SimOperatorName is returned 1582 */ 1583 /** {@hide} */ 1584 public String getSimOperatorName(int subId) { 1585 int phoneId = SubscriptionManager.getPhoneId(subId); 1586 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, ""); 1587 } 1588 1589 /** 1590 * Returns the ISO country code equivalent for the SIM provider's country code. 1591 */ 1592 public String getSimCountryIso() { 1593 return getSimCountryIso(getDefaultSubscription()); 1594 } 1595 1596 /** 1597 * Returns the ISO country code equivalent for the SIM provider's country code. 1598 * 1599 * @param subId for which SimCountryIso is returned 1600 */ 1601 /** {@hide} */ 1602 public String getSimCountryIso(int subId) { 1603 int phoneId = SubscriptionManager.getPhoneId(subId); 1604 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, 1605 ""); 1606 } 1607 1608 /** 1609 * Returns the serial number of the SIM, if applicable. Return null if it is 1610 * unavailable. 1611 * <p> 1612 * Requires Permission: 1613 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1614 */ 1615 public String getSimSerialNumber() { 1616 return getSimSerialNumber(getDefaultSubscription()); 1617 } 1618 1619 /** 1620 * Returns the serial number for the given subscription, if applicable. Return null if it is 1621 * unavailable. 1622 * <p> 1623 * @param subId for which Sim Serial number is returned 1624 * Requires Permission: 1625 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1626 */ 1627 /** {@hide} */ 1628 public String getSimSerialNumber(int subId) { 1629 try { 1630 return getSubscriberInfo().getIccSerialNumberForSubscriber(subId); 1631 } catch (RemoteException ex) { 1632 return null; 1633 } catch (NullPointerException ex) { 1634 // This could happen before phone restarts due to crashing 1635 return null; 1636 } 1637 } 1638 1639 /** 1640 * Return if the current radio is LTE on CDMA. This 1641 * is a tri-state return value as for a period of time 1642 * the mode may be unknown. 1643 * 1644 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1645 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1646 * 1647 * @hide 1648 */ 1649 public int getLteOnCdmaMode() { 1650 return getLteOnCdmaMode(getDefaultSubscription()); 1651 } 1652 1653 /** 1654 * Return if the current radio is LTE on CDMA for Subscription. This 1655 * is a tri-state return value as for a period of time 1656 * the mode may be unknown. 1657 * 1658 * @param subId for which radio is LTE on CDMA is returned 1659 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1660 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1661 * 1662 */ 1663 /** {@hide} */ 1664 public int getLteOnCdmaMode(int subId) { 1665 try { 1666 return getITelephony().getLteOnCdmaModeForSubscriber(subId); 1667 } catch (RemoteException ex) { 1668 // Assume no ICC card if remote exception which shouldn't happen 1669 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1670 } catch (NullPointerException ex) { 1671 // This could happen before phone restarts due to crashing 1672 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1673 } 1674 } 1675 1676 // 1677 // 1678 // Subscriber Info 1679 // 1680 // 1681 1682 /** 1683 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 1684 * Return null if it is unavailable. 1685 * <p> 1686 * Requires Permission: 1687 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1688 */ 1689 public String getSubscriberId() { 1690 return getSubscriberId(getDefaultSubscription()); 1691 } 1692 1693 /** 1694 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone 1695 * for a subscription. 1696 * Return null if it is unavailable. 1697 * <p> 1698 * Requires Permission: 1699 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1700 * 1701 * @param subId whose subscriber id is returned 1702 */ 1703 /** {@hide} */ 1704 public String getSubscriberId(int subId) { 1705 try { 1706 return getSubscriberInfo().getSubscriberIdForSubscriber(subId); 1707 } catch (RemoteException ex) { 1708 return null; 1709 } catch (NullPointerException ex) { 1710 // This could happen before phone restarts due to crashing 1711 return null; 1712 } 1713 } 1714 1715 /** 1716 * Returns the Group Identifier Level1 for a GSM phone. 1717 * Return null if it is unavailable. 1718 * <p> 1719 * Requires Permission: 1720 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1721 */ 1722 public String getGroupIdLevel1() { 1723 try { 1724 return getSubscriberInfo().getGroupIdLevel1(); 1725 } catch (RemoteException ex) { 1726 return null; 1727 } catch (NullPointerException ex) { 1728 // This could happen before phone restarts due to crashing 1729 return null; 1730 } 1731 } 1732 1733 /** 1734 * Returns the Group Identifier Level1 for a GSM phone for a particular subscription. 1735 * Return null if it is unavailable. 1736 * <p> 1737 * Requires Permission: 1738 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1739 * 1740 * @param subscription whose subscriber id is returned 1741 */ 1742 /** {@hide} */ 1743 public String getGroupIdLevel1(int subId) { 1744 try { 1745 return getSubscriberInfo().getGroupIdLevel1ForSubscriber(subId); 1746 } catch (RemoteException ex) { 1747 return null; 1748 } catch (NullPointerException ex) { 1749 // This could happen before phone restarts due to crashing 1750 return null; 1751 } 1752 } 1753 1754 /** 1755 * Returns the phone number string for line 1, for example, the MSISDN 1756 * for a GSM phone. Return null if it is unavailable. 1757 * <p> 1758 * Requires Permission: 1759 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1760 */ 1761 public String getLine1Number() { 1762 return getLine1NumberForSubscriber(getDefaultSubscription()); 1763 } 1764 1765 /** 1766 * Returns the phone number string for line 1, for example, the MSISDN 1767 * for a GSM phone for a particular subscription. Return null if it is unavailable. 1768 * <p> 1769 * Requires Permission: 1770 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1771 * 1772 * @param subId whose phone number for line 1 is returned 1773 */ 1774 /** {@hide} */ 1775 public String getLine1NumberForSubscriber(int subId) { 1776 String number = null; 1777 try { 1778 number = getITelephony().getLine1NumberForDisplay(subId); 1779 } catch (RemoteException ex) { 1780 } catch (NullPointerException ex) { 1781 } 1782 if (number != null) { 1783 return number; 1784 } 1785 try { 1786 return getSubscriberInfo().getLine1NumberForSubscriber(subId); 1787 } catch (RemoteException ex) { 1788 return null; 1789 } catch (NullPointerException ex) { 1790 // This could happen before phone restarts due to crashing 1791 return null; 1792 } 1793 } 1794 1795 /** 1796 * Set the line 1 phone number string and its alphatag for the current ICCID 1797 * for display purpose only, for example, displayed in Phone Status. It won't 1798 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 1799 * value. 1800 * <p> 1801 * Requires Permission: 1802 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 1803 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 1804 * 1805 * @param alphaTag alpha-tagging of the dailing nubmer 1806 * @param number The dialing number 1807 */ 1808 public void setLine1NumberForDisplay(String alphaTag, String number) { 1809 setLine1NumberForDisplayForSubscriber(getDefaultSubscription(), alphaTag, number); 1810 } 1811 1812 /** 1813 * Set the line 1 phone number string and its alphatag for the current ICCID 1814 * for display purpose only, for example, displayed in Phone Status. It won't 1815 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 1816 * value. 1817 * <p> 1818 * Requires Permission: 1819 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 1820 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 1821 * 1822 * @param subId the subscriber that the alphatag and dialing number belongs to. 1823 * @param alphaTag alpha-tagging of the dailing nubmer 1824 * @param number The dialing number 1825 * @hide 1826 */ 1827 public void setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, String number) { 1828 try { 1829 getITelephony().setLine1NumberForDisplayForSubscriber(subId, alphaTag, number); 1830 } catch (RemoteException ex) { 1831 } catch (NullPointerException ex) { 1832 } 1833 } 1834 1835 /** 1836 * Returns the alphabetic identifier associated with the line 1 number. 1837 * Return null if it is unavailable. 1838 * <p> 1839 * Requires Permission: 1840 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1841 * @hide 1842 * nobody seems to call this. 1843 */ 1844 public String getLine1AlphaTag() { 1845 return getLine1AlphaTagForSubscriber(getDefaultSubscription()); 1846 } 1847 1848 /** 1849 * Returns the alphabetic identifier associated with the line 1 number 1850 * for a subscription. 1851 * Return null if it is unavailable. 1852 * <p> 1853 * Requires Permission: 1854 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1855 * @param subId whose alphabetic identifier associated with line 1 is returned 1856 * nobody seems to call this. 1857 */ 1858 /** {@hide} */ 1859 public String getLine1AlphaTagForSubscriber(int subId) { 1860 String alphaTag = null; 1861 try { 1862 alphaTag = getITelephony().getLine1AlphaTagForDisplay(subId); 1863 } catch (RemoteException ex) { 1864 } catch (NullPointerException ex) { 1865 } 1866 if (alphaTag != null) { 1867 return alphaTag; 1868 } 1869 try { 1870 return getSubscriberInfo().getLine1AlphaTagForSubscriber(subId); 1871 } catch (RemoteException ex) { 1872 return null; 1873 } catch (NullPointerException ex) { 1874 // This could happen before phone restarts due to crashing 1875 return null; 1876 } 1877 } 1878 1879 /** 1880 * Returns the MSISDN string. 1881 * for a GSM phone. Return null if it is unavailable. 1882 * <p> 1883 * Requires Permission: 1884 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1885 * 1886 * @hide 1887 */ 1888 public String getMsisdn() { 1889 return getMsisdn(getDefaultSubscription()); 1890 } 1891 1892 /** 1893 * Returns the MSISDN string. 1894 * for a GSM phone. Return null if it is unavailable. 1895 * <p> 1896 * Requires Permission: 1897 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1898 * 1899 * @param subId for which msisdn is returned 1900 */ 1901 /** {@hide} */ 1902 public String getMsisdn(int subId) { 1903 try { 1904 return getSubscriberInfo().getMsisdnForSubscriber(subId); 1905 } catch (RemoteException ex) { 1906 return null; 1907 } catch (NullPointerException ex) { 1908 // This could happen before phone restarts due to crashing 1909 return null; 1910 } 1911 } 1912 1913 /** 1914 * Returns the voice mail number. Return null if it is unavailable. 1915 * <p> 1916 * Requires Permission: 1917 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1918 */ 1919 public String getVoiceMailNumber() { 1920 return getVoiceMailNumber(getDefaultSubscription()); 1921 } 1922 1923 /** 1924 * Returns the voice mail number for a subscription. 1925 * Return null if it is unavailable. 1926 * <p> 1927 * Requires Permission: 1928 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1929 * @param subId whose voice mail number is returned 1930 */ 1931 /** {@hide} */ 1932 public String getVoiceMailNumber(int subId) { 1933 try { 1934 return getSubscriberInfo().getVoiceMailNumberForSubscriber(subId); 1935 } catch (RemoteException ex) { 1936 return null; 1937 } catch (NullPointerException ex) { 1938 // This could happen before phone restarts due to crashing 1939 return null; 1940 } 1941 } 1942 1943 /** 1944 * Returns the complete voice mail number. Return null if it is unavailable. 1945 * <p> 1946 * Requires Permission: 1947 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 1948 * 1949 * @hide 1950 */ 1951 public String getCompleteVoiceMailNumber() { 1952 return getCompleteVoiceMailNumber(getDefaultSubscription()); 1953 } 1954 1955 /** 1956 * Returns the complete voice mail number. Return null if it is unavailable. 1957 * <p> 1958 * Requires Permission: 1959 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 1960 * 1961 * @param subId 1962 */ 1963 /** {@hide} */ 1964 public String getCompleteVoiceMailNumber(int subId) { 1965 try { 1966 return getSubscriberInfo().getCompleteVoiceMailNumberForSubscriber(subId); 1967 } catch (RemoteException ex) { 1968 return null; 1969 } catch (NullPointerException ex) { 1970 // This could happen before phone restarts due to crashing 1971 return null; 1972 } 1973 } 1974 1975 /** 1976 * Returns the voice mail count. Return 0 if unavailable. 1977 * <p> 1978 * Requires Permission: 1979 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1980 * @hide 1981 */ 1982 public int getVoiceMessageCount() { 1983 return getVoiceMessageCount(getDefaultSubscription()); 1984 } 1985 1986 /** 1987 * Returns the voice mail count for a subscription. Return 0 if unavailable. 1988 * <p> 1989 * Requires Permission: 1990 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1991 * @param subId whose voice message count is returned 1992 */ 1993 /** {@hide} */ 1994 public int getVoiceMessageCount(int subId) { 1995 try { 1996 return getITelephony().getVoiceMessageCountForSubscriber(subId); 1997 } catch (RemoteException ex) { 1998 return 0; 1999 } catch (NullPointerException ex) { 2000 // This could happen before phone restarts due to crashing 2001 return 0; 2002 } 2003 } 2004 2005 /** 2006 * Retrieves the alphabetic identifier associated with the voice 2007 * mail number. 2008 * <p> 2009 * Requires Permission: 2010 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2011 */ 2012 public String getVoiceMailAlphaTag() { 2013 return getVoiceMailAlphaTag(getDefaultSubscription()); 2014 } 2015 2016 /** 2017 * Retrieves the alphabetic identifier associated with the voice 2018 * mail number for a subscription. 2019 * <p> 2020 * Requires Permission: 2021 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2022 * @param subId whose alphabetic identifier associated with the 2023 * voice mail number is returned 2024 */ 2025 /** {@hide} */ 2026 public String getVoiceMailAlphaTag(int subId) { 2027 try { 2028 return getSubscriberInfo().getVoiceMailAlphaTagForSubscriber(subId); 2029 } catch (RemoteException ex) { 2030 return null; 2031 } catch (NullPointerException ex) { 2032 // This could happen before phone restarts due to crashing 2033 return null; 2034 } 2035 } 2036 2037 /** 2038 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 2039 * @return the IMPI, or null if not present or not loaded 2040 * @hide 2041 */ 2042 public String getIsimImpi() { 2043 try { 2044 return getSubscriberInfo().getIsimImpi(); 2045 } catch (RemoteException ex) { 2046 return null; 2047 } catch (NullPointerException ex) { 2048 // This could happen before phone restarts due to crashing 2049 return null; 2050 } 2051 } 2052 2053 /** 2054 * Returns the IMS home network domain name that was loaded from the ISIM. 2055 * @return the IMS domain name, or null if not present or not loaded 2056 * @hide 2057 */ 2058 public String getIsimDomain() { 2059 try { 2060 return getSubscriberInfo().getIsimDomain(); 2061 } catch (RemoteException ex) { 2062 return null; 2063 } catch (NullPointerException ex) { 2064 // This could happen before phone restarts due to crashing 2065 return null; 2066 } 2067 } 2068 2069 /** 2070 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 2071 * @return an array of IMPU strings, with one IMPU per string, or null if 2072 * not present or not loaded 2073 * @hide 2074 */ 2075 public String[] getIsimImpu() { 2076 try { 2077 return getSubscriberInfo().getIsimImpu(); 2078 } catch (RemoteException ex) { 2079 return null; 2080 } catch (NullPointerException ex) { 2081 // This could happen before phone restarts due to crashing 2082 return null; 2083 } 2084 } 2085 2086 /** 2087 * @hide 2088 */ 2089 private IPhoneSubInfo getSubscriberInfo() { 2090 // get it each time because that process crashes a lot 2091 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 2092 } 2093 2094 /** Device call state: No activity. */ 2095 public static final int CALL_STATE_IDLE = 0; 2096 /** Device call state: Ringing. A new call arrived and is 2097 * ringing or waiting. In the latter case, another call is 2098 * already active. */ 2099 public static final int CALL_STATE_RINGING = 1; 2100 /** Device call state: Off-hook. At least one call exists 2101 * that is dialing, active, or on hold, and no calls are ringing 2102 * or waiting. */ 2103 public static final int CALL_STATE_OFFHOOK = 2; 2104 2105 /** 2106 * Returns a constant indicating the call state (cellular) on the device. 2107 */ 2108 public int getCallState() { 2109 try { 2110 return getTelecomService().getCallState(); 2111 } catch (RemoteException | NullPointerException e) { 2112 return CALL_STATE_IDLE; 2113 } 2114 } 2115 2116 /** 2117 * Returns a constant indicating the call state (cellular) on the device 2118 * for a subscription. 2119 * 2120 * @param subId whose call state is returned 2121 */ 2122 /** {@hide} */ 2123 public int getCallState(int subId) { 2124 try { 2125 return getITelephony().getCallStateForSubscriber(subId); 2126 } catch (RemoteException ex) { 2127 // the phone process is restarting. 2128 return CALL_STATE_IDLE; 2129 } catch (NullPointerException ex) { 2130 // the phone process is restarting. 2131 return CALL_STATE_IDLE; 2132 } 2133 } 2134 2135 /** Data connection activity: No traffic. */ 2136 public static final int DATA_ACTIVITY_NONE = 0x00000000; 2137 /** Data connection activity: Currently receiving IP PPP traffic. */ 2138 public static final int DATA_ACTIVITY_IN = 0x00000001; 2139 /** Data connection activity: Currently sending IP PPP traffic. */ 2140 public static final int DATA_ACTIVITY_OUT = 0x00000002; 2141 /** Data connection activity: Currently both sending and receiving 2142 * IP PPP traffic. */ 2143 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 2144 /** 2145 * Data connection is active, but physical link is down 2146 */ 2147 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 2148 2149 /** 2150 * Returns a constant indicating the type of activity on a data connection 2151 * (cellular). 2152 * 2153 * @see #DATA_ACTIVITY_NONE 2154 * @see #DATA_ACTIVITY_IN 2155 * @see #DATA_ACTIVITY_OUT 2156 * @see #DATA_ACTIVITY_INOUT 2157 * @see #DATA_ACTIVITY_DORMANT 2158 */ 2159 public int getDataActivity() { 2160 try { 2161 return getITelephony().getDataActivity(); 2162 } catch (RemoteException ex) { 2163 // the phone process is restarting. 2164 return DATA_ACTIVITY_NONE; 2165 } catch (NullPointerException ex) { 2166 // the phone process is restarting. 2167 return DATA_ACTIVITY_NONE; 2168 } 2169 } 2170 2171 /** Data connection state: Unknown. Used before we know the state. 2172 * @hide 2173 */ 2174 public static final int DATA_UNKNOWN = -1; 2175 /** Data connection state: Disconnected. IP traffic not available. */ 2176 public static final int DATA_DISCONNECTED = 0; 2177 /** Data connection state: Currently setting up a data connection. */ 2178 public static final int DATA_CONNECTING = 1; 2179 /** Data connection state: Connected. IP traffic should be available. */ 2180 public static final int DATA_CONNECTED = 2; 2181 /** Data connection state: Suspended. The connection is up, but IP 2182 * traffic is temporarily unavailable. For example, in a 2G network, 2183 * data activity may be suspended when a voice call arrives. */ 2184 public static final int DATA_SUSPENDED = 3; 2185 2186 /** 2187 * Returns a constant indicating the current data connection state 2188 * (cellular). 2189 * 2190 * @see #DATA_DISCONNECTED 2191 * @see #DATA_CONNECTING 2192 * @see #DATA_CONNECTED 2193 * @see #DATA_SUSPENDED 2194 */ 2195 public int getDataState() { 2196 try { 2197 return getITelephony().getDataState(); 2198 } catch (RemoteException ex) { 2199 // the phone process is restarting. 2200 return DATA_DISCONNECTED; 2201 } catch (NullPointerException ex) { 2202 return DATA_DISCONNECTED; 2203 } 2204 } 2205 2206 /** 2207 * @hide 2208 */ 2209 private ITelephony getITelephony() { 2210 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 2211 } 2212 2213 /** 2214 * @hide 2215 */ 2216 private ITelecomService getTelecomService() { 2217 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); 2218 } 2219 2220 // 2221 // 2222 // PhoneStateListener 2223 // 2224 // 2225 2226 /** 2227 * Registers a listener object to receive notification of changes 2228 * in specified telephony states. 2229 * <p> 2230 * To register a listener, pass a {@link PhoneStateListener} 2231 * and specify at least one telephony state of interest in 2232 * the events argument. 2233 * 2234 * At registration, and when a specified telephony state 2235 * changes, the telephony manager invokes the appropriate 2236 * callback method on the listener object and passes the 2237 * current (updated) values. 2238 * <p> 2239 * To unregister a listener, pass the listener object and set the 2240 * events argument to 2241 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 2242 * 2243 * @param listener The {@link PhoneStateListener} object to register 2244 * (or unregister) 2245 * @param events The telephony state(s) of interest to the listener, 2246 * as a bitwise-OR combination of {@link PhoneStateListener} 2247 * LISTEN_ flags. 2248 */ 2249 public void listen(PhoneStateListener listener, int events) { 2250 String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>"; 2251 try { 2252 Boolean notifyNow = (getITelephony() != null); 2253 sRegistry.listenForSubscriber(listener.mSubId, pkgForDebug, listener.callback, events, notifyNow); 2254 } catch (RemoteException ex) { 2255 // system process dead 2256 } catch (NullPointerException ex) { 2257 // system process dead 2258 } 2259 } 2260 2261 /** 2262 * Returns the CDMA ERI icon index to display 2263 * 2264 * @hide 2265 */ 2266 public int getCdmaEriIconIndex() { 2267 return getCdmaEriIconIndex(getDefaultSubscription()); 2268 } 2269 2270 /** 2271 * Returns the CDMA ERI icon index to display for a subscription 2272 */ 2273 /** {@hide} */ 2274 public int getCdmaEriIconIndex(int subId) { 2275 try { 2276 return getITelephony().getCdmaEriIconIndexForSubscriber(subId); 2277 } catch (RemoteException ex) { 2278 // the phone process is restarting. 2279 return -1; 2280 } catch (NullPointerException ex) { 2281 return -1; 2282 } 2283 } 2284 2285 /** 2286 * Returns the CDMA ERI icon mode, 2287 * 0 - ON 2288 * 1 - FLASHING 2289 * 2290 * @hide 2291 */ 2292 public int getCdmaEriIconMode() { 2293 return getCdmaEriIconMode(getDefaultSubscription()); 2294 } 2295 2296 /** 2297 * Returns the CDMA ERI icon mode for a subscription. 2298 * 0 - ON 2299 * 1 - FLASHING 2300 */ 2301 /** {@hide} */ 2302 public int getCdmaEriIconMode(int subId) { 2303 try { 2304 return getITelephony().getCdmaEriIconModeForSubscriber(subId); 2305 } catch (RemoteException ex) { 2306 // the phone process is restarting. 2307 return -1; 2308 } catch (NullPointerException ex) { 2309 return -1; 2310 } 2311 } 2312 2313 /** 2314 * Returns the CDMA ERI text, 2315 * 2316 * @hide 2317 */ 2318 public String getCdmaEriText() { 2319 return getCdmaEriText(getDefaultSubscription()); 2320 } 2321 2322 /** 2323 * Returns the CDMA ERI text, of a subscription 2324 * 2325 */ 2326 /** {@hide} */ 2327 public String getCdmaEriText(int subId) { 2328 try { 2329 return getITelephony().getCdmaEriTextForSubscriber(subId); 2330 } catch (RemoteException ex) { 2331 // the phone process is restarting. 2332 return null; 2333 } catch (NullPointerException ex) { 2334 return null; 2335 } 2336 } 2337 2338 /** 2339 * @return true if the current device is "voice capable". 2340 * <p> 2341 * "Voice capable" means that this device supports circuit-switched 2342 * (i.e. voice) phone calls over the telephony network, and is allowed 2343 * to display the in-call UI while a cellular voice call is active. 2344 * This will be false on "data only" devices which can't make voice 2345 * calls and don't support any in-call UI. 2346 * <p> 2347 * Note: the meaning of this flag is subtly different from the 2348 * PackageManager.FEATURE_TELEPHONY system feature, which is available 2349 * on any device with a telephony radio, even if the device is 2350 * data-only. 2351 * 2352 * @hide pending API review 2353 */ 2354 public boolean isVoiceCapable() { 2355 if (mContext == null) return true; 2356 return mContext.getResources().getBoolean( 2357 com.android.internal.R.bool.config_voice_capable); 2358 } 2359 2360 /** 2361 * @return true if the current device supports sms service. 2362 * <p> 2363 * If true, this means that the device supports both sending and 2364 * receiving sms via the telephony network. 2365 * <p> 2366 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 2367 * disabled when device doesn't support sms. 2368 */ 2369 public boolean isSmsCapable() { 2370 if (mContext == null) return true; 2371 return mContext.getResources().getBoolean( 2372 com.android.internal.R.bool.config_sms_capable); 2373 } 2374 2375 /** 2376 * Returns all observed cell information from all radios on the 2377 * device including the primary and neighboring cells. This does 2378 * not cause or change the rate of PhoneStateListner#onCellInfoChanged. 2379 *<p> 2380 * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm}, 2381 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 2382 * {@link android.telephony.CellInfoLte CellInfoLte} and 2383 * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination. 2384 * Specifically on devices with multiple radios it is typical to see instances of 2385 * one or more of any these in the list. In addition 0, 1 or more CellInfo 2386 * objects may return isRegistered() true. 2387 *<p> 2388 * This is preferred over using getCellLocation although for older 2389 * devices this may return null in which case getCellLocation should 2390 * be called. 2391 *<p> 2392 * @return List of CellInfo or null if info unavailable. 2393 * 2394 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 2395 */ 2396 public List<CellInfo> getAllCellInfo() { 2397 try { 2398 return getITelephony().getAllCellInfo(); 2399 } catch (RemoteException ex) { 2400 return null; 2401 } catch (NullPointerException ex) { 2402 return null; 2403 } 2404 } 2405 2406 /** 2407 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 2408 * PhoneStateListener.onCellInfoChanged} will be invoked. 2409 *<p> 2410 * The default, 0, means invoke onCellInfoChanged when any of the reported 2411 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 2412 * A onCellInfoChanged. 2413 *<p> 2414 * @param rateInMillis the rate 2415 * 2416 * @hide 2417 */ 2418 public void setCellInfoListRate(int rateInMillis) { 2419 try { 2420 getITelephony().setCellInfoListRate(rateInMillis); 2421 } catch (RemoteException ex) { 2422 } catch (NullPointerException ex) { 2423 } 2424 } 2425 2426 /** 2427 * Returns the MMS user agent. 2428 */ 2429 public String getMmsUserAgent() { 2430 if (mContext == null) return null; 2431 return mContext.getResources().getString( 2432 com.android.internal.R.string.config_mms_user_agent); 2433 } 2434 2435 /** 2436 * Returns the MMS user agent profile URL. 2437 */ 2438 public String getMmsUAProfUrl() { 2439 if (mContext == null) return null; 2440 return mContext.getResources().getString( 2441 com.android.internal.R.string.config_mms_user_agent_profile_url); 2442 } 2443 2444 /** 2445 * Opens a logical channel to the ICC card. 2446 * 2447 * Input parameters equivalent to TS 27.007 AT+CCHO command. 2448 * 2449 * <p>Requires Permission: 2450 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2451 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2452 * 2453 * @param AID Application id. See ETSI 102.221 and 101.220. 2454 * @return an IccOpenLogicalChannelResponse object. 2455 */ 2456 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { 2457 try { 2458 return getITelephony().iccOpenLogicalChannel(AID); 2459 } catch (RemoteException ex) { 2460 } catch (NullPointerException ex) { 2461 } 2462 return null; 2463 } 2464 2465 /** 2466 * Closes a previously opened logical channel to the ICC card. 2467 * 2468 * Input parameters equivalent to TS 27.007 AT+CCHC command. 2469 * 2470 * <p>Requires Permission: 2471 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2472 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2473 * 2474 * @param channel is the channel id to be closed as retruned by a successful 2475 * iccOpenLogicalChannel. 2476 * @return true if the channel was closed successfully. 2477 */ 2478 public boolean iccCloseLogicalChannel(int channel) { 2479 try { 2480 return getITelephony().iccCloseLogicalChannel(channel); 2481 } catch (RemoteException ex) { 2482 } catch (NullPointerException ex) { 2483 } 2484 return false; 2485 } 2486 2487 /** 2488 * Transmit an APDU to the ICC card over a logical channel. 2489 * 2490 * Input parameters equivalent to TS 27.007 AT+CGLA command. 2491 * 2492 * <p>Requires Permission: 2493 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2494 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2495 * 2496 * @param channel is the channel id to be closed as returned by a successful 2497 * iccOpenLogicalChannel. 2498 * @param cla Class of the APDU command. 2499 * @param instruction Instruction of the APDU command. 2500 * @param p1 P1 value of the APDU command. 2501 * @param p2 P2 value of the APDU command. 2502 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2503 * is sent to the SIM. 2504 * @param data Data to be sent with the APDU. 2505 * @return The APDU response from the ICC card with the status appended at 2506 * the end. 2507 */ 2508 public String iccTransmitApduLogicalChannel(int channel, int cla, 2509 int instruction, int p1, int p2, int p3, String data) { 2510 try { 2511 return getITelephony().iccTransmitApduLogicalChannel(channel, cla, 2512 instruction, p1, p2, p3, data); 2513 } catch (RemoteException ex) { 2514 } catch (NullPointerException ex) { 2515 } 2516 return ""; 2517 } 2518 2519 /** 2520 * Transmit an APDU to the ICC card over the basic channel. 2521 * 2522 * Input parameters equivalent to TS 27.007 AT+CSIM command. 2523 * 2524 * <p>Requires Permission: 2525 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2526 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2527 * 2528 * @param cla Class of the APDU command. 2529 * @param instruction Instruction of the APDU command. 2530 * @param p1 P1 value of the APDU command. 2531 * @param p2 P2 value of the APDU command. 2532 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2533 * is sent to the SIM. 2534 * @param data Data to be sent with the APDU. 2535 * @return The APDU response from the ICC card with the status appended at 2536 * the end. 2537 */ 2538 public String iccTransmitApduBasicChannel(int cla, 2539 int instruction, int p1, int p2, int p3, String data) { 2540 try { 2541 return getITelephony().iccTransmitApduBasicChannel(cla, 2542 instruction, p1, p2, p3, data); 2543 } catch (RemoteException ex) { 2544 } catch (NullPointerException ex) { 2545 } 2546 return ""; 2547 } 2548 2549 /** 2550 * Returns the response APDU for a command APDU sent through SIM_IO. 2551 * 2552 * <p>Requires Permission: 2553 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2554 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2555 * 2556 * @param fileID 2557 * @param command 2558 * @param p1 P1 value of the APDU command. 2559 * @param p2 P2 value of the APDU command. 2560 * @param p3 P3 value of the APDU command. 2561 * @param filePath 2562 * @return The APDU response. 2563 */ 2564 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 2565 String filePath) { 2566 try { 2567 return getITelephony().iccExchangeSimIO(fileID, command, p1, p2, 2568 p3, filePath); 2569 } catch (RemoteException ex) { 2570 } catch (NullPointerException ex) { 2571 } 2572 return null; 2573 } 2574 2575 /** 2576 * Send ENVELOPE to the SIM and return the response. 2577 * 2578 * <p>Requires Permission: 2579 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2580 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2581 * 2582 * @param content String containing SAT/USAT response in hexadecimal 2583 * format starting with command tag. See TS 102 223 for 2584 * details. 2585 * @return The APDU response from the ICC card in hexadecimal format 2586 * with the last 4 bytes being the status word. If the command fails, 2587 * returns an empty string. 2588 */ 2589 public String sendEnvelopeWithStatus(String content) { 2590 try { 2591 return getITelephony().sendEnvelopeWithStatus(content); 2592 } catch (RemoteException ex) { 2593 } catch (NullPointerException ex) { 2594 } 2595 return ""; 2596 } 2597 2598 /** 2599 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 2600 * Used for device configuration by some CDMA operators. 2601 * <p> 2602 * Requires Permission: 2603 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2604 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2605 * 2606 * @param itemID the ID of the item to read. 2607 * @return the NV item as a String, or null on any failure. 2608 * 2609 * @hide 2610 */ 2611 public String nvReadItem(int itemID) { 2612 try { 2613 return getITelephony().nvReadItem(itemID); 2614 } catch (RemoteException ex) { 2615 Rlog.e(TAG, "nvReadItem RemoteException", ex); 2616 } catch (NullPointerException ex) { 2617 Rlog.e(TAG, "nvReadItem NPE", ex); 2618 } 2619 return ""; 2620 } 2621 2622 /** 2623 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 2624 * Used for device configuration by some CDMA operators. 2625 * <p> 2626 * Requires Permission: 2627 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2628 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2629 * 2630 * @param itemID the ID of the item to read. 2631 * @param itemValue the value to write, as a String. 2632 * @return true on success; false on any failure. 2633 * 2634 * @hide 2635 */ 2636 public boolean nvWriteItem(int itemID, String itemValue) { 2637 try { 2638 return getITelephony().nvWriteItem(itemID, itemValue); 2639 } catch (RemoteException ex) { 2640 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 2641 } catch (NullPointerException ex) { 2642 Rlog.e(TAG, "nvWriteItem NPE", ex); 2643 } 2644 return false; 2645 } 2646 2647 /** 2648 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 2649 * Used for device configuration by some CDMA operators. 2650 * <p> 2651 * Requires Permission: 2652 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2653 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2654 * 2655 * @param preferredRoamingList byte array containing the new PRL. 2656 * @return true on success; false on any failure. 2657 * 2658 * @hide 2659 */ 2660 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 2661 try { 2662 return getITelephony().nvWriteCdmaPrl(preferredRoamingList); 2663 } catch (RemoteException ex) { 2664 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 2665 } catch (NullPointerException ex) { 2666 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 2667 } 2668 return false; 2669 } 2670 2671 /** 2672 * Perform the specified type of NV config reset. The radio will be taken offline 2673 * and the device must be rebooted after the operation. Used for device 2674 * configuration by some CDMA operators. 2675 * <p> 2676 * Requires Permission: 2677 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2678 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2679 * 2680 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 2681 * @return true on success; false on any failure. 2682 * 2683 * @hide 2684 */ 2685 public boolean nvResetConfig(int resetType) { 2686 try { 2687 return getITelephony().nvResetConfig(resetType); 2688 } catch (RemoteException ex) { 2689 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 2690 } catch (NullPointerException ex) { 2691 Rlog.e(TAG, "nvResetConfig NPE", ex); 2692 } 2693 return false; 2694 } 2695 2696 /** 2697 * Returns Default subscription. 2698 */ 2699 private static int getDefaultSubscription() { 2700 return SubscriptionManager.getDefaultSubId(); 2701 } 2702 2703 /** 2704 * Returns Default phone. 2705 */ 2706 private static int getDefaultPhone() { 2707 return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubId()); 2708 } 2709 2710 /** {@hide} */ 2711 public int getDefaultSim() { 2712 return SubscriptionManager.getSlotId(SubscriptionManager.getDefaultSubId()); 2713 } 2714 2715 /** 2716 * Sets the telephony property with the value specified. 2717 * 2718 * @hide 2719 */ 2720 public static void setTelephonyProperty(int phoneId, String property, String value) { 2721 Rlog.d(TAG, "setTelephonyProperty property: " + property + " phoneId: " + phoneId + 2722 " value: " + value); 2723 String propVal = ""; 2724 String p[] = null; 2725 String prop = SystemProperties.get(property); 2726 2727 if (value == null) { 2728 value = ""; 2729 } 2730 2731 if (prop != null) { 2732 p = prop.split(","); 2733 } 2734 2735 if (!SubscriptionManager.isValidPhoneId(phoneId)) { 2736 Rlog.d(TAG, "setTelephonyProperty invalid phone id"); 2737 return; 2738 } 2739 2740 for (int i = 0; i < phoneId; i++) { 2741 String str = ""; 2742 if ((p != null) && (i < p.length)) { 2743 str = p[i]; 2744 } 2745 propVal = propVal + str + ","; 2746 } 2747 2748 propVal = propVal + value; 2749 if (p != null) { 2750 for (int i = phoneId + 1; i < p.length; i++) { 2751 propVal = propVal + "," + p[i]; 2752 } 2753 } 2754 2755 // TODO: workaround for QC 2756 if (property.length() > SystemProperties.PROP_NAME_MAX || propVal.length() > SystemProperties.PROP_VALUE_MAX) { 2757 Rlog.d(TAG, "setTelephonyProperty length too long:" + property + ", " + propVal); 2758 return; 2759 } 2760 2761 Rlog.d(TAG, "setTelephonyProperty property=" + property + " propVal=" + propVal); 2762 SystemProperties.set(property, propVal); 2763 } 2764 2765 /** 2766 * Convenience function for retrieving a value from the secure settings 2767 * value list as an integer. Note that internally setting values are 2768 * always stored as strings; this function converts the string to an 2769 * integer for you. 2770 * <p> 2771 * This version does not take a default value. If the setting has not 2772 * been set, or the string value is not a number, 2773 * it throws {@link SettingNotFoundException}. 2774 * 2775 * @param cr The ContentResolver to access. 2776 * @param name The name of the setting to retrieve. 2777 * @param index The index of the list 2778 * 2779 * @throws SettingNotFoundException Thrown if a setting by the given 2780 * name can't be found or the setting value is not an integer. 2781 * 2782 * @return The value at the given index of settings. 2783 * @hide 2784 */ 2785 public static int getIntAtIndex(android.content.ContentResolver cr, 2786 String name, int index) 2787 throws android.provider.Settings.SettingNotFoundException { 2788 String v = android.provider.Settings.Global.getString(cr, name); 2789 if (v != null) { 2790 String valArray[] = v.split(","); 2791 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 2792 try { 2793 return Integer.parseInt(valArray[index]); 2794 } catch (NumberFormatException e) { 2795 //Log.e(TAG, "Exception while parsing Integer: ", e); 2796 } 2797 } 2798 } 2799 throw new android.provider.Settings.SettingNotFoundException(name); 2800 } 2801 2802 /** 2803 * Convenience function for updating settings value as coma separated 2804 * integer values. This will either create a new entry in the table if the 2805 * given name does not exist, or modify the value of the existing row 2806 * with that name. Note that internally setting values are always 2807 * stored as strings, so this function converts the given value to a 2808 * string before storing it. 2809 * 2810 * @param cr The ContentResolver to access. 2811 * @param name The name of the setting to modify. 2812 * @param index The index of the list 2813 * @param value The new value for the setting to be added to the list. 2814 * @return true if the value was set, false on database errors 2815 * @hide 2816 */ 2817 public static boolean putIntAtIndex(android.content.ContentResolver cr, 2818 String name, int index, int value) { 2819 String data = ""; 2820 String valArray[] = null; 2821 String v = android.provider.Settings.Global.getString(cr, name); 2822 2823 if (index == Integer.MAX_VALUE) { 2824 throw new RuntimeException("putIntAtIndex index == MAX_VALUE index=" + index); 2825 } 2826 if (index < 0) { 2827 throw new RuntimeException("putIntAtIndex index < 0 index=" + index); 2828 } 2829 if (v != null) { 2830 valArray = v.split(","); 2831 } 2832 2833 // Copy the elements from valArray till index 2834 for (int i = 0; i < index; i++) { 2835 String str = ""; 2836 if ((valArray != null) && (i < valArray.length)) { 2837 str = valArray[i]; 2838 } 2839 data = data + str + ","; 2840 } 2841 2842 data = data + value; 2843 2844 // Copy the remaining elements from valArray if any. 2845 if (valArray != null) { 2846 for (int i = index+1; i < valArray.length; i++) { 2847 data = data + "," + valArray[i]; 2848 } 2849 } 2850 return android.provider.Settings.Global.putString(cr, name, data); 2851 } 2852 2853 /** 2854 * Gets the telephony property. 2855 * 2856 * @hide 2857 */ 2858 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 2859 String propVal = null; 2860 String prop = SystemProperties.get(property); 2861 if ((prop != null) && (prop.length() > 0)) { 2862 String values[] = prop.split(","); 2863 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 2864 propVal = values[phoneId]; 2865 } 2866 } 2867 return propVal == null ? defaultVal : propVal; 2868 } 2869 2870 /** @hide */ 2871 public int getSimCount() { 2872 if(isMultiSimEnabled()) { 2873 //FIXME Need to get it from Telephony Devcontroller 2874 return 2; 2875 } else { 2876 return 1; 2877 } 2878 } 2879 2880 /** 2881 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 2882 * @return IMS Service Table or null if not present or not loaded 2883 * @hide 2884 */ 2885 public String getIsimIst() { 2886 try { 2887 return getSubscriberInfo().getIsimIst(); 2888 } catch (RemoteException ex) { 2889 return null; 2890 } catch (NullPointerException ex) { 2891 // This could happen before phone restarts due to crashing 2892 return null; 2893 } 2894 } 2895 2896 /** 2897 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 2898 * @return an array of PCSCF strings with one PCSCF per string, or null if 2899 * not present or not loaded 2900 * @hide 2901 */ 2902 public String[] getIsimPcscf() { 2903 try { 2904 return getSubscriberInfo().getIsimPcscf(); 2905 } catch (RemoteException ex) { 2906 return null; 2907 } catch (NullPointerException ex) { 2908 // This could happen before phone restarts due to crashing 2909 return null; 2910 } 2911 } 2912 2913 /** 2914 * Returns the response of ISIM Authetification through RIL. 2915 * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo. 2916 * @return the response of ISIM Authetification, or null if not available 2917 * @hide 2918 * @deprecated 2919 * @see getIccSimChallengeResponse with appType=PhoneConstants.APPTYPE_ISIM 2920 */ 2921 public String getIsimChallengeResponse(String nonce){ 2922 try { 2923 return getSubscriberInfo().getIsimChallengeResponse(nonce); 2924 } catch (RemoteException ex) { 2925 return null; 2926 } catch (NullPointerException ex) { 2927 // This could happen before phone restarts due to crashing 2928 return null; 2929 } 2930 } 2931 2932 /** 2933 * Returns the response of SIM Authentication through RIL. 2934 * Returns null if the Authentication hasn't been successful 2935 * @param subId subscription ID to be queried 2936 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 2937 * @param data authentication challenge data 2938 * @return the response of SIM Authentication, or null if not available 2939 * @hide 2940 */ 2941 public String getIccSimChallengeResponse(int subId, int appType, String data) { 2942 try { 2943 return getSubscriberInfo().getIccSimChallengeResponse(subId, appType, data); 2944 } catch (RemoteException ex) { 2945 return null; 2946 } catch (NullPointerException ex) { 2947 // This could happen before phone starts 2948 return null; 2949 } 2950 } 2951 2952 /** 2953 * Returns the response of SIM Authentication through RIL for the default subscription. 2954 * Returns null if the Authentication hasn't been successful 2955 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 2956 * @param data authentication challenge data 2957 * @return the response of SIM Authentication, or null if not available 2958 * @hide 2959 */ 2960 public String getIccSimChallengeResponse(int appType, String data) { 2961 return getIccSimChallengeResponse(getDefaultSubscription(), appType, data); 2962 } 2963 2964 /** 2965 * Get P-CSCF address from PCO after data connection is established or modified. 2966 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 2967 * @return array of P-CSCF address 2968 * @hide 2969 */ 2970 public String[] getPcscfAddress(String apnType) { 2971 try { 2972 return getITelephony().getPcscfAddress(apnType); 2973 } catch (RemoteException e) { 2974 return new String[0]; 2975 } 2976 } 2977 2978 /** 2979 * Set IMS registration state 2980 * 2981 * @param Registration state 2982 * @hide 2983 */ 2984 public void setImsRegistrationState(boolean registered) { 2985 try { 2986 getITelephony().setImsRegistrationState(registered); 2987 } catch (RemoteException e) { 2988 } 2989 } 2990 2991 /** 2992 * Get the preferred network type. 2993 * Used for device configuration by some CDMA operators. 2994 * <p> 2995 * Requires Permission: 2996 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2997 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2998 * 2999 * @return the preferred network type, defined in RILConstants.java. 3000 * @hide 3001 */ 3002 public int getPreferredNetworkType() { 3003 try { 3004 return getITelephony().getPreferredNetworkType(); 3005 } catch (RemoteException ex) { 3006 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 3007 } catch (NullPointerException ex) { 3008 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 3009 } 3010 return -1; 3011 } 3012 3013 /** 3014 * Set the preferred network type. 3015 * Used for device configuration by some CDMA operators. 3016 * <p> 3017 * Requires Permission: 3018 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3019 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3020 * 3021 * @param networkType the preferred network type, defined in RILConstants.java. 3022 * @return true on success; false on any failure. 3023 * @hide 3024 */ 3025 public boolean setPreferredNetworkType(int networkType) { 3026 try { 3027 return getITelephony().setPreferredNetworkType(networkType); 3028 } catch (RemoteException ex) { 3029 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 3030 } catch (NullPointerException ex) { 3031 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 3032 } 3033 return false; 3034 } 3035 3036 /** 3037 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 3038 * 3039 * <p> 3040 * Requires Permission: 3041 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3042 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3043 * 3044 * @return true on success; false on any failure. 3045 */ 3046 public boolean setGlobalPreferredNetworkType() { 3047 return setPreferredNetworkType(RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); 3048 } 3049 3050 /** 3051 * Values used to return status for hasCarrierPrivileges call. 3052 */ 3053 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 3054 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 3055 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 3056 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 3057 3058 /** 3059 * Has the calling application been granted carrier privileges by the carrier. 3060 * 3061 * If any of the packages in the calling UID has carrier privileges, the 3062 * call will return true. This access is granted by the owner of the UICC 3063 * card and does not depend on the registered carrier. 3064 * 3065 * TODO: Add a link to documentation. 3066 * 3067 * @return CARRIER_PRIVILEGE_STATUS_HAS_ACCESS if the app has carrier privileges. 3068 * CARRIER_PRIVILEGE_STATUS_NO_ACCESS if the app does not have carrier privileges. 3069 * CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED if the carrier rules are not loaded. 3070 * CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES if there was an error loading carrier 3071 * rules (or if there are no rules). 3072 */ 3073 public int hasCarrierPrivileges() { 3074 try { 3075 return getITelephony().hasCarrierPrivileges(); 3076 } catch (RemoteException ex) { 3077 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3078 } catch (NullPointerException ex) { 3079 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3080 } 3081 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3082 } 3083 3084 /** 3085 * Override the branding for the current ICCID. 3086 * 3087 * Once set, whenever the SIM is present in the device, the service 3088 * provider name (SPN) and the operator name will both be replaced by the 3089 * brand value input. To unset the value, the same function should be 3090 * called with a null brand value. 3091 * 3092 * <p>Requires Permission: 3093 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3094 * or has to be carrier app - see #hasCarrierPrivileges. 3095 * 3096 * @param brand The brand name to display/set. 3097 * @return true if the operation was executed correctly. 3098 */ 3099 public boolean setOperatorBrandOverride(String brand) { 3100 try { 3101 return getITelephony().setOperatorBrandOverride(brand); 3102 } catch (RemoteException ex) { 3103 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 3104 } catch (NullPointerException ex) { 3105 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 3106 } 3107 return false; 3108 } 3109 3110 /** 3111 * Expose the rest of ITelephony to @SystemApi 3112 */ 3113 3114 /** @hide */ 3115 @SystemApi 3116 public String getCdmaMdn() { 3117 return getCdmaMdn(getDefaultSubscription()); 3118 } 3119 3120 /** @hide */ 3121 @SystemApi 3122 public String getCdmaMdn(int subId) { 3123 try { 3124 return getITelephony().getCdmaMdn(subId); 3125 } catch (RemoteException ex) { 3126 return null; 3127 } catch (NullPointerException ex) { 3128 return null; 3129 } 3130 } 3131 3132 /** @hide */ 3133 @SystemApi 3134 public String getCdmaMin() { 3135 return getCdmaMin(getDefaultSubscription()); 3136 } 3137 3138 /** @hide */ 3139 @SystemApi 3140 public String getCdmaMin(int subId) { 3141 try { 3142 return getITelephony().getCdmaMin(subId); 3143 } catch (RemoteException ex) { 3144 return null; 3145 } catch (NullPointerException ex) { 3146 return null; 3147 } 3148 } 3149 3150 /** @hide */ 3151 @SystemApi 3152 public int checkCarrierPrivilegesForPackage(String pkgname) { 3153 try { 3154 return getITelephony().checkCarrierPrivilegesForPackage(pkgname); 3155 } catch (RemoteException ex) { 3156 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3157 } catch (NullPointerException ex) { 3158 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3159 } 3160 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3161 } 3162 3163 /** @hide */ 3164 @SystemApi 3165 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 3166 try { 3167 return getITelephony().getCarrierPackageNamesForIntent(intent); 3168 } catch (RemoteException ex) { 3169 Rlog.e(TAG, "getCarrierPackageNamesForIntent RemoteException", ex); 3170 } catch (NullPointerException ex) { 3171 Rlog.e(TAG, "getCarrierPackageNamesForIntent NPE", ex); 3172 } 3173 return null; 3174 } 3175 3176 /** @hide */ 3177 @SystemApi 3178 public void dial(String number) { 3179 try { 3180 getITelephony().dial(number); 3181 } catch (RemoteException e) { 3182 Log.e(TAG, "Error calling ITelephony#dial", e); 3183 } 3184 } 3185 3186 /** @hide */ 3187 @SystemApi 3188 public void call(String callingPackage, String number) { 3189 try { 3190 getITelephony().call(callingPackage, number); 3191 } catch (RemoteException e) { 3192 Log.e(TAG, "Error calling ITelephony#call", e); 3193 } 3194 } 3195 3196 /** @hide */ 3197 @SystemApi 3198 public boolean endCall() { 3199 try { 3200 return getITelephony().endCall(); 3201 } catch (RemoteException e) { 3202 Log.e(TAG, "Error calling ITelephony#endCall", e); 3203 } 3204 return false; 3205 } 3206 3207 /** @hide */ 3208 @SystemApi 3209 public void answerRingingCall() { 3210 try { 3211 getITelephony().answerRingingCall(); 3212 } catch (RemoteException e) { 3213 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 3214 } 3215 } 3216 3217 /** @hide */ 3218 @SystemApi 3219 public void silenceRinger() { 3220 try { 3221 getTelecomService().silenceRinger(); 3222 } catch (RemoteException e) { 3223 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); 3224 } 3225 } 3226 3227 /** @hide */ 3228 @SystemApi 3229 public boolean isOffhook() { 3230 try { 3231 return getITelephony().isOffhook(); 3232 } catch (RemoteException e) { 3233 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 3234 } 3235 return false; 3236 } 3237 3238 /** @hide */ 3239 @SystemApi 3240 public boolean isRinging() { 3241 try { 3242 return getITelephony().isRinging(); 3243 } catch (RemoteException e) { 3244 Log.e(TAG, "Error calling ITelephony#isRinging", e); 3245 } 3246 return false; 3247 } 3248 3249 /** @hide */ 3250 @SystemApi 3251 public boolean isIdle() { 3252 try { 3253 return getITelephony().isIdle(); 3254 } catch (RemoteException e) { 3255 Log.e(TAG, "Error calling ITelephony#isIdle", e); 3256 } 3257 return true; 3258 } 3259 3260 /** @hide */ 3261 @SystemApi 3262 public boolean isRadioOn() { 3263 try { 3264 return getITelephony().isRadioOn(); 3265 } catch (RemoteException e) { 3266 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 3267 } 3268 return false; 3269 } 3270 3271 /** @hide */ 3272 @SystemApi 3273 public boolean isSimPinEnabled() { 3274 try { 3275 return getITelephony().isSimPinEnabled(); 3276 } catch (RemoteException e) { 3277 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 3278 } 3279 return false; 3280 } 3281 3282 /** @hide */ 3283 @SystemApi 3284 public boolean supplyPin(String pin) { 3285 try { 3286 return getITelephony().supplyPin(pin); 3287 } catch (RemoteException e) { 3288 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 3289 } 3290 return false; 3291 } 3292 3293 /** @hide */ 3294 @SystemApi 3295 public boolean supplyPuk(String puk, String pin) { 3296 try { 3297 return getITelephony().supplyPuk(puk, pin); 3298 } catch (RemoteException e) { 3299 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 3300 } 3301 return false; 3302 } 3303 3304 /** @hide */ 3305 @SystemApi 3306 public int[] supplyPinReportResult(String pin) { 3307 try { 3308 return getITelephony().supplyPinReportResult(pin); 3309 } catch (RemoteException e) { 3310 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 3311 } 3312 return new int[0]; 3313 } 3314 3315 /** @hide */ 3316 @SystemApi 3317 public int[] supplyPukReportResult(String puk, String pin) { 3318 try { 3319 return getITelephony().supplyPukReportResult(puk, pin); 3320 } catch (RemoteException e) { 3321 Log.e(TAG, "Error calling ITelephony#]", e); 3322 } 3323 return new int[0]; 3324 } 3325 3326 /** @hide */ 3327 @SystemApi 3328 public boolean handlePinMmi(String dialString) { 3329 try { 3330 return getITelephony().handlePinMmi(dialString); 3331 } catch (RemoteException e) { 3332 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3333 } 3334 return false; 3335 } 3336 3337 /** @hide */ 3338 @SystemApi 3339 public void toggleRadioOnOff() { 3340 try { 3341 getITelephony().toggleRadioOnOff(); 3342 } catch (RemoteException e) { 3343 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 3344 } 3345 } 3346 3347 /** @hide */ 3348 @SystemApi 3349 public boolean setRadio(boolean turnOn) { 3350 try { 3351 return getITelephony().setRadio(turnOn); 3352 } catch (RemoteException e) { 3353 Log.e(TAG, "Error calling ITelephony#setRadio", e); 3354 } 3355 return false; 3356 } 3357 3358 /** @hide */ 3359 @SystemApi 3360 public boolean setRadioPower(boolean turnOn) { 3361 try { 3362 return getITelephony().setRadioPower(turnOn); 3363 } catch (RemoteException e) { 3364 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 3365 } 3366 return false; 3367 } 3368 3369 /** @hide */ 3370 @SystemApi 3371 public void updateServiceLocation() { 3372 try { 3373 getITelephony().updateServiceLocation(); 3374 } catch (RemoteException e) { 3375 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 3376 } 3377 } 3378 3379 /** @hide */ 3380 @SystemApi 3381 public boolean enableDataConnectivity() { 3382 try { 3383 return getITelephony().enableDataConnectivity(); 3384 } catch (RemoteException e) { 3385 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 3386 } 3387 return false; 3388 } 3389 3390 /** @hide */ 3391 @SystemApi 3392 public boolean disableDataConnectivity() { 3393 try { 3394 return getITelephony().disableDataConnectivity(); 3395 } catch (RemoteException e) { 3396 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 3397 } 3398 return false; 3399 } 3400 3401 /** @hide */ 3402 @SystemApi 3403 public boolean isDataConnectivityPossible() { 3404 try { 3405 return getITelephony().isDataConnectivityPossible(); 3406 } catch (RemoteException e) { 3407 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 3408 } 3409 return false; 3410 } 3411 3412 /** @hide */ 3413 @SystemApi 3414 public boolean needsOtaServiceProvisioning() { 3415 try { 3416 return getITelephony().needsOtaServiceProvisioning(); 3417 } catch (RemoteException e) { 3418 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 3419 } 3420 return false; 3421 } 3422 3423 /** @hide */ 3424 @SystemApi 3425 public void setDataEnabled(boolean enable) { 3426 try { 3427 getITelephony().setDataEnabled(enable); 3428 } catch (RemoteException e) { 3429 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 3430 } 3431 } 3432 3433 /** @hide */ 3434 @SystemApi 3435 public boolean getDataEnabled() { 3436 try { 3437 return getITelephony().getDataEnabled(); 3438 } catch (RemoteException e) { 3439 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 3440 } 3441 return false; 3442 } 3443 3444 /** 3445 * Returns the result and response from RIL for oem request 3446 * 3447 * @param oemReq the data is sent to ril. 3448 * @param oemResp the respose data from RIL. 3449 * @return negative value request was not handled or get error 3450 * 0 request was handled succesfully, but no response data 3451 * positive value success, data length of response 3452 * @hide 3453 */ 3454 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 3455 try { 3456 return getITelephony().invokeOemRilRequestRaw(oemReq, oemResp); 3457 } catch (RemoteException ex) { 3458 } catch (NullPointerException ex) { 3459 } 3460 return -1; 3461 } 3462 3463 /** @hide */ 3464 @SystemApi 3465 public void enableVideoCalling(boolean enable) { 3466 try { 3467 getITelephony().enableVideoCalling(enable); 3468 } catch (RemoteException e) { 3469 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 3470 } 3471 } 3472 3473 /** @hide */ 3474 @SystemApi 3475 public boolean isVideoCallingEnabled() { 3476 try { 3477 return getITelephony().isVideoCallingEnabled(); 3478 } catch (RemoteException e) { 3479 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 3480 } 3481 return false; 3482 } 3483} 3484