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