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