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