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