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