TelephonyManager.java revision 015f3b464c42421ade3ce508d9412b217ba2c23d
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 * @hide 1782 */ 1783 public void setLine1NumberForDisplay(String alphaTag, String number) { 1784 setLine1NumberForDisplayForSubscriber(getDefaultSubscription(), alphaTag, number); 1785 } 1786 1787 /** 1788 * Set the line 1 phone number string and its alphatag for the current ICCID 1789 * for display purpose only, for example, displayed in Phone Status. It won't 1790 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 1791 * value. 1792 * <p> 1793 * Requires Permission: 1794 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 1795 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 1796 * 1797 * @param subId the subscriber that the alphatag and dialing number belongs to. 1798 * @param alphaTag alpha-tagging of the dailing nubmer 1799 * @param number The dialing number 1800 * @hide 1801 */ 1802 public void setLine1NumberForDisplayForSubscriber(long subId, String alphaTag, String number) { 1803 try { 1804 getITelephony().setLine1NumberForDisplayForSubscriber(subId, alphaTag, number); 1805 } catch (RemoteException ex) { 1806 } catch (NullPointerException ex) { 1807 } 1808 } 1809 1810 /** 1811 * Returns the alphabetic identifier associated with the line 1 number. 1812 * Return null if it is unavailable. 1813 * <p> 1814 * Requires Permission: 1815 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1816 * @hide 1817 * nobody seems to call this. 1818 */ 1819 public String getLine1AlphaTag() { 1820 return getLine1AlphaTagForSubscriber(getDefaultSubscription()); 1821 } 1822 1823 /** 1824 * Returns the alphabetic identifier associated with the line 1 number 1825 * for a subscription. 1826 * Return null if it is unavailable. 1827 * <p> 1828 * Requires Permission: 1829 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1830 * @param subId whose alphabetic identifier associated with line 1 is returned 1831 * nobody seems to call this. 1832 */ 1833 /** {@hide} */ 1834 public String getLine1AlphaTagForSubscriber(long subId) { 1835 String alphaTag = null; 1836 try { 1837 alphaTag = getITelephony().getLine1AlphaTagForDisplay(subId); 1838 } catch (RemoteException ex) { 1839 } catch (NullPointerException ex) { 1840 } 1841 if (alphaTag != null) { 1842 return alphaTag; 1843 } 1844 try { 1845 return getSubscriberInfo().getLine1AlphaTagForSubscriber(subId); 1846 } catch (RemoteException ex) { 1847 return null; 1848 } catch (NullPointerException ex) { 1849 // This could happen before phone restarts due to crashing 1850 return null; 1851 } 1852 } 1853 1854 /** 1855 * Returns the MSISDN string. 1856 * for a GSM phone. Return null if it is unavailable. 1857 * <p> 1858 * Requires Permission: 1859 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1860 * 1861 * @hide 1862 */ 1863 public String getMsisdn() { 1864 return getMsisdn(getDefaultSubscription()); 1865 } 1866 1867 /** 1868 * Returns the MSISDN string. 1869 * for a GSM phone. Return null if it is unavailable. 1870 * <p> 1871 * Requires Permission: 1872 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1873 * 1874 * @param subId for which msisdn is returned 1875 */ 1876 /** {@hide} */ 1877 public String getMsisdn(long subId) { 1878 try { 1879 return getSubscriberInfo().getMsisdnForSubscriber(subId); 1880 } catch (RemoteException ex) { 1881 return null; 1882 } catch (NullPointerException ex) { 1883 // This could happen before phone restarts due to crashing 1884 return null; 1885 } 1886 } 1887 1888 /** 1889 * Returns the voice mail number. Return null if it is unavailable. 1890 * <p> 1891 * Requires Permission: 1892 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1893 */ 1894 public String getVoiceMailNumber() { 1895 return getVoiceMailNumber(getDefaultSubscription()); 1896 } 1897 1898 /** 1899 * Returns the voice mail number for a subscription. 1900 * Return null if it is unavailable. 1901 * <p> 1902 * Requires Permission: 1903 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1904 * @param subId whose voice mail number is returned 1905 */ 1906 /** {@hide} */ 1907 public String getVoiceMailNumber(long subId) { 1908 try { 1909 return getSubscriberInfo().getVoiceMailNumberForSubscriber(subId); 1910 } catch (RemoteException ex) { 1911 return null; 1912 } catch (NullPointerException ex) { 1913 // This could happen before phone restarts due to crashing 1914 return null; 1915 } 1916 } 1917 1918 /** 1919 * Returns the complete voice mail number. Return null if it is unavailable. 1920 * <p> 1921 * Requires Permission: 1922 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 1923 * 1924 * @hide 1925 */ 1926 public String getCompleteVoiceMailNumber() { 1927 return getCompleteVoiceMailNumber(getDefaultSubscription()); 1928 } 1929 1930 /** 1931 * Returns the complete voice mail number. Return null if it is unavailable. 1932 * <p> 1933 * Requires Permission: 1934 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 1935 * 1936 * @param subId 1937 */ 1938 /** {@hide} */ 1939 public String getCompleteVoiceMailNumber(long subId) { 1940 try { 1941 return getSubscriberInfo().getCompleteVoiceMailNumberForSubscriber(subId); 1942 } catch (RemoteException ex) { 1943 return null; 1944 } catch (NullPointerException ex) { 1945 // This could happen before phone restarts due to crashing 1946 return null; 1947 } 1948 } 1949 1950 /** 1951 * Returns the voice mail count. Return 0 if unavailable. 1952 * <p> 1953 * Requires Permission: 1954 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1955 * @hide 1956 */ 1957 public int getVoiceMessageCount() { 1958 return getVoiceMessageCount(getDefaultSubscription()); 1959 } 1960 1961 /** 1962 * Returns the voice mail count for a subscription. Return 0 if unavailable. 1963 * <p> 1964 * Requires Permission: 1965 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1966 * @param subId whose voice message count is returned 1967 */ 1968 /** {@hide} */ 1969 public int getVoiceMessageCount(long subId) { 1970 try { 1971 return getITelephony().getVoiceMessageCountForSubscriber(subId); 1972 } catch (RemoteException ex) { 1973 return 0; 1974 } catch (NullPointerException ex) { 1975 // This could happen before phone restarts due to crashing 1976 return 0; 1977 } 1978 } 1979 1980 /** 1981 * Retrieves the alphabetic identifier associated with the voice 1982 * mail number. 1983 * <p> 1984 * Requires Permission: 1985 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1986 */ 1987 public String getVoiceMailAlphaTag() { 1988 return getVoiceMailAlphaTag(getDefaultSubscription()); 1989 } 1990 1991 /** 1992 * Retrieves the alphabetic identifier associated with the voice 1993 * mail number for a subscription. 1994 * <p> 1995 * Requires Permission: 1996 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1997 * @param subId whose alphabetic identifier associated with the 1998 * voice mail number is returned 1999 */ 2000 /** {@hide} */ 2001 public String getVoiceMailAlphaTag(long subId) { 2002 try { 2003 return getSubscriberInfo().getVoiceMailAlphaTagForSubscriber(subId); 2004 } catch (RemoteException ex) { 2005 return null; 2006 } catch (NullPointerException ex) { 2007 // This could happen before phone restarts due to crashing 2008 return null; 2009 } 2010 } 2011 2012 /** 2013 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 2014 * @return the IMPI, or null if not present or not loaded 2015 * @hide 2016 */ 2017 public String getIsimImpi() { 2018 try { 2019 return getSubscriberInfo().getIsimImpi(); 2020 } catch (RemoteException ex) { 2021 return null; 2022 } catch (NullPointerException ex) { 2023 // This could happen before phone restarts due to crashing 2024 return null; 2025 } 2026 } 2027 2028 /** 2029 * Returns the IMS home network domain name that was loaded from the ISIM. 2030 * @return the IMS domain name, or null if not present or not loaded 2031 * @hide 2032 */ 2033 public String getIsimDomain() { 2034 try { 2035 return getSubscriberInfo().getIsimDomain(); 2036 } catch (RemoteException ex) { 2037 return null; 2038 } catch (NullPointerException ex) { 2039 // This could happen before phone restarts due to crashing 2040 return null; 2041 } 2042 } 2043 2044 /** 2045 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 2046 * @return an array of IMPU strings, with one IMPU per string, or null if 2047 * not present or not loaded 2048 * @hide 2049 */ 2050 public String[] getIsimImpu() { 2051 try { 2052 return getSubscriberInfo().getIsimImpu(); 2053 } catch (RemoteException ex) { 2054 return null; 2055 } catch (NullPointerException ex) { 2056 // This could happen before phone restarts due to crashing 2057 return null; 2058 } 2059 } 2060 2061 /** 2062 * @hide 2063 */ 2064 private IPhoneSubInfo getSubscriberInfo() { 2065 // get it each time because that process crashes a lot 2066 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 2067 } 2068 2069 /** Device call state: No activity. */ 2070 public static final int CALL_STATE_IDLE = 0; 2071 /** Device call state: Ringing. A new call arrived and is 2072 * ringing or waiting. In the latter case, another call is 2073 * already active. */ 2074 public static final int CALL_STATE_RINGING = 1; 2075 /** Device call state: Off-hook. At least one call exists 2076 * that is dialing, active, or on hold, and no calls are ringing 2077 * or waiting. */ 2078 public static final int CALL_STATE_OFFHOOK = 2; 2079 2080 /** 2081 * Returns a constant indicating the call state (cellular) on the device. 2082 */ 2083 public int getCallState() { 2084 try { 2085 return getTelecomService().getCallState(); 2086 } catch (RemoteException | NullPointerException e) { 2087 return CALL_STATE_IDLE; 2088 } 2089 } 2090 2091 /** 2092 * Returns a constant indicating the call state (cellular) on the device 2093 * for a subscription. 2094 * 2095 * @param subId whose call state is returned 2096 */ 2097 /** {@hide} */ 2098 public int getCallState(long subId) { 2099 try { 2100 return getITelephony().getCallStateForSubscriber(subId); 2101 } catch (RemoteException ex) { 2102 // the phone process is restarting. 2103 return CALL_STATE_IDLE; 2104 } catch (NullPointerException ex) { 2105 // the phone process is restarting. 2106 return CALL_STATE_IDLE; 2107 } 2108 } 2109 2110 /** Data connection activity: No traffic. */ 2111 public static final int DATA_ACTIVITY_NONE = 0x00000000; 2112 /** Data connection activity: Currently receiving IP PPP traffic. */ 2113 public static final int DATA_ACTIVITY_IN = 0x00000001; 2114 /** Data connection activity: Currently sending IP PPP traffic. */ 2115 public static final int DATA_ACTIVITY_OUT = 0x00000002; 2116 /** Data connection activity: Currently both sending and receiving 2117 * IP PPP traffic. */ 2118 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 2119 /** 2120 * Data connection is active, but physical link is down 2121 */ 2122 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 2123 2124 /** 2125 * Returns a constant indicating the type of activity on a data connection 2126 * (cellular). 2127 * 2128 * @see #DATA_ACTIVITY_NONE 2129 * @see #DATA_ACTIVITY_IN 2130 * @see #DATA_ACTIVITY_OUT 2131 * @see #DATA_ACTIVITY_INOUT 2132 * @see #DATA_ACTIVITY_DORMANT 2133 */ 2134 public int getDataActivity() { 2135 try { 2136 return getITelephony().getDataActivity(); 2137 } catch (RemoteException ex) { 2138 // the phone process is restarting. 2139 return DATA_ACTIVITY_NONE; 2140 } catch (NullPointerException ex) { 2141 // the phone process is restarting. 2142 return DATA_ACTIVITY_NONE; 2143 } 2144 } 2145 2146 /** Data connection state: Unknown. Used before we know the state. 2147 * @hide 2148 */ 2149 public static final int DATA_UNKNOWN = -1; 2150 /** Data connection state: Disconnected. IP traffic not available. */ 2151 public static final int DATA_DISCONNECTED = 0; 2152 /** Data connection state: Currently setting up a data connection. */ 2153 public static final int DATA_CONNECTING = 1; 2154 /** Data connection state: Connected. IP traffic should be available. */ 2155 public static final int DATA_CONNECTED = 2; 2156 /** Data connection state: Suspended. The connection is up, but IP 2157 * traffic is temporarily unavailable. For example, in a 2G network, 2158 * data activity may be suspended when a voice call arrives. */ 2159 public static final int DATA_SUSPENDED = 3; 2160 2161 /** 2162 * Returns a constant indicating the current data connection state 2163 * (cellular). 2164 * 2165 * @see #DATA_DISCONNECTED 2166 * @see #DATA_CONNECTING 2167 * @see #DATA_CONNECTED 2168 * @see #DATA_SUSPENDED 2169 */ 2170 public int getDataState() { 2171 try { 2172 return getITelephony().getDataState(); 2173 } catch (RemoteException ex) { 2174 // the phone process is restarting. 2175 return DATA_DISCONNECTED; 2176 } catch (NullPointerException ex) { 2177 return DATA_DISCONNECTED; 2178 } 2179 } 2180 2181 /** 2182 * @hide 2183 */ 2184 private ITelephony getITelephony() { 2185 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 2186 } 2187 2188 /** 2189 * @hide 2190 */ 2191 private ITelecomService getTelecomService() { 2192 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); 2193 } 2194 2195 // 2196 // 2197 // PhoneStateListener 2198 // 2199 // 2200 2201 /** 2202 * Registers a listener object to receive notification of changes 2203 * in specified telephony states. 2204 * <p> 2205 * To register a listener, pass a {@link PhoneStateListener} 2206 * and specify at least one telephony state of interest in 2207 * the events argument. 2208 * 2209 * At registration, and when a specified telephony state 2210 * changes, the telephony manager invokes the appropriate 2211 * callback method on the listener object and passes the 2212 * current (updated) values. 2213 * <p> 2214 * To unregister a listener, pass the listener object and set the 2215 * events argument to 2216 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 2217 * 2218 * @param listener The {@link PhoneStateListener} object to register 2219 * (or unregister) 2220 * @param events The telephony state(s) of interest to the listener, 2221 * as a bitwise-OR combination of {@link PhoneStateListener} 2222 * LISTEN_ flags. 2223 */ 2224 public void listen(PhoneStateListener listener, int events) { 2225 String pkgForDebug = mContext != null ? mContext.getPackageName() : "<unknown>"; 2226 try { 2227 Boolean notifyNow = (getITelephony() != null); 2228 sRegistry.listenForSubscriber(listener.mSubId, pkgForDebug, listener.callback, events, notifyNow); 2229 } catch (RemoteException ex) { 2230 // system process dead 2231 } catch (NullPointerException ex) { 2232 // system process dead 2233 } 2234 } 2235 2236 /** 2237 * Returns the CDMA ERI icon index to display 2238 * 2239 * @hide 2240 */ 2241 public int getCdmaEriIconIndex() { 2242 return getCdmaEriIconIndex(getDefaultSubscription()); 2243 } 2244 2245 /** 2246 * Returns the CDMA ERI icon index to display for a subscription 2247 */ 2248 /** {@hide} */ 2249 public int getCdmaEriIconIndex(long subId) { 2250 try { 2251 return getITelephony().getCdmaEriIconIndexForSubscriber(subId); 2252 } catch (RemoteException ex) { 2253 // the phone process is restarting. 2254 return -1; 2255 } catch (NullPointerException ex) { 2256 return -1; 2257 } 2258 } 2259 2260 /** 2261 * Returns the CDMA ERI icon mode, 2262 * 0 - ON 2263 * 1 - FLASHING 2264 * 2265 * @hide 2266 */ 2267 public int getCdmaEriIconMode() { 2268 return getCdmaEriIconMode(getDefaultSubscription()); 2269 } 2270 2271 /** 2272 * Returns the CDMA ERI icon mode for a subscription. 2273 * 0 - ON 2274 * 1 - FLASHING 2275 */ 2276 /** {@hide} */ 2277 public int getCdmaEriIconMode(long subId) { 2278 try { 2279 return getITelephony().getCdmaEriIconModeForSubscriber(subId); 2280 } catch (RemoteException ex) { 2281 // the phone process is restarting. 2282 return -1; 2283 } catch (NullPointerException ex) { 2284 return -1; 2285 } 2286 } 2287 2288 /** 2289 * Returns the CDMA ERI text, 2290 * 2291 * @hide 2292 */ 2293 public String getCdmaEriText() { 2294 return getCdmaEriText(getDefaultSubscription()); 2295 } 2296 2297 /** 2298 * Returns the CDMA ERI text, of a subscription 2299 * 2300 */ 2301 /** {@hide} */ 2302 public String getCdmaEriText(long subId) { 2303 try { 2304 return getITelephony().getCdmaEriTextForSubscriber(subId); 2305 } catch (RemoteException ex) { 2306 // the phone process is restarting. 2307 return null; 2308 } catch (NullPointerException ex) { 2309 return null; 2310 } 2311 } 2312 2313 /** 2314 * @return true if the current device is "voice capable". 2315 * <p> 2316 * "Voice capable" means that this device supports circuit-switched 2317 * (i.e. voice) phone calls over the telephony network, and is allowed 2318 * to display the in-call UI while a cellular voice call is active. 2319 * This will be false on "data only" devices which can't make voice 2320 * calls and don't support any in-call UI. 2321 * <p> 2322 * Note: the meaning of this flag is subtly different from the 2323 * PackageManager.FEATURE_TELEPHONY system feature, which is available 2324 * on any device with a telephony radio, even if the device is 2325 * data-only. 2326 * 2327 * @hide pending API review 2328 */ 2329 public boolean isVoiceCapable() { 2330 if (mContext == null) return true; 2331 return mContext.getResources().getBoolean( 2332 com.android.internal.R.bool.config_voice_capable); 2333 } 2334 2335 /** 2336 * @return true if the current device supports sms service. 2337 * <p> 2338 * If true, this means that the device supports both sending and 2339 * receiving sms via the telephony network. 2340 * <p> 2341 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 2342 * disabled when device doesn't support sms. 2343 */ 2344 public boolean isSmsCapable() { 2345 if (mContext == null) return true; 2346 return mContext.getResources().getBoolean( 2347 com.android.internal.R.bool.config_sms_capable); 2348 } 2349 2350 /** 2351 * Returns all observed cell information from all radios on the 2352 * device including the primary and neighboring cells. This does 2353 * not cause or change the rate of PhoneStateListner#onCellInfoChanged. 2354 *<p> 2355 * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm}, 2356 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 2357 * {@link android.telephony.CellInfoLte CellInfoLte} and 2358 * {@link android.telephony.CellInfoWcdma CellInfoCdma} in any combination. 2359 * Specifically on devices with multiple radios it is typical to see instances of 2360 * one or more of any these in the list. In addition 0, 1 or more CellInfo 2361 * objects may return isRegistered() true. 2362 *<p> 2363 * This is preferred over using getCellLocation although for older 2364 * devices this may return null in which case getCellLocation should 2365 * be called. 2366 *<p> 2367 * @return List of CellInfo or null if info unavailable. 2368 * 2369 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 2370 */ 2371 public List<CellInfo> getAllCellInfo() { 2372 try { 2373 return getITelephony().getAllCellInfo(); 2374 } catch (RemoteException ex) { 2375 return null; 2376 } catch (NullPointerException ex) { 2377 return null; 2378 } 2379 } 2380 2381 /** 2382 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 2383 * PhoneStateListener.onCellInfoChanged} will be invoked. 2384 *<p> 2385 * The default, 0, means invoke onCellInfoChanged when any of the reported 2386 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 2387 * A onCellInfoChanged. 2388 *<p> 2389 * @param rateInMillis the rate 2390 * 2391 * @hide 2392 */ 2393 public void setCellInfoListRate(int rateInMillis) { 2394 try { 2395 getITelephony().setCellInfoListRate(rateInMillis); 2396 } catch (RemoteException ex) { 2397 } catch (NullPointerException ex) { 2398 } 2399 } 2400 2401 /** 2402 * Returns the MMS user agent. 2403 */ 2404 public String getMmsUserAgent() { 2405 if (mContext == null) return null; 2406 return mContext.getResources().getString( 2407 com.android.internal.R.string.config_mms_user_agent); 2408 } 2409 2410 /** 2411 * Returns the MMS user agent profile URL. 2412 */ 2413 public String getMmsUAProfUrl() { 2414 if (mContext == null) return null; 2415 return mContext.getResources().getString( 2416 com.android.internal.R.string.config_mms_user_agent_profile_url); 2417 } 2418 2419 /** 2420 * Opens a logical channel to the ICC card. 2421 * 2422 * Input parameters equivalent to TS 27.007 AT+CCHO command. 2423 * 2424 * <p>Requires Permission: 2425 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 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 * 2447 * @param channel is the channel id to be closed as retruned by a successful 2448 * iccOpenLogicalChannel. 2449 * @return true if the channel was closed successfully. 2450 */ 2451 public boolean iccCloseLogicalChannel(int channel) { 2452 try { 2453 return getITelephony().iccCloseLogicalChannel(channel); 2454 } catch (RemoteException ex) { 2455 } catch (NullPointerException ex) { 2456 } 2457 return false; 2458 } 2459 2460 /** 2461 * Transmit an APDU to the ICC card over a logical channel. 2462 * 2463 * Input parameters equivalent to TS 27.007 AT+CGLA command. 2464 * 2465 * <p>Requires Permission: 2466 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2467 * 2468 * @param channel is the channel id to be closed as returned by a successful 2469 * iccOpenLogicalChannel. 2470 * @param cla Class of the APDU command. 2471 * @param instruction Instruction of the APDU command. 2472 * @param p1 P1 value of the APDU command. 2473 * @param p2 P2 value of the APDU command. 2474 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2475 * is sent to the SIM. 2476 * @param data Data to be sent with the APDU. 2477 * @return The APDU response from the ICC card with the status appended at 2478 * the end. 2479 */ 2480 public String iccTransmitApduLogicalChannel(int channel, int cla, 2481 int instruction, int p1, int p2, int p3, String data) { 2482 try { 2483 return getITelephony().iccTransmitApduLogicalChannel(channel, cla, 2484 instruction, p1, p2, p3, data); 2485 } catch (RemoteException ex) { 2486 } catch (NullPointerException ex) { 2487 } 2488 return ""; 2489 } 2490 2491 /** 2492 * Transmit an APDU to the ICC card over the basic channel. 2493 * 2494 * Input parameters equivalent to TS 27.007 AT+CSIM command. 2495 * 2496 * <p>Requires Permission: 2497 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2498 * 2499 * @param cla Class of the APDU command. 2500 * @param instruction Instruction of the APDU command. 2501 * @param p1 P1 value of the APDU command. 2502 * @param p2 P2 value of the APDU command. 2503 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2504 * is sent to the SIM. 2505 * @param data Data to be sent with the APDU. 2506 * @return The APDU response from the ICC card with the status appended at 2507 * the end. 2508 */ 2509 public String iccTransmitApduBasicChannel(int cla, 2510 int instruction, int p1, int p2, int p3, String data) { 2511 try { 2512 return getITelephony().iccTransmitApduBasicChannel(cla, 2513 instruction, p1, p2, p3, data); 2514 } catch (RemoteException ex) { 2515 } catch (NullPointerException ex) { 2516 } 2517 return ""; 2518 } 2519 2520 /** 2521 * Returns the response APDU for a command APDU sent through SIM_IO. 2522 * 2523 * <p>Requires Permission: 2524 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2525 * 2526 * @param fileID 2527 * @param command 2528 * @param p1 P1 value of the APDU command. 2529 * @param p2 P2 value of the APDU command. 2530 * @param p3 P3 value of the APDU command. 2531 * @param filePath 2532 * @return The APDU response. 2533 */ 2534 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 2535 String filePath) { 2536 try { 2537 return getITelephony().iccExchangeSimIO(fileID, command, p1, p2, 2538 p3, filePath); 2539 } catch (RemoteException ex) { 2540 } catch (NullPointerException ex) { 2541 } 2542 return null; 2543 } 2544 2545 /** 2546 * Send ENVELOPE to the SIM and return the response. 2547 * 2548 * <p>Requires Permission: 2549 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2550 * 2551 * @param content String containing SAT/USAT response in hexadecimal 2552 * format starting with command tag. See TS 102 223 for 2553 * details. 2554 * @return The APDU response from the ICC card in hexadecimal format 2555 * with the last 4 bytes being the status word. If the command fails, 2556 * returns an empty string. 2557 */ 2558 public String sendEnvelopeWithStatus(String content) { 2559 try { 2560 return getITelephony().sendEnvelopeWithStatus(content); 2561 } catch (RemoteException ex) { 2562 } catch (NullPointerException ex) { 2563 } 2564 return ""; 2565 } 2566 2567 /** 2568 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 2569 * Used for device configuration by some CDMA operators. 2570 * <p> 2571 * Requires Permission: 2572 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2573 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2574 * 2575 * @param itemID the ID of the item to read. 2576 * @return the NV item as a String, or null on any failure. 2577 * 2578 * @hide 2579 */ 2580 public String nvReadItem(int itemID) { 2581 try { 2582 return getITelephony().nvReadItem(itemID); 2583 } catch (RemoteException ex) { 2584 Rlog.e(TAG, "nvReadItem RemoteException", ex); 2585 } catch (NullPointerException ex) { 2586 Rlog.e(TAG, "nvReadItem NPE", ex); 2587 } 2588 return ""; 2589 } 2590 2591 /** 2592 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 2593 * Used for device configuration by some CDMA operators. 2594 * <p> 2595 * Requires Permission: 2596 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2597 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2598 * 2599 * @param itemID the ID of the item to read. 2600 * @param itemValue the value to write, as a String. 2601 * @return true on success; false on any failure. 2602 * 2603 * @hide 2604 */ 2605 public boolean nvWriteItem(int itemID, String itemValue) { 2606 try { 2607 return getITelephony().nvWriteItem(itemID, itemValue); 2608 } catch (RemoteException ex) { 2609 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 2610 } catch (NullPointerException ex) { 2611 Rlog.e(TAG, "nvWriteItem NPE", ex); 2612 } 2613 return false; 2614 } 2615 2616 /** 2617 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 2618 * Used for device configuration by some CDMA operators. 2619 * <p> 2620 * Requires Permission: 2621 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2622 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2623 * 2624 * @param preferredRoamingList byte array containing the new PRL. 2625 * @return true on success; false on any failure. 2626 * 2627 * @hide 2628 */ 2629 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 2630 try { 2631 return getITelephony().nvWriteCdmaPrl(preferredRoamingList); 2632 } catch (RemoteException ex) { 2633 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 2634 } catch (NullPointerException ex) { 2635 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 2636 } 2637 return false; 2638 } 2639 2640 /** 2641 * Perform the specified type of NV config reset. The radio will be taken offline 2642 * and the device must be rebooted after the operation. Used for device 2643 * configuration by some CDMA operators. 2644 * <p> 2645 * Requires Permission: 2646 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2647 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2648 * 2649 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 2650 * @return true on success; false on any failure. 2651 * 2652 * @hide 2653 */ 2654 public boolean nvResetConfig(int resetType) { 2655 try { 2656 return getITelephony().nvResetConfig(resetType); 2657 } catch (RemoteException ex) { 2658 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 2659 } catch (NullPointerException ex) { 2660 Rlog.e(TAG, "nvResetConfig NPE", ex); 2661 } 2662 return false; 2663 } 2664 2665 /** 2666 * Returns Default subscription. 2667 */ 2668 private static long getDefaultSubscription() { 2669 return SubscriptionManager.getDefaultSubId(); 2670 } 2671 2672 /** 2673 * Returns Default phone. 2674 */ 2675 private static int getDefaultPhone() { 2676 return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubId()); 2677 } 2678 2679 /** {@hide} */ 2680 public int getDefaultSim() { 2681 return SubscriptionManager.getSlotId(SubscriptionManager.getDefaultSubId()); 2682 } 2683 2684 /** 2685 * Sets the telephony property with the value specified. 2686 * 2687 * @hide 2688 */ 2689 public static void setTelephonyProperty(int phoneId, String property, String value) { 2690 Rlog.d(TAG, "setTelephonyProperty property: " + property + " phoneId: " + phoneId + 2691 " value: " + value); 2692 String propVal = ""; 2693 String p[] = null; 2694 String prop = SystemProperties.get(property); 2695 2696 if (value == null) { 2697 value = ""; 2698 } 2699 2700 if (prop != null) { 2701 p = prop.split(","); 2702 } 2703 2704 if (!SubscriptionManager.isValidPhoneId(phoneId)) { 2705 Rlog.d(TAG, "setTelephonyProperty invalid phone id"); 2706 return; 2707 } 2708 2709 for (int i = 0; i < phoneId; i++) { 2710 String str = ""; 2711 if ((p != null) && (i < p.length)) { 2712 str = p[i]; 2713 } 2714 propVal = propVal + str + ","; 2715 } 2716 2717 propVal = propVal + value; 2718 if (p != null) { 2719 for (int i = phoneId + 1; i < p.length; i++) { 2720 propVal = propVal + "," + p[i]; 2721 } 2722 } 2723 2724 // TODO: workaround for QC 2725 if (property.length() > SystemProperties.PROP_NAME_MAX || propVal.length() > SystemProperties.PROP_VALUE_MAX) { 2726 Rlog.d(TAG, "setTelephonyProperty length too long:" + property + ", " + propVal); 2727 return; 2728 } 2729 2730 Rlog.d(TAG, "setTelephonyProperty property=" + property + " propVal=" + propVal); 2731 SystemProperties.set(property, propVal); 2732 } 2733 2734 /** 2735 * Convenience function for retrieving a value from the secure settings 2736 * value list as an integer. Note that internally setting values are 2737 * always stored as strings; this function converts the string to an 2738 * integer for you. 2739 * <p> 2740 * This version does not take a default value. If the setting has not 2741 * been set, or the string value is not a number, 2742 * it throws {@link SettingNotFoundException}. 2743 * 2744 * @param cr The ContentResolver to access. 2745 * @param name The name of the setting to retrieve. 2746 * @param index The index of the list 2747 * 2748 * @throws SettingNotFoundException Thrown if a setting by the given 2749 * name can't be found or the setting value is not an integer. 2750 * 2751 * @return The value at the given index of settings. 2752 * @hide 2753 */ 2754 public static int getIntAtIndex(android.content.ContentResolver cr, 2755 String name, int index) 2756 throws android.provider.Settings.SettingNotFoundException { 2757 String v = android.provider.Settings.Global.getString(cr, name); 2758 if (v != null) { 2759 String valArray[] = v.split(","); 2760 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 2761 try { 2762 return Integer.parseInt(valArray[index]); 2763 } catch (NumberFormatException e) { 2764 //Log.e(TAG, "Exception while parsing Integer: ", e); 2765 } 2766 } 2767 } 2768 throw new android.provider.Settings.SettingNotFoundException(name); 2769 } 2770 2771 /** 2772 * Convenience function for updating settings value as coma separated 2773 * integer values. This will either create a new entry in the table if the 2774 * given name does not exist, or modify the value of the existing row 2775 * with that name. Note that internally setting values are always 2776 * stored as strings, so this function converts the given value to a 2777 * string before storing it. 2778 * 2779 * @param cr The ContentResolver to access. 2780 * @param name The name of the setting to modify. 2781 * @param index The index of the list 2782 * @param value The new value for the setting to be added to the list. 2783 * @return true if the value was set, false on database errors 2784 * @hide 2785 */ 2786 public static boolean putIntAtIndex(android.content.ContentResolver cr, 2787 String name, int index, int value) { 2788 String data = ""; 2789 String valArray[] = null; 2790 String v = android.provider.Settings.Global.getString(cr, name); 2791 2792 if (index == Integer.MAX_VALUE) { 2793 throw new RuntimeException("putIntAtIndex index == MAX_VALUE index=" + index); 2794 } 2795 if (index < 0) { 2796 throw new RuntimeException("putIntAtIndex index < 0 index=" + index); 2797 } 2798 if (v != null) { 2799 valArray = v.split(","); 2800 } 2801 2802 // Copy the elements from valArray till index 2803 for (int i = 0; i < index; i++) { 2804 String str = ""; 2805 if ((valArray != null) && (i < valArray.length)) { 2806 str = valArray[i]; 2807 } 2808 data = data + str + ","; 2809 } 2810 2811 data = data + value; 2812 2813 // Copy the remaining elements from valArray if any. 2814 if (valArray != null) { 2815 for (int i = index+1; i < valArray.length; i++) { 2816 data = data + "," + valArray[i]; 2817 } 2818 } 2819 return android.provider.Settings.Global.putString(cr, name, data); 2820 } 2821 2822 /** 2823 * Gets the telephony property. 2824 * 2825 * @hide 2826 */ 2827 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 2828 String propVal = null; 2829 String prop = SystemProperties.get(property); 2830 if ((prop != null) && (prop.length() > 0)) { 2831 String values[] = prop.split(","); 2832 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 2833 propVal = values[phoneId]; 2834 } 2835 } 2836 return propVal == null ? defaultVal : propVal; 2837 } 2838 2839 /** @hide */ 2840 public int getSimCount() { 2841 if(isMultiSimEnabled()) { 2842 //FIXME Need to get it from Telephony Devcontroller 2843 return 2; 2844 } else { 2845 return 1; 2846 } 2847 } 2848 2849 /** 2850 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 2851 * @return IMS Service Table or null if not present or not loaded 2852 * @hide 2853 */ 2854 public String getIsimIst() { 2855 try { 2856 return getSubscriberInfo().getIsimIst(); 2857 } catch (RemoteException ex) { 2858 return null; 2859 } catch (NullPointerException ex) { 2860 // This could happen before phone restarts due to crashing 2861 return null; 2862 } 2863 } 2864 2865 /** 2866 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 2867 * @return an array of PCSCF strings with one PCSCF per string, or null if 2868 * not present or not loaded 2869 * @hide 2870 */ 2871 public String[] getIsimPcscf() { 2872 try { 2873 return getSubscriberInfo().getIsimPcscf(); 2874 } catch (RemoteException ex) { 2875 return null; 2876 } catch (NullPointerException ex) { 2877 // This could happen before phone restarts due to crashing 2878 return null; 2879 } 2880 } 2881 2882 /** 2883 * Returns the response of ISIM Authetification through RIL. 2884 * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo. 2885 * @return the response of ISIM Authetification, or null if not available 2886 * @hide 2887 * @deprecated 2888 * @see getIccSimChallengeResponse with appType=PhoneConstants.APPTYPE_ISIM 2889 */ 2890 public String getIsimChallengeResponse(String nonce){ 2891 try { 2892 return getSubscriberInfo().getIsimChallengeResponse(nonce); 2893 } catch (RemoteException ex) { 2894 return null; 2895 } catch (NullPointerException ex) { 2896 // This could happen before phone restarts due to crashing 2897 return null; 2898 } 2899 } 2900 2901 /** 2902 * Returns the response of SIM Authentication through RIL. 2903 * Returns null if the Authentication hasn't been successful 2904 * @param subId subscription ID to be queried 2905 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 2906 * @param data authentication challenge data 2907 * @return the response of SIM Authentication, or null if not available 2908 * @hide 2909 */ 2910 public String getIccSimChallengeResponse(long subId, int appType, String data) { 2911 try { 2912 return getSubscriberInfo().getIccSimChallengeResponse(subId, appType, data); 2913 } catch (RemoteException ex) { 2914 return null; 2915 } catch (NullPointerException ex) { 2916 // This could happen before phone starts 2917 return null; 2918 } 2919 } 2920 2921 /** 2922 * Returns the response of SIM Authentication through RIL for the default subscription. 2923 * Returns null if the Authentication hasn't been successful 2924 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 2925 * @param data authentication challenge data 2926 * @return the response of SIM Authentication, or null if not available 2927 * @hide 2928 */ 2929 public String getIccSimChallengeResponse(int appType, String data) { 2930 return getIccSimChallengeResponse(getDefaultSubscription(), appType, data); 2931 } 2932 2933 /** 2934 * Get P-CSCF address from PCO after data connection is established or modified. 2935 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 2936 * @return array of P-CSCF address 2937 * @hide 2938 */ 2939 public String[] getPcscfAddress(String apnType) { 2940 try { 2941 return getITelephony().getPcscfAddress(apnType); 2942 } catch (RemoteException e) { 2943 return new String[0]; 2944 } 2945 } 2946 2947 /** 2948 * Set IMS registration state 2949 * 2950 * @param Registration state 2951 * @hide 2952 */ 2953 public void setImsRegistrationState(boolean registered) { 2954 try { 2955 getITelephony().setImsRegistrationState(registered); 2956 } catch (RemoteException e) { 2957 } 2958 } 2959 2960 /** 2961 * Get the preferred network type. 2962 * Used for device configuration by some CDMA operators. 2963 * <p> 2964 * Requires Permission: 2965 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2966 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2967 * 2968 * @return the preferred network type, defined in RILConstants.java. 2969 * @hide 2970 */ 2971 public int getPreferredNetworkType() { 2972 try { 2973 return getITelephony().getPreferredNetworkType(); 2974 } catch (RemoteException ex) { 2975 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 2976 } catch (NullPointerException ex) { 2977 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 2978 } 2979 return -1; 2980 } 2981 2982 /** 2983 * Set the preferred network type. 2984 * Used for device configuration by some CDMA operators. 2985 * <p> 2986 * Requires Permission: 2987 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2988 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2989 * 2990 * @param networkType the preferred network type, defined in RILConstants.java. 2991 * @return true on success; false on any failure. 2992 * @hide 2993 */ 2994 public boolean setPreferredNetworkType(int networkType) { 2995 try { 2996 return getITelephony().setPreferredNetworkType(networkType); 2997 } catch (RemoteException ex) { 2998 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 2999 } catch (NullPointerException ex) { 3000 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 3001 } 3002 return false; 3003 } 3004 3005 /** 3006 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 3007 * 3008 * <p> 3009 * Requires Permission: 3010 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3011 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3012 * 3013 * @return true on success; false on any failure. 3014 * @hide 3015 */ 3016 public boolean setGlobalPreferredNetworkType() { 3017 return setPreferredNetworkType(RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); 3018 } 3019 3020 /** 3021 * Values used to return status for hasCarrierPrivileges call. 3022 * @hide 3023 */ 3024 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 3025 /** 3026 * Values used to return status for hasCarrierPrivileges call. 3027 * @hide 3028 */ 3029 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 3030 /** 3031 * Values used to return status for hasCarrierPrivileges call. 3032 * @hide 3033 */ 3034 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 3035 /** 3036 * Values used to return status for hasCarrierPrivileges call. 3037 * @hide 3038 */ 3039 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 3040 3041 /** 3042 * Has the calling application been granted carrier privileges by the carrier. 3043 * 3044 * If any of the packages in the calling UID has carrier privileges, the 3045 * call will return true. This access is granted by the owner of the UICC 3046 * card and does not depend on the registered carrier. 3047 * 3048 * TODO: Add a link to documentation. 3049 * 3050 * @return CARRIER_PRIVILEGE_STATUS_HAS_ACCESS if the app has carrier privileges. 3051 * CARRIER_PRIVILEGE_STATUS_NO_ACCESS if the app does not have carrier privileges. 3052 * CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED if the carrier rules are not loaded. 3053 * CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES if there was an error loading carrier 3054 * rules (or if there are no rules). 3055 * @hide 3056 */ 3057 public int hasCarrierPrivileges() { 3058 try { 3059 return getITelephony().hasCarrierPrivileges(); 3060 } catch (RemoteException ex) { 3061 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3062 } catch (NullPointerException ex) { 3063 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3064 } 3065 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3066 } 3067 3068 /** 3069 * Override the branding for the current ICCID. 3070 * 3071 * Once set, whenever the SIM is present in the device, the service 3072 * provider name (SPN) and the operator name will both be replaced by the 3073 * brand value input. To unset the value, the same function should be 3074 * called with a null brand value. 3075 * 3076 * <p>Requires Permission: 3077 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3078 * or has to be carrier app - see #hasCarrierPrivileges. 3079 * 3080 * @param brand The brand name to display/set. 3081 * @return true if the operation was executed correctly. 3082 * @hide 3083 */ 3084 public boolean setOperatorBrandOverride(String brand) { 3085 try { 3086 return getITelephony().setOperatorBrandOverride(brand); 3087 } catch (RemoteException ex) { 3088 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 3089 } catch (NullPointerException ex) { 3090 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 3091 } 3092 return false; 3093 } 3094 3095 /** 3096 * Expose the rest of ITelephony to @SystemApi 3097 */ 3098 3099 /** @hide */ 3100 @SystemApi 3101 public String getCdmaMdn() { 3102 return getCdmaMdn(getDefaultSubscription()); 3103 } 3104 3105 /** @hide */ 3106 @SystemApi 3107 public String getCdmaMdn(long subId) { 3108 try { 3109 return getITelephony().getCdmaMdn(subId); 3110 } catch (RemoteException ex) { 3111 return null; 3112 } catch (NullPointerException ex) { 3113 return null; 3114 } 3115 } 3116 3117 /** @hide */ 3118 @SystemApi 3119 public String getCdmaMin() { 3120 return getCdmaMin(getDefaultSubscription()); 3121 } 3122 3123 /** @hide */ 3124 @SystemApi 3125 public String getCdmaMin(long subId) { 3126 try { 3127 return getITelephony().getCdmaMin(subId); 3128 } catch (RemoteException ex) { 3129 return null; 3130 } catch (NullPointerException ex) { 3131 return null; 3132 } 3133 } 3134 3135 /** @hide */ 3136 @SystemApi 3137 public int checkCarrierPrivilegesForPackage(String pkgname) { 3138 try { 3139 return getITelephony().checkCarrierPrivilegesForPackage(pkgname); 3140 } catch (RemoteException ex) { 3141 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3142 } catch (NullPointerException ex) { 3143 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3144 } 3145 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3146 } 3147 3148 /** @hide */ 3149 @SystemApi 3150 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 3151 try { 3152 return getITelephony().getCarrierPackageNamesForIntent(intent); 3153 } catch (RemoteException ex) { 3154 Rlog.e(TAG, "getCarrierPackageNamesForIntent RemoteException", ex); 3155 } catch (NullPointerException ex) { 3156 Rlog.e(TAG, "getCarrierPackageNamesForIntent NPE", ex); 3157 } 3158 return null; 3159 } 3160 3161 /** @hide */ 3162 @SystemApi 3163 public void dial(String number) { 3164 try { 3165 getITelephony().dial(number); 3166 } catch (RemoteException e) { 3167 Log.e(TAG, "Error calling ITelephony#dial", e); 3168 } 3169 } 3170 3171 /** @hide */ 3172 @SystemApi 3173 public void call(String callingPackage, String number) { 3174 try { 3175 getITelephony().call(callingPackage, number); 3176 } catch (RemoteException e) { 3177 Log.e(TAG, "Error calling ITelephony#call", e); 3178 } 3179 } 3180 3181 /** @hide */ 3182 @SystemApi 3183 public boolean endCall() { 3184 try { 3185 return getITelephony().endCall(); 3186 } catch (RemoteException e) { 3187 Log.e(TAG, "Error calling ITelephony#endCall", e); 3188 } 3189 return false; 3190 } 3191 3192 /** @hide */ 3193 @SystemApi 3194 public void answerRingingCall() { 3195 try { 3196 getITelephony().answerRingingCall(); 3197 } catch (RemoteException e) { 3198 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 3199 } 3200 } 3201 3202 /** @hide */ 3203 @SystemApi 3204 public void silenceRinger() { 3205 try { 3206 getTelecomService().silenceRinger(); 3207 } catch (RemoteException e) { 3208 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); 3209 } 3210 } 3211 3212 /** @hide */ 3213 @SystemApi 3214 public boolean isOffhook() { 3215 try { 3216 return getITelephony().isOffhook(); 3217 } catch (RemoteException e) { 3218 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 3219 } 3220 return false; 3221 } 3222 3223 /** @hide */ 3224 @SystemApi 3225 public boolean isRinging() { 3226 try { 3227 return getITelephony().isRinging(); 3228 } catch (RemoteException e) { 3229 Log.e(TAG, "Error calling ITelephony#isRinging", e); 3230 } 3231 return false; 3232 } 3233 3234 /** @hide */ 3235 @SystemApi 3236 public boolean isIdle() { 3237 try { 3238 return getITelephony().isIdle(); 3239 } catch (RemoteException e) { 3240 Log.e(TAG, "Error calling ITelephony#isIdle", e); 3241 } 3242 return true; 3243 } 3244 3245 /** @hide */ 3246 @SystemApi 3247 public boolean isRadioOn() { 3248 try { 3249 return getITelephony().isRadioOn(); 3250 } catch (RemoteException e) { 3251 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 3252 } 3253 return false; 3254 } 3255 3256 /** @hide */ 3257 @SystemApi 3258 public boolean isSimPinEnabled() { 3259 try { 3260 return getITelephony().isSimPinEnabled(); 3261 } catch (RemoteException e) { 3262 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 3263 } 3264 return false; 3265 } 3266 3267 /** @hide */ 3268 @SystemApi 3269 public boolean supplyPin(String pin) { 3270 try { 3271 return getITelephony().supplyPin(pin); 3272 } catch (RemoteException e) { 3273 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 3274 } 3275 return false; 3276 } 3277 3278 /** @hide */ 3279 @SystemApi 3280 public boolean supplyPuk(String puk, String pin) { 3281 try { 3282 return getITelephony().supplyPuk(puk, pin); 3283 } catch (RemoteException e) { 3284 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 3285 } 3286 return false; 3287 } 3288 3289 /** @hide */ 3290 @SystemApi 3291 public int[] supplyPinReportResult(String pin) { 3292 try { 3293 return getITelephony().supplyPinReportResult(pin); 3294 } catch (RemoteException e) { 3295 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 3296 } 3297 return new int[0]; 3298 } 3299 3300 /** @hide */ 3301 @SystemApi 3302 public int[] supplyPukReportResult(String puk, String pin) { 3303 try { 3304 return getITelephony().supplyPukReportResult(puk, pin); 3305 } catch (RemoteException e) { 3306 Log.e(TAG, "Error calling ITelephony#]", e); 3307 } 3308 return new int[0]; 3309 } 3310 3311 /** @hide */ 3312 @SystemApi 3313 public boolean handlePinMmi(String dialString) { 3314 try { 3315 return getITelephony().handlePinMmi(dialString); 3316 } catch (RemoteException e) { 3317 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3318 } 3319 return false; 3320 } 3321 3322 /** @hide */ 3323 @SystemApi 3324 public void toggleRadioOnOff() { 3325 try { 3326 getITelephony().toggleRadioOnOff(); 3327 } catch (RemoteException e) { 3328 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 3329 } 3330 } 3331 3332 /** @hide */ 3333 @SystemApi 3334 public boolean setRadio(boolean turnOn) { 3335 try { 3336 return getITelephony().setRadio(turnOn); 3337 } catch (RemoteException e) { 3338 Log.e(TAG, "Error calling ITelephony#setRadio", e); 3339 } 3340 return false; 3341 } 3342 3343 /** @hide */ 3344 @SystemApi 3345 public boolean setRadioPower(boolean turnOn) { 3346 try { 3347 return getITelephony().setRadioPower(turnOn); 3348 } catch (RemoteException e) { 3349 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 3350 } 3351 return false; 3352 } 3353 3354 /** @hide */ 3355 @SystemApi 3356 public void updateServiceLocation() { 3357 try { 3358 getITelephony().updateServiceLocation(); 3359 } catch (RemoteException e) { 3360 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 3361 } 3362 } 3363 3364 /** @hide */ 3365 @SystemApi 3366 public boolean enableDataConnectivity() { 3367 try { 3368 return getITelephony().enableDataConnectivity(); 3369 } catch (RemoteException e) { 3370 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 3371 } 3372 return false; 3373 } 3374 3375 /** @hide */ 3376 @SystemApi 3377 public boolean disableDataConnectivity() { 3378 try { 3379 return getITelephony().disableDataConnectivity(); 3380 } catch (RemoteException e) { 3381 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 3382 } 3383 return false; 3384 } 3385 3386 /** @hide */ 3387 @SystemApi 3388 public boolean isDataConnectivityPossible() { 3389 try { 3390 return getITelephony().isDataConnectivityPossible(); 3391 } catch (RemoteException e) { 3392 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 3393 } 3394 return false; 3395 } 3396 3397 /** @hide */ 3398 @SystemApi 3399 public boolean needsOtaServiceProvisioning() { 3400 try { 3401 return getITelephony().needsOtaServiceProvisioning(); 3402 } catch (RemoteException e) { 3403 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 3404 } 3405 return false; 3406 } 3407 3408 /** @hide */ 3409 @SystemApi 3410 public void setDataEnabled(boolean enable) { 3411 try { 3412 getITelephony().setDataEnabled(enable); 3413 } catch (RemoteException e) { 3414 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 3415 } 3416 } 3417 3418 /** @hide */ 3419 @SystemApi 3420 public boolean getDataEnabled() { 3421 try { 3422 return getITelephony().getDataEnabled(); 3423 } catch (RemoteException e) { 3424 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 3425 } 3426 return false; 3427 } 3428 3429 /** 3430 * Set whether Android should display a simplified Mobile Network Settings UI 3431 * for the current ICCID. 3432 * <p> 3433 * Requires Permission: 3434 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3435 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3436 * 3437 * @param enable true means enabling the simplified UI. 3438 * @hide 3439 */ 3440 public void enableSimplifiedNetworkSettings(boolean enable) { 3441 enableSimplifiedNetworkSettingsForSubscriber(getDefaultSubscription(), enable); 3442 } 3443 3444 /** 3445 * Set whether Android should display a simplified Mobile Network Settings UI 3446 * for the current ICCID. 3447 * <p> 3448 * Requires Permission: 3449 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3450 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3451 * 3452 * @param subId for which the simplified UI should be enabled or disabled. 3453 * @param enable true means enabling the simplified UI. 3454 * @hide 3455 */ 3456 public void enableSimplifiedNetworkSettingsForSubscriber(long subId, boolean enable) { 3457 try { 3458 getITelephony().enableSimplifiedNetworkSettingsForSubscriber(subId, enable); 3459 } catch (RemoteException ex) { 3460 } catch (NullPointerException ex) { 3461 } 3462 } 3463 3464 /** 3465 * Get whether a simplified Mobile Network Settings UI is enabled for the 3466 * current ICCID. 3467 * <p> 3468 * Requires Permission: 3469 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3470 * 3471 * @return true if the simplified UI is enabled. 3472 * @hide 3473 */ 3474 public boolean getSimplifiedNetworkSettingsEnabled() { 3475 return getSimplifiedNetworkSettingsEnabledForSubscriber(getDefaultSubscription()); 3476 } 3477 3478 /** 3479 * Get whether a simplified Mobile Network Settings UI is enabled for the 3480 * current ICCID. 3481 * <p> 3482 * Requires Permission: 3483 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3484 * 3485 * @param subId for which the simplified UI should be enabled or disabled. 3486 * @return true if the simplified UI is enabled. 3487 * @hide 3488 */ 3489 public boolean getSimplifiedNetworkSettingsEnabledForSubscriber(long subId) { 3490 try { 3491 return getITelephony().getSimplifiedNetworkSettingsEnabledForSubscriber(subId); 3492 } catch (RemoteException ex) { 3493 } catch (NullPointerException ex) { 3494 } 3495 return false; 3496 } 3497 3498 /** 3499 * Returns the result and response from RIL for oem request 3500 * 3501 * @param oemReq the data is sent to ril. 3502 * @param oemResp the respose data from RIL. 3503 * @return negative value request was not handled or get error 3504 * 0 request was handled succesfully, but no response data 3505 * positive value success, data length of response 3506 * @hide 3507 */ 3508 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 3509 try { 3510 return getITelephony().invokeOemRilRequestRaw(oemReq, oemResp); 3511 } catch (RemoteException ex) { 3512 } catch (NullPointerException ex) { 3513 } 3514 return -1; 3515 } 3516} 3517