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