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