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