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