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