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