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 17 package android.telephony; 18 19 import static android.content.Context.TELECOM_SERVICE; 20 import static android.provider.Telephony.Carriers.DPC_URI; 21 import static android.provider.Telephony.Carriers.INVALID_APN_ID; 22 23 import static com.android.internal.util.Preconditions.checkNotNull; 24 25 import android.Manifest; 26 import android.annotation.BytesLong; 27 import android.annotation.CallbackExecutor; 28 import android.annotation.IntDef; 29 import android.annotation.LongDef; 30 import android.annotation.NonNull; 31 import android.annotation.Nullable; 32 import android.annotation.RequiresFeature; 33 import android.annotation.RequiresPermission; 34 import android.annotation.SdkConstant; 35 import android.annotation.SdkConstant.SdkConstantType; 36 import android.annotation.StringDef; 37 import android.annotation.SuppressAutoDoc; 38 import android.annotation.SuppressLint; 39 import android.annotation.SystemApi; 40 import android.annotation.SystemService; 41 import android.annotation.TestApi; 42 import android.annotation.WorkerThread; 43 import android.app.PendingIntent; 44 import android.app.role.RoleManager; 45 import android.compat.Compatibility; 46 import android.compat.annotation.ChangeId; 47 import android.compat.annotation.EnabledAfter; 48 import android.compat.annotation.UnsupportedAppUsage; 49 import android.content.ComponentName; 50 import android.content.Context; 51 import android.content.Intent; 52 import android.database.Cursor; 53 import android.net.ConnectivityManager; 54 import android.net.Uri; 55 import android.os.AsyncTask; 56 import android.os.Binder; 57 import android.os.Build; 58 import android.os.Bundle; 59 import android.os.Handler; 60 import android.os.IBinder; 61 import android.os.Looper; 62 import android.os.OutcomeReceiver; 63 import android.os.ParcelFileDescriptor; 64 import android.os.ParcelUuid; 65 import android.os.Parcelable; 66 import android.os.PersistableBundle; 67 import android.os.RemoteException; 68 import android.os.ResultReceiver; 69 import android.os.SystemProperties; 70 import android.os.WorkSource; 71 import android.provider.Settings.SettingNotFoundException; 72 import android.service.carrier.CarrierIdentifier; 73 import android.sysprop.TelephonyProperties; 74 import android.telecom.CallScreeningService; 75 import android.telecom.InCallService; 76 import android.telecom.PhoneAccount; 77 import android.telecom.PhoneAccountHandle; 78 import android.telecom.TelecomManager; 79 import android.telephony.Annotation.ApnType; 80 import android.telephony.Annotation.CallState; 81 import android.telephony.Annotation.CarrierPrivilegeStatus; 82 import android.telephony.Annotation.NetworkType; 83 import android.telephony.Annotation.RadioPowerState; 84 import android.telephony.Annotation.SimActivationState; 85 import android.telephony.Annotation.ThermalMitigationResult; 86 import android.telephony.Annotation.UiccAppType; 87 import android.telephony.Annotation.UiccAppTypeExt; 88 import android.telephony.CallForwardingInfo.CallForwardingReason; 89 import android.telephony.VisualVoicemailService.VisualVoicemailTask; 90 import android.telephony.data.ApnSetting; 91 import android.telephony.data.ApnSetting.MvnoType; 92 import android.telephony.data.NetworkSlicingConfig; 93 import android.telephony.emergency.EmergencyNumber; 94 import android.telephony.emergency.EmergencyNumber.EmergencyServiceCategories; 95 import android.telephony.gba.UaSecurityProtocolIdentifier; 96 import android.telephony.ims.ImsMmTelManager; 97 import android.telephony.ims.aidl.IImsConfig; 98 import android.telephony.ims.aidl.IImsRegistration; 99 import android.telephony.ims.feature.MmTelFeature; 100 import android.telephony.ims.stub.ImsRegistrationImplBase; 101 import android.text.TextUtils; 102 import android.util.Log; 103 import android.util.Pair; 104 105 import com.android.internal.annotations.GuardedBy; 106 import com.android.internal.annotations.VisibleForTesting; 107 import com.android.internal.os.BackgroundThread; 108 import com.android.internal.telephony.CellNetworkScanResult; 109 import com.android.internal.telephony.IBooleanConsumer; 110 import com.android.internal.telephony.ICallForwardingInfoCallback; 111 import com.android.internal.telephony.IIntegerConsumer; 112 import com.android.internal.telephony.INumberVerificationCallback; 113 import com.android.internal.telephony.IOns; 114 import com.android.internal.telephony.IPhoneSubInfo; 115 import com.android.internal.telephony.ISetOpportunisticDataCallback; 116 import com.android.internal.telephony.ISms; 117 import com.android.internal.telephony.ISub; 118 import com.android.internal.telephony.ITelephony; 119 import com.android.internal.telephony.IUpdateAvailableNetworksCallback; 120 import com.android.internal.telephony.OperatorInfo; 121 import com.android.internal.telephony.PhoneConstants; 122 import com.android.internal.telephony.RILConstants; 123 import com.android.internal.telephony.SmsApplication; 124 import com.android.telephony.Rlog; 125 126 import java.io.IOException; 127 import java.io.InputStream; 128 import java.io.OutputStream; 129 import java.lang.annotation.Retention; 130 import java.lang.annotation.RetentionPolicy; 131 import java.nio.file.Files; 132 import java.nio.file.Path; 133 import java.util.ArrayList; 134 import java.util.Collections; 135 import java.util.HashMap; 136 import java.util.List; 137 import java.util.Locale; 138 import java.util.Map; 139 import java.util.Objects; 140 import java.util.UUID; 141 import java.util.concurrent.Executor; 142 import java.util.concurrent.RejectedExecutionException; 143 import java.util.function.Consumer; 144 import java.util.stream.Collectors; 145 import java.util.stream.IntStream; 146 147 /** 148 * Provides access to information about the telephony services on 149 * the device. Applications can use the methods in this class to 150 * determine telephony services and states, as well as to access some 151 * types of subscriber information. Applications can also register 152 * a listener to receive notification of telephony state changes. 153 * <p> 154 * The returned TelephonyManager will use the default subscription for all calls. 155 * To call an API for a specific subscription, use {@link #createForSubscriptionId(int)}. e.g. 156 * <code> 157 * telephonyManager = defaultSubTelephonyManager.createForSubscriptionId(subId); 158 * </code> 159 * <p> 160 * Note that access to some telephony information is 161 * permission-protected. Your application cannot access the protected 162 * information unless it has the appropriate permissions declared in 163 * its manifest file. Where permissions apply, they are noted in the 164 * the methods through which you access the protected information. 165 * 166 * <p>TelephonyManager is intended for use on devices that implement 167 * {@link android.content.pm.PackageManager#FEATURE_TELEPHONY FEATURE_TELEPHONY}. On devices 168 * that do not implement this feature, the behavior is not reliable. 169 */ 170 @SystemService(Context.TELEPHONY_SERVICE) 171 public class TelephonyManager { 172 private static final String TAG = "TelephonyManager"; 173 174 private TelephonyRegistryManager mTelephonyRegistryMgr; 175 /** 176 * To expand the error codes for {@link TelephonyManager#updateAvailableNetworks} and 177 * {@link TelephonyManager#setPreferredOpportunisticDataSubscription}. 178 */ 179 @ChangeId 180 @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q) 181 private static final long CALLBACK_ON_MORE_ERROR_CODE_CHANGE = 130595455L; 182 183 /** 184 * The key to use when placing the result of {@link #requestModemActivityInfo(ResultReceiver)} 185 * into the ResultReceiver Bundle. 186 * @hide 187 */ 188 public static final String MODEM_ACTIVITY_RESULT_KEY = "controller_activity"; 189 190 /** @hide */ 191 public static final String EXCEPTION_RESULT_KEY = "exception"; 192 193 /** 194 * The process name of the Phone app as well as many other apps that use this process name, such 195 * as settings and vendor components. 196 * @hide 197 */ 198 public static final String PHONE_PROCESS_NAME = "com.android.phone"; 199 200 /** 201 * The allowed states of Wi-Fi calling. 202 * 203 * @hide 204 */ 205 public interface WifiCallingChoices { 206 /** Always use Wi-Fi calling */ 207 static final int ALWAYS_USE = 0; 208 /** Ask the user whether to use Wi-Fi on every call */ 209 static final int ASK_EVERY_TIME = 1; 210 /** Never use Wi-Fi calling */ 211 static final int NEVER_USE = 2; 212 } 213 214 /** @hide */ 215 @Retention(RetentionPolicy.SOURCE) 216 @IntDef(prefix = {"NETWORK_SELECTION_MODE_"}, 217 value = { 218 NETWORK_SELECTION_MODE_UNKNOWN, 219 NETWORK_SELECTION_MODE_AUTO, 220 NETWORK_SELECTION_MODE_MANUAL}) 221 public @interface NetworkSelectionMode {} 222 223 public static final int NETWORK_SELECTION_MODE_UNKNOWN = 0; 224 public static final int NETWORK_SELECTION_MODE_AUTO = 1; 225 public static final int NETWORK_SELECTION_MODE_MANUAL = 2; 226 227 /** The otaspMode passed to PhoneStateListener#onOtaspChanged */ 228 /** @hide */ 229 static public final int OTASP_UNINITIALIZED = 0; 230 /** @hide */ 231 static public final int OTASP_UNKNOWN = 1; 232 /** @hide */ 233 static public final int OTASP_NEEDED = 2; 234 /** @hide */ 235 static public final int OTASP_NOT_NEEDED = 3; 236 /* OtaUtil has conflict enum 4: OtaUtils.OTASP_FAILURE_SPC_RETRIES */ 237 /** @hide */ 238 static public final int OTASP_SIM_UNPROVISIONED = 5; 239 240 /** 241 * Used in carrier Wi-Fi for IMSI + IMPI encryption, this indicates a public key that's 242 * available for use in ePDG links. 243 * 244 * @hide 245 */ 246 @SystemApi 247 static public final int KEY_TYPE_EPDG = 1; 248 249 /** 250 * Used in carrier Wi-Fi for IMSI + IMPI encryption, this indicates a public key that's 251 * available for use in WLAN links. 252 * 253 * @hide 254 */ 255 @SystemApi 256 static public final int KEY_TYPE_WLAN = 2; 257 258 /** @hide */ 259 @Retention(RetentionPolicy.SOURCE) 260 @IntDef(prefix = {"KEY_TYPE_"}, value = {KEY_TYPE_EPDG, KEY_TYPE_WLAN}) 261 public @interface KeyType {} 262 263 /** 264 * No Single Radio Voice Call Continuity (SRVCC) handover is active. 265 * See TS 23.216 for more information. 266 * @hide 267 */ 268 @SystemApi 269 public static final int SRVCC_STATE_HANDOVER_NONE = -1; 270 271 /** 272 * Single Radio Voice Call Continuity (SRVCC) handover has been started on the network. 273 * See TS 23.216 for more information. 274 * @hide 275 */ 276 @SystemApi 277 public static final int SRVCC_STATE_HANDOVER_STARTED = 0; 278 279 /** 280 * Ongoing Single Radio Voice Call Continuity (SRVCC) handover has successfully completed. 281 * See TS 23.216 for more information. 282 * @hide 283 */ 284 @SystemApi 285 public static final int SRVCC_STATE_HANDOVER_COMPLETED = 1; 286 287 /** 288 * Ongoing Single Radio Voice Call Continuity (SRVCC) handover has failed. 289 * See TS 23.216 for more information. 290 * @hide 291 */ 292 @SystemApi 293 public static final int SRVCC_STATE_HANDOVER_FAILED = 2; 294 295 /** 296 * Ongoing Single Radio Voice Call Continuity (SRVCC) handover has been canceled. 297 * See TS 23.216 for more information. 298 * @hide 299 */ 300 @SystemApi 301 public static final int SRVCC_STATE_HANDOVER_CANCELED = 3; 302 303 /** 304 * A UICC card identifier used if the device does not support the operation. 305 * For example, {@link #getCardIdForDefaultEuicc()} returns this value if the device has no 306 * eUICC, or the eUICC cannot be read. 307 */ 308 public static final int UNSUPPORTED_CARD_ID = -1; 309 310 /** 311 * A UICC card identifier used before the UICC card is loaded. See 312 * {@link #getCardIdForDefaultEuicc()} and {@link UiccCardInfo#getCardId()}. 313 * <p> 314 * Note that once the UICC card is loaded, the card ID may become {@link #UNSUPPORTED_CARD_ID}. 315 */ 316 public static final int UNINITIALIZED_CARD_ID = -2; 317 318 private final Context mContext; 319 private final int mSubId; 320 @UnsupportedAppUsage 321 private SubscriptionManager mSubscriptionManager; 322 private TelephonyScanManager mTelephonyScanManager; 323 324 /** Cached service handles, cleared by resetServiceHandles() at death */ 325 private static final Object sCacheLock = new Object(); 326 327 /** @hide */ 328 private static boolean sServiceHandleCacheEnabled = true; 329 330 @GuardedBy("sCacheLock") 331 private static ITelephony sITelephony; 332 @GuardedBy("sCacheLock") 333 private static IPhoneSubInfo sIPhoneSubInfo; 334 @GuardedBy("sCacheLock") 335 private static ISub sISub; 336 @GuardedBy("sCacheLock") 337 private static ISms sISms; 338 @GuardedBy("sCacheLock") 339 private static final DeathRecipient sServiceDeath = new DeathRecipient(); 340 341 /** Enum indicating multisim variants 342 * DSDS - Dual SIM Dual Standby 343 * DSDA - Dual SIM Dual Active 344 * TSTS - Triple SIM Triple Standby 345 **/ 346 /** @hide */ 347 @UnsupportedAppUsage(implicitMember = 348 "values()[Landroid/telephony/TelephonyManager$MultiSimVariants;") 349 public enum MultiSimVariants { 350 @UnsupportedAppUsage 351 DSDS, 352 @UnsupportedAppUsage 353 DSDA, 354 @UnsupportedAppUsage 355 TSTS, 356 @UnsupportedAppUsage 357 UNKNOWN 358 }; 359 360 /** @hide */ 361 @UnsupportedAppUsage TelephonyManager(Context context)362 public TelephonyManager(Context context) { 363 this(context, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID); 364 } 365 366 /** @hide */ 367 @UnsupportedAppUsage TelephonyManager(Context context, int subId)368 public TelephonyManager(Context context, int subId) { 369 mSubId = subId; 370 Context appContext = context.getApplicationContext(); 371 if (appContext != null) { 372 if (Objects.equals(context.getAttributionTag(), appContext.getAttributionTag())) { 373 mContext = appContext; 374 } else { 375 mContext = appContext.createAttributionContext(context.getAttributionTag()); 376 } 377 } else { 378 mContext = context; 379 } 380 mSubscriptionManager = SubscriptionManager.from(mContext); 381 } 382 383 /** @hide */ 384 @UnsupportedAppUsage TelephonyManager()385 private TelephonyManager() { 386 mContext = null; 387 mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 388 } 389 390 private static TelephonyManager sInstance = new TelephonyManager(); 391 392 /** @hide 393 /* @deprecated - use getSystemService as described above */ 394 @Deprecated 395 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getDefault()396 public static TelephonyManager getDefault() { 397 return sInstance; 398 } 399 getOpPackageName()400 private String getOpPackageName() { 401 // For legacy reasons the TelephonyManager has API for getting 402 // a static instance with no context set preventing us from 403 // getting the op package name. As a workaround we do a best 404 // effort and get the context from the current activity thread. 405 if (mContext != null) { 406 return mContext.getOpPackageName(); 407 } else { 408 ITelephony telephony = getITelephony(); 409 if (telephony == null) return null; 410 try { 411 return telephony.getCurrentPackageName(); 412 } catch (RemoteException ex) { 413 return null; 414 } catch (NullPointerException ex) { 415 return null; 416 } 417 } 418 } 419 getAttributionTag()420 private String getAttributionTag() { 421 // For legacy reasons the TelephonyManager has API for getting 422 // a static instance with no context set preventing us from 423 // getting the attribution tag. 424 if (mContext != null) { 425 return mContext.getAttributionTag(); 426 } 427 return null; 428 } 429 430 /** 431 * Post a runnable to the BackgroundThread. 432 * 433 * Used to invoke user callbacks without calling into the caller's executor from the caller's 434 * calling thread context, for example to provide asynchronous error information that is 435 * generated locally (not over a binder thread). 436 * 437 * <p>This is not necessary unless you are invoking caller's code asynchronously from within 438 * the caller's thread context. 439 * 440 * @param r a runnable. 441 */ runOnBackgroundThread(@onNull Runnable r)442 private static void runOnBackgroundThread(@NonNull Runnable r) { 443 try { 444 BackgroundThread.getExecutor().execute(r); 445 } catch (RejectedExecutionException e) { 446 throw new IllegalStateException( 447 "Failed to post a callback from the caller's thread context.", e); 448 } 449 } 450 451 /** 452 * Returns the multi SIM variant 453 * Returns DSDS for Dual SIM Dual Standby 454 * Returns DSDA for Dual SIM Dual Active 455 * Returns TSTS for Triple SIM Triple Standby 456 * Returns UNKNOWN for others 457 */ 458 /** {@hide} */ 459 @UnsupportedAppUsage getMultiSimConfiguration()460 public MultiSimVariants getMultiSimConfiguration() { 461 String mSimConfig = 462 TelephonyProperties.multi_sim_config().orElse(""); 463 if (mSimConfig.equals("dsds")) { 464 return MultiSimVariants.DSDS; 465 } else if (mSimConfig.equals("dsda")) { 466 return MultiSimVariants.DSDA; 467 } else if (mSimConfig.equals("tsts")) { 468 return MultiSimVariants.TSTS; 469 } else { 470 return MultiSimVariants.UNKNOWN; 471 } 472 } 473 474 /** 475 * Returns the number of phones available. 476 * Returns 0 if none of voice, sms, data is not supported 477 * Returns 1 for Single standby mode (Single SIM functionality). 478 * Returns 2 for Dual standby mode (Dual SIM functionality). 479 * Returns 3 for Tri standby mode (Tri SIM functionality). 480 * @deprecated Use {@link #getActiveModemCount} instead. 481 */ 482 @Deprecated getPhoneCount()483 public int getPhoneCount() { 484 return getActiveModemCount(); 485 } 486 487 /** 488 * Returns the number of logical modems currently configured to be activated. 489 * 490 * Returns 0 if none of voice, sms, data is not supported 491 * Returns 1 for Single standby mode (Single SIM functionality). 492 * Returns 2 for Dual standby mode (Dual SIM functionality). 493 * Returns 3 for Tri standby mode (Tri SIM functionality). 494 */ getActiveModemCount()495 public int getActiveModemCount() { 496 int modemCount = 1; 497 switch (getMultiSimConfiguration()) { 498 case UNKNOWN: 499 modemCount = 1; 500 // check for voice and data support, 0 if not supported 501 if (!isVoiceCapable() && !isSmsCapable() && !isDataCapable()) { 502 modemCount = 0; 503 } 504 break; 505 case DSDS: 506 case DSDA: 507 modemCount = 2; 508 break; 509 case TSTS: 510 modemCount = 3; 511 break; 512 } 513 return modemCount; 514 } 515 516 /** 517 * Return how many logical modem can be potentially active simultaneously, in terms of hardware 518 * capability. 519 * It might return different value from {@link #getActiveModemCount}. For example, for a 520 * dual-SIM capable device operating in single SIM mode (only one logical modem is turned on), 521 * {@link #getActiveModemCount} returns 1 while this API returns 2. 522 */ getSupportedModemCount()523 public int getSupportedModemCount() { 524 return TelephonyProperties.max_active_modems().orElse(getActiveModemCount()); 525 } 526 527 /** 528 * Gets the maximum number of SIMs that can be active, based on the device's multisim 529 * configuration. 530 * @return 1 for single-SIM, DSDS, and TSTS devices. 2 for DSDA devices. 531 * @hide 532 */ 533 @SystemApi getMaxNumberOfSimultaneouslyActiveSims()534 public int getMaxNumberOfSimultaneouslyActiveSims() { 535 switch (getMultiSimConfiguration()) { 536 case UNKNOWN: 537 case DSDS: 538 case TSTS: 539 return 1; 540 case DSDA: 541 return 2; 542 } 543 return 1; 544 } 545 546 /** {@hide} */ 547 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) from(Context context)548 public static TelephonyManager from(Context context) { 549 return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 550 } 551 552 /** 553 * Create a new TelephonyManager object pinned to the given subscription ID. 554 * 555 * @return a TelephonyManager that uses the given subId for all calls. 556 */ createForSubscriptionId(int subId)557 public TelephonyManager createForSubscriptionId(int subId) { 558 // Don't reuse any TelephonyManager objects. 559 return new TelephonyManager(mContext, subId); 560 } 561 562 /** 563 * Create a new TelephonyManager object pinned to the subscription ID associated with the given 564 * phone account. 565 * 566 * @return a TelephonyManager that uses the given phone account for all calls, or {@code null} 567 * if the phone account does not correspond to a valid subscription ID. 568 */ 569 @Nullable createForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle)570 public TelephonyManager createForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) { 571 int subId = getSubscriptionId(phoneAccountHandle); 572 if (!SubscriptionManager.isValidSubscriptionId(subId)) { 573 return null; 574 } 575 return new TelephonyManager(mContext, subId); 576 } 577 578 /** {@hide} */ 579 @UnsupportedAppUsage isMultiSimEnabled()580 public boolean isMultiSimEnabled() { 581 return getPhoneCount() > 1; 582 } 583 584 private static final int MAXIMUM_CALL_COMPOSER_PICTURE_SIZE = 80000; 585 586 /** 587 * Indicates the maximum size of the call composure picture. 588 * 589 * Pictures sent via 590 * {@link #uploadCallComposerPicture(InputStream, String, Executor, OutcomeReceiver)} 591 * or {@link #uploadCallComposerPicture(Path, String, Executor, OutcomeReceiver)} must not 592 * exceed this size, or an error will be returned via the callback in those methods. 593 * 594 * @return Maximum file size in bytes. 595 */ getMaximumCallComposerPictureSize()596 public static @BytesLong long getMaximumCallComposerPictureSize() { 597 return MAXIMUM_CALL_COMPOSER_PICTURE_SIZE; 598 } 599 600 // 601 // Broadcast Intent actions 602 // 603 604 /** 605 * Broadcast intent action indicating that the call state 606 * on the device has changed. 607 * 608 * <p> 609 * The {@link #EXTRA_STATE} extra indicates the new call state. 610 * If a receiving app has {@link android.Manifest.permission#READ_CALL_LOG} permission, a second 611 * extra {@link #EXTRA_INCOMING_NUMBER} provides the phone number for incoming and outgoing 612 * calls as a String. 613 * <p> 614 * If the receiving app has 615 * {@link android.Manifest.permission#READ_CALL_LOG} and 616 * {@link android.Manifest.permission#READ_PHONE_STATE} permission, it will receive the 617 * broadcast twice; one with the {@link #EXTRA_INCOMING_NUMBER} populated with the phone number, 618 * and another with it blank. Due to the nature of broadcasts, you cannot assume the order 619 * in which these broadcasts will arrive, however you are guaranteed to receive two in this 620 * case. Apps which are interested in the {@link #EXTRA_INCOMING_NUMBER} can ignore the 621 * broadcasts where {@link #EXTRA_INCOMING_NUMBER} is not present in the extras (e.g. where 622 * {@link Intent#hasExtra(String)} returns {@code false}). 623 * <p class="note"> 624 * This was a {@link android.content.Context#sendStickyBroadcast sticky} 625 * broadcast in version 1.0, but it is no longer sticky. 626 * Instead, use {@link #getCallState} to synchronously query the current call state. 627 * 628 * @see #EXTRA_STATE 629 * @see #EXTRA_INCOMING_NUMBER 630 * @see #getCallState 631 */ 632 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 633 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 634 public static final String ACTION_PHONE_STATE_CHANGED = 635 "android.intent.action.PHONE_STATE"; 636 637 /** 638 * The Phone app sends this intent when a user opts to respond-via-message during an incoming 639 * call. By default, the device's default SMS app consumes this message and sends a text message 640 * to the caller. A third party app can also provide this functionality by consuming this Intent 641 * with a {@link android.app.Service} and sending the message using its own messaging system. 642 * <p>The intent contains a URI (available from {@link android.content.Intent#getData}) 643 * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:}, 644 * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the 645 * same way: the path part of the URI contains the recipient's phone number or a comma-separated 646 * set of phone numbers if there are multiple recipients. For example, {@code 647 * smsto:2065551234}.</p> 648 * 649 * <p>The intent may also contain extras for the message text (in {@link 650 * android.content.Intent#EXTRA_TEXT}) and a message subject 651 * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p> 652 * 653 * <p class="note"><strong>Note:</strong> 654 * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service} 655 * that requires the 656 * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p> 657 * <p>For example, the service that receives this intent can be declared in the manifest file 658 * with an intent filter like this:</p> 659 * <pre> 660 * <!-- Service that delivers SMS messages received from the phone "quick response" --> 661 * <service android:name=".HeadlessSmsSendService" 662 * android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" 663 * android:exported="true" > 664 * <intent-filter> 665 * <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /> 666 * <category android:name="android.intent.category.DEFAULT" /> 667 * <data android:scheme="sms" /> 668 * <data android:scheme="smsto" /> 669 * <data android:scheme="mms" /> 670 * <data android:scheme="mmsto" /> 671 * </intent-filter> 672 * </service></pre> 673 * <p> 674 * Output: nothing. 675 */ 676 @SdkConstant(SdkConstantType.SERVICE_ACTION) 677 public static final String ACTION_RESPOND_VIA_MESSAGE = 678 "android.intent.action.RESPOND_VIA_MESSAGE"; 679 680 /** 681 * The emergency dialer may choose to present activities with intent filters for this 682 * action as emergency assistance buttons that launch the activity when clicked. 683 * 684 * @hide 685 */ 686 @SystemApi 687 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 688 public static final String ACTION_EMERGENCY_ASSISTANCE = 689 "android.telephony.action.EMERGENCY_ASSISTANCE"; 690 691 /** 692 * A boolean meta-data value indicating whether the voicemail settings should be hidden in the 693 * call settings page launched by 694 * {@link android.telecom.TelecomManager#ACTION_SHOW_CALL_SETTINGS}. 695 * Dialer implementations (see {@link android.telecom.TelecomManager#getDefaultDialerPackage()}) 696 * which would also like to manage voicemail settings should set this meta-data to {@code true} 697 * in the manifest registration of their application. 698 * 699 * @see android.telecom.TelecomManager#ACTION_SHOW_CALL_SETTINGS 700 * @see #ACTION_CONFIGURE_VOICEMAIL 701 * @see #EXTRA_HIDE_PUBLIC_SETTINGS 702 */ 703 public static final String METADATA_HIDE_VOICEMAIL_SETTINGS_MENU = 704 "android.telephony.HIDE_VOICEMAIL_SETTINGS_MENU"; 705 706 /** 707 * Open the voicemail settings activity to make changes to voicemail configuration. 708 * 709 * <p> 710 * The {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra indicates which {@link PhoneAccountHandle} to 711 * configure voicemail. 712 * The {@link #EXTRA_HIDE_PUBLIC_SETTINGS} hides settings the dialer will modify through public 713 * API if set. 714 * 715 * @see #EXTRA_PHONE_ACCOUNT_HANDLE 716 * @see #EXTRA_HIDE_PUBLIC_SETTINGS 717 */ 718 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 719 public static final String ACTION_CONFIGURE_VOICEMAIL = 720 "android.telephony.action.CONFIGURE_VOICEMAIL"; 721 722 /** 723 * The boolean value indicating whether the voicemail settings activity launched by {@link 724 * #ACTION_CONFIGURE_VOICEMAIL} should hide settings accessible through public API. This is 725 * used by dialer implementations which provides their own voicemail settings UI, but still 726 * needs to expose device specific voicemail settings to the user. 727 * 728 * @see #ACTION_CONFIGURE_VOICEMAIL 729 * @see #METADATA_HIDE_VOICEMAIL_SETTINGS_MENU 730 */ 731 public static final String EXTRA_HIDE_PUBLIC_SETTINGS = 732 "android.telephony.extra.HIDE_PUBLIC_SETTINGS"; 733 734 /** 735 * @hide 736 */ 737 public static final boolean EMERGENCY_ASSISTANCE_ENABLED = true; 738 739 /** 740 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 741 * for a String containing the new call state. 742 * 743 * <p class="note"> 744 * Retrieve with 745 * {@link android.content.Intent#getStringExtra(String)}. 746 * 747 * @see #EXTRA_STATE_IDLE 748 * @see #EXTRA_STATE_RINGING 749 * @see #EXTRA_STATE_OFFHOOK 750 */ 751 public static final String EXTRA_STATE = PhoneConstants.STATE_KEY; 752 753 /** 754 * Value used with {@link #EXTRA_STATE} corresponding to 755 * {@link #CALL_STATE_IDLE}. 756 */ 757 public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString(); 758 759 /** 760 * Value used with {@link #EXTRA_STATE} corresponding to 761 * {@link #CALL_STATE_RINGING}. 762 */ 763 public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString(); 764 765 /** 766 * Value used with {@link #EXTRA_STATE} corresponding to 767 * {@link #CALL_STATE_OFFHOOK}. 768 */ 769 public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString(); 770 771 /** 772 * Extra key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 773 * for a String containing the incoming or outgoing phone number. 774 * <p> 775 * This extra is only populated for receivers of the {@link #ACTION_PHONE_STATE_CHANGED} 776 * broadcast which have been granted the {@link android.Manifest.permission#READ_CALL_LOG} and 777 * {@link android.Manifest.permission#READ_PHONE_STATE} permissions. 778 * <p> 779 * For incoming calls, the phone number is only guaranteed to be populated when the 780 * {@link #EXTRA_STATE} changes from {@link #EXTRA_STATE_IDLE} to {@link #EXTRA_STATE_RINGING}. 781 * If the incoming caller is from an unknown number, the extra will be populated with an empty 782 * string. 783 * For outgoing calls, the phone number is only guaranteed to be populated when the 784 * {@link #EXTRA_STATE} changes from {@link #EXTRA_STATE_IDLE} to {@link #EXTRA_STATE_OFFHOOK}. 785 * <p class="note"> 786 * Retrieve with 787 * {@link android.content.Intent#getStringExtra(String)}. 788 * <p> 789 * 790 * @deprecated Companion apps for wearable devices should use the {@link InCallService} API 791 * to retrieve the phone number for calls instead. Apps performing call screening should use 792 * the {@link CallScreeningService} API instead. 793 */ 794 @Deprecated 795 public static final String EXTRA_INCOMING_NUMBER = "incoming_number"; 796 797 /** 798 * Broadcast intent action indicating that call disconnect cause has changed. 799 * 800 * <p> 801 * The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause. 802 * The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause. 803 * 804 * <p class="note"> 805 * Requires the READ_PRECISE_PHONE_STATE permission. 806 * 807 * @see #EXTRA_DISCONNECT_CAUSE 808 * @see #EXTRA_PRECISE_DISCONNECT_CAUSE 809 * 810 * @hide 811 */ 812 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 813 public static final String ACTION_CALL_DISCONNECT_CAUSE_CHANGED = 814 "android.intent.action.CALL_DISCONNECT_CAUSE"; 815 816 /** 817 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast and 818 * {@link PhoneStateListener#onPreciseCallStateChanged(PreciseCallState)} for an integer 819 * containing the disconnect cause. 820 * 821 * @see DisconnectCause 822 * 823 * <p class="note"> 824 * Retrieve with 825 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 826 * 827 * @deprecated Should use the {@link TelecomManager#EXTRA_DISCONNECT_CAUSE} instead. 828 * @hide 829 */ 830 @Deprecated 831 public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause"; 832 833 /** 834 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast and 835 * {@link PhoneStateListener#onPreciseCallStateChanged(PreciseCallState)} for an integer 836 * containing the disconnect cause provided by the RIL. 837 * 838 * @see PreciseDisconnectCause 839 * 840 * <p class="note"> 841 * Retrieve with 842 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 843 * 844 * @hide 845 */ 846 public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause"; 847 848 /** 849 * Broadcast intent action for letting the default dialer to know to show voicemail 850 * notification. 851 * 852 * <p> 853 * The {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra indicates which {@link PhoneAccountHandle} the 854 * voicemail is received on. 855 * The {@link #EXTRA_NOTIFICATION_COUNT} extra indicates the total numbers of unheard 856 * voicemails. 857 * The {@link #EXTRA_VOICEMAIL_NUMBER} extra indicates the voicemail number if available. 858 * The {@link #EXTRA_CALL_VOICEMAIL_INTENT} extra is a {@link android.app.PendingIntent} that 859 * will call the voicemail number when sent. This extra will be empty if the voicemail number 860 * is not set, and {@link #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT} will be set instead. 861 * The {@link #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT} extra is a 862 * {@link android.app.PendingIntent} that will launch the voicemail settings. This extra is only 863 * available when the voicemail number is not set. 864 * The {@link #EXTRA_IS_REFRESH} extra indicates whether the notification is a refresh or a new 865 * notification. 866 * 867 * @see #EXTRA_PHONE_ACCOUNT_HANDLE 868 * @see #EXTRA_NOTIFICATION_COUNT 869 * @see #EXTRA_VOICEMAIL_NUMBER 870 * @see #EXTRA_CALL_VOICEMAIL_INTENT 871 * @see #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT 872 * @see #EXTRA_IS_REFRESH 873 */ 874 public static final String ACTION_SHOW_VOICEMAIL_NOTIFICATION = 875 "android.telephony.action.SHOW_VOICEMAIL_NOTIFICATION"; 876 877 /** 878 * The extra used with an {@link #ACTION_CONFIGURE_VOICEMAIL} and 879 * {@link #ACTION_SHOW_VOICEMAIL_NOTIFICATION} {@code Intent} to specify the 880 * {@link PhoneAccountHandle} the configuration or notification is for. 881 * <p class="note"> 882 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}. 883 */ 884 public static final String EXTRA_PHONE_ACCOUNT_HANDLE = 885 "android.telephony.extra.PHONE_ACCOUNT_HANDLE"; 886 887 /** 888 * The number of voice messages associated with the notification. 889 */ 890 public static final String EXTRA_NOTIFICATION_COUNT = 891 "android.telephony.extra.NOTIFICATION_COUNT"; 892 893 /** 894 * The voicemail number. 895 */ 896 public static final String EXTRA_VOICEMAIL_NUMBER = 897 "android.telephony.extra.VOICEMAIL_NUMBER"; 898 899 /** 900 * The intent to call voicemail. 901 */ 902 public static final String EXTRA_CALL_VOICEMAIL_INTENT = 903 "android.telephony.extra.CALL_VOICEMAIL_INTENT"; 904 905 /** 906 * The intent to launch voicemail settings. 907 */ 908 public static final String EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT = 909 "android.telephony.extra.LAUNCH_VOICEMAIL_SETTINGS_INTENT"; 910 911 /** 912 * Boolean value representing whether the {@link 913 * TelephonyManager#ACTION_SHOW_VOICEMAIL_NOTIFICATION} is new or a refresh of an existing 914 * notification. Notification refresh happens after reboot or connectivity changes. The user has 915 * already been notified for the voicemail so it should not alert the user, and should not be 916 * shown again if the user has dismissed it. 917 */ 918 public static final String EXTRA_IS_REFRESH = "android.telephony.extra.IS_REFRESH"; 919 920 /** 921 * {@link android.telecom.Connection} event used to indicate that an IMS call has be 922 * successfully handed over from WIFI to LTE. 923 * <p> 924 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 925 * The {@link Bundle} parameter is expected to be null when this connection event is used. 926 * @hide 927 */ 928 public static final String EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE = 929 "android.telephony.event.EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE"; 930 931 /** 932 * {@link android.telecom.Connection} event used to indicate that an IMS call has be 933 * successfully handed over from LTE to WIFI. 934 * <p> 935 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 936 * The {@link Bundle} parameter is expected to be null when this connection event is used. 937 * @hide 938 */ 939 public static final String EVENT_HANDOVER_VIDEO_FROM_LTE_TO_WIFI = 940 "android.telephony.event.EVENT_HANDOVER_VIDEO_FROM_LTE_TO_WIFI"; 941 942 /** 943 * {@link android.telecom.Connection} event used to indicate that an IMS call failed to be 944 * handed over from LTE to WIFI. 945 * <p> 946 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 947 * The {@link Bundle} parameter is expected to be null when this connection event is used. 948 * @hide 949 */ 950 public static final String EVENT_HANDOVER_TO_WIFI_FAILED = 951 "android.telephony.event.EVENT_HANDOVER_TO_WIFI_FAILED"; 952 953 /** 954 * {@link android.telecom.Connection} event used to indicate that a video call was downgraded to 955 * audio because the data limit was reached. 956 * <p> 957 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 958 * The {@link Bundle} parameter is expected to be null when this connection event is used. 959 * @hide 960 */ 961 public static final String EVENT_DOWNGRADE_DATA_LIMIT_REACHED = 962 "android.telephony.event.EVENT_DOWNGRADE_DATA_LIMIT_REACHED"; 963 964 /** 965 * {@link android.telecom.Connection} event used to indicate that a video call was downgraded to 966 * audio because the data was disabled. 967 * <p> 968 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 969 * The {@link Bundle} parameter is expected to be null when this connection event is used. 970 * @hide 971 */ 972 public static final String EVENT_DOWNGRADE_DATA_DISABLED = 973 "android.telephony.event.EVENT_DOWNGRADE_DATA_DISABLED"; 974 975 /** 976 * {@link android.telecom.Connection} event used to indicate that the InCall UI should notify 977 * the user when an international call is placed while on WFC only. 978 * <p> 979 * Used when the carrier config value 980 * {@link CarrierConfigManager#KEY_NOTIFY_INTERNATIONAL_CALL_ON_WFC_BOOL} is true, the device 981 * is on WFC (VoLTE not available) and an international number is dialed. 982 * <p> 983 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 984 * The {@link Bundle} parameter is expected to be null when this connection event is used. 985 * @hide 986 */ 987 public static final String EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC = 988 "android.telephony.event.EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC"; 989 990 /** 991 * {@link android.telecom.Connection} event used to indicate that an outgoing call has been 992 * forwarded to another number. 993 * <p> 994 * Sent in response to an IMS supplementary service notification indicating the call has been 995 * forwarded. 996 * <p> 997 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 998 * The {@link Bundle} parameter is expected to be null when this connection event is used. 999 * @hide 1000 */ 1001 public static final String EVENT_CALL_FORWARDED = 1002 "android.telephony.event.EVENT_CALL_FORWARDED"; 1003 1004 /** 1005 * {@link android.telecom.Connection} event used to indicate that a supplementary service 1006 * notification has been received. 1007 * <p> 1008 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1009 * The {@link Bundle} parameter is expected to include the following extras: 1010 * <ul> 1011 * <li>{@link #EXTRA_NOTIFICATION_TYPE} - the notification type.</li> 1012 * <li>{@link #EXTRA_NOTIFICATION_CODE} - the notification code.</li> 1013 * <li>{@link #EXTRA_NOTIFICATION_MESSAGE} - human-readable message associated with the 1014 * supplementary service notification.</li> 1015 * </ul> 1016 * @hide 1017 */ 1018 public static final String EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION = 1019 "android.telephony.event.EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION"; 1020 1021 /** 1022 * Integer extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} which indicates 1023 * the type of supplementary service notification which occurred. 1024 * Will be either 1025 * {@link com.android.internal.telephony.gsm.SuppServiceNotification#NOTIFICATION_TYPE_CODE_1} 1026 * or 1027 * {@link com.android.internal.telephony.gsm.SuppServiceNotification#NOTIFICATION_TYPE_CODE_2} 1028 * <p> 1029 * Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event. 1030 * @hide 1031 */ 1032 public static final String EXTRA_NOTIFICATION_TYPE = 1033 "android.telephony.extra.NOTIFICATION_TYPE"; 1034 1035 /** 1036 * Integer extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} which indicates 1037 * the supplementary service notification which occurred. 1038 * <p> 1039 * Depending on the {@link #EXTRA_NOTIFICATION_TYPE}, the code will be one of the {@code CODE_*} 1040 * codes defined in {@link com.android.internal.telephony.gsm.SuppServiceNotification}. 1041 * <p> 1042 * Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event. 1043 * @hide 1044 */ 1045 public static final String EXTRA_NOTIFICATION_CODE = 1046 "android.telephony.extra.NOTIFICATION_CODE"; 1047 1048 /** 1049 * {@link CharSequence} extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} 1050 * which contains a human-readable message which can be displayed to the user for the 1051 * supplementary service notification. 1052 * <p> 1053 * Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event. 1054 * @hide 1055 */ 1056 public static final String EXTRA_NOTIFICATION_MESSAGE = 1057 "android.telephony.extra.NOTIFICATION_MESSAGE"; 1058 1059 /* Visual voicemail protocols */ 1060 1061 /** 1062 * The OMTP protocol. 1063 */ 1064 public static final String VVM_TYPE_OMTP = "vvm_type_omtp"; 1065 1066 /** 1067 * A flavor of OMTP protocol with a different mobile originated (MO) format 1068 */ 1069 public static final String VVM_TYPE_CVVM = "vvm_type_cvvm"; 1070 1071 /** 1072 * Key in bundle returned by {@link #getVisualVoicemailPackageName()}, indicating whether visual 1073 * voicemail was enabled or disabled by the user. If the user never explicitly changed this 1074 * setting, this key will not exist. 1075 * 1076 * @see #getVisualVoicemailSettings() 1077 * @hide 1078 */ 1079 @SystemApi 1080 public static final String EXTRA_VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL = 1081 "android.telephony.extra.VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL"; 1082 1083 /** 1084 * Key in bundle returned by {@link #getVisualVoicemailPackageName()}, indicating the voicemail 1085 * access PIN scrambled during the auto provisioning process. The user is expected to reset 1086 * their PIN if this value is not {@code null}. 1087 * 1088 * @see #getVisualVoicemailSettings() 1089 * @hide 1090 */ 1091 @SystemApi 1092 public static final String EXTRA_VOICEMAIL_SCRAMBLED_PIN_STRING = 1093 "android.telephony.extra.VOICEMAIL_SCRAMBLED_PIN_STRING"; 1094 1095 /** 1096 * Broadcast action to be received by Broadcast receivers. 1097 * 1098 * Indicates multi-SIM configuration is changed. For example, it changed 1099 * from single SIM capable to dual-SIM capable (DSDS or DSDA) or triple-SIM mode. 1100 * 1101 * It doesn't indicate how many subscriptions are actually active, or which states SIMs are, 1102 * or that all steps during multi-SIM change are done. To know those information you still need 1103 * to listen to SIM_STATE changes or active subscription changes. 1104 * 1105 * See extra of {@link #EXTRA_ACTIVE_SIM_SUPPORTED_COUNT} for updated value. 1106 */ 1107 public static final String ACTION_MULTI_SIM_CONFIG_CHANGED = 1108 "android.telephony.action.MULTI_SIM_CONFIG_CHANGED"; 1109 1110 1111 /** 1112 * The number of active SIM supported by current multi-SIM config. It's not related to how many 1113 * SIM/subscriptions are currently active. 1114 * 1115 * Same value will be returned by {@link #getActiveModemCount()}. 1116 * 1117 * For single SIM mode, it's 1. 1118 * For DSDS or DSDA mode, it's 2. 1119 * For triple-SIM mode, it's 3. 1120 * 1121 * Extra of {@link #ACTION_MULTI_SIM_CONFIG_CHANGED}. 1122 * 1123 * type: integer 1124 */ 1125 public static final String EXTRA_ACTIVE_SIM_SUPPORTED_COUNT = 1126 "android.telephony.extra.ACTIVE_SIM_SUPPORTED_COUNT"; 1127 1128 /** 1129 * @hide 1130 */ 1131 public static final String USSD_RESPONSE = "USSD_RESPONSE"; 1132 1133 /** 1134 * USSD return code success. 1135 * @hide 1136 */ 1137 public static final int USSD_RETURN_SUCCESS = 100; 1138 1139 /** 1140 * Failed code returned when the mobile network has failed to complete a USSD request. 1141 * <p> 1142 * Returned via {@link TelephonyManager.UssdResponseCallback#onReceiveUssdResponseFailed( 1143 * TelephonyManager, String, int)}. 1144 */ 1145 public static final int USSD_RETURN_FAILURE = -1; 1146 1147 /** 1148 * Failure code returned when a USSD request has failed to execute because the Telephony 1149 * service is unavailable. 1150 * <p> 1151 * Returned via {@link TelephonyManager.UssdResponseCallback#onReceiveUssdResponseFailed( 1152 * TelephonyManager, String, int)}. 1153 */ 1154 public static final int USSD_ERROR_SERVICE_UNAVAIL = -2; 1155 1156 /** 1157 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which leaves the roaming 1158 * mode set to the radio default or to the user's preference if they've indicated one. 1159 */ 1160 public static final int CDMA_ROAMING_MODE_RADIO_DEFAULT = -1; 1161 /** 1162 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which only permits 1163 * connections on home networks. 1164 */ 1165 public static final int CDMA_ROAMING_MODE_HOME = 0; 1166 /** 1167 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which permits roaming on 1168 * affiliated networks. 1169 */ 1170 public static final int CDMA_ROAMING_MODE_AFFILIATED = 1; 1171 /** 1172 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which permits roaming on 1173 * any network. 1174 */ 1175 public static final int CDMA_ROAMING_MODE_ANY = 2; 1176 1177 /** @hide */ 1178 @IntDef(prefix = { "CDMA_ROAMING_MODE_" }, value = { 1179 CDMA_ROAMING_MODE_RADIO_DEFAULT, 1180 CDMA_ROAMING_MODE_HOME, 1181 CDMA_ROAMING_MODE_AFFILIATED, 1182 CDMA_ROAMING_MODE_ANY 1183 }) 1184 @Retention(RetentionPolicy.SOURCE) 1185 public @interface CdmaRoamingMode{} 1186 1187 /** 1188 * An unknown carrier id. It could either be subscription unavailable or the subscription 1189 * carrier cannot be recognized. Unrecognized carriers here means 1190 * {@link #getSimOperator() MCC+MNC} cannot be identified. 1191 */ 1192 public static final int UNKNOWN_CARRIER_ID = -1; 1193 1194 /** 1195 * An unknown carrier id list version. 1196 * @hide 1197 */ 1198 @TestApi 1199 public static final int UNKNOWN_CARRIER_ID_LIST_VERSION = -1; 1200 1201 /** 1202 * Broadcast Action: The subscription carrier identity has changed. 1203 * This intent could be sent on the following events: 1204 * <ul> 1205 * <li>Subscription absent. Carrier identity could change from a valid id to 1206 * {@link TelephonyManager#UNKNOWN_CARRIER_ID}.</li> 1207 * <li>Subscription loaded. Carrier identity could change from 1208 * {@link TelephonyManager#UNKNOWN_CARRIER_ID} to a valid id.</li> 1209 * <li>The subscription carrier is recognized after a remote update.</li> 1210 * </ul> 1211 * The intent will have the following extra values: 1212 * <ul> 1213 * <li>{@link #EXTRA_CARRIER_ID} The up-to-date carrier id of the current subscription id. 1214 * </li> 1215 * <li>{@link #EXTRA_CARRIER_NAME} The up-to-date carrier name of the current subscription. 1216 * </li> 1217 * <li>{@link #EXTRA_SUBSCRIPTION_ID} The subscription id associated with the changed carrier 1218 * identity. 1219 * </li> 1220 * </ul> 1221 * <p class="note">This is a protected intent that can only be sent by the system. 1222 */ 1223 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1224 public static final String ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED = 1225 "android.telephony.action.SUBSCRIPTION_CARRIER_IDENTITY_CHANGED"; 1226 1227 /** 1228 * An int extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} which indicates 1229 * the updated carrier id returned by {@link TelephonyManager#getSimCarrierId()}. 1230 * <p>Will be {@link TelephonyManager#UNKNOWN_CARRIER_ID} if the subscription is unavailable or 1231 * the carrier cannot be identified. 1232 */ 1233 public static final String EXTRA_CARRIER_ID = "android.telephony.extra.CARRIER_ID"; 1234 1235 /** 1236 * An string extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} which 1237 * indicates the updated carrier name of the current subscription. 1238 * @see TelephonyManager#getSimCarrierIdName() 1239 * <p>Carrier name is a user-facing name of the carrier id {@link #EXTRA_CARRIER_ID}, 1240 * usually the brand name of the subsidiary (e.g. T-Mobile). 1241 */ 1242 public static final String EXTRA_CARRIER_NAME = "android.telephony.extra.CARRIER_NAME"; 1243 1244 /** 1245 * Broadcast Action: The subscription specific carrier identity has changed. 1246 * 1247 * A specific carrier ID returns the fine-grained carrier ID of the current subscription. 1248 * It can represent the fact that a carrier may be in effect an aggregation of other carriers 1249 * (ie in an MVNO type scenario) where each of these specific carriers which are used to make 1250 * up the actual carrier service may have different carrier configurations. 1251 * A specific carrier ID could also be used, for example, in a scenario where a carrier requires 1252 * different carrier configuration for different service offering such as a prepaid plan. 1253 * 1254 * the specific carrier ID would be used for configuration purposes, but apps wishing to know 1255 * about the carrier itself should use the regular carrier ID returned by 1256 * {@link #getSimCarrierId()}. 1257 * 1258 * <p>Similar like {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED}, this intent will be 1259 * sent on the event of {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} while its also 1260 * possible to be sent without {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} when 1261 * specific carrier ID changes while carrier ID remains the same. 1262 * e.g, the same subscription switches to different IMSI could potentially change its 1263 * specific carrier ID while carrier id remains the same. 1264 * @see #getSimSpecificCarrierId() 1265 * @see #getSimCarrierId() 1266 * 1267 * The intent will have the following extra values: 1268 * <ul> 1269 * <li>{@link #EXTRA_SPECIFIC_CARRIER_ID} The up-to-date specific carrier id of the 1270 * current subscription. 1271 * </li> 1272 * <li>{@link #EXTRA_SPECIFIC_CARRIER_NAME} The up-to-date name of the specific carrier id. 1273 * </li> 1274 * <li>{@link #EXTRA_SUBSCRIPTION_ID} The subscription id associated with the changed carrier 1275 * identity. 1276 * </li> 1277 * </ul> 1278 * <p class="note">This is a protected intent that can only be sent by the system. 1279 */ 1280 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1281 public static final String ACTION_SUBSCRIPTION_SPECIFIC_CARRIER_IDENTITY_CHANGED = 1282 "android.telephony.action.SUBSCRIPTION_SPECIFIC_CARRIER_IDENTITY_CHANGED"; 1283 1284 /** 1285 * An int extra used with {@link #ACTION_SUBSCRIPTION_SPECIFIC_CARRIER_IDENTITY_CHANGED} which 1286 * indicates the updated specific carrier id returned by 1287 * {@link TelephonyManager#getSimSpecificCarrierId()}. Note, its possible specific carrier id 1288 * changes while {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} remains the same 1289 * e.g, when subscription switch to different IMSIs. 1290 * <p>Will be {@link TelephonyManager#UNKNOWN_CARRIER_ID} if the subscription is unavailable or 1291 * the carrier cannot be identified. 1292 */ 1293 public static final String EXTRA_SPECIFIC_CARRIER_ID = 1294 "android.telephony.extra.SPECIFIC_CARRIER_ID"; 1295 1296 /** 1297 * An string extra used with {@link #ACTION_SUBSCRIPTION_SPECIFIC_CARRIER_IDENTITY_CHANGED} 1298 * which indicates the updated specific carrier name returned by 1299 * {@link TelephonyManager#getSimSpecificCarrierIdName()}. 1300 * <p>it's a user-facing name of the specific carrier id {@link #EXTRA_SPECIFIC_CARRIER_ID} 1301 * e.g, Tracfone-AT&T 1302 */ 1303 public static final String EXTRA_SPECIFIC_CARRIER_NAME = 1304 "android.telephony.extra.SPECIFIC_CARRIER_NAME"; 1305 1306 /** 1307 * An int extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} to indicate the 1308 * subscription which has changed; or in general whenever a subscription ID needs specified. 1309 */ 1310 public static final String EXTRA_SUBSCRIPTION_ID = "android.telephony.extra.SUBSCRIPTION_ID"; 1311 1312 /** 1313 * Broadcast Action: The Service Provider string(s) have been updated. Activities or 1314 * services that use these strings should update their display. 1315 * 1316 * <p>The intent will have the following extra values: 1317 * <dl> 1318 * <dt>{@link #EXTRA_SHOW_PLMN}</dt> 1319 * <dd>Boolean that indicates whether the PLMN should be shown.</dd> 1320 * <dt>{@link #EXTRA_PLMN}</dt> 1321 * <dd>The operator name of the registered network, as a string.</dd> 1322 * <dt>{@link #EXTRA_SHOW_SPN}</dt> 1323 * <dd>Boolean that indicates whether the SPN should be shown.</dd> 1324 * <dt>{@link #EXTRA_SPN}</dt> 1325 * <dd>The service provider name, as a string.</dd> 1326 * <dt>{@link #EXTRA_DATA_SPN}</dt> 1327 * <dd>The service provider name for data service, as a string.</dd> 1328 * </dl> 1329 * 1330 * Note that {@link #EXTRA_SHOW_PLMN} may indicate that {@link #EXTRA_PLMN} should be displayed, 1331 * even though the value for {@link #EXTRA_PLMN} is null. This can happen, for example, if the 1332 * phone has not registered to a network yet. In this case the receiver may substitute an 1333 * appropriate placeholder string (eg, "No service"). 1334 * 1335 * It is recommended to display {@link #EXTRA_PLMN} before / above {@link #EXTRA_SPN} if 1336 * both are displayed. 1337 * 1338 * <p>Note: this is a protected intent that can only be sent by the system. 1339 * @hide 1340 */ 1341 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1342 public static final String ACTION_SERVICE_PROVIDERS_UPDATED = 1343 "android.telephony.action.SERVICE_PROVIDERS_UPDATED"; 1344 1345 /** 1346 * String intent extra to be used with {@link ACTION_SERVICE_PROVIDERS_UPDATED} to indicate 1347 * whether the PLMN should be shown. 1348 * @hide 1349 */ 1350 public static final String EXTRA_SHOW_PLMN = "android.telephony.extra.SHOW_PLMN"; 1351 1352 /** 1353 * String intent extra to be used with {@link ACTION_SERVICE_PROVIDERS_UPDATED} to indicate 1354 * the operator name of the registered network. 1355 * @hide 1356 */ 1357 public static final String EXTRA_PLMN = "android.telephony.extra.PLMN"; 1358 1359 /** 1360 * String intent extra to be used with {@link ACTION_SERVICE_PROVIDERS_UPDATED} to indicate 1361 * whether the PLMN should be shown. 1362 * @hide 1363 */ 1364 public static final String EXTRA_SHOW_SPN = "android.telephony.extra.SHOW_SPN"; 1365 1366 /** 1367 * String intent extra to be used with {@link ACTION_SERVICE_PROVIDERS_UPDATED} to indicate 1368 * the service provider name. 1369 * @hide 1370 */ 1371 public static final String EXTRA_SPN = "android.telephony.extra.SPN"; 1372 1373 /** 1374 * String intent extra to be used with {@link ACTION_SERVICE_PROVIDERS_UPDATED} to indicate 1375 * the service provider name for data service. 1376 * @hide 1377 */ 1378 public static final String EXTRA_DATA_SPN = "android.telephony.extra.DATA_SPN"; 1379 1380 /** 1381 * Broadcast intent action indicating that when data stall recovery is attempted by Telephony, 1382 * intended for report every data stall recovery step attempted. 1383 * 1384 * <p> 1385 * The {@link #EXTRA_RECOVERY_ACTION} extra indicates the action associated with the data 1386 * stall recovery. 1387 * The phone id where the data stall recovery is attempted. 1388 * 1389 * <p class="note"> 1390 * Requires the READ_PHONE_STATE permission. 1391 * 1392 * <p class="note"> 1393 * This is a protected intent that can only be sent by the system. 1394 * 1395 * @see #EXTRA_RECOVERY_ACTION 1396 * 1397 * @hide 1398 */ 1399 // TODO(b/78370030) : Restrict this to system applications only 1400 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1401 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 1402 public static final String ACTION_DATA_STALL_DETECTED = 1403 "android.intent.action.DATA_STALL_DETECTED"; 1404 1405 /** 1406 * A service action that identifies 1407 * a {@link android.service.carrier.CarrierMessagingClientService} subclass in the 1408 * AndroidManifest.xml. 1409 * 1410 * <p>See {@link android.service.carrier.CarrierMessagingClientService} for the details. 1411 */ 1412 @SdkConstant(SdkConstantType.SERVICE_ACTION) 1413 public static final String ACTION_CARRIER_MESSAGING_CLIENT_SERVICE = 1414 "android.telephony.action.CARRIER_MESSAGING_CLIENT_SERVICE"; 1415 1416 /** 1417 * An int extra used with {@link #ACTION_DATA_STALL_DETECTED} to indicate the 1418 * action associated with the data stall recovery. 1419 * 1420 * @see #ACTION_DATA_STALL_DETECTED 1421 * 1422 * @hide 1423 */ 1424 public static final String EXTRA_RECOVERY_ACTION = "recoveryAction"; 1425 1426 private static final long MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS = 60000; 1427 1428 /** 1429 * Intent sent when an error occurs that debug tools should log and possibly take further 1430 * action such as capturing vendor-specific logs. 1431 * 1432 * A privileged application that reads these events should take appropriate vendor-specific 1433 * action to record the event and collect further information to assist in analysis, debugging, 1434 * and resolution of any associated issue. 1435 * 1436 * <p>This event should not be used for generic logging or diagnostic monitoring purposes and 1437 * should generally be sent at a low rate. Instead, this mechanism should be used for the 1438 * framework to notify a debugging application that an event (such as a bug) has occured 1439 * within the framework if that event should trigger the collection and preservation of other 1440 * more detailed device state for debugging. 1441 * 1442 * <p>At most one application can receive these events and should register a receiver in 1443 * in the application manifest. For performance reasons, if no application to receive these 1444 * events is detected at boot, then these events will not be sent. 1445 * 1446 * <p>Each event will include an {@link EXTRA_ANOMALY_ID} that will uniquely identify the 1447 * event that has occurred. Each event will be sent to the diagnostic monitor only once per 1448 * boot cycle (as another optimization). 1449 * 1450 * @see #EXTRA_ANOMALY_ID 1451 * @see #EXTRA_ANOMALY_DESCRIPTION 1452 * @hide 1453 */ 1454 @SystemApi 1455 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 1456 public static final String ACTION_ANOMALY_REPORTED = 1457 "android.telephony.action.ANOMALY_REPORTED"; 1458 1459 /** 1460 * An arbitrary ParcelUuid which should be consistent for each occurrence of a DebugEvent. 1461 * 1462 * This field must be included in all {@link ACTION_ANOMALY_REPORTED} events. 1463 * 1464 * @see #ACTION_ANOMALY_REPORTED 1465 * @hide 1466 */ 1467 @SystemApi 1468 public static final String EXTRA_ANOMALY_ID = "android.telephony.extra.ANOMALY_ID"; 1469 1470 /** 1471 * A freeform string description of the Anomaly. 1472 * 1473 * This field is optional for all {@link ACTION_ANOMALY_REPORTED}s, as a guideline should not 1474 * exceed 80 characters, and should be as short as possible to convey the essence of the event. 1475 * 1476 * @see #ACTION_ANOMALY_REPORTED 1477 * @hide 1478 */ 1479 @SystemApi 1480 public static final String EXTRA_ANOMALY_DESCRIPTION = 1481 "android.telephony.extra.ANOMALY_DESCRIPTION"; 1482 1483 /** 1484 * Broadcast intent sent to indicate primary (non-opportunistic) subscription list has changed. 1485 * 1486 * @hide 1487 */ 1488 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1489 public static final String ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED = 1490 "android.telephony.action.PRIMARY_SUBSCRIPTION_LIST_CHANGED"; 1491 1492 /** 1493 * Integer intent extra to be used with {@link #ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED} 1494 * to indicate what type of SIM selection is needed. 1495 * 1496 * @hide 1497 */ 1498 public static final String EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE = 1499 "android.telephony.extra.DEFAULT_SUBSCRIPTION_SELECT_TYPE"; 1500 1501 /** @hide */ 1502 @IntDef({ 1503 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_NONE, 1504 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA, 1505 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_VOICE, 1506 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_SMS, 1507 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_ALL 1508 }) 1509 @Retention(RetentionPolicy.SOURCE) 1510 public @interface DefaultSubscriptionSelectType{} 1511 1512 /** 1513 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1514 * to indicate there's no need to re-select any default subscription. 1515 * @hide 1516 */ 1517 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_NONE = 0; 1518 1519 /** 1520 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1521 * to indicate there's a need to select default data subscription. 1522 * @hide 1523 */ 1524 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA = 1; 1525 1526 /** 1527 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1528 * to indicate there's a need to select default voice call subscription. 1529 * @hide 1530 */ 1531 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_VOICE = 2; 1532 1533 /** 1534 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1535 * to indicate there's a need to select default sms subscription. 1536 * @hide 1537 */ 1538 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_SMS = 3; 1539 1540 /** 1541 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1542 * to indicate user to decide whether current SIM should be preferred for all 1543 * data / voice / sms. {@link #EXTRA_SUBSCRIPTION_ID} will specified to indicate 1544 * which subscription should be the default subscription. 1545 * @hide 1546 */ 1547 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_ALL = 4; 1548 1549 /** 1550 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1551 * to indicate that default subscription for data/sms/voice is now determined, that 1552 * it should dismiss any dialog or pop-ups that is asking user to select default sub. 1553 * This is used when, for example, opportunistic subscription is configured. At that 1554 * time the primary becomes default sub there's no need to ask user to select anymore. 1555 * @hide 1556 */ 1557 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS = 5; 1558 1559 /** 1560 * Integer intent extra to be used with {@link #ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED} 1561 * to indicate if the SIM combination in DSDS has limitation or compatible issue. 1562 * e.g. two CDMA SIMs may disrupt each other's voice call in certain scenarios. 1563 * 1564 * @hide 1565 */ 1566 public static final String EXTRA_SIM_COMBINATION_WARNING_TYPE = 1567 "android.telephony.extra.SIM_COMBINATION_WARNING_TYPE"; 1568 1569 /** @hide */ 1570 @IntDef({ 1571 EXTRA_SIM_COMBINATION_WARNING_TYPE_NONE, 1572 EXTRA_SIM_COMBINATION_WARNING_TYPE_DUAL_CDMA 1573 }) 1574 @Retention(RetentionPolicy.SOURCE) 1575 public @interface SimCombinationWarningType{} 1576 1577 /** 1578 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1579 * to indicate there's no SIM combination warning. 1580 * @hide 1581 */ 1582 public static final int EXTRA_SIM_COMBINATION_WARNING_TYPE_NONE = 0; 1583 1584 /** 1585 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1586 * to indicate two active SIMs are both CDMA hence there might be functional limitation. 1587 * @hide 1588 */ 1589 public static final int EXTRA_SIM_COMBINATION_WARNING_TYPE_DUAL_CDMA = 1; 1590 1591 /** 1592 * String intent extra to be used with {@link #ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED} 1593 * to indicate what's the name of SIM combination it has limitation or compatible issue. 1594 * e.g. two CDMA SIMs may disrupt each other's voice call in certain scenarios, and the 1595 * name will be "operator1 & operator2". 1596 * 1597 * @hide 1598 */ 1599 public static final String EXTRA_SIM_COMBINATION_NAMES = 1600 "android.telephony.extra.SIM_COMBINATION_NAMES"; 1601 1602 /** 1603 * <p>Broadcast Action: The emergency callback mode is changed. 1604 * <ul> 1605 * <li><em>EXTRA_PHONE_IN_ECM_STATE</em> - A boolean value,true=phone in ECM, 1606 * false=ECM off</li> 1607 * </ul> 1608 * <p class="note"> 1609 * You can <em>not</em> receive this through components declared 1610 * in manifests, only by explicitly registering for it with 1611 * {@link android.content.Context#registerReceiver(android.content.BroadcastReceiver, 1612 * android.content.IntentFilter) Context.registerReceiver()}. 1613 * 1614 * <p class="note">This is a protected intent that can only be sent by the system. 1615 * 1616 * @see #EXTRA_PHONE_IN_ECM_STATE 1617 * 1618 * @hide 1619 */ 1620 @SystemApi 1621 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1622 @SuppressLint("ActionValue") 1623 public static final String ACTION_EMERGENCY_CALLBACK_MODE_CHANGED = 1624 "android.intent.action.EMERGENCY_CALLBACK_MODE_CHANGED"; 1625 1626 1627 /** 1628 * Extra included in {@link #ACTION_EMERGENCY_CALLBACK_MODE_CHANGED}. 1629 * Indicates whether the phone is in an emergency phone state. 1630 * 1631 * @hide 1632 */ 1633 @SystemApi 1634 public static final String EXTRA_PHONE_IN_ECM_STATE = 1635 "android.telephony.extra.PHONE_IN_ECM_STATE"; 1636 1637 /** 1638 * Broadcast action sent when a data connection is redirected with validation failure. 1639 * 1640 * This action is intended for sim/account status checks and only sent to the carrier apps 1641 * specified in the carrier config for the subscription ID that's attached to this intent. 1642 * 1643 * The intent will have the following extra values: 1644 * <ul> 1645 * <li>{@link #EXTRA_APN_TYPE}</li><dd>An integer indicating the apn type.</dd> 1646 * <li>{@link #EXTRA_REDIRECTION_URL}</li><dd>A string indicating the redirection url</dd> 1647 * <li>{@link SubscriptionManager#EXTRA_SUBSCRIPTION_INDEX}</li> 1648 * <dd>The subscription ID on which the validation failure happened.</dd> 1649 * </ul> 1650 * <p class="note">This is a protected intent that can only be sent by the system.</p> 1651 */ 1652 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1653 public static final String ACTION_CARRIER_SIGNAL_REDIRECTED = 1654 "android.telephony.action.CARRIER_SIGNAL_REDIRECTED"; 1655 1656 /** 1657 * Broadcast action sent when a data connection setup fails. 1658 * 1659 * This action is intended for sim/account status checks and only sent to the carrier apps 1660 * specified in the carrier config for the subscription ID that's attached to this intent. 1661 * 1662 * The intent will have the following extra values: 1663 * <ul> 1664 * <li>{@link #EXTRA_APN_TYPE}</li><dd>An integer indicating the apn type.</dd> 1665 * <li>{@link #EXTRA_DATA_FAIL_CAUSE}</li><dd>A integer indicating the data fail cause.</dd> 1666 * <li>{@link SubscriptionManager#EXTRA_SUBSCRIPTION_INDEX}</li> 1667 * <dd>The subscription ID on which the data setup failure happened.</dd> 1668 * </ul> 1669 * <p class="note">This is a protected intent that can only be sent by the system. </p> 1670 */ 1671 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1672 public static final String ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED = 1673 "android.telephony.action.CARRIER_SIGNAL_REQUEST_NETWORK_FAILED"; 1674 1675 /** 1676 * Broadcast action sent when a PCO value becomes available from the modem. 1677 * 1678 * This action is intended for sim/account status checks and only sent to the carrier apps 1679 * specified in the carrier config for the subscription ID that's attached to this intent. 1680 * 1681 * The intent will have the following extra values:</p> 1682 * <ul> 1683 * <li>{@link #EXTRA_APN_TYPE}</li><dd>An integer indicating the apn type.</dd> 1684 * <li>{@link #EXTRA_APN_PROTOCOL}</li><dd>An integer indicating the protocol of the apn 1685 * connection</dd> 1686 * <li>{@link #EXTRA_PCO_ID}</li><dd>An integer indicating the PCO id for the data.</dd> 1687 * <li>{@link #EXTRA_PCO_VALUE}</li><dd>A byte array of PCO data read from modem.</dd> 1688 * <li>{@link SubscriptionManager#EXTRA_SUBSCRIPTION_INDEX}</li> 1689 * <dd>The subscription ID for which the PCO info was received.</dd> 1690 * </ul> 1691 * <p class="note">This is a protected intent that can only be sent by the system. </p> 1692 */ 1693 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1694 public static final String ACTION_CARRIER_SIGNAL_PCO_VALUE = 1695 "android.telephony.action.CARRIER_SIGNAL_PCO_VALUE"; 1696 1697 /** 1698 * Broadcast action sent when the availability of the system default network changes. 1699 * 1700 * @see ConnectivityManager#registerDefaultNetworkCallback(ConnectivityManager.NetworkCallback) 1701 * 1702 * This action is intended for carrier apps to set/reset carrier actions. It is only sent to the 1703 * carrier apps specified in the carrier config for the subscription ID attached to this intent. 1704 * 1705 * The intent will have the following extra values:</p> 1706 * <ul> 1707 * <li>{@link #EXTRA_DEFAULT_NETWORK_AVAILABLE}</li> 1708 * <dd>{@code true} if the default network is now available, {@code false} otherwise.</dd> 1709 * <li>{@link SubscriptionManager#EXTRA_SUBSCRIPTION_INDEX}</li> 1710 * <dd>The subscription ID on which the default network availability changed.</dd> 1711 * </ul> 1712 * <p class="note">This is a protected intent that can only be sent by the system. </p> 1713 */ 1714 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1715 public static final String ACTION_CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE = 1716 "android.telephony.action.CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE"; 1717 1718 /** 1719 * Broadcast action sent when carrier apps should reset their internal state. 1720 * 1721 * Sent when certain events such as turning on/off mobile data, removing the SIM, etc. require 1722 * carrier apps to reset their state. 1723 * 1724 * This action is intended to signal carrier apps to perform cleanup operations. It is only sent 1725 * to the carrier apps specified in the carrier config for the subscription ID attached to 1726 * this intent. 1727 * 1728 * The intent will have the following extra values:</p> 1729 * <ul> 1730 * <li>{@link SubscriptionManager#EXTRA_SUBSCRIPTION_INDEX}</li> 1731 * <dd>The subscription ID for which state should be reset.</dd> 1732 * </ul> 1733 * <p class="note">This is a protected intent that can only be sent by the system.</p> 1734 */ 1735 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1736 public static final String ACTION_CARRIER_SIGNAL_RESET = 1737 "android.telephony.action.CARRIER_SIGNAL_RESET"; 1738 1739 /** 1740 * String extra containing the redirection URL sent with 1741 * {@link #ACTION_CARRIER_SIGNAL_REDIRECTED}. 1742 */ 1743 public static final String EXTRA_REDIRECTION_URL = "android.telephony.extra.REDIRECTION_URL"; 1744 1745 /** 1746 * An integer extra containing the data fail cause. 1747 * 1748 * Sent with {@link #ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED}. See {@link DataFailCause} 1749 * for a list of possible values. 1750 */ 1751 public static final String EXTRA_DATA_FAIL_CAUSE = "android.telephony.extra.DATA_FAIL_CAUSE"; 1752 1753 /** 1754 * An integer extra containing the APN type. 1755 * 1756 * Sent with the {@link #ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED}, 1757 * {@link #ACTION_CARRIER_SIGNAL_REDIRECTED}, and {@link #ACTION_CARRIER_SIGNAL_PCO_VALUE} 1758 * broadcasts. 1759 * See the {@code TYPE_} constants in {@link ApnSetting} for a list of possible values. 1760 */ 1761 public static final String EXTRA_APN_TYPE = "android.telephony.extra.APN_TYPE"; 1762 1763 /** 1764 * An integer extra containing the protocol of the apn connection. 1765 * 1766 * Sent with the {@link #ACTION_CARRIER_SIGNAL_PCO_VALUE} broadcast. 1767 * See the {@code PROTOCOL_*} constants in {@link ApnSetting} for a list of possible values. 1768 */ 1769 public static final String EXTRA_APN_PROTOCOL = "android.telephony.extra.APN_PROTOCOL"; 1770 1771 /** 1772 * An integer extra indicating the ID for the PCO data. 1773 * Sent with the {@link #ACTION_CARRIER_SIGNAL_PCO_VALUE} broadcast. 1774 */ 1775 public static final String EXTRA_PCO_ID = "android.telephony.extra.PCO_ID"; 1776 1777 /** 1778 * A byte array extra containing PCO data read from the modem. 1779 * Sent with the {@link #ACTION_CARRIER_SIGNAL_PCO_VALUE} broadcast. 1780 */ 1781 public static final String EXTRA_PCO_VALUE = "android.telephony.extra.PCO_VALUE"; 1782 1783 /** 1784 * A boolean extra indicating the availability of the default network. 1785 * Sent with the {@link #ACTION_CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE} broadcast. 1786 */ 1787 public static final String EXTRA_DEFAULT_NETWORK_AVAILABLE = 1788 "android.telephony.extra.DEFAULT_NETWORK_AVAILABLE"; 1789 1790 /** 1791 * <p>Broadcast Action: The emergency call state is changed. 1792 * <ul> 1793 * <li><em>EXTRA_PHONE_IN_EMERGENCY_CALL</em> - A boolean value, true if phone in emergency 1794 * call, false otherwise</li> 1795 * </ul> 1796 * <p class="note"> 1797 * You can <em>not</em> receive this through components declared 1798 * in manifests, only by explicitly registering for it with 1799 * {@link android.content.Context#registerReceiver(android.content.BroadcastReceiver, 1800 * android.content.IntentFilter) Context.registerReceiver()}. 1801 * 1802 * <p class="note">This is a protected intent that can only be sent by the system. 1803 * 1804 * @see #EXTRA_PHONE_IN_EMERGENCY_CALL 1805 * 1806 * @hide 1807 */ 1808 @SystemApi 1809 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1810 @SuppressLint("ActionValue") 1811 public static final String ACTION_EMERGENCY_CALL_STATE_CHANGED = 1812 "android.intent.action.EMERGENCY_CALL_STATE_CHANGED"; 1813 1814 1815 /** 1816 * Extra included in {@link #ACTION_EMERGENCY_CALL_STATE_CHANGED}. 1817 * It indicates whether the phone is making an emergency call. 1818 * 1819 * @hide 1820 */ 1821 @SystemApi 1822 public static final String EXTRA_PHONE_IN_EMERGENCY_CALL = 1823 "android.telephony.extra.PHONE_IN_EMERGENCY_CALL"; 1824 1825 /** 1826 * <p>Broadcast Action: It indicates the Emergency callback mode blocks datacall/sms 1827 * <p class="note">. 1828 * This is to pop up a notice to show user that the phone is in emergency callback mode 1829 * and data calls and outgoing sms are blocked. 1830 * 1831 * <p class="note">This is a protected intent that can only be sent by the system. 1832 * 1833 * @hide 1834 */ 1835 @SystemApi 1836 public static final String ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS = 1837 "android.telephony.action.SHOW_NOTICE_ECM_BLOCK_OTHERS"; 1838 1839 /** 1840 * Broadcast Action: The default data subscription has changed in a multi-SIM device. 1841 * This has the following extra values:</p> 1842 * <ul> 1843 * <li><em>subscription</em> - A int, the current data default subscription.</li> 1844 * </ul> 1845 * 1846 * @hide 1847 */ 1848 @SystemApi 1849 @SuppressLint("ActionValue") 1850 public static final String ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED = 1851 "android.intent.action.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED"; 1852 1853 /** 1854 * Broadcast Action: The default voice subscription has changed in a mult-SIm device. 1855 * This has the following extra values:</p> 1856 * <ul> 1857 * <li><em>subscription</em> - A int, the current voice default subscription.</li> 1858 * </ul> 1859 * 1860 * @hide 1861 */ 1862 @SystemApi 1863 @SuppressLint("ActionValue") 1864 public static final String ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED = 1865 "android.intent.action.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED"; 1866 1867 /** 1868 * Broadcast Action: This triggers a client initiated OMA-DM session to the OMA server. 1869 * <p class="note"> 1870 * Open Mobile Alliance (OMA) Device Management (DM). 1871 * 1872 * This intent is used by the system components to trigger OMA-DM 1873 * 1874 * @hide 1875 */ 1876 @SystemApi 1877 @SuppressLint("ActionValue") 1878 public static final String ACTION_REQUEST_OMADM_CONFIGURATION_UPDATE = 1879 "com.android.omadm.service.CONFIGURATION_UPDATE"; 1880 1881 // 1882 // 1883 // Device Info 1884 // 1885 // 1886 1887 /** 1888 * Returns the software version number for the device, for example, 1889 * the IMEI/SV for GSM phones. Return null if the software version is 1890 * not available. 1891 * <p> 1892 * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}. 1893 */ 1894 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 1895 @Nullable getDeviceSoftwareVersion()1896 public String getDeviceSoftwareVersion() { 1897 return getDeviceSoftwareVersion(getSlotIndex()); 1898 } 1899 1900 /** 1901 * Returns the software version number for the device, for example, 1902 * the IMEI/SV for GSM phones. Return null if the software version is 1903 * not available. 1904 * <p> 1905 * Requires Permission: READ_PHONE_STATE. 1906 * 1907 * @param slotIndex of which deviceID is returned 1908 * 1909 * @hide 1910 */ 1911 @SystemApi 1912 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 1913 @Nullable getDeviceSoftwareVersion(int slotIndex)1914 public String getDeviceSoftwareVersion(int slotIndex) { 1915 ITelephony telephony = getITelephony(); 1916 if (telephony == null) return null; 1917 1918 try { 1919 return telephony.getDeviceSoftwareVersionForSlot(slotIndex, getOpPackageName(), 1920 getAttributionTag()); 1921 } catch (RemoteException ex) { 1922 return null; 1923 } catch (NullPointerException ex) { 1924 return null; 1925 } 1926 } 1927 1928 /** 1929 * Returns the unique device ID, for example, the IMEI for GSM and the MEID 1930 * or ESN for CDMA phones. Return null if device ID is not available. 1931 * 1932 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 1933 * restrictions, and apps are recommended to use resettable identifiers (see <a 1934 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 1935 * method can be invoked if one of the following requirements is met: 1936 * <ul> 1937 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 1938 * is a privileged permission that can only be granted to apps preloaded on the device. 1939 * <li>If the calling app is the device owner of a fully-managed device, a profile 1940 * owner of an organization-owned device, or their delegates (see {@link 1941 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 1942 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) on any 1943 * active subscription. 1944 * <li>If the calling app is the default SMS role holder (see {@link 1945 * RoleManager#isRoleHeld(String)}). 1946 * </ul> 1947 * 1948 * <p>If the calling app does not meet one of these requirements then this method will behave 1949 * as follows: 1950 * 1951 * <ul> 1952 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 1953 * READ_PHONE_STATE permission then null is returned.</li> 1954 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 1955 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 1956 * higher, then a SecurityException is thrown.</li> 1957 * </ul> 1958 * 1959 * @deprecated Use {@link #getImei} which returns IMEI for GSM or {@link #getMeid} which returns 1960 * MEID for CDMA. 1961 */ 1962 @Deprecated 1963 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 1964 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getDeviceId()1965 public String getDeviceId() { 1966 try { 1967 ITelephony telephony = getITelephony(); 1968 if (telephony == null) 1969 return null; 1970 return telephony.getDeviceIdWithFeature(mContext.getOpPackageName(), 1971 mContext.getAttributionTag()); 1972 } catch (RemoteException ex) { 1973 return null; 1974 } catch (NullPointerException ex) { 1975 return null; 1976 } 1977 } 1978 1979 /** 1980 * Returns the unique device ID of a subscription, for example, the IMEI for 1981 * GSM and the MEID for CDMA phones. Return null if device ID is not available. 1982 * 1983 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 1984 * restrictions, and apps are recommended to use resettable identifiers (see <a 1985 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 1986 * method can be invoked if one of the following requirements is met: 1987 * <ul> 1988 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 1989 * is a privileged permission that can only be granted to apps preloaded on the device. 1990 * <li>If the calling app is the device owner of a fully-managed device, a profile 1991 * owner of an organization-owned device, or their delegates (see {@link 1992 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 1993 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) on any 1994 * active subscription. 1995 * <li>If the calling app is the default SMS role holder (see {@link 1996 * RoleManager#isRoleHeld(String)}). 1997 * </ul> 1998 * 1999 * <p>If the calling app does not meet one of these requirements then this method will behave 2000 * as follows: 2001 * 2002 * <ul> 2003 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 2004 * READ_PHONE_STATE permission then null is returned.</li> 2005 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 2006 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 2007 * higher, then a SecurityException is thrown.</li> 2008 * </ul> 2009 * 2010 * @param slotIndex of which deviceID is returned 2011 * 2012 * @deprecated Use {@link #getImei} which returns IMEI for GSM or {@link #getMeid} which returns 2013 * MEID for CDMA. 2014 */ 2015 @Deprecated 2016 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 2017 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getDeviceId(int slotIndex)2018 public String getDeviceId(int slotIndex) { 2019 // FIXME this assumes phoneId == slotIndex 2020 try { 2021 IPhoneSubInfo info = getSubscriberInfoService(); 2022 if (info == null) 2023 return null; 2024 return info.getDeviceIdForPhone(slotIndex, mContext.getOpPackageName(), 2025 mContext.getAttributionTag()); 2026 } catch (RemoteException ex) { 2027 return null; 2028 } catch (NullPointerException ex) { 2029 return null; 2030 } 2031 } 2032 2033 /** 2034 * Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not 2035 * available. 2036 * 2037 * See {@link #getImei(int)} for details on the required permissions and behavior 2038 * when the caller does not hold sufficient permissions. 2039 */ 2040 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 2041 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getImei()2042 public String getImei() { 2043 return getImei(getSlotIndex()); 2044 } 2045 2046 /** 2047 * Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not 2048 * available. 2049 * 2050 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 2051 * restrictions, and apps are recommended to use resettable identifiers (see <a 2052 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 2053 * method can be invoked if one of the following requirements is met: 2054 * <ul> 2055 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 2056 * is a privileged permission that can only be granted to apps preloaded on the device. 2057 * <li>If the calling app is the device owner of a fully-managed device, a profile 2058 * owner of an organization-owned device, or their delegates (see {@link 2059 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 2060 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) on any 2061 * active subscription. 2062 * <li>If the calling app is the default SMS role holder (see {@link 2063 * RoleManager#isRoleHeld(String)}). 2064 * <li>If the calling app has been granted the 2065 * {@link Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} permission. 2066 * </ul> 2067 * 2068 * <p>If the calling app does not meet one of these requirements then this method will behave 2069 * as follows: 2070 * 2071 * <ul> 2072 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 2073 * READ_PHONE_STATE permission then null is returned.</li> 2074 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 2075 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 2076 * higher, then a SecurityException is thrown.</li> 2077 * </ul> 2078 * 2079 * @param slotIndex of which IMEI is returned 2080 */ 2081 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 2082 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getImei(int slotIndex)2083 public String getImei(int slotIndex) { 2084 ITelephony telephony = getITelephony(); 2085 if (telephony == null) return null; 2086 2087 try { 2088 return telephony.getImeiForSlot(slotIndex, getOpPackageName(), getAttributionTag()); 2089 } catch (RemoteException ex) { 2090 return null; 2091 } catch (NullPointerException ex) { 2092 return null; 2093 } 2094 } 2095 2096 /** 2097 * Returns the Type Allocation Code from the IMEI. Return null if Type Allocation Code is not 2098 * available. 2099 */ 2100 @Nullable getTypeAllocationCode()2101 public String getTypeAllocationCode() { 2102 return getTypeAllocationCode(getSlotIndex()); 2103 } 2104 2105 /** 2106 * Returns the Type Allocation Code from the IMEI. Return null if Type Allocation Code is not 2107 * available. 2108 * 2109 * @param slotIndex of which Type Allocation Code is returned 2110 */ 2111 @Nullable getTypeAllocationCode(int slotIndex)2112 public String getTypeAllocationCode(int slotIndex) { 2113 ITelephony telephony = getITelephony(); 2114 if (telephony == null) return null; 2115 2116 try { 2117 return telephony.getTypeAllocationCodeForSlot(slotIndex); 2118 } catch (RemoteException ex) { 2119 return null; 2120 } catch (NullPointerException ex) { 2121 return null; 2122 } 2123 } 2124 2125 /** 2126 * Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. 2127 * 2128 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 2129 * restrictions, and apps are recommended to use resettable identifiers (see <a 2130 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 2131 * method can be invoked if one of the following requirements is met: 2132 * <ul> 2133 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 2134 * is a privileged permission that can only be granted to apps preloaded on the device. 2135 * <li>If the calling app is the device owner of a fully-managed device, a profile 2136 * owner of an organization-owned device, or their delegates (see {@link 2137 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 2138 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) on any 2139 * active subscription. 2140 * <li>If the calling app is the default SMS role holder (see {@link 2141 * RoleManager#isRoleHeld(String)}). 2142 * </ul> 2143 * 2144 * <p>If the calling app does not meet one of these requirements then this method will behave 2145 * as follows: 2146 * 2147 * <ul> 2148 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 2149 * READ_PHONE_STATE permission then null is returned.</li> 2150 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 2151 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 2152 * higher, then a SecurityException is thrown.</li> 2153 * </ul> 2154 */ 2155 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 2156 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getMeid()2157 public String getMeid() { 2158 return getMeid(getSlotIndex()); 2159 } 2160 2161 /** 2162 * Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. 2163 * 2164 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 2165 * restrictions, and apps are recommended to use resettable identifiers (see <a 2166 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 2167 * method can be invoked if one of the following requirements is met: 2168 * <ul> 2169 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 2170 * is a privileged permission that can only be granted to apps preloaded on the device. 2171 * <li>If the calling app is the device owner of a fully-managed device, a profile 2172 * owner of an organization-owned device, or their delegates (see {@link 2173 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 2174 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) on any 2175 * active subscription. 2176 * <li>If the calling app is the default SMS role holder (see {@link 2177 * RoleManager#isRoleHeld(String)}). 2178 * </ul> 2179 * 2180 * <p>If the calling app does not meet one of these requirements then this method will behave 2181 * as follows: 2182 * 2183 * <ul> 2184 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 2185 * READ_PHONE_STATE permission then null is returned.</li> 2186 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 2187 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 2188 * higher, then a SecurityException is thrown.</li> 2189 * </ul> 2190 * 2191 * @param slotIndex of which MEID is returned 2192 */ 2193 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 2194 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getMeid(int slotIndex)2195 public String getMeid(int slotIndex) { 2196 ITelephony telephony = getITelephony(); 2197 if (telephony == null) return null; 2198 2199 try { 2200 String meid = telephony.getMeidForSlot(slotIndex, getOpPackageName(), 2201 getAttributionTag()); 2202 if (TextUtils.isEmpty(meid)) { 2203 Log.d(TAG, "getMeid: return null because MEID is not available"); 2204 return null; 2205 } 2206 return meid; 2207 } catch (RemoteException ex) { 2208 return null; 2209 } catch (NullPointerException ex) { 2210 return null; 2211 } 2212 } 2213 2214 /** 2215 * Returns the Manufacturer Code from the MEID. Return null if Manufacturer Code is not 2216 * available. 2217 */ 2218 @Nullable getManufacturerCode()2219 public String getManufacturerCode() { 2220 return getManufacturerCode(getSlotIndex()); 2221 } 2222 2223 /** 2224 * Returns the Manufacturer Code from the MEID. Return null if Manufacturer Code is not 2225 * available. 2226 * 2227 * @param slotIndex of which Type Allocation Code is returned 2228 */ 2229 @Nullable getManufacturerCode(int slotIndex)2230 public String getManufacturerCode(int slotIndex) { 2231 ITelephony telephony = getITelephony(); 2232 if (telephony == null) return null; 2233 2234 try { 2235 return telephony.getManufacturerCodeForSlot(slotIndex); 2236 } catch (RemoteException ex) { 2237 return null; 2238 } catch (NullPointerException ex) { 2239 return null; 2240 } 2241 } 2242 2243 /** 2244 * Returns the Network Access Identifier (NAI). Return null if NAI is not available. 2245 * 2246 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 2247 * restrictions, and apps are recommended to use resettable identifiers (see <a 2248 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 2249 * method can be invoked if one of the following requirements is met: 2250 * <ul> 2251 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 2252 * is a privileged permission that can only be granted to apps preloaded on the device. 2253 * <li>If the calling app is the device owner of a fully-managed device, a profile 2254 * owner of an organization-owned device, or their delegates (see {@link 2255 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 2256 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 2257 * <li>If the calling app is the default SMS role holder (see {@link 2258 * RoleManager#isRoleHeld(String)}). 2259 * </ul> 2260 * 2261 * <p>If the calling app does not meet one of these requirements then this method will behave 2262 * as follows: 2263 * 2264 * <ul> 2265 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 2266 * READ_PHONE_STATE permission then null is returned.</li> 2267 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 2268 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 2269 * higher, then a SecurityException is thrown.</li> 2270 * </ul> 2271 */ 2272 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 2273 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getNai()2274 public String getNai() { 2275 return getNaiBySubscriberId(getSubId()); 2276 } 2277 2278 /** 2279 * Returns the NAI. Return null if NAI is not available. 2280 * 2281 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 2282 * restrictions, and apps are recommended to use resettable identifiers (see <a 2283 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 2284 * method can be invoked if one of the following requirements is met: 2285 * <ul> 2286 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 2287 * is a privileged permission that can only be granted to apps preloaded on the device. 2288 * <li>If the calling app is the device owner of a fully-managed device, a profile 2289 * owner of an organization-owned device, or their delegates (see {@link 2290 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 2291 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 2292 * <li>If the calling app is the default SMS role holder (see {@link 2293 * RoleManager#isRoleHeld(String)}). 2294 * </ul> 2295 * 2296 * <p>If the calling app does not meet one of these requirements then this method will behave 2297 * as follows: 2298 * 2299 * <ul> 2300 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 2301 * READ_PHONE_STATE permission then null is returned.</li> 2302 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 2303 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 2304 * higher, then a SecurityException is thrown.</li> 2305 * </ul> 2306 * 2307 * @param slotIndex of which Nai is returned 2308 */ 2309 /** {@hide}*/ 2310 @UnsupportedAppUsage getNai(int slotIndex)2311 public String getNai(int slotIndex) { 2312 int[] subId = SubscriptionManager.getSubId(slotIndex); 2313 if (subId == null) { 2314 return null; 2315 } 2316 return getNaiBySubscriberId(subId[0]); 2317 } 2318 getNaiBySubscriberId(int subId)2319 private String getNaiBySubscriberId(int subId) { 2320 try { 2321 IPhoneSubInfo info = getSubscriberInfoService(); 2322 if (info == null) 2323 return null; 2324 String nai = info.getNaiForSubscriber(subId, mContext.getOpPackageName(), 2325 mContext.getAttributionTag()); 2326 if (Log.isLoggable(TAG, Log.VERBOSE)) { 2327 Rlog.v(TAG, "Nai = " + nai); 2328 } 2329 return nai; 2330 } catch (RemoteException ex) { 2331 return null; 2332 } catch (NullPointerException ex) { 2333 return null; 2334 } 2335 } 2336 2337 /** 2338 * Returns the current location of the device. 2339 *<p> 2340 * If there is only one radio in the device and that radio has an LTE connection, 2341 * this method will return null. The implementation must not to try add LTE 2342 * identifiers into the existing cdma/gsm classes. 2343 *<p> 2344 * @return Current location of the device or null if not available. 2345 * 2346 * @deprecated use {@link #getAllCellInfo} instead, which returns a superset of this API. 2347 */ 2348 @Deprecated 2349 @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) getCellLocation()2350 public CellLocation getCellLocation() { 2351 try { 2352 ITelephony telephony = getITelephony(); 2353 if (telephony == null) { 2354 Rlog.d(TAG, "getCellLocation returning null because telephony is null"); 2355 return null; 2356 } 2357 2358 CellIdentity cellIdentity = telephony.getCellLocation(mContext.getOpPackageName(), 2359 mContext.getAttributionTag()); 2360 CellLocation cl = cellIdentity.asCellLocation(); 2361 if (cl == null || cl.isEmpty()) { 2362 Rlog.d(TAG, "getCellLocation returning null because CellLocation is empty or" 2363 + " phone type doesn't match CellLocation type"); 2364 return null; 2365 } 2366 2367 return cl; 2368 } catch (RemoteException ex) { 2369 Rlog.d(TAG, "getCellLocation returning null due to RemoteException " + ex); 2370 return null; 2371 } 2372 } 2373 2374 /** 2375 * Returns the neighboring cell information of the device. 2376 * 2377 * @return List of NeighboringCellInfo or null if info unavailable. 2378 * 2379 * @removed 2380 * @deprecated Use {@link #getAllCellInfo} which returns a superset of the information 2381 * from NeighboringCellInfo, including LTE cell information. 2382 */ 2383 @Deprecated 2384 @RequiresPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) getNeighboringCellInfo()2385 public List<NeighboringCellInfo> getNeighboringCellInfo() { 2386 try { 2387 ITelephony telephony = getITelephony(); 2388 if (telephony == null) 2389 return null; 2390 return telephony.getNeighboringCellInfo(mContext.getOpPackageName(), 2391 mContext.getAttributionTag()); 2392 } catch (RemoteException ex) { 2393 return null; 2394 } catch (NullPointerException ex) { 2395 return null; 2396 } 2397 } 2398 2399 /** No phone radio. */ 2400 public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE; 2401 /** Phone radio is GSM. */ 2402 public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM; 2403 /** Phone radio is CDMA. */ 2404 public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA; 2405 /** Phone is via SIP. */ 2406 public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP; 2407 2408 /** 2409 * Phone is via IMS. 2410 * 2411 * @hide 2412 */ 2413 public static final int PHONE_TYPE_IMS = PhoneConstants.PHONE_TYPE_IMS; 2414 2415 /** 2416 * Phone is via Third Party. 2417 * 2418 * @hide 2419 */ 2420 public static final int PHONE_TYPE_THIRD_PARTY = PhoneConstants.PHONE_TYPE_THIRD_PARTY; 2421 2422 /** 2423 * Returns the current phone type. 2424 * TODO: This is a last minute change and hence hidden. 2425 * 2426 * @see #PHONE_TYPE_NONE 2427 * @see #PHONE_TYPE_GSM 2428 * @see #PHONE_TYPE_CDMA 2429 * @see #PHONE_TYPE_SIP 2430 * 2431 * {@hide} 2432 */ 2433 @SystemApi getCurrentPhoneType()2434 public int getCurrentPhoneType() { 2435 return getCurrentPhoneType(getSubId()); 2436 } 2437 2438 /** 2439 * Returns a constant indicating the device phone type for a subscription. 2440 * 2441 * @see #PHONE_TYPE_NONE 2442 * @see #PHONE_TYPE_GSM 2443 * @see #PHONE_TYPE_CDMA 2444 * 2445 * @param subId for which phone type is returned 2446 * @hide 2447 */ 2448 @SystemApi getCurrentPhoneType(int subId)2449 public int getCurrentPhoneType(int subId) { 2450 int phoneId; 2451 if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 2452 // if we don't have any sims, we don't have subscriptions, but we 2453 // still may want to know what type of phone we've got. 2454 phoneId = 0; 2455 } else { 2456 phoneId = SubscriptionManager.getPhoneId(subId); 2457 } 2458 2459 return getCurrentPhoneTypeForSlot(phoneId); 2460 } 2461 2462 /** 2463 * See getCurrentPhoneType. 2464 * 2465 * @hide 2466 */ getCurrentPhoneTypeForSlot(int slotIndex)2467 public int getCurrentPhoneTypeForSlot(int slotIndex) { 2468 try{ 2469 ITelephony telephony = getITelephony(); 2470 if (telephony != null) { 2471 return telephony.getActivePhoneTypeForSlot(slotIndex); 2472 } else { 2473 // This can happen when the ITelephony interface is not up yet. 2474 return getPhoneTypeFromProperty(slotIndex); 2475 } 2476 } catch (RemoteException ex) { 2477 // This shouldn't happen in the normal case, as a backup we 2478 // read from the system property. 2479 return getPhoneTypeFromProperty(slotIndex); 2480 } catch (NullPointerException ex) { 2481 // This shouldn't happen in the normal case, as a backup we 2482 // read from the system property. 2483 return getPhoneTypeFromProperty(slotIndex); 2484 } 2485 } 2486 2487 /** 2488 * Returns a constant indicating the device phone type. This 2489 * indicates the type of radio used to transmit voice calls. 2490 * 2491 * @see #PHONE_TYPE_NONE 2492 * @see #PHONE_TYPE_GSM 2493 * @see #PHONE_TYPE_CDMA 2494 * @see #PHONE_TYPE_SIP 2495 */ getPhoneType()2496 public int getPhoneType() { 2497 if (!isVoiceCapable()) { 2498 return PHONE_TYPE_NONE; 2499 } 2500 return getCurrentPhoneType(); 2501 } 2502 getPhoneTypeFromProperty()2503 private int getPhoneTypeFromProperty() { 2504 return getPhoneTypeFromProperty(getPhoneId()); 2505 } 2506 2507 /** {@hide} */ 2508 @UnsupportedAppUsage getPhoneTypeFromProperty(int phoneId)2509 private int getPhoneTypeFromProperty(int phoneId) { 2510 Integer type = getTelephonyProperty( 2511 phoneId, TelephonyProperties.current_active_phone(), null); 2512 if (type != null) return type; 2513 return getPhoneTypeFromNetworkType(phoneId); 2514 } 2515 getPhoneTypeFromNetworkType()2516 private int getPhoneTypeFromNetworkType() { 2517 return getPhoneTypeFromNetworkType(getPhoneId()); 2518 } 2519 2520 /** {@hide} */ getPhoneTypeFromNetworkType(int phoneId)2521 private int getPhoneTypeFromNetworkType(int phoneId) { 2522 // When the system property CURRENT_ACTIVE_PHONE, has not been set, 2523 // use the system property for default network type. 2524 // This is a fail safe, and can only happen at first boot. 2525 Integer mode = getTelephonyProperty(phoneId, TelephonyProperties.default_network(), null); 2526 if (mode != null) { 2527 return TelephonyManager.getPhoneType(mode); 2528 } 2529 return TelephonyManager.PHONE_TYPE_NONE; 2530 } 2531 2532 /** 2533 * This function returns the type of the phone, depending 2534 * on the network mode. 2535 * 2536 * @param networkMode 2537 * @return Phone Type 2538 * 2539 * @hide 2540 */ 2541 @UnsupportedAppUsage getPhoneType(int networkMode)2542 public static int getPhoneType(int networkMode) { 2543 switch(networkMode) { 2544 case RILConstants.NETWORK_MODE_CDMA: 2545 case RILConstants.NETWORK_MODE_CDMA_NO_EVDO: 2546 case RILConstants.NETWORK_MODE_EVDO_NO_CDMA: 2547 return PhoneConstants.PHONE_TYPE_CDMA; 2548 2549 case RILConstants.NETWORK_MODE_WCDMA_PREF: 2550 case RILConstants.NETWORK_MODE_GSM_ONLY: 2551 case RILConstants.NETWORK_MODE_WCDMA_ONLY: 2552 case RILConstants.NETWORK_MODE_GSM_UMTS: 2553 case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA: 2554 case RILConstants.NETWORK_MODE_LTE_WCDMA: 2555 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA: 2556 case RILConstants.NETWORK_MODE_TDSCDMA_ONLY: 2557 case RILConstants.NETWORK_MODE_TDSCDMA_WCDMA: 2558 case RILConstants.NETWORK_MODE_LTE_TDSCDMA: 2559 case RILConstants.NETWORK_MODE_TDSCDMA_GSM: 2560 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM: 2561 case RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA: 2562 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA: 2563 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA: 2564 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA: 2565 return PhoneConstants.PHONE_TYPE_GSM; 2566 2567 // Use CDMA Phone for the global mode including CDMA 2568 case RILConstants.NETWORK_MODE_GLOBAL: 2569 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO: 2570 case RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA: 2571 return PhoneConstants.PHONE_TYPE_CDMA; 2572 2573 case RILConstants.NETWORK_MODE_LTE_ONLY: 2574 if (TelephonyProperties.lte_on_cdma_device().orElse( 2575 PhoneConstants.LTE_ON_CDMA_FALSE) == PhoneConstants.LTE_ON_CDMA_TRUE) { 2576 return PhoneConstants.PHONE_TYPE_CDMA; 2577 } else { 2578 return PhoneConstants.PHONE_TYPE_GSM; 2579 } 2580 default: 2581 return PhoneConstants.PHONE_TYPE_GSM; 2582 } 2583 } 2584 2585 /** 2586 * @return The max value for the timeout passed in {@link #requestNumberVerification}. 2587 * @hide 2588 */ 2589 @SystemApi getMaxNumberVerificationTimeoutMillis()2590 public static long getMaxNumberVerificationTimeoutMillis() { 2591 return MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS; 2592 } 2593 2594 // 2595 // 2596 // Current Network 2597 // 2598 // 2599 2600 /** 2601 * Returns the alphabetic name of current registered operator. 2602 * <p> 2603 * Availability: Only when user is registered to a network. Result may be 2604 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2605 * on a CDMA network). 2606 */ getNetworkOperatorName()2607 public String getNetworkOperatorName() { 2608 return getNetworkOperatorName(getSubId()); 2609 } 2610 2611 /** 2612 * Returns the alphabetic name of current registered operator 2613 * for a particular subscription. 2614 * <p> 2615 * Availability: Only when user is registered to a network. Result may be 2616 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2617 * on a CDMA network). 2618 * @param subId 2619 * @hide 2620 */ 2621 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getNetworkOperatorName(int subId)2622 public String getNetworkOperatorName(int subId) { 2623 int phoneId = SubscriptionManager.getPhoneId(subId); 2624 return getTelephonyProperty(phoneId, TelephonyProperties.operator_alpha(), ""); 2625 } 2626 2627 /** 2628 * Returns the numeric name (MCC+MNC) of current registered operator. 2629 * <p> 2630 * Availability: Only when user is registered to a network. Result may be 2631 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2632 * on a CDMA network). 2633 */ getNetworkOperator()2634 public String getNetworkOperator() { 2635 return getNetworkOperatorForPhone(getPhoneId()); 2636 } 2637 2638 /** 2639 * Returns the numeric name (MCC+MNC) of current registered operator 2640 * for a particular subscription. 2641 * <p> 2642 * Availability: Only when user is registered to a network. Result may be 2643 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2644 * on a CDMA network). 2645 * 2646 * @param subId 2647 * @hide 2648 */ 2649 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getNetworkOperator(int subId)2650 public String getNetworkOperator(int subId) { 2651 int phoneId = SubscriptionManager.getPhoneId(subId); 2652 return getNetworkOperatorForPhone(phoneId); 2653 } 2654 2655 /** 2656 * Returns the numeric name (MCC+MNC) of current registered operator 2657 * for a particular subscription. 2658 * <p> 2659 * Availability: Only when user is registered to a network. Result may be 2660 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2661 * on a CDMA network). 2662 * 2663 * @param phoneId 2664 * @hide 2665 **/ 2666 @UnsupportedAppUsage getNetworkOperatorForPhone(int phoneId)2667 public String getNetworkOperatorForPhone(int phoneId) { 2668 return getTelephonyProperty(phoneId, TelephonyProperties.operator_numeric(), ""); 2669 } 2670 2671 2672 /** 2673 * Returns the network specifier of the subscription ID pinned to the TelephonyManager. The 2674 * network specifier is used by {@link 2675 * android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to create a {@link 2676 * android.net.NetworkRequest} that connects through the subscription. 2677 * 2678 * @see android.net.NetworkRequest.Builder#setNetworkSpecifier(String) 2679 * @see #createForSubscriptionId(int) 2680 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 2681 */ getNetworkSpecifier()2682 public String getNetworkSpecifier() { 2683 return String.valueOf(getSubId()); 2684 } 2685 2686 /** 2687 * Returns the carrier config of the subscription ID pinned to the TelephonyManager. If an 2688 * invalid subscription ID is pinned to the TelephonyManager, the returned config will contain 2689 * default values. 2690 * 2691 * <p>This method may take several seconds to complete, so it should only be called from a 2692 * worker thread. 2693 * 2694 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2695 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 2696 * 2697 * @see CarrierConfigManager#getConfigForSubId(int) 2698 * @see #createForSubscriptionId(int) 2699 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 2700 */ 2701 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 2702 @WorkerThread 2703 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCarrierConfig()2704 public PersistableBundle getCarrierConfig() { 2705 CarrierConfigManager carrierConfigManager = mContext 2706 .getSystemService(CarrierConfigManager.class); 2707 return carrierConfigManager.getConfigForSubId(getSubId()); 2708 } 2709 2710 /** 2711 * Returns true if the device is considered roaming on the current 2712 * network, for GSM purposes. 2713 * <p> 2714 * Availability: Only when user registered to a network. 2715 */ isNetworkRoaming()2716 public boolean isNetworkRoaming() { 2717 return isNetworkRoaming(getSubId()); 2718 } 2719 2720 /** 2721 * Returns true if the device is considered roaming on the current 2722 * network for a subscription. 2723 * <p> 2724 * Availability: Only when user registered to a network. 2725 * 2726 * @param subId 2727 * @hide 2728 */ 2729 @UnsupportedAppUsage isNetworkRoaming(int subId)2730 public boolean isNetworkRoaming(int subId) { 2731 int phoneId = SubscriptionManager.getPhoneId(subId); 2732 return getTelephonyProperty(phoneId, TelephonyProperties.operator_is_roaming(), false); 2733 } 2734 2735 /** 2736 * Returns the ISO-3166-1 alpha-2 country code equivalent of the MCC (Mobile Country Code) of 2737 * the current registered operator or the cell nearby, if available. 2738 * 2739 * Note: Result may be unreliable on CDMA networks (use {@link #getPhoneType()} to determine 2740 * if on a CDMA network). 2741 * <p> 2742 * @return the lowercase 2 character ISO-3166-1 alpha-2 country code, or empty string if not 2743 * available. 2744 */ getNetworkCountryIso()2745 public String getNetworkCountryIso() { 2746 return getNetworkCountryIso(getSlotIndex()); 2747 } 2748 2749 /** 2750 * Returns the ISO-3166-1 alpha-2 country code equivalent of the MCC (Mobile Country Code) of 2751 * the current registered operator or the cell nearby, if available. This is same as 2752 * {@link #getNetworkCountryIso()} but allowing specifying the SIM slot index. This is used for 2753 * accessing network country info from the SIM slot that does not have SIM inserted. 2754 * 2755 * Note: Result may be unreliable on CDMA networks (use {@link #getPhoneType()} to determine 2756 * if on a CDMA network). 2757 * <p> 2758 * 2759 * @param slotIndex the SIM slot index to get network country ISO. 2760 * 2761 * @return the lowercase 2 character ISO-3166-1 alpha-2 country code, or empty string if not 2762 * available. 2763 * 2764 * @throws IllegalArgumentException when the slotIndex is invalid. 2765 * 2766 */ 2767 @NonNull getNetworkCountryIso(int slotIndex)2768 public String getNetworkCountryIso(int slotIndex) { 2769 try { 2770 if (slotIndex != SubscriptionManager.DEFAULT_SIM_SLOT_INDEX 2771 && !SubscriptionManager.isValidSlotIndex(slotIndex)) { 2772 throw new IllegalArgumentException("invalid slot index " + slotIndex); 2773 } 2774 2775 ITelephony telephony = getITelephony(); 2776 if (telephony == null) return ""; 2777 return telephony.getNetworkCountryIsoForPhone(slotIndex); 2778 } catch (RemoteException ex) { 2779 return ""; 2780 } 2781 } 2782 2783 /** 2784 * @hide 2785 * @deprecated Use {@link #getNetworkCountryIso(int)} instead. 2786 */ 2787 @Deprecated 2788 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, 2789 publicAlternatives = "Use {@link #getNetworkCountryIso(int)} instead.") getNetworkCountryIsoForPhone(int phoneId)2790 public String getNetworkCountryIsoForPhone(int phoneId) { 2791 return getNetworkCountryIso(phoneId); 2792 } 2793 2794 /* 2795 * When adding a network type to the list below, make sure to add the correct icon to 2796 * MobileSignalController.mapIconSets() as well as NETWORK_TYPES 2797 * Do not add negative types. 2798 */ 2799 /** Network type is unknown */ 2800 public static final int NETWORK_TYPE_UNKNOWN = TelephonyProtoEnums.NETWORK_TYPE_UNKNOWN; // = 0. 2801 /** Current network is GPRS */ 2802 public static final int NETWORK_TYPE_GPRS = TelephonyProtoEnums.NETWORK_TYPE_GPRS; // = 1. 2803 /** Current network is EDGE */ 2804 public static final int NETWORK_TYPE_EDGE = TelephonyProtoEnums.NETWORK_TYPE_EDGE; // = 2. 2805 /** Current network is UMTS */ 2806 public static final int NETWORK_TYPE_UMTS = TelephonyProtoEnums.NETWORK_TYPE_UMTS; // = 3. 2807 /** Current network is CDMA: Either IS95A or IS95B*/ 2808 public static final int NETWORK_TYPE_CDMA = TelephonyProtoEnums.NETWORK_TYPE_CDMA; // = 4. 2809 /** Current network is EVDO revision 0*/ 2810 public static final int NETWORK_TYPE_EVDO_0 = TelephonyProtoEnums.NETWORK_TYPE_EVDO_0; // = 5. 2811 /** Current network is EVDO revision A*/ 2812 public static final int NETWORK_TYPE_EVDO_A = TelephonyProtoEnums.NETWORK_TYPE_EVDO_A; // = 6. 2813 /** Current network is 1xRTT*/ 2814 public static final int NETWORK_TYPE_1xRTT = TelephonyProtoEnums.NETWORK_TYPE_1XRTT; // = 7. 2815 /** Current network is HSDPA */ 2816 public static final int NETWORK_TYPE_HSDPA = TelephonyProtoEnums.NETWORK_TYPE_HSDPA; // = 8. 2817 /** Current network is HSUPA */ 2818 public static final int NETWORK_TYPE_HSUPA = TelephonyProtoEnums.NETWORK_TYPE_HSUPA; // = 9. 2819 /** Current network is HSPA */ 2820 public static final int NETWORK_TYPE_HSPA = TelephonyProtoEnums.NETWORK_TYPE_HSPA; // = 10. 2821 /** Current network is iDen */ 2822 public static final int NETWORK_TYPE_IDEN = TelephonyProtoEnums.NETWORK_TYPE_IDEN; // = 11. 2823 /** Current network is EVDO revision B*/ 2824 public static final int NETWORK_TYPE_EVDO_B = TelephonyProtoEnums.NETWORK_TYPE_EVDO_B; // = 12. 2825 /** Current network is LTE */ 2826 public static final int NETWORK_TYPE_LTE = TelephonyProtoEnums.NETWORK_TYPE_LTE; // = 13. 2827 /** Current network is eHRPD */ 2828 public static final int NETWORK_TYPE_EHRPD = TelephonyProtoEnums.NETWORK_TYPE_EHRPD; // = 14. 2829 /** Current network is HSPA+ */ 2830 public static final int NETWORK_TYPE_HSPAP = TelephonyProtoEnums.NETWORK_TYPE_HSPAP; // = 15. 2831 /** Current network is GSM */ 2832 public static final int NETWORK_TYPE_GSM = TelephonyProtoEnums.NETWORK_TYPE_GSM; // = 16. 2833 /** Current network is TD_SCDMA */ 2834 public static final int NETWORK_TYPE_TD_SCDMA = 2835 TelephonyProtoEnums.NETWORK_TYPE_TD_SCDMA; // = 17. 2836 /** Current network is IWLAN */ 2837 public static final int NETWORK_TYPE_IWLAN = TelephonyProtoEnums.NETWORK_TYPE_IWLAN; // = 18. 2838 /** Current network is LTE_CA {@hide} */ 2839 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 2840 public static final int NETWORK_TYPE_LTE_CA = TelephonyProtoEnums.NETWORK_TYPE_LTE_CA; // = 19. 2841 /** 2842 * Current network is NR (New Radio) 5G. 2843 * This will only be returned for 5G SA. 2844 * For 5G NSA, the network type will be {@link #NETWORK_TYPE_LTE}. 2845 */ 2846 public static final int NETWORK_TYPE_NR = TelephonyProtoEnums.NETWORK_TYPE_NR; // 20. 2847 2848 private static final @NetworkType int[] NETWORK_TYPES = { 2849 NETWORK_TYPE_GPRS, 2850 NETWORK_TYPE_EDGE, 2851 NETWORK_TYPE_UMTS, 2852 NETWORK_TYPE_CDMA, 2853 NETWORK_TYPE_EVDO_0, 2854 NETWORK_TYPE_EVDO_A, 2855 NETWORK_TYPE_1xRTT, 2856 NETWORK_TYPE_HSDPA, 2857 NETWORK_TYPE_HSUPA, 2858 NETWORK_TYPE_HSPA, 2859 NETWORK_TYPE_IDEN, 2860 NETWORK_TYPE_EVDO_B, 2861 NETWORK_TYPE_LTE, 2862 NETWORK_TYPE_EHRPD, 2863 NETWORK_TYPE_HSPAP, 2864 NETWORK_TYPE_GSM, 2865 NETWORK_TYPE_TD_SCDMA, 2866 NETWORK_TYPE_IWLAN, 2867 NETWORK_TYPE_LTE_CA, 2868 NETWORK_TYPE_NR 2869 }; 2870 2871 /** 2872 * Returns an array of all valid network types. 2873 * 2874 * @return An integer array containing all valid network types in no particular order. 2875 * 2876 * @hide 2877 */ 2878 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) getAllNetworkTypes()2879 public static @NonNull @NetworkType int[] getAllNetworkTypes() { 2880 return NETWORK_TYPES.clone(); 2881 } 2882 2883 /** 2884 * Return the current data network type. 2885 * 2886 * @deprecated use {@link #getDataNetworkType()} 2887 * @return the NETWORK_TYPE_xxxx for current data connection. 2888 */ 2889 @Deprecated 2890 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getNetworkType()2891 public @NetworkType int getNetworkType() { 2892 return getNetworkType(getSubId(SubscriptionManager.getActiveDataSubscriptionId())); 2893 } 2894 2895 /** 2896 * Returns a constant indicating the radio technology (network type) 2897 * currently in use on the device for a subscription. 2898 * @return the network type 2899 * 2900 * @param subId for which network type is returned 2901 * 2902 * @see #NETWORK_TYPE_UNKNOWN 2903 * @see #NETWORK_TYPE_GPRS 2904 * @see #NETWORK_TYPE_EDGE 2905 * @see #NETWORK_TYPE_UMTS 2906 * @see #NETWORK_TYPE_HSDPA 2907 * @see #NETWORK_TYPE_HSUPA 2908 * @see #NETWORK_TYPE_HSPA 2909 * @see #NETWORK_TYPE_CDMA 2910 * @see #NETWORK_TYPE_EVDO_0 2911 * @see #NETWORK_TYPE_EVDO_A 2912 * @see #NETWORK_TYPE_EVDO_B 2913 * @see #NETWORK_TYPE_1xRTT 2914 * @see #NETWORK_TYPE_IDEN 2915 * @see #NETWORK_TYPE_LTE 2916 * @see #NETWORK_TYPE_EHRPD 2917 * @see #NETWORK_TYPE_HSPAP 2918 * @see #NETWORK_TYPE_NR 2919 * 2920 * @hide 2921 */ 2922 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 2923 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getNetworkType(int subId)2924 public int getNetworkType(int subId) { 2925 try { 2926 ITelephony telephony = getITelephony(); 2927 if (telephony != null) { 2928 return telephony.getNetworkTypeForSubscriber(subId, getOpPackageName(), 2929 getAttributionTag()); 2930 } else { 2931 // This can happen when the ITelephony interface is not up yet. 2932 return NETWORK_TYPE_UNKNOWN; 2933 } 2934 } catch (RemoteException ex) { 2935 // This shouldn't happen in the normal case 2936 return NETWORK_TYPE_UNKNOWN; 2937 } catch (NullPointerException ex) { 2938 // This could happen before phone restarts due to crashing 2939 return NETWORK_TYPE_UNKNOWN; 2940 } 2941 } 2942 2943 /** 2944 * Returns a constant indicating the radio technology (network type) 2945 * currently in use on the device for data transmission. 2946 * 2947 * If this object has been created with {@link #createForSubscriptionId}, applies to the given 2948 * subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 2949 * 2950 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2951 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 2952 * 2953 * @return the network type 2954 * 2955 * @see #NETWORK_TYPE_UNKNOWN 2956 * @see #NETWORK_TYPE_GPRS 2957 * @see #NETWORK_TYPE_EDGE 2958 * @see #NETWORK_TYPE_UMTS 2959 * @see #NETWORK_TYPE_HSDPA 2960 * @see #NETWORK_TYPE_HSUPA 2961 * @see #NETWORK_TYPE_HSPA 2962 * @see #NETWORK_TYPE_CDMA 2963 * @see #NETWORK_TYPE_EVDO_0 2964 * @see #NETWORK_TYPE_EVDO_A 2965 * @see #NETWORK_TYPE_EVDO_B 2966 * @see #NETWORK_TYPE_1xRTT 2967 * @see #NETWORK_TYPE_IDEN 2968 * @see #NETWORK_TYPE_LTE 2969 * @see #NETWORK_TYPE_EHRPD 2970 * @see #NETWORK_TYPE_HSPAP 2971 * @see #NETWORK_TYPE_NR 2972 */ 2973 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 2974 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getDataNetworkType()2975 public @NetworkType int getDataNetworkType() { 2976 return getDataNetworkType(getSubId(SubscriptionManager.getActiveDataSubscriptionId())); 2977 } 2978 2979 /** 2980 * Returns a constant indicating the radio technology (network type) 2981 * currently in use on the device for data transmission for a subscription 2982 * @return the network type 2983 * 2984 * @param subId for which network type is returned 2985 * @hide 2986 */ 2987 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 2988 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getDataNetworkType(int subId)2989 public int getDataNetworkType(int subId) { 2990 try{ 2991 ITelephony telephony = getITelephony(); 2992 if (telephony != null) { 2993 return telephony.getDataNetworkTypeForSubscriber(subId, getOpPackageName(), 2994 getAttributionTag()); 2995 } else { 2996 // This can happen when the ITelephony interface is not up yet. 2997 return NETWORK_TYPE_UNKNOWN; 2998 } 2999 } catch(RemoteException ex) { 3000 // This shouldn't happen in the normal case 3001 return NETWORK_TYPE_UNKNOWN; 3002 } catch (NullPointerException ex) { 3003 // This could happen before phone restarts due to crashing 3004 return NETWORK_TYPE_UNKNOWN; 3005 } 3006 } 3007 3008 /** 3009 * Returns the NETWORK_TYPE_xxxx for voice 3010 * 3011 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3012 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3013 */ 3014 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 3015 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceNetworkType()3016 public @NetworkType int getVoiceNetworkType() { 3017 return getVoiceNetworkType(getSubId()); 3018 } 3019 3020 /** 3021 * Returns the NETWORK_TYPE_xxxx for voice for a subId 3022 * @hide 3023 */ 3024 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 3025 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getVoiceNetworkType(int subId)3026 public int getVoiceNetworkType(int subId) { 3027 try{ 3028 ITelephony telephony = getITelephony(); 3029 if (telephony != null) { 3030 return telephony.getVoiceNetworkTypeForSubscriber(subId, getOpPackageName(), 3031 getAttributionTag()); 3032 } else { 3033 // This can happen when the ITelephony interface is not up yet. 3034 return NETWORK_TYPE_UNKNOWN; 3035 } 3036 } catch(RemoteException ex) { 3037 // This shouldn't happen in the normal case 3038 return NETWORK_TYPE_UNKNOWN; 3039 } catch (NullPointerException ex) { 3040 // This could happen before phone restarts due to crashing 3041 return NETWORK_TYPE_UNKNOWN; 3042 } 3043 } 3044 3045 /** 3046 * Returns a string representation of the radio technology (network type) 3047 * currently in use on the device. 3048 * @return the name of the radio technology 3049 * 3050 * @hide pending API council review 3051 */ 3052 @UnsupportedAppUsage getNetworkTypeName()3053 public String getNetworkTypeName() { 3054 return getNetworkTypeName(getNetworkType()); 3055 } 3056 3057 /** 3058 * Returns a string representation of the radio technology (network type) 3059 * currently in use on the device. 3060 * @param subId for which network type is returned 3061 * @return the name of the radio technology 3062 * 3063 */ 3064 /** {@hide} */ 3065 @UnsupportedAppUsage getNetworkTypeName(@etworkType int type)3066 public static String getNetworkTypeName(@NetworkType int type) { 3067 switch (type) { 3068 case NETWORK_TYPE_GPRS: 3069 return "GPRS"; 3070 case NETWORK_TYPE_EDGE: 3071 return "EDGE"; 3072 case NETWORK_TYPE_UMTS: 3073 return "UMTS"; 3074 case NETWORK_TYPE_HSDPA: 3075 return "HSDPA"; 3076 case NETWORK_TYPE_HSUPA: 3077 return "HSUPA"; 3078 case NETWORK_TYPE_HSPA: 3079 return "HSPA"; 3080 case NETWORK_TYPE_CDMA: 3081 return "CDMA"; 3082 case NETWORK_TYPE_EVDO_0: 3083 return "CDMA - EvDo rev. 0"; 3084 case NETWORK_TYPE_EVDO_A: 3085 return "CDMA - EvDo rev. A"; 3086 case NETWORK_TYPE_EVDO_B: 3087 return "CDMA - EvDo rev. B"; 3088 case NETWORK_TYPE_1xRTT: 3089 return "CDMA - 1xRTT"; 3090 case NETWORK_TYPE_LTE: 3091 return "LTE"; 3092 case NETWORK_TYPE_EHRPD: 3093 return "CDMA - eHRPD"; 3094 case NETWORK_TYPE_IDEN: 3095 return "iDEN"; 3096 case NETWORK_TYPE_HSPAP: 3097 return "HSPA+"; 3098 case NETWORK_TYPE_GSM: 3099 return "GSM"; 3100 case NETWORK_TYPE_TD_SCDMA: 3101 return "TD_SCDMA"; 3102 case NETWORK_TYPE_IWLAN: 3103 return "IWLAN"; 3104 case NETWORK_TYPE_LTE_CA: 3105 return "LTE_CA"; 3106 case NETWORK_TYPE_NR: 3107 return "NR"; 3108 default: 3109 return "UNKNOWN"; 3110 } 3111 } 3112 3113 /** 3114 * Returns the bitmask for a given technology (network type) 3115 * @param networkType for which bitmask is returned 3116 * @return the network type bitmask 3117 * {@hide} 3118 */ getBitMaskForNetworkType(@etworkType int networkType)3119 public static @NetworkTypeBitMask long getBitMaskForNetworkType(@NetworkType int networkType) { 3120 switch(networkType) { 3121 case NETWORK_TYPE_GSM: 3122 return NETWORK_TYPE_BITMASK_GSM; 3123 case NETWORK_TYPE_GPRS: 3124 return NETWORK_TYPE_BITMASK_GPRS; 3125 case NETWORK_TYPE_EDGE: 3126 return NETWORK_TYPE_BITMASK_EDGE; 3127 case NETWORK_TYPE_CDMA: 3128 return NETWORK_TYPE_BITMASK_CDMA; 3129 case NETWORK_TYPE_1xRTT: 3130 return NETWORK_TYPE_BITMASK_1xRTT; 3131 case NETWORK_TYPE_EVDO_0: 3132 return NETWORK_TYPE_BITMASK_EVDO_0; 3133 case NETWORK_TYPE_EVDO_A: 3134 return NETWORK_TYPE_BITMASK_EVDO_A; 3135 case NETWORK_TYPE_EVDO_B: 3136 return NETWORK_TYPE_BITMASK_EVDO_B; 3137 case NETWORK_TYPE_EHRPD: 3138 return NETWORK_TYPE_BITMASK_EHRPD; 3139 case NETWORK_TYPE_HSUPA: 3140 return NETWORK_TYPE_BITMASK_HSUPA; 3141 case NETWORK_TYPE_HSDPA: 3142 return NETWORK_TYPE_BITMASK_HSDPA; 3143 case NETWORK_TYPE_HSPA: 3144 return NETWORK_TYPE_BITMASK_HSPA; 3145 case NETWORK_TYPE_HSPAP: 3146 return NETWORK_TYPE_BITMASK_HSPAP; 3147 case NETWORK_TYPE_UMTS: 3148 return NETWORK_TYPE_BITMASK_UMTS; 3149 case NETWORK_TYPE_TD_SCDMA: 3150 return NETWORK_TYPE_BITMASK_TD_SCDMA; 3151 case NETWORK_TYPE_LTE: 3152 return NETWORK_TYPE_BITMASK_LTE; 3153 case NETWORK_TYPE_LTE_CA: 3154 return NETWORK_TYPE_BITMASK_LTE_CA; 3155 case NETWORK_TYPE_NR: 3156 return NETWORK_TYPE_BITMASK_NR; 3157 case NETWORK_TYPE_IWLAN: 3158 return NETWORK_TYPE_BITMASK_IWLAN; 3159 case NETWORK_TYPE_IDEN: 3160 return (1 << (NETWORK_TYPE_IDEN - 1)); 3161 default: 3162 return NETWORK_TYPE_BITMASK_UNKNOWN; 3163 } 3164 } 3165 3166 // 3167 // 3168 // SIM Card 3169 // 3170 // 3171 3172 /** @hide */ 3173 @IntDef(prefix = {"SIM_STATE_"}, 3174 value = { 3175 SIM_STATE_UNKNOWN, 3176 SIM_STATE_ABSENT, 3177 SIM_STATE_PIN_REQUIRED, 3178 SIM_STATE_PUK_REQUIRED, 3179 SIM_STATE_NETWORK_LOCKED, 3180 SIM_STATE_READY, 3181 SIM_STATE_NOT_READY, 3182 SIM_STATE_PERM_DISABLED, 3183 SIM_STATE_CARD_IO_ERROR, 3184 SIM_STATE_CARD_RESTRICTED, 3185 SIM_STATE_LOADED, 3186 SIM_STATE_PRESENT, 3187 }) 3188 public @interface SimState {} 3189 3190 /** 3191 * SIM card state: Unknown. Signifies that the SIM is in transition 3192 * between states. For example, when the user inputs the SIM pin 3193 * under PIN_REQUIRED state, a query for sim status returns 3194 * this state before turning to SIM_STATE_READY. 3195 * 3196 * These are the ordinal value of IccCardConstants.State. 3197 */ 3198 3199 public static final int SIM_STATE_UNKNOWN = TelephonyProtoEnums.SIM_STATE_UNKNOWN; // 0 3200 /** SIM card state: no SIM card is available in the device */ 3201 public static final int SIM_STATE_ABSENT = TelephonyProtoEnums.SIM_STATE_ABSENT; // 1 3202 /** SIM card state: Locked: requires the user's SIM PIN to unlock */ 3203 public static final int SIM_STATE_PIN_REQUIRED = 3204 TelephonyProtoEnums.SIM_STATE_PIN_REQUIRED; // 2 3205 /** SIM card state: Locked: requires the user's SIM PUK to unlock */ 3206 public static final int SIM_STATE_PUK_REQUIRED = 3207 TelephonyProtoEnums.SIM_STATE_PUK_REQUIRED; // 3 3208 /** SIM card state: Locked: requires a network PIN to unlock */ 3209 public static final int SIM_STATE_NETWORK_LOCKED = 3210 TelephonyProtoEnums.SIM_STATE_NETWORK_LOCKED; // 4 3211 /** SIM card state: Ready */ 3212 public static final int SIM_STATE_READY = TelephonyProtoEnums.SIM_STATE_READY; // 5 3213 /** SIM card state: SIM Card is NOT READY */ 3214 public static final int SIM_STATE_NOT_READY = TelephonyProtoEnums.SIM_STATE_NOT_READY; // 6 3215 /** SIM card state: SIM Card Error, permanently disabled */ 3216 public static final int SIM_STATE_PERM_DISABLED = 3217 TelephonyProtoEnums.SIM_STATE_PERM_DISABLED; // 7 3218 /** SIM card state: SIM Card Error, present but faulty */ 3219 public static final int SIM_STATE_CARD_IO_ERROR = 3220 TelephonyProtoEnums.SIM_STATE_CARD_IO_ERROR; // 8 3221 /** SIM card state: SIM Card restricted, present but not usable due to 3222 * carrier restrictions. 3223 */ 3224 public static final int SIM_STATE_CARD_RESTRICTED = 3225 TelephonyProtoEnums.SIM_STATE_CARD_RESTRICTED; // 9 3226 /** 3227 * SIM card state: Loaded: SIM card applications have been loaded 3228 * @hide 3229 */ 3230 @SystemApi 3231 public static final int SIM_STATE_LOADED = TelephonyProtoEnums.SIM_STATE_LOADED; // 10 3232 /** 3233 * SIM card state: SIM Card is present 3234 * @hide 3235 */ 3236 @SystemApi 3237 public static final int SIM_STATE_PRESENT = TelephonyProtoEnums.SIM_STATE_PRESENT; // 11 3238 3239 /** 3240 * Extra included in {@link #ACTION_SIM_CARD_STATE_CHANGED} and 3241 * {@link #ACTION_SIM_APPLICATION_STATE_CHANGED} to indicate the card/application state. 3242 * 3243 * @hide 3244 */ 3245 @SystemApi 3246 public static final String EXTRA_SIM_STATE = "android.telephony.extra.SIM_STATE"; 3247 3248 /** 3249 * Broadcast Action: The sim card state has changed. 3250 * The intent will have the following extra values:</p> 3251 * <dl> 3252 * <dt>{@link #EXTRA_SIM_STATE}</dt> 3253 * <dd>The sim card state. One of: 3254 * <dl> 3255 * <dt>{@link #SIM_STATE_ABSENT}</dt> 3256 * <dd>SIM card not found</dd> 3257 * <dt>{@link #SIM_STATE_CARD_IO_ERROR}</dt> 3258 * <dd>SIM card IO error</dd> 3259 * <dt>{@link #SIM_STATE_CARD_RESTRICTED}</dt> 3260 * <dd>SIM card is restricted</dd> 3261 * <dt>{@link #SIM_STATE_PRESENT}</dt> 3262 * <dd>SIM card is present</dd> 3263 * </dl> 3264 * </dd> 3265 * </dl> 3266 * 3267 * <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission. 3268 * 3269 * <p class="note">The current state can also be queried using {@link #getSimCardState()}. 3270 * 3271 * <p class="note">This is a protected intent that can only be sent by the system. 3272 * @hide 3273 */ 3274 @SystemApi 3275 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 3276 public static final String ACTION_SIM_CARD_STATE_CHANGED = 3277 "android.telephony.action.SIM_CARD_STATE_CHANGED"; 3278 3279 /** 3280 * Broadcast Action: The sim application state has changed. 3281 * The intent will have the following extra values:</p> 3282 * <dl> 3283 * <dt>{@link #EXTRA_SIM_STATE}</dt> 3284 * <dd>The sim application state. One of: 3285 * <dl> 3286 * <dt>{@link #SIM_STATE_NOT_READY}</dt> 3287 * <dd>SIM card applications not ready</dd> 3288 * <dt>{@link #SIM_STATE_PIN_REQUIRED}</dt> 3289 * <dd>SIM card PIN locked</dd> 3290 * <dt>{@link #SIM_STATE_PUK_REQUIRED}</dt> 3291 * <dd>SIM card PUK locked</dd> 3292 * <dt>{@link #SIM_STATE_NETWORK_LOCKED}</dt> 3293 * <dd>SIM card network locked</dd> 3294 * <dt>{@link #SIM_STATE_PERM_DISABLED}</dt> 3295 * <dd>SIM card permanently disabled due to PUK failures</dd> 3296 * <dt>{@link #SIM_STATE_LOADED}</dt> 3297 * <dd>SIM card data loaded</dd> 3298 * </dl> 3299 * </dd> 3300 * </dl> 3301 * 3302 * <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission. 3303 * 3304 * <p class="note">The current state can also be queried using 3305 * {@link #getSimApplicationState()}. 3306 * 3307 * <p class="note">This is a protected intent that can only be sent by the system. 3308 * @hide 3309 */ 3310 @SystemApi 3311 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 3312 public static final String ACTION_SIM_APPLICATION_STATE_CHANGED = 3313 "android.telephony.action.SIM_APPLICATION_STATE_CHANGED"; 3314 3315 /** 3316 * Broadcast Action: Status of the SIM slots on the device has changed. 3317 * 3318 * <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission. 3319 * 3320 * <p class="note">The status can be queried using 3321 * {@link #getUiccSlotsInfo()} 3322 * 3323 * <p class="note">This is a protected intent that can only be sent by the system. 3324 * @hide 3325 */ 3326 @SystemApi 3327 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 3328 public static final String ACTION_SIM_SLOT_STATUS_CHANGED = 3329 "android.telephony.action.SIM_SLOT_STATUS_CHANGED"; 3330 3331 /** 3332 * Broadcast Action: A debug code has been entered in the dialer. 3333 * <p> 3334 * This intent is broadcast by the system and OEM telephony apps may need to receive these 3335 * broadcasts. And it requires the sender to be default dialer or has carrier privileges 3336 * (see {@link #hasCarrierPrivileges}). 3337 * <p> 3338 * These "secret codes" are used to activate developer menus by dialing certain codes. 3339 * And they are of the form {@code *#*#<code>#*#*}. The intent will have the data 3340 * URI: {@code android_secret_code://<code>}. It is possible that a manifest 3341 * receiver would be woken up even if it is not currently running. 3342 * <p> 3343 * It is supposed to replace {@link android.provider.Telephony.Sms.Intents#SECRET_CODE_ACTION} 3344 * in the next Android version. 3345 * Before that both of these two actions will be broadcast. 3346 */ 3347 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 3348 public static final String ACTION_SECRET_CODE = "android.telephony.action.SECRET_CODE"; 3349 3350 /** 3351 * @return true if a ICC card is present 3352 */ hasIccCard()3353 public boolean hasIccCard() { 3354 return hasIccCard(getSlotIndex()); 3355 } 3356 3357 /** 3358 * @return true if a ICC card is present for a subscription 3359 * 3360 * @param slotIndex for which icc card presence is checked 3361 */ 3362 /** {@hide} */ 3363 // FIXME Input argument slotIndex should be of type int 3364 @UnsupportedAppUsage hasIccCard(int slotIndex)3365 public boolean hasIccCard(int slotIndex) { 3366 3367 try { 3368 ITelephony telephony = getITelephony(); 3369 if (telephony == null) 3370 return false; 3371 return telephony.hasIccCardUsingSlotIndex(slotIndex); 3372 } catch (RemoteException ex) { 3373 // Assume no ICC card if remote exception which shouldn't happen 3374 return false; 3375 } catch (NullPointerException ex) { 3376 // This could happen before phone restarts due to crashing 3377 return false; 3378 } 3379 } 3380 3381 /** 3382 * Returns a constant indicating the state of the default SIM card. 3383 * 3384 * @see #SIM_STATE_UNKNOWN 3385 * @see #SIM_STATE_ABSENT 3386 * @see #SIM_STATE_PIN_REQUIRED 3387 * @see #SIM_STATE_PUK_REQUIRED 3388 * @see #SIM_STATE_NETWORK_LOCKED 3389 * @see #SIM_STATE_READY 3390 * @see #SIM_STATE_NOT_READY 3391 * @see #SIM_STATE_PERM_DISABLED 3392 * @see #SIM_STATE_CARD_IO_ERROR 3393 * @see #SIM_STATE_CARD_RESTRICTED 3394 */ getSimState()3395 public @SimState int getSimState() { 3396 int simState = getSimStateIncludingLoaded(); 3397 if (simState == SIM_STATE_LOADED) { 3398 simState = SIM_STATE_READY; 3399 } 3400 return simState; 3401 } 3402 getSimStateIncludingLoaded()3403 private @SimState int getSimStateIncludingLoaded() { 3404 int slotIndex = getSlotIndex(); 3405 // slotIndex may be invalid due to sim being absent. In that case query all slots to get 3406 // sim state 3407 if (slotIndex < 0) { 3408 // query for all slots and return absent if all sim states are absent, otherwise 3409 // return unknown 3410 for (int i = 0; i < getPhoneCount(); i++) { 3411 int simState = getSimState(i); 3412 if (simState != SIM_STATE_ABSENT) { 3413 Rlog.d(TAG, "getSimState: default sim:" + slotIndex + ", sim state for " + 3414 "slotIndex=" + i + " is " + simState + ", return state as unknown"); 3415 return SIM_STATE_UNKNOWN; 3416 } 3417 } 3418 Rlog.d(TAG, "getSimState: default sim:" + slotIndex + ", all SIMs absent, return " + 3419 "state as absent"); 3420 return SIM_STATE_ABSENT; 3421 } 3422 return SubscriptionManager.getSimStateForSlotIndex(slotIndex); 3423 } 3424 3425 /** 3426 * Returns a constant indicating the state of the default SIM card. 3427 * 3428 * @see #SIM_STATE_UNKNOWN 3429 * @see #SIM_STATE_ABSENT 3430 * @see #SIM_STATE_CARD_IO_ERROR 3431 * @see #SIM_STATE_CARD_RESTRICTED 3432 * @see #SIM_STATE_PRESENT 3433 * 3434 * @hide 3435 */ 3436 @SystemApi getSimCardState()3437 public @SimState int getSimCardState() { 3438 int simState = getSimState(); 3439 return getSimCardStateFromSimState(simState); 3440 } 3441 3442 /** 3443 * Returns a constant indicating the state of the device SIM card in a physical slot. 3444 * 3445 * @param physicalSlotIndex physical slot index 3446 * 3447 * @see #SIM_STATE_UNKNOWN 3448 * @see #SIM_STATE_ABSENT 3449 * @see #SIM_STATE_CARD_IO_ERROR 3450 * @see #SIM_STATE_CARD_RESTRICTED 3451 * @see #SIM_STATE_PRESENT 3452 * 3453 * @hide 3454 */ 3455 @SystemApi 3456 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getSimCardState(int physicalSlotIndex)3457 public @SimState int getSimCardState(int physicalSlotIndex) { 3458 int simState = getSimState(getLogicalSlotIndex(physicalSlotIndex)); 3459 return getSimCardStateFromSimState(simState); 3460 } 3461 3462 /** 3463 * Converts SIM state to SIM card state. 3464 * @param simState 3465 * @return SIM card state 3466 */ getSimCardStateFromSimState(int simState)3467 private @SimState int getSimCardStateFromSimState(int simState) { 3468 switch (simState) { 3469 case SIM_STATE_UNKNOWN: 3470 case SIM_STATE_ABSENT: 3471 case SIM_STATE_CARD_IO_ERROR: 3472 case SIM_STATE_CARD_RESTRICTED: 3473 return simState; 3474 default: 3475 return SIM_STATE_PRESENT; 3476 } 3477 } 3478 3479 /** 3480 * Converts a physical slot index to logical slot index. 3481 * @param physicalSlotIndex physical slot index 3482 * @return logical slot index 3483 */ getLogicalSlotIndex(int physicalSlotIndex)3484 private int getLogicalSlotIndex(int physicalSlotIndex) { 3485 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); 3486 if (slotInfos != null && physicalSlotIndex >= 0 && physicalSlotIndex < slotInfos.length 3487 && slotInfos[physicalSlotIndex] != null) { 3488 return slotInfos[physicalSlotIndex].getLogicalSlotIdx(); 3489 } 3490 3491 return SubscriptionManager.INVALID_SIM_SLOT_INDEX; 3492 } 3493 3494 /** 3495 * Returns a constant indicating the state of the card applications on the default SIM card. 3496 * 3497 * @see #SIM_STATE_UNKNOWN 3498 * @see #SIM_STATE_PIN_REQUIRED 3499 * @see #SIM_STATE_PUK_REQUIRED 3500 * @see #SIM_STATE_NETWORK_LOCKED 3501 * @see #SIM_STATE_NOT_READY 3502 * @see #SIM_STATE_PERM_DISABLED 3503 * @see #SIM_STATE_LOADED 3504 * 3505 * @hide 3506 */ 3507 @SystemApi getSimApplicationState()3508 public @SimState int getSimApplicationState() { 3509 int simState = getSimStateIncludingLoaded(); 3510 return getSimApplicationStateFromSimState(simState); 3511 } 3512 3513 /** 3514 * Returns a constant indicating the state of the card applications on the device SIM card in 3515 * a physical slot. 3516 * 3517 * @param physicalSlotIndex physical slot index 3518 * 3519 * @see #SIM_STATE_UNKNOWN 3520 * @see #SIM_STATE_PIN_REQUIRED 3521 * @see #SIM_STATE_PUK_REQUIRED 3522 * @see #SIM_STATE_NETWORK_LOCKED 3523 * @see #SIM_STATE_NOT_READY 3524 * @see #SIM_STATE_PERM_DISABLED 3525 * @see #SIM_STATE_LOADED 3526 * 3527 * @hide 3528 */ 3529 @SystemApi 3530 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getSimApplicationState(int physicalSlotIndex)3531 public @SimState int getSimApplicationState(int physicalSlotIndex) { 3532 int simState = 3533 SubscriptionManager.getSimStateForSlotIndex(getLogicalSlotIndex(physicalSlotIndex)); 3534 return getSimApplicationStateFromSimState(simState); 3535 } 3536 3537 /** 3538 * Converts SIM state to SIM application state. 3539 * @param simState 3540 * @return SIM application state 3541 */ getSimApplicationStateFromSimState(int simState)3542 private @SimState int getSimApplicationStateFromSimState(int simState) { 3543 switch (simState) { 3544 case SIM_STATE_UNKNOWN: 3545 case SIM_STATE_ABSENT: 3546 case SIM_STATE_CARD_IO_ERROR: 3547 case SIM_STATE_CARD_RESTRICTED: 3548 return SIM_STATE_UNKNOWN; 3549 case SIM_STATE_READY: 3550 // Ready is not a valid state anymore. The state that is broadcast goes from 3551 // NOT_READY to either LOCKED or LOADED. 3552 return SIM_STATE_NOT_READY; 3553 default: 3554 return simState; 3555 } 3556 } 3557 3558 3559 /** 3560 * Returns true if the specified type of application (e.g. {@link #APPTYPE_CSIM} is present 3561 * on the UICC card. 3562 * 3563 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 3564 * 3565 * @param appType the uicc app type like {@link APPTYPE_CSIM} 3566 * @return true if the specified type of application in UICC CARD or false if no uicc or error. 3567 * @hide 3568 */ 3569 @SystemApi 3570 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) isApplicationOnUicc(@iccAppType int appType)3571 public boolean isApplicationOnUicc(@UiccAppType int appType) { 3572 try { 3573 ITelephony service = getITelephony(); 3574 if (service != null) { 3575 return service.isApplicationOnUicc(getSubId(), appType); 3576 } 3577 } catch (RemoteException e) { 3578 Log.e(TAG, "Error calling ITelephony#isApplicationOnUicc", e); 3579 } 3580 return false; 3581 } 3582 3583 /** 3584 * Returns a constant indicating the state of the device SIM card in a logical slot. 3585 * 3586 * @param slotIndex logical slot index 3587 * 3588 * @see #SIM_STATE_UNKNOWN 3589 * @see #SIM_STATE_ABSENT 3590 * @see #SIM_STATE_PIN_REQUIRED 3591 * @see #SIM_STATE_PUK_REQUIRED 3592 * @see #SIM_STATE_NETWORK_LOCKED 3593 * @see #SIM_STATE_READY 3594 * @see #SIM_STATE_NOT_READY 3595 * @see #SIM_STATE_PERM_DISABLED 3596 * @see #SIM_STATE_CARD_IO_ERROR 3597 * @see #SIM_STATE_CARD_RESTRICTED 3598 */ getSimState(int slotIndex)3599 public @SimState int getSimState(int slotIndex) { 3600 int simState = SubscriptionManager.getSimStateForSlotIndex(slotIndex); 3601 if (simState == SIM_STATE_LOADED) { 3602 simState = SIM_STATE_READY; 3603 } 3604 return simState; 3605 } 3606 3607 /** 3608 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3609 * provider of the SIM. 5 or 6 decimal digits. 3610 * <p> 3611 * Availability: SIM state must be {@link #SIM_STATE_READY} 3612 * 3613 * @see #getSimState 3614 */ getSimOperator()3615 public String getSimOperator() { 3616 return getSimOperatorNumeric(); 3617 } 3618 3619 /** 3620 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3621 * provider of the SIM. 5 or 6 decimal digits. 3622 * <p> 3623 * Availability: SIM state must be {@link #SIM_STATE_READY} 3624 * 3625 * @see #getSimState 3626 * 3627 * @param subId for which SimOperator is returned 3628 * @hide 3629 */ 3630 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperator(int subId)3631 public String getSimOperator(int subId) { 3632 return getSimOperatorNumeric(subId); 3633 } 3634 3635 /** 3636 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3637 * provider of the SIM. 5 or 6 decimal digits. 3638 * <p> 3639 * Availability: SIM state must be {@link #SIM_STATE_READY} 3640 * 3641 * @see #getSimState 3642 * @hide 3643 */ 3644 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperatorNumeric()3645 public String getSimOperatorNumeric() { 3646 int subId = mSubId; 3647 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 3648 subId = SubscriptionManager.getDefaultDataSubscriptionId(); 3649 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 3650 subId = SubscriptionManager.getDefaultSmsSubscriptionId(); 3651 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 3652 subId = SubscriptionManager.getDefaultVoiceSubscriptionId(); 3653 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 3654 subId = SubscriptionManager.getDefaultSubscriptionId(); 3655 } 3656 } 3657 } 3658 } 3659 return getSimOperatorNumeric(subId); 3660 } 3661 3662 /** 3663 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3664 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 3665 * <p> 3666 * Availability: SIM state must be {@link #SIM_STATE_READY} 3667 * 3668 * @see #getSimState 3669 * 3670 * @param subId for which SimOperator is returned 3671 * @hide 3672 */ 3673 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperatorNumeric(int subId)3674 public String getSimOperatorNumeric(int subId) { 3675 int phoneId = SubscriptionManager.getPhoneId(subId); 3676 return getSimOperatorNumericForPhone(phoneId); 3677 } 3678 3679 /** 3680 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3681 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 3682 * <p> 3683 * 3684 * @param phoneId for which SimOperator is returned 3685 * @hide 3686 */ 3687 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperatorNumericForPhone(int phoneId)3688 public String getSimOperatorNumericForPhone(int phoneId) { 3689 return getTelephonyProperty(phoneId, TelephonyProperties.icc_operator_numeric(), ""); 3690 } 3691 3692 /** 3693 * Returns the Service Provider Name (SPN). 3694 * <p> 3695 * Availability: SIM state must be {@link #SIM_STATE_READY} 3696 * 3697 * @see #getSimState 3698 */ getSimOperatorName()3699 public String getSimOperatorName() { 3700 return getSimOperatorNameForPhone(getPhoneId()); 3701 } 3702 3703 /** 3704 * Returns the Service Provider Name (SPN). 3705 * <p> 3706 * Availability: SIM state must be {@link #SIM_STATE_READY} 3707 * 3708 * @see #getSimState 3709 * 3710 * @param subId for which SimOperatorName is returned 3711 * @hide 3712 */ 3713 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperatorName(int subId)3714 public String getSimOperatorName(int subId) { 3715 int phoneId = SubscriptionManager.getPhoneId(subId); 3716 return getSimOperatorNameForPhone(phoneId); 3717 } 3718 3719 /** 3720 * Returns the Service Provider Name (SPN). 3721 * 3722 * @hide 3723 */ 3724 @UnsupportedAppUsage getSimOperatorNameForPhone(int phoneId)3725 public String getSimOperatorNameForPhone(int phoneId) { 3726 return getTelephonyProperty(phoneId, TelephonyProperties.icc_operator_alpha(), ""); 3727 } 3728 3729 /** 3730 * Returns the ISO-3166-1 alpha-2 country code equivalent for the SIM provider's country code. 3731 * <p> 3732 * The ISO-3166-1 alpha-2 country code is provided in lowercase 2 character format. 3733 * @return the lowercase 2 character ISO-3166-1 alpha-2 country code, or empty string is not 3734 * available. 3735 */ getSimCountryIso()3736 public String getSimCountryIso() { 3737 return getSimCountryIsoForPhone(getPhoneId()); 3738 } 3739 3740 /** 3741 * Returns the ISO country code equivalent for the SIM provider's country code. 3742 * 3743 * @param subId for which SimCountryIso is returned 3744 * @hide 3745 */ 3746 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimCountryIso(int subId)3747 public static String getSimCountryIso(int subId) { 3748 int phoneId = SubscriptionManager.getPhoneId(subId); 3749 return getSimCountryIsoForPhone(phoneId); 3750 } 3751 3752 /** 3753 * Returns the ISO country code equivalent for the SIM provider's country code. 3754 * 3755 * @hide 3756 */ 3757 @UnsupportedAppUsage getSimCountryIsoForPhone(int phoneId)3758 public static String getSimCountryIsoForPhone(int phoneId) { 3759 return getTelephonyProperty(phoneId, TelephonyProperties.icc_operator_iso_country(), ""); 3760 } 3761 3762 /** 3763 * Returns the serial number of the SIM, if applicable. Return null if it is 3764 * unavailable. 3765 * 3766 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 3767 * restrictions, and apps are recommended to use resettable identifiers (see <a 3768 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 3769 * method can be invoked if one of the following requirements is met: 3770 * <ul> 3771 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 3772 * is a privileged permission that can only be granted to apps preloaded on the device. 3773 * <li>If the calling app is the device owner of a fully-managed device, a profile 3774 * owner of an organization-owned device, or their delegates (see {@link 3775 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 3776 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3777 * <li>If the calling app is the default SMS role holder (see {@link 3778 * RoleManager#isRoleHeld(String)}). 3779 * </ul> 3780 * 3781 * <p>If the calling app does not meet one of these requirements then this method will behave 3782 * as follows: 3783 * 3784 * <ul> 3785 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 3786 * READ_PHONE_STATE permission then null is returned.</li> 3787 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 3788 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 3789 * higher, then a SecurityException is thrown.</li> 3790 * </ul> 3791 */ 3792 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 3793 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getSimSerialNumber()3794 public String getSimSerialNumber() { 3795 return getSimSerialNumber(getSubId()); 3796 } 3797 3798 /** 3799 * Returns the serial number for the given subscription, if applicable. Return null if it is 3800 * unavailable. 3801 * 3802 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 3803 * restrictions, and apps are recommended to use resettable identifiers (see <a 3804 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 3805 * method can be invoked if one of the following requirements is met: 3806 * <ul> 3807 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 3808 * is a privileged permission that can only be granted to apps preloaded on the device. 3809 * <li>If the calling app is the device owner of a fully-managed device, a profile 3810 * owner of an organization-owned device, or their delegates (see {@link 3811 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 3812 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3813 * <li>If the calling app is the default SMS role holder (see {@link 3814 * RoleManager#isRoleHeld(String)}). 3815 * </ul> 3816 * 3817 * <p>If the calling app does not meet one of these requirements then this method will behave 3818 * as follows: 3819 * 3820 * <ul> 3821 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 3822 * READ_PHONE_STATE permission then null is returned.</li> 3823 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 3824 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 3825 * higher, then a SecurityException is thrown.</li> 3826 * </ul> 3827 * 3828 * @param subId for which Sim Serial number is returned 3829 * @hide 3830 */ 3831 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 3832 @UnsupportedAppUsage getSimSerialNumber(int subId)3833 public String getSimSerialNumber(int subId) { 3834 try { 3835 IPhoneSubInfo info = getSubscriberInfoService(); 3836 if (info == null) 3837 return null; 3838 return info.getIccSerialNumberForSubscriber(subId, mContext.getOpPackageName(), 3839 mContext.getAttributionTag()); 3840 } catch (RemoteException ex) { 3841 return null; 3842 } catch (NullPointerException ex) { 3843 // This could happen before phone restarts due to crashing 3844 return null; 3845 } 3846 } 3847 3848 /** 3849 * Return if the current radio can support both 3GPP and 3GPP2 radio technologies at the same 3850 * time. This is also known as global mode, which includes LTE, CDMA, EvDo and GSM/WCDMA. 3851 * 3852 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 3853 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()}. 3854 * 3855 * @return {@code true} if 3GPP and 3GPP2 radio technologies can be supported at the same time 3856 * {@code false} if not supported or unknown 3857 * @hide 3858 */ 3859 @SystemApi 3860 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) isLteCdmaEvdoGsmWcdmaEnabled()3861 public boolean isLteCdmaEvdoGsmWcdmaEnabled() { 3862 return getLteOnCdmaMode(getSubId()) == PhoneConstants.LTE_ON_CDMA_TRUE; 3863 } 3864 3865 /** 3866 * Return if the current radio is LTE on CDMA for Subscription. This 3867 * is a tri-state return value as for a period of time 3868 * the mode may be unknown. 3869 * 3870 * @param subId for which radio is LTE on CDMA is returned 3871 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 3872 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 3873 * @hide 3874 */ 3875 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 3876 @UnsupportedAppUsage getLteOnCdmaMode(int subId)3877 public int getLteOnCdmaMode(int subId) { 3878 try { 3879 ITelephony telephony = getITelephony(); 3880 if (telephony == null) 3881 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 3882 return telephony.getLteOnCdmaModeForSubscriber(subId, getOpPackageName(), 3883 getAttributionTag()); 3884 } catch (RemoteException ex) { 3885 // Assume no ICC card if remote exception which shouldn't happen 3886 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 3887 } catch (NullPointerException ex) { 3888 // This could happen before phone restarts due to crashing 3889 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 3890 } 3891 } 3892 3893 /** 3894 * Get the card ID of the default eUICC card. If the eUICCs have not yet been loaded, returns 3895 * {@link #UNINITIALIZED_CARD_ID}. If there is no eUICC or the device does not support card IDs 3896 * for eUICCs, returns {@link #UNSUPPORTED_CARD_ID}. 3897 * 3898 * <p>The card ID is a unique identifier associated with a UICC or eUICC card. Card IDs are 3899 * unique to a device, and always refer to the same UICC or eUICC card unless the device goes 3900 * through a factory reset. 3901 * 3902 * @return card ID of the default eUICC card, if loaded. 3903 */ getCardIdForDefaultEuicc()3904 public int getCardIdForDefaultEuicc() { 3905 try { 3906 ITelephony telephony = getITelephony(); 3907 if (telephony == null) { 3908 return UNINITIALIZED_CARD_ID; 3909 } 3910 return telephony.getCardIdForDefaultEuicc(mSubId, mContext.getOpPackageName()); 3911 } catch (RemoteException e) { 3912 return UNINITIALIZED_CARD_ID; 3913 } 3914 } 3915 3916 /** 3917 * Gets information about currently inserted UICCs and eUICCs. 3918 * <p> 3919 * Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3920 * <p> 3921 * If the caller has carrier priviliges on any active subscription, then they have permission to 3922 * get simple information like the card ID ({@link UiccCardInfo#getCardId()}), whether the card 3923 * is an eUICC ({@link UiccCardInfo#isEuicc()}), and the slot index where the card is inserted 3924 * ({@link UiccCardInfo#getSlotIndex()}). 3925 * <p> 3926 * To get private information such as the EID ({@link UiccCardInfo#getEid()}) or ICCID 3927 * ({@link UiccCardInfo#getIccId()}), the caller must have carrier priviliges on that specific 3928 * UICC or eUICC card. 3929 * <p> 3930 * See {@link UiccCardInfo} for more details on the kind of information available. 3931 * 3932 * @return a list of UiccCardInfo objects, representing information on the currently inserted 3933 * UICCs and eUICCs. Each UiccCardInfo in the list will have private information filtered out if 3934 * the caller does not have adequate permissions for that card. 3935 */ 3936 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 3937 @NonNull getUiccCardsInfo()3938 public List<UiccCardInfo> getUiccCardsInfo() { 3939 try { 3940 ITelephony telephony = getITelephony(); 3941 if (telephony == null) { 3942 Log.e(TAG, "Error in getUiccCardsInfo: unable to connect to Telephony service."); 3943 return new ArrayList<UiccCardInfo>(); 3944 } 3945 return telephony.getUiccCardsInfo(mContext.getOpPackageName()); 3946 } catch (RemoteException e) { 3947 Log.e(TAG, "Error in getUiccCardsInfo: " + e); 3948 return new ArrayList<UiccCardInfo>(); 3949 } 3950 } 3951 3952 /** 3953 * Gets all the UICC slots. The objects in the array can be null if the slot info is not 3954 * available, which is possible between phone process starting and getting slot info from modem. 3955 * 3956 * @return UiccSlotInfo array. 3957 * 3958 * @hide 3959 */ 3960 @SystemApi 3961 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getUiccSlotsInfo()3962 public UiccSlotInfo[] getUiccSlotsInfo() { 3963 try { 3964 ITelephony telephony = getITelephony(); 3965 if (telephony == null) { 3966 return null; 3967 } 3968 return telephony.getUiccSlotsInfo(); 3969 } catch (RemoteException e) { 3970 return null; 3971 } 3972 } 3973 3974 /** 3975 * Test method to reload the UICC profile. 3976 * 3977 * @hide 3978 */ 3979 @TestApi 3980 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) refreshUiccProfile()3981 public void refreshUiccProfile() { 3982 try { 3983 ITelephony telephony = getITelephony(); 3984 telephony.refreshUiccProfile(mSubId); 3985 } catch (RemoteException ex) { 3986 Rlog.w(TAG, "RemoteException", ex); 3987 } 3988 } 3989 3990 /** 3991 * Map logicalSlot to physicalSlot, and activate the physicalSlot if it is inactive. For 3992 * example, passing the physicalSlots array [1, 0] means mapping the first item 1, which is 3993 * physical slot index 1, to the logical slot 0; and mapping the second item 0, which is 3994 * physical slot index 0, to the logical slot 1. The index of the array means the index of the 3995 * logical slots. 3996 * 3997 * @param physicalSlots The content of the array represents the physical slot index. The array 3998 * size should be same as {@link #getUiccSlotsInfo()}. 3999 * @return boolean Return true if the switch succeeds, false if the switch fails. 4000 * @hide 4001 */ 4002 @SystemApi 4003 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) switchSlots(int[] physicalSlots)4004 public boolean switchSlots(int[] physicalSlots) { 4005 try { 4006 ITelephony telephony = getITelephony(); 4007 if (telephony == null) { 4008 return false; 4009 } 4010 return telephony.switchSlots(physicalSlots); 4011 } catch (RemoteException e) { 4012 return false; 4013 } 4014 } 4015 4016 /** 4017 * Get the mapping from logical slots to physical slots. The key of the map is the logical slot 4018 * id and the value is the physical slots id mapped to this logical slot id. 4019 * 4020 * @return a map indicates the mapping from logical slots to physical slots. The size of the map 4021 * should be {@link #getPhoneCount()} if success, otherwise return an empty map. 4022 * 4023 * @hide 4024 */ 4025 @SystemApi 4026 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 4027 @NonNull getLogicalToPhysicalSlotMapping()4028 public Map<Integer, Integer> getLogicalToPhysicalSlotMapping() { 4029 Map<Integer, Integer> slotMapping = new HashMap<>(); 4030 try { 4031 ITelephony telephony = getITelephony(); 4032 if (telephony != null) { 4033 int[] slotMappingArray = telephony.getSlotsMapping(); 4034 for (int i = 0; i < slotMappingArray.length; i++) { 4035 slotMapping.put(i, slotMappingArray[i]); 4036 } 4037 } 4038 } catch (RemoteException e) { 4039 Log.e(TAG, "getSlotsMapping RemoteException", e); 4040 } 4041 return slotMapping; 4042 } 4043 4044 // 4045 // 4046 // Subscriber Info 4047 // 4048 // 4049 4050 /** 4051 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 4052 * Return null if it is unavailable. 4053 * 4054 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 4055 * restrictions, and apps are recommended to use resettable identifiers (see <a 4056 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 4057 * method can be invoked if one of the following requirements is met: 4058 * <ul> 4059 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 4060 * is a privileged permission that can only be granted to apps preloaded on the device. 4061 * <li>If the calling app is the device owner of a fully-managed device, a profile 4062 * owner of an organization-owned device, or their delegates (see {@link 4063 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 4064 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4065 * <li>If the calling app is the default SMS role holder (see {@link 4066 * RoleManager#isRoleHeld(String)}). 4067 * <li>If the calling app has been granted the 4068 * {@link Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} permission. 4069 * </ul> 4070 * 4071 * <p>If the calling app does not meet one of these requirements then this method will behave 4072 * as follows: 4073 * 4074 * <ul> 4075 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 4076 * READ_PHONE_STATE permission then null is returned.</li> 4077 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 4078 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 4079 * higher, then a SecurityException is thrown.</li> 4080 * </ul> 4081 */ 4082 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 4083 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getSubscriberId()4084 public String getSubscriberId() { 4085 return getSubscriberId(getSubId()); 4086 } 4087 4088 /** 4089 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone 4090 * for a subscription. 4091 * Return null if it is unavailable. 4092 * 4093 * See {@link #getSubscriberId()} for details on the required permissions and behavior 4094 * when the caller does not hold sufficient permissions. 4095 * 4096 * @param subId whose subscriber id is returned 4097 * @hide 4098 */ 4099 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 4100 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSubscriberId(int subId)4101 public String getSubscriberId(int subId) { 4102 try { 4103 IPhoneSubInfo info = getSubscriberInfoService(); 4104 if (info == null) 4105 return null; 4106 return info.getSubscriberIdForSubscriber(subId, mContext.getOpPackageName(), 4107 mContext.getAttributionTag()); 4108 } catch (RemoteException ex) { 4109 return null; 4110 } catch (NullPointerException ex) { 4111 // This could happen before phone restarts due to crashing 4112 return null; 4113 } 4114 } 4115 4116 /** 4117 * Returns carrier specific information that will be used to encrypt the IMSI and IMPI, 4118 * including the public key and the key identifier; or {@code null} if not available. 4119 * <p> 4120 * For a multi-sim device, the dafault data sim is used if not specified. 4121 * <p> 4122 * Requires Permission: READ_PRIVILEGED_PHONE_STATE. 4123 * 4124 * @param keyType whether the key is being used for EPDG or WLAN. Valid values are 4125 * {@link #KEY_TYPE_EPDG} or {@link #KEY_TYPE_WLAN}. 4126 * @return ImsiEncryptionInfo Carrier specific information that will be used to encrypt the 4127 * IMSI and IMPI. This includes the public key and the key identifier. This information 4128 * will be stored in the device keystore. {@code null} will be returned when no key is 4129 * found, and the carrier does not require a key. 4130 * @throws IllegalArgumentException when an invalid key is found or when key is required but 4131 * not found. 4132 * @hide 4133 */ 4134 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 4135 @SystemApi 4136 @Nullable getCarrierInfoForImsiEncryption(@eyType int keyType)4137 public ImsiEncryptionInfo getCarrierInfoForImsiEncryption(@KeyType int keyType) { 4138 try { 4139 IPhoneSubInfo info = getSubscriberInfoService(); 4140 if (info == null) { 4141 Rlog.e(TAG,"IMSI error: Subscriber Info is null"); 4142 return null; 4143 } 4144 int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId()); 4145 if (keyType != KEY_TYPE_EPDG && keyType != KEY_TYPE_WLAN) { 4146 throw new IllegalArgumentException("IMSI error: Invalid key type"); 4147 } 4148 ImsiEncryptionInfo imsiEncryptionInfo = info.getCarrierInfoForImsiEncryption( 4149 subId, keyType, mContext.getOpPackageName()); 4150 if (imsiEncryptionInfo == null && isImsiEncryptionRequired(subId, keyType)) { 4151 Rlog.e(TAG, "IMSI error: key is required but not found"); 4152 throw new IllegalArgumentException("IMSI error: key is required but not found"); 4153 } 4154 return imsiEncryptionInfo; 4155 } catch (RemoteException ex) { 4156 Rlog.e(TAG, "getCarrierInfoForImsiEncryption RemoteException" + ex); 4157 } catch (NullPointerException ex) { 4158 // This could happen before phone restarts due to crashing 4159 Rlog.e(TAG, "getCarrierInfoForImsiEncryption NullPointerException" + ex); 4160 } 4161 return null; 4162 } 4163 4164 /** 4165 * Resets the carrier keys used to encrypt the IMSI and IMPI. 4166 * <p> 4167 * This involves 2 steps: 4168 * 1. Delete the keys from the database. 4169 * 2. Send an intent to download new Certificates. 4170 * <p> 4171 * For a multi-sim device, the dafault data sim is used if not specified. 4172 * <p> 4173 * Requires Permission: MODIFY_PHONE_STATE. 4174 * 4175 * @see #getCarrierInfoForImsiEncryption 4176 * @hide 4177 */ 4178 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 4179 @SystemApi resetCarrierKeysForImsiEncryption()4180 public void resetCarrierKeysForImsiEncryption() { 4181 try { 4182 IPhoneSubInfo info = getSubscriberInfoService(); 4183 if (info == null) { 4184 throw new RuntimeException("IMSI error: Subscriber Info is null"); 4185 } 4186 int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId()); 4187 info.resetCarrierKeysForImsiEncryption(subId, mContext.getOpPackageName()); 4188 } catch (RemoteException ex) { 4189 Rlog.e(TAG, "Telephony#getCarrierInfoForImsiEncryption RemoteException" + ex); 4190 } 4191 } 4192 4193 /** 4194 * @param keyAvailability bitmask that defines the availabilty of keys for a type. 4195 * @param keyType the key type which is being checked. (WLAN, EPDG) 4196 * @return true if the digit at position keyType is 1, else false. 4197 * @hide 4198 */ isKeyEnabled(int keyAvailability, @KeyType int keyType)4199 private static boolean isKeyEnabled(int keyAvailability, @KeyType int keyType) { 4200 int returnValue = (keyAvailability >> (keyType - 1)) & 1; 4201 return (returnValue == 1) ? true : false; 4202 } 4203 4204 /** 4205 * If Carrier requires Imsi to be encrypted. 4206 * @hide 4207 */ isImsiEncryptionRequired(int subId, @KeyType int keyType)4208 private boolean isImsiEncryptionRequired(int subId, @KeyType int keyType) { 4209 CarrierConfigManager configManager = 4210 (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE); 4211 if (configManager == null) { 4212 return false; 4213 } 4214 PersistableBundle pb = configManager.getConfigForSubId(subId); 4215 if (pb == null) { 4216 return false; 4217 } 4218 int keyAvailability = pb.getInt(CarrierConfigManager.IMSI_KEY_AVAILABILITY_INT); 4219 return isKeyEnabled(keyAvailability, keyType); 4220 } 4221 4222 /** 4223 * Sets the Carrier specific information that will be used to encrypt the IMSI and IMPI. 4224 * This includes the public key and the key identifier. This information will be stored in the 4225 * device keystore. 4226 * <p> 4227 * Requires Permission: 4228 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 4229 * @param imsiEncryptionInfo which includes the Key Type, the Public Key 4230 * (java.security.PublicKey) and the Key Identifier.and the Key Identifier. 4231 * The keyIdentifier Attribute value pair that helps a server locate 4232 * the private key to decrypt the permanent identity. This field is 4233 * optional and if it is present then it’s always separated from encrypted 4234 * permanent identity with “,”. Key identifier AVP is presented in ASCII string 4235 * with “name=value” format. 4236 * @hide 4237 */ setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo)4238 public void setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo) { 4239 try { 4240 IPhoneSubInfo info = getSubscriberInfoService(); 4241 if (info == null) return; 4242 info.setCarrierInfoForImsiEncryption(mSubId, mContext.getOpPackageName(), 4243 imsiEncryptionInfo); 4244 } catch (NullPointerException ex) { 4245 // This could happen before phone restarts due to crashing 4246 return; 4247 } catch (RemoteException ex) { 4248 Rlog.e(TAG, "setCarrierInfoForImsiEncryption RemoteException", ex); 4249 return; 4250 } 4251 } 4252 4253 /** 4254 * Exception that may be supplied to the callback in {@link #uploadCallComposerPicture} if 4255 * something goes awry. 4256 */ 4257 public static class CallComposerException extends Exception { 4258 /** 4259 * Used internally only, signals success of the upload to the carrier. 4260 * @hide 4261 */ 4262 public static final int SUCCESS = -1; 4263 /** 4264 * Indicates that an unknown error was encountered when uploading the call composer picture. 4265 * 4266 * Clients that encounter this error should retry the upload. 4267 */ 4268 public static final int ERROR_UNKNOWN = 0; 4269 4270 /** 4271 * Indicates that the phone process died or otherwise became unavailable while uploading the 4272 * call composer picture. 4273 * 4274 * Clients that encounter this error should retry the upload. 4275 */ 4276 public static final int ERROR_REMOTE_END_CLOSED = 1; 4277 4278 /** 4279 * Indicates that the file or stream supplied exceeds the size limit defined in 4280 * {@link #getMaximumCallComposerPictureSize()}. 4281 * 4282 * Clients that encounter this error should retry the upload after reducing the size of the 4283 * picture. 4284 */ 4285 public static final int ERROR_FILE_TOO_LARGE = 2; 4286 4287 /** 4288 * Indicates that the device failed to authenticate with the carrier when uploading the 4289 * picture. 4290 * 4291 * Clients that encounter this error should not retry the upload unless a reboot or radio 4292 * reset has been performed in the interim. 4293 */ 4294 public static final int ERROR_AUTHENTICATION_FAILED = 3; 4295 4296 /** 4297 * Indicates that the {@link InputStream} passed to {@link #uploadCallComposerPicture} 4298 * was closed. 4299 * 4300 * The caller should retry if this error is encountered, and be sure to not close the stream 4301 * before the callback is called this time. 4302 */ 4303 public static final int ERROR_INPUT_CLOSED = 4; 4304 4305 /** 4306 * Indicates that an {@link IOException} was encountered while reading the picture. 4307 * 4308 * The offending {@link IOException} will be available via {@link #getIOException()}. 4309 * Clients should use the contents of the exception to determine whether a retry is 4310 * warranted. 4311 */ 4312 public static final int ERROR_IO_EXCEPTION = 5; 4313 4314 /** 4315 * Indicates that the device is currently not connected to a network that's capable of 4316 * reaching a carrier's RCS servers. 4317 * 4318 * Clients should prompt the user to remedy the issue by moving to an area with better 4319 * signal, by connecting to a different network, or to retry at another time. 4320 */ 4321 public static final int ERROR_NETWORK_UNAVAILABLE = 6; 4322 4323 /** @hide */ 4324 @IntDef(prefix = {"ERROR_"}, value = { 4325 ERROR_UNKNOWN, 4326 ERROR_REMOTE_END_CLOSED, 4327 ERROR_FILE_TOO_LARGE, 4328 ERROR_AUTHENTICATION_FAILED, 4329 ERROR_INPUT_CLOSED, 4330 ERROR_IO_EXCEPTION, 4331 ERROR_NETWORK_UNAVAILABLE, 4332 }) 4333 4334 @Retention(RetentionPolicy.SOURCE) 4335 public @interface CallComposerError {} 4336 4337 private final int mErrorCode; 4338 private final IOException mIOException; 4339 CallComposerException(@allComposerError int errorCode, @Nullable IOException ioException)4340 public CallComposerException(@CallComposerError int errorCode, 4341 @Nullable IOException ioException) { 4342 mErrorCode = errorCode; 4343 mIOException = ioException; 4344 } 4345 4346 /** 4347 * Fetches the error code associated with this exception. 4348 * @return An error code. 4349 */ getErrorCode()4350 public @CallComposerError int getErrorCode() { 4351 return mErrorCode; 4352 } 4353 4354 /** 4355 * Fetches the {@link IOException} that caused the error. 4356 */ 4357 // Follows the naming of IOException 4358 @SuppressLint("AcronymName") getIOException()4359 public @Nullable IOException getIOException() { 4360 return mIOException; 4361 } 4362 } 4363 4364 /** @hide */ 4365 public static final String KEY_CALL_COMPOSER_PICTURE_HANDLE = "call_composer_picture_handle"; 4366 4367 /** 4368 * Uploads a picture to the carrier network for use with call composer. 4369 * 4370 * @see #uploadCallComposerPicture(InputStream, String, Executor, OutcomeReceiver) 4371 * @param pictureToUpload Path to a local file containing the picture to upload. 4372 * @param contentType The MIME type of the picture you're uploading (e.g. image/jpeg) 4373 * @param executor The {@link Executor} on which the {@code pictureToUpload} file will be read 4374 * from disk, as well as on which {@code callback} will be called. 4375 * @param callback A callback called when the upload operation terminates, either in success 4376 * or in error. 4377 */ uploadCallComposerPicture(@onNull Path pictureToUpload, @NonNull String contentType, @CallbackExecutor @NonNull Executor executor, @NonNull OutcomeReceiver<ParcelUuid, CallComposerException> callback)4378 public void uploadCallComposerPicture(@NonNull Path pictureToUpload, 4379 @NonNull String contentType, 4380 @CallbackExecutor @NonNull Executor executor, 4381 @NonNull OutcomeReceiver<ParcelUuid, CallComposerException> callback) { 4382 Objects.requireNonNull(pictureToUpload); 4383 Objects.requireNonNull(executor); 4384 Objects.requireNonNull(callback); 4385 4386 // Do the role check now so that we can quit early if needed -- there's an additional 4387 // permission check on the other side of the binder call as well. 4388 RoleManager rm = mContext.getSystemService(RoleManager.class); 4389 if (!rm.isRoleHeld(RoleManager.ROLE_DIALER)) { 4390 throw new SecurityException("You must hold RoleManager.ROLE_DIALER to do this"); 4391 } 4392 4393 executor.execute(() -> { 4394 try { 4395 if (Looper.getMainLooper().isCurrentThread()) { 4396 Log.w(TAG, "Uploading call composer picture on main thread!" 4397 + " hic sunt dracones!"); 4398 } 4399 long size = Files.size(pictureToUpload); 4400 if (size > getMaximumCallComposerPictureSize()) { 4401 callback.onError(new CallComposerException( 4402 CallComposerException.ERROR_FILE_TOO_LARGE, null)); 4403 return; 4404 } 4405 InputStream fileStream = Files.newInputStream(pictureToUpload); 4406 try { 4407 uploadCallComposerPicture(fileStream, contentType, executor, 4408 new OutcomeReceiver<ParcelUuid, CallComposerException>() { 4409 @Override 4410 public void onResult(ParcelUuid result) { 4411 try { 4412 fileStream.close(); 4413 } catch (IOException e) { 4414 // ignore 4415 Log.e(TAG, "Error closing file input stream when" 4416 + " uploading call composer pic"); 4417 } 4418 callback.onResult(result); 4419 } 4420 4421 @Override 4422 public void onError(CallComposerException error) { 4423 try { 4424 fileStream.close(); 4425 } catch (IOException e) { 4426 // ignore 4427 Log.e(TAG, "Error closing file input stream when" 4428 + " uploading call composer pic"); 4429 } 4430 callback.onError(error); 4431 } 4432 }); 4433 } catch (Exception e) { 4434 Log.e(TAG, "Got exception calling into stream-version of" 4435 + " uploadCallComposerPicture: " + e); 4436 try { 4437 fileStream.close(); 4438 } catch (IOException e1) { 4439 // ignore 4440 Log.e(TAG, "Error closing file input stream when uploading" 4441 + " call composer pic"); 4442 } 4443 } 4444 } catch (IOException e) { 4445 Log.e(TAG, "IOException when uploading call composer pic:" + e); 4446 callback.onError( 4447 new CallComposerException(CallComposerException.ERROR_IO_EXCEPTION, e)); 4448 } 4449 }); 4450 4451 } 4452 4453 /** 4454 * Uploads a picture to the carrier network for use with call composer. 4455 * 4456 * This method allows a dialer app to upload a picture to the carrier network that can then 4457 * later be attached to an outgoing call. In order to attach the picture to a call, use the 4458 * {@link ParcelUuid} returned from {@code callback} upon successful upload as the value to 4459 * {@link TelecomManager#EXTRA_OUTGOING_PICTURE}. 4460 * 4461 * This functionality is only available to the app filling the {@link RoleManager#ROLE_DIALER} 4462 * role on the device. 4463 * 4464 * This functionality is only available when 4465 * {@link CarrierConfigManager#KEY_SUPPORTS_CALL_COMPOSER_BOOL} is set to {@code true} in the 4466 * bundle returned from {@link #getCarrierConfig()}. 4467 * 4468 * @param pictureToUpload An {@link InputStream} that supplies the bytes representing the 4469 * picture to upload. The client bears responsibility for closing this 4470 * stream after {@code callback} is called with success or failure. 4471 * 4472 * Additionally, if the stream supplies more bytes than the return value 4473 * of {@link #getMaximumCallComposerPictureSize()}, the upload will be 4474 * aborted and the callback will be called with an exception containing 4475 * {@link CallComposerException#ERROR_FILE_TOO_LARGE}. 4476 * @param contentType The MIME type of the picture you're uploading (e.g. image/jpeg). The list 4477 * of acceptable content types can be found at 3GPP TS 26.141 sections 4478 * 4.2 and 4.3. 4479 * @param executor The {@link Executor} on which the {@code pictureToUpload} stream will be 4480 * read, as well as on which the callback will be called. 4481 * @param callback A callback called when the upload operation terminates, either in success 4482 * or in error. 4483 */ uploadCallComposerPicture(@onNull InputStream pictureToUpload, @NonNull String contentType, @CallbackExecutor @NonNull Executor executor, @NonNull OutcomeReceiver<ParcelUuid, CallComposerException> callback)4484 public void uploadCallComposerPicture(@NonNull InputStream pictureToUpload, 4485 @NonNull String contentType, 4486 @CallbackExecutor @NonNull Executor executor, 4487 @NonNull OutcomeReceiver<ParcelUuid, CallComposerException> callback) { 4488 Objects.requireNonNull(pictureToUpload); 4489 Objects.requireNonNull(executor); 4490 Objects.requireNonNull(callback); 4491 4492 ITelephony telephony = getITelephony(); 4493 if (telephony == null) { 4494 throw new IllegalStateException("Telephony service not available."); 4495 } 4496 4497 ParcelFileDescriptor writeFd; 4498 ParcelFileDescriptor readFd; 4499 try { 4500 ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createReliablePipe(); 4501 writeFd = pipe[1]; 4502 readFd = pipe[0]; 4503 } catch (IOException e) { 4504 executor.execute(() -> callback.onError( 4505 new CallComposerException(CallComposerException.ERROR_IO_EXCEPTION, e))); 4506 return; 4507 } 4508 4509 OutputStream output = new ParcelFileDescriptor.AutoCloseOutputStream(writeFd); 4510 4511 try { 4512 telephony.uploadCallComposerPicture(getSubId(), mContext.getOpPackageName(), 4513 contentType, readFd, new ResultReceiver(null) { 4514 @Override 4515 protected void onReceiveResult(int resultCode, Bundle result) { 4516 if (resultCode != CallComposerException.SUCCESS) { 4517 executor.execute(() -> callback.onError( 4518 new CallComposerException(resultCode, null))); 4519 return; 4520 } 4521 ParcelUuid resultUuid = 4522 result.getParcelable(KEY_CALL_COMPOSER_PICTURE_HANDLE); 4523 if (resultUuid == null) { 4524 Log.e(TAG, "Got null uuid without an error" 4525 + " while uploading call composer pic"); 4526 executor.execute(() -> callback.onError( 4527 new CallComposerException( 4528 CallComposerException.ERROR_UNKNOWN, null))); 4529 return; 4530 } 4531 executor.execute(() -> callback.onResult(resultUuid)); 4532 } 4533 }); 4534 } catch (RemoteException e) { 4535 Log.e(TAG, "Remote exception uploading call composer pic:" + e); 4536 e.rethrowAsRuntimeException(); 4537 } 4538 4539 executor.execute(() -> { 4540 if (Looper.getMainLooper().isCurrentThread()) { 4541 Log.w(TAG, "Uploading call composer picture on main thread!" 4542 + " hic sunt dracones!"); 4543 } 4544 4545 int totalBytesRead = 0; 4546 byte[] buffer = new byte[16 * 1024]; 4547 try { 4548 while (true) { 4549 int numRead; 4550 try { 4551 numRead = pictureToUpload.read(buffer); 4552 } catch (IOException e) { 4553 Log.e(TAG, "IOException reading from input while uploading pic: " + e); 4554 // Most likely, this was because the stream was closed. We have no way to 4555 // tell though. 4556 callback.onError(new CallComposerException( 4557 CallComposerException.ERROR_INPUT_CLOSED, e)); 4558 try { 4559 writeFd.closeWithError("input closed"); 4560 } catch (IOException e1) { 4561 // log and ignore 4562 Log.e(TAG, "Error closing fd pipe: " + e1); 4563 } 4564 break; 4565 } 4566 4567 if (numRead < 0) { 4568 break; 4569 } 4570 4571 totalBytesRead += numRead; 4572 if (totalBytesRead > getMaximumCallComposerPictureSize()) { 4573 Log.e(TAG, "Read too many bytes from call composer pic stream: " 4574 + totalBytesRead); 4575 try { 4576 callback.onError(new CallComposerException( 4577 CallComposerException.ERROR_FILE_TOO_LARGE, null)); 4578 writeFd.closeWithError("too large"); 4579 } catch (IOException e1) { 4580 // log and ignore 4581 Log.e(TAG, "Error closing fd pipe: " + e1); 4582 } 4583 break; 4584 } 4585 4586 try { 4587 output.write(buffer, 0, numRead); 4588 } catch (IOException e) { 4589 callback.onError(new CallComposerException( 4590 CallComposerException.ERROR_REMOTE_END_CLOSED, e)); 4591 try { 4592 writeFd.closeWithError("remote end closed"); 4593 } catch (IOException e1) { 4594 // log and ignore 4595 Log.e(TAG, "Error closing fd pipe: " + e1); 4596 } 4597 break; 4598 } 4599 } 4600 } finally { 4601 try { 4602 output.close(); 4603 } catch (IOException e) { 4604 // Ignore -- we might've already closed it. 4605 } 4606 } 4607 }); 4608 } 4609 4610 /** 4611 * Returns the Group Identifier Level1 for a GSM phone. 4612 * Return null if it is unavailable. 4613 * 4614 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 4615 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4616 */ 4617 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 4618 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getGroupIdLevel1()4619 public String getGroupIdLevel1() { 4620 try { 4621 IPhoneSubInfo info = getSubscriberInfoService(); 4622 if (info == null) 4623 return null; 4624 return info.getGroupIdLevel1ForSubscriber(getSubId(), mContext.getOpPackageName(), 4625 mContext.getAttributionTag()); 4626 } catch (RemoteException ex) { 4627 return null; 4628 } catch (NullPointerException ex) { 4629 // This could happen before phone restarts due to crashing 4630 return null; 4631 } 4632 } 4633 4634 /** 4635 * Returns the Group Identifier Level1 for a GSM phone for a particular subscription. 4636 * Return null if it is unavailable. 4637 * 4638 * @param subId whose subscriber id is returned 4639 * @hide 4640 */ 4641 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 4642 @UnsupportedAppUsage getGroupIdLevel1(int subId)4643 public String getGroupIdLevel1(int subId) { 4644 try { 4645 IPhoneSubInfo info = getSubscriberInfoService(); 4646 if (info == null) 4647 return null; 4648 return info.getGroupIdLevel1ForSubscriber(subId, mContext.getOpPackageName(), 4649 mContext.getAttributionTag()); 4650 } catch (RemoteException ex) { 4651 return null; 4652 } catch (NullPointerException ex) { 4653 // This could happen before phone restarts due to crashing 4654 return null; 4655 } 4656 } 4657 4658 /** 4659 * Returns the phone number string for line 1, for example, the MSISDN 4660 * for a GSM phone for a particular subscription. Return null if it is unavailable. 4661 * <p> 4662 * The default SMS app can also use this. 4663 * 4664 * <p>Requires Permission: 4665 * {@link android.Manifest.permission#READ_SMS READ_SMS}, 4666 * {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS}, 4667 * that the caller is the default SMS app, 4668 * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}) 4669 * for any API level. 4670 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 4671 * for apps targeting SDK API level 29 and below. 4672 */ 4673 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges or default SMS app 4674 @RequiresPermission(anyOf = { 4675 android.Manifest.permission.READ_PHONE_STATE, 4676 android.Manifest.permission.READ_SMS, 4677 android.Manifest.permission.READ_PHONE_NUMBERS 4678 }) getLine1Number()4679 public String getLine1Number() { 4680 return getLine1Number(getSubId()); 4681 } 4682 4683 /** 4684 * Returns the phone number string for line 1, for example, the MSISDN 4685 * for a GSM phone for a particular subscription. Return null if it is unavailable. 4686 * <p> 4687 * The default SMS app can also use this. 4688 * 4689 * <p>Requires Permission: 4690 * {@link android.Manifest.permission#READ_SMS READ_SMS}, 4691 * {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS}, 4692 * that the caller is the default SMS app, 4693 * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}) 4694 * for any API level. 4695 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 4696 * for apps targeting SDK API level 29 and below. 4697 * 4698 * @param subId whose phone number for line 1 is returned 4699 * @hide 4700 */ 4701 @RequiresPermission(anyOf = { 4702 android.Manifest.permission.READ_PHONE_STATE, 4703 android.Manifest.permission.READ_SMS, 4704 android.Manifest.permission.READ_PHONE_NUMBERS 4705 }) 4706 @UnsupportedAppUsage getLine1Number(int subId)4707 public String getLine1Number(int subId) { 4708 String number = null; 4709 try { 4710 ITelephony telephony = getITelephony(); 4711 if (telephony != null) 4712 number = telephony.getLine1NumberForDisplay(subId, mContext.getOpPackageName(), 4713 mContext.getAttributionTag()); 4714 } catch (RemoteException ex) { 4715 } catch (NullPointerException ex) { 4716 } 4717 if (number != null) { 4718 return number; 4719 } 4720 try { 4721 IPhoneSubInfo info = getSubscriberInfoService(); 4722 if (info == null) 4723 return null; 4724 return info.getLine1NumberForSubscriber(subId, mContext.getOpPackageName(), 4725 mContext.getAttributionTag()); 4726 } catch (RemoteException ex) { 4727 return null; 4728 } catch (NullPointerException ex) { 4729 // This could happen before phone restarts due to crashing 4730 return null; 4731 } 4732 } 4733 4734 /** 4735 * Set the line 1 phone number string and its alphatag for the current ICCID 4736 * for display purpose only, for example, displayed in Phone Status. It won't 4737 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 4738 * value. 4739 * 4740 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4741 * 4742 * @param alphaTag alpha-tagging of the dailing nubmer 4743 * @param number The dialing number 4744 * @return true if the operation was executed correctly. 4745 */ setLine1NumberForDisplay(String alphaTag, String number)4746 public boolean setLine1NumberForDisplay(String alphaTag, String number) { 4747 return setLine1NumberForDisplay(getSubId(), alphaTag, number); 4748 } 4749 4750 /** 4751 * Set the line 1 phone number string and its alphatag for the current ICCID 4752 * for display purpose only, for example, displayed in Phone Status. It won't 4753 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 4754 * value. 4755 * 4756 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4757 * 4758 * @param subId the subscriber that the alphatag and dialing number belongs to. 4759 * @param alphaTag alpha-tagging of the dailing nubmer 4760 * @param number The dialing number 4761 * @return true if the operation was executed correctly. 4762 * @hide 4763 */ setLine1NumberForDisplay(int subId, String alphaTag, String number)4764 public boolean setLine1NumberForDisplay(int subId, String alphaTag, String number) { 4765 try { 4766 ITelephony telephony = getITelephony(); 4767 if (telephony != null) 4768 return telephony.setLine1NumberForDisplayForSubscriber(subId, alphaTag, number); 4769 } catch (RemoteException ex) { 4770 } catch (NullPointerException ex) { 4771 } 4772 return false; 4773 } 4774 4775 /** 4776 * Returns the alphabetic identifier associated with the line 1 number. 4777 * Return null if it is unavailable. 4778 * @hide 4779 * nobody seems to call this. 4780 */ 4781 @UnsupportedAppUsage 4782 @TestApi 4783 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getLine1AlphaTag()4784 public String getLine1AlphaTag() { 4785 return getLine1AlphaTag(getSubId()); 4786 } 4787 4788 /** 4789 * Returns the alphabetic identifier associated with the line 1 number 4790 * for a subscription. 4791 * Return null if it is unavailable. 4792 * @param subId whose alphabetic identifier associated with line 1 is returned 4793 * nobody seems to call this. 4794 * @hide 4795 */ 4796 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 4797 @UnsupportedAppUsage getLine1AlphaTag(int subId)4798 public String getLine1AlphaTag(int subId) { 4799 String alphaTag = null; 4800 try { 4801 ITelephony telephony = getITelephony(); 4802 if (telephony != null) 4803 alphaTag = telephony.getLine1AlphaTagForDisplay(subId, 4804 getOpPackageName(), getAttributionTag()); 4805 } catch (RemoteException ex) { 4806 } catch (NullPointerException ex) { 4807 } 4808 if (alphaTag != null) { 4809 return alphaTag; 4810 } 4811 try { 4812 IPhoneSubInfo info = getSubscriberInfoService(); 4813 if (info == null) 4814 return null; 4815 return info.getLine1AlphaTagForSubscriber(subId, getOpPackageName(), 4816 getAttributionTag()); 4817 } catch (RemoteException ex) { 4818 return null; 4819 } catch (NullPointerException ex) { 4820 // This could happen before phone restarts due to crashing 4821 return null; 4822 } 4823 } 4824 4825 /** 4826 * Return the set of subscriber IDs that should be considered "merged together" for data usage 4827 * purposes. This is commonly {@code null} to indicate no merging is required. Any returned 4828 * subscribers are sorted in a deterministic order. 4829 * <p> 4830 * The returned set of subscriber IDs will include the subscriber ID corresponding to this 4831 * TelephonyManager's subId. 4832 * 4833 * This is deprecated and {@link #getMergedImsisFromGroup()} should be used for data 4834 * usage merging purpose. 4835 * TODO: remove this API. 4836 * 4837 * @hide 4838 */ 4839 @UnsupportedAppUsage 4840 @Deprecated getMergedSubscriberIds()4841 public @Nullable String[] getMergedSubscriberIds() { 4842 try { 4843 ITelephony telephony = getITelephony(); 4844 if (telephony != null) 4845 return telephony.getMergedSubscriberIds(getSubId(), getOpPackageName(), 4846 getAttributionTag()); 4847 } catch (RemoteException ex) { 4848 } catch (NullPointerException ex) { 4849 } 4850 return null; 4851 } 4852 4853 /** 4854 * Return the set of IMSIs that should be considered "merged together" for data usage 4855 * purposes. This API merges IMSIs based on subscription grouping: IMSI of those in the same 4856 * group will all be returned. 4857 * Return the current IMSI if there is no subscription group, see 4858 * {@link SubscriptionManager#createSubscriptionGroup(List)} for the definition of a group, 4859 * otherwise return an empty array if there is a failure. 4860 * 4861 * @hide 4862 */ 4863 @SystemApi 4864 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getMergedImsisFromGroup()4865 public @NonNull String[] getMergedImsisFromGroup() { 4866 try { 4867 ITelephony telephony = getITelephony(); 4868 if (telephony != null) { 4869 return telephony.getMergedImsisFromGroup(getSubId(), getOpPackageName()); 4870 } 4871 } catch (RemoteException ex) { 4872 } 4873 return new String[0]; 4874 } 4875 4876 /** 4877 * Returns the MSISDN string for a GSM phone. Return null if it is unavailable. 4878 * 4879 * <p>Requires Permission: 4880 * {@link android.Manifest.permission#READ_SMS READ_SMS}, 4881 * {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS}, 4882 * that the caller is the default SMS app, 4883 * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}) 4884 * for any API level. 4885 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 4886 * for apps targeting SDK API level 29 and below. 4887 * 4888 * @hide 4889 */ 4890 @RequiresPermission(anyOf = { 4891 android.Manifest.permission.READ_PHONE_STATE, 4892 android.Manifest.permission.READ_SMS, 4893 android.Manifest.permission.READ_PHONE_NUMBERS 4894 }) 4895 @UnsupportedAppUsage getMsisdn()4896 public String getMsisdn() { 4897 return getMsisdn(getSubId()); 4898 } 4899 4900 /** 4901 * Returns the MSISDN string for a GSM phone. Return null if it is unavailable. 4902 * 4903 * @param subId for which msisdn is returned 4904 * 4905 * <p>Requires Permission: 4906 * {@link android.Manifest.permission#READ_SMS READ_SMS}, 4907 * {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS}, 4908 * that the caller is the default SMS app, 4909 * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}) 4910 * for any API level. 4911 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 4912 * for apps targeting SDK API level 29 and below. 4913 * 4914 * @hide 4915 */ 4916 @RequiresPermission(anyOf = { 4917 android.Manifest.permission.READ_PHONE_STATE, 4918 android.Manifest.permission.READ_SMS, 4919 android.Manifest.permission.READ_PHONE_NUMBERS 4920 }) 4921 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getMsisdn(int subId)4922 public String getMsisdn(int subId) { 4923 try { 4924 IPhoneSubInfo info = getSubscriberInfoService(); 4925 if (info == null) 4926 return null; 4927 return info.getMsisdnForSubscriber(subId, getOpPackageName(), getAttributionTag()); 4928 } catch (RemoteException ex) { 4929 return null; 4930 } catch (NullPointerException ex) { 4931 // This could happen before phone restarts due to crashing 4932 return null; 4933 } 4934 } 4935 4936 /** 4937 * Returns the voice mail number. Return null if it is unavailable. 4938 * 4939 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 4940 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4941 */ 4942 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 4943 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceMailNumber()4944 public String getVoiceMailNumber() { 4945 return getVoiceMailNumber(getSubId()); 4946 } 4947 4948 /** 4949 * Returns the voice mail number for a subscription. 4950 * Return null if it is unavailable. 4951 * @param subId whose voice mail number is returned 4952 * @hide 4953 */ 4954 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 4955 @UnsupportedAppUsage getVoiceMailNumber(int subId)4956 public String getVoiceMailNumber(int subId) { 4957 try { 4958 IPhoneSubInfo info = getSubscriberInfoService(); 4959 if (info == null) 4960 return null; 4961 return info.getVoiceMailNumberForSubscriber(subId, getOpPackageName(), 4962 getAttributionTag()); 4963 } catch (RemoteException ex) { 4964 return null; 4965 } catch (NullPointerException ex) { 4966 // This could happen before phone restarts due to crashing 4967 return null; 4968 } 4969 } 4970 4971 /** 4972 * Sets the voice mail number. 4973 * 4974 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4975 * 4976 * @param alphaTag The alpha tag to display. 4977 * @param number The voicemail number. 4978 */ setVoiceMailNumber(String alphaTag, String number)4979 public boolean setVoiceMailNumber(String alphaTag, String number) { 4980 return setVoiceMailNumber(getSubId(), alphaTag, number); 4981 } 4982 4983 /** 4984 * Sets the voicemail number for the given subscriber. 4985 * 4986 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4987 * 4988 * @param subId The subscription id. 4989 * @param alphaTag The alpha tag to display. 4990 * @param number The voicemail number. 4991 * @hide 4992 */ setVoiceMailNumber(int subId, String alphaTag, String number)4993 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { 4994 try { 4995 ITelephony telephony = getITelephony(); 4996 if (telephony != null) 4997 return telephony.setVoiceMailNumber(subId, alphaTag, number); 4998 } catch (RemoteException ex) { 4999 } catch (NullPointerException ex) { 5000 } 5001 return false; 5002 } 5003 5004 /** 5005 * Enables or disables the visual voicemail client for a phone account. 5006 * 5007 * <p>Requires that the calling app is the default dialer, or has carrier privileges (see 5008 * {@link #hasCarrierPrivileges}), or has permission 5009 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 5010 * 5011 * @param phoneAccountHandle the phone account to change the client state 5012 * @param enabled the new state of the client 5013 * @hide 5014 * @deprecated Visual voicemail no longer in telephony. {@link VisualVoicemailService} should 5015 * be implemented instead. 5016 */ 5017 @SystemApi 5018 @SuppressLint("RequiresPermission") setVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled)5019 public void setVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled){ 5020 } 5021 5022 /** 5023 * Returns whether the visual voicemail client is enabled. 5024 * 5025 * @param phoneAccountHandle the phone account to check for. 5026 * @return {@code true} when the visual voicemail client is enabled for this client 5027 * @hide 5028 * @deprecated Visual voicemail no longer in telephony. {@link VisualVoicemailService} should 5029 * be implemented instead. 5030 */ 5031 @SystemApi 5032 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5033 @SuppressLint("RequiresPermission") isVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle)5034 public boolean isVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle){ 5035 return false; 5036 } 5037 5038 /** 5039 * Returns an opaque bundle of settings formerly used by the visual voicemail client for the 5040 * subscription ID pinned to the TelephonyManager, or {@code null} if the subscription ID is 5041 * invalid. This method allows the system dialer to migrate settings out of the pre-O visual 5042 * voicemail client in telephony. 5043 * 5044 * <p>Requires the caller to be the system dialer. 5045 * 5046 * @see #KEY_VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL 5047 * @see #KEY_VOICEMAIL_SCRAMBLED_PIN_STRING 5048 * 5049 * @hide 5050 */ 5051 @SystemApi 5052 @SuppressLint("RequiresPermission") 5053 @Nullable getVisualVoicemailSettings()5054 public Bundle getVisualVoicemailSettings(){ 5055 try { 5056 ITelephony telephony = getITelephony(); 5057 if (telephony != null) { 5058 return telephony 5059 .getVisualVoicemailSettings(mContext.getOpPackageName(), mSubId); 5060 } 5061 } catch (RemoteException ex) { 5062 } catch (NullPointerException ex) { 5063 } 5064 return null; 5065 } 5066 5067 /** 5068 * Returns the package responsible of processing visual voicemail for the subscription ID pinned 5069 * to the TelephonyManager. Returns {@code null} when there is no package responsible for 5070 * processing visual voicemail for the subscription. 5071 * 5072 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 5073 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5074 * 5075 * @see #createForSubscriptionId(int) 5076 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 5077 * @see VisualVoicemailService 5078 */ 5079 @Nullable 5080 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 5081 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVisualVoicemailPackageName()5082 public String getVisualVoicemailPackageName() { 5083 try { 5084 ITelephony telephony = getITelephony(); 5085 if (telephony != null) { 5086 return telephony.getVisualVoicemailPackageName(mContext.getOpPackageName(), 5087 getAttributionTag(), getSubId()); 5088 } 5089 } catch (RemoteException ex) { 5090 } catch (NullPointerException ex) { 5091 } 5092 return null; 5093 } 5094 5095 /** 5096 * Set the visual voicemail SMS filter settings for the subscription ID pinned 5097 * to the TelephonyManager. 5098 * When the filter is enabled, {@link 5099 * VisualVoicemailService#onSmsReceived(VisualVoicemailTask, VisualVoicemailSms)} will be 5100 * called when a SMS matching the settings is received. Caller must be the default dialer, 5101 * system dialer, or carrier visual voicemail app. 5102 * 5103 * @param settings The settings for the filter, or {@code null} to disable the filter. 5104 * 5105 * @see TelecomManager#getDefaultDialerPackage() 5106 * @see CarrierConfigManager#KEY_CARRIER_VVM_PACKAGE_NAME_STRING_ARRAY 5107 */ setVisualVoicemailSmsFilterSettings(VisualVoicemailSmsFilterSettings settings)5108 public void setVisualVoicemailSmsFilterSettings(VisualVoicemailSmsFilterSettings settings) { 5109 if (settings == null) { 5110 disableVisualVoicemailSmsFilter(mSubId); 5111 } else { 5112 enableVisualVoicemailSmsFilter(mSubId, settings); 5113 } 5114 } 5115 5116 /** 5117 * Send a visual voicemail SMS. The caller must be the current default dialer. 5118 * A {@link VisualVoicemailService} uses this method to send a command via SMS to the carrier's 5119 * visual voicemail server. Some examples for carriers using the OMTP standard include 5120 * activating and deactivating visual voicemail, or requesting the current visual voicemail 5121 * provisioning status. See the OMTP Visual Voicemail specification for more information on the 5122 * format of these SMS messages. 5123 * 5124 * <p>Requires Permission: 5125 * {@link android.Manifest.permission#SEND_SMS SEND_SMS} 5126 * 5127 * @param number The destination number. 5128 * @param port The destination port for data SMS, or 0 for text SMS. 5129 * @param text The message content. For data sms, it will be encoded as a UTF-8 byte stream. 5130 * @param sentIntent The sent intent passed to the {@link SmsManager} 5131 * 5132 * @throws SecurityException if the caller is not the current default dialer 5133 * 5134 * @see SmsManager#sendDataMessage(String, String, short, byte[], PendingIntent, PendingIntent) 5135 * @see SmsManager#sendTextMessage(String, String, String, PendingIntent, PendingIntent) 5136 */ sendVisualVoicemailSms(String number, int port, String text, PendingIntent sentIntent)5137 public void sendVisualVoicemailSms(String number, int port, String text, 5138 PendingIntent sentIntent) { 5139 sendVisualVoicemailSmsForSubscriber(mSubId, number, port, text, sentIntent); 5140 } 5141 5142 /** 5143 * Enables the visual voicemail SMS filter for a phone account. When the filter is 5144 * enabled, Incoming SMS messages matching the OMTP VVM SMS interface will be redirected to the 5145 * visual voicemail client with 5146 * {@link android.provider.VoicemailContract.ACTION_VOICEMAIL_SMS_RECEIVED}. 5147 * 5148 * <p>This takes effect only when the caller is the default dialer. The enabled status and 5149 * settings persist through default dialer changes, but the filter will only honor the setting 5150 * set by the current default dialer. 5151 * 5152 * 5153 * @param subId The subscription id of the phone account. 5154 * @param settings The settings for the filter. 5155 */ 5156 /** @hide */ enableVisualVoicemailSmsFilter(int subId, VisualVoicemailSmsFilterSettings settings)5157 public void enableVisualVoicemailSmsFilter(int subId, 5158 VisualVoicemailSmsFilterSettings settings) { 5159 if(settings == null){ 5160 throw new IllegalArgumentException("Settings cannot be null"); 5161 } 5162 try { 5163 ITelephony telephony = getITelephony(); 5164 if (telephony != null) { 5165 telephony.enableVisualVoicemailSmsFilter(mContext.getOpPackageName(), subId, 5166 settings); 5167 } 5168 } catch (RemoteException ex) { 5169 } catch (NullPointerException ex) { 5170 } 5171 } 5172 5173 /** 5174 * Disables the visual voicemail SMS filter for a phone account. 5175 * 5176 * <p>This takes effect only when the caller is the default dialer. The enabled status and 5177 * settings persist through default dialer changes, but the filter will only honor the setting 5178 * set by the current default dialer. 5179 */ 5180 /** @hide */ disableVisualVoicemailSmsFilter(int subId)5181 public void disableVisualVoicemailSmsFilter(int subId) { 5182 try { 5183 ITelephony telephony = getITelephony(); 5184 if (telephony != null) { 5185 telephony.disableVisualVoicemailSmsFilter(mContext.getOpPackageName(), subId); 5186 } 5187 } catch (RemoteException ex) { 5188 } catch (NullPointerException ex) { 5189 } 5190 } 5191 5192 /** 5193 * @returns the settings of the visual voicemail SMS filter for a phone account, or {@code null} 5194 * if the filter is disabled. 5195 * 5196 * <p>This takes effect only when the caller is the default dialer. The enabled status and 5197 * settings persist through default dialer changes, but the filter will only honor the setting 5198 * set by the current default dialer. 5199 */ 5200 /** @hide */ 5201 @Nullable getVisualVoicemailSmsFilterSettings(int subId)5202 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(int subId) { 5203 try { 5204 ITelephony telephony = getITelephony(); 5205 if (telephony != null) { 5206 return telephony 5207 .getVisualVoicemailSmsFilterSettings(mContext.getOpPackageName(), subId); 5208 } 5209 } catch (RemoteException ex) { 5210 } catch (NullPointerException ex) { 5211 } 5212 5213 return null; 5214 } 5215 5216 /** 5217 * @returns the settings of the visual voicemail SMS filter for a phone account set by the 5218 * current active visual voicemail client, or {@code null} if the filter is disabled. 5219 * 5220 * <p>Requires the calling app to have READ_PRIVILEGED_PHONE_STATE permission. 5221 */ 5222 /** @hide */ 5223 @Nullable getActiveVisualVoicemailSmsFilterSettings(int subId)5224 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { 5225 try { 5226 ITelephony telephony = getITelephony(); 5227 if (telephony != null) { 5228 return telephony.getActiveVisualVoicemailSmsFilterSettings(subId); 5229 } 5230 } catch (RemoteException ex) { 5231 } catch (NullPointerException ex) { 5232 } 5233 5234 return null; 5235 } 5236 5237 /** 5238 * Send a visual voicemail SMS. The IPC caller must be the current default dialer. 5239 * 5240 * @param phoneAccountHandle The account to send the SMS with. 5241 * @param number The destination number. 5242 * @param port The destination port for data SMS, or 0 for text SMS. 5243 * @param text The message content. For data sms, it will be encoded as a UTF-8 byte stream. 5244 * @param sentIntent The sent intent passed to the {@link SmsManager} 5245 * 5246 * @see SmsManager#sendDataMessage(String, String, short, byte[], PendingIntent, PendingIntent) 5247 * @see SmsManager#sendTextMessage(String, String, String, PendingIntent, PendingIntent) 5248 * 5249 * @hide 5250 */ 5251 @RequiresPermission(android.Manifest.permission.SEND_SMS) sendVisualVoicemailSmsForSubscriber(int subId, String number, int port, String text, PendingIntent sentIntent)5252 public void sendVisualVoicemailSmsForSubscriber(int subId, String number, int port, 5253 String text, PendingIntent sentIntent) { 5254 try { 5255 ITelephony telephony = getITelephony(); 5256 if (telephony != null) { 5257 telephony.sendVisualVoicemailSmsForSubscriber( 5258 mContext.getOpPackageName(), mContext.getAttributionTag(), subId, number, 5259 port, text, sentIntent); 5260 } 5261 } catch (RemoteException ex) { 5262 } 5263 } 5264 5265 /** 5266 * Initial SIM activation state, unknown. Not set by any carrier apps. 5267 * @hide 5268 */ 5269 @SystemApi 5270 public static final int SIM_ACTIVATION_STATE_UNKNOWN = 0; 5271 5272 /** 5273 * indicate SIM is under activation procedure now. 5274 * intermediate state followed by another state update with activation procedure result: 5275 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5276 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5277 * @see #SIM_ACTIVATION_STATE_RESTRICTED 5278 * @hide 5279 */ 5280 @SystemApi 5281 public static final int SIM_ACTIVATION_STATE_ACTIVATING = 1; 5282 5283 /** 5284 * Indicate SIM has been successfully activated with full service 5285 * @hide 5286 */ 5287 @SystemApi 5288 public static final int SIM_ACTIVATION_STATE_ACTIVATED = 2; 5289 5290 /** 5291 * Indicate SIM has been deactivated by the carrier so that service is not available 5292 * and requires activation service to enable services. 5293 * Carrier apps could be signalled to set activation state to deactivated if detected 5294 * deactivated sim state and set it back to activated after successfully run activation service. 5295 * @hide 5296 */ 5297 @SystemApi 5298 public static final int SIM_ACTIVATION_STATE_DEACTIVATED = 3; 5299 5300 /** 5301 * Restricted state indicate SIM has been activated but service are restricted. 5302 * note this is currently available for data activation state. For example out of byte sim. 5303 * @hide 5304 */ 5305 @SystemApi 5306 public static final int SIM_ACTIVATION_STATE_RESTRICTED = 4; 5307 5308 /** 5309 * Sets the voice activation state 5310 * 5311 * <p>Requires Permission: 5312 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 5313 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5314 * 5315 * @param activationState The voice activation state 5316 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5317 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5318 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5319 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5320 * @hide 5321 */ 5322 @SystemApi 5323 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setVoiceActivationState(@imActivationState int activationState)5324 public void setVoiceActivationState(@SimActivationState int activationState) { 5325 setVoiceActivationState(getSubId(), activationState); 5326 } 5327 5328 /** 5329 * Sets the voice activation state for the given subscriber. 5330 * 5331 * <p>Requires Permission: 5332 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 5333 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5334 * 5335 * @param subId The subscription id. 5336 * @param activationState The voice activation state of the given subscriber. 5337 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5338 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5339 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5340 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5341 * @hide 5342 */ 5343 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setVoiceActivationState(int subId, @SimActivationState int activationState)5344 public void setVoiceActivationState(int subId, @SimActivationState int activationState) { 5345 try { 5346 ITelephony telephony = getITelephony(); 5347 if (telephony != null) 5348 telephony.setVoiceActivationState(subId, activationState); 5349 } catch (RemoteException ex) { 5350 } catch (NullPointerException ex) { 5351 } 5352 } 5353 5354 /** 5355 * Sets the data activation state 5356 * 5357 * <p>Requires Permission: 5358 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 5359 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5360 * 5361 * @param activationState The data activation state 5362 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5363 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5364 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5365 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5366 * @see #SIM_ACTIVATION_STATE_RESTRICTED 5367 * @hide 5368 */ 5369 @SystemApi 5370 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataActivationState(@imActivationState int activationState)5371 public void setDataActivationState(@SimActivationState int activationState) { 5372 setDataActivationState(getSubId(), activationState); 5373 } 5374 5375 /** 5376 * Sets the data activation state for the given subscriber. 5377 * 5378 * <p>Requires Permission: 5379 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 5380 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5381 * 5382 * @param subId The subscription id. 5383 * @param activationState The data activation state of the given subscriber. 5384 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5385 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5386 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5387 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5388 * @see #SIM_ACTIVATION_STATE_RESTRICTED 5389 * @hide 5390 */ 5391 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataActivationState(int subId, @SimActivationState int activationState)5392 public void setDataActivationState(int subId, @SimActivationState int activationState) { 5393 try { 5394 ITelephony telephony = getITelephony(); 5395 if (telephony != null) 5396 telephony.setDataActivationState(subId, activationState); 5397 } catch (RemoteException ex) { 5398 } catch (NullPointerException ex) { 5399 } 5400 } 5401 5402 /** 5403 * Returns the voice activation state 5404 * 5405 * <p>Requires Permission: 5406 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 5407 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5408 * 5409 * @return voiceActivationState 5410 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5411 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5412 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5413 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5414 * @hide 5415 */ 5416 @SystemApi 5417 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getVoiceActivationState()5418 public @SimActivationState int getVoiceActivationState() { 5419 return getVoiceActivationState(getSubId()); 5420 } 5421 5422 /** 5423 * Returns the voice activation state for the given subscriber. 5424 * 5425 * <p>Requires Permission: 5426 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 5427 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5428 * 5429 * @param subId The subscription id. 5430 * 5431 * @return voiceActivationState for the given subscriber 5432 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5433 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5434 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5435 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5436 * @hide 5437 */ 5438 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getVoiceActivationState(int subId)5439 public @SimActivationState int getVoiceActivationState(int subId) { 5440 try { 5441 ITelephony telephony = getITelephony(); 5442 if (telephony != null) 5443 return telephony.getVoiceActivationState(subId, getOpPackageName()); 5444 } catch (RemoteException ex) { 5445 } catch (NullPointerException ex) { 5446 } 5447 return SIM_ACTIVATION_STATE_UNKNOWN; 5448 } 5449 5450 /** 5451 * Returns the data activation state 5452 * 5453 * <p>Requires Permission: 5454 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 5455 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5456 * 5457 * @return dataActivationState for the given subscriber 5458 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5459 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5460 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5461 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5462 * @see #SIM_ACTIVATION_STATE_RESTRICTED 5463 * @hide 5464 */ 5465 @SystemApi 5466 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getDataActivationState()5467 public @SimActivationState int getDataActivationState() { 5468 return getDataActivationState(getSubId()); 5469 } 5470 5471 /** 5472 * Returns the data activation state for the given subscriber. 5473 * 5474 * <p>Requires Permission: 5475 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 5476 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5477 * 5478 * @param subId The subscription id. 5479 * 5480 * @return dataActivationState for the given subscriber 5481 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5482 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5483 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5484 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5485 * @see #SIM_ACTIVATION_STATE_RESTRICTED 5486 * @hide 5487 */ 5488 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getDataActivationState(int subId)5489 public @SimActivationState int getDataActivationState(int subId) { 5490 try { 5491 ITelephony telephony = getITelephony(); 5492 if (telephony != null) 5493 return telephony.getDataActivationState(subId, getOpPackageName()); 5494 } catch (RemoteException ex) { 5495 } catch (NullPointerException ex) { 5496 } 5497 return SIM_ACTIVATION_STATE_UNKNOWN; 5498 } 5499 5500 /** 5501 * Returns the voice mail count. Return 0 if unavailable, -1 if there are unread voice messages 5502 * but the count is unknown. 5503 * @hide 5504 */ 5505 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5506 @UnsupportedAppUsage getVoiceMessageCount()5507 public int getVoiceMessageCount() { 5508 return getVoiceMessageCount(getSubId()); 5509 } 5510 5511 /** 5512 * Returns the voice mail count for a subscription. Return 0 if unavailable or the caller does 5513 * not have the READ_PHONE_STATE permission. 5514 * @param subId whose voice message count is returned 5515 * @hide 5516 */ 5517 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5518 @UnsupportedAppUsage getVoiceMessageCount(int subId)5519 public int getVoiceMessageCount(int subId) { 5520 try { 5521 ITelephony telephony = getITelephony(); 5522 if (telephony == null) 5523 return 0; 5524 return telephony.getVoiceMessageCountForSubscriber(subId, getOpPackageName(), 5525 getAttributionTag()); 5526 } catch (RemoteException ex) { 5527 return 0; 5528 } catch (NullPointerException ex) { 5529 // This could happen before phone restarts due to crashing 5530 return 0; 5531 } 5532 } 5533 5534 /** 5535 * Retrieves the alphabetic identifier associated with the voice 5536 * mail number. 5537 * 5538 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 5539 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5540 */ 5541 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 5542 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getVoiceMailAlphaTag()5543 public String getVoiceMailAlphaTag() { 5544 return getVoiceMailAlphaTag(getSubId()); 5545 } 5546 5547 /** 5548 * Retrieves the alphabetic identifier associated with the voice 5549 * mail number for a subscription. 5550 * @param subId whose alphabetic identifier associated with the 5551 * voice mail number is returned 5552 * @hide 5553 */ 5554 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5555 @UnsupportedAppUsage getVoiceMailAlphaTag(int subId)5556 public String getVoiceMailAlphaTag(int subId) { 5557 try { 5558 IPhoneSubInfo info = getSubscriberInfoService(); 5559 if (info == null) 5560 return null; 5561 return info.getVoiceMailAlphaTagForSubscriber(subId, getOpPackageName(), 5562 getAttributionTag()); 5563 } catch (RemoteException ex) { 5564 return null; 5565 } catch (NullPointerException ex) { 5566 // This could happen before phone restarts due to crashing 5567 return null; 5568 } 5569 } 5570 5571 /** 5572 * Send the special dialer code. The IPC caller must be the current default dialer or have 5573 * carrier privileges (see {@link #hasCarrierPrivileges}). 5574 * 5575 * @param inputCode The special dialer code to send 5576 * 5577 * @throws SecurityException if the caller does not have carrier privileges or is not the 5578 * current default dialer 5579 */ sendDialerSpecialCode(String inputCode)5580 public void sendDialerSpecialCode(String inputCode) { 5581 try { 5582 final ITelephony telephony = getITelephony(); 5583 if (telephony == null) { 5584 return; 5585 } 5586 telephony.sendDialerSpecialCode(mContext.getOpPackageName(), inputCode); 5587 } catch (RemoteException ex) { 5588 Rlog.e(TAG, "Telephony#sendDialerSpecialCode RemoteException" + ex); 5589 } 5590 } 5591 5592 /** 5593 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 5594 * @return the IMPI, or null if not present or not loaded 5595 * @hide 5596 */ 5597 @UnsupportedAppUsage getIsimImpi()5598 public String getIsimImpi() { 5599 try { 5600 IPhoneSubInfo info = getSubscriberInfoService(); 5601 if (info == null) 5602 return null; 5603 //get the Isim Impi based on subId 5604 return info.getIsimImpi(getSubId()); 5605 } catch (RemoteException ex) { 5606 return null; 5607 } catch (NullPointerException ex) { 5608 // This could happen before phone restarts due to crashing 5609 return null; 5610 } 5611 } 5612 5613 /** 5614 * Returns the IMS home network domain name that was loaded from the ISIM {@see #APPTYPE_ISIM}. 5615 * @return the IMS domain name. Returns {@code null} if ISIM hasn't been loaded or IMS domain 5616 * hasn't been loaded or isn't present on the ISIM. 5617 * 5618 * <p>Requires Permission: 5619 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 5620 * @hide 5621 */ 5622 @Nullable 5623 @SystemApi 5624 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getIsimDomain()5625 public String getIsimDomain() { 5626 try { 5627 IPhoneSubInfo info = getSubscriberInfoService(); 5628 if (info == null) 5629 return null; 5630 //get the Isim Domain based on subId 5631 return info.getIsimDomain(getSubId()); 5632 } catch (RemoteException ex) { 5633 return null; 5634 } catch (NullPointerException ex) { 5635 // This could happen before phone restarts due to crashing 5636 return null; 5637 } 5638 } 5639 5640 /** 5641 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 5642 * @return an array of IMPU strings, with one IMPU per string, or null if 5643 * not present or not loaded 5644 * @hide 5645 */ 5646 @UnsupportedAppUsage 5647 @Nullable 5648 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getIsimImpu()5649 public String[] getIsimImpu() { 5650 try { 5651 IPhoneSubInfo info = getSubscriberInfoService(); 5652 if (info == null) 5653 return null; 5654 //get the Isim Impu based on subId 5655 return info.getIsimImpu(getSubId()); 5656 } catch (RemoteException ex) { 5657 return null; 5658 } catch (NullPointerException ex) { 5659 // This could happen before phone restarts due to crashing 5660 return null; 5661 } 5662 } 5663 5664 /** 5665 * Device call state: No activity. 5666 */ 5667 public static final int CALL_STATE_IDLE = 0; 5668 /** 5669 * Device call state: Ringing. A new call arrived and is 5670 * ringing or waiting. In the latter case, another call is 5671 * already active. 5672 */ 5673 public static final int CALL_STATE_RINGING = 1; 5674 /** 5675 * Device call state: Off-hook. At least one call exists 5676 * that is dialing, active, or on hold, and no calls are ringing 5677 * or waiting. 5678 */ 5679 public static final int CALL_STATE_OFFHOOK = 2; 5680 5681 /** 5682 * Returns the state of all calls on the device. 5683 * <p> 5684 * This method considers not only calls in the Telephony stack, but also calls via other 5685 * {@link android.telecom.ConnectionService} implementations. 5686 * <p> 5687 * Note: The call state returned via this method may differ from what is reported by 5688 * {@link PhoneStateListener#onCallStateChanged(int, String)}, as that callback only considers 5689 * Telephony (mobile) calls. 5690 * <p> 5691 * Requires Permission: 5692 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} for applications 5693 * targeting API level 31+. 5694 * 5695 * @return the current call state. 5696 * @deprecated Use {@link #getCallStateForSubscription} to retrieve the call state for a 5697 * specific telephony subscription (which allows carrier privileged apps), 5698 * {@link TelephonyCallback.CallStateListener} for real-time call state updates, or 5699 * {@link TelecomManager#isInCall()}, which supplies an aggregate "in call" state for the entire 5700 * device. 5701 */ 5702 @RequiresPermission(value = android.Manifest.permission.READ_PHONE_STATE, conditional = true) 5703 @Deprecated getCallState()5704 public @CallState int getCallState() { 5705 if (mContext != null) { 5706 TelecomManager telecomManager = mContext.getSystemService(TelecomManager.class); 5707 if (telecomManager != null) { 5708 return telecomManager.getCallState(); 5709 } 5710 } 5711 return CALL_STATE_IDLE; 5712 } 5713 5714 /** 5715 * Retrieve the call state for a specific subscription that was specified when this 5716 * TelephonyManager instance was created. 5717 * <p>Requires Permission: 5718 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} or that the calling 5719 * application has carrier privileges (see {@link #hasCarrierPrivileges}). 5720 * @see TelephonyManager#createForSubscriptionId(int) 5721 * @see TelephonyManager#createForPhoneAccountHandle(PhoneAccountHandle) 5722 * @return The call state of the subscription associated with this TelephonyManager instance. 5723 */ 5724 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCallStateForSubscription()5725 public @CallState int getCallStateForSubscription() { 5726 return getCallState(getSubId()); 5727 } 5728 5729 /** 5730 * Returns the Telephony call state for calls on a specific subscription. 5731 * <p> 5732 * Note: This method considers ONLY telephony/mobile calls, where {@link #getCallState()} 5733 * considers the state of calls from other {@link android.telecom.ConnectionService} 5734 * implementations. 5735 * <p> 5736 * Requires Permission: 5737 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} for applications 5738 * targeting API level 31+ or that the calling application has carrier privileges 5739 * (see {@link #hasCarrierPrivileges()}). 5740 * 5741 * @param subId the subscription to check call state for. 5742 * @hide 5743 */ 5744 @UnsupportedAppUsage 5745 @RequiresPermission(value = android.Manifest.permission.READ_PHONE_STATE, conditional = true) getCallState(int subId)5746 public @CallState int getCallState(int subId) { 5747 ITelephony telephony = getITelephony(); 5748 if (telephony == null) { 5749 return CALL_STATE_IDLE; 5750 } 5751 try { 5752 return telephony.getCallStateForSubscription(subId, mContext.getPackageName(), 5753 mContext.getAttributionTag()); 5754 } catch (RemoteException e) { 5755 return CALL_STATE_IDLE; 5756 } 5757 } 5758 5759 /** 5760 * @hide 5761 */ 5762 @UnsupportedAppUsage getSubscriberInfo()5763 private IPhoneSubInfo getSubscriberInfo() { 5764 return getSubscriberInfoService(); 5765 } 5766 5767 /** 5768 * Returns the Telephony call state for calls on a specific SIM slot. 5769 * <p> 5770 * Note: This method considers ONLY telephony/mobile calls, where {@link #getCallState()} 5771 * considers the state of calls from other {@link android.telecom.ConnectionService} 5772 * implementations. 5773 * <p> 5774 * Requires Permission: 5775 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} for applications 5776 * targeting API level 31+ or that the calling application has carrier privileges 5777 * (see {@link #hasCarrierPrivileges()}). 5778 * 5779 * @param slotIndex the SIM slot index to check call state for. 5780 * @hide 5781 */ 5782 @RequiresPermission(value = android.Manifest.permission.READ_PHONE_STATE, conditional = true) getCallStateForSlot(int slotIndex)5783 public @CallState int getCallStateForSlot(int slotIndex) { 5784 try { 5785 int[] subId = SubscriptionManager.getSubId(slotIndex); 5786 ITelephony telephony = getITelephony(); 5787 if (telephony == null || subId == null || subId.length == 0) { 5788 return CALL_STATE_IDLE; 5789 } 5790 return telephony.getCallStateForSubscription(subId[0], mContext.getPackageName(), 5791 mContext.getAttributionTag()); 5792 } catch (RemoteException | NullPointerException ex) { 5793 // the phone process is restarting. 5794 return CALL_STATE_IDLE; 5795 } 5796 } 5797 5798 5799 /** Data connection activity: No traffic. */ 5800 public static final int DATA_ACTIVITY_NONE = 0x00000000; 5801 /** Data connection activity: Currently receiving IP PPP traffic. */ 5802 public static final int DATA_ACTIVITY_IN = 0x00000001; 5803 /** Data connection activity: Currently sending IP PPP traffic. */ 5804 public static final int DATA_ACTIVITY_OUT = 0x00000002; 5805 /** Data connection activity: Currently both sending and receiving 5806 * IP PPP traffic. */ 5807 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 5808 /** 5809 * Data connection is active, but physical link is down 5810 */ 5811 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 5812 5813 /** 5814 * Returns a constant indicating the type of activity on a data connection 5815 * (cellular). 5816 * 5817 * @see #DATA_ACTIVITY_NONE 5818 * @see #DATA_ACTIVITY_IN 5819 * @see #DATA_ACTIVITY_OUT 5820 * @see #DATA_ACTIVITY_INOUT 5821 * @see #DATA_ACTIVITY_DORMANT 5822 */ getDataActivity()5823 public int getDataActivity() { 5824 try { 5825 ITelephony telephony = getITelephony(); 5826 if (telephony == null) 5827 return DATA_ACTIVITY_NONE; 5828 return telephony.getDataActivityForSubId( 5829 getSubId(SubscriptionManager.getActiveDataSubscriptionId())); 5830 } catch (RemoteException ex) { 5831 // the phone process is restarting. 5832 return DATA_ACTIVITY_NONE; 5833 } catch (NullPointerException ex) { 5834 // the phone process is restarting. 5835 return DATA_ACTIVITY_NONE; 5836 } 5837 } 5838 5839 /** @hide */ 5840 @IntDef(prefix = {"DATA_"}, value = { 5841 DATA_UNKNOWN, 5842 DATA_DISCONNECTED, 5843 DATA_CONNECTING, 5844 DATA_CONNECTED, 5845 DATA_SUSPENDED, 5846 DATA_DISCONNECTING, 5847 }) 5848 @Retention(RetentionPolicy.SOURCE) 5849 public @interface DataState{} 5850 5851 /** Data connection state: Unknown. Used before we know the state. */ 5852 public static final int DATA_UNKNOWN = -1; 5853 /** Data connection state: Disconnected. IP traffic not available. */ 5854 public static final int DATA_DISCONNECTED = 0; 5855 /** Data connection state: Currently setting up a data connection. */ 5856 public static final int DATA_CONNECTING = 1; 5857 /** Data connection state: Connected. IP traffic should be available. */ 5858 public static final int DATA_CONNECTED = 2; 5859 /** Data connection state: Suspended. The connection is up, but IP 5860 * traffic is temporarily unavailable. For example, in a 2G network, 5861 * data activity may be suspended when a voice call arrives. */ 5862 public static final int DATA_SUSPENDED = 3; 5863 /** 5864 * Data connection state: Disconnecting. 5865 * 5866 * IP traffic may be available but will cease working imminently. 5867 */ 5868 public static final int DATA_DISCONNECTING = 4; 5869 5870 /** 5871 * Used for checking if the SDK version for {@link TelephonyManager#getDataState} is above Q. 5872 */ 5873 @ChangeId 5874 @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q) 5875 private static final long GET_DATA_STATE_R_VERSION = 148534348L; 5876 5877 /** 5878 * Returns a constant indicating the current data connection state 5879 * (cellular). 5880 * 5881 * @see #DATA_DISCONNECTED 5882 * @see #DATA_CONNECTING 5883 * @see #DATA_CONNECTED 5884 * @see #DATA_SUSPENDED 5885 * @see #DATA_DISCONNECTING 5886 */ getDataState()5887 public int getDataState() { 5888 try { 5889 ITelephony telephony = getITelephony(); 5890 if (telephony == null) 5891 return DATA_DISCONNECTED; 5892 int state = telephony.getDataStateForSubId( 5893 getSubId(SubscriptionManager.getActiveDataSubscriptionId())); 5894 if (state == TelephonyManager.DATA_DISCONNECTING 5895 && !Compatibility.isChangeEnabled(GET_DATA_STATE_R_VERSION)) { 5896 return TelephonyManager.DATA_CONNECTED; 5897 } 5898 5899 return state; 5900 } catch (RemoteException ex) { 5901 // the phone process is restarting. 5902 return DATA_DISCONNECTED; 5903 } catch (NullPointerException ex) { 5904 return DATA_DISCONNECTED; 5905 } 5906 } 5907 5908 /** 5909 * @hide 5910 */ 5911 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getITelephony()5912 private ITelephony getITelephony() { 5913 // Keeps cache disabled until test fixes are checked into AOSP. 5914 if (!sServiceHandleCacheEnabled) { 5915 return ITelephony.Stub.asInterface( 5916 TelephonyFrameworkInitializer 5917 .getTelephonyServiceManager() 5918 .getTelephonyServiceRegisterer() 5919 .get()); 5920 } 5921 5922 if (sITelephony == null) { 5923 ITelephony temp = ITelephony.Stub.asInterface( 5924 TelephonyFrameworkInitializer 5925 .getTelephonyServiceManager() 5926 .getTelephonyServiceRegisterer() 5927 .get()); 5928 synchronized (sCacheLock) { 5929 if (sITelephony == null && temp != null) { 5930 try { 5931 sITelephony = temp; 5932 sITelephony.asBinder().linkToDeath(sServiceDeath, 0); 5933 } catch (Exception e) { 5934 // something has gone horribly wrong 5935 sITelephony = null; 5936 } 5937 } 5938 } 5939 } 5940 return sITelephony; 5941 } 5942 getIOns()5943 private IOns getIOns() { 5944 return IOns.Stub.asInterface( 5945 TelephonyFrameworkInitializer 5946 .getTelephonyServiceManager() 5947 .getOpportunisticNetworkServiceRegisterer() 5948 .get()); 5949 } 5950 5951 // 5952 // 5953 // PhoneStateListener 5954 // 5955 // 5956 5957 /** 5958 * Registers a listener object to receive notification of changes 5959 * in specified telephony states. 5960 * <p> 5961 * To register a listener, pass a {@link PhoneStateListener} and specify at least one telephony 5962 * state of interest in the events argument. 5963 * 5964 * At registration, and when a specified telephony state changes, the telephony manager invokes 5965 * the appropriate callback method on the listener object and passes the current (updated) 5966 * values. 5967 * <p> 5968 * To un-register a listener, pass the listener object and set the events argument to 5969 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 5970 * 5971 * If this TelephonyManager object has been created with {@link #createForSubscriptionId}, 5972 * applies to the given subId. Otherwise, applies to 5973 * {@link SubscriptionManager#getDefaultSubscriptionId()}. To listen events for multiple subIds, 5974 * pass a separate listener object to each TelephonyManager object created with 5975 * {@link #createForSubscriptionId}. 5976 * 5977 * Note: if you call this method while in the middle of a binder transaction, you <b>must</b> 5978 * call {@link android.os.Binder#clearCallingIdentity()} before calling this method. A 5979 * {@link SecurityException} will be thrown otherwise. 5980 * 5981 * This API should be used sparingly -- large numbers of listeners will cause system 5982 * instability. If a process has registered too many listeners without unregistering them, it 5983 * may encounter an {@link IllegalStateException} when trying to register more listeners. 5984 * 5985 * @param listener The {@link PhoneStateListener} object to register 5986 * (or unregister) 5987 * @param events The telephony state(s) of interest to the listener, 5988 * as a bitwise-OR combination of {@link PhoneStateListener} 5989 * LISTEN_ flags. 5990 * @deprecated Use {@link #registerTelephonyCallback(Executor, TelephonyCallback)}. 5991 */ 5992 @Deprecated listen(PhoneStateListener listener, int events)5993 public void listen(PhoneStateListener listener, int events) { 5994 if (mContext == null) return; 5995 boolean notifyNow = (getITelephony() != null); 5996 TelephonyRegistryManager telephonyRegistry = 5997 (TelephonyRegistryManager) 5998 mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE); 5999 if (telephonyRegistry != null) { 6000 telephonyRegistry.listenFromListener(mSubId, getOpPackageName(), 6001 getAttributionTag(), listener, events, notifyNow); 6002 } else { 6003 Rlog.w(TAG, "telephony registry not ready."); 6004 } 6005 } 6006 6007 /** @hide */ 6008 @Retention(RetentionPolicy.SOURCE) 6009 @IntDef(prefix = {"ERI_"}, value = { 6010 ERI_ON, 6011 ERI_OFF, 6012 ERI_FLASH 6013 }) 6014 public @interface EriIconIndex {} 6015 6016 /** 6017 * ERI (Enhanced Roaming Indicator) is ON i.e value 0 defined by 6018 * 3GPP2 C.R1001-H v1.0 Table 8.1-1. 6019 */ 6020 public static final int ERI_ON = 0; 6021 6022 /** 6023 * ERI (Enhanced Roaming Indicator) is OFF i.e value 1 defined by 6024 * 3GPP2 C.R1001-H v1.0 Table 8.1-1. 6025 */ 6026 public static final int ERI_OFF = 1; 6027 6028 /** 6029 * ERI (Enhanced Roaming Indicator) is FLASH i.e value 2 defined by 6030 * 3GPP2 C.R1001-H v1.0 Table 8.1-1. 6031 */ 6032 public static final int ERI_FLASH = 2; 6033 6034 /** @hide */ 6035 @Retention(RetentionPolicy.SOURCE) 6036 @IntDef(prefix = {"ERI_ICON_MODE_"}, value = { 6037 ERI_ICON_MODE_NORMAL, 6038 ERI_ICON_MODE_FLASH 6039 }) 6040 public @interface EriIconMode {} 6041 6042 /** 6043 * ERI (Enhanced Roaming Indicator) icon mode is normal. This constant represents that 6044 * the ERI icon should be displayed normally. 6045 * 6046 * Note: ERI is defined 3GPP2 C.R1001-H Table 8.1-1 6047 * @hide 6048 */ 6049 public static final int ERI_ICON_MODE_NORMAL = 0; 6050 6051 /** 6052 * ERI (Enhanced Roaming Indicator) icon mode flash. This constant represents that 6053 * the ERI icon should be flashing. 6054 * 6055 * Note: ERI is defined 3GPP2 C.R1001-H Table 8.1-1 6056 * @hide 6057 */ 6058 public static final int ERI_ICON_MODE_FLASH = 1; 6059 6060 /** 6061 * Returns the CDMA ERI icon display number. The number is assigned by 6062 * 3GPP2 C.R1001-H v1.0 Table 8.1-1. Additionally carriers define their own ERI display numbers. 6063 * Defined values are {@link #ERI_ON}, {@link #ERI_OFF}, and {@link #ERI_FLASH}. 6064 * @hide 6065 */ 6066 @SystemApi 6067 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getCdmaEnhancedRoamingIndicatorDisplayNumber()6068 public @EriIconIndex int getCdmaEnhancedRoamingIndicatorDisplayNumber() { 6069 return getCdmaEriIconIndex(getSubId()); 6070 } 6071 6072 /** 6073 * Returns the CDMA ERI icon index to display for a subscription. 6074 * @hide 6075 */ 6076 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 6077 @UnsupportedAppUsage getCdmaEriIconIndex(int subId)6078 public @EriIconIndex int getCdmaEriIconIndex(int subId) { 6079 try { 6080 ITelephony telephony = getITelephony(); 6081 if (telephony == null) 6082 return -1; 6083 return telephony.getCdmaEriIconIndexForSubscriber(subId, getOpPackageName(), 6084 getAttributionTag()); 6085 } catch (RemoteException ex) { 6086 // the phone process is restarting. 6087 return -1; 6088 } catch (NullPointerException ex) { 6089 return -1; 6090 } 6091 } 6092 6093 /** 6094 * Returns the CDMA ERI icon mode for a subscription. 6095 * 0 - ON 6096 * 1 - FLASHING 6097 * 6098 * @hide 6099 */ 6100 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 6101 @UnsupportedAppUsage getCdmaEriIconMode(int subId)6102 public @EriIconMode int getCdmaEriIconMode(int subId) { 6103 try { 6104 ITelephony telephony = getITelephony(); 6105 if (telephony == null) 6106 return -1; 6107 return telephony.getCdmaEriIconModeForSubscriber(subId, getOpPackageName(), 6108 getAttributionTag()); 6109 } catch (RemoteException ex) { 6110 // the phone process is restarting. 6111 return -1; 6112 } catch (NullPointerException ex) { 6113 return -1; 6114 } 6115 } 6116 6117 /** 6118 * Returns the CDMA ERI text, 6119 * 6120 * @hide 6121 */ 6122 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCdmaEriText()6123 public String getCdmaEriText() { 6124 return getCdmaEriText(getSubId()); 6125 } 6126 6127 /** 6128 * Returns the CDMA ERI text, of a subscription 6129 * 6130 * @hide 6131 */ 6132 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 6133 @UnsupportedAppUsage getCdmaEriText(int subId)6134 public String getCdmaEriText(int subId) { 6135 try { 6136 ITelephony telephony = getITelephony(); 6137 if (telephony == null) 6138 return null; 6139 return telephony.getCdmaEriTextForSubscriber(subId, getOpPackageName(), 6140 getAttributionTag()); 6141 } catch (RemoteException ex) { 6142 // the phone process is restarting. 6143 return null; 6144 } catch (NullPointerException ex) { 6145 return null; 6146 } 6147 } 6148 6149 /** 6150 * @return true if the current device is "voice capable". 6151 * <p> 6152 * "Voice capable" means that this device supports circuit-switched 6153 * (i.e. voice) phone calls over the telephony network, and is allowed 6154 * to display the in-call UI while a cellular voice call is active. 6155 * This will be false on "data only" devices which can't make voice 6156 * calls and don't support any in-call UI. 6157 * <p> 6158 * Note: the meaning of this flag is subtly different from the 6159 * PackageManager.FEATURE_TELEPHONY system feature, which is available 6160 * on any device with a telephony radio, even if the device is 6161 * data-only. 6162 */ isVoiceCapable()6163 public boolean isVoiceCapable() { 6164 if (mContext == null) return true; 6165 return mContext.getResources().getBoolean( 6166 com.android.internal.R.bool.config_voice_capable); 6167 } 6168 6169 /** 6170 * @return true if the current device supports sms service. 6171 * <p> 6172 * If true, this means that the device supports both sending and 6173 * receiving sms via the telephony network. 6174 * <p> 6175 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 6176 * disabled when device doesn't support sms. 6177 */ isSmsCapable()6178 public boolean isSmsCapable() { 6179 if (mContext == null) return true; 6180 return mContext.getResources().getBoolean( 6181 com.android.internal.R.bool.config_sms_capable); 6182 } 6183 6184 /** 6185 * Requests all available cell information from all radios on the device including the 6186 * camped/registered, serving, and neighboring cells. 6187 * 6188 * <p>The response can include one or more {@link android.telephony.CellInfoGsm CellInfoGsm}, 6189 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 6190 * {@link android.telephony.CellInfoTdscdma CellInfoTdscdma}, 6191 * {@link android.telephony.CellInfoLte CellInfoLte}, and 6192 * {@link android.telephony.CellInfoWcdma CellInfoWcdma} objects, in any combination. 6193 * It is typical to see instances of one or more of any these in the list. In addition, zero 6194 * or more of the returned objects may be considered registered; that is, their 6195 * {@link android.telephony.CellInfo#isRegistered CellInfo.isRegistered()} 6196 * methods may return true, indicating that the cell is being used or would be used for 6197 * signaling communication if necessary. 6198 * 6199 * <p>Beginning with {@link android.os.Build.VERSION_CODES#Q Android Q}, 6200 * if this API results in a change of the cached CellInfo, that change will be reported via 6201 * {@link android.telephony.PhoneStateListener#onCellInfoChanged onCellInfoChanged()}. 6202 * 6203 * <p>Apps targeting {@link android.os.Build.VERSION_CODES#Q Android Q} or higher will no 6204 * longer trigger a refresh of the cached CellInfo by invoking this API. Instead, those apps 6205 * will receive the latest cached results, which may not be current. Apps targeting 6206 * {@link android.os.Build.VERSION_CODES#Q Android Q} or higher that wish to request updated 6207 * CellInfo should call 6208 * {@link android.telephony.TelephonyManager#requestCellInfoUpdate requestCellInfoUpdate()}; 6209 * however, in all cases, updates will be rate-limited and are not guaranteed. To determine the 6210 * recency of CellInfo data, callers should check 6211 * {@link android.telephony.CellInfo#getTimeStamp CellInfo#getTimeStamp()}. 6212 * 6213 * <p>This method returns valid data for devices with 6214 * {@link android.content.pm.PackageManager#FEATURE_TELEPHONY FEATURE_TELEPHONY}. In cases 6215 * where only partial information is available for a particular CellInfo entry, unavailable 6216 * fields will be reported as {@link android.telephony.CellInfo#UNAVAILABLE}. All reported 6217 * cells will include at least a valid set of technology-specific identification info and a 6218 * power level measurement. 6219 * 6220 * <p>This method is preferred over using {@link 6221 * android.telephony.TelephonyManager#getCellLocation getCellLocation()}. 6222 * 6223 * @return List of {@link android.telephony.CellInfo}; null if cell 6224 * information is unavailable. 6225 */ 6226 @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) getAllCellInfo()6227 public List<CellInfo> getAllCellInfo() { 6228 try { 6229 ITelephony telephony = getITelephony(); 6230 if (telephony == null) 6231 return null; 6232 return telephony.getAllCellInfo(getOpPackageName(), getAttributionTag()); 6233 } catch (RemoteException ex) { 6234 } catch (NullPointerException ex) { 6235 } 6236 return null; 6237 } 6238 6239 /** Callback for providing asynchronous {@link CellInfo} on request */ 6240 public abstract static class CellInfoCallback { 6241 /** 6242 * Success response to 6243 * {@link android.telephony.TelephonyManager#requestCellInfoUpdate requestCellInfoUpdate()}. 6244 * 6245 * Invoked when there is a response to 6246 * {@link android.telephony.TelephonyManager#requestCellInfoUpdate requestCellInfoUpdate()} 6247 * to provide a list of {@link CellInfo}. If no {@link CellInfo} is available then an empty 6248 * list will be provided. If an error occurs, null will be provided unless the onError 6249 * callback is overridden. 6250 * 6251 * @param cellInfo a list of {@link CellInfo}, an empty list, or null. 6252 * 6253 * {@see android.telephony.TelephonyManager#getAllCellInfo getAllCellInfo()} 6254 */ onCellInfo(@onNull List<CellInfo> cellInfo)6255 public abstract void onCellInfo(@NonNull List<CellInfo> cellInfo); 6256 6257 /** @hide */ 6258 @Retention(RetentionPolicy.SOURCE) 6259 @IntDef(prefix = {"ERROR_"}, value = {ERROR_TIMEOUT, ERROR_MODEM_ERROR}) 6260 public @interface CellInfoCallbackError {} 6261 6262 /** 6263 * The system timed out waiting for a response from the Radio. 6264 */ 6265 public static final int ERROR_TIMEOUT = 1; 6266 6267 /** 6268 * The modem returned a failure. 6269 */ 6270 public static final int ERROR_MODEM_ERROR = 2; 6271 6272 /** 6273 * Error response to 6274 * {@link TelephonyManager#requestCellInfoUpdate requestCellInfoUpdate()}. 6275 * 6276 * Invoked when an error condition prevents updated {@link CellInfo} from being fetched 6277 * and returned from the modem. Callers of requestCellInfoUpdate() should override this 6278 * function to receive detailed status information in the event of an error. By default, 6279 * this function will invoke onCellInfo() with null. 6280 * 6281 * @param errorCode an error code indicating the type of failure. 6282 * @param detail a Throwable object with additional detail regarding the failure if 6283 * available, otherwise null. 6284 */ onError(@ellInfoCallbackError int errorCode, @Nullable Throwable detail)6285 public void onError(@CellInfoCallbackError int errorCode, @Nullable Throwable detail) { 6286 // By default, simply invoke the success callback with an empty list. 6287 onCellInfo(new ArrayList<CellInfo>()); 6288 } 6289 }; 6290 6291 /** 6292 * Used for checking if the target SDK version for the current process is S or above. 6293 * 6294 * <p> Applies to the following methods: 6295 * {@link #requestCellInfoUpdate}, 6296 * {@link #setPreferredOpportunisticDataSubscription}, 6297 * {@link #updateAvailableNetworks}, 6298 * requestNumberVerification(), 6299 * setSimPowerStateForSlot(), 6300 */ 6301 @ChangeId 6302 @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.R) 6303 private static final long NULL_TELEPHONY_THROW_NO_CB = 182185642L; 6304 6305 /** 6306 * Requests all available cell information from the current subscription for observed 6307 * camped/registered, serving, and neighboring cells. 6308 * 6309 * <p>Any available results from this request will be provided by calls to 6310 * {@link android.telephony.PhoneStateListener#onCellInfoChanged onCellInfoChanged()} 6311 * for each active subscription. 6312 * 6313 * <p>This method returns valid data for devices with 6314 * {@link android.content.pm.PackageManager#FEATURE_TELEPHONY FEATURE_TELEPHONY}. On devices 6315 * that do not implement this feature, the behavior is not reliable. 6316 * 6317 * @param executor the executor on which callback will be invoked. 6318 * @param callback a callback to receive CellInfo. 6319 */ 6320 @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) requestCellInfoUpdate( @onNull @allbackExecutor Executor executor, @NonNull CellInfoCallback callback)6321 public void requestCellInfoUpdate( 6322 @NonNull @CallbackExecutor Executor executor, @NonNull CellInfoCallback callback) { 6323 try { 6324 ITelephony telephony = getITelephony(); 6325 if (telephony == null) { 6326 if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) { 6327 throw new IllegalStateException("Telephony is null"); 6328 } else { 6329 return; 6330 } 6331 } 6332 6333 telephony.requestCellInfoUpdate( 6334 getSubId(), 6335 new ICellInfoCallback.Stub() { 6336 @Override 6337 public void onCellInfo(List<CellInfo> cellInfo) { 6338 final long identity = Binder.clearCallingIdentity(); 6339 try { 6340 executor.execute(() -> callback.onCellInfo(cellInfo)); 6341 } finally { 6342 Binder.restoreCallingIdentity(identity); 6343 } 6344 } 6345 6346 @Override 6347 public void onError(int errorCode, String exceptionName, String message) { 6348 final long identity = Binder.clearCallingIdentity(); 6349 try { 6350 executor.execute(() -> callback.onError( 6351 errorCode, 6352 createThrowableByClassName(exceptionName, message))); 6353 } finally { 6354 Binder.restoreCallingIdentity(identity); 6355 } 6356 } 6357 }, getOpPackageName(), getAttributionTag()); 6358 } catch (RemoteException ex) { 6359 runOnBackgroundThread(() -> executor.execute( 6360 () -> callback.onError(CellInfoCallback.ERROR_MODEM_ERROR, ex))); 6361 } 6362 } 6363 6364 /** 6365 * Requests all available cell information from the current subscription for observed 6366 * camped/registered, serving, and neighboring cells. 6367 * 6368 * <p>Any available results from this request will be provided by calls to 6369 * {@link android.telephony.PhoneStateListener#onCellInfoChanged onCellInfoChanged()} 6370 * for each active subscription. 6371 * 6372 * <p>This method returns valid data for devices with 6373 * {@link android.content.pm.PackageManager#FEATURE_TELEPHONY FEATURE_TELEPHONY}. On devices 6374 * that do not implement this feature, the behavior is not reliable. 6375 * 6376 * @param workSource the requestor to whom the power consumption for this should be attributed. 6377 * @param executor the executor on which callback will be invoked. 6378 * @param callback a callback to receive CellInfo. 6379 * @hide 6380 */ 6381 @SystemApi 6382 @RequiresPermission(allOf = {android.Manifest.permission.ACCESS_FINE_LOCATION, 6383 android.Manifest.permission.MODIFY_PHONE_STATE}) requestCellInfoUpdate(@onNull WorkSource workSource, @NonNull @CallbackExecutor Executor executor, @NonNull CellInfoCallback callback)6384 public void requestCellInfoUpdate(@NonNull WorkSource workSource, 6385 @NonNull @CallbackExecutor Executor executor, @NonNull CellInfoCallback callback) { 6386 try { 6387 ITelephony telephony = getITelephony(); 6388 if (telephony == null) { 6389 if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) { 6390 throw new IllegalStateException("Telephony is null"); 6391 } else { 6392 return; 6393 } 6394 } 6395 6396 telephony.requestCellInfoUpdateWithWorkSource( 6397 getSubId(), 6398 new ICellInfoCallback.Stub() { 6399 @Override 6400 public void onCellInfo(List<CellInfo> cellInfo) { 6401 final long identity = Binder.clearCallingIdentity(); 6402 try { 6403 executor.execute(() -> callback.onCellInfo(cellInfo)); 6404 } finally { 6405 Binder.restoreCallingIdentity(identity); 6406 } 6407 6408 } 6409 6410 @Override 6411 public void onError(int errorCode, String exceptionName, String message) { 6412 final long identity = Binder.clearCallingIdentity(); 6413 try { 6414 executor.execute(() -> callback.onError( 6415 errorCode, 6416 createThrowableByClassName(exceptionName, message))); 6417 } finally { 6418 Binder.restoreCallingIdentity(identity); 6419 } 6420 } 6421 }, getOpPackageName(), getAttributionTag(), workSource); 6422 } catch (RemoteException ex) { 6423 runOnBackgroundThread(() -> executor.execute( 6424 () -> callback.onError(CellInfoCallback.ERROR_MODEM_ERROR, ex))); 6425 } 6426 } 6427 createThrowableByClassName(String className, String message)6428 private static Throwable createThrowableByClassName(String className, String message) { 6429 if (className == null) { 6430 return null; 6431 } 6432 try { 6433 Class<?> c = Class.forName(className); 6434 return (Throwable) c.getConstructor(String.class).newInstance(message); 6435 } catch (ReflectiveOperationException | ClassCastException e) { 6436 } 6437 return new RuntimeException(className + ": " + message); 6438 } 6439 6440 /** 6441 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 6442 * PhoneStateListener.onCellInfoChanged} will be invoked. 6443 *<p> 6444 * The default, 0, means invoke onCellInfoChanged when any of the reported 6445 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 6446 * A onCellInfoChanged. 6447 *<p> 6448 * @param rateInMillis the rate 6449 * 6450 * @hide 6451 */ setCellInfoListRate(int rateInMillis)6452 public void setCellInfoListRate(int rateInMillis) { 6453 try { 6454 ITelephony telephony = getITelephony(); 6455 if (telephony != null) 6456 telephony.setCellInfoListRate(rateInMillis); 6457 } catch (RemoteException ex) { 6458 } catch (NullPointerException ex) { 6459 } 6460 } 6461 6462 /** 6463 * Returns the MMS user agent. 6464 */ getMmsUserAgent()6465 public String getMmsUserAgent() { 6466 try { 6467 ITelephony telephony = getITelephony(); 6468 if (telephony != null) { 6469 return telephony.getMmsUserAgent(getSubId()); 6470 } 6471 } catch (RemoteException ex) { 6472 } catch (NullPointerException ex) { 6473 } 6474 return null; 6475 } 6476 6477 /** 6478 * Returns the MMS user agent profile URL. 6479 */ getMmsUAProfUrl()6480 public String getMmsUAProfUrl() { 6481 try { 6482 ITelephony telephony = getITelephony(); 6483 if (telephony != null) { 6484 return telephony.getMmsUAProfUrl(getSubId()); 6485 } 6486 } catch (RemoteException ex) { 6487 } catch (NullPointerException ex) { 6488 } 6489 return null; 6490 } 6491 6492 /** 6493 * Opens a logical channel to the ICC card. 6494 * 6495 * Input parameters equivalent to TS 27.007 AT+CCHO command. 6496 * 6497 * <p>Requires Permission: 6498 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 6499 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6500 * 6501 * @param AID Application id. See ETSI 102.221 and 101.220. 6502 * @return an IccOpenLogicalChannelResponse object. 6503 * @deprecated Replaced by {@link #iccOpenLogicalChannel(String, int)} 6504 */ 6505 @Deprecated iccOpenLogicalChannel(String AID)6506 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { 6507 return iccOpenLogicalChannel(getSubId(), AID, -1); 6508 } 6509 6510 /** 6511 * Opens a logical channel to the ICC card using the physical slot index. 6512 * 6513 * Use this method when no subscriptions are available on the SIM and the operation must be 6514 * performed using the physical slot index. 6515 * 6516 * This operation wraps two APDU instructions: 6517 * <ul> 6518 * <li>MANAGE CHANNEL to open a logical channel</li> 6519 * <li>SELECT the given {@code AID} using the given {@code p2}</li> 6520 * </ul> 6521 * 6522 * Per Open Mobile API Specification v3.2 section 6.2.7.h, only p2 values of 0x00, 0x04, 0x08, 6523 * and 0x0C are guaranteed to be supported. 6524 * 6525 * If the SELECT command's status word is not '9000', '62xx', or '63xx', the status word will be 6526 * considered an error and the channel shall not be opened. 6527 * 6528 * Input parameters equivalent to TS 27.007 AT+CCHO command. 6529 * 6530 * <p>Requires Permission: 6531 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 6532 * 6533 * @param slotIndex the physical slot index of the ICC card 6534 * @param aid Application id. See ETSI 102.221 and 101.220. 6535 * @param p2 P2 parameter (described in ISO 7816-4). 6536 * @return an IccOpenLogicalChannelResponse object. 6537 * @hide 6538 */ 6539 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 6540 @SystemApi 6541 @Nullable iccOpenLogicalChannelBySlot(int slotIndex, @Nullable String aid, int p2)6542 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(int slotIndex, 6543 @Nullable String aid, int p2) { 6544 try { 6545 ITelephony telephony = getITelephony(); 6546 if (telephony != null) { 6547 return telephony.iccOpenLogicalChannelBySlot(slotIndex, getOpPackageName(), aid, 6548 p2); 6549 } 6550 } catch (RemoteException ex) { 6551 } catch (NullPointerException ex) { 6552 } 6553 return null; 6554 } 6555 6556 /** 6557 * Opens a logical channel to the ICC card. 6558 * 6559 * This operation wraps two APDU instructions: 6560 * <ul> 6561 * <li>MANAGE CHANNEL to open a logical channel</li> 6562 * <li>SELECT the given {@code AID} using the given {@code p2}</li> 6563 * </ul> 6564 * 6565 * Per Open Mobile API Specification v3.2 section 6.2.7.h, only p2 values of 0x00, 0x04, 0x08, 6566 * and 0x0C are guaranteed to be supported. 6567 * 6568 * If the SELECT command's status word is not '9000', '62xx', or '63xx', the status word will be 6569 * considered an error and the channel shall not be opened. 6570 * 6571 * Input parameters equivalent to TS 27.007 AT+CCHO command. 6572 * 6573 * <p>Requires Permission: 6574 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 6575 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6576 * 6577 * @param AID Application id. See ETSI 102.221 and 101.220. 6578 * @param p2 P2 parameter (described in ISO 7816-4). 6579 * @return an IccOpenLogicalChannelResponse object. 6580 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 6581 * {@link android.se.omapi.SEService#getUiccReader(int)}, 6582 * {@link android.se.omapi.Reader#openSession()}, 6583 * {@link android.se.omapi.Session#openLogicalChannel(byte[], byte)}. 6584 */ 6585 @Deprecated iccOpenLogicalChannel(String AID, int p2)6586 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID, int p2) { 6587 return iccOpenLogicalChannel(getSubId(), AID, p2); 6588 } 6589 6590 /** 6591 * Opens a logical channel to the ICC card. 6592 * 6593 * This operation wraps two APDU instructions: 6594 * <ul> 6595 * <li>MANAGE CHANNEL to open a logical channel</li> 6596 * <li>SELECT the given {@code AID} using the given {@code p2}</li> 6597 * </ul> 6598 * 6599 * Per Open Mobile API Specification v3.2 section 6.2.7.h, only p2 values of 0x00, 0x04, 0x08, 6600 * and 0x0C are guaranteed to be supported. 6601 * 6602 * If the SELECT command's status word is not '9000', '62xx', or '63xx', the status word will be 6603 * considered an error and the channel shall not be opened. 6604 * 6605 * Input parameters equivalent to TS 27.007 AT+CCHO command. 6606 * 6607 * <p>Requires Permission: 6608 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 6609 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6610 * 6611 * @param subId The subscription to use. 6612 * @param AID Application id. See ETSI 102.221 and 101.220. 6613 * @param p2 P2 parameter (described in ISO 7816-4). 6614 * @return an IccOpenLogicalChannelResponse object. 6615 * @hide 6616 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 6617 * {@link android.se.omapi.SEService#getUiccReader(int)}, 6618 * {@link android.se.omapi.Reader#openSession()}, 6619 * {@link android.se.omapi.Session#openLogicalChannel(byte[], byte)}. 6620 */ 6621 @Deprecated iccOpenLogicalChannel(int subId, String AID, int p2)6622 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID, int p2) { 6623 try { 6624 ITelephony telephony = getITelephony(); 6625 if (telephony != null) 6626 return telephony.iccOpenLogicalChannel(subId, getOpPackageName(), AID, p2); 6627 } catch (RemoteException ex) { 6628 } catch (NullPointerException ex) { 6629 } 6630 return null; 6631 } 6632 6633 /** 6634 * Closes a previously opened logical channel to the ICC card using the physical slot index. 6635 * 6636 * Use this method when no subscriptions are available on the SIM and the operation must be 6637 * performed using the physical slot index. 6638 * 6639 * Input parameters equivalent to TS 27.007 AT+CCHC command. 6640 * 6641 * <p>Requires Permission: 6642 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 6643 * 6644 * @param slotIndex the physical slot index of the ICC card 6645 * @param channel is the channel id to be closed as returned by a successful 6646 * iccOpenLogicalChannel. 6647 * @return true if the channel was closed successfully. 6648 * @hide 6649 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 6650 * {@link android.se.omapi.Channel#close()}. 6651 */ 6652 @Deprecated 6653 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 6654 @SystemApi iccCloseLogicalChannelBySlot(int slotIndex, int channel)6655 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { 6656 try { 6657 ITelephony telephony = getITelephony(); 6658 if (telephony != null) { 6659 return telephony.iccCloseLogicalChannelBySlot(slotIndex, channel); 6660 } 6661 } catch (RemoteException ex) { 6662 } catch (NullPointerException ex) { 6663 } 6664 return false; 6665 } 6666 6667 /** 6668 * Closes a previously opened logical channel to the ICC card. 6669 * 6670 * Input parameters equivalent to TS 27.007 AT+CCHC command. 6671 * 6672 * <p>Requires Permission: 6673 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 6674 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6675 * 6676 * @param channel is the channel id to be closed as returned by a successful 6677 * iccOpenLogicalChannel. 6678 * @return true if the channel was closed successfully. 6679 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 6680 * {@link android.se.omapi.Channel#close()}. 6681 */ 6682 @Deprecated iccCloseLogicalChannel(int channel)6683 public boolean iccCloseLogicalChannel(int channel) { 6684 return iccCloseLogicalChannel(getSubId(), channel); 6685 } 6686 6687 /** 6688 * Closes a previously opened logical channel to the ICC card. 6689 * 6690 * Input parameters equivalent to TS 27.007 AT+CCHC command. 6691 * 6692 * <p>Requires Permission: 6693 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 6694 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6695 * 6696 * @param subId The subscription to use. 6697 * @param channel is the channel id to be closed as returned by a successful 6698 * iccOpenLogicalChannel. 6699 * @return true if the channel was closed successfully. 6700 * @hide 6701 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 6702 * {@link android.se.omapi.Channel#close()}. 6703 */ 6704 @Deprecated iccCloseLogicalChannel(int subId, int channel)6705 public boolean iccCloseLogicalChannel(int subId, int channel) { 6706 try { 6707 ITelephony telephony = getITelephony(); 6708 if (telephony != null) 6709 return telephony.iccCloseLogicalChannel(subId, channel); 6710 } catch (RemoteException ex) { 6711 } catch (NullPointerException ex) { 6712 } 6713 return false; 6714 } 6715 6716 /** 6717 * Transmit an APDU to the ICC card over a logical channel using the physical slot index. 6718 * 6719 * Use this method when no subscriptions are available on the SIM and the operation must be 6720 * performed using the physical slot index. 6721 * 6722 * Input parameters equivalent to TS 27.007 AT+CGLA command. 6723 * 6724 * <p>Requires Permission: 6725 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 6726 * 6727 * @param slotIndex the physical slot index of the ICC card 6728 * @param channel is the channel id to be closed as returned by a successful 6729 * iccOpenLogicalChannel. 6730 * @param cla Class of the APDU command. 6731 * @param instruction Instruction of the APDU command. 6732 * @param p1 P1 value of the APDU command. 6733 * @param p2 P2 value of the APDU command. 6734 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 6735 * is sent to the SIM. 6736 * @param data Data to be sent with the APDU. 6737 * @return The APDU response from the ICC card with the status appended at the end, or null if 6738 * there is an issue connecting to the Telephony service. 6739 * @hide 6740 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 6741 * {@link android.se.omapi.Channel#transmit(byte[])}. 6742 */ 6743 @Deprecated 6744 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 6745 @SystemApi 6746 @Nullable iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, int instruction, int p1, int p2, int p3, @Nullable String data)6747 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, 6748 int instruction, int p1, int p2, int p3, @Nullable String data) { 6749 try { 6750 ITelephony telephony = getITelephony(); 6751 if (telephony != null) { 6752 return telephony.iccTransmitApduLogicalChannelBySlot(slotIndex, channel, cla, 6753 instruction, p1, p2, p3, data); 6754 } 6755 } catch (RemoteException ex) { 6756 } catch (NullPointerException ex) { 6757 } 6758 return null; 6759 } 6760 6761 /** 6762 * Transmit an APDU to the ICC card over a logical channel. 6763 * 6764 * Input parameters equivalent to TS 27.007 AT+CGLA command. 6765 * 6766 * <p>Requires Permission: 6767 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 6768 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6769 * 6770 * @param channel is the channel id to be closed as returned by a successful 6771 * iccOpenLogicalChannel. 6772 * @param cla Class of the APDU command. 6773 * @param instruction Instruction of the APDU command. 6774 * @param p1 P1 value of the APDU command. 6775 * @param p2 P2 value of the APDU command. 6776 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 6777 * is sent to the SIM. 6778 * @param data Data to be sent with the APDU. 6779 * @return The APDU response from the ICC card with the status appended at 6780 * the end. 6781 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 6782 * {@link android.se.omapi.Channel#transmit(byte[])}. 6783 */ 6784 @Deprecated iccTransmitApduLogicalChannel(int channel, int cla, int instruction, int p1, int p2, int p3, String data)6785 public String iccTransmitApduLogicalChannel(int channel, int cla, 6786 int instruction, int p1, int p2, int p3, String data) { 6787 return iccTransmitApduLogicalChannel(getSubId(), channel, cla, 6788 instruction, p1, p2, p3, data); 6789 } 6790 6791 /** 6792 * Transmit an APDU to the ICC card over a logical channel. 6793 * 6794 * Input parameters equivalent to TS 27.007 AT+CGLA command. 6795 * 6796 * <p>Requires Permission: 6797 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 6798 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6799 * 6800 * @param subId The subscription to use. 6801 * @param channel is the channel id to be closed as returned by a successful 6802 * iccOpenLogicalChannel. 6803 * @param cla Class of the APDU command. 6804 * @param instruction Instruction of the APDU command. 6805 * @param p1 P1 value of the APDU command. 6806 * @param p2 P2 value of the APDU command. 6807 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 6808 * is sent to the SIM. 6809 * @param data Data to be sent with the APDU. 6810 * @return The APDU response from the ICC card with the status appended at 6811 * the end. 6812 * @hide 6813 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 6814 * {@link android.se.omapi.Channel#transmit(byte[])}. 6815 */ 6816 @Deprecated iccTransmitApduLogicalChannel(int subId, int channel, int cla, int instruction, int p1, int p2, int p3, String data)6817 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, 6818 int instruction, int p1, int p2, int p3, String data) { 6819 try { 6820 ITelephony telephony = getITelephony(); 6821 if (telephony != null) 6822 return telephony.iccTransmitApduLogicalChannel(subId, channel, cla, 6823 instruction, p1, p2, p3, data); 6824 } catch (RemoteException ex) { 6825 } catch (NullPointerException ex) { 6826 } 6827 return ""; 6828 } 6829 6830 /** 6831 * Transmit an APDU to the ICC card over the basic channel using the physical slot index. 6832 * 6833 * Use this method when no subscriptions are available on the SIM and the operation must be 6834 * performed using the physical slot index. 6835 * 6836 * Input parameters equivalent to TS 27.007 AT+CSIM command. 6837 * 6838 * <p>Requires Permission: 6839 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 6840 * 6841 * @param slotIndex the physical slot index of the ICC card to target 6842 * @param cla Class of the APDU command. 6843 * @param instruction Instruction of the APDU command. 6844 * @param p1 P1 value of the APDU command. 6845 * @param p2 P2 value of the APDU command. 6846 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 6847 * is sent to the SIM. 6848 * @param data Data to be sent with the APDU. 6849 * @return The APDU response from the ICC card with the status appended at 6850 * the end. 6851 * @hide 6852 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 6853 * {@link android.se.omapi.SEService#getUiccReader(int)}, 6854 * {@link android.se.omapi.Reader#openSession()}, 6855 * {@link android.se.omapi.Session#openBasicChannel(byte[], byte)}, 6856 * {@link android.se.omapi.Channel#transmit(byte[])}. 6857 */ 6858 @Deprecated 6859 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 6860 @SystemApi 6861 @NonNull iccTransmitApduBasicChannelBySlot(int slotIndex, int cla, int instruction, int p1, int p2, int p3, @Nullable String data)6862 public String iccTransmitApduBasicChannelBySlot(int slotIndex, int cla, int instruction, int p1, 6863 int p2, int p3, @Nullable String data) { 6864 try { 6865 ITelephony telephony = getITelephony(); 6866 if (telephony != null) { 6867 return telephony.iccTransmitApduBasicChannelBySlot(slotIndex, getOpPackageName(), 6868 cla, instruction, p1, p2, p3, data); 6869 } 6870 } catch (RemoteException ex) { 6871 } catch (NullPointerException ex) { 6872 } 6873 return null; 6874 } 6875 6876 /** 6877 * Transmit an APDU to the ICC card over the basic channel. 6878 * 6879 * Input parameters equivalent to TS 27.007 AT+CSIM command. 6880 * 6881 * <p>Requires Permission: 6882 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 6883 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6884 * 6885 * @param cla Class of the APDU command. 6886 * @param instruction Instruction of the APDU command. 6887 * @param p1 P1 value of the APDU command. 6888 * @param p2 P2 value of the APDU command. 6889 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 6890 * is sent to the SIM. 6891 * @param data Data to be sent with the APDU. 6892 * @return The APDU response from the ICC card with the status appended at 6893 * the end. 6894 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 6895 * {@link android.se.omapi.SEService#getUiccReader(int)}, 6896 * {@link android.se.omapi.Reader#openSession()}, 6897 * {@link android.se.omapi.Session#openBasicChannel(byte[], byte)}, 6898 * {@link android.se.omapi.Channel#transmit(byte[])}. 6899 */ 6900 @Deprecated iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2, int p3, String data)6901 public String iccTransmitApduBasicChannel(int cla, 6902 int instruction, int p1, int p2, int p3, String data) { 6903 return iccTransmitApduBasicChannel(getSubId(), cla, 6904 instruction, p1, p2, p3, data); 6905 } 6906 6907 /** 6908 * Transmit an APDU to the ICC card over the basic channel. 6909 * 6910 * Input parameters equivalent to TS 27.007 AT+CSIM command. 6911 * 6912 * <p>Requires Permission: 6913 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 6914 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6915 * 6916 * @param subId The subscription to use. 6917 * @param cla Class of the APDU command. 6918 * @param instruction Instruction of the APDU command. 6919 * @param p1 P1 value of the APDU command. 6920 * @param p2 P2 value of the APDU command. 6921 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 6922 * is sent to the SIM. 6923 * @param data Data to be sent with the APDU. 6924 * @return The APDU response from the ICC card with the status appended at 6925 * the end. 6926 * @hide 6927 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 6928 * {@link android.se.omapi.SEService#getUiccReader(int)}, 6929 * {@link android.se.omapi.Reader#openSession()}, 6930 * {@link android.se.omapi.Session#openBasicChannel(byte[], byte)}, 6931 * {@link android.se.omapi.Channel#transmit(byte[])}. 6932 */ 6933 @Deprecated iccTransmitApduBasicChannel(int subId, int cla, int instruction, int p1, int p2, int p3, String data)6934 public String iccTransmitApduBasicChannel(int subId, int cla, 6935 int instruction, int p1, int p2, int p3, String data) { 6936 try { 6937 ITelephony telephony = getITelephony(); 6938 if (telephony != null) 6939 return telephony.iccTransmitApduBasicChannel(subId, getOpPackageName(), cla, 6940 instruction, p1, p2, p3, data); 6941 } catch (RemoteException ex) { 6942 } catch (NullPointerException ex) { 6943 } 6944 return ""; 6945 } 6946 6947 /** 6948 * Returns the response APDU for a command APDU sent through SIM_IO. 6949 * 6950 * <p>Requires Permission: 6951 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 6952 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6953 * 6954 * @param fileID 6955 * @param command 6956 * @param p1 P1 value of the APDU command. 6957 * @param p2 P2 value of the APDU command. 6958 * @param p3 P3 value of the APDU command. 6959 * @param filePath 6960 * @return The APDU response. 6961 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 6962 * {@link android.se.omapi.SEService#getUiccReader(int)}, 6963 * {@link android.se.omapi.Reader#openSession()}, 6964 * {@link android.se.omapi.Session#openBasicChannel(byte[], byte)}, 6965 * {@link android.se.omapi.Channel#transmit(byte[])}. 6966 */ 6967 @Deprecated iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, String filePath)6968 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 6969 String filePath) { 6970 return iccExchangeSimIO(getSubId(), fileID, command, p1, p2, p3, filePath); 6971 } 6972 6973 /** 6974 * Returns the response APDU for a command APDU sent through SIM_IO. 6975 * 6976 * <p>Requires Permission: 6977 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 6978 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 6979 * 6980 * @param subId The subscription to use. 6981 * @param fileID 6982 * @param command 6983 * @param p1 P1 value of the APDU command. 6984 * @param p2 P2 value of the APDU command. 6985 * @param p3 P3 value of the APDU command. 6986 * @param filePath 6987 * @return The APDU response. 6988 * @hide 6989 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 6990 * {@link android.se.omapi.SEService#getUiccReader(int)}, 6991 * {@link android.se.omapi.Reader#openSession()}, 6992 * {@link android.se.omapi.Session#openBasicChannel(byte[], byte)}, 6993 * {@link android.se.omapi.Channel#transmit(byte[])}. 6994 */ 6995 @Deprecated iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3, String filePath)6996 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, 6997 int p3, String filePath) { 6998 try { 6999 ITelephony telephony = getITelephony(); 7000 if (telephony != null) 7001 return telephony.iccExchangeSimIO(subId, fileID, command, p1, p2, p3, filePath); 7002 } catch (RemoteException ex) { 7003 } catch (NullPointerException ex) { 7004 } 7005 return null; 7006 } 7007 7008 /** 7009 * Send ENVELOPE to the SIM and return the response. 7010 * 7011 * <p>Requires Permission: 7012 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7013 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7014 * 7015 * @param content String containing SAT/USAT response in hexadecimal 7016 * format starting with command tag. See TS 102 223 for 7017 * details. 7018 * @return The APDU response from the ICC card in hexadecimal format 7019 * with the last 4 bytes being the status word. If the command fails, 7020 * returns an empty string. 7021 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 7022 * {@link android.se.omapi.SEService#getUiccReader(int)}, 7023 * {@link android.se.omapi.Reader#openSession()}, 7024 * {@link android.se.omapi.Session#openBasicChannel(byte[], byte)}, 7025 * {@link android.se.omapi.Channel#transmit(byte[])}. 7026 */ 7027 @Deprecated sendEnvelopeWithStatus(String content)7028 public String sendEnvelopeWithStatus(String content) { 7029 return sendEnvelopeWithStatus(getSubId(), content); 7030 } 7031 7032 /** 7033 * Send ENVELOPE to the SIM and return the response. 7034 * 7035 * <p>Requires Permission: 7036 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7037 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7038 * 7039 * @param subId The subscription to use. 7040 * @param content String containing SAT/USAT response in hexadecimal 7041 * format starting with command tag. See TS 102 223 for 7042 * details. 7043 * @return The APDU response from the ICC card in hexadecimal format 7044 * with the last 4 bytes being the status word. If the command fails, 7045 * returns an empty string. 7046 * @hide 7047 * @deprecated Use {@link android.se.omapi.SEService} APIs instead. See 7048 * {@link android.se.omapi.SEService#getUiccReader(int)}, 7049 * {@link android.se.omapi.Reader#openSession()}, 7050 * {@link android.se.omapi.Session#openBasicChannel(byte[], byte)}, 7051 * {@link android.se.omapi.Channel#transmit(byte[])}. 7052 */ 7053 @Deprecated sendEnvelopeWithStatus(int subId, String content)7054 public String sendEnvelopeWithStatus(int subId, String content) { 7055 try { 7056 ITelephony telephony = getITelephony(); 7057 if (telephony != null) 7058 return telephony.sendEnvelopeWithStatus(subId, content); 7059 } catch (RemoteException ex) { 7060 } catch (NullPointerException ex) { 7061 } 7062 return ""; 7063 } 7064 7065 /** 7066 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 7067 * Used for device configuration by some CDMA operators. 7068 * 7069 * <p>Requires Permission: 7070 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7071 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7072 * 7073 * @param itemID the ID of the item to read. 7074 * @return the NV item as a String, or null on any failure. 7075 * 7076 * @hide 7077 */ 7078 @UnsupportedAppUsage nvReadItem(int itemID)7079 public String nvReadItem(int itemID) { 7080 try { 7081 ITelephony telephony = getITelephony(); 7082 if (telephony != null) 7083 return telephony.nvReadItem(itemID); 7084 } catch (RemoteException ex) { 7085 Rlog.e(TAG, "nvReadItem RemoteException", ex); 7086 } catch (NullPointerException ex) { 7087 Rlog.e(TAG, "nvReadItem NPE", ex); 7088 } 7089 return ""; 7090 } 7091 7092 /** 7093 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 7094 * Used for device configuration by some CDMA operators. 7095 * 7096 * <p>Requires Permission: 7097 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7098 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7099 * 7100 * @param itemID the ID of the item to read. 7101 * @param itemValue the value to write, as a String. 7102 * @return true on success; false on any failure. 7103 * 7104 * @hide 7105 */ nvWriteItem(int itemID, String itemValue)7106 public boolean nvWriteItem(int itemID, String itemValue) { 7107 try { 7108 ITelephony telephony = getITelephony(); 7109 if (telephony != null) 7110 return telephony.nvWriteItem(itemID, itemValue); 7111 } catch (RemoteException ex) { 7112 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 7113 } catch (NullPointerException ex) { 7114 Rlog.e(TAG, "nvWriteItem NPE", ex); 7115 } 7116 return false; 7117 } 7118 7119 /** 7120 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 7121 * Used for device configuration by some CDMA operators. 7122 * 7123 * <p>Requires Permission: 7124 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7125 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7126 * 7127 * @param preferredRoamingList byte array containing the new PRL. 7128 * @return true on success; false on any failure. 7129 * 7130 * @hide 7131 */ nvWriteCdmaPrl(byte[] preferredRoamingList)7132 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 7133 try { 7134 ITelephony telephony = getITelephony(); 7135 if (telephony != null) 7136 return telephony.nvWriteCdmaPrl(preferredRoamingList); 7137 } catch (RemoteException ex) { 7138 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 7139 } catch (NullPointerException ex) { 7140 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 7141 } 7142 return false; 7143 } 7144 7145 /** 7146 * Perform the specified type of NV config reset. The radio will be taken offline 7147 * and the device must be rebooted after the operation. Used for device 7148 * configuration by some CDMA operators. 7149 * 7150 * <p>Requires Permission: 7151 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7152 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7153 * 7154 * TODO: remove this one. use {@link #rebootRadio()} for reset type 1 and 7155 * {@link #resetRadioConfig()} for reset type 3 7156 * 7157 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 7158 * @return true on success; false on any failure. 7159 * 7160 * @hide 7161 */ 7162 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) nvResetConfig(int resetType)7163 public boolean nvResetConfig(int resetType) { 7164 try { 7165 ITelephony telephony = getITelephony(); 7166 if (telephony != null) { 7167 if (resetType == 1 /*1: reload NV reset */) { 7168 return telephony.rebootModem(getSlotIndex()); 7169 } else if (resetType == 3 /*3: factory NV reset */) { 7170 return telephony.resetModemConfig(getSlotIndex()); 7171 } else { 7172 Rlog.e(TAG, "nvResetConfig unsupported reset type"); 7173 } 7174 } 7175 } catch (RemoteException ex) { 7176 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 7177 } catch (NullPointerException ex) { 7178 Rlog.e(TAG, "nvResetConfig NPE", ex); 7179 } 7180 return false; 7181 } 7182 7183 /** 7184 * Rollback modem configurations to factory default except some config which are in whitelist. 7185 * Used for device configuration by some carriers. 7186 * 7187 * <p>Requires Permission: 7188 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7189 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7190 * 7191 * @return {@code true} on success; {@code false} on any failure. 7192 * 7193 * @hide 7194 */ 7195 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 7196 @SystemApi resetRadioConfig()7197 public boolean resetRadioConfig() { 7198 try { 7199 ITelephony telephony = getITelephony(); 7200 if (telephony != null) { 7201 return telephony.resetModemConfig(getSlotIndex()); 7202 } 7203 } catch (RemoteException ex) { 7204 Rlog.e(TAG, "resetRadioConfig RemoteException", ex); 7205 } catch (NullPointerException ex) { 7206 Rlog.e(TAG, "resetRadioConfig NPE", ex); 7207 } 7208 return false; 7209 } 7210 7211 /** 7212 * Generate a radio modem reset. Used for device configuration by some carriers. 7213 * 7214 * <p>Requires Permission: 7215 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7216 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7217 * 7218 * @return {@code true} on success; {@code false} on any failure. 7219 * 7220 * @hide 7221 */ 7222 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 7223 @SystemApi rebootRadio()7224 public boolean rebootRadio() { 7225 try { 7226 ITelephony telephony = getITelephony(); 7227 if (telephony != null) { 7228 return telephony.rebootModem(getSlotIndex()); 7229 } 7230 } catch (RemoteException ex) { 7231 Rlog.e(TAG, "rebootRadio RemoteException", ex); 7232 } catch (NullPointerException ex) { 7233 Rlog.e(TAG, "rebootRadio NPE", ex); 7234 } 7235 return false; 7236 } 7237 7238 /** 7239 * Return an appropriate subscription ID for any situation. 7240 * 7241 * If this object has been created with {@link #createForSubscriptionId}, then the provided 7242 * subscription ID is returned. Otherwise, the default subscription ID will be returned. 7243 * 7244 */ getSubscriptionId()7245 public int getSubscriptionId() { 7246 return getSubId(); 7247 } 7248 7249 /** 7250 * Return an appropriate subscription ID for any situation. 7251 * 7252 * If this object has been created with {@link #createForSubscriptionId}, then the provided 7253 * subscription ID is returned. Otherwise, the default subscription ID will be returned. 7254 * 7255 */ getSubId()7256 private int getSubId() { 7257 if (SubscriptionManager.isUsableSubIdValue(mSubId)) { 7258 return mSubId; 7259 } 7260 return SubscriptionManager.getDefaultSubscriptionId(); 7261 } 7262 7263 /** 7264 * Return an appropriate subscription ID for any situation. 7265 * 7266 * If this object has been created with {@link #createForSubscriptionId}, then the provided 7267 * subId is returned. Otherwise, the preferred subId which is based on caller's context is 7268 * returned. 7269 * {@see SubscriptionManager#getDefaultDataSubscriptionId()} 7270 * {@see SubscriptionManager#getDefaultVoiceSubscriptionId()} 7271 * {@see SubscriptionManager#getDefaultSmsSubscriptionId()} 7272 */ 7273 @UnsupportedAppUsage getSubId(int preferredSubId)7274 private int getSubId(int preferredSubId) { 7275 if (SubscriptionManager.isUsableSubIdValue(mSubId)) { 7276 return mSubId; 7277 } 7278 return preferredSubId; 7279 } 7280 7281 /** 7282 * Return an appropriate phone ID for any situation. 7283 * 7284 * If this object has been created with {@link #createForSubscriptionId}, then the phoneId 7285 * associated with the provided subId is returned. Otherwise, the default phoneId associated 7286 * with the default subId will be returned. 7287 */ getPhoneId()7288 private int getPhoneId() { 7289 return SubscriptionManager.getPhoneId(getSubId()); 7290 } 7291 7292 /** 7293 * Return an appropriate phone ID for any situation. 7294 * 7295 * If this object has been created with {@link #createForSubscriptionId}, then the phoneId 7296 * associated with the provided subId is returned. Otherwise, return the phoneId associated 7297 * with the preferred subId based on caller's context. 7298 * {@see SubscriptionManager#getDefaultDataSubscriptionId()} 7299 * {@see SubscriptionManager#getDefaultVoiceSubscriptionId()} 7300 * {@see SubscriptionManager#getDefaultSmsSubscriptionId()} 7301 */ 7302 @UnsupportedAppUsage getPhoneId(int preferredSubId)7303 private int getPhoneId(int preferredSubId) { 7304 return SubscriptionManager.getPhoneId(getSubId(preferredSubId)); 7305 } 7306 7307 /** 7308 * Return an appropriate slot index for any situation. 7309 * 7310 * if this object has been created with {@link #createForSubscriptionId}, then the slot index 7311 * associated with the provided subId is returned. Otherwise, return the slot index associated 7312 * with the default subId. 7313 * If SIM is not inserted, return default SIM slot index. 7314 * 7315 * {@hide} 7316 */ 7317 @VisibleForTesting 7318 @UnsupportedAppUsage getSlotIndex()7319 public int getSlotIndex() { 7320 int slotIndex = SubscriptionManager.getSlotIndex(getSubId()); 7321 if (slotIndex == SubscriptionManager.SIM_NOT_INSERTED) { 7322 slotIndex = SubscriptionManager.DEFAULT_SIM_SLOT_INDEX; 7323 } 7324 return slotIndex; 7325 } 7326 7327 /** 7328 * Request that the next incoming call from a number matching {@code range} be intercepted. 7329 * 7330 * This API is intended for OEMs to provide a service for apps to verify the device's phone 7331 * number. When called, the Telephony stack will store the provided {@link PhoneNumberRange} and 7332 * intercept the next incoming call from a number that lies within the range, within a timeout 7333 * specified by {@code timeoutMillis}. 7334 * 7335 * If such a phone call is received, the caller will be notified via 7336 * {@link NumberVerificationCallback#onCallReceived(String)} on the provided {@link Executor}. 7337 * If verification fails for any reason, the caller will be notified via 7338 * {@link NumberVerificationCallback#onVerificationFailed(int)} 7339 * on the provided {@link Executor}. 7340 * 7341 * In addition to the {@link Manifest.permission#MODIFY_PHONE_STATE} permission, callers of this 7342 * API must also be listed in the device configuration as an authorized app in 7343 * {@code packages/services/Telephony/res/values/config.xml} under the 7344 * {@code config_number_verification_package_name} key. 7345 * 7346 * @hide 7347 * @param range The range of phone numbers the caller expects a phone call from. 7348 * @param timeoutMillis The amount of time to wait for such a call, or the value of 7349 * {@link #getMaxNumberVerificationTimeoutMillis()}, whichever is lesser. 7350 * @param executor The {@link Executor} that callbacks should be executed on. 7351 * @param callback The callback to use for delivering results. 7352 */ 7353 @SystemApi 7354 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) requestNumberVerification(@onNull PhoneNumberRange range, long timeoutMillis, @NonNull @CallbackExecutor Executor executor, @NonNull NumberVerificationCallback callback)7355 public void requestNumberVerification(@NonNull PhoneNumberRange range, long timeoutMillis, 7356 @NonNull @CallbackExecutor Executor executor, 7357 @NonNull NumberVerificationCallback callback) { 7358 if (executor == null) { 7359 throw new NullPointerException("Executor must be non-null"); 7360 } 7361 if (callback == null) { 7362 throw new NullPointerException("Callback must be non-null"); 7363 } 7364 7365 INumberVerificationCallback internalCallback = new INumberVerificationCallback.Stub() { 7366 @Override 7367 public void onCallReceived(String phoneNumber) { 7368 final long identity = Binder.clearCallingIdentity(); 7369 try { 7370 executor.execute(() -> 7371 callback.onCallReceived(phoneNumber)); 7372 } finally { 7373 Binder.restoreCallingIdentity(identity); 7374 } 7375 } 7376 7377 @Override 7378 public void onVerificationFailed(int reason) { 7379 final long identity = Binder.clearCallingIdentity(); 7380 try { 7381 executor.execute(() -> 7382 callback.onVerificationFailed(reason)); 7383 } finally { 7384 Binder.restoreCallingIdentity(identity); 7385 } 7386 } 7387 }; 7388 7389 try { 7390 ITelephony telephony = getITelephony(); 7391 if (telephony == null) { 7392 if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) { 7393 throw new IllegalStateException("Telephony is null"); 7394 } else { 7395 return; 7396 } 7397 } 7398 7399 telephony.requestNumberVerification(range, timeoutMillis, internalCallback, 7400 getOpPackageName()); 7401 } catch (RemoteException ex) { 7402 Rlog.e(TAG, "requestNumberVerification RemoteException", ex); 7403 runOnBackgroundThread(() -> executor.execute( 7404 () -> callback.onVerificationFailed( 7405 NumberVerificationCallback.REASON_UNSPECIFIED))); 7406 } 7407 } 7408 7409 /** 7410 * Inserts or updates a list property. Expands the list if its length is not enough. 7411 */ updateTelephonyProperty(List<T> prop, int phoneId, T value)7412 private static <T> List<T> updateTelephonyProperty(List<T> prop, int phoneId, T value) { 7413 List<T> ret = new ArrayList<>(prop); 7414 while (ret.size() <= phoneId) ret.add(null); 7415 ret.set(phoneId, value); 7416 return ret; 7417 } 7418 /** 7419 * Convenience function for retrieving a value from the secure settings 7420 * value list as an integer. Note that internally setting values are 7421 * always stored as strings; this function converts the string to an 7422 * integer for you. 7423 * <p> 7424 * This version does not take a default value. If the setting has not 7425 * been set, or the string value is not a number, 7426 * it throws {@link SettingNotFoundException}. 7427 * 7428 * @param cr The ContentResolver to access. 7429 * @param name The name of the setting to retrieve. 7430 * @param index The index of the list 7431 * 7432 * @throws SettingNotFoundException Thrown if a setting by the given 7433 * name can't be found or the setting value is not an integer. 7434 * 7435 * @return The value at the given index of settings. 7436 * @hide 7437 */ 7438 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getIntAtIndex(android.content.ContentResolver cr, String name, int index)7439 public static int getIntAtIndex(android.content.ContentResolver cr, 7440 String name, int index) 7441 throws android.provider.Settings.SettingNotFoundException { 7442 String v = android.provider.Settings.Global.getString(cr, name); 7443 if (v != null) { 7444 String valArray[] = v.split(","); 7445 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 7446 try { 7447 return Integer.parseInt(valArray[index]); 7448 } catch (NumberFormatException e) { 7449 //Log.e(TAG, "Exception while parsing Integer: ", e); 7450 } 7451 } 7452 } 7453 throw new android.provider.Settings.SettingNotFoundException(name); 7454 } 7455 7456 /** 7457 * Convenience function for updating settings value as coma separated 7458 * integer values. This will either create a new entry in the table if the 7459 * given name does not exist, or modify the value of the existing row 7460 * with that name. Note that internally setting values are always 7461 * stored as strings, so this function converts the given value to a 7462 * string before storing it. 7463 * 7464 * @param cr The ContentResolver to access. 7465 * @param name The name of the setting to modify. 7466 * @param index The index of the list 7467 * @param value The new value for the setting to be added to the list. 7468 * @return true if the value was set, false on database errors 7469 * @hide 7470 */ 7471 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) putIntAtIndex(android.content.ContentResolver cr, String name, int index, int value)7472 public static boolean putIntAtIndex(android.content.ContentResolver cr, 7473 String name, int index, int value) { 7474 String data = ""; 7475 String valArray[] = null; 7476 String v = android.provider.Settings.Global.getString(cr, name); 7477 7478 if (index == Integer.MAX_VALUE) { 7479 throw new IllegalArgumentException("putIntAtIndex index == MAX_VALUE index=" + index); 7480 } 7481 if (index < 0) { 7482 throw new IllegalArgumentException("putIntAtIndex index < 0 index=" + index); 7483 } 7484 if (v != null) { 7485 valArray = v.split(","); 7486 } 7487 7488 // Copy the elements from valArray till index 7489 for (int i = 0; i < index; i++) { 7490 String str = ""; 7491 if ((valArray != null) && (i < valArray.length)) { 7492 str = valArray[i]; 7493 } 7494 data = data + str + ","; 7495 } 7496 7497 data = data + value; 7498 7499 // Copy the remaining elements from valArray if any. 7500 if (valArray != null) { 7501 for (int i = index+1; i < valArray.length; i++) { 7502 data = data + "," + valArray[i]; 7503 } 7504 } 7505 return android.provider.Settings.Global.putString(cr, name, data); 7506 } 7507 7508 /** 7509 * Gets a per-phone telephony property from a property name. 7510 * 7511 * @hide 7512 */ 7513 @UnsupportedAppUsage getTelephonyProperty(int phoneId, String property, String defaultVal)7514 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 7515 String propVal = null; 7516 String prop = SystemProperties.get(property); 7517 if ((prop != null) && (prop.length() > 0)) { 7518 String values[] = prop.split(","); 7519 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 7520 propVal = values[phoneId]; 7521 } 7522 } 7523 return propVal == null ? defaultVal : propVal; 7524 } 7525 7526 /** 7527 * Gets a typed per-phone telephony property from a schematized list property. 7528 */ getTelephonyProperty(int phoneId, List<T> prop, T defaultValue)7529 private static <T> T getTelephonyProperty(int phoneId, List<T> prop, T defaultValue) { 7530 T ret = null; 7531 if (phoneId >= 0 && phoneId < prop.size()) ret = prop.get(phoneId); 7532 return ret != null ? ret : defaultValue; 7533 } 7534 7535 /** 7536 * Gets a global telephony property. 7537 * 7538 * See also getTelephonyProperty(phoneId, property, defaultVal). Most telephony properties are 7539 * per-phone. 7540 * 7541 * @hide 7542 */ 7543 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getTelephonyProperty(String property, String defaultVal)7544 public static String getTelephonyProperty(String property, String defaultVal) { 7545 String propVal = SystemProperties.get(property); 7546 return TextUtils.isEmpty(propVal) ? defaultVal : propVal; 7547 } 7548 7549 /** @hide */ 7550 @UnsupportedAppUsage getSimCount()7551 public int getSimCount() { 7552 // FIXME Need to get it from Telephony Dev Controller when that gets implemented! 7553 // and then this method shouldn't be used at all! 7554 return getPhoneCount(); 7555 } 7556 7557 /** 7558 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 7559 * 7560 * See 3GPP TS 31.103 (Section 4.2.7) for the definition and more information on this table. 7561 * 7562 * @return IMS Service Table or null if not present or not loaded 7563 * @hide 7564 */ 7565 @Nullable 7566 @SystemApi 7567 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getIsimIst()7568 public String getIsimIst() { 7569 try { 7570 IPhoneSubInfo info = getSubscriberInfoService(); 7571 if (info == null) 7572 return null; 7573 //get the Isim Ist based on subId 7574 return info.getIsimIst(getSubId()); 7575 } catch (RemoteException ex) { 7576 return null; 7577 } catch (NullPointerException ex) { 7578 // This could happen before phone restarts due to crashing 7579 return null; 7580 } 7581 } 7582 7583 /** 7584 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 7585 * @return an array of PCSCF strings with one PCSCF per string, or null if 7586 * not present or not loaded 7587 * @hide 7588 */ 7589 @UnsupportedAppUsage getIsimPcscf()7590 public String[] getIsimPcscf() { 7591 try { 7592 IPhoneSubInfo info = getSubscriberInfoService(); 7593 if (info == null) 7594 return null; 7595 //get the Isim Pcscf based on subId 7596 return info.getIsimPcscf(getSubId()); 7597 } catch (RemoteException ex) { 7598 return null; 7599 } catch (NullPointerException ex) { 7600 // This could happen before phone restarts due to crashing 7601 return null; 7602 } 7603 } 7604 7605 /** UICC application type is unknown or not specified */ 7606 public static final int APPTYPE_UNKNOWN = PhoneConstants.APPTYPE_UNKNOWN; 7607 /** UICC application type is SIM */ 7608 public static final int APPTYPE_SIM = PhoneConstants.APPTYPE_SIM; 7609 /** UICC application type is USIM */ 7610 public static final int APPTYPE_USIM = PhoneConstants.APPTYPE_USIM; 7611 /** UICC application type is RUIM */ 7612 public static final int APPTYPE_RUIM = PhoneConstants.APPTYPE_RUIM; 7613 /** UICC application type is CSIM */ 7614 public static final int APPTYPE_CSIM = PhoneConstants.APPTYPE_CSIM; 7615 /** UICC application type is ISIM */ 7616 public static final int APPTYPE_ISIM = PhoneConstants.APPTYPE_ISIM; 7617 7618 // authContext (parameter P2) when doing UICC challenge, 7619 // per 3GPP TS 31.102 (Section 7.1.2) 7620 /** Authentication type for UICC challenge is EAP SIM. See RFC 4186 for details. */ 7621 public static final int AUTHTYPE_EAP_SIM = PhoneConstants.AUTH_CONTEXT_EAP_SIM; 7622 /** Authentication type for UICC challenge is EAP AKA. See RFC 4187 for details. */ 7623 public static final int AUTHTYPE_EAP_AKA = PhoneConstants.AUTH_CONTEXT_EAP_AKA; 7624 7625 /** 7626 * Returns the response of authentication for the default subscription. 7627 * Returns null if the authentication hasn't been successful 7628 * 7629 * <p>Requires one of the following permissions: 7630 * <ul> 7631 * <li>READ_PRIVILEGED_PHONE_STATE 7632 * <li>the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 7633 * <li>the calling app has been granted the 7634 * {@link Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} permission. 7635 * </ul> 7636 * 7637 * @param appType the icc application type, like {@link #APPTYPE_USIM} 7638 * @param authType the authentication type, {@link #AUTHTYPE_EAP_AKA} or 7639 * {@link #AUTHTYPE_EAP_SIM} 7640 * @param data authentication challenge data, base64 encoded. 7641 * See 3GPP TS 31.102 7.1.2 for more details. 7642 * @return the response of authentication. This value will be null in the following cases: 7643 * Authentication error, incorrect MAC 7644 * Authentication error, security context not supported 7645 * Key freshness failure 7646 * Authentication error, no memory space available 7647 * Authentication error, no memory space available in EFMUK 7648 */ 7649 // TODO(b/73660190): This should probably require MODIFY_PHONE_STATE, not 7650 // READ_PRIVILEGED_PHONE_STATE. It certainly shouldn't reference the permission in Javadoc since 7651 // it's not public API. getIccAuthentication(int appType, int authType, String data)7652 public String getIccAuthentication(int appType, int authType, String data) { 7653 return getIccAuthentication(getSubId(), appType, authType, data); 7654 } 7655 7656 /** 7657 * Returns the response of USIM Authentication for specified subId. 7658 * Returns null if the authentication hasn't been successful 7659 * 7660 * <p>See {@link #getIccAuthentication(int, int, String)} for details on the required 7661 * permissions. 7662 * 7663 * @param subId subscription ID used for authentication 7664 * @param appType the icc application type, like {@link #APPTYPE_USIM} 7665 * @param authType the authentication type, {@link #AUTHTYPE_EAP_AKA} or 7666 * {@link #AUTHTYPE_EAP_SIM} 7667 * @param data authentication challenge data, base64 encoded. 7668 * See 3GPP TS 31.102 7.1.2 for more details. 7669 * @return the response of authentication. This value will be null in the following cases only 7670 * (see 3GPP TS 31.102 7.3.1): 7671 * Authentication error, incorrect MAC 7672 * Authentication error, security context not supported 7673 * Key freshness failure 7674 * Authentication error, no memory space available 7675 * Authentication error, no memory space available in EFMUK 7676 * @hide 7677 */ 7678 @UnsupportedAppUsage getIccAuthentication(int subId, int appType, int authType, String data)7679 public String getIccAuthentication(int subId, int appType, int authType, String data) { 7680 try { 7681 IPhoneSubInfo info = getSubscriberInfoService(); 7682 if (info == null) 7683 return null; 7684 return info.getIccSimChallengeResponse(subId, appType, authType, data, 7685 getOpPackageName(), getAttributionTag()); 7686 } catch (RemoteException ex) { 7687 return null; 7688 } catch (NullPointerException ex) { 7689 // This could happen before phone starts 7690 return null; 7691 } 7692 } 7693 7694 /** 7695 * Returns an array of Forbidden PLMNs from the USIM App 7696 * Returns null if the query fails. 7697 * 7698 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 7699 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 7700 * 7701 * @return an array of forbidden PLMNs or null if not available 7702 */ 7703 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 7704 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getForbiddenPlmns()7705 public String[] getForbiddenPlmns() { 7706 return getForbiddenPlmns(getSubId(), APPTYPE_USIM); 7707 } 7708 7709 /** 7710 * Returns an array of Forbidden PLMNs from the specified SIM App 7711 * Returns null if the query fails. 7712 * 7713 * @param subId subscription ID used for authentication 7714 * @param appType the icc application type, like {@link #APPTYPE_USIM} 7715 * @return fplmns an array of forbidden PLMNs 7716 * @hide 7717 */ 7718 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getForbiddenPlmns(int subId, int appType)7719 public String[] getForbiddenPlmns(int subId, int appType) { 7720 try { 7721 ITelephony telephony = getITelephony(); 7722 if (telephony == null) 7723 return null; 7724 return telephony.getForbiddenPlmns(subId, appType, mContext.getOpPackageName(), 7725 getAttributionTag()); 7726 } catch (RemoteException ex) { 7727 return null; 7728 } catch (NullPointerException ex) { 7729 // This could happen before phone starts 7730 return null; 7731 } 7732 } 7733 7734 /** 7735 * Replace the contents of the forbidden PLMN SIM file with the provided values. 7736 * Passing an empty list will clear the contents of the EFfplmn file. 7737 * If the provided list is shorter than the size of EFfplmn, then the list will be padded 7738 * up to the file size with 'FFFFFF'. (required by 3GPP TS 31.102 spec 4.2.16) 7739 * If the list is longer than the size of EFfplmn, then the file will be written from the 7740 * beginning of the list up to the file size. 7741 * 7742 * <p>Requires Permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE 7743 * MODIFY_PHONE_STATE} 7744 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 7745 * 7746 * @param fplmns a list of PLMNs to be forbidden. 7747 * 7748 * @return number of PLMNs that were successfully written to the SIM FPLMN list. 7749 * This may be less than the number of PLMNs passed in where the SIM file does not have enough 7750 * room for all of the values passed in. Return -1 in the event of an unexpected failure 7751 */ 7752 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 7753 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setForbiddenPlmns(@onNull List<String> fplmns)7754 public int setForbiddenPlmns(@NonNull List<String> fplmns) { 7755 try { 7756 ITelephony telephony = getITelephony(); 7757 if (telephony == null) return -1; 7758 return telephony.setForbiddenPlmns( 7759 getSubId(), APPTYPE_USIM, fplmns, getOpPackageName(), getAttributionTag()); 7760 } catch (RemoteException ex) { 7761 Rlog.e(TAG, "setForbiddenPlmns RemoteException: " + ex.getMessage()); 7762 } catch (NullPointerException ex) { 7763 // This could happen before phone starts 7764 Rlog.e(TAG, "setForbiddenPlmns NullPointerException: " + ex.getMessage()); 7765 } 7766 return -1; 7767 } 7768 7769 /** 7770 * Get P-CSCF address from PCO after data connection is established or modified. 7771 * @param apnType the apnType, "ims" for IMS APN, "emergency" for EMERGENCY APN 7772 * @return array of P-CSCF address 7773 * @hide 7774 */ getPcscfAddress(String apnType)7775 public String[] getPcscfAddress(String apnType) { 7776 try { 7777 ITelephony telephony = getITelephony(); 7778 if (telephony == null) 7779 return new String[0]; 7780 return telephony.getPcscfAddress(apnType, getOpPackageName(), getAttributionTag()); 7781 } catch (RemoteException e) { 7782 return new String[0]; 7783 } 7784 } 7785 7786 7787 /** 7788 * Resets the {@link android.telephony.ims.ImsService} associated with the specified sim slot. 7789 * Used by diagnostic apps to force the IMS stack to be disabled and re-enabled in an effort to 7790 * recover from scenarios where the {@link android.telephony.ims.ImsService} gets in to a bad 7791 * state. 7792 * 7793 * @param slotIndex the sim slot to reset the IMS stack on. 7794 * @hide */ 7795 @SystemApi 7796 @WorkerThread 7797 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) resetIms(int slotIndex)7798 public void resetIms(int slotIndex) { 7799 try { 7800 ITelephony telephony = getITelephony(); 7801 if (telephony != null) { 7802 telephony.resetIms(slotIndex); 7803 } 7804 } catch (RemoteException e) { 7805 Rlog.e(TAG, "toggleImsOnOff, RemoteException: " 7806 + e.getMessage()); 7807 } 7808 } 7809 7810 /** 7811 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability 7812 * status updates, if not already enabled. 7813 * @hide 7814 */ enableIms(int slotId)7815 public void enableIms(int slotId) { 7816 try { 7817 ITelephony telephony = getITelephony(); 7818 if (telephony != null) { 7819 telephony.enableIms(slotId); 7820 } 7821 } catch (RemoteException e) { 7822 Rlog.e(TAG, "enableIms, RemoteException: " 7823 + e.getMessage()); 7824 } 7825 } 7826 7827 /** 7828 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature 7829 * status updates to disabled. 7830 * @hide 7831 */ disableIms(int slotId)7832 public void disableIms(int slotId) { 7833 try { 7834 ITelephony telephony = getITelephony(); 7835 if (telephony != null) { 7836 telephony.disableIms(slotId); 7837 } 7838 } catch (RemoteException e) { 7839 Rlog.e(TAG, "disableIms, RemoteException: " 7840 + e.getMessage()); 7841 } 7842 } 7843 7844 /** 7845 * @return the {@IImsRegistration} interface that corresponds with the slot index and feature. 7846 * @param slotIndex The SIM slot corresponding to the ImsService ImsRegistration is active for. 7847 * @param feature An integer indicating the feature that we wish to get the ImsRegistration for. 7848 * Corresponds to features defined in ImsFeature. 7849 * @hide 7850 */ 7851 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getImsRegistration(int slotIndex, int feature)7852 public @Nullable IImsRegistration getImsRegistration(int slotIndex, int feature) { 7853 try { 7854 ITelephony telephony = getITelephony(); 7855 if (telephony != null) { 7856 return telephony.getImsRegistration(slotIndex, feature); 7857 } 7858 } catch (RemoteException e) { 7859 Rlog.e(TAG, "getImsRegistration, RemoteException: " + e.getMessage()); 7860 } 7861 return null; 7862 } 7863 7864 /** 7865 * @return the {@IImsConfig} interface that corresponds with the slot index and feature. 7866 * @param slotIndex The SIM slot corresponding to the ImsService ImsConfig is active for. 7867 * @param feature An integer indicating the feature that we wish to get the ImsConfig for. 7868 * Corresponds to features defined in ImsFeature. 7869 * @hide 7870 */ 7871 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getImsConfig(int slotIndex, int feature)7872 public @Nullable IImsConfig getImsConfig(int slotIndex, int feature) { 7873 try { 7874 ITelephony telephony = getITelephony(); 7875 if (telephony != null) { 7876 return telephony.getImsConfig(slotIndex, feature); 7877 } 7878 } catch (RemoteException e) { 7879 Rlog.e(TAG, "getImsRegistration, RemoteException: " + e.getMessage()); 7880 } 7881 return null; 7882 } 7883 7884 /** 7885 * Set IMS registration state on all active subscriptions. 7886 * <p/> 7887 * Use {@link android.telephony.ims.stub.ImsRegistrationImplBase#onRegistered} and 7888 * {@link android.telephony.ims.stub.ImsRegistrationImplBase#onDeregistered} to set Ims 7889 * registration state instead. 7890 * 7891 * @param registered whether ims is registered 7892 * 7893 * @hide 7894 */ 7895 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setImsRegistrationState(final boolean registered)7896 public void setImsRegistrationState(final boolean registered) { 7897 try { 7898 final ITelephony telephony = getITelephony(); 7899 if (telephony != null) 7900 telephony.setImsRegistrationState(registered); 7901 } catch (final RemoteException e) { 7902 } 7903 } 7904 7905 /** @hide */ 7906 @IntDef(prefix = { "NETWORK_MODE_" }, value = { 7907 NETWORK_MODE_WCDMA_PREF, 7908 NETWORK_MODE_GSM_ONLY, 7909 NETWORK_MODE_WCDMA_ONLY, 7910 NETWORK_MODE_GSM_UMTS, 7911 NETWORK_MODE_CDMA_EVDO, 7912 NETWORK_MODE_CDMA_NO_EVDO, 7913 NETWORK_MODE_EVDO_NO_CDMA, 7914 NETWORK_MODE_GLOBAL, 7915 NETWORK_MODE_LTE_CDMA_EVDO, 7916 NETWORK_MODE_LTE_GSM_WCDMA, 7917 NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA, 7918 NETWORK_MODE_LTE_ONLY, 7919 NETWORK_MODE_LTE_WCDMA, 7920 NETWORK_MODE_TDSCDMA_ONLY, 7921 NETWORK_MODE_TDSCDMA_WCDMA, 7922 NETWORK_MODE_LTE_TDSCDMA, 7923 NETWORK_MODE_TDSCDMA_GSM, 7924 NETWORK_MODE_LTE_TDSCDMA_GSM, 7925 NETWORK_MODE_TDSCDMA_GSM_WCDMA, 7926 NETWORK_MODE_LTE_TDSCDMA_WCDMA, 7927 NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA, 7928 NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA, 7929 NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA, 7930 NETWORK_MODE_NR_ONLY, 7931 NETWORK_MODE_NR_LTE, 7932 NETWORK_MODE_NR_LTE_CDMA_EVDO, 7933 NETWORK_MODE_NR_LTE_GSM_WCDMA, 7934 NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA, 7935 NETWORK_MODE_NR_LTE_WCDMA, 7936 NETWORK_MODE_NR_LTE_TDSCDMA, 7937 NETWORK_MODE_NR_LTE_TDSCDMA_GSM, 7938 NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA, 7939 NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA, 7940 NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA 7941 }) 7942 @Retention(RetentionPolicy.SOURCE) 7943 public @interface PrefNetworkMode{} 7944 7945 /** 7946 * Preferred network mode is GSM/WCDMA (WCDMA preferred). 7947 * @hide 7948 */ 7949 public static final int NETWORK_MODE_WCDMA_PREF = RILConstants.NETWORK_MODE_WCDMA_PREF; 7950 7951 /** 7952 * Preferred network mode is GSM only. 7953 * @hide 7954 */ 7955 public static final int NETWORK_MODE_GSM_ONLY = RILConstants.NETWORK_MODE_GSM_ONLY; 7956 7957 /** 7958 * Preferred network mode is WCDMA only. 7959 * @hide 7960 */ 7961 public static final int NETWORK_MODE_WCDMA_ONLY = RILConstants.NETWORK_MODE_WCDMA_ONLY; 7962 7963 /** 7964 * Preferred network mode is GSM/WCDMA (auto mode, according to PRL). 7965 * @hide 7966 */ 7967 public static final int NETWORK_MODE_GSM_UMTS = RILConstants.NETWORK_MODE_GSM_UMTS; 7968 7969 /** 7970 * Preferred network mode is CDMA and EvDo (auto mode, according to PRL). 7971 * @hide 7972 */ 7973 public static final int NETWORK_MODE_CDMA_EVDO = RILConstants.NETWORK_MODE_CDMA; 7974 7975 /** 7976 * Preferred network mode is CDMA only. 7977 * @hide 7978 */ 7979 public static final int NETWORK_MODE_CDMA_NO_EVDO = RILConstants.NETWORK_MODE_CDMA_NO_EVDO; 7980 7981 /** 7982 * Preferred network mode is EvDo only. 7983 * @hide 7984 */ 7985 public static final int NETWORK_MODE_EVDO_NO_CDMA = RILConstants.NETWORK_MODE_EVDO_NO_CDMA; 7986 7987 /** 7988 * Preferred network mode is GSM/WCDMA, CDMA, and EvDo (auto mode, according to PRL). 7989 * @hide 7990 */ 7991 public static final int NETWORK_MODE_GLOBAL = RILConstants.NETWORK_MODE_GLOBAL; 7992 7993 /** 7994 * Preferred network mode is LTE, CDMA and EvDo. 7995 * @hide 7996 */ 7997 public static final int NETWORK_MODE_LTE_CDMA_EVDO = RILConstants.NETWORK_MODE_LTE_CDMA_EVDO; 7998 7999 /** 8000 * Preferred network mode is LTE, GSM/WCDMA. 8001 * @hide 8002 */ 8003 public static final int NETWORK_MODE_LTE_GSM_WCDMA = RILConstants.NETWORK_MODE_LTE_GSM_WCDMA; 8004 8005 /** 8006 * Preferred network mode is LTE, CDMA, EvDo, GSM/WCDMA. 8007 * @hide 8008 */ 8009 public static final int NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA = 8010 RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA; 8011 8012 /** 8013 * Preferred network mode is LTE Only. 8014 * @hide 8015 */ 8016 public static final int NETWORK_MODE_LTE_ONLY = RILConstants.NETWORK_MODE_LTE_ONLY; 8017 8018 /** 8019 * Preferred network mode is LTE/WCDMA. 8020 * @hide 8021 */ 8022 public static final int NETWORK_MODE_LTE_WCDMA = RILConstants.NETWORK_MODE_LTE_WCDMA; 8023 8024 /** 8025 * Preferred network mode is TD-SCDMA only. 8026 * @hide 8027 */ 8028 public static final int NETWORK_MODE_TDSCDMA_ONLY = RILConstants.NETWORK_MODE_TDSCDMA_ONLY; 8029 8030 /** 8031 * Preferred network mode is TD-SCDMA and WCDMA. 8032 * @hide 8033 */ 8034 public static final int NETWORK_MODE_TDSCDMA_WCDMA = RILConstants.NETWORK_MODE_TDSCDMA_WCDMA; 8035 8036 /** 8037 * Preferred network mode is TD-SCDMA and LTE. 8038 * @hide 8039 */ 8040 public static final int NETWORK_MODE_LTE_TDSCDMA = RILConstants.NETWORK_MODE_LTE_TDSCDMA; 8041 8042 /** 8043 * Preferred network mode is TD-SCDMA and GSM. 8044 * @hide 8045 */ 8046 public static final int NETWORK_MODE_TDSCDMA_GSM = RILConstants.NETWORK_MODE_TDSCDMA_GSM; 8047 8048 /** 8049 * Preferred network mode is TD-SCDMA,GSM and LTE. 8050 * @hide 8051 */ 8052 public static final int NETWORK_MODE_LTE_TDSCDMA_GSM = 8053 RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM; 8054 8055 /** 8056 * Preferred network mode is TD-SCDMA, GSM/WCDMA. 8057 * @hide 8058 */ 8059 public static final int NETWORK_MODE_TDSCDMA_GSM_WCDMA = 8060 RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA; 8061 8062 /** 8063 * Preferred network mode is TD-SCDMA, WCDMA and LTE. 8064 * @hide 8065 */ 8066 public static final int NETWORK_MODE_LTE_TDSCDMA_WCDMA = 8067 RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA; 8068 8069 /** 8070 * Preferred network mode is TD-SCDMA, GSM/WCDMA and LTE. 8071 * @hide 8072 */ 8073 public static final int NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA = 8074 RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA; 8075 8076 /** 8077 * Preferred network mode is TD-SCDMA,EvDo,CDMA,GSM/WCDMA. 8078 * @hide 8079 */ 8080 public static final int NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 8081 RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA; 8082 /** 8083 * Preferred network mode is TD-SCDMA/LTE/GSM/WCDMA, CDMA, and EvDo. 8084 * @hide 8085 */ 8086 public static final int NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 8087 RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA; 8088 8089 /** 8090 * Preferred network mode is NR 5G only. 8091 * @hide 8092 */ 8093 public static final int NETWORK_MODE_NR_ONLY = RILConstants.NETWORK_MODE_NR_ONLY; 8094 8095 /** 8096 * Preferred network mode is NR 5G, LTE. 8097 * @hide 8098 */ 8099 public static final int NETWORK_MODE_NR_LTE = RILConstants.NETWORK_MODE_NR_LTE; 8100 8101 /** 8102 * Preferred network mode is NR 5G, LTE, CDMA and EvDo. 8103 * @hide 8104 */ 8105 public static final int NETWORK_MODE_NR_LTE_CDMA_EVDO = 8106 RILConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO; 8107 8108 /** 8109 * Preferred network mode is NR 5G, LTE, GSM and WCDMA. 8110 * @hide 8111 */ 8112 public static final int NETWORK_MODE_NR_LTE_GSM_WCDMA = 8113 RILConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA; 8114 8115 /** 8116 * Preferred network mode is NR 5G, LTE, CDMA, EvDo, GSM and WCDMA. 8117 * @hide 8118 */ 8119 public static final int NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA = 8120 RILConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA; 8121 8122 /** 8123 * Preferred network mode is NR 5G, LTE and WCDMA. 8124 * @hide 8125 */ 8126 public static final int NETWORK_MODE_NR_LTE_WCDMA = RILConstants.NETWORK_MODE_NR_LTE_WCDMA; 8127 8128 /** 8129 * Preferred network mode is NR 5G, LTE and TDSCDMA. 8130 * @hide 8131 */ 8132 public static final int NETWORK_MODE_NR_LTE_TDSCDMA = RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA; 8133 8134 /** 8135 * Preferred network mode is NR 5G, LTE, TD-SCDMA and GSM. 8136 * @hide 8137 */ 8138 public static final int NETWORK_MODE_NR_LTE_TDSCDMA_GSM = 8139 RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM; 8140 8141 /** 8142 * Preferred network mode is NR 5G, LTE, TD-SCDMA, WCDMA. 8143 * @hide 8144 */ 8145 public static final int NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA = 8146 RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA; 8147 8148 /** 8149 * Preferred network mode is NR 5G, LTE, TD-SCDMA, GSM and WCDMA. 8150 * @hide 8151 */ 8152 public static final int NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA = 8153 RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA; 8154 8155 /** 8156 * Preferred network mode is NR 5G, LTE, TD-SCDMA, CDMA, EVDO, GSM and WCDMA. 8157 * @hide 8158 */ 8159 public static final int NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 8160 RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA; 8161 8162 /** 8163 * The default preferred network mode constant. 8164 * 8165 * <p> This constant is used in case of nothing is set in 8166 * TelephonyProperties#default_network(). 8167 * 8168 * @hide 8169 */ 8170 public static final int DEFAULT_PREFERRED_NETWORK_MODE = 8171 RILConstants.PREFERRED_NETWORK_MODE; 8172 8173 /** 8174 * Get the preferred network type. 8175 * Used for device configuration by some CDMA operators. 8176 * 8177 * <p>Requires Permission: 8178 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 8179 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 8180 * 8181 * @return the preferred network type. 8182 * @hide 8183 * @deprecated Use {@link #getAllowedNetworkTypesBitmask} instead. 8184 */ 8185 @Deprecated 8186 @RequiresPermission((android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)) 8187 @UnsupportedAppUsage getPreferredNetworkType(int subId)8188 public @PrefNetworkMode int getPreferredNetworkType(int subId) { 8189 return RadioAccessFamily.getNetworkTypeFromRaf((int) getAllowedNetworkTypesBitmask()); 8190 } 8191 8192 /** 8193 * Get the preferred network type bitmask. 8194 * 8195 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8196 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8197 * 8198 * <p>Requires Permission: 8199 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 8200 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 8201 * 8202 * @return The bitmask of preferred network types. 8203 * 8204 * @hide 8205 * @deprecated Use {@link #getAllowedNetworkTypesBitmask} instead. 8206 */ 8207 @Deprecated 8208 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 8209 @SystemApi getPreferredNetworkTypeBitmask()8210 public @NetworkTypeBitMask long getPreferredNetworkTypeBitmask() { 8211 return getAllowedNetworkTypesBitmask(); 8212 } 8213 8214 /** 8215 * Get the allowed network type bitmask. 8216 * Note that the device can only register on the network of {@link NetworkTypeBitmask} 8217 * (except for emergency call cases). 8218 * 8219 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8220 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8221 * 8222 * <p>Requires Permission: 8223 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 8224 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 8225 * 8226 * @return The bitmask of allowed network types. 8227 * 8228 * @hide 8229 */ 8230 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 8231 @SystemApi getAllowedNetworkTypesBitmask()8232 public @NetworkTypeBitMask long getAllowedNetworkTypesBitmask() { 8233 try { 8234 ITelephony telephony = getITelephony(); 8235 if (telephony != null) { 8236 return (long) telephony.getAllowedNetworkTypesBitmask(getSubId()); 8237 } 8238 } catch (RemoteException ex) { 8239 Rlog.e(TAG, "getAllowedNetworkTypesBitmask RemoteException", ex); 8240 } 8241 return 0; 8242 } 8243 8244 /** 8245 * Get the allowed network types by carriers. 8246 * 8247 * <p>Requires Permission: 8248 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 8249 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 8250 * 8251 * @return the allowed network type bitmask 8252 * @hide 8253 * @deprecated Use {@link #getAllowedNetworkTypesForReason} instead. 8254 */ 8255 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 8256 @SystemApi 8257 @Deprecated getAllowedNetworkTypes()8258 public @NetworkTypeBitMask long getAllowedNetworkTypes() { 8259 try { 8260 ITelephony telephony = getITelephony(); 8261 if (telephony != null) { 8262 return telephony.getAllowedNetworkTypesForReason(getSubId(), 8263 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER); 8264 } 8265 } catch (RemoteException ex) { 8266 Rlog.e(TAG, "getAllowedNetworkTypes RemoteException", ex); 8267 } 8268 return -1; 8269 } 8270 8271 /** 8272 * Sets the network selection mode to automatic. 8273 * 8274 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8275 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8276 * 8277 * <p>Requires Permission: 8278 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 8279 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 8280 */ 8281 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 8282 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setNetworkSelectionModeAutomatic()8283 public void setNetworkSelectionModeAutomatic() { 8284 try { 8285 ITelephony telephony = getITelephony(); 8286 if (telephony != null) { 8287 telephony.setNetworkSelectionModeAutomatic(getSubId()); 8288 } 8289 } catch (RemoteException ex) { 8290 Rlog.e(TAG, "setNetworkSelectionModeAutomatic RemoteException", ex); 8291 } catch (NullPointerException ex) { 8292 Rlog.e(TAG, "setNetworkSelectionModeAutomatic NPE", ex); 8293 } 8294 } 8295 8296 /** 8297 * Perform a radio scan and return the list of available networks. 8298 * 8299 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8300 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8301 * 8302 * <p> Note that this scan can take a long time (sometimes minutes) to happen. 8303 * 8304 * <p>Requires Permissions: 8305 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier 8306 * privileges (see {@link #hasCarrierPrivileges}) 8307 * and {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 8308 * 8309 * @return {@link CellNetworkScanResult} with the status 8310 * {@link CellNetworkScanResult#STATUS_SUCCESS} and a list of 8311 * {@link com.android.internal.telephony.OperatorInfo} if it's available. Otherwise, the failure 8312 * caused will be included in the result. 8313 * 8314 * @hide 8315 */ 8316 @RequiresPermission(allOf = { 8317 android.Manifest.permission.MODIFY_PHONE_STATE, 8318 Manifest.permission.ACCESS_COARSE_LOCATION 8319 }) getAvailableNetworks()8320 public CellNetworkScanResult getAvailableNetworks() { 8321 try { 8322 ITelephony telephony = getITelephony(); 8323 if (telephony != null) { 8324 return telephony.getCellNetworkScanResults(getSubId(), getOpPackageName(), 8325 getAttributionTag()); 8326 } 8327 } catch (RemoteException ex) { 8328 Rlog.e(TAG, "getAvailableNetworks RemoteException", ex); 8329 } catch (NullPointerException ex) { 8330 Rlog.e(TAG, "getAvailableNetworks NPE", ex); 8331 } 8332 return new CellNetworkScanResult( 8333 CellNetworkScanResult.STATUS_UNKNOWN_ERROR, null /* OperatorInfo */); 8334 } 8335 8336 /** 8337 * Request a network scan. 8338 * 8339 * This method is asynchronous, so the network scan results will be returned by callback. 8340 * The returned NetworkScan will contain a callback method which can be used to stop the scan. 8341 * 8342 * <p>Requires Permission: 8343 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 8344 * app has carrier privileges (see {@link #hasCarrierPrivileges}) 8345 * and {@link android.Manifest.permission#ACCESS_FINE_LOCATION}. 8346 * 8347 * If the system-wide location switch is off, apps may still call this API, with the 8348 * following constraints: 8349 * <ol> 8350 * <li>The app must hold the {@code android.permission.NETWORK_SCAN} permission.</li> 8351 * <li>The app must not supply any specific bands or channels to scan.</li> 8352 * <li>The app must only specify MCC/MNC pairs that are 8353 * associated to a SIM in the device.</li> 8354 * <li>Returned results will have no meaningful info other than signal strength 8355 * and MCC/MNC info.</li> 8356 * </ol> 8357 * 8358 * @param request Contains all the RAT with bands/channels that need to be scanned. 8359 * @param executor The executor through which the callback should be invoked. Since the scan 8360 * request may trigger multiple callbacks and they must be invoked in the same order as 8361 * they are received by the platform, the user should provide an executor which executes 8362 * tasks one at a time in serial order. For example AsyncTask.SERIAL_EXECUTOR. 8363 * @param callback Returns network scan results or errors. 8364 * @return A NetworkScan obj which contains a callback which can be used to stop the scan. 8365 */ 8366 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 8367 @RequiresPermission(allOf = { 8368 android.Manifest.permission.MODIFY_PHONE_STATE, 8369 Manifest.permission.ACCESS_FINE_LOCATION 8370 }) requestNetworkScan( NetworkScanRequest request, Executor executor, TelephonyScanManager.NetworkScanCallback callback)8371 public NetworkScan requestNetworkScan( 8372 NetworkScanRequest request, Executor executor, 8373 TelephonyScanManager.NetworkScanCallback callback) { 8374 synchronized (this) { 8375 if (mTelephonyScanManager == null) { 8376 mTelephonyScanManager = new TelephonyScanManager(); 8377 } 8378 } 8379 return mTelephonyScanManager.requestNetworkScan(getSubId(), request, executor, callback, 8380 getOpPackageName(), getAttributionTag()); 8381 } 8382 8383 /** 8384 * @deprecated 8385 * Use {@link 8386 * #requestNetworkScan(NetworkScanRequest, Executor, TelephonyScanManager.NetworkScanCallback)} 8387 * @removed 8388 */ 8389 @Deprecated 8390 @RequiresPermission(allOf = { 8391 android.Manifest.permission.MODIFY_PHONE_STATE, 8392 Manifest.permission.ACCESS_FINE_LOCATION 8393 }) requestNetworkScan( NetworkScanRequest request, TelephonyScanManager.NetworkScanCallback callback)8394 public NetworkScan requestNetworkScan( 8395 NetworkScanRequest request, TelephonyScanManager.NetworkScanCallback callback) { 8396 return requestNetworkScan(request, AsyncTask.SERIAL_EXECUTOR, callback); 8397 } 8398 8399 /** 8400 * Ask the radio to connect to the input network and change selection mode to manual. 8401 * 8402 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8403 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8404 * 8405 * <p>Requires Permission: 8406 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 8407 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 8408 * 8409 * @param operatorNumeric the PLMN ID of the network to select. 8410 * @param persistSelection whether the selection will persist until reboot. If true, only allows 8411 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume 8412 * normal network selection next time. 8413 * @return {@code true} on success; {@code false} on any failure. 8414 */ 8415 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 8416 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setNetworkSelectionModeManual(String operatorNumeric, boolean persistSelection)8417 public boolean setNetworkSelectionModeManual(String operatorNumeric, boolean persistSelection) { 8418 return setNetworkSelectionModeManual( 8419 new OperatorInfo( 8420 "" /* operatorAlphaLong */, "" /* operatorAlphaShort */, operatorNumeric), 8421 persistSelection); 8422 } 8423 8424 /** 8425 * Ask the radio to connect to the input network and change selection mode to manual. 8426 * 8427 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8428 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8429 * 8430 * <p>Requires Permission: 8431 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 8432 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 8433 * 8434 * @param operatorNumeric the PLMN ID of the network to select. 8435 * @param persistSelection whether the selection will persist until reboot. 8436 * If true, only allows attaching to the selected PLMN until reboot; otherwise, 8437 * attach to the chosen PLMN and resume normal network selection next time. 8438 * @param ran the initial suggested radio access network type. 8439 * If registration fails, the RAN is not available after, the RAN is not within the 8440 * network types specified by the preferred network types, or the value is 8441 * {@link AccessNetworkConstants.AccessNetworkType#UNKNOWN}, modem will select 8442 * the next best RAN for network registration. 8443 * @return {@code true} on success; {@code false} on any failure. 8444 */ 8445 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setNetworkSelectionModeManual(@onNull String operatorNumeric, boolean persistSelection, @AccessNetworkConstants.RadioAccessNetworkType int ran)8446 public boolean setNetworkSelectionModeManual(@NonNull String operatorNumeric, 8447 boolean persistSelection, @AccessNetworkConstants.RadioAccessNetworkType int ran) { 8448 return setNetworkSelectionModeManual(new OperatorInfo("" /* operatorAlphaLong */, 8449 "" /* operatorAlphaShort */, operatorNumeric, ran), persistSelection); 8450 } 8451 8452 /** 8453 * Ask the radio to connect to the input network and change selection mode to manual. 8454 * 8455 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8456 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8457 * 8458 * <p>Requires Permission: 8459 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 8460 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 8461 * 8462 * @param operatorInfo included the PLMN id, long name, short name of the operator to attach to. 8463 * @param persistSelection whether the selection will persist until reboot. If true, only allows 8464 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume 8465 * normal network selection next time. 8466 * @return {@code true} on success; {@code true} on any failure. 8467 * 8468 * @hide 8469 */ 8470 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setNetworkSelectionModeManual( OperatorInfo operatorInfo, boolean persistSelection)8471 public boolean setNetworkSelectionModeManual( 8472 OperatorInfo operatorInfo, boolean persistSelection) { 8473 try { 8474 ITelephony telephony = getITelephony(); 8475 if (telephony != null) { 8476 return telephony.setNetworkSelectionModeManual( 8477 getSubId(), operatorInfo, persistSelection); 8478 } 8479 } catch (RemoteException ex) { 8480 Rlog.e(TAG, "setNetworkSelectionModeManual RemoteException", ex); 8481 } 8482 return false; 8483 } 8484 8485 /** 8486 * Get the network selection mode. 8487 * 8488 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8489 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8490 * <p>Requires Permission: {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE 8491 * READ_PRECISE_PHONE_STATE} 8492 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 8493 * 8494 * @return the network selection mode. 8495 */ 8496 @SuppressAutoDoc // No support for carrier privileges (b/72967236). 8497 @RequiresPermission(anyOf = { 8498 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 8499 android.Manifest.permission.READ_PRECISE_PHONE_STATE 8500 }) getNetworkSelectionMode()8501 public @NetworkSelectionMode int getNetworkSelectionMode() { 8502 int mode = NETWORK_SELECTION_MODE_UNKNOWN; 8503 try { 8504 ITelephony telephony = getITelephony(); 8505 if (telephony != null) { 8506 mode = telephony.getNetworkSelectionMode(getSubId()); 8507 } 8508 } catch (RemoteException ex) { 8509 Rlog.e(TAG, "getNetworkSelectionMode RemoteException", ex); 8510 } 8511 return mode; 8512 } 8513 8514 /** 8515 * Get the PLMN chosen for Manual Network Selection if active. 8516 * Return null string if in automatic selection. 8517 * 8518 * <p>Requires Permission: {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE 8519 * READ_PRECISE_PHONE_STATE} or that the calling app has carrier privileges 8520 * (see {@link #hasCarrierPrivileges}) 8521 * 8522 * @return manually selected network info on success or null string on failure 8523 */ 8524 @SuppressAutoDoc // No support carrier privileges (b/72967236). 8525 @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) getManualNetworkSelectionPlmn()8526 public @NonNull String getManualNetworkSelectionPlmn() { 8527 try { 8528 ITelephony telephony = getITelephony(); 8529 if (telephony != null && isManualNetworkSelectionAllowed()) { 8530 return telephony.getManualNetworkSelectionPlmn(getSubId()); 8531 } 8532 } catch (RemoteException ex) { 8533 Rlog.e(TAG, "getManualNetworkSelectionPlmn RemoteException", ex); 8534 } 8535 return null; 8536 } 8537 8538 /** 8539 * Query Telephony to see if there has recently been an emergency SMS sent to the network by the 8540 * user and we are still within the time interval after the emergency SMS was sent that we are 8541 * considered in Emergency SMS mode. 8542 * 8543 * <p>This mode is used by other applications to allow them to perform special functionality, 8544 * such as allow the GNSS service to provide user location to the carrier network for emergency 8545 * when an emergency SMS is sent. This interval is set by 8546 * {@link CarrierConfigManager#KEY_EMERGENCY_SMS_MODE_TIMER_MS_INT}. If 8547 * the carrier does not support this mode, this function will always return false. 8548 * 8549 * @return {@code true} if this device is in emergency SMS mode, {@code false} otherwise. 8550 * 8551 * @hide 8552 */ 8553 @SystemApi 8554 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) isInEmergencySmsMode()8555 public boolean isInEmergencySmsMode() { 8556 try { 8557 ITelephony telephony = getITelephony(); 8558 if (telephony != null) { 8559 return telephony.isInEmergencySmsMode(); 8560 } 8561 } catch (RemoteException ex) { 8562 Rlog.e(TAG, "isInEmergencySmsMode RemoteException", ex); 8563 } 8564 return false; 8565 } 8566 8567 /** 8568 * Set the preferred network type. 8569 * 8570 * <p>Requires Permission: 8571 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 8572 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 8573 * <p> 8574 * If {@link android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported} 8575 * ({@link TelephonyManager#CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK}) returns true, then 8576 * setAllowedNetworkTypesBitmap is used on the radio interface. Otherwise, 8577 * setPreferredNetworkTypesBitmap is used instead. 8578 * 8579 * @param subId the id of the subscription to set the preferred network type for. 8580 * @param networkType the preferred network type 8581 * @return true on success; false on any failure. 8582 * @hide 8583 * @deprecated Use {@link #setAllowedNetworkTypesForReason} instead. 8584 */ 8585 @Deprecated 8586 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setPreferredNetworkType(int subId, @PrefNetworkMode int networkType)8587 public boolean setPreferredNetworkType(int subId, @PrefNetworkMode int networkType) { 8588 try { 8589 ITelephony telephony = getITelephony(); 8590 if (telephony != null) { 8591 return telephony.setAllowedNetworkTypesForReason(subId, 8592 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, 8593 RadioAccessFamily.getRafFromNetworkType(networkType)); 8594 } 8595 } catch (RemoteException ex) { 8596 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 8597 } 8598 return false; 8599 } 8600 8601 /** 8602 * Set the preferred network type bitmask but if {@link #setAllowedNetworkTypes} has been set, 8603 * only the allowed network type will set to the modem. 8604 * 8605 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8606 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8607 * 8608 * <p>Requires Permission: 8609 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 8610 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 8611 * <p> 8612 * If {@link android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported} 8613 * ({@link TelephonyManager#CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK}) returns true, then 8614 * setAllowedNetworkTypesBitmap is used on the radio interface. Otherwise, 8615 * setPreferredNetworkTypesBitmap is used instead. 8616 * 8617 * @param networkTypeBitmask The bitmask of preferred network types. 8618 * @return true on success; false on any failure. 8619 * @hide 8620 * @deprecated Use {@link #setAllowedNetworkTypesForReason} instead. 8621 */ 8622 @Deprecated 8623 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 8624 @SystemApi setPreferredNetworkTypeBitmask(@etworkTypeBitMask long networkTypeBitmask)8625 public boolean setPreferredNetworkTypeBitmask(@NetworkTypeBitMask long networkTypeBitmask) { 8626 try { 8627 ITelephony telephony = getITelephony(); 8628 if (telephony != null) { 8629 return telephony.setAllowedNetworkTypesForReason(getSubId(), 8630 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, networkTypeBitmask); 8631 } 8632 } catch (RemoteException ex) { 8633 Rlog.e(TAG, "setPreferredNetworkTypeBitmask RemoteException", ex); 8634 } 8635 return false; 8636 } 8637 8638 /** 8639 * Set the allowed network types of the device. This is for carrier or privileged apps to 8640 * enable/disable certain network types on the device. The user preferred network types should 8641 * be set through {@link #setPreferredNetworkTypeBitmask}. 8642 * <p> 8643 * If {@link android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported} 8644 * ({@link TelephonyManager#CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK}) returns true, then 8645 * setAllowedNetworkTypesBitmap is used on the radio interface. Otherwise, 8646 * setPreferredNetworkTypesBitmap is used instead. 8647 * 8648 * @param allowedNetworkTypes The bitmask of allowed network types. 8649 * @return true on success; false on any failure. 8650 * @hide 8651 * @deprecated Use {@link #setAllowedNetworkTypesForReason} instead. 8652 */ 8653 @Deprecated 8654 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 8655 @RequiresFeature( 8656 enforcement = "android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported", 8657 value = TelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK) 8658 @SystemApi setAllowedNetworkTypes(@etworkTypeBitMask long allowedNetworkTypes)8659 public boolean setAllowedNetworkTypes(@NetworkTypeBitMask long allowedNetworkTypes) { 8660 try { 8661 ITelephony telephony = getITelephony(); 8662 if (telephony != null) { 8663 return telephony.setAllowedNetworkTypesForReason(getSubId(), 8664 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER, allowedNetworkTypes); 8665 } 8666 } catch (RemoteException ex) { 8667 Rlog.e(TAG, "setAllowedNetworkTypes RemoteException", ex); 8668 } 8669 return false; 8670 } 8671 8672 /** @hide */ 8673 @IntDef({ 8674 ALLOWED_NETWORK_TYPES_REASON_USER, 8675 ALLOWED_NETWORK_TYPES_REASON_POWER, 8676 ALLOWED_NETWORK_TYPES_REASON_CARRIER, 8677 ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G 8678 }) 8679 @Retention(RetentionPolicy.SOURCE) 8680 public @interface AllowedNetworkTypesReason { 8681 } 8682 8683 /** 8684 * To indicate allowed network type change is requested by user. 8685 * 8686 * @hide 8687 */ 8688 @SystemApi 8689 public static final int ALLOWED_NETWORK_TYPES_REASON_USER = 0; 8690 8691 /** 8692 * To indicate allowed network type change is requested by power manager. 8693 * Power Manger configuration won't affect the settings configured through 8694 * other reasons and will result in allowing network types that are in both 8695 * configurations (i.e intersection of both sets). 8696 * 8697 * @hide 8698 */ 8699 @SystemApi 8700 public static final int ALLOWED_NETWORK_TYPES_REASON_POWER = 1; 8701 8702 /** 8703 * To indicate allowed network type change is requested by carrier. 8704 * Carrier configuration won't affect the settings configured through 8705 * other reasons and will result in allowing network types that are in both 8706 * configurations (i.e intersection of both sets). 8707 * 8708 * @hide 8709 */ 8710 @SystemApi 8711 public static final int ALLOWED_NETWORK_TYPES_REASON_CARRIER = 2; 8712 8713 /** 8714 * To indicate allowed network type change is requested by the user via the 2G toggle. 8715 * 8716 * @hide 8717 */ 8718 @SystemApi 8719 public static final int ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G = 3; 8720 8721 /** 8722 * Set the allowed network types of the device and provide the reason triggering the allowed 8723 * network change. 8724 * This can be called for following reasons 8725 * <ol> 8726 * <li>Allowed network types control by USER {@link #ALLOWED_NETWORK_TYPES_REASON_USER} 8727 * <li>Allowed network types control by power manager 8728 * {@link #ALLOWED_NETWORK_TYPES_REASON_POWER} 8729 * <li>Allowed network types control by carrier {@link #ALLOWED_NETWORK_TYPES_REASON_CARRIER} 8730 * <li>Allowed network types control by the user-controlled "Allow 2G" toggle 8731 * {@link #ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G} 8732 * </ol> 8733 * This API will result in allowing an intersection of allowed network types for all reasons, 8734 * including the configuration done through other reasons. 8735 * 8736 * The functionality of this API with the parameter 8737 * {@link #ALLOWED_NETWORK_TYPES_REASON_CARRIER} is the same as the API 8738 * {@link TelephonyManager#setAllowedNetworkTypes}. Use this API instead of 8739 * {@link TelephonyManager#setAllowedNetworkTypes}. 8740 * <p> 8741 * If {@link android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported} 8742 * ({@link TelephonyManager#CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK}) returns true, then 8743 * setAllowedNetworkTypesBitmap is used on the radio interface. Otherwise, 8744 * setPreferredNetworkTypesBitmap is used instead. 8745 * 8746 * @param reason the reason the allowed network type change is taking place 8747 * @param allowedNetworkTypes The bitmask of allowed network types. 8748 * @throws IllegalStateException if the Telephony process is not currently available. 8749 * @throws IllegalArgumentException if invalid AllowedNetworkTypesReason is passed. 8750 * @hide 8751 */ 8752 @SystemApi 8753 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 8754 @RequiresFeature( 8755 enforcement = "android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported", 8756 value = TelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK) setAllowedNetworkTypesForReason(@llowedNetworkTypesReason int reason, @NetworkTypeBitMask long allowedNetworkTypes)8757 public void setAllowedNetworkTypesForReason(@AllowedNetworkTypesReason int reason, 8758 @NetworkTypeBitMask long allowedNetworkTypes) { 8759 if (!isValidAllowedNetworkTypesReason(reason)) { 8760 throw new IllegalArgumentException("invalid AllowedNetworkTypesReason."); 8761 } 8762 8763 try { 8764 ITelephony telephony = getITelephony(); 8765 if (telephony != null) { 8766 telephony.setAllowedNetworkTypesForReason(getSubId(), reason, 8767 allowedNetworkTypes); 8768 } else { 8769 throw new IllegalStateException("telephony service is null."); 8770 } 8771 } catch (RemoteException ex) { 8772 Rlog.e(TAG, "setAllowedNetworkTypesForReason RemoteException", ex); 8773 ex.rethrowFromSystemServer(); 8774 } 8775 } 8776 8777 /** 8778 * Get the allowed network types for certain reason. 8779 * 8780 * {@link #getAllowedNetworkTypesForReason} returns allowed network type for a 8781 * specific reason. 8782 * 8783 * @param reason the reason the allowed network type change is taking place 8784 * @return the allowed network type bitmask 8785 * @throws IllegalStateException if the Telephony process is not currently available. 8786 * @throws IllegalArgumentException if invalid AllowedNetworkTypesReason is passed. 8787 * @hide 8788 */ 8789 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 8790 @RequiresFeature( 8791 enforcement = "android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported", 8792 value = TelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK) 8793 @SystemApi getAllowedNetworkTypesForReason( @llowedNetworkTypesReason int reason)8794 public @NetworkTypeBitMask long getAllowedNetworkTypesForReason( 8795 @AllowedNetworkTypesReason int reason) { 8796 if (!isValidAllowedNetworkTypesReason(reason)) { 8797 throw new IllegalArgumentException("invalid AllowedNetworkTypesReason."); 8798 } 8799 8800 try { 8801 ITelephony telephony = getITelephony(); 8802 if (telephony != null) { 8803 return telephony.getAllowedNetworkTypesForReason(getSubId(), reason); 8804 } else { 8805 throw new IllegalStateException("telephony service is null."); 8806 } 8807 } catch (RemoteException ex) { 8808 Rlog.e(TAG, "getAllowedNetworkTypesForReason RemoteException", ex); 8809 ex.rethrowFromSystemServer(); 8810 } 8811 return -1; 8812 } 8813 /** 8814 * Verifies that the reason provided is valid. 8815 * @hide 8816 */ isValidAllowedNetworkTypesReason(@llowedNetworkTypesReason int reason)8817 public static boolean isValidAllowedNetworkTypesReason(@AllowedNetworkTypesReason int reason) { 8818 switch (reason) { 8819 case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER: 8820 case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER: 8821 case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER: 8822 case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G: 8823 return true; 8824 } 8825 return false; 8826 } 8827 /** 8828 * Get bit mask of all network types. 8829 * 8830 * @return bit mask of all network types 8831 * @hide 8832 */ getAllNetworkTypesBitmask()8833 public static @NetworkTypeBitMask long getAllNetworkTypesBitmask() { 8834 return NETWORK_STANDARDS_FAMILY_BITMASK_3GPP | NETWORK_STANDARDS_FAMILY_BITMASK_3GPP2; 8835 } 8836 8837 /** 8838 * Returns a string representation of the allowed network types{@link NetworkTypeBitMask}. 8839 * 8840 * @param networkTypeBitmask The bitmask of allowed network types. 8841 * @return the name of the allowed network types 8842 * @hide 8843 */ convertNetworkTypeBitmaskToString( @etworkTypeBitMask long networkTypeBitmask)8844 public static String convertNetworkTypeBitmaskToString( 8845 @NetworkTypeBitMask long networkTypeBitmask) { 8846 String networkTypeName = IntStream.rangeClosed(NETWORK_TYPE_GPRS, NETWORK_TYPE_NR) 8847 .filter(x -> { 8848 return (networkTypeBitmask & getBitMaskForNetworkType(x)) 8849 == getBitMaskForNetworkType(x); 8850 }) 8851 .mapToObj(x -> getNetworkTypeName(x)) 8852 .collect(Collectors.joining("|")); 8853 return TextUtils.isEmpty(networkTypeName) ? "UNKNOWN" : networkTypeName; 8854 } 8855 8856 /** 8857 * Set the preferred network type to global mode which includes NR, LTE, CDMA, EvDo 8858 * and GSM/WCDMA. 8859 * 8860 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 8861 * 8862 * @return true on success; false on any failure. 8863 */ setPreferredNetworkTypeToGlobal()8864 public boolean setPreferredNetworkTypeToGlobal() { 8865 return setPreferredNetworkTypeToGlobal(getSubId()); 8866 } 8867 8868 /** 8869 * Set the preferred network type to global mode which includes NR, LTE, CDMA, EvDo 8870 * and GSM/WCDMA. 8871 * 8872 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 8873 * 8874 * @return true on success; false on any failure. 8875 * @hide 8876 */ setPreferredNetworkTypeToGlobal(int subId)8877 public boolean setPreferredNetworkTypeToGlobal(int subId) { 8878 return setPreferredNetworkType(subId, RILConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA); 8879 } 8880 8881 /** 8882 * Check whether DUN APN is required for tethering. 8883 * <p> 8884 * Requires Permission: MODIFY_PHONE_STATE. 8885 * 8886 * @return {@code true} if DUN APN is required for tethering. 8887 * @hide 8888 */ 8889 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 8890 @SystemApi isTetheringApnRequired()8891 public boolean isTetheringApnRequired() { 8892 return isTetheringApnRequired(getSubId(SubscriptionManager.getActiveDataSubscriptionId())); 8893 } 8894 8895 /** 8896 * Check whether DUN APN is required for tethering with subId. 8897 * 8898 * @param subId the id of the subscription to require tethering. 8899 * @return {@code true} if DUN APN is required for tethering. 8900 * @hide 8901 */ isTetheringApnRequired(int subId)8902 public boolean isTetheringApnRequired(int subId) { 8903 try { 8904 ITelephony telephony = getITelephony(); 8905 if (telephony != null) 8906 return telephony.isTetheringApnRequiredForSubscriber(subId); 8907 } catch (RemoteException ex) { 8908 Rlog.e(TAG, "hasMatchedTetherApnSetting RemoteException", ex); 8909 } catch (NullPointerException ex) { 8910 Rlog.e(TAG, "hasMatchedTetherApnSetting NPE", ex); 8911 } 8912 return false; 8913 } 8914 8915 8916 /** 8917 * Values used to return status for hasCarrierPrivileges call. 8918 */ 8919 /** @hide */ @SystemApi 8920 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 8921 /** @hide */ @SystemApi 8922 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 8923 /** @hide */ @SystemApi 8924 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 8925 /** @hide */ @SystemApi 8926 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 8927 8928 /** 8929 * Has the calling application been granted carrier privileges by the carrier. 8930 * 8931 * If any of the packages in the calling UID has carrier privileges, the 8932 * call will return true. This access is granted by the owner of the UICC 8933 * card and does not depend on the registered carrier. 8934 * 8935 * Note that this API applies to both physical and embedded subscriptions and 8936 * is a superset of the checks done in SubscriptionManager#canManageSubscription. 8937 * 8938 * @return true if the app has carrier privileges. 8939 */ hasCarrierPrivileges()8940 public boolean hasCarrierPrivileges() { 8941 return hasCarrierPrivileges(getSubId()); 8942 } 8943 8944 /** 8945 * Has the calling application been granted carrier privileges by the carrier. 8946 * 8947 * If any of the packages in the calling UID has carrier privileges, the 8948 * call will return true. This access is granted by the owner of the UICC 8949 * card and does not depend on the registered carrier. 8950 * 8951 * Note that this API applies to both physical and embedded subscriptions and 8952 * is a superset of the checks done in SubscriptionManager#canManageSubscription. 8953 * 8954 * @param subId The subscription to use. 8955 * @return true if the app has carrier privileges. 8956 * @hide 8957 */ hasCarrierPrivileges(int subId)8958 public boolean hasCarrierPrivileges(int subId) { 8959 try { 8960 ITelephony telephony = getITelephony(); 8961 if (telephony != null) { 8962 return telephony.getCarrierPrivilegeStatus(subId) 8963 == CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; 8964 } 8965 } catch (RemoteException ex) { 8966 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 8967 } catch (NullPointerException ex) { 8968 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 8969 } 8970 return false; 8971 } 8972 8973 /** 8974 * Override the branding for the current ICCID. 8975 * 8976 * Once set, whenever the SIM is present in the device, the service 8977 * provider name (SPN) and the operator name will both be replaced by the 8978 * brand value input. To unset the value, the same function should be 8979 * called with a null brand value. 8980 * 8981 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 8982 * 8983 * @param brand The brand name to display/set. 8984 * @return true if the operation was executed correctly. 8985 */ setOperatorBrandOverride(String brand)8986 public boolean setOperatorBrandOverride(String brand) { 8987 return setOperatorBrandOverride(getSubId(), brand); 8988 } 8989 8990 /** 8991 * Override the branding for the current ICCID. 8992 * 8993 * Once set, whenever the SIM is present in the device, the service 8994 * provider name (SPN) and the operator name will both be replaced by the 8995 * brand value input. To unset the value, the same function should be 8996 * called with a null brand value. 8997 * 8998 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 8999 * 9000 * @param subId The subscription to use. 9001 * @param brand The brand name to display/set. 9002 * @return true if the operation was executed correctly. 9003 * @hide 9004 */ setOperatorBrandOverride(int subId, String brand)9005 public boolean setOperatorBrandOverride(int subId, String brand) { 9006 try { 9007 ITelephony telephony = getITelephony(); 9008 if (telephony != null) 9009 return telephony.setOperatorBrandOverride(subId, brand); 9010 } catch (RemoteException ex) { 9011 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 9012 } catch (NullPointerException ex) { 9013 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 9014 } 9015 return false; 9016 } 9017 9018 /** 9019 * Override the roaming preference for the current ICCID. 9020 * 9021 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 9022 * the platform's notion of a network operator being considered roaming or not. 9023 * The change only affects the ICCID that was active when this call was made. 9024 * 9025 * If null is passed as any of the input, the corresponding value is deleted. 9026 * 9027 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 9028 * 9029 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 9030 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 9031 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 9032 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 9033 * @return true if the operation was executed correctly. 9034 * 9035 * @hide 9036 */ 9037 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setRoamingOverride(List<String> gsmRoamingList, List<String> gsmNonRoamingList, List<String> cdmaRoamingList, List<String> cdmaNonRoamingList)9038 public boolean setRoamingOverride(List<String> gsmRoamingList, 9039 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 9040 List<String> cdmaNonRoamingList) { 9041 return setRoamingOverride(getSubId(), gsmRoamingList, gsmNonRoamingList, 9042 cdmaRoamingList, cdmaNonRoamingList); 9043 } 9044 9045 /** 9046 * Override the roaming preference for the current ICCID. 9047 * 9048 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 9049 * the platform's notion of a network operator being considered roaming or not. 9050 * The change only affects the ICCID that was active when this call was made. 9051 * 9052 * If null is passed as any of the input, the corresponding value is deleted. 9053 * 9054 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 9055 * 9056 * @param subId for which the roaming overrides apply. 9057 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 9058 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 9059 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 9060 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 9061 * @return true if the operation was executed correctly. 9062 * 9063 * @hide 9064 */ setRoamingOverride(int subId, List<String> gsmRoamingList, List<String> gsmNonRoamingList, List<String> cdmaRoamingList, List<String> cdmaNonRoamingList)9065 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, 9066 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 9067 List<String> cdmaNonRoamingList) { 9068 try { 9069 ITelephony telephony = getITelephony(); 9070 if (telephony != null) 9071 return telephony.setRoamingOverride(subId, gsmRoamingList, gsmNonRoamingList, 9072 cdmaRoamingList, cdmaNonRoamingList); 9073 } catch (RemoteException ex) { 9074 Rlog.e(TAG, "setRoamingOverride RemoteException", ex); 9075 } catch (NullPointerException ex) { 9076 Rlog.e(TAG, "setRoamingOverride NPE", ex); 9077 } 9078 return false; 9079 } 9080 9081 /** 9082 * Expose the rest of ITelephony to @SystemApi 9083 */ 9084 9085 /** @hide */ 9086 @SystemApi 9087 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getCdmaMdn()9088 public String getCdmaMdn() { 9089 return getCdmaMdn(getSubId()); 9090 } 9091 9092 /** @hide */ 9093 @SystemApi 9094 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getCdmaMdn(int subId)9095 public String getCdmaMdn(int subId) { 9096 try { 9097 ITelephony telephony = getITelephony(); 9098 if (telephony == null) 9099 return null; 9100 return telephony.getCdmaMdn(subId); 9101 } catch (RemoteException ex) { 9102 return null; 9103 } catch (NullPointerException ex) { 9104 return null; 9105 } 9106 } 9107 9108 /** @hide */ 9109 @SystemApi 9110 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getCdmaMin()9111 public String getCdmaMin() { 9112 return getCdmaMin(getSubId()); 9113 } 9114 9115 /** @hide */ 9116 @SystemApi 9117 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getCdmaMin(int subId)9118 public String getCdmaMin(int subId) { 9119 try { 9120 ITelephony telephony = getITelephony(); 9121 if (telephony == null) 9122 return null; 9123 return telephony.getCdmaMin(subId); 9124 } catch (RemoteException ex) { 9125 return null; 9126 } catch (NullPointerException ex) { 9127 return null; 9128 } 9129 } 9130 9131 /** @hide */ 9132 @SystemApi 9133 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) checkCarrierPrivilegesForPackage(String pkgName)9134 public int checkCarrierPrivilegesForPackage(String pkgName) { 9135 try { 9136 ITelephony telephony = getITelephony(); 9137 if (telephony != null) 9138 return telephony.checkCarrierPrivilegesForPackage(getSubId(), pkgName); 9139 } catch (RemoteException ex) { 9140 Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex); 9141 } catch (NullPointerException ex) { 9142 Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex); 9143 } 9144 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 9145 } 9146 9147 /** @hide */ 9148 @SystemApi 9149 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) checkCarrierPrivilegesForPackageAnyPhone(String pkgName)9150 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { 9151 try { 9152 ITelephony telephony = getITelephony(); 9153 if (telephony != null) 9154 return telephony.checkCarrierPrivilegesForPackageAnyPhone(pkgName); 9155 } catch (RemoteException ex) { 9156 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone RemoteException", ex); 9157 } catch (NullPointerException ex) { 9158 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone NPE", ex); 9159 } 9160 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 9161 } 9162 9163 /** @hide */ 9164 @SystemApi getCarrierPackageNamesForIntent(Intent intent)9165 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 9166 return getCarrierPackageNamesForIntentAndPhone(intent, getPhoneId()); 9167 } 9168 9169 /** @hide */ 9170 @SystemApi 9171 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId)9172 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { 9173 try { 9174 ITelephony telephony = getITelephony(); 9175 if (telephony != null) 9176 return telephony.getCarrierPackageNamesForIntentAndPhone(intent, phoneId); 9177 } catch (RemoteException ex) { 9178 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone RemoteException", ex); 9179 } catch (NullPointerException ex) { 9180 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone NPE", ex); 9181 } 9182 return null; 9183 } 9184 9185 /** @hide */ 9186 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getPackagesWithCarrierPrivileges()9187 public List<String> getPackagesWithCarrierPrivileges() { 9188 try { 9189 ITelephony telephony = getITelephony(); 9190 if (telephony != null) { 9191 return telephony.getPackagesWithCarrierPrivileges(getPhoneId()); 9192 } 9193 } catch (RemoteException ex) { 9194 Rlog.e(TAG, "getPackagesWithCarrierPrivileges RemoteException", ex); 9195 } catch (NullPointerException ex) { 9196 Rlog.e(TAG, "getPackagesWithCarrierPrivileges NPE", ex); 9197 } 9198 return Collections.EMPTY_LIST; 9199 } 9200 9201 /** 9202 * Get the names of packages with carrier privileges for all the active subscriptions. 9203 * 9204 * @hide 9205 */ 9206 @SystemApi 9207 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 9208 @NonNull getCarrierPrivilegedPackagesForAllActiveSubscriptions()9209 public List<String> getCarrierPrivilegedPackagesForAllActiveSubscriptions() { 9210 try { 9211 ITelephony telephony = getITelephony(); 9212 if (telephony != null) { 9213 return telephony.getPackagesWithCarrierPrivilegesForAllPhones(); 9214 } 9215 } catch (RemoteException ex) { 9216 Rlog.e(TAG, "getCarrierPrivilegedPackagesForAllActiveSubscriptions RemoteException", 9217 ex); 9218 } catch (NullPointerException ex) { 9219 Rlog.e(TAG, "getCarrierPrivilegedPackagesForAllActiveSubscriptions NPE", ex); 9220 } 9221 return Collections.EMPTY_LIST; 9222 } 9223 9224 /** 9225 * Call composer status OFF from user setting. 9226 */ 9227 public static final int CALL_COMPOSER_STATUS_OFF = 0; 9228 9229 /** 9230 * Call composer status ON from user setting. 9231 */ 9232 public static final int CALL_COMPOSER_STATUS_ON = 1; 9233 9234 /** @hide */ 9235 @IntDef(prefix = {"CALL_COMPOSER_STATUS_"}, 9236 value = { 9237 CALL_COMPOSER_STATUS_ON, 9238 CALL_COMPOSER_STATUS_OFF, 9239 }) 9240 public @interface CallComposerStatus {} 9241 9242 /** 9243 * Set the user-set status for enriched calling with call composer. 9244 * 9245 * @param status user-set status for enriched calling with call composer. 9246 * 9247 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 9248 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 9249 * 9250 * @throws IllegalArgumentException if requested state is invalid. 9251 * @throws SecurityException if the caller does not have the permission. 9252 */ 9253 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setCallComposerStatus(@allComposerStatus int status)9254 public void setCallComposerStatus(@CallComposerStatus int status) { 9255 if (status > CALL_COMPOSER_STATUS_ON 9256 || status < CALL_COMPOSER_STATUS_OFF) { 9257 throw new IllegalArgumentException("requested status is invalid"); 9258 } 9259 try { 9260 ITelephony telephony = getITelephony(); 9261 if (telephony != null) { 9262 telephony.setCallComposerStatus(getSubId(), status); 9263 } 9264 } catch (RemoteException ex) { 9265 Log.e(TAG, "Error calling ITelephony#setCallComposerStatus", ex); 9266 ex.rethrowFromSystemServer(); 9267 } 9268 } 9269 9270 /** 9271 * Get the user-set status for enriched calling with call composer. 9272 * 9273 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 9274 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 9275 * 9276 * @throws SecurityException if the caller does not have the permission. 9277 * 9278 * @return the user-set status for enriched calling with call composer, either of 9279 * {@link #CALL_COMPOSER_STATUS_ON} or {@link #CALL_COMPOSER_STATUS_OFF}. 9280 */ 9281 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getCallComposerStatus()9282 public @CallComposerStatus int getCallComposerStatus() { 9283 try { 9284 ITelephony telephony = getITelephony(); 9285 if (telephony != null) { 9286 return telephony.getCallComposerStatus(getSubId()); 9287 } 9288 } catch (RemoteException ex) { 9289 Log.e(TAG, "Error calling ITelephony#getCallComposerStatus", ex); 9290 ex.rethrowFromSystemServer(); 9291 } 9292 return CALL_COMPOSER_STATUS_OFF; 9293 } 9294 9295 /** @hide */ 9296 @SystemApi 9297 @SuppressLint("RequiresPermission") dial(String number)9298 public void dial(String number) { 9299 try { 9300 ITelephony telephony = getITelephony(); 9301 if (telephony != null) 9302 telephony.dial(number); 9303 } catch (RemoteException e) { 9304 Log.e(TAG, "Error calling ITelephony#dial", e); 9305 } 9306 } 9307 9308 /** 9309 * @deprecated Use {@link android.telecom.TelecomManager#placeCall(Uri address, 9310 * Bundle extras)} instead. 9311 * @hide 9312 */ 9313 @Deprecated 9314 @SystemApi 9315 @RequiresPermission(android.Manifest.permission.CALL_PHONE) call(String callingPackage, String number)9316 public void call(String callingPackage, String number) { 9317 try { 9318 ITelephony telephony = getITelephony(); 9319 if (telephony != null) 9320 telephony.call(callingPackage, number); 9321 } catch (RemoteException e) { 9322 Log.e(TAG, "Error calling ITelephony#call", e); 9323 } 9324 } 9325 9326 /** 9327 * @removed Use {@link android.telecom.TelecomManager#endCall()} instead. 9328 * @hide 9329 * @removed 9330 */ 9331 @Deprecated 9332 @SystemApi 9333 @RequiresPermission(android.Manifest.permission.CALL_PHONE) endCall()9334 public boolean endCall() { 9335 return false; 9336 } 9337 9338 /** 9339 * @removed Use {@link android.telecom.TelecomManager#acceptRingingCall} instead 9340 * @hide 9341 * @removed 9342 */ 9343 @Deprecated 9344 @SystemApi 9345 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) answerRingingCall()9346 public void answerRingingCall() { 9347 // No-op 9348 } 9349 9350 /** 9351 * @removed Use {@link android.telecom.TelecomManager#silenceRinger} instead 9352 * @hide 9353 */ 9354 @Deprecated 9355 @SystemApi 9356 @SuppressLint("RequiresPermission") silenceRinger()9357 public void silenceRinger() { 9358 // No-op 9359 } 9360 9361 /** 9362 * @deprecated Use {@link android.telecom.TelecomManager#isInCall} instead 9363 * @hide 9364 */ 9365 @Deprecated 9366 @SystemApi 9367 @RequiresPermission(anyOf = { 9368 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 9369 android.Manifest.permission.READ_PHONE_STATE 9370 }) isOffhook()9371 public boolean isOffhook() { 9372 TelecomManager tm = (TelecomManager) mContext.getSystemService(TELECOM_SERVICE); 9373 return tm.isInCall(); 9374 } 9375 9376 /** 9377 * @deprecated Use {@link android.telecom.TelecomManager#isRinging} instead 9378 * @hide 9379 */ 9380 @Deprecated 9381 @SystemApi 9382 @RequiresPermission(anyOf = { 9383 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 9384 android.Manifest.permission.READ_PHONE_STATE 9385 }) isRinging()9386 public boolean isRinging() { 9387 TelecomManager tm = (TelecomManager) mContext.getSystemService(TELECOM_SERVICE); 9388 return tm.isRinging(); 9389 } 9390 9391 /** 9392 * @deprecated Use {@link android.telecom.TelecomManager#isInCall} instead 9393 * @hide 9394 */ 9395 @Deprecated 9396 @SystemApi 9397 @RequiresPermission(anyOf = { 9398 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 9399 android.Manifest.permission.READ_PHONE_STATE 9400 }) isIdle()9401 public boolean isIdle() { 9402 TelecomManager tm = (TelecomManager) mContext.getSystemService(TELECOM_SERVICE); 9403 return !tm.isInCall(); 9404 } 9405 9406 /** 9407 * @deprecated Use {@link android.telephony.TelephonyManager#getServiceState} instead 9408 * @hide 9409 */ 9410 @Deprecated 9411 @SystemApi 9412 @RequiresPermission(anyOf = { 9413 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 9414 android.Manifest.permission.READ_PHONE_STATE 9415 }) isRadioOn()9416 public boolean isRadioOn() { 9417 try { 9418 ITelephony telephony = getITelephony(); 9419 if (telephony != null) 9420 return telephony.isRadioOnWithFeature(getOpPackageName(), getAttributionTag()); 9421 } catch (RemoteException e) { 9422 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 9423 } 9424 return false; 9425 } 9426 9427 /** @hide */ 9428 @SystemApi 9429 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) supplyPin(String pin)9430 public boolean supplyPin(String pin) { 9431 try { 9432 ITelephony telephony = getITelephony(); 9433 if (telephony != null) 9434 return telephony.supplyPinForSubscriber(getSubId(), pin); 9435 } catch (RemoteException e) { 9436 Log.e(TAG, "Error calling ITelephony#supplyPinForSubscriber", e); 9437 } 9438 return false; 9439 } 9440 9441 /** @hide */ 9442 @SystemApi 9443 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) supplyPuk(String puk, String pin)9444 public boolean supplyPuk(String puk, String pin) { 9445 try { 9446 ITelephony telephony = getITelephony(); 9447 if (telephony != null) 9448 return telephony.supplyPukForSubscriber(getSubId(), puk, pin); 9449 } catch (RemoteException e) { 9450 Log.e(TAG, "Error calling ITelephony#supplyPukForSubscriber", e); 9451 } 9452 return false; 9453 } 9454 9455 /** 9456 * @deprecated use {@link #supplyIccLockPin(String)} instead. 9457 * @hide 9458 */ 9459 @SystemApi 9460 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 9461 @Deprecated supplyPinReportResult(String pin)9462 public int[] supplyPinReportResult(String pin) { 9463 try { 9464 ITelephony telephony = getITelephony(); 9465 if (telephony != null) 9466 return telephony.supplyPinReportResultForSubscriber(getSubId(), pin); 9467 } catch (RemoteException e) { 9468 Log.e(TAG, "Error calling ITelephony#supplyPinReportResultForSubscriber", e); 9469 } 9470 return new int[0]; 9471 } 9472 9473 /** 9474 * @deprecated use {@link #supplyIccLockPuk(String, String)} instead. 9475 * @hide 9476 */ 9477 @SystemApi 9478 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 9479 @Deprecated supplyPukReportResult(String puk, String pin)9480 public int[] supplyPukReportResult(String puk, String pin) { 9481 try { 9482 ITelephony telephony = getITelephony(); 9483 if (telephony != null) 9484 return telephony.supplyPukReportResultForSubscriber(getSubId(), puk, pin); 9485 } catch (RemoteException e) { 9486 Log.e(TAG, "Error calling ITelephony#supplyPukReportResultForSubscriber", e); 9487 } 9488 return new int[0]; 9489 } 9490 9491 /** 9492 * Supplies a PIN to unlock the ICC and returns the corresponding {@link PinResult}. 9493 * Used when the user enters their ICC unlock PIN to attempt an unlock. 9494 * 9495 * @param pin The user entered PIN. 9496 * @return The result of the PIN. 9497 * @throws SecurityException if the caller doesn't have the permission. 9498 * @throws IllegalStateException if the Telephony process is not currently available. 9499 * 9500 * <p>Requires Permission: 9501 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 9502 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 9503 * 9504 * @hide 9505 */ 9506 @SystemApi 9507 @NonNull 9508 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) supplyIccLockPin(@onNull String pin)9509 public PinResult supplyIccLockPin(@NonNull String pin) { 9510 try { 9511 ITelephony telephony = getITelephony(); 9512 if (telephony != null) { 9513 int[] result = telephony.supplyPinReportResultForSubscriber(getSubId(), pin); 9514 return new PinResult(result[0], result[1]); 9515 } else { 9516 throw new IllegalStateException("telephony service is null."); 9517 } 9518 } catch (RemoteException e) { 9519 Log.e(TAG, "Error calling ITelephony#supplyIccLockPin", e); 9520 e.rethrowFromSystemServer(); 9521 } 9522 return PinResult.getDefaultFailedResult(); 9523 } 9524 9525 /** 9526 * Supplies a PUK and PIN to unlock the ICC and returns the corresponding {@link PinResult}. 9527 * Used when the user enters their ICC unlock PUK and PIN to attempt an unlock. 9528 * 9529 * @param puk The product unlocking key. 9530 * @param pin The user entered PIN. 9531 * @return The result of the PUK and PIN. 9532 * @throws SecurityException if the caller doesn't have the permission. 9533 * @throws IllegalStateException if the Telephony process is not currently available. 9534 * 9535 * <p>Requires Permission: 9536 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 9537 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 9538 * 9539 * @hide 9540 */ 9541 @SystemApi 9542 @NonNull 9543 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) supplyIccLockPuk(@onNull String puk, @NonNull String pin)9544 public PinResult supplyIccLockPuk(@NonNull String puk, @NonNull String pin) { 9545 try { 9546 ITelephony telephony = getITelephony(); 9547 if (telephony != null) { 9548 int[] result = telephony.supplyPukReportResultForSubscriber(getSubId(), puk, pin); 9549 return new PinResult(result[0], result[1]); 9550 } else { 9551 throw new IllegalStateException("telephony service is null."); 9552 } 9553 } catch (RemoteException e) { 9554 Log.e(TAG, "Error calling ITelephony#supplyIccLockPuk", e); 9555 e.rethrowFromSystemServer(); 9556 } 9557 return PinResult.getDefaultFailedResult(); 9558 } 9559 9560 /** 9561 * Used to notify callers of 9562 * {@link TelephonyManager#sendUssdRequest(String, UssdResponseCallback, Handler)} when the 9563 * network either successfully executes a USSD request, or if there was a failure while 9564 * executing the request. 9565 * <p> 9566 * {@link #onReceiveUssdResponse(TelephonyManager, String, CharSequence)} will be called if the 9567 * USSD request has succeeded. 9568 * {@link #onReceiveUssdResponseFailed(TelephonyManager, String, int)} will be called if the 9569 * USSD request has failed. 9570 */ 9571 public static abstract class UssdResponseCallback { 9572 /** 9573 * Called when a USSD request has succeeded. The {@code response} contains the USSD 9574 * response received from the network. The calling app can choose to either display the 9575 * response to the user or perform some operation based on the response. 9576 * <p> 9577 * USSD responses are unstructured text and their content is determined by the mobile network 9578 * operator. 9579 * 9580 * @param telephonyManager the TelephonyManager the callback is registered to. 9581 * @param request the USSD request sent to the mobile network. 9582 * @param response the response to the USSD request provided by the mobile network. 9583 **/ onReceiveUssdResponse(final TelephonyManager telephonyManager, String request, CharSequence response)9584 public void onReceiveUssdResponse(final TelephonyManager telephonyManager, 9585 String request, CharSequence response) {}; 9586 9587 /** 9588 * Called when a USSD request has failed to complete. 9589 * 9590 * @param telephonyManager the TelephonyManager the callback is registered to. 9591 * @param request the USSD request sent to the mobile network. 9592 * @param failureCode failure code indicating why the request failed. Will be either 9593 * {@link TelephonyManager#USSD_RETURN_FAILURE} or 9594 * {@link TelephonyManager#USSD_ERROR_SERVICE_UNAVAIL}. 9595 **/ onReceiveUssdResponseFailed(final TelephonyManager telephonyManager, String request, int failureCode)9596 public void onReceiveUssdResponseFailed(final TelephonyManager telephonyManager, 9597 String request, int failureCode) {}; 9598 } 9599 9600 /** 9601 * Sends an Unstructured Supplementary Service Data (USSD) request to the mobile network and 9602 * informs the caller of the response via the supplied {@code callback}. 9603 * <p>Carriers define USSD codes which can be sent by the user to request information such as 9604 * the user's current data balance or minutes balance. 9605 * <p>Requires permission: 9606 * {@link android.Manifest.permission#CALL_PHONE} 9607 * @param ussdRequest the USSD command to be executed. 9608 * @param callback called by the framework to inform the caller of the result of executing the 9609 * USSD request (see {@link UssdResponseCallback}). 9610 * @param handler the {@link Handler} to run the request on. 9611 */ 9612 @RequiresPermission(android.Manifest.permission.CALL_PHONE) sendUssdRequest(String ussdRequest, final UssdResponseCallback callback, Handler handler)9613 public void sendUssdRequest(String ussdRequest, 9614 final UssdResponseCallback callback, Handler handler) { 9615 checkNotNull(callback, "UssdResponseCallback cannot be null."); 9616 final TelephonyManager telephonyManager = this; 9617 9618 ResultReceiver wrappedCallback = new ResultReceiver(handler) { 9619 @Override 9620 protected void onReceiveResult(int resultCode, Bundle ussdResponse) { 9621 Rlog.d(TAG, "USSD:" + resultCode); 9622 checkNotNull(ussdResponse, "ussdResponse cannot be null."); 9623 UssdResponse response = ussdResponse.getParcelable(USSD_RESPONSE); 9624 9625 if (resultCode == USSD_RETURN_SUCCESS) { 9626 callback.onReceiveUssdResponse(telephonyManager, response.getUssdRequest(), 9627 response.getReturnMessage()); 9628 } else { 9629 callback.onReceiveUssdResponseFailed(telephonyManager, 9630 response.getUssdRequest(), resultCode); 9631 } 9632 } 9633 }; 9634 9635 try { 9636 ITelephony telephony = getITelephony(); 9637 if (telephony != null) { 9638 telephony.handleUssdRequest(getSubId(), ussdRequest, wrappedCallback); 9639 } 9640 } catch (RemoteException e) { 9641 Log.e(TAG, "Error calling ITelephony#sendUSSDCode", e); 9642 UssdResponse response = new UssdResponse(ussdRequest, ""); 9643 Bundle returnData = new Bundle(); 9644 returnData.putParcelable(USSD_RESPONSE, response); 9645 wrappedCallback.send(USSD_ERROR_SERVICE_UNAVAIL, returnData); 9646 } 9647 } 9648 9649 /** 9650 * Whether the device is currently on a technology (e.g. UMTS or LTE) which can support 9651 * voice and data simultaneously. This can change based on location or network condition. 9652 * 9653 * @return {@code true} if simultaneous voice and data supported, and {@code false} otherwise. 9654 */ isConcurrentVoiceAndDataSupported()9655 public boolean isConcurrentVoiceAndDataSupported() { 9656 try { 9657 ITelephony telephony = getITelephony(); 9658 return (telephony == null ? false : telephony.isConcurrentVoiceAndDataAllowed( 9659 getSubId())); 9660 } catch (RemoteException e) { 9661 Log.e(TAG, "Error calling ITelephony#isConcurrentVoiceAndDataAllowed", e); 9662 } 9663 return false; 9664 } 9665 9666 /** @hide */ 9667 @SystemApi 9668 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) handlePinMmi(String dialString)9669 public boolean handlePinMmi(String dialString) { 9670 try { 9671 ITelephony telephony = getITelephony(); 9672 if (telephony != null) 9673 return telephony.handlePinMmi(dialString); 9674 } catch (RemoteException e) { 9675 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 9676 } 9677 return false; 9678 } 9679 9680 /** @hide */ 9681 @SystemApi 9682 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) handlePinMmiForSubscriber(int subId, String dialString)9683 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 9684 try { 9685 ITelephony telephony = getITelephony(); 9686 if (telephony != null) 9687 return telephony.handlePinMmiForSubscriber(subId, dialString); 9688 } catch (RemoteException e) { 9689 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 9690 } 9691 return false; 9692 } 9693 9694 /** @hide */ 9695 @SystemApi 9696 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) toggleRadioOnOff()9697 public void toggleRadioOnOff() { 9698 try { 9699 ITelephony telephony = getITelephony(); 9700 if (telephony != null) 9701 telephony.toggleRadioOnOff(); 9702 } catch (RemoteException e) { 9703 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 9704 } 9705 } 9706 9707 /** @hide */ 9708 @SystemApi 9709 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setRadio(boolean turnOn)9710 public boolean setRadio(boolean turnOn) { 9711 try { 9712 ITelephony telephony = getITelephony(); 9713 if (telephony != null) 9714 return telephony.setRadio(turnOn); 9715 } catch (RemoteException e) { 9716 Log.e(TAG, "Error calling ITelephony#setRadio", e); 9717 } 9718 return false; 9719 } 9720 9721 /** @hide */ 9722 @SystemApi 9723 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setRadioPower(boolean turnOn)9724 public boolean setRadioPower(boolean turnOn) { 9725 try { 9726 ITelephony telephony = getITelephony(); 9727 if (telephony != null) 9728 return telephony.setRadioPower(turnOn); 9729 } catch (RemoteException e) { 9730 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 9731 } 9732 return false; 9733 } 9734 9735 /** 9736 * Shut down all the live radios over all the slot indexes. 9737 * 9738 * <p>To know when the radio has completed powering off, use 9739 * {@link PhoneStateListener#LISTEN_SERVICE_STATE LISTEN_SERVICE_STATE}. 9740 * 9741 * @hide 9742 */ 9743 @SystemApi 9744 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) shutdownAllRadios()9745 public void shutdownAllRadios() { 9746 try { 9747 ITelephony telephony = getITelephony(); 9748 if (telephony != null) { 9749 telephony.shutdownMobileRadios(); 9750 } 9751 } catch (RemoteException e) { 9752 Log.e(TAG, "Error calling ITelephony#shutdownAllRadios", e); 9753 e.rethrowAsRuntimeException(); 9754 } 9755 } 9756 9757 /** 9758 * Check if any radio is on over all the slot indexes. 9759 * 9760 * @return {@code true} if any radio is on over any slot index. 9761 * @hide 9762 */ 9763 @SystemApi 9764 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) isAnyRadioPoweredOn()9765 public boolean isAnyRadioPoweredOn() { 9766 try { 9767 ITelephony telephony = getITelephony(); 9768 if (telephony != null) { 9769 return telephony.needMobileRadioShutdown(); 9770 } 9771 } catch (RemoteException e) { 9772 Log.e(TAG, "Error calling ITelephony#isAnyRadioPoweredOn", e); 9773 e.rethrowAsRuntimeException(); 9774 } 9775 return false; 9776 } 9777 9778 /** 9779 * Radio explicitly powered off (e.g, airplane mode). 9780 * @hide 9781 */ 9782 @SystemApi 9783 public static final int RADIO_POWER_OFF = 0; 9784 9785 /** 9786 * Radio power is on. 9787 * @hide 9788 */ 9789 @SystemApi 9790 public static final int RADIO_POWER_ON = 1; 9791 9792 /** 9793 * Radio power unavailable (eg, modem resetting or not booted). 9794 * @hide 9795 */ 9796 @SystemApi 9797 public static final int RADIO_POWER_UNAVAILABLE = 2; 9798 9799 /** 9800 * @return current modem radio state. 9801 * 9802 * <p>Requires permission: {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} or 9803 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling 9804 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 9805 * 9806 * @hide 9807 */ 9808 @SystemApi 9809 @RequiresPermission(anyOf = {android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 9810 android.Manifest.permission.READ_PHONE_STATE}) getRadioPowerState()9811 public @RadioPowerState int getRadioPowerState() { 9812 try { 9813 ITelephony telephony = getITelephony(); 9814 if (telephony != null) { 9815 return telephony.getRadioPowerState(getSlotIndex(), mContext.getOpPackageName(), 9816 mContext.getAttributionTag()); 9817 } 9818 } catch (RemoteException ex) { 9819 // This could happen if binder process crashes. 9820 } 9821 return RADIO_POWER_UNAVAILABLE; 9822 } 9823 9824 /** 9825 * This method should not be used due to privacy and stability concerns. 9826 * 9827 * @hide 9828 */ 9829 @SystemApi updateServiceLocation()9830 public void updateServiceLocation() { 9831 Log.e(TAG, "Do not call TelephonyManager#updateServiceLocation()"); 9832 } 9833 9834 /** @hide */ 9835 @SystemApi 9836 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) enableDataConnectivity()9837 public boolean enableDataConnectivity() { 9838 try { 9839 ITelephony telephony = getITelephony(); 9840 if (telephony != null) 9841 return telephony.enableDataConnectivity(); 9842 } catch (RemoteException e) { 9843 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 9844 } 9845 return false; 9846 } 9847 9848 /** @hide */ 9849 @SystemApi 9850 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) disableDataConnectivity()9851 public boolean disableDataConnectivity() { 9852 try { 9853 ITelephony telephony = getITelephony(); 9854 if (telephony != null) 9855 return telephony.disableDataConnectivity(); 9856 } catch (RemoteException e) { 9857 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 9858 } 9859 return false; 9860 } 9861 9862 /** @hide */ 9863 @SystemApi isDataConnectivityPossible()9864 public boolean isDataConnectivityPossible() { 9865 try { 9866 ITelephony telephony = getITelephony(); 9867 if (telephony != null) 9868 return telephony.isDataConnectivityPossible(getSubId(SubscriptionManager 9869 .getActiveDataSubscriptionId())); 9870 } catch (RemoteException e) { 9871 Log.e(TAG, "Error calling ITelephony#isDataAllowed", e); 9872 } 9873 return false; 9874 } 9875 9876 /** @hide */ 9877 @SystemApi needsOtaServiceProvisioning()9878 public boolean needsOtaServiceProvisioning() { 9879 try { 9880 ITelephony telephony = getITelephony(); 9881 if (telephony != null) 9882 return telephony.needsOtaServiceProvisioning(); 9883 } catch (RemoteException e) { 9884 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 9885 } 9886 return false; 9887 } 9888 9889 /** 9890 * Get the mobile provisioning url that is used to launch a browser to allow users to manage 9891 * their mobile plan. 9892 * 9893 * <p>Requires Permission: 9894 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE}. 9895 * 9896 * TODO: The legacy design only supports single sim design. Ideally, this should support 9897 * multi-sim design in current world. 9898 * 9899 * {@hide} 9900 */ 9901 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getMobileProvisioningUrl()9902 public @Nullable String getMobileProvisioningUrl() { 9903 try { 9904 final ITelephony service = getITelephony(); 9905 if (service != null) { 9906 return service.getMobileProvisioningUrl(); 9907 } else { 9908 throw new IllegalStateException("telephony service is null."); 9909 } 9910 } catch (RemoteException ex) { 9911 Rlog.e(TAG, "Telephony#getMobileProvisioningUrl RemoteException" + ex); 9912 } 9913 return null; 9914 } 9915 9916 /** 9917 * Turns mobile data on or off. 9918 * If this object has been created with {@link #createForSubscriptionId}, applies to the given 9919 * subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 9920 * 9921 * <p>Requires Permission: 9922 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 9923 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 9924 * 9925 * @param enable Whether to enable mobile data. 9926 * @deprecated use setDataEnabledForReason with reason DATA_ENABLED_REASON_USER instead. 9927 * 9928 */ 9929 @Deprecated 9930 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 9931 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataEnabled(boolean enable)9932 public void setDataEnabled(boolean enable) { 9933 setDataEnabled(getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), enable); 9934 } 9935 9936 /** 9937 * @hide 9938 * @deprecated use {@link #setDataEnabledForReason(int, boolean)} instead. 9939 */ 9940 @SystemApi 9941 @Deprecated 9942 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataEnabled(int subId, boolean enable)9943 public void setDataEnabled(int subId, boolean enable) { 9944 try { 9945 setDataEnabledForReason(subId, DATA_ENABLED_REASON_USER, enable); 9946 } catch (RuntimeException e) { 9947 Log.e(TAG, "Error calling setDataEnabledForReason e:" + e); 9948 } 9949 } 9950 9951 /** 9952 * @deprecated use {@link #isDataEnabled()} instead. 9953 * @hide 9954 */ 9955 @SystemApi 9956 @Deprecated getDataEnabled()9957 public boolean getDataEnabled() { 9958 return isDataEnabled(); 9959 } 9960 9961 /** 9962 * Returns whether mobile data is enabled or not per user setting. There are other factors 9963 * that could disable mobile data, but they are not considered here. 9964 * 9965 * If this object has been created with {@link #createForSubscriptionId}, applies to the given 9966 * subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 9967 * 9968 * <p>Requires one of the following permissions: 9969 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, 9970 * {@link android.Manifest.permission#MODIFY_PHONE_STATE}, or that the calling app has carrier 9971 * privileges (see {@link #hasCarrierPrivileges}). 9972 * 9973 * <p>Note that this does not take into account any data restrictions that may be present on the 9974 * calling app. Such restrictions may be inspected with 9975 * {@link ConnectivityManager#getRestrictBackgroundStatus}. 9976 * 9977 * @return true if mobile data is enabled. 9978 */ 9979 @RequiresPermission(anyOf = {android.Manifest.permission.ACCESS_NETWORK_STATE, 9980 android.Manifest.permission.MODIFY_PHONE_STATE, 9981 android.Manifest.permission.READ_PHONE_STATE}) isDataEnabled()9982 public boolean isDataEnabled() { 9983 try { 9984 return isDataEnabledForReason(DATA_ENABLED_REASON_USER); 9985 } catch (IllegalStateException ise) { 9986 // TODO(b/176163590): Remove this catch once TelephonyManager is booting safely. 9987 Log.e(TAG, "Error calling #isDataEnabled, returning default (false).", ise); 9988 return false; 9989 } 9990 } 9991 9992 /** 9993 * Returns whether mobile data roaming is enabled on the subscription. 9994 * 9995 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 9996 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 9997 * 9998 * <p>Requires one of the following permissions: 9999 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, 10000 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app 10001 * has carrier privileges (see {@link #hasCarrierPrivileges}). 10002 * 10003 * @return {@code true} if the data roaming is enabled on the subscription, otherwise return 10004 * {@code false}. 10005 */ 10006 @RequiresPermission(anyOf = {android.Manifest.permission.ACCESS_NETWORK_STATE, 10007 android.Manifest.permission.READ_PHONE_STATE}) isDataRoamingEnabled()10008 public boolean isDataRoamingEnabled() { 10009 boolean isDataRoamingEnabled = false; 10010 try { 10011 ITelephony telephony = getITelephony(); 10012 if (telephony != null) { 10013 isDataRoamingEnabled = telephony.isDataRoamingEnabled( 10014 getSubId(SubscriptionManager.getDefaultDataSubscriptionId())); 10015 } 10016 } catch (RemoteException e) { 10017 Log.e(TAG, "Error calling ITelephony#isDataRoamingEnabled", e); 10018 } 10019 return isDataRoamingEnabled; 10020 } 10021 10022 /** 10023 * Gets the roaming mode for CDMA phone. 10024 * 10025 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 10026 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 10027 * 10028 * @return the CDMA roaming mode. 10029 * @throws SecurityException if the caller does not have the permission. 10030 * @throws IllegalStateException if the Telephony process is not currently available. 10031 * 10032 * @see #CDMA_ROAMING_MODE_RADIO_DEFAULT 10033 * @see #CDMA_ROAMING_MODE_HOME 10034 * @see #CDMA_ROAMING_MODE_AFFILIATED 10035 * @see #CDMA_ROAMING_MODE_ANY 10036 * 10037 * <p>Requires permission: 10038 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 10039 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 10040 * 10041 * @hide 10042 */ 10043 @SystemApi 10044 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getCdmaRoamingMode()10045 public @CdmaRoamingMode int getCdmaRoamingMode() { 10046 int mode = CDMA_ROAMING_MODE_RADIO_DEFAULT; 10047 try { 10048 ITelephony telephony = getITelephony(); 10049 if (telephony != null) { 10050 mode = telephony.getCdmaRoamingMode(getSubId()); 10051 } else { 10052 throw new IllegalStateException("telephony service is null."); 10053 } 10054 } catch (RemoteException ex) { 10055 Log.e(TAG, "Error calling ITelephony#getCdmaRoamingMode", ex); 10056 ex.rethrowFromSystemServer(); 10057 } 10058 return mode; 10059 } 10060 10061 /** 10062 * Sets the roaming mode for CDMA phone to the given mode {@code mode}. If the phone is not 10063 * CDMA capable, this method throws an IllegalStateException. 10064 * 10065 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 10066 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 10067 * 10068 * @param mode CDMA roaming mode. 10069 * @throws SecurityException if the caller does not have the permission. 10070 * @throws IllegalStateException if the Telephony process or radio is not currently available, 10071 * the device is not CDMA capable, or the request fails. 10072 * 10073 * @see #CDMA_ROAMING_MODE_RADIO_DEFAULT 10074 * @see #CDMA_ROAMING_MODE_HOME 10075 * @see #CDMA_ROAMING_MODE_AFFILIATED 10076 * @see #CDMA_ROAMING_MODE_ANY 10077 * 10078 * <p>Requires Permission: 10079 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 10080 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 10081 * 10082 * @hide 10083 */ 10084 @SystemApi 10085 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setCdmaRoamingMode(@dmaRoamingMode int mode)10086 public void setCdmaRoamingMode(@CdmaRoamingMode int mode) { 10087 if (getPhoneType() != PHONE_TYPE_CDMA) { 10088 throw new IllegalStateException("Phone does not support CDMA."); 10089 } 10090 try { 10091 ITelephony telephony = getITelephony(); 10092 if (telephony != null) { 10093 boolean result = telephony.setCdmaRoamingMode(getSubId(), mode); 10094 if (!result) throw new IllegalStateException("radio is unavailable."); 10095 } else { 10096 throw new IllegalStateException("telephony service is null."); 10097 } 10098 } catch (RemoteException ex) { 10099 Log.e(TAG, "Error calling ITelephony#setCdmaRoamingMode", ex); 10100 ex.rethrowFromSystemServer(); 10101 } 10102 } 10103 10104 /** @hide */ 10105 @IntDef(prefix = { "CDMA_SUBSCRIPTION_" }, value = { 10106 CDMA_SUBSCRIPTION_UNKNOWN, 10107 CDMA_SUBSCRIPTION_RUIM_SIM, 10108 CDMA_SUBSCRIPTION_NV 10109 }) 10110 @Retention(RetentionPolicy.SOURCE) 10111 public @interface CdmaSubscription{} 10112 10113 /** 10114 * Used for CDMA subscription mode, it'll be UNKNOWN if there is no Subscription source. 10115 * @hide 10116 */ 10117 @SystemApi 10118 public static final int CDMA_SUBSCRIPTION_UNKNOWN = -1; 10119 10120 /** 10121 * Used for CDMA subscription mode: RUIM/SIM (default) 10122 * @hide 10123 */ 10124 @SystemApi 10125 public static final int CDMA_SUBSCRIPTION_RUIM_SIM = 0; 10126 10127 /** 10128 * Used for CDMA subscription mode: NV -> non-volatile memory 10129 * @hide 10130 */ 10131 @SystemApi 10132 public static final int CDMA_SUBSCRIPTION_NV = 1; 10133 10134 /** 10135 * Gets the subscription mode for CDMA phone. 10136 * 10137 * @return the CDMA subscription mode. 10138 * @throws SecurityException if the caller does not have the permission. 10139 * @throws IllegalStateException if the Telephony process or radio is not currently available. 10140 * 10141 * @see #CDMA_SUBSCRIPTION_UNKNOWN 10142 * @see #CDMA_SUBSCRIPTION_RUIM_SIM 10143 * @see #CDMA_SUBSCRIPTION_NV 10144 * 10145 * <p>Requires Permission: 10146 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 10147 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 10148 * 10149 * @hide 10150 */ 10151 @SystemApi 10152 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getCdmaSubscriptionMode()10153 public @CdmaSubscription int getCdmaSubscriptionMode() { 10154 int mode = CDMA_SUBSCRIPTION_RUIM_SIM; 10155 try { 10156 ITelephony telephony = getITelephony(); 10157 if (telephony != null) { 10158 mode = telephony.getCdmaSubscriptionMode(getSubId()); 10159 } else { 10160 throw new IllegalStateException("telephony service is null."); 10161 } 10162 } catch (RemoteException ex) { 10163 Log.e(TAG, "Error calling ITelephony#getCdmaSubscriptionMode", ex); 10164 ex.rethrowFromSystemServer(); 10165 } 10166 return mode; 10167 } 10168 10169 /** 10170 * Sets the subscription mode for CDMA phone to the given mode {@code mode}. If the phone is not 10171 * CDMA capable, this method throws an IllegalStateException. 10172 * 10173 * @param mode CDMA subscription mode. 10174 * @throws SecurityException if the caller does not have the permission. 10175 * @throws IllegalStateException if the Telephony process or radio is not currently available, 10176 * the device is not CDMA capable, or the request fails. 10177 * 10178 * @see #CDMA_SUBSCRIPTION_UNKNOWN 10179 * @see #CDMA_SUBSCRIPTION_RUIM_SIM 10180 * @see #CDMA_SUBSCRIPTION_NV 10181 * 10182 * <p>Requires Permission: 10183 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 10184 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 10185 * 10186 * @hide 10187 */ 10188 @SystemApi 10189 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setCdmaSubscriptionMode(@dmaSubscription int mode)10190 public void setCdmaSubscriptionMode(@CdmaSubscription int mode) { 10191 if (getPhoneType() != PHONE_TYPE_CDMA) { 10192 throw new IllegalStateException("Phone does not support CDMA."); 10193 } 10194 try { 10195 ITelephony telephony = getITelephony(); 10196 if (telephony != null) { 10197 boolean result = telephony.setCdmaSubscriptionMode(getSubId(), mode); 10198 if (!result) throw new IllegalStateException("radio is unavailable."); 10199 } else { 10200 throw new IllegalStateException("telephony service is null."); 10201 } 10202 } catch (RemoteException ex) { 10203 Log.e(TAG, "Error calling ITelephony#setCdmaSubscriptionMode", ex); 10204 ex.rethrowFromSystemServer(); 10205 } 10206 } 10207 10208 /** 10209 * Enables/Disables the data roaming on the subscription. 10210 * 10211 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 10212 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 10213 * 10214 * <p> Requires permission: 10215 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier 10216 * privileges (see {@link #hasCarrierPrivileges}). 10217 * 10218 * @param isEnabled {@code true} to enable mobile data roaming, otherwise disable it. 10219 * 10220 * @hide 10221 */ 10222 @SystemApi 10223 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataRoamingEnabled(boolean isEnabled)10224 public void setDataRoamingEnabled(boolean isEnabled) { 10225 try { 10226 ITelephony telephony = getITelephony(); 10227 if (telephony != null) { 10228 telephony.setDataRoamingEnabled( 10229 getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), isEnabled); 10230 } 10231 } catch (RemoteException e) { 10232 Log.e(TAG, "Error calling ITelephony#setDataRoamingEnabled", e); 10233 } 10234 } 10235 10236 /** 10237 * @deprecated use {@link #isDataEnabled()} instead. 10238 * @hide 10239 */ 10240 @Deprecated 10241 @SystemApi getDataEnabled(int subId)10242 public boolean getDataEnabled(int subId) { 10243 try { 10244 return isDataEnabledForReason(subId, DATA_ENABLED_REASON_USER); 10245 } catch (RuntimeException e) { 10246 Log.e(TAG, "Error calling isDataEnabledForReason e:" + e); 10247 } 10248 return false; 10249 } 10250 10251 /** 10252 * Returns the result and response from RIL for oem request 10253 * 10254 * @param oemReq the data is sent to ril. 10255 * @param oemResp the respose data from RIL. 10256 * @return negative value request was not handled or get error 10257 * 0 request was handled succesfully, but no response data 10258 * positive value success, data length of response 10259 * @hide 10260 * @deprecated OEM needs a vendor-extension hal and their apps should use that instead 10261 */ 10262 @Deprecated invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp)10263 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 10264 try { 10265 ITelephony telephony = getITelephony(); 10266 if (telephony != null) 10267 return telephony.invokeOemRilRequestRaw(oemReq, oemResp); 10268 } catch (RemoteException ex) { 10269 } catch (NullPointerException ex) { 10270 } 10271 return -1; 10272 } 10273 10274 /** 10275 * @deprecated Use {@link android.telephony.ims.ImsMmTelManager#setVtSettingEnabled(boolean)} 10276 * instead. 10277 * @hide 10278 */ 10279 @Deprecated 10280 @SystemApi 10281 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) enableVideoCalling(boolean enable)10282 public void enableVideoCalling(boolean enable) { 10283 try { 10284 ITelephony telephony = getITelephony(); 10285 if (telephony != null) 10286 telephony.enableVideoCalling(enable); 10287 } catch (RemoteException e) { 10288 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 10289 } 10290 } 10291 10292 /** 10293 * @deprecated Use {@link ImsMmTelManager#isVtSettingEnabled()} instead to check if the user 10294 * has enabled the Video Calling setting, {@link ImsMmTelManager#isAvailable(int, int)} to 10295 * determine if video calling is available, or {@link ImsMmTelManager#isCapable(int, int)} to 10296 * determine if video calling is capable. 10297 * @hide 10298 */ 10299 @Deprecated 10300 @SystemApi 10301 @RequiresPermission(anyOf = { 10302 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 10303 android.Manifest.permission.READ_PHONE_STATE 10304 }) isVideoCallingEnabled()10305 public boolean isVideoCallingEnabled() { 10306 try { 10307 ITelephony telephony = getITelephony(); 10308 if (telephony != null) 10309 return telephony.isVideoCallingEnabled(getOpPackageName(), getAttributionTag()); 10310 } catch (RemoteException e) { 10311 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 10312 } 10313 return false; 10314 } 10315 10316 /** 10317 * Whether the device supports configuring the DTMF tone length. 10318 * 10319 * @return {@code true} if the DTMF tone length can be changed, and {@code false} otherwise. 10320 */ canChangeDtmfToneLength()10321 public boolean canChangeDtmfToneLength() { 10322 try { 10323 ITelephony telephony = getITelephony(); 10324 if (telephony != null) { 10325 return telephony.canChangeDtmfToneLength(mSubId, getOpPackageName(), 10326 getAttributionTag()); 10327 } 10328 } catch (RemoteException e) { 10329 Log.e(TAG, "Error calling ITelephony#canChangeDtmfToneLength", e); 10330 } catch (SecurityException e) { 10331 Log.e(TAG, "Permission error calling ITelephony#canChangeDtmfToneLength", e); 10332 } 10333 return false; 10334 } 10335 10336 /** 10337 * Whether the device is a world phone. 10338 * 10339 * @return {@code true} if the device is a world phone, and {@code false} otherwise. 10340 */ isWorldPhone()10341 public boolean isWorldPhone() { 10342 try { 10343 ITelephony telephony = getITelephony(); 10344 if (telephony != null) { 10345 return telephony.isWorldPhone(mSubId, getOpPackageName(), getAttributionTag()); 10346 } 10347 } catch (RemoteException e) { 10348 Log.e(TAG, "Error calling ITelephony#isWorldPhone", e); 10349 } catch (SecurityException e) { 10350 Log.e(TAG, "Permission error calling ITelephony#isWorldPhone", e); 10351 } 10352 return false; 10353 } 10354 10355 /** 10356 * @deprecated Use {@link TelecomManager#isTtySupported()} instead 10357 * Whether the phone supports TTY mode. 10358 * 10359 * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. 10360 * 10361 */ 10362 @Deprecated isTtyModeSupported()10363 public boolean isTtyModeSupported() { 10364 try { 10365 TelecomManager telecomManager = null; 10366 if (mContext != null) { 10367 telecomManager = mContext.getSystemService(TelecomManager.class); 10368 } 10369 if (telecomManager != null) { 10370 return telecomManager.isTtySupported(); 10371 } 10372 } catch (SecurityException e) { 10373 Log.e(TAG, "Permission error calling TelecomManager#isTtySupported", e); 10374 } 10375 return false; 10376 } 10377 10378 /** 10379 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier 10380 * support for the feature and device firmware support. 10381 * 10382 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. 10383 */ isRttSupported()10384 public boolean isRttSupported() { 10385 try { 10386 ITelephony telephony = getITelephony(); 10387 if (telephony != null) { 10388 return telephony.isRttSupported(mSubId); 10389 } 10390 } catch (RemoteException e) { 10391 Log.e(TAG, "Error calling ITelephony#isRttSupported", e); 10392 } catch (SecurityException e) { 10393 Log.e(TAG, "Permission error calling ITelephony#isWorldPhone", e); 10394 } 10395 return false; 10396 } 10397 /** 10398 * Whether the phone supports hearing aid compatibility. 10399 * 10400 * @return {@code true} if the device supports hearing aid compatibility, and {@code false} 10401 * otherwise. 10402 */ isHearingAidCompatibilitySupported()10403 public boolean isHearingAidCompatibilitySupported() { 10404 try { 10405 ITelephony telephony = getITelephony(); 10406 if (telephony != null) { 10407 return telephony.isHearingAidCompatibilitySupported(); 10408 } 10409 } catch (RemoteException e) { 10410 Log.e(TAG, "Error calling ITelephony#isHearingAidCompatibilitySupported", e); 10411 } catch (SecurityException e) { 10412 Log.e(TAG, "Permission error calling ITelephony#isHearingAidCompatibilitySupported", e); 10413 } 10414 return false; 10415 } 10416 10417 /** 10418 * Returns the IMS Registration Status for a particular Subscription ID. 10419 * 10420 * @param subId Subscription ID 10421 * @return true if IMS status is registered, false if the IMS status is not registered or a 10422 * RemoteException occurred. 10423 * Use {@link ImsMmTelManager.RegistrationCallback} instead. 10424 * @hide 10425 */ isImsRegistered(int subId)10426 public boolean isImsRegistered(int subId) { 10427 try { 10428 return getITelephony().isImsRegistered(subId); 10429 } catch (RemoteException | NullPointerException ex) { 10430 return false; 10431 } 10432 } 10433 10434 /** 10435 * Returns the IMS Registration Status for a particular Subscription ID, which is determined 10436 * when the TelephonyManager is created using {@link #createForSubscriptionId(int)}. If an 10437 * invalid subscription ID is used during creation, will the default subscription ID will be 10438 * used. 10439 * 10440 * @return true if IMS status is registered, false if the IMS status is not registered or a 10441 * RemoteException occurred. 10442 * @see SubscriptionManager#getDefaultSubscriptionId() 10443 * @hide 10444 */ 10445 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) isImsRegistered()10446 public boolean isImsRegistered() { 10447 try { 10448 return getITelephony().isImsRegistered(getSubId()); 10449 } catch (RemoteException | NullPointerException ex) { 10450 return false; 10451 } 10452 } 10453 10454 /** 10455 * The current status of Voice over LTE for the subscription associated with this instance when 10456 * it was created using {@link #createForSubscriptionId(int)}. If an invalid subscription ID was 10457 * used during creation, the default subscription ID will be used. 10458 * @return true if Voice over LTE is available or false if it is unavailable or unknown. 10459 * @see SubscriptionManager#getDefaultSubscriptionId() 10460 * <p> 10461 * Use {@link ImsMmTelManager#isAvailable(int, int)} instead. 10462 * @hide 10463 */ 10464 @UnsupportedAppUsage isVolteAvailable()10465 public boolean isVolteAvailable() { 10466 try { 10467 return getITelephony().isAvailable(getSubId(), 10468 MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE, 10469 ImsRegistrationImplBase.REGISTRATION_TECH_LTE); 10470 } catch (RemoteException | NullPointerException ex) { 10471 return false; 10472 } 10473 } 10474 10475 /** 10476 * The availability of Video Telephony (VT) for the subscription ID specified when this instance 10477 * was created using {@link #createForSubscriptionId(int)}. If an invalid subscription ID was 10478 * used during creation, the default subscription ID will be used. To query the 10479 * underlying technology that VT is available on, use {@link #getImsRegTechnologyForMmTel}. 10480 * @return true if VT is available, or false if it is unavailable or unknown. 10481 * Use {@link ImsMmTelManager#isAvailable(int, int)} instead. 10482 * @hide 10483 */ 10484 @UnsupportedAppUsage isVideoTelephonyAvailable()10485 public boolean isVideoTelephonyAvailable() { 10486 try { 10487 return getITelephony().isVideoTelephonyAvailable(getSubId()); 10488 } catch (RemoteException | NullPointerException ex) { 10489 return false; 10490 } 10491 } 10492 10493 /** 10494 * Returns the Status of Wi-Fi calling (Voice over WiFi) for the subscription ID specified. 10495 * @param subId the subscription ID. 10496 * @return true if VoWiFi is available, or false if it is unavailable or unknown. 10497 * Use {@link ImsMmTelManager#isAvailable(int, int)} instead. 10498 * @hide 10499 */ 10500 @UnsupportedAppUsage isWifiCallingAvailable()10501 public boolean isWifiCallingAvailable() { 10502 try { 10503 return getITelephony().isWifiCallingAvailable(getSubId()); 10504 } catch (RemoteException | NullPointerException ex) { 10505 return false; 10506 } 10507 } 10508 10509 /** 10510 * The technology that IMS is registered for for the MMTEL feature. 10511 * @param subId subscription ID to get IMS registration technology for. 10512 * @return The IMS registration technology that IMS is registered to for the MMTEL feature. 10513 * Valid return results are: 10514 * - {@link ImsRegistrationImplBase#REGISTRATION_TECH_LTE} for LTE registration, 10515 * - {@link ImsRegistrationImplBase#REGISTRATION_TECH_IWLAN} for IWLAN registration, or 10516 * - {@link ImsRegistrationImplBase#REGISTRATION_TECH_CROSS_SIM} for registration over 10517 * other sim's internet, or 10518 * - {@link ImsRegistrationImplBase#REGISTRATION_TECH_NONE} if we are not registered or the 10519 * result is unavailable. 10520 * Use {@link ImsMmTelManager.RegistrationCallback} instead. 10521 * @hide 10522 */ getImsRegTechnologyForMmTel()10523 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel() { 10524 try { 10525 return getITelephony().getImsRegTechnologyForMmTel(getSubId()); 10526 } catch (RemoteException ex) { 10527 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; 10528 } 10529 } 10530 10531 /** 10532 * Set TelephonyProperties.icc_operator_numeric for the default phone. 10533 * 10534 * @hide 10535 */ setSimOperatorNumeric(String numeric)10536 public void setSimOperatorNumeric(String numeric) { 10537 int phoneId = getPhoneId(); 10538 setSimOperatorNumericForPhone(phoneId, numeric); 10539 } 10540 10541 /** 10542 * Set TelephonyProperties.icc_operator_numeric for the given phone. 10543 * 10544 * @hide 10545 */ 10546 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setSimOperatorNumericForPhone(int phoneId, String numeric)10547 public void setSimOperatorNumericForPhone(int phoneId, String numeric) { 10548 if (SubscriptionManager.isValidPhoneId(phoneId)) { 10549 List<String> newList = updateTelephonyProperty( 10550 TelephonyProperties.icc_operator_numeric(), phoneId, numeric); 10551 TelephonyProperties.icc_operator_numeric(newList); 10552 } 10553 } 10554 10555 /** 10556 * Set TelephonyProperties.icc_operator_alpha for the default phone. 10557 * 10558 * @hide 10559 */ setSimOperatorName(String name)10560 public void setSimOperatorName(String name) { 10561 int phoneId = getPhoneId(); 10562 setSimOperatorNameForPhone(phoneId, name); 10563 } 10564 10565 /** 10566 * Set TelephonyProperties.icc_operator_alpha for the given phone. 10567 * 10568 * @hide 10569 */ 10570 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setSimOperatorNameForPhone(int phoneId, String name)10571 public void setSimOperatorNameForPhone(int phoneId, String name) { 10572 if (SubscriptionManager.isValidPhoneId(phoneId)) { 10573 List<String> newList = updateTelephonyProperty( 10574 TelephonyProperties.icc_operator_alpha(), phoneId, name); 10575 TelephonyProperties.icc_operator_alpha(newList); 10576 } 10577 } 10578 10579 /** 10580 * Set TelephonyProperties.icc_operator_iso_country for the default phone. 10581 * 10582 * @hide 10583 */ setSimCountryIso(String iso)10584 public void setSimCountryIso(String iso) { 10585 int phoneId = getPhoneId(); 10586 setSimCountryIsoForPhone(phoneId, iso); 10587 } 10588 10589 /** 10590 * Set TelephonyProperties.icc_operator_iso_country for the given phone. 10591 * 10592 * @hide 10593 */ 10594 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setSimCountryIsoForPhone(int phoneId, String iso)10595 public void setSimCountryIsoForPhone(int phoneId, String iso) { 10596 if (SubscriptionManager.isValidPhoneId(phoneId)) { 10597 List<String> newList = updateTelephonyProperty( 10598 TelephonyProperties.icc_operator_iso_country(), phoneId, iso); 10599 TelephonyProperties.icc_operator_iso_country(newList); 10600 } 10601 } 10602 10603 /** 10604 * Set TelephonyProperties.sim_state for the default phone. 10605 * 10606 * @hide 10607 */ setSimState(String state)10608 public void setSimState(String state) { 10609 int phoneId = getPhoneId(); 10610 setSimStateForPhone(phoneId, state); 10611 } 10612 10613 /** 10614 * Set TelephonyProperties.sim_state for the given phone. 10615 * 10616 * @hide 10617 */ 10618 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setSimStateForPhone(int phoneId, String state)10619 public void setSimStateForPhone(int phoneId, String state) { 10620 if (SubscriptionManager.isValidPhoneId(phoneId)) { 10621 List<String> newList = updateTelephonyProperty( 10622 TelephonyProperties.sim_state(), phoneId, state); 10623 TelephonyProperties.sim_state(newList); 10624 } 10625 } 10626 10627 /** 10628 * Powers down the SIM. SIM must be up prior. 10629 * @hide 10630 */ 10631 public static final int CARD_POWER_DOWN = 0; 10632 10633 /** 10634 * Powers up the SIM normally. SIM must be down prior. 10635 * @hide 10636 */ 10637 public static final int CARD_POWER_UP = 1; 10638 10639 /** 10640 * Powers up the SIM in PASS_THROUGH mode. SIM must be down prior. 10641 * When SIM is powered up in PASS_THOUGH mode, the modem does not send 10642 * any command to it (for example SELECT of MF, or TERMINAL CAPABILITY), 10643 * and the SIM card is controlled completely by Telephony sending APDUs 10644 * directly. The SIM card state will be RIL_CARDSTATE_PRESENT and the 10645 * number of card apps will be 0. 10646 * No new error code is generated. Emergency calls are supported in the 10647 * same way as if the SIM card is absent. 10648 * The PASS_THROUGH mode is valid only for the specific card session where it 10649 * is activated, and normal behavior occurs at the next SIM initialization, 10650 * unless PASS_THROUGH mode is requested again. Hence, the last power-up mode 10651 * is NOT persistent across boots. On reboot, SIM will power up normally. 10652 * @hide 10653 */ 10654 public static final int CARD_POWER_UP_PASS_THROUGH = 2; 10655 10656 /** @hide */ 10657 @Retention(RetentionPolicy.SOURCE) 10658 @IntDef(prefix = {"CARD_POWER"}, 10659 value = { 10660 CARD_POWER_DOWN, 10661 CARD_POWER_UP, 10662 CARD_POWER_UP_PASS_THROUGH, 10663 }) 10664 public @interface SimPowerState {} 10665 10666 /** 10667 * Set SIM card power state. 10668 * 10669 * @param state State of SIM (power down, power up, pass through) 10670 * @see #CARD_POWER_DOWN 10671 * @see #CARD_POWER_UP 10672 * @see #CARD_POWER_UP_PASS_THROUGH 10673 * Callers should monitor for {@link TelephonyIntents#ACTION_SIM_STATE_CHANGED} 10674 * broadcasts to determine success or failure and timeout if needed. 10675 * 10676 * @deprecated prefer {@link setSimPowerState(int, Executor, Consumer<Integer>)}. 10677 * There is no guarantee that SIM power changes will trigger ACTION_SIM_STATE_CHANGED on new 10678 * devices. 10679 * 10680 * <p>Requires Permission: 10681 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 10682 * 10683 * {@hide} 10684 **/ 10685 @SystemApi 10686 @Deprecated 10687 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setSimPowerState(int state)10688 public void setSimPowerState(int state) { 10689 setSimPowerStateForSlot(getSlotIndex(), state); 10690 } 10691 10692 /** 10693 * Set SIM card power state. 10694 * 10695 * @param slotIndex SIM slot id 10696 * @param state State of SIM (power down, power up, pass through) 10697 * @see #CARD_POWER_DOWN 10698 * @see #CARD_POWER_UP 10699 * @see #CARD_POWER_UP_PASS_THROUGH 10700 * Callers should monitor for {@link TelephonyIntents#ACTION_SIM_STATE_CHANGED} 10701 * broadcasts to determine success or failure and timeout if needed. 10702 * 10703 * @deprecated prefer {@link setSimPowerStateForSlot(int, int, Executor, Consumer<Integer>)}. 10704 * changes will trigger ACTION_SIM_STATE_CHANGED on new devices. 10705 * 10706 * <p>Requires Permission: 10707 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 10708 * 10709 * {@hide} 10710 **/ 10711 @SystemApi 10712 @Deprecated 10713 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setSimPowerStateForSlot(int slotIndex, int state)10714 public void setSimPowerStateForSlot(int slotIndex, int state) { 10715 try { 10716 ITelephony telephony = getITelephony(); 10717 if (telephony != null) { 10718 telephony.setSimPowerStateForSlot(slotIndex, state); 10719 } 10720 } catch (RemoteException e) { 10721 Log.e(TAG, "Error calling ITelephony#setSimPowerStateForSlot", e); 10722 } catch (SecurityException e) { 10723 Log.e(TAG, "Permission error calling ITelephony#setSimPowerStateForSlot", e); 10724 } 10725 } 10726 10727 /** 10728 * Set SIM card power state. 10729 * 10730 * @param state State of SIM (power down, power up, pass through) 10731 * @see #CARD_POWER_DOWN 10732 * @see #CARD_POWER_UP 10733 * @see #CARD_POWER_UP_PASS_THROUGH 10734 * @param executor The executor of where the callback will execute. 10735 * @param callback Callback will be triggered once it succeeds or failed. 10736 * @see #SET_SIM_POWER_STATE_SUCCESS 10737 * @see #SET_SIM_POWER_STATE_ALREADY_IN_STATE 10738 * @see #SET_SIM_POWER_STATE_MODEM_ERROR 10739 * @see #SET_SIM_POWER_STATE_SIM_ERROR 10740 * @see #SET_SIM_POWER_STATE_NOT_SUPPORTED 10741 * @throws IllegalArgumentException if requested SIM state is invalid 10742 * 10743 * <p>Requires Permission: 10744 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 10745 * 10746 * {@hide} 10747 **/ 10748 @SystemApi 10749 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setSimPowerState(@imPowerState int state, @NonNull Executor executor, @NonNull @SetSimPowerStateResult Consumer<Integer> callback)10750 public void setSimPowerState(@SimPowerState int state, @NonNull Executor executor, 10751 @NonNull @SetSimPowerStateResult Consumer<Integer> callback) { 10752 setSimPowerStateForSlot(getSlotIndex(), state, executor, callback); 10753 } 10754 10755 /** 10756 * Set SIM card power state. 10757 * 10758 * @param slotIndex SIM slot id 10759 * @param state State of SIM (power down, power up, pass through) 10760 * @see #CARD_POWER_DOWN 10761 * @see #CARD_POWER_UP 10762 * @see #CARD_POWER_UP_PASS_THROUGH 10763 * @param executor The executor of where the callback will execute. 10764 * @param callback Callback will be triggered once it succeeds or failed. 10765 * @see #SET_SIM_POWER_STATE_SUCCESS 10766 * @see #SET_SIM_POWER_STATE_ALREADY_IN_STATE 10767 * @see #SET_SIM_POWER_STATE_MODEM_ERROR 10768 * @see #SET_SIM_POWER_STATE_SIM_ERROR 10769 * @see #SET_SIM_POWER_STATE_NOT_SUPPORTED 10770 * @throws IllegalArgumentException if requested SIM state is invalid 10771 * 10772 * <p>Requires Permission: 10773 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 10774 * 10775 * {@hide} 10776 **/ 10777 @SystemApi 10778 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setSimPowerStateForSlot(int slotIndex, @SimPowerState int state, @NonNull Executor executor, @NonNull @SetSimPowerStateResult Consumer<Integer> callback)10779 public void setSimPowerStateForSlot(int slotIndex, @SimPowerState int state, 10780 @NonNull Executor executor, 10781 @NonNull @SetSimPowerStateResult Consumer<Integer> callback) { 10782 if (state != CARD_POWER_DOWN && state != CARD_POWER_UP 10783 && state != CARD_POWER_UP_PASS_THROUGH) { 10784 throw new IllegalArgumentException("requested SIM state is invalid"); 10785 } 10786 try { 10787 ITelephony telephony = getITelephony(); 10788 if (telephony == null) throw new IllegalStateException("Telephony is null."); 10789 10790 IIntegerConsumer internalCallback = new IIntegerConsumer.Stub() { 10791 @Override 10792 public void accept(int result) { 10793 executor.execute(() -> 10794 Binder.withCleanCallingIdentity(() -> callback.accept(result))); 10795 } 10796 }; 10797 if (telephony == null) { 10798 if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) { 10799 throw new IllegalStateException("Telephony is null"); 10800 } else { 10801 return; 10802 } 10803 } 10804 telephony.setSimPowerStateForSlotWithCallback(slotIndex, state, internalCallback); 10805 } catch (RemoteException e) { 10806 Log.e(TAG, "Error calling ITelephony#setSimPowerStateForSlot", e); 10807 runOnBackgroundThread(() -> executor.execute( 10808 () -> callback.accept(SET_SIM_POWER_STATE_MODEM_ERROR))); 10809 } catch (SecurityException e) { 10810 Log.e(TAG, "Permission error calling ITelephony#setSimPowerStateForSlot", 10811 e); 10812 } 10813 } 10814 10815 /** 10816 * Set baseband version for the default phone. 10817 * 10818 * @param version baseband version 10819 * @hide 10820 */ setBasebandVersion(String version)10821 public void setBasebandVersion(String version) { 10822 int phoneId = getPhoneId(); 10823 setBasebandVersionForPhone(phoneId, version); 10824 } 10825 10826 /** 10827 * Set baseband version by phone id. 10828 * 10829 * @param phoneId for which baseband version is set 10830 * @param version baseband version 10831 * @hide 10832 */ 10833 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setBasebandVersionForPhone(int phoneId, String version)10834 public void setBasebandVersionForPhone(int phoneId, String version) { 10835 if (SubscriptionManager.isValidPhoneId(phoneId)) { 10836 List<String> newList = updateTelephonyProperty( 10837 TelephonyProperties.baseband_version(), phoneId, version); 10838 TelephonyProperties.baseband_version(newList); 10839 } 10840 } 10841 10842 /** 10843 * Get baseband version for the default phone. 10844 * 10845 * @return baseband version. 10846 * @hide 10847 */ getBasebandVersion()10848 public String getBasebandVersion() { 10849 int phoneId = getPhoneId(); 10850 return getBasebandVersionForPhone(phoneId); 10851 } 10852 10853 /** 10854 * Get baseband version by phone id. 10855 * 10856 * @return baseband version. 10857 * @hide 10858 */ getBasebandVersionForPhone(int phoneId)10859 public String getBasebandVersionForPhone(int phoneId) { 10860 return getTelephonyProperty(phoneId, TelephonyProperties.baseband_version(), ""); 10861 } 10862 10863 /** 10864 * Set phone type for the default phone. 10865 * 10866 * @param type phone type 10867 * 10868 * @hide 10869 */ setPhoneType(int type)10870 public void setPhoneType(int type) { 10871 int phoneId = getPhoneId(); 10872 setPhoneType(phoneId, type); 10873 } 10874 10875 /** 10876 * Set phone type by phone id. 10877 * 10878 * @param phoneId for which phone type is set 10879 * @param type phone type 10880 * 10881 * @hide 10882 */ 10883 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setPhoneType(int phoneId, int type)10884 public void setPhoneType(int phoneId, int type) { 10885 if (SubscriptionManager.isValidPhoneId(phoneId)) { 10886 List<Integer> newList = updateTelephonyProperty( 10887 TelephonyProperties.current_active_phone(), phoneId, type); 10888 TelephonyProperties.current_active_phone(newList); 10889 } 10890 } 10891 10892 /** 10893 * Get OTASP number schema for the default phone. 10894 * 10895 * @param defaultValue default value 10896 * @return OTA SP number schema 10897 * 10898 * @hide 10899 */ getOtaSpNumberSchema(String defaultValue)10900 public String getOtaSpNumberSchema(String defaultValue) { 10901 int phoneId = getPhoneId(); 10902 return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); 10903 } 10904 10905 /** 10906 * Get OTASP number schema by phone id. 10907 * 10908 * @param phoneId for which OTA SP number schema is get 10909 * @param defaultValue default value 10910 * @return OTA SP number schema 10911 * 10912 * @hide 10913 */ 10914 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue)10915 public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) { 10916 if (SubscriptionManager.isValidPhoneId(phoneId)) { 10917 return getTelephonyProperty( 10918 phoneId, TelephonyProperties.otasp_num_schema(), defaultValue); 10919 } 10920 10921 return defaultValue; 10922 } 10923 10924 /** 10925 * Get SMS receive capable from system property for the default phone. 10926 * 10927 * @param defaultValue default value 10928 * @return SMS receive capable 10929 * 10930 * @hide 10931 */ getSmsReceiveCapable(boolean defaultValue)10932 public boolean getSmsReceiveCapable(boolean defaultValue) { 10933 int phoneId = getPhoneId(); 10934 return getSmsReceiveCapableForPhone(phoneId, defaultValue); 10935 } 10936 10937 /** 10938 * Get SMS receive capable from system property by phone id. 10939 * 10940 * @param phoneId for which SMS receive capable is get 10941 * @param defaultValue default value 10942 * @return SMS receive capable 10943 * 10944 * @hide 10945 */ getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue)10946 public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) { 10947 if (SubscriptionManager.isValidPhoneId(phoneId)) { 10948 return getTelephonyProperty(phoneId, TelephonyProperties.sms_receive(), defaultValue); 10949 } 10950 10951 return defaultValue; 10952 } 10953 10954 /** 10955 * Get SMS send capable from system property for the default phone. 10956 * 10957 * @param defaultValue default value 10958 * @return SMS send capable 10959 * 10960 * @hide 10961 */ getSmsSendCapable(boolean defaultValue)10962 public boolean getSmsSendCapable(boolean defaultValue) { 10963 int phoneId = getPhoneId(); 10964 return getSmsSendCapableForPhone(phoneId, defaultValue); 10965 } 10966 10967 /** 10968 * Get SMS send capable from system property by phone id. 10969 * 10970 * @param phoneId for which SMS send capable is get 10971 * @param defaultValue default value 10972 * @return SMS send capable 10973 * 10974 * @hide 10975 */ getSmsSendCapableForPhone(int phoneId, boolean defaultValue)10976 public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) { 10977 if (SubscriptionManager.isValidPhoneId(phoneId)) { 10978 return getTelephonyProperty(phoneId, TelephonyProperties.sms_send(), defaultValue); 10979 } 10980 10981 return defaultValue; 10982 } 10983 10984 /** 10985 * Gets the default Respond Via Message application, updating the cache if there is no 10986 * respond-via-message application currently configured. 10987 * @return component name of the app and class to direct Respond Via Message intent to, or 10988 * {@code null} if the functionality is not supported. 10989 * @hide 10990 */ 10991 @SystemApi 10992 @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS) getAndUpdateDefaultRespondViaMessageApplication()10993 public @Nullable ComponentName getAndUpdateDefaultRespondViaMessageApplication() { 10994 return SmsApplication.getDefaultRespondViaMessageApplication(mContext, true); 10995 } 10996 10997 /** 10998 * Gets the default Respond Via Message application. 10999 * @return component name of the app and class to direct Respond Via Message intent to, or 11000 * {@code null} if the functionality is not supported. 11001 * @hide 11002 */ 11003 @SystemApi 11004 @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS) getDefaultRespondViaMessageApplication()11005 public @Nullable ComponentName getDefaultRespondViaMessageApplication() { 11006 return SmsApplication.getDefaultRespondViaMessageApplication(mContext, false); 11007 } 11008 11009 /** 11010 * Set the alphabetic name of current registered operator. 11011 * @param name the alphabetic name of current registered operator. 11012 * @hide 11013 */ setNetworkOperatorName(String name)11014 public void setNetworkOperatorName(String name) { 11015 int phoneId = getPhoneId(); 11016 setNetworkOperatorNameForPhone(phoneId, name); 11017 } 11018 11019 /** 11020 * Set the alphabetic name of current registered operator. 11021 * @param phoneId which phone you want to set 11022 * @param name the alphabetic name of current registered operator. 11023 * @hide 11024 */ 11025 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setNetworkOperatorNameForPhone(int phoneId, String name)11026 public void setNetworkOperatorNameForPhone(int phoneId, String name) { 11027 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11028 List<String> newList = updateTelephonyProperty( 11029 TelephonyProperties.operator_alpha(), phoneId, name); 11030 TelephonyProperties.operator_alpha(newList); 11031 } 11032 } 11033 11034 /** 11035 * Set the numeric name (MCC+MNC) of current registered operator. 11036 * @param operator the numeric name (MCC+MNC) of current registered operator 11037 * @hide 11038 */ setNetworkOperatorNumeric(String numeric)11039 public void setNetworkOperatorNumeric(String numeric) { 11040 int phoneId = getPhoneId(); 11041 setNetworkOperatorNumericForPhone(phoneId, numeric); 11042 } 11043 11044 /** 11045 * Set the numeric name (MCC+MNC) of current registered operator. 11046 * @param phoneId for which phone type is set 11047 * @param operator the numeric name (MCC+MNC) of current registered operator 11048 * @hide 11049 */ 11050 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setNetworkOperatorNumericForPhone(int phoneId, String numeric)11051 public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) { 11052 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11053 List<String> newList = updateTelephonyProperty( 11054 TelephonyProperties.operator_numeric(), phoneId, numeric); 11055 TelephonyProperties.operator_numeric(newList); 11056 } 11057 } 11058 11059 /** 11060 * Set roaming state of the current network, for GSM purposes. 11061 * @param isRoaming is network in romaing state or not 11062 * @hide 11063 */ setNetworkRoaming(boolean isRoaming)11064 public void setNetworkRoaming(boolean isRoaming) { 11065 int phoneId = getPhoneId(); 11066 setNetworkRoamingForPhone(phoneId, isRoaming); 11067 } 11068 11069 /** 11070 * Set roaming state of the current network, for GSM purposes. 11071 * @param phoneId which phone you want to set 11072 * @param isRoaming is network in romaing state or not 11073 * @hide 11074 */ 11075 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setNetworkRoamingForPhone(int phoneId, boolean isRoaming)11076 public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) { 11077 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11078 List<Boolean> newList = updateTelephonyProperty( 11079 TelephonyProperties.operator_is_roaming(), phoneId, isRoaming); 11080 TelephonyProperties.operator_is_roaming(newList); 11081 } 11082 } 11083 11084 /** 11085 * Set the network type currently in use on the device for data transmission. 11086 * 11087 * If this object has been created with {@link #createForSubscriptionId}, applies to the 11088 * phoneId associated with the given subId. Otherwise, applies to the phoneId associated with 11089 * {@link SubscriptionManager#getDefaultDataSubscriptionId()} 11090 * @param type the network type currently in use on the device for data transmission 11091 * @hide 11092 */ setDataNetworkType(int type)11093 public void setDataNetworkType(int type) { 11094 int phoneId = getPhoneId(SubscriptionManager.getDefaultDataSubscriptionId()); 11095 setDataNetworkTypeForPhone(phoneId, type); 11096 } 11097 11098 /** 11099 * Set the network type currently in use on the device for data transmission. 11100 * @param phoneId which phone you want to set 11101 * @param type the network type currently in use on the device for data transmission 11102 * @hide 11103 */ 11104 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setDataNetworkTypeForPhone(int phoneId, int type)11105 public void setDataNetworkTypeForPhone(int phoneId, int type) { 11106 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11107 List<String> newList = updateTelephonyProperty( 11108 TelephonyProperties.data_network_type(), phoneId, 11109 ServiceState.rilRadioTechnologyToString(type)); 11110 TelephonyProperties.data_network_type(newList); 11111 } 11112 } 11113 11114 /** 11115 * Returns the subscription ID for the given phone account. 11116 * @hide 11117 */ 11118 @UnsupportedAppUsage getSubIdForPhoneAccount(@ullable PhoneAccount phoneAccount)11119 public int getSubIdForPhoneAccount(@Nullable PhoneAccount phoneAccount) { 11120 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 11121 try { 11122 ITelephony service = getITelephony(); 11123 if (service != null) { 11124 retval = service.getSubIdForPhoneAccount(phoneAccount); 11125 } 11126 } catch (RemoteException e) { 11127 } 11128 11129 return retval; 11130 } 11131 11132 /** 11133 * Determines the {@link PhoneAccountHandle} associated with this TelephonyManager. 11134 * 11135 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 11136 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 11137 * 11138 * <p>Requires Permission android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE or that the 11139 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}) 11140 * 11141 * @return The {@link PhoneAccountHandle} associated with the TelphonyManager, or {@code null} 11142 * if there is no associated {@link PhoneAccountHandle}; this can happen if the subscription is 11143 * data-only or an opportunistic subscription. 11144 */ 11145 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 11146 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getPhoneAccountHandle()11147 public @Nullable PhoneAccountHandle getPhoneAccountHandle() { 11148 return getPhoneAccountHandleForSubscriptionId(getSubId()); 11149 } 11150 11151 /** 11152 * Determines the {@link PhoneAccountHandle} associated with a subscription Id. 11153 * 11154 * @param subscriptionId The subscription Id to check. 11155 * @return The {@link PhoneAccountHandle} associated with a subscription Id, or {@code null} if 11156 * there is no associated {@link PhoneAccountHandle}. 11157 * @hide 11158 */ getPhoneAccountHandleForSubscriptionId(int subscriptionId)11159 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { 11160 PhoneAccountHandle returnValue = null; 11161 try { 11162 ITelephony service = getITelephony(); 11163 if (service != null) { 11164 returnValue = service.getPhoneAccountHandleForSubscriptionId(subscriptionId); 11165 } 11166 } catch (RemoteException e) { 11167 } 11168 11169 return returnValue; 11170 } 11171 11172 /** 11173 * Returns the subscription ID for the given phone account handle. 11174 * 11175 * @param phoneAccountHandle the phone account handle for outgoing calls 11176 * @return subscription ID for the given phone account handle; or 11177 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} 11178 * if not available; or throw a SecurityException if the caller doesn't have the 11179 * permission. 11180 */ 11181 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getSubscriptionId(@onNull PhoneAccountHandle phoneAccountHandle)11182 public int getSubscriptionId(@NonNull PhoneAccountHandle phoneAccountHandle) { 11183 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 11184 try { 11185 ITelephony service = getITelephony(); 11186 if (service != null) { 11187 retval = service.getSubIdForPhoneAccountHandle( 11188 phoneAccountHandle, mContext.getOpPackageName(), 11189 mContext.getAttributionTag()); 11190 } 11191 } catch (RemoteException ex) { 11192 Log.e(TAG, "getSubscriptionId RemoteException", ex); 11193 ex.rethrowAsRuntimeException(); 11194 } 11195 return retval; 11196 } 11197 11198 /** 11199 * Resets telephony manager settings back to factory defaults. 11200 * 11201 * @hide 11202 */ factoryReset(int subId)11203 public void factoryReset(int subId) { 11204 try { 11205 Log.d(TAG, "factoryReset: subId=" + subId); 11206 ITelephony telephony = getITelephony(); 11207 if (telephony != null) { 11208 telephony.factoryReset(subId); 11209 } 11210 } catch (RemoteException e) { 11211 } 11212 } 11213 11214 11215 /** 11216 * Resets Telephony and IMS settings back to factory defaults only for the subscription 11217 * associated with this instance. 11218 * @see #createForSubscriptionId(int) 11219 * @hide 11220 */ 11221 @SystemApi 11222 @RequiresPermission(Manifest.permission.CONNECTIVITY_INTERNAL) resetSettings()11223 public void resetSettings() { 11224 try { 11225 Log.d(TAG, "resetSettings: subId=" + getSubId()); 11226 ITelephony telephony = getITelephony(); 11227 if (telephony != null) { 11228 telephony.factoryReset(getSubId()); 11229 } 11230 } catch (RemoteException e) { 11231 } 11232 } 11233 11234 11235 /** 11236 * Returns a locale based on the country and language from the SIM. Returns {@code null} if 11237 * no locale could be derived from subscriptions. 11238 * 11239 * <p>Requires Permission: 11240 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 11241 * 11242 * @see Locale#toLanguageTag() 11243 * 11244 * @hide 11245 */ 11246 @SystemApi 11247 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getSimLocale()11248 @Nullable public Locale getSimLocale() { 11249 try { 11250 final ITelephony telephony = getITelephony(); 11251 if (telephony != null) { 11252 String languageTag = telephony.getSimLocaleForSubscriber(getSubId()); 11253 if (!TextUtils.isEmpty(languageTag)) { 11254 return Locale.forLanguageTag(languageTag); 11255 } 11256 } 11257 } catch (RemoteException ex) { 11258 } 11259 return null; 11260 } 11261 11262 /** 11263 * TODO delete after SuW migrates to new API. 11264 * @hide 11265 */ getLocaleFromDefaultSim()11266 public String getLocaleFromDefaultSim() { 11267 try { 11268 final ITelephony telephony = getITelephony(); 11269 if (telephony != null) { 11270 return telephony.getSimLocaleForSubscriber(getSubId()); 11271 } 11272 } catch (RemoteException ex) { 11273 } 11274 return null; 11275 } 11276 11277 /** 11278 * Exception that may be supplied to the callback provided in {@link #requestModemActivityInfo}. 11279 * @hide 11280 */ 11281 @SystemApi 11282 public static class ModemActivityInfoException extends Exception { 11283 /** Indicates that an unknown error occurred */ 11284 public static final int ERROR_UNKNOWN = 0; 11285 11286 /** 11287 * Indicates that the modem or phone processes are not available (such as when the device 11288 * is in airplane mode). 11289 */ 11290 public static final int ERROR_PHONE_NOT_AVAILABLE = 1; 11291 11292 /** 11293 * Indicates that the modem supplied an invalid instance of {@link ModemActivityInfo} 11294 */ 11295 public static final int ERROR_INVALID_INFO_RECEIVED = 2; 11296 11297 /** 11298 * Indicates that the modem encountered an internal failure when processing the request 11299 * for activity info. 11300 */ 11301 public static final int ERROR_MODEM_RESPONSE_ERROR = 3; 11302 11303 /** @hide */ 11304 @Retention(RetentionPolicy.SOURCE) 11305 @IntDef(prefix = {"ERROR_"}, 11306 value = { 11307 ERROR_UNKNOWN, 11308 ERROR_PHONE_NOT_AVAILABLE, 11309 ERROR_INVALID_INFO_RECEIVED, 11310 ERROR_MODEM_RESPONSE_ERROR, 11311 }) 11312 public @interface ModemActivityInfoError {} 11313 11314 private final int mErrorCode; 11315 11316 /** @hide */ ModemActivityInfoException(@odemActivityInfoError int errorCode)11317 public ModemActivityInfoException(@ModemActivityInfoError int errorCode) { 11318 mErrorCode = errorCode; 11319 } 11320 getErrorCode()11321 public @ModemActivityInfoError int getErrorCode() { 11322 return mErrorCode; 11323 } 11324 11325 @Override toString()11326 public String toString() { 11327 switch (mErrorCode) { 11328 case ERROR_UNKNOWN: return "ERROR_UNKNOWN"; 11329 case ERROR_PHONE_NOT_AVAILABLE: return "ERROR_PHONE_NOT_AVAILABLE"; 11330 case ERROR_INVALID_INFO_RECEIVED: return "ERROR_INVALID_INFO_RECEIVED"; 11331 case ERROR_MODEM_RESPONSE_ERROR: return "ERROR_MODEM_RESPONSE_ERROR"; 11332 default: return "UNDEFINED"; 11333 } 11334 } 11335 } 11336 11337 /** 11338 * Requests the current modem activity info. 11339 * 11340 * The provided instance of {@link ModemActivityInfo} represents the cumulative activity since 11341 * the last restart of the phone process. 11342 * 11343 * @param callback A callback object to which the result will be delivered. If there was an 11344 * error processing the request, {@link OutcomeReceiver#onError} will be called 11345 * with more details about the error. 11346 * @hide 11347 */ 11348 @SystemApi 11349 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) requestModemActivityInfo(@onNull @allbackExecutor Executor executor, @NonNull OutcomeReceiver<ModemActivityInfo, ModemActivityInfoException> callback)11350 public void requestModemActivityInfo(@NonNull @CallbackExecutor Executor executor, 11351 @NonNull OutcomeReceiver<ModemActivityInfo, ModemActivityInfoException> callback) { 11352 Objects.requireNonNull(executor); 11353 Objects.requireNonNull(callback); 11354 11355 // Pass no handler into the receiver, since we're going to be trampolining the call to the 11356 // listener onto the provided executor. 11357 ResultReceiver wrapperResultReceiver = new ResultReceiver(null) { 11358 @Override 11359 protected void onReceiveResult(int resultCode, Bundle data) { 11360 if (data == null) { 11361 Log.w(TAG, "requestModemActivityInfo: received null bundle"); 11362 sendErrorToListener(ModemActivityInfoException.ERROR_UNKNOWN); 11363 return; 11364 } 11365 data.setDefusable(true); 11366 if (data.containsKey(EXCEPTION_RESULT_KEY)) { 11367 int receivedErrorCode = data.getInt(EXCEPTION_RESULT_KEY); 11368 sendErrorToListener(receivedErrorCode); 11369 return; 11370 } 11371 11372 if (!data.containsKey(MODEM_ACTIVITY_RESULT_KEY)) { 11373 Log.w(TAG, "requestModemActivityInfo: Bundle did not contain expected key"); 11374 sendErrorToListener(ModemActivityInfoException.ERROR_UNKNOWN); 11375 return; 11376 } 11377 Parcelable receivedResult = data.getParcelable(MODEM_ACTIVITY_RESULT_KEY); 11378 if (!(receivedResult instanceof ModemActivityInfo)) { 11379 Log.w(TAG, "requestModemActivityInfo: Bundle contained something that wasn't " 11380 + "a ModemActivityInfo."); 11381 sendErrorToListener(ModemActivityInfoException.ERROR_UNKNOWN); 11382 return; 11383 } 11384 ModemActivityInfo modemActivityInfo = (ModemActivityInfo) receivedResult; 11385 if (!modemActivityInfo.isValid()) { 11386 Log.w(TAG, "requestModemActivityInfo: Received an invalid ModemActivityInfo"); 11387 sendErrorToListener(ModemActivityInfoException.ERROR_INVALID_INFO_RECEIVED); 11388 return; 11389 } 11390 Log.d(TAG, "requestModemActivityInfo: Sending result to app: " + modemActivityInfo); 11391 sendResultToListener(modemActivityInfo); 11392 } 11393 11394 private void sendResultToListener(ModemActivityInfo info) { 11395 Binder.withCleanCallingIdentity(() -> 11396 executor.execute(() -> 11397 callback.onResult(info))); 11398 } 11399 11400 private void sendErrorToListener(int code) { 11401 ModemActivityInfoException e = new ModemActivityInfoException(code); 11402 Binder.withCleanCallingIdentity(() -> 11403 executor.execute(() -> 11404 callback.onError(e))); 11405 } 11406 }; 11407 11408 try { 11409 ITelephony service = getITelephony(); 11410 if (service != null) { 11411 service.requestModemActivityInfo(wrapperResultReceiver); 11412 return; 11413 } 11414 } catch (RemoteException e) { 11415 Log.e(TAG, "Error calling ITelephony#getModemActivityInfo", e); 11416 } 11417 executor.execute(() -> callback.onError( 11418 new ModemActivityInfoException( 11419 ModemActivityInfoException.ERROR_PHONE_NOT_AVAILABLE))); 11420 } 11421 11422 /** 11423 * Returns the current {@link ServiceState} information. 11424 * 11425 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 11426 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 11427 * 11428 * If you want continuous updates of service state info, register a {@link PhoneStateListener} 11429 * via {@link #listen} with the {@link PhoneStateListener#LISTEN_SERVICE_STATE} event. 11430 * 11431 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 11432 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) 11433 * and {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 11434 * 11435 * May return {@code null} when the subscription is inactive or when there was an error 11436 * communicating with the phone process. 11437 */ 11438 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 11439 @RequiresPermission(allOf = { 11440 Manifest.permission.READ_PHONE_STATE, 11441 Manifest.permission.ACCESS_COARSE_LOCATION 11442 }) getServiceState()11443 public @Nullable ServiceState getServiceState() { 11444 return getServiceStateForSubscriber(getSubId()); 11445 } 11446 11447 /** 11448 * Returns the service state information on specified subscription. Callers require 11449 * either READ_PRIVILEGED_PHONE_STATE or READ_PHONE_STATE to retrieve the information. 11450 * 11451 * May return {@code null} when the subscription is inactive or when there was an error 11452 * communicating with the phone process. 11453 * @hide 11454 */ 11455 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getServiceStateForSubscriber(int subId)11456 public ServiceState getServiceStateForSubscriber(int subId) { 11457 try { 11458 ITelephony service = getITelephony(); 11459 if (service != null) { 11460 return service.getServiceStateForSubscriber(subId, getOpPackageName(), 11461 getAttributionTag()); 11462 } 11463 } catch (RemoteException e) { 11464 Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e); 11465 } catch (NullPointerException e) { 11466 AnomalyReporter.reportAnomaly( 11467 UUID.fromString("a3ab0b9d-f2aa-4baf-911d-7096c0d4645a"), 11468 "getServiceStateForSubscriber " + subId + " NPE"); 11469 } 11470 return null; 11471 } 11472 11473 /** 11474 * Returns the URI for the per-account voicemail ringtone set in Phone settings. 11475 * 11476 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the 11477 * voicemail ringtone. 11478 * @return The URI for the ringtone to play when receiving a voicemail from a specific 11479 * PhoneAccount. May be {@code null} if no ringtone is set. 11480 */ getVoicemailRingtoneUri(PhoneAccountHandle accountHandle)11481 public @Nullable Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { 11482 try { 11483 ITelephony service = getITelephony(); 11484 if (service != null) { 11485 return service.getVoicemailRingtoneUri(accountHandle); 11486 } 11487 } catch (RemoteException e) { 11488 Log.e(TAG, "Error calling ITelephony#getVoicemailRingtoneUri", e); 11489 } 11490 return null; 11491 } 11492 11493 /** 11494 * Sets the per-account voicemail ringtone. 11495 * 11496 * <p>Requires that the calling app is the default dialer, or has carrier privileges (see 11497 * {@link #hasCarrierPrivileges}, or has permission 11498 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 11499 * 11500 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the 11501 * voicemail ringtone. 11502 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific 11503 * PhoneAccount. 11504 * 11505 * @deprecated Use {@link android.provider.Settings#ACTION_CHANNEL_NOTIFICATION_SETTINGS} 11506 * instead. 11507 */ setVoicemailRingtoneUri(PhoneAccountHandle phoneAccountHandle, Uri uri)11508 public void setVoicemailRingtoneUri(PhoneAccountHandle phoneAccountHandle, Uri uri) { 11509 try { 11510 ITelephony service = getITelephony(); 11511 if (service != null) { 11512 service.setVoicemailRingtoneUri(getOpPackageName(), phoneAccountHandle, uri); 11513 } 11514 } catch (RemoteException e) { 11515 Log.e(TAG, "Error calling ITelephony#setVoicemailRingtoneUri", e); 11516 } 11517 } 11518 11519 /** 11520 * Returns whether vibration is set for voicemail notification in Phone settings. 11521 * 11522 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the 11523 * voicemail vibration setting. 11524 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. 11525 */ isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle)11526 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { 11527 try { 11528 ITelephony service = getITelephony(); 11529 if (service != null) { 11530 return service.isVoicemailVibrationEnabled(accountHandle); 11531 } 11532 } catch (RemoteException e) { 11533 Log.e(TAG, "Error calling ITelephony#isVoicemailVibrationEnabled", e); 11534 } 11535 return false; 11536 } 11537 11538 /** 11539 * Sets the per-account preference whether vibration is enabled for voicemail notifications. 11540 * 11541 * <p>Requires that the calling app is the default dialer, or has carrier privileges (see 11542 * {@link #hasCarrierPrivileges}, or has permission 11543 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 11544 * 11545 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the 11546 * voicemail vibration setting. 11547 * @param enabled Whether to enable or disable vibration for voicemail notifications from a 11548 * specific PhoneAccount. 11549 * 11550 * @deprecated Use {@link android.provider.Settings#ACTION_CHANNEL_NOTIFICATION_SETTINGS} 11551 * instead. 11552 */ setVoicemailVibrationEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled)11553 public void setVoicemailVibrationEnabled(PhoneAccountHandle phoneAccountHandle, 11554 boolean enabled) { 11555 try { 11556 ITelephony service = getITelephony(); 11557 if (service != null) { 11558 service.setVoicemailVibrationEnabled(getOpPackageName(), phoneAccountHandle, 11559 enabled); 11560 } 11561 } catch (RemoteException e) { 11562 Log.e(TAG, "Error calling ITelephony#isVoicemailVibrationEnabled", e); 11563 } 11564 } 11565 11566 /** 11567 * Returns carrier id of the current subscription. 11568 * <p>To recognize a carrier (including MVNO) as a first-class identity, Android assigns each 11569 * carrier with a canonical integer a.k.a. carrier id. The carrier ID is an Android 11570 * platform-wide identifier for a carrier. AOSP maintains carrier ID assignments in 11571 * <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/latest_carrier_id/carrier_list.textpb">here</a> 11572 * 11573 * <p>Apps which have carrier-specific configurations or business logic can use the carrier id 11574 * as an Android platform-wide identifier for carriers. 11575 * 11576 * @return Carrier id of the current subscription. Return {@link #UNKNOWN_CARRIER_ID} if the 11577 * subscription is unavailable or the carrier cannot be identified. 11578 */ getSimCarrierId()11579 public int getSimCarrierId() { 11580 try { 11581 ITelephony service = getITelephony(); 11582 if (service != null) { 11583 return service.getSubscriptionCarrierId(getSubId()); 11584 } 11585 } catch (RemoteException ex) { 11586 // This could happen if binder process crashes. 11587 } 11588 return UNKNOWN_CARRIER_ID; 11589 } 11590 11591 /** 11592 * Returns carrier id name of the current subscription. 11593 * <p>Carrier id name is a user-facing name of carrier id returned by 11594 * {@link #getSimCarrierId()}, usually the brand name of the subsidiary 11595 * (e.g. T-Mobile). Each carrier could configure multiple {@link #getSimOperatorName() SPN} but 11596 * should have a single carrier name. Carrier name is not a canonical identity, 11597 * use {@link #getSimCarrierId()} instead. 11598 * <p>The returned carrier name is unlocalized. 11599 * 11600 * @return Carrier name of the current subscription. Return {@code null} if the subscription is 11601 * unavailable or the carrier cannot be identified. 11602 */ getSimCarrierIdName()11603 public @Nullable CharSequence getSimCarrierIdName() { 11604 try { 11605 ITelephony service = getITelephony(); 11606 if (service != null) { 11607 return service.getSubscriptionCarrierName(getSubId()); 11608 } 11609 } catch (RemoteException ex) { 11610 // This could happen if binder process crashes. 11611 } 11612 return null; 11613 } 11614 11615 /** 11616 * Returns fine-grained carrier ID of the current subscription. 11617 * 11618 * A specific carrier ID can represent the fact that a carrier may be in effect an aggregation 11619 * of other carriers (ie in an MVNO type scenario) where each of these specific carriers which 11620 * are used to make up the actual carrier service may have different carrier configurations. 11621 * A specific carrier ID could also be used, for example, in a scenario where a carrier requires 11622 * different carrier configuration for different service offering such as a prepaid plan. 11623 * 11624 * the specific carrier ID would be used for configuration purposes, but apps wishing to know 11625 * about the carrier itself should use the regular carrier ID returned by 11626 * {@link #getSimCarrierId()}. 11627 * 11628 * e.g, Tracfone SIMs could return different specific carrier ID based on IMSI from current 11629 * subscription while carrier ID remains the same. 11630 * 11631 * <p>For carriers without fine-grained specific carrier ids, return {@link #getSimCarrierId()} 11632 * <p>Specific carrier ids are defined in the same way as carrier id 11633 * <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/latest_carrier_id/carrier_list.textpb">here</a> 11634 * except each with a "parent" id linking to its top-level carrier id. 11635 * 11636 * @return Returns fine-grained carrier id of the current subscription. 11637 * Return {@link #UNKNOWN_CARRIER_ID} if the subscription is unavailable or the carrier cannot 11638 * be identified. 11639 */ getSimSpecificCarrierId()11640 public int getSimSpecificCarrierId() { 11641 try { 11642 ITelephony service = getITelephony(); 11643 if (service != null) { 11644 return service.getSubscriptionSpecificCarrierId(getSubId()); 11645 } 11646 } catch (RemoteException ex) { 11647 // This could happen if binder process crashes. 11648 } 11649 return UNKNOWN_CARRIER_ID; 11650 } 11651 11652 /** 11653 * Similar like {@link #getSimCarrierIdName()}, returns user-facing name of the 11654 * specific carrier id returned by {@link #getSimSpecificCarrierId()}. 11655 * 11656 * The specific carrier ID would be used for configuration purposes, but apps wishing to know 11657 * about the carrier itself should use the regular carrier ID returned by 11658 * {@link #getSimCarrierIdName()}. 11659 * 11660 * <p>The returned name is unlocalized. 11661 * 11662 * @return user-facing name of the subscription specific carrier id. Return {@code null} if the 11663 * subscription is unavailable or the carrier cannot be identified. 11664 */ getSimSpecificCarrierIdName()11665 public @Nullable CharSequence getSimSpecificCarrierIdName() { 11666 try { 11667 ITelephony service = getITelephony(); 11668 if (service != null) { 11669 return service.getSubscriptionSpecificCarrierName(getSubId()); 11670 } 11671 } catch (RemoteException ex) { 11672 // This could happen if binder process crashes. 11673 } 11674 return null; 11675 } 11676 11677 /** 11678 * Returns carrier id based on sim MCCMNC (returned by {@link #getSimOperator()}) only. 11679 * This is used for fallback when configurations/logic for exact carrier id 11680 * {@link #getSimCarrierId()} are not found. 11681 * 11682 * Android carrier id table <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/latest_carrier_id/carrier_list.textpb">here</a> 11683 * can be updated out-of-band, its possible a MVNO (Mobile Virtual Network Operator) carrier 11684 * was not fully recognized and assigned to its MNO (Mobile Network Operator) carrier id 11685 * by default. After carrier id table update, a new carrier id was assigned. If apps don't 11686 * take the update with the new id, it might be helpful to always fallback by using carrier 11687 * id based on MCCMNC if there is no match. 11688 * 11689 * @return matching carrier id from sim MCCMNC. Return {@link #UNKNOWN_CARRIER_ID} if the 11690 * subscription is unavailable or the carrier cannot be identified. 11691 */ getCarrierIdFromSimMccMnc()11692 public int getCarrierIdFromSimMccMnc() { 11693 try { 11694 ITelephony service = getITelephony(); 11695 if (service != null) { 11696 return service.getCarrierIdFromMccMnc(getSlotIndex(), getSimOperator(), true); 11697 } 11698 } catch (RemoteException ex) { 11699 // This could happen if binder process crashes. 11700 } 11701 return UNKNOWN_CARRIER_ID; 11702 } 11703 11704 /** 11705 * Returns carrier id based on MCCMNC (returned by {@link #getSimOperator()}) only. This is 11706 * used for fallback when configurations/logic for exact carrier id {@link #getSimCarrierId()} 11707 * are not found. 11708 * 11709 * Android carrier id table <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/latest_carrier_id/carrier_list.textpb">here</a> 11710 * can be updated out-of-band, its possible a MVNO (Mobile Virtual Network Operator) carrier 11711 * was not fully recognized and assigned to its MNO (Mobile Network Operator) carrier id 11712 * by default. After carrier id table update, a new carrier id was assigned. If apps don't 11713 * take the update with the new id, it might be helpful to always fallback by using carrier 11714 * id based on MCCMNC if there is no match. 11715 * 11716 * @return matching carrier id from passing MCCMNC. Return {@link #UNKNOWN_CARRIER_ID} if the 11717 * subscription is unavailable or the carrier cannot be identified. 11718 * @hide 11719 */ 11720 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getCarrierIdFromMccMnc(String mccmnc)11721 public int getCarrierIdFromMccMnc(String mccmnc) { 11722 try { 11723 ITelephony service = getITelephony(); 11724 if (service != null) { 11725 return service.getCarrierIdFromMccMnc(getSlotIndex(), mccmnc, false); 11726 } 11727 } catch (RemoteException ex) { 11728 // This could happen if binder process crashes. 11729 } 11730 return UNKNOWN_CARRIER_ID; 11731 } 11732 11733 /** 11734 * Return a list of certs as hex strings from loaded carrier privileges access rules. 11735 * 11736 * @return a list of certificates as hex strings, or an empty list if there are no certs or 11737 * privilege rules are not loaded yet. 11738 * @hide 11739 */ 11740 @TestApi 11741 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 11742 @NonNull getCertsFromCarrierPrivilegeAccessRules()11743 public List<String> getCertsFromCarrierPrivilegeAccessRules() { 11744 List<String> certs = null; 11745 try { 11746 ITelephony service = getITelephony(); 11747 if (service != null) { 11748 certs = service.getCertsFromCarrierPrivilegeAccessRules(getSubId()); 11749 } 11750 } catch (RemoteException ex) { 11751 // This could happen if binder process crashes. 11752 } 11753 return certs == null ? Collections.emptyList() : certs; 11754 } 11755 11756 /** 11757 * Return the application ID for the uicc application type like {@link #APPTYPE_CSIM}. 11758 * All uicc applications are uniquely identified by application ID, represented by the hex 11759 * string. e.g, A00000015141434C00. See ETSI 102.221 and 101.220 11760 * <p>Requires Permission: 11761 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} 11762 * 11763 * @param appType the uicc app type. 11764 * @return Application ID for specified app type or {@code null} if no uicc or error. 11765 * @hide 11766 */ 11767 @Nullable 11768 @SystemApi 11769 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getAidForAppType(@iccAppType int appType)11770 public String getAidForAppType(@UiccAppType int appType) { 11771 return getAidForAppType(getSubId(), appType); 11772 } 11773 11774 /** 11775 * same as {@link #getAidForAppType(int)} 11776 * @hide 11777 */ getAidForAppType(int subId, int appType)11778 public String getAidForAppType(int subId, int appType) { 11779 try { 11780 ITelephony service = getITelephony(); 11781 if (service != null) { 11782 return service.getAidForAppType(subId, appType); 11783 } 11784 } catch (RemoteException e) { 11785 Log.e(TAG, "Error calling ITelephony#getAidForAppType", e); 11786 } 11787 return null; 11788 } 11789 11790 /** 11791 * Return the Electronic Serial Number. 11792 * 11793 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 11794 * 11795 * @return ESN or null if error. 11796 * @hide 11797 */ getEsn()11798 public String getEsn() { 11799 return getEsn(getSubId()); 11800 } 11801 11802 /** 11803 * Return the Electronic Serial Number. 11804 * 11805 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 11806 * 11807 * @param subId the subscription ID that this request applies to. 11808 * @return ESN or null if error. 11809 * @hide 11810 */ getEsn(int subId)11811 public String getEsn(int subId) { 11812 try { 11813 ITelephony service = getITelephony(); 11814 if (service != null) { 11815 return service.getEsn(subId); 11816 } 11817 } catch (RemoteException e) { 11818 Log.e(TAG, "Error calling ITelephony#getEsn", e); 11819 } 11820 return null; 11821 } 11822 11823 /** 11824 * Return the Preferred Roaming List Version 11825 * 11826 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 11827 * 11828 * @return PRLVersion or null if error. 11829 * @hide 11830 */ 11831 @SystemApi getCdmaPrlVersion()11832 public String getCdmaPrlVersion() { 11833 return getCdmaPrlVersion(getSubId()); 11834 } 11835 11836 /** 11837 * Return the Preferred Roaming List Version 11838 * 11839 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 11840 * 11841 * @param subId the subscription ID that this request applies to. 11842 * @return PRLVersion or null if error. 11843 * @hide 11844 */ getCdmaPrlVersion(int subId)11845 public String getCdmaPrlVersion(int subId) { 11846 try { 11847 ITelephony service = getITelephony(); 11848 if (service != null) { 11849 return service.getCdmaPrlVersion(subId); 11850 } 11851 } catch (RemoteException e) { 11852 Log.e(TAG, "Error calling ITelephony#getCdmaPrlVersion", e); 11853 } 11854 return null; 11855 } 11856 11857 /** 11858 * Get snapshot of Telephony histograms 11859 * @return List of Telephony histograms 11860 * Requires Permission: 11861 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 11862 * Or the calling app has carrier privileges. 11863 * @hide 11864 */ 11865 @SystemApi 11866 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getTelephonyHistograms()11867 public List<TelephonyHistogram> getTelephonyHistograms() { 11868 try { 11869 ITelephony service = getITelephony(); 11870 if (service != null) { 11871 return service.getTelephonyHistograms(); 11872 } 11873 } catch (RemoteException e) { 11874 Log.e(TAG, "Error calling ITelephony#getTelephonyHistograms", e); 11875 } 11876 return null; 11877 } 11878 11879 /** 11880 * Set the allowed carrier list for slotIndex 11881 * Require system privileges. In the future we may add this to carrier APIs. 11882 * 11883 * <p>Requires Permission: 11884 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} 11885 * 11886 * <p>This method works only on devices with {@link 11887 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 11888 * 11889 * @deprecated use setCarrierRestrictionRules instead 11890 * 11891 * @return The number of carriers set successfully. Should be length of 11892 * carrierList on success; -1 if carrierList null or on error. 11893 * @hide 11894 */ 11895 @SystemApi 11896 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers)11897 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) { 11898 if (carriers == null || !SubscriptionManager.isValidPhoneId(slotIndex)) { 11899 return -1; 11900 } 11901 // Execute the method setCarrierRestrictionRules with an empty excluded list. 11902 // If the allowed list is empty, it means that all carriers are allowed (default allowed), 11903 // otherwise it means that only specified carriers are allowed (default not allowed). 11904 CarrierRestrictionRules carrierRestrictionRules = CarrierRestrictionRules.newBuilder() 11905 .setAllowedCarriers(carriers) 11906 .setDefaultCarrierRestriction( 11907 carriers.isEmpty() 11908 ? CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_ALLOWED 11909 : CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED) 11910 .build(); 11911 11912 int result = setCarrierRestrictionRules(carrierRestrictionRules); 11913 11914 // Convert result into int, as required by this method. 11915 if (result == SET_CARRIER_RESTRICTION_SUCCESS) { 11916 return carriers.size(); 11917 } else { 11918 return -1; 11919 } 11920 } 11921 11922 /** 11923 * The carrier restrictions were successfully set. 11924 * @hide 11925 */ 11926 @SystemApi 11927 public static final int SET_CARRIER_RESTRICTION_SUCCESS = 0; 11928 11929 /** 11930 * The carrier restrictions were not set due to lack of support in the modem. This can happen 11931 * if the modem does not support setting the carrier restrictions or if the configuration 11932 * passed in the {@code setCarrierRestrictionRules} is not supported by the modem. 11933 * @hide 11934 */ 11935 @SystemApi 11936 public static final int SET_CARRIER_RESTRICTION_NOT_SUPPORTED = 1; 11937 11938 /** 11939 * The setting of carrier restrictions failed. 11940 * @hide 11941 */ 11942 @SystemApi 11943 public static final int SET_CARRIER_RESTRICTION_ERROR = 2; 11944 11945 /** @hide */ 11946 @Retention(RetentionPolicy.SOURCE) 11947 @IntDef(prefix = {"SET_CARRIER_RESTRICTION_"}, 11948 value = { 11949 SET_CARRIER_RESTRICTION_SUCCESS, 11950 SET_CARRIER_RESTRICTION_NOT_SUPPORTED, 11951 SET_CARRIER_RESTRICTION_ERROR 11952 }) 11953 public @interface SetCarrierRestrictionResult {} 11954 11955 /** 11956 * The SIM power state was successfully set. 11957 * @hide 11958 */ 11959 @SystemApi 11960 public static final int SET_SIM_POWER_STATE_SUCCESS = 0; 11961 11962 /** 11963 * The SIM is already in the requested power state. 11964 * @hide 11965 */ 11966 @SystemApi 11967 public static final int SET_SIM_POWER_STATE_ALREADY_IN_STATE = 1; 11968 11969 /** 11970 * Failed to connect to the modem to make the power state request. This may happen if the 11971 * modem has an error. The user may want to make the request again later. 11972 * @hide 11973 */ 11974 @SystemApi 11975 public static final int SET_SIM_POWER_STATE_MODEM_ERROR = 2; 11976 11977 /** 11978 * Failed to connect to the SIM to make the power state request. This may happen if the 11979 * SIM has been removed. The user may want to make the request again later. 11980 * @hide 11981 */ 11982 @SystemApi 11983 public static final int SET_SIM_POWER_STATE_SIM_ERROR = 3; 11984 11985 /** 11986 * The modem version does not support synchronous power. 11987 * @hide 11988 */ 11989 @SystemApi 11990 public static final int SET_SIM_POWER_STATE_NOT_SUPPORTED = 4; 11991 11992 /** @hide */ 11993 @Retention(RetentionPolicy.SOURCE) 11994 @IntDef(prefix = {"SET_SIM_POWER_STATE_"}, 11995 value = { 11996 SET_SIM_POWER_STATE_SUCCESS, 11997 SET_SIM_POWER_STATE_ALREADY_IN_STATE, 11998 SET_SIM_POWER_STATE_MODEM_ERROR, 11999 SET_SIM_POWER_STATE_SIM_ERROR, 12000 SET_SIM_POWER_STATE_NOT_SUPPORTED 12001 }) 12002 public @interface SetSimPowerStateResult {} 12003 12004 /** 12005 * Set the allowed carrier list and the excluded carrier list indicating the priority between 12006 * the two lists. 12007 * Requires system privileges. 12008 * 12009 * <p>Requires Permission: 12010 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} 12011 * 12012 * <p>This method works only on devices with {@link 12013 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 12014 * 12015 * @return {@link #SET_CARRIER_RESTRICTION_SUCCESS} in case of success. 12016 * {@link #SET_CARRIER_RESTRICTION_NOT_SUPPORTED} if the modem does not support the 12017 * configuration. {@link #SET_CARRIER_RESTRICTION_ERROR} in all other error cases. 12018 * @hide 12019 */ 12020 @SystemApi 12021 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 12022 @SetCarrierRestrictionResult setCarrierRestrictionRules(@onNull CarrierRestrictionRules rules)12023 public int setCarrierRestrictionRules(@NonNull CarrierRestrictionRules rules) { 12024 try { 12025 ITelephony service = getITelephony(); 12026 if (service != null) { 12027 return service.setAllowedCarriers(rules); 12028 } 12029 } catch (RemoteException e) { 12030 Log.e(TAG, "Error calling ITelephony#setAllowedCarriers", e); 12031 } catch (NullPointerException e) { 12032 Log.e(TAG, "Error calling ITelephony#setAllowedCarriers", e); 12033 } 12034 return SET_CARRIER_RESTRICTION_ERROR; 12035 } 12036 12037 /** 12038 * Get the allowed carrier list for slotIndex. 12039 * Requires system privileges. 12040 * 12041 * <p>This method returns valid data on devices with {@link 12042 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 12043 * 12044 * @deprecated Apps should use {@link getCarriersRestrictionRules} to retrieve the list of 12045 * allowed and excliuded carriers, as the result of this API is valid only when the excluded 12046 * list is empty. This API could return an empty list, even if some restrictions are present. 12047 * 12048 * @return List of {@link android.telephony.CarrierIdentifier}; empty list 12049 * means all carriers are allowed. 12050 * @hide 12051 */ 12052 @Deprecated 12053 @SystemApi 12054 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getAllowedCarriers(int slotIndex)12055 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) { 12056 if (SubscriptionManager.isValidPhoneId(slotIndex)) { 12057 CarrierRestrictionRules carrierRestrictionRule = getCarrierRestrictionRules(); 12058 if (carrierRestrictionRule != null) { 12059 return carrierRestrictionRule.getAllowedCarriers(); 12060 } 12061 } 12062 return new ArrayList<CarrierIdentifier>(0); 12063 } 12064 12065 /** 12066 * Get the allowed carrier list and the excluded carrier list indicating the priority between 12067 * the two lists. 12068 * Require system privileges. In the future we may add this to carrier APIs. 12069 * 12070 * <p>This method returns valid data on devices with {@link 12071 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 12072 * 12073 * @return {@link CarrierRestrictionRules} which contains the allowed carrier list and the 12074 * excluded carrier list with the priority between the two lists. Returns {@code null} 12075 * in case of error. 12076 * @hide 12077 */ 12078 @SystemApi 12079 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 12080 @Nullable getCarrierRestrictionRules()12081 public CarrierRestrictionRules getCarrierRestrictionRules() { 12082 try { 12083 ITelephony service = getITelephony(); 12084 if (service != null) { 12085 return service.getAllowedCarriers(); 12086 } 12087 } catch (RemoteException e) { 12088 Log.e(TAG, "Error calling ITelephony#getAllowedCarriers", e); 12089 } catch (NullPointerException e) { 12090 Log.e(TAG, "Error calling ITelephony#getAllowedCarriers", e); 12091 } 12092 return null; 12093 } 12094 12095 /** 12096 * Used to enable or disable carrier data by the system based on carrier signalling or 12097 * carrier privileged apps. Different from {@link #setDataEnabled(boolean)} which is linked to 12098 * user settings, carrier data on/off won't affect user settings but will bypass the 12099 * settings and turns off data internally if set to {@code false}. 12100 * 12101 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 12102 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 12103 * 12104 * <p>Requires Permission: 12105 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 12106 * 12107 * @param enabled control enable or disable carrier data. 12108 * @see #resetAllCarrierActions() 12109 * @deprecated use {@link #setDataEnabledForReason(int, boolean) with 12110 * reason {@link #DATA_ENABLED_REASON_CARRIER}} instead. 12111 * @hide 12112 */ 12113 @Deprecated 12114 @SystemApi 12115 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setCarrierDataEnabled(boolean enabled)12116 public void setCarrierDataEnabled(boolean enabled) { 12117 try { 12118 setDataEnabledForReason(DATA_ENABLED_REASON_CARRIER, enabled); 12119 } catch (RuntimeException e) { 12120 Log.e(TAG, "Error calling setDataEnabledForReason e:" + e); 12121 } 12122 } 12123 12124 /** 12125 * Carrier action to enable or disable the radio. 12126 * 12127 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 12128 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 12129 * 12130 * <p>Requires Permission: 12131 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 12132 * 12133 * @param enabled control enable or disable radio. 12134 * @see #resetAllCarrierActions() 12135 * @hide 12136 */ 12137 @SystemApi 12138 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setRadioEnabled(boolean enabled)12139 public void setRadioEnabled(boolean enabled) { 12140 try { 12141 ITelephony service = getITelephony(); 12142 if (service != null) { 12143 service.carrierActionSetRadioEnabled( 12144 getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), enabled); 12145 } 12146 } catch (RemoteException e) { 12147 Log.e(TAG, "Error calling ITelephony#carrierActionSetRadioEnabled", e); 12148 } 12149 } 12150 12151 /** 12152 * No error. Operation succeeded. 12153 * @hide 12154 */ 12155 public static final int ENABLE_VONR_SUCCESS = 0; 12156 12157 /** 12158 * Radio is not available. 12159 * @hide 12160 */ 12161 public static final int ENABLE_VONR_RADIO_NOT_AVAILABLE = 2; 12162 12163 /** 12164 * Internal Radio error. 12165 * @hide 12166 */ 12167 public static final int ENABLE_VONR_RADIO_ERROR = 3; 12168 12169 /** 12170 * Voice over NR enable/disable request is received when system is in invalid state. 12171 * @hide 12172 */ 12173 public static final int ENABLE_VONR_RADIO_INVALID_STATE = 4; 12174 12175 /** 12176 * Voice over NR enable/disable request is not supported. 12177 * @hide 12178 */ 12179 public static final int ENABLE_VONR_REQUEST_NOT_SUPPORTED = 5; 12180 12181 /** @hide */ 12182 @Retention(RetentionPolicy.SOURCE) 12183 @IntDef(prefix = {"EnableVoNrResult"}, value = { 12184 ENABLE_VONR_SUCCESS, 12185 ENABLE_VONR_RADIO_NOT_AVAILABLE, 12186 ENABLE_VONR_RADIO_ERROR, 12187 ENABLE_VONR_RADIO_INVALID_STATE, 12188 ENABLE_VONR_REQUEST_NOT_SUPPORTED}) 12189 public @interface EnableVoNrResult {} 12190 12191 /** 12192 * Enable or disable Voice over NR (VoNR) 12193 * 12194 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 12195 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 12196 * 12197 * <p>Requires Permission: 12198 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 12199 * 12200 * @param enabled enable or disable VoNR. 12201 * @throws IllegalStateException if the Telephony process is not currently available. 12202 * @hide 12203 */ 12204 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setVoNrEnabled(boolean enabled)12205 public @EnableVoNrResult int setVoNrEnabled(boolean enabled) { 12206 try { 12207 ITelephony service = getITelephony(); 12208 if (service != null) { 12209 return service.setVoNrEnabled( 12210 getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), enabled); 12211 } else { 12212 throw new IllegalStateException("telephony service is null."); 12213 } 12214 } catch (RemoteException e) { 12215 Log.e(TAG, "Error calling ITelephony#setVoNrEnabled", e); 12216 } 12217 12218 return ENABLE_VONR_RADIO_INVALID_STATE; 12219 } 12220 12221 /** 12222 * Is Voice over NR (VoNR) enabled. 12223 * @return true if Voice over NR (VoNR) is enabled else false. Enabled state does not mean 12224 * voice call over NR is active or voice ove NR is available. It means the device is allowed to 12225 * register IMS over NR. 12226 * @throws IllegalStateException if the Telephony process is not currently available. 12227 * @hide 12228 */ 12229 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) isVoNrEnabled()12230 public boolean isVoNrEnabled() { 12231 try { 12232 ITelephony telephony = getITelephony(); 12233 if (telephony != null) { 12234 return telephony.isVoNrEnabled(getSubId()); 12235 } else { 12236 throw new IllegalStateException("telephony service is null."); 12237 } 12238 } catch (RemoteException ex) { 12239 Rlog.e(TAG, "isVoNrEnabled RemoteException", ex); 12240 ex.rethrowFromSystemServer(); 12241 } 12242 return false; 12243 } 12244 12245 /** 12246 * Carrier action to start or stop reporting default network available events. 12247 * 12248 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 12249 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 12250 * 12251 * <p>Requires Permission: 12252 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 12253 * 12254 * @param report control start/stop reporting network status. 12255 * @see #resetAllCarrierActions() 12256 * @hide 12257 */ 12258 @SystemApi 12259 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) reportDefaultNetworkStatus(boolean report)12260 public void reportDefaultNetworkStatus(boolean report) { 12261 try { 12262 ITelephony service = getITelephony(); 12263 if (service != null) { 12264 service.carrierActionReportDefaultNetworkStatus( 12265 getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), report); 12266 } 12267 } catch (RemoteException e) { 12268 Log.e(TAG, "Error calling ITelephony#carrierActionReportDefaultNetworkStatus", e); 12269 } 12270 } 12271 12272 /** 12273 * Reset all carrier actions previously set by {@link #setRadioEnabled}, 12274 * {@link #reportDefaultNetworkStatus} and {@link #setCarrierDataEnabled}. 12275 * 12276 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 12277 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 12278 * 12279 * <p>Requires Permission: 12280 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 12281 * @hide 12282 */ 12283 @SystemApi 12284 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) resetAllCarrierActions()12285 public void resetAllCarrierActions() { 12286 try { 12287 ITelephony service = getITelephony(); 12288 if (service != null) { 12289 service.carrierActionResetAll( 12290 getSubId(SubscriptionManager.getDefaultDataSubscriptionId())); 12291 } 12292 } catch (RemoteException e) { 12293 Log.e(TAG, "Error calling ITelephony#carrierActionResetAll", e); 12294 } 12295 } 12296 12297 /** 12298 * Policy control of data connection. Usually used when data limit is passed. 12299 * @param enabled True if enabling the data, otherwise disabling. 12300 * @deprecated use {@link #setDataEnabledForReason(int, boolean) with 12301 * reason {@link #DATA_ENABLED_REASON_POLICY}} instead. 12302 * @hide 12303 */ 12304 @Deprecated 12305 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) setPolicyDataEnabled(boolean enabled)12306 public void setPolicyDataEnabled(boolean enabled) { 12307 try { 12308 setDataEnabledForReason(DATA_ENABLED_REASON_POLICY, enabled); 12309 } catch (RuntimeException e) { 12310 Log.e(TAG, "Error calling setDataEnabledForReason e:" + e); 12311 } 12312 } 12313 12314 /** @hide */ 12315 @IntDef({ 12316 DATA_ENABLED_REASON_USER, 12317 DATA_ENABLED_REASON_POLICY, 12318 DATA_ENABLED_REASON_CARRIER, 12319 DATA_ENABLED_REASON_THERMAL 12320 }) 12321 @Retention(RetentionPolicy.SOURCE) 12322 public @interface DataEnabledReason{} 12323 12324 /** 12325 * To indicate that user enabled or disabled data. 12326 */ 12327 public static final int DATA_ENABLED_REASON_USER = 0; 12328 12329 /** 12330 * To indicate that data control due to policy. Usually used when data limit is passed. 12331 * Policy data on/off won't affect user settings but will bypass the 12332 * settings and turns off data internally if set to {@code false}. 12333 */ 12334 public static final int DATA_ENABLED_REASON_POLICY = 1; 12335 12336 /** 12337 * To indicate enable or disable carrier data by the system based on carrier signalling or 12338 * carrier privileged apps. Carrier data on/off won't affect user settings but will bypass the 12339 * settings and turns off data internally if set to {@code false}. 12340 */ 12341 public static final int DATA_ENABLED_REASON_CARRIER = 2; 12342 12343 /** 12344 * To indicate enable or disable data by thermal service. 12345 * Thermal data on/off won't affect user settings but will bypass the 12346 * settings and turns off data internally if set to {@code false}. 12347 */ 12348 public static final int DATA_ENABLED_REASON_THERMAL = 3; 12349 12350 /** 12351 * Control of data connection and provide the reason triggering the data connection control. 12352 * This can be called for following reasons 12353 * <ol> 12354 * <li>data limit is passed {@link #DATA_ENABLED_REASON_POLICY} 12355 * <li>data disabled by carrier {@link #DATA_ENABLED_REASON_CARRIER} 12356 * <li>data disabled by user {@link #DATA_ENABLED_REASON_USER} 12357 * <li>data disabled due to thermal {@link #DATA_ENABLED_REASON_THERMAL} 12358 * </ol> 12359 * If any of the reason is off, then it will result in 12360 * bypassing user preference and result in data to be turned off. 12361 * 12362 * <p>If this object has been created with {@link #createForSubscriptionId}, applies 12363 * to the given subId. Otherwise, applies to 12364 * {@link SubscriptionManager#getDefaultDataSubscriptionId()} 12365 * 12366 * 12367 * @param reason the reason the data enable change is taking place 12368 * @param enabled True if enabling the data, otherwise disabling. 12369 * 12370 * <p>Requires Permission: 12371 * The calling app has carrier privileges (see {@link #hasCarrierPrivileges}) if the reason is 12372 * {@link #DATA_ENABLED_REASON_USER} or {@link #DATA_ENABLED_REASON_CARRIER} or the call app 12373 * has {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} irrespective of 12374 * the reason. 12375 * @throws IllegalStateException if the Telephony process is not currently available. 12376 */ 12377 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) setDataEnabledForReason(@ataEnabledReason int reason, boolean enabled)12378 public void setDataEnabledForReason(@DataEnabledReason int reason, boolean enabled) { 12379 setDataEnabledForReason(getSubId(), reason, enabled); 12380 } 12381 setDataEnabledForReason(int subId, @DataEnabledReason int reason, boolean enabled)12382 private void setDataEnabledForReason(int subId, @DataEnabledReason int reason, 12383 boolean enabled) { 12384 try { 12385 ITelephony service = getITelephony(); 12386 if (service != null) { 12387 service.setDataEnabledForReason(subId, reason, enabled); 12388 } else { 12389 throw new IllegalStateException("telephony service is null."); 12390 } 12391 } catch (RemoteException ex) { 12392 Log.e(TAG, "Telephony#setDataEnabledForReason RemoteException", ex); 12393 ex.rethrowFromSystemServer(); 12394 } 12395 } 12396 12397 /** 12398 * Return whether data is enabled for certain reason . 12399 * 12400 * If {@link #isDataEnabledForReason} returns false, it means in data enablement for a 12401 * specific reason is turned off. If any of the reason is off, then it will result in 12402 * bypassing user preference and result in data to be turned off. Call 12403 * {@link #isDataConnectionAllowed} in order to know whether 12404 * data connection is allowed on the device. 12405 * 12406 * <p>If this object has been created with {@link #createForSubscriptionId}, applies 12407 * to the given subId. Otherwise, applies to 12408 * {@link SubscriptionManager#getDefaultDataSubscriptionId()} 12409 * 12410 * @param reason the reason the data enable change is taking place 12411 * @return whether data is enabled for a reason. 12412 * <p>Requires Permission: 12413 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} or 12414 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE} 12415 * @throws IllegalStateException if the Telephony process is not currently available. 12416 */ 12417 @RequiresPermission(anyOf = {android.Manifest.permission.ACCESS_NETWORK_STATE, 12418 android.Manifest.permission.READ_PHONE_STATE}) isDataEnabledForReason(@ataEnabledReason int reason)12419 public boolean isDataEnabledForReason(@DataEnabledReason int reason) { 12420 return isDataEnabledForReason(getSubId(), reason); 12421 } 12422 isDataEnabledForReason(int subId, @DataEnabledReason int reason)12423 private boolean isDataEnabledForReason(int subId, @DataEnabledReason int reason) { 12424 try { 12425 ITelephony service = getITelephony(); 12426 if (service != null) { 12427 return service.isDataEnabledForReason(subId, reason); 12428 } else { 12429 throw new IllegalStateException("telephony service is null."); 12430 } 12431 } catch (RemoteException ex) { 12432 Log.e(TAG, "Telephony#isDataEnabledForReason RemoteException", ex); 12433 ex.rethrowFromSystemServer(); 12434 } 12435 return false; 12436 } 12437 12438 /** 12439 * Get Client request stats which will contain statistical information 12440 * on each request made by client. 12441 * Callers require either READ_PRIVILEGED_PHONE_STATE or 12442 * READ_PHONE_STATE to retrieve the information. 12443 * @param subId sub id 12444 * @return List of Client Request Stats 12445 * @hide 12446 */ getClientRequestStats(int subId)12447 public List<ClientRequestStats> getClientRequestStats(int subId) { 12448 try { 12449 ITelephony service = getITelephony(); 12450 if (service != null) { 12451 return service.getClientRequestStats(getOpPackageName(), getAttributionTag(), 12452 subId); 12453 } 12454 } catch (RemoteException e) { 12455 Log.e(TAG, "Error calling ITelephony#getClientRequestStats", e); 12456 } 12457 12458 return null; 12459 } 12460 12461 /** 12462 * Checks if phone is in emergency callback mode. 12463 * 12464 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 12465 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 12466 * 12467 * @return true if phone is in emergency callback mode. 12468 * @hide 12469 */ 12470 @SystemApi 12471 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getEmergencyCallbackMode()12472 public boolean getEmergencyCallbackMode() { 12473 return getEmergencyCallbackMode(getSubId()); 12474 } 12475 12476 /** 12477 * Check if phone is in emergency callback mode 12478 * @return true if phone is in emergency callback mode 12479 * @param subId the subscription ID that this action applies to. 12480 * @hide 12481 */ getEmergencyCallbackMode(int subId)12482 public boolean getEmergencyCallbackMode(int subId) { 12483 try { 12484 ITelephony telephony = getITelephony(); 12485 if (telephony == null) { 12486 return false; 12487 } 12488 return telephony.getEmergencyCallbackMode(subId); 12489 } catch (RemoteException e) { 12490 Log.e(TAG, "Error calling ITelephony#getEmergencyCallbackMode", e); 12491 } 12492 return false; 12493 } 12494 12495 /** 12496 * Checks if manual network selection is allowed. 12497 * 12498 * <p>Requires Permission: {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE 12499 * READ_PRECISE_PHONE_STATE} or that the calling app has carrier privileges 12500 * (see {@link #hasCarrierPrivileges}) 12501 * 12502 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 12503 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()}. 12504 * 12505 * @return {@code true} if manual network selection is allowed, otherwise return {@code false}. 12506 */ 12507 @SuppressAutoDoc // No support carrier privileges (b/72967236). 12508 @RequiresPermission(anyOf = {android.Manifest.permission.READ_PRECISE_PHONE_STATE, 12509 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE}) isManualNetworkSelectionAllowed()12510 public boolean isManualNetworkSelectionAllowed() { 12511 try { 12512 ITelephony telephony = getITelephony(); 12513 if (telephony != null) { 12514 return telephony.isManualNetworkSelectionAllowed(getSubId()); 12515 } 12516 } catch (RemoteException e) { 12517 Log.e(TAG, "Error calling ITelephony#isManualNetworkSelectionAllowed", e); 12518 } 12519 return true; 12520 } 12521 12522 /** 12523 * Enable or disable signal strength changes from radio will always be reported in any 12524 * condition (e.g. screen is off). This is only allowed for System caller. 12525 * 12526 * @param isEnabled {@code true} for enabling; {@code false} for disabling. 12527 * @hide 12528 */ 12529 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setAlwaysReportSignalStrength(boolean isEnabled)12530 public void setAlwaysReportSignalStrength(boolean isEnabled) { 12531 try { 12532 ITelephony telephony = getITelephony(); 12533 if (telephony != null) { 12534 telephony.setAlwaysReportSignalStrength(getSubId(), isEnabled); 12535 } 12536 } catch (RemoteException ex) { 12537 Log.e(TAG, "setAlwaysReportSignalStrength RemoteException", ex); 12538 ex.rethrowAsRuntimeException(); 12539 } 12540 } 12541 12542 /** 12543 * Get the most recently available signal strength information. 12544 * 12545 * Get the most recent SignalStrength information reported by the modem. Due 12546 * to power saving this information may not always be current. 12547 * @return the most recent cached signal strength info from the modem 12548 */ 12549 @Nullable getSignalStrength()12550 public SignalStrength getSignalStrength() { 12551 try { 12552 ITelephony service = getITelephony(); 12553 if (service != null) { 12554 return service.getSignalStrength(getSubId()); 12555 } 12556 } catch (RemoteException e) { 12557 Log.e(TAG, "Error calling ITelephony#getSignalStrength", e); 12558 } 12559 return null; 12560 } 12561 12562 /** 12563 * Checks whether cellular data connection is allowed in the device. 12564 * 12565 * <p>Whether cellular data connection is allowed considers all factors below: 12566 * <UL> 12567 * <LI>User turned on data setting {@link #isDataEnabled}.</LI> 12568 * <LI>Carrier allows data to be on.</LI> 12569 * <LI>Network policy.</LI> 12570 * <LI>And possibly others.</LI> 12571 * </UL> 12572 * @return {@code true} if the overall data connection is allowed; {@code false} if not. 12573 * <p>Requires Permission: 12574 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} or 12575 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE} or 12576 * android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE 12577 */ 12578 @RequiresPermission(anyOf = {android.Manifest.permission.ACCESS_NETWORK_STATE, 12579 android.Manifest.permission.READ_PHONE_STATE, 12580 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE}) isDataConnectionAllowed()12581 public boolean isDataConnectionAllowed() { 12582 boolean retVal = false; 12583 try { 12584 int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId()); 12585 ITelephony telephony = getITelephony(); 12586 if (telephony != null) 12587 retVal = telephony.isDataEnabled(subId); 12588 } catch (RemoteException e) { 12589 Log.e(TAG, "Error isDataConnectionAllowed", e); 12590 } 12591 return retVal; 12592 } 12593 12594 /** 12595 * @return true if the current device is "data capable" over a radio on the device. 12596 * <p> 12597 * "Data capable" means that this device supports packet-switched 12598 * data connections over the telephony network. 12599 * <p> 12600 */ isDataCapable()12601 public boolean isDataCapable() { 12602 if (mContext == null) return true; 12603 return mContext.getResources().getBoolean( 12604 com.android.internal.R.bool.config_mobile_data_capable); 12605 } 12606 12607 /** 12608 * The indication for signal strength update. 12609 * @hide 12610 */ 12611 public static final int INDICATION_FILTER_SIGNAL_STRENGTH = 0x1; 12612 12613 /** 12614 * The indication for full network state update. 12615 * @hide 12616 */ 12617 public static final int INDICATION_FILTER_FULL_NETWORK_STATE = 0x2; 12618 12619 /** 12620 * The indication for data call dormancy changed update. 12621 * @hide 12622 */ 12623 public static final int INDICATION_FILTER_DATA_CALL_DORMANCY_CHANGED = 0x4; 12624 12625 /** 12626 * The indication for link capacity estimate update. 12627 * @hide 12628 */ 12629 public static final int INDICATION_FILTER_LINK_CAPACITY_ESTIMATE = 0x8; 12630 12631 /** 12632 * The indication for physical channel config update. 12633 * @hide 12634 */ 12635 public static final int INDICATION_FILTER_PHYSICAL_CHANNEL_CONFIG = 0x10; 12636 12637 /** 12638 * A test API to override carrier information including mccmnc, imsi, iccid, gid1, gid2, 12639 * plmn and spn. This would be handy for, eg, forcing a particular carrier id, carrier's config 12640 * (also any country or carrier overlays) to be loaded when using a test SIM with a call box. 12641 * 12642 * <p>Requires Permission: 12643 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 12644 * 12645 * 12646 * @deprecated 12647 * @hide 12648 */ 12649 @Deprecated 12650 @TestApi setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, String gid2, String plmn, String spn)12651 public void setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, 12652 String gid2, String plmn, String spn) { 12653 try { 12654 ITelephony telephony = getITelephony(); 12655 if (telephony != null) { 12656 telephony.setCarrierTestOverride( 12657 getSubId(), mccmnc, imsi, iccid, gid1, gid2, plmn, spn, 12658 null, null); 12659 } 12660 } catch (RemoteException ex) { 12661 // This could happen if binder process crashes. 12662 } 12663 } 12664 12665 /** 12666 * A test API to override carrier information including mccmnc, imsi, iccid, gid1, gid2, 12667 * plmn, spn, apn and carrier priviledge. This would be handy for, eg, forcing a particular 12668 * carrier id, carrier's config (also any country or carrier overlays) to be loaded when using 12669 * a test SIM with a call box. 12670 * 12671 * <p>Requires Permission: 12672 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 12673 * 12674 * @hide 12675 */ 12676 @TestApi setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, String gid2, String plmn, String spn, String carrierPriviledgeRules, String apn)12677 public void setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, 12678 String gid2, String plmn, String spn, 12679 String carrierPriviledgeRules, String apn) { 12680 try { 12681 ITelephony telephony = getITelephony(); 12682 if (telephony != null) { 12683 telephony.setCarrierTestOverride( 12684 getSubId(), mccmnc, imsi, iccid, gid1, gid2, plmn, spn, 12685 carrierPriviledgeRules, apn); 12686 } 12687 } catch (RemoteException ex) { 12688 // This could happen if binder process crashes. 12689 } 12690 } 12691 12692 /** 12693 * A test API to return installed carrier id list version 12694 * 12695 * <p>Requires Permission: 12696 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 12697 * 12698 * @hide 12699 */ 12700 @UnsupportedAppUsage 12701 @TestApi getCarrierIdListVersion()12702 public int getCarrierIdListVersion() { 12703 try { 12704 ITelephony telephony = getITelephony(); 12705 if (telephony != null) { 12706 return telephony.getCarrierIdListVersion(getSubId()); 12707 } 12708 } catch (RemoteException ex) { 12709 // This could happen if binder process crashes. 12710 } 12711 return UNKNOWN_CARRIER_ID_LIST_VERSION; 12712 } 12713 12714 /** 12715 * How many modems can have simultaneous data connections. 12716 * @hide 12717 */ 12718 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getNumberOfModemsWithSimultaneousDataConnections()12719 public int getNumberOfModemsWithSimultaneousDataConnections() { 12720 try { 12721 ITelephony telephony = getITelephony(); 12722 if (telephony != null) { 12723 return telephony.getNumberOfModemsWithSimultaneousDataConnections( 12724 getSubId(), getOpPackageName(), getAttributionTag()); 12725 } 12726 } catch (RemoteException ex) { 12727 // This could happen if binder process crashes. 12728 } 12729 return 0; 12730 } 12731 12732 /** 12733 * Enable or disable OpportunisticNetworkService. 12734 * 12735 * This method should be called to enable or disable 12736 * OpportunisticNetwork service on the device. 12737 * 12738 * <p> 12739 * Requires Permission: 12740 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 12741 * 12742 * @param enable enable(True) or disable(False) 12743 * @return returns true if successfully set. 12744 * @hide 12745 */ 12746 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 12747 @SystemApi setOpportunisticNetworkState(boolean enable)12748 public boolean setOpportunisticNetworkState(boolean enable) { 12749 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 12750 boolean ret = false; 12751 try { 12752 IOns iOpportunisticNetworkService = getIOns(); 12753 if (iOpportunisticNetworkService != null) { 12754 ret = iOpportunisticNetworkService.setEnable(enable, pkgForDebug); 12755 } 12756 } catch (RemoteException ex) { 12757 Rlog.e(TAG, "enableOpportunisticNetwork RemoteException", ex); 12758 } 12759 12760 return ret; 12761 } 12762 12763 /** 12764 * is OpportunisticNetworkService enabled 12765 * 12766 * This method should be called to determine if the OpportunisticNetworkService is 12767 * enabled 12768 * 12769 * <p> 12770 * Requires Permission: 12771 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 12772 * @hide 12773 */ 12774 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 12775 @SystemApi isOpportunisticNetworkEnabled()12776 public boolean isOpportunisticNetworkEnabled() { 12777 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 12778 boolean isEnabled = false; 12779 12780 try { 12781 IOns iOpportunisticNetworkService = getIOns(); 12782 if (iOpportunisticNetworkService != null) { 12783 isEnabled = iOpportunisticNetworkService.isEnabled(pkgForDebug); 12784 } 12785 } catch (RemoteException ex) { 12786 Rlog.e(TAG, "enableOpportunisticNetwork RemoteException", ex); 12787 } 12788 12789 return isEnabled; 12790 } 12791 12792 /** @hide */ 12793 @Retention(RetentionPolicy.SOURCE) 12794 @LongDef(flag = true, prefix = {"NETWORK_TYPE_BITMASK_"}, 12795 value = {NETWORK_TYPE_BITMASK_UNKNOWN, 12796 NETWORK_TYPE_BITMASK_GSM, 12797 NETWORK_TYPE_BITMASK_GPRS, 12798 NETWORK_TYPE_BITMASK_EDGE, 12799 NETWORK_TYPE_BITMASK_CDMA, 12800 NETWORK_TYPE_BITMASK_1xRTT, 12801 NETWORK_TYPE_BITMASK_EVDO_0, 12802 NETWORK_TYPE_BITMASK_EVDO_A, 12803 NETWORK_TYPE_BITMASK_EVDO_B, 12804 NETWORK_TYPE_BITMASK_EHRPD, 12805 NETWORK_TYPE_BITMASK_HSUPA, 12806 NETWORK_TYPE_BITMASK_HSDPA, 12807 NETWORK_TYPE_BITMASK_HSPA, 12808 NETWORK_TYPE_BITMASK_HSPAP, 12809 NETWORK_TYPE_BITMASK_UMTS, 12810 NETWORK_TYPE_BITMASK_TD_SCDMA, 12811 NETWORK_TYPE_BITMASK_LTE, 12812 NETWORK_TYPE_BITMASK_LTE_CA, 12813 NETWORK_TYPE_BITMASK_NR, 12814 NETWORK_TYPE_BITMASK_IWLAN 12815 }) 12816 public @interface NetworkTypeBitMask {} 12817 12818 // 2G 12819 /** 12820 * network type bitmask unknown. 12821 * @hide 12822 */ 12823 @SystemApi 12824 public static final long NETWORK_TYPE_BITMASK_UNKNOWN = 0L; 12825 /** 12826 * network type bitmask indicating the support of radio tech GSM. 12827 * @hide 12828 */ 12829 @SystemApi 12830 public static final long NETWORK_TYPE_BITMASK_GSM = (1 << (NETWORK_TYPE_GSM -1)); 12831 /** 12832 * network type bitmask indicating the support of radio tech GPRS. 12833 * @hide 12834 */ 12835 @SystemApi 12836 public static final long NETWORK_TYPE_BITMASK_GPRS = (1 << (NETWORK_TYPE_GPRS -1)); 12837 /** 12838 * network type bitmask indicating the support of radio tech EDGE. 12839 * @hide 12840 */ 12841 @SystemApi 12842 public static final long NETWORK_TYPE_BITMASK_EDGE = (1 << (NETWORK_TYPE_EDGE -1)); 12843 /** 12844 * network type bitmask indicating the support of radio tech CDMA(IS95A/IS95B). 12845 * @hide 12846 */ 12847 @SystemApi 12848 public static final long NETWORK_TYPE_BITMASK_CDMA = (1 << (NETWORK_TYPE_CDMA -1)); 12849 /** 12850 * network type bitmask indicating the support of radio tech 1xRTT. 12851 * @hide 12852 */ 12853 @SystemApi 12854 public static final long NETWORK_TYPE_BITMASK_1xRTT = (1 << (NETWORK_TYPE_1xRTT - 1)); 12855 // 3G 12856 /** 12857 * network type bitmask indicating the support of radio tech EVDO 0. 12858 * @hide 12859 */ 12860 @SystemApi 12861 public static final long NETWORK_TYPE_BITMASK_EVDO_0 = (1 << (NETWORK_TYPE_EVDO_0 -1)); 12862 /** 12863 * network type bitmask indicating the support of radio tech EVDO A. 12864 * @hide 12865 */ 12866 @SystemApi 12867 public static final long NETWORK_TYPE_BITMASK_EVDO_A = (1 << (NETWORK_TYPE_EVDO_A - 1)); 12868 /** 12869 * network type bitmask indicating the support of radio tech EVDO B. 12870 * @hide 12871 */ 12872 @SystemApi 12873 public static final long NETWORK_TYPE_BITMASK_EVDO_B = (1 << (NETWORK_TYPE_EVDO_B -1)); 12874 /** 12875 * network type bitmask indicating the support of radio tech EHRPD. 12876 * @hide 12877 */ 12878 @SystemApi 12879 public static final long NETWORK_TYPE_BITMASK_EHRPD = (1 << (NETWORK_TYPE_EHRPD -1)); 12880 /** 12881 * network type bitmask indicating the support of radio tech HSUPA. 12882 * @hide 12883 */ 12884 @SystemApi 12885 public static final long NETWORK_TYPE_BITMASK_HSUPA = (1 << (NETWORK_TYPE_HSUPA -1)); 12886 /** 12887 * network type bitmask indicating the support of radio tech HSDPA. 12888 * @hide 12889 */ 12890 @SystemApi 12891 public static final long NETWORK_TYPE_BITMASK_HSDPA = (1 << (NETWORK_TYPE_HSDPA -1)); 12892 /** 12893 * network type bitmask indicating the support of radio tech HSPA. 12894 * @hide 12895 */ 12896 @SystemApi 12897 public static final long NETWORK_TYPE_BITMASK_HSPA = (1 << (NETWORK_TYPE_HSPA -1)); 12898 /** 12899 * network type bitmask indicating the support of radio tech HSPAP. 12900 * @hide 12901 */ 12902 @SystemApi 12903 public static final long NETWORK_TYPE_BITMASK_HSPAP = (1 << (NETWORK_TYPE_HSPAP -1)); 12904 /** 12905 * network type bitmask indicating the support of radio tech UMTS. 12906 * @hide 12907 */ 12908 @SystemApi 12909 public static final long NETWORK_TYPE_BITMASK_UMTS = (1 << (NETWORK_TYPE_UMTS -1)); 12910 /** 12911 * network type bitmask indicating the support of radio tech TD_SCDMA. 12912 * @hide 12913 */ 12914 @SystemApi 12915 public static final long NETWORK_TYPE_BITMASK_TD_SCDMA = (1 << (NETWORK_TYPE_TD_SCDMA -1)); 12916 // 4G 12917 /** 12918 * network type bitmask indicating the support of radio tech LTE. 12919 * @hide 12920 */ 12921 @SystemApi 12922 public static final long NETWORK_TYPE_BITMASK_LTE = (1 << (NETWORK_TYPE_LTE -1)); 12923 /** 12924 * network type bitmask indicating the support of radio tech LTE CA (carrier aggregation). 12925 * @hide 12926 */ 12927 @SystemApi 12928 public static final long NETWORK_TYPE_BITMASK_LTE_CA = (1 << (NETWORK_TYPE_LTE_CA -1)); 12929 12930 /** 12931 * network type bitmask indicating the support of radio tech NR(New Radio) 5G. 12932 * @hide 12933 */ 12934 @SystemApi 12935 public static final long NETWORK_TYPE_BITMASK_NR = (1 << (NETWORK_TYPE_NR -1)); 12936 12937 /** 12938 * network type bitmask indicating the support of radio tech IWLAN. 12939 * @hide 12940 */ 12941 @SystemApi 12942 public static final long NETWORK_TYPE_BITMASK_IWLAN = (1 << (NETWORK_TYPE_IWLAN -1)); 12943 12944 /** @hide */ 12945 public static final long NETWORK_CLASS_BITMASK_2G = NETWORK_TYPE_BITMASK_GSM 12946 | NETWORK_TYPE_BITMASK_GPRS 12947 | NETWORK_TYPE_BITMASK_EDGE 12948 | NETWORK_TYPE_BITMASK_CDMA 12949 | NETWORK_TYPE_BITMASK_1xRTT; 12950 12951 /** @hide */ 12952 public static final long NETWORK_CLASS_BITMASK_3G = NETWORK_TYPE_BITMASK_EVDO_0 12953 | NETWORK_TYPE_BITMASK_EVDO_A 12954 | NETWORK_TYPE_BITMASK_EVDO_B 12955 | NETWORK_TYPE_BITMASK_EHRPD 12956 | NETWORK_TYPE_BITMASK_HSUPA 12957 | NETWORK_TYPE_BITMASK_HSDPA 12958 | NETWORK_TYPE_BITMASK_HSPA 12959 | NETWORK_TYPE_BITMASK_HSPAP 12960 | NETWORK_TYPE_BITMASK_UMTS 12961 | NETWORK_TYPE_BITMASK_TD_SCDMA; 12962 12963 /** @hide */ 12964 public static final long NETWORK_CLASS_BITMASK_4G = NETWORK_TYPE_BITMASK_LTE 12965 | NETWORK_TYPE_BITMASK_LTE_CA 12966 | NETWORK_TYPE_BITMASK_IWLAN; 12967 12968 /** @hide */ 12969 public static final long NETWORK_CLASS_BITMASK_5G = NETWORK_TYPE_BITMASK_NR; 12970 12971 /** @hide */ 12972 public static final long NETWORK_STANDARDS_FAMILY_BITMASK_3GPP = NETWORK_TYPE_BITMASK_GSM 12973 | NETWORK_TYPE_BITMASK_GPRS 12974 | NETWORK_TYPE_BITMASK_EDGE 12975 | NETWORK_TYPE_BITMASK_HSUPA 12976 | NETWORK_TYPE_BITMASK_HSDPA 12977 | NETWORK_TYPE_BITMASK_HSPA 12978 | NETWORK_TYPE_BITMASK_HSPAP 12979 | NETWORK_TYPE_BITMASK_UMTS 12980 | NETWORK_TYPE_BITMASK_TD_SCDMA 12981 | NETWORK_TYPE_BITMASK_LTE 12982 | NETWORK_TYPE_BITMASK_LTE_CA 12983 | NETWORK_TYPE_BITMASK_NR; 12984 12985 /** @hide */ 12986 public static final long NETWORK_STANDARDS_FAMILY_BITMASK_3GPP2 = NETWORK_TYPE_BITMASK_CDMA 12987 | NETWORK_TYPE_BITMASK_1xRTT 12988 | NETWORK_TYPE_BITMASK_EVDO_0 12989 | NETWORK_TYPE_BITMASK_EVDO_A 12990 | NETWORK_TYPE_BITMASK_EVDO_B 12991 | NETWORK_TYPE_BITMASK_EHRPD; 12992 12993 /** 12994 * @return Modem supported radio access family bitmask 12995 * 12996 * <p>Requires permission: {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} or 12997 * that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 12998 * @hide 12999 */ 13000 @SystemApi 13001 @TestApi 13002 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getSupportedRadioAccessFamily()13003 public @NetworkTypeBitMask long getSupportedRadioAccessFamily() { 13004 try { 13005 ITelephony telephony = getITelephony(); 13006 if (telephony != null) { 13007 return telephony.getRadioAccessFamily(getSlotIndex(), getOpPackageName()); 13008 } else { 13009 // This can happen when the ITelephony interface is not up yet. 13010 return NETWORK_TYPE_BITMASK_UNKNOWN; 13011 } 13012 } catch (RemoteException ex) { 13013 // This shouldn't happen in the normal case 13014 return NETWORK_TYPE_BITMASK_UNKNOWN; 13015 } catch (NullPointerException ex) { 13016 // This could happen before phone restarts due to crashing 13017 return NETWORK_TYPE_BITMASK_UNKNOWN; 13018 } 13019 } 13020 13021 /** 13022 * Indicates Emergency number database version is invalid. 13023 * 13024 * @hide 13025 */ 13026 @SystemApi 13027 public static final int INVALID_EMERGENCY_NUMBER_DB_VERSION = -1; 13028 13029 /** 13030 * Notify Telephony for OTA emergency number database installation complete. 13031 * 13032 * <p> Requires permission: 13033 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 13034 * 13035 * @hide 13036 */ 13037 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 13038 @SystemApi notifyOtaEmergencyNumberDbInstalled()13039 public void notifyOtaEmergencyNumberDbInstalled() { 13040 try { 13041 ITelephony telephony = getITelephony(); 13042 if (telephony != null) { 13043 telephony.notifyOtaEmergencyNumberDbInstalled(); 13044 } else { 13045 throw new IllegalStateException("telephony service is null."); 13046 } 13047 } catch (RemoteException ex) { 13048 Log.e(TAG, "notifyOtaEmergencyNumberDatabaseInstalled RemoteException", ex); 13049 ex.rethrowAsRuntimeException(); 13050 } 13051 } 13052 13053 /** 13054 * Override the file path for OTA emergency number database in a file partition. 13055 * 13056 * @param otaParcelFileDescriptor parcelable file descriptor for OTA emergency number database. 13057 * 13058 * <p> Requires permission: 13059 * {@link android.Manifest.permission#READ_ACTIVE_EMERGENCY_SESSION} 13060 * 13061 * @hide 13062 */ 13063 @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) 13064 @SystemApi updateOtaEmergencyNumberDbFilePath( @onNull ParcelFileDescriptor otaParcelFileDescriptor)13065 public void updateOtaEmergencyNumberDbFilePath( 13066 @NonNull ParcelFileDescriptor otaParcelFileDescriptor) { 13067 try { 13068 ITelephony telephony = getITelephony(); 13069 if (telephony != null) { 13070 telephony.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); 13071 } else { 13072 throw new IllegalStateException("telephony service is null."); 13073 } 13074 } catch (RemoteException ex) { 13075 Log.e(TAG, "updateOtaEmergencyNumberDbFilePath RemoteException", ex); 13076 ex.rethrowAsRuntimeException(); 13077 } 13078 } 13079 13080 /** 13081 * Reset the file path to default for OTA emergency number database in a file partition. 13082 * 13083 * <p> Requires permission: 13084 * {@link android.Manifest.permission#READ_ACTIVE_EMERGENCY_SESSION} 13085 * 13086 * @hide 13087 */ 13088 @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) 13089 @SystemApi resetOtaEmergencyNumberDbFilePath()13090 public void resetOtaEmergencyNumberDbFilePath() { 13091 try { 13092 ITelephony telephony = getITelephony(); 13093 if (telephony != null) { 13094 telephony.resetOtaEmergencyNumberDbFilePath(); 13095 } else { 13096 throw new IllegalStateException("telephony service is null."); 13097 } 13098 } catch (RemoteException ex) { 13099 Log.e(TAG, "resetOtaEmergencyNumberDbFilePath RemoteException", ex); 13100 ex.rethrowAsRuntimeException(); 13101 } 13102 } 13103 13104 /** 13105 * Returns whether {@link TelephonyManager#ACTION_EMERGENCY_ASSISTANCE emergency assistance} is 13106 * available on the device. 13107 * <p> 13108 * Requires permission: {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} 13109 * 13110 * @return {@code true} if emergency assistance is available, {@code false} otherwise 13111 * 13112 * @hide 13113 */ 13114 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 13115 @SuppressWarnings("AndroidFrameworkClientSidePermissionCheck") 13116 @SystemApi isEmergencyAssistanceEnabled()13117 public boolean isEmergencyAssistanceEnabled() { 13118 mContext.enforceCallingOrSelfPermission( 13119 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 13120 "isEmergencyAssistanceEnabled"); 13121 return EMERGENCY_ASSISTANCE_ENABLED; 13122 } 13123 13124 /** 13125 * Get the emergency number list based on current locale, sim, default, modem and network. 13126 * 13127 * <p>In each returned list, the emergency number {@link EmergencyNumber} coming from higher 13128 * priority sources will be located at the smaller index; the priority order of sources are: 13129 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_NETWORK_SIGNALING} > 13130 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_SIM} > 13131 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_DATABASE} > 13132 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_DEFAULT} > 13133 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_MODEM_CONFIG} 13134 * 13135 * <p>The subscriptions which the returned list would be based on, are all the active 13136 * subscriptions, no matter which subscription could be used to create TelephonyManager. 13137 * 13138 * <p>Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling 13139 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 13140 * 13141 * @return Map including the keys as the active subscription IDs (Note: if there is no active 13142 * subscription, the key is {@link SubscriptionManager#getDefaultSubscriptionId}) and the value 13143 * as the list of {@link EmergencyNumber}; empty Map if this information is not available; 13144 * or throw a SecurityException if the caller does not have the permission. 13145 */ 13146 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 13147 @NonNull getEmergencyNumberList()13148 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList() { 13149 Map<Integer, List<EmergencyNumber>> emergencyNumberList = new HashMap<>(); 13150 try { 13151 ITelephony telephony = getITelephony(); 13152 if (telephony != null) { 13153 return telephony.getEmergencyNumberList(mContext.getOpPackageName(), 13154 mContext.getAttributionTag()); 13155 } else { 13156 throw new IllegalStateException("telephony service is null."); 13157 } 13158 } catch (RemoteException ex) { 13159 Log.e(TAG, "getEmergencyNumberList RemoteException", ex); 13160 ex.rethrowAsRuntimeException(); 13161 } 13162 return emergencyNumberList; 13163 } 13164 13165 /** 13166 * Get the per-category emergency number list based on current locale, sim, default, modem 13167 * and network. 13168 * 13169 * <p>In each returned list, the emergency number {@link EmergencyNumber} coming from higher 13170 * priority sources will be located at the smaller index; the priority order of sources are: 13171 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_NETWORK_SIGNALING} > 13172 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_SIM} > 13173 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_DATABASE} > 13174 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_DEFAULT} > 13175 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_MODEM_CONFIG} 13176 * 13177 * <p>The subscriptions which the returned list would be based on, are all the active 13178 * subscriptions, no matter which subscription could be used to create TelephonyManager. 13179 * 13180 * <p>Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling 13181 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 13182 * 13183 * @param categories the emergency service categories which are the bitwise-OR combination of 13184 * the following constants: 13185 * <ol> 13186 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED} </li> 13187 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_POLICE} </li> 13188 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_AMBULANCE} </li> 13189 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_FIRE_BRIGADE} </li> 13190 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_MARINE_GUARD} </li> 13191 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_MOUNTAIN_RESCUE} </li> 13192 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_MIEC} </li> 13193 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_AIEC} </li> 13194 * </ol> 13195 * @return Map including the keys as the active subscription IDs (Note: if there is no active 13196 * subscription, the key is {@link SubscriptionManager#getDefaultSubscriptionId}) and the value 13197 * as the list of {@link EmergencyNumber}; empty Map if this information is not available; 13198 * or throw a SecurityException if the caller does not have the permission. 13199 * @throws IllegalStateException if the Telephony process is not currently available. 13200 */ 13201 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 13202 @NonNull getEmergencyNumberList( @mergencyServiceCategories int categories)13203 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( 13204 @EmergencyServiceCategories int categories) { 13205 Map<Integer, List<EmergencyNumber>> emergencyNumberListForCategories = new HashMap<>(); 13206 try { 13207 ITelephony telephony = getITelephony(); 13208 if (telephony != null) { 13209 Map<Integer, List<EmergencyNumber>> emergencyNumberList = 13210 telephony.getEmergencyNumberList(mContext.getOpPackageName(), 13211 mContext.getAttributionTag()); 13212 emergencyNumberListForCategories = 13213 filterEmergencyNumbersByCategories(emergencyNumberList, categories); 13214 } else { 13215 throw new IllegalStateException("telephony service is null."); 13216 } 13217 } catch (RemoteException ex) { 13218 Log.e(TAG, "getEmergencyNumberList with Categories RemoteException", ex); 13219 ex.rethrowAsRuntimeException(); 13220 } 13221 return emergencyNumberListForCategories; 13222 } 13223 13224 /** 13225 * Filter emergency numbers with categories. 13226 * 13227 * @hide 13228 */ 13229 @VisibleForTesting filterEmergencyNumbersByCategories( Map<Integer, List<EmergencyNumber>> emergencyNumberList, @EmergencyServiceCategories int categories)13230 public Map<Integer, List<EmergencyNumber>> filterEmergencyNumbersByCategories( 13231 Map<Integer, List<EmergencyNumber>> emergencyNumberList, 13232 @EmergencyServiceCategories int categories) { 13233 Map<Integer, List<EmergencyNumber>> emergencyNumberListForCategories = new HashMap<>(); 13234 if (emergencyNumberList != null) { 13235 for (Integer subscriptionId : emergencyNumberList.keySet()) { 13236 List<EmergencyNumber> allNumbersForSub = emergencyNumberList.get( 13237 subscriptionId); 13238 List<EmergencyNumber> numbersForCategoriesPerSub = new ArrayList<>(); 13239 for (EmergencyNumber number : allNumbersForSub) { 13240 if (number.isInEmergencyServiceCategories(categories)) { 13241 numbersForCategoriesPerSub.add(number); 13242 } 13243 } 13244 emergencyNumberListForCategories.put( 13245 subscriptionId, numbersForCategoriesPerSub); 13246 } 13247 } 13248 return emergencyNumberListForCategories; 13249 } 13250 13251 /** 13252 * Identifies if the supplied phone number is an emergency number that matches a known 13253 * emergency number based on current locale, SIM card(s), Android database, modem, network, 13254 * or defaults. 13255 * 13256 * <p>This method assumes that only dialable phone numbers are passed in; non-dialable 13257 * numbers are not considered emergency numbers. A dialable phone number consists only 13258 * of characters/digits identified by {@link PhoneNumberUtils#isDialable(char)}. 13259 * 13260 * <p>The subscriptions which the identification would be based on, are all the active 13261 * subscriptions, no matter which subscription could be used to create TelephonyManager. 13262 * 13263 * @param number - the number to look up 13264 * @return {@code true} if the given number is an emergency number based on current locale, 13265 * SIM card(s), Android database, modem, network or defaults; {@code false} otherwise. 13266 * @throws IllegalStateException if the Telephony process is not currently available. 13267 */ isEmergencyNumber(@onNull String number)13268 public boolean isEmergencyNumber(@NonNull String number) { 13269 try { 13270 ITelephony telephony = getITelephony(); 13271 if (telephony != null) { 13272 return telephony.isEmergencyNumber(number, true); 13273 } else { 13274 throw new IllegalStateException("telephony service is null."); 13275 } 13276 } catch (RemoteException ex) { 13277 Log.e(TAG, "isEmergencyNumber RemoteException", ex); 13278 ex.rethrowAsRuntimeException(); 13279 } 13280 return false; 13281 } 13282 13283 /** 13284 * Checks if the supplied number is an emergency number based on current locale, sim, default, 13285 * modem and network. 13286 * 13287 * <p> Specifically, this method will return {@code true} if the specified number is an 13288 * emergency number, *or* if the number simply starts with the same digits as any current 13289 * emergency number. 13290 * 13291 * <p>The subscriptions which the identification would be based on, are all the active 13292 * subscriptions, no matter which subscription could be used to create TelephonyManager. 13293 * 13294 * <p>Requires permission: {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} or 13295 * that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 13296 * 13297 * @param number - the number to look up 13298 * @return {@code true} if the given number is an emergency number or it simply starts with 13299 * the same digits of any current emergency number based on current locale, sim, modem and 13300 * network; {@code false} if it is not; or throw an SecurityException if the caller does not 13301 * have the required permission/privileges 13302 * @throws IllegalStateException if the Telephony process is not currently available. 13303 * @hide 13304 */ 13305 @SystemApi 13306 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) isPotentialEmergencyNumber(@onNull String number)13307 public boolean isPotentialEmergencyNumber(@NonNull String number) { 13308 try { 13309 ITelephony telephony = getITelephony(); 13310 if (telephony != null) { 13311 return telephony.isEmergencyNumber(number, false); 13312 } else { 13313 throw new IllegalStateException("telephony service is null."); 13314 } 13315 } catch (RemoteException ex) { 13316 Log.e(TAG, "isEmergencyNumber RemoteException", ex); 13317 ex.rethrowAsRuntimeException(); 13318 } 13319 return false; 13320 } 13321 13322 /** 13323 * Returns the emergency number database version. 13324 * 13325 * <p>Requires Permission: 13326 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 13327 * 13328 * @hide 13329 */ 13330 @SystemApi 13331 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getEmergencyNumberDbVersion()13332 public int getEmergencyNumberDbVersion() { 13333 try { 13334 ITelephony telephony = getITelephony(); 13335 if (telephony != null) { 13336 return telephony.getEmergencyNumberDbVersion(getSubId()); 13337 } 13338 } catch (RemoteException ex) { 13339 Log.e(TAG, "getEmergencyNumberDbVersion RemoteException", ex); 13340 ex.rethrowAsRuntimeException(); 13341 } 13342 return INVALID_EMERGENCY_NUMBER_DB_VERSION; 13343 } 13344 13345 /** @hide */ 13346 @Retention(RetentionPolicy.SOURCE) 13347 @IntDef(prefix = {"SET_OPPORTUNISTIC_SUB"}, value = { 13348 SET_OPPORTUNISTIC_SUB_SUCCESS, 13349 SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED, 13350 SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION, 13351 SET_OPPORTUNISTIC_SUB_NO_OPPORTUNISTIC_SUB_AVAILABLE, 13352 SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION}) 13353 public @interface SetOpportunisticSubscriptionResult {} 13354 13355 /** 13356 * No error. Operation succeeded. 13357 */ 13358 public static final int SET_OPPORTUNISTIC_SUB_SUCCESS = 0; 13359 13360 /** 13361 * Validation failed when trying to switch to preferred subscription. 13362 */ 13363 public static final int SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED = 1; 13364 13365 /** 13366 * The subscription is not valid. It must be an active opportunistic subscription. 13367 */ 13368 public static final int SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION = 2; 13369 13370 /** 13371 * The subscription is not valid. It must be an opportunistic subscription. 13372 */ 13373 public static final int SET_OPPORTUNISTIC_SUB_NO_OPPORTUNISTIC_SUB_AVAILABLE = 3; 13374 13375 /** 13376 * Subscription service happened remote exception. 13377 */ 13378 public static final int SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION = 4; 13379 13380 13381 /** @hide */ 13382 @Retention(RetentionPolicy.SOURCE) 13383 @IntDef(prefix = {"UPDATE_AVAILABLE_NETWORKS"}, value = { 13384 UPDATE_AVAILABLE_NETWORKS_SUCCESS, 13385 UPDATE_AVAILABLE_NETWORKS_UNKNOWN_FAILURE, 13386 UPDATE_AVAILABLE_NETWORKS_ABORTED, 13387 UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS, 13388 UPDATE_AVAILABLE_NETWORKS_NO_CARRIER_PRIVILEGE, 13389 UPDATE_AVAILABLE_NETWORKS_DISABLE_MODEM_FAIL, 13390 UPDATE_AVAILABLE_NETWORKS_ENABLE_MODEM_FAIL, 13391 UPDATE_AVAILABLE_NETWORKS_MULTIPLE_NETWORKS_NOT_SUPPORTED, 13392 UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE, 13393 UPDATE_AVAILABLE_NETWORKS_REMOTE_SERVICE_EXCEPTION, 13394 UPDATE_AVAILABLE_NETWORKS_SERVICE_IS_DISABLED}) 13395 public @interface UpdateAvailableNetworksResult {} 13396 13397 /** 13398 * No error. Operation succeeded. 13399 */ 13400 public static final int UPDATE_AVAILABLE_NETWORKS_SUCCESS = 0; 13401 13402 /** 13403 * There is a unknown failure happened. 13404 */ 13405 public static final int UPDATE_AVAILABLE_NETWORKS_UNKNOWN_FAILURE = 1; 13406 13407 /** 13408 * The request is aborted. 13409 */ 13410 public static final int UPDATE_AVAILABLE_NETWORKS_ABORTED = 2; 13411 13412 /** 13413 * The parameter passed in is invalid. 13414 */ 13415 public static final int UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS = 3; 13416 13417 /** 13418 * No carrier privilege. 13419 */ 13420 public static final int UPDATE_AVAILABLE_NETWORKS_NO_CARRIER_PRIVILEGE = 4; 13421 13422 /** 13423 * Disable modem fail. 13424 */ 13425 public static final int UPDATE_AVAILABLE_NETWORKS_DISABLE_MODEM_FAIL = 5; 13426 13427 /** 13428 * Enable modem fail. 13429 */ 13430 public static final int UPDATE_AVAILABLE_NETWORKS_ENABLE_MODEM_FAIL = 6; 13431 13432 /** 13433 * Carrier app does not support multiple available networks. 13434 */ 13435 public static final int UPDATE_AVAILABLE_NETWORKS_MULTIPLE_NETWORKS_NOT_SUPPORTED = 7; 13436 13437 /** 13438 * The subscription is not valid. It must be an opportunistic subscription. 13439 */ 13440 public static final int UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE = 8; 13441 13442 /** 13443 * There is no OpportunisticNetworkService. 13444 */ 13445 public static final int UPDATE_AVAILABLE_NETWORKS_REMOTE_SERVICE_EXCEPTION = 9; 13446 13447 /** 13448 * OpportunisticNetworkService is disabled. 13449 */ 13450 public static final int UPDATE_AVAILABLE_NETWORKS_SERVICE_IS_DISABLED = 10; 13451 13452 /** 13453 * Set preferred opportunistic data subscription id. 13454 * 13455 * Switch internet data to preferred opportunistic data subscription id. This api 13456 * can result in lose of internet connectivity for short period of time while internet data 13457 * is handed over. 13458 * <p>Requires that the calling app has carrier privileges on both primary and 13459 * secondary subscriptions (see 13460 * {@link #hasCarrierPrivileges}), or has permission 13461 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 13462 * 13463 * @param subId which opportunistic subscription 13464 * {@link SubscriptionManager#getOpportunisticSubscriptions} is preferred for cellular data. 13465 * Pass {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} to unset the preference 13466 * @param needValidation whether validation is needed before switch happens. 13467 * @param executor The executor of where the callback will execute. 13468 * @param callback Callback will be triggered once it succeeds or failed. 13469 * See {@link TelephonyManager.SetOpportunisticSubscriptionResult} 13470 * for more details. Pass null if don't care about the result. 13471 */ setPreferredOpportunisticDataSubscription(int subId, boolean needValidation, @Nullable @CallbackExecutor Executor executor, @Nullable Consumer<Integer> callback)13472 public void setPreferredOpportunisticDataSubscription(int subId, boolean needValidation, 13473 @Nullable @CallbackExecutor Executor executor, @Nullable Consumer<Integer> callback) { 13474 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 13475 try { 13476 IOns iOpportunisticNetworkService = getIOns(); 13477 if (iOpportunisticNetworkService == null) { 13478 if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) { 13479 throw new IllegalStateException("Opportunistic Network Service is null"); 13480 } else { 13481 // Let the general remote exception handling catch this. 13482 throw new RemoteException("Null Opportunistic Network Service!"); 13483 } 13484 } 13485 ISetOpportunisticDataCallback callbackStub = new ISetOpportunisticDataCallback.Stub() { 13486 @Override 13487 public void onComplete(int result) { 13488 if (executor == null || callback == null) { 13489 return; 13490 } 13491 final long identity = Binder.clearCallingIdentity(); 13492 try { 13493 executor.execute(() -> { 13494 callback.accept(result); 13495 }); 13496 } finally { 13497 Binder.restoreCallingIdentity(identity); 13498 } 13499 } 13500 }; 13501 13502 iOpportunisticNetworkService 13503 .setPreferredDataSubscriptionId(subId, needValidation, callbackStub, 13504 pkgForDebug); 13505 } catch (RemoteException ex) { 13506 Rlog.e(TAG, "setPreferredOpportunisticDataSubscription RemoteException", ex); 13507 if (executor == null || callback == null) { 13508 return; 13509 } 13510 runOnBackgroundThread(() -> executor.execute(() -> { 13511 if (Compatibility.isChangeEnabled(CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { 13512 callback.accept(SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION); 13513 } else { 13514 callback.accept(SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION); 13515 } 13516 })); 13517 } 13518 } 13519 13520 /** 13521 * Get preferred opportunistic data subscription Id 13522 * 13523 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}), 13524 * or has either READ_PRIVILEGED_PHONE_STATE 13525 * or {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} permission. 13526 * @return subId preferred opportunistic subscription id or 13527 * {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} if there are no preferred 13528 * subscription id 13529 * 13530 */ 13531 @RequiresPermission(anyOf = { 13532 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 13533 android.Manifest.permission.READ_PHONE_STATE 13534 }) getPreferredOpportunisticDataSubscription()13535 public int getPreferredOpportunisticDataSubscription() { 13536 String packageName = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 13537 String attributionTag = mContext != null ? mContext.getAttributionTag() : null; 13538 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 13539 try { 13540 IOns iOpportunisticNetworkService = getIOns(); 13541 if (iOpportunisticNetworkService != null) { 13542 subId = iOpportunisticNetworkService.getPreferredDataSubscriptionId( 13543 packageName, attributionTag); 13544 } 13545 } catch (RemoteException ex) { 13546 Rlog.e(TAG, "getPreferredDataSubscriptionId RemoteException", ex); 13547 } 13548 return subId; 13549 } 13550 13551 /** 13552 * Update availability of a list of networks in the current location. 13553 * 13554 * This api should be called to inform OpportunisticNetwork Service about the availability 13555 * of a network at the current location. This information will be used by OpportunisticNetwork 13556 * service to enable modem stack and to attach to the network. If an empty list is passed, 13557 * it is assumed that no network is available and will result in disabling the modem stack 13558 * to save power. This api do not switch internet data once network attach is completed. 13559 * Use {@link TelephonyManager#setPreferredOpportunisticDataSubscription} 13560 * to switch internet data after network attach is complete. 13561 * Requires that the calling app has carrier privileges on both primary and 13562 * secondary subscriptions (see {@link #hasCarrierPrivileges}), or has permission 13563 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 13564 * @param availableNetworks is a list of available network information. 13565 * @param executor The executor of where the callback will execute. 13566 * @param callback Callback will be triggered once it succeeds or failed. 13567 * 13568 */ 13569 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges updateAvailableNetworks(@onNull List<AvailableNetworkInfo> availableNetworks, @Nullable @CallbackExecutor Executor executor, @UpdateAvailableNetworksResult @Nullable Consumer<Integer> callback)13570 public void updateAvailableNetworks(@NonNull List<AvailableNetworkInfo> availableNetworks, 13571 @Nullable @CallbackExecutor Executor executor, 13572 @UpdateAvailableNetworksResult @Nullable Consumer<Integer> callback) { 13573 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 13574 Objects.requireNonNull(availableNetworks, "availableNetworks must not be null."); 13575 try { 13576 IOns iOpportunisticNetworkService = getIOns(); 13577 if (iOpportunisticNetworkService == null) { 13578 if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) { 13579 throw new IllegalStateException("Opportunistic Network Service is null"); 13580 } else { 13581 // Let the general remote exception handling catch this. 13582 throw new RemoteException("Null Opportunistic Network Service!"); 13583 } 13584 } 13585 13586 IUpdateAvailableNetworksCallback callbackStub = 13587 new IUpdateAvailableNetworksCallback.Stub() { 13588 @Override 13589 public void onComplete(int result) { 13590 if (executor == null || callback == null) { 13591 return; 13592 } 13593 Binder.withCleanCallingIdentity(() -> { 13594 executor.execute(() -> callback.accept(result)); 13595 }); 13596 } 13597 }; 13598 iOpportunisticNetworkService 13599 .updateAvailableNetworks(availableNetworks, callbackStub, pkgForDebug); 13600 } catch (RemoteException ex) { 13601 Rlog.e(TAG, "updateAvailableNetworks RemoteException", ex); 13602 if (executor == null || callback == null) { 13603 return; 13604 } 13605 runOnBackgroundThread(() -> executor.execute(() -> { 13606 if (Compatibility.isChangeEnabled(CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { 13607 callback.accept(UPDATE_AVAILABLE_NETWORKS_REMOTE_SERVICE_EXCEPTION); 13608 } else { 13609 callback.accept(UPDATE_AVAILABLE_NETWORKS_UNKNOWN_FAILURE); 13610 } 13611 })); 13612 } 13613 } 13614 13615 /** 13616 * Enable or disable a logical modem stack. When a logical modem is disabled, the corresponding 13617 * SIM will still be visible to the user but its mapping modem will not have any radio activity. 13618 * For example, we will disable a modem when user or system believes the corresponding SIM 13619 * is temporarily not needed (e.g. out of coverage), and will enable it back on when needed. 13620 * 13621 * Requires that the calling app has permission 13622 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 13623 * @param slotIndex which corresponding modem will operate on. 13624 * @param enable whether to enable or disable the modem stack. 13625 * @return whether the operation is successful. 13626 * 13627 * @hide 13628 */ 13629 @SystemApi 13630 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) enableModemForSlot(int slotIndex, boolean enable)13631 public boolean enableModemForSlot(int slotIndex, boolean enable) { 13632 boolean ret = false; 13633 try { 13634 ITelephony telephony = getITelephony(); 13635 if (telephony != null) { 13636 ret = telephony.enableModemForSlot(slotIndex, enable); 13637 } 13638 } catch (RemoteException ex) { 13639 Log.e(TAG, "enableModem RemoteException", ex); 13640 } 13641 return ret; 13642 } 13643 13644 /** 13645 * It indicates whether modem is enabled or not per slot. 13646 * It's the corresponding status of TelephonyManager.enableModemForSlot. 13647 * 13648 * <p>Requires Permission: 13649 * READ_PRIVILEGED_PHONE_STATE or 13650 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 13651 * @param slotIndex which slot it's checking. 13652 */ 13653 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) isModemEnabledForSlot(int slotIndex)13654 public boolean isModemEnabledForSlot(int slotIndex) { 13655 try { 13656 ITelephony telephony = getITelephony(); 13657 if (telephony != null) { 13658 return telephony.isModemEnabledForSlot(slotIndex, mContext.getOpPackageName(), 13659 mContext.getAttributionTag()); 13660 } 13661 } catch (RemoteException ex) { 13662 Log.e(TAG, "enableModem RemoteException", ex); 13663 } 13664 return false; 13665 } 13666 13667 /** 13668 * Broadcast intent action for network country code changes. 13669 * 13670 * <p> 13671 * The {@link #EXTRA_NETWORK_COUNTRY} extra indicates the country code of the current 13672 * network returned by {@link #getNetworkCountryIso()}. 13673 * 13674 * <p>There may be a delay of several minutes before reporting that no country is detected. 13675 * 13676 * @see #EXTRA_NETWORK_COUNTRY 13677 * @see #getNetworkCountryIso() 13678 */ 13679 public static final String ACTION_NETWORK_COUNTRY_CHANGED = 13680 "android.telephony.action.NETWORK_COUNTRY_CHANGED"; 13681 13682 /** 13683 * The extra used with an {@link #ACTION_NETWORK_COUNTRY_CHANGED} to specify the 13684 * the country code in ISO-3166-1 alpha-2 format. 13685 * <p class="note"> 13686 * Retrieve with {@link android.content.Intent#getStringExtra(String)}. 13687 */ 13688 public static final String EXTRA_NETWORK_COUNTRY = 13689 "android.telephony.extra.NETWORK_COUNTRY"; 13690 13691 /** 13692 * The extra used with an {@link #ACTION_NETWORK_COUNTRY_CHANGED} to specify the 13693 * last known the country code in ISO-3166-1 alpha-2 format. 13694 * <p class="note"> 13695 * Retrieve with {@link android.content.Intent#getStringExtra(String)}. 13696 * 13697 * @hide 13698 */ 13699 public static final String EXTRA_LAST_KNOWN_NETWORK_COUNTRY = 13700 "android.telephony.extra.LAST_KNOWN_NETWORK_COUNTRY"; 13701 13702 /** 13703 * Indicate if the user is allowed to use multiple SIM cards at the same time to register 13704 * on the network (e.g. Dual Standby or Dual Active) when the device supports it, or if the 13705 * usage is restricted. This API is used to prevent usage of multiple SIM card, based on 13706 * policies of the carrier. 13707 * <p>Note: the API does not prevent access to the SIM cards for operations that don't require 13708 * access to the network. 13709 * 13710 * @param isMultiSimCarrierRestricted true if usage of multiple SIMs is restricted, false 13711 * otherwise. 13712 * 13713 * @hide 13714 */ 13715 @SystemApi 13716 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted)13717 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { 13718 try { 13719 ITelephony service = getITelephony(); 13720 if (service != null) { 13721 service.setMultiSimCarrierRestriction(isMultiSimCarrierRestricted); 13722 } 13723 } catch (RemoteException e) { 13724 Log.e(TAG, "setMultiSimCarrierRestriction RemoteException", e); 13725 } 13726 } 13727 13728 /** 13729 * The usage of multiple SIM cards at the same time to register on the network (e.g. Dual 13730 * Standby or Dual Active) is supported. 13731 */ 13732 public static final int MULTISIM_ALLOWED = 0; 13733 13734 /** 13735 * The usage of multiple SIM cards at the same time to register on the network (e.g. Dual 13736 * Standby or Dual Active) is not supported by the hardware. 13737 */ 13738 public static final int MULTISIM_NOT_SUPPORTED_BY_HARDWARE = 1; 13739 13740 /** 13741 * The usage of multiple SIM cards at the same time to register on the network (e.g. Dual 13742 * Standby or Dual Active) is supported by the hardware, but restricted by the carrier. 13743 */ 13744 public static final int MULTISIM_NOT_SUPPORTED_BY_CARRIER = 2; 13745 13746 /** @hide */ 13747 @Retention(RetentionPolicy.SOURCE) 13748 @IntDef(prefix = {"MULTISIM_"}, 13749 value = { 13750 MULTISIM_ALLOWED, 13751 MULTISIM_NOT_SUPPORTED_BY_HARDWARE, 13752 MULTISIM_NOT_SUPPORTED_BY_CARRIER 13753 }) 13754 public @interface IsMultiSimSupportedResult {} 13755 13756 /** 13757 * Returns if the usage of multiple SIM cards at the same time to register on the network 13758 * (e.g. Dual Standby or Dual Active) is supported by the device and by the carrier. 13759 * 13760 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 13761 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 13762 * 13763 * @return {@link #MULTISIM_ALLOWED} if the device supports multiple SIMs. 13764 * {@link #MULTISIM_NOT_SUPPORTED_BY_HARDWARE} if the device does not support multiple SIMs. 13765 * {@link #MULTISIM_NOT_SUPPORTED_BY_CARRIER} in the device supports multiple SIMs, but the 13766 * functionality is restricted by the carrier. 13767 */ 13768 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 13769 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 13770 @IsMultiSimSupportedResult isMultiSimSupported()13771 public int isMultiSimSupported() { 13772 if (getSupportedModemCount() < 2) { 13773 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; 13774 } 13775 try { 13776 ITelephony service = getITelephony(); 13777 if (service != null) { 13778 return service.isMultiSimSupported(getOpPackageName(), getAttributionTag()); 13779 } 13780 } catch (RemoteException e) { 13781 Log.e(TAG, "isMultiSimSupported RemoteException", e); 13782 } 13783 return MULTISIM_NOT_SUPPORTED_BY_HARDWARE; 13784 } 13785 13786 /** 13787 * Switch configs to enable multi-sim or switch back to single-sim 13788 * <p>Requires Permission: 13789 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 13790 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 13791 * 13792 * Note: with only carrier privileges, it is not allowed to switch from multi-sim 13793 * to single-sim 13794 * 13795 * @param numOfSims number of live SIMs we want to switch to 13796 * @throws android.os.RemoteException 13797 */ 13798 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 13799 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) switchMultiSimConfig(int numOfSims)13800 public void switchMultiSimConfig(int numOfSims) { 13801 try { 13802 ITelephony telephony = getITelephony(); 13803 if (telephony != null) { 13804 telephony.switchMultiSimConfig(numOfSims); 13805 } 13806 } catch (RemoteException ex) { 13807 Rlog.e(TAG, "switchMultiSimConfig RemoteException", ex); 13808 } 13809 } 13810 13811 /** 13812 * Get whether making changes to modem configurations by {@link #switchMultiSimConfig(int)} will 13813 * trigger device reboot. 13814 * The modem configuration change refers to switching from single SIM configuration to DSDS 13815 * or the other way around. 13816 * 13817 * <p>Requires Permission: 13818 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} or that the 13819 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 13820 * 13821 * @return {@code true} if reboot will be triggered after making changes to modem 13822 * configurations, otherwise return {@code false}. 13823 */ 13824 @RequiresPermission(Manifest.permission.READ_PHONE_STATE) doesSwitchMultiSimConfigTriggerReboot()13825 public boolean doesSwitchMultiSimConfigTriggerReboot() { 13826 try { 13827 ITelephony service = getITelephony(); 13828 if (service != null) { 13829 return service.doesSwitchMultiSimConfigTriggerReboot(getSubId(), 13830 getOpPackageName(), getAttributionTag()); 13831 } 13832 } catch (RemoteException e) { 13833 Log.e(TAG, "doesSwitchMultiSimConfigTriggerReboot RemoteException", e); 13834 } 13835 return false; 13836 } 13837 13838 /** 13839 * Retrieve the Radio HAL Version for this device. 13840 * 13841 * Get the HAL version for the IRadio interface for test purposes. 13842 * 13843 * @return a Pair of (major version, minor version) or (-1,-1) if unknown. 13844 * 13845 * @hide 13846 */ 13847 @UnsupportedAppUsage 13848 @TestApi getRadioHalVersion()13849 public Pair<Integer, Integer> getRadioHalVersion() { 13850 try { 13851 ITelephony service = getITelephony(); 13852 if (service != null) { 13853 int version = service.getRadioHalVersion(); 13854 if (version == -1) return new Pair<Integer, Integer>(-1, -1); 13855 return new Pair<Integer, Integer>(version / 100, version % 100); 13856 } 13857 } catch (RemoteException e) { 13858 Log.e(TAG, "getRadioHalVersion() RemoteException", e); 13859 } 13860 return new Pair<Integer, Integer>(-1, -1); 13861 } 13862 13863 /** 13864 * Get the calling application status about carrier privileges for the subscription created 13865 * in TelephonyManager. Used by Telephony Module for permission checking. 13866 * 13867 * @param uid Uid to check. 13868 * @return any value of {@link #CARRIER_PRIVILEGE_STATUS_HAS_ACCESS}, 13869 * {@link #CARRIER_PRIVILEGE_STATUS_NO_ACCESS}, 13870 * {@link #CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED}, or 13871 * {@link #CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES} 13872 * 13873 * @hide 13874 */ 13875 @SystemApi 13876 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getCarrierPrivilegeStatus(int uid)13877 public @CarrierPrivilegeStatus int getCarrierPrivilegeStatus(int uid) { 13878 try { 13879 ITelephony telephony = getITelephony(); 13880 if (telephony != null) { 13881 return telephony.getCarrierPrivilegeStatusForUid(getSubId(), uid); 13882 } 13883 } catch (RemoteException ex) { 13884 Log.e(TAG, "getCarrierPrivilegeStatus RemoteException", ex); 13885 } 13886 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 13887 } 13888 13889 /** 13890 * Returns a list of APNs set as overrides by the device policy manager via 13891 * {@link #addDevicePolicyOverrideApn}. 13892 * This method must only be called from the system or phone processes. 13893 * 13894 * @param context Context to use. 13895 * @return {@link List} of APNs that have been set as overrides. 13896 * @throws {@link SecurityException} if the caller is not the system or phone process. 13897 * @hide 13898 */ 13899 @TestApi 13900 // TODO: add new permission tag indicating that this is system-only. getDevicePolicyOverrideApns(@onNull Context context)13901 public @NonNull List<ApnSetting> getDevicePolicyOverrideApns(@NonNull Context context) { 13902 try (Cursor cursor = context.getContentResolver().query(DPC_URI, null, null, null, null)) { 13903 if (cursor == null) { 13904 return Collections.emptyList(); 13905 } 13906 List<ApnSetting> apnList = new ArrayList<ApnSetting>(); 13907 cursor.moveToPosition(-1); 13908 while (cursor.moveToNext()) { 13909 ApnSetting apn = ApnSetting.makeApnSetting(cursor); 13910 apnList.add(apn); 13911 } 13912 return apnList; 13913 } 13914 } 13915 13916 /** 13917 * Used by the device policy manager to add a new override APN. 13918 * This method must only be called from the system or phone processes. 13919 * 13920 * @param context Context to use. 13921 * @param apnSetting The {@link ApnSetting} describing the new APN. 13922 * @return An integer, corresponding to a primary key in a database, that allows the caller to 13923 * modify the APN in the future via {@link #modifyDevicePolicyOverrideApn}, or 13924 * {@link android.provider.Telephony.Carriers.INVALID_APN_ID} if the override operation 13925 * failed. 13926 * @throws {@link SecurityException} if the caller is not the system or phone process. 13927 * @hide 13928 */ 13929 @TestApi 13930 // TODO: add new permission tag indicating that this is system-only. addDevicePolicyOverrideApn(@onNull Context context, @NonNull ApnSetting apnSetting)13931 public int addDevicePolicyOverrideApn(@NonNull Context context, 13932 @NonNull ApnSetting apnSetting) { 13933 Uri resultUri = context.getContentResolver().insert(DPC_URI, apnSetting.toContentValues()); 13934 13935 int resultId = INVALID_APN_ID; 13936 if (resultUri != null) { 13937 try { 13938 resultId = Integer.parseInt(resultUri.getLastPathSegment()); 13939 } catch (NumberFormatException e) { 13940 Rlog.e(TAG, "Failed to parse inserted override APN id: " 13941 + resultUri.getLastPathSegment()); 13942 } 13943 } 13944 return resultId; 13945 } 13946 13947 /** 13948 * Used by the device policy manager to modify an override APN. 13949 * This method must only be called from the system or phone processes. 13950 * 13951 * @param context Context to use. 13952 * @param apnId The integer key of the APN to modify, as returned by 13953 * {@link #addDevicePolicyOverrideApn} 13954 * @param apnSetting The {@link ApnSetting} describing the updated APN. 13955 * @return {@code true} if successful, {@code false} otherwise. 13956 * @throws {@link SecurityException} if the caller is not the system or phone process. 13957 * @hide 13958 */ 13959 @TestApi 13960 // TODO: add new permission tag indicating that this is system-only. modifyDevicePolicyOverrideApn(@onNull Context context, int apnId, @NonNull ApnSetting apnSetting)13961 public boolean modifyDevicePolicyOverrideApn(@NonNull Context context, int apnId, 13962 @NonNull ApnSetting apnSetting) { 13963 return context.getContentResolver().update( 13964 Uri.withAppendedPath(DPC_URI, Integer.toString(apnId)), 13965 apnSetting.toContentValues(), null, null) > 0; 13966 } 13967 13968 /** 13969 * Return whether data is enabled for certain APN type. This will tell if framework will accept 13970 * corresponding network requests on a subId. 13971 * 13972 * {@link #isDataEnabled()} is directly associated with users' Mobile data toggle on / off. If 13973 * {@link #isDataEnabled()} returns false, it means in general all meter-ed data are disabled. 13974 * 13975 * This per APN type API gives a better idea whether data is allowed on a specific APN type. 13976 * It will return true if: 13977 * 13978 * 1) User data is turned on, or 13979 * 2) APN is un-metered for this subscription, or 13980 * 3) APN type is whitelisted. E.g. MMS is whitelisted if 13981 * {@link #MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. 13982 * 13983 * @param apnType Value indicating the apn type. Apn types are defined in {@link ApnSetting}. 13984 * @return whether data is enabled for a apn type. 13985 * 13986 * @hide 13987 */ 13988 @SystemApi 13989 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) isDataEnabledForApn(@pnType int apnType)13990 public boolean isDataEnabledForApn(@ApnType int apnType) { 13991 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 13992 try { 13993 ITelephony service = getITelephony(); 13994 if (service != null) { 13995 return service.isDataEnabledForApn(apnType, getSubId(), pkgForDebug); 13996 } 13997 } catch (RemoteException ex) { 13998 Rlog.e(TAG, "Telephony#isDataEnabledForApn RemoteException" + ex); 13999 } 14000 return false; 14001 } 14002 14003 /** 14004 * Whether an APN type is metered or not. It will be evaluated with the subId associated 14005 * with the TelephonyManager instance. 14006 * 14007 * @hide 14008 */ 14009 @SystemApi 14010 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) isApnMetered(@pnType int apnType)14011 public boolean isApnMetered(@ApnType int apnType) { 14012 try { 14013 ITelephony service = getITelephony(); 14014 if (service != null) { 14015 return service.isApnMetered(apnType, getSubId()); 14016 } 14017 } catch (RemoteException ex) { 14018 Rlog.e(TAG, "Telephony#isApnMetered RemoteException" + ex); 14019 } 14020 return true; 14021 } 14022 14023 /** 14024 * Specify which bands modem's background scan must act on. 14025 * If {@code specifiers} is non-empty, the scan will be restricted to the bands specified. 14026 * Otherwise, it scans all bands. 14027 * 14028 * For example, CBRS is only on LTE band 48. By specifying this band, 14029 * modem saves more power. 14030 * 14031 * @param specifiers which bands to scan. 14032 * @param executor The executor to execute the callback on 14033 * @param callback The callback that gets invoked when the radio responds to the request. Called 14034 * with {@code true} if the request succeeded, {@code false} otherwise. 14035 * @hide 14036 */ 14037 @SystemApi 14038 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setSystemSelectionChannels(@onNull List<RadioAccessSpecifier> specifiers, @NonNull @CallbackExecutor Executor executor, @NonNull Consumer<Boolean> callback)14039 public void setSystemSelectionChannels(@NonNull List<RadioAccessSpecifier> specifiers, 14040 @NonNull @CallbackExecutor Executor executor, 14041 @NonNull Consumer<Boolean> callback) { 14042 Objects.requireNonNull(specifiers, "Specifiers must not be null."); 14043 Objects.requireNonNull(executor, "Executor must not be null."); 14044 Objects.requireNonNull(callback, "Callback must not be null."); 14045 setSystemSelectionChannelsInternal(specifiers, executor, callback); 14046 } 14047 14048 /** 14049 * Same as {@link #setSystemSelectionChannels(List, Executor, Consumer<Boolean>)}, but to be 14050 * used when the caller does not need feedback on the results of the operation. 14051 * @param specifiers which bands to scan. 14052 * @hide 14053 */ 14054 @SystemApi 14055 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setSystemSelectionChannels(@onNull List<RadioAccessSpecifier> specifiers)14056 public void setSystemSelectionChannels(@NonNull List<RadioAccessSpecifier> specifiers) { 14057 Objects.requireNonNull(specifiers, "Specifiers must not be null."); 14058 setSystemSelectionChannelsInternal(specifiers, null, null); 14059 } 14060 14061 setSystemSelectionChannelsInternal(@onNull List<RadioAccessSpecifier> specifiers, @Nullable @CallbackExecutor Executor executor, @Nullable Consumer<Boolean> callback)14062 private void setSystemSelectionChannelsInternal(@NonNull List<RadioAccessSpecifier> specifiers, 14063 @Nullable @CallbackExecutor Executor executor, 14064 @Nullable Consumer<Boolean> callback) { 14065 IBooleanConsumer aidlConsumer = callback == null ? null : new IBooleanConsumer.Stub() { 14066 @Override 14067 public void accept(boolean result) { 14068 final long identity = Binder.clearCallingIdentity(); 14069 try { 14070 executor.execute(() -> callback.accept(result)); 14071 } finally { 14072 Binder.restoreCallingIdentity(identity); 14073 } 14074 } 14075 }; 14076 14077 try { 14078 ITelephony service = getITelephony(); 14079 if (service != null) { 14080 service.setSystemSelectionChannels(specifiers, getSubId(), aidlConsumer); 14081 } 14082 } catch (RemoteException ex) { 14083 Rlog.e(TAG, "Telephony#setSystemSelectionChannels RemoteException" + ex); 14084 } 14085 } 14086 14087 /** 14088 * Get which bands the modem's background scan is acting on, specified by 14089 * {@link #setSystemSelectionChannels}. 14090 * 14091 * <p>Requires Permission: 14092 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 14093 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 14094 * 14095 * @return a list of {@link RadioAccessSpecifier}, or an empty list if no bands are specified. 14096 * @throws IllegalStateException if the Telephony process is not currently available. 14097 * 14098 * @hide 14099 */ 14100 @SystemApi 14101 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getSystemSelectionChannels()14102 public @NonNull List<RadioAccessSpecifier> getSystemSelectionChannels() { 14103 try { 14104 ITelephony service = getITelephony(); 14105 if (service != null) { 14106 return service.getSystemSelectionChannels(getSubId()); 14107 } else { 14108 throw new IllegalStateException("telephony service is null."); 14109 } 14110 } catch (RemoteException ex) { 14111 Rlog.e(TAG, "Telephony#getSystemSelectionChannels RemoteException" + ex); 14112 } 14113 return new ArrayList<>(); 14114 } 14115 14116 /** 14117 * Verifies whether the input MCC/MNC and MVNO correspond to the current carrier. 14118 * 14119 * @param mccmnc the carrier's mccmnc that you want to match 14120 * @param mvnoType the mvnoType that defined in {@link ApnSetting} 14121 * @param mvnoMatchData the MVNO match data 14122 * @return {@code true} if input mccmnc and mvno matches with data from sim operator. 14123 * {@code false} otherwise. 14124 * 14125 * {@hide} 14126 */ 14127 @SystemApi 14128 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) matchesCurrentSimOperator(@onNull String mccmnc, @MvnoType int mvnoType, @Nullable String mvnoMatchData)14129 public boolean matchesCurrentSimOperator(@NonNull String mccmnc, @MvnoType int mvnoType, 14130 @Nullable String mvnoMatchData) { 14131 try { 14132 if (!mccmnc.equals(getSimOperator())) { 14133 return false; 14134 } 14135 ITelephony service = getITelephony(); 14136 if (service != null) { 14137 return service.isMvnoMatched(getSubId(), mvnoType, mvnoMatchData); 14138 } 14139 } catch (RemoteException ex) { 14140 Rlog.e(TAG, "Telephony#matchesCurrentSimOperator RemoteException" + ex); 14141 } 14142 return false; 14143 } 14144 14145 /** 14146 * Callback to be used with {@link #getCallForwarding} 14147 * @hide 14148 */ 14149 @SystemApi 14150 public interface CallForwardingInfoCallback { 14151 /** 14152 * Indicates that the operation was successful. 14153 */ 14154 int RESULT_SUCCESS = 0; 14155 14156 /** 14157 * Indicates that setting or retrieving the call forwarding info failed with an unknown 14158 * error. 14159 */ 14160 int RESULT_ERROR_UNKNOWN = 1; 14161 14162 /** 14163 * Indicates that call forwarding is not enabled because the recipient is not on a 14164 * Fixed Dialing Number (FDN) list. 14165 */ 14166 int RESULT_ERROR_FDN_CHECK_FAILURE = 2; 14167 14168 /** 14169 * Indicates that call forwarding is not supported on the network at this time. 14170 */ 14171 int RESULT_ERROR_NOT_SUPPORTED = 3; 14172 14173 /** 14174 * Call forwarding errors 14175 * @hide 14176 */ 14177 @IntDef(prefix = { "RESULT_ERROR_" }, value = { 14178 RESULT_ERROR_UNKNOWN, 14179 RESULT_ERROR_NOT_SUPPORTED, 14180 RESULT_ERROR_FDN_CHECK_FAILURE 14181 }) 14182 @Retention(RetentionPolicy.SOURCE) 14183 @interface CallForwardingError{ 14184 } 14185 /** 14186 * Called when the call forwarding info is successfully retrieved from the network. 14187 * @param info information about how calls are forwarded 14188 */ onCallForwardingInfoAvailable(@onNull CallForwardingInfo info)14189 void onCallForwardingInfoAvailable(@NonNull CallForwardingInfo info); 14190 14191 /** 14192 * Called when there was an error retrieving the call forwarding information. 14193 * @param error 14194 */ onError(@allForwardingError int error)14195 void onError(@CallForwardingError int error); 14196 } 14197 14198 /** 14199 * Gets the voice call forwarding info for a given call forwarding reason. 14200 * 14201 * This method queries the network for the currently set call forwarding configuration for the 14202 * provided call forwarding reason. When the network has provided its response, the result will 14203 * be supplied via the provided {@link Executor} on the provided 14204 * {@link CallForwardingInfoCallback}. 14205 * 14206 * @param callForwardingReason the call forwarding reason to query. 14207 * @param executor The executor on which to execute the callback once the result is ready. 14208 * @param callback The callback the results should be delivered on. 14209 * 14210 * @throws IllegalArgumentException if callForwardingReason is not any of 14211 * {@link CallForwardingInfo#REASON_UNCONDITIONAL}, {@link CallForwardingInfo#REASON_BUSY}, 14212 * {@link CallForwardingInfo#REASON_NO_REPLY}, {@link CallForwardingInfo#REASON_NOT_REACHABLE}, 14213 * {@link CallForwardingInfo#REASON_ALL}, or {@link CallForwardingInfo#REASON_ALL_CONDITIONAL} 14214 * 14215 * @hide 14216 */ 14217 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 14218 @SystemApi getCallForwarding(@allForwardingReason int callForwardingReason, @NonNull Executor executor, @NonNull CallForwardingInfoCallback callback)14219 public void getCallForwarding(@CallForwardingReason int callForwardingReason, 14220 @NonNull Executor executor, @NonNull CallForwardingInfoCallback callback) { 14221 if (callForwardingReason < CallForwardingInfo.REASON_UNCONDITIONAL 14222 || callForwardingReason > CallForwardingInfo.REASON_ALL_CONDITIONAL) { 14223 throw new IllegalArgumentException("callForwardingReason is out of range"); 14224 } 14225 14226 ICallForwardingInfoCallback internalCallback = new ICallForwardingInfoCallback.Stub() { 14227 @Override 14228 public void onCallForwardingInfoAvailable(CallForwardingInfo info) { 14229 executor.execute(() -> 14230 Binder.withCleanCallingIdentity(() -> 14231 callback.onCallForwardingInfoAvailable(info))); 14232 } 14233 14234 @Override 14235 public void onError(int error) { 14236 executor.execute(() -> 14237 Binder.withCleanCallingIdentity(() -> 14238 callback.onError(error))); 14239 } 14240 }; 14241 14242 try { 14243 ITelephony telephony = getITelephony(); 14244 if (telephony != null) { 14245 telephony.getCallForwarding(getSubId(), callForwardingReason, internalCallback); 14246 } 14247 } catch (RemoteException ex) { 14248 Rlog.e(TAG, "getCallForwarding RemoteException", ex); 14249 ex.rethrowAsRuntimeException(); 14250 } 14251 } 14252 14253 /** 14254 * Sets voice call forwarding behavior as described by the provided {@link CallForwardingInfo}. 14255 * 14256 * This method will enable call forwarding if the provided {@link CallForwardingInfo} returns 14257 * {@code true} from its {@link CallForwardingInfo#isEnabled()} method, and disables call 14258 * forwarding otherwise. 14259 * 14260 * If you wish to be notified about the results of this operation, provide an {@link Executor} 14261 * and {@link Consumer<Integer>} to be notified asynchronously when the operation completes. 14262 * 14263 * @param callForwardingInfo Info about whether calls should be forwarded and where they 14264 * should be forwarded to. 14265 * @param executor The executor on which the listener will be called. Must be non-null if 14266 * {@code listener} is non-null. 14267 * @param resultListener Asynchronous listener that'll be called when the operation completes. 14268 * Called with {@link CallForwardingInfoCallback#RESULT_SUCCESS} if the 14269 * operation succeeded and an error code from 14270 * {@link CallForwardingInfoCallback} it failed. 14271 * 14272 * @throws IllegalArgumentException if any of the following are true for the parameter 14273 * callForwardingInfo: 14274 * <ul> 14275 * <li>it is {@code null}.</li> 14276 * <li>{@link CallForwardingInfo#getReason()} is not any of: 14277 * <ul> 14278 * <li>{@link CallForwardingInfo#REASON_UNCONDITIONAL}</li> 14279 * <li>{@link CallForwardingInfo#REASON_BUSY}</li> 14280 * <li>{@link CallForwardingInfo#REASON_NO_REPLY}</li> 14281 * <li>{@link CallForwardingInfo#REASON_NOT_REACHABLE}</li> 14282 * <li>{@link CallForwardingInfo#REASON_ALL}</li> 14283 * <li>{@link CallForwardingInfo#REASON_ALL_CONDITIONAL}</li> 14284 * </ul> 14285 * <li>{@link CallForwardingInfo#getNumber()} returns {@code null} when enabling call 14286 * forwarding</li> 14287 * <li>{@link CallForwardingInfo#getTimeoutSeconds()} returns a non-positive value when 14288 * enabling call forwarding</li> 14289 * </ul> 14290 * @hide 14291 */ 14292 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 14293 @SystemApi setCallForwarding(@onNull CallForwardingInfo callForwardingInfo, @Nullable @CallbackExecutor Executor executor, @Nullable @CallForwardingInfoCallback.CallForwardingError Consumer<Integer> resultListener)14294 public void setCallForwarding(@NonNull CallForwardingInfo callForwardingInfo, 14295 @Nullable @CallbackExecutor Executor executor, 14296 @Nullable @CallForwardingInfoCallback.CallForwardingError 14297 Consumer<Integer> resultListener) { 14298 if (callForwardingInfo == null) { 14299 throw new IllegalArgumentException("callForwardingInfo is null"); 14300 } 14301 int callForwardingReason = callForwardingInfo.getReason(); 14302 if (callForwardingReason < CallForwardingInfo.REASON_UNCONDITIONAL 14303 || callForwardingReason > CallForwardingInfo.REASON_ALL_CONDITIONAL) { 14304 throw new IllegalArgumentException("callForwardingReason is out of range"); 14305 } 14306 if (callForwardingInfo.isEnabled()) { 14307 if (callForwardingInfo.getNumber() == null) { 14308 throw new IllegalArgumentException("callForwarding number is null"); 14309 } 14310 if (callForwardingReason == CallForwardingInfo.REASON_NO_REPLY 14311 && callForwardingInfo.getTimeoutSeconds() <= 0) { 14312 throw new IllegalArgumentException("callForwarding timeout isn't positive"); 14313 } 14314 } 14315 if (resultListener != null) { 14316 Objects.requireNonNull(executor); 14317 } 14318 14319 IIntegerConsumer internalCallback = new IIntegerConsumer.Stub() { 14320 @Override 14321 public void accept(int result) { 14322 executor.execute(() -> 14323 Binder.withCleanCallingIdentity(() -> resultListener.accept(result))); 14324 } 14325 }; 14326 14327 try { 14328 ITelephony telephony = getITelephony(); 14329 if (telephony != null) { 14330 telephony.setCallForwarding(getSubId(), callForwardingInfo, internalCallback); 14331 } 14332 } catch (RemoteException ex) { 14333 Rlog.e(TAG, "setCallForwarding RemoteException", ex); 14334 ex.rethrowAsRuntimeException(); 14335 } catch (NullPointerException ex) { 14336 Rlog.e(TAG, "setCallForwarding NPE", ex); 14337 throw ex; 14338 } 14339 } 14340 14341 /** 14342 * Indicates that call waiting is enabled. 14343 * 14344 * @hide 14345 */ 14346 @SystemApi 14347 public static final int CALL_WAITING_STATUS_ENABLED = 1; 14348 14349 /** 14350 * Indicates that call waiting is disabled. 14351 * 14352 * @hide 14353 */ 14354 @SystemApi 14355 public static final int CALL_WAITING_STATUS_DISABLED = 2; 14356 14357 /** 14358 * Indicates there was an unknown error retrieving the call waiting status. 14359 * 14360 * @hide 14361 */ 14362 @SystemApi 14363 public static final int CALL_WAITING_STATUS_UNKNOWN_ERROR = 3; 14364 14365 /** 14366 * Indicates the call waiting is not supported on the current network. 14367 * 14368 * @hide 14369 */ 14370 @SystemApi 14371 public static final int CALL_WAITING_STATUS_NOT_SUPPORTED = 4; 14372 14373 /** 14374 * @hide 14375 */ 14376 @IntDef(prefix = { "CALL_WAITING_STATUS_" }, value = { 14377 CALL_WAITING_STATUS_ENABLED, 14378 CALL_WAITING_STATUS_DISABLED, 14379 CALL_WAITING_STATUS_UNKNOWN_ERROR, 14380 CALL_WAITING_STATUS_NOT_SUPPORTED, 14381 }) 14382 @Retention(RetentionPolicy.SOURCE) 14383 public @interface CallWaitingStatus { 14384 } 14385 14386 /** 14387 * Retrieves the call waiting status of this device from the network. 14388 * 14389 * When call waiting is enabled, an incoming call that arrives when the user is already on 14390 * an active call will be held in a waiting state while the user is notified instead of being 14391 * rejected with a busy signal. 14392 * 14393 * @param executor The executor on which the result listener will be called. 14394 * @param resultListener A {@link Consumer} that will be called with the result fetched 14395 * from the network. The result will be one of: 14396 * <ul> 14397 * <li>{@link #CALL_WAITING_STATUS_ENABLED}}</li> 14398 * <li>{@link #CALL_WAITING_STATUS_DISABLED}}</li> 14399 * <li>{@link #CALL_WAITING_STATUS_UNKNOWN_ERROR}}</li> 14400 * <li>{@link #CALL_WAITING_STATUS_NOT_SUPPORTED}}</li> 14401 * </ul> 14402 * @hide 14403 */ 14404 @SystemApi 14405 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getCallWaitingStatus(@onNull Executor executor, @NonNull @CallWaitingStatus Consumer<Integer> resultListener)14406 public void getCallWaitingStatus(@NonNull Executor executor, 14407 @NonNull @CallWaitingStatus Consumer<Integer> resultListener) { 14408 Objects.requireNonNull(executor); 14409 Objects.requireNonNull(resultListener); 14410 14411 IIntegerConsumer internalCallback = new IIntegerConsumer.Stub() { 14412 @Override 14413 public void accept(int result) { 14414 executor.execute(() -> Binder.withCleanCallingIdentity( 14415 () -> resultListener.accept(result))); 14416 } 14417 }; 14418 14419 try { 14420 ITelephony telephony = getITelephony(); 14421 if (telephony != null) { 14422 telephony.getCallWaitingStatus(getSubId(), internalCallback); 14423 } 14424 } catch (RemoteException ex) { 14425 Rlog.e(TAG, "getCallWaitingStatus RemoteException", ex); 14426 ex.rethrowAsRuntimeException(); 14427 } catch (NullPointerException ex) { 14428 Rlog.e(TAG, "getCallWaitingStatus NPE", ex); 14429 throw ex; 14430 } 14431 } 14432 14433 /** 14434 * Sets the call waiting status of this device with the network. 14435 * 14436 * If you wish to be notified about the results of this operation, provide an {@link Executor} 14437 * and {@link Consumer<Integer>} to be notified asynchronously when the operation completes. 14438 * 14439 * @see #getCallWaitingStatus for a description of the call waiting functionality. 14440 * 14441 * @param enabled {@code true} to enable; {@code false} to disable. 14442 * @param executor The executor on which the listener will be called. Must be non-null if 14443 * {@code listener} is non-null. 14444 * @param resultListener Asynchronous listener that'll be called when the operation completes. 14445 * Called with the new call waiting status (either 14446 * {@link #CALL_WAITING_STATUS_ENABLED} or 14447 * {@link #CALL_WAITING_STATUS_DISABLED} if the operation succeeded and 14448 * {@link #CALL_WAITING_STATUS_NOT_SUPPORTED} or 14449 * {@link #CALL_WAITING_STATUS_UNKNOWN_ERROR} if it failed. 14450 * @hide 14451 */ 14452 @SystemApi 14453 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setCallWaitingEnabled(boolean enabled, @Nullable Executor executor, @Nullable Consumer<Integer> resultListener)14454 public void setCallWaitingEnabled(boolean enabled, @Nullable Executor executor, 14455 @Nullable Consumer<Integer> resultListener) { 14456 if (resultListener != null) { 14457 Objects.requireNonNull(executor); 14458 } 14459 14460 IIntegerConsumer internalCallback = new IIntegerConsumer.Stub() { 14461 @Override 14462 public void accept(int result) { 14463 executor.execute(() -> 14464 Binder.withCleanCallingIdentity(() -> resultListener.accept(result))); 14465 } 14466 }; 14467 14468 try { 14469 ITelephony telephony = getITelephony(); 14470 if (telephony != null) { 14471 telephony.setCallWaitingStatus(getSubId(), enabled, internalCallback); 14472 } 14473 } catch (RemoteException ex) { 14474 Rlog.e(TAG, "setCallWaitingStatus RemoteException", ex); 14475 ex.rethrowAsRuntimeException(); 14476 } catch (NullPointerException ex) { 14477 Rlog.e(TAG, "setCallWaitingStatus NPE", ex); 14478 throw ex; 14479 } 14480 } 14481 14482 /** 14483 * Controls whether mobile data on the non-default SIM is allowed during a voice call. 14484 * 14485 * This is used for allowing data on the non-default data SIM when a voice call is placed on 14486 * the non-default data SIM on DSDS devices. If this policy is disabled, users will not be able 14487 * to use mobile data via the non-default data SIM during the call, which may mean no mobile 14488 * data at all since some modem implementations disallow mobile data via the default data SIM 14489 * during voice calls. 14490 * If this policy is enabled, data will be temporarily enabled on the non-default data SIM 14491 * during any voice calls. 14492 * 14493 * This policy can be enabled and disabled via {@link #setMobileDataPolicyEnabled}. 14494 * @hide 14495 */ 14496 @SystemApi 14497 public static final int MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL = 1; 14498 14499 /** 14500 * Controls whether MMS messages bypass the user-specified "mobile data" toggle. 14501 * 14502 * When enabled, requests for connections to the MMS APN will be accepted by telephony even if 14503 * the user has turned "mobile data" off on this specific sim card. {@link #isDataEnabledForApn} 14504 * will also return true for {@link ApnSetting#TYPE_MMS}. 14505 * When disabled, the MMS APN will be governed by the same rules as all other APNs. 14506 * 14507 * This policy can be enabled and disabled via {@link #setMobileDataPolicyEnabled}. 14508 * @hide 14509 */ 14510 @SystemApi 14511 public static final int MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED = 2; 14512 14513 /** 14514 * @hide 14515 */ 14516 @IntDef(prefix = { "MOBILE_DATA_POLICY_" }, value = { 14517 MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL, 14518 MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, 14519 }) 14520 @Retention(RetentionPolicy.SOURCE) 14521 public @interface MobileDataPolicy { } 14522 14523 /** 14524 * Enables or disables a piece of mobile data policy. 14525 * 14526 * Enables or disables the mobile data policy specified in {@code policy}. See the detailed 14527 * description of each policy constant for what they do. 14528 * 14529 * @param policy The data policy to enable. 14530 * @param enabled Whether to enable or disable the policy. 14531 * @hide 14532 */ 14533 @SystemApi 14534 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setMobileDataPolicyEnabled(@obileDataPolicy int policy, boolean enabled)14535 public void setMobileDataPolicyEnabled(@MobileDataPolicy int policy, boolean enabled) { 14536 try { 14537 ITelephony service = getITelephony(); 14538 if (service != null) { 14539 service.setMobileDataPolicyEnabled(getSubId(), policy, enabled); 14540 } 14541 } catch (RemoteException ex) { 14542 Rlog.e(TAG, "Telephony#setMobileDataPolicyEnabled RemoteException" + ex); 14543 } 14544 } 14545 14546 /** 14547 * Fetches the status of a piece of mobile data policy. 14548 * 14549 * @param policy The data policy that you want the status for. 14550 * @return {@code true} if enabled, {@code false} otherwise. 14551 * @hide 14552 */ 14553 @SystemApi 14554 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) isMobileDataPolicyEnabled(@obileDataPolicy int policy)14555 public boolean isMobileDataPolicyEnabled(@MobileDataPolicy int policy) { 14556 try { 14557 ITelephony service = getITelephony(); 14558 if (service != null) { 14559 return service.isMobileDataPolicyEnabled(getSubId(), policy); 14560 } 14561 } catch (RemoteException ex) { 14562 Rlog.e(TAG, "Telephony#isMobileDataPolicyEnabled RemoteException" + ex); 14563 } 14564 return false; 14565 } 14566 14567 /** 14568 * Indicates that the ICC PIN lock state or PIN was changed successfully. 14569 * @hide 14570 */ 14571 public static final int CHANGE_ICC_LOCK_SUCCESS = Integer.MAX_VALUE; 14572 14573 /** 14574 * Check whether ICC PIN lock is enabled. 14575 * This is a sync call which returns the cached PIN enabled state. 14576 * 14577 * @return {@code true} if ICC PIN lock enabled, {@code false} if disabled. 14578 * @throws SecurityException if the caller doesn't have the permission. 14579 * @throws IllegalStateException if the Telephony process is not currently available. 14580 * 14581 * <p>Requires Permission: 14582 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 14583 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 14584 * 14585 * @hide 14586 */ 14587 @WorkerThread 14588 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 14589 @SystemApi isIccLockEnabled()14590 public boolean isIccLockEnabled() { 14591 try { 14592 ITelephony telephony = getITelephony(); 14593 if (telephony != null) { 14594 return telephony.isIccLockEnabled(getSubId()); 14595 } else { 14596 throw new IllegalStateException("telephony service is null."); 14597 } 14598 } catch (RemoteException e) { 14599 Log.e(TAG, "isIccLockEnabled RemoteException", e); 14600 e.rethrowFromSystemServer(); 14601 } 14602 return false; 14603 } 14604 14605 /** 14606 * Enable or disable the ICC PIN lock. 14607 * 14608 * @param enabled "true" for locked, "false" for unlocked. 14609 * @param pin needed to change the ICC PIN lock, aka. Pin1. 14610 * @return the result of enabling or disabling the ICC PIN lock. 14611 * @throws SecurityException if the caller doesn't have the permission. 14612 * @throws IllegalStateException if the Telephony process is not currently available. 14613 * 14614 * <p>Requires Permission: 14615 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 14616 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 14617 * 14618 * @hide 14619 */ 14620 @SystemApi 14621 @NonNull 14622 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setIccLockEnabled(boolean enabled, @NonNull String pin)14623 public PinResult setIccLockEnabled(boolean enabled, @NonNull String pin) { 14624 checkNotNull(pin, "setIccLockEnabled pin can't be null."); 14625 try { 14626 ITelephony telephony = getITelephony(); 14627 if (telephony != null) { 14628 int result = telephony.setIccLockEnabled(getSubId(), enabled, pin); 14629 if (result == CHANGE_ICC_LOCK_SUCCESS) { 14630 return new PinResult(PinResult.PIN_RESULT_TYPE_SUCCESS, 0); 14631 } else if (result < 0) { 14632 return PinResult.getDefaultFailedResult(); 14633 } else { 14634 return new PinResult(PinResult.PIN_RESULT_TYPE_INCORRECT, result); 14635 } 14636 } else { 14637 throw new IllegalStateException("telephony service is null."); 14638 } 14639 } catch (RemoteException e) { 14640 Log.e(TAG, "setIccLockEnabled RemoteException", e); 14641 e.rethrowFromSystemServer(); 14642 } 14643 return PinResult.getDefaultFailedResult(); 14644 } 14645 14646 /** 14647 * Change the ICC lock PIN. 14648 * 14649 * @param oldPin is the old PIN 14650 * @param newPin is the new PIN 14651 * @return The result of changing the ICC lock PIN. 14652 * @throws SecurityException if the caller doesn't have the permission. 14653 * @throws IllegalStateException if the Telephony process is not currently available. 14654 * 14655 * <p>Requires Permission: 14656 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 14657 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 14658 * 14659 * @hide 14660 */ 14661 @SystemApi 14662 @NonNull 14663 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) changeIccLockPin(@onNull String oldPin, @NonNull String newPin)14664 public PinResult changeIccLockPin(@NonNull String oldPin, @NonNull String newPin) { 14665 checkNotNull(oldPin, "changeIccLockPin oldPin can't be null."); 14666 checkNotNull(newPin, "changeIccLockPin newPin can't be null."); 14667 try { 14668 ITelephony telephony = getITelephony(); 14669 if (telephony != null) { 14670 int result = telephony.changeIccLockPassword(getSubId(), oldPin, newPin); 14671 if (result == CHANGE_ICC_LOCK_SUCCESS) { 14672 return new PinResult(PinResult.PIN_RESULT_TYPE_SUCCESS, 0); 14673 } else if (result < 0) { 14674 return PinResult.getDefaultFailedResult(); 14675 } else { 14676 return new PinResult(PinResult.PIN_RESULT_TYPE_INCORRECT, result); 14677 } 14678 } else { 14679 throw new IllegalStateException("telephony service is null."); 14680 } 14681 } catch (RemoteException e) { 14682 Log.e(TAG, "changeIccLockPin RemoteException", e); 14683 e.rethrowFromSystemServer(); 14684 } 14685 return PinResult.getDefaultFailedResult(); 14686 } 14687 14688 /** 14689 * Called when userActivity is signalled in the power manager. 14690 * This should only be called from system Uid. 14691 * @hide 14692 */ 14693 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) notifyUserActivity()14694 public void notifyUserActivity() { 14695 try { 14696 ITelephony service = getITelephony(); 14697 if (service != null) { 14698 service.userActivity(); 14699 } 14700 } catch (RemoteException e) { 14701 // one-way notification, if telephony is not available, it is okay to not throw 14702 // exception here. 14703 Log.w(TAG, "notifyUserActivity exception: " + e.getMessage()); 14704 } 14705 } 14706 14707 /** 14708 * No error. Operation succeeded. 14709 * @hide 14710 */ 14711 @SystemApi 14712 public static final int ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS = 0; 14713 14714 /** 14715 * NR Dual connectivity enablement is not supported. 14716 * @hide 14717 */ 14718 @SystemApi 14719 public static final int ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED = 1; 14720 14721 /** 14722 * Radio is not available. 14723 * @hide 14724 */ 14725 @SystemApi 14726 public static final int ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE = 2; 14727 14728 /** 14729 * Internal Radio error. 14730 * @hide 14731 */ 14732 @SystemApi 14733 public static final int ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR = 3; 14734 14735 /** 14736 * Currently in invalid state. Not able to process the request. 14737 * @hide 14738 */ 14739 @SystemApi 14740 public static final int ENABLE_NR_DUAL_CONNECTIVITY_INVALID_STATE = 4; 14741 14742 /** @hide */ 14743 @Retention(RetentionPolicy.SOURCE) 14744 @IntDef(prefix = {"ENABLE_NR_DUAL_CONNECTIVITY"}, value = { 14745 ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS, 14746 ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED, 14747 ENABLE_NR_DUAL_CONNECTIVITY_INVALID_STATE, 14748 ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE, 14749 ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR}) 14750 public @interface EnableNrDualConnectivityResult {} 14751 14752 /** 14753 * Enable NR dual connectivity. Enabled state does not mean dual connectivity 14754 * is active. It means device is allowed to connect to both primary and secondary. 14755 * 14756 * @hide 14757 */ 14758 @SystemApi 14759 public static final int NR_DUAL_CONNECTIVITY_ENABLE = 1; 14760 14761 /** 14762 * Disable NR dual connectivity. Disabled state does not mean the secondary cell is released. 14763 * Modem will release it only if the current bearer is released to avoid radio link failure. 14764 * @hide 14765 */ 14766 @SystemApi 14767 public static final int NR_DUAL_CONNECTIVITY_DISABLE = 2; 14768 14769 /** 14770 * Disable NR dual connectivity and force the secondary cell to be released if dual connectivity 14771 * was active. This will result in radio link failure. 14772 * @hide 14773 */ 14774 @SystemApi 14775 public static final int NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE = 3; 14776 14777 /** 14778 * @hide 14779 */ 14780 @IntDef(prefix = { "NR_DUAL_CONNECTIVITY_" }, value = { 14781 NR_DUAL_CONNECTIVITY_ENABLE, 14782 NR_DUAL_CONNECTIVITY_DISABLE, 14783 NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE, 14784 }) 14785 @Retention(RetentionPolicy.SOURCE) 14786 public @interface NrDualConnectivityState { 14787 } 14788 14789 /** 14790 * Enable/Disable E-UTRA-NR Dual Connectivity. 14791 * 14792 * This api is supported only if 14793 * {@link android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported} 14794 * ({@link TelephonyManager#CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE}) 14795 * returns true. 14796 * @param nrDualConnectivityState expected NR dual connectivity state 14797 * This can be passed following states 14798 * <ol> 14799 * <li>Enable NR dual connectivity {@link #NR_DUAL_CONNECTIVITY_ENABLE} 14800 * <li>Disable NR dual connectivity {@link #NR_DUAL_CONNECTIVITY_DISABLE} 14801 * <li>Disable NR dual connectivity and force secondary cell to be released 14802 * {@link #NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} 14803 * </ol> 14804 * @return operation result. 14805 * @throws IllegalStateException if the Telephony process is not currently available. 14806 * @hide 14807 */ 14808 @SystemApi 14809 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 14810 @RequiresFeature( 14811 enforcement = "android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported", 14812 value = TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE) setNrDualConnectivityState( @rDualConnectivityState int nrDualConnectivityState)14813 public @EnableNrDualConnectivityResult int setNrDualConnectivityState( 14814 @NrDualConnectivityState int nrDualConnectivityState) { 14815 try { 14816 ITelephony telephony = getITelephony(); 14817 if (telephony != null) { 14818 return telephony.setNrDualConnectivityState(getSubId(), nrDualConnectivityState); 14819 } else { 14820 throw new IllegalStateException("telephony service is null."); 14821 } 14822 } catch (RemoteException ex) { 14823 Rlog.e(TAG, "setNrDualConnectivityState RemoteException", ex); 14824 ex.rethrowFromSystemServer(); 14825 } 14826 14827 return ENABLE_NR_DUAL_CONNECTIVITY_INVALID_STATE; 14828 } 14829 14830 /** 14831 * Is E-UTRA-NR Dual Connectivity enabled. 14832 * This api is supported only if 14833 * {@link android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported} 14834 * ({@link TelephonyManager#CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE}) 14835 * returns true. 14836 * @return true if dual connectivity is enabled else false. Enabled state does not mean dual 14837 * connectivity is active. It means the device is allowed to connect to both primary and 14838 * secondary cell. 14839 * @throws IllegalStateException if the Telephony process is not currently available. 14840 * @hide 14841 */ 14842 @SystemApi 14843 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 14844 @RequiresFeature( 14845 enforcement = "android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported", 14846 value = TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE) isNrDualConnectivityEnabled()14847 public boolean isNrDualConnectivityEnabled() { 14848 try { 14849 ITelephony telephony = getITelephony(); 14850 if (telephony != null) { 14851 return telephony.isNrDualConnectivityEnabled(getSubId()); 14852 } else { 14853 throw new IllegalStateException("telephony service is null."); 14854 } 14855 } catch (RemoteException ex) { 14856 Rlog.e(TAG, "isNRDualConnectivityEnabled RemoteException", ex); 14857 ex.rethrowFromSystemServer(); 14858 } 14859 return false; 14860 } 14861 14862 private static class DeathRecipient implements IBinder.DeathRecipient { 14863 @Override binderDied()14864 public void binderDied() { 14865 resetServiceCache(); 14866 } 14867 } 14868 14869 /** 14870 * Reset everything in the service cache; if one handle died then they are 14871 * all probably broken. 14872 * @hide 14873 */ resetServiceCache()14874 private static void resetServiceCache() { 14875 synchronized (sCacheLock) { 14876 if (sITelephony != null) { 14877 sITelephony.asBinder().unlinkToDeath(sServiceDeath, 0); 14878 sITelephony = null; 14879 } 14880 if (sISub != null) { 14881 sISub.asBinder().unlinkToDeath(sServiceDeath, 0); 14882 sISub = null; 14883 SubscriptionManager.clearCaches(); 14884 } 14885 if (sISms != null) { 14886 sISms.asBinder().unlinkToDeath(sServiceDeath, 0); 14887 sISms = null; 14888 } 14889 if (sIPhoneSubInfo != null) { 14890 sIPhoneSubInfo.asBinder().unlinkToDeath(sServiceDeath, 0); 14891 sIPhoneSubInfo = null; 14892 } 14893 } 14894 } 14895 14896 /** 14897 * @hide 14898 */ getSubscriberInfoService()14899 static IPhoneSubInfo getSubscriberInfoService() { 14900 // Keeps cache disabled until test fixes are checked into AOSP. 14901 if (!sServiceHandleCacheEnabled) { 14902 return IPhoneSubInfo.Stub.asInterface( 14903 TelephonyFrameworkInitializer 14904 .getTelephonyServiceManager() 14905 .getPhoneSubServiceRegisterer() 14906 .get()); 14907 } 14908 14909 if (sIPhoneSubInfo == null) { 14910 IPhoneSubInfo temp = IPhoneSubInfo.Stub.asInterface( 14911 TelephonyFrameworkInitializer 14912 .getTelephonyServiceManager() 14913 .getPhoneSubServiceRegisterer() 14914 .get()); 14915 synchronized (sCacheLock) { 14916 if (sIPhoneSubInfo == null && temp != null) { 14917 try { 14918 sIPhoneSubInfo = temp; 14919 sIPhoneSubInfo.asBinder().linkToDeath(sServiceDeath, 0); 14920 } catch (Exception e) { 14921 // something has gone horribly wrong 14922 sIPhoneSubInfo = null; 14923 } 14924 } 14925 } 14926 } 14927 return sIPhoneSubInfo; 14928 } 14929 14930 /** 14931 * @hide 14932 */ getSubscriptionService()14933 static ISub getSubscriptionService() { 14934 // Keeps cache disabled until test fixes are checked into AOSP. 14935 if (!sServiceHandleCacheEnabled) { 14936 return ISub.Stub.asInterface( 14937 TelephonyFrameworkInitializer 14938 .getTelephonyServiceManager() 14939 .getSubscriptionServiceRegisterer() 14940 .get()); 14941 } 14942 14943 if (sISub == null) { 14944 ISub temp = ISub.Stub.asInterface( 14945 TelephonyFrameworkInitializer 14946 .getTelephonyServiceManager() 14947 .getSubscriptionServiceRegisterer() 14948 .get()); 14949 synchronized (sCacheLock) { 14950 if (sISub == null && temp != null) { 14951 try { 14952 sISub = temp; 14953 sISub.asBinder().linkToDeath(sServiceDeath, 0); 14954 } catch (Exception e) { 14955 // something has gone horribly wrong 14956 sISub = null; 14957 } 14958 } 14959 } 14960 } 14961 return sISub; 14962 } 14963 14964 /** 14965 * @hide 14966 */ getSmsService()14967 static ISms getSmsService() { 14968 // Keeps cache disabled until test fixes are checked into AOSP. 14969 if (!sServiceHandleCacheEnabled) { 14970 return ISms.Stub.asInterface( 14971 TelephonyFrameworkInitializer 14972 .getTelephonyServiceManager() 14973 .getSmsServiceRegisterer() 14974 .get()); 14975 } 14976 14977 if (sISms == null) { 14978 ISms temp = ISms.Stub.asInterface( 14979 TelephonyFrameworkInitializer 14980 .getTelephonyServiceManager() 14981 .getSmsServiceRegisterer() 14982 .get()); 14983 synchronized (sCacheLock) { 14984 if (sISms == null && temp != null) { 14985 try { 14986 sISms = temp; 14987 sISms.asBinder().linkToDeath(sServiceDeath, 0); 14988 } catch (Exception e) { 14989 // something has gone horribly wrong 14990 sISms = null; 14991 } 14992 } 14993 } 14994 } 14995 return sISms; 14996 } 14997 14998 /** 14999 * Disables service handle caching for tests that utilize mock services. 15000 * @hide 15001 */ 15002 @VisibleForTesting disableServiceHandleCaching()15003 public static void disableServiceHandleCaching() { 15004 sServiceHandleCacheEnabled = false; 15005 } 15006 15007 /** 15008 * Reenables service handle caching. 15009 * @hide 15010 */ 15011 @VisibleForTesting enableServiceHandleCaching()15012 public static void enableServiceHandleCaching() { 15013 sServiceHandleCacheEnabled = true; 15014 } 15015 15016 /** 15017 * Setup sITelephony for testing. 15018 * @hide 15019 */ 15020 @VisibleForTesting setupITelephonyForTest(ITelephony telephony)15021 public static void setupITelephonyForTest(ITelephony telephony) { 15022 sITelephony = telephony; 15023 } 15024 15025 /** 15026 * Whether device can connect to 5G network when two SIMs are active. 15027 * @hide 15028 * TODO b/153669716: remove or make system API. 15029 */ canConnectTo5GInDsdsMode()15030 public boolean canConnectTo5GInDsdsMode() { 15031 ITelephony telephony = getITelephony(); 15032 if (telephony == null) return true; 15033 try { 15034 return telephony.canConnectTo5GInDsdsMode(); 15035 } catch (RemoteException ex) { 15036 return true; 15037 } catch (NullPointerException ex) { 15038 return true; 15039 } 15040 } 15041 15042 /** 15043 * Returns a list of the equivalent home PLMNs (EF_EHPLMN) from the USIM app. 15044 * 15045 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 15046 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 15047 * 15048 * @return A list of equivalent home PLMNs. Returns an empty list if EF_EHPLMN is empty or 15049 * does not exist on the SIM card. 15050 * 15051 * @throws IllegalStateException if the Telephony process is not currently available. 15052 * @throws SecurityException if the caller doesn't have the permission. 15053 * 15054 */ 15055 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getEquivalentHomePlmns()15056 public @NonNull List<String> getEquivalentHomePlmns() { 15057 try { 15058 ITelephony telephony = getITelephony(); 15059 if (telephony != null) { 15060 return telephony.getEquivalentHomePlmns(getSubId(), mContext.getOpPackageName(), 15061 getAttributionTag()); 15062 } else { 15063 throw new IllegalStateException("telephony service is null."); 15064 } 15065 } catch (RemoteException ex) { 15066 Rlog.e(TAG, "Telephony#getEquivalentHomePlmns RemoteException" + ex); 15067 } 15068 15069 return Collections.emptyList(); 15070 } 15071 15072 /** 15073 * Indicates whether {@link CarrierBandwidth#getSecondaryDownlinkCapacityKbps()} and 15074 * {@link CarrierBandwidth#getSecondaryUplinkCapacityKbps()} are visible. See comments 15075 * on respective methods for more information. 15076 * 15077 * @hide 15078 */ 15079 @SystemApi 15080 public static final String CAPABILITY_SECONDARY_LINK_BANDWIDTH_VISIBLE = 15081 "CAPABILITY_SECONDARY_LINK_BANDWIDTH_VISIBLE"; 15082 15083 /** 15084 * Indicates whether {@link #setPreferredNetworkType}, {@link 15085 * #setPreferredNetworkTypeBitmask}, {@link #setAllowedNetworkTypes} and 15086 * {@link #setAllowedNetworkTypesForReason} rely on 15087 * setAllowedNetworkTypesBitmap instead of setPreferredNetworkTypesBitmap on the radio 15088 * interface. 15089 * 15090 * @hide 15091 */ 15092 @SystemApi 15093 public static final String CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK = 15094 "CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK"; 15095 15096 /** 15097 * Indicates whether {@link #setNrDualConnectivityState()} and 15098 * {@link #isNrDualConnectivityEnabled()} ()} are available. See comments 15099 * on respective methods for more information. 15100 * 15101 * @hide 15102 */ 15103 @SystemApi 15104 public static final String CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE = 15105 "CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE"; 15106 15107 /** 15108 * Indicates whether a data throttling request sent with {@link #sendThermalMitigationRequest} 15109 * is supported. See comments on {@link #sendThermalMitigationRequest} for more information. 15110 * 15111 * @hide 15112 */ 15113 @SystemApi 15114 public static final String CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING = 15115 "CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING"; 15116 15117 /** 15118 * Indicates whether {@link #getNetworkSlicingConfiguration} is supported. See comments on 15119 * respective methods for more information. 15120 */ 15121 public static final String CAPABILITY_SLICING_CONFIG_SUPPORTED = 15122 "CAPABILITY_SLICING_CONFIG_SUPPORTED"; 15123 15124 /** 15125 * Indicates whether PHYSICAL_CHANNEL_CONFIG HAL1.6 is supported. See comments on 15126 * respective methods for more information. 15127 * 15128 * @hide 15129 */ 15130 public static final String CAPABILITY_PHYSICAL_CHANNEL_CONFIG_1_6_SUPPORTED = 15131 "CAPABILITY_PHYSICAL_CHANNEL_CONFIG_1_6_SUPPORTED"; 15132 15133 /** 15134 * Indicates whether modem supports handling parsed SIM phonebook records through the RIL, 15135 * both batched reads and individual writes. 15136 * 15137 * @hide 15138 */ 15139 public static final String CAPABILITY_SIM_PHONEBOOK_IN_MODEM = 15140 "CAPABILITY_SIM_PHONEBOOK_IN_MODEM"; 15141 15142 /** 15143 * A list of the radio interface capability values with public valid constants. 15144 * 15145 * Here is a related list for the systemapi-only valid constants: 15146 * CAPABILITY_SECONDARY_LINK_BANDWIDTH_VISIBLE 15147 * CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK 15148 * CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE 15149 * CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING 15150 * 15151 * @hide 15152 * TODO(b/185508047): Doc generation for mixed public/systemapi StringDefs formats badly. 15153 */ 15154 @Retention(RetentionPolicy.SOURCE) 15155 @StringDef(prefix = "CAPABILITY_", value = { 15156 CAPABILITY_SLICING_CONFIG_SUPPORTED, 15157 CAPABILITY_SIM_PHONEBOOK_IN_MODEM, 15158 }) 15159 public @interface RadioInterfaceCapability {} 15160 15161 /** 15162 * Whether the device supports a given capability on the radio interface. 15163 * 15164 * If the capability is not in the set of radio interface capabilities, false is returned. 15165 * 15166 * @param capability the name of the capability to check for 15167 * @return the availability of the capability 15168 */ isRadioInterfaceCapabilitySupported( @onNull @adioInterfaceCapability String capability)15169 public boolean isRadioInterfaceCapabilitySupported( 15170 @NonNull @RadioInterfaceCapability String capability) { 15171 try { 15172 if (capability == null) return false; 15173 15174 ITelephony telephony = getITelephony(); 15175 if (telephony != null) { 15176 return telephony.isRadioInterfaceCapabilitySupported(capability); 15177 } else { 15178 throw new IllegalStateException("telephony service is null."); 15179 } 15180 } catch (RemoteException ex) { 15181 Rlog.e(TAG, "Telephony#isRadioInterfaceCapabilitySupported RemoteException" + ex); 15182 } 15183 return false; 15184 } 15185 15186 /** 15187 * Indicates that the thermal mitigation request was completed successfully. 15188 * 15189 * @hide 15190 */ 15191 @SystemApi 15192 public static final int THERMAL_MITIGATION_RESULT_SUCCESS = 0; 15193 15194 /** 15195 * Indicates that the thermal mitigation request was not completed because of a modem error. 15196 * 15197 * @hide 15198 */ 15199 @SystemApi 15200 public static final int THERMAL_MITIGATION_RESULT_MODEM_ERROR = 1; 15201 15202 /** 15203 * Indicates that the thermal mitigation request was not completed because the modem is not 15204 * available. 15205 * 15206 * @hide 15207 */ 15208 @SystemApi 15209 public static final int THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE = 2; 15210 15211 /** 15212 * Indicates that the thermal mitigation request could not power off the radio due to the device 15213 * either being in an active emergency voice call, device pending an emergency call, or any 15214 * other state that would disallow powering off of radio. 15215 * 15216 * @hide 15217 */ 15218 @SystemApi 15219 public static final int THERMAL_MITIGATION_RESULT_INVALID_STATE = 3; 15220 15221 /** 15222 * Indicates that the thermal mitigation request resulted an unknown error. 15223 * 15224 * @hide 15225 */ 15226 @SystemApi 15227 public static final int THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR = 4; 15228 15229 /** 15230 * Thermal mitigation request to control functionalities at modem. Thermal mitigation is done 15231 * per-subscription. Caller must be sure to bind the TelephonyManager instance to subId by 15232 * calling {@link #createForSubscriptionId(int)} if they want thermal mitigation on a specific 15233 * subscription Id. Otherwise, TelephonyManager will use the default subscription. 15234 * 15235 * Calling this does not guarantee that the thermal mitigation action requested was done to 15236 * completion. A thermal module should actively monitor the temperature levels and request an 15237 * appropriate thermal mitigation action. Every action is assumed to be done 'on top of' the 15238 * previous action, where the order of actions from least thermal mitigation to most is as 15239 * follows: 15240 * <ol> 15241 * <li>{@link ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_DATA_THROTTLING}</li> 15242 * <ol> 15243 * <li>{@link DataThrottlingRequest#DATA_THROTTLING_ACTION_NO_DATA_THROTTLING}</li> 15244 * <li>{@link DataThrottlingRequest#DATA_THROTTLING_ACTION_THROTTLE_SECONDARY_CARRIER}</li> 15245 * <li>{@link DataThrottlingRequest#DATA_THROTTLING_ACTION_THROTTLE_PRIMARY_CARRIER}</li> 15246 * </ol> 15247 * <li>{@link ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_VOICE_ONLY}</li> 15248 * <li>{@link ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_RADIO_OFF}</li> 15249 * </ol> 15250 * 15251 * So, for example, requesting {@link 15252 * DataThrottlingRequest#DATA_THROTTLING_ACTION_THROTTLE_PRIMARY_CARRIER} will ensure that the 15253 * data on secondary carrier has been disabled before throttling on primary carrier. {@link 15254 * ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_VOICE_ONLY} will ensure that data on both 15255 * primary and secondary have been disabled. {@link 15256 * ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_RADIO_OFF} will ensure that voice is 15257 * disabled and that data on both primary and secondary carriers are disabled before turning 15258 * radio off. {@link DataThrottlingRequest#DATA_THROTTLING_ACTION_HOLD} is not part of the order 15259 * and can be used at any time during data throttling to hold onto the current level of data 15260 * throttling. 15261 * 15262 * <p> If {@link android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported}({@link 15263 * #CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING}) returns false, then sending a {@link 15264 * DataThrottlingRequest#DATA_THROTTLING_ACTION_HOLD}, {@link 15265 * DataThrottlingRequest#DATA_THROTTLING_ACTION_THROTTLE_SECONDARY_CARRIER}, or {@link 15266 * DataThrottlingRequest#DATA_THROTTLING_ACTION_THROTTLE_PRIMARY_CARRIER} will result in {@link 15267 * IllegalArgumentException} being thrown. However, on devices that do not 15268 * support data throttling, {@link 15269 * DataThrottlingRequest#DATA_THROTTLING_ACTION_NO_DATA_THROTTLING} can still be requested in 15270 * order to undo the mitigations above it (i.e {@link 15271 * ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_VOICE_ONLY} and/or {@link 15272 * ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_RADIO_OFF}). </p> 15273 * 15274 * <p> In addition to the {@link Manifest.permission#MODIFY_PHONE_STATE} permission, callers of 15275 * this API must also be listed in the device configuration as an authorized app in 15276 * {@code packages/services/Telephony/res/values/config.xml} under the 15277 * {@code thermal_mitigation_allowlisted_packages} key. </p> 15278 * 15279 * @param thermalMitigationRequest Thermal mitigation request. See {@link 15280 * ThermalMitigationRequest} for details. 15281 * 15282 * @throws IllegalStateException if the Telephony process is not currently available. 15283 * @throws IllegalArgumentException if the thermalMitigationRequest had invalid parameters or 15284 * if the device's modem does not support data throttling. 15285 * 15286 * @hide 15287 */ 15288 @SystemApi 15289 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 15290 @ThermalMitigationResult sendThermalMitigationRequest( @onNull ThermalMitigationRequest thermalMitigationRequest)15291 public int sendThermalMitigationRequest( 15292 @NonNull ThermalMitigationRequest thermalMitigationRequest) { 15293 try { 15294 ITelephony telephony = getITelephony(); 15295 if (telephony != null) { 15296 return telephony.sendThermalMitigationRequest(getSubId(), thermalMitigationRequest, 15297 getOpPackageName()); 15298 } 15299 throw new IllegalStateException("telephony service is null."); 15300 } catch (RemoteException ex) { 15301 Log.e(TAG, "Telephony#thermalMitigationRequest RemoteException", ex); 15302 ex.rethrowFromSystemServer(); 15303 } 15304 return THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; 15305 } 15306 15307 /** 15308 * Registers a callback object to receive notification of changes in specified telephony states. 15309 * <p> 15310 * To register a callback, pass a {@link TelephonyCallback} which implements 15311 * interfaces of events. For example, 15312 * FakeServiceStateCallback extends {@link TelephonyCallback} implements 15313 * {@link TelephonyCallback.ServiceStateListener}. 15314 * 15315 * At registration, and when a specified telephony state changes, the telephony manager invokes 15316 * the appropriate callback method on the callback object and passes the current (updated) 15317 * values. 15318 * <p> 15319 * 15320 * If this TelephonyManager object has been created with {@link #createForSubscriptionId}, 15321 * applies to the given subId. Otherwise, applies to 15322 * {@link SubscriptionManager#getDefaultSubscriptionId()}. To register events for multiple 15323 * subIds, pass a separate callback object to each TelephonyManager object created with 15324 * {@link #createForSubscriptionId}. 15325 * 15326 * Note: if you call this method while in the middle of a binder transaction, you <b>must</b> 15327 * call {@link android.os.Binder#clearCallingIdentity()} before calling this method. A 15328 * {@link SecurityException} will be thrown otherwise. 15329 * 15330 * This API should be used sparingly -- large numbers of callbacks will cause system 15331 * instability. If a process has registered too many callbacks without unregistering them, it 15332 * may encounter an {@link IllegalStateException} when trying to register more callbacks. 15333 * 15334 * @param executor The executor of where the callback will execute. 15335 * @param callback The {@link TelephonyCallback} object to register. 15336 */ registerTelephonyCallback(@onNull @allbackExecutor Executor executor, @NonNull TelephonyCallback callback)15337 public void registerTelephonyCallback(@NonNull @CallbackExecutor Executor executor, 15338 @NonNull TelephonyCallback callback) { 15339 15340 if (mContext == null) { 15341 throw new IllegalStateException("telephony service is null."); 15342 } 15343 15344 if (executor == null || callback == null) { 15345 throw new IllegalArgumentException("TelephonyCallback and executor must be non-null"); 15346 } 15347 mTelephonyRegistryMgr = (TelephonyRegistryManager) 15348 mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE); 15349 if (mTelephonyRegistryMgr != null) { 15350 mTelephonyRegistryMgr.registerTelephonyCallback(executor, mSubId, getOpPackageName(), 15351 getAttributionTag(), callback, getITelephony() != null); 15352 } else { 15353 throw new IllegalStateException("telephony service is null."); 15354 } 15355 } 15356 15357 /** 15358 * Unregister an existing {@link TelephonyCallback}. 15359 * 15360 * @param callback The {@link TelephonyCallback} object to unregister. 15361 */ unregisterTelephonyCallback(@onNull TelephonyCallback callback)15362 public void unregisterTelephonyCallback(@NonNull TelephonyCallback callback) { 15363 15364 if (mContext == null) { 15365 throw new IllegalStateException("telephony service is null."); 15366 } 15367 15368 if (callback.callback == null) { 15369 return; 15370 } 15371 15372 mTelephonyRegistryMgr = mContext.getSystemService(TelephonyRegistryManager.class); 15373 if (mTelephonyRegistryMgr != null) { 15374 mTelephonyRegistryMgr.unregisterTelephonyCallback(mSubId, getOpPackageName(), 15375 getAttributionTag(), callback, getITelephony() != null); 15376 } else { 15377 throw new IllegalStateException("telephony service is null."); 15378 } 15379 } 15380 15381 /** @hide */ 15382 @Retention(RetentionPolicy.SOURCE) 15383 @IntDef(prefix = {"GBA_FAILURE_REASON_"}, value = { 15384 GBA_FAILURE_REASON_UNKNOWN, 15385 GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED, 15386 GBA_FAILURE_REASON_FEATURE_NOT_READY, 15387 GBA_FAILURE_REASON_NETWORK_FAILURE, 15388 GBA_FAILURE_REASON_INCORRECT_NAF_ID, 15389 GBA_FAILURE_REASON_SECURITY_PROTOCOL_NOT_SUPPORTED}) 15390 public @interface AuthenticationFailureReason {} 15391 15392 /** 15393 * GBA Authentication has failed for an unknown reason. 15394 * 15395 * <p>The caller should retry a message that failed with this response. 15396 * @hide 15397 */ 15398 @SystemApi 15399 public static final int GBA_FAILURE_REASON_UNKNOWN = 0; 15400 15401 /** 15402 * GBA Authentication is not supported by the carrier, SIM or android. 15403 * 15404 * <p>Application should use other authentication mechanisms if possible. 15405 * @hide 15406 */ 15407 @SystemApi 15408 public static final int GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED = 1; 15409 15410 /** 15411 * GBA Authentication service is not ready for use. 15412 * 15413 * <p>Application could try again at a later time. 15414 * @hide 15415 */ 15416 @SystemApi 15417 public static final int GBA_FAILURE_REASON_FEATURE_NOT_READY = 2; 15418 15419 /** 15420 * GBA Authentication has been failed by the network. 15421 * @hide 15422 */ 15423 @SystemApi 15424 public static final int GBA_FAILURE_REASON_NETWORK_FAILURE = 3; 15425 15426 /** 15427 * GBA Authentication has failed due to incorrect NAF URL. 15428 * @hide 15429 */ 15430 @SystemApi 15431 public static final int GBA_FAILURE_REASON_INCORRECT_NAF_ID = 4; 15432 15433 /** 15434 * GBA Authentication has failed due to unsupported security protocol 15435 * @hide 15436 */ 15437 @SystemApi 15438 public static final int GBA_FAILURE_REASON_SECURITY_PROTOCOL_NOT_SUPPORTED = 5; 15439 15440 /** 15441 * The callback associated with a {@link #bootstrapAuthenticationRequest()}. 15442 * @hide 15443 */ 15444 @SystemApi 15445 public static class BootstrapAuthenticationCallback { 15446 15447 /** 15448 * Invoked when the previously requested GBA keys are available (@see 15449 * bootstrapAuthenticationRequest()). 15450 * @param gbaKey Ks_NAF/Ks_ext_NAF Response 15451 * @param transactionId Bootstrapping Transaction Identifier 15452 */ onKeysAvailable(@onNull byte[] gbaKey, @NonNull String transactionId)15453 public void onKeysAvailable(@NonNull byte[] gbaKey, @NonNull String transactionId) {} 15454 15455 /** 15456 * @param reason The reason for the authentication failure. 15457 */ onAuthenticationFailure(@uthenticationFailureReason int reason)15458 public void onAuthenticationFailure(@AuthenticationFailureReason int reason) {} 15459 } 15460 15461 /** 15462 * Used to get the Generic Bootstrapping Architecture authentication keys 15463 * KsNAF/Ks_ext_NAF for a particular NAF as defined in 3GPP spec TS 33.220 for 15464 * the specified sub id. 15465 * 15466 * <p>Application must be prepared to wait for receiving the Gba keys through the 15467 * registered callback and not invoke the API on the main application thread. 15468 * Application also must call the api to get the fresh key every time instead 15469 * of caching the key. 15470 * 15471 * Following steps may be invoked on the API call depending on the state of the 15472 * underlying GBA implementation: 15473 * <ol> 15474 * <li>Resolve and bind to a Gba implementation.</li> 15475 * <li>Run bootstrapping if no valid keys are available or bootstrapping is forced.</li> 15476 * <li>Generate the ks_NAF/ ks_Ext_NAF to be returned via the callback.</li> 15477 * </ol> 15478 * 15479 * <p> Requires Permission: 15480 * <ul> 15481 * <li>{@link android.Manifest.permission#MODIFY_PHONE_STATE},</li> 15482 * <li>{@link android.Manifest.permission#PERFORM_IMS_SINGLE_REGISTRATION},</li> 15483 * <li>or that the caller has carrier privileges (see 15484 * {@link TelephonyManager#hasCarrierPrivileges()}).</li> 15485 * </ul> 15486 * @param appType icc application type, like {@link #APPTYPE_USIM} or {@link 15487 * #APPTYPE_ISIM} or {@link#APPTYPE_UNKNOWN} 15488 * @param nafId A URI to specify Network Application Function(NAF) fully qualified domain 15489 * name (FQDN) and the selected GBA mode. The authority of the URI must contain two parts 15490 * delimited by "@" sign. The first part is the constant string "3GPP-bootstrapping" (GBA_ME), 15491 * "3GPP-bootstrapping-uicc" (GBA_ U), or "3GPP-bootstrapping-digest" (GBA_Digest). 15492 * The second part shall be the FQDN of the NAF. The scheme of the URI is not actually used 15493 * for the authentication, which may be set the same as the resource that the application is 15494 * going to access. For example, the nafId can be 15495 * "https://3GPP-bootstrapping@naf1.operator.com", 15496 * "https://3GPP-bootstrapping-uicc@naf1.operator.com", 15497 * "https://3GPP-bootstrapping-digest@naf1.operator.com", 15498 * "ftps://3GPP-bootstrapping-digest@naf1.operator.com". 15499 * @param securityProtocol Security protocol identifier between UE and NAF. See 15500 * 3GPP TS 33.220 Annex H. Application can use 15501 * {@link UaSecurityProtocolIdentifier#createDefaultUaSpId}, 15502 * {@link UaSecurityProtocolIdentifier#create3GppUaSpId}, 15503 * to create the ua security protocol identifier as needed 15504 * @param forceBootStrapping true=force bootstrapping, false=do not force 15505 * bootstrapping. Bootstrapping shouldn't be forced unless the application sees 15506 * authentication errors from the server. 15507 * @param e The {@link Executor} that will be used to call the Gba callback. 15508 * @param callback A callback called on the supplied {@link Executor} that will 15509 * contain the GBA Ks_NAF/Ks_ext_NAF when available. If the NAF keys are 15510 * available and valid at the time of call and bootstrapping is not requested, 15511 * then the callback shall be invoked with the available keys. 15512 * @hide 15513 */ 15514 @SystemApi 15515 @WorkerThread 15516 @RequiresPermission(anyOf = {android.Manifest.permission.MODIFY_PHONE_STATE, 15517 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION}) bootstrapAuthenticationRequest( @iccAppTypeExt int appType, @NonNull Uri nafId, @NonNull UaSecurityProtocolIdentifier securityProtocol, boolean forceBootStrapping, @NonNull Executor e, @NonNull BootstrapAuthenticationCallback callback)15518 public void bootstrapAuthenticationRequest( 15519 @UiccAppTypeExt int appType, @NonNull Uri nafId, 15520 @NonNull UaSecurityProtocolIdentifier securityProtocol, 15521 boolean forceBootStrapping, @NonNull Executor e, 15522 @NonNull BootstrapAuthenticationCallback callback) { 15523 try { 15524 ITelephony service = getITelephony(); 15525 if (service == null) { 15526 e.execute(() -> callback.onAuthenticationFailure( 15527 GBA_FAILURE_REASON_FEATURE_NOT_READY)); 15528 return; 15529 } 15530 service.bootstrapAuthenticationRequest( 15531 getSubId(), appType, nafId, securityProtocol, forceBootStrapping, 15532 new IBootstrapAuthenticationCallback.Stub() { 15533 @Override 15534 public void onKeysAvailable(int token, byte[] gbaKey, 15535 String transactionId) { 15536 final long identity = Binder.clearCallingIdentity(); 15537 try { 15538 e.execute(() -> callback.onKeysAvailable(gbaKey, transactionId)); 15539 } finally { 15540 Binder.restoreCallingIdentity(identity); 15541 } 15542 } 15543 15544 @Override 15545 public void onAuthenticationFailure(int token, int reason) { 15546 final long identity = Binder.clearCallingIdentity(); 15547 try { 15548 e.execute(() -> callback.onAuthenticationFailure(reason)); 15549 } finally { 15550 Binder.restoreCallingIdentity(identity); 15551 } 15552 } 15553 }); 15554 } catch (RemoteException exception) { 15555 Log.e(TAG, "Error calling ITelephony#bootstrapAuthenticationRequest", exception); 15556 e.execute(() -> callback.onAuthenticationFailure(GBA_FAILURE_REASON_FEATURE_NOT_READY)); 15557 } 15558 } 15559 15560 /** 15561 * The network type is valid or not. 15562 * 15563 * @param networkType The network type {@link NetworkType}. 15564 * @return {@code true} if valid, {@code false} otherwise. 15565 * 15566 * @hide 15567 */ isNetworkTypeValid(@etworkType int networkType)15568 public static boolean isNetworkTypeValid(@NetworkType int networkType) { 15569 return networkType >= TelephonyManager.NETWORK_TYPE_UNKNOWN && 15570 networkType <= TelephonyManager.NETWORK_TYPE_NR; 15571 } 15572 15573 /** 15574 * Set a {@link SignalStrengthUpdateRequest} to receive notification when signal quality 15575 * measurements breach the specified thresholds. 15576 * 15577 * To be notified, set the signal strength update request and then register 15578 * {@link TelephonyManager#listen(PhoneStateListener, int)} with 15579 * {@link PhoneStateListener#LISTEN_SIGNAL_STRENGTHS}. The notification will arrive through 15580 * {@link PhoneStateListener#onSignalStrengthsChanged(SignalStrength)}. 15581 * 15582 * To stop receiving the notification over the specified thresholds, pass the same 15583 * {@link SignalStrengthUpdateRequest} object to 15584 * {@link #clearSignalStrengthUpdateRequest(SignalStrengthUpdateRequest)}. 15585 * 15586 * System will clean up the {@link SignalStrengthUpdateRequest} if the caller process died 15587 * without calling {@link #clearSignalStrengthUpdateRequest(SignalStrengthUpdateRequest)}. 15588 * 15589 * If this TelephonyManager object has been created with {@link #createForSubscriptionId}, 15590 * applies to the given subId. Otherwise, applies to 15591 * {@link SubscriptionManager#getDefaultSubscriptionId()}. To request for multiple subIds, 15592 * pass a request object to each TelephonyManager object created with 15593 * {@link #createForSubscriptionId}. 15594 * 15595 * <p>Requires Permission: 15596 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 15597 * or that the calling app has carrier privileges (see 15598 * {@link TelephonyManager#hasCarrierPrivileges}). 15599 * 15600 * Note that the thresholds in the request will be used on a best-effort basis; the system may 15601 * modify requests to multiplex various request sources or to optimize power consumption. The 15602 * caller should not expect to be notified with the exactly the same thresholds. 15603 * 15604 * @see #clearSignalStrengthUpdateRequest(SignalStrengthUpdateRequest) 15605 * 15606 * @param request the SignalStrengthUpdateRequest to be set into the System 15607 * 15608 * @throws IllegalStateException if a new request is set with same subId from the same caller 15609 */ 15610 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 15611 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setSignalStrengthUpdateRequest(@onNull SignalStrengthUpdateRequest request)15612 public void setSignalStrengthUpdateRequest(@NonNull SignalStrengthUpdateRequest request) { 15613 Objects.requireNonNull(request, "request must not be null"); 15614 15615 try { 15616 ITelephony service = getITelephony(); 15617 if (service != null) { 15618 service.setSignalStrengthUpdateRequest(getSubId(), request, getOpPackageName()); 15619 } 15620 } catch (RemoteException e) { 15621 Log.e(TAG, "Error calling ITelephony#setSignalStrengthUpdateRequest", e); 15622 } 15623 } 15624 15625 /** 15626 * Clear a {@link SignalStrengthUpdateRequest} from the system. 15627 * 15628 * <p>Requires Permission: 15629 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 15630 * or that the calling app has carrier privileges (see 15631 * {@link TelephonyManager#hasCarrierPrivileges}). 15632 * 15633 * <p>If the given request was not set before, this operation is a no-op. 15634 * 15635 * @see #setSignalStrengthUpdateRequest(SignalStrengthUpdateRequest) 15636 * 15637 * @param request the SignalStrengthUpdateRequest to be cleared from the System 15638 */ 15639 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 15640 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) clearSignalStrengthUpdateRequest(@onNull SignalStrengthUpdateRequest request)15641 public void clearSignalStrengthUpdateRequest(@NonNull SignalStrengthUpdateRequest request) { 15642 Objects.requireNonNull(request, "request must not be null"); 15643 15644 try { 15645 ITelephony service = getITelephony(); 15646 if (service != null) { 15647 service.clearSignalStrengthUpdateRequest(getSubId(), request, getOpPackageName()); 15648 } 15649 } catch (RemoteException e) { 15650 Log.e(TAG, "Error calling ITelephony#clearSignalStrengthUpdateRequest", e); 15651 } 15652 } 15653 15654 /** 15655 * Gets the current phone capability. 15656 * 15657 * @return the PhoneCapability which describes the data connection capability of modem. 15658 * It's used to evaluate possible phone config change, for example from single 15659 * SIM device to multi-SIM device. 15660 * @hide 15661 */ 15662 @SystemApi 15663 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getPhoneCapability()15664 public @NonNull PhoneCapability getPhoneCapability() { 15665 try { 15666 ITelephony telephony = getITelephony(); 15667 if (telephony != null) { 15668 return telephony.getPhoneCapability(); 15669 } else { 15670 throw new IllegalStateException("telephony service is null."); 15671 } 15672 } catch (RemoteException ex) { 15673 ex.rethrowAsRuntimeException(); 15674 } 15675 if (getActiveModemCount() > 1) { 15676 return PhoneCapability.DEFAULT_DSDS_CAPABILITY; 15677 } else { 15678 return PhoneCapability.DEFAULT_SSSS_CAPABILITY; 15679 } 15680 } 15681 15682 /** 15683 * The unattended reboot was prepared successfully. 15684 * @hide 15685 */ 15686 @SystemApi 15687 public static final int PREPARE_UNATTENDED_REBOOT_SUCCESS = 0; 15688 15689 /** 15690 * The unattended reboot was prepared, but the user will need to manually 15691 * enter the PIN code of at least one SIM card present in the device. 15692 * @hide 15693 */ 15694 @SystemApi 15695 public static final int PREPARE_UNATTENDED_REBOOT_PIN_REQUIRED = 1; 15696 15697 /** 15698 * The unattended reboot was not prepared due to a non-recoverable error. After this error, 15699 * the client that manages the unattended reboot should not try to invoke the API again 15700 * until the next power cycle. 15701 * @hide 15702 */ 15703 @SystemApi 15704 public static final int PREPARE_UNATTENDED_REBOOT_ERROR = 2; 15705 15706 /** @hide */ 15707 @Retention(RetentionPolicy.SOURCE) 15708 @IntDef(prefix = {"PREPARE_UNATTENDED_REBOOT_"}, 15709 value = { 15710 PREPARE_UNATTENDED_REBOOT_SUCCESS, 15711 PREPARE_UNATTENDED_REBOOT_PIN_REQUIRED, 15712 PREPARE_UNATTENDED_REBOOT_ERROR 15713 }) 15714 public @interface PrepareUnattendedRebootResult {} 15715 15716 /** 15717 * Prepare TelephonyManager for an unattended reboot. The reboot is required to be done 15718 * shortly (e.g. within 15 seconds) after the API is invoked. 15719 * 15720 * <p>Requires Permission: 15721 * {@link android.Manifest.permission#REBOOT} 15722 * 15723 * @return {@link #PREPARE_UNATTENDED_REBOOT_SUCCESS} in case of success. 15724 * {@link #PREPARE_UNATTENDED_REBOOT_PIN_REQUIRED} if the device contains 15725 * at least one SIM card for which the user needs to manually enter the PIN 15726 * code after the reboot. {@link #PREPARE_UNATTENDED_REBOOT_ERROR} in case 15727 * of error. 15728 * @hide 15729 */ 15730 @SystemApi 15731 @RequiresPermission(android.Manifest.permission.REBOOT) 15732 @PrepareUnattendedRebootResult prepareForUnattendedReboot()15733 public int prepareForUnattendedReboot() { 15734 try { 15735 ITelephony service = getITelephony(); 15736 if (service != null) { 15737 return service.prepareForUnattendedReboot(); 15738 } 15739 } catch (RemoteException e) { 15740 Log.e(TAG, "Telephony#prepareForUnattendedReboot RemoteException", e); 15741 e.rethrowFromSystemServer(); 15742 } 15743 return PREPARE_UNATTENDED_REBOOT_ERROR; 15744 } 15745 15746 /** 15747 * Exception that may be supplied to the callback in {@link #getNetworkSlicingConfiguration} if 15748 * something goes awry. 15749 */ 15750 public static class NetworkSlicingException extends Exception { 15751 /** 15752 * Getting the current slicing configuration successfully. Used internally only. 15753 * @hide 15754 */ 15755 public static final int SUCCESS = 0; 15756 15757 /** 15758 * The system timed out waiting for a response from the Radio. 15759 * @hide 15760 */ 15761 public static final int ERROR_TIMEOUT = 1; 15762 15763 /** 15764 * The modem returned a failure. 15765 * @hide 15766 */ 15767 public static final int ERROR_MODEM_ERROR = 2; 15768 15769 /** @hide */ 15770 @IntDef(prefix = {"ERROR_"}, value = { 15771 ERROR_TIMEOUT, 15772 ERROR_MODEM_ERROR, 15773 }) 15774 @Retention(RetentionPolicy.SOURCE) 15775 public @interface NetworkSlicingError {} 15776 15777 private final int mErrorCode; 15778 15779 /** @hide */ NetworkSlicingException(@etworkSlicingError int errorCode)15780 public NetworkSlicingException(@NetworkSlicingError int errorCode) { 15781 mErrorCode = errorCode; 15782 } 15783 15784 @Override toString()15785 public String toString() { 15786 switch (mErrorCode) { 15787 case ERROR_TIMEOUT: return "ERROR_TIMEOUT"; 15788 case ERROR_MODEM_ERROR: return "ERROR_MODEM_ERROR"; 15789 default: return "UNDEFINED"; 15790 } 15791 } 15792 } 15793 15794 /** 15795 * Exception that is supplied to the callback in {@link #getNetworkSlicingConfiguration} if the 15796 * system timed out waiting for a response from the Radio. 15797 */ 15798 public class TimeoutException extends NetworkSlicingException { 15799 /** @hide */ TimeoutException(int errorCode)15800 public TimeoutException(int errorCode) { 15801 super(errorCode); 15802 } 15803 } 15804 15805 /** 15806 * Exception that is supplied to the callback in {@link #getNetworkSlicingConfiguration} if the 15807 * modem returned a failure. 15808 */ 15809 public class ModemErrorException extends NetworkSlicingException { 15810 /** @hide */ ModemErrorException(int errorCode)15811 public ModemErrorException(int errorCode) { 15812 super(errorCode); 15813 } 15814 } 15815 15816 /** @hide */ 15817 public static final String KEY_SLICING_CONFIG_HANDLE = "slicing_config_handle"; 15818 15819 /** 15820 * Request to get the current slicing configuration including URSP rules and 15821 * NSSAIs (configured, allowed and rejected). 15822 * 15823 * This method can be invoked if one of the following requirements is met: 15824 * <ul> 15825 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 15826 * is a privileged permission that can only be granted to apps preloaded on the device. 15827 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 15828 * </ul> 15829 * 15830 * This will be invalid if the device does not support 15831 * android.telephony.TelephonyManager#CAPABILITY_SLICING_CONFIG_SUPPORTED. 15832 * 15833 * @param executor the executor on which callback will be invoked. 15834 * @param callback a callback to receive the current slicing configuration. 15835 */ 15836 @RequiresFeature( 15837 enforcement = "android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported", 15838 value = TelephonyManager.CAPABILITY_SLICING_CONFIG_SUPPORTED) 15839 @SuppressAutoDoc // No support for carrier privileges (b/72967236). 15840 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getNetworkSlicingConfiguration( @onNull @allbackExecutor Executor executor, @NonNull OutcomeReceiver<NetworkSlicingConfig, NetworkSlicingException> callback)15841 public void getNetworkSlicingConfiguration( 15842 @NonNull @CallbackExecutor Executor executor, 15843 @NonNull OutcomeReceiver<NetworkSlicingConfig, NetworkSlicingException> callback) { 15844 Objects.requireNonNull(executor); 15845 Objects.requireNonNull(callback); 15846 15847 try { 15848 ITelephony telephony = getITelephony(); 15849 if (telephony == null) { 15850 throw new IllegalStateException("telephony service is null."); 15851 } 15852 telephony.getSlicingConfig(new ResultReceiver(null) { 15853 @Override 15854 protected void onReceiveResult(int resultCode, Bundle result) { 15855 if (resultCode == NetworkSlicingException.ERROR_TIMEOUT) { 15856 executor.execute(() -> callback.onError( 15857 new TimeoutException(resultCode))); 15858 return; 15859 } else if (resultCode == NetworkSlicingException.ERROR_MODEM_ERROR) { 15860 executor.execute(() -> callback.onError( 15861 new ModemErrorException(resultCode))); 15862 return; 15863 } 15864 15865 NetworkSlicingConfig slicingConfig = 15866 result.getParcelable(KEY_SLICING_CONFIG_HANDLE); 15867 executor.execute(() -> callback.onResult(slicingConfig)); 15868 } 15869 }); 15870 } catch (RemoteException ex) { 15871 ex.rethrowAsRuntimeException(); 15872 } 15873 } 15874 } 15875