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