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