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