TelephonyManager.java revision dbc6689664156a42ecd2b4bd53ffd772e276bf63
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.telephony; 18 19import android.annotation.SystemApi; 20import android.annotation.SdkConstant; 21import android.annotation.SdkConstant.SdkConstantType; 22import android.content.Context; 23import android.content.Intent; 24import android.os.Bundle; 25import android.os.RemoteException; 26import android.os.ServiceManager; 27import android.os.SystemProperties; 28import android.util.Log; 29import android.util.Pair; 30 31import com.android.internal.telecomm.ITelecommService; 32import com.android.internal.telephony.IPhoneSubInfo; 33import com.android.internal.telephony.ITelephony; 34import com.android.internal.telephony.ITelephonyRegistry; 35import com.android.internal.telephony.PhoneConstants; 36import com.android.internal.telephony.RILConstants; 37import com.android.internal.telephony.TelephonyProperties; 38 39import java.io.FileInputStream; 40import java.io.IOException; 41import java.util.List; 42import java.util.regex.Matcher; 43import java.util.regex.Pattern; 44 45/** 46 * Provides access to information about the telephony services on 47 * the device. Applications can use the methods in this class to 48 * determine telephony services and states, as well as to access some 49 * types of subscriber information. Applications can also register 50 * a listener to receive notification of telephony state changes. 51 * <p> 52 * You do not instantiate this class directly; instead, you retrieve 53 * a reference to an instance through 54 * {@link android.content.Context#getSystemService 55 * Context.getSystemService(Context.TELEPHONY_SERVICE)}. 56 * <p> 57 * Note that access to some telephony information is 58 * permission-protected. Your application cannot access the protected 59 * information unless it has the appropriate permissions declared in 60 * its manifest file. Where permissions apply, they are noted in the 61 * the methods through which you access the protected information. 62 */ 63public class TelephonyManager { 64 private static final String TAG = "TelephonyManager"; 65 66 private static final String TELECOMM_SERVICE_NAME = "telecomm"; 67 68 private static ITelephonyRegistry sRegistry; 69 70 /** 71 * The allowed states of Wi-Fi calling. 72 * 73 * @hide 74 */ 75 public interface WifiCallingChoices { 76 /** Always use Wi-Fi calling */ 77 static final int ALWAYS_USE = 0; 78 /** Ask the user whether to use Wi-Fi on every call */ 79 static final int ASK_EVERY_TIME = 1; 80 /** Never use Wi-Fi calling */ 81 static final int NEVER_USE = 2; 82 } 83 84 private final Context mContext; 85 86 private static String multiSimConfig = 87 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 88 89 /** Enum indicating multisim variants 90 * DSDS - Dual SIM Dual Standby 91 * DSDA - Dual SIM Dual Active 92 * TSTS - Triple SIM Triple Standby 93 **/ 94 /** @hide */ 95 public enum MultiSimVariants { 96 DSDS, 97 DSDA, 98 TSTS, 99 UNKNOWN 100 }; 101 102 /** @hide */ 103 public TelephonyManager(Context context) { 104 Context appContext = context.getApplicationContext(); 105 if (appContext != null) { 106 mContext = appContext; 107 } else { 108 mContext = context; 109 } 110 111 if (sRegistry == null) { 112 sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService( 113 "telephony.registry")); 114 } 115 } 116 117 /** @hide */ 118 private TelephonyManager() { 119 mContext = null; 120 } 121 122 private static TelephonyManager sInstance = new TelephonyManager(); 123 124 /** @hide 125 /* @deprecated - use getSystemService as described above */ 126 public static TelephonyManager getDefault() { 127 return sInstance; 128 } 129 130 131 /** 132 * Returns the multi SIM variant 133 * Returns DSDS for Dual SIM Dual Standby 134 * Returns DSDA for Dual SIM Dual Active 135 * Returns TSTS for Triple SIM Triple Standby 136 * Returns UNKNOWN for others 137 */ 138 /** {@hide} */ 139 public MultiSimVariants getMultiSimConfiguration() { 140 String mSimConfig = 141 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 142 if (mSimConfig.equals("dsds")) { 143 return MultiSimVariants.DSDS; 144 } else if (mSimConfig.equals("dsda")) { 145 return MultiSimVariants.DSDA; 146 } else if (mSimConfig.equals("tsts")) { 147 return MultiSimVariants.TSTS; 148 } else { 149 return MultiSimVariants.UNKNOWN; 150 } 151 } 152 153 154 /** 155 * Returns the number of phones available. 156 * Returns 1 for Single standby mode (Single SIM functionality) 157 * Returns 2 for Dual standby mode.(Dual SIM functionality) 158 */ 159 /** {@hide} */ 160 public int getPhoneCount() { 161 int phoneCount = 1; 162 switch (getMultiSimConfiguration()) { 163 case DSDS: 164 case DSDA: 165 phoneCount = PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM; 166 break; 167 case TSTS: 168 phoneCount = PhoneConstants.MAX_PHONE_COUNT_TRI_SIM; 169 break; 170 } 171 return phoneCount; 172 } 173 174 /** {@hide} */ 175 public static TelephonyManager from(Context context) { 176 return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 177 } 178 179 /** {@hide} */ 180 public boolean isMultiSimEnabled() { 181 return (multiSimConfig.equals("dsds") || multiSimConfig.equals("dsda") || 182 multiSimConfig.equals("tsts")); 183 } 184 185 // 186 // Broadcast Intent actions 187 // 188 189 /** 190 * Broadcast intent action indicating that the call state (cellular) 191 * on the device has changed. 192 * 193 * <p> 194 * The {@link #EXTRA_STATE} extra indicates the new call state. 195 * If the new state is RINGING, a second extra 196 * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as 197 * a String. 198 * 199 * <p class="note"> 200 * Requires the READ_PHONE_STATE permission. 201 * 202 * <p class="note"> 203 * This was a {@link android.content.Context#sendStickyBroadcast sticky} 204 * broadcast in version 1.0, but it is no longer sticky. 205 * Instead, use {@link #getCallState} to synchronously query the current call state. 206 * 207 * @see #EXTRA_STATE 208 * @see #EXTRA_INCOMING_NUMBER 209 * @see #getCallState 210 */ 211 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 212 public static final String ACTION_PHONE_STATE_CHANGED = 213 "android.intent.action.PHONE_STATE"; 214 215 /** 216 * The Phone app sends this intent when a user opts to respond-via-message during an incoming 217 * call. By default, the device's default SMS app consumes this message and sends a text message 218 * to the caller. A third party app can also provide this functionality by consuming this Intent 219 * with a {@link android.app.Service} and sending the message using its own messaging system. 220 * <p>The intent contains a URI (available from {@link android.content.Intent#getData}) 221 * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:}, 222 * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the 223 * same way: the path part of the URI contains the recipient's phone number or a comma-separated 224 * set of phone numbers if there are multiple recipients. For example, {@code 225 * smsto:2065551234}.</p> 226 * 227 * <p>The intent may also contain extras for the message text (in {@link 228 * android.content.Intent#EXTRA_TEXT}) and a message subject 229 * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p> 230 * 231 * <p class="note"><strong>Note:</strong> 232 * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service} 233 * that requires the 234 * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p> 235 * <p>For example, the service that receives this intent can be declared in the manifest file 236 * with an intent filter like this:</p> 237 * <pre> 238 * <!-- Service that delivers SMS messages received from the phone "quick response" --> 239 * <service android:name=".HeadlessSmsSendService" 240 * android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" 241 * android:exported="true" > 242 * <intent-filter> 243 * <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /> 244 * <category android:name="android.intent.category.DEFAULT" /> 245 * <data android:scheme="sms" /> 246 * <data android:scheme="smsto" /> 247 * <data android:scheme="mms" /> 248 * <data android:scheme="mmsto" /> 249 * </intent-filter> 250 * </service></pre> 251 * <p> 252 * Output: nothing. 253 */ 254 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 255 public static final String ACTION_RESPOND_VIA_MESSAGE = 256 "android.intent.action.RESPOND_VIA_MESSAGE"; 257 258 /** 259 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 260 * for a String containing the new call state. 261 * 262 * @see #EXTRA_STATE_IDLE 263 * @see #EXTRA_STATE_RINGING 264 * @see #EXTRA_STATE_OFFHOOK 265 * 266 * <p class="note"> 267 * Retrieve with 268 * {@link android.content.Intent#getStringExtra(String)}. 269 */ 270 public static final String EXTRA_STATE = PhoneConstants.STATE_KEY; 271 272 /** 273 * Value used with {@link #EXTRA_STATE} corresponding to 274 * {@link #CALL_STATE_IDLE}. 275 */ 276 public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString(); 277 278 /** 279 * Value used with {@link #EXTRA_STATE} corresponding to 280 * {@link #CALL_STATE_RINGING}. 281 */ 282 public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString(); 283 284 /** 285 * Value used with {@link #EXTRA_STATE} corresponding to 286 * {@link #CALL_STATE_OFFHOOK}. 287 */ 288 public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString(); 289 290 /** 291 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 292 * for a String containing the incoming phone number. 293 * Only valid when the new call state is RINGING. 294 * 295 * <p class="note"> 296 * Retrieve with 297 * {@link android.content.Intent#getStringExtra(String)}. 298 */ 299 public static final String EXTRA_INCOMING_NUMBER = "incoming_number"; 300 301 /** 302 * Broadcast intent action indicating that a precise call state 303 * (cellular) on the device has changed. 304 * 305 * <p> 306 * The {@link #EXTRA_RINGING_CALL_STATE} extra indicates the ringing call state. 307 * The {@link #EXTRA_FOREGROUND_CALL_STATE} extra indicates the foreground call state. 308 * The {@link #EXTRA_BACKGROUND_CALL_STATE} extra indicates the background call state. 309 * The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause. 310 * The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause. 311 * 312 * <p class="note"> 313 * Requires the READ_PRECISE_PHONE_STATE permission. 314 * 315 * @see #EXTRA_RINGING_CALL_STATE 316 * @see #EXTRA_FOREGROUND_CALL_STATE 317 * @see #EXTRA_BACKGROUND_CALL_STATE 318 * @see #EXTRA_DISCONNECT_CAUSE 319 * @see #EXTRA_PRECISE_DISCONNECT_CAUSE 320 * 321 * <p class="note"> 322 * Requires the READ_PRECISE_PHONE_STATE permission. 323 * 324 * @hide 325 */ 326 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 327 public static final String ACTION_PRECISE_CALL_STATE_CHANGED = 328 "android.intent.action.PRECISE_CALL_STATE"; 329 330 /** 331 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 332 * for an integer containing the state of the current ringing call. 333 * 334 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 335 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 336 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 337 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 338 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 339 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 340 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 341 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 342 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 343 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 344 * 345 * <p class="note"> 346 * Retrieve with 347 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 348 * 349 * @hide 350 */ 351 public static final String EXTRA_RINGING_CALL_STATE = "ringing_state"; 352 353 /** 354 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 355 * for an integer containing the state of the current foreground call. 356 * 357 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 358 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 359 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 360 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 361 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 362 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 363 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 364 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 365 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 366 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 367 * 368 * <p class="note"> 369 * Retrieve with 370 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 371 * 372 * @hide 373 */ 374 public static final String EXTRA_FOREGROUND_CALL_STATE = "foreground_state"; 375 376 /** 377 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 378 * for an integer containing the state of the current background call. 379 * 380 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 381 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 382 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 383 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 384 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 385 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 386 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 387 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 388 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 389 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 390 * 391 * <p class="note"> 392 * Retrieve with 393 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 394 * 395 * @hide 396 */ 397 public static final String EXTRA_BACKGROUND_CALL_STATE = "background_state"; 398 399 /** 400 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 401 * for an integer containing the disconnect cause. 402 * 403 * @see DisconnectCause 404 * 405 * <p class="note"> 406 * Retrieve with 407 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 408 * 409 * @hide 410 */ 411 public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause"; 412 413 /** 414 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 415 * for an integer containing the disconnect cause provided by the RIL. 416 * 417 * @see PreciseDisconnectCause 418 * 419 * <p class="note"> 420 * Retrieve with 421 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 422 * 423 * @hide 424 */ 425 public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause"; 426 427 /** 428 * Broadcast intent action indicating a data connection has changed, 429 * providing precise information about the connection. 430 * 431 * <p> 432 * The {@link #EXTRA_DATA_STATE} extra indicates the connection state. 433 * The {@link #EXTRA_DATA_NETWORK_TYPE} extra indicates the connection network type. 434 * The {@link #EXTRA_DATA_APN_TYPE} extra indicates the APN type. 435 * The {@link #EXTRA_DATA_APN} extra indicates the APN. 436 * The {@link #EXTRA_DATA_CHANGE_REASON} extra indicates the connection change reason. 437 * The {@link #EXTRA_DATA_IFACE_PROPERTIES} extra indicates the connection interface. 438 * The {@link #EXTRA_DATA_FAILURE_CAUSE} extra indicates the connection fail cause. 439 * 440 * <p class="note"> 441 * Requires the READ_PRECISE_PHONE_STATE permission. 442 * 443 * @see #EXTRA_DATA_STATE 444 * @see #EXTRA_DATA_NETWORK_TYPE 445 * @see #EXTRA_DATA_APN_TYPE 446 * @see #EXTRA_DATA_APN 447 * @see #EXTRA_DATA_CHANGE_REASON 448 * @see #EXTRA_DATA_IFACE 449 * @see #EXTRA_DATA_FAILURE_CAUSE 450 * @hide 451 */ 452 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 453 public static final String ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED = 454 "android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED"; 455 456 /** 457 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 458 * for an integer containing the state of the current data connection. 459 * 460 * @see TelephonyManager#DATA_UNKNOWN 461 * @see TelephonyManager#DATA_DISCONNECTED 462 * @see TelephonyManager#DATA_CONNECTING 463 * @see TelephonyManager#DATA_CONNECTED 464 * @see TelephonyManager#DATA_SUSPENDED 465 * 466 * <p class="note"> 467 * Retrieve with 468 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 469 * 470 * @hide 471 */ 472 public static final String EXTRA_DATA_STATE = PhoneConstants.STATE_KEY; 473 474 /** 475 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 476 * for an integer containing the network type. 477 * 478 * @see TelephonyManager#NETWORK_TYPE_UNKNOWN 479 * @see TelephonyManager#NETWORK_TYPE_GPRS 480 * @see TelephonyManager#NETWORK_TYPE_EDGE 481 * @see TelephonyManager#NETWORK_TYPE_UMTS 482 * @see TelephonyManager#NETWORK_TYPE_CDMA 483 * @see TelephonyManager#NETWORK_TYPE_EVDO_0 484 * @see TelephonyManager#NETWORK_TYPE_EVDO_A 485 * @see TelephonyManager#NETWORK_TYPE_1xRTT 486 * @see TelephonyManager#NETWORK_TYPE_HSDPA 487 * @see TelephonyManager#NETWORK_TYPE_HSUPA 488 * @see TelephonyManager#NETWORK_TYPE_HSPA 489 * @see TelephonyManager#NETWORK_TYPE_IDEN 490 * @see TelephonyManager#NETWORK_TYPE_EVDO_B 491 * @see TelephonyManager#NETWORK_TYPE_LTE 492 * @see TelephonyManager#NETWORK_TYPE_EHRPD 493 * @see TelephonyManager#NETWORK_TYPE_HSPAP 494 * 495 * <p class="note"> 496 * Retrieve with 497 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 498 * 499 * @hide 500 */ 501 public static final String EXTRA_DATA_NETWORK_TYPE = PhoneConstants.DATA_NETWORK_TYPE_KEY; 502 503 /** 504 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 505 * for an String containing the data APN type. 506 * 507 * <p class="note"> 508 * Retrieve with 509 * {@link android.content.Intent#getStringExtra(String name)}. 510 * 511 * @hide 512 */ 513 public static final String EXTRA_DATA_APN_TYPE = PhoneConstants.DATA_APN_TYPE_KEY; 514 515 /** 516 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 517 * for an String containing the data APN. 518 * 519 * <p class="note"> 520 * Retrieve with 521 * {@link android.content.Intent#getStringExtra(String name)}. 522 * 523 * @hide 524 */ 525 public static final String EXTRA_DATA_APN = PhoneConstants.DATA_APN_KEY; 526 527 /** 528 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 529 * for an String representation of the change reason. 530 * 531 * <p class="note"> 532 * Retrieve with 533 * {@link android.content.Intent#getStringExtra(String name)}. 534 * 535 * @hide 536 */ 537 public static final String EXTRA_DATA_CHANGE_REASON = PhoneConstants.STATE_CHANGE_REASON_KEY; 538 539 /** 540 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 541 * for an String representation of the data interface. 542 * 543 * <p class="note"> 544 * Retrieve with 545 * {@link android.content.Intent#getParcelableExtra(String name)}. 546 * 547 * @hide 548 */ 549 public static final String EXTRA_DATA_LINK_PROPERTIES_KEY = PhoneConstants.DATA_LINK_PROPERTIES_KEY; 550 551 /** 552 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 553 * for the data connection fail cause. 554 * 555 * <p class="note"> 556 * Retrieve with 557 * {@link android.content.Intent#getStringExtra(String name)}. 558 * 559 * @hide 560 */ 561 public static final String EXTRA_DATA_FAILURE_CAUSE = PhoneConstants.DATA_FAILURE_CAUSE_KEY; 562 563 // 564 // 565 // Device Info 566 // 567 // 568 569 /** 570 * Returns the software version number for the device, for example, 571 * the IMEI/SV for GSM phones. Return null if the software version is 572 * not available. 573 * 574 * <p>Requires Permission: 575 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 576 */ 577 public String getDeviceSoftwareVersion() { 578 try { 579 return getSubscriberInfo().getDeviceSvn(); 580 } catch (RemoteException ex) { 581 return null; 582 } catch (NullPointerException ex) { 583 return null; 584 } 585 } 586 587 /** 588 * Returns the unique device ID, for example, the IMEI for GSM and the MEID 589 * or ESN for CDMA phones. Return null if device ID is not available. 590 * 591 * <p>Requires Permission: 592 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 593 */ 594 public String getDeviceId() { 595 return getDeviceId(getDefaultSim()); 596 } 597 598 /** 599 * Returns the unique device ID of a subscription, for example, the IMEI for 600 * GSM and the MEID for CDMA phones. Return null if device ID is not available. 601 * 602 * <p>Requires Permission: 603 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 604 * 605 * @param slotId of which deviceID is returned 606 */ 607 /** {@hide} */ 608 public String getDeviceId(int slotId) { 609 long[] subId = SubscriptionManager.getSubId(slotId); 610 try { 611 return getSubscriberInfo().getDeviceIdUsingSubId(subId[0]); 612 } catch (RemoteException ex) { 613 return null; 614 } catch (NullPointerException ex) { 615 return null; 616 } 617 } 618 619 /** 620 * Returns the IMEI. Return null if IMEI is not available. 621 * 622 * <p>Requires Permission: 623 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 624 */ 625 /** {@hide} */ 626 public String getImei() { 627 return getImei(getDefaultSim()); 628 } 629 630 /** 631 * Returns the IMEI. Return null if IMEI is not available. 632 * 633 * <p>Requires Permission: 634 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 635 * 636 * @param slotId of which deviceID is returned 637 */ 638 /** {@hide} */ 639 public String getImei(int slotId) { 640 long[] subId = SubscriptionManager.getSubId(slotId); 641 try { 642 return getSubscriberInfo().getImeiUsingSubId(subId[0]); 643 } catch (RemoteException ex) { 644 return null; 645 } catch (NullPointerException ex) { 646 return null; 647 } 648 } 649 650 /** 651 * Returns the current location of the device. 652 *<p> 653 * If there is only one radio in the device and that radio has an LTE connection, 654 * this method will return null. The implementation must not to try add LTE 655 * identifiers into the existing cdma/gsm classes. 656 *<p> 657 * In the future this call will be deprecated. 658 *<p> 659 * @return Current location of the device or null if not available. 660 * 661 * <p>Requires Permission: 662 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or 663 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}. 664 */ 665 public CellLocation getCellLocation() { 666 try { 667 Bundle bundle = getITelephony().getCellLocation(); 668 if (bundle.isEmpty()) return null; 669 CellLocation cl = CellLocation.newFromBundle(bundle); 670 if (cl.isEmpty()) 671 return null; 672 return cl; 673 } catch (RemoteException ex) { 674 return null; 675 } catch (NullPointerException ex) { 676 return null; 677 } 678 } 679 680 /** 681 * Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged 682 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 683 * 684 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 685 * CONTROL_LOCATION_UPDATES} 686 * 687 * @hide 688 */ 689 public void enableLocationUpdates() { 690 enableLocationUpdates(getDefaultSubscription()); 691 } 692 693 /** 694 * Enables location update notifications for a subscription. 695 * {@link PhoneStateListener#onCellLocationChanged 696 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 697 * 698 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 699 * CONTROL_LOCATION_UPDATES} 700 * 701 * @param subId for which the location updates are enabled 702 */ 703 /** @hide */ 704 public void enableLocationUpdates(long subId) { 705 try { 706 getITelephony().enableLocationUpdatesUsingSubId(subId); 707 } catch (RemoteException ex) { 708 } catch (NullPointerException ex) { 709 } 710 } 711 712 /** 713 * Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged 714 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 715 * 716 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 717 * CONTROL_LOCATION_UPDATES} 718 * 719 * @hide 720 */ 721 public void disableLocationUpdates() { 722 disableLocationUpdates(getDefaultSubscription()); 723 } 724 725 /** @hide */ 726 public void disableLocationUpdates(long subId) { 727 try { 728 getITelephony().disableLocationUpdatesUsingSubId(subId); 729 } catch (RemoteException ex) { 730 } catch (NullPointerException ex) { 731 } 732 } 733 734 /** 735 * Returns the neighboring cell information of the device. The getAllCellInfo is preferred 736 * and use this only if getAllCellInfo return nulls or an empty list. 737 *<p> 738 * In the future this call will be deprecated. 739 *<p> 740 * @return List of NeighboringCellInfo or null if info unavailable. 741 * 742 * <p>Requires Permission: 743 * (@link android.Manifest.permission#ACCESS_COARSE_UPDATES} 744 */ 745 public List<NeighboringCellInfo> getNeighboringCellInfo() { 746 try { 747 return getITelephony().getNeighboringCellInfo(mContext.getOpPackageName()); 748 } catch (RemoteException ex) { 749 return null; 750 } catch (NullPointerException ex) { 751 return null; 752 } 753 } 754 755 /** No phone radio. */ 756 public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE; 757 /** Phone radio is GSM. */ 758 public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM; 759 /** Phone radio is CDMA. */ 760 public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA; 761 /** Phone is via SIP. */ 762 public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP; 763 764 /** 765 * Returns the current phone type. 766 * TODO: This is a last minute change and hence hidden. 767 * 768 * @see #PHONE_TYPE_NONE 769 * @see #PHONE_TYPE_GSM 770 * @see #PHONE_TYPE_CDMA 771 * @see #PHONE_TYPE_SIP 772 * 773 * {@hide} 774 */ 775 public int getCurrentPhoneType() { 776 return getCurrentPhoneType(getDefaultSubscription()); 777 } 778 779 /** 780 * Returns a constant indicating the device phone type for a subscription. 781 * 782 * @see #PHONE_TYPE_NONE 783 * @see #PHONE_TYPE_GSM 784 * @see #PHONE_TYPE_CDMA 785 * 786 * @param subId for which phone type is returned 787 */ 788 /** {@hide} */ 789 public int getCurrentPhoneType(long subId) { 790 791 try{ 792 ITelephony telephony = getITelephony(); 793 if (telephony != null) { 794 return telephony.getActivePhoneTypeUsingSubId(subId); 795 } else { 796 // This can happen when the ITelephony interface is not up yet. 797 return getPhoneTypeFromProperty(subId); 798 } 799 } catch (RemoteException ex) { 800 // This shouldn't happen in the normal case, as a backup we 801 // read from the system property. 802 return getPhoneTypeFromProperty(subId); 803 } catch (NullPointerException ex) { 804 // This shouldn't happen in the normal case, as a backup we 805 // read from the system property. 806 return getPhoneTypeFromProperty(subId); 807 } 808 } 809 810 /** 811 * Returns a constant indicating the device phone type. This 812 * indicates the type of radio used to transmit voice calls. 813 * 814 * @see #PHONE_TYPE_NONE 815 * @see #PHONE_TYPE_GSM 816 * @see #PHONE_TYPE_CDMA 817 * @see #PHONE_TYPE_SIP 818 */ 819 public int getPhoneType() { 820 if (!isVoiceCapable()) { 821 return PHONE_TYPE_NONE; 822 } 823 return getCurrentPhoneType(); 824 } 825 826 private int getPhoneTypeFromProperty() { 827 return getPhoneTypeFromProperty(getDefaultSubscription()); 828 } 829 830 /** {@hide} */ 831 private int getPhoneTypeFromProperty(long subId) { 832 String type = 833 getTelephonyProperty 834 (TelephonyProperties.CURRENT_ACTIVE_PHONE, subId, null); 835 if (type != null) { 836 return (Integer.parseInt(type)); 837 } else { 838 return getPhoneTypeFromNetworkType(subId); 839 } 840 } 841 842 private int getPhoneTypeFromNetworkType() { 843 return getPhoneTypeFromNetworkType(getDefaultSubscription()); 844 } 845 846 /** {@hide} */ 847 private int getPhoneTypeFromNetworkType(long subId) { 848 // When the system property CURRENT_ACTIVE_PHONE, has not been set, 849 // use the system property for default network type. 850 // This is a fail safe, and can only happen at first boot. 851 String mode = getTelephonyProperty("ro.telephony.default_network", subId, null); 852 if (mode != null) { 853 return TelephonyManager.getPhoneType(Integer.parseInt(mode)); 854 } 855 return TelephonyManager.PHONE_TYPE_NONE; 856 } 857 858 /** 859 * This function returns the type of the phone, depending 860 * on the network mode. 861 * 862 * @param networkMode 863 * @return Phone Type 864 * 865 * @hide 866 */ 867 public static int getPhoneType(int networkMode) { 868 switch(networkMode) { 869 case RILConstants.NETWORK_MODE_CDMA: 870 case RILConstants.NETWORK_MODE_CDMA_NO_EVDO: 871 case RILConstants.NETWORK_MODE_EVDO_NO_CDMA: 872 return PhoneConstants.PHONE_TYPE_CDMA; 873 874 case RILConstants.NETWORK_MODE_WCDMA_PREF: 875 case RILConstants.NETWORK_MODE_GSM_ONLY: 876 case RILConstants.NETWORK_MODE_WCDMA_ONLY: 877 case RILConstants.NETWORK_MODE_GSM_UMTS: 878 case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA: 879 case RILConstants.NETWORK_MODE_LTE_WCDMA: 880 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA: 881 return PhoneConstants.PHONE_TYPE_GSM; 882 883 // Use CDMA Phone for the global mode including CDMA 884 case RILConstants.NETWORK_MODE_GLOBAL: 885 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO: 886 return PhoneConstants.PHONE_TYPE_CDMA; 887 888 case RILConstants.NETWORK_MODE_LTE_ONLY: 889 if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) { 890 return PhoneConstants.PHONE_TYPE_CDMA; 891 } else { 892 return PhoneConstants.PHONE_TYPE_GSM; 893 } 894 default: 895 return PhoneConstants.PHONE_TYPE_GSM; 896 } 897 } 898 899 /** 900 * The contents of the /proc/cmdline file 901 */ 902 private static String getProcCmdLine() 903 { 904 String cmdline = ""; 905 FileInputStream is = null; 906 try { 907 is = new FileInputStream("/proc/cmdline"); 908 byte [] buffer = new byte[2048]; 909 int count = is.read(buffer); 910 if (count > 0) { 911 cmdline = new String(buffer, 0, count); 912 } 913 } catch (IOException e) { 914 Rlog.d(TAG, "No /proc/cmdline exception=" + e); 915 } finally { 916 if (is != null) { 917 try { 918 is.close(); 919 } catch (IOException e) { 920 } 921 } 922 } 923 Rlog.d(TAG, "/proc/cmdline=" + cmdline); 924 return cmdline; 925 } 926 927 /** Kernel command line */ 928 private static final String sKernelCmdLine = getProcCmdLine(); 929 930 /** Pattern for selecting the product type from the kernel command line */ 931 private static final Pattern sProductTypePattern = 932 Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)"); 933 934 /** The ProductType used for LTE on CDMA devices */ 935 private static final String sLteOnCdmaProductType = 936 SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, ""); 937 938 /** 939 * Return if the current radio is LTE on CDMA. This 940 * is a tri-state return value as for a period of time 941 * the mode may be unknown. 942 * 943 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 944 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 945 * 946 * @hide 947 */ 948 public static int getLteOnCdmaModeStatic() { 949 int retVal; 950 int curVal; 951 String productType = ""; 952 953 curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE, 954 PhoneConstants.LTE_ON_CDMA_UNKNOWN); 955 retVal = curVal; 956 if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) { 957 Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine); 958 if (matcher.find()) { 959 productType = matcher.group(1); 960 if (sLteOnCdmaProductType.equals(productType)) { 961 retVal = PhoneConstants.LTE_ON_CDMA_TRUE; 962 } else { 963 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 964 } 965 } else { 966 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 967 } 968 } 969 970 Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal + 971 " product_type='" + productType + 972 "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'"); 973 return retVal; 974 } 975 976 // 977 // 978 // Current Network 979 // 980 // 981 982 /** 983 * Returns the alphabetic name of current registered operator. 984 * <p> 985 * Availability: Only when user is registered to a network. Result may be 986 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 987 * on a CDMA network). 988 */ 989 public String getNetworkOperatorName() { 990 return getNetworkOperatorName(getDefaultSubscription()); 991 } 992 993 /** 994 * Returns the alphabetic name of current registered operator 995 * for a particular subscription. 996 * <p> 997 * Availability: Only when user is registered to a network. Result may be 998 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 999 * on a CDMA network). 1000 * @param subId 1001 */ 1002 /** {@hide} */ 1003 public String getNetworkOperatorName(long subId) { 1004 1005 return getTelephonyProperty(TelephonyProperties.PROPERTY_OPERATOR_ALPHA, 1006 subId, ""); 1007 } 1008 1009 /** 1010 * Returns the numeric name (MCC+MNC) of current registered operator. 1011 * <p> 1012 * Availability: Only when user is registered to a network. Result may be 1013 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1014 * on a CDMA network). 1015 */ 1016 public String getNetworkOperator() { 1017 return getNetworkOperator(getDefaultSubscription()); 1018 } 1019 1020 /** 1021 * Returns the numeric name (MCC+MNC) of current registered operator 1022 * for a particular subscription. 1023 * <p> 1024 * Availability: Only when user is registered to a network. Result may be 1025 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1026 * on a CDMA network). 1027 * 1028 * @param subId 1029 */ 1030 /** {@hide} */ 1031 public String getNetworkOperator(long subId) { 1032 1033 return getTelephonyProperty(TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, 1034 subId, ""); 1035 } 1036 1037 /** 1038 * Returns true if the device is considered roaming on the current 1039 * network, for GSM purposes. 1040 * <p> 1041 * Availability: Only when user registered to a network. 1042 */ 1043 public boolean isNetworkRoaming() { 1044 return isNetworkRoaming(getDefaultSubscription()); 1045 } 1046 1047 /** 1048 * Returns true if the device is considered roaming on the current 1049 * network for a subscription. 1050 * <p> 1051 * Availability: Only when user registered to a network. 1052 * 1053 * @param subId 1054 */ 1055 /** {@hide} */ 1056 public boolean isNetworkRoaming(long subId) { 1057 return "true".equals(getTelephonyProperty(TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, 1058 subId, null)); 1059 } 1060 1061 /** 1062 * Returns the ISO country code equivalent of the current registered 1063 * operator's MCC (Mobile Country Code). 1064 * <p> 1065 * Availability: Only when user is registered to a network. Result may be 1066 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1067 * on a CDMA network). 1068 */ 1069 public String getNetworkCountryIso() { 1070 return getNetworkCountryIso(getDefaultSubscription()); 1071 } 1072 1073 /** 1074 * Returns the ISO country code equivalent of the current registered 1075 * operator's MCC (Mobile Country Code) of a subscription. 1076 * <p> 1077 * Availability: Only when user is registered to a network. Result may be 1078 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1079 * on a CDMA network). 1080 * 1081 * @param subId for which Network CountryIso is returned 1082 */ 1083 /** {@hide} */ 1084 public String getNetworkCountryIso(long subId) { 1085 return getTelephonyProperty(TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, 1086 subId, ""); 1087 } 1088 1089 /** Network type is unknown */ 1090 public static final int NETWORK_TYPE_UNKNOWN = 0; 1091 /** Current network is GPRS */ 1092 public static final int NETWORK_TYPE_GPRS = 1; 1093 /** Current network is EDGE */ 1094 public static final int NETWORK_TYPE_EDGE = 2; 1095 /** Current network is UMTS */ 1096 public static final int NETWORK_TYPE_UMTS = 3; 1097 /** Current network is CDMA: Either IS95A or IS95B*/ 1098 public static final int NETWORK_TYPE_CDMA = 4; 1099 /** Current network is EVDO revision 0*/ 1100 public static final int NETWORK_TYPE_EVDO_0 = 5; 1101 /** Current network is EVDO revision A*/ 1102 public static final int NETWORK_TYPE_EVDO_A = 6; 1103 /** Current network is 1xRTT*/ 1104 public static final int NETWORK_TYPE_1xRTT = 7; 1105 /** Current network is HSDPA */ 1106 public static final int NETWORK_TYPE_HSDPA = 8; 1107 /** Current network is HSUPA */ 1108 public static final int NETWORK_TYPE_HSUPA = 9; 1109 /** Current network is HSPA */ 1110 public static final int NETWORK_TYPE_HSPA = 10; 1111 /** Current network is iDen */ 1112 public static final int NETWORK_TYPE_IDEN = 11; 1113 /** Current network is EVDO revision B*/ 1114 public static final int NETWORK_TYPE_EVDO_B = 12; 1115 /** Current network is LTE */ 1116 public static final int NETWORK_TYPE_LTE = 13; 1117 /** Current network is eHRPD */ 1118 public static final int NETWORK_TYPE_EHRPD = 14; 1119 /** Current network is HSPA+ */ 1120 public static final int NETWORK_TYPE_HSPAP = 15; 1121 /** Current network is GSM {@hide} */ 1122 public static final int NETWORK_TYPE_GSM = 16; 1123 1124 /** 1125 * @return the NETWORK_TYPE_xxxx for current data connection. 1126 */ 1127 public int getNetworkType() { 1128 return getDataNetworkType(); 1129 } 1130 1131 /** 1132 * Returns a constant indicating the radio technology (network type) 1133 * currently in use on the device for a subscription. 1134 * @return the network type 1135 * 1136 * @param subId for which network type is returned 1137 * 1138 * @see #NETWORK_TYPE_UNKNOWN 1139 * @see #NETWORK_TYPE_GPRS 1140 * @see #NETWORK_TYPE_EDGE 1141 * @see #NETWORK_TYPE_UMTS 1142 * @see #NETWORK_TYPE_HSDPA 1143 * @see #NETWORK_TYPE_HSUPA 1144 * @see #NETWORK_TYPE_HSPA 1145 * @see #NETWORK_TYPE_CDMA 1146 * @see #NETWORK_TYPE_EVDO_0 1147 * @see #NETWORK_TYPE_EVDO_A 1148 * @see #NETWORK_TYPE_EVDO_B 1149 * @see #NETWORK_TYPE_1xRTT 1150 * @see #NETWORK_TYPE_IDEN 1151 * @see #NETWORK_TYPE_LTE 1152 * @see #NETWORK_TYPE_EHRPD 1153 * @see #NETWORK_TYPE_HSPAP 1154 */ 1155 /** {@hide} */ 1156 public int getNetworkType(long subId) { 1157 try { 1158 ITelephony telephony = getITelephony(); 1159 if (telephony != null) { 1160 return telephony.getNetworkTypeUsingSubId(subId); 1161 } else { 1162 // This can happen when the ITelephony interface is not up yet. 1163 return NETWORK_TYPE_UNKNOWN; 1164 } 1165 } catch(RemoteException ex) { 1166 // This shouldn't happen in the normal case 1167 return NETWORK_TYPE_UNKNOWN; 1168 } catch (NullPointerException ex) { 1169 // This could happen before phone restarts due to crashing 1170 return NETWORK_TYPE_UNKNOWN; 1171 } 1172 } 1173 1174 /** 1175 * Returns a constant indicating the radio technology (network type) 1176 * currently in use on the device for data transmission. 1177 * @return the network type 1178 * 1179 * @see #NETWORK_TYPE_UNKNOWN 1180 * @see #NETWORK_TYPE_GPRS 1181 * @see #NETWORK_TYPE_EDGE 1182 * @see #NETWORK_TYPE_UMTS 1183 * @see #NETWORK_TYPE_HSDPA 1184 * @see #NETWORK_TYPE_HSUPA 1185 * @see #NETWORK_TYPE_HSPA 1186 * @see #NETWORK_TYPE_CDMA 1187 * @see #NETWORK_TYPE_EVDO_0 1188 * @see #NETWORK_TYPE_EVDO_A 1189 * @see #NETWORK_TYPE_EVDO_B 1190 * @see #NETWORK_TYPE_1xRTT 1191 * @see #NETWORK_TYPE_IDEN 1192 * @see #NETWORK_TYPE_LTE 1193 * @see #NETWORK_TYPE_EHRPD 1194 * @see #NETWORK_TYPE_HSPAP 1195 * 1196 * @hide 1197 */ 1198 public int getDataNetworkType() { 1199 return getDataNetworkType(getDefaultSubscription()); 1200 } 1201 1202 /** 1203 * Returns a constant indicating the radio technology (network type) 1204 * currently in use on the device for data transmission for a subscription 1205 * @return the network type 1206 * 1207 * @param subId for which network type is returned 1208 */ 1209 /** {@hide} */ 1210 public int getDataNetworkType(long subId) { 1211 try{ 1212 ITelephony telephony = getITelephony(); 1213 if (telephony != null) { 1214 return telephony.getDataNetworkTypeUsingSubId(subId); 1215 } else { 1216 // This can happen when the ITelephony interface is not up yet. 1217 return NETWORK_TYPE_UNKNOWN; 1218 } 1219 } catch(RemoteException ex) { 1220 // This shouldn't happen in the normal case 1221 return NETWORK_TYPE_UNKNOWN; 1222 } catch (NullPointerException ex) { 1223 // This could happen before phone restarts due to crashing 1224 return NETWORK_TYPE_UNKNOWN; 1225 } 1226 } 1227 1228 /** 1229 * Returns the NETWORK_TYPE_xxxx for voice 1230 * 1231 * @hide 1232 */ 1233 public int getVoiceNetworkType() { 1234 return getVoiceNetworkType(getDefaultSubscription()); 1235 } 1236 1237 /** 1238 * Returns the NETWORK_TYPE_xxxx for voice for a subId 1239 * 1240 */ 1241 /** {@hide} */ 1242 public int getVoiceNetworkType(long subId) { 1243 try{ 1244 ITelephony telephony = getITelephony(); 1245 if (telephony != null) { 1246 return telephony.getVoiceNetworkTypeUsingSubId(subId); 1247 } else { 1248 // This can happen when the ITelephony interface is not up yet. 1249 return NETWORK_TYPE_UNKNOWN; 1250 } 1251 } catch(RemoteException ex) { 1252 // This shouldn't happen in the normal case 1253 return NETWORK_TYPE_UNKNOWN; 1254 } catch (NullPointerException ex) { 1255 // This could happen before phone restarts due to crashing 1256 return NETWORK_TYPE_UNKNOWN; 1257 } 1258 } 1259 1260 /** Unknown network class. {@hide} */ 1261 public static final int NETWORK_CLASS_UNKNOWN = 0; 1262 /** Class of broadly defined "2G" networks. {@hide} */ 1263 public static final int NETWORK_CLASS_2_G = 1; 1264 /** Class of broadly defined "3G" networks. {@hide} */ 1265 public static final int NETWORK_CLASS_3_G = 2; 1266 /** Class of broadly defined "4G" networks. {@hide} */ 1267 public static final int NETWORK_CLASS_4_G = 3; 1268 1269 /** 1270 * Return general class of network type, such as "3G" or "4G". In cases 1271 * where classification is contentious, this method is conservative. 1272 * 1273 * @hide 1274 */ 1275 public static int getNetworkClass(int networkType) { 1276 switch (networkType) { 1277 case NETWORK_TYPE_GPRS: 1278 case NETWORK_TYPE_GSM: 1279 case NETWORK_TYPE_EDGE: 1280 case NETWORK_TYPE_CDMA: 1281 case NETWORK_TYPE_1xRTT: 1282 case NETWORK_TYPE_IDEN: 1283 return NETWORK_CLASS_2_G; 1284 case NETWORK_TYPE_UMTS: 1285 case NETWORK_TYPE_EVDO_0: 1286 case NETWORK_TYPE_EVDO_A: 1287 case NETWORK_TYPE_HSDPA: 1288 case NETWORK_TYPE_HSUPA: 1289 case NETWORK_TYPE_HSPA: 1290 case NETWORK_TYPE_EVDO_B: 1291 case NETWORK_TYPE_EHRPD: 1292 case NETWORK_TYPE_HSPAP: 1293 return NETWORK_CLASS_3_G; 1294 case NETWORK_TYPE_LTE: 1295 return NETWORK_CLASS_4_G; 1296 default: 1297 return NETWORK_CLASS_UNKNOWN; 1298 } 1299 } 1300 1301 /** 1302 * Returns a string representation of the radio technology (network type) 1303 * currently in use on the device. 1304 * @return the name of the radio technology 1305 * 1306 * @hide pending API council review 1307 */ 1308 public String getNetworkTypeName() { 1309 return getNetworkTypeName(getNetworkType()); 1310 } 1311 1312 /** 1313 * Returns a string representation of the radio technology (network type) 1314 * currently in use on the device. 1315 * @param subId for which network type is returned 1316 * @return the name of the radio technology 1317 * 1318 */ 1319 /** {@hide} */ 1320 public static String getNetworkTypeName(int type) { 1321 switch (type) { 1322 case NETWORK_TYPE_GPRS: 1323 return "GPRS"; 1324 case NETWORK_TYPE_EDGE: 1325 return "EDGE"; 1326 case NETWORK_TYPE_UMTS: 1327 return "UMTS"; 1328 case NETWORK_TYPE_HSDPA: 1329 return "HSDPA"; 1330 case NETWORK_TYPE_HSUPA: 1331 return "HSUPA"; 1332 case NETWORK_TYPE_HSPA: 1333 return "HSPA"; 1334 case NETWORK_TYPE_CDMA: 1335 return "CDMA"; 1336 case NETWORK_TYPE_EVDO_0: 1337 return "CDMA - EvDo rev. 0"; 1338 case NETWORK_TYPE_EVDO_A: 1339 return "CDMA - EvDo rev. A"; 1340 case NETWORK_TYPE_EVDO_B: 1341 return "CDMA - EvDo rev. B"; 1342 case NETWORK_TYPE_1xRTT: 1343 return "CDMA - 1xRTT"; 1344 case NETWORK_TYPE_LTE: 1345 return "LTE"; 1346 case NETWORK_TYPE_EHRPD: 1347 return "CDMA - eHRPD"; 1348 case NETWORK_TYPE_IDEN: 1349 return "iDEN"; 1350 case NETWORK_TYPE_HSPAP: 1351 return "HSPA+"; 1352 case NETWORK_TYPE_GSM: 1353 return "GSM"; 1354 default: 1355 return "UNKNOWN"; 1356 } 1357 } 1358 1359 // 1360 // 1361 // SIM Card 1362 // 1363 // 1364 1365 /** SIM card state: Unknown. Signifies that the SIM is in transition 1366 * between states. For example, when the user inputs the SIM pin 1367 * under PIN_REQUIRED state, a query for sim status returns 1368 * this state before turning to SIM_STATE_READY. */ 1369 public static final int SIM_STATE_UNKNOWN = 0; 1370 /** SIM card state: no SIM card is available in the device */ 1371 public static final int SIM_STATE_ABSENT = 1; 1372 /** SIM card state: Locked: requires the user's SIM PIN to unlock */ 1373 public static final int SIM_STATE_PIN_REQUIRED = 2; 1374 /** SIM card state: Locked: requires the user's SIM PUK to unlock */ 1375 public static final int SIM_STATE_PUK_REQUIRED = 3; 1376 /** SIM card state: Locked: requries a network PIN to unlock */ 1377 public static final int SIM_STATE_NETWORK_LOCKED = 4; 1378 /** SIM card state: Ready */ 1379 public static final int SIM_STATE_READY = 5; 1380 /** SIM card state: SIM Card Error, Sim Card is present but faulty 1381 *@hide 1382 */ 1383 public static final int SIM_STATE_CARD_IO_ERROR = 6; 1384 1385 /** 1386 * @return true if a ICC card is present 1387 */ 1388 public boolean hasIccCard() { 1389 return hasIccCard(getDefaultSim()); 1390 } 1391 1392 /** 1393 * @return true if a ICC card is present for a subscription 1394 * 1395 * @param slotId for which icc card presence is checked 1396 */ 1397 /** {@hide} */ 1398 // FIXME Input argument slotId should be of type int 1399 public boolean hasIccCard(long slotId) { 1400 1401 try { 1402 return getITelephony().hasIccCardUsingSlotId(slotId); 1403 } catch (RemoteException ex) { 1404 // Assume no ICC card if remote exception which shouldn't happen 1405 return false; 1406 } catch (NullPointerException ex) { 1407 // This could happen before phone restarts due to crashing 1408 return false; 1409 } 1410 } 1411 1412 /** 1413 * Returns a constant indicating the state of the 1414 * device SIM card. 1415 * 1416 * @see #SIM_STATE_UNKNOWN 1417 * @see #SIM_STATE_ABSENT 1418 * @see #SIM_STATE_PIN_REQUIRED 1419 * @see #SIM_STATE_PUK_REQUIRED 1420 * @see #SIM_STATE_NETWORK_LOCKED 1421 * @see #SIM_STATE_READY 1422 * @see #SIM_STATE_CARD_IO_ERROR 1423 */ 1424 public int getSimState() { 1425 return getSimState(getDefaultSim()); 1426 } 1427 1428 /** 1429 * Returns a constant indicating the state of the 1430 * device SIM card in a slot. 1431 * 1432 * @param slotId 1433 * 1434 * @see #SIM_STATE_UNKNOWN 1435 * @see #SIM_STATE_ABSENT 1436 * @see #SIM_STATE_PIN_REQUIRED 1437 * @see #SIM_STATE_PUK_REQUIRED 1438 * @see #SIM_STATE_NETWORK_LOCKED 1439 * @see #SIM_STATE_READY 1440 */ 1441 /** {@hide} */ 1442 // FIXME the argument to pass is subId ?? 1443 public int getSimState(int slotId) { 1444 long[] subId = SubscriptionManager.getSubId(slotId); 1445 if (subId == null) { 1446 return SIM_STATE_ABSENT; 1447 } 1448 // FIXME Do not use a property to determine SIM_STATE, call 1449 // appropriate method on some object. 1450 String prop = 1451 getTelephonyProperty(TelephonyProperties.PROPERTY_SIM_STATE, subId[0], ""); 1452 if ("ABSENT".equals(prop)) { 1453 return SIM_STATE_ABSENT; 1454 } 1455 else if ("PIN_REQUIRED".equals(prop)) { 1456 return SIM_STATE_PIN_REQUIRED; 1457 } 1458 else if ("PUK_REQUIRED".equals(prop)) { 1459 return SIM_STATE_PUK_REQUIRED; 1460 } 1461 else if ("NETWORK_LOCKED".equals(prop)) { 1462 return SIM_STATE_NETWORK_LOCKED; 1463 } 1464 else if ("READY".equals(prop)) { 1465 return SIM_STATE_READY; 1466 } 1467 else if ("CARD_IO_ERROR".equals(prop)) { 1468 return SIM_STATE_CARD_IO_ERROR; 1469 } 1470 else { 1471 return SIM_STATE_UNKNOWN; 1472 } 1473 } 1474 1475 /** 1476 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1477 * provider of the SIM. 5 or 6 decimal digits. 1478 * <p> 1479 * Availability: SIM state must be {@link #SIM_STATE_READY} 1480 * 1481 * @see #getSimState 1482 */ 1483 public String getSimOperator() { 1484 long subId = getDefaultSubscription(); 1485 Rlog.d(TAG, "getSimOperator(): default subId=" + subId); 1486 return getSimOperator(subId); 1487 } 1488 1489 /** 1490 * Returns the MCC+MNC (mobile country code + mobile network code) of the 1491 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 1492 * <p> 1493 * Availability: SIM state must be {@link #SIM_STATE_READY} 1494 * 1495 * @see #getSimState 1496 * 1497 * @param subId for which SimOperator is returned 1498 */ 1499 /** {@hide} */ 1500 public String getSimOperator(long subId) { 1501 String operator = getTelephonyProperty(TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, 1502 subId, ""); 1503 Rlog.d(TAG, "getSimOperator: subId=" + subId + " operator=" + operator); 1504 return operator; 1505 } 1506 1507 /** 1508 * Returns the Service Provider Name (SPN). 1509 * <p> 1510 * Availability: SIM state must be {@link #SIM_STATE_READY} 1511 * 1512 * @see #getSimState 1513 */ 1514 public String getSimOperatorName() { 1515 return getSimOperatorName(getDefaultSubscription()); 1516 } 1517 1518 /** 1519 * Returns the Service Provider Name (SPN). 1520 * <p> 1521 * Availability: SIM state must be {@link #SIM_STATE_READY} 1522 * 1523 * @see #getSimState 1524 * 1525 * @param subId for which SimOperatorName is returned 1526 */ 1527 /** {@hide} */ 1528 public String getSimOperatorName(long subId) { 1529 return getTelephonyProperty(TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, 1530 subId, ""); 1531 } 1532 1533 /** 1534 * Returns the ISO country code equivalent for the SIM provider's country code. 1535 */ 1536 public String getSimCountryIso() { 1537 return getSimCountryIso(getDefaultSubscription()); 1538 } 1539 1540 /** 1541 * Returns the ISO country code equivalent for the SIM provider's country code. 1542 * 1543 * @param subId for which SimCountryIso is returned 1544 */ 1545 /** {@hide} */ 1546 public String getSimCountryIso(long subId) { 1547 return getTelephonyProperty(TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, 1548 subId, ""); 1549 } 1550 1551 /** 1552 * Returns the serial number of the SIM, if applicable. Return null if it is 1553 * unavailable. 1554 * <p> 1555 * Requires Permission: 1556 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1557 */ 1558 public String getSimSerialNumber() { 1559 return getSimSerialNumber(getDefaultSubscription()); 1560 } 1561 1562 /** 1563 * Returns the serial number for the given subscription, if applicable. Return null if it is 1564 * unavailable. 1565 * <p> 1566 * @param subId for which Sim Serial number is returned 1567 * Requires Permission: 1568 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1569 */ 1570 /** {@hide} */ 1571 public String getSimSerialNumber(long subId) { 1572 try { 1573 return getSubscriberInfo().getIccSerialNumberUsingSubId(subId); 1574 } catch (RemoteException ex) { 1575 return null; 1576 } catch (NullPointerException ex) { 1577 // This could happen before phone restarts due to crashing 1578 return null; 1579 } 1580 } 1581 1582 /** 1583 * Return if the current radio is LTE on CDMA. This 1584 * is a tri-state return value as for a period of time 1585 * the mode may be unknown. 1586 * 1587 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1588 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1589 * 1590 * @hide 1591 */ 1592 public int getLteOnCdmaMode() { 1593 return getLteOnCdmaMode(getDefaultSubscription()); 1594 } 1595 1596 /** 1597 * Return if the current radio is LTE on CDMA for Subscription. This 1598 * is a tri-state return value as for a period of time 1599 * the mode may be unknown. 1600 * 1601 * @param subId for which radio is LTE on CDMA is returned 1602 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1603 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1604 * 1605 */ 1606 /** {@hide} */ 1607 public int getLteOnCdmaMode(long subId) { 1608 try { 1609 return getITelephony().getLteOnCdmaModeUsingSubId(subId); 1610 } catch (RemoteException ex) { 1611 // Assume no ICC card if remote exception which shouldn't happen 1612 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1613 } catch (NullPointerException ex) { 1614 // This could happen before phone restarts due to crashing 1615 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 1616 } 1617 } 1618 1619 // 1620 // 1621 // Subscriber Info 1622 // 1623 // 1624 1625 /** 1626 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 1627 * Return null if it is unavailable. 1628 * <p> 1629 * Requires Permission: 1630 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1631 */ 1632 public String getSubscriberId() { 1633 return getSubscriberId(getDefaultSubscription()); 1634 } 1635 1636 /** 1637 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone 1638 * for a subscription. 1639 * Return null if it is unavailable. 1640 * <p> 1641 * Requires Permission: 1642 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1643 * 1644 * @param subId whose subscriber id is returned 1645 */ 1646 /** {@hide} */ 1647 public String getSubscriberId(long subId) { 1648 try { 1649 return getSubscriberInfo().getSubscriberIdUsingSubId(subId); 1650 } catch (RemoteException ex) { 1651 return null; 1652 } catch (NullPointerException ex) { 1653 // This could happen before phone restarts due to crashing 1654 return null; 1655 } 1656 } 1657 1658 /** 1659 * Returns the Group Identifier Level1 for a GSM phone. 1660 * Return null if it is unavailable. 1661 * <p> 1662 * Requires Permission: 1663 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1664 */ 1665 public String getGroupIdLevel1() { 1666 try { 1667 return getSubscriberInfo().getGroupIdLevel1(); 1668 } catch (RemoteException ex) { 1669 return null; 1670 } catch (NullPointerException ex) { 1671 // This could happen before phone restarts due to crashing 1672 return null; 1673 } 1674 } 1675 1676 /** 1677 * Returns the Group Identifier Level1 for a GSM phone for a particular subscription. 1678 * Return null if it is unavailable. 1679 * <p> 1680 * Requires Permission: 1681 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1682 * 1683 * @param subscription whose subscriber id is returned 1684 */ 1685 /** {@hide} */ 1686 public String getGroupIdLevel1(long subId) { 1687 try { 1688 return getSubscriberInfo().getGroupIdLevel1UsingSubId(subId); 1689 } catch (RemoteException ex) { 1690 return null; 1691 } catch (NullPointerException ex) { 1692 // This could happen before phone restarts due to crashing 1693 return null; 1694 } 1695 } 1696 1697 /** 1698 * Returns the phone number string for line 1, for example, the MSISDN 1699 * for a GSM phone. Return null if it is unavailable. 1700 * <p> 1701 * Requires Permission: 1702 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1703 */ 1704 public String getLine1Number() { 1705 return getLine1Number(getDefaultSubscription()); 1706 } 1707 1708 /** 1709 * Returns the phone number string for line 1, for example, the MSISDN 1710 * for a GSM phone for a particular subscription. Return null if it is unavailable. 1711 * <p> 1712 * Requires Permission: 1713 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1714 * 1715 * @param subId whose phone number for line 1 is returned 1716 */ 1717 /** {@hide} */ 1718 public String getLine1Number(long subId) { 1719 String number = null; 1720 try { 1721 number = getITelephony().getLine1NumberForDisplay(subId); 1722 } catch (RemoteException ex) { 1723 } catch (NullPointerException ex) { 1724 } 1725 if (number != null) { 1726 return number; 1727 } 1728 try { 1729 return getSubscriberInfo().getLine1NumberUsingSubId(subId); 1730 } catch (RemoteException ex) { 1731 return null; 1732 } catch (NullPointerException ex) { 1733 // This could happen before phone restarts due to crashing 1734 return null; 1735 } 1736 } 1737 1738 /** 1739 * Set the phone number string and its alphatag for line 1 for display 1740 * purpose only, for example, displayed in Phone Status. It won't change 1741 * the actual MSISDN/MDN. This setting won't be persisted during power cycle 1742 * and it should be set again after reboot. 1743 * <p> 1744 * Requires Permission: 1745 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 1746 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 1747 * 1748 * @param alphaTag alpha-tagging of the dailing nubmer 1749 * @param number The dialing number 1750 */ 1751 public void setLine1NumberForDisplay(String alphaTag, String number) { 1752 setLine1NumberForDisplay(getDefaultSubscription(), alphaTag, number); 1753 } 1754 1755 /** 1756 * Set the phone number string and its alphatag for line 1 for display 1757 * purpose only, for example, displayed in Phone Status. It won't change 1758 * the actual MSISDN/MDN. This setting won't be persisted during power cycle 1759 * and it should be set again after reboot. 1760 * <p> 1761 * Requires Permission: 1762 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 1763 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 1764 * 1765 * @param subId the subscriber that the alphatag and dialing number belongs to. 1766 * @param alphaTag alpha-tagging of the dailing nubmer 1767 * @param number The dialing number 1768 */ 1769 public void setLine1NumberForDisplay(long subId, String alphaTag, String number) { 1770 try { 1771 getITelephony().setLine1NumberForDisplay(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 getLine1AlphaTag(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 getLine1AlphaTag(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().getLine1AlphaTagUsingSubId(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().getMsisdnUsingSubId(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().getVoiceMailNumberUsingSubId(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().getCompleteVoiceMailNumberUsingSubId(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().getVoiceMessageCountUsingSubId(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().getVoiceMailAlphaTagUsingSubId(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().getCallStateUsingSubId(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 ITelecommService getTelecommService() { 2146 return ITelecommService.Stub.asInterface(ServiceManager.getService(TELECOMM_SERVICE_NAME)); 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.listenUsingSubId(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().getCdmaEriIconIndexUsingSubId(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().getCdmaEriIconModeUsingSubId(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().getCdmaEriTextUsingSubId(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, with the last 4 bytes 2515 * being the status word. If the command fails, returns an empty 2516 * 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 calculated preferred network type. 2907 * Used for debugging incorrect network type. 2908 * <p> 2909 * Requires Permission: 2910 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2911 * 2912 * @return the preferred network type, defined in RILConstants.java or -1 if 2913 * none available. 2914 */ 2915 public int getCalculatedPreferredNetworkType() { 2916 try { 2917 return getITelephony().getCalculatedPreferredNetworkType(); 2918 } catch (RemoteException ex) { 2919 Rlog.e(TAG, "getCalculatedPreferredNetworkType RemoteException", ex); 2920 } catch (NullPointerException ex) { 2921 Rlog.e(TAG, "getCalculatedPreferredNetworkType NPE", ex); 2922 } 2923 return -1; 2924 } 2925 2926 /** 2927 * Get the preferred network type. 2928 * Used for device configuration by some CDMA operators. 2929 * <p> 2930 * Requires Permission: 2931 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2932 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2933 * 2934 * @return the preferred network type, defined in RILConstants.java. 2935 */ 2936 public int getPreferredNetworkType() { 2937 try { 2938 return getITelephony().getPreferredNetworkType(); 2939 } catch (RemoteException ex) { 2940 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 2941 } catch (NullPointerException ex) { 2942 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 2943 } 2944 return -1; 2945 } 2946 2947 /** 2948 * Set the preferred network type. 2949 * Used for device configuration by some CDMA operators. 2950 * <p> 2951 * Requires Permission: 2952 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2953 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2954 * 2955 * @param networkType the preferred network type, defined in RILConstants.java. 2956 * @return true on success; false on any failure. 2957 */ 2958 public boolean setPreferredNetworkType(int networkType) { 2959 try { 2960 return getITelephony().setPreferredNetworkType(networkType); 2961 } catch (RemoteException ex) { 2962 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 2963 } catch (NullPointerException ex) { 2964 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 2965 } 2966 return false; 2967 } 2968 2969 /** 2970 * Set the CDMA subscription source. 2971 * Used for device supporting both NV and RUIM for CDMA. 2972 * <p> 2973 * Requires Permission: 2974 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2975 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2976 * 2977 * @param subscriptionType the subscription type, 0 for RUIM, 1 for NV. 2978 * @return true on success; false on any failure. 2979 */ 2980 public boolean setCdmaSubscription(int subscriptionType) { 2981 try { 2982 return getITelephony().setCdmaSubscription(subscriptionType); 2983 } catch (RemoteException ex) { 2984 Rlog.e(TAG, "setCdmaSubscription RemoteException", ex); 2985 } catch (NullPointerException ex) { 2986 Rlog.e(TAG, "setCdmaSubscription NPE", ex); 2987 } 2988 return false; 2989 } 2990 2991 /** 2992 * Values used to return status for hasCarrierPrivileges call. 2993 */ 2994 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 2995 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 2996 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 2997 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 2998 2999 /** 3000 * Has the calling application been granted carrier privileges by the carrier. 3001 * 3002 * If any of the packages in the calling UID has carrier privileges, the 3003 * call will return true. This access is granted by the owner of the UICC 3004 * card and does not depend on the registered carrier. 3005 * 3006 * TODO: Add a link to documentation. 3007 * 3008 * @return CARRIER_PRIVILEGE_STATUS_HAS_ACCESS if the app has carrier privileges. 3009 * CARRIER_PRIVILEGE_STATUS_NO_ACCESS if the app does not have carrier privileges. 3010 * CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED if the carrier rules are not loaded. 3011 * CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES if there was an error loading carrier 3012 * rules (or if there are no rules). 3013 */ 3014 public int hasCarrierPrivileges() { 3015 try { 3016 return getITelephony().hasCarrierPrivileges(); 3017 } catch (RemoteException ex) { 3018 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3019 } catch (NullPointerException ex) { 3020 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3021 } 3022 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3023 } 3024 3025 /** 3026 * Override the branding for the input ICCID. 3027 * 3028 * Once set, whenever the ICCID is inserted into the device, the service 3029 * provider name (SPN) and the operator name will both be replaced by the 3030 * brand value input. To unset the value, the same function should be 3031 * called with a null brand value. 3032 * 3033 * <p>Requires Permission: 3034 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3035 * or has to be carrier app - see #hasCarrierPrivileges. 3036 * 3037 * @param iccId The ICCID of that the branding applies to. 3038 * @param brand The brand name to display/set. 3039 * @return true if the operation was executed correctly. 3040 */ 3041 public boolean setOperatorBrandOverride(String iccId, String brand) { 3042 // TODO: Validate ICCID format. 3043 try { 3044 return getITelephony().setOperatorBrandOverride(iccId, brand); 3045 } catch (RemoteException ex) { 3046 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 3047 } catch (NullPointerException ex) { 3048 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 3049 } 3050 return false; 3051 } 3052 3053 /** 3054 * Expose the rest of ITelephony to @SystemApi 3055 */ 3056 3057 /** @hide */ 3058 @SystemApi 3059 public int checkCarrierPrivilegesForPackage(String pkgname) { 3060 try { 3061 return getITelephony().checkCarrierPrivilegesForPackage(pkgname); 3062 } catch (RemoteException ex) { 3063 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3064 } catch (NullPointerException ex) { 3065 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3066 } 3067 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3068 } 3069 3070 /** @hide */ 3071 @SystemApi 3072 public List<String> getCarrierPackageNamesForBroadcastIntent(Intent intent) { 3073 try { 3074 return getITelephony().getCarrierPackageNamesForBroadcastIntent(intent); 3075 } catch (RemoteException ex) { 3076 Rlog.e(TAG, "getCarrierPackageNamesForBroadcastIntent RemoteException", ex); 3077 } catch (NullPointerException ex) { 3078 Rlog.e(TAG, "getCarrierPackageNamesForBroadcastIntent NPE", ex); 3079 } 3080 return null; 3081 } 3082 3083 /** @hide */ 3084 @SystemApi 3085 public void dial(String number) { 3086 try { 3087 getITelephony().dial(number); 3088 } catch (RemoteException e) { 3089 Log.e(TAG, "Error calling ITelephony#dial", e); 3090 } 3091 } 3092 3093 /** @hide */ 3094 @SystemApi 3095 public void call(String callingPackage, String number) { 3096 try { 3097 getITelephony().call(callingPackage, number); 3098 } catch (RemoteException e) { 3099 Log.e(TAG, "Error calling ITelephony#call", e); 3100 } 3101 } 3102 3103 /** @hide */ 3104 @SystemApi 3105 public boolean endCall() { 3106 try { 3107 return getITelephony().endCall(); 3108 } catch (RemoteException e) { 3109 Log.e(TAG, "Error calling ITelephony#endCall", e); 3110 } 3111 return false; 3112 } 3113 3114 /** @hide */ 3115 @SystemApi 3116 public void answerRingingCall() { 3117 try { 3118 getITelephony().answerRingingCall(); 3119 } catch (RemoteException e) { 3120 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 3121 } 3122 } 3123 3124 /** @hide */ 3125 @SystemApi 3126 public void silenceRinger() { 3127 try { 3128 getTelecommService().silenceRinger(); 3129 } catch (RemoteException e) { 3130 Log.e(TAG, "Error calling ITelecommService#silenceRinger", e); 3131 } 3132 } 3133 3134 /** @hide */ 3135 @SystemApi 3136 public boolean isOffhook() { 3137 try { 3138 return getITelephony().isOffhook(); 3139 } catch (RemoteException e) { 3140 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 3141 } 3142 return false; 3143 } 3144 3145 /** @hide */ 3146 @SystemApi 3147 public boolean isRinging() { 3148 try { 3149 return getITelephony().isRinging(); 3150 } catch (RemoteException e) { 3151 Log.e(TAG, "Error calling ITelephony#isRinging", e); 3152 } 3153 return false; 3154 } 3155 3156 /** @hide */ 3157 @SystemApi 3158 public boolean isIdle() { 3159 try { 3160 return getITelephony().isIdle(); 3161 } catch (RemoteException e) { 3162 Log.e(TAG, "Error calling ITelephony#isIdle", e); 3163 } 3164 return true; 3165 } 3166 3167 /** @hide */ 3168 @SystemApi 3169 public boolean isRadioOn() { 3170 try { 3171 return getITelephony().isRadioOn(); 3172 } catch (RemoteException e) { 3173 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 3174 } 3175 return false; 3176 } 3177 3178 /** @hide */ 3179 @SystemApi 3180 public boolean isSimPinEnabled() { 3181 try { 3182 return getITelephony().isSimPinEnabled(); 3183 } catch (RemoteException e) { 3184 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 3185 } 3186 return false; 3187 } 3188 3189 /** @hide */ 3190 @SystemApi 3191 public boolean supplyPin(String pin) { 3192 try { 3193 return getITelephony().supplyPin(pin); 3194 } catch (RemoteException e) { 3195 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 3196 } 3197 return false; 3198 } 3199 3200 /** @hide */ 3201 @SystemApi 3202 public boolean supplyPuk(String puk, String pin) { 3203 try { 3204 return getITelephony().supplyPuk(puk, pin); 3205 } catch (RemoteException e) { 3206 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 3207 } 3208 return false; 3209 } 3210 3211 /** @hide */ 3212 @SystemApi 3213 public int[] supplyPinReportResult(String pin) { 3214 try { 3215 return getITelephony().supplyPinReportResult(pin); 3216 } catch (RemoteException e) { 3217 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 3218 } 3219 return new int[0]; 3220 } 3221 3222 /** @hide */ 3223 @SystemApi 3224 public int[] supplyPukReportResult(String puk, String pin) { 3225 try { 3226 return getITelephony().supplyPukReportResult(puk, pin); 3227 } catch (RemoteException e) { 3228 Log.e(TAG, "Error calling ITelephony#]", e); 3229 } 3230 return new int[0]; 3231 } 3232 3233 /** @hide */ 3234 @SystemApi 3235 public boolean handlePinMmi(String dialString) { 3236 try { 3237 return getITelephony().handlePinMmi(dialString); 3238 } catch (RemoteException e) { 3239 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3240 } 3241 return false; 3242 } 3243 3244 /** @hide */ 3245 @SystemApi 3246 public void toggleRadioOnOff() { 3247 try { 3248 getITelephony().toggleRadioOnOff(); 3249 } catch (RemoteException e) { 3250 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 3251 } 3252 } 3253 3254 /** @hide */ 3255 @SystemApi 3256 public boolean setRadio(boolean turnOn) { 3257 try { 3258 return getITelephony().setRadio(turnOn); 3259 } catch (RemoteException e) { 3260 Log.e(TAG, "Error calling ITelephony#setRadio", e); 3261 } 3262 return false; 3263 } 3264 3265 /** @hide */ 3266 @SystemApi 3267 public boolean setRadioPower(boolean turnOn) { 3268 try { 3269 return getITelephony().setRadioPower(turnOn); 3270 } catch (RemoteException e) { 3271 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 3272 } 3273 return false; 3274 } 3275 3276 /** @hide */ 3277 @SystemApi 3278 public void updateServiceLocation() { 3279 try { 3280 getITelephony().updateServiceLocation(); 3281 } catch (RemoteException e) { 3282 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 3283 } 3284 } 3285 3286 /** @hide */ 3287 @SystemApi 3288 public boolean enableDataConnectivity() { 3289 try { 3290 return getITelephony().enableDataConnectivity(); 3291 } catch (RemoteException e) { 3292 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 3293 } 3294 return false; 3295 } 3296 3297 /** @hide */ 3298 @SystemApi 3299 public boolean disableDataConnectivity() { 3300 try { 3301 return getITelephony().disableDataConnectivity(); 3302 } catch (RemoteException e) { 3303 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 3304 } 3305 return false; 3306 } 3307 3308 /** @hide */ 3309 @SystemApi 3310 public boolean isDataConnectivityPossible() { 3311 try { 3312 return getITelephony().isDataConnectivityPossible(); 3313 } catch (RemoteException e) { 3314 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 3315 } 3316 return false; 3317 } 3318 3319 /** @hide */ 3320 @SystemApi 3321 public boolean needsOtaServiceProvisioning() { 3322 try { 3323 return getITelephony().needsOtaServiceProvisioning(); 3324 } catch (RemoteException e) { 3325 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 3326 } 3327 return false; 3328 } 3329 3330 /** @hide */ 3331 @SystemApi 3332 public void setDataEnabled(boolean enable) { 3333 try { 3334 getITelephony().setDataEnabled(enable); 3335 } catch (RemoteException e) { 3336 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 3337 } 3338 } 3339 3340 /** @hide */ 3341 @SystemApi 3342 public boolean getDataEnabled() { 3343 try { 3344 return getITelephony().getDataEnabled(); 3345 } catch (RemoteException e) { 3346 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 3347 } 3348 return false; 3349 } 3350 3351 /** 3352 * Set whether Android should display a simplified Mobile Network Settings UI. 3353 * The setting won't be persisted during power cycle. 3354 * <p> 3355 * Requires Permission: 3356 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3357 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3358 * 3359 * @param enable true means enabling the simplified UI. 3360 */ 3361 public void enableSimplifiedNetworkSettings(boolean enable) { 3362 enableSimplifiedNetworkSettings(getDefaultSubscription(), enable); 3363 } 3364 3365 /** 3366 * Set whether Android should display a simplified Mobile Network Settings UI. 3367 * The setting won't be persisted during power cycle. 3368 * <p> 3369 * Requires Permission: 3370 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3371 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3372 * 3373 * @param subId for which the simplified UI should be enabled or disabled. 3374 * @param enable true means enabling the simplified UI. 3375 */ 3376 public void enableSimplifiedNetworkSettings(long subId, boolean enable) { 3377 try { 3378 getITelephony().enableSimplifiedNetworkSettings(subId, enable); 3379 } catch (RemoteException ex) { 3380 } catch (NullPointerException ex) { 3381 } 3382 } 3383 3384 /** 3385 * Get whether a simplified Mobile Network Settings UI is enabled. 3386 * <p> 3387 * Requires Permission: 3388 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3389 * 3390 * @return true if the simplified UI is enabled. 3391 */ 3392 public boolean getSimplifiedNetworkSettingsEnabled() { 3393 return getSimplifiedNetworkSettingsEnabled(getDefaultSubscription()); 3394 } 3395 3396 /** 3397 * Get whether a simplified Mobile Network Settings UI is enabled. 3398 * <p> 3399 * Requires Permission: 3400 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3401 * 3402 * @param subId for which the simplified UI should be enabled or disabled. 3403 * @return true if the simplified UI is enabled. 3404 */ 3405 public boolean getSimplifiedNetworkSettingsEnabled(long subId) { 3406 try { 3407 return getITelephony().getSimplifiedNetworkSettingsEnabled(subId); 3408 } catch (RemoteException ex) { 3409 } catch (NullPointerException ex) { 3410 } 3411 return false; 3412 } 3413 3414 /** 3415 * Returns the result and response from RIL for oem request 3416 * 3417 * @param oemReq the data is sent to ril. 3418 * @param oemResp the respose data from RIL. 3419 * @return negative value request was not handled or get error 3420 * 0 request was handled succesfully, but no response data 3421 * positive value success, data length of response 3422 * @hide 3423 */ 3424 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 3425 try { 3426 return getITelephony().invokeOemRilRequestRaw(oemReq, oemResp); 3427 } catch (RemoteException ex) { 3428 } catch (NullPointerException ex) { 3429 } 3430 return -1; 3431 } 3432} 3433