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