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