TelephonyManager.java revision 0dc3b9104b0e3d9a86cc786acefa45475acfae16
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 static com.android.internal.util.Preconditions.checkNotNull; 20 21import android.annotation.IntDef; 22import android.annotation.Nullable; 23import android.annotation.RequiresPermission; 24import android.annotation.SdkConstant; 25import android.annotation.SdkConstant.SdkConstantType; 26import android.annotation.SystemApi; 27import android.annotation.WorkerThread; 28import android.app.ActivityThread; 29import android.app.PendingIntent; 30import android.content.ContentResolver; 31import android.content.Context; 32import android.content.Intent; 33import android.net.ConnectivityManager; 34import android.net.Uri; 35import android.os.BatteryStats; 36import android.os.Bundle; 37import android.os.Handler; 38import android.os.PersistableBundle; 39import android.os.RemoteException; 40import android.os.ResultReceiver; 41import android.os.ServiceManager; 42import android.os.SystemProperties; 43import android.provider.Settings; 44import android.provider.Settings.SettingNotFoundException; 45import android.service.carrier.CarrierIdentifier; 46import android.telecom.PhoneAccount; 47import android.telecom.PhoneAccountHandle; 48import android.telephony.ims.feature.ImsFeature; 49import android.util.Log; 50 51import com.android.ims.internal.IImsServiceController; 52import com.android.ims.internal.IImsServiceFeatureListener; 53import com.android.internal.annotations.VisibleForTesting; 54import com.android.internal.telecom.ITelecomService; 55import com.android.internal.telephony.CellNetworkScanResult; 56import com.android.internal.telephony.IPhoneSubInfo; 57import com.android.internal.telephony.ITelephony; 58import com.android.internal.telephony.ITelephonyRegistry; 59import com.android.internal.telephony.OperatorInfo; 60import com.android.internal.telephony.PhoneConstants; 61import com.android.internal.telephony.RILConstants; 62import com.android.internal.telephony.TelephonyProperties; 63 64import java.io.FileInputStream; 65import java.io.IOException; 66import java.lang.annotation.Retention; 67import java.lang.annotation.RetentionPolicy; 68import java.util.ArrayList; 69import java.util.Collections; 70import java.util.List; 71import java.util.regex.Matcher; 72import java.util.regex.Pattern; 73 74/** 75 * Provides access to information about the telephony services on 76 * the device. Applications can use the methods in this class to 77 * determine telephony services and states, as well as to access some 78 * types of subscriber information. Applications can also register 79 * a listener to receive notification of telephony state changes. 80 * <p> 81 * You do not instantiate this class directly; instead, you retrieve 82 * a reference to an instance through 83 * {@link android.content.Context#getSystemService 84 * Context.getSystemService(Context.TELEPHONY_SERVICE)}. 85 * 86 * The returned TelephonyManager will use the default subscription for all calls. 87 * To call an API for a specific subscription, use {@link #createForSubscriptionId(int)}. e.g. 88 * <code> 89 * telephonyManager = defaultSubTelephonyManager.createForSubscriptionId(subId); 90 * </code> 91 * <p> 92 * Note that access to some telephony information is 93 * permission-protected. Your application cannot access the protected 94 * information unless it has the appropriate permissions declared in 95 * its manifest file. Where permissions apply, they are noted in the 96 * the methods through which you access the protected information. 97 */ 98public class TelephonyManager { 99 private static final String TAG = "TelephonyManager"; 100 101 /** 102 * The key to use when placing the result of {@link #requestModemActivityInfo(ResultReceiver)} 103 * into the ResultReceiver Bundle. 104 * @hide 105 */ 106 public static final String MODEM_ACTIVITY_RESULT_KEY = 107 BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY; 108 109 private static ITelephonyRegistry sRegistry; 110 111 /** 112 * The allowed states of Wi-Fi calling. 113 * 114 * @hide 115 */ 116 public interface WifiCallingChoices { 117 /** Always use Wi-Fi calling */ 118 static final int ALWAYS_USE = 0; 119 /** Ask the user whether to use Wi-Fi on every call */ 120 static final int ASK_EVERY_TIME = 1; 121 /** Never use Wi-Fi calling */ 122 static final int NEVER_USE = 2; 123 } 124 125 /** The otaspMode passed to PhoneStateListener#onOtaspChanged */ 126 /** @hide */ 127 static public final int OTASP_UNINITIALIZED = 0; 128 /** @hide */ 129 static public final int OTASP_UNKNOWN = 1; 130 /** @hide */ 131 static public final int OTASP_NEEDED = 2; 132 /** @hide */ 133 static public final int OTASP_NOT_NEEDED = 3; 134 /* OtaUtil has conflict enum 4: OtaUtils.OTASP_FAILURE_SPC_RETRIES */ 135 /** @hide */ 136 static public final int OTASP_SIM_UNPROVISIONED = 5; 137 138 139 private final Context mContext; 140 private final int mSubId; 141 private SubscriptionManager mSubscriptionManager; 142 143 private static String multiSimConfig = 144 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 145 146 /** Enum indicating multisim variants 147 * DSDS - Dual SIM Dual Standby 148 * DSDA - Dual SIM Dual Active 149 * TSTS - Triple SIM Triple Standby 150 **/ 151 /** @hide */ 152 public enum MultiSimVariants { 153 DSDS, 154 DSDA, 155 TSTS, 156 UNKNOWN 157 }; 158 159 /** @hide */ 160 public TelephonyManager(Context context) { 161 this(context, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID); 162 } 163 164 /** @hide */ 165 public TelephonyManager(Context context, int subId) { 166 mSubId = subId; 167 Context appContext = context.getApplicationContext(); 168 if (appContext != null) { 169 mContext = appContext; 170 } else { 171 mContext = context; 172 } 173 mSubscriptionManager = SubscriptionManager.from(mContext); 174 175 if (sRegistry == null) { 176 sRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService( 177 "telephony.registry")); 178 } 179 } 180 181 /** @hide */ 182 private TelephonyManager() { 183 mContext = null; 184 mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 185 } 186 187 private static TelephonyManager sInstance = new TelephonyManager(); 188 189 /** @hide 190 /* @deprecated - use getSystemService as described above */ 191 public static TelephonyManager getDefault() { 192 return sInstance; 193 } 194 195 private String getOpPackageName() { 196 // For legacy reasons the TelephonyManager has API for getting 197 // a static instance with no context set preventing us from 198 // getting the op package name. As a workaround we do a best 199 // effort and get the context from the current activity thread. 200 if (mContext != null) { 201 return mContext.getOpPackageName(); 202 } 203 return ActivityThread.currentOpPackageName(); 204 } 205 206 /** 207 * Returns the multi SIM variant 208 * Returns DSDS for Dual SIM Dual Standby 209 * Returns DSDA for Dual SIM Dual Active 210 * Returns TSTS for Triple SIM Triple Standby 211 * Returns UNKNOWN for others 212 */ 213 /** {@hide} */ 214 public MultiSimVariants getMultiSimConfiguration() { 215 String mSimConfig = 216 SystemProperties.get(TelephonyProperties.PROPERTY_MULTI_SIM_CONFIG); 217 if (mSimConfig.equals("dsds")) { 218 return MultiSimVariants.DSDS; 219 } else if (mSimConfig.equals("dsda")) { 220 return MultiSimVariants.DSDA; 221 } else if (mSimConfig.equals("tsts")) { 222 return MultiSimVariants.TSTS; 223 } else { 224 return MultiSimVariants.UNKNOWN; 225 } 226 } 227 228 229 /** 230 * Returns the number of phones available. 231 * Returns 0 if none of voice, sms, data is not supported 232 * Returns 1 for Single standby mode (Single SIM functionality) 233 * Returns 2 for Dual standby mode.(Dual SIM functionality) 234 */ 235 public int getPhoneCount() { 236 int phoneCount = 1; 237 switch (getMultiSimConfiguration()) { 238 case UNKNOWN: 239 // if voice or sms or data is supported, return 1 otherwise 0 240 if (isVoiceCapable() || isSmsCapable()) { 241 phoneCount = 1; 242 } else { 243 // todo: try to clean this up further by getting rid of the nested conditions 244 if (mContext == null) { 245 phoneCount = 1; 246 } else { 247 // check for data support 248 ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService( 249 Context.CONNECTIVITY_SERVICE); 250 if (cm == null) { 251 phoneCount = 1; 252 } else { 253 if (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) { 254 phoneCount = 1; 255 } else { 256 phoneCount = 0; 257 } 258 } 259 } 260 } 261 break; 262 case DSDS: 263 case DSDA: 264 phoneCount = PhoneConstants.MAX_PHONE_COUNT_DUAL_SIM; 265 break; 266 case TSTS: 267 phoneCount = PhoneConstants.MAX_PHONE_COUNT_TRI_SIM; 268 break; 269 } 270 return phoneCount; 271 } 272 273 /** {@hide} */ 274 public static TelephonyManager from(Context context) { 275 return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 276 } 277 278 /** 279 * Create a new TelephonyManager object pinned to the given subscription ID. 280 * 281 * @return a TelephonyManager that uses the given subId for all calls. 282 */ 283 public TelephonyManager createForSubscriptionId(int subId) { 284 // Don't reuse any TelephonyManager objects. 285 return new TelephonyManager(mContext, subId); 286 } 287 288 /** 289 * Create a new TelephonyManager object pinned to the subscription ID associated with the given 290 * phone account. 291 * 292 * @return a TelephonyManager that uses the given phone account for all calls, or {@code null} 293 * if the phone account does not correspond to a valid subscription ID. 294 */ 295 @Nullable 296 public TelephonyManager createForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) { 297 int subId = getSubIdForPhoneAccountHandle(phoneAccountHandle); 298 if (!SubscriptionManager.isValidSubscriptionId(subId)) { 299 return null; 300 } 301 return new TelephonyManager(mContext, subId); 302 } 303 304 /** {@hide} */ 305 public boolean isMultiSimEnabled() { 306 return (multiSimConfig.equals("dsds") || multiSimConfig.equals("dsda") || 307 multiSimConfig.equals("tsts")); 308 } 309 310 // 311 // Broadcast Intent actions 312 // 313 314 /** 315 * Broadcast intent action indicating that the call state 316 * on the device has changed. 317 * 318 * <p> 319 * The {@link #EXTRA_STATE} extra indicates the new call state. 320 * If the new state is RINGING, a second extra 321 * {@link #EXTRA_INCOMING_NUMBER} provides the incoming phone number as 322 * a String. 323 * 324 * <p class="note"> 325 * Requires the READ_PHONE_STATE permission. 326 * 327 * <p class="note"> 328 * This was a {@link android.content.Context#sendStickyBroadcast sticky} 329 * broadcast in version 1.0, but it is no longer sticky. 330 * Instead, use {@link #getCallState} to synchronously query the current call state. 331 * 332 * @see #EXTRA_STATE 333 * @see #EXTRA_INCOMING_NUMBER 334 * @see #getCallState 335 */ 336 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 337 public static final String ACTION_PHONE_STATE_CHANGED = 338 "android.intent.action.PHONE_STATE"; 339 340 /** 341 * The Phone app sends this intent when a user opts to respond-via-message during an incoming 342 * call. By default, the device's default SMS app consumes this message and sends a text message 343 * to the caller. A third party app can also provide this functionality by consuming this Intent 344 * with a {@link android.app.Service} and sending the message using its own messaging system. 345 * <p>The intent contains a URI (available from {@link android.content.Intent#getData}) 346 * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:}, 347 * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the 348 * same way: the path part of the URI contains the recipient's phone number or a comma-separated 349 * set of phone numbers if there are multiple recipients. For example, {@code 350 * smsto:2065551234}.</p> 351 * 352 * <p>The intent may also contain extras for the message text (in {@link 353 * android.content.Intent#EXTRA_TEXT}) and a message subject 354 * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p> 355 * 356 * <p class="note"><strong>Note:</strong> 357 * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service} 358 * that requires the 359 * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p> 360 * <p>For example, the service that receives this intent can be declared in the manifest file 361 * with an intent filter like this:</p> 362 * <pre> 363 * <!-- Service that delivers SMS messages received from the phone "quick response" --> 364 * <service android:name=".HeadlessSmsSendService" 365 * android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" 366 * android:exported="true" > 367 * <intent-filter> 368 * <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /> 369 * <category android:name="android.intent.category.DEFAULT" /> 370 * <data android:scheme="sms" /> 371 * <data android:scheme="smsto" /> 372 * <data android:scheme="mms" /> 373 * <data android:scheme="mmsto" /> 374 * </intent-filter> 375 * </service></pre> 376 * <p> 377 * Output: nothing. 378 */ 379 @SdkConstant(SdkConstantType.SERVICE_ACTION) 380 public static final String ACTION_RESPOND_VIA_MESSAGE = 381 "android.intent.action.RESPOND_VIA_MESSAGE"; 382 383 /** 384 * The emergency dialer may choose to present activities with intent filters for this 385 * action as emergency assistance buttons that launch the activity when clicked. 386 * 387 * @hide 388 */ 389 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 390 public static final String ACTION_EMERGENCY_ASSISTANCE = 391 "android.telephony.action.EMERGENCY_ASSISTANCE"; 392 393 /** 394 * A boolean meta-data value indicating whether the voicemail settings should be hidden in the 395 * call settings page launched by 396 * {@link android.telecom.TelecomManager#ACTION_SHOW_CALL_SETTINGS}. 397 * Dialer implementations (see {@link android.telecom.TelecomManager#getDefaultDialerPackage()}) 398 * which would also like to manage voicemail settings should set this meta-data to {@code true} 399 * in the manifest registration of their application. 400 * 401 * @see android.telecom.TelecomManager#ACTION_SHOW_CALL_SETTINGS 402 * @see #ACTION_CONFIGURE_VOICEMAIL 403 * @see #EXTRA_HIDE_PUBLIC_SETTINGS 404 */ 405 public static final String METADATA_HIDE_VOICEMAIL_SETTINGS_MENU = 406 "android.telephony.HIDE_VOICEMAIL_SETTINGS_MENU"; 407 408 /** 409 * Open the voicemail settings activity to make changes to voicemail configuration. 410 * 411 * <p> 412 * The {@link #EXTRA_HIDE_PUBLIC_SETTINGS} hides settings the dialer will modify through public 413 * API if set. 414 * 415 * @see #EXTRA_HIDE_PUBLIC_SETTINGS 416 */ 417 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 418 public static final String ACTION_CONFIGURE_VOICEMAIL = 419 "android.telephony.action.CONFIGURE_VOICEMAIL"; 420 421 /** 422 * The boolean value indicating whether the voicemail settings activity launched by {@link 423 * #ACTION_CONFIGURE_VOICEMAIL} should hide settings accessible through public API. This is 424 * used by dialer implementations which provides their own voicemail settings UI, but still 425 * needs to expose device specific voicemail settings to the user. 426 * 427 * @see #ACTION_CONFIGURE_VOICEMAIL 428 * @see #METADATA_HIDE_VOICEMAIL_SETTINGS_MENU 429 */ 430 public static final String EXTRA_HIDE_PUBLIC_SETTINGS = 431 "android.telephony.extra.HIDE_PUBLIC_SETTINGS"; 432 433 /** 434 * @hide 435 */ 436 public static final boolean EMERGENCY_ASSISTANCE_ENABLED = true; 437 438 /** 439 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 440 * for a String containing the new call state. 441 * 442 * <p class="note"> 443 * Retrieve with 444 * {@link android.content.Intent#getStringExtra(String)}. 445 * 446 * @see #EXTRA_STATE_IDLE 447 * @see #EXTRA_STATE_RINGING 448 * @see #EXTRA_STATE_OFFHOOK 449 */ 450 public static final String EXTRA_STATE = PhoneConstants.STATE_KEY; 451 452 /** 453 * Value used with {@link #EXTRA_STATE} corresponding to 454 * {@link #CALL_STATE_IDLE}. 455 */ 456 public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString(); 457 458 /** 459 * Value used with {@link #EXTRA_STATE} corresponding to 460 * {@link #CALL_STATE_RINGING}. 461 */ 462 public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString(); 463 464 /** 465 * Value used with {@link #EXTRA_STATE} corresponding to 466 * {@link #CALL_STATE_OFFHOOK}. 467 */ 468 public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString(); 469 470 /** 471 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 472 * for a String containing the incoming phone number. 473 * Only valid when the new call state is RINGING. 474 * 475 * <p class="note"> 476 * Retrieve with 477 * {@link android.content.Intent#getStringExtra(String)}. 478 */ 479 public static final String EXTRA_INCOMING_NUMBER = "incoming_number"; 480 481 /** 482 * Broadcast intent action indicating that a precise call state 483 * (cellular) on the device has changed. 484 * 485 * <p> 486 * The {@link #EXTRA_RINGING_CALL_STATE} extra indicates the ringing call state. 487 * The {@link #EXTRA_FOREGROUND_CALL_STATE} extra indicates the foreground call state. 488 * The {@link #EXTRA_BACKGROUND_CALL_STATE} extra indicates the background call state. 489 * The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause. 490 * The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause. 491 * 492 * <p class="note"> 493 * Requires the READ_PRECISE_PHONE_STATE permission. 494 * 495 * @see #EXTRA_RINGING_CALL_STATE 496 * @see #EXTRA_FOREGROUND_CALL_STATE 497 * @see #EXTRA_BACKGROUND_CALL_STATE 498 * @see #EXTRA_DISCONNECT_CAUSE 499 * @see #EXTRA_PRECISE_DISCONNECT_CAUSE 500 * 501 * <p class="note"> 502 * Requires the READ_PRECISE_PHONE_STATE permission. 503 * 504 * @hide 505 */ 506 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 507 public static final String ACTION_PRECISE_CALL_STATE_CHANGED = 508 "android.intent.action.PRECISE_CALL_STATE"; 509 510 /** 511 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 512 * for an integer containing the state of the current ringing call. 513 * 514 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 515 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 516 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 517 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 518 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 519 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 520 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 521 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 522 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 523 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 524 * 525 * <p class="note"> 526 * Retrieve with 527 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 528 * 529 * @hide 530 */ 531 public static final String EXTRA_RINGING_CALL_STATE = "ringing_state"; 532 533 /** 534 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 535 * for an integer containing the state of the current foreground call. 536 * 537 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 538 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 539 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 540 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 541 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 542 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 543 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 544 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 545 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 546 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 547 * 548 * <p class="note"> 549 * Retrieve with 550 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 551 * 552 * @hide 553 */ 554 public static final String EXTRA_FOREGROUND_CALL_STATE = "foreground_state"; 555 556 /** 557 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 558 * for an integer containing the state of the current background call. 559 * 560 * @see PreciseCallState#PRECISE_CALL_STATE_NOT_VALID 561 * @see PreciseCallState#PRECISE_CALL_STATE_IDLE 562 * @see PreciseCallState#PRECISE_CALL_STATE_ACTIVE 563 * @see PreciseCallState#PRECISE_CALL_STATE_HOLDING 564 * @see PreciseCallState#PRECISE_CALL_STATE_DIALING 565 * @see PreciseCallState#PRECISE_CALL_STATE_ALERTING 566 * @see PreciseCallState#PRECISE_CALL_STATE_INCOMING 567 * @see PreciseCallState#PRECISE_CALL_STATE_WAITING 568 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTED 569 * @see PreciseCallState#PRECISE_CALL_STATE_DISCONNECTING 570 * 571 * <p class="note"> 572 * Retrieve with 573 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 574 * 575 * @hide 576 */ 577 public static final String EXTRA_BACKGROUND_CALL_STATE = "background_state"; 578 579 /** 580 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 581 * for an integer containing the disconnect cause. 582 * 583 * @see DisconnectCause 584 * 585 * <p class="note"> 586 * Retrieve with 587 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 588 * 589 * @hide 590 */ 591 public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause"; 592 593 /** 594 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast 595 * for an integer containing the disconnect cause provided by the RIL. 596 * 597 * @see PreciseDisconnectCause 598 * 599 * <p class="note"> 600 * Retrieve with 601 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 602 * 603 * @hide 604 */ 605 public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause"; 606 607 /** 608 * Broadcast intent action indicating a data connection has changed, 609 * providing precise information about the connection. 610 * 611 * <p> 612 * The {@link #EXTRA_DATA_STATE} extra indicates the connection state. 613 * The {@link #EXTRA_DATA_NETWORK_TYPE} extra indicates the connection network type. 614 * The {@link #EXTRA_DATA_APN_TYPE} extra indicates the APN type. 615 * The {@link #EXTRA_DATA_APN} extra indicates the APN. 616 * The {@link #EXTRA_DATA_CHANGE_REASON} extra indicates the connection change reason. 617 * The {@link #EXTRA_DATA_IFACE_PROPERTIES} extra indicates the connection interface. 618 * The {@link #EXTRA_DATA_FAILURE_CAUSE} extra indicates the connection fail cause. 619 * 620 * <p class="note"> 621 * Requires the READ_PRECISE_PHONE_STATE permission. 622 * 623 * @see #EXTRA_DATA_STATE 624 * @see #EXTRA_DATA_NETWORK_TYPE 625 * @see #EXTRA_DATA_APN_TYPE 626 * @see #EXTRA_DATA_APN 627 * @see #EXTRA_DATA_CHANGE_REASON 628 * @see #EXTRA_DATA_IFACE 629 * @see #EXTRA_DATA_FAILURE_CAUSE 630 * @hide 631 */ 632 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 633 public static final String ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED = 634 "android.intent.action.PRECISE_DATA_CONNECTION_STATE_CHANGED"; 635 636 /** 637 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 638 * for an integer containing the state of the current data connection. 639 * 640 * @see TelephonyManager#DATA_UNKNOWN 641 * @see TelephonyManager#DATA_DISCONNECTED 642 * @see TelephonyManager#DATA_CONNECTING 643 * @see TelephonyManager#DATA_CONNECTED 644 * @see TelephonyManager#DATA_SUSPENDED 645 * 646 * <p class="note"> 647 * Retrieve with 648 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 649 * 650 * @hide 651 */ 652 public static final String EXTRA_DATA_STATE = PhoneConstants.STATE_KEY; 653 654 /** 655 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 656 * for an integer containing the network type. 657 * 658 * @see TelephonyManager#NETWORK_TYPE_UNKNOWN 659 * @see TelephonyManager#NETWORK_TYPE_GPRS 660 * @see TelephonyManager#NETWORK_TYPE_EDGE 661 * @see TelephonyManager#NETWORK_TYPE_UMTS 662 * @see TelephonyManager#NETWORK_TYPE_CDMA 663 * @see TelephonyManager#NETWORK_TYPE_EVDO_0 664 * @see TelephonyManager#NETWORK_TYPE_EVDO_A 665 * @see TelephonyManager#NETWORK_TYPE_1xRTT 666 * @see TelephonyManager#NETWORK_TYPE_HSDPA 667 * @see TelephonyManager#NETWORK_TYPE_HSUPA 668 * @see TelephonyManager#NETWORK_TYPE_HSPA 669 * @see TelephonyManager#NETWORK_TYPE_IDEN 670 * @see TelephonyManager#NETWORK_TYPE_EVDO_B 671 * @see TelephonyManager#NETWORK_TYPE_LTE 672 * @see TelephonyManager#NETWORK_TYPE_EHRPD 673 * @see TelephonyManager#NETWORK_TYPE_HSPAP 674 * 675 * <p class="note"> 676 * Retrieve with 677 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 678 * 679 * @hide 680 */ 681 public static final String EXTRA_DATA_NETWORK_TYPE = PhoneConstants.DATA_NETWORK_TYPE_KEY; 682 683 /** 684 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 685 * for an String containing the data APN type. 686 * 687 * <p class="note"> 688 * Retrieve with 689 * {@link android.content.Intent#getStringExtra(String name)}. 690 * 691 * @hide 692 */ 693 public static final String EXTRA_DATA_APN_TYPE = PhoneConstants.DATA_APN_TYPE_KEY; 694 695 /** 696 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 697 * for an String containing the data APN. 698 * 699 * <p class="note"> 700 * Retrieve with 701 * {@link android.content.Intent#getStringExtra(String name)}. 702 * 703 * @hide 704 */ 705 public static final String EXTRA_DATA_APN = PhoneConstants.DATA_APN_KEY; 706 707 /** 708 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 709 * for an String representation of the change reason. 710 * 711 * <p class="note"> 712 * Retrieve with 713 * {@link android.content.Intent#getStringExtra(String name)}. 714 * 715 * @hide 716 */ 717 public static final String EXTRA_DATA_CHANGE_REASON = PhoneConstants.STATE_CHANGE_REASON_KEY; 718 719 /** 720 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 721 * for an String representation of the data interface. 722 * 723 * <p class="note"> 724 * Retrieve with 725 * {@link android.content.Intent#getParcelableExtra(String name)}. 726 * 727 * @hide 728 */ 729 public static final String EXTRA_DATA_LINK_PROPERTIES_KEY = PhoneConstants.DATA_LINK_PROPERTIES_KEY; 730 731 /** 732 * The lookup key used with the {@link #ACTION_PRECISE_DATA_CONNECTION_STATE_CHANGED} broadcast 733 * for the data connection fail cause. 734 * 735 * <p class="note"> 736 * Retrieve with 737 * {@link android.content.Intent#getStringExtra(String name)}. 738 * 739 * @hide 740 */ 741 public static final String EXTRA_DATA_FAILURE_CAUSE = PhoneConstants.DATA_FAILURE_CAUSE_KEY; 742 743 /** 744 * Broadcast intent action for letting the default dialer to know to show voicemail 745 * notification. 746 * 747 * <p> 748 * The {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra indicates which {@link PhoneAccountHandle} the 749 * voicemail is received on. 750 * The {@link #EXTRA_NOTIFICATION_COUNT} extra indicates the total numbers of unheard 751 * voicemails. 752 * The {@link #EXTRA_VOICEMAIL_NUMBER} extra indicates the voicemail number if available. 753 * The {@link #EXTRA_CALL_VOICEMAIL_INTENT} extra is a {@link android.app.PendingIntent} that 754 * will call the voicemail number when sent. This extra will be empty if the voicemail number 755 * is not set, and {@link #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT} will be set instead. 756 * The {@link #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT} extra is a 757 * {@link android.app.PendingIntent} that will launch the voicemail settings. This extra is only 758 * available when the voicemail number is not set. 759 * 760 * @see #EXTRA_PHONE_ACCOUNT_HANDLE 761 * @see #EXTRA_NOTIFICATION_COUNT 762 * @see #EXTRA_VOICEMAIL_NUMBER 763 * @see #EXTRA_CALL_VOICEMAIL_INTENT 764 * @see #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT 765 */ 766 public static final String ACTION_SHOW_VOICEMAIL_NOTIFICATION = 767 "android.telephony.action.SHOW_VOICEMAIL_NOTIFICATION"; 768 769 /** 770 * The extra used with an {@link #ACTION_SHOW_VOICEMAIL_NOTIFICATION} {@code Intent} to specify 771 * the {@link PhoneAccountHandle} the notification is for. 772 * <p class="note"> 773 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}. 774 */ 775 public static final String EXTRA_PHONE_ACCOUNT_HANDLE = 776 "android.telephony.extra.PHONE_ACCOUNT_HANDLE"; 777 778 /** 779 * The number of voice messages associated with the notification. 780 */ 781 public static final String EXTRA_NOTIFICATION_COUNT = 782 "android.telephony.extra.NOTIFICATION_COUNT"; 783 784 /** 785 * The voicemail number. 786 */ 787 public static final String EXTRA_VOICEMAIL_NUMBER = 788 "android.telephony.extra.VOICEMAIL_NUMBER"; 789 790 /** 791 * The intent to call voicemail. 792 */ 793 public static final String EXTRA_CALL_VOICEMAIL_INTENT = 794 "android.telephony.extra.CALL_VOICEMAIL_INTENT"; 795 796 /** 797 * The intent to launch voicemail settings. 798 */ 799 public static final String EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT = 800 "android.telephony.extra.LAUNCH_VOICEMAIL_SETTINGS_INTENT"; 801 802 /** 803 * {@link android.telecom.Connection} event used to indicate that an IMS call has be 804 * successfully handed over from WIFI to LTE. 805 * <p> 806 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 807 * The {@link Bundle} parameter is expected to be null when this connection event is used. 808 * @hide 809 */ 810 public static final String EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE = 811 "android.telephony.event.EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE"; 812 813 /** 814 * {@link android.telecom.Connection} event used to indicate that an IMS call failed to be 815 * handed over from LTE to WIFI. 816 * <p> 817 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 818 * The {@link Bundle} parameter is expected to be null when this connection event is used. 819 * @hide 820 */ 821 public static final String EVENT_HANDOVER_TO_WIFI_FAILED = 822 "android.telephony.event.EVENT_HANDOVER_TO_WIFI_FAILED"; 823 824 /** 825 * {@link android.telecom.Connection} event used to indicate that a video call was downgraded to 826 * audio because the data limit was reached. 827 * <p> 828 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 829 * The {@link Bundle} parameter is expected to be null when this connection event is used. 830 * @hide 831 */ 832 public static final String EVENT_DOWNGRADE_DATA_LIMIT_REACHED = 833 "android.telephony.event.EVENT_DOWNGRADE_DATA_LIMIT_REACHED"; 834 835 /** 836 * {@link android.telecom.Connection} event used to indicate that a video call was downgraded to 837 * audio because the data was disabled. 838 * <p> 839 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 840 * The {@link Bundle} parameter is expected to be null when this connection event is used. 841 * @hide 842 */ 843 public static final String EVENT_DOWNGRADE_DATA_DISABLED = 844 "android.telephony.event.EVENT_DOWNGRADE_DATA_DISABLED"; 845 846 /** 847 * {@link android.telecom.Connection} event used to indicate that the InCall UI should notify 848 * the user when an international call is placed while on WFC only. 849 * <p> 850 * Used when the carrier config value 851 * {@link CarrierConfigManager#KEY_NOTIFY_INTERNATIONAL_CALL_ON_WFC_BOOL} is true, the device 852 * is on WFC (VoLTE not available) and an international number is dialed. 853 * <p> 854 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 855 * The {@link Bundle} parameter is expected to be null when this connection event is used. 856 * @hide 857 */ 858 public static final String EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC = 859 "android.telephony.event.EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC"; 860 861 /* Visual voicemail protocols */ 862 863 /** 864 * The OMTP protocol. 865 */ 866 public static final String VVM_TYPE_OMTP = "vvm_type_omtp"; 867 868 /** 869 * A flavor of OMTP protocol with a different mobile originated (MO) format 870 */ 871 public static final String VVM_TYPE_CVVM = "vvm_type_cvvm"; 872 873 /** 874 * @hide 875 */ 876 public static final String USSD_RESPONSE = "USSD_RESPONSE"; 877 878 /** 879 * USSD return code success. 880 * @hide 881 */ 882 public static final int USSD_RETURN_SUCCESS = 100; 883 884 /** 885 * USSD return code for failure case. 886 * @hide 887 */ 888 public static final int USSD_RETURN_FAILURE = -1; 889 890 /** 891 * USSD return code for failure case. 892 * @hide 893 */ 894 public static final int USSD_ERROR_SERVICE_UNAVAIL = -2; 895 896 // 897 // 898 // Device Info 899 // 900 // 901 902 /** 903 * Returns the software version number for the device, for example, 904 * the IMEI/SV for GSM phones. Return null if the software version is 905 * not available. 906 * 907 * <p>Requires Permission: 908 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 909 */ 910 public String getDeviceSoftwareVersion() { 911 return getDeviceSoftwareVersion(getDefaultSim()); 912 } 913 914 /** 915 * Returns the software version number for the device, for example, 916 * the IMEI/SV for GSM phones. Return null if the software version is 917 * not available. 918 * 919 * <p>Requires Permission: 920 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 921 * 922 * @param slotIndex of which deviceID is returned 923 */ 924 /** {@hide} */ 925 public String getDeviceSoftwareVersion(int slotIndex) { 926 ITelephony telephony = getITelephony(); 927 if (telephony == null) return null; 928 929 try { 930 return telephony.getDeviceSoftwareVersionForSlot(slotIndex, getOpPackageName()); 931 } catch (RemoteException ex) { 932 return null; 933 } catch (NullPointerException ex) { 934 return null; 935 } 936 } 937 938 /** 939 * Returns the unique device ID, for example, the IMEI for GSM and the MEID 940 * or ESN for CDMA phones. Return null if device ID is not available. 941 * 942 * <p>Requires Permission: 943 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 944 * 945 * @deprecated Use (@link getImei} which returns IMEI for GSM or (@link getMeid} which returns 946 * MEID for CDMA. 947 */ 948 @Deprecated 949 public String getDeviceId() { 950 try { 951 ITelephony telephony = getITelephony(); 952 if (telephony == null) 953 return null; 954 return telephony.getDeviceId(mContext.getOpPackageName()); 955 } catch (RemoteException ex) { 956 return null; 957 } catch (NullPointerException ex) { 958 return null; 959 } 960 } 961 962 /** 963 * Returns the unique device ID of a subscription, for example, the IMEI for 964 * GSM and the MEID for CDMA phones. Return null if device ID is not available. 965 * 966 * <p>Requires Permission: 967 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 968 * 969 * @param slotIndex of which deviceID is returned 970 * 971 * @deprecated Use (@link getImei} which returns IMEI for GSM or (@link getMeid} which returns 972 * MEID for CDMA. 973 */ 974 @Deprecated 975 public String getDeviceId(int slotIndex) { 976 // FIXME this assumes phoneId == slotIndex 977 try { 978 IPhoneSubInfo info = getSubscriberInfo(); 979 if (info == null) 980 return null; 981 return info.getDeviceIdForPhone(slotIndex, mContext.getOpPackageName()); 982 } catch (RemoteException ex) { 983 return null; 984 } catch (NullPointerException ex) { 985 return null; 986 } 987 } 988 989 /** 990 * Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not 991 * available. 992 * 993 * <p>Requires Permission: 994 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 995 */ 996 public String getImei() { 997 return getImei(getDefaultSim()); 998 } 999 1000 /** 1001 * Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not 1002 * available. 1003 * 1004 * <p>Requires Permission: 1005 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1006 * 1007 * @param slotIndex of which IMEI is returned 1008 */ 1009 public String getImei(int slotIndex) { 1010 ITelephony telephony = getITelephony(); 1011 if (telephony == null) return null; 1012 1013 try { 1014 return telephony.getImeiForSlot(slotIndex, getOpPackageName()); 1015 } catch (RemoteException ex) { 1016 return null; 1017 } catch (NullPointerException ex) { 1018 return null; 1019 } 1020 } 1021 1022 /** 1023 * Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. 1024 * 1025 * <p>Requires Permission: 1026 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1027 */ 1028 public String getMeid() { 1029 return getMeid(getDefaultSim()); 1030 } 1031 1032 /** 1033 * Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. 1034 * 1035 * <p>Requires Permission: 1036 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1037 * 1038 * @param slotIndex of which MEID is returned 1039 */ 1040 public String getMeid(int slotIndex) { 1041 ITelephony telephony = getITelephony(); 1042 if (telephony == null) return null; 1043 1044 try { 1045 return telephony.getMeidForSlot(slotIndex, getOpPackageName()); 1046 } catch (RemoteException ex) { 1047 return null; 1048 } catch (NullPointerException ex) { 1049 return null; 1050 } 1051 } 1052 1053 /** 1054 * Returns the NAI. Return null if NAI is not available. 1055 * 1056 */ 1057 /** {@hide}*/ 1058 public String getNai() { 1059 return getNai(getDefaultSim()); 1060 } 1061 1062 /** 1063 * Returns the NAI. Return null if NAI is not available. 1064 * 1065 * @param slotIndex of which Nai is returned 1066 */ 1067 /** {@hide}*/ 1068 public String getNai(int slotIndex) { 1069 int[] subId = SubscriptionManager.getSubId(slotIndex); 1070 try { 1071 IPhoneSubInfo info = getSubscriberInfo(); 1072 if (info == null) 1073 return null; 1074 String nai = info.getNaiForSubscriber(subId[0], mContext.getOpPackageName()); 1075 if (Log.isLoggable(TAG, Log.VERBOSE)) { 1076 Rlog.v(TAG, "Nai = " + nai); 1077 } 1078 return nai; 1079 } catch (RemoteException ex) { 1080 return null; 1081 } catch (NullPointerException ex) { 1082 return null; 1083 } 1084 } 1085 1086 /** 1087 * Returns the current location of the device. 1088 *<p> 1089 * If there is only one radio in the device and that radio has an LTE connection, 1090 * this method will return null. The implementation must not to try add LTE 1091 * identifiers into the existing cdma/gsm classes. 1092 *<p> 1093 * In the future this call will be deprecated. 1094 *<p> 1095 * @return Current location of the device or null if not available. 1096 * 1097 * <p>Requires Permission: 1098 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_COARSE_LOCATION} or 1099 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION ACCESS_FINE_LOCATION}. 1100 */ 1101 public CellLocation getCellLocation() { 1102 try { 1103 ITelephony telephony = getITelephony(); 1104 if (telephony == null) { 1105 Rlog.d(TAG, "getCellLocation returning null because telephony is null"); 1106 return null; 1107 } 1108 Bundle bundle = telephony.getCellLocation(mContext.getOpPackageName()); 1109 if (bundle.isEmpty()) { 1110 Rlog.d(TAG, "getCellLocation returning null because bundle is empty"); 1111 return null; 1112 } 1113 CellLocation cl = CellLocation.newFromBundle(bundle); 1114 if (cl.isEmpty()) { 1115 Rlog.d(TAG, "getCellLocation returning null because CellLocation is empty"); 1116 return null; 1117 } 1118 return cl; 1119 } catch (RemoteException ex) { 1120 Rlog.d(TAG, "getCellLocation returning null due to RemoteException " + ex); 1121 return null; 1122 } catch (NullPointerException ex) { 1123 Rlog.d(TAG, "getCellLocation returning null due to NullPointerException " + ex); 1124 return null; 1125 } 1126 } 1127 1128 /** 1129 * Enables location update notifications. {@link PhoneStateListener#onCellLocationChanged 1130 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 1131 * 1132 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 1133 * CONTROL_LOCATION_UPDATES} 1134 * 1135 * @hide 1136 */ 1137 public void enableLocationUpdates() { 1138 enableLocationUpdates(getSubId()); 1139 } 1140 1141 /** 1142 * Enables location update notifications for a subscription. 1143 * {@link PhoneStateListener#onCellLocationChanged 1144 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 1145 * 1146 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 1147 * CONTROL_LOCATION_UPDATES} 1148 * 1149 * @param subId for which the location updates are enabled 1150 * @hide 1151 */ 1152 public void enableLocationUpdates(int subId) { 1153 try { 1154 ITelephony telephony = getITelephony(); 1155 if (telephony != null) 1156 telephony.enableLocationUpdatesForSubscriber(subId); 1157 } catch (RemoteException ex) { 1158 } catch (NullPointerException ex) { 1159 } 1160 } 1161 1162 /** 1163 * Disables location update notifications. {@link PhoneStateListener#onCellLocationChanged 1164 * PhoneStateListener.onCellLocationChanged} will be called on location updates. 1165 * 1166 * <p>Requires Permission: {@link android.Manifest.permission#CONTROL_LOCATION_UPDATES 1167 * CONTROL_LOCATION_UPDATES} 1168 * 1169 * @hide 1170 */ 1171 public void disableLocationUpdates() { 1172 disableLocationUpdates(getSubId()); 1173 } 1174 1175 /** @hide */ 1176 public void disableLocationUpdates(int subId) { 1177 try { 1178 ITelephony telephony = getITelephony(); 1179 if (telephony != null) 1180 telephony.disableLocationUpdatesForSubscriber(subId); 1181 } catch (RemoteException ex) { 1182 } catch (NullPointerException ex) { 1183 } 1184 } 1185 1186 /** 1187 * Returns the neighboring cell information of the device. 1188 * 1189 * <p>Requires Permission: 1190 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 1191 * 1192 * @return List of NeighboringCellInfo or null if info unavailable. 1193 * 1194 * @deprecated Use {@link #getAllCellInfo} which returns a superset of the information 1195 * from NeighboringCellInfo. 1196 */ 1197 @Deprecated 1198 public List<NeighboringCellInfo> getNeighboringCellInfo() { 1199 try { 1200 ITelephony telephony = getITelephony(); 1201 if (telephony == null) 1202 return null; 1203 return telephony.getNeighboringCellInfo(mContext.getOpPackageName()); 1204 } catch (RemoteException ex) { 1205 return null; 1206 } catch (NullPointerException ex) { 1207 return null; 1208 } 1209 } 1210 1211 /** No phone radio. */ 1212 public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE; 1213 /** Phone radio is GSM. */ 1214 public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM; 1215 /** Phone radio is CDMA. */ 1216 public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA; 1217 /** Phone is via SIP. */ 1218 public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP; 1219 1220 /** 1221 * Returns the current phone type. 1222 * TODO: This is a last minute change and hence hidden. 1223 * 1224 * @see #PHONE_TYPE_NONE 1225 * @see #PHONE_TYPE_GSM 1226 * @see #PHONE_TYPE_CDMA 1227 * @see #PHONE_TYPE_SIP 1228 * 1229 * {@hide} 1230 */ 1231 @SystemApi 1232 public int getCurrentPhoneType() { 1233 return getCurrentPhoneType(getSubId()); 1234 } 1235 1236 /** 1237 * Returns a constant indicating the device phone type for a subscription. 1238 * 1239 * @see #PHONE_TYPE_NONE 1240 * @see #PHONE_TYPE_GSM 1241 * @see #PHONE_TYPE_CDMA 1242 * 1243 * @param subId for which phone type is returned 1244 * @hide 1245 */ 1246 @SystemApi 1247 public int getCurrentPhoneType(int subId) { 1248 int phoneId; 1249 if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 1250 // if we don't have any sims, we don't have subscriptions, but we 1251 // still may want to know what type of phone we've got. 1252 phoneId = 0; 1253 } else { 1254 phoneId = SubscriptionManager.getPhoneId(subId); 1255 } 1256 1257 return getCurrentPhoneTypeForSlot(phoneId); 1258 } 1259 1260 /** 1261 * See getCurrentPhoneType. 1262 * 1263 * @hide 1264 */ 1265 public int getCurrentPhoneTypeForSlot(int slotIndex) { 1266 try{ 1267 ITelephony telephony = getITelephony(); 1268 if (telephony != null) { 1269 return telephony.getActivePhoneTypeForSlot(slotIndex); 1270 } else { 1271 // This can happen when the ITelephony interface is not up yet. 1272 return getPhoneTypeFromProperty(slotIndex); 1273 } 1274 } catch (RemoteException ex) { 1275 // This shouldn't happen in the normal case, as a backup we 1276 // read from the system property. 1277 return getPhoneTypeFromProperty(slotIndex); 1278 } catch (NullPointerException ex) { 1279 // This shouldn't happen in the normal case, as a backup we 1280 // read from the system property. 1281 return getPhoneTypeFromProperty(slotIndex); 1282 } 1283 } 1284 1285 /** 1286 * Returns a constant indicating the device phone type. This 1287 * indicates the type of radio used to transmit voice calls. 1288 * 1289 * @see #PHONE_TYPE_NONE 1290 * @see #PHONE_TYPE_GSM 1291 * @see #PHONE_TYPE_CDMA 1292 * @see #PHONE_TYPE_SIP 1293 */ 1294 public int getPhoneType() { 1295 if (!isVoiceCapable()) { 1296 return PHONE_TYPE_NONE; 1297 } 1298 return getCurrentPhoneType(); 1299 } 1300 1301 private int getPhoneTypeFromProperty() { 1302 return getPhoneTypeFromProperty(getDefaultPhone()); 1303 } 1304 1305 /** {@hide} */ 1306 private int getPhoneTypeFromProperty(int phoneId) { 1307 String type = getTelephonyProperty(phoneId, 1308 TelephonyProperties.CURRENT_ACTIVE_PHONE, null); 1309 if (type == null || type.isEmpty()) { 1310 return getPhoneTypeFromNetworkType(phoneId); 1311 } 1312 return Integer.parseInt(type); 1313 } 1314 1315 private int getPhoneTypeFromNetworkType() { 1316 return getPhoneTypeFromNetworkType(getDefaultPhone()); 1317 } 1318 1319 /** {@hide} */ 1320 private int getPhoneTypeFromNetworkType(int phoneId) { 1321 // When the system property CURRENT_ACTIVE_PHONE, has not been set, 1322 // use the system property for default network type. 1323 // This is a fail safe, and can only happen at first boot. 1324 String mode = getTelephonyProperty(phoneId, "ro.telephony.default_network", null); 1325 if (mode != null && !mode.isEmpty()) { 1326 return TelephonyManager.getPhoneType(Integer.parseInt(mode)); 1327 } 1328 return TelephonyManager.PHONE_TYPE_NONE; 1329 } 1330 1331 /** 1332 * This function returns the type of the phone, depending 1333 * on the network mode. 1334 * 1335 * @param networkMode 1336 * @return Phone Type 1337 * 1338 * @hide 1339 */ 1340 public static int getPhoneType(int networkMode) { 1341 switch(networkMode) { 1342 case RILConstants.NETWORK_MODE_CDMA: 1343 case RILConstants.NETWORK_MODE_CDMA_NO_EVDO: 1344 case RILConstants.NETWORK_MODE_EVDO_NO_CDMA: 1345 return PhoneConstants.PHONE_TYPE_CDMA; 1346 1347 case RILConstants.NETWORK_MODE_WCDMA_PREF: 1348 case RILConstants.NETWORK_MODE_GSM_ONLY: 1349 case RILConstants.NETWORK_MODE_WCDMA_ONLY: 1350 case RILConstants.NETWORK_MODE_GSM_UMTS: 1351 case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA: 1352 case RILConstants.NETWORK_MODE_LTE_WCDMA: 1353 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA: 1354 case RILConstants.NETWORK_MODE_TDSCDMA_ONLY: 1355 case RILConstants.NETWORK_MODE_TDSCDMA_WCDMA: 1356 case RILConstants.NETWORK_MODE_LTE_TDSCDMA: 1357 case RILConstants.NETWORK_MODE_TDSCDMA_GSM: 1358 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM: 1359 case RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA: 1360 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA: 1361 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA: 1362 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA: 1363 return PhoneConstants.PHONE_TYPE_GSM; 1364 1365 // Use CDMA Phone for the global mode including CDMA 1366 case RILConstants.NETWORK_MODE_GLOBAL: 1367 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO: 1368 case RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA: 1369 return PhoneConstants.PHONE_TYPE_CDMA; 1370 1371 case RILConstants.NETWORK_MODE_LTE_ONLY: 1372 if (getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) { 1373 return PhoneConstants.PHONE_TYPE_CDMA; 1374 } else { 1375 return PhoneConstants.PHONE_TYPE_GSM; 1376 } 1377 default: 1378 return PhoneConstants.PHONE_TYPE_GSM; 1379 } 1380 } 1381 1382 /** 1383 * The contents of the /proc/cmdline file 1384 */ 1385 private static String getProcCmdLine() 1386 { 1387 String cmdline = ""; 1388 FileInputStream is = null; 1389 try { 1390 is = new FileInputStream("/proc/cmdline"); 1391 byte [] buffer = new byte[2048]; 1392 int count = is.read(buffer); 1393 if (count > 0) { 1394 cmdline = new String(buffer, 0, count); 1395 } 1396 } catch (IOException e) { 1397 Rlog.d(TAG, "No /proc/cmdline exception=" + e); 1398 } finally { 1399 if (is != null) { 1400 try { 1401 is.close(); 1402 } catch (IOException e) { 1403 } 1404 } 1405 } 1406 Rlog.d(TAG, "/proc/cmdline=" + cmdline); 1407 return cmdline; 1408 } 1409 1410 /** Kernel command line */ 1411 private static final String sKernelCmdLine = getProcCmdLine(); 1412 1413 /** Pattern for selecting the product type from the kernel command line */ 1414 private static final Pattern sProductTypePattern = 1415 Pattern.compile("\\sproduct_type\\s*=\\s*(\\w+)"); 1416 1417 /** The ProductType used for LTE on CDMA devices */ 1418 private static final String sLteOnCdmaProductType = 1419 SystemProperties.get(TelephonyProperties.PROPERTY_LTE_ON_CDMA_PRODUCT_TYPE, ""); 1420 1421 /** 1422 * Return if the current radio is LTE on CDMA. This 1423 * is a tri-state return value as for a period of time 1424 * the mode may be unknown. 1425 * 1426 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 1427 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 1428 * 1429 * @hide 1430 */ 1431 public static int getLteOnCdmaModeStatic() { 1432 int retVal; 1433 int curVal; 1434 String productType = ""; 1435 1436 curVal = SystemProperties.getInt(TelephonyProperties.PROPERTY_LTE_ON_CDMA_DEVICE, 1437 PhoneConstants.LTE_ON_CDMA_UNKNOWN); 1438 retVal = curVal; 1439 if (retVal == PhoneConstants.LTE_ON_CDMA_UNKNOWN) { 1440 Matcher matcher = sProductTypePattern.matcher(sKernelCmdLine); 1441 if (matcher.find()) { 1442 productType = matcher.group(1); 1443 if (sLteOnCdmaProductType.equals(productType)) { 1444 retVal = PhoneConstants.LTE_ON_CDMA_TRUE; 1445 } else { 1446 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 1447 } 1448 } else { 1449 retVal = PhoneConstants.LTE_ON_CDMA_FALSE; 1450 } 1451 } 1452 1453 Rlog.d(TAG, "getLteOnCdmaMode=" + retVal + " curVal=" + curVal + 1454 " product_type='" + productType + 1455 "' lteOnCdmaProductType='" + sLteOnCdmaProductType + "'"); 1456 return retVal; 1457 } 1458 1459 // 1460 // 1461 // Current Network 1462 // 1463 // 1464 1465 /** 1466 * Returns the alphabetic name of current registered operator. 1467 * <p> 1468 * Availability: Only when user is registered to a network. Result may be 1469 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1470 * on a CDMA network). 1471 */ 1472 public String getNetworkOperatorName() { 1473 return getNetworkOperatorName(getSubId()); 1474 } 1475 1476 /** 1477 * Returns the alphabetic name of current registered operator 1478 * for a particular subscription. 1479 * <p> 1480 * Availability: Only when user is registered to a network. Result may be 1481 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1482 * on a CDMA network). 1483 * @param subId 1484 * @hide 1485 */ 1486 public String getNetworkOperatorName(int subId) { 1487 int phoneId = SubscriptionManager.getPhoneId(subId); 1488 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, ""); 1489 } 1490 1491 /** 1492 * Returns the numeric name (MCC+MNC) of current registered operator. 1493 * <p> 1494 * Availability: Only when user is registered to a network. Result may be 1495 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1496 * on a CDMA network). 1497 */ 1498 public String getNetworkOperator() { 1499 return getNetworkOperatorForPhone(getDefaultPhone()); 1500 } 1501 1502 /** 1503 * Returns the numeric name (MCC+MNC) of current registered operator 1504 * for a particular subscription. 1505 * <p> 1506 * Availability: Only when user is registered to a network. Result may be 1507 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1508 * on a CDMA network). 1509 * 1510 * @param subId 1511 * @hide 1512 */ 1513 public String getNetworkOperator(int subId) { 1514 int phoneId = SubscriptionManager.getPhoneId(subId); 1515 return getNetworkOperatorForPhone(phoneId); 1516 } 1517 1518 /** 1519 * Returns the numeric name (MCC+MNC) of current registered operator 1520 * for a particular subscription. 1521 * <p> 1522 * Availability: Only when user is registered to a network. Result may be 1523 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1524 * on a CDMA network). 1525 * 1526 * @param phoneId 1527 * @hide 1528 **/ 1529 public String getNetworkOperatorForPhone(int phoneId) { 1530 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, ""); 1531 } 1532 1533 1534 /** 1535 * Returns the network specifier of the subscription ID pinned to the TelephonyManager. The 1536 * network specifier is used by {@link 1537 * android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to create a {@link 1538 * android.net.NetworkRequest} that connects through the subscription. 1539 * 1540 * @see android.net.NetworkRequest.Builder#setNetworkSpecifier(String) 1541 * @see #createForSubscriptionId(int) 1542 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 1543 */ 1544 public String getNetworkSpecifier() { 1545 return String.valueOf(mSubId); 1546 } 1547 1548 /** 1549 * Returns the carrier config of the subscription ID pinned to the TelephonyManager. If an 1550 * invalid subscription ID is pinned to the TelephonyManager, the returned config will contain 1551 * default values. 1552 * 1553 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE 1554 * READ_PHONE_STATE} 1555 * 1556 * @see CarrierConfigManager#getConfigForSubId(int) 1557 * @see #createForSubscriptionId(int) 1558 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 1559 */ 1560 @WorkerThread 1561 public PersistableBundle getCarrierConfig() { 1562 CarrierConfigManager carrierConfigManager = mContext 1563 .getSystemService(CarrierConfigManager.class); 1564 return carrierConfigManager.getConfigForSubId(mSubId); 1565 } 1566 1567 /** 1568 * Returns true if the device is considered roaming on the current 1569 * network, for GSM purposes. 1570 * <p> 1571 * Availability: Only when user registered to a network. 1572 */ 1573 public boolean isNetworkRoaming() { 1574 return isNetworkRoaming(getSubId()); 1575 } 1576 1577 /** 1578 * Returns true if the device is considered roaming on the current 1579 * network for a subscription. 1580 * <p> 1581 * Availability: Only when user registered to a network. 1582 * 1583 * @param subId 1584 * @hide 1585 */ 1586 public boolean isNetworkRoaming(int subId) { 1587 int phoneId = SubscriptionManager.getPhoneId(subId); 1588 return Boolean.parseBoolean(getTelephonyProperty(phoneId, 1589 TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, null)); 1590 } 1591 1592 /** 1593 * Returns the ISO country code equivalent of the current registered 1594 * operator's MCC (Mobile Country Code). 1595 * <p> 1596 * Availability: Only when user is registered to a network. Result may be 1597 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1598 * on a CDMA network). 1599 */ 1600 public String getNetworkCountryIso() { 1601 return getNetworkCountryIsoForPhone(getDefaultPhone()); 1602 } 1603 1604 /** 1605 * Returns the ISO country code equivalent of the current registered 1606 * operator's MCC (Mobile Country Code) of a subscription. 1607 * <p> 1608 * Availability: Only when user is registered to a network. Result may be 1609 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1610 * on a CDMA network). 1611 * 1612 * @param subId for which Network CountryIso is returned 1613 * @hide 1614 */ 1615 public String getNetworkCountryIso(int subId) { 1616 int phoneId = SubscriptionManager.getPhoneId(subId); 1617 return getNetworkCountryIsoForPhone(phoneId); 1618 } 1619 1620 /** 1621 * Returns the ISO country code equivalent of the current registered 1622 * operator's MCC (Mobile Country Code) of a subscription. 1623 * <p> 1624 * Availability: Only when user is registered to a network. Result may be 1625 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 1626 * on a CDMA network). 1627 * 1628 * @param phoneId for which Network CountryIso is returned 1629 */ 1630 /** {@hide} */ 1631 public String getNetworkCountryIsoForPhone(int phoneId) { 1632 return getTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, ""); 1633 } 1634 1635 /** Network type is unknown */ 1636 public static final int NETWORK_TYPE_UNKNOWN = 0; 1637 /** Current network is GPRS */ 1638 public static final int NETWORK_TYPE_GPRS = 1; 1639 /** Current network is EDGE */ 1640 public static final int NETWORK_TYPE_EDGE = 2; 1641 /** Current network is UMTS */ 1642 public static final int NETWORK_TYPE_UMTS = 3; 1643 /** Current network is CDMA: Either IS95A or IS95B*/ 1644 public static final int NETWORK_TYPE_CDMA = 4; 1645 /** Current network is EVDO revision 0*/ 1646 public static final int NETWORK_TYPE_EVDO_0 = 5; 1647 /** Current network is EVDO revision A*/ 1648 public static final int NETWORK_TYPE_EVDO_A = 6; 1649 /** Current network is 1xRTT*/ 1650 public static final int NETWORK_TYPE_1xRTT = 7; 1651 /** Current network is HSDPA */ 1652 public static final int NETWORK_TYPE_HSDPA = 8; 1653 /** Current network is HSUPA */ 1654 public static final int NETWORK_TYPE_HSUPA = 9; 1655 /** Current network is HSPA */ 1656 public static final int NETWORK_TYPE_HSPA = 10; 1657 /** Current network is iDen */ 1658 public static final int NETWORK_TYPE_IDEN = 11; 1659 /** Current network is EVDO revision B*/ 1660 public static final int NETWORK_TYPE_EVDO_B = 12; 1661 /** Current network is LTE */ 1662 public static final int NETWORK_TYPE_LTE = 13; 1663 /** Current network is eHRPD */ 1664 public static final int NETWORK_TYPE_EHRPD = 14; 1665 /** Current network is HSPA+ */ 1666 public static final int NETWORK_TYPE_HSPAP = 15; 1667 /** Current network is GSM */ 1668 public static final int NETWORK_TYPE_GSM = 16; 1669 /** Current network is TD_SCDMA */ 1670 public static final int NETWORK_TYPE_TD_SCDMA = 17; 1671 /** Current network is IWLAN */ 1672 public static final int NETWORK_TYPE_IWLAN = 18; 1673 /** Current network is LTE_CA {@hide} */ 1674 public static final int NETWORK_TYPE_LTE_CA = 19; 1675 /** 1676 * @return the NETWORK_TYPE_xxxx for current data connection. 1677 */ 1678 public int getNetworkType() { 1679 try { 1680 ITelephony telephony = getITelephony(); 1681 if (telephony != null) { 1682 return telephony.getNetworkType(); 1683 } else { 1684 // This can happen when the ITelephony interface is not up yet. 1685 return NETWORK_TYPE_UNKNOWN; 1686 } 1687 } catch(RemoteException ex) { 1688 // This shouldn't happen in the normal case 1689 return NETWORK_TYPE_UNKNOWN; 1690 } catch (NullPointerException ex) { 1691 // This could happen before phone restarts due to crashing 1692 return NETWORK_TYPE_UNKNOWN; 1693 } 1694 } 1695 1696 /** 1697 * Returns a constant indicating the radio technology (network type) 1698 * currently in use on the device for a subscription. 1699 * @return the network type 1700 * 1701 * @param subId for which network type is returned 1702 * 1703 * @see #NETWORK_TYPE_UNKNOWN 1704 * @see #NETWORK_TYPE_GPRS 1705 * @see #NETWORK_TYPE_EDGE 1706 * @see #NETWORK_TYPE_UMTS 1707 * @see #NETWORK_TYPE_HSDPA 1708 * @see #NETWORK_TYPE_HSUPA 1709 * @see #NETWORK_TYPE_HSPA 1710 * @see #NETWORK_TYPE_CDMA 1711 * @see #NETWORK_TYPE_EVDO_0 1712 * @see #NETWORK_TYPE_EVDO_A 1713 * @see #NETWORK_TYPE_EVDO_B 1714 * @see #NETWORK_TYPE_1xRTT 1715 * @see #NETWORK_TYPE_IDEN 1716 * @see #NETWORK_TYPE_LTE 1717 * @see #NETWORK_TYPE_EHRPD 1718 * @see #NETWORK_TYPE_HSPAP 1719 * 1720 * <p> 1721 * Requires Permission: 1722 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1723 * @hide 1724 */ 1725 public int getNetworkType(int subId) { 1726 try { 1727 ITelephony telephony = getITelephony(); 1728 if (telephony != null) { 1729 return telephony.getNetworkTypeForSubscriber(subId, getOpPackageName()); 1730 } else { 1731 // This can happen when the ITelephony interface is not up yet. 1732 return NETWORK_TYPE_UNKNOWN; 1733 } 1734 } catch(RemoteException ex) { 1735 // This shouldn't happen in the normal case 1736 return NETWORK_TYPE_UNKNOWN; 1737 } catch (NullPointerException ex) { 1738 // This could happen before phone restarts due to crashing 1739 return NETWORK_TYPE_UNKNOWN; 1740 } 1741 } 1742 1743 /** 1744 * Returns a constant indicating the radio technology (network type) 1745 * currently in use on the device for data transmission. 1746 * 1747 * <p> 1748 * Requires Permission: 1749 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1750 * 1751 * @return the network type 1752 * 1753 * @see #NETWORK_TYPE_UNKNOWN 1754 * @see #NETWORK_TYPE_GPRS 1755 * @see #NETWORK_TYPE_EDGE 1756 * @see #NETWORK_TYPE_UMTS 1757 * @see #NETWORK_TYPE_HSDPA 1758 * @see #NETWORK_TYPE_HSUPA 1759 * @see #NETWORK_TYPE_HSPA 1760 * @see #NETWORK_TYPE_CDMA 1761 * @see #NETWORK_TYPE_EVDO_0 1762 * @see #NETWORK_TYPE_EVDO_A 1763 * @see #NETWORK_TYPE_EVDO_B 1764 * @see #NETWORK_TYPE_1xRTT 1765 * @see #NETWORK_TYPE_IDEN 1766 * @see #NETWORK_TYPE_LTE 1767 * @see #NETWORK_TYPE_EHRPD 1768 * @see #NETWORK_TYPE_HSPAP 1769 */ 1770 public int getDataNetworkType() { 1771 return getDataNetworkType(getSubId()); 1772 } 1773 1774 /** 1775 * Returns a constant indicating the radio technology (network type) 1776 * currently in use on the device for data transmission for a subscription 1777 * @return the network type 1778 * 1779 * @param subId for which network type is returned 1780 * 1781 * <p> 1782 * Requires Permission: 1783 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1784 * @hide 1785 */ 1786 public int getDataNetworkType(int subId) { 1787 try{ 1788 ITelephony telephony = getITelephony(); 1789 if (telephony != null) { 1790 return telephony.getDataNetworkTypeForSubscriber(subId, getOpPackageName()); 1791 } else { 1792 // This can happen when the ITelephony interface is not up yet. 1793 return NETWORK_TYPE_UNKNOWN; 1794 } 1795 } catch(RemoteException ex) { 1796 // This shouldn't happen in the normal case 1797 return NETWORK_TYPE_UNKNOWN; 1798 } catch (NullPointerException ex) { 1799 // This could happen before phone restarts due to crashing 1800 return NETWORK_TYPE_UNKNOWN; 1801 } 1802 } 1803 1804 /** 1805 * Returns the NETWORK_TYPE_xxxx for voice 1806 * 1807 * <p> 1808 * Requires Permission: 1809 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1810 */ 1811 public int getVoiceNetworkType() { 1812 return getVoiceNetworkType(getSubId()); 1813 } 1814 1815 /** 1816 * Returns the NETWORK_TYPE_xxxx for voice for a subId 1817 * 1818 * <p> 1819 * Requires Permission: 1820 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 1821 * @hide 1822 */ 1823 public int getVoiceNetworkType(int subId) { 1824 try{ 1825 ITelephony telephony = getITelephony(); 1826 if (telephony != null) { 1827 return telephony.getVoiceNetworkTypeForSubscriber(subId, getOpPackageName()); 1828 } else { 1829 // This can happen when the ITelephony interface is not up yet. 1830 return NETWORK_TYPE_UNKNOWN; 1831 } 1832 } catch(RemoteException ex) { 1833 // This shouldn't happen in the normal case 1834 return NETWORK_TYPE_UNKNOWN; 1835 } catch (NullPointerException ex) { 1836 // This could happen before phone restarts due to crashing 1837 return NETWORK_TYPE_UNKNOWN; 1838 } 1839 } 1840 1841 /** 1842 * Network Class Definitions. 1843 * Do not change this order, it is used for sorting during emergency calling in 1844 * {@link TelephonyConnectionService#getFirstPhoneForEmergencyCall()}. Any newer technologies 1845 * should be added after the current definitions. 1846 */ 1847 /** Unknown network class. {@hide} */ 1848 public static final int NETWORK_CLASS_UNKNOWN = 0; 1849 /** Class of broadly defined "2G" networks. {@hide} */ 1850 public static final int NETWORK_CLASS_2_G = 1; 1851 /** Class of broadly defined "3G" networks. {@hide} */ 1852 public static final int NETWORK_CLASS_3_G = 2; 1853 /** Class of broadly defined "4G" networks. {@hide} */ 1854 public static final int NETWORK_CLASS_4_G = 3; 1855 1856 /** 1857 * Return general class of network type, such as "3G" or "4G". In cases 1858 * where classification is contentious, this method is conservative. 1859 * 1860 * @hide 1861 */ 1862 public static int getNetworkClass(int networkType) { 1863 switch (networkType) { 1864 case NETWORK_TYPE_GPRS: 1865 case NETWORK_TYPE_GSM: 1866 case NETWORK_TYPE_EDGE: 1867 case NETWORK_TYPE_CDMA: 1868 case NETWORK_TYPE_1xRTT: 1869 case NETWORK_TYPE_IDEN: 1870 return NETWORK_CLASS_2_G; 1871 case NETWORK_TYPE_UMTS: 1872 case NETWORK_TYPE_EVDO_0: 1873 case NETWORK_TYPE_EVDO_A: 1874 case NETWORK_TYPE_HSDPA: 1875 case NETWORK_TYPE_HSUPA: 1876 case NETWORK_TYPE_HSPA: 1877 case NETWORK_TYPE_EVDO_B: 1878 case NETWORK_TYPE_EHRPD: 1879 case NETWORK_TYPE_HSPAP: 1880 case NETWORK_TYPE_TD_SCDMA: 1881 return NETWORK_CLASS_3_G; 1882 case NETWORK_TYPE_LTE: 1883 case NETWORK_TYPE_IWLAN: 1884 case NETWORK_TYPE_LTE_CA: 1885 return NETWORK_CLASS_4_G; 1886 default: 1887 return NETWORK_CLASS_UNKNOWN; 1888 } 1889 } 1890 1891 /** 1892 * Returns a string representation of the radio technology (network type) 1893 * currently in use on the device. 1894 * @return the name of the radio technology 1895 * 1896 * @hide pending API council review 1897 */ 1898 public String getNetworkTypeName() { 1899 return getNetworkTypeName(getNetworkType()); 1900 } 1901 1902 /** 1903 * Returns a string representation of the radio technology (network type) 1904 * currently in use on the device. 1905 * @param subId for which network type is returned 1906 * @return the name of the radio technology 1907 * 1908 */ 1909 /** {@hide} */ 1910 public static String getNetworkTypeName(int type) { 1911 switch (type) { 1912 case NETWORK_TYPE_GPRS: 1913 return "GPRS"; 1914 case NETWORK_TYPE_EDGE: 1915 return "EDGE"; 1916 case NETWORK_TYPE_UMTS: 1917 return "UMTS"; 1918 case NETWORK_TYPE_HSDPA: 1919 return "HSDPA"; 1920 case NETWORK_TYPE_HSUPA: 1921 return "HSUPA"; 1922 case NETWORK_TYPE_HSPA: 1923 return "HSPA"; 1924 case NETWORK_TYPE_CDMA: 1925 return "CDMA"; 1926 case NETWORK_TYPE_EVDO_0: 1927 return "CDMA - EvDo rev. 0"; 1928 case NETWORK_TYPE_EVDO_A: 1929 return "CDMA - EvDo rev. A"; 1930 case NETWORK_TYPE_EVDO_B: 1931 return "CDMA - EvDo rev. B"; 1932 case NETWORK_TYPE_1xRTT: 1933 return "CDMA - 1xRTT"; 1934 case NETWORK_TYPE_LTE: 1935 return "LTE"; 1936 case NETWORK_TYPE_EHRPD: 1937 return "CDMA - eHRPD"; 1938 case NETWORK_TYPE_IDEN: 1939 return "iDEN"; 1940 case NETWORK_TYPE_HSPAP: 1941 return "HSPA+"; 1942 case NETWORK_TYPE_GSM: 1943 return "GSM"; 1944 case NETWORK_TYPE_TD_SCDMA: 1945 return "TD_SCDMA"; 1946 case NETWORK_TYPE_IWLAN: 1947 return "IWLAN"; 1948 case NETWORK_TYPE_LTE_CA: 1949 return "LTE_CA"; 1950 default: 1951 return "UNKNOWN"; 1952 } 1953 } 1954 1955 // 1956 // 1957 // SIM Card 1958 // 1959 // 1960 1961 /** 1962 * SIM card state: Unknown. Signifies that the SIM is in transition 1963 * between states. For example, when the user inputs the SIM pin 1964 * under PIN_REQUIRED state, a query for sim status returns 1965 * this state before turning to SIM_STATE_READY. 1966 * 1967 * These are the ordinal value of IccCardConstants.State. 1968 */ 1969 public static final int SIM_STATE_UNKNOWN = 0; 1970 /** SIM card state: no SIM card is available in the device */ 1971 public static final int SIM_STATE_ABSENT = 1; 1972 /** SIM card state: Locked: requires the user's SIM PIN to unlock */ 1973 public static final int SIM_STATE_PIN_REQUIRED = 2; 1974 /** SIM card state: Locked: requires the user's SIM PUK to unlock */ 1975 public static final int SIM_STATE_PUK_REQUIRED = 3; 1976 /** SIM card state: Locked: requires a network PIN to unlock */ 1977 public static final int SIM_STATE_NETWORK_LOCKED = 4; 1978 /** SIM card state: Ready */ 1979 public static final int SIM_STATE_READY = 5; 1980 /** SIM card state: SIM Card is NOT READY */ 1981 public static final int SIM_STATE_NOT_READY = 6; 1982 /** SIM card state: SIM Card Error, permanently disabled */ 1983 public static final int SIM_STATE_PERM_DISABLED = 7; 1984 /** SIM card state: SIM Card Error, present but faulty */ 1985 public static final int SIM_STATE_CARD_IO_ERROR = 8; 1986 /** SIM card state: SIM Card restricted, present but not usable due to 1987 * carrier restrictions. 1988 */ 1989 public static final int SIM_STATE_CARD_RESTRICTED = 9; 1990 1991 /** 1992 * @return true if a ICC card is present 1993 */ 1994 public boolean hasIccCard() { 1995 return hasIccCard(getDefaultSim()); 1996 } 1997 1998 /** 1999 * @return true if a ICC card is present for a subscription 2000 * 2001 * @param slotIndex for which icc card presence is checked 2002 */ 2003 /** {@hide} */ 2004 // FIXME Input argument slotIndex should be of type int 2005 public boolean hasIccCard(int slotIndex) { 2006 2007 try { 2008 ITelephony telephony = getITelephony(); 2009 if (telephony == null) 2010 return false; 2011 return telephony.hasIccCardUsingSlotIndex(slotIndex); 2012 } catch (RemoteException ex) { 2013 // Assume no ICC card if remote exception which shouldn't happen 2014 return false; 2015 } catch (NullPointerException ex) { 2016 // This could happen before phone restarts due to crashing 2017 return false; 2018 } 2019 } 2020 2021 /** 2022 * Returns a constant indicating the state of the default SIM card. 2023 * 2024 * @see #SIM_STATE_UNKNOWN 2025 * @see #SIM_STATE_ABSENT 2026 * @see #SIM_STATE_PIN_REQUIRED 2027 * @see #SIM_STATE_PUK_REQUIRED 2028 * @see #SIM_STATE_NETWORK_LOCKED 2029 * @see #SIM_STATE_READY 2030 * @see #SIM_STATE_NOT_READY 2031 * @see #SIM_STATE_PERM_DISABLED 2032 * @see #SIM_STATE_CARD_IO_ERROR 2033 * @see #SIM_STATE_CARD_RESTRICTED 2034 */ 2035 public int getSimState() { 2036 int slotIndex = getDefaultSim(); 2037 // slotIndex may be invalid due to sim being absent. In that case query all slots to get 2038 // sim state 2039 if (slotIndex < 0) { 2040 // query for all slots and return absent if all sim states are absent, otherwise 2041 // return unknown 2042 for (int i = 0; i < getPhoneCount(); i++) { 2043 int simState = getSimState(i); 2044 if (simState != SIM_STATE_ABSENT) { 2045 Rlog.d(TAG, "getSimState: default sim:" + slotIndex + ", sim state for " + 2046 "slotIndex=" + i + " is " + simState + ", return state as unknown"); 2047 return SIM_STATE_UNKNOWN; 2048 } 2049 } 2050 Rlog.d(TAG, "getSimState: default sim:" + slotIndex + ", all SIMs absent, return " + 2051 "state as absent"); 2052 return SIM_STATE_ABSENT; 2053 } 2054 return getSimState(slotIndex); 2055 } 2056 2057 /** 2058 * Returns a constant indicating the state of the device SIM card in a slot. 2059 * 2060 * @param slotIndex 2061 * 2062 * @see #SIM_STATE_UNKNOWN 2063 * @see #SIM_STATE_ABSENT 2064 * @see #SIM_STATE_PIN_REQUIRED 2065 * @see #SIM_STATE_PUK_REQUIRED 2066 * @see #SIM_STATE_NETWORK_LOCKED 2067 * @see #SIM_STATE_READY 2068 * @see #SIM_STATE_NOT_READY 2069 * @see #SIM_STATE_PERM_DISABLED 2070 * @see #SIM_STATE_CARD_IO_ERROR 2071 * @see #SIM_STATE_CARD_RESTRICTED 2072 */ 2073 public int getSimState(int slotIndex) { 2074 int simState = SubscriptionManager.getSimStateForSlotIndex(slotIndex); 2075 return simState; 2076 } 2077 2078 /** 2079 * Returns the MCC+MNC (mobile country code + mobile network code) of the 2080 * provider of the SIM. 5 or 6 decimal digits. 2081 * <p> 2082 * Availability: SIM state must be {@link #SIM_STATE_READY} 2083 * 2084 * @see #getSimState 2085 */ 2086 public String getSimOperator() { 2087 return getSimOperatorNumeric(); 2088 } 2089 2090 /** 2091 * Returns the MCC+MNC (mobile country code + mobile network code) of the 2092 * provider of the SIM. 5 or 6 decimal digits. 2093 * <p> 2094 * Availability: SIM state must be {@link #SIM_STATE_READY} 2095 * 2096 * @see #getSimState 2097 * 2098 * @param subId for which SimOperator is returned 2099 * @hide 2100 */ 2101 public String getSimOperator(int subId) { 2102 return getSimOperatorNumeric(subId); 2103 } 2104 2105 /** 2106 * Returns the MCC+MNC (mobile country code + mobile network code) of the 2107 * provider of the SIM. 5 or 6 decimal digits. 2108 * <p> 2109 * Availability: SIM state must be {@link #SIM_STATE_READY} 2110 * 2111 * @see #getSimState 2112 * @hide 2113 */ 2114 public String getSimOperatorNumeric() { 2115 int subId = SubscriptionManager.getDefaultDataSubscriptionId(); 2116 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 2117 subId = SubscriptionManager.getDefaultSmsSubscriptionId(); 2118 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 2119 subId = SubscriptionManager.getDefaultVoiceSubscriptionId(); 2120 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 2121 subId = SubscriptionManager.getDefaultSubscriptionId(); 2122 } 2123 } 2124 } 2125 return getSimOperatorNumeric(subId); 2126 } 2127 2128 /** 2129 * Returns the MCC+MNC (mobile country code + mobile network code) of the 2130 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 2131 * <p> 2132 * Availability: SIM state must be {@link #SIM_STATE_READY} 2133 * 2134 * @see #getSimState 2135 * 2136 * @param subId for which SimOperator is returned 2137 * @hide 2138 */ 2139 public String getSimOperatorNumeric(int subId) { 2140 int phoneId = SubscriptionManager.getPhoneId(subId); 2141 return getSimOperatorNumericForPhone(phoneId); 2142 } 2143 2144 /** 2145 * Returns the MCC+MNC (mobile country code + mobile network code) of the 2146 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 2147 * <p> 2148 * 2149 * @param phoneId for which SimOperator is returned 2150 * @hide 2151 */ 2152 public String getSimOperatorNumericForPhone(int phoneId) { 2153 return getTelephonyProperty(phoneId, 2154 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, ""); 2155 } 2156 2157 /** 2158 * Returns the Service Provider Name (SPN). 2159 * <p> 2160 * Availability: SIM state must be {@link #SIM_STATE_READY} 2161 * 2162 * @see #getSimState 2163 */ 2164 public String getSimOperatorName() { 2165 return getSimOperatorNameForPhone(getDefaultPhone()); 2166 } 2167 2168 /** 2169 * Returns the Service Provider Name (SPN). 2170 * <p> 2171 * Availability: SIM state must be {@link #SIM_STATE_READY} 2172 * 2173 * @see #getSimState 2174 * 2175 * @param subId for which SimOperatorName is returned 2176 * @hide 2177 */ 2178 public String getSimOperatorName(int subId) { 2179 int phoneId = SubscriptionManager.getPhoneId(subId); 2180 return getSimOperatorNameForPhone(phoneId); 2181 } 2182 2183 /** 2184 * Returns the Service Provider Name (SPN). 2185 * 2186 * @hide 2187 */ 2188 public String getSimOperatorNameForPhone(int phoneId) { 2189 return getTelephonyProperty(phoneId, 2190 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, ""); 2191 } 2192 2193 /** 2194 * Returns the ISO country code equivalent for the SIM provider's country code. 2195 */ 2196 public String getSimCountryIso() { 2197 return getSimCountryIsoForPhone(getDefaultPhone()); 2198 } 2199 2200 /** 2201 * Returns the ISO country code equivalent for the SIM provider's country code. 2202 * 2203 * @param subId for which SimCountryIso is returned 2204 * @hide 2205 */ 2206 public String getSimCountryIso(int subId) { 2207 int phoneId = SubscriptionManager.getPhoneId(subId); 2208 return getSimCountryIsoForPhone(phoneId); 2209 } 2210 2211 /** 2212 * Returns the ISO country code equivalent for the SIM provider's country code. 2213 * 2214 * @hide 2215 */ 2216 public String getSimCountryIsoForPhone(int phoneId) { 2217 return getTelephonyProperty(phoneId, 2218 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, ""); 2219 } 2220 2221 /** 2222 * Returns the serial number of the SIM, if applicable. Return null if it is 2223 * unavailable. 2224 * <p> 2225 * Requires Permission: 2226 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2227 */ 2228 public String getSimSerialNumber() { 2229 return getSimSerialNumber(getSubId()); 2230 } 2231 2232 /** 2233 * Returns the serial number for the given subscription, if applicable. Return null if it is 2234 * unavailable. 2235 * <p> 2236 * @param subId for which Sim Serial number is returned 2237 * Requires Permission: 2238 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2239 * @hide 2240 */ 2241 public String getSimSerialNumber(int subId) { 2242 try { 2243 IPhoneSubInfo info = getSubscriberInfo(); 2244 if (info == null) 2245 return null; 2246 return info.getIccSerialNumberForSubscriber(subId, mContext.getOpPackageName()); 2247 } catch (RemoteException ex) { 2248 return null; 2249 } catch (NullPointerException ex) { 2250 // This could happen before phone restarts due to crashing 2251 return null; 2252 } 2253 } 2254 2255 /** 2256 * Return if the current radio is LTE on CDMA. This 2257 * is a tri-state return value as for a period of time 2258 * the mode may be unknown. 2259 * 2260 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 2261 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 2262 * 2263 * <p> 2264 * Requires Permission: 2265 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2266 * 2267 * @hide 2268 */ 2269 public int getLteOnCdmaMode() { 2270 return getLteOnCdmaMode(getSubId()); 2271 } 2272 2273 /** 2274 * Return if the current radio is LTE on CDMA for Subscription. This 2275 * is a tri-state return value as for a period of time 2276 * the mode may be unknown. 2277 * 2278 * @param subId for which radio is LTE on CDMA is returned 2279 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 2280 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 2281 * 2282 * <p> 2283 * Requires Permission: 2284 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2285 * @hide 2286 */ 2287 public int getLteOnCdmaMode(int subId) { 2288 try { 2289 ITelephony telephony = getITelephony(); 2290 if (telephony == null) 2291 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 2292 return telephony.getLteOnCdmaModeForSubscriber(subId, getOpPackageName()); 2293 } catch (RemoteException ex) { 2294 // Assume no ICC card if remote exception which shouldn't happen 2295 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 2296 } catch (NullPointerException ex) { 2297 // This could happen before phone restarts due to crashing 2298 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 2299 } 2300 } 2301 2302 // 2303 // 2304 // Subscriber Info 2305 // 2306 // 2307 2308 /** 2309 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 2310 * Return null if it is unavailable. 2311 * <p> 2312 * Requires Permission: 2313 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2314 */ 2315 public String getSubscriberId() { 2316 return getSubscriberId(getSubId()); 2317 } 2318 2319 /** 2320 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone 2321 * for a subscription. 2322 * Return null if it is unavailable. 2323 * <p> 2324 * Requires Permission: 2325 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2326 * 2327 * @param subId whose subscriber id is returned 2328 * @hide 2329 */ 2330 public String getSubscriberId(int subId) { 2331 try { 2332 IPhoneSubInfo info = getSubscriberInfo(); 2333 if (info == null) 2334 return null; 2335 return info.getSubscriberIdForSubscriber(subId, mContext.getOpPackageName()); 2336 } catch (RemoteException ex) { 2337 return null; 2338 } catch (NullPointerException ex) { 2339 // This could happen before phone restarts due to crashing 2340 return null; 2341 } 2342 } 2343 2344 /** 2345 * Returns the Group Identifier Level1 for a GSM phone. 2346 * Return null if it is unavailable. 2347 * <p> 2348 * Requires Permission: 2349 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2350 */ 2351 public String getGroupIdLevel1() { 2352 try { 2353 IPhoneSubInfo info = getSubscriberInfo(); 2354 if (info == null) 2355 return null; 2356 return info.getGroupIdLevel1(mContext.getOpPackageName()); 2357 } catch (RemoteException ex) { 2358 return null; 2359 } catch (NullPointerException ex) { 2360 // This could happen before phone restarts due to crashing 2361 return null; 2362 } 2363 } 2364 2365 /** 2366 * Returns the Group Identifier Level1 for a GSM phone for a particular subscription. 2367 * Return null if it is unavailable. 2368 * <p> 2369 * Requires Permission: 2370 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2371 * 2372 * @param subId whose subscriber id is returned 2373 * @hide 2374 */ 2375 public String getGroupIdLevel1(int subId) { 2376 try { 2377 IPhoneSubInfo info = getSubscriberInfo(); 2378 if (info == null) 2379 return null; 2380 return info.getGroupIdLevel1ForSubscriber(subId, mContext.getOpPackageName()); 2381 } catch (RemoteException ex) { 2382 return null; 2383 } catch (NullPointerException ex) { 2384 // This could happen before phone restarts due to crashing 2385 return null; 2386 } 2387 } 2388 2389 /** 2390 * Returns the phone number string for line 1, for example, the MSISDN 2391 * for a GSM phone. Return null if it is unavailable. 2392 * <p> 2393 * Requires Permission: 2394 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2395 * OR 2396 * {@link android.Manifest.permission#READ_SMS} 2397 * OR 2398 * {@link android.Manifest.permission#READ_PHONE_NUMBER} 2399 * <p> 2400 * The default SMS app can also use this. 2401 */ 2402 public String getLine1Number() { 2403 return getLine1Number(getSubId()); 2404 } 2405 2406 /** 2407 * Returns the phone number string for line 1, for example, the MSISDN 2408 * for a GSM phone for a particular subscription. Return null if it is unavailable. 2409 * <p> 2410 * Requires Permission: 2411 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2412 * OR 2413 * {@link android.Manifest.permission#READ_SMS} 2414 * OR 2415 * {@link android.Manifest.permission#READ_PHONE_NUMBER} 2416 * <p> 2417 * The default SMS app can also use this. 2418 * 2419 * @param subId whose phone number for line 1 is returned 2420 * @hide 2421 */ 2422 public String getLine1Number(int subId) { 2423 String number = null; 2424 try { 2425 ITelephony telephony = getITelephony(); 2426 if (telephony != null) 2427 number = telephony.getLine1NumberForDisplay(subId, mContext.getOpPackageName()); 2428 } catch (RemoteException ex) { 2429 } catch (NullPointerException ex) { 2430 } 2431 if (number != null) { 2432 return number; 2433 } 2434 try { 2435 IPhoneSubInfo info = getSubscriberInfo(); 2436 if (info == null) 2437 return null; 2438 return info.getLine1NumberForSubscriber(subId, mContext.getOpPackageName()); 2439 } catch (RemoteException ex) { 2440 return null; 2441 } catch (NullPointerException ex) { 2442 // This could happen before phone restarts due to crashing 2443 return null; 2444 } 2445 } 2446 2447 /** 2448 * Set the line 1 phone number string and its alphatag for the current ICCID 2449 * for display purpose only, for example, displayed in Phone Status. It won't 2450 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 2451 * value. 2452 * 2453 * <p>Requires that the calling app has carrier privileges. 2454 * @see #hasCarrierPrivileges 2455 * 2456 * @param alphaTag alpha-tagging of the dailing nubmer 2457 * @param number The dialing number 2458 * @return true if the operation was executed correctly. 2459 */ 2460 public boolean setLine1NumberForDisplay(String alphaTag, String number) { 2461 return setLine1NumberForDisplay(getSubId(), alphaTag, number); 2462 } 2463 2464 /** 2465 * Set the line 1 phone number string and its alphatag for the current ICCID 2466 * for display purpose only, for example, displayed in Phone Status. It won't 2467 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 2468 * value. 2469 * 2470 * <p>Requires that the calling app has carrier privileges. 2471 * @see #hasCarrierPrivileges 2472 * 2473 * @param subId the subscriber that the alphatag and dialing number belongs to. 2474 * @param alphaTag alpha-tagging of the dailing nubmer 2475 * @param number The dialing number 2476 * @return true if the operation was executed correctly. 2477 * @hide 2478 */ 2479 public boolean setLine1NumberForDisplay(int subId, String alphaTag, String number) { 2480 try { 2481 ITelephony telephony = getITelephony(); 2482 if (telephony != null) 2483 return telephony.setLine1NumberForDisplayForSubscriber(subId, alphaTag, number); 2484 } catch (RemoteException ex) { 2485 } catch (NullPointerException ex) { 2486 } 2487 return false; 2488 } 2489 2490 /** 2491 * Returns the alphabetic identifier associated with the line 1 number. 2492 * Return null if it is unavailable. 2493 * <p> 2494 * Requires Permission: 2495 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2496 * @hide 2497 * nobody seems to call this. 2498 */ 2499 public String getLine1AlphaTag() { 2500 return getLine1AlphaTag(getSubId()); 2501 } 2502 2503 /** 2504 * Returns the alphabetic identifier associated with the line 1 number 2505 * for a subscription. 2506 * Return null if it is unavailable. 2507 * <p> 2508 * Requires Permission: 2509 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2510 * @param subId whose alphabetic identifier associated with line 1 is returned 2511 * nobody seems to call this. 2512 * @hide 2513 */ 2514 public String getLine1AlphaTag(int subId) { 2515 String alphaTag = null; 2516 try { 2517 ITelephony telephony = getITelephony(); 2518 if (telephony != null) 2519 alphaTag = telephony.getLine1AlphaTagForDisplay(subId, 2520 getOpPackageName()); 2521 } catch (RemoteException ex) { 2522 } catch (NullPointerException ex) { 2523 } 2524 if (alphaTag != null) { 2525 return alphaTag; 2526 } 2527 try { 2528 IPhoneSubInfo info = getSubscriberInfo(); 2529 if (info == null) 2530 return null; 2531 return info.getLine1AlphaTagForSubscriber(subId, getOpPackageName()); 2532 } catch (RemoteException ex) { 2533 return null; 2534 } catch (NullPointerException ex) { 2535 // This could happen before phone restarts due to crashing 2536 return null; 2537 } 2538 } 2539 2540 /** 2541 * Return the set of subscriber IDs that should be considered as "merged 2542 * together" for data usage purposes. This is commonly {@code null} to 2543 * indicate no merging is required. Any returned subscribers are sorted in a 2544 * deterministic order. 2545 * 2546 * @hide 2547 */ 2548 public @Nullable String[] getMergedSubscriberIds() { 2549 try { 2550 ITelephony telephony = getITelephony(); 2551 if (telephony != null) 2552 return telephony.getMergedSubscriberIds(getOpPackageName()); 2553 } catch (RemoteException ex) { 2554 } catch (NullPointerException ex) { 2555 } 2556 return null; 2557 } 2558 2559 /** 2560 * Returns the MSISDN string. 2561 * for a GSM phone. Return null if it is unavailable. 2562 * <p> 2563 * Requires Permission: 2564 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2565 * 2566 * @hide 2567 */ 2568 public String getMsisdn() { 2569 return getMsisdn(getSubId()); 2570 } 2571 2572 /** 2573 * Returns the MSISDN string. 2574 * for a GSM phone. Return null if it is unavailable. 2575 * <p> 2576 * Requires Permission: 2577 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2578 * 2579 * @param subId for which msisdn is returned 2580 * @hide 2581 */ 2582 public String getMsisdn(int subId) { 2583 try { 2584 IPhoneSubInfo info = getSubscriberInfo(); 2585 if (info == null) 2586 return null; 2587 return info.getMsisdnForSubscriber(subId, getOpPackageName()); 2588 } catch (RemoteException ex) { 2589 return null; 2590 } catch (NullPointerException ex) { 2591 // This could happen before phone restarts due to crashing 2592 return null; 2593 } 2594 } 2595 2596 /** 2597 * Returns the voice mail number. Return null if it is unavailable. 2598 * <p> 2599 * Requires Permission: 2600 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2601 */ 2602 public String getVoiceMailNumber() { 2603 return getVoiceMailNumber(getSubId()); 2604 } 2605 2606 /** 2607 * Returns the voice mail number for a subscription. 2608 * Return null if it is unavailable. 2609 * <p> 2610 * Requires Permission: 2611 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2612 * @param subId whose voice mail number is returned 2613 * @hide 2614 */ 2615 public String getVoiceMailNumber(int subId) { 2616 try { 2617 IPhoneSubInfo info = getSubscriberInfo(); 2618 if (info == null) 2619 return null; 2620 return info.getVoiceMailNumberForSubscriber(subId, getOpPackageName()); 2621 } catch (RemoteException ex) { 2622 return null; 2623 } catch (NullPointerException ex) { 2624 // This could happen before phone restarts due to crashing 2625 return null; 2626 } 2627 } 2628 2629 /** 2630 * Returns the complete voice mail number. Return null if it is unavailable. 2631 * <p> 2632 * Requires Permission: 2633 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 2634 * 2635 * @hide 2636 */ 2637 public String getCompleteVoiceMailNumber() { 2638 return getCompleteVoiceMailNumber(getSubId()); 2639 } 2640 2641 /** 2642 * Returns the complete voice mail number. Return null if it is unavailable. 2643 * <p> 2644 * Requires Permission: 2645 * {@link android.Manifest.permission#CALL_PRIVILEGED CALL_PRIVILEGED} 2646 * 2647 * @param subId 2648 * @hide 2649 */ 2650 public String getCompleteVoiceMailNumber(int subId) { 2651 try { 2652 IPhoneSubInfo info = getSubscriberInfo(); 2653 if (info == null) 2654 return null; 2655 return info.getCompleteVoiceMailNumberForSubscriber(subId); 2656 } catch (RemoteException ex) { 2657 return null; 2658 } catch (NullPointerException ex) { 2659 // This could happen before phone restarts due to crashing 2660 return null; 2661 } 2662 } 2663 2664 /** 2665 * Sets the voice mail number. 2666 * 2667 * <p>Requires that the calling app has carrier privileges. 2668 * @see #hasCarrierPrivileges 2669 * 2670 * @param alphaTag The alpha tag to display. 2671 * @param number The voicemail number. 2672 */ 2673 public boolean setVoiceMailNumber(String alphaTag, String number) { 2674 return setVoiceMailNumber(getSubId(), alphaTag, number); 2675 } 2676 2677 /** 2678 * Sets the voicemail number for the given subscriber. 2679 * 2680 * <p>Requires that the calling app has carrier privileges. 2681 * @see #hasCarrierPrivileges 2682 * 2683 * @param subId The subscription id. 2684 * @param alphaTag The alpha tag to display. 2685 * @param number The voicemail number. 2686 * @hide 2687 */ 2688 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { 2689 try { 2690 ITelephony telephony = getITelephony(); 2691 if (telephony != null) 2692 return telephony.setVoiceMailNumber(subId, alphaTag, number); 2693 } catch (RemoteException ex) { 2694 } catch (NullPointerException ex) { 2695 } 2696 return false; 2697 } 2698 2699 /** 2700 * Enables or disables the visual voicemail client for a phone account. 2701 * 2702 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or 2703 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 2704 * @see #hasCarrierPrivileges 2705 * 2706 * @param phoneAccountHandle the phone account to change the client state 2707 * @param enabled the new state of the client 2708 * @hide 2709 */ 2710 @SystemApi 2711 public void setVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled){ 2712 try { 2713 ITelephony telephony = getITelephony(); 2714 if (telephony != null) { 2715 telephony.setVisualVoicemailEnabled(mContext.getOpPackageName(), phoneAccountHandle, 2716 enabled); 2717 } 2718 } catch (RemoteException ex) { 2719 } catch (NullPointerException ex) { 2720 // This could happen before phone restarts due to crashing 2721 } 2722 } 2723 2724 /** 2725 * Returns whether the visual voicemail client is enabled. 2726 * 2727 * <p>Requires Permission: 2728 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2729 * 2730 * @param phoneAccountHandle the phone account to check for. 2731 * @return {@code true} when the visual voicemail client is enabled for this client 2732 * @hide 2733 */ 2734 @SystemApi 2735 public boolean isVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle){ 2736 try { 2737 ITelephony telephony = getITelephony(); 2738 if (telephony != null) { 2739 return telephony.isVisualVoicemailEnabled( 2740 mContext.getOpPackageName(), phoneAccountHandle); 2741 } 2742 } catch (RemoteException ex) { 2743 } catch (NullPointerException ex) { 2744 // This could happen before phone restarts due to crashing 2745 } 2746 return false; 2747 } 2748 2749 2750 /** 2751 * Returns the package responsible of processing visual voicemail for the subscription ID pinned 2752 * to the TelephonyManager. Returns {@code null} when there is no package responsible for 2753 * processing visual voicemail for the subscription. 2754 * 2755 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE 2756 * READ_PHONE_STATE} 2757 * 2758 * @see #createForSubscriptionId(int) 2759 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 2760 * @see VisualVoicemailService 2761 */ 2762 @Nullable 2763 public String getVisualVoicemailPackageName() { 2764 try { 2765 ITelephony telephony = getITelephony(); 2766 if (telephony != null) { 2767 return telephony 2768 .getVisualVoicemailPackageName(mContext.getOpPackageName(), mSubId); 2769 } 2770 } catch (RemoteException ex) { 2771 } catch (NullPointerException ex) { 2772 } 2773 return null; 2774 } 2775 2776 /** 2777 * Enables the visual voicemail SMS filter for a phone account. When the filter is 2778 * enabled, Incoming SMS messages matching the OMTP VVM SMS interface will be redirected to the 2779 * visual voicemail client with 2780 * {@link android.provider.VoicemailContract.ACTION_VOICEMAIL_SMS_RECEIVED}. 2781 * 2782 * <p>This takes effect only when the caller is the default dialer. The enabled status and 2783 * settings persist through default dialer changes, but the filter will only honor the setting 2784 * set by the current default dialer. 2785 * 2786 * 2787 * @param subId The subscription id of the phone account. 2788 * @param settings The settings for the filter. 2789 */ 2790 /** @hide */ 2791 public void enableVisualVoicemailSmsFilter(int subId, 2792 VisualVoicemailSmsFilterSettings settings) { 2793 if(settings == null){ 2794 throw new IllegalArgumentException("Settings cannot be null"); 2795 } 2796 try { 2797 ITelephony telephony = getITelephony(); 2798 if (telephony != null) { 2799 telephony.enableVisualVoicemailSmsFilter(mContext.getOpPackageName(), subId, 2800 settings); 2801 } 2802 } catch (RemoteException ex) { 2803 } catch (NullPointerException ex) { 2804 } 2805 } 2806 2807 /** 2808 * Disables the visual voicemail SMS filter for a phone account. 2809 * 2810 * <p>This takes effect only when the caller is the default dialer. The enabled status and 2811 * settings persist through default dialer changes, but the filter will only honor the setting 2812 * set by the current default dialer. 2813 */ 2814 /** @hide */ 2815 public void disableVisualVoicemailSmsFilter(int subId) { 2816 try { 2817 ITelephony telephony = getITelephony(); 2818 if (telephony != null) { 2819 telephony.disableVisualVoicemailSmsFilter(mContext.getOpPackageName(), subId); 2820 } 2821 } catch (RemoteException ex) { 2822 } catch (NullPointerException ex) { 2823 } 2824 } 2825 2826 /** 2827 * @returns the settings of the visual voicemail SMS filter for a phone account, or {@code null} 2828 * if the filter is disabled. 2829 * 2830 * <p>This takes effect only when the caller is the default dialer. The enabled status and 2831 * settings persist through default dialer changes, but the filter will only honor the setting 2832 * set by the current default dialer. 2833 */ 2834 /** @hide */ 2835 @Nullable 2836 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(int subId) { 2837 try { 2838 ITelephony telephony = getITelephony(); 2839 if (telephony != null) { 2840 return telephony 2841 .getVisualVoicemailSmsFilterSettings(mContext.getOpPackageName(), subId); 2842 } 2843 } catch (RemoteException ex) { 2844 } catch (NullPointerException ex) { 2845 } 2846 2847 return null; 2848 } 2849 2850 /** 2851 * @returns the settings of the visual voicemail SMS filter for a phone account set by the 2852 * current active visual voicemail client, or {@code null} if the filter is disabled. 2853 * 2854 * <p>Requires the calling app to have READ_PRIVILEGED_PHONE_STATE permission. 2855 */ 2856 /** @hide */ 2857 @Nullable 2858 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { 2859 try { 2860 ITelephony telephony = getITelephony(); 2861 if (telephony != null) { 2862 return telephony.getActiveVisualVoicemailSmsFilterSettings(subId); 2863 } 2864 } catch (RemoteException ex) { 2865 } catch (NullPointerException ex) { 2866 } 2867 2868 return null; 2869 } 2870 2871 /** 2872 * Send a visual voicemail SMS. The IPC caller must be the current default dialer. 2873 * 2874 * <p>Requires Permission: 2875 * {@link android.Manifest.permission#SEND_SMS SEND_SMS} 2876 * 2877 * @param phoneAccountHandle The account to send the SMS with. 2878 * @param number The destination number. 2879 * @param port The destination port for data SMS, or 0 for text SMS. 2880 * @param text The message content. For data sms, it will be encoded as a UTF-8 byte stream. 2881 * @param sentIntent The sent intent passed to the {@link SmsManager} 2882 * 2883 * @see SmsManager#sendDataMessage(String, String, short, byte[], PendingIntent, PendingIntent) 2884 * @see SmsManager#sendTextMessage(String, String, String, PendingIntent, PendingIntent) 2885 * 2886 * @hide 2887 */ 2888 public void sendVisualVoicemailSmsForSubscriber(int subId, String number, int port, 2889 String text, PendingIntent sentIntent) { 2890 try { 2891 ITelephony telephony = getITelephony(); 2892 if (telephony != null) { 2893 telephony.sendVisualVoicemailSmsForSubscriber( 2894 mContext.getOpPackageName(), subId, number, port, text, sentIntent); 2895 } 2896 } catch (RemoteException ex) { 2897 } 2898 } 2899 2900 /** 2901 * Initial SIM activation state, unknown. Not set by any carrier apps. 2902 * @hide 2903 */ 2904 public static final int SIM_ACTIVATION_STATE_UNKNOWN = 0; 2905 2906 /** 2907 * indicate SIM is under activation procedure now. 2908 * intermediate state followed by another state update with activation procedure result: 2909 * @see #SIM_ACTIVATION_STATE_ACTIVATED 2910 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 2911 * @see #SIM_ACTIVATION_STATE_RESTRICTED 2912 * @hide 2913 */ 2914 public static final int SIM_ACTIVATION_STATE_ACTIVATING = 1; 2915 2916 /** 2917 * Indicate SIM has been successfully activated with full service 2918 * @hide 2919 */ 2920 public static final int SIM_ACTIVATION_STATE_ACTIVATED = 2; 2921 2922 /** 2923 * Indicate SIM has been deactivated by the carrier so that service is not available 2924 * and requires activation service to enable services. 2925 * Carrier apps could be signalled to set activation state to deactivated if detected 2926 * deactivated sim state and set it back to activated after successfully run activation service. 2927 * @hide 2928 */ 2929 public static final int SIM_ACTIVATION_STATE_DEACTIVATED = 3; 2930 2931 /** 2932 * Restricted state indicate SIM has been activated but service are restricted. 2933 * note this is currently available for data activation state. For example out of byte sim. 2934 * @hide 2935 */ 2936 public static final int SIM_ACTIVATION_STATE_RESTRICTED = 4; 2937 2938 /** 2939 * Sets the voice activation state for the given subscriber. 2940 * 2941 * <p>Requires Permission: 2942 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 2943 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2944 * 2945 * @param subId The subscription id. 2946 * @param activationState The voice activation state of the given subscriber. 2947 * @see #SIM_ACTIVATION_STATE_UNKNOWN 2948 * @see #SIM_ACTIVATION_STATE_ACTIVATING 2949 * @see #SIM_ACTIVATION_STATE_ACTIVATED 2950 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 2951 * @hide 2952 */ 2953 public void setVoiceActivationState(int subId, int activationState) { 2954 try { 2955 ITelephony telephony = getITelephony(); 2956 if (telephony != null) 2957 telephony.setVoiceActivationState(subId, activationState); 2958 } catch (RemoteException ex) { 2959 } catch (NullPointerException ex) { 2960 } 2961 } 2962 2963 /** 2964 * Sets the data activation state for the given subscriber. 2965 * 2966 * <p>Requires Permission: 2967 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} 2968 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 2969 * 2970 * @param subId The subscription id. 2971 * @param activationState The data activation state of the given subscriber. 2972 * @see #SIM_ACTIVATION_STATE_UNKNOWN 2973 * @see #SIM_ACTIVATION_STATE_ACTIVATING 2974 * @see #SIM_ACTIVATION_STATE_ACTIVATED 2975 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 2976 * @see #SIM_ACTIVATION_STATE_RESTRICTED 2977 * @hide 2978 */ 2979 public void setDataActivationState(int subId, int activationState) { 2980 try { 2981 ITelephony telephony = getITelephony(); 2982 if (telephony != null) 2983 telephony.setDataActivationState(subId, activationState); 2984 } catch (RemoteException ex) { 2985 } catch (NullPointerException ex) { 2986 } 2987 } 2988 2989 /** 2990 * Returns the voice activation state for the given subscriber. 2991 * 2992 * <p>Requires Permission: 2993 * {@link android.Manifest.permission#READ_PHONE_STATE} 2994 * 2995 * @param subId The subscription id. 2996 * 2997 * @return voiceActivationState for the given subscriber 2998 * @see #SIM_ACTIVATION_STATE_UNKNOWN 2999 * @see #SIM_ACTIVATION_STATE_ACTIVATING 3000 * @see #SIM_ACTIVATION_STATE_ACTIVATED 3001 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 3002 * @hide 3003 */ 3004 public int getVoiceActivationState(int subId) { 3005 try { 3006 ITelephony telephony = getITelephony(); 3007 if (telephony != null) 3008 return telephony.getVoiceActivationState(subId, getOpPackageName()); 3009 } catch (RemoteException ex) { 3010 } catch (NullPointerException ex) { 3011 } 3012 return SIM_ACTIVATION_STATE_UNKNOWN; 3013 } 3014 3015 /** 3016 * Returns the data activation state for the given subscriber. 3017 * 3018 * <p>Requires Permission: 3019 * {@link android.Manifest.permission#READ_PHONE_STATE} 3020 * 3021 * @param subId The subscription id. 3022 * 3023 * @return dataActivationState for the given subscriber 3024 * @see #SIM_ACTIVATION_STATE_UNKNOWN 3025 * @see #SIM_ACTIVATION_STATE_ACTIVATING 3026 * @see #SIM_ACTIVATION_STATE_ACTIVATED 3027 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 3028 * @see #SIM_ACTIVATION_STATE_RESTRICTED 3029 * @hide 3030 */ 3031 public int getDataActivationState(int subId) { 3032 try { 3033 ITelephony telephony = getITelephony(); 3034 if (telephony != null) 3035 return telephony.getDataActivationState(subId, getOpPackageName()); 3036 } catch (RemoteException ex) { 3037 } catch (NullPointerException ex) { 3038 } 3039 return SIM_ACTIVATION_STATE_UNKNOWN; 3040 } 3041 3042 /** 3043 * Returns the voice mail count. Return 0 if unavailable, -1 if there are unread voice messages 3044 * but the count is unknown. 3045 * <p> 3046 * Requires Permission: 3047 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3048 * @hide 3049 */ 3050 public int getVoiceMessageCount() { 3051 return getVoiceMessageCount(getSubId()); 3052 } 3053 3054 /** 3055 * Returns the voice mail count for a subscription. Return 0 if unavailable. 3056 * <p> 3057 * Requires Permission: 3058 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3059 * @param subId whose voice message count is returned 3060 * @hide 3061 */ 3062 public int getVoiceMessageCount(int subId) { 3063 try { 3064 ITelephony telephony = getITelephony(); 3065 if (telephony == null) 3066 return 0; 3067 return telephony.getVoiceMessageCountForSubscriber(subId); 3068 } catch (RemoteException ex) { 3069 return 0; 3070 } catch (NullPointerException ex) { 3071 // This could happen before phone restarts due to crashing 3072 return 0; 3073 } 3074 } 3075 3076 /** 3077 * Retrieves the alphabetic identifier associated with the voice 3078 * mail number. 3079 * <p> 3080 * Requires Permission: 3081 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3082 */ 3083 public String getVoiceMailAlphaTag() { 3084 return getVoiceMailAlphaTag(getSubId()); 3085 } 3086 3087 /** 3088 * Retrieves the alphabetic identifier associated with the voice 3089 * mail number for a subscription. 3090 * <p> 3091 * Requires Permission: 3092 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3093 * @param subId whose alphabetic identifier associated with the 3094 * voice mail number is returned 3095 * @hide 3096 */ 3097 public String getVoiceMailAlphaTag(int subId) { 3098 try { 3099 IPhoneSubInfo info = getSubscriberInfo(); 3100 if (info == null) 3101 return null; 3102 return info.getVoiceMailAlphaTagForSubscriber(subId, getOpPackageName()); 3103 } catch (RemoteException ex) { 3104 return null; 3105 } catch (NullPointerException ex) { 3106 // This could happen before phone restarts due to crashing 3107 return null; 3108 } 3109 } 3110 3111 /** 3112 * Send the special dialer code. The IPC caller must be the current default dialer. 3113 * <p> 3114 * Requires Permission: 3115 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3116 * 3117 * @param inputCode The special dialer code to send which follows the format of *#*#<code>#*#* 3118 * @return true if sent sucessfully, false otherwise 3119 * @deprecated use {@link #sendDialerSpecialCode(String)} ()} instead. 3120 */ 3121 public boolean sendDialerCode(String inputCode) { 3122 try { 3123 final ITelephony telephony = getITelephony(); 3124 if (telephony == null) { 3125 Log.e(TAG, "Telephony service unavailable"); 3126 return false; 3127 } 3128 return telephony.sendDialerCode(mContext.getOpPackageName(), inputCode); 3129 } catch (RemoteException | NullPointerException ex) { 3130 // This could happen before phone restarts due to crashing 3131 return false; 3132 } 3133 } 3134 3135 /** 3136 * Send the special dialer code. The IPC caller must be the current default dialer or has 3137 * carrier privileges. 3138 * @see #hasCarrierPrivileges 3139 * 3140 * @param inputCode The special dialer code to send 3141 * 3142 * @throws SecurityException if the caller does not have carrier privileges or is not the 3143 * current default dialer 3144 * 3145 * @throws IllegalStateException if telephony service is unavailable. 3146 */ 3147 public void sendDialerSpecialCode(String inputCode) { 3148 try { 3149 final ITelephony telephony = getITelephony(); 3150 telephony.sendDialerSpecialCode(mContext.getOpPackageName(), inputCode); 3151 } catch (RemoteException ex) { 3152 // This could happen if binder process crashes. 3153 ex.rethrowFromSystemServer(); 3154 } catch (NullPointerException ex) { 3155 // This could happen before phone restarts due to crashing 3156 throw new IllegalStateException("Telephony service unavailable"); 3157 } 3158 } 3159 3160 /** 3161 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 3162 * @return the IMPI, or null if not present or not loaded 3163 * @hide 3164 */ 3165 public String getIsimImpi() { 3166 try { 3167 IPhoneSubInfo info = getSubscriberInfo(); 3168 if (info == null) 3169 return null; 3170 return info.getIsimImpi(); 3171 } catch (RemoteException ex) { 3172 return null; 3173 } catch (NullPointerException ex) { 3174 // This could happen before phone restarts due to crashing 3175 return null; 3176 } 3177 } 3178 3179 /** 3180 * Returns the IMS home network domain name that was loaded from the ISIM. 3181 * @return the IMS domain name, or null if not present or not loaded 3182 * @hide 3183 */ 3184 public String getIsimDomain() { 3185 try { 3186 IPhoneSubInfo info = getSubscriberInfo(); 3187 if (info == null) 3188 return null; 3189 return info.getIsimDomain(); 3190 } catch (RemoteException ex) { 3191 return null; 3192 } catch (NullPointerException ex) { 3193 // This could happen before phone restarts due to crashing 3194 return null; 3195 } 3196 } 3197 3198 /** 3199 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 3200 * @return an array of IMPU strings, with one IMPU per string, or null if 3201 * not present or not loaded 3202 * @hide 3203 */ 3204 public String[] getIsimImpu() { 3205 try { 3206 IPhoneSubInfo info = getSubscriberInfo(); 3207 if (info == null) 3208 return null; 3209 return info.getIsimImpu(); 3210 } catch (RemoteException ex) { 3211 return null; 3212 } catch (NullPointerException ex) { 3213 // This could happen before phone restarts due to crashing 3214 return null; 3215 } 3216 } 3217 3218 /** 3219 * @hide 3220 */ 3221 private IPhoneSubInfo getSubscriberInfo() { 3222 // get it each time because that process crashes a lot 3223 return IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo")); 3224 } 3225 3226 /** Device call state: No activity. */ 3227 public static final int CALL_STATE_IDLE = 0; 3228 /** Device call state: Ringing. A new call arrived and is 3229 * ringing or waiting. In the latter case, another call is 3230 * already active. */ 3231 public static final int CALL_STATE_RINGING = 1; 3232 /** Device call state: Off-hook. At least one call exists 3233 * that is dialing, active, or on hold, and no calls are ringing 3234 * or waiting. */ 3235 public static final int CALL_STATE_OFFHOOK = 2; 3236 3237 /** 3238 * Returns one of the following constants that represents the current state of all 3239 * phone calls. 3240 * 3241 * {@link TelephonyManager#CALL_STATE_RINGING} 3242 * {@link TelephonyManager#CALL_STATE_OFFHOOK} 3243 * {@link TelephonyManager#CALL_STATE_IDLE} 3244 */ 3245 public int getCallState() { 3246 try { 3247 ITelecomService telecom = getTelecomService(); 3248 if (telecom != null) { 3249 return telecom.getCallState(); 3250 } 3251 } catch (RemoteException e) { 3252 Log.e(TAG, "Error calling ITelecomService#getCallState", e); 3253 } 3254 return CALL_STATE_IDLE; 3255 } 3256 3257 /** 3258 * Returns a constant indicating the call state (cellular) on the device 3259 * for a subscription. 3260 * 3261 * @param subId whose call state is returned 3262 * @hide 3263 */ 3264 public int getCallState(int subId) { 3265 int phoneId = SubscriptionManager.getPhoneId(subId); 3266 return getCallStateForSlot(phoneId); 3267 } 3268 3269 /** 3270 * See getCallState. 3271 * 3272 * @hide 3273 */ 3274 public int getCallStateForSlot(int slotIndex) { 3275 try { 3276 ITelephony telephony = getITelephony(); 3277 if (telephony == null) 3278 return CALL_STATE_IDLE; 3279 return telephony.getCallStateForSlot(slotIndex); 3280 } catch (RemoteException ex) { 3281 // the phone process is restarting. 3282 return CALL_STATE_IDLE; 3283 } catch (NullPointerException ex) { 3284 // the phone process is restarting. 3285 return CALL_STATE_IDLE; 3286 } 3287 } 3288 3289 3290 /** Data connection activity: No traffic. */ 3291 public static final int DATA_ACTIVITY_NONE = 0x00000000; 3292 /** Data connection activity: Currently receiving IP PPP traffic. */ 3293 public static final int DATA_ACTIVITY_IN = 0x00000001; 3294 /** Data connection activity: Currently sending IP PPP traffic. */ 3295 public static final int DATA_ACTIVITY_OUT = 0x00000002; 3296 /** Data connection activity: Currently both sending and receiving 3297 * IP PPP traffic. */ 3298 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 3299 /** 3300 * Data connection is active, but physical link is down 3301 */ 3302 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 3303 3304 /** 3305 * Returns a constant indicating the type of activity on a data connection 3306 * (cellular). 3307 * 3308 * @see #DATA_ACTIVITY_NONE 3309 * @see #DATA_ACTIVITY_IN 3310 * @see #DATA_ACTIVITY_OUT 3311 * @see #DATA_ACTIVITY_INOUT 3312 * @see #DATA_ACTIVITY_DORMANT 3313 */ 3314 public int getDataActivity() { 3315 try { 3316 ITelephony telephony = getITelephony(); 3317 if (telephony == null) 3318 return DATA_ACTIVITY_NONE; 3319 return telephony.getDataActivity(); 3320 } catch (RemoteException ex) { 3321 // the phone process is restarting. 3322 return DATA_ACTIVITY_NONE; 3323 } catch (NullPointerException ex) { 3324 // the phone process is restarting. 3325 return DATA_ACTIVITY_NONE; 3326 } 3327 } 3328 3329 /** Data connection state: Unknown. Used before we know the state. 3330 * @hide 3331 */ 3332 public static final int DATA_UNKNOWN = -1; 3333 /** Data connection state: Disconnected. IP traffic not available. */ 3334 public static final int DATA_DISCONNECTED = 0; 3335 /** Data connection state: Currently setting up a data connection. */ 3336 public static final int DATA_CONNECTING = 1; 3337 /** Data connection state: Connected. IP traffic should be available. */ 3338 public static final int DATA_CONNECTED = 2; 3339 /** Data connection state: Suspended. The connection is up, but IP 3340 * traffic is temporarily unavailable. For example, in a 2G network, 3341 * data activity may be suspended when a voice call arrives. */ 3342 public static final int DATA_SUSPENDED = 3; 3343 3344 /** 3345 * Returns a constant indicating the current data connection state 3346 * (cellular). 3347 * 3348 * @see #DATA_DISCONNECTED 3349 * @see #DATA_CONNECTING 3350 * @see #DATA_CONNECTED 3351 * @see #DATA_SUSPENDED 3352 */ 3353 public int getDataState() { 3354 try { 3355 ITelephony telephony = getITelephony(); 3356 if (telephony == null) 3357 return DATA_DISCONNECTED; 3358 return telephony.getDataState(); 3359 } catch (RemoteException ex) { 3360 // the phone process is restarting. 3361 return DATA_DISCONNECTED; 3362 } catch (NullPointerException ex) { 3363 return DATA_DISCONNECTED; 3364 } 3365 } 3366 3367 /** 3368 * @hide 3369 */ 3370 private ITelephony getITelephony() { 3371 return ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); 3372 } 3373 3374 /** 3375 * @hide 3376 */ 3377 private ITelecomService getTelecomService() { 3378 return ITelecomService.Stub.asInterface(ServiceManager.getService(Context.TELECOM_SERVICE)); 3379 } 3380 3381 // 3382 // 3383 // PhoneStateListener 3384 // 3385 // 3386 3387 /** 3388 * Registers a listener object to receive notification of changes 3389 * in specified telephony states. 3390 * <p> 3391 * To register a listener, pass a {@link PhoneStateListener} 3392 * and specify at least one telephony state of interest in 3393 * the events argument. 3394 * 3395 * At registration, and when a specified telephony state 3396 * changes, the telephony manager invokes the appropriate 3397 * callback method on the listener object and passes the 3398 * current (updated) values. 3399 * <p> 3400 * To unregister a listener, pass the listener object and set the 3401 * events argument to 3402 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 3403 * 3404 * @param listener The {@link PhoneStateListener} object to register 3405 * (or unregister) 3406 * @param events The telephony state(s) of interest to the listener, 3407 * as a bitwise-OR combination of {@link PhoneStateListener} 3408 * LISTEN_ flags. 3409 */ 3410 public void listen(PhoneStateListener listener, int events) { 3411 if (mContext == null) return; 3412 try { 3413 boolean notifyNow = (getITelephony() != null); 3414 // If the listener has not explicitly set the subId (for example, created with the 3415 // default constructor), replace the subId so it will listen to the account the 3416 // telephony manager is created with. 3417 if (listener.mSubId == null) { 3418 listener.mSubId = mSubId; 3419 } 3420 sRegistry.listenForSubscriber(listener.mSubId, getOpPackageName(), 3421 listener.callback, events, notifyNow); 3422 } catch (RemoteException ex) { 3423 // system process dead 3424 } catch (NullPointerException ex) { 3425 // system process dead 3426 } 3427 } 3428 3429 /** 3430 * Returns the CDMA ERI icon index to display 3431 * 3432 * <p> 3433 * Requires Permission: 3434 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3435 * @hide 3436 */ 3437 public int getCdmaEriIconIndex() { 3438 return getCdmaEriIconIndex(getSubId()); 3439 } 3440 3441 /** 3442 * Returns the CDMA ERI icon index to display for a subscription 3443 * <p> 3444 * Requires Permission: 3445 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3446 * @hide 3447 */ 3448 public int getCdmaEriIconIndex(int subId) { 3449 try { 3450 ITelephony telephony = getITelephony(); 3451 if (telephony == null) 3452 return -1; 3453 return telephony.getCdmaEriIconIndexForSubscriber(subId, getOpPackageName()); 3454 } catch (RemoteException ex) { 3455 // the phone process is restarting. 3456 return -1; 3457 } catch (NullPointerException ex) { 3458 return -1; 3459 } 3460 } 3461 3462 /** 3463 * Returns the CDMA ERI icon mode, 3464 * 0 - ON 3465 * 1 - FLASHING 3466 * 3467 * <p> 3468 * Requires Permission: 3469 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3470 * @hide 3471 */ 3472 public int getCdmaEriIconMode() { 3473 return getCdmaEriIconMode(getSubId()); 3474 } 3475 3476 /** 3477 * Returns the CDMA ERI icon mode for a subscription. 3478 * 0 - ON 3479 * 1 - FLASHING 3480 * 3481 * <p> 3482 * Requires Permission: 3483 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3484 * @hide 3485 */ 3486 public int getCdmaEriIconMode(int subId) { 3487 try { 3488 ITelephony telephony = getITelephony(); 3489 if (telephony == null) 3490 return -1; 3491 return telephony.getCdmaEriIconModeForSubscriber(subId, getOpPackageName()); 3492 } catch (RemoteException ex) { 3493 // the phone process is restarting. 3494 return -1; 3495 } catch (NullPointerException ex) { 3496 return -1; 3497 } 3498 } 3499 3500 /** 3501 * Returns the CDMA ERI text, 3502 * 3503 * <p> 3504 * Requires Permission: 3505 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3506 * @hide 3507 */ 3508 public String getCdmaEriText() { 3509 return getCdmaEriText(getSubId()); 3510 } 3511 3512 /** 3513 * Returns the CDMA ERI text, of a subscription 3514 * 3515 * <p> 3516 * Requires Permission: 3517 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3518 * @hide 3519 */ 3520 public String getCdmaEriText(int subId) { 3521 try { 3522 ITelephony telephony = getITelephony(); 3523 if (telephony == null) 3524 return null; 3525 return telephony.getCdmaEriTextForSubscriber(subId, getOpPackageName()); 3526 } catch (RemoteException ex) { 3527 // the phone process is restarting. 3528 return null; 3529 } catch (NullPointerException ex) { 3530 return null; 3531 } 3532 } 3533 3534 /** 3535 * @return true if the current device is "voice capable". 3536 * <p> 3537 * "Voice capable" means that this device supports circuit-switched 3538 * (i.e. voice) phone calls over the telephony network, and is allowed 3539 * to display the in-call UI while a cellular voice call is active. 3540 * This will be false on "data only" devices which can't make voice 3541 * calls and don't support any in-call UI. 3542 * <p> 3543 * Note: the meaning of this flag is subtly different from the 3544 * PackageManager.FEATURE_TELEPHONY system feature, which is available 3545 * on any device with a telephony radio, even if the device is 3546 * data-only. 3547 */ 3548 public boolean isVoiceCapable() { 3549 if (mContext == null) return true; 3550 return mContext.getResources().getBoolean( 3551 com.android.internal.R.bool.config_voice_capable); 3552 } 3553 3554 /** 3555 * @return true if the current device supports sms service. 3556 * <p> 3557 * If true, this means that the device supports both sending and 3558 * receiving sms via the telephony network. 3559 * <p> 3560 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 3561 * disabled when device doesn't support sms. 3562 */ 3563 public boolean isSmsCapable() { 3564 if (mContext == null) return true; 3565 return mContext.getResources().getBoolean( 3566 com.android.internal.R.bool.config_sms_capable); 3567 } 3568 3569 /** 3570 * Returns all observed cell information from all radios on the 3571 * device including the primary and neighboring cells. Calling this method does 3572 * not trigger a call to {@link android.telephony.PhoneStateListener#onCellInfoChanged 3573 * onCellInfoChanged()}, or change the rate at which 3574 * {@link android.telephony.PhoneStateListener#onCellInfoChanged 3575 * onCellInfoChanged()} is called. 3576 * 3577 *<p> 3578 * The list can include one or more {@link android.telephony.CellInfoGsm CellInfoGsm}, 3579 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 3580 * {@link android.telephony.CellInfoLte CellInfoLte}, and 3581 * {@link android.telephony.CellInfoWcdma CellInfoWcdma} objects, in any combination. 3582 * On devices with multiple radios it is typical to see instances of 3583 * one or more of any these in the list. In addition, zero, one, or more 3584 * of the returned objects may be considered registered; that is, their 3585 * {@link android.telephony.CellInfo#isRegistered CellInfo.isRegistered()} 3586 * methods may return true. 3587 * 3588 * <p>This method returns valid data for registered cells on devices with 3589 * {@link android.content.pm.PackageManager#FEATURE_TELEPHONY}. In cases where only 3590 * partial information is available for a particular CellInfo entry, unavailable fields 3591 * will be reported as Integer.MAX_VALUE. All reported cells will include at least a 3592 * valid set of technology-specific identification info and a power level measurement. 3593 * 3594 *<p> 3595 * This method is preferred over using {@link 3596 * android.telephony.TelephonyManager#getCellLocation getCellLocation()}. 3597 * However, for older devices, <code>getAllCellInfo()</code> may return 3598 * null. In these cases, you should call {@link 3599 * android.telephony.TelephonyManager#getCellLocation getCellLocation()} 3600 * instead. 3601 * 3602 * <p>Requires permission: 3603 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} 3604 * 3605 * @return List of {@link android.telephony.CellInfo}; null if cell 3606 * information is unavailable. 3607 * 3608 */ 3609 public List<CellInfo> getAllCellInfo() { 3610 try { 3611 ITelephony telephony = getITelephony(); 3612 if (telephony == null) 3613 return null; 3614 return telephony.getAllCellInfo(getOpPackageName()); 3615 } catch (RemoteException ex) { 3616 return null; 3617 } catch (NullPointerException ex) { 3618 return null; 3619 } 3620 } 3621 3622 /** 3623 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 3624 * PhoneStateListener.onCellInfoChanged} will be invoked. 3625 *<p> 3626 * The default, 0, means invoke onCellInfoChanged when any of the reported 3627 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 3628 * A onCellInfoChanged. 3629 *<p> 3630 * @param rateInMillis the rate 3631 * 3632 * @hide 3633 */ 3634 public void setCellInfoListRate(int rateInMillis) { 3635 try { 3636 ITelephony telephony = getITelephony(); 3637 if (telephony != null) 3638 telephony.setCellInfoListRate(rateInMillis); 3639 } catch (RemoteException ex) { 3640 } catch (NullPointerException ex) { 3641 } 3642 } 3643 3644 /** 3645 * Returns the MMS user agent. 3646 */ 3647 public String getMmsUserAgent() { 3648 if (mContext == null) return null; 3649 return mContext.getResources().getString( 3650 com.android.internal.R.string.config_mms_user_agent); 3651 } 3652 3653 /** 3654 * Returns the MMS user agent profile URL. 3655 */ 3656 public String getMmsUAProfUrl() { 3657 if (mContext == null) return null; 3658 return mContext.getResources().getString( 3659 com.android.internal.R.string.config_mms_user_agent_profile_url); 3660 } 3661 3662 /** 3663 * Opens a logical channel to the ICC card. 3664 * 3665 * Input parameters equivalent to TS 27.007 AT+CCHO command. 3666 * 3667 * <p>Requires Permission: 3668 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3669 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3670 * 3671 * @param AID Application id. See ETSI 102.221 and 101.220. 3672 * @return an IccOpenLogicalChannelResponse object. 3673 */ 3674 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { 3675 return iccOpenLogicalChannel(getSubId(), AID); 3676 } 3677 3678 /** 3679 * Opens a logical channel to the ICC card. 3680 * 3681 * Input parameters equivalent to TS 27.007 AT+CCHO command. 3682 * 3683 * <p>Requires Permission: 3684 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3685 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3686 * 3687 * @param subId The subscription to use. 3688 * @param AID Application id. See ETSI 102.221 and 101.220. 3689 * @return an IccOpenLogicalChannelResponse object. 3690 * @hide 3691 */ 3692 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID) { 3693 try { 3694 ITelephony telephony = getITelephony(); 3695 if (telephony != null) 3696 return telephony.iccOpenLogicalChannel(subId, AID); 3697 } catch (RemoteException ex) { 3698 } catch (NullPointerException ex) { 3699 } 3700 return null; 3701 } 3702 3703 /** 3704 * Closes a previously opened logical channel to the ICC card. 3705 * 3706 * Input parameters equivalent to TS 27.007 AT+CCHC command. 3707 * 3708 * <p>Requires Permission: 3709 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3710 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3711 * 3712 * @param channel is the channel id to be closed as retruned by a successful 3713 * iccOpenLogicalChannel. 3714 * @return true if the channel was closed successfully. 3715 */ 3716 public boolean iccCloseLogicalChannel(int channel) { 3717 return iccCloseLogicalChannel(getSubId(), channel); 3718 } 3719 3720 /** 3721 * Closes a previously opened logical channel to the ICC card. 3722 * 3723 * Input parameters equivalent to TS 27.007 AT+CCHC command. 3724 * 3725 * <p>Requires Permission: 3726 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3727 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3728 * 3729 * @param subId The subscription to use. 3730 * @param channel is the channel id to be closed as retruned by a successful 3731 * iccOpenLogicalChannel. 3732 * @return true if the channel was closed successfully. 3733 * @hide 3734 */ 3735 public boolean iccCloseLogicalChannel(int subId, int channel) { 3736 try { 3737 ITelephony telephony = getITelephony(); 3738 if (telephony != null) 3739 return telephony.iccCloseLogicalChannel(subId, channel); 3740 } catch (RemoteException ex) { 3741 } catch (NullPointerException ex) { 3742 } 3743 return false; 3744 } 3745 3746 /** 3747 * Transmit an APDU to the ICC card over a logical channel. 3748 * 3749 * Input parameters equivalent to TS 27.007 AT+CGLA command. 3750 * 3751 * <p>Requires Permission: 3752 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3753 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3754 * 3755 * @param channel is the channel id to be closed as returned by a successful 3756 * iccOpenLogicalChannel. 3757 * @param cla Class of the APDU command. 3758 * @param instruction Instruction of the APDU command. 3759 * @param p1 P1 value of the APDU command. 3760 * @param p2 P2 value of the APDU command. 3761 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 3762 * is sent to the SIM. 3763 * @param data Data to be sent with the APDU. 3764 * @return The APDU response from the ICC card with the status appended at 3765 * the end. 3766 */ 3767 public String iccTransmitApduLogicalChannel(int channel, int cla, 3768 int instruction, int p1, int p2, int p3, String data) { 3769 return iccTransmitApduLogicalChannel(getSubId(), channel, cla, 3770 instruction, p1, p2, p3, data); 3771 } 3772 3773 /** 3774 * Transmit an APDU to the ICC card over a logical channel. 3775 * 3776 * Input parameters equivalent to TS 27.007 AT+CGLA command. 3777 * 3778 * <p>Requires Permission: 3779 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3780 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3781 * 3782 * @param subId The subscription to use. 3783 * @param channel is the channel id to be closed as returned by a successful 3784 * iccOpenLogicalChannel. 3785 * @param cla Class of the APDU command. 3786 * @param instruction Instruction of the APDU command. 3787 * @param p1 P1 value of the APDU command. 3788 * @param p2 P2 value of the APDU command. 3789 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 3790 * is sent to the SIM. 3791 * @param data Data to be sent with the APDU. 3792 * @return The APDU response from the ICC card with the status appended at 3793 * the end. 3794 * @hide 3795 */ 3796 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, 3797 int instruction, int p1, int p2, int p3, String data) { 3798 try { 3799 ITelephony telephony = getITelephony(); 3800 if (telephony != null) 3801 return telephony.iccTransmitApduLogicalChannel(subId, channel, cla, 3802 instruction, p1, p2, p3, data); 3803 } catch (RemoteException ex) { 3804 } catch (NullPointerException ex) { 3805 } 3806 return ""; 3807 } 3808 3809 /** 3810 * Transmit an APDU to the ICC card over the basic channel. 3811 * 3812 * Input parameters equivalent to TS 27.007 AT+CSIM command. 3813 * 3814 * <p>Requires Permission: 3815 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3816 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3817 * 3818 * @param cla Class of the APDU command. 3819 * @param instruction Instruction of the APDU command. 3820 * @param p1 P1 value of the APDU command. 3821 * @param p2 P2 value of the APDU command. 3822 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 3823 * is sent to the SIM. 3824 * @param data Data to be sent with the APDU. 3825 * @return The APDU response from the ICC card with the status appended at 3826 * the end. 3827 */ 3828 public String iccTransmitApduBasicChannel(int cla, 3829 int instruction, int p1, int p2, int p3, String data) { 3830 return iccTransmitApduBasicChannel(getSubId(), cla, 3831 instruction, p1, p2, p3, data); 3832 } 3833 3834 /** 3835 * Transmit an APDU to the ICC card over the basic channel. 3836 * 3837 * Input parameters equivalent to TS 27.007 AT+CSIM command. 3838 * 3839 * <p>Requires Permission: 3840 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3841 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3842 * 3843 * @param subId The subscription to use. 3844 * @param cla Class of the APDU command. 3845 * @param instruction Instruction of the APDU command. 3846 * @param p1 P1 value of the APDU command. 3847 * @param p2 P2 value of the APDU command. 3848 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 3849 * is sent to the SIM. 3850 * @param data Data to be sent with the APDU. 3851 * @return The APDU response from the ICC card with the status appended at 3852 * the end. 3853 * @hide 3854 */ 3855 public String iccTransmitApduBasicChannel(int subId, int cla, 3856 int instruction, int p1, int p2, int p3, String data) { 3857 try { 3858 ITelephony telephony = getITelephony(); 3859 if (telephony != null) 3860 return telephony.iccTransmitApduBasicChannel(subId, cla, 3861 instruction, p1, p2, p3, data); 3862 } catch (RemoteException ex) { 3863 } catch (NullPointerException ex) { 3864 } 3865 return ""; 3866 } 3867 3868 /** 3869 * Returns the response APDU for a command APDU sent through SIM_IO. 3870 * 3871 * <p>Requires Permission: 3872 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3873 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3874 * 3875 * @param fileID 3876 * @param command 3877 * @param p1 P1 value of the APDU command. 3878 * @param p2 P2 value of the APDU command. 3879 * @param p3 P3 value of the APDU command. 3880 * @param filePath 3881 * @return The APDU response. 3882 */ 3883 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 3884 String filePath) { 3885 return iccExchangeSimIO(getSubId(), fileID, command, p1, p2, p3, filePath); 3886 } 3887 3888 /** 3889 * Returns the response APDU for a command APDU sent through SIM_IO. 3890 * 3891 * <p>Requires Permission: 3892 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3893 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3894 * 3895 * @param subId The subscription to use. 3896 * @param fileID 3897 * @param command 3898 * @param p1 P1 value of the APDU command. 3899 * @param p2 P2 value of the APDU command. 3900 * @param p3 P3 value of the APDU command. 3901 * @param filePath 3902 * @return The APDU response. 3903 * @hide 3904 */ 3905 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, 3906 int p3, String filePath) { 3907 try { 3908 ITelephony telephony = getITelephony(); 3909 if (telephony != null) 3910 return telephony.iccExchangeSimIO(subId, fileID, command, p1, p2, p3, filePath); 3911 } catch (RemoteException ex) { 3912 } catch (NullPointerException ex) { 3913 } 3914 return null; 3915 } 3916 3917 /** 3918 * Send ENVELOPE to the SIM and return the response. 3919 * 3920 * <p>Requires Permission: 3921 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3922 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3923 * 3924 * @param content String containing SAT/USAT response in hexadecimal 3925 * format starting with command tag. See TS 102 223 for 3926 * details. 3927 * @return The APDU response from the ICC card in hexadecimal format 3928 * with the last 4 bytes being the status word. If the command fails, 3929 * returns an empty string. 3930 */ 3931 public String sendEnvelopeWithStatus(String content) { 3932 return sendEnvelopeWithStatus(getSubId(), content); 3933 } 3934 3935 /** 3936 * Send ENVELOPE to the SIM and return the response. 3937 * 3938 * <p>Requires Permission: 3939 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3940 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3941 * 3942 * @param subId The subscription to use. 3943 * @param content String containing SAT/USAT response in hexadecimal 3944 * format starting with command tag. See TS 102 223 for 3945 * details. 3946 * @return The APDU response from the ICC card in hexadecimal format 3947 * with the last 4 bytes being the status word. If the command fails, 3948 * returns an empty string. 3949 * @hide 3950 */ 3951 public String sendEnvelopeWithStatus(int subId, String content) { 3952 try { 3953 ITelephony telephony = getITelephony(); 3954 if (telephony != null) 3955 return telephony.sendEnvelopeWithStatus(subId, content); 3956 } catch (RemoteException ex) { 3957 } catch (NullPointerException ex) { 3958 } 3959 return ""; 3960 } 3961 3962 /** 3963 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 3964 * Used for device configuration by some CDMA operators. 3965 * <p> 3966 * Requires Permission: 3967 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3968 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3969 * 3970 * @param itemID the ID of the item to read. 3971 * @return the NV item as a String, or null on any failure. 3972 * 3973 * @hide 3974 */ 3975 public String nvReadItem(int itemID) { 3976 try { 3977 ITelephony telephony = getITelephony(); 3978 if (telephony != null) 3979 return telephony.nvReadItem(itemID); 3980 } catch (RemoteException ex) { 3981 Rlog.e(TAG, "nvReadItem RemoteException", ex); 3982 } catch (NullPointerException ex) { 3983 Rlog.e(TAG, "nvReadItem NPE", ex); 3984 } 3985 return ""; 3986 } 3987 3988 /** 3989 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 3990 * Used for device configuration by some CDMA operators. 3991 * <p> 3992 * Requires Permission: 3993 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 3994 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 3995 * 3996 * @param itemID the ID of the item to read. 3997 * @param itemValue the value to write, as a String. 3998 * @return true on success; false on any failure. 3999 * 4000 * @hide 4001 */ 4002 public boolean nvWriteItem(int itemID, String itemValue) { 4003 try { 4004 ITelephony telephony = getITelephony(); 4005 if (telephony != null) 4006 return telephony.nvWriteItem(itemID, itemValue); 4007 } catch (RemoteException ex) { 4008 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 4009 } catch (NullPointerException ex) { 4010 Rlog.e(TAG, "nvWriteItem NPE", ex); 4011 } 4012 return false; 4013 } 4014 4015 /** 4016 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 4017 * Used for device configuration by some CDMA operators. 4018 * <p> 4019 * Requires Permission: 4020 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 4021 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 4022 * 4023 * @param preferredRoamingList byte array containing the new PRL. 4024 * @return true on success; false on any failure. 4025 * 4026 * @hide 4027 */ 4028 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 4029 try { 4030 ITelephony telephony = getITelephony(); 4031 if (telephony != null) 4032 return telephony.nvWriteCdmaPrl(preferredRoamingList); 4033 } catch (RemoteException ex) { 4034 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 4035 } catch (NullPointerException ex) { 4036 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 4037 } 4038 return false; 4039 } 4040 4041 /** 4042 * Perform the specified type of NV config reset. The radio will be taken offline 4043 * and the device must be rebooted after the operation. Used for device 4044 * configuration by some CDMA operators. 4045 * <p> 4046 * Requires Permission: 4047 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 4048 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 4049 * 4050 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 4051 * @return true on success; false on any failure. 4052 * 4053 * @hide 4054 */ 4055 public boolean nvResetConfig(int resetType) { 4056 try { 4057 ITelephony telephony = getITelephony(); 4058 if (telephony != null) 4059 return telephony.nvResetConfig(resetType); 4060 } catch (RemoteException ex) { 4061 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 4062 } catch (NullPointerException ex) { 4063 Rlog.e(TAG, "nvResetConfig NPE", ex); 4064 } 4065 return false; 4066 } 4067 4068 /** 4069 * Return an appropriate subscription ID for any situation. 4070 * 4071 * If this object has been created with {@link #createForSubscriptionId}, then the provided 4072 * subId is returned. Otherwise, the default subId will be returned. 4073 */ 4074 private int getSubId() { 4075 if (mSubId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { 4076 return getDefaultSubscription(); 4077 } 4078 return mSubId; 4079 } 4080 4081 /** 4082 * Returns Default subscription. 4083 */ 4084 private static int getDefaultSubscription() { 4085 return SubscriptionManager.getDefaultSubscriptionId(); 4086 } 4087 4088 /** 4089 * Returns Default phone. 4090 */ 4091 private static int getDefaultPhone() { 4092 return SubscriptionManager.getPhoneId(SubscriptionManager.getDefaultSubscriptionId()); 4093 } 4094 4095 /** 4096 * @return default SIM's slot index. If SIM is not inserted, return default SIM slot index. 4097 * 4098 * {@hide} 4099 */ 4100 @VisibleForTesting 4101 public int getDefaultSim() { 4102 int slotIndex = SubscriptionManager.getSlotIndex( 4103 SubscriptionManager.getDefaultSubscriptionId()); 4104 if (slotIndex == SubscriptionManager.SIM_NOT_INSERTED) { 4105 slotIndex = SubscriptionManager.DEFAULT_SIM_SLOT_INDEX; 4106 } 4107 return slotIndex; 4108 } 4109 4110 /** 4111 * Sets the telephony property with the value specified. 4112 * 4113 * @hide 4114 */ 4115 public static void setTelephonyProperty(int phoneId, String property, String value) { 4116 String propVal = ""; 4117 String p[] = null; 4118 String prop = SystemProperties.get(property); 4119 4120 if (value == null) { 4121 value = ""; 4122 } 4123 4124 if (prop != null) { 4125 p = prop.split(","); 4126 } 4127 4128 if (!SubscriptionManager.isValidPhoneId(phoneId)) { 4129 Rlog.d(TAG, "setTelephonyProperty: invalid phoneId=" + phoneId + 4130 " property=" + property + " value: " + value + " prop=" + prop); 4131 return; 4132 } 4133 4134 for (int i = 0; i < phoneId; i++) { 4135 String str = ""; 4136 if ((p != null) && (i < p.length)) { 4137 str = p[i]; 4138 } 4139 propVal = propVal + str + ","; 4140 } 4141 4142 propVal = propVal + value; 4143 if (p != null) { 4144 for (int i = phoneId + 1; i < p.length; i++) { 4145 propVal = propVal + "," + p[i]; 4146 } 4147 } 4148 4149 if (propVal.length() > SystemProperties.PROP_VALUE_MAX) { 4150 Rlog.d(TAG, "setTelephonyProperty: property too long phoneId=" + phoneId + 4151 " property=" + property + " value: " + value + " propVal=" + propVal); 4152 return; 4153 } 4154 4155 Rlog.d(TAG, "setTelephonyProperty: success phoneId=" + phoneId + 4156 " property=" + property + " value: " + value + " propVal=" + propVal); 4157 SystemProperties.set(property, propVal); 4158 } 4159 4160 /** 4161 * Convenience function for retrieving a value from the secure settings 4162 * value list as an integer. Note that internally setting values are 4163 * always stored as strings; this function converts the string to an 4164 * integer for you. 4165 * <p> 4166 * This version does not take a default value. If the setting has not 4167 * been set, or the string value is not a number, 4168 * it throws {@link SettingNotFoundException}. 4169 * 4170 * @param cr The ContentResolver to access. 4171 * @param name The name of the setting to retrieve. 4172 * @param index The index of the list 4173 * 4174 * @throws SettingNotFoundException Thrown if a setting by the given 4175 * name can't be found or the setting value is not an integer. 4176 * 4177 * @return The value at the given index of settings. 4178 * @hide 4179 */ 4180 public static int getIntAtIndex(android.content.ContentResolver cr, 4181 String name, int index) 4182 throws android.provider.Settings.SettingNotFoundException { 4183 String v = android.provider.Settings.Global.getString(cr, name); 4184 if (v != null) { 4185 String valArray[] = v.split(","); 4186 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 4187 try { 4188 return Integer.parseInt(valArray[index]); 4189 } catch (NumberFormatException e) { 4190 //Log.e(TAG, "Exception while parsing Integer: ", e); 4191 } 4192 } 4193 } 4194 throw new android.provider.Settings.SettingNotFoundException(name); 4195 } 4196 4197 /** 4198 * Convenience function for updating settings value as coma separated 4199 * integer values. This will either create a new entry in the table if the 4200 * given name does not exist, or modify the value of the existing row 4201 * with that name. Note that internally setting values are always 4202 * stored as strings, so this function converts the given value to a 4203 * string before storing it. 4204 * 4205 * @param cr The ContentResolver to access. 4206 * @param name The name of the setting to modify. 4207 * @param index The index of the list 4208 * @param value The new value for the setting to be added to the list. 4209 * @return true if the value was set, false on database errors 4210 * @hide 4211 */ 4212 public static boolean putIntAtIndex(android.content.ContentResolver cr, 4213 String name, int index, int value) { 4214 String data = ""; 4215 String valArray[] = null; 4216 String v = android.provider.Settings.Global.getString(cr, name); 4217 4218 if (index == Integer.MAX_VALUE) { 4219 throw new RuntimeException("putIntAtIndex index == MAX_VALUE index=" + index); 4220 } 4221 if (index < 0) { 4222 throw new RuntimeException("putIntAtIndex index < 0 index=" + index); 4223 } 4224 if (v != null) { 4225 valArray = v.split(","); 4226 } 4227 4228 // Copy the elements from valArray till index 4229 for (int i = 0; i < index; i++) { 4230 String str = ""; 4231 if ((valArray != null) && (i < valArray.length)) { 4232 str = valArray[i]; 4233 } 4234 data = data + str + ","; 4235 } 4236 4237 data = data + value; 4238 4239 // Copy the remaining elements from valArray if any. 4240 if (valArray != null) { 4241 for (int i = index+1; i < valArray.length; i++) { 4242 data = data + "," + valArray[i]; 4243 } 4244 } 4245 return android.provider.Settings.Global.putString(cr, name, data); 4246 } 4247 4248 /** 4249 * Gets the telephony property. 4250 * 4251 * @hide 4252 */ 4253 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 4254 String propVal = null; 4255 String prop = SystemProperties.get(property); 4256 if ((prop != null) && (prop.length() > 0)) { 4257 String values[] = prop.split(","); 4258 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 4259 propVal = values[phoneId]; 4260 } 4261 } 4262 return propVal == null ? defaultVal : propVal; 4263 } 4264 4265 /** @hide */ 4266 public int getSimCount() { 4267 // FIXME Need to get it from Telephony Dev Controller when that gets implemented! 4268 // and then this method shouldn't be used at all! 4269 if(isMultiSimEnabled()) { 4270 return 2; 4271 } else { 4272 return 1; 4273 } 4274 } 4275 4276 /** 4277 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 4278 * @return IMS Service Table or null if not present or not loaded 4279 * @hide 4280 */ 4281 public String getIsimIst() { 4282 try { 4283 IPhoneSubInfo info = getSubscriberInfo(); 4284 if (info == null) 4285 return null; 4286 return info.getIsimIst(); 4287 } catch (RemoteException ex) { 4288 return null; 4289 } catch (NullPointerException ex) { 4290 // This could happen before phone restarts due to crashing 4291 return null; 4292 } 4293 } 4294 4295 /** 4296 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 4297 * @return an array of PCSCF strings with one PCSCF per string, or null if 4298 * not present or not loaded 4299 * @hide 4300 */ 4301 public String[] getIsimPcscf() { 4302 try { 4303 IPhoneSubInfo info = getSubscriberInfo(); 4304 if (info == null) 4305 return null; 4306 return info.getIsimPcscf(); 4307 } catch (RemoteException ex) { 4308 return null; 4309 } catch (NullPointerException ex) { 4310 // This could happen before phone restarts due to crashing 4311 return null; 4312 } 4313 } 4314 4315 /** 4316 * Returns the response of ISIM Authetification through RIL. 4317 * Returns null if the Authentification hasn't been successed or isn't present iphonesubinfo. 4318 * @return the response of ISIM Authetification, or null if not available 4319 * @hide 4320 * @deprecated 4321 * @see getIccAuthentication with appType=PhoneConstants.APPTYPE_ISIM 4322 */ 4323 public String getIsimChallengeResponse(String nonce){ 4324 try { 4325 IPhoneSubInfo info = getSubscriberInfo(); 4326 if (info == null) 4327 return null; 4328 return info.getIsimChallengeResponse(nonce); 4329 } catch (RemoteException ex) { 4330 return null; 4331 } catch (NullPointerException ex) { 4332 // This could happen before phone restarts due to crashing 4333 return null; 4334 } 4335 } 4336 4337 // ICC SIM Application Types 4338 /** UICC application type is SIM */ 4339 public static final int APPTYPE_SIM = PhoneConstants.APPTYPE_SIM; 4340 /** UICC application type is USIM */ 4341 public static final int APPTYPE_USIM = PhoneConstants.APPTYPE_USIM; 4342 /** UICC application type is RUIM */ 4343 public static final int APPTYPE_RUIM = PhoneConstants.APPTYPE_RUIM; 4344 /** UICC application type is CSIM */ 4345 public static final int APPTYPE_CSIM = PhoneConstants.APPTYPE_CSIM; 4346 /** UICC application type is ISIM */ 4347 public static final int APPTYPE_ISIM = PhoneConstants.APPTYPE_ISIM; 4348 // authContext (parameter P2) when doing UICC challenge, 4349 // per 3GPP TS 31.102 (Section 7.1.2) 4350 /** Authentication type for UICC challenge is EAP SIM. See RFC 4186 for details. */ 4351 public static final int AUTHTYPE_EAP_SIM = PhoneConstants.AUTH_CONTEXT_EAP_SIM; 4352 /** Authentication type for UICC challenge is EAP AKA. See RFC 4187 for details. */ 4353 public static final int AUTHTYPE_EAP_AKA = PhoneConstants.AUTH_CONTEXT_EAP_AKA; 4354 4355 /** 4356 * Returns the response of authentication for the default subscription. 4357 * Returns null if the authentication hasn't been successful 4358 * 4359 * <p>Requires that the calling app has carrier privileges or READ_PRIVILEGED_PHONE_STATE 4360 * permission. 4361 * 4362 * @param appType the icc application type, like {@link #APPTYPE_USIM} 4363 * @param authType the authentication type, {@link #AUTHTYPE_EAP_AKA} or 4364 * {@link #AUTHTYPE_EAP_SIM} 4365 * @param data authentication challenge data, base64 encoded. 4366 * See 3GPP TS 31.102 7.1.2 for more details. 4367 * @return the response of authentication, or null if not available 4368 * 4369 * @see #hasCarrierPrivileges 4370 */ 4371 public String getIccAuthentication(int appType, int authType, String data) { 4372 return getIccAuthentication(getSubId(), appType, authType, data); 4373 } 4374 4375 /** 4376 * Returns the response of USIM Authentication for specified subId. 4377 * Returns null if the authentication hasn't been successful 4378 * 4379 * <p>Requires that the calling app has carrier privileges. 4380 * 4381 * @param subId subscription ID used for authentication 4382 * @param appType the icc application type, like {@link #APPTYPE_USIM} 4383 * @param authType the authentication type, {@link #AUTHTYPE_EAP_AKA} or 4384 * {@link #AUTHTYPE_EAP_SIM} 4385 * @param data authentication challenge data, base64 encoded. 4386 * See 3GPP TS 31.102 7.1.2 for more details. 4387 * @return the response of authentication, or null if not available 4388 * 4389 * @see #hasCarrierPrivileges 4390 * @hide 4391 */ 4392 public String getIccAuthentication(int subId, int appType, int authType, String data) { 4393 try { 4394 IPhoneSubInfo info = getSubscriberInfo(); 4395 if (info == null) 4396 return null; 4397 return info.getIccSimChallengeResponse(subId, appType, authType, data); 4398 } catch (RemoteException ex) { 4399 return null; 4400 } catch (NullPointerException ex) { 4401 // This could happen before phone starts 4402 return null; 4403 } 4404 } 4405 4406 /** 4407 * Returns an array of Forbidden PLMNs from the USIM App 4408 * Returns null if the query fails. 4409 * 4410 * 4411 * <p>Requires that the caller has READ_PRIVILEGED_PHONE_STATE 4412 * 4413 * @return an array of forbidden PLMNs or null if not available 4414 */ 4415 public String[] getForbiddenPlmns() { 4416 return getForbiddenPlmns(getSubId(), APPTYPE_USIM); 4417 } 4418 4419 /** 4420 * Returns an array of Forbidden PLMNs from the specified SIM App 4421 * Returns null if the query fails. 4422 * 4423 * 4424 * <p>Requires that the calling app has READ_PRIVILEGED_PHONE_STATE 4425 * 4426 * @param subId subscription ID used for authentication 4427 * @param appType the icc application type, like {@link #APPTYPE_USIM} 4428 * @return fplmns an array of forbidden PLMNs 4429 * @hide 4430 */ 4431 public String[] getForbiddenPlmns(int subId, int appType) { 4432 try { 4433 ITelephony telephony = getITelephony(); 4434 if (telephony == null) 4435 return null; 4436 return telephony.getForbiddenPlmns(subId, appType); 4437 } catch (RemoteException ex) { 4438 return null; 4439 } catch (NullPointerException ex) { 4440 // This could happen before phone starts 4441 return null; 4442 } 4443 } 4444 4445 /** 4446 * Get P-CSCF address from PCO after data connection is established or modified. 4447 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 4448 * @return array of P-CSCF address 4449 * @hide 4450 */ 4451 public String[] getPcscfAddress(String apnType) { 4452 try { 4453 ITelephony telephony = getITelephony(); 4454 if (telephony == null) 4455 return new String[0]; 4456 return telephony.getPcscfAddress(apnType, getOpPackageName()); 4457 } catch (RemoteException e) { 4458 return new String[0]; 4459 } 4460 } 4461 4462 /** @hide */ 4463 @IntDef({ImsFeature.EMERGENCY_MMTEL, ImsFeature.MMTEL, ImsFeature.RCS}) 4464 @Retention(RetentionPolicy.SOURCE) 4465 public @interface Feature {} 4466 4467 /** 4468 * Returns the {@link IImsServiceController} that corresponds to the given slot Id and IMS 4469 * feature or {@link null} if the service is not available. If an ImsServiceController is 4470 * available, the {@link IImsServiceFeatureListener} callback is registered as a listener for 4471 * feature updates. 4472 * @param slotIndex The SIM slot that we are requesting the {@link IImsServiceController} for. 4473 * @param feature The IMS Feature we are requesting, corresponding to {@link ImsFeature}. 4474 * @param callback Listener that will send updates to ImsManager when there are updates to 4475 * ImsServiceController. 4476 * @return {@link IImsServiceController} interface for the feature specified or {@link null} if 4477 * it is unavailable. 4478 * @hide 4479 */ 4480 public IImsServiceController getImsServiceControllerAndListen(int slotIndex, @Feature int feature, 4481 IImsServiceFeatureListener callback) { 4482 try { 4483 ITelephony telephony = getITelephony(); 4484 if (telephony != null) { 4485 return telephony.getImsServiceControllerAndListen(slotIndex, feature, callback); 4486 } 4487 } catch (RemoteException e) { 4488 Rlog.e(TAG, "getImsServiceControllerAndListen, RemoteException: " + e.getMessage()); 4489 } 4490 return null; 4491 } 4492 4493 /** 4494 * Set IMS registration state 4495 * 4496 * @param Registration state 4497 * @hide 4498 */ 4499 public void setImsRegistrationState(boolean registered) { 4500 try { 4501 ITelephony telephony = getITelephony(); 4502 if (telephony != null) 4503 telephony.setImsRegistrationState(registered); 4504 } catch (RemoteException e) { 4505 } 4506 } 4507 4508 /** 4509 * Get the preferred network type. 4510 * Used for device configuration by some CDMA operators. 4511 * <p> 4512 * Requires Permission: 4513 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 4514 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 4515 * 4516 * @return the preferred network type, defined in RILConstants.java. 4517 * @hide 4518 */ 4519 public int getPreferredNetworkType(int subId) { 4520 try { 4521 ITelephony telephony = getITelephony(); 4522 if (telephony != null) 4523 return telephony.getPreferredNetworkType(subId); 4524 } catch (RemoteException ex) { 4525 Rlog.e(TAG, "getPreferredNetworkType RemoteException", ex); 4526 } catch (NullPointerException ex) { 4527 Rlog.e(TAG, "getPreferredNetworkType NPE", ex); 4528 } 4529 return -1; 4530 } 4531 4532 /** 4533 * Sets the network selection mode to automatic. 4534 * <p> 4535 * Requires Permission: 4536 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 4537 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 4538 * 4539 * @hide 4540 * TODO: Add an overload that takes no args. 4541 */ 4542 public void setNetworkSelectionModeAutomatic(int subId) { 4543 try { 4544 ITelephony telephony = getITelephony(); 4545 if (telephony != null) 4546 telephony.setNetworkSelectionModeAutomatic(subId); 4547 } catch (RemoteException ex) { 4548 Rlog.e(TAG, "setNetworkSelectionModeAutomatic RemoteException", ex); 4549 } catch (NullPointerException ex) { 4550 Rlog.e(TAG, "setNetworkSelectionModeAutomatic NPE", ex); 4551 } 4552 } 4553 4554 /** 4555 * Perform a radio scan and return the list of avialble networks. 4556 * 4557 * The return value is a list of the OperatorInfo of the networks found. Note that this 4558 * scan can take a long time (sometimes minutes) to happen. 4559 * 4560 * <p> 4561 * Requires Permission: 4562 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 4563 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 4564 * 4565 * @hide 4566 * TODO: Add an overload that takes no args. 4567 */ 4568 public CellNetworkScanResult getCellNetworkScanResults(int subId) { 4569 try { 4570 ITelephony telephony = getITelephony(); 4571 if (telephony != null) 4572 return telephony.getCellNetworkScanResults(subId); 4573 } catch (RemoteException ex) { 4574 Rlog.e(TAG, "getCellNetworkScanResults RemoteException", ex); 4575 } catch (NullPointerException ex) { 4576 Rlog.e(TAG, "getCellNetworkScanResults NPE", ex); 4577 } 4578 return null; 4579 } 4580 4581 /** 4582 * Ask the radio to connect to the input network and change selection mode to manual. 4583 * 4584 * <p> 4585 * Requires Permission: 4586 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 4587 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 4588 * 4589 * @hide 4590 * TODO: Add an overload that takes no args. 4591 */ 4592 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator, 4593 boolean persistSelection) { 4594 try { 4595 ITelephony telephony = getITelephony(); 4596 if (telephony != null) 4597 return telephony.setNetworkSelectionModeManual(subId, operator, persistSelection); 4598 } catch (RemoteException ex) { 4599 Rlog.e(TAG, "setNetworkSelectionModeManual RemoteException", ex); 4600 } catch (NullPointerException ex) { 4601 Rlog.e(TAG, "setNetworkSelectionModeManual NPE", ex); 4602 } 4603 return false; 4604 } 4605 4606 /** 4607 * Set the preferred network type. 4608 * Used for device configuration by some CDMA operators. 4609 * <p> 4610 * Requires Permission: 4611 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 4612 * Or the calling app has carrier privileges. @see #hasCarrierPrivileges 4613 * 4614 * @param subId the id of the subscription to set the preferred network type for. 4615 * @param networkType the preferred network type, defined in RILConstants.java. 4616 * @return true on success; false on any failure. 4617 * @hide 4618 */ 4619 public boolean setPreferredNetworkType(int subId, int networkType) { 4620 try { 4621 ITelephony telephony = getITelephony(); 4622 if (telephony != null) 4623 return telephony.setPreferredNetworkType(subId, networkType); 4624 } catch (RemoteException ex) { 4625 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 4626 } catch (NullPointerException ex) { 4627 Rlog.e(TAG, "setPreferredNetworkType NPE", ex); 4628 } 4629 return false; 4630 } 4631 4632 /** 4633 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 4634 * 4635 * <p> 4636 * Requires that the calling app has carrier privileges. 4637 * @see #hasCarrierPrivileges 4638 * 4639 * @return true on success; false on any failure. 4640 */ 4641 public boolean setPreferredNetworkTypeToGlobal() { 4642 return setPreferredNetworkTypeToGlobal(getSubId()); 4643 } 4644 4645 /** 4646 * Set the preferred network type to global mode which includes LTE, CDMA, EvDo and GSM/WCDMA. 4647 * 4648 * <p> 4649 * Requires that the calling app has carrier privileges. 4650 * @see #hasCarrierPrivileges 4651 * 4652 * @return true on success; false on any failure. 4653 * @hide 4654 */ 4655 public boolean setPreferredNetworkTypeToGlobal(int subId) { 4656 return setPreferredNetworkType(subId, RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA); 4657 } 4658 4659 /** 4660 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning 4661 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for 4662 * tethering. 4663 * 4664 * @return 0: Not required. 1: required. 2: Not set. 4665 * @hide 4666 */ 4667 public int getTetherApnRequired() { 4668 try { 4669 ITelephony telephony = getITelephony(); 4670 if (telephony != null) 4671 return telephony.getTetherApnRequired(); 4672 } catch (RemoteException ex) { 4673 Rlog.e(TAG, "hasMatchedTetherApnSetting RemoteException", ex); 4674 } catch (NullPointerException ex) { 4675 Rlog.e(TAG, "hasMatchedTetherApnSetting NPE", ex); 4676 } 4677 return 2; 4678 } 4679 4680 4681 /** 4682 * Values used to return status for hasCarrierPrivileges call. 4683 */ 4684 /** @hide */ @SystemApi 4685 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 4686 /** @hide */ @SystemApi 4687 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 4688 /** @hide */ @SystemApi 4689 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 4690 /** @hide */ @SystemApi 4691 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 4692 4693 /** 4694 * Has the calling application been granted carrier privileges by the carrier. 4695 * 4696 * If any of the packages in the calling UID has carrier privileges, the 4697 * call will return true. This access is granted by the owner of the UICC 4698 * card and does not depend on the registered carrier. 4699 * 4700 * @return true if the app has carrier privileges. 4701 */ 4702 public boolean hasCarrierPrivileges() { 4703 return hasCarrierPrivileges(getSubId()); 4704 } 4705 4706 /** 4707 * Has the calling application been granted carrier privileges by the carrier. 4708 * 4709 * If any of the packages in the calling UID has carrier privileges, the 4710 * call will return true. This access is granted by the owner of the UICC 4711 * card and does not depend on the registered carrier. 4712 * 4713 * @param subId The subscription to use. 4714 * @return true if the app has carrier privileges. 4715 * @hide 4716 */ 4717 public boolean hasCarrierPrivileges(int subId) { 4718 try { 4719 ITelephony telephony = getITelephony(); 4720 if (telephony != null) { 4721 return telephony.getCarrierPrivilegeStatus(mSubId) == 4722 CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; 4723 } 4724 } catch (RemoteException ex) { 4725 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 4726 } catch (NullPointerException ex) { 4727 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 4728 } 4729 return false; 4730 } 4731 4732 /** 4733 * Override the branding for the current ICCID. 4734 * 4735 * Once set, whenever the SIM is present in the device, the service 4736 * provider name (SPN) and the operator name will both be replaced by the 4737 * brand value input. To unset the value, the same function should be 4738 * called with a null brand value. 4739 * 4740 * <p>Requires that the calling app has carrier privileges. 4741 * @see #hasCarrierPrivileges 4742 * 4743 * @param brand The brand name to display/set. 4744 * @return true if the operation was executed correctly. 4745 */ 4746 public boolean setOperatorBrandOverride(String brand) { 4747 return setOperatorBrandOverride(getSubId(), brand); 4748 } 4749 4750 /** 4751 * Override the branding for the current ICCID. 4752 * 4753 * Once set, whenever the SIM is present in the device, the service 4754 * provider name (SPN) and the operator name will both be replaced by the 4755 * brand value input. To unset the value, the same function should be 4756 * called with a null brand value. 4757 * 4758 * <p>Requires that the calling app has carrier privileges. 4759 * @see #hasCarrierPrivileges 4760 * 4761 * @param subId The subscription to use. 4762 * @param brand The brand name to display/set. 4763 * @return true if the operation was executed correctly. 4764 * @hide 4765 */ 4766 public boolean setOperatorBrandOverride(int subId, String brand) { 4767 try { 4768 ITelephony telephony = getITelephony(); 4769 if (telephony != null) 4770 return telephony.setOperatorBrandOverride(subId, brand); 4771 } catch (RemoteException ex) { 4772 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 4773 } catch (NullPointerException ex) { 4774 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 4775 } 4776 return false; 4777 } 4778 4779 /** 4780 * Override the roaming preference for the current ICCID. 4781 * 4782 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 4783 * the platform's notion of a network operator being considered roaming or not. 4784 * The change only affects the ICCID that was active when this call was made. 4785 * 4786 * If null is passed as any of the input, the corresponding value is deleted. 4787 * 4788 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 4789 * 4790 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 4791 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 4792 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 4793 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 4794 * @return true if the operation was executed correctly. 4795 * 4796 * @hide 4797 */ 4798 public boolean setRoamingOverride(List<String> gsmRoamingList, 4799 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 4800 List<String> cdmaNonRoamingList) { 4801 return setRoamingOverride(getSubId(), gsmRoamingList, gsmNonRoamingList, 4802 cdmaRoamingList, cdmaNonRoamingList); 4803 } 4804 4805 /** 4806 * Override the roaming preference for the current ICCID. 4807 * 4808 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 4809 * the platform's notion of a network operator being considered roaming or not. 4810 * The change only affects the ICCID that was active when this call was made. 4811 * 4812 * If null is passed as any of the input, the corresponding value is deleted. 4813 * 4814 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 4815 * 4816 * @param subId for which the roaming overrides apply. 4817 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 4818 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 4819 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 4820 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 4821 * @return true if the operation was executed correctly. 4822 * 4823 * @hide 4824 */ 4825 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, 4826 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 4827 List<String> cdmaNonRoamingList) { 4828 try { 4829 ITelephony telephony = getITelephony(); 4830 if (telephony != null) 4831 return telephony.setRoamingOverride(subId, gsmRoamingList, gsmNonRoamingList, 4832 cdmaRoamingList, cdmaNonRoamingList); 4833 } catch (RemoteException ex) { 4834 Rlog.e(TAG, "setRoamingOverride RemoteException", ex); 4835 } catch (NullPointerException ex) { 4836 Rlog.e(TAG, "setRoamingOverride NPE", ex); 4837 } 4838 return false; 4839 } 4840 4841 /** 4842 * Expose the rest of ITelephony to @SystemApi 4843 */ 4844 4845 /** @hide */ 4846 @SystemApi 4847 public String getCdmaMdn() { 4848 return getCdmaMdn(getSubId()); 4849 } 4850 4851 /** @hide */ 4852 @SystemApi 4853 public String getCdmaMdn(int subId) { 4854 try { 4855 ITelephony telephony = getITelephony(); 4856 if (telephony == null) 4857 return null; 4858 return telephony.getCdmaMdn(subId); 4859 } catch (RemoteException ex) { 4860 return null; 4861 } catch (NullPointerException ex) { 4862 return null; 4863 } 4864 } 4865 4866 /** @hide */ 4867 @SystemApi 4868 public String getCdmaMin() { 4869 return getCdmaMin(getSubId()); 4870 } 4871 4872 /** @hide */ 4873 @SystemApi 4874 public String getCdmaMin(int subId) { 4875 try { 4876 ITelephony telephony = getITelephony(); 4877 if (telephony == null) 4878 return null; 4879 return telephony.getCdmaMin(subId); 4880 } catch (RemoteException ex) { 4881 return null; 4882 } catch (NullPointerException ex) { 4883 return null; 4884 } 4885 } 4886 4887 /** @hide */ 4888 @SystemApi 4889 public int checkCarrierPrivilegesForPackage(String pkgName) { 4890 try { 4891 ITelephony telephony = getITelephony(); 4892 if (telephony != null) 4893 return telephony.checkCarrierPrivilegesForPackage(pkgName); 4894 } catch (RemoteException ex) { 4895 Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex); 4896 } catch (NullPointerException ex) { 4897 Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex); 4898 } 4899 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 4900 } 4901 4902 /** @hide */ 4903 @SystemApi 4904 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { 4905 try { 4906 ITelephony telephony = getITelephony(); 4907 if (telephony != null) 4908 return telephony.checkCarrierPrivilegesForPackageAnyPhone(pkgName); 4909 } catch (RemoteException ex) { 4910 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone RemoteException", ex); 4911 } catch (NullPointerException ex) { 4912 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone NPE", ex); 4913 } 4914 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 4915 } 4916 4917 /** @hide */ 4918 @SystemApi 4919 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 4920 return getCarrierPackageNamesForIntentAndPhone(intent, getDefaultPhone()); 4921 } 4922 4923 /** @hide */ 4924 @SystemApi 4925 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { 4926 try { 4927 ITelephony telephony = getITelephony(); 4928 if (telephony != null) 4929 return telephony.getCarrierPackageNamesForIntentAndPhone(intent, phoneId); 4930 } catch (RemoteException ex) { 4931 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone RemoteException", ex); 4932 } catch (NullPointerException ex) { 4933 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone NPE", ex); 4934 } 4935 return null; 4936 } 4937 4938 /** @hide */ 4939 public List<String> getPackagesWithCarrierPrivileges() { 4940 try { 4941 ITelephony telephony = getITelephony(); 4942 if (telephony != null) { 4943 return telephony.getPackagesWithCarrierPrivileges(); 4944 } 4945 } catch (RemoteException ex) { 4946 Rlog.e(TAG, "getPackagesWithCarrierPrivileges RemoteException", ex); 4947 } catch (NullPointerException ex) { 4948 Rlog.e(TAG, "getPackagesWithCarrierPrivileges NPE", ex); 4949 } 4950 return Collections.EMPTY_LIST; 4951 } 4952 4953 /** @hide */ 4954 @SystemApi 4955 public void dial(String number) { 4956 try { 4957 ITelephony telephony = getITelephony(); 4958 if (telephony != null) 4959 telephony.dial(number); 4960 } catch (RemoteException e) { 4961 Log.e(TAG, "Error calling ITelephony#dial", e); 4962 } 4963 } 4964 4965 /** @hide */ 4966 @SystemApi 4967 public void call(String callingPackage, String number) { 4968 try { 4969 ITelephony telephony = getITelephony(); 4970 if (telephony != null) 4971 telephony.call(callingPackage, number); 4972 } catch (RemoteException e) { 4973 Log.e(TAG, "Error calling ITelephony#call", e); 4974 } 4975 } 4976 4977 /** @hide */ 4978 @SystemApi 4979 public boolean endCall() { 4980 try { 4981 ITelephony telephony = getITelephony(); 4982 if (telephony != null) 4983 return telephony.endCall(); 4984 } catch (RemoteException e) { 4985 Log.e(TAG, "Error calling ITelephony#endCall", e); 4986 } 4987 return false; 4988 } 4989 4990 /** @hide */ 4991 @SystemApi 4992 public void answerRingingCall() { 4993 try { 4994 ITelephony telephony = getITelephony(); 4995 if (telephony != null) 4996 telephony.answerRingingCall(); 4997 } catch (RemoteException e) { 4998 Log.e(TAG, "Error calling ITelephony#answerRingingCall", e); 4999 } 5000 } 5001 5002 /** @hide */ 5003 @SystemApi 5004 public void silenceRinger() { 5005 try { 5006 getTelecomService().silenceRinger(getOpPackageName()); 5007 } catch (RemoteException e) { 5008 Log.e(TAG, "Error calling ITelecomService#silenceRinger", e); 5009 } 5010 } 5011 5012 /** @hide */ 5013 @SystemApi 5014 public boolean isOffhook() { 5015 try { 5016 ITelephony telephony = getITelephony(); 5017 if (telephony != null) 5018 return telephony.isOffhook(getOpPackageName()); 5019 } catch (RemoteException e) { 5020 Log.e(TAG, "Error calling ITelephony#isOffhook", e); 5021 } 5022 return false; 5023 } 5024 5025 /** @hide */ 5026 @SystemApi 5027 public boolean isRinging() { 5028 try { 5029 ITelephony telephony = getITelephony(); 5030 if (telephony != null) 5031 return telephony.isRinging(getOpPackageName()); 5032 } catch (RemoteException e) { 5033 Log.e(TAG, "Error calling ITelephony#isRinging", e); 5034 } 5035 return false; 5036 } 5037 5038 /** @hide */ 5039 @SystemApi 5040 public boolean isIdle() { 5041 try { 5042 ITelephony telephony = getITelephony(); 5043 if (telephony != null) 5044 return telephony.isIdle(getOpPackageName()); 5045 } catch (RemoteException e) { 5046 Log.e(TAG, "Error calling ITelephony#isIdle", e); 5047 } 5048 return true; 5049 } 5050 5051 /** @hide */ 5052 @SystemApi 5053 public boolean isRadioOn() { 5054 try { 5055 ITelephony telephony = getITelephony(); 5056 if (telephony != null) 5057 return telephony.isRadioOn(getOpPackageName()); 5058 } catch (RemoteException e) { 5059 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 5060 } 5061 return false; 5062 } 5063 5064 /** @hide */ 5065 @SystemApi 5066 public boolean supplyPin(String pin) { 5067 try { 5068 ITelephony telephony = getITelephony(); 5069 if (telephony != null) 5070 return telephony.supplyPin(pin); 5071 } catch (RemoteException e) { 5072 Log.e(TAG, "Error calling ITelephony#supplyPin", e); 5073 } 5074 return false; 5075 } 5076 5077 /** @hide */ 5078 @SystemApi 5079 public boolean supplyPuk(String puk, String pin) { 5080 try { 5081 ITelephony telephony = getITelephony(); 5082 if (telephony != null) 5083 return telephony.supplyPuk(puk, pin); 5084 } catch (RemoteException e) { 5085 Log.e(TAG, "Error calling ITelephony#supplyPuk", e); 5086 } 5087 return false; 5088 } 5089 5090 /** @hide */ 5091 @SystemApi 5092 public int[] supplyPinReportResult(String pin) { 5093 try { 5094 ITelephony telephony = getITelephony(); 5095 if (telephony != null) 5096 return telephony.supplyPinReportResult(pin); 5097 } catch (RemoteException e) { 5098 Log.e(TAG, "Error calling ITelephony#supplyPinReportResult", e); 5099 } 5100 return new int[0]; 5101 } 5102 5103 /** @hide */ 5104 @SystemApi 5105 public int[] supplyPukReportResult(String puk, String pin) { 5106 try { 5107 ITelephony telephony = getITelephony(); 5108 if (telephony != null) 5109 return telephony.supplyPukReportResult(puk, pin); 5110 } catch (RemoteException e) { 5111 Log.e(TAG, "Error calling ITelephony#]", e); 5112 } 5113 return new int[0]; 5114 } 5115 5116 public static abstract class OnReceiveUssdResponseCallback { 5117 /** 5118 ** Called when USSD has succeeded. 5119 **/ 5120 public void onReceiveUssdResponse(String request, CharSequence response) {}; 5121 5122 /** 5123 ** Called when USSD has failed. 5124 **/ 5125 public void onReceiveUssdResponseFailed(String request, int failureCode) {}; 5126 } 5127 5128 /** 5129 * Sends an Unstructured Supplementary Service Data (USSD) request to the cellular network and 5130 * informs the caller of the response via {@code callback}. 5131 * <p>Carriers define USSD codes which can be sent by the user to request information such as 5132 * the user's current data balance or minutes balance. 5133 * <p>Requires permission: 5134 * {@link android.Manifest.permission#CALL_PHONE} 5135 * @param ussdRequest the USSD command to be executed. 5136 * @param callback called by the framework to inform the caller of the result of executing the 5137 * USSD request (see {@link OnReceiveUssdResponseCallback}). 5138 * @param handler the {@link Handler} to run the request on. 5139 */ 5140 @RequiresPermission(android.Manifest.permission.CALL_PHONE) 5141 public void sendUssdRequest(String ussdRequest, 5142 final OnReceiveUssdResponseCallback callback, Handler handler) { 5143 checkNotNull(callback, "OnReceiveUssdResponseCallback cannot be null."); 5144 5145 ResultReceiver wrappedCallback = new ResultReceiver(handler) { 5146 @Override 5147 protected void onReceiveResult(int resultCode, Bundle ussdResponse) { 5148 Rlog.d(TAG, "USSD:" + resultCode); 5149 checkNotNull(ussdResponse, "ussdResponse cannot be null."); 5150 UssdResponse response = ussdResponse.getParcelable(USSD_RESPONSE); 5151 5152 if (resultCode == USSD_RETURN_SUCCESS) { 5153 callback.onReceiveUssdResponse(response.getUssdRequest(), 5154 response.getReturnMessage()); 5155 } else { 5156 callback.onReceiveUssdResponseFailed(response.getUssdRequest(), resultCode); 5157 } 5158 } 5159 }; 5160 5161 try { 5162 ITelephony telephony = getITelephony(); 5163 if (telephony != null) { 5164 telephony.handleUssdRequest(mSubId, ussdRequest, wrappedCallback); 5165 } 5166 } catch (RemoteException e) { 5167 Log.e(TAG, "Error calling ITelephony#sendUSSDCode", e); 5168 UssdResponse response = new UssdResponse(ussdRequest, ""); 5169 Bundle returnData = new Bundle(); 5170 returnData.putParcelable(USSD_RESPONSE, response); 5171 wrappedCallback.send(USSD_ERROR_SERVICE_UNAVAIL, returnData); 5172 } 5173 } 5174 5175 /* 5176 * @return true, if the device is currently on a technology (e.g. UMTS or LTE) which can support 5177 * voice and data simultaneously. This can change based on location or network condition. 5178 */ 5179 public boolean isConcurrentVoiceAndDataAllowed() { 5180 try { 5181 ITelephony telephony = getITelephony(); 5182 return (telephony == null ? false : telephony.isConcurrentVoiceAndDataAllowed(mSubId)); 5183 } catch (RemoteException e) { 5184 Log.e(TAG, "Error calling ITelephony#isConcurrentVoiceAndDataAllowed", e); 5185 } 5186 return false; 5187 } 5188 5189 /** @hide */ 5190 @SystemApi 5191 public boolean handlePinMmi(String dialString) { 5192 try { 5193 ITelephony telephony = getITelephony(); 5194 if (telephony != null) 5195 return telephony.handlePinMmi(dialString); 5196 } catch (RemoteException e) { 5197 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 5198 } 5199 return false; 5200 } 5201 5202 /** @hide */ 5203 @SystemApi 5204 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 5205 try { 5206 ITelephony telephony = getITelephony(); 5207 if (telephony != null) 5208 return telephony.handlePinMmiForSubscriber(subId, dialString); 5209 } catch (RemoteException e) { 5210 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 5211 } 5212 return false; 5213 } 5214 5215 /** @hide */ 5216 @SystemApi 5217 public void toggleRadioOnOff() { 5218 try { 5219 ITelephony telephony = getITelephony(); 5220 if (telephony != null) 5221 telephony.toggleRadioOnOff(); 5222 } catch (RemoteException e) { 5223 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 5224 } 5225 } 5226 5227 /** @hide */ 5228 @SystemApi 5229 public boolean setRadio(boolean turnOn) { 5230 try { 5231 ITelephony telephony = getITelephony(); 5232 if (telephony != null) 5233 return telephony.setRadio(turnOn); 5234 } catch (RemoteException e) { 5235 Log.e(TAG, "Error calling ITelephony#setRadio", e); 5236 } 5237 return false; 5238 } 5239 5240 /** @hide */ 5241 @SystemApi 5242 public boolean setRadioPower(boolean turnOn) { 5243 try { 5244 ITelephony telephony = getITelephony(); 5245 if (telephony != null) 5246 return telephony.setRadioPower(turnOn); 5247 } catch (RemoteException e) { 5248 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 5249 } 5250 return false; 5251 } 5252 5253 /** @hide */ 5254 @SystemApi 5255 public void updateServiceLocation() { 5256 try { 5257 ITelephony telephony = getITelephony(); 5258 if (telephony != null) 5259 telephony.updateServiceLocation(); 5260 } catch (RemoteException e) { 5261 Log.e(TAG, "Error calling ITelephony#updateServiceLocation", e); 5262 } 5263 } 5264 5265 /** @hide */ 5266 @SystemApi 5267 public boolean enableDataConnectivity() { 5268 try { 5269 ITelephony telephony = getITelephony(); 5270 if (telephony != null) 5271 return telephony.enableDataConnectivity(); 5272 } catch (RemoteException e) { 5273 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 5274 } 5275 return false; 5276 } 5277 5278 /** @hide */ 5279 @SystemApi 5280 public boolean disableDataConnectivity() { 5281 try { 5282 ITelephony telephony = getITelephony(); 5283 if (telephony != null) 5284 return telephony.disableDataConnectivity(); 5285 } catch (RemoteException e) { 5286 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 5287 } 5288 return false; 5289 } 5290 5291 /** @hide */ 5292 @SystemApi 5293 public boolean isDataConnectivityPossible() { 5294 try { 5295 ITelephony telephony = getITelephony(); 5296 if (telephony != null) 5297 return telephony.isDataConnectivityPossible(); 5298 } catch (RemoteException e) { 5299 Log.e(TAG, "Error calling ITelephony#isDataConnectivityPossible", e); 5300 } 5301 return false; 5302 } 5303 5304 /** @hide */ 5305 @SystemApi 5306 public boolean needsOtaServiceProvisioning() { 5307 try { 5308 ITelephony telephony = getITelephony(); 5309 if (telephony != null) 5310 return telephony.needsOtaServiceProvisioning(); 5311 } catch (RemoteException e) { 5312 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 5313 } 5314 return false; 5315 } 5316 5317 /** 5318 * Turns mobile data on or off. 5319 * 5320 * <p>Requires Permission: 5321 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 5322 * calling app has carrier privileges. 5323 * 5324 * @param enable Whether to enable mobile data. 5325 * 5326 * @see #hasCarrierPrivileges 5327 */ 5328 public void setDataEnabled(boolean enable) { 5329 setDataEnabled(getSubId(), enable); 5330 } 5331 5332 /** @hide */ 5333 @SystemApi 5334 public void setDataEnabled(int subId, boolean enable) { 5335 try { 5336 Log.d(TAG, "setDataEnabled: enabled=" + enable); 5337 ITelephony telephony = getITelephony(); 5338 if (telephony != null) 5339 telephony.setDataEnabled(subId, enable); 5340 } catch (RemoteException e) { 5341 Log.e(TAG, "Error calling ITelephony#setDataEnabled", e); 5342 } 5343 } 5344 5345 5346 /** 5347 * @deprecated use {@link #isDataEnabled()} instead. 5348 * @hide 5349 */ 5350 @SystemApi 5351 @Deprecated 5352 public boolean getDataEnabled() { 5353 return isDataEnabled(); 5354 } 5355 5356 /** 5357 * Returns whether mobile data is enabled or not. 5358 * 5359 * <p>Requires one of the following permissions: 5360 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE ACCESS_NETWORK_STATE}, 5361 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}, or that the 5362 * calling app has carrier privileges. 5363 * 5364 * <p>Note that this does not take into account any data restrictions that may be present on the 5365 * calling app. Such restrictions may be inspected with 5366 * {@link ConnectivityManager#getRestrictBackgroundStatus}. 5367 * 5368 * @return true if mobile data is enabled. 5369 * 5370 * @see #hasCarrierPrivileges 5371 */ 5372 @SuppressWarnings("deprecation") 5373 public boolean isDataEnabled() { 5374 return getDataEnabled(getSubId()); 5375 } 5376 5377 /** 5378 * @deprecated use {@link #isDataEnabled(int)} instead. 5379 * @hide 5380 */ 5381 @SystemApi 5382 public boolean getDataEnabled(int subId) { 5383 boolean retVal = false; 5384 try { 5385 ITelephony telephony = getITelephony(); 5386 if (telephony != null) 5387 retVal = telephony.getDataEnabled(subId); 5388 } catch (RemoteException e) { 5389 Log.e(TAG, "Error calling ITelephony#getDataEnabled", e); 5390 } catch (NullPointerException e) { 5391 } 5392 return retVal; 5393 } 5394 5395 /** 5396 * Returns the result and response from RIL for oem request 5397 * 5398 * @param oemReq the data is sent to ril. 5399 * @param oemResp the respose data from RIL. 5400 * @return negative value request was not handled or get error 5401 * 0 request was handled succesfully, but no response data 5402 * positive value success, data length of response 5403 * @hide 5404 * @deprecated OEM needs a vendor-extension hal and their apps should use that instead 5405 */ 5406 @Deprecated 5407 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 5408 try { 5409 ITelephony telephony = getITelephony(); 5410 if (telephony != null) 5411 return telephony.invokeOemRilRequestRaw(oemReq, oemResp); 5412 } catch (RemoteException ex) { 5413 } catch (NullPointerException ex) { 5414 } 5415 return -1; 5416 } 5417 5418 /** @hide */ 5419 @SystemApi 5420 public void enableVideoCalling(boolean enable) { 5421 try { 5422 ITelephony telephony = getITelephony(); 5423 if (telephony != null) 5424 telephony.enableVideoCalling(enable); 5425 } catch (RemoteException e) { 5426 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 5427 } 5428 } 5429 5430 /** @hide */ 5431 @SystemApi 5432 public boolean isVideoCallingEnabled() { 5433 try { 5434 ITelephony telephony = getITelephony(); 5435 if (telephony != null) 5436 return telephony.isVideoCallingEnabled(getOpPackageName()); 5437 } catch (RemoteException e) { 5438 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 5439 } 5440 return false; 5441 } 5442 5443 /** 5444 * Whether the device supports configuring the DTMF tone length. 5445 * 5446 * @return {@code true} if the DTMF tone length can be changed, and {@code false} otherwise. 5447 */ 5448 public boolean canChangeDtmfToneLength() { 5449 try { 5450 ITelephony telephony = getITelephony(); 5451 if (telephony != null) { 5452 return telephony.canChangeDtmfToneLength(); 5453 } 5454 } catch (RemoteException e) { 5455 Log.e(TAG, "Error calling ITelephony#canChangeDtmfToneLength", e); 5456 } catch (SecurityException e) { 5457 Log.e(TAG, "Permission error calling ITelephony#canChangeDtmfToneLength", e); 5458 } 5459 return false; 5460 } 5461 5462 /** 5463 * Whether the device is a world phone. 5464 * 5465 * @return {@code true} if the device is a world phone, and {@code false} otherwise. 5466 */ 5467 public boolean isWorldPhone() { 5468 try { 5469 ITelephony telephony = getITelephony(); 5470 if (telephony != null) { 5471 return telephony.isWorldPhone(); 5472 } 5473 } catch (RemoteException e) { 5474 Log.e(TAG, "Error calling ITelephony#isWorldPhone", e); 5475 } catch (SecurityException e) { 5476 Log.e(TAG, "Permission error calling ITelephony#isWorldPhone", e); 5477 } 5478 return false; 5479 } 5480 5481 /** 5482 * Whether the phone supports TTY mode. 5483 * 5484 * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. 5485 */ 5486 public boolean isTtyModeSupported() { 5487 try { 5488 ITelephony telephony = getITelephony(); 5489 if (telephony != null) { 5490 return telephony.isTtyModeSupported(); 5491 } 5492 } catch (RemoteException e) { 5493 Log.e(TAG, "Error calling ITelephony#isTtyModeSupported", e); 5494 } catch (SecurityException e) { 5495 Log.e(TAG, "Permission error calling ITelephony#isTtyModeSupported", e); 5496 } 5497 return false; 5498 } 5499 5500 /** 5501 * Whether the phone supports hearing aid compatibility. 5502 * 5503 * @return {@code true} if the device supports hearing aid compatibility, and {@code false} 5504 * otherwise. 5505 */ 5506 public boolean isHearingAidCompatibilitySupported() { 5507 try { 5508 ITelephony telephony = getITelephony(); 5509 if (telephony != null) { 5510 return telephony.isHearingAidCompatibilitySupported(); 5511 } 5512 } catch (RemoteException e) { 5513 Log.e(TAG, "Error calling ITelephony#isHearingAidCompatibilitySupported", e); 5514 } catch (SecurityException e) { 5515 Log.e(TAG, "Permission error calling ITelephony#isHearingAidCompatibilitySupported", e); 5516 } 5517 return false; 5518 } 5519 5520 /** 5521 * This function retrieves value for setting "name+subId", and if that is not found 5522 * retrieves value for setting "name", and if that is not found throws 5523 * SettingNotFoundException 5524 * 5525 * @hide 5526 */ 5527 public static int getIntWithSubId(ContentResolver cr, String name, int subId) 5528 throws SettingNotFoundException { 5529 try { 5530 return Settings.Global.getInt(cr, name + subId); 5531 } catch (SettingNotFoundException e) { 5532 try { 5533 int val = Settings.Global.getInt(cr, name); 5534 Settings.Global.putInt(cr, name + subId, val); 5535 5536 /* We are now moving from 'setting' to 'setting+subId', and using the value stored 5537 * for 'setting' as default. Reset the default (since it may have a user set 5538 * value). */ 5539 int default_val = val; 5540 if (name.equals(Settings.Global.MOBILE_DATA)) { 5541 default_val = "true".equalsIgnoreCase( 5542 SystemProperties.get("ro.com.android.mobiledata", "true")) ? 1 : 0; 5543 } else if (name.equals(Settings.Global.DATA_ROAMING)) { 5544 default_val = "true".equalsIgnoreCase( 5545 SystemProperties.get("ro.com.android.dataroaming", "false")) ? 1 : 0; 5546 } 5547 5548 if (default_val != val) { 5549 Settings.Global.putInt(cr, name, default_val); 5550 } 5551 5552 return val; 5553 } catch (SettingNotFoundException exc) { 5554 throw new SettingNotFoundException(name); 5555 } 5556 } 5557 } 5558 5559 /** 5560 * Returns the IMS Registration Status 5561 * @hide 5562 */ 5563 public boolean isImsRegistered() { 5564 try { 5565 ITelephony telephony = getITelephony(); 5566 if (telephony == null) 5567 return false; 5568 return telephony.isImsRegistered(); 5569 } catch (RemoteException ex) { 5570 return false; 5571 } catch (NullPointerException ex) { 5572 return false; 5573 } 5574 } 5575 5576 /** 5577 * Returns the Status of Volte 5578 * @hide 5579 */ 5580 public boolean isVolteAvailable() { 5581 try { 5582 return getITelephony().isVolteAvailable(); 5583 } catch (RemoteException ex) { 5584 return false; 5585 } catch (NullPointerException ex) { 5586 return false; 5587 } 5588 } 5589 5590 /** 5591 * Returns the Status of video telephony (VT) 5592 * @hide 5593 */ 5594 public boolean isVideoTelephonyAvailable() { 5595 try { 5596 return getITelephony().isVideoTelephonyAvailable(); 5597 } catch (RemoteException ex) { 5598 return false; 5599 } catch (NullPointerException ex) { 5600 return false; 5601 } 5602 } 5603 5604 /** 5605 * Returns the Status of Wi-Fi Calling 5606 * @hide 5607 */ 5608 public boolean isWifiCallingAvailable() { 5609 try { 5610 return getITelephony().isWifiCallingAvailable(); 5611 } catch (RemoteException ex) { 5612 return false; 5613 } catch (NullPointerException ex) { 5614 return false; 5615 } 5616 } 5617 5618 /** 5619 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 5620 * 5621 * @hide 5622 */ 5623 public void setSimOperatorNumeric(String numeric) { 5624 int phoneId = getDefaultPhone(); 5625 setSimOperatorNumericForPhone(phoneId, numeric); 5626 } 5627 5628 /** 5629 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 5630 * 5631 * @hide 5632 */ 5633 public void setSimOperatorNumericForPhone(int phoneId, String numeric) { 5634 setTelephonyProperty(phoneId, 5635 TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC, numeric); 5636 } 5637 5638 /** 5639 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the default phone. 5640 * 5641 * @hide 5642 */ 5643 public void setSimOperatorName(String name) { 5644 int phoneId = getDefaultPhone(); 5645 setSimOperatorNameForPhone(phoneId, name); 5646 } 5647 5648 /** 5649 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_NUMERIC for the given phone. 5650 * 5651 * @hide 5652 */ 5653 public void setSimOperatorNameForPhone(int phoneId, String name) { 5654 setTelephonyProperty(phoneId, 5655 TelephonyProperties.PROPERTY_ICC_OPERATOR_ALPHA, name); 5656 } 5657 5658 /** 5659 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the default phone. 5660 * 5661 * @hide 5662 */ 5663 public void setSimCountryIso(String iso) { 5664 int phoneId = getDefaultPhone(); 5665 setSimCountryIsoForPhone(phoneId, iso); 5666 } 5667 5668 /** 5669 * Set TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY for the given phone. 5670 * 5671 * @hide 5672 */ 5673 public void setSimCountryIsoForPhone(int phoneId, String iso) { 5674 setTelephonyProperty(phoneId, 5675 TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY, iso); 5676 } 5677 5678 /** 5679 * Set TelephonyProperties.PROPERTY_SIM_STATE for the default phone. 5680 * 5681 * @hide 5682 */ 5683 public void setSimState(String state) { 5684 int phoneId = getDefaultPhone(); 5685 setSimStateForPhone(phoneId, state); 5686 } 5687 5688 /** 5689 * Set TelephonyProperties.PROPERTY_SIM_STATE for the given phone. 5690 * 5691 * @hide 5692 */ 5693 public void setSimStateForPhone(int phoneId, String state) { 5694 setTelephonyProperty(phoneId, 5695 TelephonyProperties.PROPERTY_SIM_STATE, state); 5696 } 5697 5698 /** 5699 * Set SIM card power state. Request is equivalent to inserting or removing the card. 5700 * 5701 * @param powerUp True if powering up the SIM, otherwise powering down 5702 * 5703 * <p>Requires Permission: 5704 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 5705 * 5706 * @hide 5707 **/ 5708 public void setSimPowerState(boolean powerUp) { 5709 setSimPowerStateForSlot(getDefaultSim(), powerUp); 5710 } 5711 5712 /** 5713 * Set SIM card power state. Request is equivalent to inserting or removing the card. 5714 * 5715 * @param slotIndex SIM slot id 5716 * @param powerUp True if powering up the SIM, otherwise powering down 5717 * 5718 * <p>Requires Permission: 5719 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 5720 * 5721 * @hide 5722 **/ 5723 public void setSimPowerStateForSlot(int slotIndex, boolean powerUp) { 5724 try { 5725 ITelephony telephony = getITelephony(); 5726 if (telephony != null) { 5727 telephony.setSimPowerStateForSlot(slotIndex, powerUp); 5728 } 5729 } catch (RemoteException e) { 5730 Log.e(TAG, "Error calling ITelephony#setSimPowerStateForSlot", e); 5731 } catch (SecurityException e) { 5732 Log.e(TAG, "Permission error calling ITelephony#setSimPowerStateForSlot", e); 5733 } 5734 } 5735 5736 /** 5737 * Set baseband version for the default phone. 5738 * 5739 * @param version baseband version 5740 * @hide 5741 */ 5742 public void setBasebandVersion(String version) { 5743 int phoneId = getDefaultPhone(); 5744 setBasebandVersionForPhone(phoneId, version); 5745 } 5746 5747 /** 5748 * Set baseband version by phone id. 5749 * 5750 * @param phoneId for which baseband version is set 5751 * @param version baseband version 5752 * @hide 5753 */ 5754 public void setBasebandVersionForPhone(int phoneId, String version) { 5755 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5756 String prop = TelephonyProperties.PROPERTY_BASEBAND_VERSION + 5757 ((phoneId == 0) ? "" : Integer.toString(phoneId)); 5758 SystemProperties.set(prop, version); 5759 } 5760 } 5761 5762 /** 5763 * Set phone type for the default phone. 5764 * 5765 * @param type phone type 5766 * 5767 * @hide 5768 */ 5769 public void setPhoneType(int type) { 5770 int phoneId = getDefaultPhone(); 5771 setPhoneType(phoneId, type); 5772 } 5773 5774 /** 5775 * Set phone type by phone id. 5776 * 5777 * @param phoneId for which phone type is set 5778 * @param type phone type 5779 * 5780 * @hide 5781 */ 5782 public void setPhoneType(int phoneId, int type) { 5783 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5784 TelephonyManager.setTelephonyProperty(phoneId, 5785 TelephonyProperties.CURRENT_ACTIVE_PHONE, String.valueOf(type)); 5786 } 5787 } 5788 5789 /** 5790 * Get OTASP number schema for the default phone. 5791 * 5792 * @param defaultValue default value 5793 * @return OTA SP number schema 5794 * 5795 * @hide 5796 */ 5797 public String getOtaSpNumberSchema(String defaultValue) { 5798 int phoneId = getDefaultPhone(); 5799 return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); 5800 } 5801 5802 /** 5803 * Get OTASP number schema by phone id. 5804 * 5805 * @param phoneId for which OTA SP number schema is get 5806 * @param defaultValue default value 5807 * @return OTA SP number schema 5808 * 5809 * @hide 5810 */ 5811 public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) { 5812 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5813 return TelephonyManager.getTelephonyProperty(phoneId, 5814 TelephonyProperties.PROPERTY_OTASP_NUM_SCHEMA, defaultValue); 5815 } 5816 5817 return defaultValue; 5818 } 5819 5820 /** 5821 * Get SMS receive capable from system property for the default phone. 5822 * 5823 * @param defaultValue default value 5824 * @return SMS receive capable 5825 * 5826 * @hide 5827 */ 5828 public boolean getSmsReceiveCapable(boolean defaultValue) { 5829 int phoneId = getDefaultPhone(); 5830 return getSmsReceiveCapableForPhone(phoneId, defaultValue); 5831 } 5832 5833 /** 5834 * Get SMS receive capable from system property by phone id. 5835 * 5836 * @param phoneId for which SMS receive capable is get 5837 * @param defaultValue default value 5838 * @return SMS receive capable 5839 * 5840 * @hide 5841 */ 5842 public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) { 5843 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5844 return Boolean.parseBoolean(TelephonyManager.getTelephonyProperty(phoneId, 5845 TelephonyProperties.PROPERTY_SMS_RECEIVE, String.valueOf(defaultValue))); 5846 } 5847 5848 return defaultValue; 5849 } 5850 5851 /** 5852 * Get SMS send capable from system property for the default phone. 5853 * 5854 * @param defaultValue default value 5855 * @return SMS send capable 5856 * 5857 * @hide 5858 */ 5859 public boolean getSmsSendCapable(boolean defaultValue) { 5860 int phoneId = getDefaultPhone(); 5861 return getSmsSendCapableForPhone(phoneId, defaultValue); 5862 } 5863 5864 /** 5865 * Get SMS send capable from system property by phone id. 5866 * 5867 * @param phoneId for which SMS send capable is get 5868 * @param defaultValue default value 5869 * @return SMS send capable 5870 * 5871 * @hide 5872 */ 5873 public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) { 5874 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5875 return Boolean.parseBoolean(TelephonyManager.getTelephonyProperty(phoneId, 5876 TelephonyProperties.PROPERTY_SMS_SEND, String.valueOf(defaultValue))); 5877 } 5878 5879 return defaultValue; 5880 } 5881 5882 /** 5883 * Set the alphabetic name of current registered operator. 5884 * @param name the alphabetic name of current registered operator. 5885 * @hide 5886 */ 5887 public void setNetworkOperatorName(String name) { 5888 int phoneId = getDefaultPhone(); 5889 setNetworkOperatorNameForPhone(phoneId, name); 5890 } 5891 5892 /** 5893 * Set the alphabetic name of current registered operator. 5894 * @param phoneId which phone you want to set 5895 * @param name the alphabetic name of current registered operator. 5896 * @hide 5897 */ 5898 public void setNetworkOperatorNameForPhone(int phoneId, String name) { 5899 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5900 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ALPHA, name); 5901 } 5902 } 5903 5904 /** 5905 * Set the numeric name (MCC+MNC) of current registered operator. 5906 * @param operator the numeric name (MCC+MNC) of current registered operator 5907 * @hide 5908 */ 5909 public void setNetworkOperatorNumeric(String numeric) { 5910 int phoneId = getDefaultPhone(); 5911 setNetworkOperatorNumericForPhone(phoneId, numeric); 5912 } 5913 5914 /** 5915 * Set the numeric name (MCC+MNC) of current registered operator. 5916 * @param phoneId for which phone type is set 5917 * @param operator the numeric name (MCC+MNC) of current registered operator 5918 * @hide 5919 */ 5920 public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) { 5921 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_NUMERIC, numeric); 5922 } 5923 5924 /** 5925 * Set roaming state of the current network, for GSM purposes. 5926 * @param isRoaming is network in romaing state or not 5927 * @hide 5928 */ 5929 public void setNetworkRoaming(boolean isRoaming) { 5930 int phoneId = getDefaultPhone(); 5931 setNetworkRoamingForPhone(phoneId, isRoaming); 5932 } 5933 5934 /** 5935 * Set roaming state of the current network, for GSM purposes. 5936 * @param phoneId which phone you want to set 5937 * @param isRoaming is network in romaing state or not 5938 * @hide 5939 */ 5940 public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) { 5941 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5942 setTelephonyProperty(phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, 5943 isRoaming ? "true" : "false"); 5944 } 5945 } 5946 5947 /** 5948 * Set the ISO country code equivalent of the current registered 5949 * operator's MCC (Mobile Country Code). 5950 * @param iso the ISO country code equivalent of the current registered 5951 * @hide 5952 */ 5953 public void setNetworkCountryIso(String iso) { 5954 int phoneId = getDefaultPhone(); 5955 setNetworkCountryIsoForPhone(phoneId, iso); 5956 } 5957 5958 /** 5959 * Set the ISO country code equivalent of the current registered 5960 * operator's MCC (Mobile Country Code). 5961 * @param phoneId which phone you want to set 5962 * @param iso the ISO country code equivalent of the current registered 5963 * @hide 5964 */ 5965 public void setNetworkCountryIsoForPhone(int phoneId, String iso) { 5966 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5967 setTelephonyProperty(phoneId, 5968 TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, iso); 5969 } 5970 } 5971 5972 /** 5973 * Set the network type currently in use on the device for data transmission. 5974 * @param type the network type currently in use on the device for data transmission 5975 * @hide 5976 */ 5977 public void setDataNetworkType(int type) { 5978 int phoneId = getDefaultPhone(); 5979 setDataNetworkTypeForPhone(phoneId, type); 5980 } 5981 5982 /** 5983 * Set the network type currently in use on the device for data transmission. 5984 * @param phoneId which phone you want to set 5985 * @param type the network type currently in use on the device for data transmission 5986 * @hide 5987 */ 5988 public void setDataNetworkTypeForPhone(int phoneId, int type) { 5989 if (SubscriptionManager.isValidPhoneId(phoneId)) { 5990 setTelephonyProperty(phoneId, 5991 TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE, 5992 ServiceState.rilRadioTechnologyToString(type)); 5993 } 5994 } 5995 5996 /** 5997 * Returns the subscription ID for the given phone account. 5998 * @hide 5999 */ 6000 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { 6001 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 6002 try { 6003 ITelephony service = getITelephony(); 6004 if (service != null) { 6005 retval = service.getSubIdForPhoneAccount(phoneAccount); 6006 } 6007 } catch (RemoteException e) { 6008 } 6009 6010 return retval; 6011 } 6012 6013 private int getSubIdForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) { 6014 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 6015 try { 6016 ITelecomService service = getTelecomService(); 6017 if (service != null) { 6018 retval = getSubIdForPhoneAccount(service.getPhoneAccount(phoneAccountHandle)); 6019 } 6020 } catch (RemoteException e) { 6021 } 6022 6023 return retval; 6024 } 6025 6026 /** 6027 * Resets telephony manager settings back to factory defaults. 6028 * 6029 * @hide 6030 */ 6031 public void factoryReset(int subId) { 6032 try { 6033 Log.d(TAG, "factoryReset: subId=" + subId); 6034 ITelephony telephony = getITelephony(); 6035 if (telephony != null) 6036 telephony.factoryReset(subId); 6037 } catch (RemoteException e) { 6038 } 6039 } 6040 6041 6042 /** @hide */ 6043 public String getLocaleFromDefaultSim() { 6044 try { 6045 final ITelephony telephony = getITelephony(); 6046 if (telephony != null) { 6047 return telephony.getLocaleFromDefaultSim(); 6048 } 6049 } catch (RemoteException ex) { 6050 } 6051 return null; 6052 } 6053 6054 /** 6055 * Requests the modem activity info. The recipient will place the result 6056 * in `result`. 6057 * @param result The object on which the recipient will send the resulting 6058 * {@link android.telephony.ModemActivityInfo} object. 6059 * @hide 6060 */ 6061 public void requestModemActivityInfo(ResultReceiver result) { 6062 try { 6063 ITelephony service = getITelephony(); 6064 if (service != null) { 6065 service.requestModemActivityInfo(result); 6066 return; 6067 } 6068 } catch (RemoteException e) { 6069 Log.e(TAG, "Error calling ITelephony#getModemActivityInfo", e); 6070 } 6071 result.send(0, null); 6072 } 6073 6074 /** 6075 * Returns the current {@link ServiceState} information. 6076 * 6077 * <p>Requires Permission: 6078 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 6079 */ 6080 public ServiceState getServiceState() { 6081 return getServiceStateForSubscriber(getSubId()); 6082 } 6083 6084 /** 6085 * Returns the service state information on specified subscription. Callers require 6086 * either READ_PRIVILEGED_PHONE_STATE or READ_PHONE_STATE to retrieve the information. 6087 * @hide 6088 */ 6089 public ServiceState getServiceStateForSubscriber(int subId) { 6090 try { 6091 ITelephony service = getITelephony(); 6092 if (service != null) { 6093 return service.getServiceStateForSubscriber(subId, getOpPackageName()); 6094 } 6095 } catch (RemoteException e) { 6096 Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e); 6097 } 6098 return null; 6099 } 6100 6101 /** 6102 * Returns the URI for the per-account voicemail ringtone set in Phone settings. 6103 * 6104 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the 6105 * voicemail ringtone. 6106 * @return The URI for the ringtone to play when receiving a voicemail from a specific 6107 * PhoneAccount. 6108 */ 6109 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { 6110 try { 6111 ITelephony service = getITelephony(); 6112 if (service != null) { 6113 return service.getVoicemailRingtoneUri(accountHandle); 6114 } 6115 } catch (RemoteException e) { 6116 Log.e(TAG, "Error calling ITelephony#getVoicemailRingtoneUri", e); 6117 } 6118 return null; 6119 } 6120 6121 /** 6122 * Sets the per-account voicemail ringtone. 6123 * 6124 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or has 6125 * permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 6126 * 6127 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the 6128 * voicemail ringtone. 6129 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific 6130 * PhoneAccount. 6131 * @see #hasCarrierPrivileges 6132 */ 6133 public void setVoicemailRingtoneUri(PhoneAccountHandle phoneAccountHandle, Uri uri) { 6134 try { 6135 ITelephony service = getITelephony(); 6136 if (service != null) { 6137 service.setVoicemailRingtoneUri(getOpPackageName(), phoneAccountHandle, uri); 6138 } 6139 } catch (RemoteException e) { 6140 Log.e(TAG, "Error calling ITelephony#setVoicemailRingtoneUri", e); 6141 } 6142 } 6143 6144 /** 6145 * Returns whether vibration is set for voicemail notification in Phone settings. 6146 * 6147 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the 6148 * voicemail vibration setting. 6149 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. 6150 */ 6151 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { 6152 try { 6153 ITelephony service = getITelephony(); 6154 if (service != null) { 6155 return service.isVoicemailVibrationEnabled(accountHandle); 6156 } 6157 } catch (RemoteException e) { 6158 Log.e(TAG, "Error calling ITelephony#isVoicemailVibrationEnabled", e); 6159 } 6160 return false; 6161 } 6162 6163 /** 6164 * Sets the per-account preference whether vibration is enabled for voicemail notifications. 6165 * 6166 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or has 6167 * permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 6168 * 6169 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the 6170 * voicemail vibration setting. 6171 * @param enabled Whether to enable or disable vibration for voicemail notifications from a 6172 * specific PhoneAccount. 6173 * @see #hasCarrierPrivileges 6174 */ 6175 public void setVoicemailVibrationEnabled(PhoneAccountHandle phoneAccountHandle, 6176 boolean enabled) { 6177 try { 6178 ITelephony service = getITelephony(); 6179 if (service != null) { 6180 service.setVoicemailVibrationEnabled(getOpPackageName(), phoneAccountHandle, 6181 enabled); 6182 } 6183 } catch (RemoteException e) { 6184 Log.e(TAG, "Error calling ITelephony#isVoicemailVibrationEnabled", e); 6185 } 6186 } 6187 6188 /** 6189 * Return the application ID for the app type like {@link APPTYPE_CSIM}. 6190 * 6191 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 6192 * 6193 * @param appType the uicc app type like {@link APPTYPE_CSIM} 6194 * @return Application ID for specificied app type or null if no uicc or error. 6195 * @hide 6196 */ 6197 public String getAidForAppType(int appType) { 6198 return getAidForAppType(getDefaultSubscription(), appType); 6199 } 6200 6201 /** 6202 * Return the application ID for the app type like {@link APPTYPE_CSIM}. 6203 * 6204 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 6205 * 6206 * @param subId the subscription ID that this request applies to. 6207 * @param appType the uicc app type, like {@link APPTYPE_CSIM} 6208 * @return Application ID for specificied app type or null if no uicc or error. 6209 * @hide 6210 */ 6211 public String getAidForAppType(int subId, int appType) { 6212 try { 6213 ITelephony service = getITelephony(); 6214 if (service != null) { 6215 return service.getAidForAppType(subId, appType); 6216 } 6217 } catch (RemoteException e) { 6218 Log.e(TAG, "Error calling ITelephony#getAidForAppType", e); 6219 } 6220 return null; 6221 } 6222 6223 /** 6224 * Return the Electronic Serial Number. 6225 * 6226 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 6227 * 6228 * @return ESN or null if error. 6229 * @hide 6230 */ 6231 public String getEsn() { 6232 return getEsn(getDefaultSubscription()); 6233 } 6234 6235 /** 6236 * Return the Electronic Serial Number. 6237 * 6238 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 6239 * 6240 * @param subId the subscription ID that this request applies to. 6241 * @return ESN or null if error. 6242 * @hide 6243 */ 6244 public String getEsn(int subId) { 6245 try { 6246 ITelephony service = getITelephony(); 6247 if (service != null) { 6248 return service.getEsn(subId); 6249 } 6250 } catch (RemoteException e) { 6251 Log.e(TAG, "Error calling ITelephony#getEsn", e); 6252 } 6253 return null; 6254 } 6255 6256 /** 6257 * Return the Preferred Roaming List Version 6258 * 6259 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 6260 * 6261 * @return PRLVersion or null if error. 6262 * @hide 6263 */ 6264 public String getCdmaPrlVersion() { 6265 return getCdmaPrlVersion(getDefaultSubscription()); 6266 } 6267 6268 /** 6269 * Return the Preferred Roaming List Version 6270 * 6271 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 6272 * 6273 * @param subId the subscription ID that this request applies to. 6274 * @return PRLVersion or null if error. 6275 * @hide 6276 */ 6277 public String getCdmaPrlVersion(int subId) { 6278 try { 6279 ITelephony service = getITelephony(); 6280 if (service != null) { 6281 return service.getCdmaPrlVersion(subId); 6282 } 6283 } catch (RemoteException e) { 6284 Log.e(TAG, "Error calling ITelephony#getCdmaPrlVersion", e); 6285 } 6286 return null; 6287 } 6288 6289 /** 6290 * Get snapshot of Telephony histograms 6291 * @return List of Telephony histograms 6292 * Requires Permission: 6293 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 6294 * Or the calling app has carrier privileges. 6295 * @hide 6296 */ 6297 @SystemApi 6298 public List<TelephonyHistogram> getTelephonyHistograms() { 6299 try { 6300 ITelephony service = getITelephony(); 6301 if (service != null) { 6302 return service.getTelephonyHistograms(); 6303 } 6304 } catch (RemoteException e) { 6305 Log.e(TAG, "Error calling ITelephony#getTelephonyHistograms", e); 6306 } 6307 return null; 6308 } 6309 6310 /** 6311 * Set the allowed carrier list for slotIndex 6312 * Require system privileges. In the future we may add this to carrier APIs. 6313 * 6314 * <p>Requires Permission: 6315 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} 6316 * 6317 * <p>This method works only on devices with {@link 6318 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 6319 * 6320 * @return The number of carriers set successfully. Should be length of 6321 * carrierList on success; -1 if carrierList null or on error. 6322 * @hide 6323 */ 6324 @SystemApi 6325 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) { 6326 try { 6327 ITelephony service = getITelephony(); 6328 if (service != null) { 6329 return service.setAllowedCarriers(slotIndex, carriers); 6330 } 6331 } catch (RemoteException e) { 6332 Log.e(TAG, "Error calling ITelephony#setAllowedCarriers", e); 6333 } catch (NullPointerException e) { 6334 Log.e(TAG, "Error calling ITelephony#setAllowedCarriers", e); 6335 } 6336 return -1; 6337 } 6338 6339 /** 6340 * Get the allowed carrier list for slotIndex. 6341 * Require system privileges. In the future we may add this to carrier APIs. 6342 * 6343 * <p>Requires Permission: 6344 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} 6345 * 6346 * <p>This method returns valid data on devices with {@link 6347 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 6348 * 6349 * @return List of {@link android.telephony.CarrierIdentifier}; empty list 6350 * means all carriers are allowed. 6351 * @hide 6352 */ 6353 @SystemApi 6354 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) { 6355 try { 6356 ITelephony service = getITelephony(); 6357 if (service != null) { 6358 return service.getAllowedCarriers(slotIndex); 6359 } 6360 } catch (RemoteException e) { 6361 Log.e(TAG, "Error calling ITelephony#getAllowedCarriers", e); 6362 } catch (NullPointerException e) { 6363 Log.e(TAG, "Error calling ITelephony#setAllowedCarriers", e); 6364 } 6365 return new ArrayList<CarrierIdentifier>(0); 6366 } 6367 6368 /** 6369 * Action set from carrier signalling broadcast receivers to enable/disable metered apns 6370 * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required 6371 * @param subId the subscription ID that this action applies to. 6372 * @param enabled control enable or disable metered apns. 6373 * @hide 6374 */ 6375 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { 6376 try { 6377 ITelephony service = getITelephony(); 6378 if (service != null) { 6379 service.carrierActionSetMeteredApnsEnabled(subId, enabled); 6380 } 6381 } catch (RemoteException e) { 6382 Log.e(TAG, "Error calling ITelephony#carrierActionSetMeteredApnsEnabled", e); 6383 } 6384 } 6385 6386 /** 6387 * Action set from carrier signalling broadcast receivers to enable/disable radio 6388 * Permissions android.Manifest.permission.MODIFY_PHONE_STATE is required 6389 * @param subId the subscription ID that this action applies to. 6390 * @param enabled control enable or disable radio. 6391 * @hide 6392 */ 6393 public void carrierActionSetRadioEnabled(int subId, boolean enabled) { 6394 try { 6395 ITelephony service = getITelephony(); 6396 if (service != null) { 6397 service.carrierActionSetRadioEnabled(subId, enabled); 6398 } 6399 } catch (RemoteException e) { 6400 Log.e(TAG, "Error calling ITelephony#carrierActionSetRadioEnabled", e); 6401 } 6402 } 6403 6404 /** 6405 * Get aggregated video call data usage since boot. 6406 * Permissions android.Manifest.permission.READ_NETWORK_USAGE_HISTORY is required. 6407 * @return total data usage in bytes 6408 * @hide 6409 */ 6410 public long getVtDataUsage() { 6411 6412 try { 6413 ITelephony service = getITelephony(); 6414 if (service != null) { 6415 return service.getVtDataUsage(); 6416 } 6417 } catch (RemoteException e) { 6418 Log.e(TAG, "Error calling getVtDataUsage", e); 6419 } 6420 return 0; 6421 } 6422 6423 /** 6424 * Policy control of data connection. Usually used when data limit is passed. 6425 * @param enabled True if enabling the data, otherwise disabling. 6426 * @param subId sub id 6427 * @hide 6428 */ 6429 public void setPolicyDataEnabled(boolean enabled, int subId) { 6430 try { 6431 ITelephony service = getITelephony(); 6432 if (service != null) { 6433 service.setPolicyDataEnabled(enabled, subId); 6434 } 6435 } catch (RemoteException e) { 6436 Log.e(TAG, "Error calling ITelephony#setPolicyDataEnabled", e); 6437 } 6438 } 6439 6440 /** 6441 * Get Client request stats which will contain statistical information 6442 * on each request made by client. 6443 * Callers require either READ_PRIVILEGED_PHONE_STATE or 6444 * READ_PHONE_STATE to retrieve the information. 6445 * @param subId sub id 6446 * @return List of Client Request Stats 6447 * @hide 6448 */ 6449 public List<ClientRequestStats> getClientRequestStats(int subId) { 6450 try { 6451 ITelephony service = getITelephony(); 6452 if (service != null) { 6453 return service.getClientRequestStats(getOpPackageName(), subId); 6454 } 6455 } catch (RemoteException e) { 6456 Log.e(TAG, "Error calling ITelephony#getClientRequestStats", e); 6457 } 6458 6459 return null; 6460 } 6461} 6462 6463