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