TelephonyManager.java revision 2d1ee982276f5dbd0e035778b731b48e4ef34515
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 * Sets the voice mail number. 1977 * <p> 1978 * Requires Permission: 1979 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 1980 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 1981 * 1982 * @param alphaTag The alpha tag to display. 1983 * @param number The voicemail number. 1984 */ 1985 public boolean setVoiceMailNumber(String alphaTag, String number) { 1986 return setVoiceMailNumber(getDefaultSubscription(), alphaTag, number); 1987 } 1988 1989 /** 1990 * Sets the voicemail number for the given subscriber. 1991 * <p> 1992 * Requires Permission: 1993 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 1994 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 1995 * 1996 * @param subId The subscriber id. 1997 * @param alphaTag The alpha tag to display. 1998 * @param number The voicemail number. 1999 */ 2000 /** {@hide} */ 2001 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { 2002 try { 2003 return getITelephony().setVoiceMailNumber(subId, alphaTag, number); 2004 } catch (RemoteException ex) { 2005 } catch (NullPointerException ex) { 2006 } 2007 return false; 2008 } 2009 2010 /** 2011 * Returns the voice mail count. Return 0 if unavailable. 2012 * <p> 2013 * Requires Permission: 2014 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2015 * @hide 2016 */ 2017 public int getVoiceMessageCount() { 2018 return getVoiceMessageCount(getDefaultSubscription()); 2019 } 2020 2021 /** 2022 * Returns the voice mail count for a subscription. Return 0 if unavailable. 2023 * <p> 2024 * Requires Permission: 2025 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2026 * @param subId whose voice message count is returned 2027 */ 2028 /** {@hide} */ 2029 public int getVoiceMessageCount(int subId) { 2030 try { 2031 return getITelephony().getVoiceMessageCountForSubscriber(subId); 2032 } catch (RemoteException ex) { 2033 return 0; 2034 } catch (NullPointerException ex) { 2035 // This could happen before phone restarts due to crashing 2036 return 0; 2037 } 2038 } 2039 2040 /** 2041 * Retrieves the alphabetic identifier associated with the voice 2042 * mail number. 2043 * <p> 2044 * Requires Permission: 2045 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2046 */ 2047 public String getVoiceMailAlphaTag() { 2048 return getVoiceMailAlphaTag(getDefaultSubscription()); 2049 } 2050 2051 /** 2052 * Retrieves the alphabetic identifier associated with the voice 2053 * mail number for a subscription. 2054 * <p> 2055 * Requires Permission: 2056 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2057 * @param subId whose alphabetic identifier associated with the 2058 * voice mail number is returned 2059 */ 2060 /** {@hide} */ 2061 public String getVoiceMailAlphaTag(int subId) { 2062 try { 2063 return getSubscriberInfo().getVoiceMailAlphaTagForSubscriber(subId); 2064 } catch (RemoteException ex) { 2065 return null; 2066 } catch (NullPointerException ex) { 2067 // This could happen before phone restarts due to crashing 2068 return null; 2069 } 2070 } 2071 2072 /** 2073 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 2074 * @return the IMPI, or null if not present or not loaded 2075 * @hide 2076 */ 2077 public String getIsimImpi() { 2078 try { 2079 return getSubscriberInfo().getIsimImpi(); 2080 } catch (RemoteException ex) { 2081 return null; 2082 } catch (NullPointerException ex) { 2083 // This could happen before phone restarts due to crashing 2084 return null; 2085 } 2086 } 2087 2088 /** 2089 * Returns the IMS home network domain name that was loaded from the ISIM. 2090 * @return the IMS domain name, or null if not present or not loaded 2091 * @hide 2092 */ 2093 public String getIsimDomain() { 2094 try { 2095 return getSubscriberInfo().getIsimDomain(); 2096 } catch (RemoteException ex) { 2097 return null; 2098 } catch (NullPointerException ex) { 2099 // This could happen before phone restarts due to crashing 2100 return null; 2101 } 2102 } 2103 2104 /** 2105 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 2106 * @return an array of IMPU strings, with one IMPU per string, or null if 2107 * not present or not loaded 2108 * @hide 2109 */ 2110 public String[] getIsimImpu() { 2111 try { 2112 return getSubscriberInfo().getIsimImpu(); 2113 } catch (RemoteException ex) { 2114 return null; 2115 } catch (NullPointerException ex) { 2116 // This could happen before phone restarts due to crashing 2117 return null; 2118 } 2119 } 2120 2121 /** 2122 * @hide 2123 */ 2124 private IPhoneSubInfo getSubscriberInfo() { 2125 // get it each time because that process crashes a lot 2126 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 2127 } 2128 2129 /** Device call state: No activity. */ 2130 public static final int CALL_STATE_IDLE = 0; 2131 /** Device call state: Ringing. A new call arrived and is 2132 * ringing or waiting. In the latter case, another call is 2133 * already active. */ 2134 public static final int CALL_STATE_RINGING = 1; 2135 /** Device call state: Off-hook. At least one call exists 2136 * that is dialing, active, or on hold, and no calls are ringing 2137 * or waiting. */ 2138 public static final int CALL_STATE_OFFHOOK = 2; 2139 2140 /** 2141 * Returns a constant indicating the call state (cellular) on the device. 2142 */ 2143 public int getCallState() { 2144 try { 2145 return getTelecomService().getCallState(); 2146 } catch (RemoteException | NullPointerException e) { 2147 return CALL_STATE_IDLE; 2148 } 2149 } 2150 2151 /** 2152 * Returns a constant indicating the call state (cellular) on the device 2153 * for a subscription. 2154 * 2155 * @param subId whose call state is returned 2156 */ 2157 /** {@hide} */ 2158 public int getCallState(int subId) { 2159 try { 2160 return getITelephony().getCallStateForSubscriber(subId); 2161 } catch (RemoteException ex) { 2162 // the phone process is restarting. 2163 return CALL_STATE_IDLE; 2164 } catch (NullPointerException ex) { 2165 // the phone process is restarting. 2166 return CALL_STATE_IDLE; 2167 } 2168 } 2169 2170 /** Data connection activity: No traffic. */ 2171 public static final int DATA_ACTIVITY_NONE = 0x00000000; 2172 /** Data connection activity: Currently receiving IP PPP traffic. */ 2173 public static final int DATA_ACTIVITY_IN = 0x00000001; 2174 /** Data connection activity: Currently sending IP PPP traffic. */ 2175 public static final int DATA_ACTIVITY_OUT = 0x00000002; 2176 /** Data connection activity: Currently both sending and receiving 2177 * IP PPP traffic. */ 2178 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 2179 /** 2180 * Data connection is active, but physical link is down 2181 */ 2182 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 2183 2184 /** 2185 * Returns a constant indicating the type of activity on a data connection 2186 * (cellular). 2187 * 2188 * @see #DATA_ACTIVITY_NONE 2189 * @see #DATA_ACTIVITY_IN 2190 * @see #DATA_ACTIVITY_OUT 2191 * @see #DATA_ACTIVITY_INOUT 2192 * @see #DATA_ACTIVITY_DORMANT 2193 */ 2194 public int getDataActivity() { 2195 try { 2196 return getITelephony().getDataActivity(); 2197 } catch (RemoteException ex) { 2198 // the phone process is restarting. 2199 return DATA_ACTIVITY_NONE; 2200 } catch (NullPointerException ex) { 2201 // the phone process is restarting. 2202 return DATA_ACTIVITY_NONE; 2203 } 2204 } 2205 2206 /** Data connection state: Unknown. Used before we know the state. 2207 * @hide 2208 */ 2209 public static final int DATA_UNKNOWN = -1; 2210 /** Data connection state: Disconnected. IP traffic not available. */ 2211 public static final int DATA_DISCONNECTED = 0; 2212 /** Data connection state: Currently setting up a data connection. */ 2213 public static final int DATA_CONNECTING = 1; 2214 /** Data connection state: Connected. IP traffic should be available. */ 2215 public static final int DATA_CONNECTED = 2; 2216 /** Data connection state: Suspended. The connection is up, but IP 2217 * traffic is temporarily unavailable. For example, in a 2G network, 2218 * data activity may be suspended when a voice call arrives. */ 2219 public static final int DATA_SUSPENDED = 3; 2220 2221 /** 2222 * Returns a constant indicating the current data connection state 2223 * (cellular). 2224 * 2225 * @see #DATA_DISCONNECTED 2226 * @see #DATA_CONNECTING 2227 * @see #DATA_CONNECTED 2228 * @see #DATA_SUSPENDED 2229 */ 2230 public int getDataState() { 2231 try { 2232 return getITelephony().getDataState(); 2233 } catch (RemoteException ex) { 2234 // the phone process is restarting. 2235 return DATA_DISCONNECTED; 2236 } catch (NullPointerException ex) { 2237 return DATA_DISCONNECTED; 2238 } 2239 } 2240 2241 /** 2242 * @hide 2243 */ 2244 private ITelephony getITelephony() { 2245 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 2246 } 2247 2248 /** 2249 * @hide 2250 */ 2251 private ITelecomService getTelecomService() { 2252 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); 2253 } 2254 2255 // 2256 // 2257 // PhoneStateListener 2258 // 2259 // 2260 2261 /** 2262 * Registers a listener object to receive notification of changes 2263 * in specified telephony states. 2264 * <p> 2265 * To register a listener, pass a {@link PhoneStateListener} 2266 * and specify at least one telephony state of interest in 2267 * the events argument. 2268 * 2269 * At registration, and when a specified telephony state 2270 * changes, the telephony manager invokes the appropriate 2271 * callback method on the listener object and passes the 2272 * current (updated) values. 2273 * <p> 2274 * To unregister a listener, pass the listener object and set the 2275 * events argument to 2276 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 2277 * 2278 * @param listener The {@link PhoneStateListener} object to register 2279 * (or unregister) 2280 * @param events The telephony state(s) of interest to the listener, 2281 * as a bitwise-OR combination of {@link PhoneStateListener} 2282 * LISTEN_ flags. 2283 */ 2284 public void listen(PhoneStateListener listener, int events) { 2285 String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>"; 2286 try { 2287 Boolean notifyNow = (getITelephony() != null); 2288 sRegistry.listenForSubscriber(listener.mSubId, pkgForDebug, listener.callback, events, notifyNow); 2289 } catch (RemoteException ex) { 2290 // system process dead 2291 } catch (NullPointerException ex) { 2292 // system process dead 2293 } 2294 } 2295 2296 /** 2297 * Returns the CDMA ERI icon index to display 2298 * 2299 * @hide 2300 */ 2301 public int getCdmaEriIconIndex() { 2302 return getCdmaEriIconIndex(getDefaultSubscription()); 2303 } 2304 2305 /** 2306 * Returns the CDMA ERI icon index to display for a subscription 2307 */ 2308 /** {@hide} */ 2309 public int getCdmaEriIconIndex(int subId) { 2310 try { 2311 return getITelephony().getCdmaEriIconIndexForSubscriber(subId); 2312 } catch (RemoteException ex) { 2313 // the phone process is restarting. 2314 return -1; 2315 } catch (NullPointerException ex) { 2316 return -1; 2317 } 2318 } 2319 2320 /** 2321 * Returns the CDMA ERI icon mode, 2322 * 0 - ON 2323 * 1 - FLASHING 2324 * 2325 * @hide 2326 */ 2327 public int getCdmaEriIconMode() { 2328 return getCdmaEriIconMode(getDefaultSubscription()); 2329 } 2330 2331 /** 2332 * Returns the CDMA ERI icon mode for a subscription. 2333 * 0 - ON 2334 * 1 - FLASHING 2335 */ 2336 /** {@hide} */ 2337 public int getCdmaEriIconMode(int subId) { 2338 try { 2339 return getITelephony().getCdmaEriIconModeForSubscriber(subId); 2340 } catch (RemoteException ex) { 2341 // the phone process is restarting. 2342 return -1; 2343 } catch (NullPointerException ex) { 2344 return -1; 2345 } 2346 } 2347 2348 /** 2349 * Returns the CDMA ERI text, 2350 * 2351 * @hide 2352 */ 2353 public String getCdmaEriText() { 2354 return getCdmaEriText(getDefaultSubscription()); 2355 } 2356 2357 /** 2358 * Returns the CDMA ERI text, of a subscription 2359 * 2360 */ 2361 /** {@hide} */ 2362 public String getCdmaEriText(int subId) { 2363 try { 2364 return getITelephony().getCdmaEriTextForSubscriber(subId); 2365 } catch (RemoteException ex) { 2366 // the phone process is restarting. 2367 return null; 2368 } catch (NullPointerException ex) { 2369 return null; 2370 } 2371 } 2372 2373 /** 2374 * @return true if the current device is "voice capable". 2375 * <p> 2376 * "Voice capable" means that this device supports circuit-switched 2377 * (i.e. voice) phone calls over the telephony network, and is allowed 2378 * to display the in-call UI while a cellular voice call is active. 2379 * This will be false on "data only" devices which can't make voice 2380 * calls and don't support any in-call UI. 2381 * <p> 2382 * Note: the meaning of this flag is subtly different from the 2383 * PackageManager.FEATURE_TELEPHONY system feature, which is available 2384 * on any device with a telephony radio, even if the device is 2385 * data-only. 2386 * 2387 * @hide pending API review 2388 */ 2389 public boolean isVoiceCapable() { 2390 if (mContext == null) return true; 2391 return mContext.getResources().getBoolean( 2392 com.android.internal.R.bool.config_voice_capable); 2393 } 2394 2395 /** 2396 * @return true if the current device supports sms service. 2397 * <p> 2398 * If true, this means that the device supports both sending and 2399 * receiving sms via the telephony network. 2400 * <p> 2401 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 2402 * disabled when device doesn't support sms. 2403 */ 2404 public boolean isSmsCapable() { 2405 if (mContext == null) return true; 2406 return mContext.getResources().getBoolean( 2407 com.android.internal.R.bool.config_sms_capable); 2408 } 2409 2410 /** 2411 * Returns all observed cell information from all radios on the 2412 * device including the primary and neighboring cells. This does 2413 * not cause or change the rate of PhoneStateListner#onCellInfoChanged. 2414 *<p> 2415 * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm}, 2416 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 2417 * {@link android.telephony.CellInfoLte CellInfoLte} and 2418 * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination. 2419 * Specifically on devices with multiple radios it is typical to see instances of 2420 * one or more of any these in the list. In addition 0, 1 or more CellInfo 2421 * objects may return isRegistered() true. 2422 *<p> 2423 * This is preferred over using getCellLocation although for older 2424 * devices this may return null in which case getCellLocation should 2425 * be called. 2426 *<p> 2427 * @return List of CellInfo or null if info unavailable. 2428 * 2429 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 2430 */ 2431 public List<CellInfo> getAllCellInfo() { 2432 try { 2433 return getITelephony().getAllCellInfo(); 2434 } catch (RemoteException ex) { 2435 return null; 2436 } catch (NullPointerException ex) { 2437 return null; 2438 } 2439 } 2440 2441 /** 2442 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 2443 * PhoneStateListener.onCellInfoChanged} will be invoked. 2444 *<p> 2445 * The default, 0, means invoke onCellInfoChanged when any of the reported 2446 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 2447 * A onCellInfoChanged. 2448 *<p> 2449 * @param rateInMillis the rate 2450 * 2451 * @hide 2452 */ 2453 public void setCellInfoListRate(int rateInMillis) { 2454 try { 2455 getITelephony().setCellInfoListRate(rateInMillis); 2456 } catch (RemoteException ex) { 2457 } catch (NullPointerException ex) { 2458 } 2459 } 2460 2461 /** 2462 * Returns the MMS user agent. 2463 */ 2464 public String getMmsUserAgent() { 2465 if (mContext == null) return null; 2466 return mContext.getResources().getString( 2467 com.android.internal.R.string.config_mms_user_agent); 2468 } 2469 2470 /** 2471 * Returns the MMS user agent profile URL. 2472 */ 2473 public String getMmsUAProfUrl() { 2474 if (mContext == null) return null; 2475 return mContext.getResources().getString( 2476 com.android.internal.R.string.config_mms_user_agent_profile_url); 2477 } 2478 2479 /** 2480 * Opens a logical channel to the ICC card. 2481 * 2482 * Input parameters equivalent to TS 27.007 AT+CCHO command. 2483 * 2484 * <p>Requires Permission: 2485 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2486 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2487 * 2488 * @param AID Application id. See ETSI 102.221 and 101.220. 2489 * @return an IccOpenLogicalChannelResponse object. 2490 */ 2491 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { 2492 try { 2493 return getITelephony().iccOpenLogicalChannel(AID); 2494 } catch (RemoteException ex) { 2495 } catch (NullPointerException ex) { 2496 } 2497 return null; 2498 } 2499 2500 /** 2501 * Closes a previously opened logical channel to the ICC card. 2502 * 2503 * Input parameters equivalent to TS 27.007 AT+CCHC command. 2504 * 2505 * <p>Requires Permission: 2506 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2507 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2508 * 2509 * @param channel is the channel id to be closed as retruned by a successful 2510 * iccOpenLogicalChannel. 2511 * @return true if the channel was closed successfully. 2512 */ 2513 public boolean iccCloseLogicalChannel(int channel) { 2514 try { 2515 return getITelephony().iccCloseLogicalChannel(channel); 2516 } catch (RemoteException ex) { 2517 } catch (NullPointerException ex) { 2518 } 2519 return false; 2520 } 2521 2522 /** 2523 * Transmit an APDU to the ICC card over a logical channel. 2524 * 2525 * Input parameters equivalent to TS 27.007 AT+CGLA command. 2526 * 2527 * <p>Requires Permission: 2528 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2529 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2530 * 2531 * @param channel is the channel id to be closed as returned by a successful 2532 * iccOpenLogicalChannel. 2533 * @param cla Class of the APDU command. 2534 * @param instruction Instruction of the APDU command. 2535 * @param p1 P1 value of the APDU command. 2536 * @param p2 P2 value of the APDU command. 2537 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2538 * is sent to the SIM. 2539 * @param data Data to be sent with the APDU. 2540 * @return The APDU response from the ICC card with the status appended at 2541 * the end. 2542 */ 2543 public String iccTransmitApduLogicalChannel(int channel, int cla, 2544 int instruction, int p1, int p2, int p3, String data) { 2545 try { 2546 return getITelephony().iccTransmitApduLogicalChannel(channel, cla, 2547 instruction, p1, p2, p3, data); 2548 } catch (RemoteException ex) { 2549 } catch (NullPointerException ex) { 2550 } 2551 return ""; 2552 } 2553 2554 /** 2555 * Transmit an APDU to the ICC card over the basic channel. 2556 * 2557 * Input parameters equivalent to TS 27.007 AT+CSIM command. 2558 * 2559 * <p>Requires Permission: 2560 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2561 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2562 * 2563 * @param cla Class of the APDU command. 2564 * @param instruction Instruction of the APDU command. 2565 * @param p1 P1 value of the APDU command. 2566 * @param p2 P2 value of the APDU command. 2567 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2568 * is sent to the SIM. 2569 * @param data Data to be sent with the APDU. 2570 * @return The APDU response from the ICC card with the status appended at 2571 * the end. 2572 */ 2573 public String iccTransmitApduBasicChannel(int cla, 2574 int instruction, int p1, int p2, int p3, String data) { 2575 try { 2576 return getITelephony().iccTransmitApduBasicChannel(cla, 2577 instruction, p1, p2, p3, data); 2578 } catch (RemoteException ex) { 2579 } catch (NullPointerException ex) { 2580 } 2581 return ""; 2582 } 2583 2584 /** 2585 * Returns the response APDU for a command APDU sent through SIM_IO. 2586 * 2587 * <p>Requires Permission: 2588 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2589 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2590 * 2591 * @param fileID 2592 * @param command 2593 * @param p1 P1 value of the APDU command. 2594 * @param p2 P2 value of the APDU command. 2595 * @param p3 P3 value of the APDU command. 2596 * @param filePath 2597 * @return The APDU response. 2598 */ 2599 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 2600 String filePath) { 2601 try { 2602 return getITelephony().iccExchangeSimIO(fileID, command, p1, p2, 2603 p3, filePath); 2604 } catch (RemoteException ex) { 2605 } catch (NullPointerException ex) { 2606 } 2607 return null; 2608 } 2609 2610 /** 2611 * Send ENVELOPE to the SIM and return the response. 2612 * 2613 * <p>Requires Permission: 2614 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2615 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2616 * 2617 * @param content String containing SAT/USAT response in hexadecimal 2618 * format starting with command tag. See TS 102 223 for 2619 * details. 2620 * @return The APDU response from the ICC card in hexadecimal format 2621 * with the last 4 bytes being the status word. If the command fails, 2622 * returns an empty string. 2623 */ 2624 public String sendEnvelopeWithStatus(String content) { 2625 try { 2626 return getITelephony().sendEnvelopeWithStatus(content); 2627 } catch (RemoteException ex) { 2628 } catch (NullPointerException ex) { 2629 } 2630 return ""; 2631 } 2632 2633 /** 2634 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 2635 * Used for device configuration by some CDMA operators. 2636 * <p> 2637 * Requires Permission: 2638 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2639 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2640 * 2641 * @param itemID the ID of the item to read. 2642 * @return the NV item as a String, or null on any failure. 2643 * 2644 * @hide 2645 */ 2646 public String nvReadItem(int itemID) { 2647 try { 2648 return getITelephony().nvReadItem(itemID); 2649 } catch (RemoteException ex) { 2650 Rlog.e(TAG, "nvReadItem RemoteException", ex); 2651 } catch (NullPointerException ex) { 2652 Rlog.e(TAG, "nvReadItem NPE", ex); 2653 } 2654 return ""; 2655 } 2656 2657 /** 2658 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 2659 * Used for device configuration by some CDMA operators. 2660 * <p> 2661 * Requires Permission: 2662 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2663 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2664 * 2665 * @param itemID the ID of the item to read. 2666 * @param itemValue the value to write, as a String. 2667 * @return true on success; false on any failure. 2668 * 2669 * @hide 2670 */ 2671 public boolean nvWriteItem(int itemID, String itemValue) { 2672 try { 2673 return getITelephony().nvWriteItem(itemID, itemValue); 2674 } catch (RemoteException ex) { 2675 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 2676 } catch (NullPointerException ex) { 2677 Rlog.e(TAG, "nvWriteItem NPE", ex); 2678 } 2679 return false; 2680 } 2681 2682 /** 2683 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 2684 * Used for device configuration by some CDMA operators. 2685 * <p> 2686 * Requires Permission: 2687 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2688 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2689 * 2690 * @param preferredRoamingList byte array containing the new PRL. 2691 * @return true on success; false on any failure. 2692 * 2693 * @hide 2694 */ 2695 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 2696 try { 2697 return getITelephony().nvWriteCdmaPrl(preferredRoamingList); 2698 } catch (RemoteException ex) { 2699 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 2700 } catch (NullPointerException ex) { 2701 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 2702 } 2703 return false; 2704 } 2705 2706 /** 2707 * Perform the specified type of NV config reset. The radio will be taken offline 2708 * and the device must be rebooted after the operation. Used for device 2709 * configuration by some CDMA operators. 2710 * <p> 2711 * Requires Permission: 2712 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2713 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2714 * 2715 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 2716 * @return true on success; false on any failure. 2717 * 2718 * @hide 2719 */ 2720 public boolean nvResetConfig(int resetType) { 2721 try { 2722 return getITelephony().nvResetConfig(resetType); 2723 } catch (RemoteException ex) { 2724 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 2725 } catch (NullPointerException ex) { 2726 Rlog.e(TAG, "nvResetConfig NPE", ex); 2727 } 2728 return false; 2729 } 2730 2731 /** 2732 * Returns Default subscription. 2733 */ 2734 private static int getDefaultSubscription() { 2735 return SubscriptionManager.getDefaultSubId(); 2736 } 2737 2738 /** 2739 * Returns Default phone. 2740 */ 2741 private static int getDefaultPhone() { 2742 return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubId()); 2743 } 2744 2745 /** {@hide} */ 2746 public int getDefaultSim() { 2747 return SubscriptionManager.getSlotId(SubscriptionManager.getDefaultSubId()); 2748 } 2749 2750 /** 2751 * Sets the telephony property with the value specified. 2752 * 2753 * @hide 2754 */ 2755 public static void setTelephonyProperty(int phoneId, String property, String value) { 2756 Rlog.d(TAG, "setTelephonyProperty property: " + property + " phoneId: " + phoneId + 2757 " value: " + value); 2758 String propVal = ""; 2759 String p[] = null; 2760 String prop = SystemProperties.get(property); 2761 2762 if (value == null) { 2763 value = ""; 2764 } 2765 2766 if (prop != null) { 2767 p = prop.split(","); 2768 } 2769 2770 if (!SubscriptionManager.isValidPhoneId(phoneId)) { 2771 Rlog.d(TAG, "setTelephonyProperty invalid phone id"); 2772 return; 2773 } 2774 2775 for (int i = 0; i < phoneId; i++) { 2776 String str = ""; 2777 if ((p != null) && (i < p.length)) { 2778 str = p[i]; 2779 } 2780 propVal = propVal + str + ","; 2781 } 2782 2783 propVal = propVal + value; 2784 if (p != null) { 2785 for (int i = phoneId + 1; i < p.length; i++) { 2786 propVal = propVal + "," + p[i]; 2787 } 2788 } 2789 2790 // TODO: workaround for QC 2791 if (property.length() > SystemProperties.PROP_NAME_MAX || propVal.length() > SystemProperties.PROP_VALUE_MAX) { 2792 Rlog.d(TAG, "setTelephonyProperty length too long:" + property + ", " + propVal); 2793 return; 2794 } 2795 2796 Rlog.d(TAG, "setTelephonyProperty property=" + property + " propVal=" + propVal); 2797 SystemProperties.set(property, propVal); 2798 } 2799 2800 /** 2801 * Convenience function for retrieving a value from the secure settings 2802 * value list as an integer. Note that internally setting values are 2803 * always stored as strings; this function converts the string to an 2804 * integer for you. 2805 * <p> 2806 * This version does not take a default value. If the setting has not 2807 * been set, or the string value is not a number, 2808 * it throws {@link SettingNotFoundException}. 2809 * 2810 * @param cr The ContentResolver to access. 2811 * @param name The name of the setting to retrieve. 2812 * @param index The index of the list 2813 * 2814 * @throws SettingNotFoundException Thrown if a setting by the given 2815 * name can't be found or the setting value is not an integer. 2816 * 2817 * @return The value at the given index of settings. 2818 * @hide 2819 */ 2820 public static int getIntAtIndex(android.content.ContentResolver cr, 2821 String name, int index) 2822 throws android.provider.Settings.SettingNotFoundException { 2823 String v = android.provider.Settings.Global.getString(cr, name); 2824 if (v != null) { 2825 String valArray[] = v.split(","); 2826 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 2827 try { 2828 return Integer.parseInt(valArray[index]); 2829 } catch (NumberFormatException e) { 2830 //Log.e(TAG, "Exception while parsing Integer: ", e); 2831 } 2832 } 2833 } 2834 throw new android.provider.Settings.SettingNotFoundException(name); 2835 } 2836 2837 /** 2838 * Convenience function for updating settings value as coma separated 2839 * integer values. This will either create a new entry in the table if the 2840 * given name does not exist, or modify the value of the existing row 2841 * with that name. Note that internally setting values are always 2842 * stored as strings, so this function converts the given value to a 2843 * string before storing it. 2844 * 2845 * @param cr The ContentResolver to access. 2846 * @param name The name of the setting to modify. 2847 * @param index The index of the list 2848 * @param value The new value for the setting to be added to the list. 2849 * @return true if the value was set, false on database errors 2850 * @hide 2851 */ 2852 public static boolean putIntAtIndex(android.content.ContentResolver cr, 2853 String name, int index, int value) { 2854 String data = ""; 2855 String valArray[] = null; 2856 String v = android.provider.Settings.Global.getString(cr, name); 2857 2858 if (index == Integer.MAX_VALUE) { 2859 throw new RuntimeException("putIntAtIndex index == MAX_VALUE index=" + index); 2860 } 2861 if (index < 0) { 2862 throw new RuntimeException("putIntAtIndex index < 0 index=" + index); 2863 } 2864 if (v != null) { 2865 valArray = v.split(","); 2866 } 2867 2868 // Copy the elements from valArray till index 2869 for (int i = 0; i < index; i++) { 2870 String str = ""; 2871 if ((valArray != null) && (i < valArray.length)) { 2872 str = valArray[i]; 2873 } 2874 data = data + str + ","; 2875 } 2876 2877 data = data + value; 2878 2879 // Copy the remaining elements from valArray if any. 2880 if (valArray != null) { 2881 for (int i = index+1; i < valArray.length; i++) { 2882 data = data + "," + valArray[i]; 2883 } 2884 } 2885 return android.provider.Settings.Global.putString(cr, name, data); 2886 } 2887 2888 /** 2889 * Gets the telephony property. 2890 * 2891 * @hide 2892 */ 2893 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 2894 String propVal = null; 2895 String prop = SystemProperties.get(property); 2896 if ((prop != null) && (prop.length() > 0)) { 2897 String values[] = prop.split(","); 2898 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 2899 propVal = values[phoneId]; 2900 } 2901 } 2902 return propVal == null ? defaultVal : propVal; 2903 } 2904 2905 /** @hide */ 2906 public int getSimCount() { 2907 if(isMultiSimEnabled()) { 2908 //FIXME Need to get it from Telephony Devcontroller 2909 return 2; 2910 } else { 2911 return 1; 2912 } 2913 } 2914 2915 /** 2916 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 2917 * @return IMS Service Table or null if not present or not loaded 2918 * @hide 2919 */ 2920 public String getIsimIst() { 2921 try { 2922 return getSubscriberInfo().getIsimIst(); 2923 } catch (RemoteException ex) { 2924 return null; 2925 } catch (NullPointerException ex) { 2926 // This could happen before phone restarts due to crashing 2927 return null; 2928 } 2929 } 2930 2931 /** 2932 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 2933 * @return an array of PCSCF strings with one PCSCF per string, or null if 2934 * not present or not loaded 2935 * @hide 2936 */ 2937 public String[] getIsimPcscf() { 2938 try { 2939 return getSubscriberInfo().getIsimPcscf(); 2940 } catch (RemoteException ex) { 2941 return null; 2942 } catch (NullPointerException ex) { 2943 // This could happen before phone restarts due to crashing 2944 return null; 2945 } 2946 } 2947 2948 /** 2949 * Returns the response of ISIM Authetification through RIL. 2950 * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo. 2951 * @return the response of ISIM Authetification, or null if not available 2952 * @hide 2953 * @deprecated 2954 * @see getIccSimChallengeResponse with appType=PhoneConstants.APPTYPE_ISIM 2955 */ 2956 public String getIsimChallengeResponse(String nonce){ 2957 try { 2958 return getSubscriberInfo().getIsimChallengeResponse(nonce); 2959 } catch (RemoteException ex) { 2960 return null; 2961 } catch (NullPointerException ex) { 2962 // This could happen before phone restarts due to crashing 2963 return null; 2964 } 2965 } 2966 2967 /** 2968 * Returns the response of SIM Authentication through RIL. 2969 * Returns null if the Authentication hasn't been successful 2970 * @param subId subscription ID to be queried 2971 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 2972 * @param data authentication challenge data 2973 * @return the response of SIM Authentication, or null if not available 2974 * @hide 2975 */ 2976 public String getIccSimChallengeResponse(int subId, int appType, String data) { 2977 try { 2978 return getSubscriberInfo().getIccSimChallengeResponse(subId, appType, data); 2979 } catch (RemoteException ex) { 2980 return null; 2981 } catch (NullPointerException ex) { 2982 // This could happen before phone starts 2983 return null; 2984 } 2985 } 2986 2987 /** 2988 * Returns the response of SIM Authentication through RIL for the default subscription. 2989 * Returns null if the Authentication hasn't been successful 2990 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 2991 * @param data authentication challenge data 2992 * @return the response of SIM Authentication, or null if not available 2993 * @hide 2994 */ 2995 public String getIccSimChallengeResponse(int appType, String data) { 2996 return getIccSimChallengeResponse(getDefaultSubscription(), appType, data); 2997 } 2998 2999 /** 3000 * Get P-CSCF address from PCO after data connection is established or modified. 3001 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 3002 * @return array of P-CSCF address 3003 * @hide 3004 */ 3005 public String[] getPcscfAddress(String apnType) { 3006 try { 3007 return getITelephony().getPcscfAddress(apnType); 3008 } catch (RemoteException e) { 3009 return new String[0]; 3010 } 3011 } 3012 3013 /** 3014 * Set IMS registration state 3015 * 3016 * @param Registration state 3017 * @hide 3018 */ 3019 public void setImsRegistrationState(boolean registered) { 3020 try { 3021 getITelephony().setImsRegistrationState(registered); 3022 } catch (RemoteException e) { 3023 } 3024 } 3025 3026 /** 3027 * Get the preferred network type. 3028 * Used for device configuration by some CDMA operators. 3029 * <p> 3030 * Requires Permission: 3031 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3032 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3033 * 3034 * @return the preferred network type, defined in RILConstants.java. 3035 * @hide 3036 */ 3037 public int getPreferredNetworkType() { 3038 try { 3039 return getITelephony().getPreferredNetworkType(); 3040 } catch (RemoteException ex) { 3041 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 3042 } catch (NullPointerException ex) { 3043 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 3044 } 3045 return -1; 3046 } 3047 3048 /** 3049 * Set the preferred network type. 3050 * Used for device configuration by some CDMA operators. 3051 * <p> 3052 * Requires Permission: 3053 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3054 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3055 * 3056 * @param networkType the preferred network type, defined in RILConstants.java. 3057 * @return true on success; false on any failure. 3058 * @hide 3059 */ 3060 public boolean setPreferredNetworkType(int networkType) { 3061 try { 3062 return getITelephony().setPreferredNetworkType(networkType); 3063 } catch (RemoteException ex) { 3064 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 3065 } catch (NullPointerException ex) { 3066 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 3067 } 3068 return false; 3069 } 3070 3071 /** 3072 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 3073 * 3074 * <p> 3075 * Requires Permission: 3076 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3077 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3078 * 3079 * @return true on success; false on any failure. 3080 */ 3081 public boolean setGlobalPreferredNetworkType() { 3082 return setPreferredNetworkType(RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); 3083 } 3084 3085 /** 3086 * Values used to return status for hasCarrierPrivileges call. 3087 */ 3088 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 3089 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 3090 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 3091 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 3092 3093 /** 3094 * Has the calling application been granted carrier privileges by the carrier. 3095 * 3096 * If any of the packages in the calling UID has carrier privileges, the 3097 * call will return true. This access is granted by the owner of the UICC 3098 * card and does not depend on the registered carrier. 3099 * 3100 * TODO: Add a link to documentation. 3101 * 3102 * @return CARRIER_PRIVILEGE_STATUS_HAS_ACCESS if the app has carrier privileges. 3103 * CARRIER_PRIVILEGE_STATUS_NO_ACCESS if the app does not have carrier privileges. 3104 * CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED if the carrier rules are not loaded. 3105 * CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES if there was an error loading carrier 3106 * rules (or if there are no rules). 3107 */ 3108 public int hasCarrierPrivileges() { 3109 try { 3110 return getITelephony().hasCarrierPrivileges(); 3111 } catch (RemoteException ex) { 3112 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3113 } catch (NullPointerException ex) { 3114 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3115 } 3116 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3117 } 3118 3119 /** 3120 * Override the branding for the current ICCID. 3121 * 3122 * Once set, whenever the SIM is present in the device, the service 3123 * provider name (SPN) and the operator name will both be replaced by the 3124 * brand value input. To unset the value, the same function should be 3125 * called with a null brand value. 3126 * 3127 * <p>Requires Permission: 3128 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3129 * or has to be carrier app - see #hasCarrierPrivileges. 3130 * 3131 * @param brand The brand name to display/set. 3132 * @return true if the operation was executed correctly. 3133 */ 3134 public boolean setOperatorBrandOverride(String brand) { 3135 try { 3136 return getITelephony().setOperatorBrandOverride(brand); 3137 } catch (RemoteException ex) { 3138 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 3139 } catch (NullPointerException ex) { 3140 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 3141 } 3142 return false; 3143 } 3144 3145 /** 3146 * Expose the rest of ITelephony to @SystemApi 3147 */ 3148 3149 /** @hide */ 3150 @SystemApi 3151 public String getCdmaMdn() { 3152 return getCdmaMdn(getDefaultSubscription()); 3153 } 3154 3155 /** @hide */ 3156 @SystemApi 3157 public String getCdmaMdn(int subId) { 3158 try { 3159 return getITelephony().getCdmaMdn(subId); 3160 } catch (RemoteException ex) { 3161 return null; 3162 } catch (NullPointerException ex) { 3163 return null; 3164 } 3165 } 3166 3167 /** @hide */ 3168 @SystemApi 3169 public String getCdmaMin() { 3170 return getCdmaMin(getDefaultSubscription()); 3171 } 3172 3173 /** @hide */ 3174 @SystemApi 3175 public String getCdmaMin(int subId) { 3176 try { 3177 return getITelephony().getCdmaMin(subId); 3178 } catch (RemoteException ex) { 3179 return null; 3180 } catch (NullPointerException ex) { 3181 return null; 3182 } 3183 } 3184 3185 /** @hide */ 3186 @SystemApi 3187 public int checkCarrierPrivilegesForPackage(String pkgname) { 3188 try { 3189 return getITelephony().checkCarrierPrivilegesForPackage(pkgname); 3190 } catch (RemoteException ex) { 3191 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3192 } catch (NullPointerException ex) { 3193 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3194 } 3195 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3196 } 3197 3198 /** @hide */ 3199 @SystemApi 3200 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 3201 try { 3202 return getITelephony().getCarrierPackageNamesForIntent(intent); 3203 } catch (RemoteException ex) { 3204 Rlog.e(TAG, "getCarrierPackageNamesForIntent RemoteException", ex); 3205 } catch (NullPointerException ex) { 3206 Rlog.e(TAG, "getCarrierPackageNamesForIntent NPE", ex); 3207 } 3208 return null; 3209 } 3210 3211 /** @hide */ 3212 @SystemApi 3213 public void dial(String number) { 3214 try { 3215 getITelephony().dial(number); 3216 } catch (RemoteException e) { 3217 Log.e(TAG, "Error calling ITelephony#dial", e); 3218 } 3219 } 3220 3221 /** @hide */ 3222 @SystemApi 3223 public void call(String callingPackage, String number) { 3224 try { 3225 getITelephony().call(callingPackage, number); 3226 } catch (RemoteException e) { 3227 Log.e(TAG, "Error calling ITelephony#call", e); 3228 } 3229 } 3230 3231 /** @hide */ 3232 @SystemApi 3233 public boolean endCall() { 3234 try { 3235 return getITelephony().endCall(); 3236 } catch (RemoteException e) { 3237 Log.e(TAG, "Error calling ITelephony#endCall", e); 3238 } 3239 return false; 3240 } 3241 3242 /** @hide */ 3243 @SystemApi 3244 public void answerRingingCall() { 3245 try { 3246 getITelephony().answerRingingCall(); 3247 } catch (RemoteException e) { 3248 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 3249 } 3250 } 3251 3252 /** @hide */ 3253 @SystemApi 3254 public void silenceRinger() { 3255 try { 3256 getTelecomService().silenceRinger(); 3257 } catch (RemoteException e) { 3258 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); 3259 } 3260 } 3261 3262 /** @hide */ 3263 @SystemApi 3264 public boolean isOffhook() { 3265 try { 3266 return getITelephony().isOffhook(); 3267 } catch (RemoteException e) { 3268 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 3269 } 3270 return false; 3271 } 3272 3273 /** @hide */ 3274 @SystemApi 3275 public boolean isRinging() { 3276 try { 3277 return getITelephony().isRinging(); 3278 } catch (RemoteException e) { 3279 Log.e(TAG, "Error calling ITelephony#isRinging", e); 3280 } 3281 return false; 3282 } 3283 3284 /** @hide */ 3285 @SystemApi 3286 public boolean isIdle() { 3287 try { 3288 return getITelephony().isIdle(); 3289 } catch (RemoteException e) { 3290 Log.e(TAG, "Error calling ITelephony#isIdle", e); 3291 } 3292 return true; 3293 } 3294 3295 /** @hide */ 3296 @SystemApi 3297 public boolean isRadioOn() { 3298 try { 3299 return getITelephony().isRadioOn(); 3300 } catch (RemoteException e) { 3301 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 3302 } 3303 return false; 3304 } 3305 3306 /** @hide */ 3307 @SystemApi 3308 public boolean isSimPinEnabled() { 3309 try { 3310 return getITelephony().isSimPinEnabled(); 3311 } catch (RemoteException e) { 3312 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 3313 } 3314 return false; 3315 } 3316 3317 /** @hide */ 3318 @SystemApi 3319 public boolean supplyPin(String pin) { 3320 try { 3321 return getITelephony().supplyPin(pin); 3322 } catch (RemoteException e) { 3323 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 3324 } 3325 return false; 3326 } 3327 3328 /** @hide */ 3329 @SystemApi 3330 public boolean supplyPuk(String puk, String pin) { 3331 try { 3332 return getITelephony().supplyPuk(puk, pin); 3333 } catch (RemoteException e) { 3334 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 3335 } 3336 return false; 3337 } 3338 3339 /** @hide */ 3340 @SystemApi 3341 public int[] supplyPinReportResult(String pin) { 3342 try { 3343 return getITelephony().supplyPinReportResult(pin); 3344 } catch (RemoteException e) { 3345 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 3346 } 3347 return new int[0]; 3348 } 3349 3350 /** @hide */ 3351 @SystemApi 3352 public int[] supplyPukReportResult(String puk, String pin) { 3353 try { 3354 return getITelephony().supplyPukReportResult(puk, pin); 3355 } catch (RemoteException e) { 3356 Log.e(TAG, "Error calling ITelephony#]", e); 3357 } 3358 return new int[0]; 3359 } 3360 3361 /** @hide */ 3362 @SystemApi 3363 public boolean handlePinMmi(String dialString) { 3364 try { 3365 return getITelephony().handlePinMmi(dialString); 3366 } catch (RemoteException e) { 3367 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3368 } 3369 return false; 3370 } 3371 3372 /** @hide */ 3373 @SystemApi 3374 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 3375 try { 3376 return getITelephony().handlePinMmiForSubscriber(subId, dialString); 3377 } catch (RemoteException e) { 3378 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3379 } 3380 return false; 3381 } 3382 3383 /** @hide */ 3384 @SystemApi 3385 public void toggleRadioOnOff() { 3386 try { 3387 getITelephony().toggleRadioOnOff(); 3388 } catch (RemoteException e) { 3389 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 3390 } 3391 } 3392 3393 /** @hide */ 3394 @SystemApi 3395 public boolean setRadio(boolean turnOn) { 3396 try { 3397 return getITelephony().setRadio(turnOn); 3398 } catch (RemoteException e) { 3399 Log.e(TAG, "Error calling ITelephony#setRadio", e); 3400 } 3401 return false; 3402 } 3403 3404 /** @hide */ 3405 @SystemApi 3406 public boolean setRadioPower(boolean turnOn) { 3407 try { 3408 return getITelephony().setRadioPower(turnOn); 3409 } catch (RemoteException e) { 3410 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 3411 } 3412 return false; 3413 } 3414 3415 /** @hide */ 3416 @SystemApi 3417 public void updateServiceLocation() { 3418 try { 3419 getITelephony().updateServiceLocation(); 3420 } catch (RemoteException e) { 3421 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 3422 } 3423 } 3424 3425 /** @hide */ 3426 @SystemApi 3427 public boolean enableDataConnectivity() { 3428 try { 3429 return getITelephony().enableDataConnectivity(); 3430 } catch (RemoteException e) { 3431 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 3432 } 3433 return false; 3434 } 3435 3436 /** @hide */ 3437 @SystemApi 3438 public boolean disableDataConnectivity() { 3439 try { 3440 return getITelephony().disableDataConnectivity(); 3441 } catch (RemoteException e) { 3442 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 3443 } 3444 return false; 3445 } 3446 3447 /** @hide */ 3448 @SystemApi 3449 public boolean isDataConnectivityPossible() { 3450 try { 3451 return getITelephony().isDataConnectivityPossible(); 3452 } catch (RemoteException e) { 3453 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 3454 } 3455 return false; 3456 } 3457 3458 /** @hide */ 3459 @SystemApi 3460 public boolean needsOtaServiceProvisioning() { 3461 try { 3462 return getITelephony().needsOtaServiceProvisioning(); 3463 } catch (RemoteException e) { 3464 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 3465 } 3466 return false; 3467 } 3468 3469 /** @hide */ 3470 @SystemApi 3471 public void setDataEnabled(boolean enable) { 3472 try { 3473 getITelephony().setDataEnabled(enable); 3474 } catch (RemoteException e) { 3475 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 3476 } 3477 } 3478 3479 /** @hide */ 3480 @SystemApi 3481 public boolean getDataEnabled() { 3482 try { 3483 return getITelephony().getDataEnabled(); 3484 } catch (RemoteException e) { 3485 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 3486 } 3487 return false; 3488 } 3489 3490 /** 3491 * Returns the result and response from RIL for oem request 3492 * 3493 * @param oemReq the data is sent to ril. 3494 * @param oemResp the respose data from RIL. 3495 * @return negative value request was not handled or get error 3496 * 0 request was handled succesfully, but no response data 3497 * positive value success, data length of response 3498 * @hide 3499 */ 3500 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 3501 try { 3502 return getITelephony().invokeOemRilRequestRaw(oemReq, oemResp); 3503 } catch (RemoteException ex) { 3504 } catch (NullPointerException ex) { 3505 } 3506 return -1; 3507 } 3508 3509 /** @hide */ 3510 @SystemApi 3511 public void enableVideoCalling(boolean enable) { 3512 try { 3513 getITelephony().enableVideoCalling(enable); 3514 } catch (RemoteException e) { 3515 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 3516 } 3517 } 3518 3519 /** @hide */ 3520 @SystemApi 3521 public boolean isVideoCallingEnabled() { 3522 try { 3523 return getITelephony().isVideoCallingEnabled(); 3524 } catch (RemoteException e) { 3525 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 3526 } 3527 return false; 3528 } 3529} 3530