TelephonyManager.java revision 6e4a98f8707f759fa9f47a458683a3627e42b0b6
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, getOpPackageName()); 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, getOpPackageName()); 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, getOpPackageName()); 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 * <p> 2026 * The default SMS app can also use this. 2027 */ 2028 public String getLine1Number() { 2029 return getLine1NumberForSubscriber(getDefaultSubscription()); 2030 } 2031 2032 /** 2033 * Returns the phone number string for line 1, for example, the MSISDN 2034 * for a GSM phone for a particular subscription. Return null if it is unavailable. 2035 * <p> 2036 * Requires Permission: 2037 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2038 * <p> 2039 * The default SMS app can also use this. 2040 * 2041 * @param subId whose phone number for line 1 is returned 2042 */ 2043 /** {@hide} */ 2044 public String getLine1NumberForSubscriber(int subId) { 2045 String number = null; 2046 try { 2047 ITelephony telephony = getITelephony(); 2048 if (telephony != null) 2049 number = telephony.getLine1NumberForDisplay(subId, mContext.getOpPackageName()); 2050 } catch (RemoteException ex) { 2051 } catch (NullPointerException ex) { 2052 } 2053 if (number != null) { 2054 return number; 2055 } 2056 try { 2057 IPhoneSubInfo info = getSubscriberInfo(); 2058 if (info == null) 2059 return null; 2060 return info.getLine1NumberForSubscriber(subId, mContext.getOpPackageName()); 2061 } catch (RemoteException ex) { 2062 return null; 2063 } catch (NullPointerException ex) { 2064 // This could happen before phone restarts due to crashing 2065 return null; 2066 } 2067 } 2068 2069 /** 2070 * Set the line 1 phone number string and its alphatag for the current ICCID 2071 * for display purpose only, for example, displayed in Phone Status. It won't 2072 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 2073 * value. 2074 * 2075 * <p>Requires that the calling app has carrier privileges. 2076 * @see #hasCarrierPrivileges 2077 * 2078 * @param alphaTag alpha-tagging of the dailing nubmer 2079 * @param number The dialing number 2080 * @return true if the operation was executed correctly. 2081 */ 2082 public boolean setLine1NumberForDisplay(String alphaTag, String number) { 2083 return setLine1NumberForDisplayForSubscriber(getDefaultSubscription(), alphaTag, number); 2084 } 2085 2086 /** 2087 * Set the line 1 phone number string and its alphatag for the current ICCID 2088 * for display purpose only, for example, displayed in Phone Status. It won't 2089 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 2090 * value. 2091 * 2092 * <p>Requires that the calling app has carrier privileges. 2093 * @see #hasCarrierPrivileges 2094 * 2095 * @param subId the subscriber that the alphatag and dialing number belongs to. 2096 * @param alphaTag alpha-tagging of the dailing nubmer 2097 * @param number The dialing number 2098 * @return true if the operation was executed correctly. 2099 * @hide 2100 */ 2101 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, String number) { 2102 try { 2103 ITelephony telephony = getITelephony(); 2104 if (telephony != null) 2105 return telephony.setLine1NumberForDisplayForSubscriber(subId, alphaTag, number); 2106 } catch (RemoteException ex) { 2107 } catch (NullPointerException ex) { 2108 } 2109 return false; 2110 } 2111 2112 /** 2113 * Returns the alphabetic identifier associated with the line 1 number. 2114 * Return null if it is unavailable. 2115 * <p> 2116 * Requires Permission: 2117 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2118 * @hide 2119 * nobody seems to call this. 2120 */ 2121 public String getLine1AlphaTag() { 2122 return getLine1AlphaTagForSubscriber(getDefaultSubscription()); 2123 } 2124 2125 /** 2126 * Returns the alphabetic identifier associated with the line 1 number 2127 * for a subscription. 2128 * Return null if it is unavailable. 2129 * <p> 2130 * Requires Permission: 2131 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2132 * @param subId whose alphabetic identifier associated with line 1 is returned 2133 * nobody seems to call this. 2134 */ 2135 /** {@hide} */ 2136 public String getLine1AlphaTagForSubscriber(int subId) { 2137 String alphaTag = null; 2138 try { 2139 ITelephony telephony = getITelephony(); 2140 if (telephony != null) 2141 alphaTag = telephony.getLine1AlphaTagForDisplay(subId, 2142 getOpPackageName()); 2143 } catch (RemoteException ex) { 2144 } catch (NullPointerException ex) { 2145 } 2146 if (alphaTag != null) { 2147 return alphaTag; 2148 } 2149 try { 2150 IPhoneSubInfo info = getSubscriberInfo(); 2151 if (info == null) 2152 return null; 2153 return info.getLine1AlphaTagForSubscriber(subId, getOpPackageName()); 2154 } catch (RemoteException ex) { 2155 return null; 2156 } catch (NullPointerException ex) { 2157 // This could happen before phone restarts due to crashing 2158 return null; 2159 } 2160 } 2161 2162 /** 2163 * Return the set of subscriber IDs that should be considered as "merged 2164 * together" for data usage purposes. This is commonly {@code null} to 2165 * indicate no merging is required. Any returned subscribers are sorted in a 2166 * deterministic order. 2167 * 2168 * @hide 2169 */ 2170 public @Nullable String[] getMergedSubscriberIds() { 2171 try { 2172 ITelephony telephony = getITelephony(); 2173 if (telephony != null) 2174 return telephony.getMergedSubscriberIds(getOpPackageName()); 2175 } catch (RemoteException ex) { 2176 } catch (NullPointerException ex) { 2177 } 2178 return null; 2179 } 2180 2181 /** 2182 * Returns the MSISDN string. 2183 * for a GSM phone. Return null if it is unavailable. 2184 * <p> 2185 * Requires Permission: 2186 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2187 * 2188 * @hide 2189 */ 2190 public String getMsisdn() { 2191 return getMsisdn(getDefaultSubscription()); 2192 } 2193 2194 /** 2195 * Returns the MSISDN string. 2196 * for a GSM phone. Return null if it is unavailable. 2197 * <p> 2198 * Requires Permission: 2199 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2200 * 2201 * @param subId for which msisdn is returned 2202 */ 2203 /** {@hide} */ 2204 public String getMsisdn(int subId) { 2205 try { 2206 IPhoneSubInfo info = getSubscriberInfo(); 2207 if (info == null) 2208 return null; 2209 return info.getMsisdnForSubscriber(subId, getOpPackageName()); 2210 } catch (RemoteException ex) { 2211 return null; 2212 } catch (NullPointerException ex) { 2213 // This could happen before phone restarts due to crashing 2214 return null; 2215 } 2216 } 2217 2218 /** 2219 * Returns the voice mail number. Return null if it is unavailable. 2220 * <p> 2221 * Requires Permission: 2222 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2223 */ 2224 public String getVoiceMailNumber() { 2225 return getVoiceMailNumber(getDefaultSubscription()); 2226 } 2227 2228 /** 2229 * Returns the voice mail number for a subscription. 2230 * Return null if it is unavailable. 2231 * <p> 2232 * Requires Permission: 2233 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2234 * @param subId whose voice mail number is returned 2235 */ 2236 /** {@hide} */ 2237 public String getVoiceMailNumber(int subId) { 2238 try { 2239 IPhoneSubInfo info = getSubscriberInfo(); 2240 if (info == null) 2241 return null; 2242 return info.getVoiceMailNumberForSubscriber(subId, getOpPackageName()); 2243 } catch (RemoteException ex) { 2244 return null; 2245 } catch (NullPointerException ex) { 2246 // This could happen before phone restarts due to crashing 2247 return null; 2248 } 2249 } 2250 2251 /** 2252 * Returns the complete voice mail number. Return null if it is unavailable. 2253 * <p> 2254 * Requires Permission: 2255 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 2256 * 2257 * @hide 2258 */ 2259 public String getCompleteVoiceMailNumber() { 2260 return getCompleteVoiceMailNumber(getDefaultSubscription()); 2261 } 2262 2263 /** 2264 * Returns the complete voice mail number. Return null if it is unavailable. 2265 * <p> 2266 * Requires Permission: 2267 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 2268 * 2269 * @param subId 2270 */ 2271 /** {@hide} */ 2272 public String getCompleteVoiceMailNumber(int subId) { 2273 try { 2274 IPhoneSubInfo info = getSubscriberInfo(); 2275 if (info == null) 2276 return null; 2277 return info.getCompleteVoiceMailNumberForSubscriber(subId); 2278 } catch (RemoteException ex) { 2279 return null; 2280 } catch (NullPointerException ex) { 2281 // This could happen before phone restarts due to crashing 2282 return null; 2283 } 2284 } 2285 2286 /** 2287 * Sets the voice mail number. 2288 * 2289 * <p>Requires that the calling app has carrier privileges. 2290 * @see #hasCarrierPrivileges 2291 * 2292 * @param alphaTag The alpha tag to display. 2293 * @param number The voicemail number. 2294 */ 2295 public boolean setVoiceMailNumber(String alphaTag, String number) { 2296 return setVoiceMailNumber(getDefaultSubscription(), alphaTag, number); 2297 } 2298 2299 /** 2300 * Sets the voicemail number for the given subscriber. 2301 * 2302 * <p>Requires that the calling app has carrier privileges. 2303 * @see #hasCarrierPrivileges 2304 * 2305 * @param subId The subscription id. 2306 * @param alphaTag The alpha tag to display. 2307 * @param number The voicemail number. 2308 */ 2309 /** {@hide} */ 2310 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { 2311 try { 2312 ITelephony telephony = getITelephony(); 2313 if (telephony != null) 2314 return telephony.setVoiceMailNumber(subId, alphaTag, number); 2315 } catch (RemoteException ex) { 2316 } catch (NullPointerException ex) { 2317 } 2318 return false; 2319 } 2320 2321 /** 2322 * Returns the voice mail count. Return 0 if unavailable, -1 if there are unread voice messages 2323 * but the count is unknown. 2324 * <p> 2325 * Requires Permission: 2326 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2327 * @hide 2328 */ 2329 public int getVoiceMessageCount() { 2330 return getVoiceMessageCount(getDefaultSubscription()); 2331 } 2332 2333 /** 2334 * Returns the voice mail count for a subscription. Return 0 if unavailable. 2335 * <p> 2336 * Requires Permission: 2337 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2338 * @param subId whose voice message count is returned 2339 */ 2340 /** {@hide} */ 2341 public int getVoiceMessageCount(int subId) { 2342 try { 2343 ITelephony telephony = getITelephony(); 2344 if (telephony == null) 2345 return 0; 2346 return telephony.getVoiceMessageCountForSubscriber(subId); 2347 } catch (RemoteException ex) { 2348 return 0; 2349 } catch (NullPointerException ex) { 2350 // This could happen before phone restarts due to crashing 2351 return 0; 2352 } 2353 } 2354 2355 /** 2356 * Retrieves the alphabetic identifier associated with the voice 2357 * mail number. 2358 * <p> 2359 * Requires Permission: 2360 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2361 */ 2362 public String getVoiceMailAlphaTag() { 2363 return getVoiceMailAlphaTag(getDefaultSubscription()); 2364 } 2365 2366 /** 2367 * Retrieves the alphabetic identifier associated with the voice 2368 * mail number for a subscription. 2369 * <p> 2370 * Requires Permission: 2371 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2372 * @param subId whose alphabetic identifier associated with the 2373 * voice mail number is returned 2374 */ 2375 /** {@hide} */ 2376 public String getVoiceMailAlphaTag(int subId) { 2377 try { 2378 IPhoneSubInfo info = getSubscriberInfo(); 2379 if (info == null) 2380 return null; 2381 return info.getVoiceMailAlphaTagForSubscriber(subId, getOpPackageName()); 2382 } catch (RemoteException ex) { 2383 return null; 2384 } catch (NullPointerException ex) { 2385 // This could happen before phone restarts due to crashing 2386 return null; 2387 } 2388 } 2389 2390 /** 2391 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 2392 * @return the IMPI, or null if not present or not loaded 2393 * @hide 2394 */ 2395 public String getIsimImpi() { 2396 try { 2397 IPhoneSubInfo info = getSubscriberInfo(); 2398 if (info == null) 2399 return null; 2400 return info.getIsimImpi(); 2401 } catch (RemoteException ex) { 2402 return null; 2403 } catch (NullPointerException ex) { 2404 // This could happen before phone restarts due to crashing 2405 return null; 2406 } 2407 } 2408 2409 /** 2410 * Returns the IMS home network domain name that was loaded from the ISIM. 2411 * @return the IMS domain name, or null if not present or not loaded 2412 * @hide 2413 */ 2414 public String getIsimDomain() { 2415 try { 2416 IPhoneSubInfo info = getSubscriberInfo(); 2417 if (info == null) 2418 return null; 2419 return info.getIsimDomain(); 2420 } catch (RemoteException ex) { 2421 return null; 2422 } catch (NullPointerException ex) { 2423 // This could happen before phone restarts due to crashing 2424 return null; 2425 } 2426 } 2427 2428 /** 2429 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 2430 * @return an array of IMPU strings, with one IMPU per string, or null if 2431 * not present or not loaded 2432 * @hide 2433 */ 2434 public String[] getIsimImpu() { 2435 try { 2436 IPhoneSubInfo info = getSubscriberInfo(); 2437 if (info == null) 2438 return null; 2439 return info.getIsimImpu(); 2440 } catch (RemoteException ex) { 2441 return null; 2442 } catch (NullPointerException ex) { 2443 // This could happen before phone restarts due to crashing 2444 return null; 2445 } 2446 } 2447 2448 /** 2449 * @hide 2450 */ 2451 private IPhoneSubInfo getSubscriberInfo() { 2452 // get it each time because that process crashes a lot 2453 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 2454 } 2455 2456 /** Device call state: No activity. */ 2457 public static final int CALL_STATE_IDLE = 0; 2458 /** Device call state: Ringing. A new call arrived and is 2459 * ringing or waiting. In the latter case, another call is 2460 * already active. */ 2461 public static final int CALL_STATE_RINGING = 1; 2462 /** Device call state: Off-hook. At least one call exists 2463 * that is dialing, active, or on hold, and no calls are ringing 2464 * or waiting. */ 2465 public static final int CALL_STATE_OFFHOOK = 2; 2466 2467 /** 2468 * Returns one of the following constants that represents the current state of all 2469 * phone calls. 2470 * 2471 * {@link TelephonyManager#CALL_STATE_RINGING} 2472 * {@link TelephonyManager#CALL_STATE_OFFHOOK} 2473 * {@link TelephonyManager#CALL_STATE_IDLE} 2474 */ 2475 public int getCallState() { 2476 try { 2477 ITelecomService telecom = getTelecomService(); 2478 if (telecom != null) { 2479 return telecom.getCallState(); 2480 } 2481 } catch (RemoteException e) { 2482 Log.e(TAG, "Error calling ITelecomService#getCallState", e); 2483 } 2484 return CALL_STATE_IDLE; 2485 } 2486 2487 /** 2488 * Returns a constant indicating the call state (cellular) on the device 2489 * for a subscription. 2490 * 2491 * @param subId whose call state is returned 2492 */ 2493 /** {@hide} */ 2494 public int getCallState(int subId) { 2495 try { 2496 ITelephony telephony = getITelephony(); 2497 if (telephony == null) 2498 return CALL_STATE_IDLE; 2499 return telephony.getCallStateForSubscriber(subId); 2500 } catch (RemoteException ex) { 2501 // the phone process is restarting. 2502 return CALL_STATE_IDLE; 2503 } catch (NullPointerException ex) { 2504 // the phone process is restarting. 2505 return CALL_STATE_IDLE; 2506 } 2507 } 2508 2509 /** Data connection activity: No traffic. */ 2510 public static final int DATA_ACTIVITY_NONE = 0x00000000; 2511 /** Data connection activity: Currently receiving IP PPP traffic. */ 2512 public static final int DATA_ACTIVITY_IN = 0x00000001; 2513 /** Data connection activity: Currently sending IP PPP traffic. */ 2514 public static final int DATA_ACTIVITY_OUT = 0x00000002; 2515 /** Data connection activity: Currently both sending and receiving 2516 * IP PPP traffic. */ 2517 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 2518 /** 2519 * Data connection is active, but physical link is down 2520 */ 2521 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 2522 2523 /** 2524 * Returns a constant indicating the type of activity on a data connection 2525 * (cellular). 2526 * 2527 * @see #DATA_ACTIVITY_NONE 2528 * @see #DATA_ACTIVITY_IN 2529 * @see #DATA_ACTIVITY_OUT 2530 * @see #DATA_ACTIVITY_INOUT 2531 * @see #DATA_ACTIVITY_DORMANT 2532 */ 2533 public int getDataActivity() { 2534 try { 2535 ITelephony telephony = getITelephony(); 2536 if (telephony == null) 2537 return DATA_ACTIVITY_NONE; 2538 return telephony.getDataActivity(); 2539 } catch (RemoteException ex) { 2540 // the phone process is restarting. 2541 return DATA_ACTIVITY_NONE; 2542 } catch (NullPointerException ex) { 2543 // the phone process is restarting. 2544 return DATA_ACTIVITY_NONE; 2545 } 2546 } 2547 2548 /** Data connection state: Unknown. Used before we know the state. 2549 * @hide 2550 */ 2551 public static final int DATA_UNKNOWN = -1; 2552 /** Data connection state: Disconnected. IP traffic not available. */ 2553 public static final int DATA_DISCONNECTED = 0; 2554 /** Data connection state: Currently setting up a data connection. */ 2555 public static final int DATA_CONNECTING = 1; 2556 /** Data connection state: Connected. IP traffic should be available. */ 2557 public static final int DATA_CONNECTED = 2; 2558 /** Data connection state: Suspended. The connection is up, but IP 2559 * traffic is temporarily unavailable. For example, in a 2G network, 2560 * data activity may be suspended when a voice call arrives. */ 2561 public static final int DATA_SUSPENDED = 3; 2562 2563 /** 2564 * Returns a constant indicating the current data connection state 2565 * (cellular). 2566 * 2567 * @see #DATA_DISCONNECTED 2568 * @see #DATA_CONNECTING 2569 * @see #DATA_CONNECTED 2570 * @see #DATA_SUSPENDED 2571 */ 2572 public int getDataState() { 2573 try { 2574 ITelephony telephony = getITelephony(); 2575 if (telephony == null) 2576 return DATA_DISCONNECTED; 2577 return telephony.getDataState(); 2578 } catch (RemoteException ex) { 2579 // the phone process is restarting. 2580 return DATA_DISCONNECTED; 2581 } catch (NullPointerException ex) { 2582 return DATA_DISCONNECTED; 2583 } 2584 } 2585 2586 /** 2587 * @hide 2588 */ 2589 private ITelephony getITelephony() { 2590 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 2591 } 2592 2593 /** 2594 * @hide 2595 */ 2596 private ITelecomService getTelecomService() { 2597 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); 2598 } 2599 2600 // 2601 // 2602 // PhoneStateListener 2603 // 2604 // 2605 2606 /** 2607 * Registers a listener object to receive notification of changes 2608 * in specified telephony states. 2609 * <p> 2610 * To register a listener, pass a {@link PhoneStateListener} 2611 * and specify at least one telephony state of interest in 2612 * the events argument. 2613 * 2614 * At registration, and when a specified telephony state 2615 * changes, the telephony manager invokes the appropriate 2616 * callback method on the listener object and passes the 2617 * current (updated) values. 2618 * <p> 2619 * To unregister a listener, pass the listener object and set the 2620 * events argument to 2621 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 2622 * 2623 * @param listener The {@link PhoneStateListener} object to register 2624 * (or unregister) 2625 * @param events The telephony state(s) of interest to the listener, 2626 * as a bitwise-OR combination of {@link PhoneStateListener} 2627 * LISTEN_ flags. 2628 */ 2629 public void listen(PhoneStateListener listener, int events) { 2630 if (mContext == null) return; 2631 try { 2632 Boolean notifyNow = (getITelephony() != null); 2633 sRegistry.listenForSubscriber(listener.mSubId, getOpPackageName(), 2634 listener.callback, events, notifyNow); 2635 } catch (RemoteException ex) { 2636 // system process dead 2637 } catch (NullPointerException ex) { 2638 // system process dead 2639 } 2640 } 2641 2642 /** 2643 * Returns the CDMA ERI icon index to display 2644 * 2645 * @hide 2646 */ 2647 public int getCdmaEriIconIndex() { 2648 return getCdmaEriIconIndex(getDefaultSubscription()); 2649 } 2650 2651 /** 2652 * Returns the CDMA ERI icon index to display for a subscription 2653 */ 2654 /** {@hide} */ 2655 public int getCdmaEriIconIndex(int subId) { 2656 try { 2657 ITelephony telephony = getITelephony(); 2658 if (telephony == null) 2659 return -1; 2660 return telephony.getCdmaEriIconIndexForSubscriber(subId, getOpPackageName()); 2661 } catch (RemoteException ex) { 2662 // the phone process is restarting. 2663 return -1; 2664 } catch (NullPointerException ex) { 2665 return -1; 2666 } 2667 } 2668 2669 /** 2670 * Returns the CDMA ERI icon mode, 2671 * 0 - ON 2672 * 1 - FLASHING 2673 * 2674 * @hide 2675 */ 2676 public int getCdmaEriIconMode() { 2677 return getCdmaEriIconMode(getDefaultSubscription()); 2678 } 2679 2680 /** 2681 * Returns the CDMA ERI icon mode for a subscription. 2682 * 0 - ON 2683 * 1 - FLASHING 2684 */ 2685 /** {@hide} */ 2686 public int getCdmaEriIconMode(int subId) { 2687 try { 2688 ITelephony telephony = getITelephony(); 2689 if (telephony == null) 2690 return -1; 2691 return telephony.getCdmaEriIconModeForSubscriber(subId, getOpPackageName()); 2692 } catch (RemoteException ex) { 2693 // the phone process is restarting. 2694 return -1; 2695 } catch (NullPointerException ex) { 2696 return -1; 2697 } 2698 } 2699 2700 /** 2701 * Returns the CDMA ERI text, 2702 * 2703 * @hide 2704 */ 2705 public String getCdmaEriText() { 2706 return getCdmaEriText(getDefaultSubscription()); 2707 } 2708 2709 /** 2710 * Returns the CDMA ERI text, of a subscription 2711 * 2712 */ 2713 /** {@hide} */ 2714 public String getCdmaEriText(int subId) { 2715 try { 2716 ITelephony telephony = getITelephony(); 2717 if (telephony == null) 2718 return null; 2719 return telephony.getCdmaEriTextForSubscriber(subId, getOpPackageName()); 2720 } catch (RemoteException ex) { 2721 // the phone process is restarting. 2722 return null; 2723 } catch (NullPointerException ex) { 2724 return null; 2725 } 2726 } 2727 2728 /** 2729 * @return true if the current device is "voice capable". 2730 * <p> 2731 * "Voice capable" means that this device supports circuit-switched 2732 * (i.e. voice) phone calls over the telephony network, and is allowed 2733 * to display the in-call UI while a cellular voice call is active. 2734 * This will be false on "data only" devices which can't make voice 2735 * calls and don't support any in-call UI. 2736 * <p> 2737 * Note: the meaning of this flag is subtly different from the 2738 * PackageManager.FEATURE_TELEPHONY system feature, which is available 2739 * on any device with a telephony radio, even if the device is 2740 * data-only. 2741 */ 2742 public boolean isVoiceCapable() { 2743 if (mContext == null) return true; 2744 return mContext.getResources().getBoolean( 2745 com.android.internal.R.bool.config_voice_capable); 2746 } 2747 2748 /** 2749 * @return true if the current device supports sms service. 2750 * <p> 2751 * If true, this means that the device supports both sending and 2752 * receiving sms via the telephony network. 2753 * <p> 2754 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 2755 * disabled when device doesn't support sms. 2756 */ 2757 public boolean isSmsCapable() { 2758 if (mContext == null) return true; 2759 return mContext.getResources().getBoolean( 2760 com.android.internal.R.bool.config_sms_capable); 2761 } 2762 2763 /** 2764 * Returns all observed cell information from all radios on the 2765 * device including the primary and neighboring cells. This does 2766 * not cause or change the rate of PhoneStateListner#onCellInfoChanged. 2767 *<p> 2768 * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm}, 2769 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 2770 * {@link android.telephony.CellInfoLte CellInfoLte} and 2771 * {@link android.telephony.CellInfoWcdma CellInfoWcdma} in any combination. 2772 * Specifically on devices with multiple radios it is typical to see instances of 2773 * one or more of any these in the list. In addition 0, 1 or more CellInfo 2774 * objects may return isRegistered() true. 2775 *<p> 2776 * This is preferred over using getCellLocation although for older 2777 * devices this may return null in which case getCellLocation should 2778 * be called. 2779 *<p> 2780 * @return List of CellInfo or null if info unavailable. 2781 * 2782 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 2783 */ 2784 public List<CellInfo> getAllCellInfo() { 2785 try { 2786 ITelephony telephony = getITelephony(); 2787 if (telephony == null) 2788 return null; 2789 return telephony.getAllCellInfo(getOpPackageName()); 2790 } catch (RemoteException ex) { 2791 return null; 2792 } catch (NullPointerException ex) { 2793 return null; 2794 } 2795 } 2796 2797 /** 2798 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 2799 * PhoneStateListener.onCellInfoChanged} will be invoked. 2800 *<p> 2801 * The default, 0, means invoke onCellInfoChanged when any of the reported 2802 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 2803 * A onCellInfoChanged. 2804 *<p> 2805 * @param rateInMillis the rate 2806 * 2807 * @hide 2808 */ 2809 public void setCellInfoListRate(int rateInMillis) { 2810 try { 2811 ITelephony telephony = getITelephony(); 2812 if (telephony != null) 2813 telephony.setCellInfoListRate(rateInMillis); 2814 } catch (RemoteException ex) { 2815 } catch (NullPointerException ex) { 2816 } 2817 } 2818 2819 /** 2820 * Returns the MMS user agent. 2821 */ 2822 public String getMmsUserAgent() { 2823 if (mContext == null) return null; 2824 return mContext.getResources().getString( 2825 com.android.internal.R.string.config_mms_user_agent); 2826 } 2827 2828 /** 2829 * Returns the MMS user agent profile URL. 2830 */ 2831 public String getMmsUAProfUrl() { 2832 if (mContext == null) return null; 2833 return mContext.getResources().getString( 2834 com.android.internal.R.string.config_mms_user_agent_profile_url); 2835 } 2836 2837 /** 2838 * Opens a logical channel to the ICC card. 2839 * 2840 * Input parameters equivalent to TS 27.007 AT+CCHO command. 2841 * 2842 * <p>Requires Permission: 2843 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2844 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2845 * 2846 * @param AID Application id. See ETSI 102.221 and 101.220. 2847 * @return an IccOpenLogicalChannelResponse object. 2848 */ 2849 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { 2850 try { 2851 ITelephony telephony = getITelephony(); 2852 if (telephony != null) 2853 return telephony.iccOpenLogicalChannel(AID); 2854 } catch (RemoteException ex) { 2855 } catch (NullPointerException ex) { 2856 } 2857 return null; 2858 } 2859 2860 /** 2861 * Closes a previously opened logical channel to the ICC card. 2862 * 2863 * Input parameters equivalent to TS 27.007 AT+CCHC command. 2864 * 2865 * <p>Requires Permission: 2866 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2867 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2868 * 2869 * @param channel is the channel id to be closed as retruned by a successful 2870 * iccOpenLogicalChannel. 2871 * @return true if the channel was closed successfully. 2872 */ 2873 public boolean iccCloseLogicalChannel(int channel) { 2874 try { 2875 ITelephony telephony = getITelephony(); 2876 if (telephony != null) 2877 return telephony.iccCloseLogicalChannel(channel); 2878 } catch (RemoteException ex) { 2879 } catch (NullPointerException ex) { 2880 } 2881 return false; 2882 } 2883 2884 /** 2885 * Transmit an APDU to the ICC card over a logical channel. 2886 * 2887 * Input parameters equivalent to TS 27.007 AT+CGLA command. 2888 * 2889 * <p>Requires Permission: 2890 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2891 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2892 * 2893 * @param channel is the channel id to be closed as returned by a successful 2894 * iccOpenLogicalChannel. 2895 * @param cla Class of the APDU command. 2896 * @param instruction Instruction of the APDU command. 2897 * @param p1 P1 value of the APDU command. 2898 * @param p2 P2 value of the APDU command. 2899 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2900 * is sent to the SIM. 2901 * @param data Data to be sent with the APDU. 2902 * @return The APDU response from the ICC card with the status appended at 2903 * the end. 2904 */ 2905 public String iccTransmitApduLogicalChannel(int channel, int cla, 2906 int instruction, int p1, int p2, int p3, String data) { 2907 try { 2908 ITelephony telephony = getITelephony(); 2909 if (telephony != null) 2910 return telephony.iccTransmitApduLogicalChannel(channel, cla, 2911 instruction, p1, p2, p3, data); 2912 } catch (RemoteException ex) { 2913 } catch (NullPointerException ex) { 2914 } 2915 return ""; 2916 } 2917 2918 /** 2919 * Transmit an APDU to the ICC card over the basic channel. 2920 * 2921 * Input parameters equivalent to TS 27.007 AT+CSIM command. 2922 * 2923 * <p>Requires Permission: 2924 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2925 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2926 * 2927 * @param cla Class of the APDU command. 2928 * @param instruction Instruction of the APDU command. 2929 * @param p1 P1 value of the APDU command. 2930 * @param p2 P2 value of the APDU command. 2931 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 2932 * is sent to the SIM. 2933 * @param data Data to be sent with the APDU. 2934 * @return The APDU response from the ICC card with the status appended at 2935 * the end. 2936 */ 2937 public String iccTransmitApduBasicChannel(int cla, 2938 int instruction, int p1, int p2, int p3, String data) { 2939 try { 2940 ITelephony telephony = getITelephony(); 2941 if (telephony != null) 2942 return telephony.iccTransmitApduBasicChannel(cla, 2943 instruction, p1, p2, p3, data); 2944 } catch (RemoteException ex) { 2945 } catch (NullPointerException ex) { 2946 } 2947 return ""; 2948 } 2949 2950 /** 2951 * Returns the response APDU for a command APDU sent through SIM_IO. 2952 * 2953 * <p>Requires Permission: 2954 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2955 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2956 * 2957 * @param fileID 2958 * @param command 2959 * @param p1 P1 value of the APDU command. 2960 * @param p2 P2 value of the APDU command. 2961 * @param p3 P3 value of the APDU command. 2962 * @param filePath 2963 * @return The APDU response. 2964 */ 2965 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 2966 String filePath) { 2967 try { 2968 ITelephony telephony = getITelephony(); 2969 if (telephony != null) 2970 return telephony.iccExchangeSimIO(fileID, command, p1, p2, p3, filePath); 2971 } catch (RemoteException ex) { 2972 } catch (NullPointerException ex) { 2973 } 2974 return null; 2975 } 2976 2977 /** 2978 * Send ENVELOPE to the SIM and return the response. 2979 * 2980 * <p>Requires Permission: 2981 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2982 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2983 * 2984 * @param content String containing SAT/USAT response in hexadecimal 2985 * format starting with command tag. See TS 102 223 for 2986 * details. 2987 * @return The APDU response from the ICC card in hexadecimal format 2988 * with the last 4 bytes being the status word. If the command fails, 2989 * returns an empty string. 2990 */ 2991 public String sendEnvelopeWithStatus(String content) { 2992 try { 2993 ITelephony telephony = getITelephony(); 2994 if (telephony != null) 2995 return telephony.sendEnvelopeWithStatus(content); 2996 } catch (RemoteException ex) { 2997 } catch (NullPointerException ex) { 2998 } 2999 return ""; 3000 } 3001 3002 /** 3003 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 3004 * Used for device configuration by some CDMA operators. 3005 * <p> 3006 * Requires Permission: 3007 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3008 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3009 * 3010 * @param itemID the ID of the item to read. 3011 * @return the NV item as a String, or null on any failure. 3012 * 3013 * @hide 3014 */ 3015 public String nvReadItem(int itemID) { 3016 try { 3017 ITelephony telephony = getITelephony(); 3018 if (telephony != null) 3019 return telephony.nvReadItem(itemID); 3020 } catch (RemoteException ex) { 3021 Rlog.e(TAG, "nvReadItem RemoteException", ex); 3022 } catch (NullPointerException ex) { 3023 Rlog.e(TAG, "nvReadItem NPE", ex); 3024 } 3025 return ""; 3026 } 3027 3028 /** 3029 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 3030 * Used for device configuration by some CDMA operators. 3031 * <p> 3032 * Requires Permission: 3033 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3034 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3035 * 3036 * @param itemID the ID of the item to read. 3037 * @param itemValue the value to write, as a String. 3038 * @return true on success; false on any failure. 3039 * 3040 * @hide 3041 */ 3042 public boolean nvWriteItem(int itemID, String itemValue) { 3043 try { 3044 ITelephony telephony = getITelephony(); 3045 if (telephony != null) 3046 return telephony.nvWriteItem(itemID, itemValue); 3047 } catch (RemoteException ex) { 3048 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 3049 } catch (NullPointerException ex) { 3050 Rlog.e(TAG, "nvWriteItem NPE", ex); 3051 } 3052 return false; 3053 } 3054 3055 /** 3056 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 3057 * Used for device configuration by some CDMA operators. 3058 * <p> 3059 * Requires Permission: 3060 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3061 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3062 * 3063 * @param preferredRoamingList byte array containing the new PRL. 3064 * @return true on success; false on any failure. 3065 * 3066 * @hide 3067 */ 3068 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 3069 try { 3070 ITelephony telephony = getITelephony(); 3071 if (telephony != null) 3072 return telephony.nvWriteCdmaPrl(preferredRoamingList); 3073 } catch (RemoteException ex) { 3074 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 3075 } catch (NullPointerException ex) { 3076 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 3077 } 3078 return false; 3079 } 3080 3081 /** 3082 * Perform the specified type of NV config reset. The radio will be taken offline 3083 * and the device must be rebooted after the operation. Used for device 3084 * configuration by some CDMA operators. 3085 * <p> 3086 * Requires Permission: 3087 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3088 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3089 * 3090 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 3091 * @return true on success; false on any failure. 3092 * 3093 * @hide 3094 */ 3095 public boolean nvResetConfig(int resetType) { 3096 try { 3097 ITelephony telephony = getITelephony(); 3098 if (telephony != null) 3099 return telephony.nvResetConfig(resetType); 3100 } catch (RemoteException ex) { 3101 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 3102 } catch (NullPointerException ex) { 3103 Rlog.e(TAG, "nvResetConfig NPE", ex); 3104 } 3105 return false; 3106 } 3107 3108 /** 3109 * Returns Default subscription. 3110 */ 3111 private static int getDefaultSubscription() { 3112 return SubscriptionManager.getDefaultSubId(); 3113 } 3114 3115 /** 3116 * Returns Default phone. 3117 */ 3118 private static int getDefaultPhone() { 3119 return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubId()); 3120 } 3121 3122 /** {@hide} */ 3123 public int getDefaultSim() { 3124 return SubscriptionManager.getSlotId(SubscriptionManager.getDefaultSubId()); 3125 } 3126 3127 /** 3128 * Sets the telephony property with the value specified. 3129 * 3130 * @hide 3131 */ 3132 public static void setTelephonyProperty(int phoneId, String property, String value) { 3133 String propVal = ""; 3134 String p[] = null; 3135 String prop = SystemProperties.get(property); 3136 3137 if (value == null) { 3138 value = ""; 3139 } 3140 3141 if (prop != null) { 3142 p = prop.split(","); 3143 } 3144 3145 if (!SubscriptionManager.isValidPhoneId(phoneId)) { 3146 Rlog.d(TAG, "setTelephonyProperty: invalid phoneId=" + phoneId + 3147 " property=" + property + " value: " + value + " prop=" + prop); 3148 return; 3149 } 3150 3151 for (int i = 0; i < phoneId; i++) { 3152 String str = ""; 3153 if ((p != null) && (i < p.length)) { 3154 str = p[i]; 3155 } 3156 propVal = propVal + str + ","; 3157 } 3158 3159 propVal = propVal + value; 3160 if (p != null) { 3161 for (int i = phoneId + 1; i < p.length; i++) { 3162 propVal = propVal + "," + p[i]; 3163 } 3164 } 3165 3166 if (property.length() > SystemProperties.PROP_NAME_MAX 3167 || propVal.length() > SystemProperties.PROP_VALUE_MAX) { 3168 Rlog.d(TAG, "setTelephonyProperty: property to long phoneId=" + phoneId + 3169 " property=" + property + " value: " + value + " propVal=" + propVal); 3170 return; 3171 } 3172 3173 Rlog.d(TAG, "setTelephonyProperty: success phoneId=" + phoneId + 3174 " property=" + property + " value: " + value + " propVal=" + propVal); 3175 SystemProperties.set(property, propVal); 3176 } 3177 3178 /** 3179 * Convenience function for retrieving a value from the secure settings 3180 * value list as an integer. Note that internally setting values are 3181 * always stored as strings; this function converts the string to an 3182 * integer for you. 3183 * <p> 3184 * This version does not take a default value. If the setting has not 3185 * been set, or the string value is not a number, 3186 * it throws {@link SettingNotFoundException}. 3187 * 3188 * @param cr The ContentResolver to access. 3189 * @param name The name of the setting to retrieve. 3190 * @param index The index of the list 3191 * 3192 * @throws SettingNotFoundException Thrown if a setting by the given 3193 * name can't be found or the setting value is not an integer. 3194 * 3195 * @return The value at the given index of settings. 3196 * @hide 3197 */ 3198 public static int getIntAtIndex(android.content.ContentResolver cr, 3199 String name, int index) 3200 throws android.provider.Settings.SettingNotFoundException { 3201 String v = android.provider.Settings.Global.getString(cr, name); 3202 if (v != null) { 3203 String valArray[] = v.split(","); 3204 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 3205 try { 3206 return Integer.parseInt(valArray[index]); 3207 } catch (NumberFormatException e) { 3208 //Log.e(TAG, "Exception while parsing Integer: ", e); 3209 } 3210 } 3211 } 3212 throw new android.provider.Settings.SettingNotFoundException(name); 3213 } 3214 3215 /** 3216 * Convenience function for updating settings value as coma separated 3217 * integer values. This will either create a new entry in the table if the 3218 * given name does not exist, or modify the value of the existing row 3219 * with that name. Note that internally setting values are always 3220 * stored as strings, so this function converts the given value to a 3221 * string before storing it. 3222 * 3223 * @param cr The ContentResolver to access. 3224 * @param name The name of the setting to modify. 3225 * @param index The index of the list 3226 * @param value The new value for the setting to be added to the list. 3227 * @return true if the value was set, false on database errors 3228 * @hide 3229 */ 3230 public static boolean putIntAtIndex(android.content.ContentResolver cr, 3231 String name, int index, int value) { 3232 String data = ""; 3233 String valArray[] = null; 3234 String v = android.provider.Settings.Global.getString(cr, name); 3235 3236 if (index == Integer.MAX_VALUE) { 3237 throw new RuntimeException("putIntAtIndex index == MAX_VALUE index=" + index); 3238 } 3239 if (index < 0) { 3240 throw new RuntimeException("putIntAtIndex index < 0 index=" + index); 3241 } 3242 if (v != null) { 3243 valArray = v.split(","); 3244 } 3245 3246 // Copy the elements from valArray till index 3247 for (int i = 0; i < index; i++) { 3248 String str = ""; 3249 if ((valArray != null) && (i < valArray.length)) { 3250 str = valArray[i]; 3251 } 3252 data = data + str + ","; 3253 } 3254 3255 data = data + value; 3256 3257 // Copy the remaining elements from valArray if any. 3258 if (valArray != null) { 3259 for (int i = index+1; i < valArray.length; i++) { 3260 data = data + "," + valArray[i]; 3261 } 3262 } 3263 return android.provider.Settings.Global.putString(cr, name, data); 3264 } 3265 3266 /** 3267 * Gets the telephony property. 3268 * 3269 * @hide 3270 */ 3271 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 3272 String propVal = null; 3273 String prop = SystemProperties.get(property); 3274 if ((prop != null) && (prop.length() > 0)) { 3275 String values[] = prop.split(","); 3276 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 3277 propVal = values[phoneId]; 3278 } 3279 } 3280 return propVal == null ? defaultVal : propVal; 3281 } 3282 3283 /** @hide */ 3284 public int getSimCount() { 3285 // FIXME Need to get it from Telephony Dev Controller when that gets implemented! 3286 // and then this method shouldn't be used at all! 3287 if(isMultiSimEnabled()) { 3288 return 2; 3289 } else { 3290 return 1; 3291 } 3292 } 3293 3294 /** 3295 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 3296 * @return IMS Service Table or null if not present or not loaded 3297 * @hide 3298 */ 3299 public String getIsimIst() { 3300 try { 3301 IPhoneSubInfo info = getSubscriberInfo(); 3302 if (info == null) 3303 return null; 3304 return info.getIsimIst(); 3305 } catch (RemoteException ex) { 3306 return null; 3307 } catch (NullPointerException ex) { 3308 // This could happen before phone restarts due to crashing 3309 return null; 3310 } 3311 } 3312 3313 /** 3314 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 3315 * @return an array of PCSCF strings with one PCSCF per string, or null if 3316 * not present or not loaded 3317 * @hide 3318 */ 3319 public String[] getIsimPcscf() { 3320 try { 3321 IPhoneSubInfo info = getSubscriberInfo(); 3322 if (info == null) 3323 return null; 3324 return info.getIsimPcscf(); 3325 } catch (RemoteException ex) { 3326 return null; 3327 } catch (NullPointerException ex) { 3328 // This could happen before phone restarts due to crashing 3329 return null; 3330 } 3331 } 3332 3333 /** 3334 * Returns the response of ISIM Authetification through RIL. 3335 * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo. 3336 * @return the response of ISIM Authetification, or null if not available 3337 * @hide 3338 * @deprecated 3339 * @see getIccSimChallengeResponse with appType=PhoneConstants.APPTYPE_ISIM 3340 */ 3341 public String getIsimChallengeResponse(String nonce){ 3342 try { 3343 IPhoneSubInfo info = getSubscriberInfo(); 3344 if (info == null) 3345 return null; 3346 return info.getIsimChallengeResponse(nonce); 3347 } catch (RemoteException ex) { 3348 return null; 3349 } catch (NullPointerException ex) { 3350 // This could happen before phone restarts due to crashing 3351 return null; 3352 } 3353 } 3354 3355 /** 3356 * Returns the response of SIM Authentication through RIL. 3357 * Returns null if the Authentication hasn't been successful 3358 * @param subId subscription ID to be queried 3359 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3360 * @param data authentication challenge data 3361 * @return the response of SIM Authentication, or null if not available 3362 * @hide 3363 */ 3364 public String getIccSimChallengeResponse(int subId, int appType, String data) { 3365 try { 3366 IPhoneSubInfo info = getSubscriberInfo(); 3367 if (info == null) 3368 return null; 3369 return info.getIccSimChallengeResponse(subId, appType, data); 3370 } catch (RemoteException ex) { 3371 return null; 3372 } catch (NullPointerException ex) { 3373 // This could happen before phone starts 3374 return null; 3375 } 3376 } 3377 3378 /** 3379 * Returns the response of SIM Authentication through RIL for the default subscription. 3380 * Returns null if the Authentication hasn't been successful 3381 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3382 * @param data authentication challenge data 3383 * @return the response of SIM Authentication, or null if not available 3384 * @hide 3385 */ 3386 public String getIccSimChallengeResponse(int appType, String data) { 3387 return getIccSimChallengeResponse(getDefaultSubscription(), appType, data); 3388 } 3389 3390 /** 3391 * Get P-CSCF address from PCO after data connection is established or modified. 3392 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 3393 * @return array of P-CSCF address 3394 * @hide 3395 */ 3396 public String[] getPcscfAddress(String apnType) { 3397 try { 3398 ITelephony telephony = getITelephony(); 3399 if (telephony == null) 3400 return new String[0]; 3401 return telephony.getPcscfAddress(apnType, getOpPackageName()); 3402 } catch (RemoteException e) { 3403 return new String[0]; 3404 } 3405 } 3406 3407 /** 3408 * Set IMS registration state 3409 * 3410 * @param Registration state 3411 * @hide 3412 */ 3413 public void setImsRegistrationState(boolean registered) { 3414 try { 3415 ITelephony telephony = getITelephony(); 3416 if (telephony != null) 3417 telephony.setImsRegistrationState(registered); 3418 } catch (RemoteException e) { 3419 } 3420 } 3421 3422 /** 3423 * Get the preferred network type. 3424 * Used for device configuration by some CDMA operators. 3425 * <p> 3426 * Requires Permission: 3427 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3428 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3429 * 3430 * @return the preferred network type, defined in RILConstants.java. 3431 * @hide 3432 */ 3433 public int getPreferredNetworkType(int subId) { 3434 try { 3435 ITelephony telephony = getITelephony(); 3436 if (telephony != null) 3437 return telephony.getPreferredNetworkType(subId); 3438 } catch (RemoteException ex) { 3439 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 3440 } catch (NullPointerException ex) { 3441 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 3442 } 3443 return -1; 3444 } 3445 3446 /** 3447 * Sets the network selection mode to automatic. 3448 * <p> 3449 * Requires Permission: 3450 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3451 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3452 * 3453 * @hide 3454 */ 3455 public void setNetworkSelectionModeAutomatic(int subId) { 3456 try { 3457 ITelephony telephony = getITelephony(); 3458 if (telephony != null) 3459 telephony.setNetworkSelectionModeAutomatic(subId); 3460 } catch (RemoteException ex) { 3461 Rlog.e(TAG, "setNetworkSelectionModeAutomatic RemoteException", ex); 3462 } catch (NullPointerException ex) { 3463 Rlog.e(TAG, "setNetworkSelectionModeAutomatic NPE", ex); 3464 } 3465 } 3466 3467 /** 3468 * Perform a radio scan and return the list of avialble networks. 3469 * 3470 * The return value is a list of the OperatorInfo of the networks found. Note that this 3471 * scan can take a long time (sometimes minutes) to happen. 3472 * 3473 * <p> 3474 * Requires Permission: 3475 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3476 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3477 * 3478 * @hide 3479 */ 3480 public CellNetworkScanResult getCellNetworkScanResults(int subId) { 3481 try { 3482 ITelephony telephony = getITelephony(); 3483 if (telephony != null) 3484 return telephony.getCellNetworkScanResults(subId); 3485 } catch (RemoteException ex) { 3486 Rlog.e(TAG, "getCellNetworkScanResults RemoteException", ex); 3487 } catch (NullPointerException ex) { 3488 Rlog.e(TAG, "getCellNetworkScanResults NPE", ex); 3489 } 3490 return null; 3491 } 3492 3493 /** 3494 * Ask the radio to connect to the input network and change selection mode to manual. 3495 * 3496 * <p> 3497 * Requires Permission: 3498 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3499 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3500 * 3501 * @hide 3502 */ 3503 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator) { 3504 try { 3505 ITelephony telephony = getITelephony(); 3506 if (telephony != null) 3507 return telephony.setNetworkSelectionModeManual(subId, operator); 3508 } catch (RemoteException ex) { 3509 Rlog.e(TAG, "setNetworkSelectionModeManual RemoteException", ex); 3510 } catch (NullPointerException ex) { 3511 Rlog.e(TAG, "setNetworkSelectionModeManual NPE", ex); 3512 } 3513 return false; 3514 } 3515 3516 /** 3517 * Set the preferred network type. 3518 * Used for device configuration by some CDMA operators. 3519 * <p> 3520 * Requires Permission: 3521 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3522 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3523 * 3524 * @param subId the id of the subscription to set the preferred network type for. 3525 * @param networkType the preferred network type, defined in RILConstants.java. 3526 * @return true on success; false on any failure. 3527 * @hide 3528 */ 3529 public boolean setPreferredNetworkType(int subId, int networkType) { 3530 try { 3531 ITelephony telephony = getITelephony(); 3532 if (telephony != null) 3533 return telephony.setPreferredNetworkType(subId, networkType); 3534 } catch (RemoteException ex) { 3535 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 3536 } catch (NullPointerException ex) { 3537 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 3538 } 3539 return false; 3540 } 3541 3542 /** 3543 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 3544 * 3545 * <p> 3546 * Requires that the calling app has carrier privileges. 3547 * @see #hasCarrierPrivileges 3548 * 3549 * @return true on success; false on any failure. 3550 */ 3551 public boolean setPreferredNetworkTypeToGlobal() { 3552 return setPreferredNetworkType(getDefaultSubscription(), 3553 RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); 3554 } 3555 3556 /** 3557 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning 3558 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for 3559 * tethering. 3560 * 3561 * @return 0: Not required. 1: required. 2: Not set. 3562 * @hide 3563 */ 3564 public int getTetherApnRequired() { 3565 try { 3566 ITelephony telephony = getITelephony(); 3567 if (telephony != null) 3568 return telephony.getTetherApnRequired(); 3569 } catch (RemoteException ex) { 3570 Rlog.e(TAG, "hasMatchedTetherApnSetting RemoteException", ex); 3571 } catch (NullPointerException ex) { 3572 Rlog.e(TAG, "hasMatchedTetherApnSetting NPE", ex); 3573 } 3574 return 2; 3575 } 3576 3577 3578 /** 3579 * Values used to return status for hasCarrierPrivileges call. 3580 */ 3581 /** @hide */ @SystemApi 3582 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 3583 /** @hide */ @SystemApi 3584 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 3585 /** @hide */ @SystemApi 3586 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 3587 /** @hide */ @SystemApi 3588 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 3589 3590 /** 3591 * Has the calling application been granted carrier privileges by the carrier. 3592 * 3593 * If any of the packages in the calling UID has carrier privileges, the 3594 * call will return true. This access is granted by the owner of the UICC 3595 * card and does not depend on the registered carrier. 3596 * 3597 * @return true if the app has carrier privileges. 3598 */ 3599 public boolean hasCarrierPrivileges() { 3600 try { 3601 ITelephony telephony = getITelephony(); 3602 if (telephony != null) 3603 return telephony.getCarrierPrivilegeStatus() == CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; 3604 } catch (RemoteException ex) { 3605 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3606 } catch (NullPointerException ex) { 3607 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3608 } 3609 return false; 3610 } 3611 3612 /** 3613 * Override the branding for the current ICCID. 3614 * 3615 * Once set, whenever the SIM is present in the device, the service 3616 * provider name (SPN) and the operator name will both be replaced by the 3617 * brand value input. To unset the value, the same function should be 3618 * called with a null brand value. 3619 * 3620 * <p>Requires that the calling app has carrier privileges. 3621 * @see #hasCarrierPrivileges 3622 * 3623 * @param brand The brand name to display/set. 3624 * @return true if the operation was executed correctly. 3625 */ 3626 public boolean setOperatorBrandOverride(String brand) { 3627 try { 3628 ITelephony telephony = getITelephony(); 3629 if (telephony != null) 3630 return telephony.setOperatorBrandOverride(brand); 3631 } catch (RemoteException ex) { 3632 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 3633 } catch (NullPointerException ex) { 3634 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 3635 } 3636 return false; 3637 } 3638 3639 /** 3640 * Override the roaming preference for the current ICCID. 3641 * 3642 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 3643 * the platform's notion of a network operator being considered roaming or not. 3644 * The change only affects the ICCID that was active when this call was made. 3645 * 3646 * If null is passed as any of the input, the corresponding value is deleted. 3647 * 3648 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 3649 * 3650 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 3651 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 3652 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 3653 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 3654 * @return true if the operation was executed correctly. 3655 * 3656 * @hide 3657 */ 3658 public boolean setRoamingOverride(List<String> gsmRoamingList, 3659 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 3660 List<String> cdmaNonRoamingList) { 3661 try { 3662 ITelephony telephony = getITelephony(); 3663 if (telephony != null) 3664 return telephony.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, 3665 cdmaRoamingList, cdmaNonRoamingList); 3666 } catch (RemoteException ex) { 3667 Rlog.e(TAG, "setRoamingOverride RemoteException", ex); 3668 } catch (NullPointerException ex) { 3669 Rlog.e(TAG, "setRoamingOverride NPE", ex); 3670 } 3671 return false; 3672 } 3673 3674 /** 3675 * Expose the rest of ITelephony to @SystemApi 3676 */ 3677 3678 /** @hide */ 3679 @SystemApi 3680 public String getCdmaMdn() { 3681 return getCdmaMdn(getDefaultSubscription()); 3682 } 3683 3684 /** @hide */ 3685 @SystemApi 3686 public String getCdmaMdn(int subId) { 3687 try { 3688 ITelephony telephony = getITelephony(); 3689 if (telephony == null) 3690 return null; 3691 return telephony.getCdmaMdn(subId); 3692 } catch (RemoteException ex) { 3693 return null; 3694 } catch (NullPointerException ex) { 3695 return null; 3696 } 3697 } 3698 3699 /** @hide */ 3700 @SystemApi 3701 public String getCdmaMin() { 3702 return getCdmaMin(getDefaultSubscription()); 3703 } 3704 3705 /** @hide */ 3706 @SystemApi 3707 public String getCdmaMin(int subId) { 3708 try { 3709 ITelephony telephony = getITelephony(); 3710 if (telephony == null) 3711 return null; 3712 return telephony.getCdmaMin(subId); 3713 } catch (RemoteException ex) { 3714 return null; 3715 } catch (NullPointerException ex) { 3716 return null; 3717 } 3718 } 3719 3720 /** @hide */ 3721 @SystemApi 3722 public int checkCarrierPrivilegesForPackage(String pkgName) { 3723 try { 3724 ITelephony telephony = getITelephony(); 3725 if (telephony != null) 3726 return telephony.checkCarrierPrivilegesForPackage(pkgName); 3727 } catch (RemoteException ex) { 3728 Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex); 3729 } catch (NullPointerException ex) { 3730 Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex); 3731 } 3732 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3733 } 3734 3735 /** @hide */ 3736 @SystemApi 3737 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { 3738 try { 3739 ITelephony telephony = getITelephony(); 3740 if (telephony != null) 3741 return telephony.checkCarrierPrivilegesForPackageAnyPhone(pkgName); 3742 } catch (RemoteException ex) { 3743 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone RemoteException", ex); 3744 } catch (NullPointerException ex) { 3745 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone NPE", ex); 3746 } 3747 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 3748 } 3749 3750 /** @hide */ 3751 @SystemApi 3752 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 3753 return getCarrierPackageNamesForIntentAndPhone(intent, getDefaultPhone()); 3754 } 3755 3756 /** @hide */ 3757 @SystemApi 3758 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { 3759 try { 3760 ITelephony telephony = getITelephony(); 3761 if (telephony != null) 3762 return telephony.getCarrierPackageNamesForIntentAndPhone(intent, phoneId); 3763 } catch (RemoteException ex) { 3764 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone RemoteException", ex); 3765 } catch (NullPointerException ex) { 3766 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone NPE", ex); 3767 } 3768 return null; 3769 } 3770 3771 /** @hide */ 3772 @SystemApi 3773 public void dial(String number) { 3774 try { 3775 ITelephony telephony = getITelephony(); 3776 if (telephony != null) 3777 telephony.dial(number); 3778 } catch (RemoteException e) { 3779 Log.e(TAG, "Error calling ITelephony#dial", e); 3780 } 3781 } 3782 3783 /** @hide */ 3784 @SystemApi 3785 public void call(String callingPackage, String number) { 3786 try { 3787 ITelephony telephony = getITelephony(); 3788 if (telephony != null) 3789 telephony.call(callingPackage, number); 3790 } catch (RemoteException e) { 3791 Log.e(TAG, "Error calling ITelephony#call", e); 3792 } 3793 } 3794 3795 /** @hide */ 3796 @SystemApi 3797 public boolean endCall() { 3798 try { 3799 ITelephony telephony = getITelephony(); 3800 if (telephony != null) 3801 return telephony.endCall(); 3802 } catch (RemoteException e) { 3803 Log.e(TAG, "Error calling ITelephony#endCall", e); 3804 } 3805 return false; 3806 } 3807 3808 /** @hide */ 3809 @SystemApi 3810 public void answerRingingCall() { 3811 try { 3812 ITelephony telephony = getITelephony(); 3813 if (telephony != null) 3814 telephony.answerRingingCall(); 3815 } catch (RemoteException e) { 3816 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 3817 } 3818 } 3819 3820 /** @hide */ 3821 @SystemApi 3822 public void silenceRinger() { 3823 try { 3824 getTelecomService().silenceRinger(getOpPackageName()); 3825 } catch (RemoteException e) { 3826 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); 3827 } 3828 } 3829 3830 /** @hide */ 3831 @SystemApi 3832 public boolean isOffhook() { 3833 try { 3834 ITelephony telephony = getITelephony(); 3835 if (telephony != null) 3836 return telephony.isOffhook(getOpPackageName()); 3837 } catch (RemoteException e) { 3838 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 3839 } 3840 return false; 3841 } 3842 3843 /** @hide */ 3844 @SystemApi 3845 public boolean isRinging() { 3846 try { 3847 ITelephony telephony = getITelephony(); 3848 if (telephony != null) 3849 return telephony.isRinging(getOpPackageName()); 3850 } catch (RemoteException e) { 3851 Log.e(TAG, "Error calling ITelephony#isRinging", e); 3852 } 3853 return false; 3854 } 3855 3856 /** @hide */ 3857 @SystemApi 3858 public boolean isIdle() { 3859 try { 3860 ITelephony telephony = getITelephony(); 3861 if (telephony != null) 3862 return telephony.isIdle(getOpPackageName()); 3863 } catch (RemoteException e) { 3864 Log.e(TAG, "Error calling ITelephony#isIdle", e); 3865 } 3866 return true; 3867 } 3868 3869 /** @hide */ 3870 @SystemApi 3871 public boolean isRadioOn() { 3872 try { 3873 ITelephony telephony = getITelephony(); 3874 if (telephony != null) 3875 return telephony.isRadioOn(getOpPackageName()); 3876 } catch (RemoteException e) { 3877 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 3878 } 3879 return false; 3880 } 3881 3882 /** @hide */ 3883 @SystemApi 3884 public boolean isSimPinEnabled() { 3885 try { 3886 ITelephony telephony = getITelephony(); 3887 if (telephony != null) 3888 return telephony.isSimPinEnabled(getOpPackageName()); 3889 } catch (RemoteException e) { 3890 Log.e(TAG, "Error calling ITelephony#isSimPinEnabled", e); 3891 } 3892 return false; 3893 } 3894 3895 /** @hide */ 3896 @SystemApi 3897 public boolean supplyPin(String pin) { 3898 try { 3899 ITelephony telephony = getITelephony(); 3900 if (telephony != null) 3901 return telephony.supplyPin(pin); 3902 } catch (RemoteException e) { 3903 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 3904 } 3905 return false; 3906 } 3907 3908 /** @hide */ 3909 @SystemApi 3910 public boolean supplyPuk(String puk, String pin) { 3911 try { 3912 ITelephony telephony = getITelephony(); 3913 if (telephony != null) 3914 return telephony.supplyPuk(puk, pin); 3915 } catch (RemoteException e) { 3916 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 3917 } 3918 return false; 3919 } 3920 3921 /** @hide */ 3922 @SystemApi 3923 public int[] supplyPinReportResult(String pin) { 3924 try { 3925 ITelephony telephony = getITelephony(); 3926 if (telephony != null) 3927 return telephony.supplyPinReportResult(pin); 3928 } catch (RemoteException e) { 3929 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 3930 } 3931 return new int[0]; 3932 } 3933 3934 /** @hide */ 3935 @SystemApi 3936 public int[] supplyPukReportResult(String puk, String pin) { 3937 try { 3938 ITelephony telephony = getITelephony(); 3939 if (telephony != null) 3940 return telephony.supplyPukReportResult(puk, pin); 3941 } catch (RemoteException e) { 3942 Log.e(TAG, "Error calling ITelephony#]", e); 3943 } 3944 return new int[0]; 3945 } 3946 3947 /** @hide */ 3948 @SystemApi 3949 public boolean handlePinMmi(String dialString) { 3950 try { 3951 ITelephony telephony = getITelephony(); 3952 if (telephony != null) 3953 return telephony.handlePinMmi(dialString); 3954 } catch (RemoteException e) { 3955 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3956 } 3957 return false; 3958 } 3959 3960 /** @hide */ 3961 @SystemApi 3962 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 3963 try { 3964 ITelephony telephony = getITelephony(); 3965 if (telephony != null) 3966 return telephony.handlePinMmiForSubscriber(subId, dialString); 3967 } catch (RemoteException e) { 3968 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 3969 } 3970 return false; 3971 } 3972 3973 /** @hide */ 3974 @SystemApi 3975 public void toggleRadioOnOff() { 3976 try { 3977 ITelephony telephony = getITelephony(); 3978 if (telephony != null) 3979 telephony.toggleRadioOnOff(); 3980 } catch (RemoteException e) { 3981 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 3982 } 3983 } 3984 3985 /** @hide */ 3986 @SystemApi 3987 public boolean setRadio(boolean turnOn) { 3988 try { 3989 ITelephony telephony = getITelephony(); 3990 if (telephony != null) 3991 return telephony.setRadio(turnOn); 3992 } catch (RemoteException e) { 3993 Log.e(TAG, "Error calling ITelephony#setRadio", e); 3994 } 3995 return false; 3996 } 3997 3998 /** @hide */ 3999 @SystemApi 4000 public boolean setRadioPower(boolean turnOn) { 4001 try { 4002 ITelephony telephony = getITelephony(); 4003 if (telephony != null) 4004 return telephony.setRadioPower(turnOn); 4005 } catch (RemoteException e) { 4006 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 4007 } 4008 return false; 4009 } 4010 4011 /** @hide */ 4012 @SystemApi 4013 public void updateServiceLocation() { 4014 try { 4015 ITelephony telephony = getITelephony(); 4016 if (telephony != null) 4017 telephony.updateServiceLocation(); 4018 } catch (RemoteException e) { 4019 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 4020 } 4021 } 4022 4023 /** @hide */ 4024 @SystemApi 4025 public boolean enableDataConnectivity() { 4026 try { 4027 ITelephony telephony = getITelephony(); 4028 if (telephony != null) 4029 return telephony.enableDataConnectivity(); 4030 } catch (RemoteException e) { 4031 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 4032 } 4033 return false; 4034 } 4035 4036 /** @hide */ 4037 @SystemApi 4038 public boolean disableDataConnectivity() { 4039 try { 4040 ITelephony telephony = getITelephony(); 4041 if (telephony != null) 4042 return telephony.disableDataConnectivity(); 4043 } catch (RemoteException e) { 4044 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 4045 } 4046 return false; 4047 } 4048 4049 /** @hide */ 4050 @SystemApi 4051 public boolean isDataConnectivityPossible() { 4052 try { 4053 ITelephony telephony = getITelephony(); 4054 if (telephony != null) 4055 return telephony.isDataConnectivityPossible(); 4056 } catch (RemoteException e) { 4057 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 4058 } 4059 return false; 4060 } 4061 4062 /** @hide */ 4063 @SystemApi 4064 public boolean needsOtaServiceProvisioning() { 4065 try { 4066 ITelephony telephony = getITelephony(); 4067 if (telephony != null) 4068 return telephony.needsOtaServiceProvisioning(); 4069 } catch (RemoteException e) { 4070 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 4071 } 4072 return false; 4073 } 4074 4075 /** @hide */ 4076 @SystemApi 4077 public void setDataEnabled(boolean enable) { 4078 setDataEnabled(SubscriptionManager.getDefaultDataSubId(), enable); 4079 } 4080 4081 /** @hide */ 4082 @SystemApi 4083 public void setDataEnabled(int subId, boolean enable) { 4084 try { 4085 Log.d(TAG, "setDataEnabled: enabled=" + enable); 4086 ITelephony telephony = getITelephony(); 4087 if (telephony != null) 4088 telephony.setDataEnabled(subId, enable); 4089 } catch (RemoteException e) { 4090 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 4091 } 4092 } 4093 4094 /** @hide */ 4095 @SystemApi 4096 public boolean getDataEnabled() { 4097 return getDataEnabled(SubscriptionManager.getDefaultDataSubId()); 4098 } 4099 4100 /** @hide */ 4101 @SystemApi 4102 public boolean getDataEnabled(int subId) { 4103 boolean retVal = false; 4104 try { 4105 ITelephony telephony = getITelephony(); 4106 if (telephony != null) 4107 retVal = telephony.getDataEnabled(subId); 4108 } catch (RemoteException e) { 4109 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 4110 } catch (NullPointerException e) { 4111 } 4112 Log.d(TAG, "getDataEnabled: retVal=" + retVal); 4113 return retVal; 4114 } 4115 4116 /** 4117 * Returns the result and response from RIL for oem request 4118 * 4119 * @param oemReq the data is sent to ril. 4120 * @param oemResp the respose data from RIL. 4121 * @return negative value request was not handled or get error 4122 * 0 request was handled succesfully, but no response data 4123 * positive value success, data length of response 4124 * @hide 4125 */ 4126 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 4127 try { 4128 ITelephony telephony = getITelephony(); 4129 if (telephony != null) 4130 return telephony.invokeOemRilRequestRaw(oemReq, oemResp); 4131 } catch (RemoteException ex) { 4132 } catch (NullPointerException ex) { 4133 } 4134 return -1; 4135 } 4136 4137 /** @hide */ 4138 @SystemApi 4139 public void enableVideoCalling(boolean enable) { 4140 try { 4141 ITelephony telephony = getITelephony(); 4142 if (telephony != null) 4143 telephony.enableVideoCalling(enable); 4144 } catch (RemoteException e) { 4145 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 4146 } 4147 } 4148 4149 /** @hide */ 4150 @SystemApi 4151 public boolean isVideoCallingEnabled() { 4152 try { 4153 ITelephony telephony = getITelephony(); 4154 if (telephony != null) 4155 return telephony.isVideoCallingEnabled(getOpPackageName()); 4156 } catch (RemoteException e) { 4157 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 4158 } 4159 return false; 4160 } 4161 4162 /** 4163 * Whether the device supports configuring the DTMF tone length. 4164 * 4165 * @return {@code true} if the DTMF tone length can be changed, and {@code false} otherwise. 4166 */ 4167 public boolean canChangeDtmfToneLength() { 4168 try { 4169 ITelephony telephony = getITelephony(); 4170 if (telephony != null) { 4171 return telephony.canChangeDtmfToneLength(); 4172 } 4173 } catch (RemoteException e) { 4174 Log.e(TAG, "Error calling ITelephony#canChangeDtmfToneLength", e); 4175 } catch (SecurityException e) { 4176 Log.w(TAG, "Permission error calling ITelephony#canChangeDtmfToneLength", e); 4177 } 4178 return false; 4179 } 4180 4181 /** 4182 * Whether the device is a world phone. 4183 * 4184 * @return {@code true} if the device is a world phone, and {@code false} otherwise. 4185 */ 4186 public boolean isWorldPhone() { 4187 try { 4188 ITelephony telephony = getITelephony(); 4189 if (telephony != null) { 4190 return telephony.isWorldPhone(); 4191 } 4192 } catch (RemoteException e) { 4193 Log.e(TAG, "Error calling ITelephony#isWorldPhone", e); 4194 } 4195 return false; 4196 } 4197 4198 /** 4199 * Whether the phone supports TTY mode. 4200 * 4201 * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. 4202 */ 4203 public boolean isTtyModeSupported() { 4204 try { 4205 ITelephony telephony = getITelephony(); 4206 if (telephony != null) { 4207 return telephony.isTtyModeSupported(); 4208 } 4209 } catch (RemoteException e) { 4210 Log.e(TAG, "Error calling ITelephony#isTtyModeSupported", e); 4211 } 4212 return false; 4213 } 4214 4215 /** 4216 * Whether the phone supports hearing aid compatibility. 4217 * 4218 * @return {@code true} if the device supports hearing aid compatibility, and {@code false} 4219 * otherwise. 4220 */ 4221 public boolean isHearingAidCompatibilitySupported() { 4222 try { 4223 ITelephony telephony = getITelephony(); 4224 if (telephony != null) { 4225 return telephony.isHearingAidCompatibilitySupported(); 4226 } 4227 } catch (RemoteException e) { 4228 Log.e(TAG, "Error calling ITelephony#isHearingAidCompatibilitySupported", e); 4229 } 4230 return false; 4231 } 4232 4233 /** 4234 * This function retrieves value for setting "name+subId", and if that is not found 4235 * retrieves value for setting "name", and if that is not found throws 4236 * SettingNotFoundException 4237 * 4238 * @hide */ 4239 public static int getIntWithSubId(ContentResolver cr, String name, int subId) 4240 throws SettingNotFoundException { 4241 try { 4242 return Settings.Global.getInt(cr, name + subId); 4243 } catch (SettingNotFoundException e) { 4244 try { 4245 int val = Settings.Global.getInt(cr, name); 4246 Settings.Global.putInt(cr, name + subId, val); 4247 4248 /* We are now moving from 'setting' to 'setting+subId', and using the value stored 4249 * for 'setting' as default. Reset the default (since it may have a user set 4250 * value). */ 4251 int default_val = val; 4252 if (name.equals(Settings.Global.MOBILE_DATA)) { 4253 default_val = "true".equalsIgnoreCase( 4254 SystemProperties.get("ro.com.android.mobiledata", "true")) ? 1 : 0; 4255 } else if (name.equals(Settings.Global.DATA_ROAMING)) { 4256 default_val = "true".equalsIgnoreCase( 4257 SystemProperties.get("ro.com.android.dataroaming", "false")) ? 1 : 0; 4258 } 4259 4260 if (default_val != val) { 4261 Settings.Global.putInt(cr, name, default_val); 4262 } 4263 4264 return val; 4265 } catch (SettingNotFoundException exc) { 4266 throw new SettingNotFoundException(name); 4267 } 4268 } 4269 } 4270 4271 /** 4272 * Returns the IMS Registration Status 4273 * @hide 4274 */ 4275 public boolean isImsRegistered() { 4276 try { 4277 ITelephony telephony = getITelephony(); 4278 if (telephony == null) 4279 return false; 4280 return telephony.isImsRegistered(); 4281 } catch (RemoteException ex) { 4282 return false; 4283 } catch (NullPointerException ex) { 4284 return false; 4285 } 4286 } 4287 4288 /** 4289 * Returns the Status of Volte 4290 *@hide 4291 */ 4292 public boolean isVolteEnabled() { 4293 try { 4294 return getITelephony().isVolteEnabled(); 4295 } catch (RemoteException ex) { 4296 return false; 4297 } catch (NullPointerException ex) { 4298 return false; 4299 } 4300 } 4301 4302 /** 4303 * Returns the Status of Wi-Fi Calling 4304 *@hide 4305 */ 4306 public boolean isWifiCallingEnabled() { 4307 try { 4308 return getITelephony().isWifiCallingEnabled(); 4309 } catch (RemoteException ex) { 4310 return false; 4311 } catch (NullPointerException ex) { 4312 return false; 4313 } 4314 } 4315 4316 /** 4317 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 4318 * 4319 * @hide 4320 */ 4321 public void setSimOperatorNumeric(String numeric) { 4322 int phoneId = getDefaultPhone(); 4323 setSimOperatorNumericForPhone(phoneId, numeric); 4324 } 4325 4326 /** 4327 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 4328 * 4329 * @hide 4330 */ 4331 public void setSimOperatorNumericForPhone(int phoneId, String numeric) { 4332 setTelephonyProperty(phoneId, 4333 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, numeric); 4334 } 4335 4336 /** 4337 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 4338 * 4339 * @hide 4340 */ 4341 public void setSimOperatorName(String name) { 4342 int phoneId = getDefaultPhone(); 4343 setSimOperatorNameForPhone(phoneId, name); 4344 } 4345 4346 /** 4347 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 4348 * 4349 * @hide 4350 */ 4351 public void setSimOperatorNameForPhone(int phoneId, String name) { 4352 setTelephonyProperty(phoneId, 4353 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, name); 4354 } 4355 4356 /** 4357 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the default phone. 4358 * 4359 * @hide 4360 */ 4361 public void setSimCountryIso(String iso) { 4362 int phoneId = getDefaultPhone(); 4363 setSimCountryIsoForPhone(phoneId, iso); 4364 } 4365 4366 /** 4367 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the given phone. 4368 * 4369 * @hide 4370 */ 4371 public void setSimCountryIsoForPhone(int phoneId, String iso) { 4372 setTelephonyProperty(phoneId, 4373 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso); 4374 } 4375 4376 /** 4377 * Set TelephonyProperties.PROPERTY_SIM_STATE for the default phone. 4378 * 4379 * @hide 4380 */ 4381 public void setSimState(String state) { 4382 int phoneId = getDefaultPhone(); 4383 setSimStateForPhone(phoneId, state); 4384 } 4385 4386 /** 4387 * Set TelephonyProperties.PROPERTY_SIM_STATE for the given phone. 4388 * 4389 * @hide 4390 */ 4391 public void setSimStateForPhone(int phoneId, String state) { 4392 setTelephonyProperty(phoneId, 4393 TelephonyProperties.PROPERTY_SIM_STATE, state); 4394 } 4395 4396 /** 4397 * Set baseband version for the default phone. 4398 * 4399 * @param version baseband version 4400 * @hide 4401 */ 4402 public void setBasebandVersion(String version) { 4403 int phoneId = getDefaultPhone(); 4404 setBasebandVersionForPhone(phoneId, version); 4405 } 4406 4407 /** 4408 * Set baseband version by phone id. 4409 * 4410 * @param phoneId for which baseband version is set 4411 * @param version baseband version 4412 * @hide 4413 */ 4414 public void setBasebandVersionForPhone(int phoneId, String version) { 4415 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4416 String prop = TelephonyProperties.PROPERTY_BASEBAND_VERSION + 4417 ((phoneId == 0) ? "" : Integer.toString(phoneId)); 4418 SystemProperties.set(prop, version); 4419 } 4420 } 4421 4422 /** 4423 * Set phone type for the default phone. 4424 * 4425 * @param type phone type 4426 * 4427 * @hide 4428 */ 4429 public void setPhoneType(int type) { 4430 int phoneId = getDefaultPhone(); 4431 setPhoneType(phoneId, type); 4432 } 4433 4434 /** 4435 * Set phone type by phone id. 4436 * 4437 * @param phoneId for which phone type is set 4438 * @param type phone type 4439 * 4440 * @hide 4441 */ 4442 public void setPhoneType(int phoneId, int type) { 4443 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4444 TelephonyManager.setTelephonyProperty(phoneId, 4445 TelephonyProperties.CURRENT_ACTIVE_PHONE, String.valueOf(type)); 4446 } 4447 } 4448 4449 /** 4450 * Get OTASP number schema for the default phone. 4451 * 4452 * @param defaultValue default value 4453 * @return OTA SP number schema 4454 * 4455 * @hide 4456 */ 4457 public String getOtaSpNumberSchema(String defaultValue) { 4458 int phoneId = getDefaultPhone(); 4459 return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); 4460 } 4461 4462 /** 4463 * Get OTASP number schema by phone id. 4464 * 4465 * @param phoneId for which OTA SP number schema is get 4466 * @param defaultValue default value 4467 * @return OTA SP number schema 4468 * 4469 * @hide 4470 */ 4471 public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) { 4472 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4473 return TelephonyManager.getTelephonyProperty(phoneId, 4474 TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA, defaultValue); 4475 } 4476 4477 return defaultValue; 4478 } 4479 4480 /** 4481 * Get SMS receive capable from system property for the default phone. 4482 * 4483 * @param defaultValue default value 4484 * @return SMS receive capable 4485 * 4486 * @hide 4487 */ 4488 public boolean getSmsReceiveCapable(boolean defaultValue) { 4489 int phoneId = getDefaultPhone(); 4490 return getSmsReceiveCapableForPhone(phoneId, defaultValue); 4491 } 4492 4493 /** 4494 * Get SMS receive capable from system property by phone id. 4495 * 4496 * @param phoneId for which SMS receive capable is get 4497 * @param defaultValue default value 4498 * @return SMS receive capable 4499 * 4500 * @hide 4501 */ 4502 public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) { 4503 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4504 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 4505 TelephonyProperties.PROPERTY_SMS_RECEIVE, String.valueOf(defaultValue))); 4506 } 4507 4508 return defaultValue; 4509 } 4510 4511 /** 4512 * Get SMS send capable from system property for the default phone. 4513 * 4514 * @param defaultValue default value 4515 * @return SMS send capable 4516 * 4517 * @hide 4518 */ 4519 public boolean getSmsSendCapable(boolean defaultValue) { 4520 int phoneId = getDefaultPhone(); 4521 return getSmsSendCapableForPhone(phoneId, defaultValue); 4522 } 4523 4524 /** 4525 * Get SMS send capable from system property by phone id. 4526 * 4527 * @param phoneId for which SMS send capable is get 4528 * @param defaultValue default value 4529 * @return SMS send capable 4530 * 4531 * @hide 4532 */ 4533 public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) { 4534 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4535 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 4536 TelephonyProperties.PROPERTY_SMS_SEND, String.valueOf(defaultValue))); 4537 } 4538 4539 return defaultValue; 4540 } 4541 4542 /** 4543 * Set the alphabetic name of current registered operator. 4544 * @param name the alphabetic name of current registered operator. 4545 * @hide 4546 */ 4547 public void setNetworkOperatorName(String name) { 4548 int phoneId = getDefaultPhone(); 4549 setNetworkOperatorNameForPhone(phoneId, name); 4550 } 4551 4552 /** 4553 * Set the alphabetic name of current registered operator. 4554 * @param phoneId which phone you want to set 4555 * @param name the alphabetic name of current registered operator. 4556 * @hide 4557 */ 4558 public void setNetworkOperatorNameForPhone(int phoneId, String name) { 4559 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4560 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, name); 4561 } 4562 } 4563 4564 /** 4565 * Set the numeric name (MCC+MNC) of current registered operator. 4566 * @param operator the numeric name (MCC+MNC) of current registered operator 4567 * @hide 4568 */ 4569 public void setNetworkOperatorNumeric(String numeric) { 4570 int phoneId = getDefaultPhone(); 4571 setNetworkOperatorNumericForPhone(phoneId, numeric); 4572 } 4573 4574 /** 4575 * Set the numeric name (MCC+MNC) of current registered operator. 4576 * @param phoneId for which phone type is set 4577 * @param operator the numeric name (MCC+MNC) of current registered operator 4578 * @hide 4579 */ 4580 public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) { 4581 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, numeric); 4582 } 4583 4584 /** 4585 * Set roaming state of the current network, for GSM purposes. 4586 * @param isRoaming is network in romaing state or not 4587 * @hide 4588 */ 4589 public void setNetworkRoaming(boolean isRoaming) { 4590 int phoneId = getDefaultPhone(); 4591 setNetworkRoamingForPhone(phoneId, isRoaming); 4592 } 4593 4594 /** 4595 * Set roaming state of the current network, for GSM purposes. 4596 * @param phoneId which phone you want to set 4597 * @param isRoaming is network in romaing state or not 4598 * @hide 4599 */ 4600 public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) { 4601 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4602 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, 4603 isRoaming ? "true" : "false"); 4604 } 4605 } 4606 4607 /** 4608 * Set the ISO country code equivalent of the current registered 4609 * operator's MCC (Mobile Country Code). 4610 * @param iso the ISO country code equivalent of the current registered 4611 * @hide 4612 */ 4613 public void setNetworkCountryIso(String iso) { 4614 int phoneId = getDefaultPhone(); 4615 setNetworkCountryIsoForPhone(phoneId, iso); 4616 } 4617 4618 /** 4619 * Set the ISO country code equivalent of the current registered 4620 * operator's MCC (Mobile Country Code). 4621 * @param phoneId which phone you want to set 4622 * @param iso the ISO country code equivalent of the current registered 4623 * @hide 4624 */ 4625 public void setNetworkCountryIsoForPhone(int phoneId, String iso) { 4626 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4627 setTelephonyProperty(phoneId, 4628 TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso); 4629 } 4630 } 4631 4632 /** 4633 * Set the network type currently in use on the device for data transmission. 4634 * @param type the network type currently in use on the device for data transmission 4635 * @hide 4636 */ 4637 public void setDataNetworkType(int type) { 4638 int phoneId = getDefaultPhone(); 4639 setDataNetworkTypeForPhone(phoneId, type); 4640 } 4641 4642 /** 4643 * Set the network type currently in use on the device for data transmission. 4644 * @param phoneId which phone you want to set 4645 * @param type the network type currently in use on the device for data transmission 4646 * @hide 4647 */ 4648 public void setDataNetworkTypeForPhone(int phoneId, int type) { 4649 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4650 setTelephonyProperty(phoneId, 4651 TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, 4652 ServiceState.rilRadioTechnologyToString(type)); 4653 } 4654 } 4655 4656 /** 4657 * Returns the subscription ID for the given phone account. 4658 * @hide 4659 */ 4660 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { 4661 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 4662 try { 4663 ITelephony service = getITelephony(); 4664 if (service != null) { 4665 retval = service.getSubIdForPhoneAccount(phoneAccount); 4666 } 4667 } catch (RemoteException e) { 4668 } 4669 4670 return retval; 4671 } 4672 4673 /** 4674 * Resets telephony manager settings back to factory defaults. 4675 * 4676 * @hide 4677 */ 4678 public void factoryReset(int subId) { 4679 try { 4680 Log.d(TAG, "factoryReset: subId=" + subId); 4681 ITelephony telephony = getITelephony(); 4682 if (telephony != null) 4683 telephony.factoryReset(subId); 4684 } catch (RemoteException e) { 4685 } 4686 } 4687 4688 4689 /** @hide */ 4690 public String getLocaleFromDefaultSim() { 4691 try { 4692 final ITelephony telephony = getITelephony(); 4693 if (telephony != null) { 4694 return telephony.getLocaleFromDefaultSim(); 4695 } 4696 } catch (RemoteException ex) { 4697 } 4698 return null; 4699 } 4700 4701 /** 4702 * Returns the modem activity info. 4703 * @hide 4704 */ 4705 public ModemActivityInfo getModemActivityInfo() { 4706 try { 4707 ITelephony service = getITelephony(); 4708 if (service != null) { 4709 return service.getModemActivityInfo(); 4710 } 4711 } catch (RemoteException e) { 4712 Log.e(TAG, "Error calling ITelephony#getModemActivityInfo", e); 4713 } 4714 return null; 4715 } 4716} 4717