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