TelephonyManager.java revision 142529702dad9a6612271f487d500db80173ba7b
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 try { 1699 return getSubscriberInfo().getLine1NumberUsingSubId(subId); 1700 } catch (RemoteException ex) { 1701 return null; 1702 } catch (NullPointerException ex) { 1703 // This could happen before phone restarts due to crashing 1704 return null; 1705 } 1706 } 1707 1708 /** 1709 * Returns the alphabetic identifier associated with the line 1 number. 1710 * Return null if it is unavailable. 1711 * <p> 1712 * Requires Permission: 1713 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1714 * @hide 1715 * nobody seems to call this. 1716 */ 1717 public String getLine1AlphaTag() { 1718 return getLine1AlphaTag(getDefaultSubscription()); 1719 } 1720 1721 /** 1722 * Returns the alphabetic identifier associated with the line 1 number 1723 * for a subscription. 1724 * Return null if it is unavailable. 1725 * <p> 1726 * Requires Permission: 1727 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1728 * @param subId whose alphabetic identifier associated with line 1 is returned 1729 * nobody seems to call this. 1730 */ 1731 /** {@hide} */ 1732 public String getLine1AlphaTag(long subId) { 1733 try { 1734 return getSubscriberInfo().getLine1AlphaTagUsingSubId(subId); 1735 } catch (RemoteException ex) { 1736 return null; 1737 } catch (NullPointerException ex) { 1738 // This could happen before phone restarts due to crashing 1739 return null; 1740 } 1741 } 1742 1743 /** 1744 * Returns the MSISDN string. 1745 * for a GSM phone. Return null if it is unavailable. 1746 * <p> 1747 * Requires Permission: 1748 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1749 * 1750 * @hide 1751 */ 1752 public String getMsisdn() { 1753 return getMsisdn(getDefaultSubscription()); 1754 } 1755 1756 /** 1757 * Returns the MSISDN string. 1758 * for a GSM phone. Return null if it is unavailable. 1759 * <p> 1760 * Requires Permission: 1761 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1762 * 1763 * @param subId for which msisdn is returned 1764 */ 1765 /** {@hide} */ 1766 public String getMsisdn(long subId) { 1767 try { 1768 return getSubscriberInfo().getMsisdnUsingSubId(subId); 1769 } catch (RemoteException ex) { 1770 return null; 1771 } catch (NullPointerException ex) { 1772 // This could happen before phone restarts due to crashing 1773 return null; 1774 } 1775 } 1776 1777 /** 1778 * Returns the voice mail number. Return null if it is unavailable. 1779 * <p> 1780 * Requires Permission: 1781 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1782 */ 1783 public String getVoiceMailNumber() { 1784 return getVoiceMailNumber(getDefaultSubscription()); 1785 } 1786 1787 /** 1788 * Returns the voice mail number for a subscription. 1789 * Return null if it is unavailable. 1790 * <p> 1791 * Requires Permission: 1792 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1793 * @param subId whose voice mail number is returned 1794 */ 1795 /** {@hide} */ 1796 public String getVoiceMailNumber(long subId) { 1797 try { 1798 return getSubscriberInfo().getVoiceMailNumberUsingSubId(subId); 1799 } catch (RemoteException ex) { 1800 return null; 1801 } catch (NullPointerException ex) { 1802 // This could happen before phone restarts due to crashing 1803 return null; 1804 } 1805 } 1806 1807 /** 1808 * Returns the complete voice mail number. Return null if it is unavailable. 1809 * <p> 1810 * Requires Permission: 1811 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 1812 * 1813 * @hide 1814 */ 1815 public String getCompleteVoiceMailNumber() { 1816 return getCompleteVoiceMailNumber(getDefaultSubscription()); 1817 } 1818 1819 /** 1820 * Returns the complete voice mail number. Return null if it is unavailable. 1821 * <p> 1822 * Requires Permission: 1823 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 1824 * 1825 * @param subId 1826 */ 1827 /** {@hide} */ 1828 public String getCompleteVoiceMailNumber(long subId) { 1829 try { 1830 return getSubscriberInfo().getCompleteVoiceMailNumberUsingSubId(subId); 1831 } catch (RemoteException ex) { 1832 return null; 1833 } catch (NullPointerException ex) { 1834 // This could happen before phone restarts due to crashing 1835 return null; 1836 } 1837 } 1838 1839 /** 1840 * Returns the voice mail count. Return 0 if unavailable. 1841 * <p> 1842 * Requires Permission: 1843 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1844 * @hide 1845 */ 1846 public int getVoiceMessageCount() { 1847 return getVoiceMessageCount(getDefaultSubscription()); 1848 } 1849 1850 /** 1851 * Returns the voice mail count for a subscription. Return 0 if unavailable. 1852 * <p> 1853 * Requires Permission: 1854 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1855 * @param subId whose voice message count is returned 1856 */ 1857 /** {@hide} */ 1858 public int getVoiceMessageCount(long subId) { 1859 try { 1860 return getITelephony().getVoiceMessageCountUsingSubId(subId); 1861 } catch (RemoteException ex) { 1862 return 0; 1863 } catch (NullPointerException ex) { 1864 // This could happen before phone restarts due to crashing 1865 return 0; 1866 } 1867 } 1868 1869 /** 1870 * Retrieves the alphabetic identifier associated with the voice 1871 * mail number. 1872 * <p> 1873 * Requires Permission: 1874 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1875 */ 1876 public String getVoiceMailAlphaTag() { 1877 return getVoiceMailAlphaTag(getDefaultSubscription()); 1878 } 1879 1880 /** 1881 * Retrieves the alphabetic identifier associated with the voice 1882 * mail number for a subscription. 1883 * <p> 1884 * Requires Permission: 1885 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1886 * @param subId whose alphabetic identifier associated with the 1887 * voice mail number is returned 1888 */ 1889 /** {@hide} */ 1890 public String getVoiceMailAlphaTag(long subId) { 1891 try { 1892 return getSubscriberInfo().getVoiceMailAlphaTagUsingSubId(subId); 1893 } catch (RemoteException ex) { 1894 return null; 1895 } catch (NullPointerException ex) { 1896 // This could happen before phone restarts due to crashing 1897 return null; 1898 } 1899 } 1900 1901 /** 1902 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 1903 * @return the IMPI, or null if not present or not loaded 1904 * @hide 1905 */ 1906 public String getIsimImpi() { 1907 try { 1908 return getSubscriberInfo().getIsimImpi(); 1909 } catch (RemoteException ex) { 1910 return null; 1911 } catch (NullPointerException ex) { 1912 // This could happen before phone restarts due to crashing 1913 return null; 1914 } 1915 } 1916 1917 /** 1918 * Returns the IMS home network domain name that was loaded from the ISIM. 1919 * @return the IMS domain name, or null if not present or not loaded 1920 * @hide 1921 */ 1922 public String getIsimDomain() { 1923 try { 1924 return getSubscriberInfo().getIsimDomain(); 1925 } catch (RemoteException ex) { 1926 return null; 1927 } catch (NullPointerException ex) { 1928 // This could happen before phone restarts due to crashing 1929 return null; 1930 } 1931 } 1932 1933 /** 1934 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 1935 * @return an array of IMPU strings, with one IMPU per string, or null if 1936 * not present or not loaded 1937 * @hide 1938 */ 1939 public String[] getIsimImpu() { 1940 try { 1941 return getSubscriberInfo().getIsimImpu(); 1942 } catch (RemoteException ex) { 1943 return null; 1944 } catch (NullPointerException ex) { 1945 // This could happen before phone restarts due to crashing 1946 return null; 1947 } 1948 } 1949 1950 private IPhoneSubInfo getSubscriberInfo() { 1951 // get it each time because that process crashes a lot 1952 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 1953 } 1954 1955 /** Device call state: No activity. */ 1956 public static final int CALL_STATE_IDLE = 0; 1957 /** Device call state: Ringing. A new call arrived and is 1958 * ringing or waiting. In the latter case, another call is 1959 * already active. */ 1960 public static final int CALL_STATE_RINGING = 1; 1961 /** Device call state: Off-hook. At least one call exists 1962 * that is dialing, active, or on hold, and no calls are ringing 1963 * or waiting. */ 1964 public static final int CALL_STATE_OFFHOOK = 2; 1965 1966 /** 1967 * Returns a constant indicating the call state (cellular) on the device. 1968 */ 1969 public int getCallState() { 1970 return getCallState(getDefaultSubscription()); 1971 } 1972 1973 /** 1974 * Returns a constant indicating the call state (cellular) on the device 1975 * for a subscription. 1976 * 1977 * @param subId whose call state is returned 1978 */ 1979 /** {@hide} */ 1980 public int getCallState(long subId) { 1981 try { 1982 return getITelephony().getCallStateUsingSubId(subId); 1983 } catch (RemoteException ex) { 1984 // the phone process is restarting. 1985 return CALL_STATE_IDLE; 1986 } catch (NullPointerException ex) { 1987 // the phone process is restarting. 1988 return CALL_STATE_IDLE; 1989 } 1990 } 1991 1992 /** Data connection activity: No traffic. */ 1993 public static final int DATA_ACTIVITY_NONE = 0x00000000; 1994 /** Data connection activity: Currently receiving IP PPP traffic. */ 1995 public static final int DATA_ACTIVITY_IN = 0x00000001; 1996 /** Data connection activity: Currently sending IP PPP traffic. */ 1997 public static final int DATA_ACTIVITY_OUT = 0x00000002; 1998 /** Data connection activity: Currently both sending and receiving 1999 * IP PPP traffic. */ 2000 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 2001 /** 2002 * Data connection is active, but physical link is down 2003 */ 2004 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 2005 2006 /** 2007 * Returns a constant indicating the type of activity on a data connection 2008 * (cellular). 2009 * 2010 * @see #DATA_ACTIVITY_NONE 2011 * @see #DATA_ACTIVITY_IN 2012 * @see #DATA_ACTIVITY_OUT 2013 * @see #DATA_ACTIVITY_INOUT 2014 * @see #DATA_ACTIVITY_DORMANT 2015 */ 2016 public int getDataActivity() { 2017 try { 2018 return getITelephony().getDataActivity(); 2019 } catch (RemoteException ex) { 2020 // the phone process is restarting. 2021 return DATA_ACTIVITY_NONE; 2022 } catch (NullPointerException ex) { 2023 // the phone process is restarting. 2024 return DATA_ACTIVITY_NONE; 2025 } 2026 } 2027 2028 /** Data connection state: Unknown. Used before we know the state. 2029 * @hide 2030 */ 2031 public static final int DATA_UNKNOWN = -1; 2032 /** Data connection state: Disconnected. IP traffic not available. */ 2033 public static final int DATA_DISCONNECTED = 0; 2034 /** Data connection state: Currently setting up a data connection. */ 2035 public static final int DATA_CONNECTING = 1; 2036 /** Data connection state: Connected. IP traffic should be available. */ 2037 public static final int DATA_CONNECTED = 2; 2038 /** Data connection state: Suspended. The connection is up, but IP 2039 * traffic is temporarily unavailable. For example, in a 2G network, 2040 * data activity may be suspended when a voice call arrives. */ 2041 public static final int DATA_SUSPENDED = 3; 2042 2043 /** 2044 * Returns a constant indicating the current data connection state 2045 * (cellular). 2046 * 2047 * @see #DATA_DISCONNECTED 2048 * @see #DATA_CONNECTING 2049 * @see #DATA_CONNECTED 2050 * @see #DATA_SUSPENDED 2051 */ 2052 public int getDataState() { 2053 try { 2054 return getITelephony().getDataState(); 2055 } catch (RemoteException ex) { 2056 // the phone process is restarting. 2057 return DATA_DISCONNECTED; 2058 } catch (NullPointerException ex) { 2059 return DATA_DISCONNECTED; 2060 } 2061 } 2062 2063 private ITelephony getITelephony() { 2064 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 2065 } 2066 2067 private ITelecommService getTelecommService() { 2068 return ITelecommService.Stub.asInterface(ServiceManager.getService(TELECOMM_SERVICE_NAME)); 2069 } 2070 2071 // 2072 // 2073 // PhoneStateListener 2074 // 2075 // 2076 2077 /** 2078 * Registers a listener object to receive notification of changes 2079 * in specified telephony states. 2080 * <p> 2081 * To register a listener, pass a {@link PhoneStateListener} 2082 * and specify at least one telephony state of interest in 2083 * the events argument. 2084 * 2085 * At registration, and when a specified telephony state 2086 * changes, the telephony manager invokes the appropriate 2087 * callback method on the listener object and passes the 2088 * current (updated) values. 2089 * <p> 2090 * To unregister a listener, pass the listener object and set the 2091 * events argument to 2092 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 2093 * 2094 * @param listener The {@link PhoneStateListener} object to register 2095 * (or unregister) 2096 * @param events The telephony state(s) of interest to the listener, 2097 * as a bitwise-OR combination of {@link PhoneStateListener} 2098 * LISTEN_ flags. 2099 */ 2100 public void listen(PhoneStateListener listener, int events) { 2101 String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>"; 2102 try { 2103 Boolean notifyNow = (getITelephony() != null); 2104 sRegistry.listenUsingSubId(listener.mSubId, pkgForDebug, listener.callback, events, notifyNow); 2105 } catch (RemoteException ex) { 2106 // system process dead 2107 } catch (NullPointerException ex) { 2108 // system process dead 2109 } 2110 } 2111 2112 /** 2113 * Returns the CDMA ERI icon index to display 2114 * 2115 * @hide 2116 */ 2117 public int getCdmaEriIconIndex() { 2118 return getCdmaEriIconIndex(getDefaultSubscription()); 2119 } 2120 2121 /** 2122 * Returns the CDMA ERI icon index to display for a subscription 2123 */ 2124 /** {@hide} */ 2125 public int getCdmaEriIconIndex(long subId) { 2126 try { 2127 return getITelephony().getCdmaEriIconIndexUsingSubId(subId); 2128 } catch (RemoteException ex) { 2129 // the phone process is restarting. 2130 return -1; 2131 } catch (NullPointerException ex) { 2132 return -1; 2133 } 2134 } 2135 2136 /** 2137 * Returns the CDMA ERI icon mode, 2138 * 0 - ON 2139 * 1 - FLASHING 2140 * 2141 * @hide 2142 */ 2143 public int getCdmaEriIconMode() { 2144 return getCdmaEriIconMode(getDefaultSubscription()); 2145 } 2146 2147 /** 2148 * Returns the CDMA ERI icon mode for a subscription. 2149 * 0 - ON 2150 * 1 - FLASHING 2151 */ 2152 /** {@hide} */ 2153 public int getCdmaEriIconMode(long subId) { 2154 try { 2155 return getITelephony().getCdmaEriIconModeUsingSubId(subId); 2156 } catch (RemoteException ex) { 2157 // the phone process is restarting. 2158 return -1; 2159 } catch (NullPointerException ex) { 2160 return -1; 2161 } 2162 } 2163 2164 /** 2165 * Returns the CDMA ERI text, 2166 * 2167 * @hide 2168 */ 2169 public String getCdmaEriText() { 2170 return getCdmaEriText(getDefaultSubscription()); 2171 } 2172 2173 /** 2174 * Returns the CDMA ERI text, of a subscription 2175 * 2176 */ 2177 /** {@hide} */ 2178 public String getCdmaEriText(long subId) { 2179 try { 2180 return getITelephony().getCdmaEriTextUsingSubId(subId); 2181 } catch (RemoteException ex) { 2182 // the phone process is restarting. 2183 return null; 2184 } catch (NullPointerException ex) { 2185 return null; 2186 } 2187 } 2188 2189 /** 2190 * @return true if the current device is "voice capable". 2191 * <p> 2192 * "Voice capable" means that this device supports circuit-switched 2193 * (i.e. voice) phone calls over the telephony network, and is allowed 2194 * to display the in-call UI while a cellular voice call is active. 2195 * This will be false on "data only" devices which can't make voice 2196 * calls and don't support any in-call UI. 2197 * <p> 2198 * Note: the meaning of this flag is subtly different from the 2199 * PackageManager.FEATURE_TELEPHONY system feature, which is available 2200 * on any device with a telephony radio, even if the device is 2201 * data-only. 2202 * 2203 * @hide pending API review 2204 */ 2205 public boolean isVoiceCapable() { 2206 if (mContext == null) return true; 2207 return mContext.getResources().getBoolean( 2208 com.android.internal.R.bool.config_voice_capable); 2209 } 2210 2211 /** 2212 * @return true if the current device supports sms service. 2213 * <p> 2214 * If true, this means that the device supports both sending and 2215 * receiving sms via the telephony network. 2216 * <p> 2217 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 2218 * disabled when device doesn't support sms. 2219 * 2220 * @hide pending API review 2221 */ 2222 public boolean isSmsCapable() { 2223 if (mContext == null) return true; 2224 return mContext.getResources().getBoolean( 2225 com.android.internal.R.bool.config_sms_capable); 2226 } 2227 2228 /** 2229 * Returns all observed cell information from all radios on the 2230 * device including the primary and neighboring cells. This does 2231 * not cause or change the rate of PhoneStateListner#onCellInfoChanged. 2232 *<p> 2233 * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm}, 2234 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 2235 * {@link android.telephony.CellInfoLte CellInfoLte} and 2236 * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination. 2237 * Specifically on devices with multiple radios it is typical to see instances of 2238 * one or more of any these in the list. In addition 0, 1 or more CellInfo 2239 * objects may return isRegistered() true. 2240 *<p> 2241 * This is preferred over using getCellLocation although for older 2242 * devices this may return null in which case getCellLocation should 2243 * be called. 2244 *<p> 2245 * @return List of CellInfo or null if info unavailable. 2246 * 2247 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 2248 */ 2249 public List<CellInfo> getAllCellInfo() { 2250 try { 2251 return getITelephony().getAllCellInfo(); 2252 } catch (RemoteException ex) { 2253 return null; 2254 } catch (NullPointerException ex) { 2255 return null; 2256 } 2257 } 2258 2259 /** 2260 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 2261 * PhoneStateListener.onCellInfoChanged} will be invoked. 2262 *<p> 2263 * The default, 0, means invoke onCellInfoChanged when any of the reported 2264 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 2265 * A onCellInfoChanged. 2266 *<p> 2267 * @param rateInMillis the rate 2268 * 2269 * @hide 2270 */ 2271 public void setCellInfoListRate(int rateInMillis) { 2272 try { 2273 getITelephony().setCellInfoListRate(rateInMillis); 2274 } catch (RemoteException ex) { 2275 } catch (NullPointerException ex) { 2276 } 2277 } 2278 2279 /** 2280 * Returns the MMS user agent. 2281 */ 2282 public String getMmsUserAgent() { 2283 if (mContext == null) return null; 2284 return mContext.getResources().getString( 2285 com.android.internal.R.string.config_mms_user_agent); 2286 } 2287 2288 /** 2289 * Returns the MMS user agent profile URL. 2290 */ 2291 public String getMmsUAProfUrl() { 2292 if (mContext == null) return null; 2293 return mContext.getResources().getString( 2294 com.android.internal.R.string.config_mms_user_agent_profile_url); 2295 } 2296 2297 /** 2298 * Opens a logical channel to the ICC card. 2299 * 2300 * Input parameters equivalent to TS 27.007 AT+CCHO command. 2301 * 2302 * <p>Requires Permission: 2303 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2304 * 2305 * @param AID Application id. See ETSI 102.221 and 101.220. 2306 * @return The logical channel id which is negative on error. 2307 * 2308 * @hide 2309 */ 2310 public int iccOpenLogicalChannel(String AID) { 2311 try { 2312 return getITelephony().iccOpenLogicalChannel(AID); 2313 } catch (RemoteException ex) { 2314 } catch (NullPointerException ex) { 2315 } 2316 return -1; 2317 } 2318 2319 /** 2320 * Closes a previously opened logical channel to the ICC card. 2321 * 2322 * Input parameters equivalent to TS 27.007 AT+CCHC command. 2323 * 2324 * <p>Requires Permission: 2325 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2326 * 2327 * @param channel is the channel id to be closed as retruned by a successful 2328 * iccOpenLogicalChannel. 2329 * @return true if the channel was closed successfully. 2330 * 2331 * @hide 2332 */ 2333 public boolean iccCloseLogicalChannel(int channel) { 2334 try { 2335 return getITelephony().iccCloseLogicalChannel(channel); 2336 } catch (RemoteException ex) { 2337 } catch (NullPointerException ex) { 2338 } 2339 return false; 2340 } 2341 2342 /** 2343 * Transmit an APDU to the ICC card over a logical channel. 2344 * 2345 * Input parameters equivalent to TS 27.007 AT+CGLA command. 2346 * 2347 * <p>Requires Permission: 2348 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2349 * 2350 * @param channel is the channel id to be closed as returned by a successful 2351 * iccOpenLogicalChannel. 2352 * @param cla Class of the APDU command. 2353 * @param instruction Instruction of the APDU command. 2354 * @param p1 P1 value of the APDU command. 2355 * @param p2 P2 value of the APDU command. 2356 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2357 * is sent to the SIM. 2358 * @param data Data to be sent with the APDU. 2359 * @return The APDU response from the ICC card with the status appended at 2360 * the end. If an error occurs, an empty string is returned. 2361 * 2362 * @hide 2363 */ 2364 public String iccTransmitApduLogicalChannel(int channel, int cla, 2365 int instruction, int p1, int p2, int p3, String data) { 2366 try { 2367 return getITelephony().iccTransmitApduLogicalChannel(channel, cla, 2368 instruction, p1, p2, p3, data); 2369 } catch (RemoteException ex) { 2370 } catch (NullPointerException ex) { 2371 } 2372 return ""; 2373 } 2374 2375 /** 2376 * Send ENVELOPE to the SIM and return the response. 2377 * 2378 * <p>Requires Permission: 2379 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2380 * 2381 * @param content String containing SAT/USAT response in hexadecimal 2382 * format starting with command tag. See TS 102 223 for 2383 * details. 2384 * @return The APDU response from the ICC card, with the last 4 bytes 2385 * being the status word. If the command fails, returns an empty 2386 * string. 2387 * 2388 * @hide 2389 */ 2390 public String sendEnvelopeWithStatus(String content) { 2391 try { 2392 return getITelephony().sendEnvelopeWithStatus(content); 2393 } catch (RemoteException ex) { 2394 } catch (NullPointerException ex) { 2395 } 2396 return ""; 2397 } 2398 2399 /** 2400 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}. 2401 * Used for device configuration by some CDMA operators. 2402 * 2403 * @param itemID the ID of the item to read. 2404 * @return the NV item as a String, or null on any failure. 2405 * @hide 2406 */ 2407 public String nvReadItem(int itemID) { 2408 try { 2409 return getITelephony().nvReadItem(itemID); 2410 } catch (RemoteException ex) { 2411 Rlog.e(TAG, "nvReadItem RemoteException", ex); 2412 } catch (NullPointerException ex) { 2413 Rlog.e(TAG, "nvReadItem NPE", ex); 2414 } 2415 return ""; 2416 } 2417 2418 2419 /** 2420 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}. 2421 * Used for device configuration by some CDMA operators. 2422 * 2423 * @param itemID the ID of the item to read. 2424 * @param itemValue the value to write, as a String. 2425 * @return true on success; false on any failure. 2426 * @hide 2427 */ 2428 public boolean nvWriteItem(int itemID, String itemValue) { 2429 try { 2430 return getITelephony().nvWriteItem(itemID, itemValue); 2431 } catch (RemoteException ex) { 2432 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 2433 } catch (NullPointerException ex) { 2434 Rlog.e(TAG, "nvWriteItem NPE", ex); 2435 } 2436 return false; 2437 } 2438 2439 /** 2440 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 2441 * Used for device configuration by some CDMA operators. 2442 * 2443 * @param preferredRoamingList byte array containing the new PRL. 2444 * @return true on success; false on any failure. 2445 * @hide 2446 */ 2447 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 2448 try { 2449 return getITelephony().nvWriteCdmaPrl(preferredRoamingList); 2450 } catch (RemoteException ex) { 2451 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 2452 } catch (NullPointerException ex) { 2453 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 2454 } 2455 return false; 2456 } 2457 2458 /** 2459 * Perform the specified type of NV config reset. The radio will be taken offline 2460 * and the device must be rebooted after the operation. Used for device 2461 * configuration by some CDMA operators. 2462 * 2463 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 2464 * @return true on success; false on any failure. 2465 * @hide 2466 */ 2467 public boolean nvResetConfig(int resetType) { 2468 try { 2469 return getITelephony().nvResetConfig(resetType); 2470 } catch (RemoteException ex) { 2471 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 2472 } catch (NullPointerException ex) { 2473 Rlog.e(TAG, "nvResetConfig NPE", ex); 2474 } 2475 return false; 2476 } 2477 2478 /** 2479 * Returns Default subscription. 2480 */ 2481 private static long getDefaultSubscription() { 2482 return SubscriptionManager.getDefaultSubId(); 2483 } 2484 2485 /** {@hide} */ 2486 public int getDefaultSim() { 2487 //TODO Need to get it from Telephony Devcontroller 2488 return 0; 2489 } 2490 2491 /** 2492 * Sets the telephony property with the value specified. 2493 * 2494 * @hide 2495 */ 2496 public static void setTelephonyProperty(String property, long subId, String value) { 2497 String propVal = ""; 2498 String p[] = null; 2499 String prop = SystemProperties.get(property); 2500 int phoneId = SubscriptionManager.getPhoneId(subId); 2501 2502 if (value == null) { 2503 value = ""; 2504 } 2505 2506 if (prop != null) { 2507 p = prop.split(","); 2508 } 2509 2510 if (phoneId < 0) return; 2511 2512 for (int i = 0; i < phoneId; i++) { 2513 String str = ""; 2514 if ((p != null) && (i < p.length)) { 2515 str = p[i]; 2516 } 2517 propVal = propVal + str + ","; 2518 } 2519 2520 propVal = propVal + value; 2521 if (p != null) { 2522 for (int i = phoneId + 1; i < p.length; i++) { 2523 propVal = propVal + "," + p[i]; 2524 } 2525 } 2526 2527 // TODO: workaround for QC 2528 if (property.length() > SystemProperties.PROP_NAME_MAX || propVal.length() > SystemProperties.PROP_VALUE_MAX) { 2529 Rlog.d(TAG, "setTelephonyProperty length too long:" + property + ", " + propVal); 2530 return; 2531 } 2532 2533 Rlog.d(TAG, "setTelephonyProperty property=" + property + " propVal=" + propVal); 2534 SystemProperties.set(property, propVal); 2535 } 2536 2537 /** 2538 * Convenience function for retrieving a value from the secure settings 2539 * value list as an integer. Note that internally setting values are 2540 * always stored as strings; this function converts the string to an 2541 * integer for you. 2542 * <p> 2543 * This version does not take a default value. If the setting has not 2544 * been set, or the string value is not a number, 2545 * it throws {@link SettingNotFoundException}. 2546 * 2547 * @param cr The ContentResolver to access. 2548 * @param name The name of the setting to retrieve. 2549 * @param index The index of the list 2550 * 2551 * @throws SettingNotFoundException Thrown if a setting by the given 2552 * name can't be found or the setting value is not an integer. 2553 * 2554 * @return The value at the given index of settings. 2555 * @hide 2556 */ 2557 public static int getIntAtIndex(android.content.ContentResolver cr, 2558 String name, int index) 2559 throws android.provider.Settings.SettingNotFoundException { 2560 String v = android.provider.Settings.Global.getString(cr, name); 2561 if (v != null) { 2562 String valArray[] = v.split(","); 2563 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 2564 try { 2565 return Integer.parseInt(valArray[index]); 2566 } catch (NumberFormatException e) { 2567 //Log.e(TAG, "Exception while parsing Integer: ", e); 2568 } 2569 } 2570 } 2571 throw new android.provider.Settings.SettingNotFoundException(name); 2572 } 2573 2574 /** 2575 * Convenience function for updating settings value as coma separated 2576 * integer values. This will either create a new entry in the table if the 2577 * given name does not exist, or modify the value of the existing row 2578 * with that name. Note that internally setting values are always 2579 * stored as strings, so this function converts the given value to a 2580 * string before storing it. 2581 * 2582 * @param cr The ContentResolver to access. 2583 * @param name The name of the setting to modify. 2584 * @param index The index of the list 2585 * @param value The new value for the setting to be added to the list. 2586 * @return true if the value was set, false on database errors 2587 * @hide 2588 */ 2589 public static boolean putIntAtIndex(android.content.ContentResolver cr, 2590 String name, int index, int value) { 2591 String data = ""; 2592 String valArray[] = null; 2593 String v = android.provider.Settings.Global.getString(cr, name); 2594 2595 if (v != null) { 2596 valArray = v.split(","); 2597 } 2598 2599 // Copy the elements from valArray till index 2600 for (int i = 0; i < index; i++) { 2601 String str = ""; 2602 if ((valArray != null) && (i < valArray.length)) { 2603 str = valArray[i]; 2604 } 2605 data = data + str + ","; 2606 } 2607 2608 data = data + value; 2609 2610 // Copy the remaining elements from valArray if any. 2611 if (valArray != null) { 2612 for (int i = index+1; i < valArray.length; i++) { 2613 data = data + "," + valArray[i]; 2614 } 2615 } 2616 return android.provider.Settings.Global.putString(cr, name, data); 2617 } 2618 2619 /** 2620 * Gets the telephony property. 2621 * 2622 * @hide 2623 */ 2624 public static String getTelephonyProperty(String property, long subId, String defaultVal) { 2625 String propVal = null; 2626 int phoneId = SubscriptionManager.getPhoneId(subId); 2627 String prop = SystemProperties.get(property); 2628 if ((prop != null) && (prop.length() > 0)) { 2629 String values[] = prop.split(","); 2630 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 2631 propVal = values[phoneId]; 2632 } 2633 } 2634 return propVal == null ? defaultVal : propVal; 2635 } 2636 2637 /** @hide */ 2638 public int getSimCount() { 2639 if(isMultiSimEnabled()) { 2640 //TODO Need to get it from Telephony Devcontroller 2641 return 2; 2642 } else { 2643 return 1; 2644 } 2645 } 2646 2647 /** 2648 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 2649 * @return IMS Service Table or null if not present or not loaded 2650 * @hide 2651 */ 2652 public String getIsimIst() { 2653 try { 2654 return getSubscriberInfo().getIsimIst(); 2655 } catch (RemoteException ex) { 2656 return null; 2657 } catch (NullPointerException ex) { 2658 // This could happen before phone restarts due to crashing 2659 return null; 2660 } 2661 } 2662 2663 /** 2664 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 2665 * @return an array of PCSCF strings with one PCSCF per string, or null if 2666 * not present or not loaded 2667 * @hide 2668 */ 2669 public String[] getIsimPcscf() { 2670 try { 2671 return getSubscriberInfo().getIsimPcscf(); 2672 } catch (RemoteException ex) { 2673 return null; 2674 } catch (NullPointerException ex) { 2675 // This could happen before phone restarts due to crashing 2676 return null; 2677 } 2678 } 2679 2680 /** 2681 * Returns the response of ISIM Authetification through RIL. 2682 * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo. 2683 * @return the response of ISIM Authetification, or null if not available 2684 * @hide 2685 * @deprecated 2686 * @see getIccSimChallengeResponse with appType=PhoneConstants.APPTYPE_ISIM 2687 */ 2688 public String getIsimChallengeResponse(String nonce){ 2689 try { 2690 return getSubscriberInfo().getIsimChallengeResponse(nonce); 2691 } catch (RemoteException ex) { 2692 return null; 2693 } catch (NullPointerException ex) { 2694 // This could happen before phone restarts due to crashing 2695 return null; 2696 } 2697 } 2698 2699 /** 2700 * Returns the response of SIM Authentication through RIL. 2701 * Returns null if the Authentication hasn't been successful 2702 * @param subId subscription ID to be queried 2703 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 2704 * @param data authentication challenge data 2705 * @return the response of SIM Authentication, or null if not available 2706 * @hide 2707 */ 2708 public String getIccSimChallengeResponse(long subId, int appType, String data) { 2709 try { 2710 return getSubscriberInfo().getIccSimChallengeResponse(subId, appType, data); 2711 } catch (RemoteException ex) { 2712 return null; 2713 } catch (NullPointerException ex) { 2714 // This could happen before phone starts 2715 return null; 2716 } 2717 } 2718 2719 /** 2720 * Returns the response of SIM Authentication through RIL for the default subscription. 2721 * Returns null if the Authentication hasn't been successful 2722 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 2723 * @param data authentication challenge data 2724 * @return the response of SIM Authentication, or null if not available 2725 * @hide 2726 */ 2727 public String getIccSimChallengeResponse(int appType, String data) { 2728 return getIccSimChallengeResponse(getDefaultSubscription(), appType, data); 2729 } 2730 2731 /** 2732 * Get P-CSCF address from PCO after data connection is established or modified. 2733 * 2734 * @return array of P-CSCF address 2735 * @hide 2736 */ 2737 public String[] getPcscfAddress() { 2738 try { 2739 return getITelephony().getPcscfAddress(); 2740 } catch (RemoteException e) { 2741 return new String[0]; 2742 } 2743 } 2744 2745 /** 2746 * Set IMS registration state 2747 * 2748 * @param Registration state 2749 * @hide 2750 */ 2751 public void setImsRegistrationState(boolean registered) { 2752 try { 2753 getITelephony().setImsRegistrationState(registered); 2754 } catch (RemoteException e) { 2755 } 2756 } 2757 2758 /** 2759 * Get the calculated preferred network type. 2760 * Used for debugging incorrect network type. 2761 * 2762 * @return the preferred network type, defined in RILConstants.java or -1 if 2763 * none available. 2764 * @hide 2765 */ 2766 public int getCalculatedPreferredNetworkType() { 2767 try { 2768 return getITelephony().getCalculatedPreferredNetworkType(); 2769 } catch (RemoteException ex) { 2770 Rlog.e(TAG, "getCalculatedPreferredNetworkType RemoteException", ex); 2771 } catch (NullPointerException ex) { 2772 Rlog.e(TAG, "getCalculatedPreferredNetworkType NPE", ex); 2773 } 2774 return -1; 2775 } 2776 2777 /** 2778 * Get the preferred network type. 2779 * Used for device configuration by some CDMA operators. 2780 * 2781 * @return the preferred network type, defined in RILConstants.java. 2782 * @hide 2783 */ 2784 public int getPreferredNetworkType() { 2785 try { 2786 return getITelephony().getPreferredNetworkType(); 2787 } catch (RemoteException ex) { 2788 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 2789 } catch (NullPointerException ex) { 2790 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 2791 } 2792 return -1; 2793 } 2794 2795 /** 2796 * Set the preferred network type. 2797 * Used for device configuration by some CDMA operators. 2798 * 2799 * @param networkType the preferred network type, defined in RILConstants.java. 2800 * @return true on success; false on any failure. 2801 * @hide 2802 */ 2803 public boolean setPreferredNetworkType(int networkType) { 2804 try { 2805 return getITelephony().setPreferredNetworkType(networkType); 2806 } catch (RemoteException ex) { 2807 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 2808 } catch (NullPointerException ex) { 2809 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 2810 } 2811 return false; 2812 } 2813 2814 /** 2815 * Set the CDMA subscription source. 2816 * Used for device supporting both NV and RUIM for CDMA. 2817 * 2818 * @param subscriptionType the subscription type, 0 for RUIM, 1 for NV. 2819 * @return true on success; false on any failure. 2820 * @hide 2821 */ 2822 public boolean setCdmaSubscription(int subscriptionType) { 2823 try { 2824 return getITelephony().setCdmaSubscription(subscriptionType); 2825 } catch (RemoteException ex) { 2826 Rlog.e(TAG, "setCdmaSubscription RemoteException", ex); 2827 } catch (NullPointerException ex) { 2828 Rlog.e(TAG, "setCdmaSubscription NPE", ex); 2829 } 2830 return false; 2831 } 2832 2833 /** 2834 * Values used to return status for hasCarrierPrivileges call. 2835 */ 2836 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 2837 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 2838 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 2839 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 2840 2841 /** 2842 * Has the calling application been granted carrier privileges by the carrier. 2843 * 2844 * If any of the packages in the calling UID has carrier privileges, the 2845 * call will return true. This access is granted by the owner of the UICC 2846 * card and does not depend on the registered carrier. 2847 * 2848 * TODO: Add a link to documentation. 2849 * 2850 * @return CARRIER_PRIVILEGE_STATUS_HAS_ACCESS if the app has carrier privileges. 2851 * CARRIER_PRIVILEGE_STATUS_NO_ACCESS if the app does not have carrier privileges. 2852 * CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED if the carrier rules are not loaded. 2853 * CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES if there was an error loading carrier 2854 * rules (or if there are no rules). 2855 */ 2856 public int hasCarrierPrivileges() { 2857 try { 2858 return getITelephony().hasCarrierPrivileges(); 2859 } catch (RemoteException ex) { 2860 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 2861 } catch (NullPointerException ex) { 2862 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 2863 } 2864 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 2865 } 2866 2867 /** 2868 * Expose the rest of ITelephony to @SystemApi 2869 */ 2870 2871 /** @hide */ 2872 @SystemApi 2873 public int hasCarrierPrivileges(String pkgname) { 2874 try { 2875 return getITelephony().hasCarrierPrivileges(pkgname); 2876 } catch (RemoteException ex) { 2877 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 2878 } catch (NullPointerException ex) { 2879 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 2880 } 2881 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 2882 } 2883 /** @hide */ 2884 2885 @SystemApi 2886 public void dial(String number) { 2887 try { 2888 getITelephony().dial(number); 2889 } catch (RemoteException e) { 2890 Log.e(TAG, "Error calling ITelephony#dial", e); 2891 } 2892 } 2893 2894 /** @hide */ 2895 @SystemApi 2896 public void call(String callingPackage, String number) { 2897 try { 2898 getITelephony().call(callingPackage, number); 2899 } catch (RemoteException e) { 2900 Log.e(TAG, "Error calling ITelephony#call", e); 2901 } 2902 } 2903 2904 /** @hide */ 2905 @SystemApi 2906 public boolean endCall() { 2907 try { 2908 return getITelephony().endCall(); 2909 } catch (RemoteException e) { 2910 Log.e(TAG, "Error calling ITelephony#endCall", e); 2911 } 2912 return false; 2913 } 2914 2915 /** @hide */ 2916 @SystemApi 2917 public void answerRingingCall() { 2918 try { 2919 getITelephony().answerRingingCall(); 2920 } catch (RemoteException e) { 2921 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 2922 } 2923 } 2924 2925 /** @hide */ 2926 @SystemApi 2927 public void silenceRinger() { 2928 try { 2929 getTelecommService().silenceRinger(); 2930 } catch (RemoteException e) { 2931 Log.e(TAG, "Error calling ITelecommService#silenceRinger", e); 2932 } 2933 } 2934 2935 /** @hide */ 2936 @SystemApi 2937 public boolean isOffhook() { 2938 try { 2939 return getITelephony().isOffhook(); 2940 } catch (RemoteException e) { 2941 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 2942 } 2943 return false; 2944 } 2945 2946 /** @hide */ 2947 @SystemApi 2948 public boolean isRinging() { 2949 try { 2950 return getITelephony().isRinging(); 2951 } catch (RemoteException e) { 2952 Log.e(TAG, "Error calling ITelephony#isRinging", e); 2953 } 2954 return false; 2955 } 2956 2957 /** @hide */ 2958 @SystemApi 2959 public boolean isIdle() { 2960 try { 2961 return getITelephony().isIdle(); 2962 } catch (RemoteException e) { 2963 Log.e(TAG, "Error calling ITelephony#isIdle", e); 2964 } 2965 return true; 2966 } 2967 2968 /** @hide */ 2969 @SystemApi 2970 public boolean isRadioOn() { 2971 try { 2972 return getITelephony().isRadioOn(); 2973 } catch (RemoteException e) { 2974 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 2975 } 2976 return false; 2977 } 2978 2979 /** @hide */ 2980 @SystemApi 2981 public boolean isSimPinEnabled() { 2982 try { 2983 return getITelephony().isSimPinEnabled(); 2984 } catch (RemoteException e) { 2985 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 2986 } 2987 return false; 2988 } 2989 2990 /** @hide */ 2991 @SystemApi 2992 public boolean supplyPin(String pin) { 2993 try { 2994 return getITelephony().supplyPin(pin); 2995 } catch (RemoteException e) { 2996 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 2997 } 2998 return false; 2999 } 3000 3001 /** @hide */ 3002 @SystemApi 3003 public boolean supplyPuk(String puk, String pin) { 3004 try { 3005 return getITelephony().supplyPuk(puk, pin); 3006 } catch (RemoteException e) { 3007 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 3008 } 3009 return false; 3010 } 3011 3012 /** @hide */ 3013 @SystemApi 3014 public int[] supplyPinReportResult(String pin) { 3015 try { 3016 return getITelephony().supplyPinReportResult(pin); 3017 } catch (RemoteException e) { 3018 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 3019 } 3020 return new int[0]; 3021 } 3022 3023 /** @hide */ 3024 @SystemApi 3025 public int[] supplyPukReportResult(String puk, String pin) { 3026 try { 3027 return getITelephony().supplyPukReportResult(puk, pin); 3028 } catch (RemoteException e) { 3029 Log.e(TAG, "Error calling ITelephony#]", e); 3030 } 3031 return new int[0]; 3032 } 3033 3034 /** @hide */ 3035 @SystemApi 3036 public boolean handlePinMmi(String dialString) { 3037 try { 3038 return getITelephony().handlePinMmi(dialString); 3039 } catch (RemoteException e) { 3040 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3041 } 3042 return false; 3043 } 3044 3045 /** @hide */ 3046 @SystemApi 3047 public void toggleRadioOnOff() { 3048 try { 3049 getITelephony().toggleRadioOnOff(); 3050 } catch (RemoteException e) { 3051 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 3052 } 3053 } 3054 3055 /** @hide */ 3056 @SystemApi 3057 public boolean setRadio(boolean turnOn) { 3058 try { 3059 return getITelephony().setRadio(turnOn); 3060 } catch (RemoteException e) { 3061 Log.e(TAG, "Error calling ITelephony#setRadio", e); 3062 } 3063 return false; 3064 } 3065 3066 /** @hide */ 3067 @SystemApi 3068 public boolean setRadioPower(boolean turnOn) { 3069 try { 3070 return getITelephony().setRadioPower(turnOn); 3071 } catch (RemoteException e) { 3072 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 3073 } 3074 return false; 3075 } 3076 3077 /** @hide */ 3078 @SystemApi 3079 public void updateServiceLocation() { 3080 try { 3081 getITelephony().updateServiceLocation(); 3082 } catch (RemoteException e) { 3083 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 3084 } 3085 } 3086 3087 /** @hide */ 3088 @SystemApi 3089 public boolean enableDataConnectivity() { 3090 try { 3091 return getITelephony().enableDataConnectivity(); 3092 } catch (RemoteException e) { 3093 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 3094 } 3095 return false; 3096 } 3097 3098 /** @hide */ 3099 @SystemApi 3100 public boolean disableDataConnectivity() { 3101 try { 3102 return getITelephony().disableDataConnectivity(); 3103 } catch (RemoteException e) { 3104 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 3105 } 3106 return false; 3107 } 3108 3109 /** @hide */ 3110 @SystemApi 3111 public boolean isDataConnectivityPossible() { 3112 try { 3113 return getITelephony().isDataConnectivityPossible(); 3114 } catch (RemoteException e) { 3115 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 3116 } 3117 return false; 3118 } 3119 3120 /** @hide */ 3121 @SystemApi 3122 public boolean needsOtaServiceProvisioning() { 3123 try { 3124 return getITelephony().needsOtaServiceProvisioning(); 3125 } catch (RemoteException e) { 3126 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 3127 } 3128 return false; 3129 } 3130 3131 /** @hide */ 3132 @SystemApi 3133 public void setDataEnabled(boolean enable) { 3134 try { 3135 getITelephony().setDataEnabled(enable); 3136 } catch (RemoteException e) { 3137 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 3138 } 3139 } 3140 3141 /** @hide */ 3142 @SystemApi 3143 public boolean getDataEnabled() { 3144 try { 3145 return getITelephony().getDataEnabled(); 3146 } catch (RemoteException e) { 3147 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 3148 } 3149 return false; 3150 } 3151 3152 /** 3153 * Return a list of Accounts that can be used to indicate a preference when making 3154 * a phone call. 3155 * 3156 * @see #EXTRA_ACCOUNT 3157 * @return A list of {@code Accouint} objects. 3158 */ 3159 public List<PhoneAccount> getAccounts() { 3160 try { 3161 return getTelecommService().getAccounts(); 3162 } catch (RemoteException e) { 3163 Log.e(TAG, "Error calling ITelephony#getAccounts", e); 3164 } 3165 return null; 3166 } 3167 3168 /** @hide */ 3169 @SystemApi 3170 public void setEnabled(PhoneAccount account, boolean enabled) { 3171 try { 3172 getTelecommService().setEnabled(account, enabled); 3173 } catch (RemoteException e) { 3174 Log.e(TAG, "Error calling ITelephony#setEnabled", e); 3175 } 3176 } 3177 3178 /** @hide */ 3179 @SystemApi 3180 public void setSystemDefault(PhoneAccount account) { 3181 try { 3182 getTelecommService().setSystemDefault(account); 3183 } catch (RemoteException e) { 3184 Log.e(TAG, "Error calling ITelephony#setSystemDefault", e); 3185 } 3186 } 3187} 3188