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