TelephonyManager.java revision 66f0c6f3b8bde3ba224a1333a4acbf1b86c959ec
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. This does 2848 * not cause or change the rate of PhoneStateListener#onCellInfoChanged. 2849 *<p> 2850 * The list can include one or more of {@link android.telephony.CellInfoGsm CellInfoGsm}, 2851 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 2852 * {@link android.telephony.CellInfoLte CellInfoLte} and 2853 * {@link android.telephony.CellInfoWcdma CellInfoWcdma} in any combination. 2854 * Specifically on devices with multiple radios it is typical to see instances of 2855 * one or more of any these in the list. In addition 0, 1 or more CellInfo 2856 * objects may return isRegistered() true. 2857 *<p> 2858 * This is preferred over using getCellLocation although for older 2859 * devices this may return null in which case getCellLocation should 2860 * be called. 2861 *<p> 2862 * This API will return valid data for registered cells on devices with 2863 * {@link android.content.pm.PackageManager#FEATURE_TELEPHONY} 2864 *<p> 2865 * @return List of CellInfo or null if info unavailable. 2866 * 2867 * <p>Requires Permission: {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 2868 */ 2869 public List<CellInfo> getAllCellInfo() { 2870 try { 2871 ITelephony telephony = getITelephony(); 2872 if (telephony == null) 2873 return null; 2874 return telephony.getAllCellInfo(getOpPackageName()); 2875 } catch (RemoteException ex) { 2876 return null; 2877 } catch (NullPointerException ex) { 2878 return null; 2879 } 2880 } 2881 2882 /** 2883 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 2884 * PhoneStateListener.onCellInfoChanged} will be invoked. 2885 *<p> 2886 * The default, 0, means invoke onCellInfoChanged when any of the reported 2887 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 2888 * A onCellInfoChanged. 2889 *<p> 2890 * @param rateInMillis the rate 2891 * 2892 * @hide 2893 */ 2894 public void setCellInfoListRate(int rateInMillis) { 2895 try { 2896 ITelephony telephony = getITelephony(); 2897 if (telephony != null) 2898 telephony.setCellInfoListRate(rateInMillis); 2899 } catch (RemoteException ex) { 2900 } catch (NullPointerException ex) { 2901 } 2902 } 2903 2904 /** 2905 * Returns the MMS user agent. 2906 */ 2907 public String getMmsUserAgent() { 2908 if (mContext == null) return null; 2909 return mContext.getResources().getString( 2910 com.android.internal.R.string.config_mms_user_agent); 2911 } 2912 2913 /** 2914 * Returns the MMS user agent profile URL. 2915 */ 2916 public String getMmsUAProfUrl() { 2917 if (mContext == null) return null; 2918 return mContext.getResources().getString( 2919 com.android.internal.R.string.config_mms_user_agent_profile_url); 2920 } 2921 2922 /** 2923 * Opens a logical channel to the ICC card. 2924 * 2925 * Input parameters equivalent to TS 27.007 AT+CCHO command. 2926 * 2927 * <p>Requires Permission: 2928 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2929 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2930 * 2931 * @param AID Application id. See ETSI 102.221 and 101.220. 2932 * @return an IccOpenLogicalChannelResponse object. 2933 */ 2934 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { 2935 return iccOpenLogicalChannel(getDefaultSubscription(), AID); 2936 } 2937 2938 /** 2939 * Opens a logical channel to the ICC card. 2940 * 2941 * Input parameters equivalent to TS 27.007 AT+CCHO command. 2942 * 2943 * <p>Requires Permission: 2944 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2945 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2946 * 2947 * @param subId The subscription to use. 2948 * @param AID Application id. See ETSI 102.221 and 101.220. 2949 * @return an IccOpenLogicalChannelResponse object. 2950 */ 2951 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID) { 2952 try { 2953 ITelephony telephony = getITelephony(); 2954 if (telephony != null) 2955 return telephony.iccOpenLogicalChannel(subId, AID); 2956 } catch (RemoteException ex) { 2957 } catch (NullPointerException ex) { 2958 } 2959 return null; 2960 } 2961 2962 /** 2963 * Closes a previously opened logical channel to the ICC card. 2964 * 2965 * Input parameters equivalent to TS 27.007 AT+CCHC command. 2966 * 2967 * <p>Requires Permission: 2968 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2969 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2970 * 2971 * @param channel is the channel id to be closed as retruned by a successful 2972 * iccOpenLogicalChannel. 2973 * @return true if the channel was closed successfully. 2974 */ 2975 public boolean iccCloseLogicalChannel(int channel) { 2976 return iccCloseLogicalChannel(getDefaultSubscription(), channel); 2977 } 2978 2979 /** 2980 * Closes a previously opened logical channel to the ICC card. 2981 * 2982 * Input parameters equivalent to TS 27.007 AT+CCHC command. 2983 * 2984 * <p>Requires Permission: 2985 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2986 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2987 * 2988 * @param subId The subscription to use. 2989 * @param channel is the channel id to be closed as retruned by a successful 2990 * iccOpenLogicalChannel. 2991 * @return true if the channel was closed successfully. 2992 */ 2993 public boolean iccCloseLogicalChannel(int subId, int channel) { 2994 try { 2995 ITelephony telephony = getITelephony(); 2996 if (telephony != null) 2997 return telephony.iccCloseLogicalChannel(subId, channel); 2998 } catch (RemoteException ex) { 2999 } catch (NullPointerException ex) { 3000 } 3001 return false; 3002 } 3003 3004 /** 3005 * Transmit an APDU to the ICC card over a logical channel. 3006 * 3007 * Input parameters equivalent to TS 27.007 AT+CGLA command. 3008 * 3009 * <p>Requires Permission: 3010 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3011 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3012 * 3013 * @param channel is the channel id to be closed as returned by a successful 3014 * iccOpenLogicalChannel. 3015 * @param cla Class of the APDU command. 3016 * @param instruction Instruction of the APDU command. 3017 * @param p1 P1 value of the APDU command. 3018 * @param p2 P2 value of the APDU command. 3019 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 3020 * is sent to the SIM. 3021 * @param data Data to be sent with the APDU. 3022 * @return The APDU response from the ICC card with the status appended at 3023 * the end. 3024 */ 3025 public String iccTransmitApduLogicalChannel(int channel, int cla, 3026 int instruction, int p1, int p2, int p3, String data) { 3027 return iccTransmitApduLogicalChannel(getDefaultSubscription(), channel, cla, 3028 instruction, p1, p2, p3, data); 3029 } 3030 3031 /** 3032 * Transmit an APDU to the ICC card over a logical channel. 3033 * 3034 * Input parameters equivalent to TS 27.007 AT+CGLA command. 3035 * 3036 * <p>Requires Permission: 3037 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3038 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3039 * 3040 * @param subId The subscription to use. 3041 * @param channel is the channel id to be closed as returned by a successful 3042 * iccOpenLogicalChannel. 3043 * @param cla Class of the APDU command. 3044 * @param instruction Instruction of the APDU command. 3045 * @param p1 P1 value of the APDU command. 3046 * @param p2 P2 value of the APDU command. 3047 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 3048 * is sent to the SIM. 3049 * @param data Data to be sent with the APDU. 3050 * @return The APDU response from the ICC card with the status appended at 3051 * the end. 3052 */ 3053 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, 3054 int instruction, int p1, int p2, int p3, String data) { 3055 try { 3056 ITelephony telephony = getITelephony(); 3057 if (telephony != null) 3058 return telephony.iccTransmitApduLogicalChannel(subId, channel, cla, 3059 instruction, p1, p2, p3, data); 3060 } catch (RemoteException ex) { 3061 } catch (NullPointerException ex) { 3062 } 3063 return ""; 3064 } 3065 3066 /** 3067 * Transmit an APDU to the ICC card over the basic channel. 3068 * 3069 * Input parameters equivalent to TS 27.007 AT+CSIM command. 3070 * 3071 * <p>Requires Permission: 3072 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3073 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3074 * 3075 * @param cla Class of the APDU command. 3076 * @param instruction Instruction of the APDU command. 3077 * @param p1 P1 value of the APDU command. 3078 * @param p2 P2 value of the APDU command. 3079 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 3080 * is sent to the SIM. 3081 * @param data Data to be sent with the APDU. 3082 * @return The APDU response from the ICC card with the status appended at 3083 * the end. 3084 */ 3085 public String iccTransmitApduBasicChannel(int cla, 3086 int instruction, int p1, int p2, int p3, String data) { 3087 return iccTransmitApduBasicChannel(getDefaultSubscription(), cla, 3088 instruction, p1, p2, p3, data); 3089 } 3090 3091 /** 3092 * Transmit an APDU to the ICC card over the basic channel. 3093 * 3094 * Input parameters equivalent to TS 27.007 AT+CSIM command. 3095 * 3096 * <p>Requires Permission: 3097 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3098 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3099 * 3100 * @param subId The subscription to use. 3101 * @param cla Class of the APDU command. 3102 * @param instruction Instruction of the APDU command. 3103 * @param p1 P1 value of the APDU command. 3104 * @param p2 P2 value of the APDU command. 3105 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 3106 * is sent to the SIM. 3107 * @param data Data to be sent with the APDU. 3108 * @return The APDU response from the ICC card with the status appended at 3109 * the end. 3110 */ 3111 public String iccTransmitApduBasicChannel(int subId, int cla, 3112 int instruction, int p1, int p2, int p3, String data) { 3113 try { 3114 ITelephony telephony = getITelephony(); 3115 if (telephony != null) 3116 return telephony.iccTransmitApduBasicChannel(subId, cla, 3117 instruction, p1, p2, p3, data); 3118 } catch (RemoteException ex) { 3119 } catch (NullPointerException ex) { 3120 } 3121 return ""; 3122 } 3123 3124 /** 3125 * Returns the response APDU for a command APDU sent through SIM_IO. 3126 * 3127 * <p>Requires Permission: 3128 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3129 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3130 * 3131 * @param fileID 3132 * @param command 3133 * @param p1 P1 value of the APDU command. 3134 * @param p2 P2 value of the APDU command. 3135 * @param p3 P3 value of the APDU command. 3136 * @param filePath 3137 * @return The APDU response. 3138 */ 3139 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 3140 String filePath) { 3141 return iccExchangeSimIO(getDefaultSubscription(), fileID, command, p1, p2, p3, filePath); 3142 } 3143 3144 /** 3145 * Returns the response APDU for a command APDU sent through SIM_IO. 3146 * 3147 * <p>Requires Permission: 3148 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3149 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3150 * 3151 * @param subId The subscription to use. 3152 * @param fileID 3153 * @param command 3154 * @param p1 P1 value of the APDU command. 3155 * @param p2 P2 value of the APDU command. 3156 * @param p3 P3 value of the APDU command. 3157 * @param filePath 3158 * @return The APDU response. 3159 */ 3160 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, 3161 int p3, String filePath) { 3162 try { 3163 ITelephony telephony = getITelephony(); 3164 if (telephony != null) 3165 return telephony.iccExchangeSimIO(subId, fileID, command, p1, p2, p3, filePath); 3166 } catch (RemoteException ex) { 3167 } catch (NullPointerException ex) { 3168 } 3169 return null; 3170 } 3171 3172 /** 3173 * Send ENVELOPE to the SIM and return the response. 3174 * 3175 * <p>Requires Permission: 3176 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3177 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3178 * 3179 * @param content String containing SAT/USAT response in hexadecimal 3180 * format starting with command tag. See TS 102 223 for 3181 * details. 3182 * @return The APDU response from the ICC card in hexadecimal format 3183 * with the last 4 bytes being the status word. If the command fails, 3184 * returns an empty string. 3185 */ 3186 public String sendEnvelopeWithStatus(String content) { 3187 return sendEnvelopeWithStatus(getDefaultSubscription(), content); 3188 } 3189 3190 /** 3191 * Send ENVELOPE to the SIM and return the response. 3192 * 3193 * <p>Requires Permission: 3194 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3195 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3196 * 3197 * @param subId The subscription to use. 3198 * @param content String containing SAT/USAT response in hexadecimal 3199 * format starting with command tag. See TS 102 223 for 3200 * details. 3201 * @return The APDU response from the ICC card in hexadecimal format 3202 * with the last 4 bytes being the status word. If the command fails, 3203 * returns an empty string. 3204 */ 3205 public String sendEnvelopeWithStatus(int subId, String content) { 3206 try { 3207 ITelephony telephony = getITelephony(); 3208 if (telephony != null) 3209 return telephony.sendEnvelopeWithStatus(subId, content); 3210 } catch (RemoteException ex) { 3211 } catch (NullPointerException ex) { 3212 } 3213 return ""; 3214 } 3215 3216 /** 3217 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 3218 * Used for device configuration by some CDMA operators. 3219 * <p> 3220 * Requires Permission: 3221 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3222 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3223 * 3224 * @param itemID the ID of the item to read. 3225 * @return the NV item as a String, or null on any failure. 3226 * 3227 * @hide 3228 */ 3229 public String nvReadItem(int itemID) { 3230 try { 3231 ITelephony telephony = getITelephony(); 3232 if (telephony != null) 3233 return telephony.nvReadItem(itemID); 3234 } catch (RemoteException ex) { 3235 Rlog.e(TAG, "nvReadItem RemoteException", ex); 3236 } catch (NullPointerException ex) { 3237 Rlog.e(TAG, "nvReadItem NPE", ex); 3238 } 3239 return ""; 3240 } 3241 3242 /** 3243 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 3244 * Used for device configuration by some CDMA operators. 3245 * <p> 3246 * Requires Permission: 3247 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3248 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3249 * 3250 * @param itemID the ID of the item to read. 3251 * @param itemValue the value to write, as a String. 3252 * @return true on success; false on any failure. 3253 * 3254 * @hide 3255 */ 3256 public boolean nvWriteItem(int itemID, String itemValue) { 3257 try { 3258 ITelephony telephony = getITelephony(); 3259 if (telephony != null) 3260 return telephony.nvWriteItem(itemID, itemValue); 3261 } catch (RemoteException ex) { 3262 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 3263 } catch (NullPointerException ex) { 3264 Rlog.e(TAG, "nvWriteItem NPE", ex); 3265 } 3266 return false; 3267 } 3268 3269 /** 3270 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 3271 * Used for device configuration by some CDMA operators. 3272 * <p> 3273 * Requires Permission: 3274 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3275 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3276 * 3277 * @param preferredRoamingList byte array containing the new PRL. 3278 * @return true on success; false on any failure. 3279 * 3280 * @hide 3281 */ 3282 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 3283 try { 3284 ITelephony telephony = getITelephony(); 3285 if (telephony != null) 3286 return telephony.nvWriteCdmaPrl(preferredRoamingList); 3287 } catch (RemoteException ex) { 3288 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 3289 } catch (NullPointerException ex) { 3290 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 3291 } 3292 return false; 3293 } 3294 3295 /** 3296 * Perform the specified type of NV config reset. The radio will be taken offline 3297 * and the device must be rebooted after the operation. Used for device 3298 * configuration by some CDMA operators. 3299 * <p> 3300 * Requires Permission: 3301 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3302 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3303 * 3304 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 3305 * @return true on success; false on any failure. 3306 * 3307 * @hide 3308 */ 3309 public boolean nvResetConfig(int resetType) { 3310 try { 3311 ITelephony telephony = getITelephony(); 3312 if (telephony != null) 3313 return telephony.nvResetConfig(resetType); 3314 } catch (RemoteException ex) { 3315 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 3316 } catch (NullPointerException ex) { 3317 Rlog.e(TAG, "nvResetConfig NPE", ex); 3318 } 3319 return false; 3320 } 3321 3322 /** 3323 * Returns Default subscription. 3324 */ 3325 private static int getDefaultSubscription() { 3326 return SubscriptionManager.getDefaultSubscriptionId(); 3327 } 3328 3329 /** 3330 * Returns Default phone. 3331 */ 3332 private static int getDefaultPhone() { 3333 return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubscriptionId()); 3334 } 3335 3336 /** {@hide} */ 3337 public int getDefaultSim() { 3338 return SubscriptionManager.getSlotId(SubscriptionManager.getDefaultSubscriptionId()); 3339 } 3340 3341 /** 3342 * Sets the telephony property with the value specified. 3343 * 3344 * @hide 3345 */ 3346 public static void setTelephonyProperty(int phoneId, String property, String value) { 3347 String propVal = ""; 3348 String p[] = null; 3349 String prop = SystemProperties.get(property); 3350 3351 if (value == null) { 3352 value = ""; 3353 } 3354 3355 if (prop != null) { 3356 p = prop.split(","); 3357 } 3358 3359 if (!SubscriptionManager.isValidPhoneId(phoneId)) { 3360 Rlog.d(TAG, "setTelephonyProperty: invalid phoneId=" + phoneId + 3361 " property=" + property + " value: " + value + " prop=" + prop); 3362 return; 3363 } 3364 3365 for (int i = 0; i < phoneId; i++) { 3366 String str = ""; 3367 if ((p != null) && (i < p.length)) { 3368 str = p[i]; 3369 } 3370 propVal = propVal + str + ","; 3371 } 3372 3373 propVal = propVal + value; 3374 if (p != null) { 3375 for (int i = phoneId + 1; i < p.length; i++) { 3376 propVal = propVal + "," + p[i]; 3377 } 3378 } 3379 3380 if (property.length() > SystemProperties.PROP_NAME_MAX 3381 || propVal.length() > SystemProperties.PROP_VALUE_MAX) { 3382 Rlog.d(TAG, "setTelephonyProperty: property to long phoneId=" + phoneId + 3383 " property=" + property + " value: " + value + " propVal=" + propVal); 3384 return; 3385 } 3386 3387 Rlog.d(TAG, "setTelephonyProperty: success phoneId=" + phoneId + 3388 " property=" + property + " value: " + value + " propVal=" + propVal); 3389 SystemProperties.set(property, propVal); 3390 } 3391 3392 /** 3393 * Convenience function for retrieving a value from the secure settings 3394 * value list as an integer. Note that internally setting values are 3395 * always stored as strings; this function converts the string to an 3396 * integer for you. 3397 * <p> 3398 * This version does not take a default value. If the setting has not 3399 * been set, or the string value is not a number, 3400 * it throws {@link SettingNotFoundException}. 3401 * 3402 * @param cr The ContentResolver to access. 3403 * @param name The name of the setting to retrieve. 3404 * @param index The index of the list 3405 * 3406 * @throws SettingNotFoundException Thrown if a setting by the given 3407 * name can't be found or the setting value is not an integer. 3408 * 3409 * @return The value at the given index of settings. 3410 * @hide 3411 */ 3412 public static int getIntAtIndex(android.content.ContentResolver cr, 3413 String name, int index) 3414 throws android.provider.Settings.SettingNotFoundException { 3415 String v = android.provider.Settings.Global.getString(cr, name); 3416 if (v != null) { 3417 String valArray[] = v.split(","); 3418 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 3419 try { 3420 return Integer.parseInt(valArray[index]); 3421 } catch (NumberFormatException e) { 3422 //Log.e(TAG, "Exception while parsing Integer: ", e); 3423 } 3424 } 3425 } 3426 throw new android.provider.Settings.SettingNotFoundException(name); 3427 } 3428 3429 /** 3430 * Convenience function for updating settings value as coma separated 3431 * integer values. This will either create a new entry in the table if the 3432 * given name does not exist, or modify the value of the existing row 3433 * with that name. Note that internally setting values are always 3434 * stored as strings, so this function converts the given value to a 3435 * string before storing it. 3436 * 3437 * @param cr The ContentResolver to access. 3438 * @param name The name of the setting to modify. 3439 * @param index The index of the list 3440 * @param value The new value for the setting to be added to the list. 3441 * @return true if the value was set, false on database errors 3442 * @hide 3443 */ 3444 public static boolean putIntAtIndex(android.content.ContentResolver cr, 3445 String name, int index, int value) { 3446 String data = ""; 3447 String valArray[] = null; 3448 String v = android.provider.Settings.Global.getString(cr, name); 3449 3450 if (index == Integer.MAX_VALUE) { 3451 throw new RuntimeException("putIntAtIndex index == MAX_VALUE index=" + index); 3452 } 3453 if (index < 0) { 3454 throw new RuntimeException("putIntAtIndex index < 0 index=" + index); 3455 } 3456 if (v != null) { 3457 valArray = v.split(","); 3458 } 3459 3460 // Copy the elements from valArray till index 3461 for (int i = 0; i < index; i++) { 3462 String str = ""; 3463 if ((valArray != null) && (i < valArray.length)) { 3464 str = valArray[i]; 3465 } 3466 data = data + str + ","; 3467 } 3468 3469 data = data + value; 3470 3471 // Copy the remaining elements from valArray if any. 3472 if (valArray != null) { 3473 for (int i = index+1; i < valArray.length; i++) { 3474 data = data + "," + valArray[i]; 3475 } 3476 } 3477 return android.provider.Settings.Global.putString(cr, name, data); 3478 } 3479 3480 /** 3481 * Gets the telephony property. 3482 * 3483 * @hide 3484 */ 3485 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 3486 String propVal = null; 3487 String prop = SystemProperties.get(property); 3488 if ((prop != null) && (prop.length() > 0)) { 3489 String values[] = prop.split(","); 3490 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 3491 propVal = values[phoneId]; 3492 } 3493 } 3494 return propVal == null ? defaultVal : propVal; 3495 } 3496 3497 /** @hide */ 3498 public int getSimCount() { 3499 // FIXME Need to get it from Telephony Dev Controller when that gets implemented! 3500 // and then this method shouldn't be used at all! 3501 if(isMultiSimEnabled()) { 3502 return 2; 3503 } else { 3504 return 1; 3505 } 3506 } 3507 3508 /** 3509 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 3510 * @return IMS Service Table or null if not present or not loaded 3511 * @hide 3512 */ 3513 public String getIsimIst() { 3514 try { 3515 IPhoneSubInfo info = getSubscriberInfo(); 3516 if (info == null) 3517 return null; 3518 return info.getIsimIst(); 3519 } catch (RemoteException ex) { 3520 return null; 3521 } catch (NullPointerException ex) { 3522 // This could happen before phone restarts due to crashing 3523 return null; 3524 } 3525 } 3526 3527 /** 3528 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 3529 * @return an array of PCSCF strings with one PCSCF per string, or null if 3530 * not present or not loaded 3531 * @hide 3532 */ 3533 public String[] getIsimPcscf() { 3534 try { 3535 IPhoneSubInfo info = getSubscriberInfo(); 3536 if (info == null) 3537 return null; 3538 return info.getIsimPcscf(); 3539 } catch (RemoteException ex) { 3540 return null; 3541 } catch (NullPointerException ex) { 3542 // This could happen before phone restarts due to crashing 3543 return null; 3544 } 3545 } 3546 3547 /** 3548 * Returns the response of ISIM Authetification through RIL. 3549 * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo. 3550 * @return the response of ISIM Authetification, or null if not available 3551 * @hide 3552 * @deprecated 3553 * @see getIccSimChallengeResponse with appType=PhoneConstants.APPTYPE_ISIM 3554 */ 3555 public String getIsimChallengeResponse(String nonce){ 3556 try { 3557 IPhoneSubInfo info = getSubscriberInfo(); 3558 if (info == null) 3559 return null; 3560 return info.getIsimChallengeResponse(nonce); 3561 } catch (RemoteException ex) { 3562 return null; 3563 } catch (NullPointerException ex) { 3564 // This could happen before phone restarts due to crashing 3565 return null; 3566 } 3567 } 3568 3569 /** 3570 * Returns the response of SIM Authentication through RIL. 3571 * Returns null if the Authentication hasn't been successful 3572 * @param subId subscription ID to be queried 3573 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3574 * @param data authentication challenge data 3575 * @return the response of SIM Authentication, or null if not available 3576 * @hide 3577 */ 3578 public String getIccSimChallengeResponse(int subId, int appType, String data) { 3579 try { 3580 IPhoneSubInfo info = getSubscriberInfo(); 3581 if (info == null) 3582 return null; 3583 return info.getIccSimChallengeResponse(subId, appType, data); 3584 } catch (RemoteException ex) { 3585 return null; 3586 } catch (NullPointerException ex) { 3587 // This could happen before phone starts 3588 return null; 3589 } 3590 } 3591 3592 /** 3593 * Returns the response of SIM Authentication through RIL for the default subscription. 3594 * Returns null if the Authentication hasn't been successful 3595 * 3596 * <p>Requires that the calling app has carrier privileges. 3597 * @see #hasCarrierPrivileges 3598 * 3599 * @param appType ICC application type (@see com.android.internal.telephony.PhoneConstants#APPTYPE_xxx) 3600 * @param data authentication challenge data 3601 * @return the response of SIM Authentication, or null if not available 3602 */ 3603 public String getIccSimChallengeResponse(int appType, String data) { 3604 return getIccSimChallengeResponse(getDefaultSubscription(), appType, data); 3605 } 3606 3607 /** 3608 * Get P-CSCF address from PCO after data connection is established or modified. 3609 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 3610 * @return array of P-CSCF address 3611 * @hide 3612 */ 3613 public String[] getPcscfAddress(String apnType) { 3614 try { 3615 ITelephony telephony = getITelephony(); 3616 if (telephony == null) 3617 return new String[0]; 3618 return telephony.getPcscfAddress(apnType, getOpPackageName()); 3619 } catch (RemoteException e) { 3620 return new String[0]; 3621 } 3622 } 3623 3624 /** 3625 * Set IMS registration state 3626 * 3627 * @param Registration state 3628 * @hide 3629 */ 3630 public void setImsRegistrationState(boolean registered) { 3631 try { 3632 ITelephony telephony = getITelephony(); 3633 if (telephony != null) 3634 telephony.setImsRegistrationState(registered); 3635 } catch (RemoteException e) { 3636 } 3637 } 3638 3639 /** 3640 * Get the preferred network type. 3641 * Used for device configuration by some CDMA operators. 3642 * <p> 3643 * Requires Permission: 3644 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3645 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3646 * 3647 * @return the preferred network type, defined in RILConstants.java. 3648 * @hide 3649 */ 3650 public int getPreferredNetworkType(int subId) { 3651 try { 3652 ITelephony telephony = getITelephony(); 3653 if (telephony != null) 3654 return telephony.getPreferredNetworkType(subId); 3655 } catch (RemoteException ex) { 3656 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 3657 } catch (NullPointerException ex) { 3658 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 3659 } 3660 return -1; 3661 } 3662 3663 /** 3664 * Sets the network selection mode to automatic. 3665 * <p> 3666 * Requires Permission: 3667 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3668 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3669 * 3670 * @hide 3671 */ 3672 public void setNetworkSelectionModeAutomatic(int subId) { 3673 try { 3674 ITelephony telephony = getITelephony(); 3675 if (telephony != null) 3676 telephony.setNetworkSelectionModeAutomatic(subId); 3677 } catch (RemoteException ex) { 3678 Rlog.e(TAG, "setNetworkSelectionModeAutomatic RemoteException", ex); 3679 } catch (NullPointerException ex) { 3680 Rlog.e(TAG, "setNetworkSelectionModeAutomatic NPE", ex); 3681 } 3682 } 3683 3684 /** 3685 * Perform a radio scan and return the list of avialble networks. 3686 * 3687 * The return value is a list of the OperatorInfo of the networks found. Note that this 3688 * scan can take a long time (sometimes minutes) to happen. 3689 * 3690 * <p> 3691 * Requires Permission: 3692 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3693 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3694 * 3695 * @hide 3696 */ 3697 public CellNetworkScanResult getCellNetworkScanResults(int subId) { 3698 try { 3699 ITelephony telephony = getITelephony(); 3700 if (telephony != null) 3701 return telephony.getCellNetworkScanResults(subId); 3702 } catch (RemoteException ex) { 3703 Rlog.e(TAG, "getCellNetworkScanResults RemoteException", ex); 3704 } catch (NullPointerException ex) { 3705 Rlog.e(TAG, "getCellNetworkScanResults NPE", ex); 3706 } 3707 return null; 3708 } 3709 3710 /** 3711 * Ask the radio to connect to the input network and change selection mode to manual. 3712 * 3713 * <p> 3714 * Requires Permission: 3715 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3716 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3717 * 3718 * @hide 3719 */ 3720 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator, 3721 boolean persistSelection) { 3722 try { 3723 ITelephony telephony = getITelephony(); 3724 if (telephony != null) 3725 return telephony.setNetworkSelectionModeManual(subId, operator, persistSelection); 3726 } catch (RemoteException ex) { 3727 Rlog.e(TAG, "setNetworkSelectionModeManual RemoteException", ex); 3728 } catch (NullPointerException ex) { 3729 Rlog.e(TAG, "setNetworkSelectionModeManual NPE", ex); 3730 } 3731 return false; 3732 } 3733 3734 /** 3735 * Set the preferred network type. 3736 * Used for device configuration by some CDMA operators. 3737 * <p> 3738 * Requires Permission: 3739 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3740 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3741 * 3742 * @param subId the id of the subscription to set the preferred network type for. 3743 * @param networkType the preferred network type, defined in RILConstants.java. 3744 * @return true on success; false on any failure. 3745 * @hide 3746 */ 3747 public boolean setPreferredNetworkType(int subId, int networkType) { 3748 try { 3749 ITelephony telephony = getITelephony(); 3750 if (telephony != null) 3751 return telephony.setPreferredNetworkType(subId, networkType); 3752 } catch (RemoteException ex) { 3753 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 3754 } catch (NullPointerException ex) { 3755 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 3756 } 3757 return false; 3758 } 3759 3760 /** 3761 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 3762 * 3763 * <p> 3764 * Requires that the calling app has carrier privileges. 3765 * @see #hasCarrierPrivileges 3766 * 3767 * @return true on success; false on any failure. 3768 */ 3769 public boolean setPreferredNetworkTypeToGlobal() { 3770 return setPreferredNetworkTypeToGlobal(getDefaultSubscription()); 3771 } 3772 3773 /** 3774 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 3775 * 3776 * <p> 3777 * Requires that the calling app has carrier privileges. 3778 * @see #hasCarrierPrivileges 3779 * 3780 * @return true on success; false on any failure. 3781 */ 3782 public boolean setPreferredNetworkTypeToGlobal(int subId) { 3783 return setPreferredNetworkType(subId, RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); 3784 } 3785 3786 /** 3787 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning 3788 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for 3789 * tethering. 3790 * 3791 * @return 0: Not required. 1: required. 2: Not set. 3792 * @hide 3793 */ 3794 public int getTetherApnRequired() { 3795 try { 3796 ITelephony telephony = getITelephony(); 3797 if (telephony != null) 3798 return telephony.getTetherApnRequired(); 3799 } catch (RemoteException ex) { 3800 Rlog.e(TAG, "hasMatchedTetherApnSetting RemoteException", ex); 3801 } catch (NullPointerException ex) { 3802 Rlog.e(TAG, "hasMatchedTetherApnSetting NPE", ex); 3803 } 3804 return 2; 3805 } 3806 3807 3808 /** 3809 * Values used to return status for hasCarrierPrivileges call. 3810 */ 3811 /** @hide */ @SystemApi 3812 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 3813 /** @hide */ @SystemApi 3814 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 3815 /** @hide */ @SystemApi 3816 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 3817 /** @hide */ @SystemApi 3818 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 3819 3820 /** 3821 * Has the calling application been granted carrier privileges by the carrier. 3822 * 3823 * If any of the packages in the calling UID has carrier privileges, the 3824 * call will return true. This access is granted by the owner of the UICC 3825 * card and does not depend on the registered carrier. 3826 * 3827 * @return true if the app has carrier privileges. 3828 */ 3829 public boolean hasCarrierPrivileges() { 3830 return hasCarrierPrivileges(getDefaultSubscription()); 3831 } 3832 3833 /** 3834 * Has the calling application been granted carrier privileges by the carrier. 3835 * 3836 * If any of the packages in the calling UID has carrier privileges, the 3837 * call will return true. This access is granted by the owner of the UICC 3838 * card and does not depend on the registered carrier. 3839 * 3840 * @param subId The subscription to use. 3841 * @return true if the app has carrier privileges. 3842 */ 3843 public boolean hasCarrierPrivileges(int subId) { 3844 try { 3845 ITelephony telephony = getITelephony(); 3846 if (telephony != null) { 3847 return telephony.getCarrierPrivilegeStatus(subId) == 3848 CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; 3849 } 3850 } catch (RemoteException ex) { 3851 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 3852 } catch (NullPointerException ex) { 3853 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 3854 } 3855 return false; 3856 } 3857 3858 /** 3859 * Override the branding for the current ICCID. 3860 * 3861 * Once set, whenever the SIM is present in the device, the service 3862 * provider name (SPN) and the operator name will both be replaced by the 3863 * brand value input. To unset the value, the same function should be 3864 * called with a null brand value. 3865 * 3866 * <p>Requires that the calling app has carrier privileges. 3867 * @see #hasCarrierPrivileges 3868 * 3869 * @param brand The brand name to display/set. 3870 * @return true if the operation was executed correctly. 3871 */ 3872 public boolean setOperatorBrandOverride(String brand) { 3873 return setOperatorBrandOverride(getDefaultSubscription(), brand); 3874 } 3875 3876 /** 3877 * Override the branding for the current ICCID. 3878 * 3879 * Once set, whenever the SIM is present in the device, the service 3880 * provider name (SPN) and the operator name will both be replaced by the 3881 * brand value input. To unset the value, the same function should be 3882 * called with a null brand value. 3883 * 3884 * <p>Requires that the calling app has carrier privileges. 3885 * @see #hasCarrierPrivileges 3886 * 3887 * @param subId The subscription to use. 3888 * @param brand The brand name to display/set. 3889 * @return true if the operation was executed correctly. 3890 */ 3891 public boolean setOperatorBrandOverride(int subId, String brand) { 3892 try { 3893 ITelephony telephony = getITelephony(); 3894 if (telephony != null) 3895 return telephony.setOperatorBrandOverride(subId, brand); 3896 } catch (RemoteException ex) { 3897 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 3898 } catch (NullPointerException ex) { 3899 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 3900 } 3901 return false; 3902 } 3903 3904 /** 3905 * Override the roaming preference for the current ICCID. 3906 * 3907 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 3908 * the platform's notion of a network operator being considered roaming or not. 3909 * The change only affects the ICCID that was active when this call was made. 3910 * 3911 * If null is passed as any of the input, the corresponding value is deleted. 3912 * 3913 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 3914 * 3915 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 3916 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 3917 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 3918 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 3919 * @return true if the operation was executed correctly. 3920 * 3921 * @hide 3922 */ 3923 public boolean setRoamingOverride(List<String> gsmRoamingList, 3924 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 3925 List<String> cdmaNonRoamingList) { 3926 return setRoamingOverride(getDefaultSubscription(), gsmRoamingList, gsmNonRoamingList, 3927 cdmaRoamingList, cdmaNonRoamingList); 3928 } 3929 3930 /** 3931 * Override the roaming preference for the current ICCID. 3932 * 3933 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 3934 * the platform's notion of a network operator being considered roaming or not. 3935 * The change only affects the ICCID that was active when this call was made. 3936 * 3937 * If null is passed as any of the input, the corresponding value is deleted. 3938 * 3939 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 3940 * 3941 * @param subId for which the roaming overrides apply. 3942 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 3943 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 3944 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 3945 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 3946 * @return true if the operation was executed correctly. 3947 * 3948 * @hide 3949 */ 3950 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, 3951 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 3952 List<String> cdmaNonRoamingList) { 3953 try { 3954 ITelephony telephony = getITelephony(); 3955 if (telephony != null) 3956 return telephony.setRoamingOverride(subId, gsmRoamingList, gsmNonRoamingList, 3957 cdmaRoamingList, cdmaNonRoamingList); 3958 } catch (RemoteException ex) { 3959 Rlog.e(TAG, "setRoamingOverride RemoteException", ex); 3960 } catch (NullPointerException ex) { 3961 Rlog.e(TAG, "setRoamingOverride NPE", ex); 3962 } 3963 return false; 3964 } 3965 3966 /** 3967 * Expose the rest of ITelephony to @SystemApi 3968 */ 3969 3970 /** @hide */ 3971 @SystemApi 3972 public String getCdmaMdn() { 3973 return getCdmaMdn(getDefaultSubscription()); 3974 } 3975 3976 /** @hide */ 3977 @SystemApi 3978 public String getCdmaMdn(int subId) { 3979 try { 3980 ITelephony telephony = getITelephony(); 3981 if (telephony == null) 3982 return null; 3983 return telephony.getCdmaMdn(subId); 3984 } catch (RemoteException ex) { 3985 return null; 3986 } catch (NullPointerException ex) { 3987 return null; 3988 } 3989 } 3990 3991 /** @hide */ 3992 @SystemApi 3993 public String getCdmaMin() { 3994 return getCdmaMin(getDefaultSubscription()); 3995 } 3996 3997 /** @hide */ 3998 @SystemApi 3999 public String getCdmaMin(int subId) { 4000 try { 4001 ITelephony telephony = getITelephony(); 4002 if (telephony == null) 4003 return null; 4004 return telephony.getCdmaMin(subId); 4005 } catch (RemoteException ex) { 4006 return null; 4007 } catch (NullPointerException ex) { 4008 return null; 4009 } 4010 } 4011 4012 /** @hide */ 4013 @SystemApi 4014 public int checkCarrierPrivilegesForPackage(String pkgName) { 4015 try { 4016 ITelephony telephony = getITelephony(); 4017 if (telephony != null) 4018 return telephony.checkCarrierPrivilegesForPackage(pkgName); 4019 } catch (RemoteException ex) { 4020 Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex); 4021 } catch (NullPointerException ex) { 4022 Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex); 4023 } 4024 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 4025 } 4026 4027 /** @hide */ 4028 @SystemApi 4029 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { 4030 try { 4031 ITelephony telephony = getITelephony(); 4032 if (telephony != null) 4033 return telephony.checkCarrierPrivilegesForPackageAnyPhone(pkgName); 4034 } catch (RemoteException ex) { 4035 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone RemoteException", ex); 4036 } catch (NullPointerException ex) { 4037 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone NPE", ex); 4038 } 4039 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 4040 } 4041 4042 /** @hide */ 4043 @SystemApi 4044 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 4045 return getCarrierPackageNamesForIntentAndPhone(intent, getDefaultPhone()); 4046 } 4047 4048 /** @hide */ 4049 @SystemApi 4050 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { 4051 try { 4052 ITelephony telephony = getITelephony(); 4053 if (telephony != null) 4054 return telephony.getCarrierPackageNamesForIntentAndPhone(intent, phoneId); 4055 } catch (RemoteException ex) { 4056 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone RemoteException", ex); 4057 } catch (NullPointerException ex) { 4058 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone NPE", ex); 4059 } 4060 return null; 4061 } 4062 4063 /** @hide */ 4064 public List<String> getPackagesWithCarrierPrivileges() { 4065 try { 4066 ITelephony telephony = getITelephony(); 4067 if (telephony != null) { 4068 return telephony.getPackagesWithCarrierPrivileges(); 4069 } 4070 } catch (RemoteException ex) { 4071 Rlog.e(TAG, "getPackagesWithCarrierPrivileges RemoteException", ex); 4072 } catch (NullPointerException ex) { 4073 Rlog.e(TAG, "getPackagesWithCarrierPrivileges NPE", ex); 4074 } 4075 return Collections.EMPTY_LIST; 4076 } 4077 4078 /** @hide */ 4079 @SystemApi 4080 public void dial(String number) { 4081 try { 4082 ITelephony telephony = getITelephony(); 4083 if (telephony != null) 4084 telephony.dial(number); 4085 } catch (RemoteException e) { 4086 Log.e(TAG, "Error calling ITelephony#dial", e); 4087 } 4088 } 4089 4090 /** @hide */ 4091 @SystemApi 4092 public void call(String callingPackage, String number) { 4093 try { 4094 ITelephony telephony = getITelephony(); 4095 if (telephony != null) 4096 telephony.call(callingPackage, number); 4097 } catch (RemoteException e) { 4098 Log.e(TAG, "Error calling ITelephony#call", e); 4099 } 4100 } 4101 4102 /** @hide */ 4103 @SystemApi 4104 public boolean endCall() { 4105 try { 4106 ITelephony telephony = getITelephony(); 4107 if (telephony != null) 4108 return telephony.endCall(); 4109 } catch (RemoteException e) { 4110 Log.e(TAG, "Error calling ITelephony#endCall", e); 4111 } 4112 return false; 4113 } 4114 4115 /** @hide */ 4116 @SystemApi 4117 public void answerRingingCall() { 4118 try { 4119 ITelephony telephony = getITelephony(); 4120 if (telephony != null) 4121 telephony.answerRingingCall(); 4122 } catch (RemoteException e) { 4123 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 4124 } 4125 } 4126 4127 /** @hide */ 4128 @SystemApi 4129 public void silenceRinger() { 4130 try { 4131 getTelecomService().silenceRinger(getOpPackageName()); 4132 } catch (RemoteException e) { 4133 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); 4134 } 4135 } 4136 4137 /** @hide */ 4138 @SystemApi 4139 public boolean isOffhook() { 4140 try { 4141 ITelephony telephony = getITelephony(); 4142 if (telephony != null) 4143 return telephony.isOffhook(getOpPackageName()); 4144 } catch (RemoteException e) { 4145 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 4146 } 4147 return false; 4148 } 4149 4150 /** @hide */ 4151 @SystemApi 4152 public boolean isRinging() { 4153 try { 4154 ITelephony telephony = getITelephony(); 4155 if (telephony != null) 4156 return telephony.isRinging(getOpPackageName()); 4157 } catch (RemoteException e) { 4158 Log.e(TAG, "Error calling ITelephony#isRinging", e); 4159 } 4160 return false; 4161 } 4162 4163 /** @hide */ 4164 @SystemApi 4165 public boolean isIdle() { 4166 try { 4167 ITelephony telephony = getITelephony(); 4168 if (telephony != null) 4169 return telephony.isIdle(getOpPackageName()); 4170 } catch (RemoteException e) { 4171 Log.e(TAG, "Error calling ITelephony#isIdle", e); 4172 } 4173 return true; 4174 } 4175 4176 /** @hide */ 4177 @SystemApi 4178 public boolean isRadioOn() { 4179 try { 4180 ITelephony telephony = getITelephony(); 4181 if (telephony != null) 4182 return telephony.isRadioOn(getOpPackageName()); 4183 } catch (RemoteException e) { 4184 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 4185 } 4186 return false; 4187 } 4188 4189 /** @hide */ 4190 @SystemApi 4191 public boolean supplyPin(String pin) { 4192 try { 4193 ITelephony telephony = getITelephony(); 4194 if (telephony != null) 4195 return telephony.supplyPin(pin); 4196 } catch (RemoteException e) { 4197 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 4198 } 4199 return false; 4200 } 4201 4202 /** @hide */ 4203 @SystemApi 4204 public boolean supplyPuk(String puk, String pin) { 4205 try { 4206 ITelephony telephony = getITelephony(); 4207 if (telephony != null) 4208 return telephony.supplyPuk(puk, pin); 4209 } catch (RemoteException e) { 4210 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 4211 } 4212 return false; 4213 } 4214 4215 /** @hide */ 4216 @SystemApi 4217 public int[] supplyPinReportResult(String pin) { 4218 try { 4219 ITelephony telephony = getITelephony(); 4220 if (telephony != null) 4221 return telephony.supplyPinReportResult(pin); 4222 } catch (RemoteException e) { 4223 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 4224 } 4225 return new int[0]; 4226 } 4227 4228 /** @hide */ 4229 @SystemApi 4230 public int[] supplyPukReportResult(String puk, String pin) { 4231 try { 4232 ITelephony telephony = getITelephony(); 4233 if (telephony != null) 4234 return telephony.supplyPukReportResult(puk, pin); 4235 } catch (RemoteException e) { 4236 Log.e(TAG, "Error calling ITelephony#]", e); 4237 } 4238 return new int[0]; 4239 } 4240 4241 /** @hide */ 4242 @SystemApi 4243 public boolean handlePinMmi(String dialString) { 4244 try { 4245 ITelephony telephony = getITelephony(); 4246 if (telephony != null) 4247 return telephony.handlePinMmi(dialString); 4248 } catch (RemoteException e) { 4249 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 4250 } 4251 return false; 4252 } 4253 4254 /** @hide */ 4255 @SystemApi 4256 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 4257 try { 4258 ITelephony telephony = getITelephony(); 4259 if (telephony != null) 4260 return telephony.handlePinMmiForSubscriber(subId, dialString); 4261 } catch (RemoteException e) { 4262 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 4263 } 4264 return false; 4265 } 4266 4267 /** @hide */ 4268 @SystemApi 4269 public void toggleRadioOnOff() { 4270 try { 4271 ITelephony telephony = getITelephony(); 4272 if (telephony != null) 4273 telephony.toggleRadioOnOff(); 4274 } catch (RemoteException e) { 4275 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 4276 } 4277 } 4278 4279 /** @hide */ 4280 @SystemApi 4281 public boolean setRadio(boolean turnOn) { 4282 try { 4283 ITelephony telephony = getITelephony(); 4284 if (telephony != null) 4285 return telephony.setRadio(turnOn); 4286 } catch (RemoteException e) { 4287 Log.e(TAG, "Error calling ITelephony#setRadio", e); 4288 } 4289 return false; 4290 } 4291 4292 /** @hide */ 4293 @SystemApi 4294 public boolean setRadioPower(boolean turnOn) { 4295 try { 4296 ITelephony telephony = getITelephony(); 4297 if (telephony != null) 4298 return telephony.setRadioPower(turnOn); 4299 } catch (RemoteException e) { 4300 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 4301 } 4302 return false; 4303 } 4304 4305 /** @hide */ 4306 @SystemApi 4307 public void updateServiceLocation() { 4308 try { 4309 ITelephony telephony = getITelephony(); 4310 if (telephony != null) 4311 telephony.updateServiceLocation(); 4312 } catch (RemoteException e) { 4313 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 4314 } 4315 } 4316 4317 /** @hide */ 4318 @SystemApi 4319 public boolean enableDataConnectivity() { 4320 try { 4321 ITelephony telephony = getITelephony(); 4322 if (telephony != null) 4323 return telephony.enableDataConnectivity(); 4324 } catch (RemoteException e) { 4325 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 4326 } 4327 return false; 4328 } 4329 4330 /** @hide */ 4331 @SystemApi 4332 public boolean disableDataConnectivity() { 4333 try { 4334 ITelephony telephony = getITelephony(); 4335 if (telephony != null) 4336 return telephony.disableDataConnectivity(); 4337 } catch (RemoteException e) { 4338 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 4339 } 4340 return false; 4341 } 4342 4343 /** @hide */ 4344 @SystemApi 4345 public boolean isDataConnectivityPossible() { 4346 try { 4347 ITelephony telephony = getITelephony(); 4348 if (telephony != null) 4349 return telephony.isDataConnectivityPossible(); 4350 } catch (RemoteException e) { 4351 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 4352 } 4353 return false; 4354 } 4355 4356 /** @hide */ 4357 @SystemApi 4358 public boolean needsOtaServiceProvisioning() { 4359 try { 4360 ITelephony telephony = getITelephony(); 4361 if (telephony != null) 4362 return telephony.needsOtaServiceProvisioning(); 4363 } catch (RemoteException e) { 4364 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 4365 } 4366 return false; 4367 } 4368 4369 /** @hide */ 4370 @SystemApi 4371 public void setDataEnabled(boolean enable) { 4372 setDataEnabled(SubscriptionManager.getDefaultDataSubscriptionId(), enable); 4373 } 4374 4375 /** @hide */ 4376 @SystemApi 4377 public void setDataEnabled(int subId, boolean enable) { 4378 try { 4379 Log.d(TAG, "setDataEnabled: enabled=" + enable); 4380 ITelephony telephony = getITelephony(); 4381 if (telephony != null) 4382 telephony.setDataEnabled(subId, enable); 4383 } catch (RemoteException e) { 4384 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 4385 } 4386 } 4387 4388 /** @hide */ 4389 @SystemApi 4390 public boolean getDataEnabled() { 4391 return getDataEnabled(SubscriptionManager.getDefaultDataSubscriptionId()); 4392 } 4393 4394 /** @hide */ 4395 @SystemApi 4396 public boolean getDataEnabled(int subId) { 4397 boolean retVal = false; 4398 try { 4399 ITelephony telephony = getITelephony(); 4400 if (telephony != null) 4401 retVal = telephony.getDataEnabled(subId); 4402 } catch (RemoteException e) { 4403 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 4404 } catch (NullPointerException e) { 4405 } 4406 Log.d(TAG, "getDataEnabled: retVal=" + retVal); 4407 return retVal; 4408 } 4409 4410 /** 4411 * Returns the result and response from RIL for oem request 4412 * 4413 * @param oemReq the data is sent to ril. 4414 * @param oemResp the respose data from RIL. 4415 * @return negative value request was not handled or get error 4416 * 0 request was handled succesfully, but no response data 4417 * positive value success, data length of response 4418 * @hide 4419 */ 4420 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 4421 try { 4422 ITelephony telephony = getITelephony(); 4423 if (telephony != null) 4424 return telephony.invokeOemRilRequestRaw(oemReq, oemResp); 4425 } catch (RemoteException ex) { 4426 } catch (NullPointerException ex) { 4427 } 4428 return -1; 4429 } 4430 4431 /** @hide */ 4432 @SystemApi 4433 public void enableVideoCalling(boolean enable) { 4434 try { 4435 ITelephony telephony = getITelephony(); 4436 if (telephony != null) 4437 telephony.enableVideoCalling(enable); 4438 } catch (RemoteException e) { 4439 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 4440 } 4441 } 4442 4443 /** @hide */ 4444 @SystemApi 4445 public boolean isVideoCallingEnabled() { 4446 try { 4447 ITelephony telephony = getITelephony(); 4448 if (telephony != null) 4449 return telephony.isVideoCallingEnabled(getOpPackageName()); 4450 } catch (RemoteException e) { 4451 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 4452 } 4453 return false; 4454 } 4455 4456 /** 4457 * Whether the device supports configuring the DTMF tone length. 4458 * 4459 * @return {@code true} if the DTMF tone length can be changed, and {@code false} otherwise. 4460 */ 4461 public boolean canChangeDtmfToneLength() { 4462 try { 4463 ITelephony telephony = getITelephony(); 4464 if (telephony != null) { 4465 return telephony.canChangeDtmfToneLength(); 4466 } 4467 } catch (RemoteException e) { 4468 Log.e(TAG, "Error calling ITelephony#canChangeDtmfToneLength", e); 4469 } catch (SecurityException e) { 4470 Log.e(TAG, "Permission error calling ITelephony#canChangeDtmfToneLength", e); 4471 } 4472 return false; 4473 } 4474 4475 /** 4476 * Whether the device is a world phone. 4477 * 4478 * @return {@code true} if the device is a world phone, and {@code false} otherwise. 4479 */ 4480 public boolean isWorldPhone() { 4481 try { 4482 ITelephony telephony = getITelephony(); 4483 if (telephony != null) { 4484 return telephony.isWorldPhone(); 4485 } 4486 } catch (RemoteException e) { 4487 Log.e(TAG, "Error calling ITelephony#isWorldPhone", e); 4488 } catch (SecurityException e) { 4489 Log.e(TAG, "Permission error calling ITelephony#isWorldPhone", e); 4490 } 4491 return false; 4492 } 4493 4494 /** 4495 * Whether the phone supports TTY mode. 4496 * 4497 * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. 4498 */ 4499 public boolean isTtyModeSupported() { 4500 try { 4501 ITelephony telephony = getITelephony(); 4502 if (telephony != null) { 4503 return telephony.isTtyModeSupported(); 4504 } 4505 } catch (RemoteException e) { 4506 Log.e(TAG, "Error calling ITelephony#isTtyModeSupported", e); 4507 } catch (SecurityException e) { 4508 Log.e(TAG, "Permission error calling ITelephony#isTtyModeSupported", e); 4509 } 4510 return false; 4511 } 4512 4513 /** 4514 * Whether the phone supports hearing aid compatibility. 4515 * 4516 * @return {@code true} if the device supports hearing aid compatibility, and {@code false} 4517 * otherwise. 4518 */ 4519 public boolean isHearingAidCompatibilitySupported() { 4520 try { 4521 ITelephony telephony = getITelephony(); 4522 if (telephony != null) { 4523 return telephony.isHearingAidCompatibilitySupported(); 4524 } 4525 } catch (RemoteException e) { 4526 Log.e(TAG, "Error calling ITelephony#isHearingAidCompatibilitySupported", e); 4527 } catch (SecurityException e) { 4528 Log.e(TAG, "Permission error calling ITelephony#isHearingAidCompatibilitySupported", e); 4529 } 4530 return false; 4531 } 4532 4533 /** 4534 * This function retrieves value for setting "name+subId", and if that is not found 4535 * retrieves value for setting "name", and if that is not found throws 4536 * SettingNotFoundException 4537 * 4538 * @hide */ 4539 public static int getIntWithSubId(ContentResolver cr, String name, int subId) 4540 throws SettingNotFoundException { 4541 try { 4542 return Settings.Global.getInt(cr, name + subId); 4543 } catch (SettingNotFoundException e) { 4544 try { 4545 int val = Settings.Global.getInt(cr, name); 4546 Settings.Global.putInt(cr, name + subId, val); 4547 4548 /* We are now moving from 'setting' to 'setting+subId', and using the value stored 4549 * for 'setting' as default. Reset the default (since it may have a user set 4550 * value). */ 4551 int default_val = val; 4552 if (name.equals(Settings.Global.MOBILE_DATA)) { 4553 default_val = "true".equalsIgnoreCase( 4554 SystemProperties.get("ro.com.android.mobiledata", "true")) ? 1 : 0; 4555 } else if (name.equals(Settings.Global.DATA_ROAMING)) { 4556 default_val = "true".equalsIgnoreCase( 4557 SystemProperties.get("ro.com.android.dataroaming", "false")) ? 1 : 0; 4558 } 4559 4560 if (default_val != val) { 4561 Settings.Global.putInt(cr, name, default_val); 4562 } 4563 4564 return val; 4565 } catch (SettingNotFoundException exc) { 4566 throw new SettingNotFoundException(name); 4567 } 4568 } 4569 } 4570 4571 /** 4572 * Returns the IMS Registration Status 4573 * @hide 4574 */ 4575 public boolean isImsRegistered() { 4576 try { 4577 ITelephony telephony = getITelephony(); 4578 if (telephony == null) 4579 return false; 4580 return telephony.isImsRegistered(); 4581 } catch (RemoteException ex) { 4582 return false; 4583 } catch (NullPointerException ex) { 4584 return false; 4585 } 4586 } 4587 4588 /** 4589 * Returns the Status of Volte 4590 * @hide 4591 */ 4592 public boolean isVolteAvailable() { 4593 try { 4594 return getITelephony().isVolteAvailable(); 4595 } catch (RemoteException ex) { 4596 return false; 4597 } catch (NullPointerException ex) { 4598 return false; 4599 } 4600 } 4601 4602 /** 4603 * Returns the Status of video telephony (VT) 4604 * @hide 4605 */ 4606 public boolean isVideoTelephonyAvailable() { 4607 try { 4608 return getITelephony().isVideoTelephonyAvailable(); 4609 } catch (RemoteException ex) { 4610 return false; 4611 } catch (NullPointerException ex) { 4612 return false; 4613 } 4614 } 4615 4616 /** 4617 * Returns the Status of Wi-Fi Calling 4618 * @hide 4619 */ 4620 public boolean isWifiCallingAvailable() { 4621 try { 4622 return getITelephony().isWifiCallingAvailable(); 4623 } catch (RemoteException ex) { 4624 return false; 4625 } catch (NullPointerException ex) { 4626 return false; 4627 } 4628 } 4629 4630 /** 4631 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 4632 * 4633 * @hide 4634 */ 4635 public void setSimOperatorNumeric(String numeric) { 4636 int phoneId = getDefaultPhone(); 4637 setSimOperatorNumericForPhone(phoneId, numeric); 4638 } 4639 4640 /** 4641 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 4642 * 4643 * @hide 4644 */ 4645 public void setSimOperatorNumericForPhone(int phoneId, String numeric) { 4646 setTelephonyProperty(phoneId, 4647 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, numeric); 4648 } 4649 4650 /** 4651 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 4652 * 4653 * @hide 4654 */ 4655 public void setSimOperatorName(String name) { 4656 int phoneId = getDefaultPhone(); 4657 setSimOperatorNameForPhone(phoneId, name); 4658 } 4659 4660 /** 4661 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 4662 * 4663 * @hide 4664 */ 4665 public void setSimOperatorNameForPhone(int phoneId, String name) { 4666 setTelephonyProperty(phoneId, 4667 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, name); 4668 } 4669 4670 /** 4671 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the default phone. 4672 * 4673 * @hide 4674 */ 4675 public void setSimCountryIso(String iso) { 4676 int phoneId = getDefaultPhone(); 4677 setSimCountryIsoForPhone(phoneId, iso); 4678 } 4679 4680 /** 4681 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the given phone. 4682 * 4683 * @hide 4684 */ 4685 public void setSimCountryIsoForPhone(int phoneId, String iso) { 4686 setTelephonyProperty(phoneId, 4687 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso); 4688 } 4689 4690 /** 4691 * Set TelephonyProperties.PROPERTY_SIM_STATE for the default phone. 4692 * 4693 * @hide 4694 */ 4695 public void setSimState(String state) { 4696 int phoneId = getDefaultPhone(); 4697 setSimStateForPhone(phoneId, state); 4698 } 4699 4700 /** 4701 * Set TelephonyProperties.PROPERTY_SIM_STATE for the given phone. 4702 * 4703 * @hide 4704 */ 4705 public void setSimStateForPhone(int phoneId, String state) { 4706 setTelephonyProperty(phoneId, 4707 TelephonyProperties.PROPERTY_SIM_STATE, state); 4708 } 4709 4710 /** 4711 * Set baseband version for the default phone. 4712 * 4713 * @param version baseband version 4714 * @hide 4715 */ 4716 public void setBasebandVersion(String version) { 4717 int phoneId = getDefaultPhone(); 4718 setBasebandVersionForPhone(phoneId, version); 4719 } 4720 4721 /** 4722 * Set baseband version by phone id. 4723 * 4724 * @param phoneId for which baseband version is set 4725 * @param version baseband version 4726 * @hide 4727 */ 4728 public void setBasebandVersionForPhone(int phoneId, String version) { 4729 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4730 String prop = TelephonyProperties.PROPERTY_BASEBAND_VERSION + 4731 ((phoneId == 0) ? "" : Integer.toString(phoneId)); 4732 SystemProperties.set(prop, version); 4733 } 4734 } 4735 4736 /** 4737 * Set phone type for the default phone. 4738 * 4739 * @param type phone type 4740 * 4741 * @hide 4742 */ 4743 public void setPhoneType(int type) { 4744 int phoneId = getDefaultPhone(); 4745 setPhoneType(phoneId, type); 4746 } 4747 4748 /** 4749 * Set phone type by phone id. 4750 * 4751 * @param phoneId for which phone type is set 4752 * @param type phone type 4753 * 4754 * @hide 4755 */ 4756 public void setPhoneType(int phoneId, int type) { 4757 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4758 TelephonyManager.setTelephonyProperty(phoneId, 4759 TelephonyProperties.CURRENT_ACTIVE_PHONE, String.valueOf(type)); 4760 } 4761 } 4762 4763 /** 4764 * Get OTASP number schema for the default phone. 4765 * 4766 * @param defaultValue default value 4767 * @return OTA SP number schema 4768 * 4769 * @hide 4770 */ 4771 public String getOtaSpNumberSchema(String defaultValue) { 4772 int phoneId = getDefaultPhone(); 4773 return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); 4774 } 4775 4776 /** 4777 * Get OTASP number schema by phone id. 4778 * 4779 * @param phoneId for which OTA SP number schema is get 4780 * @param defaultValue default value 4781 * @return OTA SP number schema 4782 * 4783 * @hide 4784 */ 4785 public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) { 4786 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4787 return TelephonyManager.getTelephonyProperty(phoneId, 4788 TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA, defaultValue); 4789 } 4790 4791 return defaultValue; 4792 } 4793 4794 /** 4795 * Get SMS receive capable from system property for the default phone. 4796 * 4797 * @param defaultValue default value 4798 * @return SMS receive capable 4799 * 4800 * @hide 4801 */ 4802 public boolean getSmsReceiveCapable(boolean defaultValue) { 4803 int phoneId = getDefaultPhone(); 4804 return getSmsReceiveCapableForPhone(phoneId, defaultValue); 4805 } 4806 4807 /** 4808 * Get SMS receive capable from system property by phone id. 4809 * 4810 * @param phoneId for which SMS receive capable is get 4811 * @param defaultValue default value 4812 * @return SMS receive capable 4813 * 4814 * @hide 4815 */ 4816 public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) { 4817 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4818 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 4819 TelephonyProperties.PROPERTY_SMS_RECEIVE, String.valueOf(defaultValue))); 4820 } 4821 4822 return defaultValue; 4823 } 4824 4825 /** 4826 * Get SMS send capable from system property for the default phone. 4827 * 4828 * @param defaultValue default value 4829 * @return SMS send capable 4830 * 4831 * @hide 4832 */ 4833 public boolean getSmsSendCapable(boolean defaultValue) { 4834 int phoneId = getDefaultPhone(); 4835 return getSmsSendCapableForPhone(phoneId, defaultValue); 4836 } 4837 4838 /** 4839 * Get SMS send capable from system property by phone id. 4840 * 4841 * @param phoneId for which SMS send capable is get 4842 * @param defaultValue default value 4843 * @return SMS send capable 4844 * 4845 * @hide 4846 */ 4847 public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) { 4848 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4849 return Boolean.valueOf(TelephonyManager.getTelephonyProperty(phoneId, 4850 TelephonyProperties.PROPERTY_SMS_SEND, String.valueOf(defaultValue))); 4851 } 4852 4853 return defaultValue; 4854 } 4855 4856 /** 4857 * Set the alphabetic name of current registered operator. 4858 * @param name the alphabetic name of current registered operator. 4859 * @hide 4860 */ 4861 public void setNetworkOperatorName(String name) { 4862 int phoneId = getDefaultPhone(); 4863 setNetworkOperatorNameForPhone(phoneId, name); 4864 } 4865 4866 /** 4867 * Set the alphabetic name of current registered operator. 4868 * @param phoneId which phone you want to set 4869 * @param name the alphabetic name of current registered operator. 4870 * @hide 4871 */ 4872 public void setNetworkOperatorNameForPhone(int phoneId, String name) { 4873 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4874 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, name); 4875 } 4876 } 4877 4878 /** 4879 * Set the numeric name (MCC+MNC) of current registered operator. 4880 * @param operator the numeric name (MCC+MNC) of current registered operator 4881 * @hide 4882 */ 4883 public void setNetworkOperatorNumeric(String numeric) { 4884 int phoneId = getDefaultPhone(); 4885 setNetworkOperatorNumericForPhone(phoneId, numeric); 4886 } 4887 4888 /** 4889 * Set the numeric name (MCC+MNC) of current registered operator. 4890 * @param phoneId for which phone type is set 4891 * @param operator the numeric name (MCC+MNC) of current registered operator 4892 * @hide 4893 */ 4894 public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) { 4895 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, numeric); 4896 } 4897 4898 /** 4899 * Set roaming state of the current network, for GSM purposes. 4900 * @param isRoaming is network in romaing state or not 4901 * @hide 4902 */ 4903 public void setNetworkRoaming(boolean isRoaming) { 4904 int phoneId = getDefaultPhone(); 4905 setNetworkRoamingForPhone(phoneId, isRoaming); 4906 } 4907 4908 /** 4909 * Set roaming state of the current network, for GSM purposes. 4910 * @param phoneId which phone you want to set 4911 * @param isRoaming is network in romaing state or not 4912 * @hide 4913 */ 4914 public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) { 4915 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4916 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, 4917 isRoaming ? "true" : "false"); 4918 } 4919 } 4920 4921 /** 4922 * Set the ISO country code equivalent of the current registered 4923 * operator's MCC (Mobile Country Code). 4924 * @param iso the ISO country code equivalent of the current registered 4925 * @hide 4926 */ 4927 public void setNetworkCountryIso(String iso) { 4928 int phoneId = getDefaultPhone(); 4929 setNetworkCountryIsoForPhone(phoneId, iso); 4930 } 4931 4932 /** 4933 * Set the ISO country code equivalent of the current registered 4934 * operator's MCC (Mobile Country Code). 4935 * @param phoneId which phone you want to set 4936 * @param iso the ISO country code equivalent of the current registered 4937 * @hide 4938 */ 4939 public void setNetworkCountryIsoForPhone(int phoneId, String iso) { 4940 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4941 setTelephonyProperty(phoneId, 4942 TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso); 4943 } 4944 } 4945 4946 /** 4947 * Set the network type currently in use on the device for data transmission. 4948 * @param type the network type currently in use on the device for data transmission 4949 * @hide 4950 */ 4951 public void setDataNetworkType(int type) { 4952 int phoneId = getDefaultPhone(); 4953 setDataNetworkTypeForPhone(phoneId, type); 4954 } 4955 4956 /** 4957 * Set the network type currently in use on the device for data transmission. 4958 * @param phoneId which phone you want to set 4959 * @param type the network type currently in use on the device for data transmission 4960 * @hide 4961 */ 4962 public void setDataNetworkTypeForPhone(int phoneId, int type) { 4963 if (SubscriptionManager.isValidPhoneId(phoneId)) { 4964 setTelephonyProperty(phoneId, 4965 TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, 4966 ServiceState.rilRadioTechnologyToString(type)); 4967 } 4968 } 4969 4970 /** 4971 * Returns the subscription ID for the given phone account. 4972 * @hide 4973 */ 4974 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { 4975 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 4976 try { 4977 ITelephony service = getITelephony(); 4978 if (service != null) { 4979 retval = service.getSubIdForPhoneAccount(phoneAccount); 4980 } 4981 } catch (RemoteException e) { 4982 } 4983 4984 return retval; 4985 } 4986 4987 /** 4988 * Resets telephony manager settings back to factory defaults. 4989 * 4990 * @hide 4991 */ 4992 public void factoryReset(int subId) { 4993 try { 4994 Log.d(TAG, "factoryReset: subId=" + subId); 4995 ITelephony telephony = getITelephony(); 4996 if (telephony != null) 4997 telephony.factoryReset(subId); 4998 } catch (RemoteException e) { 4999 } 5000 } 5001 5002 5003 /** @hide */ 5004 public String getLocaleFromDefaultSim() { 5005 try { 5006 final ITelephony telephony = getITelephony(); 5007 if (telephony != null) { 5008 return telephony.getLocaleFromDefaultSim(); 5009 } 5010 } catch (RemoteException ex) { 5011 } 5012 return null; 5013 } 5014 5015 /** 5016 * Returns the modem activity info. 5017 * @hide 5018 */ 5019 public ModemActivityInfo getModemActivityInfo() { 5020 try { 5021 ITelephony service = getITelephony(); 5022 if (service != null) { 5023 return service.getModemActivityInfo(); 5024 } 5025 } catch (RemoteException e) { 5026 Log.e(TAG, "Error calling ITelephony#getModemActivityInfo", e); 5027 } 5028 return null; 5029 } 5030 5031 /** 5032 * Returns the service state information on specified subscription. Callers require 5033 * either READ_PRIVILEGED_PHONE_STATE or READ_PHONE_STATE to retrieve the information. 5034 * @hide 5035 */ 5036 public ServiceState getServiceStateForSubscriber(int subId) { 5037 try { 5038 ITelephony service = getITelephony(); 5039 if (service != null) { 5040 return service.getServiceStateForSubscriber(subId, getOpPackageName()); 5041 } 5042 } catch (RemoteException e) { 5043 Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e); 5044 } 5045 return null; 5046 } 5047 5048 /** 5049 * Returns the URI for the per-account voicemail ringtone set in Phone settings. 5050 * 5051 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the 5052 * voicemail ringtone. 5053 * @return The URI for the ringtone to play when receiving a voicemail from a specific 5054 * PhoneAccount. 5055 */ 5056 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { 5057 try { 5058 ITelephony service = getITelephony(); 5059 if (service != null) { 5060 return service.getVoicemailRingtoneUri(accountHandle); 5061 } 5062 } catch (RemoteException e) { 5063 Log.e(TAG, "Error calling ITelephony#getVoicemailRingtoneUri", e); 5064 } 5065 return null; 5066 } 5067 5068 /** 5069 * Returns whether vibration is set for voicemail notification in Phone settings. 5070 * 5071 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the 5072 * voicemail vibration setting. 5073 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. 5074 */ 5075 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { 5076 try { 5077 ITelephony service = getITelephony(); 5078 if (service != null) { 5079 return service.isVoicemailVibrationEnabled(accountHandle); 5080 } 5081 } catch (RemoteException e) { 5082 Log.e(TAG, "Error calling ITelephony#isVoicemailVibrationEnabled", e); 5083 } 5084 return false; 5085 } 5086} 5087