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