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.PropertyInvalidatedCache; 45 import android.app.role.RoleManager; 46 import android.compat.Compatibility; 47 import android.compat.annotation.ChangeId; 48 import android.compat.annotation.EnabledAfter; 49 import android.compat.annotation.UnsupportedAppUsage; 50 import android.content.ComponentName; 51 import android.content.Context; 52 import android.content.ContextParams; 53 import android.content.Intent; 54 import android.content.pm.PackageManager; 55 import android.database.Cursor; 56 import android.net.ConnectivityManager; 57 import android.net.Uri; 58 import android.os.AsyncTask; 59 import android.os.Binder; 60 import android.os.Build; 61 import android.os.Bundle; 62 import android.os.Handler; 63 import android.os.IBinder; 64 import android.os.Looper; 65 import android.os.OutcomeReceiver; 66 import android.os.ParcelFileDescriptor; 67 import android.os.ParcelUuid; 68 import android.os.Parcelable; 69 import android.os.PersistableBundle; 70 import android.os.RemoteException; 71 import android.os.ResultReceiver; 72 import android.os.SystemProperties; 73 import android.os.WorkSource; 74 import android.provider.Settings.SettingNotFoundException; 75 import android.service.carrier.CarrierIdentifier; 76 import android.service.carrier.CarrierService; 77 import android.sysprop.TelephonyProperties; 78 import android.telecom.CallScreeningService; 79 import android.telecom.InCallService; 80 import android.telecom.PhoneAccount; 81 import android.telecom.PhoneAccountHandle; 82 import android.telecom.TelecomManager; 83 import android.telephony.Annotation.ApnType; 84 import android.telephony.Annotation.CallState; 85 import android.telephony.Annotation.CarrierPrivilegeStatus; 86 import android.telephony.Annotation.NetworkType; 87 import android.telephony.Annotation.RadioPowerState; 88 import android.telephony.Annotation.SimActivationState; 89 import android.telephony.Annotation.ThermalMitigationResult; 90 import android.telephony.Annotation.UiccAppType; 91 import android.telephony.Annotation.UiccAppTypeExt; 92 import android.telephony.CallForwardingInfo.CallForwardingReason; 93 import android.telephony.VisualVoicemailService.VisualVoicemailTask; 94 import android.telephony.data.ApnSetting; 95 import android.telephony.data.ApnSetting.MvnoType; 96 import android.telephony.data.NetworkSlicingConfig; 97 import android.telephony.emergency.EmergencyNumber; 98 import android.telephony.emergency.EmergencyNumber.EmergencyServiceCategories; 99 import android.telephony.gba.UaSecurityProtocolIdentifier; 100 import android.telephony.ims.ImsMmTelManager; 101 import android.telephony.ims.aidl.IImsConfig; 102 import android.telephony.ims.aidl.IImsRegistration; 103 import android.telephony.ims.feature.MmTelFeature; 104 import android.telephony.ims.stub.ImsRegistrationImplBase; 105 import android.text.TextUtils; 106 import android.util.Log; 107 import android.util.Pair; 108 109 import com.android.internal.annotations.GuardedBy; 110 import com.android.internal.annotations.VisibleForTesting; 111 import com.android.internal.os.BackgroundThread; 112 import com.android.internal.telephony.CellNetworkScanResult; 113 import com.android.internal.telephony.IBooleanConsumer; 114 import com.android.internal.telephony.ICallForwardingInfoCallback; 115 import com.android.internal.telephony.IIntegerConsumer; 116 import com.android.internal.telephony.INumberVerificationCallback; 117 import com.android.internal.telephony.IOns; 118 import com.android.internal.telephony.IPhoneSubInfo; 119 import com.android.internal.telephony.ISetOpportunisticDataCallback; 120 import com.android.internal.telephony.ISms; 121 import com.android.internal.telephony.ISub; 122 import com.android.internal.telephony.ITelephony; 123 import com.android.internal.telephony.IUpdateAvailableNetworksCallback; 124 import com.android.internal.telephony.IccLogicalChannelRequest; 125 import com.android.internal.telephony.OperatorInfo; 126 import com.android.internal.telephony.PhoneConstants; 127 import com.android.internal.telephony.RILConstants; 128 import com.android.internal.telephony.SmsApplication; 129 import com.android.telephony.Rlog; 130 131 import java.io.IOException; 132 import java.io.InputStream; 133 import java.io.OutputStream; 134 import java.lang.annotation.Retention; 135 import java.lang.annotation.RetentionPolicy; 136 import java.nio.file.Files; 137 import java.nio.file.Path; 138 import java.util.ArrayList; 139 import java.util.Arrays; 140 import java.util.Collection; 141 import java.util.Collections; 142 import java.util.HashMap; 143 import java.util.List; 144 import java.util.Locale; 145 import java.util.Map; 146 import java.util.Objects; 147 import java.util.Optional; 148 import java.util.Set; 149 import java.util.UUID; 150 import java.util.concurrent.Executor; 151 import java.util.concurrent.RejectedExecutionException; 152 import java.util.function.Consumer; 153 import java.util.stream.Collectors; 154 import java.util.stream.IntStream; 155 156 /** 157 * Provides access to information about the telephony services on 158 * the device. Applications can use the methods in this class to 159 * determine telephony services and states, as well as to access some 160 * types of subscriber information. Applications can also register 161 * a listener to receive notification of telephony state changes. 162 * <p> 163 * The returned TelephonyManager will use the default subscription for all calls. 164 * To call an API for a specific subscription, use {@link #createForSubscriptionId(int)}. e.g. 165 * <code> 166 * telephonyManager = defaultSubTelephonyManager.createForSubscriptionId(subId); 167 * </code> 168 * <p> 169 * Note that access to some telephony information is 170 * permission-protected. Your application cannot access the protected 171 * information unless it has the appropriate permissions declared in 172 * its manifest file. Where permissions apply, they are noted in the 173 * the methods through which you access the protected information. 174 * 175 * <p>TelephonyManager is intended for use on devices that implement 176 * {@link android.content.pm.PackageManager#FEATURE_TELEPHONY FEATURE_TELEPHONY}. On devices 177 * that do not implement this feature, the behavior is not reliable. 178 */ 179 @SystemService(Context.TELEPHONY_SERVICE) 180 @RequiresFeature(PackageManager.FEATURE_TELEPHONY) 181 public class TelephonyManager { 182 private static final String TAG = "TelephonyManager"; 183 184 private TelephonyRegistryManager mTelephonyRegistryMgr; 185 /** 186 * To expand the error codes for {@link TelephonyManager#updateAvailableNetworks} and 187 * {@link TelephonyManager#setPreferredOpportunisticDataSubscription}. 188 */ 189 @ChangeId 190 @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q) 191 private static final long CALLBACK_ON_MORE_ERROR_CODE_CHANGE = 130595455L; 192 193 /** 194 * The key to use when placing the result of {@link #requestModemActivityInfo(ResultReceiver)} 195 * into the ResultReceiver Bundle. 196 * @hide 197 */ 198 public static final String MODEM_ACTIVITY_RESULT_KEY = "controller_activity"; 199 200 /** @hide */ 201 public static final String EXCEPTION_RESULT_KEY = "exception"; 202 203 /** 204 * The process name of the Phone app as well as many other apps that use this process name, such 205 * as settings and vendor components. 206 * @hide 207 */ 208 public static final String PHONE_PROCESS_NAME = "com.android.phone"; 209 210 /** 211 * The allowed states of Wi-Fi calling. 212 * 213 * @hide 214 */ 215 public interface WifiCallingChoices { 216 /** Always use Wi-Fi calling */ 217 static final int ALWAYS_USE = 0; 218 /** Ask the user whether to use Wi-Fi on every call */ 219 static final int ASK_EVERY_TIME = 1; 220 /** Never use Wi-Fi calling */ 221 static final int NEVER_USE = 2; 222 } 223 224 /** @hide */ 225 @Retention(RetentionPolicy.SOURCE) 226 @IntDef(prefix = {"NETWORK_SELECTION_MODE_"}, 227 value = { 228 NETWORK_SELECTION_MODE_UNKNOWN, 229 NETWORK_SELECTION_MODE_AUTO, 230 NETWORK_SELECTION_MODE_MANUAL}) 231 public @interface NetworkSelectionMode {} 232 233 public static final int NETWORK_SELECTION_MODE_UNKNOWN = 0; 234 public static final int NETWORK_SELECTION_MODE_AUTO = 1; 235 public static final int NETWORK_SELECTION_MODE_MANUAL = 2; 236 237 /** The otaspMode passed to PhoneStateListener#onOtaspChanged */ 238 /** @hide */ 239 static public final int OTASP_UNINITIALIZED = 0; 240 /** @hide */ 241 static public final int OTASP_UNKNOWN = 1; 242 /** @hide */ 243 static public final int OTASP_NEEDED = 2; 244 /** @hide */ 245 static public final int OTASP_NOT_NEEDED = 3; 246 /* OtaUtil has conflict enum 4: OtaUtils.OTASP_FAILURE_SPC_RETRIES */ 247 /** @hide */ 248 static public final int OTASP_SIM_UNPROVISIONED = 5; 249 250 /** 251 * Used in carrier Wi-Fi for IMSI + IMPI encryption, this indicates a public key that's 252 * available for use in ePDG links. 253 * 254 * @hide 255 */ 256 @SystemApi 257 static public final int KEY_TYPE_EPDG = 1; 258 259 /** 260 * Used in carrier Wi-Fi for IMSI + IMPI encryption, this indicates a public key that's 261 * available for use in WLAN links. 262 * 263 * @hide 264 */ 265 @SystemApi 266 static public final int KEY_TYPE_WLAN = 2; 267 268 /** @hide */ 269 @Retention(RetentionPolicy.SOURCE) 270 @IntDef(prefix = {"KEY_TYPE_"}, value = {KEY_TYPE_EPDG, KEY_TYPE_WLAN}) 271 public @interface KeyType {} 272 273 /** 274 * No Single Radio Voice Call Continuity (SRVCC) handover is active. 275 * See TS 23.216 for more information. 276 * @hide 277 */ 278 @SystemApi 279 public static final int SRVCC_STATE_HANDOVER_NONE = -1; 280 281 /** 282 * Single Radio Voice Call Continuity (SRVCC) handover has been started on the network. 283 * See TS 23.216 for more information. 284 * @hide 285 */ 286 @SystemApi 287 public static final int SRVCC_STATE_HANDOVER_STARTED = 0; 288 289 /** 290 * Ongoing Single Radio Voice Call Continuity (SRVCC) handover has successfully completed. 291 * See TS 23.216 for more information. 292 * @hide 293 */ 294 @SystemApi 295 public static final int SRVCC_STATE_HANDOVER_COMPLETED = 1; 296 297 /** 298 * Ongoing Single Radio Voice Call Continuity (SRVCC) handover has failed. 299 * See TS 23.216 for more information. 300 * @hide 301 */ 302 @SystemApi 303 public static final int SRVCC_STATE_HANDOVER_FAILED = 2; 304 305 /** 306 * Ongoing Single Radio Voice Call Continuity (SRVCC) handover has been canceled. 307 * See TS 23.216 for more information. 308 * @hide 309 */ 310 @SystemApi 311 public static final int SRVCC_STATE_HANDOVER_CANCELED = 3; 312 313 /** 314 * A UICC card identifier used if the device does not support the operation. 315 * For example, {@link #getCardIdForDefaultEuicc()} returns this value if the device has no 316 * eUICC, or the eUICC cannot be read. 317 */ 318 public static final int UNSUPPORTED_CARD_ID = -1; 319 320 /** 321 * A UICC card identifier used before the UICC card is loaded. See 322 * {@link #getCardIdForDefaultEuicc()} and {@link UiccCardInfo#getCardId()}. 323 * <p> 324 * Note that once the UICC card is loaded, the card ID may become {@link #UNSUPPORTED_CARD_ID}. 325 */ 326 public static final int UNINITIALIZED_CARD_ID = -2; 327 328 /** 329 * Default port index for a UICC. 330 * 331 * On physical SIM cards the only available port is 0. 332 * See {@link android.telephony.UiccPortInfo} for more information on ports. 333 * 334 * See {@link android.telephony.euicc.EuiccManager#isSimPortAvailable(int)} for information on 335 * how portIndex is used on eUICCs. 336 */ 337 public static final int DEFAULT_PORT_INDEX = 0; 338 339 /** @hide */ 340 public static final int INVALID_PORT_INDEX = -1; 341 342 private final Context mContext; 343 private final int mSubId; 344 @UnsupportedAppUsage 345 private SubscriptionManager mSubscriptionManager; 346 private TelephonyScanManager mTelephonyScanManager; 347 348 /** Cached service handles, cleared by resetServiceHandles() at death */ 349 private static final Object sCacheLock = new Object(); 350 351 /** @hide */ 352 private static boolean sServiceHandleCacheEnabled = true; 353 354 @GuardedBy("sCacheLock") 355 private static ITelephony sITelephony; 356 @GuardedBy("sCacheLock") 357 private static IPhoneSubInfo sIPhoneSubInfo; 358 @GuardedBy("sCacheLock") 359 private static ISub sISub; 360 @GuardedBy("sCacheLock") 361 private static ISms sISms; 362 @GuardedBy("sCacheLock") 363 private static final DeathRecipient sServiceDeath = new DeathRecipient(); 364 365 /** 366 * Cache key for a {@link PropertyInvalidatedCache} which maps from {@link PhoneAccountHandle} 367 * to subscription Id. The cache is initialized in {@code PhoneInterfaceManager}'s constructor 368 * when {@link PropertyInvalidatedCache#invalidateCache(String)} is called. 369 * The cache is cleared from {@code TelecomAccountRegistry#tearDown} when all phone accounts are 370 * removed from Telecom. 371 * @hide 372 */ 373 public static final String CACHE_KEY_PHONE_ACCOUNT_TO_SUBID = 374 "cache_key.telephony.phone_account_to_subid"; 375 private static final int CACHE_MAX_SIZE = 4; 376 377 /** 378 * A {@link PropertyInvalidatedCache} which lives in an app's {@link TelephonyManager} instance. 379 * Caches any queries for a mapping between {@link PhoneAccountHandle} and {@code subscription 380 * id}. The cache may be invalidated from Telephony when phone account re-registration takes 381 * place. 382 */ 383 private PropertyInvalidatedCache<PhoneAccountHandle, Integer> mPhoneAccountHandleToSubIdCache = 384 new PropertyInvalidatedCache<PhoneAccountHandle, Integer>(CACHE_MAX_SIZE, 385 CACHE_KEY_PHONE_ACCOUNT_TO_SUBID) { 386 @Override 387 public Integer recompute(PhoneAccountHandle phoneAccountHandle) { 388 try { 389 ITelephony telephony = getITelephony(); 390 if (telephony != null) { 391 return telephony.getSubIdForPhoneAccountHandle(phoneAccountHandle, 392 mContext.getOpPackageName(), mContext.getAttributionTag()); 393 } 394 } catch (RemoteException e) { 395 throw e.rethrowAsRuntimeException(); 396 } 397 return SubscriptionManager.INVALID_SUBSCRIPTION_ID; 398 } 399 }; 400 401 /** Enum indicating multisim variants 402 * DSDS - Dual SIM Dual Standby 403 * DSDA - Dual SIM Dual Active 404 * TSTS - Triple SIM Triple Standby 405 **/ 406 /** @hide */ 407 @UnsupportedAppUsage(implicitMember = 408 "values()[Landroid/telephony/TelephonyManager$MultiSimVariants;") 409 public enum MultiSimVariants { 410 @UnsupportedAppUsage 411 DSDS, 412 @UnsupportedAppUsage 413 DSDA, 414 @UnsupportedAppUsage 415 TSTS, 416 @UnsupportedAppUsage 417 UNKNOWN 418 }; 419 420 /** @hide */ 421 @UnsupportedAppUsage TelephonyManager(Context context)422 public TelephonyManager(Context context) { 423 this(context, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID); 424 } 425 426 /** @hide */ 427 @UnsupportedAppUsage TelephonyManager(Context context, int subId)428 public TelephonyManager(Context context, int subId) { 429 mSubId = subId; 430 mContext = mergeAttributionAndRenouncedPermissions(context.getApplicationContext(), 431 context); 432 mSubscriptionManager = SubscriptionManager.from(mContext); 433 } 434 435 /** @hide */ 436 @UnsupportedAppUsage TelephonyManager()437 private TelephonyManager() { 438 mContext = null; 439 mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 440 } 441 442 private static TelephonyManager sInstance = new TelephonyManager(); 443 444 /** @hide 445 /* @deprecated - use getSystemService as described above */ 446 @Deprecated 447 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getDefault()448 public static TelephonyManager getDefault() { 449 return sInstance; 450 } 451 452 // This method takes the Application context and adds the attributionTag 453 // and renouncedPermissions from the given context. mergeAttributionAndRenouncedPermissions(Context to, Context from)454 private Context mergeAttributionAndRenouncedPermissions(Context to, Context from) { 455 Context contextToReturn = from; 456 if (to != null) { 457 if (!Objects.equals(from.getAttributionTag(), to.getAttributionTag())) { 458 contextToReturn = to.createAttributionContext(from.getAttributionTag()); 459 } else { 460 contextToReturn = to; 461 } 462 463 Set<String> renouncedPermissions = 464 from.getAttributionSource().getRenouncedPermissions(); 465 if (!renouncedPermissions.isEmpty()) { 466 if (to.getParams() != null) { 467 contextToReturn = contextToReturn.createContext( 468 new ContextParams.Builder(to.getParams()) 469 .setRenouncedPermissions(renouncedPermissions).build()); 470 } else { 471 contextToReturn = contextToReturn.createContext( 472 new ContextParams.Builder() 473 .setRenouncedPermissions(renouncedPermissions).build()); 474 } 475 } 476 } 477 return contextToReturn; 478 } 479 getOpPackageName()480 private String getOpPackageName() { 481 // For legacy reasons the TelephonyManager has API for getting 482 // a static instance with no context set preventing us from 483 // getting the op package name. As a workaround we do a best 484 // effort and get the context from the current activity thread. 485 if (mContext != null) { 486 return mContext.getOpPackageName(); 487 } else { 488 ITelephony telephony = getITelephony(); 489 if (telephony == null) return null; 490 try { 491 return telephony.getCurrentPackageName(); 492 } catch (RemoteException ex) { 493 return null; 494 } catch (NullPointerException ex) { 495 return null; 496 } 497 } 498 } 499 getAttributionTag()500 private String getAttributionTag() { 501 // For legacy reasons the TelephonyManager has API for getting 502 // a static instance with no context set preventing us from 503 // getting the attribution tag. 504 if (mContext != null) { 505 return mContext.getAttributionTag(); 506 } 507 return null; 508 } 509 getRenouncedPermissions()510 private Set<String> getRenouncedPermissions() { 511 // For legacy reasons the TelephonyManager has API for getting 512 // a static instance with no context set preventing us from 513 // getting the attribution source. 514 if (mContext != null) { 515 return mContext.getAttributionSource().getRenouncedPermissions(); 516 } 517 return Collections.emptySet(); 518 } 519 520 /** 521 * Post a runnable to the BackgroundThread. 522 * 523 * Used to invoke user callbacks without calling into the caller's executor from the caller's 524 * calling thread context, for example to provide asynchronous error information that is 525 * generated locally (not over a binder thread). 526 * 527 * <p>This is not necessary unless you are invoking caller's code asynchronously from within 528 * the caller's thread context. 529 * 530 * @param r a runnable. 531 */ runOnBackgroundThread(@onNull Runnable r)532 private static void runOnBackgroundThread(@NonNull Runnable r) { 533 try { 534 BackgroundThread.getExecutor().execute(r); 535 } catch (RejectedExecutionException e) { 536 throw new IllegalStateException( 537 "Failed to post a callback from the caller's thread context.", e); 538 } 539 } 540 541 /** 542 * Returns the multi SIM variant 543 * Returns DSDS for Dual SIM Dual Standby 544 * Returns DSDA for Dual SIM Dual Active 545 * Returns TSTS for Triple SIM Triple Standby 546 * Returns UNKNOWN for others 547 */ 548 /** {@hide} */ 549 @UnsupportedAppUsage getMultiSimConfiguration()550 public MultiSimVariants getMultiSimConfiguration() { 551 String mSimConfig = 552 TelephonyProperties.multi_sim_config().orElse(""); 553 if (mSimConfig.equals("dsds")) { 554 return MultiSimVariants.DSDS; 555 } else if (mSimConfig.equals("dsda")) { 556 return MultiSimVariants.DSDA; 557 } else if (mSimConfig.equals("tsts")) { 558 return MultiSimVariants.TSTS; 559 } else { 560 return MultiSimVariants.UNKNOWN; 561 } 562 } 563 564 /** 565 * Returns the number of phones available. 566 * Returns 0 if none of voice, sms, data is not supported 567 * Returns 1 for Single standby mode (Single SIM functionality). 568 * Returns 2 for Dual standby mode (Dual SIM functionality). 569 * Returns 3 for Tri standby mode (Tri SIM functionality). 570 * @deprecated Use {@link #getActiveModemCount} instead. 571 */ 572 @Deprecated getPhoneCount()573 public int getPhoneCount() { 574 return getActiveModemCount(); 575 } 576 577 /** 578 * Returns the number of logical modems currently configured to be activated. 579 * 580 * Returns 0 if none of voice, sms, data is not supported 581 * Returns 1 for Single standby mode (Single SIM functionality). 582 * Returns 2 for Dual standby mode (Dual SIM functionality). 583 * Returns 3 for Tri standby mode (Tri SIM functionality). 584 */ getActiveModemCount()585 public int getActiveModemCount() { 586 int modemCount = 1; 587 switch (getMultiSimConfiguration()) { 588 case UNKNOWN: 589 modemCount = 1; 590 // check for voice and data support, 0 if not supported 591 if (!isVoiceCapable() && !isSmsCapable() && !isDataCapable()) { 592 modemCount = 0; 593 } 594 break; 595 case DSDS: 596 case DSDA: 597 modemCount = 2; 598 break; 599 case TSTS: 600 modemCount = 3; 601 break; 602 } 603 return modemCount; 604 } 605 606 /** 607 * Return how many logical modem can be potentially active simultaneously, in terms of hardware 608 * capability. 609 * It might return different value from {@link #getActiveModemCount}. For example, for a 610 * dual-SIM capable device operating in single SIM mode (only one logical modem is turned on), 611 * {@link #getActiveModemCount} returns 1 while this API returns 2. 612 */ getSupportedModemCount()613 public int getSupportedModemCount() { 614 return TelephonyProperties.max_active_modems().orElse(getActiveModemCount()); 615 } 616 617 /** 618 * Gets the maximum number of SIMs that can be active, based on the device's multisim 619 * configuration. 620 * @return 1 for single-SIM, DSDS, and TSTS devices. 2 for DSDA devices. 621 * @hide 622 */ 623 @SystemApi getMaxNumberOfSimultaneouslyActiveSims()624 public int getMaxNumberOfSimultaneouslyActiveSims() { 625 switch (getMultiSimConfiguration()) { 626 case UNKNOWN: 627 case DSDS: 628 case TSTS: 629 return 1; 630 case DSDA: 631 return 2; 632 } 633 return 1; 634 } 635 636 /** {@hide} */ 637 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) from(Context context)638 public static TelephonyManager from(Context context) { 639 return (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 640 } 641 642 /** 643 * Create a new TelephonyManager object pinned to the given subscription ID. 644 * 645 * @return a TelephonyManager that uses the given subId for all calls. 646 */ createForSubscriptionId(int subId)647 public TelephonyManager createForSubscriptionId(int subId) { 648 // Don't reuse any TelephonyManager objects. 649 return new TelephonyManager(mContext, subId); 650 } 651 652 /** 653 * Create a new TelephonyManager object pinned to the subscription ID associated with the given 654 * phone account. 655 * 656 * @return a TelephonyManager that uses the given phone account for all calls, or {@code null} 657 * if the phone account does not correspond to a valid subscription ID. 658 */ 659 @Nullable createForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle)660 public TelephonyManager createForPhoneAccountHandle(PhoneAccountHandle phoneAccountHandle) { 661 int subId = getSubscriptionId(phoneAccountHandle); 662 if (!SubscriptionManager.isValidSubscriptionId(subId)) { 663 return null; 664 } 665 return new TelephonyManager(mContext, subId); 666 } 667 668 /** {@hide} */ 669 @UnsupportedAppUsage isMultiSimEnabled()670 public boolean isMultiSimEnabled() { 671 return getPhoneCount() > 1; 672 } 673 674 private static final int MAXIMUM_CALL_COMPOSER_PICTURE_SIZE = 80000; 675 676 /** 677 * Indicates the maximum size of the call composure picture. 678 * 679 * Pictures sent via 680 * {@link #uploadCallComposerPicture(InputStream, String, Executor, OutcomeReceiver)} 681 * or {@link #uploadCallComposerPicture(Path, String, Executor, OutcomeReceiver)} must not 682 * exceed this size, or an error will be returned via the callback in those methods. 683 * 684 * @return Maximum file size in bytes. 685 */ getMaximumCallComposerPictureSize()686 public static @BytesLong long getMaximumCallComposerPictureSize() { 687 return MAXIMUM_CALL_COMPOSER_PICTURE_SIZE; 688 } 689 690 // 691 // Broadcast Intent actions 692 // 693 694 /** 695 * Broadcast intent action indicating that the call state 696 * on the device has changed. 697 * 698 * <p> 699 * The {@link #EXTRA_STATE} extra indicates the new call state. 700 * If a receiving app has {@link android.Manifest.permission#READ_CALL_LOG} permission, a second 701 * extra {@link #EXTRA_INCOMING_NUMBER} provides the phone number for incoming and outgoing 702 * calls as a String. 703 * <p> 704 * If the receiving app has 705 * {@link android.Manifest.permission#READ_CALL_LOG} and 706 * {@link android.Manifest.permission#READ_PHONE_STATE} permission, it will receive the 707 * broadcast twice; one with the {@link #EXTRA_INCOMING_NUMBER} populated with the phone number, 708 * and another with it blank. Due to the nature of broadcasts, you cannot assume the order 709 * in which these broadcasts will arrive, however you are guaranteed to receive two in this 710 * case. Apps which are interested in the {@link #EXTRA_INCOMING_NUMBER} can ignore the 711 * broadcasts where {@link #EXTRA_INCOMING_NUMBER} is not present in the extras (e.g. where 712 * {@link Intent#hasExtra(String)} returns {@code false}). 713 * <p class="note"> 714 * This was a {@link android.content.Context#sendStickyBroadcast sticky} 715 * broadcast in version 1.0, but it is no longer sticky. 716 * Instead, use {@link #getCallState} to synchronously query the current call state. 717 * 718 * @see #EXTRA_STATE 719 * @see #EXTRA_INCOMING_NUMBER 720 * @see #getCallState 721 */ 722 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 723 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 724 public static final String ACTION_PHONE_STATE_CHANGED = 725 "android.intent.action.PHONE_STATE"; 726 727 /** 728 * The Phone app sends this intent when a user opts to respond-via-message during an incoming 729 * call. By default, the device's default SMS app consumes this message and sends a text message 730 * to the caller. A third party app can also provide this functionality by consuming this Intent 731 * with a {@link android.app.Service} and sending the message using its own messaging system. 732 * <p>The intent contains a URI (available from {@link android.content.Intent#getData}) 733 * describing the recipient, using either the {@code sms:}, {@code smsto:}, {@code mms:}, 734 * or {@code mmsto:} URI schema. Each of these URI schema carry the recipient information the 735 * same way: the path part of the URI contains the recipient's phone number or a comma-separated 736 * set of phone numbers if there are multiple recipients. For example, {@code 737 * smsto:2065551234}.</p> 738 * 739 * <p>The intent may also contain extras for the message text (in {@link 740 * android.content.Intent#EXTRA_TEXT}) and a message subject 741 * (in {@link android.content.Intent#EXTRA_SUBJECT}).</p> 742 * 743 * <p class="note"><strong>Note:</strong> 744 * The intent-filter that consumes this Intent needs to be in a {@link android.app.Service} 745 * that requires the 746 * permission {@link android.Manifest.permission#SEND_RESPOND_VIA_MESSAGE}.</p> 747 * <p>For example, the service that receives this intent can be declared in the manifest file 748 * with an intent filter like this:</p> 749 * <pre> 750 * <!-- Service that delivers SMS messages received from the phone "quick response" --> 751 * <service android:name=".HeadlessSmsSendService" 752 * android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" 753 * android:exported="true" > 754 * <intent-filter> 755 * <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /> 756 * <category android:name="android.intent.category.DEFAULT" /> 757 * <data android:scheme="sms" /> 758 * <data android:scheme="smsto" /> 759 * <data android:scheme="mms" /> 760 * <data android:scheme="mmsto" /> 761 * </intent-filter> 762 * </service></pre> 763 * <p> 764 * Output: nothing. 765 */ 766 @SdkConstant(SdkConstantType.SERVICE_ACTION) 767 public static final String ACTION_RESPOND_VIA_MESSAGE = 768 "android.intent.action.RESPOND_VIA_MESSAGE"; 769 770 /** 771 * The emergency dialer may choose to present activities with intent filters for this 772 * action as emergency assistance buttons that launch the activity when clicked. 773 * 774 * @hide 775 */ 776 @SystemApi 777 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 778 public static final String ACTION_EMERGENCY_ASSISTANCE = 779 "android.telephony.action.EMERGENCY_ASSISTANCE"; 780 781 /** 782 * A boolean meta-data value indicating whether the voicemail settings should be hidden in the 783 * call settings page launched by 784 * {@link android.telecom.TelecomManager#ACTION_SHOW_CALL_SETTINGS}. 785 * Dialer implementations (see {@link android.telecom.TelecomManager#getDefaultDialerPackage()}) 786 * which would also like to manage voicemail settings should set this meta-data to {@code true} 787 * in the manifest registration of their application. 788 * 789 * @see android.telecom.TelecomManager#ACTION_SHOW_CALL_SETTINGS 790 * @see #ACTION_CONFIGURE_VOICEMAIL 791 * @see #EXTRA_HIDE_PUBLIC_SETTINGS 792 */ 793 public static final String METADATA_HIDE_VOICEMAIL_SETTINGS_MENU = 794 "android.telephony.HIDE_VOICEMAIL_SETTINGS_MENU"; 795 796 /** 797 * Open the voicemail settings activity to make changes to voicemail configuration. 798 * 799 * <p> 800 * The {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra indicates which {@link PhoneAccountHandle} to 801 * configure voicemail. 802 * The {@link #EXTRA_HIDE_PUBLIC_SETTINGS} hides settings the dialer will modify through public 803 * API if set. 804 * 805 * @see #EXTRA_PHONE_ACCOUNT_HANDLE 806 * @see #EXTRA_HIDE_PUBLIC_SETTINGS 807 */ 808 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 809 public static final String ACTION_CONFIGURE_VOICEMAIL = 810 "android.telephony.action.CONFIGURE_VOICEMAIL"; 811 812 /** 813 * The boolean value indicating whether the voicemail settings activity launched by {@link 814 * #ACTION_CONFIGURE_VOICEMAIL} should hide settings accessible through public API. This is 815 * used by dialer implementations which provides their own voicemail settings UI, but still 816 * needs to expose device specific voicemail settings to the user. 817 * 818 * @see #ACTION_CONFIGURE_VOICEMAIL 819 * @see #METADATA_HIDE_VOICEMAIL_SETTINGS_MENU 820 */ 821 public static final String EXTRA_HIDE_PUBLIC_SETTINGS = 822 "android.telephony.extra.HIDE_PUBLIC_SETTINGS"; 823 824 /** 825 * @hide 826 */ 827 public static final boolean EMERGENCY_ASSISTANCE_ENABLED = true; 828 829 /** 830 * The lookup key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 831 * for a String containing the new call state. 832 * 833 * <p class="note"> 834 * Retrieve with 835 * {@link android.content.Intent#getStringExtra(String)}. 836 * 837 * @see #EXTRA_STATE_IDLE 838 * @see #EXTRA_STATE_RINGING 839 * @see #EXTRA_STATE_OFFHOOK 840 */ 841 public static final String EXTRA_STATE = PhoneConstants.STATE_KEY; 842 843 /** 844 * Value used with {@link #EXTRA_STATE} corresponding to 845 * {@link #CALL_STATE_IDLE}. 846 */ 847 public static final String EXTRA_STATE_IDLE = PhoneConstants.State.IDLE.toString(); 848 849 /** 850 * Value used with {@link #EXTRA_STATE} corresponding to 851 * {@link #CALL_STATE_RINGING}. 852 */ 853 public static final String EXTRA_STATE_RINGING = PhoneConstants.State.RINGING.toString(); 854 855 /** 856 * Value used with {@link #EXTRA_STATE} corresponding to 857 * {@link #CALL_STATE_OFFHOOK}. 858 */ 859 public static final String EXTRA_STATE_OFFHOOK = PhoneConstants.State.OFFHOOK.toString(); 860 861 /** 862 * Extra key used with the {@link #ACTION_PHONE_STATE_CHANGED} broadcast 863 * for a String containing the incoming or outgoing phone number. 864 * <p> 865 * This extra is only populated for receivers of the {@link #ACTION_PHONE_STATE_CHANGED} 866 * broadcast which have been granted the {@link android.Manifest.permission#READ_CALL_LOG} and 867 * {@link android.Manifest.permission#READ_PHONE_STATE} permissions. 868 * <p> 869 * For incoming calls, the phone number is only guaranteed to be populated when the 870 * {@link #EXTRA_STATE} changes from {@link #EXTRA_STATE_IDLE} to {@link #EXTRA_STATE_RINGING}. 871 * If the incoming caller is from an unknown number, the extra will be populated with an empty 872 * string. 873 * For outgoing calls, the phone number is only guaranteed to be populated when the 874 * {@link #EXTRA_STATE} changes from {@link #EXTRA_STATE_IDLE} to {@link #EXTRA_STATE_OFFHOOK}. 875 * <p class="note"> 876 * Retrieve with 877 * {@link android.content.Intent#getStringExtra(String)}. 878 * <p> 879 * 880 * @deprecated Companion apps for wearable devices should use the {@link InCallService} API 881 * to retrieve the phone number for calls instead. Apps performing call screening should use 882 * the {@link CallScreeningService} API instead. 883 */ 884 @Deprecated 885 public static final String EXTRA_INCOMING_NUMBER = "incoming_number"; 886 887 /** 888 * Broadcast intent action indicating that call disconnect cause has changed. 889 * 890 * <p> 891 * The {@link #EXTRA_DISCONNECT_CAUSE} extra indicates the disconnect cause. 892 * The {@link #EXTRA_PRECISE_DISCONNECT_CAUSE} extra indicates the precise disconnect cause. 893 * 894 * <p class="note"> 895 * Requires the READ_PRECISE_PHONE_STATE permission. 896 * 897 * @see #EXTRA_DISCONNECT_CAUSE 898 * @see #EXTRA_PRECISE_DISCONNECT_CAUSE 899 * 900 * @hide 901 */ 902 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 903 public static final String ACTION_CALL_DISCONNECT_CAUSE_CHANGED = 904 "android.intent.action.CALL_DISCONNECT_CAUSE"; 905 906 /** 907 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast and 908 * {@link PhoneStateListener#onPreciseCallStateChanged(PreciseCallState)} for an integer 909 * containing the disconnect cause. 910 * 911 * @see DisconnectCause 912 * 913 * <p class="note"> 914 * Retrieve with 915 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 916 * 917 * @deprecated Should use the {@link TelecomManager#EXTRA_DISCONNECT_CAUSE} instead. 918 * @hide 919 */ 920 @Deprecated 921 public static final String EXTRA_DISCONNECT_CAUSE = "disconnect_cause"; 922 923 /** 924 * The lookup key used with the {@link #ACTION_PRECISE_CALL_STATE_CHANGED} broadcast and 925 * {@link PhoneStateListener#onPreciseCallStateChanged(PreciseCallState)} for an integer 926 * containing the disconnect cause provided by the RIL. 927 * 928 * @see PreciseDisconnectCause 929 * 930 * <p class="note"> 931 * Retrieve with 932 * {@link android.content.Intent#getIntExtra(String name, int defaultValue)}. 933 * 934 * @hide 935 */ 936 public static final String EXTRA_PRECISE_DISCONNECT_CAUSE = "precise_disconnect_cause"; 937 938 /** 939 * Broadcast intent action for letting the default dialer to know to show voicemail 940 * notification. 941 * 942 * <p> 943 * The {@link #EXTRA_PHONE_ACCOUNT_HANDLE} extra indicates which {@link PhoneAccountHandle} the 944 * voicemail is received on. 945 * The {@link #EXTRA_NOTIFICATION_COUNT} extra indicates the total numbers of unheard 946 * voicemails. 947 * The {@link #EXTRA_VOICEMAIL_NUMBER} extra indicates the voicemail number if available. 948 * The {@link #EXTRA_CALL_VOICEMAIL_INTENT} extra is a {@link android.app.PendingIntent} that 949 * will call the voicemail number when sent. This extra will be empty if the voicemail number 950 * is not set, and {@link #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT} will be set instead. 951 * The {@link #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT} extra is a 952 * {@link android.app.PendingIntent} that will launch the voicemail settings. This extra is only 953 * available when the voicemail number is not set. 954 * The {@link #EXTRA_IS_REFRESH} extra indicates whether the notification is a refresh or a new 955 * notification. 956 * 957 * @see #EXTRA_PHONE_ACCOUNT_HANDLE 958 * @see #EXTRA_NOTIFICATION_COUNT 959 * @see #EXTRA_VOICEMAIL_NUMBER 960 * @see #EXTRA_CALL_VOICEMAIL_INTENT 961 * @see #EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT 962 * @see #EXTRA_IS_REFRESH 963 */ 964 public static final String ACTION_SHOW_VOICEMAIL_NOTIFICATION = 965 "android.telephony.action.SHOW_VOICEMAIL_NOTIFICATION"; 966 967 /** 968 * The extra used with an {@link #ACTION_CONFIGURE_VOICEMAIL} and 969 * {@link #ACTION_SHOW_VOICEMAIL_NOTIFICATION} {@code Intent} to specify the 970 * {@link PhoneAccountHandle} the configuration or notification is for. 971 * <p class="note"> 972 * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}. 973 */ 974 public static final String EXTRA_PHONE_ACCOUNT_HANDLE = 975 "android.telephony.extra.PHONE_ACCOUNT_HANDLE"; 976 977 /** 978 * The number of voice messages associated with the notification. 979 */ 980 public static final String EXTRA_NOTIFICATION_COUNT = 981 "android.telephony.extra.NOTIFICATION_COUNT"; 982 983 /** 984 * The voicemail number. 985 */ 986 public static final String EXTRA_VOICEMAIL_NUMBER = 987 "android.telephony.extra.VOICEMAIL_NUMBER"; 988 989 /** 990 * The intent to call voicemail. 991 */ 992 public static final String EXTRA_CALL_VOICEMAIL_INTENT = 993 "android.telephony.extra.CALL_VOICEMAIL_INTENT"; 994 995 /** 996 * The intent to launch voicemail settings. 997 */ 998 public static final String EXTRA_LAUNCH_VOICEMAIL_SETTINGS_INTENT = 999 "android.telephony.extra.LAUNCH_VOICEMAIL_SETTINGS_INTENT"; 1000 1001 /** 1002 * Boolean value representing whether the {@link 1003 * TelephonyManager#ACTION_SHOW_VOICEMAIL_NOTIFICATION} is new or a refresh of an existing 1004 * notification. Notification refresh happens after reboot or connectivity changes. The user has 1005 * already been notified for the voicemail so it should not alert the user, and should not be 1006 * shown again if the user has dismissed it. 1007 */ 1008 public static final String EXTRA_IS_REFRESH = "android.telephony.extra.IS_REFRESH"; 1009 1010 /** 1011 * {@link android.telecom.Connection} event used to indicate that an IMS call has be 1012 * successfully handed over from WIFI to LTE. 1013 * <p> 1014 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1015 * The {@link Bundle} parameter is expected to be null when this connection event is used. 1016 * @hide 1017 */ 1018 public static final String EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE = 1019 "android.telephony.event.EVENT_HANDOVER_VIDEO_FROM_WIFI_TO_LTE"; 1020 1021 /** 1022 * {@link android.telecom.Connection} event used to indicate that an IMS call has be 1023 * successfully handed over from LTE to WIFI. 1024 * <p> 1025 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1026 * The {@link Bundle} parameter is expected to be null when this connection event is used. 1027 * @hide 1028 */ 1029 public static final String EVENT_HANDOVER_VIDEO_FROM_LTE_TO_WIFI = 1030 "android.telephony.event.EVENT_HANDOVER_VIDEO_FROM_LTE_TO_WIFI"; 1031 1032 /** 1033 * {@link android.telecom.Connection} event used to indicate that an IMS call failed to be 1034 * handed over from LTE to WIFI. 1035 * <p> 1036 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1037 * The {@link Bundle} parameter is expected to be null when this connection event is used. 1038 * @hide 1039 */ 1040 public static final String EVENT_HANDOVER_TO_WIFI_FAILED = 1041 "android.telephony.event.EVENT_HANDOVER_TO_WIFI_FAILED"; 1042 1043 /** 1044 * {@link android.telecom.Connection} event used to indicate that a video call was downgraded to 1045 * audio because the data limit was reached. 1046 * <p> 1047 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1048 * The {@link Bundle} parameter is expected to be null when this connection event is used. 1049 * @hide 1050 */ 1051 public static final String EVENT_DOWNGRADE_DATA_LIMIT_REACHED = 1052 "android.telephony.event.EVENT_DOWNGRADE_DATA_LIMIT_REACHED"; 1053 1054 /** 1055 * {@link android.telecom.Connection} event used to indicate that a video call was downgraded to 1056 * audio because the data was disabled. 1057 * <p> 1058 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1059 * The {@link Bundle} parameter is expected to be null when this connection event is used. 1060 * @hide 1061 */ 1062 public static final String EVENT_DOWNGRADE_DATA_DISABLED = 1063 "android.telephony.event.EVENT_DOWNGRADE_DATA_DISABLED"; 1064 1065 /** 1066 * {@link android.telecom.Connection} event used to indicate that the InCall UI should notify 1067 * the user when an international call is placed while on WFC only. 1068 * <p> 1069 * Used when the carrier config value 1070 * {@link CarrierConfigManager#KEY_NOTIFY_INTERNATIONAL_CALL_ON_WFC_BOOL} is true, the device 1071 * is on WFC (VoLTE not available) and an international number is dialed. 1072 * <p> 1073 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1074 * The {@link Bundle} parameter is expected to be null when this connection event is used. 1075 * @hide 1076 */ 1077 public static final String EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC = 1078 "android.telephony.event.EVENT_NOTIFY_INTERNATIONAL_CALL_ON_WFC"; 1079 1080 /** 1081 * {@link android.telecom.Connection} event used to indicate that an outgoing call has been 1082 * forwarded to another number. 1083 * <p> 1084 * Sent in response to an IMS supplementary service notification indicating the call has been 1085 * forwarded. 1086 * <p> 1087 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1088 * The {@link Bundle} parameter is expected to be null when this connection event is used. 1089 * @hide 1090 */ 1091 public static final String EVENT_CALL_FORWARDED = 1092 "android.telephony.event.EVENT_CALL_FORWARDED"; 1093 1094 /** 1095 * {@link android.telecom.Connection} event used to indicate that a supplementary service 1096 * notification has been received. 1097 * <p> 1098 * Sent via {@link android.telecom.Connection#sendConnectionEvent(String, Bundle)}. 1099 * The {@link Bundle} parameter is expected to include the following extras: 1100 * <ul> 1101 * <li>{@link #EXTRA_NOTIFICATION_TYPE} - the notification type.</li> 1102 * <li>{@link #EXTRA_NOTIFICATION_CODE} - the notification code.</li> 1103 * <li>{@link #EXTRA_NOTIFICATION_MESSAGE} - human-readable message associated with the 1104 * supplementary service notification.</li> 1105 * </ul> 1106 * @hide 1107 */ 1108 public static final String EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION = 1109 "android.telephony.event.EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION"; 1110 1111 /** 1112 * Integer extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} which indicates 1113 * the type of supplementary service notification which occurred. 1114 * Will be either 1115 * {@link com.android.internal.telephony.gsm.SuppServiceNotification#NOTIFICATION_TYPE_CODE_1} 1116 * or 1117 * {@link com.android.internal.telephony.gsm.SuppServiceNotification#NOTIFICATION_TYPE_CODE_2} 1118 * <p> 1119 * Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event. 1120 * @hide 1121 */ 1122 public static final String EXTRA_NOTIFICATION_TYPE = 1123 "android.telephony.extra.NOTIFICATION_TYPE"; 1124 1125 /** 1126 * Integer extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} which indicates 1127 * the supplementary service notification which occurred. 1128 * <p> 1129 * Depending on the {@link #EXTRA_NOTIFICATION_TYPE}, the code will be one of the {@code CODE_*} 1130 * codes defined in {@link com.android.internal.telephony.gsm.SuppServiceNotification}. 1131 * <p> 1132 * Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event. 1133 * @hide 1134 */ 1135 public static final String EXTRA_NOTIFICATION_CODE = 1136 "android.telephony.extra.NOTIFICATION_CODE"; 1137 1138 /** 1139 * {@link CharSequence} extra key used with {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} 1140 * which contains a human-readable message which can be displayed to the user for the 1141 * supplementary service notification. 1142 * <p> 1143 * Set in the extras for the {@link #EVENT_SUPPLEMENTARY_SERVICE_NOTIFICATION} connection event. 1144 * @hide 1145 */ 1146 public static final String EXTRA_NOTIFICATION_MESSAGE = 1147 "android.telephony.extra.NOTIFICATION_MESSAGE"; 1148 1149 /* Visual voicemail protocols */ 1150 1151 /** 1152 * The OMTP protocol. 1153 */ 1154 public static final String VVM_TYPE_OMTP = "vvm_type_omtp"; 1155 1156 /** 1157 * A flavor of OMTP protocol with a different mobile originated (MO) format 1158 */ 1159 public static final String VVM_TYPE_CVVM = "vvm_type_cvvm"; 1160 1161 /** 1162 * Key in bundle returned by {@link #getVisualVoicemailPackageName()}, indicating whether visual 1163 * voicemail was enabled or disabled by the user. If the user never explicitly changed this 1164 * setting, this key will not exist. 1165 * 1166 * @see #getVisualVoicemailSettings() 1167 * @hide 1168 */ 1169 @SystemApi 1170 public static final String EXTRA_VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL = 1171 "android.telephony.extra.VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL"; 1172 1173 /** 1174 * Key in bundle returned by {@link #getVisualVoicemailPackageName()}, indicating the voicemail 1175 * access PIN scrambled during the auto provisioning process. The user is expected to reset 1176 * their PIN if this value is not {@code null}. 1177 * 1178 * @see #getVisualVoicemailSettings() 1179 * @hide 1180 */ 1181 @SystemApi 1182 public static final String EXTRA_VOICEMAIL_SCRAMBLED_PIN_STRING = 1183 "android.telephony.extra.VOICEMAIL_SCRAMBLED_PIN_STRING"; 1184 1185 /** 1186 * Broadcast action to be received by Broadcast receivers. 1187 * 1188 * Indicates multi-SIM configuration is changed. For example, it changed 1189 * from single SIM capable to dual-SIM capable (DSDS or DSDA) or triple-SIM mode. 1190 * 1191 * It doesn't indicate how many subscriptions are actually active, or which states SIMs are, 1192 * or that all steps during multi-SIM change are done. To know those information you still need 1193 * to listen to SIM_STATE changes or active subscription changes. 1194 * 1195 * See extra of {@link #EXTRA_ACTIVE_SIM_SUPPORTED_COUNT} for updated value. 1196 */ 1197 public static final String ACTION_MULTI_SIM_CONFIG_CHANGED = 1198 "android.telephony.action.MULTI_SIM_CONFIG_CHANGED"; 1199 1200 1201 /** 1202 * The number of active SIM supported by current multi-SIM config. It's not related to how many 1203 * SIM/subscriptions are currently active. 1204 * 1205 * Same value will be returned by {@link #getActiveModemCount()}. 1206 * 1207 * For single SIM mode, it's 1. 1208 * For DSDS or DSDA mode, it's 2. 1209 * For triple-SIM mode, it's 3. 1210 * 1211 * Extra of {@link #ACTION_MULTI_SIM_CONFIG_CHANGED}. 1212 * 1213 * type: integer 1214 */ 1215 public static final String EXTRA_ACTIVE_SIM_SUPPORTED_COUNT = 1216 "android.telephony.extra.ACTIVE_SIM_SUPPORTED_COUNT"; 1217 1218 /** 1219 * @hide 1220 */ 1221 public static final String USSD_RESPONSE = "USSD_RESPONSE"; 1222 1223 /** 1224 * USSD return code success. 1225 * @hide 1226 */ 1227 public static final int USSD_RETURN_SUCCESS = 100; 1228 1229 /** 1230 * Failed code returned when the mobile network has failed to complete a USSD request. 1231 * <p> 1232 * Returned via {@link TelephonyManager.UssdResponseCallback#onReceiveUssdResponseFailed( 1233 * TelephonyManager, String, int)}. 1234 */ 1235 public static final int USSD_RETURN_FAILURE = -1; 1236 1237 /** 1238 * Failure code returned when a USSD request has failed to execute because the Telephony 1239 * service is unavailable. 1240 * <p> 1241 * Returned via {@link TelephonyManager.UssdResponseCallback#onReceiveUssdResponseFailed( 1242 * TelephonyManager, String, int)}. 1243 */ 1244 public static final int USSD_ERROR_SERVICE_UNAVAIL = -2; 1245 1246 /** 1247 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which leaves the roaming 1248 * mode set to the radio default or to the user's preference if they've indicated one. 1249 */ 1250 public static final int CDMA_ROAMING_MODE_RADIO_DEFAULT = -1; 1251 /** 1252 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which only permits 1253 * connections on home networks. 1254 */ 1255 public static final int CDMA_ROAMING_MODE_HOME = 0; 1256 /** 1257 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which permits roaming on 1258 * affiliated networks. 1259 */ 1260 public static final int CDMA_ROAMING_MODE_AFFILIATED = 1; 1261 /** 1262 * Value for {@link CarrierConfigManager#KEY_CDMA_ROAMING_MODE_INT} which permits roaming on 1263 * any network. 1264 */ 1265 public static final int CDMA_ROAMING_MODE_ANY = 2; 1266 1267 /** @hide */ 1268 @IntDef(prefix = { "CDMA_ROAMING_MODE_" }, value = { 1269 CDMA_ROAMING_MODE_RADIO_DEFAULT, 1270 CDMA_ROAMING_MODE_HOME, 1271 CDMA_ROAMING_MODE_AFFILIATED, 1272 CDMA_ROAMING_MODE_ANY 1273 }) 1274 @Retention(RetentionPolicy.SOURCE) 1275 public @interface CdmaRoamingMode{} 1276 1277 /** 1278 * An unknown carrier id. It could either be subscription unavailable or the subscription 1279 * carrier cannot be recognized. Unrecognized carriers here means 1280 * {@link #getSimOperator() MCC+MNC} cannot be identified. 1281 */ 1282 public static final int UNKNOWN_CARRIER_ID = -1; 1283 1284 /** 1285 * An unknown carrier id list version. 1286 * @hide 1287 */ 1288 @TestApi 1289 public static final int UNKNOWN_CARRIER_ID_LIST_VERSION = -1; 1290 1291 /** 1292 * Broadcast Action: The subscription carrier identity has changed. 1293 * This intent could be sent on the following events: 1294 * <ul> 1295 * <li>Subscription absent. Carrier identity could change from a valid id to 1296 * {@link TelephonyManager#UNKNOWN_CARRIER_ID}.</li> 1297 * <li>Subscription loaded. Carrier identity could change from 1298 * {@link TelephonyManager#UNKNOWN_CARRIER_ID} to a valid id.</li> 1299 * <li>The subscription carrier is recognized after a remote update.</li> 1300 * </ul> 1301 * The intent will have the following extra values: 1302 * <ul> 1303 * <li>{@link #EXTRA_CARRIER_ID} The up-to-date carrier id of the current subscription id. 1304 * </li> 1305 * <li>{@link #EXTRA_CARRIER_NAME} The up-to-date carrier name of the current subscription. 1306 * </li> 1307 * <li>{@link #EXTRA_SUBSCRIPTION_ID} The subscription id associated with the changed carrier 1308 * identity. 1309 * </li> 1310 * </ul> 1311 * <p class="note">This is a protected intent that can only be sent by the system. 1312 */ 1313 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1314 public static final String ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED = 1315 "android.telephony.action.SUBSCRIPTION_CARRIER_IDENTITY_CHANGED"; 1316 1317 /** 1318 * An int extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} which indicates 1319 * the updated carrier id returned by {@link TelephonyManager#getSimCarrierId()}. 1320 * <p>Will be {@link TelephonyManager#UNKNOWN_CARRIER_ID} if the subscription is unavailable or 1321 * the carrier cannot be identified. 1322 */ 1323 public static final String EXTRA_CARRIER_ID = "android.telephony.extra.CARRIER_ID"; 1324 1325 /** 1326 * An string extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} which 1327 * indicates the updated carrier name of the current subscription. 1328 * @see TelephonyManager#getSimCarrierIdName() 1329 * <p>Carrier name is a user-facing name of the carrier id {@link #EXTRA_CARRIER_ID}, 1330 * usually the brand name of the subsidiary (e.g. T-Mobile). 1331 */ 1332 public static final String EXTRA_CARRIER_NAME = "android.telephony.extra.CARRIER_NAME"; 1333 1334 /** 1335 * Broadcast Action: The subscription specific carrier identity has changed. 1336 * 1337 * A specific carrier ID returns the fine-grained carrier ID of the current subscription. 1338 * It can represent the fact that a carrier may be in effect an aggregation of other carriers 1339 * (ie in an MVNO type scenario) where each of these specific carriers which are used to make 1340 * up the actual carrier service may have different carrier configurations. 1341 * A specific carrier ID could also be used, for example, in a scenario where a carrier requires 1342 * different carrier configuration for different service offering such as a prepaid plan. 1343 * 1344 * the specific carrier ID would be used for configuration purposes, but apps wishing to know 1345 * about the carrier itself should use the regular carrier ID returned by 1346 * {@link #getSimCarrierId()}. 1347 * 1348 * <p>Similar like {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED}, this intent will be 1349 * sent on the event of {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} while its also 1350 * possible to be sent without {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} when 1351 * specific carrier ID changes while carrier ID remains the same. 1352 * e.g, the same subscription switches to different IMSI could potentially change its 1353 * specific carrier ID while carrier id remains the same. 1354 * @see #getSimSpecificCarrierId() 1355 * @see #getSimCarrierId() 1356 * 1357 * The intent will have the following extra values: 1358 * <ul> 1359 * <li>{@link #EXTRA_SPECIFIC_CARRIER_ID} The up-to-date specific carrier id of the 1360 * current subscription. 1361 * </li> 1362 * <li>{@link #EXTRA_SPECIFIC_CARRIER_NAME} The up-to-date name of the specific carrier id. 1363 * </li> 1364 * <li>{@link #EXTRA_SUBSCRIPTION_ID} The subscription id associated with the changed carrier 1365 * identity. 1366 * </li> 1367 * </ul> 1368 * <p class="note">This is a protected intent that can only be sent by the system. 1369 */ 1370 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1371 public static final String ACTION_SUBSCRIPTION_SPECIFIC_CARRIER_IDENTITY_CHANGED = 1372 "android.telephony.action.SUBSCRIPTION_SPECIFIC_CARRIER_IDENTITY_CHANGED"; 1373 1374 /** 1375 * An int extra used with {@link #ACTION_SUBSCRIPTION_SPECIFIC_CARRIER_IDENTITY_CHANGED} which 1376 * indicates the updated specific carrier id returned by 1377 * {@link TelephonyManager#getSimSpecificCarrierId()}. Note, its possible specific carrier id 1378 * changes while {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} remains the same 1379 * e.g, when subscription switch to different IMSIs. 1380 * <p>Will be {@link TelephonyManager#UNKNOWN_CARRIER_ID} if the subscription is unavailable or 1381 * the carrier cannot be identified. 1382 */ 1383 public static final String EXTRA_SPECIFIC_CARRIER_ID = 1384 "android.telephony.extra.SPECIFIC_CARRIER_ID"; 1385 1386 /** 1387 * An string extra used with {@link #ACTION_SUBSCRIPTION_SPECIFIC_CARRIER_IDENTITY_CHANGED} 1388 * which indicates the updated specific carrier name returned by 1389 * {@link TelephonyManager#getSimSpecificCarrierIdName()}. 1390 * <p>it's a user-facing name of the specific carrier id {@link #EXTRA_SPECIFIC_CARRIER_ID} 1391 * e.g, Tracfone-AT&T 1392 */ 1393 public static final String EXTRA_SPECIFIC_CARRIER_NAME = 1394 "android.telephony.extra.SPECIFIC_CARRIER_NAME"; 1395 1396 /** 1397 * An int extra used with {@link #ACTION_SUBSCRIPTION_CARRIER_IDENTITY_CHANGED} to indicate the 1398 * subscription which has changed; or in general whenever a subscription ID needs specified. 1399 */ 1400 public static final String EXTRA_SUBSCRIPTION_ID = "android.telephony.extra.SUBSCRIPTION_ID"; 1401 1402 /** 1403 * Broadcast Action: The Service Provider string(s) have been updated. Activities or 1404 * services that use these strings should update their display. 1405 * 1406 * <p>The intent will have the following extra values: 1407 * <dl> 1408 * <dt>{@link #EXTRA_SHOW_PLMN}</dt> 1409 * <dd>Boolean that indicates whether the PLMN should be shown.</dd> 1410 * <dt>{@link #EXTRA_PLMN}</dt> 1411 * <dd>The operator name of the registered network, as a string.</dd> 1412 * <dt>{@link #EXTRA_SHOW_SPN}</dt> 1413 * <dd>Boolean that indicates whether the SPN should be shown.</dd> 1414 * <dt>{@link #EXTRA_SPN}</dt> 1415 * <dd>The service provider name, as a string.</dd> 1416 * <dt>{@link #EXTRA_DATA_SPN}</dt> 1417 * <dd>The service provider name for data service, as a string.</dd> 1418 * </dl> 1419 * 1420 * Note that {@link #EXTRA_SHOW_PLMN} may indicate that {@link #EXTRA_PLMN} should be displayed, 1421 * even though the value for {@link #EXTRA_PLMN} is null. This can happen, for example, if the 1422 * phone has not registered to a network yet. In this case the receiver may substitute an 1423 * appropriate placeholder string (eg, "No service"). 1424 * 1425 * It is recommended to display {@link #EXTRA_PLMN} before / above {@link #EXTRA_SPN} if 1426 * both are displayed. 1427 * 1428 * <p>Note: this is a protected intent that can only be sent by the system. 1429 * @hide 1430 */ 1431 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1432 public static final String ACTION_SERVICE_PROVIDERS_UPDATED = 1433 "android.telephony.action.SERVICE_PROVIDERS_UPDATED"; 1434 1435 /** 1436 * String intent extra to be used with {@link ACTION_SERVICE_PROVIDERS_UPDATED} to indicate 1437 * whether the PLMN should be shown. 1438 * @hide 1439 */ 1440 public static final String EXTRA_SHOW_PLMN = "android.telephony.extra.SHOW_PLMN"; 1441 1442 /** 1443 * String intent extra to be used with {@link ACTION_SERVICE_PROVIDERS_UPDATED} to indicate 1444 * the operator name of the registered network. 1445 * @hide 1446 */ 1447 public static final String EXTRA_PLMN = "android.telephony.extra.PLMN"; 1448 1449 /** 1450 * String intent extra to be used with {@link ACTION_SERVICE_PROVIDERS_UPDATED} to indicate 1451 * whether the PLMN should be shown. 1452 * @hide 1453 */ 1454 public static final String EXTRA_SHOW_SPN = "android.telephony.extra.SHOW_SPN"; 1455 1456 /** 1457 * String intent extra to be used with {@link ACTION_SERVICE_PROVIDERS_UPDATED} to indicate 1458 * the service provider name. 1459 * @hide 1460 */ 1461 public static final String EXTRA_SPN = "android.telephony.extra.SPN"; 1462 1463 /** 1464 * String intent extra to be used with {@link ACTION_SERVICE_PROVIDERS_UPDATED} to indicate 1465 * the service provider name for data service. 1466 * @hide 1467 */ 1468 public static final String EXTRA_DATA_SPN = "android.telephony.extra.DATA_SPN"; 1469 1470 /** 1471 * Broadcast intent action indicating that when data stall recovery is attempted by Telephony, 1472 * intended for report every data stall recovery step attempted. 1473 * 1474 * <p> 1475 * The {@link #EXTRA_RECOVERY_ACTION} extra indicates the action associated with the data 1476 * stall recovery. 1477 * The phone id where the data stall recovery is attempted. 1478 * 1479 * <p class="note"> 1480 * Requires the READ_PHONE_STATE permission. 1481 * 1482 * <p class="note"> 1483 * This is a protected intent that can only be sent by the system. 1484 * 1485 * @see #EXTRA_RECOVERY_ACTION 1486 * 1487 * @hide 1488 */ 1489 // TODO(b/78370030) : Restrict this to system applications only 1490 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1491 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 1492 public static final String ACTION_DATA_STALL_DETECTED = 1493 "android.intent.action.DATA_STALL_DETECTED"; 1494 1495 /** 1496 * A service action that identifies 1497 * a {@link android.service.carrier.CarrierMessagingClientService} subclass in the 1498 * AndroidManifest.xml. 1499 * 1500 * <p>See {@link android.service.carrier.CarrierMessagingClientService} for the details. 1501 */ 1502 @SdkConstant(SdkConstantType.SERVICE_ACTION) 1503 public static final String ACTION_CARRIER_MESSAGING_CLIENT_SERVICE = 1504 "android.telephony.action.CARRIER_MESSAGING_CLIENT_SERVICE"; 1505 1506 /** 1507 * An int extra used with {@link #ACTION_DATA_STALL_DETECTED} to indicate the 1508 * action associated with the data stall recovery. 1509 * 1510 * @see #ACTION_DATA_STALL_DETECTED 1511 * 1512 * @hide 1513 */ 1514 public static final String EXTRA_RECOVERY_ACTION = "recoveryAction"; 1515 1516 private static final long MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS = 60000; 1517 1518 /** 1519 * Intent sent when an error occurs that debug tools should log and possibly take further 1520 * action such as capturing vendor-specific logs. 1521 * 1522 * A privileged application that reads these events should take appropriate vendor-specific 1523 * action to record the event and collect further information to assist in analysis, debugging, 1524 * and resolution of any associated issue. 1525 * 1526 * <p>This event should not be used for generic logging or diagnostic monitoring purposes and 1527 * should generally be sent at a low rate. Instead, this mechanism should be used for the 1528 * framework to notify a debugging application that an event (such as a bug) has occured 1529 * within the framework if that event should trigger the collection and preservation of other 1530 * more detailed device state for debugging. 1531 * 1532 * <p>At most one application can receive these events and should register a receiver in 1533 * in the application manifest. For performance reasons, if no application to receive these 1534 * events is detected at boot, then these events will not be sent. 1535 * 1536 * <p>Each event will include an {@link EXTRA_ANOMALY_ID} that will uniquely identify the 1537 * event that has occurred. Each event will be sent to the diagnostic monitor only once per 1538 * boot cycle (as another optimization). 1539 * 1540 * @see #EXTRA_ANOMALY_ID 1541 * @see #EXTRA_ANOMALY_DESCRIPTION 1542 * @hide 1543 */ 1544 @SystemApi 1545 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 1546 public static final String ACTION_ANOMALY_REPORTED = 1547 "android.telephony.action.ANOMALY_REPORTED"; 1548 1549 /** 1550 * An arbitrary ParcelUuid which should be consistent for each occurrence of a DebugEvent. 1551 * 1552 * This field must be included in all {@link ACTION_ANOMALY_REPORTED} events. 1553 * 1554 * @see #ACTION_ANOMALY_REPORTED 1555 * @hide 1556 */ 1557 @SystemApi 1558 public static final String EXTRA_ANOMALY_ID = "android.telephony.extra.ANOMALY_ID"; 1559 1560 /** 1561 * A freeform string description of the Anomaly. 1562 * 1563 * This field is optional for all {@link ACTION_ANOMALY_REPORTED}s, as a guideline should not 1564 * exceed 80 characters, and should be as short as possible to convey the essence of the event. 1565 * 1566 * @see #ACTION_ANOMALY_REPORTED 1567 * @hide 1568 */ 1569 @SystemApi 1570 public static final String EXTRA_ANOMALY_DESCRIPTION = 1571 "android.telephony.extra.ANOMALY_DESCRIPTION"; 1572 1573 /** 1574 * Broadcast intent sent to indicate primary (non-opportunistic) subscription list has changed. 1575 * 1576 * @hide 1577 */ 1578 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1579 public static final String ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED = 1580 "android.telephony.action.PRIMARY_SUBSCRIPTION_LIST_CHANGED"; 1581 1582 /** 1583 * Integer intent extra to be used with {@link #ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED} 1584 * to indicate what type of SIM selection is needed. 1585 * 1586 * @hide 1587 */ 1588 public static final String EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE = 1589 "android.telephony.extra.DEFAULT_SUBSCRIPTION_SELECT_TYPE"; 1590 1591 /** @hide */ 1592 @IntDef({ 1593 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_NONE, 1594 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA, 1595 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_VOICE, 1596 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_SMS, 1597 EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_ALL 1598 }) 1599 @Retention(RetentionPolicy.SOURCE) 1600 public @interface DefaultSubscriptionSelectType{} 1601 1602 /** 1603 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1604 * to indicate there's no need to re-select any default subscription. 1605 * @hide 1606 */ 1607 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_NONE = 0; 1608 1609 /** 1610 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1611 * to indicate there's a need to select default data subscription. 1612 * @hide 1613 */ 1614 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA = 1; 1615 1616 /** 1617 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1618 * to indicate there's a need to select default voice call subscription. 1619 * @hide 1620 */ 1621 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_VOICE = 2; 1622 1623 /** 1624 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1625 * to indicate there's a need to select default sms subscription. 1626 * @hide 1627 */ 1628 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_SMS = 3; 1629 1630 /** 1631 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1632 * to indicate user to decide whether current SIM should be preferred for all 1633 * data / voice / sms. {@link #EXTRA_SUBSCRIPTION_ID} will specified to indicate 1634 * which subscription should be the default subscription. 1635 * @hide 1636 */ 1637 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_ALL = 4; 1638 1639 /** 1640 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1641 * to indicate that default subscription for data/sms/voice is now determined, that 1642 * it should dismiss any dialog or pop-ups that is asking user to select default sub. 1643 * This is used when, for example, opportunistic subscription is configured. At that 1644 * time the primary becomes default sub there's no need to ask user to select anymore. 1645 * @hide 1646 */ 1647 public static final int EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DISMISS = 5; 1648 1649 /** 1650 * Integer intent extra to be used with {@link #ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED} 1651 * to indicate if the SIM combination in DSDS has limitation or compatible issue. 1652 * e.g. two CDMA SIMs may disrupt each other's voice call in certain scenarios. 1653 * 1654 * @hide 1655 */ 1656 public static final String EXTRA_SIM_COMBINATION_WARNING_TYPE = 1657 "android.telephony.extra.SIM_COMBINATION_WARNING_TYPE"; 1658 1659 /** @hide */ 1660 @IntDef({ 1661 EXTRA_SIM_COMBINATION_WARNING_TYPE_NONE, 1662 EXTRA_SIM_COMBINATION_WARNING_TYPE_DUAL_CDMA 1663 }) 1664 @Retention(RetentionPolicy.SOURCE) 1665 public @interface SimCombinationWarningType{} 1666 1667 /** 1668 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1669 * to indicate there's no SIM combination warning. 1670 * @hide 1671 */ 1672 public static final int EXTRA_SIM_COMBINATION_WARNING_TYPE_NONE = 0; 1673 1674 /** 1675 * Used as an int value for {@link #EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE} 1676 * to indicate two active SIMs are both CDMA hence there might be functional limitation. 1677 * @hide 1678 */ 1679 public static final int EXTRA_SIM_COMBINATION_WARNING_TYPE_DUAL_CDMA = 1; 1680 1681 /** 1682 * String intent extra to be used with {@link #ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED} 1683 * to indicate what's the name of SIM combination it has limitation or compatible issue. 1684 * e.g. two CDMA SIMs may disrupt each other's voice call in certain scenarios, and the 1685 * name will be "operator1 & operator2". 1686 * 1687 * @hide 1688 */ 1689 public static final String EXTRA_SIM_COMBINATION_NAMES = 1690 "android.telephony.extra.SIM_COMBINATION_NAMES"; 1691 1692 /** 1693 * <p>Broadcast Action: The emergency callback mode is changed. 1694 * <ul> 1695 * <li><em>EXTRA_PHONE_IN_ECM_STATE</em> - A boolean value,true=phone in ECM, 1696 * false=ECM off</li> 1697 * </ul> 1698 * <p class="note"> 1699 * You can <em>not</em> receive this through components declared 1700 * in manifests, only by explicitly registering for it with 1701 * {@link android.content.Context#registerReceiver(android.content.BroadcastReceiver, 1702 * android.content.IntentFilter) Context.registerReceiver()}. 1703 * 1704 * <p class="note">This is a protected intent that can only be sent by the system. 1705 * 1706 * @see #EXTRA_PHONE_IN_ECM_STATE 1707 * 1708 * @hide 1709 */ 1710 @SystemApi 1711 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1712 @SuppressLint("ActionValue") 1713 public static final String ACTION_EMERGENCY_CALLBACK_MODE_CHANGED = 1714 "android.intent.action.EMERGENCY_CALLBACK_MODE_CHANGED"; 1715 1716 1717 /** 1718 * Extra included in {@link #ACTION_EMERGENCY_CALLBACK_MODE_CHANGED}. 1719 * Indicates whether the phone is in an emergency phone state. 1720 * 1721 * @hide 1722 */ 1723 @SystemApi 1724 public static final String EXTRA_PHONE_IN_ECM_STATE = 1725 "android.telephony.extra.PHONE_IN_ECM_STATE"; 1726 1727 /** 1728 * Broadcast action sent when a data connection is redirected with validation failure. 1729 * 1730 * This action is intended for sim/account status checks and only sent to the carrier apps 1731 * specified in the carrier config for the subscription ID that's attached to this intent. 1732 * 1733 * The intent will have the following extra values: 1734 * <ul> 1735 * <li>{@link #EXTRA_APN_TYPE}</li><dd>An integer indicating the apn type.</dd> 1736 * <li>{@link #EXTRA_REDIRECTION_URL}</li><dd>A string indicating the redirection url</dd> 1737 * <li>{@link SubscriptionManager#EXTRA_SUBSCRIPTION_INDEX}</li> 1738 * <dd>The subscription ID on which the validation failure happened.</dd> 1739 * </ul> 1740 * <p class="note">This is a protected intent that can only be sent by the system.</p> 1741 */ 1742 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1743 public static final String ACTION_CARRIER_SIGNAL_REDIRECTED = 1744 "android.telephony.action.CARRIER_SIGNAL_REDIRECTED"; 1745 1746 /** 1747 * Broadcast action sent when a data connection setup fails. 1748 * 1749 * This action is intended for sim/account status checks and only sent to the carrier apps 1750 * specified in the carrier config for the subscription ID that's attached to this intent. 1751 * 1752 * The intent will have the following extra values: 1753 * <ul> 1754 * <li>{@link #EXTRA_APN_TYPE}</li><dd>An integer indicating the apn type.</dd> 1755 * <li>{@link #EXTRA_DATA_FAIL_CAUSE}</li><dd>A integer indicating the data fail cause.</dd> 1756 * <li>{@link SubscriptionManager#EXTRA_SUBSCRIPTION_INDEX}</li> 1757 * <dd>The subscription ID on which the data setup failure happened.</dd> 1758 * </ul> 1759 * <p class="note">This is a protected intent that can only be sent by the system. </p> 1760 */ 1761 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1762 public static final String ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED = 1763 "android.telephony.action.CARRIER_SIGNAL_REQUEST_NETWORK_FAILED"; 1764 1765 /** 1766 * Broadcast action sent when a PCO value becomes available from the modem. 1767 * 1768 * This action is intended for sim/account status checks and only sent to the carrier apps 1769 * specified in the carrier config for the subscription ID that's attached to this intent. 1770 * 1771 * The intent will have the following extra values:</p> 1772 * <ul> 1773 * <li>{@link #EXTRA_APN_TYPE}</li><dd>An integer indicating the apn type.</dd> 1774 * <li>{@link #EXTRA_APN_PROTOCOL}</li><dd>An integer indicating the protocol of the apn 1775 * connection</dd> 1776 * <li>{@link #EXTRA_PCO_ID}</li><dd>An integer indicating the PCO id for the data.</dd> 1777 * <li>{@link #EXTRA_PCO_VALUE}</li><dd>A byte array of PCO data read from modem.</dd> 1778 * <li>{@link SubscriptionManager#EXTRA_SUBSCRIPTION_INDEX}</li> 1779 * <dd>The subscription ID for which the PCO info was received.</dd> 1780 * </ul> 1781 * <p class="note">This is a protected intent that can only be sent by the system. </p> 1782 */ 1783 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1784 public static final String ACTION_CARRIER_SIGNAL_PCO_VALUE = 1785 "android.telephony.action.CARRIER_SIGNAL_PCO_VALUE"; 1786 1787 /** 1788 * Broadcast action sent when the availability of the system default network changes. 1789 * 1790 * @see ConnectivityManager#registerDefaultNetworkCallback(ConnectivityManager.NetworkCallback) 1791 * 1792 * This action is intended for carrier apps to set/reset carrier actions. It is only sent to the 1793 * carrier apps specified in the carrier config for the subscription ID attached to this intent. 1794 * 1795 * The intent will have the following extra values:</p> 1796 * <ul> 1797 * <li>{@link #EXTRA_DEFAULT_NETWORK_AVAILABLE}</li> 1798 * <dd>{@code true} if the default network is now available, {@code false} otherwise.</dd> 1799 * <li>{@link SubscriptionManager#EXTRA_SUBSCRIPTION_INDEX}</li> 1800 * <dd>The subscription ID on which the default network availability changed.</dd> 1801 * </ul> 1802 * <p class="note">This is a protected intent that can only be sent by the system. </p> 1803 */ 1804 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1805 public static final String ACTION_CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE = 1806 "android.telephony.action.CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE"; 1807 1808 /** 1809 * Broadcast action sent when carrier apps should reset their internal state. 1810 * 1811 * Sent when certain events such as turning on/off mobile data, removing the SIM, etc. require 1812 * carrier apps to reset their state. 1813 * 1814 * This action is intended to signal carrier apps to perform cleanup operations. It is only sent 1815 * to the carrier apps specified in the carrier config for the subscription ID attached to 1816 * this intent. 1817 * 1818 * The intent will have the following extra values:</p> 1819 * <ul> 1820 * <li>{@link SubscriptionManager#EXTRA_SUBSCRIPTION_INDEX}</li> 1821 * <dd>The subscription ID for which state should be reset.</dd> 1822 * </ul> 1823 * <p class="note">This is a protected intent that can only be sent by the system.</p> 1824 */ 1825 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1826 public static final String ACTION_CARRIER_SIGNAL_RESET = 1827 "android.telephony.action.CARRIER_SIGNAL_RESET"; 1828 1829 /** 1830 * String extra containing the redirection URL sent with 1831 * {@link #ACTION_CARRIER_SIGNAL_REDIRECTED}. 1832 */ 1833 public static final String EXTRA_REDIRECTION_URL = "android.telephony.extra.REDIRECTION_URL"; 1834 1835 /** 1836 * An integer extra containing the data fail cause. 1837 * 1838 * Sent with {@link #ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED}. See {@link DataFailCause} 1839 * for a list of possible values. 1840 */ 1841 public static final String EXTRA_DATA_FAIL_CAUSE = "android.telephony.extra.DATA_FAIL_CAUSE"; 1842 1843 /** 1844 * An integer extra containing the APN type. 1845 * 1846 * Sent with the {@link #ACTION_CARRIER_SIGNAL_REQUEST_NETWORK_FAILED}, 1847 * {@link #ACTION_CARRIER_SIGNAL_REDIRECTED}, and {@link #ACTION_CARRIER_SIGNAL_PCO_VALUE} 1848 * broadcasts. 1849 * See the {@code TYPE_} constants in {@link ApnSetting} for a list of possible values. 1850 */ 1851 public static final String EXTRA_APN_TYPE = "android.telephony.extra.APN_TYPE"; 1852 1853 /** 1854 * An integer extra containing the protocol of the apn connection. 1855 * 1856 * Sent with the {@link #ACTION_CARRIER_SIGNAL_PCO_VALUE} broadcast. 1857 * See the {@code PROTOCOL_*} constants in {@link ApnSetting} for a list of possible values. 1858 */ 1859 public static final String EXTRA_APN_PROTOCOL = "android.telephony.extra.APN_PROTOCOL"; 1860 1861 /** 1862 * An integer extra indicating the ID for the PCO data. 1863 * Sent with the {@link #ACTION_CARRIER_SIGNAL_PCO_VALUE} broadcast. 1864 */ 1865 public static final String EXTRA_PCO_ID = "android.telephony.extra.PCO_ID"; 1866 1867 /** 1868 * A byte array extra containing PCO data read from the modem. 1869 * Sent with the {@link #ACTION_CARRIER_SIGNAL_PCO_VALUE} broadcast. 1870 */ 1871 public static final String EXTRA_PCO_VALUE = "android.telephony.extra.PCO_VALUE"; 1872 1873 /** 1874 * A boolean extra indicating the availability of the default network. 1875 * Sent with the {@link #ACTION_CARRIER_SIGNAL_DEFAULT_NETWORK_AVAILABLE} broadcast. 1876 */ 1877 public static final String EXTRA_DEFAULT_NETWORK_AVAILABLE = 1878 "android.telephony.extra.DEFAULT_NETWORK_AVAILABLE"; 1879 1880 /** 1881 * <p>Broadcast Action: The emergency call state is changed. 1882 * <ul> 1883 * <li><em>EXTRA_PHONE_IN_EMERGENCY_CALL</em> - A boolean value, true if phone in emergency 1884 * call, false otherwise</li> 1885 * </ul> 1886 * <p class="note"> 1887 * You can <em>not</em> receive this through components declared 1888 * in manifests, only by explicitly registering for it with 1889 * {@link android.content.Context#registerReceiver(android.content.BroadcastReceiver, 1890 * android.content.IntentFilter) Context.registerReceiver()}. 1891 * 1892 * <p class="note">This is a protected intent that can only be sent by the system. 1893 * 1894 * @see #EXTRA_PHONE_IN_EMERGENCY_CALL 1895 * 1896 * @hide 1897 */ 1898 @SystemApi 1899 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 1900 @SuppressLint("ActionValue") 1901 public static final String ACTION_EMERGENCY_CALL_STATE_CHANGED = 1902 "android.intent.action.EMERGENCY_CALL_STATE_CHANGED"; 1903 1904 1905 /** 1906 * Extra included in {@link #ACTION_EMERGENCY_CALL_STATE_CHANGED}. 1907 * It indicates whether the phone is making an emergency call. 1908 * 1909 * @hide 1910 */ 1911 @SystemApi 1912 public static final String EXTRA_PHONE_IN_EMERGENCY_CALL = 1913 "android.telephony.extra.PHONE_IN_EMERGENCY_CALL"; 1914 1915 /** 1916 * <p>Broadcast Action: It indicates the Emergency callback mode blocks datacall/sms 1917 * <p class="note">. 1918 * This is to pop up a notice to show user that the phone is in emergency callback mode 1919 * and data calls and outgoing sms are blocked. 1920 * 1921 * <p class="note">This is a protected intent that can only be sent by the system. 1922 * 1923 * @hide 1924 */ 1925 @SystemApi 1926 public static final String ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS = 1927 "android.telephony.action.SHOW_NOTICE_ECM_BLOCK_OTHERS"; 1928 1929 /** 1930 * Broadcast Action: The default data subscription has changed in a multi-SIM device. 1931 * This has the following extra values:</p> 1932 * <ul> 1933 * <li><em>subscription</em> - A int, the current data default subscription.</li> 1934 * </ul> 1935 * 1936 * @hide 1937 */ 1938 @SystemApi 1939 @SuppressLint("ActionValue") 1940 public static final String ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED = 1941 "android.intent.action.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED"; 1942 1943 /** 1944 * Broadcast Action: The default voice subscription has changed in a mult-SIm device. 1945 * This has the following extra values:</p> 1946 * <ul> 1947 * <li><em>subscription</em> - A int, the current voice default subscription.</li> 1948 * </ul> 1949 * 1950 * @hide 1951 */ 1952 @SystemApi 1953 @SuppressLint("ActionValue") 1954 public static final String ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED = 1955 "android.intent.action.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED"; 1956 1957 /** 1958 * Broadcast Action: This triggers a client initiated OMA-DM session to the OMA server. 1959 * <p class="note"> 1960 * Open Mobile Alliance (OMA) Device Management (DM). 1961 * 1962 * This intent is used by the system components to trigger OMA-DM 1963 * 1964 * @hide 1965 */ 1966 @SystemApi 1967 @SuppressLint("ActionValue") 1968 public static final String ACTION_REQUEST_OMADM_CONFIGURATION_UPDATE = 1969 "com.android.omadm.service.CONFIGURATION_UPDATE"; 1970 1971 // 1972 // 1973 // Device Info 1974 // 1975 // 1976 1977 /** 1978 * Returns the software version number for the device, for example, 1979 * the IMEI/SV for GSM phones. Return null if the software version is 1980 * not available. 1981 * <p> 1982 */ 1983 @RequiresPermission(anyOf = { 1984 android.Manifest.permission.READ_PHONE_STATE, 1985 android.Manifest.permission.READ_BASIC_PHONE_STATE}) 1986 @Nullable getDeviceSoftwareVersion()1987 public String getDeviceSoftwareVersion() { 1988 return getDeviceSoftwareVersion(getSlotIndex()); 1989 } 1990 1991 /** 1992 * Returns the software version number for the device, for example, 1993 * the IMEI/SV for GSM phones. Return null if the software version is 1994 * not available. 1995 * <p> 1996 * Requires Permission: READ_PHONE_STATE. 1997 * 1998 * @param slotIndex of which deviceID is returned 1999 * 2000 * @hide 2001 */ 2002 @SystemApi 2003 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 2004 @Nullable getDeviceSoftwareVersion(int slotIndex)2005 public String getDeviceSoftwareVersion(int slotIndex) { 2006 ITelephony telephony = getITelephony(); 2007 if (telephony == null) return null; 2008 2009 try { 2010 return telephony.getDeviceSoftwareVersionForSlot(slotIndex, getOpPackageName(), 2011 getAttributionTag()); 2012 } catch (RemoteException ex) { 2013 return null; 2014 } catch (NullPointerException ex) { 2015 return null; 2016 } 2017 } 2018 2019 /** 2020 * Returns the unique device ID, for example, the IMEI for GSM and the MEID 2021 * or ESN for CDMA phones. Return null if device ID is not available. 2022 * 2023 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 2024 * restrictions, and apps are recommended to use resettable identifiers (see <a 2025 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 2026 * method can be invoked if one of the following requirements is met: 2027 * <ul> 2028 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 2029 * is a privileged permission that can only be granted to apps preloaded on the device. 2030 * <li>If the calling app is the device owner of a fully-managed device, a profile 2031 * owner of an organization-owned device, or their delegates (see {@link 2032 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 2033 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) on any 2034 * active subscription. 2035 * <li>If the calling app is the default SMS role holder (see {@link 2036 * RoleManager#isRoleHeld(String)}). 2037 * </ul> 2038 * 2039 * <p>If the calling app does not meet one of these requirements then this method will behave 2040 * as follows: 2041 * 2042 * <ul> 2043 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 2044 * READ_PHONE_STATE permission then null is returned.</li> 2045 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 2046 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 2047 * higher, then a SecurityException is thrown.</li> 2048 * </ul> 2049 * 2050 * @deprecated Use {@link #getImei} which returns IMEI for GSM or {@link #getMeid} which returns 2051 * MEID for CDMA. 2052 */ 2053 @Deprecated 2054 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 2055 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getDeviceId()2056 public String getDeviceId() { 2057 try { 2058 ITelephony telephony = getITelephony(); 2059 if (telephony == null) 2060 return null; 2061 return telephony.getDeviceIdWithFeature(mContext.getOpPackageName(), 2062 mContext.getAttributionTag()); 2063 } catch (RemoteException ex) { 2064 return null; 2065 } catch (NullPointerException ex) { 2066 return null; 2067 } 2068 } 2069 2070 /** 2071 * Returns the unique device ID of a subscription, for example, the IMEI for 2072 * GSM and the MEID for CDMA phones. Return null if device ID is not available. 2073 * 2074 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 2075 * restrictions, and apps are recommended to use resettable identifiers (see <a 2076 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 2077 * method can be invoked if one of the following requirements is met: 2078 * <ul> 2079 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 2080 * is a privileged permission that can only be granted to apps preloaded on the device. 2081 * <li>If the calling app is the device owner of a fully-managed device, a profile 2082 * owner of an organization-owned device, or their delegates (see {@link 2083 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 2084 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) on any 2085 * active subscription. 2086 * <li>If the calling app is the default SMS role holder (see {@link 2087 * RoleManager#isRoleHeld(String)}). 2088 * </ul> 2089 * 2090 * <p>If the calling app does not meet one of these requirements then this method will behave 2091 * as follows: 2092 * 2093 * <ul> 2094 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 2095 * READ_PHONE_STATE permission then null is returned.</li> 2096 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 2097 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 2098 * higher, then a SecurityException is thrown.</li> 2099 * </ul> 2100 * 2101 * @param slotIndex of which deviceID is returned 2102 * 2103 * @deprecated Use {@link #getImei} which returns IMEI for GSM or {@link #getMeid} which returns 2104 * MEID for CDMA. 2105 */ 2106 @Deprecated 2107 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 2108 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getDeviceId(int slotIndex)2109 public String getDeviceId(int slotIndex) { 2110 // FIXME this assumes phoneId == slotIndex 2111 try { 2112 IPhoneSubInfo info = getSubscriberInfoService(); 2113 if (info == null) 2114 return null; 2115 return info.getDeviceIdForPhone(slotIndex, mContext.getOpPackageName(), 2116 mContext.getAttributionTag()); 2117 } catch (RemoteException ex) { 2118 return null; 2119 } catch (NullPointerException ex) { 2120 return null; 2121 } 2122 } 2123 2124 /** 2125 * Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not 2126 * available. 2127 * 2128 * See {@link #getImei(int)} for details on the required permissions and behavior 2129 * when the caller does not hold sufficient permissions. 2130 */ 2131 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 2132 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 2133 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_GSM) getImei()2134 public String getImei() { 2135 return getImei(getSlotIndex()); 2136 } 2137 2138 /** 2139 * Returns the IMEI (International Mobile Equipment Identity). Return null if IMEI is not 2140 * available. 2141 * 2142 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 2143 * restrictions, and apps are recommended to use resettable identifiers (see <a 2144 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 2145 * method can be invoked if one of the following requirements is met: 2146 * <ul> 2147 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 2148 * is a privileged permission that can only be granted to apps preloaded on the device. 2149 * <li>If the calling app is the device owner of a fully-managed device, a profile 2150 * owner of an organization-owned device, or their delegates (see {@link 2151 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 2152 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) on any 2153 * active subscription. 2154 * <li>If the calling app is the default SMS role holder (see {@link 2155 * RoleManager#isRoleHeld(String)}). 2156 * <li>If the calling app has been granted the 2157 * {@link Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} permission. 2158 * </ul> 2159 * 2160 * <p>If the calling app does not meet one of these requirements then this method will behave 2161 * as follows: 2162 * 2163 * <ul> 2164 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 2165 * READ_PHONE_STATE permission then null is returned.</li> 2166 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 2167 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 2168 * higher, then a SecurityException is thrown.</li> 2169 * </ul> 2170 * 2171 * @param slotIndex of which IMEI is returned 2172 */ 2173 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 2174 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 2175 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_GSM) getImei(int slotIndex)2176 public String getImei(int slotIndex) { 2177 ITelephony telephony = getITelephony(); 2178 if (telephony == null) return null; 2179 2180 try { 2181 return telephony.getImeiForSlot(slotIndex, getOpPackageName(), getAttributionTag()); 2182 } catch (RemoteException ex) { 2183 return null; 2184 } catch (NullPointerException ex) { 2185 return null; 2186 } 2187 } 2188 2189 /** 2190 * Returns the Type Allocation Code from the IMEI. Return null if Type Allocation Code is not 2191 * available. 2192 */ 2193 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_GSM) 2194 @Nullable getTypeAllocationCode()2195 public String getTypeAllocationCode() { 2196 return getTypeAllocationCode(getSlotIndex()); 2197 } 2198 2199 /** 2200 * Returns the Type Allocation Code from the IMEI. Return null if Type Allocation Code is not 2201 * available. 2202 * 2203 * @param slotIndex of which Type Allocation Code is returned 2204 */ 2205 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_GSM) 2206 @Nullable getTypeAllocationCode(int slotIndex)2207 public String getTypeAllocationCode(int slotIndex) { 2208 ITelephony telephony = getITelephony(); 2209 if (telephony == null) return null; 2210 2211 try { 2212 return telephony.getTypeAllocationCodeForSlot(slotIndex); 2213 } catch (RemoteException ex) { 2214 return null; 2215 } catch (NullPointerException ex) { 2216 return null; 2217 } 2218 } 2219 2220 /** 2221 * Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. 2222 * 2223 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 2224 * restrictions, and apps are recommended to use resettable identifiers (see <a 2225 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 2226 * method can be invoked if one of the following requirements is met: 2227 * <ul> 2228 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 2229 * is a privileged permission that can only be granted to apps preloaded on the device. 2230 * <li>If the calling app is the device owner of a fully-managed device, a profile 2231 * owner of an organization-owned device, or their delegates (see {@link 2232 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 2233 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) on any 2234 * active subscription. 2235 * <li>If the calling app is the default SMS role holder (see {@link 2236 * RoleManager#isRoleHeld(String)}). 2237 * </ul> 2238 * 2239 * <p>If the calling app does not meet one of these requirements then this method will behave 2240 * as follows: 2241 * 2242 * <ul> 2243 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 2244 * READ_PHONE_STATE permission then null is returned.</li> 2245 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 2246 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 2247 * higher, then a SecurityException is thrown.</li> 2248 * </ul> 2249 */ 2250 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 2251 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 2252 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CDMA) getMeid()2253 public String getMeid() { 2254 return getMeid(getSlotIndex()); 2255 } 2256 2257 /** 2258 * Returns the MEID (Mobile Equipment Identifier). Return null if MEID is not available. 2259 * 2260 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 2261 * restrictions, and apps are recommended to use resettable identifiers (see <a 2262 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 2263 * method can be invoked if one of the following requirements is met: 2264 * <ul> 2265 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 2266 * is a privileged permission that can only be granted to apps preloaded on the device. 2267 * <li>If the calling app is the device owner of a fully-managed device, a profile 2268 * owner of an organization-owned device, or their delegates (see {@link 2269 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 2270 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) on any 2271 * active subscription. 2272 * <li>If the calling app is the default SMS role holder (see {@link 2273 * RoleManager#isRoleHeld(String)}). 2274 * </ul> 2275 * 2276 * <p>If the calling app does not meet one of these requirements then this method will behave 2277 * as follows: 2278 * 2279 * <ul> 2280 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 2281 * READ_PHONE_STATE permission then null is returned.</li> 2282 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 2283 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 2284 * higher, then a SecurityException is thrown.</li> 2285 * </ul> 2286 * 2287 * @param slotIndex of which MEID is returned 2288 */ 2289 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 2290 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 2291 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CDMA) getMeid(int slotIndex)2292 public String getMeid(int slotIndex) { 2293 ITelephony telephony = getITelephony(); 2294 if (telephony == null) return null; 2295 2296 try { 2297 String meid = telephony.getMeidForSlot(slotIndex, getOpPackageName(), 2298 getAttributionTag()); 2299 if (TextUtils.isEmpty(meid)) { 2300 Log.d(TAG, "getMeid: return null because MEID is not available"); 2301 return null; 2302 } 2303 return meid; 2304 } catch (RemoteException ex) { 2305 return null; 2306 } catch (NullPointerException ex) { 2307 return null; 2308 } 2309 } 2310 2311 /** 2312 * Returns the Manufacturer Code from the MEID. Return null if Manufacturer Code is not 2313 * available. 2314 */ 2315 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CDMA) 2316 @Nullable getManufacturerCode()2317 public String getManufacturerCode() { 2318 return getManufacturerCode(getSlotIndex()); 2319 } 2320 2321 /** 2322 * Returns the Manufacturer Code from the MEID. Return null if Manufacturer Code is not 2323 * available. 2324 * 2325 * @param slotIndex of which Type Allocation Code is returned 2326 */ 2327 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CDMA) 2328 @Nullable getManufacturerCode(int slotIndex)2329 public String getManufacturerCode(int slotIndex) { 2330 ITelephony telephony = getITelephony(); 2331 if (telephony == null) return null; 2332 2333 try { 2334 return telephony.getManufacturerCodeForSlot(slotIndex); 2335 } catch (RemoteException ex) { 2336 return null; 2337 } catch (NullPointerException ex) { 2338 return null; 2339 } 2340 } 2341 2342 /** 2343 * Returns the Network Access Identifier (NAI). Return null if NAI is not available. 2344 * 2345 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 2346 * restrictions, and apps are recommended to use resettable identifiers (see <a 2347 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 2348 * method can be invoked if one of the following requirements is met: 2349 * <ul> 2350 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 2351 * is a privileged permission that can only be granted to apps preloaded on the device. 2352 * <li>If the calling app is the device owner of a fully-managed device, a profile 2353 * owner of an organization-owned device, or their delegates (see {@link 2354 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 2355 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 2356 * <li>If the calling app is the default SMS role holder (see {@link 2357 * RoleManager#isRoleHeld(String)}). 2358 * </ul> 2359 * 2360 * <p>If the calling app does not meet one of these requirements then this method will behave 2361 * as follows: 2362 * 2363 * <ul> 2364 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 2365 * READ_PHONE_STATE permission then null is returned.</li> 2366 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 2367 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 2368 * higher, then a SecurityException is thrown.</li> 2369 * </ul> 2370 */ 2371 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 2372 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 2373 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getNai()2374 public String getNai() { 2375 return getNaiBySubscriberId(getSubId()); 2376 } 2377 2378 /** 2379 * Returns the NAI. Return null if NAI is not available. 2380 * 2381 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 2382 * restrictions, and apps are recommended to use resettable identifiers (see <a 2383 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 2384 * method can be invoked if one of the following requirements is met: 2385 * <ul> 2386 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 2387 * is a privileged permission that can only be granted to apps preloaded on the device. 2388 * <li>If the calling app is the device owner of a fully-managed device, a profile 2389 * owner of an organization-owned device, or their delegates (see {@link 2390 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 2391 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 2392 * <li>If the calling app is the default SMS role holder (see {@link 2393 * RoleManager#isRoleHeld(String)}). 2394 * </ul> 2395 * 2396 * <p>If the calling app does not meet one of these requirements then this method will behave 2397 * as follows: 2398 * 2399 * <ul> 2400 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 2401 * READ_PHONE_STATE permission then null is returned.</li> 2402 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 2403 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 2404 * higher, then a SecurityException is thrown.</li> 2405 * </ul> 2406 * 2407 * @param slotIndex of which Nai is returned 2408 */ 2409 /** {@hide}*/ 2410 @UnsupportedAppUsage getNai(int slotIndex)2411 public String getNai(int slotIndex) { 2412 int[] subId = SubscriptionManager.getSubId(slotIndex); 2413 if (subId == null) { 2414 return null; 2415 } 2416 return getNaiBySubscriberId(subId[0]); 2417 } 2418 getNaiBySubscriberId(int subId)2419 private String getNaiBySubscriberId(int subId) { 2420 try { 2421 IPhoneSubInfo info = getSubscriberInfoService(); 2422 if (info == null) 2423 return null; 2424 String nai = info.getNaiForSubscriber(subId, mContext.getOpPackageName(), 2425 mContext.getAttributionTag()); 2426 if (Log.isLoggable(TAG, Log.VERBOSE)) { 2427 Rlog.v(TAG, "Nai = " + nai); 2428 } 2429 return nai; 2430 } catch (RemoteException ex) { 2431 return null; 2432 } catch (NullPointerException ex) { 2433 return null; 2434 } 2435 } 2436 2437 /** 2438 * Returns the current location of the device. 2439 *<p> 2440 * If there is only one radio in the device and that radio has an LTE connection, 2441 * this method will return null. The implementation must not to try add LTE 2442 * identifiers into the existing cdma/gsm classes. 2443 *<p> 2444 * @return Current location of the device or null if not available. 2445 * 2446 * @deprecated use {@link #getAllCellInfo} instead, which returns a superset of this API. 2447 */ 2448 @Deprecated 2449 @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) getCellLocation()2450 public CellLocation getCellLocation() { 2451 try { 2452 ITelephony telephony = getITelephony(); 2453 if (telephony == null) { 2454 Rlog.d(TAG, "getCellLocation returning null because telephony is null"); 2455 return null; 2456 } 2457 2458 CellIdentity cellIdentity = telephony.getCellLocation(mContext.getOpPackageName(), 2459 mContext.getAttributionTag()); 2460 CellLocation cl = cellIdentity.asCellLocation(); 2461 if (cl == null || cl.isEmpty()) { 2462 Rlog.d(TAG, "getCellLocation returning null because CellLocation is empty or" 2463 + " phone type doesn't match CellLocation type"); 2464 return null; 2465 } 2466 2467 return cl; 2468 } catch (RemoteException ex) { 2469 Rlog.d(TAG, "getCellLocation returning null due to RemoteException " + ex); 2470 return null; 2471 } 2472 } 2473 2474 /** 2475 * Returns the neighboring cell information of the device. 2476 * 2477 * @return List of NeighboringCellInfo or null if info unavailable. 2478 * 2479 * @removed 2480 * @deprecated Use {@link #getAllCellInfo} which returns a superset of the information 2481 * from NeighboringCellInfo, including LTE cell information. 2482 */ 2483 @Deprecated 2484 @RequiresPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) getNeighboringCellInfo()2485 public List<NeighboringCellInfo> getNeighboringCellInfo() { 2486 try { 2487 ITelephony telephony = getITelephony(); 2488 if (telephony == null) 2489 return null; 2490 return telephony.getNeighboringCellInfo(mContext.getOpPackageName(), 2491 mContext.getAttributionTag()); 2492 } catch (RemoteException ex) { 2493 return null; 2494 } catch (NullPointerException ex) { 2495 return null; 2496 } 2497 } 2498 2499 /** No phone radio. */ 2500 public static final int PHONE_TYPE_NONE = PhoneConstants.PHONE_TYPE_NONE; 2501 /** Phone radio is GSM. */ 2502 public static final int PHONE_TYPE_GSM = PhoneConstants.PHONE_TYPE_GSM; 2503 /** Phone radio is CDMA. */ 2504 public static final int PHONE_TYPE_CDMA = PhoneConstants.PHONE_TYPE_CDMA; 2505 /** Phone is via SIP. */ 2506 public static final int PHONE_TYPE_SIP = PhoneConstants.PHONE_TYPE_SIP; 2507 2508 /** 2509 * Phone is via IMS. 2510 * 2511 * @hide 2512 */ 2513 public static final int PHONE_TYPE_IMS = PhoneConstants.PHONE_TYPE_IMS; 2514 2515 /** 2516 * Phone is via Third Party. 2517 * 2518 * @hide 2519 */ 2520 public static final int PHONE_TYPE_THIRD_PARTY = PhoneConstants.PHONE_TYPE_THIRD_PARTY; 2521 2522 /** 2523 * Returns the current phone type. 2524 * TODO: This is a last minute change and hence hidden. 2525 * 2526 * @see #PHONE_TYPE_NONE 2527 * @see #PHONE_TYPE_GSM 2528 * @see #PHONE_TYPE_CDMA 2529 * @see #PHONE_TYPE_SIP 2530 * 2531 * {@hide} 2532 */ 2533 @SystemApi getCurrentPhoneType()2534 public int getCurrentPhoneType() { 2535 return getCurrentPhoneType(getSubId()); 2536 } 2537 2538 /** 2539 * Returns a constant indicating the device phone type for a subscription. 2540 * 2541 * @see #PHONE_TYPE_NONE 2542 * @see #PHONE_TYPE_GSM 2543 * @see #PHONE_TYPE_CDMA 2544 * 2545 * @param subId for which phone type is returned 2546 * @hide 2547 */ 2548 @SystemApi getCurrentPhoneType(int subId)2549 public int getCurrentPhoneType(int subId) { 2550 int phoneId; 2551 if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { 2552 // if we don't have any sims, we don't have subscriptions, but we 2553 // still may want to know what type of phone we've got. 2554 phoneId = 0; 2555 } else { 2556 phoneId = SubscriptionManager.getPhoneId(subId); 2557 } 2558 2559 return getCurrentPhoneTypeForSlot(phoneId); 2560 } 2561 2562 /** 2563 * See getCurrentPhoneType. 2564 * 2565 * @hide 2566 */ getCurrentPhoneTypeForSlot(int slotIndex)2567 public int getCurrentPhoneTypeForSlot(int slotIndex) { 2568 try{ 2569 ITelephony telephony = getITelephony(); 2570 if (telephony != null) { 2571 return telephony.getActivePhoneTypeForSlot(slotIndex); 2572 } else { 2573 // This can happen when the ITelephony interface is not up yet. 2574 return getPhoneTypeFromProperty(slotIndex); 2575 } 2576 } catch (RemoteException ex) { 2577 // This shouldn't happen in the normal case, as a backup we 2578 // read from the system property. 2579 return getPhoneTypeFromProperty(slotIndex); 2580 } catch (NullPointerException ex) { 2581 // This shouldn't happen in the normal case, as a backup we 2582 // read from the system property. 2583 return getPhoneTypeFromProperty(slotIndex); 2584 } 2585 } 2586 2587 /** 2588 * Returns a constant indicating the device phone type. This 2589 * indicates the type of radio used to transmit voice calls. 2590 * 2591 * @see #PHONE_TYPE_NONE 2592 * @see #PHONE_TYPE_GSM 2593 * @see #PHONE_TYPE_CDMA 2594 * @see #PHONE_TYPE_SIP 2595 */ getPhoneType()2596 public int getPhoneType() { 2597 if (!isVoiceCapable()) { 2598 return PHONE_TYPE_NONE; 2599 } 2600 return getCurrentPhoneType(); 2601 } 2602 getPhoneTypeFromProperty()2603 private int getPhoneTypeFromProperty() { 2604 return getPhoneTypeFromProperty(getPhoneId()); 2605 } 2606 2607 /** {@hide} */ 2608 @UnsupportedAppUsage getPhoneTypeFromProperty(int phoneId)2609 private int getPhoneTypeFromProperty(int phoneId) { 2610 Integer type = getTelephonyProperty( 2611 phoneId, TelephonyProperties.current_active_phone(), null); 2612 if (type != null) return type; 2613 return getPhoneTypeFromNetworkType(phoneId); 2614 } 2615 getPhoneTypeFromNetworkType()2616 private int getPhoneTypeFromNetworkType() { 2617 return getPhoneTypeFromNetworkType(getPhoneId()); 2618 } 2619 2620 /** {@hide} */ getPhoneTypeFromNetworkType(int phoneId)2621 private int getPhoneTypeFromNetworkType(int phoneId) { 2622 // When the system property CURRENT_ACTIVE_PHONE, has not been set, 2623 // use the system property for default network type. 2624 // This is a fail safe, and can only happen at first boot. 2625 Integer mode = getTelephonyProperty(phoneId, TelephonyProperties.default_network(), null); 2626 if (mode != null) { 2627 return TelephonyManager.getPhoneType(mode); 2628 } 2629 return TelephonyManager.PHONE_TYPE_NONE; 2630 } 2631 2632 /** 2633 * This function returns the type of the phone, depending 2634 * on the network mode. 2635 * 2636 * @param networkMode 2637 * @return Phone Type 2638 * 2639 * @hide 2640 */ 2641 @UnsupportedAppUsage getPhoneType(int networkMode)2642 public static int getPhoneType(int networkMode) { 2643 switch(networkMode) { 2644 case RILConstants.NETWORK_MODE_CDMA: 2645 case RILConstants.NETWORK_MODE_CDMA_NO_EVDO: 2646 case RILConstants.NETWORK_MODE_EVDO_NO_CDMA: 2647 return PhoneConstants.PHONE_TYPE_CDMA; 2648 2649 case RILConstants.NETWORK_MODE_WCDMA_PREF: 2650 case RILConstants.NETWORK_MODE_GSM_ONLY: 2651 case RILConstants.NETWORK_MODE_WCDMA_ONLY: 2652 case RILConstants.NETWORK_MODE_GSM_UMTS: 2653 case RILConstants.NETWORK_MODE_LTE_GSM_WCDMA: 2654 case RILConstants.NETWORK_MODE_LTE_WCDMA: 2655 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA: 2656 case RILConstants.NETWORK_MODE_TDSCDMA_ONLY: 2657 case RILConstants.NETWORK_MODE_TDSCDMA_WCDMA: 2658 case RILConstants.NETWORK_MODE_LTE_TDSCDMA: 2659 case RILConstants.NETWORK_MODE_TDSCDMA_GSM: 2660 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM: 2661 case RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA: 2662 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA: 2663 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA: 2664 case RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA: 2665 return PhoneConstants.PHONE_TYPE_GSM; 2666 2667 // Use CDMA Phone for the global mode including CDMA 2668 case RILConstants.NETWORK_MODE_GLOBAL: 2669 case RILConstants.NETWORK_MODE_LTE_CDMA_EVDO: 2670 case RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA: 2671 return PhoneConstants.PHONE_TYPE_CDMA; 2672 2673 case RILConstants.NETWORK_MODE_LTE_ONLY: 2674 if (TelephonyProperties.lte_on_cdma_device().orElse( 2675 PhoneConstants.LTE_ON_CDMA_FALSE) == PhoneConstants.LTE_ON_CDMA_TRUE) { 2676 return PhoneConstants.PHONE_TYPE_CDMA; 2677 } else { 2678 return PhoneConstants.PHONE_TYPE_GSM; 2679 } 2680 default: 2681 return PhoneConstants.PHONE_TYPE_GSM; 2682 } 2683 } 2684 2685 /** 2686 * @return The max value for the timeout passed in {@link #requestNumberVerification}. 2687 * @hide 2688 */ 2689 @SystemApi getMaxNumberVerificationTimeoutMillis()2690 public static long getMaxNumberVerificationTimeoutMillis() { 2691 return MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS; 2692 } 2693 2694 // 2695 // 2696 // Current Network 2697 // 2698 // 2699 2700 /** 2701 * Returns the alphabetic name of current registered operator. 2702 * <p> 2703 * Availability: Only when user is registered to a network. Result may be 2704 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2705 * on a CDMA network). 2706 */ 2707 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) getNetworkOperatorName()2708 public String getNetworkOperatorName() { 2709 return getNetworkOperatorName(getSubId()); 2710 } 2711 2712 /** 2713 * Returns the alphabetic name of current registered operator 2714 * for a particular subscription. 2715 * <p> 2716 * Availability: Only when user is registered to a network. Result may be 2717 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2718 * on a CDMA network). 2719 * @param subId 2720 * @hide 2721 */ 2722 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getNetworkOperatorName(int subId)2723 public String getNetworkOperatorName(int subId) { 2724 int phoneId = SubscriptionManager.getPhoneId(subId); 2725 return getTelephonyProperty(phoneId, TelephonyProperties.operator_alpha(), ""); 2726 } 2727 2728 /** 2729 * Returns the numeric name (MCC+MNC) of current registered operator. 2730 * <p> 2731 * Availability: Only when user is registered to a network. Result may be 2732 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2733 * on a CDMA network). 2734 */ 2735 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) getNetworkOperator()2736 public String getNetworkOperator() { 2737 return getNetworkOperatorForPhone(getPhoneId()); 2738 } 2739 2740 /** 2741 * Returns the numeric name (MCC+MNC) of current registered operator 2742 * for a particular subscription. 2743 * <p> 2744 * Availability: Only when user is registered to a network. Result may be 2745 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2746 * on a CDMA network). 2747 * 2748 * @param subId 2749 * @hide 2750 */ 2751 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getNetworkOperator(int subId)2752 public String getNetworkOperator(int subId) { 2753 int phoneId = SubscriptionManager.getPhoneId(subId); 2754 return getNetworkOperatorForPhone(phoneId); 2755 } 2756 2757 /** 2758 * Returns the numeric name (MCC+MNC) of current registered operator 2759 * for a particular subscription. 2760 * <p> 2761 * Availability: Only when user is registered to a network. Result may be 2762 * unreliable on CDMA networks (use {@link #getPhoneType()} to determine if 2763 * on a CDMA network). 2764 * 2765 * @param phoneId 2766 * @hide 2767 **/ 2768 @UnsupportedAppUsage getNetworkOperatorForPhone(int phoneId)2769 public String getNetworkOperatorForPhone(int phoneId) { 2770 return getTelephonyProperty(phoneId, TelephonyProperties.operator_numeric(), ""); 2771 } 2772 2773 2774 /** 2775 * Returns the network specifier of the subscription ID pinned to the TelephonyManager. The 2776 * network specifier is used by {@link 2777 * android.net.NetworkRequest.Builder#setNetworkSpecifier(String)} to create a {@link 2778 * android.net.NetworkRequest} that connects through the subscription. 2779 * 2780 * @see android.net.NetworkRequest.Builder#setNetworkSpecifier(String) 2781 * @see #createForSubscriptionId(int) 2782 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 2783 */ 2784 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) getNetworkSpecifier()2785 public String getNetworkSpecifier() { 2786 return String.valueOf(getSubId()); 2787 } 2788 2789 /** 2790 * Returns the carrier config of the subscription ID pinned to the TelephonyManager. If an 2791 * invalid subscription ID is pinned to the TelephonyManager, the returned config will contain 2792 * default values. 2793 * 2794 * <p>This method may take several seconds to complete, so it should only be called from a 2795 * worker thread. 2796 * 2797 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 2798 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 2799 * 2800 * @see CarrierConfigManager#getConfigForSubId(int) 2801 * @see #createForSubscriptionId(int) 2802 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 2803 */ 2804 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 2805 @WorkerThread 2806 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 2807 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getCarrierConfig()2808 public PersistableBundle getCarrierConfig() { 2809 CarrierConfigManager carrierConfigManager = mContext 2810 .getSystemService(CarrierConfigManager.class); 2811 return carrierConfigManager.getConfigForSubId(getSubId()); 2812 } 2813 2814 /** 2815 * Returns true if the device is considered roaming on the current 2816 * network, for GSM purposes. 2817 * <p> 2818 * Availability: Only when user registered to a network. 2819 */ 2820 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) isNetworkRoaming()2821 public boolean isNetworkRoaming() { 2822 return isNetworkRoaming(getSubId()); 2823 } 2824 2825 /** 2826 * Returns true if the device is considered roaming on the current 2827 * network for a subscription. 2828 * <p> 2829 * Availability: Only when user registered to a network. 2830 * 2831 * @param subId 2832 * @hide 2833 */ 2834 @UnsupportedAppUsage isNetworkRoaming(int subId)2835 public boolean isNetworkRoaming(int subId) { 2836 int phoneId = SubscriptionManager.getPhoneId(subId); 2837 return getTelephonyProperty(phoneId, TelephonyProperties.operator_is_roaming(), false); 2838 } 2839 2840 /** 2841 * Returns the ISO-3166-1 alpha-2 country code equivalent of the MCC (Mobile Country Code) of 2842 * the current registered operator or the cell nearby, if available. 2843 * 2844 * Note: Result may be unreliable on CDMA networks (use {@link #getPhoneType()} to determine 2845 * if on a CDMA network). 2846 * <p> 2847 * @return the lowercase 2 character ISO-3166-1 alpha-2 country code, or empty string if not 2848 * available. 2849 */ 2850 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) getNetworkCountryIso()2851 public String getNetworkCountryIso() { 2852 return getNetworkCountryIso(getSlotIndex()); 2853 } 2854 2855 /** 2856 * Returns the ISO-3166-1 alpha-2 country code equivalent of the MCC (Mobile Country Code) of 2857 * the current registered operator or the cell nearby, if available. This is same as 2858 * {@link #getNetworkCountryIso()} but allowing specifying the SIM slot index. This is used for 2859 * accessing network country info from the SIM slot that does not have SIM inserted. 2860 * 2861 * Note: Result may be unreliable on CDMA networks (use {@link #getPhoneType()} to determine 2862 * if on a CDMA network). 2863 * <p> 2864 * 2865 * @param slotIndex the SIM slot index to get network country ISO. 2866 * 2867 * @return the lowercase 2 character ISO-3166-1 alpha-2 country code, or empty string if not 2868 * available. 2869 * 2870 * @throws IllegalArgumentException when the slotIndex is invalid. 2871 * 2872 */ 2873 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) 2874 @NonNull getNetworkCountryIso(int slotIndex)2875 public String getNetworkCountryIso(int slotIndex) { 2876 try { 2877 if (slotIndex != SubscriptionManager.DEFAULT_SIM_SLOT_INDEX 2878 && !SubscriptionManager.isValidSlotIndex(slotIndex)) { 2879 throw new IllegalArgumentException("invalid slot index " + slotIndex); 2880 } 2881 2882 ITelephony telephony = getITelephony(); 2883 if (telephony == null) return ""; 2884 return telephony.getNetworkCountryIsoForPhone(slotIndex); 2885 } catch (RemoteException ex) { 2886 return ""; 2887 } 2888 } 2889 2890 /** 2891 * @hide 2892 * @deprecated Use {@link #getNetworkCountryIso(int)} instead. 2893 */ 2894 @Deprecated 2895 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, 2896 publicAlternatives = "Use {@link #getNetworkCountryIso(int)} instead.") getNetworkCountryIsoForPhone(int phoneId)2897 public String getNetworkCountryIsoForPhone(int phoneId) { 2898 return getNetworkCountryIso(phoneId); 2899 } 2900 2901 /* 2902 * When adding a network type to the list below, make sure to add the correct icon to 2903 * MobileSignalController.mapIconSets() as well as NETWORK_TYPES 2904 * Do not add negative types. 2905 */ 2906 /** Network type is unknown */ 2907 public static final int NETWORK_TYPE_UNKNOWN = TelephonyProtoEnums.NETWORK_TYPE_UNKNOWN; // = 0. 2908 /** Current network is GPRS */ 2909 public static final int NETWORK_TYPE_GPRS = TelephonyProtoEnums.NETWORK_TYPE_GPRS; // = 1. 2910 /** Current network is EDGE */ 2911 public static final int NETWORK_TYPE_EDGE = TelephonyProtoEnums.NETWORK_TYPE_EDGE; // = 2. 2912 /** Current network is UMTS */ 2913 public static final int NETWORK_TYPE_UMTS = TelephonyProtoEnums.NETWORK_TYPE_UMTS; // = 3. 2914 /** Current network is CDMA: Either IS95A or IS95B*/ 2915 public static final int NETWORK_TYPE_CDMA = TelephonyProtoEnums.NETWORK_TYPE_CDMA; // = 4. 2916 /** Current network is EVDO revision 0*/ 2917 public static final int NETWORK_TYPE_EVDO_0 = TelephonyProtoEnums.NETWORK_TYPE_EVDO_0; // = 5. 2918 /** Current network is EVDO revision A*/ 2919 public static final int NETWORK_TYPE_EVDO_A = TelephonyProtoEnums.NETWORK_TYPE_EVDO_A; // = 6. 2920 /** Current network is 1xRTT*/ 2921 public static final int NETWORK_TYPE_1xRTT = TelephonyProtoEnums.NETWORK_TYPE_1XRTT; // = 7. 2922 /** Current network is HSDPA */ 2923 public static final int NETWORK_TYPE_HSDPA = TelephonyProtoEnums.NETWORK_TYPE_HSDPA; // = 8. 2924 /** Current network is HSUPA */ 2925 public static final int NETWORK_TYPE_HSUPA = TelephonyProtoEnums.NETWORK_TYPE_HSUPA; // = 9. 2926 /** Current network is HSPA */ 2927 public static final int NETWORK_TYPE_HSPA = TelephonyProtoEnums.NETWORK_TYPE_HSPA; // = 10. 2928 /** Current network is iDen */ 2929 public static final int NETWORK_TYPE_IDEN = TelephonyProtoEnums.NETWORK_TYPE_IDEN; // = 11. 2930 /** Current network is EVDO revision B*/ 2931 public static final int NETWORK_TYPE_EVDO_B = TelephonyProtoEnums.NETWORK_TYPE_EVDO_B; // = 12. 2932 /** Current network is LTE */ 2933 public static final int NETWORK_TYPE_LTE = TelephonyProtoEnums.NETWORK_TYPE_LTE; // = 13. 2934 /** Current network is eHRPD */ 2935 public static final int NETWORK_TYPE_EHRPD = TelephonyProtoEnums.NETWORK_TYPE_EHRPD; // = 14. 2936 /** Current network is HSPA+ */ 2937 public static final int NETWORK_TYPE_HSPAP = TelephonyProtoEnums.NETWORK_TYPE_HSPAP; // = 15. 2938 /** Current network is GSM */ 2939 public static final int NETWORK_TYPE_GSM = TelephonyProtoEnums.NETWORK_TYPE_GSM; // = 16. 2940 /** Current network is TD_SCDMA */ 2941 public static final int NETWORK_TYPE_TD_SCDMA = 2942 TelephonyProtoEnums.NETWORK_TYPE_TD_SCDMA; // = 17. 2943 /** Current network is IWLAN */ 2944 public static final int NETWORK_TYPE_IWLAN = TelephonyProtoEnums.NETWORK_TYPE_IWLAN; // = 18. 2945 /** Current network is LTE_CA {@hide} */ 2946 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 2947 public static final int NETWORK_TYPE_LTE_CA = TelephonyProtoEnums.NETWORK_TYPE_LTE_CA; // = 19. 2948 /** 2949 * Current network is NR (New Radio) 5G. 2950 * This will only be returned for 5G SA. 2951 * For 5G NSA, the network type will be {@link #NETWORK_TYPE_LTE}. 2952 */ 2953 public static final int NETWORK_TYPE_NR = TelephonyProtoEnums.NETWORK_TYPE_NR; // 20. 2954 2955 private static final @NetworkType int[] NETWORK_TYPES = { 2956 NETWORK_TYPE_GPRS, 2957 NETWORK_TYPE_EDGE, 2958 NETWORK_TYPE_UMTS, 2959 NETWORK_TYPE_CDMA, 2960 NETWORK_TYPE_EVDO_0, 2961 NETWORK_TYPE_EVDO_A, 2962 NETWORK_TYPE_1xRTT, 2963 NETWORK_TYPE_HSDPA, 2964 NETWORK_TYPE_HSUPA, 2965 NETWORK_TYPE_HSPA, 2966 NETWORK_TYPE_IDEN, 2967 NETWORK_TYPE_EVDO_B, 2968 NETWORK_TYPE_LTE, 2969 NETWORK_TYPE_EHRPD, 2970 NETWORK_TYPE_HSPAP, 2971 NETWORK_TYPE_GSM, 2972 NETWORK_TYPE_TD_SCDMA, 2973 NETWORK_TYPE_IWLAN, 2974 NETWORK_TYPE_LTE_CA, 2975 NETWORK_TYPE_NR 2976 }; 2977 2978 /** 2979 * Returns an array of all valid network types. 2980 * 2981 * @return An integer array containing all valid network types in no particular order. 2982 * 2983 * @hide 2984 */ 2985 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) getAllNetworkTypes()2986 public static @NonNull @NetworkType int[] getAllNetworkTypes() { 2987 return NETWORK_TYPES.clone(); 2988 } 2989 2990 /** 2991 * Return the current data network type. 2992 * 2993 * @deprecated use {@link #getDataNetworkType()} 2994 * @return the NETWORK_TYPE_xxxx for current data connection. 2995 */ 2996 @Deprecated 2997 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getNetworkType()2998 public @NetworkType int getNetworkType() { 2999 return getNetworkType(getSubId(SubscriptionManager.getActiveDataSubscriptionId())); 3000 } 3001 3002 /** 3003 * Returns a constant indicating the radio technology (network type) 3004 * currently in use on the device for a subscription. 3005 * @return the network type 3006 * 3007 * @param subId for which network type is returned 3008 * 3009 * @see #NETWORK_TYPE_UNKNOWN 3010 * @see #NETWORK_TYPE_GPRS 3011 * @see #NETWORK_TYPE_EDGE 3012 * @see #NETWORK_TYPE_UMTS 3013 * @see #NETWORK_TYPE_HSDPA 3014 * @see #NETWORK_TYPE_HSUPA 3015 * @see #NETWORK_TYPE_HSPA 3016 * @see #NETWORK_TYPE_CDMA 3017 * @see #NETWORK_TYPE_EVDO_0 3018 * @see #NETWORK_TYPE_EVDO_A 3019 * @see #NETWORK_TYPE_EVDO_B 3020 * @see #NETWORK_TYPE_1xRTT 3021 * @see #NETWORK_TYPE_IDEN 3022 * @see #NETWORK_TYPE_LTE 3023 * @see #NETWORK_TYPE_EHRPD 3024 * @see #NETWORK_TYPE_HSPAP 3025 * @see #NETWORK_TYPE_NR 3026 * 3027 * @hide 3028 */ 3029 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 3030 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getNetworkType(int subId)3031 public int getNetworkType(int subId) { 3032 try { 3033 ITelephony telephony = getITelephony(); 3034 if (telephony != null) { 3035 return telephony.getNetworkTypeForSubscriber(subId, getOpPackageName(), 3036 getAttributionTag()); 3037 } else { 3038 // This can happen when the ITelephony interface is not up yet. 3039 return NETWORK_TYPE_UNKNOWN; 3040 } 3041 } catch (RemoteException ex) { 3042 // This shouldn't happen in the normal case 3043 return NETWORK_TYPE_UNKNOWN; 3044 } catch (NullPointerException ex) { 3045 // This could happen before phone restarts due to crashing 3046 return NETWORK_TYPE_UNKNOWN; 3047 } 3048 } 3049 3050 /** 3051 * Returns a constant indicating the radio technology (network type) 3052 * currently in use on the device for data transmission. 3053 * 3054 * If this object has been created with {@link #createForSubscriptionId}, applies to the given 3055 * subId. Otherwise, applies to {@link SubscriptionManager#getActiveDataSubscriptionId()}. 3056 * 3057 * Note: Before {@link SubscriptionManager#getActiveDataSubscriptionId()} was introduced in API 3058 * level 30, it was applied to {@link SubscriptionManager#getDefaultDataSubscriptionId()} which 3059 * may be different now from {@link SubscriptionManager#getActiveDataSubscriptionId()}, e.g. 3060 * when opportunistic network is providing cellular internet connection to the user. 3061 * 3062 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3063 * or {@link android.Manifest.permission#READ_BASIC_PHONE_STATE 3064 * READ_BASIC_PHONE_STATE} or that the calling app has carrier privileges 3065 * (see {@link #hasCarrierPrivileges}). 3066 * 3067 * @return the network type 3068 * 3069 * @see #NETWORK_TYPE_UNKNOWN 3070 * @see #NETWORK_TYPE_GPRS 3071 * @see #NETWORK_TYPE_EDGE 3072 * @see #NETWORK_TYPE_UMTS 3073 * @see #NETWORK_TYPE_HSDPA 3074 * @see #NETWORK_TYPE_HSUPA 3075 * @see #NETWORK_TYPE_HSPA 3076 * @see #NETWORK_TYPE_CDMA 3077 * @see #NETWORK_TYPE_EVDO_0 3078 * @see #NETWORK_TYPE_EVDO_A 3079 * @see #NETWORK_TYPE_EVDO_B 3080 * @see #NETWORK_TYPE_1xRTT 3081 * @see #NETWORK_TYPE_IDEN 3082 * @see #NETWORK_TYPE_LTE 3083 * @see #NETWORK_TYPE_EHRPD 3084 * @see #NETWORK_TYPE_HSPAP 3085 * @see #NETWORK_TYPE_NR 3086 */ 3087 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 3088 @RequiresPermission(anyOf = { 3089 android.Manifest.permission.READ_PHONE_STATE, 3090 android.Manifest.permission.READ_BASIC_PHONE_STATE}) 3091 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) getDataNetworkType()3092 public @NetworkType int getDataNetworkType() { 3093 return getDataNetworkType(getSubId(SubscriptionManager.getActiveDataSubscriptionId())); 3094 } 3095 3096 /** 3097 * Returns a constant indicating the radio technology (network type) 3098 * currently in use on the device for data transmission for a subscription 3099 * @return the network type 3100 * 3101 * @param subId for which network type is returned 3102 * @hide 3103 */ 3104 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 3105 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getDataNetworkType(int subId)3106 public int getDataNetworkType(int subId) { 3107 try{ 3108 ITelephony telephony = getITelephony(); 3109 if (telephony != null) { 3110 return telephony.getDataNetworkTypeForSubscriber(subId, getOpPackageName(), 3111 getAttributionTag()); 3112 } else { 3113 // This can happen when the ITelephony interface is not up yet. 3114 return NETWORK_TYPE_UNKNOWN; 3115 } 3116 } catch(RemoteException ex) { 3117 // This shouldn't happen in the normal case 3118 return NETWORK_TYPE_UNKNOWN; 3119 } catch (NullPointerException ex) { 3120 // This could happen before phone restarts due to crashing 3121 return NETWORK_TYPE_UNKNOWN; 3122 } 3123 } 3124 3125 /** 3126 * Returns the NETWORK_TYPE_xxxx for voice 3127 * 3128 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 3129 * or {@link android.Manifest.permission#READ_BASIC_PHONE_STATE 3130 * READ_BASIC_PHONE_STATE} or that the calling app has carrier privileges 3131 * (see {@link #hasCarrierPrivileges}). 3132 */ 3133 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 3134 @RequiresPermission(anyOf = { 3135 android.Manifest.permission.READ_PHONE_STATE, 3136 android.Manifest.permission.READ_BASIC_PHONE_STATE}) 3137 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) getVoiceNetworkType()3138 public @NetworkType int getVoiceNetworkType() { 3139 return getVoiceNetworkType(getSubId()); 3140 } 3141 3142 /** 3143 * Returns the NETWORK_TYPE_xxxx for voice for a subId 3144 * @hide 3145 */ 3146 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 3147 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getVoiceNetworkType(int subId)3148 public int getVoiceNetworkType(int subId) { 3149 try{ 3150 ITelephony telephony = getITelephony(); 3151 if (telephony != null) { 3152 return telephony.getVoiceNetworkTypeForSubscriber(subId, getOpPackageName(), 3153 getAttributionTag()); 3154 } else { 3155 // This can happen when the ITelephony interface is not up yet. 3156 return NETWORK_TYPE_UNKNOWN; 3157 } 3158 } catch(RemoteException ex) { 3159 // This shouldn't happen in the normal case 3160 return NETWORK_TYPE_UNKNOWN; 3161 } catch (NullPointerException ex) { 3162 // This could happen before phone restarts due to crashing 3163 return NETWORK_TYPE_UNKNOWN; 3164 } 3165 } 3166 3167 /** 3168 * Returns a string representation of the radio technology (network type) 3169 * currently in use on the device. 3170 * @return the name of the radio technology 3171 * 3172 * @hide pending API council review 3173 */ 3174 @UnsupportedAppUsage getNetworkTypeName()3175 public String getNetworkTypeName() { 3176 return getNetworkTypeName(getNetworkType()); 3177 } 3178 3179 /** 3180 * Returns a string representation of the radio technology (network type) 3181 * currently in use on the device. 3182 * @param subId for which network type is returned 3183 * @return the name of the radio technology 3184 * 3185 */ 3186 /** {@hide} */ 3187 @UnsupportedAppUsage getNetworkTypeName(@etworkType int type)3188 public static String getNetworkTypeName(@NetworkType int type) { 3189 switch (type) { 3190 case NETWORK_TYPE_GPRS: 3191 return "GPRS"; 3192 case NETWORK_TYPE_EDGE: 3193 return "EDGE"; 3194 case NETWORK_TYPE_UMTS: 3195 return "UMTS"; 3196 case NETWORK_TYPE_HSDPA: 3197 return "HSDPA"; 3198 case NETWORK_TYPE_HSUPA: 3199 return "HSUPA"; 3200 case NETWORK_TYPE_HSPA: 3201 return "HSPA"; 3202 case NETWORK_TYPE_CDMA: 3203 return "CDMA"; 3204 case NETWORK_TYPE_EVDO_0: 3205 return "CDMA - EvDo rev. 0"; 3206 case NETWORK_TYPE_EVDO_A: 3207 return "CDMA - EvDo rev. A"; 3208 case NETWORK_TYPE_EVDO_B: 3209 return "CDMA - EvDo rev. B"; 3210 case NETWORK_TYPE_1xRTT: 3211 return "CDMA - 1xRTT"; 3212 case NETWORK_TYPE_LTE: 3213 return "LTE"; 3214 case NETWORK_TYPE_EHRPD: 3215 return "CDMA - eHRPD"; 3216 case NETWORK_TYPE_IDEN: 3217 return "iDEN"; 3218 case NETWORK_TYPE_HSPAP: 3219 return "HSPA+"; 3220 case NETWORK_TYPE_GSM: 3221 return "GSM"; 3222 case NETWORK_TYPE_TD_SCDMA: 3223 return "TD_SCDMA"; 3224 case NETWORK_TYPE_IWLAN: 3225 return "IWLAN"; 3226 case NETWORK_TYPE_LTE_CA: 3227 return "LTE_CA"; 3228 case NETWORK_TYPE_NR: 3229 return "NR"; 3230 case NETWORK_TYPE_UNKNOWN: 3231 return "UNKNOWN"; 3232 default: 3233 return "UNKNOWN(" + type + ")"; 3234 } 3235 } 3236 3237 /** 3238 * Returns the bitmask for a given technology (network type) 3239 * @param networkType for which bitmask is returned 3240 * @return the network type bitmask 3241 * {@hide} 3242 */ getBitMaskForNetworkType(@etworkType int networkType)3243 public static @NetworkTypeBitMask long getBitMaskForNetworkType(@NetworkType int networkType) { 3244 switch(networkType) { 3245 case NETWORK_TYPE_GSM: 3246 return NETWORK_TYPE_BITMASK_GSM; 3247 case NETWORK_TYPE_GPRS: 3248 return NETWORK_TYPE_BITMASK_GPRS; 3249 case NETWORK_TYPE_EDGE: 3250 return NETWORK_TYPE_BITMASK_EDGE; 3251 case NETWORK_TYPE_CDMA: 3252 return NETWORK_TYPE_BITMASK_CDMA; 3253 case NETWORK_TYPE_1xRTT: 3254 return NETWORK_TYPE_BITMASK_1xRTT; 3255 case NETWORK_TYPE_EVDO_0: 3256 return NETWORK_TYPE_BITMASK_EVDO_0; 3257 case NETWORK_TYPE_EVDO_A: 3258 return NETWORK_TYPE_BITMASK_EVDO_A; 3259 case NETWORK_TYPE_EVDO_B: 3260 return NETWORK_TYPE_BITMASK_EVDO_B; 3261 case NETWORK_TYPE_EHRPD: 3262 return NETWORK_TYPE_BITMASK_EHRPD; 3263 case NETWORK_TYPE_HSUPA: 3264 return NETWORK_TYPE_BITMASK_HSUPA; 3265 case NETWORK_TYPE_HSDPA: 3266 return NETWORK_TYPE_BITMASK_HSDPA; 3267 case NETWORK_TYPE_HSPA: 3268 return NETWORK_TYPE_BITMASK_HSPA; 3269 case NETWORK_TYPE_HSPAP: 3270 return NETWORK_TYPE_BITMASK_HSPAP; 3271 case NETWORK_TYPE_UMTS: 3272 return NETWORK_TYPE_BITMASK_UMTS; 3273 case NETWORK_TYPE_TD_SCDMA: 3274 return NETWORK_TYPE_BITMASK_TD_SCDMA; 3275 case NETWORK_TYPE_LTE: 3276 return NETWORK_TYPE_BITMASK_LTE; 3277 case NETWORK_TYPE_LTE_CA: 3278 return NETWORK_TYPE_BITMASK_LTE_CA; 3279 case NETWORK_TYPE_NR: 3280 return NETWORK_TYPE_BITMASK_NR; 3281 case NETWORK_TYPE_IWLAN: 3282 return NETWORK_TYPE_BITMASK_IWLAN; 3283 case NETWORK_TYPE_IDEN: 3284 return (1 << (NETWORK_TYPE_IDEN - 1)); 3285 default: 3286 return NETWORK_TYPE_BITMASK_UNKNOWN; 3287 } 3288 } 3289 3290 // 3291 // 3292 // SIM Card 3293 // 3294 // 3295 3296 /** @hide */ 3297 @IntDef(prefix = {"SIM_STATE_"}, 3298 value = { 3299 SIM_STATE_UNKNOWN, 3300 SIM_STATE_ABSENT, 3301 SIM_STATE_PIN_REQUIRED, 3302 SIM_STATE_PUK_REQUIRED, 3303 SIM_STATE_NETWORK_LOCKED, 3304 SIM_STATE_READY, 3305 SIM_STATE_NOT_READY, 3306 SIM_STATE_PERM_DISABLED, 3307 SIM_STATE_CARD_IO_ERROR, 3308 SIM_STATE_CARD_RESTRICTED, 3309 SIM_STATE_LOADED, 3310 SIM_STATE_PRESENT, 3311 }) 3312 public @interface SimState {} 3313 3314 /** 3315 * SIM card state: Unknown. Signifies that the SIM is in transition 3316 * between states. For example, when the user inputs the SIM pin 3317 * under PIN_REQUIRED state, a query for sim status returns 3318 * this state before turning to SIM_STATE_READY. 3319 * 3320 * These are the ordinal value of IccCardConstants.State. 3321 */ 3322 3323 public static final int SIM_STATE_UNKNOWN = TelephonyProtoEnums.SIM_STATE_UNKNOWN; // 0 3324 /** SIM card state: no SIM card is available in the device */ 3325 public static final int SIM_STATE_ABSENT = TelephonyProtoEnums.SIM_STATE_ABSENT; // 1 3326 /** SIM card state: Locked: requires the user's SIM PIN to unlock */ 3327 public static final int SIM_STATE_PIN_REQUIRED = 3328 TelephonyProtoEnums.SIM_STATE_PIN_REQUIRED; // 2 3329 /** SIM card state: Locked: requires the user's SIM PUK to unlock */ 3330 public static final int SIM_STATE_PUK_REQUIRED = 3331 TelephonyProtoEnums.SIM_STATE_PUK_REQUIRED; // 3 3332 /** SIM card state: Locked: requires a network PIN to unlock */ 3333 public static final int SIM_STATE_NETWORK_LOCKED = 3334 TelephonyProtoEnums.SIM_STATE_NETWORK_LOCKED; // 4 3335 /** SIM card state: Ready */ 3336 public static final int SIM_STATE_READY = TelephonyProtoEnums.SIM_STATE_READY; // 5 3337 /** SIM card state: SIM Card is NOT READY */ 3338 public static final int SIM_STATE_NOT_READY = TelephonyProtoEnums.SIM_STATE_NOT_READY; // 6 3339 /** SIM card state: SIM Card Error, permanently disabled */ 3340 public static final int SIM_STATE_PERM_DISABLED = 3341 TelephonyProtoEnums.SIM_STATE_PERM_DISABLED; // 7 3342 /** SIM card state: SIM Card Error, present but faulty */ 3343 public static final int SIM_STATE_CARD_IO_ERROR = 3344 TelephonyProtoEnums.SIM_STATE_CARD_IO_ERROR; // 8 3345 /** SIM card state: SIM Card restricted, present but not usable due to 3346 * carrier restrictions. 3347 */ 3348 public static final int SIM_STATE_CARD_RESTRICTED = 3349 TelephonyProtoEnums.SIM_STATE_CARD_RESTRICTED; // 9 3350 /** 3351 * SIM card state: Loaded: SIM card applications have been loaded 3352 * @hide 3353 */ 3354 @SystemApi 3355 public static final int SIM_STATE_LOADED = TelephonyProtoEnums.SIM_STATE_LOADED; // 10 3356 /** 3357 * SIM card state: SIM Card is present 3358 * @hide 3359 */ 3360 @SystemApi 3361 public static final int SIM_STATE_PRESENT = TelephonyProtoEnums.SIM_STATE_PRESENT; // 11 3362 3363 /** 3364 * Extra included in {@link #ACTION_SIM_CARD_STATE_CHANGED} and 3365 * {@link #ACTION_SIM_APPLICATION_STATE_CHANGED} to indicate the card/application state. 3366 * 3367 * @hide 3368 */ 3369 @SystemApi 3370 public static final String EXTRA_SIM_STATE = "android.telephony.extra.SIM_STATE"; 3371 3372 /** 3373 * Broadcast Action: The sim card state has changed. 3374 * The intent will have the following extra values:</p> 3375 * <dl> 3376 * <dt>{@link #EXTRA_SIM_STATE}</dt> 3377 * <dd>The sim card state. One of: 3378 * <dl> 3379 * <dt>{@link #SIM_STATE_ABSENT}</dt> 3380 * <dd>SIM card not found</dd> 3381 * <dt>{@link #SIM_STATE_CARD_IO_ERROR}</dt> 3382 * <dd>SIM card IO error</dd> 3383 * <dt>{@link #SIM_STATE_CARD_RESTRICTED}</dt> 3384 * <dd>SIM card is restricted</dd> 3385 * <dt>{@link #SIM_STATE_PRESENT}</dt> 3386 * <dd>SIM card is present</dd> 3387 * </dl> 3388 * </dd> 3389 * </dl> 3390 * 3391 * <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission. 3392 * 3393 * <p class="note">The current state can also be queried using {@link #getSimCardState()}. 3394 * 3395 * <p class="note">This is a protected intent that can only be sent by the system. 3396 * @hide 3397 */ 3398 @SystemApi 3399 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 3400 public static final String ACTION_SIM_CARD_STATE_CHANGED = 3401 "android.telephony.action.SIM_CARD_STATE_CHANGED"; 3402 3403 /** 3404 * Broadcast Action: The sim application state has changed. 3405 * The intent will have the following extra values:</p> 3406 * <dl> 3407 * <dt>{@link #EXTRA_SIM_STATE}</dt> 3408 * <dd>The sim application state. One of: 3409 * <dl> 3410 * <dt>{@link #SIM_STATE_NOT_READY}</dt> 3411 * <dd>SIM card applications not ready</dd> 3412 * <dt>{@link #SIM_STATE_PIN_REQUIRED}</dt> 3413 * <dd>SIM card PIN locked</dd> 3414 * <dt>{@link #SIM_STATE_PUK_REQUIRED}</dt> 3415 * <dd>SIM card PUK locked</dd> 3416 * <dt>{@link #SIM_STATE_NETWORK_LOCKED}</dt> 3417 * <dd>SIM card network locked</dd> 3418 * <dt>{@link #SIM_STATE_PERM_DISABLED}</dt> 3419 * <dd>SIM card permanently disabled due to PUK failures</dd> 3420 * <dt>{@link #SIM_STATE_LOADED}</dt> 3421 * <dd>SIM card data loaded</dd> 3422 * </dl> 3423 * </dd> 3424 * </dl> 3425 * 3426 * <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission. 3427 * 3428 * <p class="note">The current state can also be queried using 3429 * {@link #getSimApplicationState()}. 3430 * 3431 * <p class="note">This is a protected intent that can only be sent by the system. 3432 * @hide 3433 */ 3434 @SystemApi 3435 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 3436 public static final String ACTION_SIM_APPLICATION_STATE_CHANGED = 3437 "android.telephony.action.SIM_APPLICATION_STATE_CHANGED"; 3438 3439 /** 3440 * Broadcast Action: Status of the SIM slots on the device has changed. 3441 * 3442 * <p class="note">Requires the READ_PRIVILEGED_PHONE_STATE permission. 3443 * 3444 * <p class="note">The status can be queried using 3445 * {@link #getUiccSlotsInfo()} 3446 * 3447 * <p class="note">This is a protected intent that can only be sent by the system. 3448 * @hide 3449 */ 3450 @SystemApi 3451 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 3452 public static final String ACTION_SIM_SLOT_STATUS_CHANGED = 3453 "android.telephony.action.SIM_SLOT_STATUS_CHANGED"; 3454 3455 /** 3456 * Broadcast Action: A debug code has been entered in the dialer. 3457 * <p> 3458 * This intent is broadcast by the system and OEM telephony apps may need to receive these 3459 * broadcasts. And it requires the sender to be default dialer or has carrier privileges 3460 * (see {@link #hasCarrierPrivileges}). 3461 * <p> 3462 * These "secret codes" are used to activate developer menus by dialing certain codes. 3463 * And they are of the form {@code *#*#<code>#*#*}. The intent will have the data 3464 * URI: {@code android_secret_code://<code>}. It is possible that a manifest 3465 * receiver would be woken up even if it is not currently running. 3466 * <p> 3467 * It is supposed to replace {@link android.provider.Telephony.Sms.Intents#SECRET_CODE_ACTION} 3468 * in the next Android version. 3469 * Before that both of these two actions will be broadcast. 3470 */ 3471 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) 3472 public static final String ACTION_SECRET_CODE = "android.telephony.action.SECRET_CODE"; 3473 3474 /** 3475 * @return true if a ICC card is present 3476 */ 3477 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) hasIccCard()3478 public boolean hasIccCard() { 3479 return hasIccCard(getSlotIndex()); 3480 } 3481 3482 /** 3483 * @return true if a ICC card is present for a subscription 3484 * 3485 * @param slotIndex for which icc card presence is checked 3486 */ 3487 /** {@hide} */ 3488 // FIXME Input argument slotIndex should be of type int 3489 @UnsupportedAppUsage hasIccCard(int slotIndex)3490 public boolean hasIccCard(int slotIndex) { 3491 3492 try { 3493 ITelephony telephony = getITelephony(); 3494 if (telephony == null) 3495 return false; 3496 return telephony.hasIccCardUsingSlotIndex(slotIndex); 3497 } catch (RemoteException ex) { 3498 // Assume no ICC card if remote exception which shouldn't happen 3499 return false; 3500 } catch (NullPointerException ex) { 3501 // This could happen before phone restarts due to crashing 3502 return false; 3503 } 3504 } 3505 3506 /** 3507 * Returns a constant indicating the state of the default SIM card. 3508 * 3509 * @see #SIM_STATE_UNKNOWN 3510 * @see #SIM_STATE_ABSENT 3511 * @see #SIM_STATE_PIN_REQUIRED 3512 * @see #SIM_STATE_PUK_REQUIRED 3513 * @see #SIM_STATE_NETWORK_LOCKED 3514 * @see #SIM_STATE_READY 3515 * @see #SIM_STATE_NOT_READY 3516 * @see #SIM_STATE_PERM_DISABLED 3517 * @see #SIM_STATE_CARD_IO_ERROR 3518 * @see #SIM_STATE_CARD_RESTRICTED 3519 */ 3520 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimState()3521 public @SimState int getSimState() { 3522 int simState = getSimStateIncludingLoaded(); 3523 if (simState == SIM_STATE_LOADED) { 3524 simState = SIM_STATE_READY; 3525 } 3526 return simState; 3527 } 3528 getSimStateIncludingLoaded()3529 private @SimState int getSimStateIncludingLoaded() { 3530 int slotIndex = getSlotIndex(); 3531 // slotIndex may be invalid due to sim being absent. In that case query all slots to get 3532 // sim state 3533 if (slotIndex < 0) { 3534 // query for all slots and return absent if all sim states are absent, otherwise 3535 // return unknown 3536 for (int i = 0; i < getPhoneCount(); i++) { 3537 int simState = getSimState(i); 3538 if (simState != SIM_STATE_ABSENT) { 3539 Rlog.d(TAG, "getSimState: default sim:" + slotIndex + ", sim state for " + 3540 "slotIndex=" + i + " is " + simState + ", return state as unknown"); 3541 return SIM_STATE_UNKNOWN; 3542 } 3543 } 3544 Rlog.d(TAG, "getSimState: default sim:" + slotIndex + ", all SIMs absent, return " + 3545 "state as absent"); 3546 return SIM_STATE_ABSENT; 3547 } 3548 return SubscriptionManager.getSimStateForSlotIndex(slotIndex); 3549 } 3550 3551 /** 3552 * Returns a constant indicating the state of the default SIM card. 3553 * 3554 * @see #SIM_STATE_UNKNOWN 3555 * @see #SIM_STATE_ABSENT 3556 * @see #SIM_STATE_CARD_IO_ERROR 3557 * @see #SIM_STATE_CARD_RESTRICTED 3558 * @see #SIM_STATE_PRESENT 3559 * 3560 * @hide 3561 */ 3562 @SystemApi 3563 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimCardState()3564 public @SimState int getSimCardState() { 3565 int simState = getSimState(); 3566 return getSimCardStateFromSimState(simState); 3567 } 3568 3569 /** 3570 * Returns a constant indicating the state of the device SIM card in a physical slot. 3571 * 3572 * @param physicalSlotIndex physical slot index 3573 * 3574 * @see #SIM_STATE_UNKNOWN 3575 * @see #SIM_STATE_ABSENT 3576 * @see #SIM_STATE_CARD_IO_ERROR 3577 * @see #SIM_STATE_CARD_RESTRICTED 3578 * @see #SIM_STATE_PRESENT 3579 * 3580 * @hide 3581 * @deprecated instead use {@link #getSimCardState(int, int)} 3582 */ 3583 @SystemApi 3584 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 3585 @Deprecated getSimCardState(int physicalSlotIndex)3586 public @SimState int getSimCardState(int physicalSlotIndex) { 3587 int activePort = getFirstActivePortIndex(physicalSlotIndex); 3588 int simState = getSimState(getLogicalSlotIndex(physicalSlotIndex, activePort)); 3589 return getSimCardStateFromSimState(simState); 3590 } 3591 3592 /** 3593 * Returns a constant indicating the state of the device SIM card in a physical slot and 3594 * port index. 3595 * 3596 * @param physicalSlotIndex physical slot index 3597 * @param portIndex The port index is an enumeration of the ports available on the UICC. 3598 * Use {@link UiccPortInfo#getPortIndex()} to get portIndex. 3599 * 3600 * @see #SIM_STATE_UNKNOWN 3601 * @see #SIM_STATE_ABSENT 3602 * @see #SIM_STATE_CARD_IO_ERROR 3603 * @see #SIM_STATE_CARD_RESTRICTED 3604 * @see #SIM_STATE_PRESENT 3605 * 3606 * @hide 3607 */ 3608 @SystemApi 3609 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 3610 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimCardState(int physicalSlotIndex, int portIndex)3611 public @SimState int getSimCardState(int physicalSlotIndex, int portIndex) { 3612 int simState = getSimState(getLogicalSlotIndex(physicalSlotIndex, portIndex)); 3613 return getSimCardStateFromSimState(simState); 3614 } 3615 /** 3616 * Converts SIM state to SIM card state. 3617 * @param simState 3618 * @return SIM card state 3619 */ getSimCardStateFromSimState(int simState)3620 private @SimState int getSimCardStateFromSimState(int simState) { 3621 switch (simState) { 3622 case SIM_STATE_UNKNOWN: 3623 case SIM_STATE_ABSENT: 3624 case SIM_STATE_CARD_IO_ERROR: 3625 case SIM_STATE_CARD_RESTRICTED: 3626 return simState; 3627 default: 3628 return SIM_STATE_PRESENT; 3629 } 3630 } 3631 3632 /** 3633 * Converts a physical slot index to logical slot index. 3634 * @param physicalSlotIndex physical slot index 3635 * @param portIndex The port index is an enumeration of the ports available on the UICC. 3636 * Use {@link UiccPortInfo#getPortIndex()} to get portIndex. 3637 * @return logical slot index 3638 */ getLogicalSlotIndex(int physicalSlotIndex, int portIndex)3639 private int getLogicalSlotIndex(int physicalSlotIndex, int portIndex) { 3640 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); 3641 if (slotInfos != null && physicalSlotIndex >= 0 && physicalSlotIndex < slotInfos.length 3642 && slotInfos[physicalSlotIndex] != null) { 3643 for (UiccPortInfo portInfo : slotInfos[physicalSlotIndex].getPorts()) { 3644 if (portInfo.getPortIndex() == portIndex) { 3645 return portInfo.getLogicalSlotIndex(); 3646 } 3647 } 3648 } 3649 3650 return SubscriptionManager.INVALID_SIM_SLOT_INDEX; 3651 } 3652 3653 /** 3654 * Returns a constant indicating the state of the card applications on the default SIM card. 3655 * 3656 * @see #SIM_STATE_UNKNOWN 3657 * @see #SIM_STATE_PIN_REQUIRED 3658 * @see #SIM_STATE_PUK_REQUIRED 3659 * @see #SIM_STATE_NETWORK_LOCKED 3660 * @see #SIM_STATE_NOT_READY 3661 * @see #SIM_STATE_PERM_DISABLED 3662 * @see #SIM_STATE_LOADED 3663 * 3664 * @hide 3665 */ 3666 @SystemApi 3667 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimApplicationState()3668 public @SimState int getSimApplicationState() { 3669 int simState = getSimStateIncludingLoaded(); 3670 return getSimApplicationStateFromSimState(simState); 3671 } 3672 3673 /** 3674 * Returns a constant indicating the state of the card applications on the device SIM card in 3675 * a physical slot. 3676 * 3677 * @param physicalSlotIndex physical slot index 3678 * 3679 * @see #SIM_STATE_UNKNOWN 3680 * @see #SIM_STATE_PIN_REQUIRED 3681 * @see #SIM_STATE_PUK_REQUIRED 3682 * @see #SIM_STATE_NETWORK_LOCKED 3683 * @see #SIM_STATE_NOT_READY 3684 * @see #SIM_STATE_PERM_DISABLED 3685 * @see #SIM_STATE_LOADED 3686 * 3687 * @hide 3688 * @deprecated instead use {@link #getSimApplicationState(int, int)} 3689 */ 3690 @SystemApi 3691 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 3692 @Deprecated getSimApplicationState(int physicalSlotIndex)3693 public @SimState int getSimApplicationState(int physicalSlotIndex) { 3694 int activePort = getFirstActivePortIndex(physicalSlotIndex); 3695 int simState = 3696 SubscriptionManager.getSimStateForSlotIndex(getLogicalSlotIndex(physicalSlotIndex, 3697 activePort)); 3698 return getSimApplicationStateFromSimState(simState); 3699 } 3700 3701 /** 3702 * Returns a constant indicating the state of the card applications on the device SIM card in 3703 * a physical slot. 3704 * 3705 * @param physicalSlotIndex physical slot index 3706 * @param portIndex The port index is an enumeration of the ports available on the UICC. 3707 * Use {@link UiccPortInfo#getPortIndex()} to get portIndex. 3708 * 3709 * @see #SIM_STATE_UNKNOWN 3710 * @see #SIM_STATE_PIN_REQUIRED 3711 * @see #SIM_STATE_PUK_REQUIRED 3712 * @see #SIM_STATE_NETWORK_LOCKED 3713 * @see #SIM_STATE_NOT_READY 3714 * @see #SIM_STATE_PERM_DISABLED 3715 * @see #SIM_STATE_LOADED 3716 * 3717 * @hide 3718 */ 3719 @SystemApi 3720 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 3721 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimApplicationState(int physicalSlotIndex, int portIndex)3722 public @SimState int getSimApplicationState(int physicalSlotIndex, int portIndex) { 3723 int simState = 3724 SubscriptionManager.getSimStateForSlotIndex(getLogicalSlotIndex(physicalSlotIndex, 3725 portIndex)); 3726 return getSimApplicationStateFromSimState(simState); 3727 } 3728 3729 /** 3730 * Converts SIM state to SIM application state. 3731 * @param simState 3732 * @return SIM application state 3733 */ getSimApplicationStateFromSimState(int simState)3734 private @SimState int getSimApplicationStateFromSimState(int simState) { 3735 switch (simState) { 3736 case SIM_STATE_UNKNOWN: 3737 case SIM_STATE_ABSENT: 3738 case SIM_STATE_CARD_IO_ERROR: 3739 case SIM_STATE_CARD_RESTRICTED: 3740 return SIM_STATE_UNKNOWN; 3741 case SIM_STATE_READY: 3742 // Ready is not a valid state anymore. The state that is broadcast goes from 3743 // NOT_READY to either LOCKED or LOADED. 3744 return SIM_STATE_NOT_READY; 3745 default: 3746 return simState; 3747 } 3748 } 3749 3750 3751 /** 3752 * Returns true if the specified type of application (e.g. {@link #APPTYPE_CSIM} is present 3753 * on the UICC card. 3754 * 3755 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 3756 * 3757 * @param appType the uicc app type like {@link APPTYPE_CSIM} 3758 * @return true if the specified type of application in UICC CARD or false if no uicc or error. 3759 * @hide 3760 */ 3761 @SystemApi 3762 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 3763 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) isApplicationOnUicc(@iccAppType int appType)3764 public boolean isApplicationOnUicc(@UiccAppType int appType) { 3765 try { 3766 ITelephony service = getITelephony(); 3767 if (service != null) { 3768 return service.isApplicationOnUicc(getSubId(), appType); 3769 } 3770 } catch (RemoteException e) { 3771 Log.e(TAG, "Error calling ITelephony#isApplicationOnUicc", e); 3772 } 3773 return false; 3774 } 3775 3776 /** 3777 * Returns a constant indicating the state of the device SIM card in a logical slot. 3778 * 3779 * @param slotIndex logical slot index 3780 * 3781 * @see #SIM_STATE_UNKNOWN 3782 * @see #SIM_STATE_ABSENT 3783 * @see #SIM_STATE_PIN_REQUIRED 3784 * @see #SIM_STATE_PUK_REQUIRED 3785 * @see #SIM_STATE_NETWORK_LOCKED 3786 * @see #SIM_STATE_READY 3787 * @see #SIM_STATE_NOT_READY 3788 * @see #SIM_STATE_PERM_DISABLED 3789 * @see #SIM_STATE_CARD_IO_ERROR 3790 * @see #SIM_STATE_CARD_RESTRICTED 3791 */ 3792 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimState(int slotIndex)3793 public @SimState int getSimState(int slotIndex) { 3794 int simState = SubscriptionManager.getSimStateForSlotIndex(slotIndex); 3795 if (simState == SIM_STATE_LOADED) { 3796 simState = SIM_STATE_READY; 3797 } 3798 return simState; 3799 } 3800 3801 /** 3802 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3803 * provider of the SIM. 5 or 6 decimal digits. 3804 * <p> 3805 * Availability: SIM state must be {@link #SIM_STATE_READY} 3806 * 3807 * @see #getSimState 3808 */ 3809 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimOperator()3810 public String getSimOperator() { 3811 return getSimOperatorNumeric(); 3812 } 3813 3814 /** 3815 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3816 * provider of the SIM. 5 or 6 decimal digits. 3817 * <p> 3818 * Availability: SIM state must be {@link #SIM_STATE_READY} 3819 * 3820 * @see #getSimState 3821 * 3822 * @param subId for which SimOperator is returned 3823 * @hide 3824 */ 3825 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperator(int subId)3826 public String getSimOperator(int subId) { 3827 return getSimOperatorNumeric(subId); 3828 } 3829 3830 /** 3831 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3832 * provider of the SIM. 5 or 6 decimal digits. 3833 * <p> 3834 * Availability: SIM state must be {@link #SIM_STATE_READY} 3835 * 3836 * @see #getSimState 3837 * @hide 3838 */ 3839 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperatorNumeric()3840 public String getSimOperatorNumeric() { 3841 int subId = mSubId; 3842 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 3843 subId = SubscriptionManager.getDefaultDataSubscriptionId(); 3844 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 3845 subId = SubscriptionManager.getDefaultSmsSubscriptionId(); 3846 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 3847 subId = SubscriptionManager.getDefaultVoiceSubscriptionId(); 3848 if (!SubscriptionManager.isUsableSubIdValue(subId)) { 3849 subId = SubscriptionManager.getDefaultSubscriptionId(); 3850 } 3851 } 3852 } 3853 } 3854 return getSimOperatorNumeric(subId); 3855 } 3856 3857 /** 3858 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3859 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 3860 * <p> 3861 * Availability: SIM state must be {@link #SIM_STATE_READY} 3862 * 3863 * @see #getSimState 3864 * 3865 * @param subId for which SimOperator is returned 3866 * @hide 3867 */ 3868 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperatorNumeric(int subId)3869 public String getSimOperatorNumeric(int subId) { 3870 int phoneId = SubscriptionManager.getPhoneId(subId); 3871 return getSimOperatorNumericForPhone(phoneId); 3872 } 3873 3874 /** 3875 * Returns the MCC+MNC (mobile country code + mobile network code) of the 3876 * provider of the SIM for a particular subscription. 5 or 6 decimal digits. 3877 * <p> 3878 * 3879 * @param phoneId for which SimOperator is returned 3880 * @hide 3881 */ 3882 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperatorNumericForPhone(int phoneId)3883 public String getSimOperatorNumericForPhone(int phoneId) { 3884 return getTelephonyProperty(phoneId, TelephonyProperties.icc_operator_numeric(), ""); 3885 } 3886 3887 /** 3888 * Returns the Service Provider Name (SPN). 3889 * <p> 3890 * Availability: SIM state must be {@link #SIM_STATE_READY} 3891 * 3892 * @see #getSimState 3893 */ 3894 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimOperatorName()3895 public String getSimOperatorName() { 3896 return getSimOperatorNameForPhone(getPhoneId()); 3897 } 3898 3899 /** 3900 * Returns the Service Provider Name (SPN). 3901 * <p> 3902 * Availability: SIM state must be {@link #SIM_STATE_READY} 3903 * 3904 * @see #getSimState 3905 * 3906 * @param subId for which SimOperatorName is returned 3907 * @hide 3908 */ 3909 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimOperatorName(int subId)3910 public String getSimOperatorName(int subId) { 3911 int phoneId = SubscriptionManager.getPhoneId(subId); 3912 return getSimOperatorNameForPhone(phoneId); 3913 } 3914 3915 /** 3916 * Returns the Service Provider Name (SPN). 3917 * 3918 * @hide 3919 */ 3920 @UnsupportedAppUsage getSimOperatorNameForPhone(int phoneId)3921 public String getSimOperatorNameForPhone(int phoneId) { 3922 return getTelephonyProperty(phoneId, TelephonyProperties.icc_operator_alpha(), ""); 3923 } 3924 3925 /** 3926 * Returns the ISO-3166-1 alpha-2 country code equivalent for the SIM provider's country code. 3927 * <p> 3928 * The ISO-3166-1 alpha-2 country code is provided in lowercase 2 character format. 3929 * @return the lowercase 2 character ISO-3166-1 alpha-2 country code, or empty string is not 3930 * available. 3931 */ 3932 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimCountryIso()3933 public String getSimCountryIso() { 3934 return getSimCountryIsoForPhone(getPhoneId()); 3935 } 3936 3937 /** 3938 * Returns the ISO country code equivalent for the SIM provider's country code. 3939 * 3940 * @param subId for which SimCountryIso is returned 3941 * @hide 3942 */ 3943 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSimCountryIso(int subId)3944 public static String getSimCountryIso(int subId) { 3945 int phoneId = SubscriptionManager.getPhoneId(subId); 3946 return getSimCountryIsoForPhone(phoneId); 3947 } 3948 3949 /** 3950 * Returns the ISO country code equivalent for the SIM provider's country code. 3951 * 3952 * @hide 3953 */ 3954 @UnsupportedAppUsage getSimCountryIsoForPhone(int phoneId)3955 public static String getSimCountryIsoForPhone(int phoneId) { 3956 return getTelephonyProperty(phoneId, TelephonyProperties.icc_operator_iso_country(), ""); 3957 } 3958 3959 /** 3960 * Returns the serial number of the SIM, if applicable. Return null if it is 3961 * unavailable. 3962 * 3963 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 3964 * restrictions, and apps are recommended to use resettable identifiers (see <a 3965 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 3966 * method can be invoked if one of the following requirements is met: 3967 * <ul> 3968 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 3969 * is a privileged permission that can only be granted to apps preloaded on the device. 3970 * <li>If the calling app is the device owner of a fully-managed device, a profile 3971 * owner of an organization-owned device, or their delegates (see {@link 3972 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 3973 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 3974 * <li>If the calling app is the default SMS role holder (see {@link 3975 * RoleManager#isRoleHeld(String)}). 3976 * </ul> 3977 * 3978 * <p>If the calling app does not meet one of these requirements then this method will behave 3979 * as follows: 3980 * 3981 * <ul> 3982 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 3983 * READ_PHONE_STATE permission then null is returned.</li> 3984 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 3985 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 3986 * higher, then a SecurityException is thrown.</li> 3987 * </ul> 3988 */ 3989 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 3990 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 3991 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimSerialNumber()3992 public String getSimSerialNumber() { 3993 return getSimSerialNumber(getSubId()); 3994 } 3995 3996 /** 3997 * Returns the serial number for the given subscription, if applicable. Return null if it is 3998 * unavailable. 3999 * 4000 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 4001 * restrictions, and apps are recommended to use resettable identifiers (see <a 4002 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 4003 * method can be invoked if one of the following requirements is met: 4004 * <ul> 4005 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 4006 * is a privileged permission that can only be granted to apps preloaded on the device. 4007 * <li>If the calling app is the device owner of a fully-managed device, a profile 4008 * owner of an organization-owned device, or their delegates (see {@link 4009 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 4010 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4011 * <li>If the calling app is the default SMS role holder (see {@link 4012 * RoleManager#isRoleHeld(String)}). 4013 * </ul> 4014 * 4015 * <p>If the calling app does not meet one of these requirements then this method will behave 4016 * as follows: 4017 * 4018 * <ul> 4019 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 4020 * READ_PHONE_STATE permission then null is returned.</li> 4021 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 4022 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 4023 * higher, then a SecurityException is thrown.</li> 4024 * </ul> 4025 * 4026 * @param subId for which Sim Serial number is returned 4027 * @hide 4028 */ 4029 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 4030 @UnsupportedAppUsage getSimSerialNumber(int subId)4031 public String getSimSerialNumber(int subId) { 4032 try { 4033 IPhoneSubInfo info = getSubscriberInfoService(); 4034 if (info == null) 4035 return null; 4036 return info.getIccSerialNumberForSubscriber(subId, mContext.getOpPackageName(), 4037 mContext.getAttributionTag()); 4038 } catch (RemoteException ex) { 4039 return null; 4040 } catch (NullPointerException ex) { 4041 // This could happen before phone restarts due to crashing 4042 return null; 4043 } 4044 } 4045 4046 /** 4047 * Return if the current radio can support both 3GPP and 3GPP2 radio technologies at the same 4048 * time. This is also known as global mode, which includes LTE, CDMA, EvDo and GSM/WCDMA. 4049 * 4050 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 4051 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()}. 4052 * 4053 * @return {@code true} if 3GPP and 3GPP2 radio technologies can be supported at the same time 4054 * {@code false} if not supported or unknown 4055 * @hide 4056 */ 4057 @SystemApi 4058 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 4059 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) isLteCdmaEvdoGsmWcdmaEnabled()4060 public boolean isLteCdmaEvdoGsmWcdmaEnabled() { 4061 return getLteOnCdmaMode(getSubId()) == PhoneConstants.LTE_ON_CDMA_TRUE; 4062 } 4063 4064 /** 4065 * Return if the current radio is LTE on CDMA for Subscription. This 4066 * is a tri-state return value as for a period of time 4067 * the mode may be unknown. 4068 * 4069 * @param subId for which radio is LTE on CDMA is returned 4070 * @return {@link PhoneConstants#LTE_ON_CDMA_UNKNOWN}, {@link PhoneConstants#LTE_ON_CDMA_FALSE} 4071 * or {@link PhoneConstants#LTE_ON_CDMA_TRUE} 4072 * @hide 4073 */ 4074 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 4075 @UnsupportedAppUsage getLteOnCdmaMode(int subId)4076 public int getLteOnCdmaMode(int subId) { 4077 try { 4078 ITelephony telephony = getITelephony(); 4079 if (telephony == null) 4080 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 4081 return telephony.getLteOnCdmaModeForSubscriber(subId, getOpPackageName(), 4082 getAttributionTag()); 4083 } catch (RemoteException ex) { 4084 // Assume no ICC card if remote exception which shouldn't happen 4085 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 4086 } catch (NullPointerException ex) { 4087 // This could happen before phone restarts due to crashing 4088 return PhoneConstants.LTE_ON_CDMA_UNKNOWN; 4089 } 4090 } 4091 4092 /** 4093 * Get the card ID of the default eUICC card. If the eUICCs have not yet been loaded, returns 4094 * {@link #UNINITIALIZED_CARD_ID}. If there is no eUICC or the device does not support card IDs 4095 * for eUICCs, returns {@link #UNSUPPORTED_CARD_ID}. 4096 * 4097 * <p>The card ID is a unique identifier associated with a UICC or eUICC card. Card IDs are 4098 * unique to a device, and always refer to the same UICC or eUICC card unless the device goes 4099 * through a factory reset. 4100 * 4101 * @return card ID of the default eUICC card, if loaded. 4102 */ 4103 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_EUICC) getCardIdForDefaultEuicc()4104 public int getCardIdForDefaultEuicc() { 4105 try { 4106 ITelephony telephony = getITelephony(); 4107 if (telephony == null) { 4108 return UNINITIALIZED_CARD_ID; 4109 } 4110 return telephony.getCardIdForDefaultEuicc(mSubId, mContext.getOpPackageName()); 4111 } catch (RemoteException e) { 4112 return UNINITIALIZED_CARD_ID; 4113 } 4114 } 4115 4116 /** 4117 * Gets information about currently inserted UICCs and eUICCs. 4118 * <p> 4119 * Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4120 * <p> 4121 * If the caller has carrier priviliges on any active subscription, then they have permission to 4122 * get simple information like the card ID ({@link UiccCardInfo#getCardId()}), whether the card 4123 * is an eUICC ({@link UiccCardInfo#isEuicc()}), and the physical slot index where the card is 4124 * inserted ({@link UiccCardInfo#getPhysicalSlotIndex()}. 4125 * <p> 4126 * To get private information such as the EID ({@link UiccCardInfo#getEid()}) or ICCID 4127 * ({@link UiccCardInfo#getIccId()}), the caller must have carrier priviliges on that specific 4128 * UICC or eUICC card. 4129 * <p> 4130 * See {@link UiccCardInfo} for more details on the kind of information available. 4131 * 4132 * @return a list of UiccCardInfo objects, representing information on the currently inserted 4133 * UICCs and eUICCs. Each UiccCardInfo in the list will have private information filtered out if 4134 * the caller does not have adequate permissions for that card. 4135 */ 4136 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 4137 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) 4138 @NonNull getUiccCardsInfo()4139 public List<UiccCardInfo> getUiccCardsInfo() { 4140 try { 4141 ITelephony telephony = getITelephony(); 4142 if (telephony == null) { 4143 Log.e(TAG, "Error in getUiccCardsInfo: unable to connect to Telephony service."); 4144 return new ArrayList<UiccCardInfo>(); 4145 } 4146 return telephony.getUiccCardsInfo(mContext.getOpPackageName()); 4147 } catch (RemoteException e) { 4148 Log.e(TAG, "Error in getUiccCardsInfo: " + e); 4149 return new ArrayList<UiccCardInfo>(); 4150 } 4151 } 4152 4153 /** 4154 * Gets all the UICC slots. The objects in the array can be null if the slot info is not 4155 * available, which is possible between phone process starting and getting slot info from modem. 4156 * 4157 * @return UiccSlotInfo array. 4158 * 4159 * @hide 4160 */ 4161 @SystemApi 4162 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 4163 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getUiccSlotsInfo()4164 public UiccSlotInfo[] getUiccSlotsInfo() { 4165 try { 4166 ITelephony telephony = getITelephony(); 4167 if (telephony == null) { 4168 return null; 4169 } 4170 return telephony.getUiccSlotsInfo(mContext.getOpPackageName()); 4171 } catch (RemoteException e) { 4172 return null; 4173 } 4174 } 4175 4176 /** 4177 * Test method to reload the UICC profile. 4178 * 4179 * @hide 4180 */ 4181 @TestApi 4182 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) refreshUiccProfile()4183 public void refreshUiccProfile() { 4184 try { 4185 ITelephony telephony = getITelephony(); 4186 telephony.refreshUiccProfile(mSubId); 4187 } catch (RemoteException ex) { 4188 Rlog.w(TAG, "RemoteException", ex); 4189 } 4190 } 4191 4192 /** 4193 * Map logicalSlot to physicalSlot, and activate the physicalSlot if it is inactive. For 4194 * example, passing the physicalSlots array [1, 0] means mapping the first item 1, which is 4195 * physical slot index 1, to the logical slot 0; and mapping the second item 0, which is 4196 * physical slot index 0, to the logical slot 1. The index of the array means the index of the 4197 * logical slots. 4198 * 4199 * @param physicalSlots The content of the array represents the physical slot index. The array 4200 * size should be same as {@link #getUiccSlotsInfo()}. 4201 * @return boolean Return true if the switch succeeds, false if the switch fails. 4202 * @hide 4203 * @deprecated {@link #setSimSlotMapping(Collection, Executor, Consumer)} 4204 */ 4205 // TODO: once integrating the HAL changes we can convert int[] to List<UiccSlotMapping> and 4206 // converge API's in ITelephony.aidl and PhoneInterfaceManager 4207 4208 @SystemApi 4209 @Deprecated 4210 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) switchSlots(int[] physicalSlots)4211 public boolean switchSlots(int[] physicalSlots) { 4212 try { 4213 ITelephony telephony = getITelephony(); 4214 if (telephony == null) { 4215 return false; 4216 } 4217 return telephony.switchSlots(physicalSlots); 4218 } catch (RemoteException e) { 4219 return false; 4220 } 4221 } 4222 4223 /** 4224 * @param slotMapping Logical to physical slot and port mapping. 4225 * @return {@code true} if slotMapping is valid. 4226 * @return {@code false} if slotMapping is invalid. 4227 * 4228 * slotMapping is invalid if there are different entries (physical slot + port) mapping to the 4229 * same logical slot or if there are same {physical slot + port} mapping to the different 4230 * logical slot 4231 * @hide 4232 */ isSlotMappingValid(@onNull Collection<UiccSlotMapping> slotMapping)4233 private static boolean isSlotMappingValid(@NonNull Collection<UiccSlotMapping> slotMapping) { 4234 // Grouping the collection by logicalSlotIndex, finding different entries mapping to the 4235 // same logical slot 4236 Map<Integer, List<UiccSlotMapping>> slotMappingInfo = slotMapping.stream().collect( 4237 Collectors.groupingBy(UiccSlotMapping::getLogicalSlotIndex)); 4238 for (Map.Entry<Integer, List<UiccSlotMapping>> entry : slotMappingInfo.entrySet()) { 4239 List<UiccSlotMapping> logicalSlotMap = entry.getValue(); 4240 if (logicalSlotMap.size() > 1) { 4241 // duplicate logicalSlotIndex found 4242 return false; 4243 } 4244 } 4245 4246 // Grouping the collection by physical slot and port, finding same entries mapping to the 4247 // different logical slot 4248 Map<List<Integer>, List<UiccSlotMapping>> slotMapInfos = slotMapping.stream().collect( 4249 Collectors.groupingBy( 4250 slot -> Arrays.asList(slot.getPhysicalSlotIndex(), slot.getPortIndex()))); 4251 for (Map.Entry<List<Integer>, List<UiccSlotMapping>> entry : slotMapInfos.entrySet()) { 4252 List<UiccSlotMapping> portAndPhysicalSlotList = entry.getValue(); 4253 if (portAndPhysicalSlotList.size() > 1) { 4254 // duplicate pair of portIndex and physicalSlotIndex found 4255 return false; 4256 } 4257 } 4258 return true; 4259 } 4260 /** 4261 * Maps the logical slots to physical slots and ports. Mapping is specified from 4262 * {@link UiccSlotMapping} which consist of both physical slot index and port index. 4263 * Logical slot is the slot that is seen by modem. Physical slot is the actual physical slot. 4264 * Port index is the index (enumerated value) for the associated port available on the SIM. 4265 * Each physical slot can have multiple ports if 4266 * {@link PackageManager#FEATURE_TELEPHONY_EUICC_MEP} is supported. 4267 * 4268 * Example: no. of logical slots 1 and physical slots 2 do not support MEP, each physical slot 4269 * has one port: 4270 * The only logical slot (index 0) can be mapped to first physical slot (value 0), port(index 4271 * 0) or 4272 * second physical slot(value 1), port (index 0), while the other physical slot remains unmapped 4273 * and inactive. 4274 * slotMapping[0] = UiccSlotMapping{0 //port index, 0 //physical slot, 0 //logical slot} or 4275 * slotMapping[0] = UiccSlotMapping{0 //port index, 1 //physical slot, 0 //logical slot} 4276 * 4277 * Example no. of logical slots 2 and physical slots 2 supports MEP with 2 ports available: 4278 * Each logical slot must be mapped to a port (physical slot and port combination). 4279 * First logical slot (index 0) can be mapped to physical slot 1 and the second logical slot 4280 * can be mapped to either port from physical slot 2. 4281 * 4282 * slotMapping[0] = UiccSlotMapping{0, 0, 0} and slotMapping[1] = UiccSlotMapping{0, 1, 1} or 4283 * slotMapping[0] = UiccSlotMapping{0, 0, 0} and slotMapping[1] = UiccSlotMapping{1, 1, 1} 4284 * 4285 * or the other way around, the second logical slot(index 1) can be mapped to physical slot 1 4286 * and the first logical slot can be mapped to either port from physical slot 2. 4287 * 4288 * slotMapping[1] = UiccSlotMapping{0, 0, 0} and slotMapping[0] = UiccSlotMapping{0, 1, 1} or 4289 * slotMapping[1] = UiccSlotMapping{0, 0, 0} and slotMapping[0] = UiccSlotMapping{1, 1, 1} 4290 * 4291 * another possible mapping is each logical slot maps to each port of physical slot 2 and there 4292 * is no active logical modem mapped to physical slot 1. 4293 * 4294 * slotMapping[0] = UiccSlotMapping{0, 1, 0} and slotMapping[1] = UiccSlotMapping{1, 1, 1} or 4295 * slotMapping[0] = UiccSlotMapping{1, 1, 0} and slotMapping[1] = UiccSlotMapping{0, 1, 1} 4296 * 4297 * @param slotMapping Logical to physical slot and port mapping. 4298 * @throws IllegalStateException if telephony service is null or slot mapping was sent when the 4299 * radio in middle of a silent restart or other invalid states to handle the command 4300 * @throws IllegalArgumentException if the caller passes in an invalid collection of 4301 * UiccSlotMapping like duplicate data, etc 4302 * 4303 * @hide 4304 */ 4305 @SystemApi 4306 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 4307 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) setSimSlotMapping(@onNull Collection<UiccSlotMapping> slotMapping)4308 public void setSimSlotMapping(@NonNull Collection<UiccSlotMapping> slotMapping) { 4309 try { 4310 ITelephony telephony = getITelephony(); 4311 if (telephony != null) { 4312 if (isSlotMappingValid(slotMapping)) { 4313 boolean result = telephony.setSimSlotMapping(new ArrayList(slotMapping)); 4314 if (!result) { 4315 throw new IllegalStateException("setSimSlotMapping has failed"); 4316 } 4317 } else { 4318 throw new IllegalArgumentException("Duplicate UiccSlotMapping data found"); 4319 } 4320 } else { 4321 throw new IllegalStateException("telephony service is null."); 4322 } 4323 } catch (RemoteException e) { 4324 throw e.rethrowAsRuntimeException(); 4325 } 4326 } 4327 4328 /** 4329 * Get the mapping from logical slots to physical slots. The key of the map is the logical slot 4330 * id and the value is the physical slots id mapped to this logical slot id. 4331 * 4332 * @return a map indicates the mapping from logical slots to physical slots. The size of the map 4333 * should be {@link #getPhoneCount()} if success, otherwise return an empty map. 4334 * 4335 * @hide 4336 * @deprecated use {@link #getSimSlotMapping()} instead. 4337 */ 4338 @SystemApi 4339 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 4340 @NonNull 4341 @Deprecated getLogicalToPhysicalSlotMapping()4342 public Map<Integer, Integer> getLogicalToPhysicalSlotMapping() { 4343 Map<Integer, Integer> slotMapping = new HashMap<>(); 4344 try { 4345 ITelephony telephony = getITelephony(); 4346 if (telephony != null) { 4347 List<UiccSlotMapping> simSlotsMapping = telephony.getSlotsMapping( 4348 mContext.getOpPackageName()); 4349 for (UiccSlotMapping slotMap : simSlotsMapping) { 4350 slotMapping.put(slotMap.getLogicalSlotIndex(), slotMap.getPhysicalSlotIndex()); 4351 } 4352 } 4353 } catch (RemoteException e) { 4354 Log.e(TAG, "getSlotsMapping RemoteException", e); 4355 } 4356 return slotMapping; 4357 } 4358 4359 /** 4360 * Get the mapping from logical slots to physical sim slots and port indexes. Initially the 4361 * logical slot index was mapped to physical slot index, but with support for multi-enabled 4362 * profile(MEP){@link PackageManager#FEATURE_TELEPHONY_EUICC_MEP},logical slot is now mapped to 4363 * port index. 4364 * 4365 * @return a collection of {@link UiccSlotMapping} which indicates the mapping from logical 4366 * slots to ports and physical slots. 4367 * @hide 4368 */ 4369 @SystemApi 4370 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 4371 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) 4372 @NonNull getSimSlotMapping()4373 public Collection<UiccSlotMapping> getSimSlotMapping() { 4374 List<UiccSlotMapping> slotMap; 4375 try { 4376 ITelephony telephony = getITelephony(); 4377 if (telephony != null) { 4378 slotMap = telephony.getSlotsMapping(mContext.getOpPackageName()); 4379 } else { 4380 throw new IllegalStateException("telephony service is null."); 4381 } 4382 } catch (RemoteException e) { 4383 throw e.rethrowAsRuntimeException(); 4384 } 4385 return slotMap; 4386 } 4387 // 4388 // 4389 // Subscriber Info 4390 // 4391 // 4392 4393 /** 4394 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone. 4395 * Return null if it is unavailable. 4396 * 4397 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 4398 * restrictions, and apps are recommended to use resettable identifiers (see <a 4399 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 4400 * method can be invoked if one of the following requirements is met: 4401 * <ul> 4402 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 4403 * is a privileged permission that can only be granted to apps preloaded on the device. 4404 * <li>If the calling app is the device owner of a fully-managed device, a profile 4405 * owner of an organization-owned device, or their delegates (see {@link 4406 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 4407 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4408 * <li>If the calling app is the default SMS role holder (see {@link 4409 * RoleManager#isRoleHeld(String)}). 4410 * <li>If the calling app has been granted the 4411 * {@link Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} permission. 4412 * </ul> 4413 * 4414 * <p>If the calling app does not meet one of these requirements then this method will behave 4415 * as follows: 4416 * 4417 * <ul> 4418 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 4419 * READ_PHONE_STATE permission then null is returned.</li> 4420 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 4421 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 4422 * higher, then a SecurityException is thrown.</li> 4423 * </ul> 4424 */ 4425 @SuppressAutoDoc // No support for device / profile owner or carrier privileges (b/72967236). 4426 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 4427 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSubscriberId()4428 public String getSubscriberId() { 4429 return getSubscriberId(getSubId()); 4430 } 4431 4432 /** 4433 * Returns the unique subscriber ID, for example, the IMSI for a GSM phone 4434 * for a subscription. 4435 * Return null if it is unavailable. 4436 * 4437 * See {@link #getSubscriberId()} for details on the required permissions and behavior 4438 * when the caller does not hold sufficient permissions. 4439 * 4440 * @param subId whose subscriber id is returned 4441 * @hide 4442 */ 4443 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 4444 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getSubscriberId(int subId)4445 public String getSubscriberId(int subId) { 4446 try { 4447 IPhoneSubInfo info = getSubscriberInfoService(); 4448 if (info == null) 4449 return null; 4450 return info.getSubscriberIdForSubscriber(subId, mContext.getOpPackageName(), 4451 mContext.getAttributionTag()); 4452 } catch (RemoteException ex) { 4453 return null; 4454 } catch (NullPointerException ex) { 4455 // This could happen before phone restarts due to crashing 4456 return null; 4457 } 4458 } 4459 4460 /** 4461 * Returns carrier specific information that will be used to encrypt the IMSI and IMPI, 4462 * including the public key and the key identifier; or {@code null} if not available. 4463 * <p> 4464 * For a multi-sim device, the dafault data sim is used if not specified. 4465 * <p> 4466 * Requires Permission: READ_PRIVILEGED_PHONE_STATE. 4467 * 4468 * @param keyType whether the key is being used for EPDG or WLAN. Valid values are 4469 * {@link #KEY_TYPE_EPDG} or {@link #KEY_TYPE_WLAN}. 4470 * @return ImsiEncryptionInfo Carrier specific information that will be used to encrypt the 4471 * IMSI and IMPI. This includes the public key and the key identifier. This information 4472 * will be stored in the device keystore. {@code null} will be returned when no key is 4473 * found, and the carrier does not require a key. 4474 * @throws IllegalArgumentException when an invalid key is found or when key is required but 4475 * not found. 4476 * @hide 4477 */ 4478 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 4479 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) 4480 @SystemApi 4481 @Nullable getCarrierInfoForImsiEncryption(@eyType int keyType)4482 public ImsiEncryptionInfo getCarrierInfoForImsiEncryption(@KeyType int keyType) { 4483 try { 4484 IPhoneSubInfo info = getSubscriberInfoService(); 4485 if (info == null) { 4486 Rlog.e(TAG,"IMSI error: Subscriber Info is null"); 4487 return null; 4488 } 4489 int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId()); 4490 if (keyType != KEY_TYPE_EPDG && keyType != KEY_TYPE_WLAN) { 4491 throw new IllegalArgumentException("IMSI error: Invalid key type"); 4492 } 4493 ImsiEncryptionInfo imsiEncryptionInfo = info.getCarrierInfoForImsiEncryption( 4494 subId, keyType, mContext.getOpPackageName()); 4495 if (imsiEncryptionInfo == null && isImsiEncryptionRequired(subId, keyType)) { 4496 Rlog.e(TAG, "IMSI error: key is required but not found"); 4497 throw new IllegalArgumentException("IMSI error: key is required but not found"); 4498 } 4499 return imsiEncryptionInfo; 4500 } catch (RemoteException ex) { 4501 Rlog.e(TAG, "getCarrierInfoForImsiEncryption RemoteException" + ex); 4502 } catch (NullPointerException ex) { 4503 // This could happen before phone restarts due to crashing 4504 Rlog.e(TAG, "getCarrierInfoForImsiEncryption NullPointerException" + ex); 4505 } 4506 return null; 4507 } 4508 4509 /** 4510 * Resets the carrier keys used to encrypt the IMSI and IMPI. 4511 * <p> 4512 * This involves 2 steps: 4513 * 1. Delete the keys from the database. 4514 * 2. Send an intent to download new Certificates. 4515 * <p> 4516 * For a multi-sim device, the dafault data sim is used if not specified. 4517 * <p> 4518 * Requires Permission: MODIFY_PHONE_STATE. 4519 * 4520 * @see #getCarrierInfoForImsiEncryption 4521 * @hide 4522 */ 4523 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 4524 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) 4525 @SystemApi resetCarrierKeysForImsiEncryption()4526 public void resetCarrierKeysForImsiEncryption() { 4527 try { 4528 IPhoneSubInfo info = getSubscriberInfoService(); 4529 if (info == null) { 4530 throw new RuntimeException("IMSI error: Subscriber Info is null"); 4531 } 4532 int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId()); 4533 info.resetCarrierKeysForImsiEncryption(subId, mContext.getOpPackageName()); 4534 } catch (RemoteException ex) { 4535 Rlog.e(TAG, "Telephony#getCarrierInfoForImsiEncryption RemoteException" + ex); 4536 } 4537 } 4538 4539 /** 4540 * @param keyAvailability bitmask that defines the availabilty of keys for a type. 4541 * @param keyType the key type which is being checked. (WLAN, EPDG) 4542 * @return true if the digit at position keyType is 1, else false. 4543 * @hide 4544 */ isKeyEnabled(int keyAvailability, @KeyType int keyType)4545 private static boolean isKeyEnabled(int keyAvailability, @KeyType int keyType) { 4546 int returnValue = (keyAvailability >> (keyType - 1)) & 1; 4547 return (returnValue == 1) ? true : false; 4548 } 4549 4550 /** 4551 * If Carrier requires Imsi to be encrypted. 4552 * @hide 4553 */ isImsiEncryptionRequired(int subId, @KeyType int keyType)4554 private boolean isImsiEncryptionRequired(int subId, @KeyType int keyType) { 4555 CarrierConfigManager configManager = 4556 (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE); 4557 if (configManager == null) { 4558 return false; 4559 } 4560 PersistableBundle pb = configManager.getConfigForSubId(subId); 4561 if (pb == null) { 4562 return false; 4563 } 4564 int keyAvailability = pb.getInt(CarrierConfigManager.IMSI_KEY_AVAILABILITY_INT); 4565 return isKeyEnabled(keyAvailability, keyType); 4566 } 4567 4568 /** 4569 * Sets the Carrier specific information that will be used to encrypt the IMSI and IMPI. 4570 * This includes the public key and the key identifier. This information will be stored in the 4571 * device keystore. 4572 * <p> 4573 * Requires Permission: 4574 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 4575 * @param imsiEncryptionInfo which includes the Key Type, the Public Key 4576 * (java.security.PublicKey) and the Key Identifier.and the Key Identifier. 4577 * The keyIdentifier Attribute value pair that helps a server locate 4578 * the private key to decrypt the permanent identity. This field is 4579 * optional and if it is present then it’s always separated from encrypted 4580 * permanent identity with “,”. Key identifier AVP is presented in ASCII string 4581 * with “name=value” format. 4582 * @hide 4583 */ setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo)4584 public void setCarrierInfoForImsiEncryption(ImsiEncryptionInfo imsiEncryptionInfo) { 4585 try { 4586 IPhoneSubInfo info = getSubscriberInfoService(); 4587 if (info == null) return; 4588 info.setCarrierInfoForImsiEncryption(mSubId, mContext.getOpPackageName(), 4589 imsiEncryptionInfo); 4590 } catch (NullPointerException ex) { 4591 // This could happen before phone restarts due to crashing 4592 return; 4593 } catch (RemoteException ex) { 4594 Rlog.e(TAG, "setCarrierInfoForImsiEncryption RemoteException", ex); 4595 return; 4596 } 4597 } 4598 4599 /** 4600 * Exception that may be supplied to the callback in {@link #uploadCallComposerPicture} if 4601 * something goes awry. 4602 */ 4603 public static class CallComposerException extends Exception { 4604 /** 4605 * Used internally only, signals success of the upload to the carrier. 4606 * @hide 4607 */ 4608 public static final int SUCCESS = -1; 4609 /** 4610 * Indicates that an unknown error was encountered when uploading the call composer picture. 4611 * 4612 * Clients that encounter this error should retry the upload. 4613 */ 4614 public static final int ERROR_UNKNOWN = 0; 4615 4616 /** 4617 * Indicates that the phone process died or otherwise became unavailable while uploading the 4618 * call composer picture. 4619 * 4620 * Clients that encounter this error should retry the upload. 4621 */ 4622 public static final int ERROR_REMOTE_END_CLOSED = 1; 4623 4624 /** 4625 * Indicates that the file or stream supplied exceeds the size limit defined in 4626 * {@link #getMaximumCallComposerPictureSize()}. 4627 * 4628 * Clients that encounter this error should retry the upload after reducing the size of the 4629 * picture. 4630 */ 4631 public static final int ERROR_FILE_TOO_LARGE = 2; 4632 4633 /** 4634 * Indicates that the device failed to authenticate with the carrier when uploading the 4635 * picture. 4636 * 4637 * Clients that encounter this error should not retry the upload unless a reboot or radio 4638 * reset has been performed in the interim. 4639 */ 4640 public static final int ERROR_AUTHENTICATION_FAILED = 3; 4641 4642 /** 4643 * Indicates that the {@link InputStream} passed to {@link #uploadCallComposerPicture} 4644 * was closed. 4645 * 4646 * The caller should retry if this error is encountered, and be sure to not close the stream 4647 * before the callback is called this time. 4648 */ 4649 public static final int ERROR_INPUT_CLOSED = 4; 4650 4651 /** 4652 * Indicates that an {@link IOException} was encountered while reading the picture. 4653 * 4654 * The offending {@link IOException} will be available via {@link #getIOException()}. 4655 * Clients should use the contents of the exception to determine whether a retry is 4656 * warranted. 4657 */ 4658 public static final int ERROR_IO_EXCEPTION = 5; 4659 4660 /** 4661 * Indicates that the device is currently not connected to a network that's capable of 4662 * reaching a carrier's RCS servers. 4663 * 4664 * Clients should prompt the user to remedy the issue by moving to an area with better 4665 * signal, by connecting to a different network, or to retry at another time. 4666 */ 4667 public static final int ERROR_NETWORK_UNAVAILABLE = 6; 4668 4669 /** @hide */ 4670 @IntDef(prefix = {"ERROR_"}, value = { 4671 ERROR_UNKNOWN, 4672 ERROR_REMOTE_END_CLOSED, 4673 ERROR_FILE_TOO_LARGE, 4674 ERROR_AUTHENTICATION_FAILED, 4675 ERROR_INPUT_CLOSED, 4676 ERROR_IO_EXCEPTION, 4677 ERROR_NETWORK_UNAVAILABLE, 4678 }) 4679 4680 @Retention(RetentionPolicy.SOURCE) 4681 public @interface CallComposerError {} 4682 4683 private final int mErrorCode; 4684 private final IOException mIOException; 4685 CallComposerException(@allComposerError int errorCode, @Nullable IOException ioException)4686 public CallComposerException(@CallComposerError int errorCode, 4687 @Nullable IOException ioException) { 4688 mErrorCode = errorCode; 4689 mIOException = ioException; 4690 } 4691 4692 /** 4693 * Fetches the error code associated with this exception. 4694 * @return An error code. 4695 */ getErrorCode()4696 public @CallComposerError int getErrorCode() { 4697 return mErrorCode; 4698 } 4699 4700 /** 4701 * Fetches the {@link IOException} that caused the error. 4702 */ 4703 // Follows the naming of IOException 4704 @SuppressLint("AcronymName") getIOException()4705 public @Nullable IOException getIOException() { 4706 return mIOException; 4707 } 4708 } 4709 4710 /** @hide */ 4711 public static final String KEY_CALL_COMPOSER_PICTURE_HANDLE = "call_composer_picture_handle"; 4712 4713 /** 4714 * Uploads a picture to the carrier network for use with call composer. 4715 * 4716 * @see #uploadCallComposerPicture(InputStream, String, Executor, OutcomeReceiver) 4717 * @param pictureToUpload Path to a local file containing the picture to upload. 4718 * @param contentType The MIME type of the picture you're uploading (e.g. image/jpeg) 4719 * @param executor The {@link Executor} on which the {@code pictureToUpload} file will be read 4720 * from disk, as well as on which {@code callback} will be called. 4721 * @param callback A callback called when the upload operation terminates, either in success 4722 * or in error. 4723 */ 4724 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) uploadCallComposerPicture(@onNull Path pictureToUpload, @NonNull String contentType, @CallbackExecutor @NonNull Executor executor, @NonNull OutcomeReceiver<ParcelUuid, CallComposerException> callback)4725 public void uploadCallComposerPicture(@NonNull Path pictureToUpload, 4726 @NonNull String contentType, 4727 @CallbackExecutor @NonNull Executor executor, 4728 @NonNull OutcomeReceiver<ParcelUuid, CallComposerException> callback) { 4729 Objects.requireNonNull(pictureToUpload); 4730 Objects.requireNonNull(executor); 4731 Objects.requireNonNull(callback); 4732 4733 // Do the role check now so that we can quit early if needed -- there's an additional 4734 // permission check on the other side of the binder call as well. 4735 RoleManager rm = mContext.getSystemService(RoleManager.class); 4736 if (!rm.isRoleHeld(RoleManager.ROLE_DIALER)) { 4737 throw new SecurityException("You must hold RoleManager.ROLE_DIALER to do this"); 4738 } 4739 4740 executor.execute(() -> { 4741 try { 4742 if (Looper.getMainLooper().isCurrentThread()) { 4743 Log.w(TAG, "Uploading call composer picture on main thread!" 4744 + " hic sunt dracones!"); 4745 } 4746 long size = Files.size(pictureToUpload); 4747 if (size > getMaximumCallComposerPictureSize()) { 4748 callback.onError(new CallComposerException( 4749 CallComposerException.ERROR_FILE_TOO_LARGE, null)); 4750 return; 4751 } 4752 InputStream fileStream = Files.newInputStream(pictureToUpload); 4753 try { 4754 uploadCallComposerPicture(fileStream, contentType, executor, 4755 new OutcomeReceiver<ParcelUuid, CallComposerException>() { 4756 @Override 4757 public void onResult(ParcelUuid result) { 4758 try { 4759 fileStream.close(); 4760 } catch (IOException e) { 4761 // ignore 4762 Log.e(TAG, "Error closing file input stream when" 4763 + " uploading call composer pic"); 4764 } 4765 callback.onResult(result); 4766 } 4767 4768 @Override 4769 public void onError(CallComposerException error) { 4770 try { 4771 fileStream.close(); 4772 } catch (IOException e) { 4773 // ignore 4774 Log.e(TAG, "Error closing file input stream when" 4775 + " uploading call composer pic"); 4776 } 4777 callback.onError(error); 4778 } 4779 }); 4780 } catch (Exception e) { 4781 Log.e(TAG, "Got exception calling into stream-version of" 4782 + " uploadCallComposerPicture: " + e); 4783 try { 4784 fileStream.close(); 4785 } catch (IOException e1) { 4786 // ignore 4787 Log.e(TAG, "Error closing file input stream when uploading" 4788 + " call composer pic"); 4789 } 4790 } 4791 } catch (IOException e) { 4792 Log.e(TAG, "IOException when uploading call composer pic:" + e); 4793 callback.onError( 4794 new CallComposerException(CallComposerException.ERROR_IO_EXCEPTION, e)); 4795 } 4796 }); 4797 4798 } 4799 4800 /** 4801 * Uploads a picture to the carrier network for use with call composer. 4802 * 4803 * This method allows a dialer app to upload a picture to the carrier network that can then 4804 * later be attached to an outgoing call. In order to attach the picture to a call, use the 4805 * {@link ParcelUuid} returned from {@code callback} upon successful upload as the value to 4806 * {@link TelecomManager#EXTRA_OUTGOING_PICTURE}. 4807 * 4808 * This functionality is only available to the app filling the {@link RoleManager#ROLE_DIALER} 4809 * role on the device. 4810 * 4811 * This functionality is only available when 4812 * {@link CarrierConfigManager#KEY_SUPPORTS_CALL_COMPOSER_BOOL} is set to {@code true} in the 4813 * bundle returned from {@link #getCarrierConfig()}. 4814 * 4815 * @param pictureToUpload An {@link InputStream} that supplies the bytes representing the 4816 * picture to upload. The client bears responsibility for closing this 4817 * stream after {@code callback} is called with success or failure. 4818 * 4819 * Additionally, if the stream supplies more bytes than the return value 4820 * of {@link #getMaximumCallComposerPictureSize()}, the upload will be 4821 * aborted and the callback will be called with an exception containing 4822 * {@link CallComposerException#ERROR_FILE_TOO_LARGE}. 4823 * @param contentType The MIME type of the picture you're uploading (e.g. image/jpeg). The list 4824 * of acceptable content types can be found at 3GPP TS 26.141 sections 4825 * 4.2 and 4.3. 4826 * @param executor The {@link Executor} on which the {@code pictureToUpload} stream will be 4827 * read, as well as on which the callback will be called. 4828 * @param callback A callback called when the upload operation terminates, either in success 4829 * or in error. 4830 */ 4831 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) uploadCallComposerPicture(@onNull InputStream pictureToUpload, @NonNull String contentType, @CallbackExecutor @NonNull Executor executor, @NonNull OutcomeReceiver<ParcelUuid, CallComposerException> callback)4832 public void uploadCallComposerPicture(@NonNull InputStream pictureToUpload, 4833 @NonNull String contentType, 4834 @CallbackExecutor @NonNull Executor executor, 4835 @NonNull OutcomeReceiver<ParcelUuid, CallComposerException> callback) { 4836 Objects.requireNonNull(pictureToUpload); 4837 Objects.requireNonNull(executor); 4838 Objects.requireNonNull(callback); 4839 4840 ITelephony telephony = getITelephony(); 4841 if (telephony == null) { 4842 throw new IllegalStateException("Telephony service not available."); 4843 } 4844 4845 ParcelFileDescriptor writeFd; 4846 ParcelFileDescriptor readFd; 4847 try { 4848 ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createReliablePipe(); 4849 writeFd = pipe[1]; 4850 readFd = pipe[0]; 4851 } catch (IOException e) { 4852 executor.execute(() -> callback.onError( 4853 new CallComposerException(CallComposerException.ERROR_IO_EXCEPTION, e))); 4854 return; 4855 } 4856 4857 OutputStream output = new ParcelFileDescriptor.AutoCloseOutputStream(writeFd); 4858 4859 try { 4860 telephony.uploadCallComposerPicture(getSubId(), mContext.getOpPackageName(), 4861 contentType, readFd, new ResultReceiver(null) { 4862 @Override 4863 protected void onReceiveResult(int resultCode, Bundle result) { 4864 if (resultCode != CallComposerException.SUCCESS) { 4865 executor.execute(() -> callback.onError( 4866 new CallComposerException(resultCode, null))); 4867 return; 4868 } 4869 ParcelUuid resultUuid = 4870 result.getParcelable(KEY_CALL_COMPOSER_PICTURE_HANDLE); 4871 if (resultUuid == null) { 4872 Log.e(TAG, "Got null uuid without an error" 4873 + " while uploading call composer pic"); 4874 executor.execute(() -> callback.onError( 4875 new CallComposerException( 4876 CallComposerException.ERROR_UNKNOWN, null))); 4877 return; 4878 } 4879 executor.execute(() -> callback.onResult(resultUuid)); 4880 } 4881 }); 4882 } catch (RemoteException e) { 4883 Log.e(TAG, "Remote exception uploading call composer pic:" + e); 4884 e.rethrowAsRuntimeException(); 4885 } 4886 4887 executor.execute(() -> { 4888 if (Looper.getMainLooper().isCurrentThread()) { 4889 Log.w(TAG, "Uploading call composer picture on main thread!" 4890 + " hic sunt dracones!"); 4891 } 4892 4893 int totalBytesRead = 0; 4894 byte[] buffer = new byte[16 * 1024]; 4895 try { 4896 while (true) { 4897 int numRead; 4898 try { 4899 numRead = pictureToUpload.read(buffer); 4900 } catch (IOException e) { 4901 Log.e(TAG, "IOException reading from input while uploading pic: " + e); 4902 // Most likely, this was because the stream was closed. We have no way to 4903 // tell though. 4904 callback.onError(new CallComposerException( 4905 CallComposerException.ERROR_INPUT_CLOSED, e)); 4906 try { 4907 writeFd.closeWithError("input closed"); 4908 } catch (IOException e1) { 4909 // log and ignore 4910 Log.e(TAG, "Error closing fd pipe: " + e1); 4911 } 4912 break; 4913 } 4914 4915 if (numRead < 0) { 4916 break; 4917 } 4918 4919 totalBytesRead += numRead; 4920 if (totalBytesRead > getMaximumCallComposerPictureSize()) { 4921 Log.e(TAG, "Read too many bytes from call composer pic stream: " 4922 + totalBytesRead); 4923 try { 4924 callback.onError(new CallComposerException( 4925 CallComposerException.ERROR_FILE_TOO_LARGE, null)); 4926 writeFd.closeWithError("too large"); 4927 } catch (IOException e1) { 4928 // log and ignore 4929 Log.e(TAG, "Error closing fd pipe: " + e1); 4930 } 4931 break; 4932 } 4933 4934 try { 4935 output.write(buffer, 0, numRead); 4936 } catch (IOException e) { 4937 callback.onError(new CallComposerException( 4938 CallComposerException.ERROR_REMOTE_END_CLOSED, e)); 4939 try { 4940 writeFd.closeWithError("remote end closed"); 4941 } catch (IOException e1) { 4942 // log and ignore 4943 Log.e(TAG, "Error closing fd pipe: " + e1); 4944 } 4945 break; 4946 } 4947 } 4948 } finally { 4949 try { 4950 output.close(); 4951 } catch (IOException e) { 4952 // Ignore -- we might've already closed it. 4953 } 4954 } 4955 }); 4956 } 4957 4958 /** 4959 * Returns the Group Identifier Level1 for a GSM phone. 4960 * Return null if it is unavailable. 4961 * 4962 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 4963 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 4964 */ 4965 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 4966 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 4967 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getGroupIdLevel1()4968 public String getGroupIdLevel1() { 4969 try { 4970 IPhoneSubInfo info = getSubscriberInfoService(); 4971 if (info == null) 4972 return null; 4973 return info.getGroupIdLevel1ForSubscriber(getSubId(), mContext.getOpPackageName(), 4974 mContext.getAttributionTag()); 4975 } catch (RemoteException ex) { 4976 return null; 4977 } catch (NullPointerException ex) { 4978 // This could happen before phone restarts due to crashing 4979 return null; 4980 } 4981 } 4982 4983 /** 4984 * Returns the Group Identifier Level1 for a GSM phone for a particular subscription. 4985 * Return null if it is unavailable. 4986 * 4987 * @param subId whose subscriber id is returned 4988 * @hide 4989 */ 4990 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 4991 @UnsupportedAppUsage getGroupIdLevel1(int subId)4992 public String getGroupIdLevel1(int subId) { 4993 try { 4994 IPhoneSubInfo info = getSubscriberInfoService(); 4995 if (info == null) 4996 return null; 4997 return info.getGroupIdLevel1ForSubscriber(subId, mContext.getOpPackageName(), 4998 mContext.getAttributionTag()); 4999 } catch (RemoteException ex) { 5000 return null; 5001 } catch (NullPointerException ex) { 5002 // This could happen before phone restarts due to crashing 5003 return null; 5004 } 5005 } 5006 5007 /** 5008 * Returns the phone number string for line 1, for example, the MSISDN 5009 * for a GSM phone for a particular subscription. Return null if it is unavailable. 5010 * <p> 5011 * The default SMS app can also use this. 5012 * 5013 * <p>Requires Permission: 5014 * {@link android.Manifest.permission#READ_SMS READ_SMS}, 5015 * {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS}, 5016 * that the caller is the default SMS app, 5017 * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}) 5018 * for any API level. 5019 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 5020 * for apps targeting SDK API level 29 and below. 5021 * 5022 * @deprecated use {@link SubscriptionManager#getPhoneNumber(int)} instead. 5023 */ 5024 @Deprecated 5025 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges or default SMS app 5026 @RequiresPermission(anyOf = { 5027 android.Manifest.permission.READ_PHONE_STATE, 5028 android.Manifest.permission.READ_SMS, 5029 android.Manifest.permission.READ_PHONE_NUMBERS 5030 }) getLine1Number()5031 public String getLine1Number() { 5032 return getLine1Number(getSubId()); 5033 } 5034 5035 /** 5036 * Returns the phone number string for line 1, for example, the MSISDN 5037 * for a GSM phone for a particular subscription. Return null if it is unavailable. 5038 * <p> 5039 * The default SMS app can also use this. 5040 * 5041 * <p>Requires Permission: 5042 * {@link android.Manifest.permission#READ_SMS READ_SMS}, 5043 * {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS}, 5044 * that the caller is the default SMS app, 5045 * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}) 5046 * for any API level. 5047 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 5048 * for apps targeting SDK API level 29 and below. 5049 * 5050 * @param subId whose phone number for line 1 is returned 5051 * @hide 5052 */ 5053 @RequiresPermission(anyOf = { 5054 android.Manifest.permission.READ_PHONE_STATE, 5055 android.Manifest.permission.READ_SMS, 5056 android.Manifest.permission.READ_PHONE_NUMBERS 5057 }) 5058 @UnsupportedAppUsage getLine1Number(int subId)5059 public String getLine1Number(int subId) { 5060 String number = null; 5061 try { 5062 ITelephony telephony = getITelephony(); 5063 if (telephony != null) 5064 number = telephony.getLine1NumberForDisplay(subId, mContext.getOpPackageName(), 5065 mContext.getAttributionTag()); 5066 } catch (RemoteException ex) { 5067 } catch (NullPointerException ex) { 5068 } 5069 if (number != null) { 5070 return number; 5071 } 5072 try { 5073 IPhoneSubInfo info = getSubscriberInfoService(); 5074 if (info == null) 5075 return null; 5076 return info.getLine1NumberForSubscriber(subId, mContext.getOpPackageName(), 5077 mContext.getAttributionTag()); 5078 } catch (RemoteException ex) { 5079 return null; 5080 } catch (NullPointerException ex) { 5081 // This could happen before phone restarts due to crashing 5082 return null; 5083 } 5084 } 5085 5086 /** 5087 * Set the line 1 phone number string and its alphatag for the current ICCID 5088 * for display purpose only, for example, displayed in Phone Status. It won't 5089 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 5090 * value. 5091 * 5092 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5093 * 5094 * @param alphaTag alpha-tagging of the dailing nubmer 5095 * @param number The dialing number 5096 * @return true if the operation was executed correctly. 5097 * @deprecated use {@link SubscriptionManager#setCarrierPhoneNumber(int, String)} instead. 5098 */ 5099 @Deprecated setLine1NumberForDisplay(String alphaTag, String number)5100 public boolean setLine1NumberForDisplay(String alphaTag, String number) { 5101 return setLine1NumberForDisplay(getSubId(), alphaTag, number); 5102 } 5103 5104 /** 5105 * Set the line 1 phone number string and its alphatag for the current ICCID 5106 * for display purpose only, for example, displayed in Phone Status. It won't 5107 * change the actual MSISDN/MDN. To unset alphatag or number, pass in a null 5108 * value. 5109 * 5110 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5111 * 5112 * @param subId the subscriber that the alphatag and dialing number belongs to. 5113 * @param alphaTag alpha-tagging of the dailing nubmer 5114 * @param number The dialing number 5115 * @return true if the operation was executed correctly. 5116 * @hide 5117 */ setLine1NumberForDisplay(int subId, String alphaTag, String number)5118 public boolean setLine1NumberForDisplay(int subId, String alphaTag, String number) { 5119 try { 5120 // This API is deprecated; call the new API to allow smooth migartion. 5121 // The new API doesn't accept null so convert null to empty string. 5122 mSubscriptionManager.setCarrierPhoneNumber(subId, (number == null ? "" : number)); 5123 5124 ITelephony telephony = getITelephony(); 5125 if (telephony != null) 5126 return telephony.setLine1NumberForDisplayForSubscriber(subId, alphaTag, number); 5127 } catch (RemoteException ex) { 5128 } catch (NullPointerException ex) { 5129 } 5130 return false; 5131 } 5132 5133 /** 5134 * Returns the alphabetic identifier associated with the line 1 number. 5135 * Return null if it is unavailable. 5136 * @hide 5137 * nobody seems to call this. 5138 */ 5139 @UnsupportedAppUsage 5140 @TestApi 5141 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getLine1AlphaTag()5142 public String getLine1AlphaTag() { 5143 return getLine1AlphaTag(getSubId()); 5144 } 5145 5146 /** 5147 * Returns the alphabetic identifier associated with the line 1 number 5148 * for a subscription. 5149 * Return null if it is unavailable. 5150 * @param subId whose alphabetic identifier associated with line 1 is returned 5151 * nobody seems to call this. 5152 * @hide 5153 */ 5154 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5155 @UnsupportedAppUsage getLine1AlphaTag(int subId)5156 public String getLine1AlphaTag(int subId) { 5157 String alphaTag = null; 5158 try { 5159 ITelephony telephony = getITelephony(); 5160 if (telephony != null) 5161 alphaTag = telephony.getLine1AlphaTagForDisplay(subId, 5162 getOpPackageName(), getAttributionTag()); 5163 } catch (RemoteException ex) { 5164 } catch (NullPointerException ex) { 5165 } 5166 if (alphaTag != null) { 5167 return alphaTag; 5168 } 5169 try { 5170 IPhoneSubInfo info = getSubscriberInfoService(); 5171 if (info == null) 5172 return null; 5173 return info.getLine1AlphaTagForSubscriber(subId, getOpPackageName(), 5174 getAttributionTag()); 5175 } catch (RemoteException ex) { 5176 return null; 5177 } catch (NullPointerException ex) { 5178 // This could happen before phone restarts due to crashing 5179 return null; 5180 } 5181 } 5182 5183 /** 5184 * Return the set of subscriber IDs that should be considered "merged together" for data usage 5185 * purposes. This is commonly {@code null} to indicate no merging is required. Any returned 5186 * subscribers are sorted in a deterministic order. 5187 * <p> 5188 * The returned set of subscriber IDs will include the subscriber ID corresponding to this 5189 * TelephonyManager's subId. 5190 * 5191 * This is deprecated and {@link #getMergedImsisFromGroup()} should be used for data 5192 * usage merging purpose. 5193 * TODO: remove this API. 5194 * 5195 * @hide 5196 */ 5197 @UnsupportedAppUsage 5198 @Deprecated getMergedSubscriberIds()5199 public @Nullable String[] getMergedSubscriberIds() { 5200 try { 5201 ITelephony telephony = getITelephony(); 5202 if (telephony != null) 5203 return telephony.getMergedSubscriberIds(getSubId(), getOpPackageName(), 5204 getAttributionTag()); 5205 } catch (RemoteException ex) { 5206 } catch (NullPointerException ex) { 5207 } 5208 return null; 5209 } 5210 5211 /** 5212 * Return the set of IMSIs that should be considered "merged together" for data usage 5213 * purposes. This API merges IMSIs based on subscription grouping: IMSI of those in the same 5214 * group will all be returned. 5215 * Return the current IMSI if there is no subscription group, see 5216 * {@link SubscriptionManager#createSubscriptionGroup(List)} for the definition of a group, 5217 * otherwise return an empty array if there is a failure. 5218 * 5219 * @hide 5220 */ 5221 @SystemApi 5222 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 5223 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getMergedImsisFromGroup()5224 public @NonNull String[] getMergedImsisFromGroup() { 5225 try { 5226 ITelephony telephony = getITelephony(); 5227 if (telephony != null) { 5228 return telephony.getMergedImsisFromGroup(getSubId(), getOpPackageName()); 5229 } 5230 } catch (RemoteException ex) { 5231 } 5232 return new String[0]; 5233 } 5234 5235 /** 5236 * Returns the MSISDN string for a GSM phone. Return null if it is unavailable. 5237 * 5238 * <p>Requires Permission: 5239 * {@link android.Manifest.permission#READ_SMS READ_SMS}, 5240 * {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS}, 5241 * that the caller is the default SMS app, 5242 * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}) 5243 * for any API level. 5244 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 5245 * for apps targeting SDK API level 29 and below. 5246 * 5247 * @hide 5248 */ 5249 @RequiresPermission(anyOf = { 5250 android.Manifest.permission.READ_PHONE_STATE, 5251 android.Manifest.permission.READ_SMS, 5252 android.Manifest.permission.READ_PHONE_NUMBERS 5253 }) 5254 @UnsupportedAppUsage getMsisdn()5255 public String getMsisdn() { 5256 return getMsisdn(getSubId()); 5257 } 5258 5259 /** 5260 * Returns the MSISDN string for a GSM phone. Return null if it is unavailable. 5261 * 5262 * @param subId for which msisdn is returned 5263 * 5264 * <p>Requires Permission: 5265 * {@link android.Manifest.permission#READ_SMS READ_SMS}, 5266 * {@link android.Manifest.permission#READ_PHONE_NUMBERS READ_PHONE_NUMBERS}, 5267 * that the caller is the default SMS app, 5268 * or that the caller has carrier privileges (see {@link #hasCarrierPrivileges}) 5269 * for any API level. 5270 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 5271 * for apps targeting SDK API level 29 and below. 5272 * 5273 * @hide 5274 */ 5275 @RequiresPermission(anyOf = { 5276 android.Manifest.permission.READ_PHONE_STATE, 5277 android.Manifest.permission.READ_SMS, 5278 android.Manifest.permission.READ_PHONE_NUMBERS 5279 }) 5280 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getMsisdn(int subId)5281 public String getMsisdn(int subId) { 5282 try { 5283 IPhoneSubInfo info = getSubscriberInfoService(); 5284 if (info == null) 5285 return null; 5286 return info.getMsisdnForSubscriber(subId, getOpPackageName(), getAttributionTag()); 5287 } catch (RemoteException ex) { 5288 return null; 5289 } catch (NullPointerException ex) { 5290 // This could happen before phone restarts due to crashing 5291 return null; 5292 } 5293 } 5294 5295 /** 5296 * Returns the voice mail number. Return null if it is unavailable. 5297 * 5298 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 5299 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5300 */ 5301 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 5302 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5303 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) getVoiceMailNumber()5304 public String getVoiceMailNumber() { 5305 return getVoiceMailNumber(getSubId()); 5306 } 5307 5308 /** 5309 * Returns the voice mail number for a subscription. 5310 * Return null if it is unavailable. 5311 * @param subId whose voice mail number is returned 5312 * @hide 5313 */ 5314 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5315 @UnsupportedAppUsage getVoiceMailNumber(int subId)5316 public String getVoiceMailNumber(int subId) { 5317 try { 5318 IPhoneSubInfo info = getSubscriberInfoService(); 5319 if (info == null) 5320 return null; 5321 return info.getVoiceMailNumberForSubscriber(subId, getOpPackageName(), 5322 getAttributionTag()); 5323 } catch (RemoteException ex) { 5324 return null; 5325 } catch (NullPointerException ex) { 5326 // This could happen before phone restarts due to crashing 5327 return null; 5328 } 5329 } 5330 5331 /** 5332 * Sets the voice mail number. 5333 * 5334 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5335 * 5336 * @param alphaTag The alpha tag to display. 5337 * @param number The voicemail number. 5338 */ 5339 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) setVoiceMailNumber(String alphaTag, String number)5340 public boolean setVoiceMailNumber(String alphaTag, String number) { 5341 return setVoiceMailNumber(getSubId(), alphaTag, number); 5342 } 5343 5344 /** 5345 * Sets the voicemail number for the given subscriber. 5346 * 5347 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5348 * 5349 * @param subId The subscription id. 5350 * @param alphaTag The alpha tag to display. 5351 * @param number The voicemail number. 5352 * @hide 5353 */ setVoiceMailNumber(int subId, String alphaTag, String number)5354 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { 5355 try { 5356 ITelephony telephony = getITelephony(); 5357 if (telephony != null) 5358 return telephony.setVoiceMailNumber(subId, alphaTag, number); 5359 } catch (RemoteException ex) { 5360 } catch (NullPointerException ex) { 5361 } 5362 return false; 5363 } 5364 5365 /** 5366 * Enables or disables the visual voicemail client for a phone account. 5367 * 5368 * <p>Requires that the calling app is the default dialer, or has carrier privileges (see 5369 * {@link #hasCarrierPrivileges}), or has permission 5370 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 5371 * 5372 * @param phoneAccountHandle the phone account to change the client state 5373 * @param enabled the new state of the client 5374 * @hide 5375 * @deprecated Visual voicemail no longer in telephony. {@link VisualVoicemailService} should 5376 * be implemented instead. 5377 */ 5378 @SystemApi 5379 @Deprecated 5380 @SuppressLint("RequiresPermission") setVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled)5381 public void setVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled){ 5382 } 5383 5384 /** 5385 * Returns whether the visual voicemail client is enabled. 5386 * 5387 * @param phoneAccountHandle the phone account to check for. 5388 * @return {@code true} when the visual voicemail client is enabled for this client 5389 * @hide 5390 * @deprecated Visual voicemail no longer in telephony. {@link VisualVoicemailService} should 5391 * be implemented instead. 5392 */ 5393 @SystemApi 5394 @Deprecated 5395 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5396 @SuppressLint("RequiresPermission") isVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle)5397 public boolean isVisualVoicemailEnabled(PhoneAccountHandle phoneAccountHandle){ 5398 return false; 5399 } 5400 5401 /** 5402 * Returns an opaque bundle of settings formerly used by the visual voicemail client for the 5403 * subscription ID pinned to the TelephonyManager, or {@code null} if the subscription ID is 5404 * invalid. This method allows the system dialer to migrate settings out of the pre-O visual 5405 * voicemail client in telephony. 5406 * 5407 * <p>Requires the caller to be the system dialer. 5408 * 5409 * @see #KEY_VISUAL_VOICEMAIL_ENABLED_BY_USER_BOOL 5410 * @see #KEY_VOICEMAIL_SCRAMBLED_PIN_STRING 5411 * 5412 * @hide 5413 */ 5414 @SystemApi 5415 @SuppressLint("RequiresPermission") 5416 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) 5417 @Nullable getVisualVoicemailSettings()5418 public Bundle getVisualVoicemailSettings(){ 5419 try { 5420 ITelephony telephony = getITelephony(); 5421 if (telephony != null) { 5422 return telephony 5423 .getVisualVoicemailSettings(mContext.getOpPackageName(), mSubId); 5424 } 5425 } catch (RemoteException ex) { 5426 } catch (NullPointerException ex) { 5427 } 5428 return null; 5429 } 5430 5431 /** 5432 * Returns the package responsible of processing visual voicemail for the subscription ID pinned 5433 * to the TelephonyManager. Returns {@code null} when there is no package responsible for 5434 * processing visual voicemail for the subscription. 5435 * 5436 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 5437 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5438 * 5439 * @see #createForSubscriptionId(int) 5440 * @see #createForPhoneAccountHandle(PhoneAccountHandle) 5441 * @see VisualVoicemailService 5442 */ 5443 @Nullable 5444 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 5445 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5446 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) getVisualVoicemailPackageName()5447 public String getVisualVoicemailPackageName() { 5448 try { 5449 ITelephony telephony = getITelephony(); 5450 if (telephony != null) { 5451 return telephony.getVisualVoicemailPackageName(mContext.getOpPackageName(), 5452 getAttributionTag(), getSubId()); 5453 } 5454 } catch (RemoteException ex) { 5455 } catch (NullPointerException ex) { 5456 } 5457 return null; 5458 } 5459 5460 /** 5461 * Set the visual voicemail SMS filter settings for the subscription ID pinned 5462 * to the TelephonyManager. 5463 * When the filter is enabled, {@link 5464 * VisualVoicemailService#onSmsReceived(VisualVoicemailTask, VisualVoicemailSms)} will be 5465 * called when a SMS matching the settings is received. Caller must be the default dialer, 5466 * system dialer, or carrier visual voicemail app. 5467 * 5468 * @param settings The settings for the filter, or {@code null} to disable the filter. 5469 * 5470 * @see TelecomManager#getDefaultDialerPackage() 5471 * @see CarrierConfigManager#KEY_CARRIER_VVM_PACKAGE_NAME_STRING_ARRAY 5472 */ 5473 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) setVisualVoicemailSmsFilterSettings(VisualVoicemailSmsFilterSettings settings)5474 public void setVisualVoicemailSmsFilterSettings(VisualVoicemailSmsFilterSettings settings) { 5475 if (settings == null) { 5476 disableVisualVoicemailSmsFilter(mSubId); 5477 } else { 5478 enableVisualVoicemailSmsFilter(mSubId, settings); 5479 } 5480 } 5481 5482 /** 5483 * Send a visual voicemail SMS. The caller must be the current default dialer. 5484 * A {@link VisualVoicemailService} uses this method to send a command via SMS to the carrier's 5485 * visual voicemail server. Some examples for carriers using the OMTP standard include 5486 * activating and deactivating visual voicemail, or requesting the current visual voicemail 5487 * provisioning status. See the OMTP Visual Voicemail specification for more information on the 5488 * format of these SMS messages. 5489 * 5490 * <p>Requires Permission: 5491 * {@link android.Manifest.permission#SEND_SMS SEND_SMS} 5492 * 5493 * @param number The destination number. 5494 * @param port The destination port for data SMS, or 0 for text SMS. 5495 * @param text The message content. For data sms, it will be encoded as a UTF-8 byte stream. 5496 * @param sentIntent The sent intent passed to the {@link SmsManager} 5497 * 5498 * @throws SecurityException if the caller is not the current default dialer 5499 * 5500 * @see SmsManager#sendDataMessage(String, String, short, byte[], PendingIntent, PendingIntent) 5501 * @see SmsManager#sendTextMessage(String, String, String, PendingIntent, PendingIntent) 5502 */ 5503 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) sendVisualVoicemailSms(String number, int port, String text, PendingIntent sentIntent)5504 public void sendVisualVoicemailSms(String number, int port, String text, 5505 PendingIntent sentIntent) { 5506 sendVisualVoicemailSmsForSubscriber(mSubId, number, port, text, sentIntent); 5507 } 5508 5509 /** 5510 * Enables the visual voicemail SMS filter for a phone account. When the filter is 5511 * enabled, Incoming SMS messages matching the OMTP VVM SMS interface will be redirected to the 5512 * visual voicemail client with 5513 * {@link android.provider.VoicemailContract.ACTION_VOICEMAIL_SMS_RECEIVED}. 5514 * 5515 * <p>This takes effect only when the caller is the default dialer. The enabled status and 5516 * settings persist through default dialer changes, but the filter will only honor the setting 5517 * set by the current default dialer. 5518 * 5519 * 5520 * @param subId The subscription id of the phone account. 5521 * @param settings The settings for the filter. 5522 */ 5523 /** @hide */ enableVisualVoicemailSmsFilter(int subId, VisualVoicemailSmsFilterSettings settings)5524 public void enableVisualVoicemailSmsFilter(int subId, 5525 VisualVoicemailSmsFilterSettings settings) { 5526 if(settings == null){ 5527 throw new IllegalArgumentException("Settings cannot be null"); 5528 } 5529 try { 5530 ITelephony telephony = getITelephony(); 5531 if (telephony != null) { 5532 telephony.enableVisualVoicemailSmsFilter(mContext.getOpPackageName(), subId, 5533 settings); 5534 } 5535 } catch (RemoteException ex) { 5536 } catch (NullPointerException ex) { 5537 } 5538 } 5539 5540 /** 5541 * Disables the visual voicemail SMS filter for a phone account. 5542 * 5543 * <p>This takes effect only when the caller is the default dialer. The enabled status and 5544 * settings persist through default dialer changes, but the filter will only honor the setting 5545 * set by the current default dialer. 5546 */ 5547 /** @hide */ disableVisualVoicemailSmsFilter(int subId)5548 public void disableVisualVoicemailSmsFilter(int subId) { 5549 try { 5550 ITelephony telephony = getITelephony(); 5551 if (telephony != null) { 5552 telephony.disableVisualVoicemailSmsFilter(mContext.getOpPackageName(), subId); 5553 } 5554 } catch (RemoteException ex) { 5555 } catch (NullPointerException ex) { 5556 } 5557 } 5558 5559 /** 5560 * @returns the settings of the visual voicemail SMS filter for a phone account, or {@code null} 5561 * if the filter is disabled. 5562 * 5563 * <p>This takes effect only when the caller is the default dialer. The enabled status and 5564 * settings persist through default dialer changes, but the filter will only honor the setting 5565 * set by the current default dialer. 5566 */ 5567 /** @hide */ 5568 @Nullable getVisualVoicemailSmsFilterSettings(int subId)5569 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(int subId) { 5570 try { 5571 ITelephony telephony = getITelephony(); 5572 if (telephony != null) { 5573 return telephony 5574 .getVisualVoicemailSmsFilterSettings(mContext.getOpPackageName(), subId); 5575 } 5576 } catch (RemoteException ex) { 5577 } catch (NullPointerException ex) { 5578 } 5579 5580 return null; 5581 } 5582 5583 /** 5584 * @returns the settings of the visual voicemail SMS filter for a phone account set by the 5585 * current active visual voicemail client, or {@code null} if the filter is disabled. 5586 * 5587 * <p>Requires the calling app to have READ_PRIVILEGED_PHONE_STATE permission. 5588 */ 5589 /** @hide */ 5590 @Nullable getActiveVisualVoicemailSmsFilterSettings(int subId)5591 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { 5592 try { 5593 ITelephony telephony = getITelephony(); 5594 if (telephony != null) { 5595 return telephony.getActiveVisualVoicemailSmsFilterSettings(subId); 5596 } 5597 } catch (RemoteException ex) { 5598 } catch (NullPointerException ex) { 5599 } 5600 5601 return null; 5602 } 5603 5604 /** 5605 * Send a visual voicemail SMS. The IPC caller must be the current default dialer. 5606 * 5607 * @param phoneAccountHandle The account to send the SMS with. 5608 * @param number The destination number. 5609 * @param port The destination port for data SMS, or 0 for text SMS. 5610 * @param text The message content. For data sms, it will be encoded as a UTF-8 byte stream. 5611 * @param sentIntent The sent intent passed to the {@link SmsManager} 5612 * 5613 * @see SmsManager#sendDataMessage(String, String, short, byte[], PendingIntent, PendingIntent) 5614 * @see SmsManager#sendTextMessage(String, String, String, PendingIntent, PendingIntent) 5615 * 5616 * @hide 5617 */ 5618 @RequiresPermission(android.Manifest.permission.SEND_SMS) sendVisualVoicemailSmsForSubscriber(int subId, String number, int port, String text, PendingIntent sentIntent)5619 public void sendVisualVoicemailSmsForSubscriber(int subId, String number, int port, 5620 String text, PendingIntent sentIntent) { 5621 try { 5622 ITelephony telephony = getITelephony(); 5623 if (telephony != null) { 5624 telephony.sendVisualVoicemailSmsForSubscriber( 5625 mContext.getOpPackageName(), mContext.getAttributionTag(), subId, number, 5626 port, text, sentIntent); 5627 } 5628 } catch (RemoteException ex) { 5629 } 5630 } 5631 5632 /** 5633 * Initial SIM activation state, unknown. Not set by any carrier apps. 5634 * @hide 5635 */ 5636 @SystemApi 5637 public static final int SIM_ACTIVATION_STATE_UNKNOWN = 0; 5638 5639 /** 5640 * indicate SIM is under activation procedure now. 5641 * intermediate state followed by another state update with activation procedure result: 5642 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5643 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5644 * @see #SIM_ACTIVATION_STATE_RESTRICTED 5645 * @hide 5646 */ 5647 @SystemApi 5648 public static final int SIM_ACTIVATION_STATE_ACTIVATING = 1; 5649 5650 /** 5651 * Indicate SIM has been successfully activated with full service 5652 * @hide 5653 */ 5654 @SystemApi 5655 public static final int SIM_ACTIVATION_STATE_ACTIVATED = 2; 5656 5657 /** 5658 * Indicate SIM has been deactivated by the carrier so that service is not available 5659 * and requires activation service to enable services. 5660 * Carrier apps could be signalled to set activation state to deactivated if detected 5661 * deactivated sim state and set it back to activated after successfully run activation service. 5662 * @hide 5663 */ 5664 @SystemApi 5665 public static final int SIM_ACTIVATION_STATE_DEACTIVATED = 3; 5666 5667 /** 5668 * Restricted state indicate SIM has been activated but service are restricted. 5669 * note this is currently available for data activation state. For example out of byte sim. 5670 * @hide 5671 */ 5672 @SystemApi 5673 public static final int SIM_ACTIVATION_STATE_RESTRICTED = 4; 5674 5675 /** 5676 * Sets the voice activation state 5677 * 5678 * <p>Requires Permission: 5679 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 5680 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5681 * 5682 * @param activationState The voice activation state 5683 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5684 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5685 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5686 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5687 * @hide 5688 */ 5689 @SystemApi 5690 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 5691 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) setVoiceActivationState(@imActivationState int activationState)5692 public void setVoiceActivationState(@SimActivationState int activationState) { 5693 setVoiceActivationState(getSubId(), activationState); 5694 } 5695 5696 /** 5697 * Sets the voice activation state for the given subscriber. 5698 * 5699 * <p>Requires Permission: 5700 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 5701 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5702 * 5703 * @param subId The subscription id. 5704 * @param activationState The voice activation state of the given subscriber. 5705 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5706 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5707 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5708 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5709 * @hide 5710 */ 5711 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setVoiceActivationState(int subId, @SimActivationState int activationState)5712 public void setVoiceActivationState(int subId, @SimActivationState int activationState) { 5713 try { 5714 ITelephony telephony = getITelephony(); 5715 if (telephony != null) 5716 telephony.setVoiceActivationState(subId, activationState); 5717 } catch (RemoteException ex) { 5718 } catch (NullPointerException ex) { 5719 } 5720 } 5721 5722 /** 5723 * Sets the data activation state 5724 * 5725 * <p>Requires Permission: 5726 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 5727 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5728 * 5729 * @param activationState The data activation state 5730 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5731 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5732 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5733 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5734 * @see #SIM_ACTIVATION_STATE_RESTRICTED 5735 * @hide 5736 */ 5737 @SystemApi 5738 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 5739 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) setDataActivationState(@imActivationState int activationState)5740 public void setDataActivationState(@SimActivationState int activationState) { 5741 setDataActivationState(getSubId(), activationState); 5742 } 5743 5744 /** 5745 * Sets the data activation state for the given subscriber. 5746 * 5747 * <p>Requires Permission: 5748 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 5749 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5750 * 5751 * @param subId The subscription id. 5752 * @param activationState The data activation state of the given subscriber. 5753 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5754 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5755 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5756 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5757 * @see #SIM_ACTIVATION_STATE_RESTRICTED 5758 * @hide 5759 */ 5760 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataActivationState(int subId, @SimActivationState int activationState)5761 public void setDataActivationState(int subId, @SimActivationState int activationState) { 5762 try { 5763 ITelephony telephony = getITelephony(); 5764 if (telephony != null) 5765 telephony.setDataActivationState(subId, activationState); 5766 } catch (RemoteException ex) { 5767 } catch (NullPointerException ex) { 5768 } 5769 } 5770 5771 /** 5772 * Returns the voice activation state 5773 * 5774 * <p>Requires Permission: 5775 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 5776 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5777 * 5778 * @return voiceActivationState 5779 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5780 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5781 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5782 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5783 * @hide 5784 */ 5785 @SystemApi 5786 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 5787 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) getVoiceActivationState()5788 public @SimActivationState int getVoiceActivationState() { 5789 return getVoiceActivationState(getSubId()); 5790 } 5791 5792 /** 5793 * Returns the voice activation state for the given subscriber. 5794 * 5795 * <p>Requires Permission: 5796 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 5797 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5798 * 5799 * @param subId The subscription id. 5800 * 5801 * @return voiceActivationState for the given subscriber 5802 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5803 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5804 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5805 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5806 * @hide 5807 */ 5808 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getVoiceActivationState(int subId)5809 public @SimActivationState int getVoiceActivationState(int subId) { 5810 try { 5811 ITelephony telephony = getITelephony(); 5812 if (telephony != null) 5813 return telephony.getVoiceActivationState(subId, getOpPackageName()); 5814 } catch (RemoteException ex) { 5815 } catch (NullPointerException ex) { 5816 } 5817 return SIM_ACTIVATION_STATE_UNKNOWN; 5818 } 5819 5820 /** 5821 * Returns the data activation state 5822 * 5823 * <p>Requires Permission: 5824 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 5825 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5826 * 5827 * @return dataActivationState for the given subscriber 5828 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5829 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5830 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5831 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5832 * @see #SIM_ACTIVATION_STATE_RESTRICTED 5833 * @hide 5834 */ 5835 @SystemApi 5836 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 5837 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) getDataActivationState()5838 public @SimActivationState int getDataActivationState() { 5839 return getDataActivationState(getSubId()); 5840 } 5841 5842 /** 5843 * Returns the data activation state for the given subscriber. 5844 * 5845 * <p>Requires Permission: 5846 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 5847 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5848 * 5849 * @param subId The subscription id. 5850 * 5851 * @return dataActivationState for the given subscriber 5852 * @see #SIM_ACTIVATION_STATE_UNKNOWN 5853 * @see #SIM_ACTIVATION_STATE_ACTIVATING 5854 * @see #SIM_ACTIVATION_STATE_ACTIVATED 5855 * @see #SIM_ACTIVATION_STATE_DEACTIVATED 5856 * @see #SIM_ACTIVATION_STATE_RESTRICTED 5857 * @hide 5858 */ 5859 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getDataActivationState(int subId)5860 public @SimActivationState int getDataActivationState(int subId) { 5861 try { 5862 ITelephony telephony = getITelephony(); 5863 if (telephony != null) 5864 return telephony.getDataActivationState(subId, getOpPackageName()); 5865 } catch (RemoteException ex) { 5866 } catch (NullPointerException ex) { 5867 } 5868 return SIM_ACTIVATION_STATE_UNKNOWN; 5869 } 5870 5871 /** 5872 * Returns the voice mail count. Return 0 if unavailable, -1 if there are unread voice messages 5873 * but the count is unknown. 5874 * @hide 5875 */ 5876 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5877 @UnsupportedAppUsage getVoiceMessageCount()5878 public int getVoiceMessageCount() { 5879 return getVoiceMessageCount(getSubId()); 5880 } 5881 5882 /** 5883 * Returns the voice mail count for a subscription. Return 0 if unavailable or the caller does 5884 * not have the READ_PHONE_STATE permission. 5885 * @param subId whose voice message count is returned 5886 * @hide 5887 */ 5888 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5889 @UnsupportedAppUsage getVoiceMessageCount(int subId)5890 public int getVoiceMessageCount(int subId) { 5891 try { 5892 ITelephony telephony = getITelephony(); 5893 if (telephony == null) 5894 return 0; 5895 return telephony.getVoiceMessageCountForSubscriber(subId, getOpPackageName(), 5896 getAttributionTag()); 5897 } catch (RemoteException ex) { 5898 return 0; 5899 } catch (NullPointerException ex) { 5900 // This could happen before phone restarts due to crashing 5901 return 0; 5902 } 5903 } 5904 5905 /** 5906 * Retrieves the alphabetic identifier associated with the voice 5907 * mail number. 5908 * 5909 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 5910 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 5911 */ 5912 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 5913 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5914 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) getVoiceMailAlphaTag()5915 public String getVoiceMailAlphaTag() { 5916 return getVoiceMailAlphaTag(getSubId()); 5917 } 5918 5919 /** 5920 * Retrieves the alphabetic identifier associated with the voice 5921 * mail number for a subscription. 5922 * @param subId whose alphabetic identifier associated with the 5923 * voice mail number is returned 5924 * @hide 5925 */ 5926 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 5927 @UnsupportedAppUsage getVoiceMailAlphaTag(int subId)5928 public String getVoiceMailAlphaTag(int subId) { 5929 try { 5930 IPhoneSubInfo info = getSubscriberInfoService(); 5931 if (info == null) 5932 return null; 5933 return info.getVoiceMailAlphaTagForSubscriber(subId, getOpPackageName(), 5934 getAttributionTag()); 5935 } catch (RemoteException ex) { 5936 return null; 5937 } catch (NullPointerException ex) { 5938 // This could happen before phone restarts due to crashing 5939 return null; 5940 } 5941 } 5942 5943 /** 5944 * Send the special dialer code. The IPC caller must be the current default dialer or have 5945 * carrier privileges (see {@link #hasCarrierPrivileges}). 5946 * 5947 * @param inputCode The special dialer code to send 5948 * 5949 * @throws SecurityException if the caller does not have carrier privileges or is not the 5950 * current default dialer 5951 */ sendDialerSpecialCode(String inputCode)5952 public void sendDialerSpecialCode(String inputCode) { 5953 try { 5954 final ITelephony telephony = getITelephony(); 5955 if (telephony == null) { 5956 return; 5957 } 5958 telephony.sendDialerSpecialCode(mContext.getOpPackageName(), inputCode); 5959 } catch (RemoteException ex) { 5960 Rlog.e(TAG, "Telephony#sendDialerSpecialCode RemoteException" + ex); 5961 } 5962 } 5963 5964 /** 5965 * Returns the IMS private user identity (IMPI) that was loaded from the ISIM. 5966 * @return the IMPI, or null if not present or not loaded 5967 * @hide 5968 */ 5969 @UnsupportedAppUsage getIsimImpi()5970 public String getIsimImpi() { 5971 try { 5972 IPhoneSubInfo info = getSubscriberInfoService(); 5973 if (info == null) 5974 return null; 5975 //get the Isim Impi based on subId 5976 return info.getIsimImpi(getSubId()); 5977 } catch (RemoteException ex) { 5978 return null; 5979 } catch (NullPointerException ex) { 5980 // This could happen before phone restarts due to crashing 5981 return null; 5982 } 5983 } 5984 5985 /** 5986 * Returns the IMS home network domain name that was loaded from the ISIM {@see #APPTYPE_ISIM}. 5987 * @return the IMS domain name. Returns {@code null} if ISIM hasn't been loaded or IMS domain 5988 * hasn't been loaded or isn't present on the ISIM. 5989 * 5990 * <p>Requires Permission: 5991 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 5992 * @hide 5993 */ 5994 @Nullable 5995 @SystemApi 5996 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 5997 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getIsimDomain()5998 public String getIsimDomain() { 5999 try { 6000 IPhoneSubInfo info = getSubscriberInfoService(); 6001 if (info == null) 6002 return null; 6003 //get the Isim Domain based on subId 6004 return info.getIsimDomain(getSubId()); 6005 } catch (RemoteException ex) { 6006 return null; 6007 } catch (NullPointerException ex) { 6008 // This could happen before phone restarts due to crashing 6009 return null; 6010 } 6011 } 6012 6013 /** 6014 * Returns the IMS public user identities (IMPU) that were loaded from the ISIM. 6015 * @return an array of IMPU strings, with one IMPU per string, or null if 6016 * not present or not loaded 6017 * @hide 6018 */ 6019 @UnsupportedAppUsage 6020 @Nullable 6021 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getIsimImpu()6022 public String[] getIsimImpu() { 6023 try { 6024 IPhoneSubInfo info = getSubscriberInfoService(); 6025 if (info == null) 6026 return null; 6027 //get the Isim Impu based on subId 6028 return info.getIsimImpu(getSubId()); 6029 } catch (RemoteException ex) { 6030 return null; 6031 } catch (NullPointerException ex) { 6032 // This could happen before phone restarts due to crashing 6033 return null; 6034 } 6035 } 6036 6037 /** 6038 * Device call state: No activity. 6039 */ 6040 public static final int CALL_STATE_IDLE = 0; 6041 /** 6042 * Device call state: Ringing. A new call arrived and is 6043 * ringing or waiting. In the latter case, another call is 6044 * already active. 6045 */ 6046 public static final int CALL_STATE_RINGING = 1; 6047 /** 6048 * Device call state: Off-hook. At least one call exists 6049 * that is dialing, active, or on hold, and no calls are ringing 6050 * or waiting. 6051 */ 6052 public static final int CALL_STATE_OFFHOOK = 2; 6053 6054 /** 6055 * Returns the state of all calls on the device. 6056 * <p> 6057 * This method considers not only calls in the Telephony stack, but also calls via other 6058 * {@link android.telecom.ConnectionService} implementations. 6059 * <p> 6060 * Note: The call state returned via this method may differ from what is reported by 6061 * {@link PhoneStateListener#onCallStateChanged(int, String)}, as that callback only considers 6062 * Telephony (mobile) calls. 6063 * <p> 6064 * Requires Permission: 6065 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} for applications 6066 * targeting API level 31+. 6067 * 6068 * @return the current call state. 6069 * @deprecated Use {@link #getCallStateForSubscription} to retrieve the call state for a 6070 * specific telephony subscription (which allows carrier privileged apps), 6071 * {@link TelephonyCallback.CallStateListener} for real-time call state updates, or 6072 * {@link TelecomManager#isInCall()}, which supplies an aggregate "in call" state for the entire 6073 * device. 6074 */ 6075 @RequiresPermission(value = android.Manifest.permission.READ_PHONE_STATE, conditional = true) 6076 @Deprecated getCallState()6077 public @CallState int getCallState() { 6078 if (mContext != null) { 6079 TelecomManager telecomManager = mContext.getSystemService(TelecomManager.class); 6080 if (telecomManager != null) { 6081 return telecomManager.getCallState(); 6082 } 6083 } 6084 return CALL_STATE_IDLE; 6085 } 6086 6087 /** 6088 * Retrieve the call state for a specific subscription that was specified when this 6089 * TelephonyManager instance was created. 6090 * <p>Requires Permission: 6091 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} or that the calling 6092 * application has carrier privileges (see {@link #hasCarrierPrivileges}). 6093 * @see TelephonyManager#createForSubscriptionId(int) 6094 * @see TelephonyManager#createForPhoneAccountHandle(PhoneAccountHandle) 6095 * @return The call state of the subscription associated with this TelephonyManager instance. 6096 */ 6097 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 6098 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) getCallStateForSubscription()6099 public @CallState int getCallStateForSubscription() { 6100 return getCallState(getSubId()); 6101 } 6102 6103 /** 6104 * Returns the Telephony call state for calls on a specific subscription. 6105 * <p> 6106 * Note: This method considers ONLY telephony/mobile calls, where {@link #getCallState()} 6107 * considers the state of calls from other {@link android.telecom.ConnectionService} 6108 * implementations. 6109 * <p> 6110 * Requires Permission: 6111 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} for applications 6112 * targeting API level 31+ or that the calling application has carrier privileges 6113 * (see {@link #hasCarrierPrivileges()}). 6114 * 6115 * @param subId the subscription to check call state for. 6116 * @hide 6117 */ 6118 @UnsupportedAppUsage 6119 @RequiresPermission(value = android.Manifest.permission.READ_PHONE_STATE, conditional = true) getCallState(int subId)6120 public @CallState int getCallState(int subId) { 6121 ITelephony telephony = getITelephony(); 6122 if (telephony == null) { 6123 return CALL_STATE_IDLE; 6124 } 6125 try { 6126 return telephony.getCallStateForSubscription(subId, mContext.getPackageName(), 6127 mContext.getAttributionTag()); 6128 } catch (RemoteException e) { 6129 return CALL_STATE_IDLE; 6130 } 6131 } 6132 6133 /** 6134 * @hide 6135 */ 6136 @UnsupportedAppUsage getSubscriberInfo()6137 private IPhoneSubInfo getSubscriberInfo() { 6138 return getSubscriberInfoService(); 6139 } 6140 6141 /** 6142 * Returns the Telephony call state for calls on a specific SIM slot. 6143 * <p> 6144 * Note: This method considers ONLY telephony/mobile calls, where {@link #getCallState()} 6145 * considers the state of calls from other {@link android.telecom.ConnectionService} 6146 * implementations. 6147 * <p> 6148 * Requires Permission: 6149 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} for applications 6150 * targeting API level 31+ or that the calling application has carrier privileges 6151 * (see {@link #hasCarrierPrivileges()}). 6152 * 6153 * @param slotIndex the SIM slot index to check call state for. 6154 * @hide 6155 */ 6156 @RequiresPermission(value = android.Manifest.permission.READ_PHONE_STATE, conditional = true) getCallStateForSlot(int slotIndex)6157 public @CallState int getCallStateForSlot(int slotIndex) { 6158 try { 6159 int[] subId = SubscriptionManager.getSubId(slotIndex); 6160 ITelephony telephony = getITelephony(); 6161 if (telephony == null || subId == null || subId.length == 0) { 6162 return CALL_STATE_IDLE; 6163 } 6164 return telephony.getCallStateForSubscription(subId[0], mContext.getPackageName(), 6165 mContext.getAttributionTag()); 6166 } catch (RemoteException | NullPointerException ex) { 6167 // the phone process is restarting. 6168 return CALL_STATE_IDLE; 6169 } 6170 } 6171 6172 6173 /** Data connection activity: No traffic. */ 6174 public static final int DATA_ACTIVITY_NONE = 0x00000000; 6175 /** Data connection activity: Currently receiving IP PPP traffic. */ 6176 public static final int DATA_ACTIVITY_IN = 0x00000001; 6177 /** Data connection activity: Currently sending IP PPP traffic. */ 6178 public static final int DATA_ACTIVITY_OUT = 0x00000002; 6179 /** Data connection activity: Currently both sending and receiving 6180 * IP PPP traffic. */ 6181 public static final int DATA_ACTIVITY_INOUT = DATA_ACTIVITY_IN | DATA_ACTIVITY_OUT; 6182 /** 6183 * Data connection is active, but physical link is down 6184 */ 6185 public static final int DATA_ACTIVITY_DORMANT = 0x00000004; 6186 6187 /** 6188 * Returns a constant indicating the type of activity on a data connection 6189 * (cellular). 6190 * 6191 * @see #DATA_ACTIVITY_NONE 6192 * @see #DATA_ACTIVITY_IN 6193 * @see #DATA_ACTIVITY_OUT 6194 * @see #DATA_ACTIVITY_INOUT 6195 * @see #DATA_ACTIVITY_DORMANT 6196 */ 6197 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) getDataActivity()6198 public int getDataActivity() { 6199 try { 6200 ITelephony telephony = getITelephony(); 6201 if (telephony == null) 6202 return DATA_ACTIVITY_NONE; 6203 return telephony.getDataActivityForSubId( 6204 getSubId(SubscriptionManager.getActiveDataSubscriptionId())); 6205 } catch (RemoteException ex) { 6206 // the phone process is restarting. 6207 return DATA_ACTIVITY_NONE; 6208 } catch (NullPointerException ex) { 6209 // the phone process is restarting. 6210 return DATA_ACTIVITY_NONE; 6211 } 6212 } 6213 6214 /** @hide */ 6215 @IntDef(prefix = {"DATA_"}, value = { 6216 DATA_UNKNOWN, 6217 DATA_DISCONNECTED, 6218 DATA_CONNECTING, 6219 DATA_CONNECTED, 6220 DATA_SUSPENDED, 6221 DATA_DISCONNECTING, 6222 DATA_HANDOVER_IN_PROGRESS, 6223 }) 6224 @Retention(RetentionPolicy.SOURCE) 6225 public @interface DataState{} 6226 6227 /** Data connection state: Unknown. Used before we know the state. */ 6228 public static final int DATA_UNKNOWN = -1; 6229 /** Data connection state: Disconnected. IP traffic not available. */ 6230 public static final int DATA_DISCONNECTED = 0; 6231 /** Data connection state: Currently setting up a data connection. */ 6232 public static final int DATA_CONNECTING = 1; 6233 /** Data connection state: Connected. IP traffic should be available. */ 6234 public static final int DATA_CONNECTED = 2; 6235 /** Data connection state: Suspended. The connection is up, but IP 6236 * traffic is temporarily unavailable. For example, in a 2G network, 6237 * data activity may be suspended when a voice call arrives. */ 6238 public static final int DATA_SUSPENDED = 3; 6239 /** 6240 * Data connection state: Disconnecting. 6241 * 6242 * IP traffic may be available but will cease working imminently. 6243 */ 6244 public static final int DATA_DISCONNECTING = 4; 6245 6246 /** 6247 * Data connection state: Handover in progress. The connection is being transited from cellular 6248 * network to IWLAN, or from IWLAN to cellular network. 6249 */ 6250 public static final int DATA_HANDOVER_IN_PROGRESS = 5; 6251 6252 /** 6253 * Used for checking if the SDK version for {@link TelephonyManager#getDataState} is above Q. 6254 */ 6255 @ChangeId 6256 @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q) 6257 private static final long GET_DATA_STATE_R_VERSION = 148534348L; 6258 6259 /** 6260 * Returns a constant indicating the current data connection state 6261 * (cellular). 6262 * 6263 * @see #DATA_DISCONNECTED 6264 * @see #DATA_CONNECTING 6265 * @see #DATA_CONNECTED 6266 * @see #DATA_SUSPENDED 6267 * @see #DATA_DISCONNECTING 6268 * @see #DATA_HANDOVER_IN_PROGRESS 6269 */ 6270 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) getDataState()6271 public int getDataState() { 6272 try { 6273 ITelephony telephony = getITelephony(); 6274 if (telephony == null) 6275 return DATA_DISCONNECTED; 6276 int state = telephony.getDataStateForSubId( 6277 getSubId(SubscriptionManager.getActiveDataSubscriptionId())); 6278 if (state == TelephonyManager.DATA_DISCONNECTING 6279 && !Compatibility.isChangeEnabled(GET_DATA_STATE_R_VERSION)) { 6280 return TelephonyManager.DATA_CONNECTED; 6281 } 6282 6283 return state; 6284 } catch (RemoteException ex) { 6285 // the phone process is restarting. 6286 return DATA_DISCONNECTED; 6287 } catch (NullPointerException ex) { 6288 return DATA_DISCONNECTED; 6289 } 6290 } 6291 6292 /** 6293 * @hide 6294 */ 6295 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getITelephony()6296 private ITelephony getITelephony() { 6297 // Keeps cache disabled until test fixes are checked into AOSP. 6298 if (!sServiceHandleCacheEnabled) { 6299 return ITelephony.Stub.asInterface( 6300 TelephonyFrameworkInitializer 6301 .getTelephonyServiceManager() 6302 .getTelephonyServiceRegisterer() 6303 .get()); 6304 } 6305 6306 if (sITelephony == null) { 6307 ITelephony temp = ITelephony.Stub.asInterface( 6308 TelephonyFrameworkInitializer 6309 .getTelephonyServiceManager() 6310 .getTelephonyServiceRegisterer() 6311 .get()); 6312 synchronized (sCacheLock) { 6313 if (sITelephony == null && temp != null) { 6314 try { 6315 sITelephony = temp; 6316 sITelephony.asBinder().linkToDeath(sServiceDeath, 0); 6317 } catch (Exception e) { 6318 // something has gone horribly wrong 6319 sITelephony = null; 6320 } 6321 } 6322 } 6323 } 6324 return sITelephony; 6325 } 6326 getIOns()6327 private IOns getIOns() { 6328 return IOns.Stub.asInterface( 6329 TelephonyFrameworkInitializer 6330 .getTelephonyServiceManager() 6331 .getOpportunisticNetworkServiceRegisterer() 6332 .get()); 6333 } 6334 6335 // 6336 // 6337 // PhoneStateListener 6338 // 6339 // 6340 6341 /** 6342 * Registers a listener object to receive notification of changes 6343 * in specified telephony states. 6344 * <p> 6345 * To register a listener, pass a {@link PhoneStateListener} and specify at least one telephony 6346 * state of interest in the events argument. 6347 * 6348 * At registration, and when a specified telephony state changes, the telephony manager invokes 6349 * the appropriate callback method on the listener object and passes the current (updated) 6350 * values. 6351 * <p> 6352 * To un-register a listener, pass the listener object and set the events argument to 6353 * {@link PhoneStateListener#LISTEN_NONE LISTEN_NONE} (0). 6354 * 6355 * If this TelephonyManager object has been created with {@link #createForSubscriptionId}, 6356 * applies to the given subId. Otherwise, applies to 6357 * {@link SubscriptionManager#getDefaultSubscriptionId()}. To listen events for multiple subIds, 6358 * pass a separate listener object to each TelephonyManager object created with 6359 * {@link #createForSubscriptionId}. 6360 * 6361 * Note: if you call this method while in the middle of a binder transaction, you <b>must</b> 6362 * call {@link android.os.Binder#clearCallingIdentity()} before calling this method. A 6363 * {@link SecurityException} will be thrown otherwise. 6364 * 6365 * This API should be used sparingly -- large numbers of listeners will cause system 6366 * instability. If a process has registered too many listeners without unregistering them, it 6367 * may encounter an {@link IllegalStateException} when trying to register more listeners. 6368 * 6369 * @param listener The {@link PhoneStateListener} object to register 6370 * (or unregister) 6371 * @param events The telephony state(s) of interest to the listener, 6372 * as a bitwise-OR combination of {@link PhoneStateListener} 6373 * LISTEN_ flags. 6374 * @deprecated Use {@link #registerTelephonyCallback(Executor, TelephonyCallback)}. 6375 */ 6376 @Deprecated listen(PhoneStateListener listener, int events)6377 public void listen(PhoneStateListener listener, int events) { 6378 if (mContext == null) return; 6379 boolean notifyNow = (getITelephony() != null); 6380 TelephonyRegistryManager telephonyRegistry = 6381 (TelephonyRegistryManager) 6382 mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE); 6383 if (telephonyRegistry != null) { 6384 Set<String> renouncedPermissions = getRenouncedPermissions(); 6385 boolean renounceFineLocationAccess = renouncedPermissions 6386 .contains(Manifest.permission.ACCESS_FINE_LOCATION); 6387 boolean renounceCoarseLocationAccess = renouncedPermissions 6388 .contains(Manifest.permission.ACCESS_COARSE_LOCATION); 6389 telephonyRegistry.listenFromListener(mSubId, renounceFineLocationAccess, 6390 renounceCoarseLocationAccess, getOpPackageName(), getAttributionTag(), 6391 listener, events, notifyNow); 6392 } else { 6393 Rlog.w(TAG, "telephony registry not ready."); 6394 } 6395 } 6396 6397 /** @hide */ 6398 @Retention(RetentionPolicy.SOURCE) 6399 @IntDef(prefix = {"ERI_"}, value = { 6400 ERI_ON, 6401 ERI_OFF, 6402 ERI_FLASH 6403 }) 6404 public @interface EriIconIndex {} 6405 6406 /** 6407 * ERI (Enhanced Roaming Indicator) is ON i.e value 0 defined by 6408 * 3GPP2 C.R1001-H v1.0 Table 8.1-1. 6409 */ 6410 public static final int ERI_ON = 0; 6411 6412 /** 6413 * ERI (Enhanced Roaming Indicator) is OFF i.e value 1 defined by 6414 * 3GPP2 C.R1001-H v1.0 Table 8.1-1. 6415 */ 6416 public static final int ERI_OFF = 1; 6417 6418 /** 6419 * ERI (Enhanced Roaming Indicator) is FLASH i.e value 2 defined by 6420 * 3GPP2 C.R1001-H v1.0 Table 8.1-1. 6421 */ 6422 public static final int ERI_FLASH = 2; 6423 6424 /** @hide */ 6425 @Retention(RetentionPolicy.SOURCE) 6426 @IntDef(prefix = {"ERI_ICON_MODE_"}, value = { 6427 ERI_ICON_MODE_NORMAL, 6428 ERI_ICON_MODE_FLASH 6429 }) 6430 public @interface EriIconMode {} 6431 6432 /** 6433 * ERI (Enhanced Roaming Indicator) icon mode is normal. This constant represents that 6434 * the ERI icon should be displayed normally. 6435 * 6436 * Note: ERI is defined 3GPP2 C.R1001-H Table 8.1-1 6437 * @hide 6438 */ 6439 public static final int ERI_ICON_MODE_NORMAL = 0; 6440 6441 /** 6442 * ERI (Enhanced Roaming Indicator) icon mode flash. This constant represents that 6443 * the ERI icon should be flashing. 6444 * 6445 * Note: ERI is defined 3GPP2 C.R1001-H Table 8.1-1 6446 * @hide 6447 */ 6448 public static final int ERI_ICON_MODE_FLASH = 1; 6449 6450 /** 6451 * Returns the CDMA ERI icon display number. The number is assigned by 6452 * 3GPP2 C.R1001-H v1.0 Table 8.1-1. Additionally carriers define their own ERI display numbers. 6453 * Defined values are {@link #ERI_ON}, {@link #ERI_OFF}, and {@link #ERI_FLASH}. 6454 * @hide 6455 */ 6456 @SystemApi 6457 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getCdmaEnhancedRoamingIndicatorDisplayNumber()6458 public @EriIconIndex int getCdmaEnhancedRoamingIndicatorDisplayNumber() { 6459 return getCdmaEriIconIndex(getSubId()); 6460 } 6461 6462 /** 6463 * Returns the CDMA ERI icon index to display for a subscription. 6464 * @hide 6465 */ 6466 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 6467 @UnsupportedAppUsage getCdmaEriIconIndex(int subId)6468 public @EriIconIndex int getCdmaEriIconIndex(int subId) { 6469 try { 6470 ITelephony telephony = getITelephony(); 6471 if (telephony == null) 6472 return -1; 6473 return telephony.getCdmaEriIconIndexForSubscriber(subId, getOpPackageName(), 6474 getAttributionTag()); 6475 } catch (RemoteException ex) { 6476 // the phone process is restarting. 6477 return -1; 6478 } catch (NullPointerException ex) { 6479 return -1; 6480 } 6481 } 6482 6483 /** 6484 * Returns the CDMA ERI icon mode for a subscription. 6485 * 0 - ON 6486 * 1 - FLASHING 6487 * 6488 * @hide 6489 */ 6490 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 6491 @UnsupportedAppUsage getCdmaEriIconMode(int subId)6492 public @EriIconMode int getCdmaEriIconMode(int subId) { 6493 try { 6494 ITelephony telephony = getITelephony(); 6495 if (telephony == null) 6496 return -1; 6497 return telephony.getCdmaEriIconModeForSubscriber(subId, getOpPackageName(), 6498 getAttributionTag()); 6499 } catch (RemoteException ex) { 6500 // the phone process is restarting. 6501 return -1; 6502 } catch (NullPointerException ex) { 6503 return -1; 6504 } 6505 } 6506 6507 /** 6508 * Returns the CDMA ERI text, 6509 * 6510 * @hide 6511 */ 6512 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getCdmaEriText()6513 public String getCdmaEriText() { 6514 return getCdmaEriText(getSubId()); 6515 } 6516 6517 /** 6518 * Returns the CDMA ERI text, of a subscription 6519 * 6520 * @hide 6521 */ 6522 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 6523 @UnsupportedAppUsage getCdmaEriText(int subId)6524 public String getCdmaEriText(int subId) { 6525 try { 6526 ITelephony telephony = getITelephony(); 6527 if (telephony == null) 6528 return null; 6529 return telephony.getCdmaEriTextForSubscriber(subId, getOpPackageName(), 6530 getAttributionTag()); 6531 } catch (RemoteException ex) { 6532 // the phone process is restarting. 6533 return null; 6534 } catch (NullPointerException ex) { 6535 return null; 6536 } 6537 } 6538 6539 /** 6540 * @return true if the current device is "voice capable". 6541 * <p> 6542 * "Voice capable" means that this device supports circuit-switched 6543 * (i.e. voice) phone calls over the telephony network, and is allowed 6544 * to display the in-call UI while a cellular voice call is active. 6545 * This will be false on "data only" devices which can't make voice 6546 * calls and don't support any in-call UI. 6547 * <p> 6548 * Note: the meaning of this flag is subtly different from the 6549 * PackageManager.FEATURE_TELEPHONY system feature, which is available 6550 * on any device with a telephony radio, even if the device is 6551 * data-only. 6552 */ 6553 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) isVoiceCapable()6554 public boolean isVoiceCapable() { 6555 if (mContext == null) return true; 6556 return mContext.getResources().getBoolean( 6557 com.android.internal.R.bool.config_voice_capable); 6558 } 6559 6560 /** 6561 * @return true if the current device supports sms service. 6562 * <p> 6563 * If true, this means that the device supports both sending and 6564 * receiving sms via the telephony network. 6565 * <p> 6566 * Note: Voicemail waiting sms, cell broadcasting sms, and MMS are 6567 * disabled when device doesn't support sms. 6568 */ 6569 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING) isSmsCapable()6570 public boolean isSmsCapable() { 6571 if (mContext == null) return true; 6572 return mContext.getResources().getBoolean( 6573 com.android.internal.R.bool.config_sms_capable); 6574 } 6575 6576 /** 6577 * Requests all available cell information from all radios on the device including the 6578 * camped/registered, serving, and neighboring cells. 6579 * 6580 * <p>The response can include one or more {@link android.telephony.CellInfoGsm CellInfoGsm}, 6581 * {@link android.telephony.CellInfoCdma CellInfoCdma}, 6582 * {@link android.telephony.CellInfoTdscdma CellInfoTdscdma}, 6583 * {@link android.telephony.CellInfoLte CellInfoLte}, and 6584 * {@link android.telephony.CellInfoWcdma CellInfoWcdma} objects, in any combination. 6585 * It is typical to see instances of one or more of any these in the list. In addition, zero 6586 * or more of the returned objects may be considered registered; that is, their 6587 * {@link android.telephony.CellInfo#isRegistered CellInfo.isRegistered()} 6588 * methods may return true, indicating that the cell is being used or would be used for 6589 * signaling communication if necessary. 6590 * 6591 * <p>Beginning with {@link android.os.Build.VERSION_CODES#Q Android Q}, 6592 * if this API results in a change of the cached CellInfo, that change will be reported via 6593 * {@link android.telephony.PhoneStateListener#onCellInfoChanged onCellInfoChanged()}. 6594 * 6595 * <p>Apps targeting {@link android.os.Build.VERSION_CODES#Q Android Q} or higher will no 6596 * longer trigger a refresh of the cached CellInfo by invoking this API. Instead, those apps 6597 * will receive the latest cached results, which may not be current. Apps targeting 6598 * {@link android.os.Build.VERSION_CODES#Q Android Q} or higher that wish to request updated 6599 * CellInfo should call 6600 * {@link android.telephony.TelephonyManager#requestCellInfoUpdate requestCellInfoUpdate()}; 6601 * however, in all cases, updates will be rate-limited and are not guaranteed. To determine the 6602 * recency of CellInfo data, callers should check 6603 * {@link android.telephony.CellInfo#getTimeStamp CellInfo#getTimeStamp()}. 6604 * 6605 * <p>This method returns valid data for devices with 6606 * {@link android.content.pm.PackageManager#FEATURE_TELEPHONY FEATURE_TELEPHONY}. In cases 6607 * where only partial information is available for a particular CellInfo entry, unavailable 6608 * fields will be reported as {@link android.telephony.CellInfo#UNAVAILABLE}. All reported 6609 * cells will include at least a valid set of technology-specific identification info and a 6610 * power level measurement. 6611 * 6612 * <p>This method is preferred over using {@link 6613 * android.telephony.TelephonyManager#getCellLocation getCellLocation()}. 6614 * 6615 * @return List of {@link android.telephony.CellInfo}; null if cell 6616 * information is unavailable. 6617 */ 6618 @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) 6619 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) getAllCellInfo()6620 public List<CellInfo> getAllCellInfo() { 6621 try { 6622 ITelephony telephony = getITelephony(); 6623 if (telephony == null) 6624 return null; 6625 return telephony.getAllCellInfo(getOpPackageName(), getAttributionTag()); 6626 } catch (RemoteException ex) { 6627 } catch (NullPointerException ex) { 6628 } 6629 return null; 6630 } 6631 6632 /** Callback for providing asynchronous {@link CellInfo} on request */ 6633 public abstract static class CellInfoCallback { 6634 /** 6635 * Success response to 6636 * {@link android.telephony.TelephonyManager#requestCellInfoUpdate requestCellInfoUpdate()}. 6637 * 6638 * Invoked when there is a response to 6639 * {@link android.telephony.TelephonyManager#requestCellInfoUpdate requestCellInfoUpdate()} 6640 * to provide a list of {@link CellInfo}. If no {@link CellInfo} is available then an empty 6641 * list will be provided. If an error occurs, null will be provided unless the onError 6642 * callback is overridden. 6643 * 6644 * @param cellInfo a list of {@link CellInfo}, an empty list, or null. 6645 * 6646 * {@see android.telephony.TelephonyManager#getAllCellInfo getAllCellInfo()} 6647 */ onCellInfo(@onNull List<CellInfo> cellInfo)6648 public abstract void onCellInfo(@NonNull List<CellInfo> cellInfo); 6649 6650 /** @hide */ 6651 @Retention(RetentionPolicy.SOURCE) 6652 @IntDef(prefix = {"ERROR_"}, value = {ERROR_TIMEOUT, ERROR_MODEM_ERROR}) 6653 public @interface CellInfoCallbackError {} 6654 6655 /** 6656 * The system timed out waiting for a response from the Radio. 6657 */ 6658 public static final int ERROR_TIMEOUT = 1; 6659 6660 /** 6661 * The modem returned a failure. 6662 */ 6663 public static final int ERROR_MODEM_ERROR = 2; 6664 6665 /** 6666 * Error response to 6667 * {@link TelephonyManager#requestCellInfoUpdate requestCellInfoUpdate()}. 6668 * 6669 * Invoked when an error condition prevents updated {@link CellInfo} from being fetched 6670 * and returned from the modem. Callers of requestCellInfoUpdate() should override this 6671 * function to receive detailed status information in the event of an error. By default, 6672 * this function will invoke onCellInfo() with null. 6673 * 6674 * @param errorCode an error code indicating the type of failure. 6675 * @param detail a Throwable object with additional detail regarding the failure if 6676 * available, otherwise null. 6677 */ onError(@ellInfoCallbackError int errorCode, @Nullable Throwable detail)6678 public void onError(@CellInfoCallbackError int errorCode, @Nullable Throwable detail) { 6679 // By default, simply invoke the success callback with an empty list. 6680 onCellInfo(new ArrayList<CellInfo>()); 6681 } 6682 }; 6683 6684 /** 6685 * Used for checking if the target SDK version for the current process is S or above. 6686 * 6687 * <p> Applies to the following methods: 6688 * {@link #requestCellInfoUpdate}, 6689 * {@link #setPreferredOpportunisticDataSubscription}, 6690 * {@link #updateAvailableNetworks}, 6691 * requestNumberVerification(), 6692 * setSimPowerStateForSlot(), 6693 */ 6694 @ChangeId 6695 @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.R) 6696 private static final long NULL_TELEPHONY_THROW_NO_CB = 182185642L; 6697 6698 /** 6699 * Requests all available cell information from the current subscription for observed 6700 * camped/registered, serving, and neighboring cells. 6701 * 6702 * <p>Any available results from this request will be provided by calls to 6703 * {@link android.telephony.PhoneStateListener#onCellInfoChanged onCellInfoChanged()} 6704 * for each active subscription. 6705 * 6706 * <p>This method returns valid data for devices with 6707 * {@link android.content.pm.PackageManager#FEATURE_TELEPHONY FEATURE_TELEPHONY}. On devices 6708 * that do not implement this feature, the behavior is not reliable. 6709 * 6710 * @param executor the executor on which callback will be invoked. 6711 * @param callback a callback to receive CellInfo. 6712 */ 6713 @RequiresPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) 6714 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) requestCellInfoUpdate( @onNull @allbackExecutor Executor executor, @NonNull CellInfoCallback callback)6715 public void requestCellInfoUpdate( 6716 @NonNull @CallbackExecutor Executor executor, @NonNull CellInfoCallback callback) { 6717 try { 6718 ITelephony telephony = getITelephony(); 6719 if (telephony == null) { 6720 if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) { 6721 throw new IllegalStateException("Telephony is null"); 6722 } else { 6723 return; 6724 } 6725 } 6726 6727 telephony.requestCellInfoUpdate( 6728 getSubId(), 6729 new ICellInfoCallback.Stub() { 6730 @Override 6731 public void onCellInfo(List<CellInfo> cellInfo) { 6732 final long identity = Binder.clearCallingIdentity(); 6733 try { 6734 executor.execute(() -> callback.onCellInfo(cellInfo)); 6735 } finally { 6736 Binder.restoreCallingIdentity(identity); 6737 } 6738 } 6739 6740 @Override 6741 public void onError(int errorCode, String exceptionName, String message) { 6742 final long identity = Binder.clearCallingIdentity(); 6743 try { 6744 executor.execute(() -> callback.onError( 6745 errorCode, 6746 createThrowableByClassName(exceptionName, message))); 6747 } finally { 6748 Binder.restoreCallingIdentity(identity); 6749 } 6750 } 6751 }, getOpPackageName(), getAttributionTag()); 6752 } catch (RemoteException ex) { 6753 runOnBackgroundThread(() -> executor.execute( 6754 () -> callback.onError(CellInfoCallback.ERROR_MODEM_ERROR, ex))); 6755 } 6756 } 6757 6758 /** 6759 * Requests all available cell information from the current subscription for observed 6760 * camped/registered, serving, and neighboring cells. 6761 * 6762 * <p>Any available results from this request will be provided by calls to 6763 * {@link android.telephony.PhoneStateListener#onCellInfoChanged onCellInfoChanged()} 6764 * for each active subscription. 6765 * 6766 * <p>This method returns valid data for devices with 6767 * {@link android.content.pm.PackageManager#FEATURE_TELEPHONY FEATURE_TELEPHONY}. On devices 6768 * that do not implement this feature, the behavior is not reliable. 6769 * 6770 * @param workSource the requestor to whom the power consumption for this should be attributed. 6771 * @param executor the executor on which callback will be invoked. 6772 * @param callback a callback to receive CellInfo. 6773 * @hide 6774 */ 6775 @SystemApi 6776 @RequiresPermission(allOf = {android.Manifest.permission.ACCESS_FINE_LOCATION, 6777 android.Manifest.permission.MODIFY_PHONE_STATE}) 6778 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) requestCellInfoUpdate(@onNull WorkSource workSource, @NonNull @CallbackExecutor Executor executor, @NonNull CellInfoCallback callback)6779 public void requestCellInfoUpdate(@NonNull WorkSource workSource, 6780 @NonNull @CallbackExecutor Executor executor, @NonNull CellInfoCallback callback) { 6781 try { 6782 ITelephony telephony = getITelephony(); 6783 if (telephony == null) { 6784 if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) { 6785 throw new IllegalStateException("Telephony is null"); 6786 } else { 6787 return; 6788 } 6789 } 6790 6791 telephony.requestCellInfoUpdateWithWorkSource( 6792 getSubId(), 6793 new ICellInfoCallback.Stub() { 6794 @Override 6795 public void onCellInfo(List<CellInfo> cellInfo) { 6796 final long identity = Binder.clearCallingIdentity(); 6797 try { 6798 executor.execute(() -> callback.onCellInfo(cellInfo)); 6799 } finally { 6800 Binder.restoreCallingIdentity(identity); 6801 } 6802 6803 } 6804 6805 @Override 6806 public void onError(int errorCode, String exceptionName, String message) { 6807 final long identity = Binder.clearCallingIdentity(); 6808 try { 6809 executor.execute(() -> callback.onError( 6810 errorCode, 6811 createThrowableByClassName(exceptionName, message))); 6812 } finally { 6813 Binder.restoreCallingIdentity(identity); 6814 } 6815 } 6816 }, getOpPackageName(), getAttributionTag(), workSource); 6817 } catch (RemoteException ex) { 6818 runOnBackgroundThread(() -> executor.execute( 6819 () -> callback.onError(CellInfoCallback.ERROR_MODEM_ERROR, ex))); 6820 } 6821 } 6822 createThrowableByClassName(String className, String message)6823 private static Throwable createThrowableByClassName(String className, String message) { 6824 if (className == null) { 6825 return null; 6826 } 6827 try { 6828 Class<?> c = Class.forName(className); 6829 return (Throwable) c.getConstructor(String.class).newInstance(message); 6830 } catch (ReflectiveOperationException | ClassCastException e) { 6831 } 6832 return new RuntimeException(className + ": " + message); 6833 } 6834 6835 /** 6836 * Sets the minimum time in milli-seconds between {@link PhoneStateListener#onCellInfoChanged 6837 * PhoneStateListener.onCellInfoChanged} will be invoked. 6838 *<p> 6839 * The default, 0, means invoke onCellInfoChanged when any of the reported 6840 * information changes. Setting the value to INT_MAX(0x7fffffff) means never issue 6841 * A onCellInfoChanged. 6842 *<p> 6843 * @param rateInMillis the rate 6844 * 6845 * @hide 6846 */ setCellInfoListRate(int rateInMillis)6847 public void setCellInfoListRate(int rateInMillis) { 6848 try { 6849 ITelephony telephony = getITelephony(); 6850 if (telephony != null) 6851 telephony.setCellInfoListRate(rateInMillis); 6852 } catch (RemoteException ex) { 6853 } catch (NullPointerException ex) { 6854 } 6855 } 6856 6857 /** 6858 * Returns the MMS user agent. 6859 */ 6860 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING) getMmsUserAgent()6861 public String getMmsUserAgent() { 6862 try { 6863 ITelephony telephony = getITelephony(); 6864 if (telephony != null) { 6865 return telephony.getMmsUserAgent(getSubId()); 6866 } 6867 } catch (RemoteException ex) { 6868 } catch (NullPointerException ex) { 6869 } 6870 return null; 6871 } 6872 6873 /** 6874 * Returns the MMS user agent profile URL. 6875 */ 6876 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING) getMmsUAProfUrl()6877 public String getMmsUAProfUrl() { 6878 try { 6879 ITelephony telephony = getITelephony(); 6880 if (telephony != null) { 6881 return telephony.getMmsUAProfUrl(getSubId()); 6882 } 6883 } catch (RemoteException ex) { 6884 } catch (NullPointerException ex) { 6885 } 6886 return null; 6887 } 6888 6889 /** 6890 * Get the first active portIndex from the corresponding physical slot index. 6891 * @param physicalSlotIndex physical slot index 6892 * @return first active port index or INVALID_PORT_INDEX if no port is active 6893 */ getFirstActivePortIndex(int physicalSlotIndex)6894 private int getFirstActivePortIndex(int physicalSlotIndex) { 6895 UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); 6896 if (slotInfos != null && physicalSlotIndex >= 0 && physicalSlotIndex < slotInfos.length 6897 && slotInfos[physicalSlotIndex] != null) { 6898 Optional<UiccPortInfo> result = slotInfos[physicalSlotIndex].getPorts().stream() 6899 .filter(portInfo -> portInfo.isActive()).findFirst(); 6900 if (result.isPresent()) { 6901 return result.get().getPortIndex(); 6902 } 6903 } 6904 return INVALID_PORT_INDEX; 6905 } 6906 6907 /** 6908 * Opens a logical channel to the ICC card. 6909 * 6910 * Input parameters equivalent to TS 27.007 AT+CCHO 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 AID Application id. See ETSI 102.221 and 101.220. 6917 * @return an IccOpenLogicalChannelResponse object. 6918 * @deprecated Replaced by {@link #iccOpenLogicalChannel(String, int)} 6919 */ 6920 @Deprecated iccOpenLogicalChannel(String AID)6921 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID) { 6922 return iccOpenLogicalChannel(getSubId(), AID, -1); 6923 } 6924 6925 /** 6926 * Opens a logical channel to the ICC card using the physical slot index. 6927 * 6928 * Use this method when no subscriptions are available on the SIM and the operation must be 6929 * performed using the physical slot index. 6930 * 6931 * This operation wraps two APDU instructions: 6932 * <ul> 6933 * <li>MANAGE CHANNEL to open a logical channel</li> 6934 * <li>SELECT the given {@code AID} using the given {@code p2}</li> 6935 * </ul> 6936 * 6937 * Per Open Mobile API Specification v3.2 section 6.2.7.h, only p2 values of 0x00, 0x04, 0x08, 6938 * and 0x0C are guaranteed to be supported. 6939 * 6940 * If the SELECT command's status word is not '9000', '62xx', or '63xx', the status word will be 6941 * considered an error and the channel shall not be opened. 6942 * 6943 * Input parameters equivalent to TS 27.007 AT+CCHO command. 6944 * 6945 * <p>Requires Permission: 6946 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 6947 * 6948 * @param slotIndex the physical slot index of the ICC card 6949 * @param aid Application id. See ETSI 102.221 and 101.220. 6950 * @param p2 P2 parameter (described in ISO 7816-4). 6951 * @return an IccOpenLogicalChannelResponse object. 6952 * @hide 6953 * @deprecated This API is not compatible on eUICC supporting Multiple Enabled Profile(MEP), 6954 * instead use {@link #iccOpenLogicalChannelByPort(int, int, String, int)} 6955 */ 6956 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 6957 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) 6958 @SystemApi 6959 @Nullable 6960 @Deprecated iccOpenLogicalChannelBySlot(int slotIndex, @Nullable String aid, int p2)6961 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(int slotIndex, 6962 @Nullable String aid, int p2) { 6963 try { 6964 ITelephony telephony = getITelephony(); 6965 if (telephony != null) { 6966 IccLogicalChannelRequest request = new IccLogicalChannelRequest(); 6967 request.slotIndex = slotIndex; 6968 request.portIndex = getFirstActivePortIndex(slotIndex); 6969 request.aid = aid; 6970 request.p2 = p2; 6971 request.callingPackage = getOpPackageName(); 6972 request.binder = new Binder(); 6973 return telephony.iccOpenLogicalChannel(request); 6974 } 6975 } catch (RemoteException ex) { 6976 } catch (NullPointerException ex) { 6977 } 6978 return null; 6979 } 6980 6981 /** 6982 * Opens a logical channel to the ICC card using the physical slot index and port index. 6983 * 6984 * Use this method when no subscriptions are available on the SIM and the operation must be 6985 * performed using the physical slot index and port index. 6986 * 6987 * This operation wraps two APDU instructions: 6988 * <ul> 6989 * <li>MANAGE CHANNEL to open a logical channel</li> 6990 * <li>SELECT the given {@code AID} using the given {@code p2}</li> 6991 * </ul> 6992 * 6993 * Per Open Mobile API Specification v3.2 section 6.2.7.h, only p2 values of 0x00, 0x04, 0x08, 6994 * and 0x0C are guaranteed to be supported. 6995 * 6996 * If the SELECT command's status word is not '9000', '62xx', or '63xx', the status word will be 6997 * considered an error and the channel shall not be opened. 6998 * 6999 * Input parameters equivalent to TS 27.007 AT+CCHO command. 7000 * 7001 * @param slotIndex the physical slot index of the ICC card 7002 * @param portIndex The port index is an enumeration of the ports available on the UICC. 7003 * Use {@link UiccPortInfo#getPortIndex()} to get portIndex. 7004 * @param aid Application id. See ETSI 102.221 and 101.220. 7005 * @param p2 P2 parameter (described in ISO 7816-4). 7006 * @return an IccOpenLogicalChannelResponse object. 7007 * @hide 7008 */ 7009 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 7010 @SystemApi 7011 @NonNull iccOpenLogicalChannelByPort(int slotIndex, int portIndex, @Nullable String aid, int p2)7012 public IccOpenLogicalChannelResponse iccOpenLogicalChannelByPort(int slotIndex, 7013 int portIndex, @Nullable String aid, int p2) { 7014 try { 7015 ITelephony telephony = getITelephony(); 7016 if (telephony != null) { 7017 IccLogicalChannelRequest request = new IccLogicalChannelRequest(); 7018 request.slotIndex = slotIndex; 7019 request.portIndex = portIndex; 7020 request.aid = aid; 7021 request.p2 = p2; 7022 request.callingPackage = getOpPackageName(); 7023 request.binder = new Binder(); 7024 return telephony.iccOpenLogicalChannel(request); 7025 } else { 7026 throw new IllegalStateException("telephony service is null."); 7027 } 7028 } catch (RemoteException ex) { 7029 throw ex.rethrowAsRuntimeException(); 7030 } 7031 } 7032 7033 /** 7034 * Opens a logical channel to the ICC card. 7035 * 7036 * This operation wraps two APDU instructions: 7037 * <ul> 7038 * <li>MANAGE CHANNEL to open a logical channel</li> 7039 * <li>SELECT the given {@code AID} using the given {@code p2}</li> 7040 * </ul> 7041 * 7042 * Per Open Mobile API Specification v3.2 section 6.2.7.h, only p2 values of 0x00, 0x04, 0x08, 7043 * and 0x0C are guaranteed to be supported. 7044 * 7045 * If the SELECT command's status word is not '9000', '62xx', or '63xx', the status word will be 7046 * considered an error and the channel shall not be opened. 7047 * 7048 * Input parameters equivalent to TS 27.007 AT+CCHO command. 7049 * 7050 * It is strongly recommended that callers of this should firstly create a new TelephonyManager 7051 * instance by calling {@link TelephonyManager#createForSubscriptionId(int)}. Failure to do so 7052 * can result in unpredictable and detrimental behavior like callers can end up talking to the 7053 * wrong SIM card. 7054 * 7055 * <p>Requires Permission: 7056 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7057 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7058 * 7059 * @param AID Application id. See ETSI 102.221 and 101.220. 7060 * @param p2 P2 parameter (described in ISO 7816-4). 7061 * @return an IccOpenLogicalChannelResponse object. 7062 */ 7063 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) iccOpenLogicalChannel(String AID, int p2)7064 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(String AID, int p2) { 7065 return iccOpenLogicalChannel(getSubId(), AID, p2); 7066 } 7067 7068 /** 7069 * Opens a logical channel to the ICC card. 7070 * 7071 * This operation wraps two APDU instructions: 7072 * <ul> 7073 * <li>MANAGE CHANNEL to open a logical channel</li> 7074 * <li>SELECT the given {@code AID} using the given {@code p2}</li> 7075 * </ul> 7076 * 7077 * Per Open Mobile API Specification v3.2 section 6.2.7.h, only p2 values of 0x00, 0x04, 0x08, 7078 * and 0x0C are guaranteed to be supported. 7079 * 7080 * If the SELECT command's status word is not '9000', '62xx', or '63xx', the status word will be 7081 * considered an error and the channel shall not be opened. 7082 * 7083 * Input parameters equivalent to TS 27.007 AT+CCHO command. 7084 * 7085 * <p>Requires Permission: 7086 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7087 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7088 * 7089 * @param subId The subscription to use. 7090 * @param AID Application id. See ETSI 102.221 and 101.220. 7091 * @param p2 P2 parameter (described in ISO 7816-4). 7092 * @return an IccOpenLogicalChannelResponse object. 7093 * @hide 7094 */ iccOpenLogicalChannel(int subId, String AID, int p2)7095 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(int subId, String AID, int p2) { 7096 try { 7097 ITelephony telephony = getITelephony(); 7098 if (telephony != null) { 7099 IccLogicalChannelRequest request = new IccLogicalChannelRequest(); 7100 request.subId = subId; 7101 request.callingPackage = getOpPackageName(); 7102 request.aid = AID; 7103 request.p2 = p2; 7104 request.binder = new Binder(); 7105 return telephony.iccOpenLogicalChannel(request); 7106 } 7107 } catch (RemoteException ex) { 7108 } catch (NullPointerException ex) { 7109 } 7110 return null; 7111 } 7112 7113 /** 7114 * Closes a previously opened logical channel to the ICC card using the physical slot index. 7115 * 7116 * Use this method when no subscriptions are available on the SIM and the operation must be 7117 * performed using the physical slot index. 7118 * 7119 * Input parameters equivalent to TS 27.007 AT+CCHC command. 7120 * 7121 * <p>Requires Permission: 7122 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 7123 * 7124 * @param slotIndex the physical slot index of the ICC card 7125 * @param channel is the channel id to be closed as returned by a successful 7126 * iccOpenLogicalChannel. 7127 * @return true if the channel was closed successfully. 7128 * @hide 7129 * @deprecated This API is not compatible on eUICC supporting Multiple Enabled Profile(MEP), 7130 * instead use {@link #iccCloseLogicalChannelByPort(int, int, int)} 7131 */ 7132 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 7133 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) 7134 @SystemApi 7135 @Deprecated iccCloseLogicalChannelBySlot(int slotIndex, int channel)7136 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { 7137 try { 7138 ITelephony telephony = getITelephony(); 7139 if (telephony != null) { 7140 IccLogicalChannelRequest request = new IccLogicalChannelRequest(); 7141 request.slotIndex = slotIndex; 7142 request.portIndex = getFirstActivePortIndex(slotIndex); 7143 request.channel = channel; 7144 return telephony.iccCloseLogicalChannel(request); 7145 } 7146 } catch (RemoteException ex) { 7147 } catch (NullPointerException ex) { 7148 } catch (IllegalStateException ex) { 7149 Rlog.e(TAG, "iccCloseLogicalChannel IllegalStateException", ex); 7150 } 7151 return false; 7152 } 7153 7154 /** 7155 * Closes a previously opened logical channel to the ICC card using the physical slot index and 7156 * port index. 7157 * 7158 * Use this method when no subscriptions are available on the SIM and the operation must be 7159 * performed using the physical slot index and port index. 7160 * 7161 * Input parameters equivalent to TS 27.007 AT+CCHC command. 7162 * 7163 * @param slotIndex the physical slot index of the ICC card 7164 * @param portIndex The port index is an enumeration of the ports available on the UICC. 7165 * Use {@link UiccPortInfo#getPortIndex()} to get portIndex. 7166 * @param channel is the channel id to be closed as returned by a successful 7167 * iccOpenLogicalChannel. 7168 * 7169 * @throws IllegalStateException if the Telephony process is not currently available or modem 7170 * currently can't process this command. 7171 * @throws IllegalArgumentException if invalid arguments are passed. 7172 * @hide 7173 */ 7174 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 7175 @SystemApi iccCloseLogicalChannelByPort(int slotIndex, int portIndex, int channel)7176 public void iccCloseLogicalChannelByPort(int slotIndex, int portIndex, int channel) { 7177 try { 7178 ITelephony telephony = getITelephony(); 7179 if (telephony != null) { 7180 IccLogicalChannelRequest request = new IccLogicalChannelRequest(); 7181 request.slotIndex = slotIndex; 7182 request.portIndex = portIndex; 7183 request.channel = channel; 7184 telephony.iccCloseLogicalChannel(request); 7185 } else { 7186 throw new IllegalStateException("telephony service is null."); 7187 } 7188 } catch (RemoteException ex) { 7189 throw ex.rethrowAsRuntimeException(); 7190 } 7191 } 7192 7193 /** 7194 * Closes a previously opened logical channel to the ICC card. 7195 * 7196 * Input parameters equivalent to TS 27.007 AT+CCHC command. 7197 * It is strongly recommended that callers of this API should firstly create 7198 * new TelephonyManager instance by calling 7199 * {@link TelephonyManager#createForSubscriptionId(int)}. Failure to do so can result in 7200 * unpredictable and detrimental behavior like callers can end up talking to the wrong SIM card. 7201 * 7202 * <p>Requires Permission: 7203 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7204 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7205 * 7206 * @param channel is the channel id to be closed as returned by a successful 7207 * iccOpenLogicalChannel. 7208 * @return true if the channel was closed successfully. 7209 * @throws IllegalArgumentException if input parameters are wrong. e.g., invalid channel 7210 */ 7211 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) iccCloseLogicalChannel(int channel)7212 public boolean iccCloseLogicalChannel(int channel) { 7213 try { 7214 return iccCloseLogicalChannel(getSubId(), channel); 7215 } catch (IllegalStateException ex) { 7216 Rlog.e(TAG, "iccCloseLogicalChannel IllegalStateException", ex); 7217 } 7218 return false; 7219 } 7220 7221 /** 7222 * Closes a previously opened logical channel to the ICC card. 7223 * 7224 * Input parameters equivalent to TS 27.007 AT+CCHC command. 7225 * 7226 * <p>Requires Permission: 7227 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7228 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7229 * 7230 * @param subId The subscription to use. 7231 * @param channel is the channel id to be closed as returned by a successful 7232 * iccOpenLogicalChannel. 7233 * @return true if the channel was closed successfully. 7234 * @hide 7235 */ iccCloseLogicalChannel(int subId, int channel)7236 public boolean iccCloseLogicalChannel(int subId, int channel) { 7237 try { 7238 ITelephony telephony = getITelephony(); 7239 if (telephony != null) { 7240 IccLogicalChannelRequest request = new IccLogicalChannelRequest(); 7241 request.subId = subId; 7242 request.channel = channel; 7243 return telephony.iccCloseLogicalChannel(request); 7244 } 7245 } catch (RemoteException ex) { 7246 } catch (NullPointerException ex) { 7247 } catch (IllegalStateException ex) { 7248 Rlog.e(TAG, "iccCloseLogicalChannel IllegalStateException", ex); 7249 } 7250 return false; 7251 } 7252 7253 /** 7254 * Transmit an APDU to the ICC card over a logical channel using the physical slot index. 7255 * 7256 * Use this method when no subscriptions are available on the SIM and the operation must be 7257 * performed using the physical slot index. 7258 * 7259 * Input parameters equivalent to TS 27.007 AT+CGLA command. 7260 * 7261 * <p>Requires Permission: 7262 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 7263 * 7264 * @param slotIndex the physical slot index of the ICC card 7265 * @param channel is the channel id to be closed as returned by a successful 7266 * iccOpenLogicalChannel. 7267 * @param cla Class of the APDU command. 7268 * @param instruction Instruction of the APDU command. 7269 * @param p1 P1 value of the APDU command. 7270 * @param p2 P2 value of the APDU command. 7271 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 7272 * is sent to the SIM. 7273 * @param data Data to be sent with the APDU. 7274 * @return The APDU response from the ICC card with the status appended at the end, or null if 7275 * there is an issue connecting to the Telephony service. 7276 * @hide 7277 * @deprecated This API is not compatible on eUICC supporting Multiple Enabled Profile(MEP), 7278 * instead use 7279 * {@link #iccTransmitApduLogicalChannelByPort(int, int, int, int, int, int, int, int, String)} 7280 */ 7281 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 7282 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) 7283 @SystemApi 7284 @Nullable 7285 @Deprecated iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, int instruction, int p1, int p2, int p3, @Nullable String data)7286 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, 7287 int instruction, int p1, int p2, int p3, @Nullable String data) { 7288 try { 7289 ITelephony telephony = getITelephony(); 7290 if (telephony != null) { 7291 return telephony.iccTransmitApduLogicalChannelByPort(slotIndex, 7292 getFirstActivePortIndex(slotIndex), channel, cla, instruction, 7293 p1, p2, p3, data); 7294 } 7295 } catch (RemoteException ex) { 7296 } catch (NullPointerException ex) { 7297 } 7298 return null; 7299 } 7300 7301 /** 7302 * Transmit an APDU to the ICC card over a logical channel using the physical slot index. 7303 * 7304 * Use this method when no subscriptions are available on the SIM and the operation must be 7305 * performed using the physical slot index. 7306 * 7307 * Input parameters equivalent to TS 27.007 AT+CGLA command. 7308 * 7309 * @param slotIndex the physical slot index of the ICC card 7310 * @param portIndex The port index is an enumeration of the ports available on the UICC. 7311 * Use {@link UiccPortInfo#getPortIndex()} to get portIndex. 7312 * @param channel is the channel id to be closed as returned by a successful 7313 * iccOpenLogicalChannel. 7314 * @param cla Class of the APDU command. 7315 * @param instruction Instruction of the APDU command. 7316 * @param p1 P1 value of the APDU command. 7317 * @param p2 P2 value of the APDU command. 7318 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 7319 * is sent to the SIM. 7320 * @param data Data to be sent with the APDU. 7321 * @return The APDU response from the ICC card with the status appended at the end, or null if 7322 * there is an issue connecting to the Telephony service. 7323 * @hide 7324 */ 7325 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 7326 @SystemApi 7327 @NonNull iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, int cla, int instruction, int p1, int p2, int p3, @Nullable String data)7328 public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, 7329 int cla, int instruction, int p1, int p2, int p3, @Nullable String data) { 7330 String response; 7331 try { 7332 ITelephony telephony = getITelephony(); 7333 if (telephony != null) { 7334 response = telephony.iccTransmitApduLogicalChannelByPort(slotIndex, portIndex, 7335 channel, cla, instruction, p1, p2, p3, data); 7336 } else { 7337 throw new IllegalStateException("telephony service is null."); 7338 } 7339 } catch (RemoteException ex) { 7340 throw ex.rethrowAsRuntimeException(); 7341 } 7342 return response; 7343 } 7344 7345 /** 7346 * Transmit an APDU to the ICC card over a logical channel. 7347 * 7348 * Input parameters equivalent to TS 27.007 AT+CGLA command. 7349 * 7350 * It is strongly recommended that callers of this API should firstly create a new 7351 * TelephonyManager instance by calling 7352 * {@link TelephonyManager#createForSubscriptionId(int)}. Failure to do so can result in 7353 * unpredictable and detrimental behavior like callers can end up talking to the wrong SIM card. 7354 * 7355 * <p>Requires Permission: 7356 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7357 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7358 * 7359 * @param channel is the channel id to be closed as returned by a successful 7360 * iccOpenLogicalChannel. 7361 * @param cla Class of the APDU command. 7362 * @param instruction Instruction of the APDU command. 7363 * @param p1 P1 value of the APDU command. 7364 * @param p2 P2 value of the APDU command. 7365 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 7366 * is sent to the SIM. 7367 * @param data Data to be sent with the APDU. 7368 * @return The APDU response from the ICC card with the status appended at 7369 * the end. 7370 */ 7371 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) iccTransmitApduLogicalChannel(int channel, int cla, int instruction, int p1, int p2, int p3, String data)7372 public String iccTransmitApduLogicalChannel(int channel, int cla, 7373 int instruction, int p1, int p2, int p3, String data) { 7374 return iccTransmitApduLogicalChannel(getSubId(), channel, cla, 7375 instruction, p1, p2, p3, data); 7376 } 7377 7378 /** 7379 * Transmit an APDU to the ICC card over a logical channel. 7380 * 7381 * Input parameters equivalent to TS 27.007 AT+CGLA command. 7382 * 7383 * <p>Requires Permission: 7384 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7385 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7386 * 7387 * @param subId The subscription to use. 7388 * @param channel is the channel id to be closed as returned by a successful 7389 * iccOpenLogicalChannel. 7390 * @param cla Class of the APDU command. 7391 * @param instruction Instruction of the APDU command. 7392 * @param p1 P1 value of the APDU command. 7393 * @param p2 P2 value of the APDU command. 7394 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 7395 * is sent to the SIM. 7396 * @param data Data to be sent with the APDU. 7397 * @return The APDU response from the ICC card with the status appended at 7398 * the end. 7399 * @hide 7400 */ iccTransmitApduLogicalChannel(int subId, int channel, int cla, int instruction, int p1, int p2, int p3, String data)7401 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, 7402 int instruction, int p1, int p2, int p3, String data) { 7403 try { 7404 ITelephony telephony = getITelephony(); 7405 if (telephony != null) 7406 return telephony.iccTransmitApduLogicalChannel(subId, channel, cla, 7407 instruction, p1, p2, p3, data); 7408 } catch (RemoteException ex) { 7409 } catch (NullPointerException ex) { 7410 } 7411 return ""; 7412 } 7413 7414 /** 7415 * Transmit an APDU to the ICC card over the basic channel using the physical slot index. 7416 * 7417 * Use this method when no subscriptions are available on the SIM and the operation must be 7418 * performed using the physical slot index. 7419 * 7420 * Input parameters equivalent to TS 27.007 AT+CSIM command. 7421 * 7422 * <p>Requires Permission: 7423 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 7424 * 7425 * @param slotIndex the physical slot index of the ICC card to target 7426 * @param cla Class of the APDU command. 7427 * @param instruction Instruction of the APDU command. 7428 * @param p1 P1 value of the APDU command. 7429 * @param p2 P2 value of the APDU command. 7430 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 7431 * is sent to the SIM. 7432 * @param data Data to be sent with the APDU. 7433 * @return The APDU response from the ICC card with the status appended at 7434 * the end. 7435 * @hide 7436 * @deprecated This API is not compatible on eUICC supporting Multiple Enabled Profile(MEP), 7437 * instead use 7438 * {@link #iccTransmitApduBasicChannelByPort(int, int, int, int, int, int, int, String)} 7439 */ 7440 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 7441 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) 7442 @SystemApi 7443 @NonNull 7444 @Deprecated iccTransmitApduBasicChannelBySlot(int slotIndex, int cla, int instruction, int p1, int p2, int p3, @Nullable String data)7445 public String iccTransmitApduBasicChannelBySlot(int slotIndex, int cla, int instruction, int p1, 7446 int p2, int p3, @Nullable String data) { 7447 try { 7448 ITelephony telephony = getITelephony(); 7449 if (telephony != null) { 7450 return telephony.iccTransmitApduBasicChannelByPort(slotIndex, 7451 getFirstActivePortIndex(slotIndex), getOpPackageName(), 7452 cla, instruction, p1, p2, p3, data); 7453 } 7454 } catch (RemoteException ex) { 7455 } catch (NullPointerException ex) { 7456 } 7457 return null; 7458 } 7459 7460 /** 7461 * Transmit an APDU to the ICC card over the basic channel using the physical slot index. 7462 * 7463 * Use this method when no subscriptions are available on the SIM and the operation must be 7464 * performed using the physical slot index. 7465 * 7466 * Input parameters equivalent to TS 27.007 AT+CSIM command. 7467 * 7468 * @param slotIndex the physical slot index of the ICC card to target 7469 * @param portIndex The port index is an enumeration of the ports available on the UICC. 7470 * Use {@link UiccPortInfo#getPortIndex()} to get portIndex. 7471 * @param cla Class of the APDU command. 7472 * @param instruction Instruction of the APDU command. 7473 * @param p1 P1 value of the APDU command. 7474 * @param p2 P2 value of the APDU command. 7475 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 7476 * is sent to the SIM. 7477 * @param data Data to be sent with the APDU. 7478 * @return The APDU response from the ICC card with the status appended at 7479 * the end. 7480 * @hide 7481 */ 7482 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 7483 @SystemApi 7484 @NonNull iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, int cla, int instruction, int p1, int p2, int p3, @Nullable String data)7485 public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, int cla, 7486 int instruction, int p1, int p2, int p3, @Nullable String data) { 7487 String response; 7488 try { 7489 ITelephony telephony = getITelephony(); 7490 if (telephony != null) { 7491 response = telephony.iccTransmitApduBasicChannelByPort(slotIndex, portIndex, 7492 getOpPackageName(), cla, instruction, p1, p2, p3, data); 7493 } else { 7494 throw new IllegalStateException("telephony service is null."); 7495 } 7496 } catch (RemoteException ex) { 7497 throw ex.rethrowAsRuntimeException(); 7498 } 7499 return response; 7500 } 7501 /** 7502 * Transmit an APDU to the ICC card over the basic channel. 7503 * 7504 * Input parameters equivalent to TS 27.007 AT+CSIM command. 7505 * 7506 * <p>Requires Permission: 7507 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7508 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7509 * 7510 * @param cla Class of the APDU command. 7511 * @param instruction Instruction of the APDU command. 7512 * @param p1 P1 value of the APDU command. 7513 * @param p2 P2 value of the APDU command. 7514 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 7515 * is sent to the SIM. 7516 * @param data Data to be sent with the APDU. 7517 * @return The APDU response from the ICC card with the status appended at 7518 * the end. 7519 */ 7520 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) iccTransmitApduBasicChannel(int cla, int instruction, int p1, int p2, int p3, String data)7521 public String iccTransmitApduBasicChannel(int cla, 7522 int instruction, int p1, int p2, int p3, String data) { 7523 return iccTransmitApduBasicChannel(getSubId(), cla, 7524 instruction, p1, p2, p3, data); 7525 } 7526 7527 /** 7528 * Transmit an APDU to the ICC card over the basic channel. 7529 * 7530 * Input parameters equivalent to TS 27.007 AT+CSIM command. 7531 * 7532 * <p>Requires Permission: 7533 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7534 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7535 * 7536 * @param subId The subscription to use. 7537 * @param cla Class of the APDU command. 7538 * @param instruction Instruction of the APDU command. 7539 * @param p1 P1 value of the APDU command. 7540 * @param p2 P2 value of the APDU command. 7541 * @param p3 P3 value of the APDU command. If p3 is negative a 4 byte APDU 7542 * is sent to the SIM. 7543 * @param data Data to be sent with the APDU. 7544 * @return The APDU response from the ICC card with the status appended at 7545 * the end. 7546 * @hide 7547 */ iccTransmitApduBasicChannel(int subId, int cla, int instruction, int p1, int p2, int p3, String data)7548 public String iccTransmitApduBasicChannel(int subId, int cla, 7549 int instruction, int p1, int p2, int p3, String data) { 7550 try { 7551 ITelephony telephony = getITelephony(); 7552 if (telephony != null) 7553 return telephony.iccTransmitApduBasicChannel(subId, getOpPackageName(), cla, 7554 instruction, p1, p2, p3, data); 7555 } catch (RemoteException ex) { 7556 } catch (NullPointerException ex) { 7557 } 7558 return ""; 7559 } 7560 7561 /** 7562 * Returns the response APDU for a command APDU sent through SIM_IO. 7563 * 7564 * <p>Requires Permission: 7565 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7566 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7567 * 7568 * @param fileID 7569 * @param command 7570 * @param p1 P1 value of the APDU command. 7571 * @param p2 P2 value of the APDU command. 7572 * @param p3 P3 value of the APDU command. 7573 * @param filePath 7574 * @return The APDU response. 7575 */ 7576 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, String filePath)7577 public byte[] iccExchangeSimIO(int fileID, int command, int p1, int p2, int p3, 7578 String filePath) { 7579 return iccExchangeSimIO(getSubId(), fileID, command, p1, p2, p3, filePath); 7580 } 7581 7582 /** 7583 * Returns the response APDU for a command APDU sent through SIM_IO. 7584 * 7585 * <p>Requires Permission: 7586 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7587 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7588 * 7589 * @param subId The subscription to use. 7590 * @param fileID 7591 * @param command 7592 * @param p1 P1 value of the APDU command. 7593 * @param p2 P2 value of the APDU command. 7594 * @param p3 P3 value of the APDU command. 7595 * @param filePath 7596 * @return The APDU response. 7597 * @hide 7598 */ iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3, String filePath)7599 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, 7600 int p3, String filePath) { 7601 try { 7602 ITelephony telephony = getITelephony(); 7603 if (telephony != null) 7604 return telephony.iccExchangeSimIO(subId, fileID, command, p1, p2, p3, filePath); 7605 } catch (RemoteException ex) { 7606 } catch (NullPointerException ex) { 7607 } 7608 return null; 7609 } 7610 7611 /** 7612 * Send ENVELOPE to the SIM and return the response. 7613 * 7614 * <p>Requires Permission: 7615 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7616 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7617 * 7618 * @param content String containing SAT/USAT response in hexadecimal 7619 * format starting with command tag. See TS 102 223 for 7620 * details. 7621 * @return The APDU response from the ICC card in hexadecimal format 7622 * with the last 4 bytes being the status word. If the command fails, 7623 * returns an empty string. 7624 */ 7625 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) sendEnvelopeWithStatus(String content)7626 public String sendEnvelopeWithStatus(String content) { 7627 return sendEnvelopeWithStatus(getSubId(), content); 7628 } 7629 7630 /** 7631 * Send ENVELOPE to the SIM and return the response. 7632 * 7633 * <p>Requires Permission: 7634 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7635 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7636 * 7637 * @param subId The subscription to use. 7638 * @param content String containing SAT/USAT response in hexadecimal 7639 * format starting with command tag. See TS 102 223 for 7640 * details. 7641 * @return The APDU response from the ICC card in hexadecimal format 7642 * with the last 4 bytes being the status word. If the command fails, 7643 * returns an empty string. 7644 * @hide 7645 */ sendEnvelopeWithStatus(int subId, String content)7646 public String sendEnvelopeWithStatus(int subId, String content) { 7647 try { 7648 ITelephony telephony = getITelephony(); 7649 if (telephony != null) 7650 return telephony.sendEnvelopeWithStatus(subId, content); 7651 } catch (RemoteException ex) { 7652 } catch (NullPointerException ex) { 7653 } 7654 return ""; 7655 } 7656 7657 /** 7658 * Read one of the NV items defined in com.android.internal.telephony.RadioNVItems. 7659 * Used for device configuration by some CDMA operators. 7660 * 7661 * <p>Requires Permission: 7662 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7663 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7664 * 7665 * @param itemID the ID of the item to read. 7666 * @return the NV item as a String, or null on any failure. 7667 * 7668 * @hide 7669 */ 7670 @UnsupportedAppUsage nvReadItem(int itemID)7671 public String nvReadItem(int itemID) { 7672 try { 7673 ITelephony telephony = getITelephony(); 7674 if (telephony != null) 7675 return telephony.nvReadItem(itemID); 7676 } catch (RemoteException ex) { 7677 Rlog.e(TAG, "nvReadItem RemoteException", ex); 7678 } catch (NullPointerException ex) { 7679 Rlog.e(TAG, "nvReadItem NPE", ex); 7680 } 7681 return ""; 7682 } 7683 7684 /** 7685 * Write one of the NV items defined in com.android.internal.telephony.RadioNVItems. 7686 * Used for device configuration by some CDMA operators. 7687 * 7688 * <p>Requires Permission: 7689 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7690 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7691 * 7692 * @param itemID the ID of the item to read. 7693 * @param itemValue the value to write, as a String. 7694 * @return true on success; false on any failure. 7695 * 7696 * @hide 7697 */ nvWriteItem(int itemID, String itemValue)7698 public boolean nvWriteItem(int itemID, String itemValue) { 7699 try { 7700 ITelephony telephony = getITelephony(); 7701 if (telephony != null) 7702 return telephony.nvWriteItem(itemID, itemValue); 7703 } catch (RemoteException ex) { 7704 Rlog.e(TAG, "nvWriteItem RemoteException", ex); 7705 } catch (NullPointerException ex) { 7706 Rlog.e(TAG, "nvWriteItem NPE", ex); 7707 } 7708 return false; 7709 } 7710 7711 /** 7712 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. 7713 * Used for device configuration by some CDMA operators. 7714 * 7715 * <p>Requires Permission: 7716 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7717 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7718 * 7719 * @param preferredRoamingList byte array containing the new PRL. 7720 * @return true on success; false on any failure. 7721 * 7722 * @hide 7723 */ nvWriteCdmaPrl(byte[] preferredRoamingList)7724 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { 7725 try { 7726 ITelephony telephony = getITelephony(); 7727 if (telephony != null) 7728 return telephony.nvWriteCdmaPrl(preferredRoamingList); 7729 } catch (RemoteException ex) { 7730 Rlog.e(TAG, "nvWriteCdmaPrl RemoteException", ex); 7731 } catch (NullPointerException ex) { 7732 Rlog.e(TAG, "nvWriteCdmaPrl NPE", ex); 7733 } 7734 return false; 7735 } 7736 7737 /** 7738 * Perform the specified type of NV config reset. The radio will be taken offline 7739 * and the device must be rebooted after the operation. Used for device 7740 * configuration by some CDMA operators. 7741 * 7742 * <p>Requires Permission: 7743 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7744 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7745 * 7746 * TODO: remove this one. use {@link #rebootModem()} for reset type 1 and 7747 * {@link #resetRadioConfig()} for reset type 3 7748 * 7749 * @param resetType reset type: 1: reload NV reset, 2: erase NV reset, 3: factory NV reset 7750 * @return true on success; false on any failure. 7751 * 7752 * @hide 7753 */ 7754 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) nvResetConfig(int resetType)7755 public boolean nvResetConfig(int resetType) { 7756 try { 7757 ITelephony telephony = getITelephony(); 7758 if (telephony != null) { 7759 if (resetType == 1 /*1: reload NV reset */) { 7760 return telephony.rebootModem(getSlotIndex()); 7761 } else if (resetType == 3 /*3: factory NV reset */) { 7762 return telephony.resetModemConfig(getSlotIndex()); 7763 } else { 7764 Rlog.e(TAG, "nvResetConfig unsupported reset type"); 7765 } 7766 } 7767 } catch (RemoteException ex) { 7768 Rlog.e(TAG, "nvResetConfig RemoteException", ex); 7769 } catch (NullPointerException ex) { 7770 Rlog.e(TAG, "nvResetConfig NPE", ex); 7771 } 7772 return false; 7773 } 7774 7775 /** 7776 * Rollback modem configurations to factory default except some config which are in whitelist. 7777 * Used for device configuration by some carriers. 7778 * 7779 * <p>Requires Permission: 7780 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7781 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7782 * 7783 * @return {@code true} on success; {@code false} on any failure. 7784 * 7785 * @hide 7786 */ 7787 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 7788 @SystemApi 7789 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) resetRadioConfig()7790 public boolean resetRadioConfig() { 7791 try { 7792 ITelephony telephony = getITelephony(); 7793 if (telephony != null) { 7794 return telephony.resetModemConfig(getSlotIndex()); 7795 } 7796 } catch (RemoteException ex) { 7797 Rlog.e(TAG, "resetRadioConfig RemoteException", ex); 7798 } catch (NullPointerException ex) { 7799 Rlog.e(TAG, "resetRadioConfig NPE", ex); 7800 } 7801 return false; 7802 } 7803 7804 /** 7805 * Generate a radio modem reset. Used for device configuration by some carriers. 7806 * 7807 * <p>Requires Permission: 7808 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7809 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7810 * 7811 * @return {@code true} on success; {@code false} on any failure. 7812 * 7813 * @deprecated Using {@link #rebootModem()} instead. 7814 * 7815 * @hide 7816 */ 7817 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 7818 @SystemApi 7819 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) rebootRadio()7820 public boolean rebootRadio() { 7821 try { 7822 ITelephony telephony = getITelephony(); 7823 if (telephony != null) { 7824 return telephony.rebootModem(getSlotIndex()); 7825 } 7826 } catch (RemoteException ex) { 7827 Rlog.e(TAG, "rebootRadio RemoteException", ex); 7828 } catch (NullPointerException ex) { 7829 Rlog.e(TAG, "rebootRadio NPE", ex); 7830 } 7831 return false; 7832 } 7833 7834 /** 7835 * Generate a radio modem reset. Used for device configuration by some carriers. 7836 * 7837 * <p>Requires Permission: 7838 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 7839 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 7840 * @throws IllegalStateException if the Telephony process is not currently available. 7841 * @throws RuntimeException 7842 */ 7843 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 7844 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) rebootModem()7845 public void rebootModem() { 7846 try { 7847 ITelephony telephony = getITelephony(); 7848 if (telephony == null) { 7849 throw new IllegalStateException("telephony service is null."); 7850 } 7851 telephony.rebootModem(getSlotIndex()); 7852 } catch (RemoteException ex) { 7853 Rlog.e(TAG, "rebootRadio RemoteException", ex); 7854 throw ex.rethrowAsRuntimeException(); 7855 } 7856 } 7857 7858 /** 7859 * Return an appropriate subscription ID for any situation. 7860 * 7861 * If this object has been created with {@link #createForSubscriptionId}, then the provided 7862 * subscription ID is returned. Otherwise, the default subscription ID will be returned. 7863 * 7864 */ 7865 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSubscriptionId()7866 public int getSubscriptionId() { 7867 return getSubId(); 7868 } 7869 7870 /** 7871 * Return an appropriate subscription ID for any situation. 7872 * 7873 * If this object has been created with {@link #createForSubscriptionId}, then the provided 7874 * subscription ID is returned. Otherwise, the default subscription ID will be returned. 7875 * 7876 */ getSubId()7877 private int getSubId() { 7878 if (SubscriptionManager.isUsableSubIdValue(mSubId)) { 7879 return mSubId; 7880 } 7881 return SubscriptionManager.getDefaultSubscriptionId(); 7882 } 7883 7884 /** 7885 * Return an appropriate subscription ID for any situation. 7886 * 7887 * If this object has been created with {@link #createForSubscriptionId}, then the provided 7888 * subId is returned. Otherwise, the preferred subId which is based on caller's context is 7889 * returned. 7890 * {@see SubscriptionManager#getDefaultDataSubscriptionId()} 7891 * {@see SubscriptionManager#getDefaultVoiceSubscriptionId()} 7892 * {@see SubscriptionManager#getDefaultSmsSubscriptionId()} 7893 */ 7894 @UnsupportedAppUsage getSubId(int preferredSubId)7895 private int getSubId(int preferredSubId) { 7896 if (SubscriptionManager.isUsableSubIdValue(mSubId)) { 7897 return mSubId; 7898 } 7899 return preferredSubId; 7900 } 7901 7902 /** 7903 * Return an appropriate phone ID for any situation. 7904 * 7905 * If this object has been created with {@link #createForSubscriptionId}, then the phoneId 7906 * associated with the provided subId is returned. Otherwise, the default phoneId associated 7907 * with the default subId will be returned. 7908 */ getPhoneId()7909 private int getPhoneId() { 7910 return SubscriptionManager.getPhoneId(getSubId()); 7911 } 7912 7913 /** 7914 * Return an appropriate phone ID for any situation. 7915 * 7916 * If this object has been created with {@link #createForSubscriptionId}, then the phoneId 7917 * associated with the provided subId is returned. Otherwise, return the phoneId associated 7918 * with the preferred subId based on caller's context. 7919 * {@see SubscriptionManager#getDefaultDataSubscriptionId()} 7920 * {@see SubscriptionManager#getDefaultVoiceSubscriptionId()} 7921 * {@see SubscriptionManager#getDefaultSmsSubscriptionId()} 7922 */ 7923 @UnsupportedAppUsage getPhoneId(int preferredSubId)7924 private int getPhoneId(int preferredSubId) { 7925 return SubscriptionManager.getPhoneId(getSubId(preferredSubId)); 7926 } 7927 7928 /** 7929 * Return an appropriate slot index for any situation. 7930 * 7931 * if this object has been created with {@link #createForSubscriptionId}, then the slot index 7932 * associated with the provided subId is returned. Otherwise, return the slot index associated 7933 * with the default subId. 7934 * If SIM is not inserted, return default SIM slot index. 7935 * 7936 * {@hide} 7937 */ 7938 @VisibleForTesting 7939 @UnsupportedAppUsage getSlotIndex()7940 public int getSlotIndex() { 7941 int slotIndex = SubscriptionManager.getSlotIndex(getSubId()); 7942 if (slotIndex == SubscriptionManager.SIM_NOT_INSERTED) { 7943 slotIndex = SubscriptionManager.DEFAULT_SIM_SLOT_INDEX; 7944 } 7945 return slotIndex; 7946 } 7947 7948 /** 7949 * Request that the next incoming call from a number matching {@code range} be intercepted. 7950 * 7951 * This API is intended for OEMs to provide a service for apps to verify the device's phone 7952 * number. When called, the Telephony stack will store the provided {@link PhoneNumberRange} and 7953 * intercept the next incoming call from a number that lies within the range, within a timeout 7954 * specified by {@code timeoutMillis}. 7955 * 7956 * If such a phone call is received, the caller will be notified via 7957 * {@link NumberVerificationCallback#onCallReceived(String)} on the provided {@link Executor}. 7958 * If verification fails for any reason, the caller will be notified via 7959 * {@link NumberVerificationCallback#onVerificationFailed(int)} 7960 * on the provided {@link Executor}. 7961 * 7962 * In addition to the {@link Manifest.permission#MODIFY_PHONE_STATE} permission, callers of this 7963 * API must also be listed in the device configuration as an authorized app in 7964 * {@code packages/services/Telephony/res/values/config.xml} under the 7965 * {@code config_number_verification_package_name} key. 7966 * 7967 * @hide 7968 * @param range The range of phone numbers the caller expects a phone call from. 7969 * @param timeoutMillis The amount of time to wait for such a call, or the value of 7970 * {@link #getMaxNumberVerificationTimeoutMillis()}, whichever is lesser. 7971 * @param executor The {@link Executor} that callbacks should be executed on. 7972 * @param callback The callback to use for delivering results. 7973 */ 7974 @SystemApi 7975 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 7976 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) requestNumberVerification(@onNull PhoneNumberRange range, long timeoutMillis, @NonNull @CallbackExecutor Executor executor, @NonNull NumberVerificationCallback callback)7977 public void requestNumberVerification(@NonNull PhoneNumberRange range, long timeoutMillis, 7978 @NonNull @CallbackExecutor Executor executor, 7979 @NonNull NumberVerificationCallback callback) { 7980 if (executor == null) { 7981 throw new NullPointerException("Executor must be non-null"); 7982 } 7983 if (callback == null) { 7984 throw new NullPointerException("Callback must be non-null"); 7985 } 7986 7987 INumberVerificationCallback internalCallback = new INumberVerificationCallback.Stub() { 7988 @Override 7989 public void onCallReceived(String phoneNumber) { 7990 final long identity = Binder.clearCallingIdentity(); 7991 try { 7992 executor.execute(() -> 7993 callback.onCallReceived(phoneNumber)); 7994 } finally { 7995 Binder.restoreCallingIdentity(identity); 7996 } 7997 } 7998 7999 @Override 8000 public void onVerificationFailed(int reason) { 8001 final long identity = Binder.clearCallingIdentity(); 8002 try { 8003 executor.execute(() -> 8004 callback.onVerificationFailed(reason)); 8005 } finally { 8006 Binder.restoreCallingIdentity(identity); 8007 } 8008 } 8009 }; 8010 8011 try { 8012 ITelephony telephony = getITelephony(); 8013 if (telephony == null) { 8014 if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) { 8015 throw new IllegalStateException("Telephony is null"); 8016 } else { 8017 return; 8018 } 8019 } 8020 8021 telephony.requestNumberVerification(range, timeoutMillis, internalCallback, 8022 getOpPackageName()); 8023 } catch (RemoteException ex) { 8024 Rlog.e(TAG, "requestNumberVerification RemoteException", ex); 8025 runOnBackgroundThread(() -> executor.execute( 8026 () -> callback.onVerificationFailed( 8027 NumberVerificationCallback.REASON_UNSPECIFIED))); 8028 } 8029 } 8030 8031 /** 8032 * Inserts or updates a list property. Expands the list if its length is not enough. 8033 */ updateTelephonyProperty(List<T> prop, int phoneId, T value)8034 private static <T> List<T> updateTelephonyProperty(List<T> prop, int phoneId, T value) { 8035 List<T> ret = new ArrayList<>(prop); 8036 while (ret.size() <= phoneId) ret.add(null); 8037 ret.set(phoneId, value); 8038 return ret; 8039 } 8040 /** 8041 * Convenience function for retrieving a value from the secure settings 8042 * value list as an integer. Note that internally setting values are 8043 * always stored as strings; this function converts the string to an 8044 * integer for you. 8045 * <p> 8046 * This version does not take a default value. If the setting has not 8047 * been set, or the string value is not a number, 8048 * it throws {@link SettingNotFoundException}. 8049 * 8050 * @param cr The ContentResolver to access. 8051 * @param name The name of the setting to retrieve. 8052 * @param index The index of the list 8053 * 8054 * @throws SettingNotFoundException Thrown if a setting by the given 8055 * name can't be found or the setting value is not an integer. 8056 * 8057 * @return The value at the given index of settings. 8058 * @hide 8059 */ 8060 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getIntAtIndex(android.content.ContentResolver cr, String name, int index)8061 public static int getIntAtIndex(android.content.ContentResolver cr, 8062 String name, int index) 8063 throws android.provider.Settings.SettingNotFoundException { 8064 String v = android.provider.Settings.Global.getString(cr, name); 8065 if (v != null) { 8066 String valArray[] = v.split(","); 8067 if ((index >= 0) && (index < valArray.length) && (valArray[index] != null)) { 8068 try { 8069 return Integer.parseInt(valArray[index]); 8070 } catch (NumberFormatException e) { 8071 //Log.e(TAG, "Exception while parsing Integer: ", e); 8072 } 8073 } 8074 } 8075 throw new android.provider.Settings.SettingNotFoundException(name); 8076 } 8077 8078 /** 8079 * Convenience function for updating settings value as coma separated 8080 * integer values. This will either create a new entry in the table if the 8081 * given name does not exist, or modify the value of the existing row 8082 * with that name. Note that internally setting values are always 8083 * stored as strings, so this function converts the given value to a 8084 * string before storing it. 8085 * 8086 * @param cr The ContentResolver to access. 8087 * @param name The name of the setting to modify. 8088 * @param index The index of the list 8089 * @param value The new value for the setting to be added to the list. 8090 * @return true if the value was set, false on database errors 8091 * @hide 8092 */ 8093 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) putIntAtIndex(android.content.ContentResolver cr, String name, int index, int value)8094 public static boolean putIntAtIndex(android.content.ContentResolver cr, 8095 String name, int index, int value) { 8096 String data = ""; 8097 String valArray[] = null; 8098 String v = android.provider.Settings.Global.getString(cr, name); 8099 8100 if (index == Integer.MAX_VALUE) { 8101 throw new IllegalArgumentException("putIntAtIndex index == MAX_VALUE index=" + index); 8102 } 8103 if (index < 0) { 8104 throw new IllegalArgumentException("putIntAtIndex index < 0 index=" + index); 8105 } 8106 if (v != null) { 8107 valArray = v.split(","); 8108 } 8109 8110 // Copy the elements from valArray till index 8111 for (int i = 0; i < index; i++) { 8112 String str = ""; 8113 if ((valArray != null) && (i < valArray.length)) { 8114 str = valArray[i]; 8115 } 8116 data = data + str + ","; 8117 } 8118 8119 data = data + value; 8120 8121 // Copy the remaining elements from valArray if any. 8122 if (valArray != null) { 8123 for (int i = index+1; i < valArray.length; i++) { 8124 data = data + "," + valArray[i]; 8125 } 8126 } 8127 return android.provider.Settings.Global.putString(cr, name, data); 8128 } 8129 8130 /** 8131 * Gets a per-phone telephony property from a property name. 8132 * 8133 * @hide 8134 */ 8135 @UnsupportedAppUsage getTelephonyProperty(int phoneId, String property, String defaultVal)8136 public static String getTelephonyProperty(int phoneId, String property, String defaultVal) { 8137 String propVal = null; 8138 String prop = SystemProperties.get(property); 8139 if ((prop != null) && (prop.length() > 0)) { 8140 String values[] = prop.split(","); 8141 if ((phoneId >= 0) && (phoneId < values.length) && (values[phoneId] != null)) { 8142 propVal = values[phoneId]; 8143 } 8144 } 8145 return propVal == null ? defaultVal : propVal; 8146 } 8147 8148 /** 8149 * Gets a typed per-phone telephony property from a schematized list property. 8150 */ getTelephonyProperty(int phoneId, List<T> prop, T defaultValue)8151 private static <T> T getTelephonyProperty(int phoneId, List<T> prop, T defaultValue) { 8152 T ret = null; 8153 if (phoneId >= 0 && phoneId < prop.size()) ret = prop.get(phoneId); 8154 return ret != null ? ret : defaultValue; 8155 } 8156 8157 /** 8158 * Gets a global telephony property. 8159 * 8160 * See also getTelephonyProperty(phoneId, property, defaultVal). Most telephony properties are 8161 * per-phone. 8162 * 8163 * @hide 8164 */ 8165 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getTelephonyProperty(String property, String defaultVal)8166 public static String getTelephonyProperty(String property, String defaultVal) { 8167 String propVal = SystemProperties.get(property); 8168 return TextUtils.isEmpty(propVal) ? defaultVal : propVal; 8169 } 8170 8171 /** @hide */ 8172 @UnsupportedAppUsage getSimCount()8173 public int getSimCount() { 8174 // FIXME Need to get it from Telephony Dev Controller when that gets implemented! 8175 // and then this method shouldn't be used at all! 8176 return getPhoneCount(); 8177 } 8178 8179 /** 8180 * Returns the IMS Service Table (IST) that was loaded from the ISIM. 8181 * 8182 * See 3GPP TS 31.103 (Section 4.2.7) for the definition and more information on this table. 8183 * 8184 * @return IMS Service Table or null if not present or not loaded 8185 * @hide 8186 */ 8187 @Nullable 8188 @SystemApi 8189 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 8190 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getIsimIst()8191 public String getIsimIst() { 8192 try { 8193 IPhoneSubInfo info = getSubscriberInfoService(); 8194 if (info == null) 8195 return null; 8196 //get the Isim Ist based on subId 8197 return info.getIsimIst(getSubId()); 8198 } catch (RemoteException ex) { 8199 return null; 8200 } catch (NullPointerException ex) { 8201 // This could happen before phone restarts due to crashing 8202 return null; 8203 } 8204 } 8205 8206 /** 8207 * Returns the IMS Proxy Call Session Control Function(PCSCF) that were loaded from the ISIM. 8208 * @return an array of PCSCF strings with one PCSCF per string, or null if 8209 * not present or not loaded 8210 * @hide 8211 */ 8212 @UnsupportedAppUsage getIsimPcscf()8213 public String[] getIsimPcscf() { 8214 try { 8215 IPhoneSubInfo info = getSubscriberInfoService(); 8216 if (info == null) 8217 return null; 8218 //get the Isim Pcscf based on subId 8219 return info.getIsimPcscf(getSubId()); 8220 } catch (RemoteException ex) { 8221 return null; 8222 } catch (NullPointerException ex) { 8223 // This could happen before phone restarts due to crashing 8224 return null; 8225 } 8226 } 8227 8228 /** UICC application type is unknown or not specified */ 8229 public static final int APPTYPE_UNKNOWN = PhoneConstants.APPTYPE_UNKNOWN; 8230 /** UICC application type is SIM */ 8231 public static final int APPTYPE_SIM = PhoneConstants.APPTYPE_SIM; 8232 /** UICC application type is USIM */ 8233 public static final int APPTYPE_USIM = PhoneConstants.APPTYPE_USIM; 8234 /** UICC application type is RUIM */ 8235 public static final int APPTYPE_RUIM = PhoneConstants.APPTYPE_RUIM; 8236 /** UICC application type is CSIM */ 8237 public static final int APPTYPE_CSIM = PhoneConstants.APPTYPE_CSIM; 8238 /** UICC application type is ISIM */ 8239 public static final int APPTYPE_ISIM = PhoneConstants.APPTYPE_ISIM; 8240 8241 // authContext (parameter P2) when doing UICC challenge, 8242 // per 3GPP TS 31.102 (Section 7.1.2) 8243 /** Authentication type for UICC challenge is EAP SIM. See RFC 4186 for details. */ 8244 public static final int AUTHTYPE_EAP_SIM = PhoneConstants.AUTH_CONTEXT_EAP_SIM; 8245 /** Authentication type for UICC challenge is EAP AKA. See RFC 4187 for details. */ 8246 public static final int AUTHTYPE_EAP_AKA = PhoneConstants.AUTH_CONTEXT_EAP_AKA; 8247 8248 /** 8249 * Returns the response of authentication for the default subscription. 8250 * Returns null if the authentication hasn't been successful 8251 * 8252 * <p>Requires one of the following permissions: 8253 * <ul> 8254 * <li>READ_PRIVILEGED_PHONE_STATE 8255 * <li>the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 8256 * <li>the calling app has been granted the 8257 * {@link Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} permission. 8258 * </ul> 8259 * 8260 * @param appType the icc application type, like {@link #APPTYPE_USIM} 8261 * @param authType the authentication type, {@link #AUTHTYPE_EAP_AKA} or 8262 * {@link #AUTHTYPE_EAP_SIM} 8263 * @param data authentication challenge data, base64 encoded. 8264 * See 3GPP TS 31.102 7.1.2 for more details. 8265 * @return the response of authentication. This value will be null in the following cases: 8266 * Authentication error, incorrect MAC 8267 * Authentication error, security context not supported 8268 * Key freshness failure 8269 * Authentication error, no memory space available 8270 * Authentication error, no memory space available in EFMUK 8271 */ 8272 // TODO(b/73660190): This should probably require MODIFY_PHONE_STATE, not 8273 // READ_PRIVILEGED_PHONE_STATE. It certainly shouldn't reference the permission in Javadoc since 8274 // it's not public API. 8275 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getIccAuthentication(int appType, int authType, String data)8276 public String getIccAuthentication(int appType, int authType, String data) { 8277 return getIccAuthentication(getSubId(), appType, authType, data); 8278 } 8279 8280 /** 8281 * Returns the response of USIM Authentication for specified subId. 8282 * Returns null if the authentication hasn't been successful 8283 * 8284 * <p>See {@link #getIccAuthentication(int, int, String)} for details on the required 8285 * permissions. 8286 * 8287 * @param subId subscription ID used for authentication 8288 * @param appType the icc application type, like {@link #APPTYPE_USIM} 8289 * @param authType the authentication type, {@link #AUTHTYPE_EAP_AKA} or 8290 * {@link #AUTHTYPE_EAP_SIM} 8291 * @param data authentication challenge data, base64 encoded. 8292 * See 3GPP TS 31.102 7.1.2 for more details. 8293 * @return the response of authentication. This value will be null in the following cases only 8294 * (see 3GPP TS 31.102 7.3.1): 8295 * Authentication error, incorrect MAC 8296 * Authentication error, security context not supported 8297 * Key freshness failure 8298 * Authentication error, no memory space available 8299 * Authentication error, no memory space available in EFMUK 8300 * @hide 8301 */ 8302 @UnsupportedAppUsage getIccAuthentication(int subId, int appType, int authType, String data)8303 public String getIccAuthentication(int subId, int appType, int authType, String data) { 8304 try { 8305 IPhoneSubInfo info = getSubscriberInfoService(); 8306 if (info == null) 8307 return null; 8308 return info.getIccSimChallengeResponse(subId, appType, authType, data, 8309 getOpPackageName(), getAttributionTag()); 8310 } catch (RemoteException ex) { 8311 return null; 8312 } catch (NullPointerException ex) { 8313 // This could happen before phone starts 8314 return null; 8315 } 8316 } 8317 8318 /** 8319 * Returns an array of Forbidden PLMNs from the USIM App 8320 * Returns null if the query fails. 8321 * 8322 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 8323 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 8324 * 8325 * @return an array of forbidden PLMNs or null if not available 8326 */ 8327 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 8328 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 8329 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getForbiddenPlmns()8330 public String[] getForbiddenPlmns() { 8331 return getForbiddenPlmns(getSubId(), APPTYPE_USIM); 8332 } 8333 8334 /** 8335 * Returns an array of Forbidden PLMNs from the specified SIM App 8336 * Returns null if the query fails. 8337 * 8338 * @param subId subscription ID used for authentication 8339 * @param appType the icc application type, like {@link #APPTYPE_USIM} 8340 * @return fplmns an array of forbidden PLMNs 8341 * @hide 8342 */ 8343 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getForbiddenPlmns(int subId, int appType)8344 public String[] getForbiddenPlmns(int subId, int appType) { 8345 try { 8346 ITelephony telephony = getITelephony(); 8347 if (telephony == null) 8348 return null; 8349 return telephony.getForbiddenPlmns(subId, appType, mContext.getOpPackageName(), 8350 getAttributionTag()); 8351 } catch (RemoteException ex) { 8352 return null; 8353 } catch (NullPointerException ex) { 8354 // This could happen before phone starts 8355 return null; 8356 } 8357 } 8358 8359 /** 8360 * Replace the contents of the forbidden PLMN SIM file with the provided values. 8361 * Passing an empty list will clear the contents of the EFfplmn file. 8362 * If the provided list is shorter than the size of EFfplmn, then the list will be padded 8363 * up to the file size with 'FFFFFF'. (required by 3GPP TS 31.102 spec 4.2.16) 8364 * If the list is longer than the size of EFfplmn, then the file will be written from the 8365 * beginning of the list up to the file size. 8366 * 8367 * <p>Requires Permission: {@link android.Manifest.permission#MODIFY_PHONE_STATE 8368 * MODIFY_PHONE_STATE} 8369 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 8370 * 8371 * @param fplmns a list of PLMNs to be forbidden. 8372 * 8373 * @return number of PLMNs that were successfully written to the SIM FPLMN list. 8374 * This may be less than the number of PLMNs passed in where the SIM file does not have enough 8375 * room for all of the values passed in. Return -1 in the event of an unexpected failure 8376 */ 8377 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 8378 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 8379 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) setForbiddenPlmns(@onNull List<String> fplmns)8380 public int setForbiddenPlmns(@NonNull List<String> fplmns) { 8381 try { 8382 ITelephony telephony = getITelephony(); 8383 if (telephony == null) return -1; 8384 return telephony.setForbiddenPlmns( 8385 getSubId(), APPTYPE_USIM, fplmns, getOpPackageName(), getAttributionTag()); 8386 } catch (RemoteException ex) { 8387 Rlog.e(TAG, "setForbiddenPlmns RemoteException: " + ex.getMessage()); 8388 } catch (NullPointerException ex) { 8389 // This could happen before phone starts 8390 Rlog.e(TAG, "setForbiddenPlmns NullPointerException: " + ex.getMessage()); 8391 } 8392 return -1; 8393 } 8394 8395 /** 8396 * Resets the {@link android.telephony.ims.ImsService} associated with the specified sim slot. 8397 * Used by diagnostic apps to force the IMS stack to be disabled and re-enabled in an effort to 8398 * recover from scenarios where the {@link android.telephony.ims.ImsService} gets in to a bad 8399 * state. 8400 * 8401 * @param slotIndex the sim slot to reset the IMS stack on. 8402 * @hide */ 8403 @SystemApi 8404 @WorkerThread 8405 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 8406 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_IMS) resetIms(int slotIndex)8407 public void resetIms(int slotIndex) { 8408 try { 8409 ITelephony telephony = getITelephony(); 8410 if (telephony != null) { 8411 telephony.resetIms(slotIndex); 8412 } 8413 } catch (RemoteException e) { 8414 Rlog.e(TAG, "toggleImsOnOff, RemoteException: " 8415 + e.getMessage()); 8416 } 8417 } 8418 8419 /** 8420 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability 8421 * status updates, if not already enabled. 8422 * @hide 8423 */ enableIms(int slotId)8424 public void enableIms(int slotId) { 8425 try { 8426 ITelephony telephony = getITelephony(); 8427 if (telephony != null) { 8428 telephony.enableIms(slotId); 8429 } 8430 } catch (RemoteException e) { 8431 Rlog.e(TAG, "enableIms, RemoteException: " 8432 + e.getMessage()); 8433 } 8434 } 8435 8436 /** 8437 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature 8438 * status updates to disabled. 8439 * @hide 8440 */ disableIms(int slotId)8441 public void disableIms(int slotId) { 8442 try { 8443 ITelephony telephony = getITelephony(); 8444 if (telephony != null) { 8445 telephony.disableIms(slotId); 8446 } 8447 } catch (RemoteException e) { 8448 Rlog.e(TAG, "disableIms, RemoteException: " 8449 + e.getMessage()); 8450 } 8451 } 8452 8453 /** 8454 * @return the {@IImsRegistration} interface that corresponds with the slot index and feature. 8455 * @param slotIndex The SIM slot corresponding to the ImsService ImsRegistration is active for. 8456 * @param feature An integer indicating the feature that we wish to get the ImsRegistration for. 8457 * Corresponds to features defined in ImsFeature. 8458 * @hide 8459 */ 8460 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getImsRegistration(int slotIndex, int feature)8461 public @Nullable IImsRegistration getImsRegistration(int slotIndex, int feature) { 8462 try { 8463 ITelephony telephony = getITelephony(); 8464 if (telephony != null) { 8465 return telephony.getImsRegistration(slotIndex, feature); 8466 } 8467 } catch (RemoteException e) { 8468 Rlog.e(TAG, "getImsRegistration, RemoteException: " + e.getMessage()); 8469 } 8470 return null; 8471 } 8472 8473 /** 8474 * @return the {@IImsConfig} interface that corresponds with the slot index and feature. 8475 * @param slotIndex The SIM slot corresponding to the ImsService ImsConfig is active for. 8476 * @param feature An integer indicating the feature that we wish to get the ImsConfig for. 8477 * Corresponds to features defined in ImsFeature. 8478 * @hide 8479 */ 8480 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) getImsConfig(int slotIndex, int feature)8481 public @Nullable IImsConfig getImsConfig(int slotIndex, int feature) { 8482 try { 8483 ITelephony telephony = getITelephony(); 8484 if (telephony != null) { 8485 return telephony.getImsConfig(slotIndex, feature); 8486 } 8487 } catch (RemoteException e) { 8488 Rlog.e(TAG, "getImsRegistration, RemoteException: " + e.getMessage()); 8489 } 8490 return null; 8491 } 8492 8493 /** 8494 * Set IMS registration state on all active subscriptions. 8495 * <p/> 8496 * Use {@link android.telephony.ims.stub.ImsRegistrationImplBase#onRegistered} and 8497 * {@link android.telephony.ims.stub.ImsRegistrationImplBase#onDeregistered} to set Ims 8498 * registration state instead. 8499 * 8500 * @param registered whether ims is registered 8501 * 8502 * @hide 8503 */ 8504 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setImsRegistrationState(final boolean registered)8505 public void setImsRegistrationState(final boolean registered) { 8506 try { 8507 final ITelephony telephony = getITelephony(); 8508 if (telephony != null) 8509 telephony.setImsRegistrationState(registered); 8510 } catch (final RemoteException e) { 8511 } 8512 } 8513 8514 /** @hide */ 8515 @IntDef(prefix = { "NETWORK_MODE_" }, value = { 8516 NETWORK_MODE_WCDMA_PREF, 8517 NETWORK_MODE_GSM_ONLY, 8518 NETWORK_MODE_WCDMA_ONLY, 8519 NETWORK_MODE_GSM_UMTS, 8520 NETWORK_MODE_CDMA_EVDO, 8521 NETWORK_MODE_CDMA_NO_EVDO, 8522 NETWORK_MODE_EVDO_NO_CDMA, 8523 NETWORK_MODE_GLOBAL, 8524 NETWORK_MODE_LTE_CDMA_EVDO, 8525 NETWORK_MODE_LTE_GSM_WCDMA, 8526 NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA, 8527 NETWORK_MODE_LTE_ONLY, 8528 NETWORK_MODE_LTE_WCDMA, 8529 NETWORK_MODE_TDSCDMA_ONLY, 8530 NETWORK_MODE_TDSCDMA_WCDMA, 8531 NETWORK_MODE_LTE_TDSCDMA, 8532 NETWORK_MODE_TDSCDMA_GSM, 8533 NETWORK_MODE_LTE_TDSCDMA_GSM, 8534 NETWORK_MODE_TDSCDMA_GSM_WCDMA, 8535 NETWORK_MODE_LTE_TDSCDMA_WCDMA, 8536 NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA, 8537 NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA, 8538 NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA, 8539 NETWORK_MODE_NR_ONLY, 8540 NETWORK_MODE_NR_LTE, 8541 NETWORK_MODE_NR_LTE_CDMA_EVDO, 8542 NETWORK_MODE_NR_LTE_GSM_WCDMA, 8543 NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA, 8544 NETWORK_MODE_NR_LTE_WCDMA, 8545 NETWORK_MODE_NR_LTE_TDSCDMA, 8546 NETWORK_MODE_NR_LTE_TDSCDMA_GSM, 8547 NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA, 8548 NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA, 8549 NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA 8550 }) 8551 @Retention(RetentionPolicy.SOURCE) 8552 public @interface PrefNetworkMode{} 8553 8554 /** 8555 * Preferred network mode is GSM/WCDMA (WCDMA preferred). 8556 * @hide 8557 */ 8558 public static final int NETWORK_MODE_WCDMA_PREF = RILConstants.NETWORK_MODE_WCDMA_PREF; 8559 8560 /** 8561 * Preferred network mode is GSM only. 8562 * @hide 8563 */ 8564 public static final int NETWORK_MODE_GSM_ONLY = RILConstants.NETWORK_MODE_GSM_ONLY; 8565 8566 /** 8567 * Preferred network mode is WCDMA only. 8568 * @hide 8569 */ 8570 public static final int NETWORK_MODE_WCDMA_ONLY = RILConstants.NETWORK_MODE_WCDMA_ONLY; 8571 8572 /** 8573 * Preferred network mode is GSM/WCDMA (auto mode, according to PRL). 8574 * @hide 8575 */ 8576 public static final int NETWORK_MODE_GSM_UMTS = RILConstants.NETWORK_MODE_GSM_UMTS; 8577 8578 /** 8579 * Preferred network mode is CDMA and EvDo (auto mode, according to PRL). 8580 * @hide 8581 */ 8582 public static final int NETWORK_MODE_CDMA_EVDO = RILConstants.NETWORK_MODE_CDMA; 8583 8584 /** 8585 * Preferred network mode is CDMA only. 8586 * @hide 8587 */ 8588 public static final int NETWORK_MODE_CDMA_NO_EVDO = RILConstants.NETWORK_MODE_CDMA_NO_EVDO; 8589 8590 /** 8591 * Preferred network mode is EvDo only. 8592 * @hide 8593 */ 8594 public static final int NETWORK_MODE_EVDO_NO_CDMA = RILConstants.NETWORK_MODE_EVDO_NO_CDMA; 8595 8596 /** 8597 * Preferred network mode is GSM/WCDMA, CDMA, and EvDo (auto mode, according to PRL). 8598 * @hide 8599 */ 8600 public static final int NETWORK_MODE_GLOBAL = RILConstants.NETWORK_MODE_GLOBAL; 8601 8602 /** 8603 * Preferred network mode is LTE, CDMA and EvDo. 8604 * @hide 8605 */ 8606 public static final int NETWORK_MODE_LTE_CDMA_EVDO = RILConstants.NETWORK_MODE_LTE_CDMA_EVDO; 8607 8608 /** 8609 * Preferred network mode is LTE, GSM/WCDMA. 8610 * @hide 8611 */ 8612 public static final int NETWORK_MODE_LTE_GSM_WCDMA = RILConstants.NETWORK_MODE_LTE_GSM_WCDMA; 8613 8614 /** 8615 * Preferred network mode is LTE, CDMA, EvDo, GSM/WCDMA. 8616 * @hide 8617 */ 8618 public static final int NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA = 8619 RILConstants.NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA; 8620 8621 /** 8622 * Preferred network mode is LTE Only. 8623 * @hide 8624 */ 8625 public static final int NETWORK_MODE_LTE_ONLY = RILConstants.NETWORK_MODE_LTE_ONLY; 8626 8627 /** 8628 * Preferred network mode is LTE/WCDMA. 8629 * @hide 8630 */ 8631 public static final int NETWORK_MODE_LTE_WCDMA = RILConstants.NETWORK_MODE_LTE_WCDMA; 8632 8633 /** 8634 * Preferred network mode is TD-SCDMA only. 8635 * @hide 8636 */ 8637 public static final int NETWORK_MODE_TDSCDMA_ONLY = RILConstants.NETWORK_MODE_TDSCDMA_ONLY; 8638 8639 /** 8640 * Preferred network mode is TD-SCDMA and WCDMA. 8641 * @hide 8642 */ 8643 public static final int NETWORK_MODE_TDSCDMA_WCDMA = RILConstants.NETWORK_MODE_TDSCDMA_WCDMA; 8644 8645 /** 8646 * Preferred network mode is TD-SCDMA and LTE. 8647 * @hide 8648 */ 8649 public static final int NETWORK_MODE_LTE_TDSCDMA = RILConstants.NETWORK_MODE_LTE_TDSCDMA; 8650 8651 /** 8652 * Preferred network mode is TD-SCDMA and GSM. 8653 * @hide 8654 */ 8655 public static final int NETWORK_MODE_TDSCDMA_GSM = RILConstants.NETWORK_MODE_TDSCDMA_GSM; 8656 8657 /** 8658 * Preferred network mode is TD-SCDMA,GSM and LTE. 8659 * @hide 8660 */ 8661 public static final int NETWORK_MODE_LTE_TDSCDMA_GSM = 8662 RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM; 8663 8664 /** 8665 * Preferred network mode is TD-SCDMA, GSM/WCDMA. 8666 * @hide 8667 */ 8668 public static final int NETWORK_MODE_TDSCDMA_GSM_WCDMA = 8669 RILConstants.NETWORK_MODE_TDSCDMA_GSM_WCDMA; 8670 8671 /** 8672 * Preferred network mode is TD-SCDMA, WCDMA and LTE. 8673 * @hide 8674 */ 8675 public static final int NETWORK_MODE_LTE_TDSCDMA_WCDMA = 8676 RILConstants.NETWORK_MODE_LTE_TDSCDMA_WCDMA; 8677 8678 /** 8679 * Preferred network mode is TD-SCDMA, GSM/WCDMA and LTE. 8680 * @hide 8681 */ 8682 public static final int NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA = 8683 RILConstants.NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA; 8684 8685 /** 8686 * Preferred network mode is TD-SCDMA,EvDo,CDMA,GSM/WCDMA. 8687 * @hide 8688 */ 8689 public static final int NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 8690 RILConstants.NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA; 8691 /** 8692 * Preferred network mode is TD-SCDMA/LTE/GSM/WCDMA, CDMA, and EvDo. 8693 * @hide 8694 */ 8695 public static final int NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 8696 RILConstants.NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA; 8697 8698 /** 8699 * Preferred network mode is NR 5G only. 8700 * @hide 8701 */ 8702 public static final int NETWORK_MODE_NR_ONLY = RILConstants.NETWORK_MODE_NR_ONLY; 8703 8704 /** 8705 * Preferred network mode is NR 5G, LTE. 8706 * @hide 8707 */ 8708 public static final int NETWORK_MODE_NR_LTE = RILConstants.NETWORK_MODE_NR_LTE; 8709 8710 /** 8711 * Preferred network mode is NR 5G, LTE, CDMA and EvDo. 8712 * @hide 8713 */ 8714 public static final int NETWORK_MODE_NR_LTE_CDMA_EVDO = 8715 RILConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO; 8716 8717 /** 8718 * Preferred network mode is NR 5G, LTE, GSM and WCDMA. 8719 * @hide 8720 */ 8721 public static final int NETWORK_MODE_NR_LTE_GSM_WCDMA = 8722 RILConstants.NETWORK_MODE_NR_LTE_GSM_WCDMA; 8723 8724 /** 8725 * Preferred network mode is NR 5G, LTE, CDMA, EvDo, GSM and WCDMA. 8726 * @hide 8727 */ 8728 public static final int NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA = 8729 RILConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA; 8730 8731 /** 8732 * Preferred network mode is NR 5G, LTE and WCDMA. 8733 * @hide 8734 */ 8735 public static final int NETWORK_MODE_NR_LTE_WCDMA = RILConstants.NETWORK_MODE_NR_LTE_WCDMA; 8736 8737 /** 8738 * Preferred network mode is NR 5G, LTE and TDSCDMA. 8739 * @hide 8740 */ 8741 public static final int NETWORK_MODE_NR_LTE_TDSCDMA = RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA; 8742 8743 /** 8744 * Preferred network mode is NR 5G, LTE, TD-SCDMA and GSM. 8745 * @hide 8746 */ 8747 public static final int NETWORK_MODE_NR_LTE_TDSCDMA_GSM = 8748 RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM; 8749 8750 /** 8751 * Preferred network mode is NR 5G, LTE, TD-SCDMA, WCDMA. 8752 * @hide 8753 */ 8754 public static final int NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA = 8755 RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_WCDMA; 8756 8757 /** 8758 * Preferred network mode is NR 5G, LTE, TD-SCDMA, GSM and WCDMA. 8759 * @hide 8760 */ 8761 public static final int NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA = 8762 RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_GSM_WCDMA; 8763 8764 /** 8765 * Preferred network mode is NR 5G, LTE, TD-SCDMA, CDMA, EVDO, GSM and WCDMA. 8766 * @hide 8767 */ 8768 public static final int NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA = 8769 RILConstants.NETWORK_MODE_NR_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA; 8770 8771 /** 8772 * The default preferred network mode constant. 8773 * 8774 * <p> This constant is used in case of nothing is set in 8775 * TelephonyProperties#default_network(). 8776 * 8777 * @hide 8778 */ 8779 public static final int DEFAULT_PREFERRED_NETWORK_MODE = 8780 RILConstants.PREFERRED_NETWORK_MODE; 8781 8782 /** 8783 * Get the preferred network type. 8784 * Used for device configuration by some CDMA operators. 8785 * 8786 * <p>Requires Permission: 8787 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 8788 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 8789 * 8790 * @return the preferred network type. 8791 * @hide 8792 * @deprecated Use {@link #getAllowedNetworkTypesBitmask} instead. 8793 */ 8794 @Deprecated 8795 @RequiresPermission((android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)) 8796 @UnsupportedAppUsage getPreferredNetworkType(int subId)8797 public @PrefNetworkMode int getPreferredNetworkType(int subId) { 8798 return RadioAccessFamily.getNetworkTypeFromRaf((int) getAllowedNetworkTypesBitmask()); 8799 } 8800 8801 /** 8802 * Get the preferred network type bitmask. 8803 * 8804 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8805 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8806 * 8807 * <p>Requires Permission: 8808 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 8809 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 8810 * 8811 * @return The bitmask of preferred network types. 8812 * 8813 * @hide 8814 * @deprecated Use {@link #getAllowedNetworkTypesBitmask} instead. 8815 */ 8816 @Deprecated 8817 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 8818 @SystemApi getPreferredNetworkTypeBitmask()8819 public @NetworkTypeBitMask long getPreferredNetworkTypeBitmask() { 8820 return getAllowedNetworkTypesBitmask(); 8821 } 8822 8823 /** 8824 * Get the allowed network type bitmask. 8825 * Note that the device can only register on the network of {@link NetworkTypeBitmask} 8826 * (except for emergency call cases). 8827 * 8828 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8829 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8830 * 8831 * <p>Requires Permission: 8832 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 8833 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 8834 * 8835 * @return The bitmask of allowed network types. 8836 * 8837 * @hide 8838 */ 8839 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 8840 @SystemApi 8841 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) getAllowedNetworkTypesBitmask()8842 public @NetworkTypeBitMask long getAllowedNetworkTypesBitmask() { 8843 try { 8844 ITelephony telephony = getITelephony(); 8845 if (telephony != null) { 8846 return (long) telephony.getAllowedNetworkTypesBitmask(getSubId()); 8847 } 8848 } catch (RemoteException ex) { 8849 Rlog.e(TAG, "getAllowedNetworkTypesBitmask RemoteException", ex); 8850 } 8851 return 0; 8852 } 8853 8854 /** 8855 * Get the allowed network types by carriers. 8856 * 8857 * <p>Requires Permission: 8858 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 8859 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 8860 * 8861 * @return the allowed network type bitmask 8862 * @hide 8863 * @deprecated Use {@link #getAllowedNetworkTypesForReason} instead. 8864 */ 8865 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 8866 @SystemApi 8867 @Deprecated getAllowedNetworkTypes()8868 public @NetworkTypeBitMask long getAllowedNetworkTypes() { 8869 try { 8870 ITelephony telephony = getITelephony(); 8871 if (telephony != null) { 8872 return telephony.getAllowedNetworkTypesForReason(getSubId(), 8873 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER); 8874 } 8875 } catch (RemoteException ex) { 8876 Rlog.e(TAG, "getAllowedNetworkTypes RemoteException", ex); 8877 } 8878 return -1; 8879 } 8880 8881 /** 8882 * Sets the network selection mode to automatic. 8883 * 8884 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8885 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8886 * 8887 * <p>Requires Permission: 8888 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 8889 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 8890 */ 8891 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 8892 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 8893 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) setNetworkSelectionModeAutomatic()8894 public void setNetworkSelectionModeAutomatic() { 8895 try { 8896 ITelephony telephony = getITelephony(); 8897 if (telephony != null) { 8898 telephony.setNetworkSelectionModeAutomatic(getSubId()); 8899 } 8900 } catch (RemoteException ex) { 8901 Rlog.e(TAG, "setNetworkSelectionModeAutomatic RemoteException", ex); 8902 } catch (NullPointerException ex) { 8903 Rlog.e(TAG, "setNetworkSelectionModeAutomatic NPE", ex); 8904 } 8905 } 8906 8907 /** 8908 * Perform a radio scan and return the list of available networks. 8909 * 8910 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 8911 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 8912 * 8913 * <p> Note that this scan can take a long time (sometimes minutes) to happen. 8914 * 8915 * <p>Requires Permissions: 8916 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier 8917 * privileges (see {@link #hasCarrierPrivileges}) 8918 * and {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 8919 * 8920 * @return {@link CellNetworkScanResult} with the status 8921 * {@link CellNetworkScanResult#STATUS_SUCCESS} and a list of 8922 * {@link com.android.internal.telephony.OperatorInfo} if it's available. Otherwise, the failure 8923 * caused will be included in the result. 8924 * 8925 * @hide 8926 */ 8927 @RequiresPermission(allOf = { 8928 android.Manifest.permission.MODIFY_PHONE_STATE, 8929 Manifest.permission.ACCESS_COARSE_LOCATION 8930 }) getAvailableNetworks()8931 public CellNetworkScanResult getAvailableNetworks() { 8932 try { 8933 ITelephony telephony = getITelephony(); 8934 if (telephony != null) { 8935 return telephony.getCellNetworkScanResults(getSubId(), getOpPackageName(), 8936 getAttributionTag()); 8937 } 8938 } catch (RemoteException ex) { 8939 Rlog.e(TAG, "getAvailableNetworks RemoteException", ex); 8940 } catch (NullPointerException ex) { 8941 Rlog.e(TAG, "getAvailableNetworks NPE", ex); 8942 } 8943 return new CellNetworkScanResult( 8944 CellNetworkScanResult.STATUS_UNKNOWN_ERROR, null /* OperatorInfo */); 8945 } 8946 8947 /** 8948 * Request a network scan. 8949 * 8950 * This method is asynchronous, so the network scan results will be returned by callback. 8951 * The returned NetworkScan will contain a callback method which can be used to stop the scan. 8952 * 8953 * <p>Requires Permission: 8954 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 8955 * app has carrier privileges (see {@link #hasCarrierPrivileges}) 8956 * and {@link android.Manifest.permission#ACCESS_FINE_LOCATION}. 8957 * 8958 * If the system-wide location switch is off, apps may still call this API, with the 8959 * following constraints: 8960 * <ol> 8961 * <li>The app must hold the {@code android.permission.NETWORK_SCAN} permission.</li> 8962 * <li>The app must not supply any specific bands or channels to scan.</li> 8963 * <li>The app must only specify MCC/MNC pairs that are 8964 * associated to a SIM in the device.</li> 8965 * <li>Returned results will have no meaningful info other than signal strength 8966 * and MCC/MNC info.</li> 8967 * </ol> 8968 * 8969 * @param request Contains all the RAT with bands/channels that need to be scanned. 8970 * @param executor The executor through which the callback should be invoked. Since the scan 8971 * request may trigger multiple callbacks and they must be invoked in the same order as 8972 * they are received by the platform, the user should provide an executor which executes 8973 * tasks one at a time in serial order. For example AsyncTask.SERIAL_EXECUTOR. 8974 * @param callback Returns network scan results or errors. 8975 * @return A NetworkScan obj which contains a callback which can be used to stop the scan. 8976 */ 8977 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 8978 @RequiresPermission(allOf = { 8979 android.Manifest.permission.MODIFY_PHONE_STATE, 8980 Manifest.permission.ACCESS_FINE_LOCATION 8981 }) 8982 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) requestNetworkScan( NetworkScanRequest request, Executor executor, TelephonyScanManager.NetworkScanCallback callback)8983 public NetworkScan requestNetworkScan( 8984 NetworkScanRequest request, Executor executor, 8985 TelephonyScanManager.NetworkScanCallback callback) { 8986 return requestNetworkScan(INCLUDE_LOCATION_DATA_FINE, request, executor, callback); 8987 } 8988 8989 /** 8990 * Request a network scan. 8991 * 8992 * This method is asynchronous, so the network scan results will be returned by callback. 8993 * The returned NetworkScan will contain a callback method which can be used to stop the scan. 8994 * 8995 * <p>Requires Permission: 8996 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 8997 * app has carrier privileges (see {@link #hasCarrierPrivileges}) 8998 * and {@link android.Manifest.permission#ACCESS_FINE_LOCATION}. 8999 * 9000 * If the system-wide location switch is off, apps may still call this API, with the 9001 * following constraints: 9002 * <ol> 9003 * <li>The app must hold the {@code android.permission.NETWORK_SCAN} permission.</li> 9004 * <li>The app must not supply any specific bands or channels to scan.</li> 9005 * <li>The app must only specify MCC/MNC pairs that are 9006 * associated to a SIM in the device.</li> 9007 * <li>Returned results will have no meaningful info other than signal strength 9008 * and MCC/MNC info.</li> 9009 * </ol> 9010 * 9011 * @param includeLocationData Specifies if the caller would like to receive 9012 * location related information. 9013 * @param request Contains all the RAT with bands/channels that need to be scanned. 9014 * @param executor The executor through which the callback should be invoked. Since the scan 9015 * request may trigger multiple callbacks and they must be invoked in the same order as 9016 * they are received by the platform, the user should provide an executor which executes 9017 * tasks one at a time in serial order. For example AsyncTask.SERIAL_EXECUTOR. 9018 * @param callback Returns network scan results or errors. 9019 * @return A NetworkScan obj which contains a callback which can be used to stop the scan. 9020 */ 9021 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 9022 @RequiresPermission(allOf = { 9023 android.Manifest.permission.MODIFY_PHONE_STATE, 9024 Manifest.permission.ACCESS_FINE_LOCATION 9025 }) requestNetworkScan( @ncludeLocationData int includeLocationData, @NonNull NetworkScanRequest request, @NonNull Executor executor, @NonNull TelephonyScanManager.NetworkScanCallback callback)9026 public @Nullable NetworkScan requestNetworkScan( 9027 @IncludeLocationData int includeLocationData, 9028 @NonNull NetworkScanRequest request, 9029 @NonNull Executor executor, 9030 @NonNull TelephonyScanManager.NetworkScanCallback callback) { 9031 synchronized (sCacheLock) { 9032 if (mTelephonyScanManager == null) { 9033 mTelephonyScanManager = new TelephonyScanManager(); 9034 } 9035 } 9036 return mTelephonyScanManager.requestNetworkScan(getSubId(), 9037 includeLocationData != INCLUDE_LOCATION_DATA_FINE, 9038 request, executor, callback, 9039 getOpPackageName(), getAttributionTag()); 9040 } 9041 9042 /** 9043 * @deprecated 9044 * Use {@link 9045 * #requestNetworkScan(NetworkScanRequest, Executor, TelephonyScanManager.NetworkScanCallback)} 9046 * @removed 9047 */ 9048 @Deprecated 9049 @RequiresPermission(allOf = { 9050 android.Manifest.permission.MODIFY_PHONE_STATE, 9051 Manifest.permission.ACCESS_FINE_LOCATION 9052 }) requestNetworkScan( NetworkScanRequest request, TelephonyScanManager.NetworkScanCallback callback)9053 public NetworkScan requestNetworkScan( 9054 NetworkScanRequest request, TelephonyScanManager.NetworkScanCallback callback) { 9055 return requestNetworkScan(request, AsyncTask.SERIAL_EXECUTOR, callback); 9056 } 9057 9058 /** 9059 * Ask the radio to connect to the input network and change selection mode to manual. 9060 * 9061 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 9062 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 9063 * 9064 * <p>Requires Permission: 9065 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 9066 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 9067 * 9068 * @param operatorNumeric the PLMN ID of the network to select. 9069 * @param persistSelection whether the selection will persist until reboot. If true, only allows 9070 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume 9071 * normal network selection next time. 9072 * @return {@code true} on success; {@code false} on any failure. 9073 */ 9074 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 9075 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 9076 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) setNetworkSelectionModeManual(String operatorNumeric, boolean persistSelection)9077 public boolean setNetworkSelectionModeManual(String operatorNumeric, boolean persistSelection) { 9078 return setNetworkSelectionModeManual( 9079 new OperatorInfo( 9080 "" /* operatorAlphaLong */, "" /* operatorAlphaShort */, operatorNumeric), 9081 persistSelection); 9082 } 9083 9084 /** 9085 * Ask the radio to connect to the input network and change selection mode to manual. 9086 * 9087 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 9088 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 9089 * 9090 * <p>Requires Permission: 9091 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 9092 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 9093 * 9094 * @param operatorNumeric the PLMN ID of the network to select. 9095 * @param persistSelection whether the selection will persist until reboot. 9096 * If true, only allows attaching to the selected PLMN until reboot; otherwise, 9097 * attach to the chosen PLMN and resume normal network selection next time. 9098 * @param ran the initial suggested radio access network type. 9099 * If registration fails, the RAN is not available after, the RAN is not within the 9100 * network types specified by the preferred network types, or the value is 9101 * {@link AccessNetworkConstants.AccessNetworkType#UNKNOWN}, modem will select 9102 * the next best RAN for network registration. 9103 * @return {@code true} on success; {@code false} on any failure. 9104 */ 9105 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 9106 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) setNetworkSelectionModeManual(@onNull String operatorNumeric, boolean persistSelection, @AccessNetworkConstants.RadioAccessNetworkType int ran)9107 public boolean setNetworkSelectionModeManual(@NonNull String operatorNumeric, 9108 boolean persistSelection, @AccessNetworkConstants.RadioAccessNetworkType int ran) { 9109 return setNetworkSelectionModeManual(new OperatorInfo("" /* operatorAlphaLong */, 9110 "" /* operatorAlphaShort */, operatorNumeric, ran), persistSelection); 9111 } 9112 9113 /** 9114 * Ask the radio to connect to the input network and change selection mode to manual. 9115 * 9116 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 9117 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 9118 * 9119 * <p>Requires Permission: 9120 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 9121 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 9122 * 9123 * @param operatorInfo included the PLMN id, long name, short name of the operator to attach to. 9124 * @param persistSelection whether the selection will persist until reboot. If true, only allows 9125 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume 9126 * normal network selection next time. 9127 * @return {@code true} on success; {@code true} on any failure. 9128 * 9129 * @hide 9130 */ 9131 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setNetworkSelectionModeManual( OperatorInfo operatorInfo, boolean persistSelection)9132 public boolean setNetworkSelectionModeManual( 9133 OperatorInfo operatorInfo, boolean persistSelection) { 9134 try { 9135 ITelephony telephony = getITelephony(); 9136 if (telephony != null) { 9137 return telephony.setNetworkSelectionModeManual( 9138 getSubId(), operatorInfo, persistSelection); 9139 } 9140 } catch (RemoteException ex) { 9141 Rlog.e(TAG, "setNetworkSelectionModeManual RemoteException", ex); 9142 } 9143 return false; 9144 } 9145 9146 /** 9147 * Get the network selection mode. 9148 * 9149 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 9150 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 9151 * <p>Requires Permission: {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE 9152 * READ_PRECISE_PHONE_STATE} 9153 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 9154 * 9155 * @return the network selection mode. 9156 */ 9157 @SuppressAutoDoc // No support for carrier privileges (b/72967236). 9158 @RequiresPermission(anyOf = { 9159 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 9160 android.Manifest.permission.READ_PRECISE_PHONE_STATE 9161 }) 9162 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) getNetworkSelectionMode()9163 public @NetworkSelectionMode int getNetworkSelectionMode() { 9164 int mode = NETWORK_SELECTION_MODE_UNKNOWN; 9165 try { 9166 ITelephony telephony = getITelephony(); 9167 if (telephony != null) { 9168 mode = telephony.getNetworkSelectionMode(getSubId()); 9169 } 9170 } catch (RemoteException ex) { 9171 Rlog.e(TAG, "getNetworkSelectionMode RemoteException", ex); 9172 } 9173 return mode; 9174 } 9175 9176 /** 9177 * Get the PLMN chosen for Manual Network Selection if active. 9178 * Return empty string if in automatic selection. 9179 * 9180 * <p>Requires Permission: {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE 9181 * READ_PRECISE_PHONE_STATE} or that the calling app has carrier privileges 9182 * (see {@link #hasCarrierPrivileges}) 9183 * 9184 * @return manually selected network info on success or empty string on failure 9185 */ 9186 @SuppressAutoDoc // No support carrier privileges (b/72967236). 9187 @RequiresPermission(android.Manifest.permission.READ_PRECISE_PHONE_STATE) 9188 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) getManualNetworkSelectionPlmn()9189 public @NonNull String getManualNetworkSelectionPlmn() { 9190 try { 9191 ITelephony telephony = getITelephony(); 9192 if (telephony != null && isManualNetworkSelectionAllowed()) { 9193 return telephony.getManualNetworkSelectionPlmn(getSubId()); 9194 } 9195 } catch (RemoteException ex) { 9196 Rlog.e(TAG, "getManualNetworkSelectionPlmn RemoteException", ex); 9197 } 9198 return ""; 9199 } 9200 9201 /** 9202 * Query Telephony to see if there has recently been an emergency SMS sent to the network by the 9203 * user and we are still within the time interval after the emergency SMS was sent that we are 9204 * considered in Emergency SMS mode. 9205 * 9206 * <p>This mode is used by other applications to allow them to perform special functionality, 9207 * such as allow the GNSS service to provide user location to the carrier network for emergency 9208 * when an emergency SMS is sent. This interval is set by 9209 * {@link CarrierConfigManager#KEY_EMERGENCY_SMS_MODE_TIMER_MS_INT}. If 9210 * the carrier does not support this mode, this function will always return false. 9211 * 9212 * @return {@code true} if this device is in emergency SMS mode, {@code false} otherwise. 9213 * 9214 * @hide 9215 */ 9216 @SystemApi 9217 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 9218 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING) isInEmergencySmsMode()9219 public boolean isInEmergencySmsMode() { 9220 try { 9221 ITelephony telephony = getITelephony(); 9222 if (telephony != null) { 9223 return telephony.isInEmergencySmsMode(); 9224 } 9225 } catch (RemoteException ex) { 9226 Rlog.e(TAG, "isInEmergencySmsMode RemoteException", ex); 9227 } 9228 return false; 9229 } 9230 9231 /** 9232 * Set the preferred network type. 9233 * 9234 * <p>Requires Permission: 9235 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 9236 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 9237 * <p> 9238 * If {@link android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported} 9239 * ({@link TelephonyManager#CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK}) returns true, then 9240 * setAllowedNetworkTypesBitmap is used on the radio interface. Otherwise, 9241 * setPreferredNetworkTypesBitmap is used instead. 9242 * 9243 * @param subId the id of the subscription to set the preferred network type for. 9244 * @param networkType the preferred network type 9245 * @return true on success; false on any failure. 9246 * @hide 9247 * @deprecated Use {@link #setAllowedNetworkTypesForReason} instead. 9248 */ 9249 @Deprecated 9250 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setPreferredNetworkType(int subId, @PrefNetworkMode int networkType)9251 public boolean setPreferredNetworkType(int subId, @PrefNetworkMode int networkType) { 9252 try { 9253 ITelephony telephony = getITelephony(); 9254 if (telephony != null) { 9255 return telephony.setAllowedNetworkTypesForReason(subId, 9256 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, 9257 RadioAccessFamily.getRafFromNetworkType(networkType)); 9258 } 9259 } catch (RemoteException ex) { 9260 Rlog.e(TAG, "setPreferredNetworkType RemoteException", ex); 9261 } 9262 return false; 9263 } 9264 9265 /** 9266 * Set the preferred network type bitmask but if {@link #setAllowedNetworkTypes} has been set, 9267 * only the allowed network type will set to the modem. 9268 * 9269 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 9270 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 9271 * 9272 * <p>Requires Permission: 9273 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 9274 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 9275 * <p> 9276 * If {@link android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported} 9277 * ({@link TelephonyManager#CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK}) returns true, then 9278 * setAllowedNetworkTypesBitmap is used on the radio interface. Otherwise, 9279 * setPreferredNetworkTypesBitmap is used instead. 9280 * 9281 * @param networkTypeBitmask The bitmask of preferred network types. 9282 * @return true on success; false on any failure. 9283 * @hide 9284 * @deprecated Use {@link #setAllowedNetworkTypesForReason} instead. 9285 */ 9286 @Deprecated 9287 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 9288 @SystemApi setPreferredNetworkTypeBitmask(@etworkTypeBitMask long networkTypeBitmask)9289 public boolean setPreferredNetworkTypeBitmask(@NetworkTypeBitMask long networkTypeBitmask) { 9290 try { 9291 ITelephony telephony = getITelephony(); 9292 if (telephony != null) { 9293 networkTypeBitmask = checkNetworkTypeBitmask(networkTypeBitmask); 9294 return telephony.setAllowedNetworkTypesForReason(getSubId(), 9295 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, networkTypeBitmask); 9296 } 9297 } catch (RemoteException ex) { 9298 Rlog.e(TAG, "setPreferredNetworkTypeBitmask RemoteException", ex); 9299 } 9300 return false; 9301 } 9302 9303 /** 9304 * If {@link #NETWORK_TYPE_BITMASK_LTE_CA} bit is set, convert it to NETWORK_TYPE_BITMASK_LTE. 9305 * 9306 * @param networkTypeBitmask The networkTypeBitmask being checked 9307 * @return The checked/converted networkTypeBitmask 9308 */ checkNetworkTypeBitmask(@etworkTypeBitMask long networkTypeBitmask)9309 private long checkNetworkTypeBitmask(@NetworkTypeBitMask long networkTypeBitmask) { 9310 if ((networkTypeBitmask & NETWORK_TYPE_BITMASK_LTE_CA) != 0) { 9311 networkTypeBitmask ^= NETWORK_TYPE_BITMASK_LTE_CA; 9312 networkTypeBitmask |= NETWORK_TYPE_BITMASK_LTE; 9313 } 9314 return networkTypeBitmask; 9315 } 9316 9317 /** 9318 * Set the allowed network types of the device. This is for carrier or privileged apps to 9319 * enable/disable certain network types on the device. The user preferred network types should 9320 * be set through {@link #setPreferredNetworkTypeBitmask}. 9321 * <p> 9322 * If {@link android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported} 9323 * ({@link TelephonyManager#CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK}) returns true, then 9324 * setAllowedNetworkTypesBitmap is used on the radio interface. Otherwise, 9325 * setPreferredNetworkTypesBitmap is used instead. 9326 * 9327 * @param allowedNetworkTypes The bitmask of allowed network types. 9328 * @return true on success; false on any failure. 9329 * @hide 9330 * @deprecated Use {@link #setAllowedNetworkTypesForReason} instead with reason 9331 * {@link #ALLOWED_NETWORK_TYPES_REASON_CARRIER}. 9332 */ 9333 @Deprecated 9334 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 9335 @RequiresFeature( 9336 enforcement = "android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported", 9337 value = TelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK) 9338 @SystemApi setAllowedNetworkTypes(@etworkTypeBitMask long allowedNetworkTypes)9339 public boolean setAllowedNetworkTypes(@NetworkTypeBitMask long allowedNetworkTypes) { 9340 try { 9341 ITelephony telephony = getITelephony(); 9342 if (telephony != null) { 9343 allowedNetworkTypes = checkNetworkTypeBitmask(allowedNetworkTypes); 9344 return telephony.setAllowedNetworkTypesForReason(getSubId(), 9345 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER, allowedNetworkTypes); 9346 } 9347 } catch (RemoteException ex) { 9348 Rlog.e(TAG, "setAllowedNetworkTypes RemoteException", ex); 9349 } 9350 return false; 9351 } 9352 9353 /** @hide */ 9354 @IntDef({ 9355 ALLOWED_NETWORK_TYPES_REASON_USER, 9356 ALLOWED_NETWORK_TYPES_REASON_POWER, 9357 ALLOWED_NETWORK_TYPES_REASON_CARRIER, 9358 ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G 9359 }) 9360 @Retention(RetentionPolicy.SOURCE) 9361 public @interface AllowedNetworkTypesReason { 9362 } 9363 9364 /** 9365 * To indicate allowed network type change is requested by user. 9366 */ 9367 public static final int ALLOWED_NETWORK_TYPES_REASON_USER = 0; 9368 9369 /** 9370 * To indicate allowed network type change is requested by power manager. 9371 * Power Manger configuration won't affect the settings configured through 9372 * other reasons and will result in allowing network types that are in both 9373 * configurations (i.e intersection of both sets). 9374 * 9375 * @hide 9376 */ 9377 @SystemApi 9378 public static final int ALLOWED_NETWORK_TYPES_REASON_POWER = 1; 9379 9380 /** 9381 * To indicate allowed network type change is requested by carrier. 9382 * Carrier configuration won't affect the settings configured through 9383 * other reasons and will result in allowing network types that are in both 9384 * configurations (i.e intersection of both sets). 9385 */ 9386 public static final int ALLOWED_NETWORK_TYPES_REASON_CARRIER = 2; 9387 9388 /** 9389 * To indicate allowed network type change is requested by the user via the 2G toggle. 9390 * 9391 * @hide 9392 */ 9393 @SystemApi 9394 public static final int ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G = 3; 9395 9396 /** 9397 * Set the allowed network types of the device and provide the reason triggering the allowed 9398 * network change. 9399 * <p>Requires permission: android.Manifest.MODIFY_PHONE_STATE or 9400 * that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 9401 * 9402 * This can be called for following reasons 9403 * <ol> 9404 * <li>Allowed network types control by USER {@link #ALLOWED_NETWORK_TYPES_REASON_USER} 9405 * <li>Allowed network types control by carrier {@link #ALLOWED_NETWORK_TYPES_REASON_CARRIER} 9406 * </ol> 9407 * This API will result in allowing an intersection of allowed network types for all reasons, 9408 * including the configuration done through other reasons. 9409 * 9410 * @param reason the reason the allowed network type change is taking place 9411 * @param allowedNetworkTypes The bitmask of allowed network type 9412 * @throws IllegalStateException if the Telephony process is not currently available. 9413 * @throws IllegalArgumentException if invalid AllowedNetworkTypesReason is passed. 9414 * @throws SecurityException if the caller does not have the required privileges 9415 */ 9416 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 9417 @RequiresFeature( 9418 enforcement = "android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported", 9419 value = TelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK) setAllowedNetworkTypesForReason(@llowedNetworkTypesReason int reason, @NetworkTypeBitMask long allowedNetworkTypes)9420 public void setAllowedNetworkTypesForReason(@AllowedNetworkTypesReason int reason, 9421 @NetworkTypeBitMask long allowedNetworkTypes) { 9422 if (!isValidAllowedNetworkTypesReason(reason)) { 9423 throw new IllegalArgumentException("invalid AllowedNetworkTypesReason."); 9424 } 9425 9426 try { 9427 ITelephony telephony = getITelephony(); 9428 if (telephony != null) { 9429 allowedNetworkTypes = checkNetworkTypeBitmask(allowedNetworkTypes); 9430 telephony.setAllowedNetworkTypesForReason(getSubId(), reason, 9431 allowedNetworkTypes); 9432 } else { 9433 throw new IllegalStateException("telephony service is null."); 9434 } 9435 } catch (RemoteException ex) { 9436 Rlog.e(TAG, "setAllowedNetworkTypesForReason RemoteException", ex); 9437 ex.rethrowFromSystemServer(); 9438 } 9439 } 9440 9441 /** 9442 * Get the allowed network types for certain reason. 9443 * 9444 * {@link #getAllowedNetworkTypesForReason} returns allowed network type for a 9445 * specific reason. 9446 * <p>Requires permission: android.Manifest.READ_PRIVILEGED_PHONE_STATE or 9447 * that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 9448 * 9449 * @param reason the reason the allowed network type change is taking place 9450 * @return the allowed network type bitmask 9451 * @throws IllegalStateException if the Telephony process is not currently available. 9452 * @throws IllegalArgumentException if invalid AllowedNetworkTypesReason is passed. 9453 * @throws SecurityException if the caller does not have the required permission/privileges 9454 */ 9455 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 9456 @RequiresFeature( 9457 enforcement = "android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported", 9458 value = TelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK) getAllowedNetworkTypesForReason( @llowedNetworkTypesReason int reason)9459 public @NetworkTypeBitMask long getAllowedNetworkTypesForReason( 9460 @AllowedNetworkTypesReason int reason) { 9461 if (!isValidAllowedNetworkTypesReason(reason)) { 9462 throw new IllegalArgumentException("invalid AllowedNetworkTypesReason."); 9463 } 9464 9465 try { 9466 ITelephony telephony = getITelephony(); 9467 if (telephony != null) { 9468 return telephony.getAllowedNetworkTypesForReason(getSubId(), reason); 9469 } else { 9470 throw new IllegalStateException("telephony service is null."); 9471 } 9472 } catch (RemoteException ex) { 9473 Rlog.e(TAG, "getAllowedNetworkTypesForReason RemoteException", ex); 9474 ex.rethrowFromSystemServer(); 9475 } 9476 return -1; 9477 } 9478 /** 9479 * Verifies that the reason provided is valid. 9480 * @hide 9481 */ isValidAllowedNetworkTypesReason(@llowedNetworkTypesReason int reason)9482 public static boolean isValidAllowedNetworkTypesReason(@AllowedNetworkTypesReason int reason) { 9483 switch (reason) { 9484 case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER: 9485 case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER: 9486 case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER: 9487 case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G: 9488 return true; 9489 } 9490 return false; 9491 } 9492 /** 9493 * Get bit mask of all network types. 9494 * 9495 * @return bit mask of all network types 9496 * @hide 9497 */ getAllNetworkTypesBitmask()9498 public static @NetworkTypeBitMask long getAllNetworkTypesBitmask() { 9499 return NETWORK_STANDARDS_FAMILY_BITMASK_3GPP | NETWORK_STANDARDS_FAMILY_BITMASK_3GPP2; 9500 } 9501 9502 /** 9503 * Returns a string representation of the allowed network types{@link NetworkTypeBitMask}. 9504 * 9505 * @param networkTypeBitmask The bitmask of allowed network types. 9506 * @return the name of the allowed network types 9507 * @hide 9508 */ convertNetworkTypeBitmaskToString( @etworkTypeBitMask long networkTypeBitmask)9509 public static String convertNetworkTypeBitmaskToString( 9510 @NetworkTypeBitMask long networkTypeBitmask) { 9511 String networkTypeName = IntStream.rangeClosed(NETWORK_TYPE_GPRS, NETWORK_TYPE_NR) 9512 .filter(x -> { 9513 return (networkTypeBitmask & getBitMaskForNetworkType(x)) 9514 == getBitMaskForNetworkType(x); 9515 }) 9516 .mapToObj(x -> getNetworkTypeName(x)) 9517 .collect(Collectors.joining("|")); 9518 return TextUtils.isEmpty(networkTypeName) ? "UNKNOWN" : networkTypeName; 9519 } 9520 9521 /** 9522 * Set the preferred network type to global mode which includes NR, LTE, CDMA, EvDo 9523 * and GSM/WCDMA. 9524 * 9525 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 9526 * 9527 * @return true on success; false on any failure. 9528 */ 9529 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) setPreferredNetworkTypeToGlobal()9530 public boolean setPreferredNetworkTypeToGlobal() { 9531 return setPreferredNetworkTypeToGlobal(getSubId()); 9532 } 9533 9534 /** 9535 * Set the preferred network type to global mode which includes NR, LTE, CDMA, EvDo 9536 * and GSM/WCDMA. 9537 * 9538 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 9539 * 9540 * @return true on success; false on any failure. 9541 * @hide 9542 */ setPreferredNetworkTypeToGlobal(int subId)9543 public boolean setPreferredNetworkTypeToGlobal(int subId) { 9544 return setPreferredNetworkType(subId, RILConstants.NETWORK_MODE_NR_LTE_CDMA_EVDO_GSM_WCDMA); 9545 } 9546 9547 /** 9548 * Check whether DUN APN is required for tethering. 9549 * <p> 9550 * Requires Permission: MODIFY_PHONE_STATE. 9551 * 9552 * @return {@code true} if DUN APN is required for tethering. 9553 * @hide 9554 */ 9555 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 9556 @SystemApi 9557 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) isTetheringApnRequired()9558 public boolean isTetheringApnRequired() { 9559 return isTetheringApnRequired(getSubId(SubscriptionManager.getActiveDataSubscriptionId())); 9560 } 9561 9562 /** 9563 * Check whether DUN APN is required for tethering with subId. 9564 * 9565 * @param subId the id of the subscription to require tethering. 9566 * @return {@code true} if DUN APN is required for tethering. 9567 * @hide 9568 */ isTetheringApnRequired(int subId)9569 public boolean isTetheringApnRequired(int subId) { 9570 try { 9571 ITelephony telephony = getITelephony(); 9572 if (telephony != null) 9573 return telephony.isTetheringApnRequiredForSubscriber(subId); 9574 } catch (RemoteException ex) { 9575 Rlog.e(TAG, "hasMatchedTetherApnSetting RemoteException", ex); 9576 } catch (NullPointerException ex) { 9577 Rlog.e(TAG, "hasMatchedTetherApnSetting NPE", ex); 9578 } 9579 return false; 9580 } 9581 9582 9583 /** 9584 * Values used to return status for hasCarrierPrivileges call. 9585 */ 9586 /** @hide */ @SystemApi 9587 public static final int CARRIER_PRIVILEGE_STATUS_HAS_ACCESS = 1; 9588 /** @hide */ @SystemApi 9589 public static final int CARRIER_PRIVILEGE_STATUS_NO_ACCESS = 0; 9590 /** @hide */ @SystemApi 9591 public static final int CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED = -1; 9592 /** @hide */ @SystemApi 9593 public static final int CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES = -2; 9594 9595 /** 9596 * Has the calling application been granted carrier privileges by the carrier. 9597 * 9598 * If any of the packages in the calling UID has carrier privileges, the 9599 * call will return true. This access is granted by the owner of the UICC 9600 * card and does not depend on the registered carrier. 9601 * 9602 * Note that this API applies to both physical and embedded subscriptions and 9603 * is a superset of the checks done in SubscriptionManager#canManageSubscription. 9604 * 9605 * @return true if the app has carrier privileges. 9606 */ 9607 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) hasCarrierPrivileges()9608 public boolean hasCarrierPrivileges() { 9609 return hasCarrierPrivileges(getSubId()); 9610 } 9611 9612 /** 9613 * Has the calling application been granted carrier privileges by the carrier. 9614 * 9615 * If any of the packages in the calling UID has carrier privileges, the 9616 * call will return true. This access is granted by the owner of the UICC 9617 * card and does not depend on the registered carrier. 9618 * 9619 * Note that this API applies to both physical and embedded subscriptions and 9620 * is a superset of the checks done in SubscriptionManager#canManageSubscription. 9621 * 9622 * @param subId The subscription to use. 9623 * @return true if the app has carrier privileges. 9624 * @hide 9625 */ hasCarrierPrivileges(int subId)9626 public boolean hasCarrierPrivileges(int subId) { 9627 try { 9628 ITelephony telephony = getITelephony(); 9629 if (telephony != null) { 9630 return telephony.getCarrierPrivilegeStatus(subId) 9631 == CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; 9632 } 9633 } catch (RemoteException ex) { 9634 Rlog.e(TAG, "hasCarrierPrivileges RemoteException", ex); 9635 } catch (NullPointerException ex) { 9636 Rlog.e(TAG, "hasCarrierPrivileges NPE", ex); 9637 } 9638 return false; 9639 } 9640 9641 /** 9642 * Override the branding for the current ICCID. 9643 * 9644 * Once set, whenever the SIM is present in the device, the service 9645 * provider name (SPN) and the operator name will both be replaced by the 9646 * brand value input. To unset the value, the same function should be 9647 * called with a null brand value. 9648 * 9649 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 9650 * 9651 * @param brand The brand name to display/set. 9652 * @return true if the operation was executed correctly. 9653 */ 9654 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) setOperatorBrandOverride(String brand)9655 public boolean setOperatorBrandOverride(String brand) { 9656 return setOperatorBrandOverride(getSubId(), brand); 9657 } 9658 9659 /** 9660 * Override the branding for the current ICCID. 9661 * 9662 * Once set, whenever the SIM is present in the device, the service 9663 * provider name (SPN) and the operator name will both be replaced by the 9664 * brand value input. To unset the value, the same function should be 9665 * called with a null brand value. 9666 * 9667 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 9668 * 9669 * @param subId The subscription to use. 9670 * @param brand The brand name to display/set. 9671 * @return true if the operation was executed correctly. 9672 * @hide 9673 */ setOperatorBrandOverride(int subId, String brand)9674 public boolean setOperatorBrandOverride(int subId, String brand) { 9675 try { 9676 ITelephony telephony = getITelephony(); 9677 if (telephony != null) 9678 return telephony.setOperatorBrandOverride(subId, brand); 9679 } catch (RemoteException ex) { 9680 Rlog.e(TAG, "setOperatorBrandOverride RemoteException", ex); 9681 } catch (NullPointerException ex) { 9682 Rlog.e(TAG, "setOperatorBrandOverride NPE", ex); 9683 } 9684 return false; 9685 } 9686 9687 /** 9688 * Override the roaming preference for the current ICCID. 9689 * 9690 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 9691 * the platform's notion of a network operator being considered roaming or not. 9692 * The change only affects the ICCID that was active when this call was made. 9693 * 9694 * If null is passed as any of the input, the corresponding value is deleted. 9695 * 9696 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 9697 * 9698 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 9699 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 9700 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 9701 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 9702 * @return true if the operation was executed correctly. 9703 * 9704 * @hide 9705 */ 9706 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setRoamingOverride(List<String> gsmRoamingList, List<String> gsmNonRoamingList, List<String> cdmaRoamingList, List<String> cdmaNonRoamingList)9707 public boolean setRoamingOverride(List<String> gsmRoamingList, 9708 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 9709 List<String> cdmaNonRoamingList) { 9710 return setRoamingOverride(getSubId(), gsmRoamingList, gsmNonRoamingList, 9711 cdmaRoamingList, cdmaNonRoamingList); 9712 } 9713 9714 /** 9715 * Override the roaming preference for the current ICCID. 9716 * 9717 * Using this call, the carrier app (see #hasCarrierPrivileges) can override 9718 * the platform's notion of a network operator being considered roaming or not. 9719 * The change only affects the ICCID that was active when this call was made. 9720 * 9721 * If null is passed as any of the input, the corresponding value is deleted. 9722 * 9723 * <p>Requires that the caller have carrier privilege. See #hasCarrierPrivileges. 9724 * 9725 * @param subId for which the roaming overrides apply. 9726 * @param gsmRoamingList - List of MCCMNCs to be considered roaming for 3GPP RATs. 9727 * @param gsmNonRoamingList - List of MCCMNCs to be considered not roaming for 3GPP RATs. 9728 * @param cdmaRoamingList - List of SIDs to be considered roaming for 3GPP2 RATs. 9729 * @param cdmaNonRoamingList - List of SIDs to be considered not roaming for 3GPP2 RATs. 9730 * @return true if the operation was executed correctly. 9731 * 9732 * @hide 9733 */ setRoamingOverride(int subId, List<String> gsmRoamingList, List<String> gsmNonRoamingList, List<String> cdmaRoamingList, List<String> cdmaNonRoamingList)9734 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, 9735 List<String> gsmNonRoamingList, List<String> cdmaRoamingList, 9736 List<String> cdmaNonRoamingList) { 9737 try { 9738 ITelephony telephony = getITelephony(); 9739 if (telephony != null) 9740 return telephony.setRoamingOverride(subId, gsmRoamingList, gsmNonRoamingList, 9741 cdmaRoamingList, cdmaNonRoamingList); 9742 } catch (RemoteException ex) { 9743 Rlog.e(TAG, "setRoamingOverride RemoteException", ex); 9744 } catch (NullPointerException ex) { 9745 Rlog.e(TAG, "setRoamingOverride NPE", ex); 9746 } 9747 return false; 9748 } 9749 9750 /** 9751 * Expose the rest of ITelephony to @SystemApi 9752 */ 9753 9754 /** @hide */ 9755 @SystemApi 9756 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 9757 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CDMA) getCdmaMdn()9758 public String getCdmaMdn() { 9759 return getCdmaMdn(getSubId()); 9760 } 9761 9762 /** @hide */ 9763 @SystemApi 9764 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 9765 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CDMA) getCdmaMdn(int subId)9766 public String getCdmaMdn(int subId) { 9767 try { 9768 ITelephony telephony = getITelephony(); 9769 if (telephony == null) 9770 return null; 9771 return telephony.getCdmaMdn(subId); 9772 } catch (RemoteException ex) { 9773 return null; 9774 } catch (NullPointerException ex) { 9775 return null; 9776 } 9777 } 9778 9779 /** @hide */ 9780 @SystemApi 9781 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 9782 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CDMA) getCdmaMin()9783 public String getCdmaMin() { 9784 return getCdmaMin(getSubId()); 9785 } 9786 9787 /** @hide */ 9788 @SystemApi 9789 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 9790 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CDMA) getCdmaMin(int subId)9791 public String getCdmaMin(int subId) { 9792 try { 9793 ITelephony telephony = getITelephony(); 9794 if (telephony == null) 9795 return null; 9796 return telephony.getCdmaMin(subId); 9797 } catch (RemoteException ex) { 9798 return null; 9799 } catch (NullPointerException ex) { 9800 return null; 9801 } 9802 } 9803 9804 /** @hide */ 9805 @SystemApi 9806 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 9807 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) checkCarrierPrivilegesForPackage(String pkgName)9808 public int checkCarrierPrivilegesForPackage(String pkgName) { 9809 try { 9810 ITelephony telephony = getITelephony(); 9811 if (telephony != null) 9812 return telephony.checkCarrierPrivilegesForPackage(getSubId(), pkgName); 9813 } catch (RemoteException ex) { 9814 Rlog.e(TAG, "checkCarrierPrivilegesForPackage RemoteException", ex); 9815 } catch (NullPointerException ex) { 9816 Rlog.e(TAG, "checkCarrierPrivilegesForPackage NPE", ex); 9817 } 9818 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 9819 } 9820 9821 /** @hide */ 9822 @SystemApi 9823 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 9824 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) checkCarrierPrivilegesForPackageAnyPhone(String pkgName)9825 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { 9826 try { 9827 ITelephony telephony = getITelephony(); 9828 if (telephony != null) 9829 return telephony.checkCarrierPrivilegesForPackageAnyPhone(pkgName); 9830 } catch (RemoteException ex) { 9831 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone RemoteException", ex); 9832 } catch (NullPointerException ex) { 9833 Rlog.e(TAG, "checkCarrierPrivilegesForPackageAnyPhone NPE", ex); 9834 } 9835 return CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 9836 } 9837 9838 /** @hide */ 9839 @SystemApi 9840 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getCarrierPackageNamesForIntent(Intent intent)9841 public List<String> getCarrierPackageNamesForIntent(Intent intent) { 9842 return getCarrierPackageNamesForIntentAndPhone(intent, getPhoneId()); 9843 } 9844 9845 /** @hide */ 9846 @SystemApi 9847 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 9848 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId)9849 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { 9850 try { 9851 ITelephony telephony = getITelephony(); 9852 if (telephony != null) 9853 return telephony.getCarrierPackageNamesForIntentAndPhone(intent, phoneId); 9854 } catch (RemoteException ex) { 9855 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone RemoteException", ex); 9856 } catch (NullPointerException ex) { 9857 Rlog.e(TAG, "getCarrierPackageNamesForIntentAndPhone NPE", ex); 9858 } 9859 return null; 9860 } 9861 9862 /** 9863 * Returns the package name that provides the {@link CarrierService} implementation for the 9864 * current subscription, or {@code null} if no package with carrier privileges declares one. 9865 * 9866 * <p>If this object has been created with {@link #createForSubscriptionId}, then the provided 9867 * subscription ID is used. Otherwise, the default subscription ID will be used. 9868 * 9869 * @return The system-selected package that provides the {@link CarrierService} implementation 9870 * for the current subscription, or {@code null} if none is resolved 9871 * 9872 * @hide 9873 */ 9874 @SystemApi 9875 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getCarrierServicePackageName()9876 public @Nullable String getCarrierServicePackageName() { 9877 return getCarrierServicePackageNameForLogicalSlot(getPhoneId()); 9878 } 9879 9880 /** 9881 * Returns the package name that provides the {@link CarrierService} implementation for the 9882 * specified {@code logicalSlotIndex}, or {@code null} if no package with carrier privileges 9883 * declares one. 9884 * 9885 * @param logicalSlotIndex The slot index to fetch the {@link CarrierService} package for 9886 * @return The system-selected package that provides the {@link CarrierService} implementation 9887 * for the slot, or {@code null} if none is resolved 9888 * 9889 * @hide 9890 */ 9891 @SystemApi 9892 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex)9893 public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { 9894 try { 9895 ITelephony telephony = getITelephony(); 9896 if (telephony != null) { 9897 return telephony.getCarrierServicePackageNameForLogicalSlot(logicalSlotIndex); 9898 } 9899 } catch (RemoteException ex) { 9900 Rlog.e(TAG, "getCarrierServicePackageNameForLogicalSlot RemoteException", ex); 9901 } catch (NullPointerException ex) { 9902 Rlog.e(TAG, "getCarrierServicePackageNameForLogicalSlot NPE", ex); 9903 } 9904 return null; 9905 } 9906 9907 /** @hide */ 9908 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getPackagesWithCarrierPrivileges()9909 public List<String> getPackagesWithCarrierPrivileges() { 9910 try { 9911 ITelephony telephony = getITelephony(); 9912 if (telephony != null) { 9913 return telephony.getPackagesWithCarrierPrivileges(getPhoneId()); 9914 } 9915 } catch (RemoteException ex) { 9916 Rlog.e(TAG, "getPackagesWithCarrierPrivileges RemoteException", ex); 9917 } catch (NullPointerException ex) { 9918 Rlog.e(TAG, "getPackagesWithCarrierPrivileges NPE", ex); 9919 } 9920 return Collections.EMPTY_LIST; 9921 } 9922 9923 /** 9924 * Get the names of packages with carrier privileges for all the active subscriptions. 9925 * 9926 * @hide 9927 */ 9928 @SystemApi 9929 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 9930 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) 9931 @NonNull getCarrierPrivilegedPackagesForAllActiveSubscriptions()9932 public List<String> getCarrierPrivilegedPackagesForAllActiveSubscriptions() { 9933 try { 9934 ITelephony telephony = getITelephony(); 9935 if (telephony != null) { 9936 return telephony.getPackagesWithCarrierPrivilegesForAllPhones(); 9937 } 9938 } catch (RemoteException ex) { 9939 Rlog.e(TAG, "getCarrierPrivilegedPackagesForAllActiveSubscriptions RemoteException", 9940 ex); 9941 } catch (NullPointerException ex) { 9942 Rlog.e(TAG, "getCarrierPrivilegedPackagesForAllActiveSubscriptions NPE", ex); 9943 } 9944 return Collections.EMPTY_LIST; 9945 } 9946 9947 /** 9948 * Call composer status OFF from user setting. 9949 */ 9950 public static final int CALL_COMPOSER_STATUS_OFF = 0; 9951 9952 /** 9953 * Call composer status ON from user setting. 9954 */ 9955 public static final int CALL_COMPOSER_STATUS_ON = 1; 9956 9957 /** @hide */ 9958 @IntDef(prefix = {"CALL_COMPOSER_STATUS_"}, 9959 value = { 9960 CALL_COMPOSER_STATUS_ON, 9961 CALL_COMPOSER_STATUS_OFF, 9962 }) 9963 public @interface CallComposerStatus {} 9964 9965 /** 9966 * Set the user-set status for enriched calling with call composer. 9967 * 9968 * @param status user-set status for enriched calling with call composer. 9969 * 9970 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 9971 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 9972 * 9973 * @throws IllegalArgumentException if requested state is invalid. 9974 * @throws SecurityException if the caller does not have the permission. 9975 */ 9976 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 9977 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) setCallComposerStatus(@allComposerStatus int status)9978 public void setCallComposerStatus(@CallComposerStatus int status) { 9979 if (status > CALL_COMPOSER_STATUS_ON 9980 || status < CALL_COMPOSER_STATUS_OFF) { 9981 throw new IllegalArgumentException("requested status is invalid"); 9982 } 9983 try { 9984 ITelephony telephony = getITelephony(); 9985 if (telephony != null) { 9986 telephony.setCallComposerStatus(getSubId(), status); 9987 } 9988 } catch (RemoteException ex) { 9989 Log.e(TAG, "Error calling ITelephony#setCallComposerStatus", ex); 9990 ex.rethrowFromSystemServer(); 9991 } 9992 } 9993 9994 /** 9995 * Get the user-set status for enriched calling with call composer. 9996 * 9997 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 9998 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 9999 * 10000 * @throws SecurityException if the caller does not have the permission. 10001 * 10002 * @return the user-set status for enriched calling with call composer, either of 10003 * {@link #CALL_COMPOSER_STATUS_ON} or {@link #CALL_COMPOSER_STATUS_OFF}. 10004 */ 10005 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 10006 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) getCallComposerStatus()10007 public @CallComposerStatus int getCallComposerStatus() { 10008 try { 10009 ITelephony telephony = getITelephony(); 10010 if (telephony != null) { 10011 return telephony.getCallComposerStatus(getSubId()); 10012 } 10013 } catch (RemoteException ex) { 10014 Log.e(TAG, "Error calling ITelephony#getCallComposerStatus", ex); 10015 ex.rethrowFromSystemServer(); 10016 } 10017 return CALL_COMPOSER_STATUS_OFF; 10018 } 10019 10020 /** @hide */ 10021 @SystemApi 10022 @SuppressLint("RequiresPermission") 10023 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) dial(String number)10024 public void dial(String number) { 10025 try { 10026 ITelephony telephony = getITelephony(); 10027 if (telephony != null) 10028 telephony.dial(number); 10029 } catch (RemoteException e) { 10030 Log.e(TAG, "Error calling ITelephony#dial", e); 10031 } 10032 } 10033 10034 /** 10035 * @deprecated Use {@link android.telecom.TelecomManager#placeCall(Uri address, 10036 * Bundle extras)} instead. 10037 * @hide 10038 */ 10039 @Deprecated 10040 @SystemApi 10041 @RequiresPermission(android.Manifest.permission.CALL_PHONE) call(String callingPackage, String number)10042 public void call(String callingPackage, String number) { 10043 try { 10044 ITelephony telephony = getITelephony(); 10045 if (telephony != null) 10046 telephony.call(callingPackage, number); 10047 } catch (RemoteException e) { 10048 Log.e(TAG, "Error calling ITelephony#call", e); 10049 } 10050 } 10051 10052 /** 10053 * @removed Use {@link android.telecom.TelecomManager#endCall()} instead. 10054 * @hide 10055 * @removed 10056 */ 10057 @Deprecated 10058 @SystemApi 10059 @RequiresPermission(android.Manifest.permission.CALL_PHONE) endCall()10060 public boolean endCall() { 10061 return false; 10062 } 10063 10064 /** 10065 * @removed Use {@link android.telecom.TelecomManager#acceptRingingCall} instead 10066 * @hide 10067 * @removed 10068 */ 10069 @Deprecated 10070 @SystemApi 10071 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) answerRingingCall()10072 public void answerRingingCall() { 10073 // No-op 10074 } 10075 10076 /** 10077 * @removed Use {@link android.telecom.TelecomManager#silenceRinger} instead 10078 * @hide 10079 */ 10080 @Deprecated 10081 @SystemApi 10082 @SuppressLint("RequiresPermission") silenceRinger()10083 public void silenceRinger() { 10084 // No-op 10085 } 10086 10087 /** 10088 * @deprecated Use {@link android.telecom.TelecomManager#isInCall} instead 10089 * @hide 10090 */ 10091 @Deprecated 10092 @SystemApi 10093 @RequiresPermission(anyOf = { 10094 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 10095 android.Manifest.permission.READ_PHONE_STATE 10096 }) isOffhook()10097 public boolean isOffhook() { 10098 TelecomManager tm = (TelecomManager) mContext.getSystemService(TELECOM_SERVICE); 10099 return tm.isInCall(); 10100 } 10101 10102 /** 10103 * @deprecated Use {@link android.telecom.TelecomManager#isRinging} instead 10104 * @hide 10105 */ 10106 @Deprecated 10107 @SystemApi 10108 @RequiresPermission(anyOf = { 10109 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 10110 android.Manifest.permission.READ_PHONE_STATE 10111 }) isRinging()10112 public boolean isRinging() { 10113 TelecomManager tm = (TelecomManager) mContext.getSystemService(TELECOM_SERVICE); 10114 return tm.isRinging(); 10115 } 10116 10117 /** 10118 * @deprecated Use {@link android.telecom.TelecomManager#isInCall} instead 10119 * @hide 10120 */ 10121 @Deprecated 10122 @SystemApi 10123 @RequiresPermission(anyOf = { 10124 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 10125 android.Manifest.permission.READ_PHONE_STATE 10126 }) isIdle()10127 public boolean isIdle() { 10128 TelecomManager tm = (TelecomManager) mContext.getSystemService(TELECOM_SERVICE); 10129 return !tm.isInCall(); 10130 } 10131 10132 /** 10133 * @deprecated Use {@link android.telephony.TelephonyManager#getServiceState} instead 10134 * @hide 10135 */ 10136 @Deprecated 10137 @SystemApi 10138 @RequiresPermission(anyOf = { 10139 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 10140 android.Manifest.permission.READ_PHONE_STATE 10141 }) isRadioOn()10142 public boolean isRadioOn() { 10143 try { 10144 ITelephony telephony = getITelephony(); 10145 if (telephony != null) 10146 return telephony.isRadioOnWithFeature(getOpPackageName(), getAttributionTag()); 10147 } catch (RemoteException e) { 10148 Log.e(TAG, "Error calling ITelephony#isRadioOn", e); 10149 } 10150 return false; 10151 } 10152 10153 /** @hide */ 10154 @SystemApi 10155 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10156 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) supplyPin(String pin)10157 public boolean supplyPin(String pin) { 10158 try { 10159 ITelephony telephony = getITelephony(); 10160 if (telephony != null) 10161 return telephony.supplyPinForSubscriber(getSubId(), pin); 10162 } catch (RemoteException e) { 10163 Log.e(TAG, "Error calling ITelephony#supplyPinForSubscriber", e); 10164 } 10165 return false; 10166 } 10167 10168 /** @hide */ 10169 @SystemApi 10170 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10171 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) supplyPuk(String puk, String pin)10172 public boolean supplyPuk(String puk, String pin) { 10173 try { 10174 ITelephony telephony = getITelephony(); 10175 if (telephony != null) 10176 return telephony.supplyPukForSubscriber(getSubId(), puk, pin); 10177 } catch (RemoteException e) { 10178 Log.e(TAG, "Error calling ITelephony#supplyPukForSubscriber", e); 10179 } 10180 return false; 10181 } 10182 10183 /** 10184 * @deprecated use {@link #supplyIccLockPin(String)} instead. 10185 * @hide 10186 */ 10187 @SystemApi 10188 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10189 @Deprecated supplyPinReportResult(String pin)10190 public int[] supplyPinReportResult(String pin) { 10191 try { 10192 ITelephony telephony = getITelephony(); 10193 if (telephony != null) 10194 return telephony.supplyPinReportResultForSubscriber(getSubId(), pin); 10195 } catch (RemoteException e) { 10196 Log.e(TAG, "Error calling ITelephony#supplyPinReportResultForSubscriber", e); 10197 } 10198 return new int[0]; 10199 } 10200 10201 /** 10202 * @deprecated use {@link #supplyIccLockPuk(String, String)} instead. 10203 * @hide 10204 */ 10205 @SystemApi 10206 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10207 @Deprecated supplyPukReportResult(String puk, String pin)10208 public int[] supplyPukReportResult(String puk, String pin) { 10209 try { 10210 ITelephony telephony = getITelephony(); 10211 if (telephony != null) 10212 return telephony.supplyPukReportResultForSubscriber(getSubId(), puk, pin); 10213 } catch (RemoteException e) { 10214 Log.e(TAG, "Error calling ITelephony#supplyPukReportResultForSubscriber", e); 10215 } 10216 return new int[0]; 10217 } 10218 10219 /** 10220 * Supplies a PIN to unlock the ICC and returns the corresponding {@link PinResult}. 10221 * Used when the user enters their ICC unlock PIN to attempt an unlock. 10222 * 10223 * @param pin The user entered PIN. 10224 * @return The result of the PIN. 10225 * @throws SecurityException if the caller doesn't have the permission. 10226 * @throws IllegalStateException if the Telephony process is not currently available. 10227 * 10228 * <p>Requires Permission: 10229 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 10230 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 10231 * 10232 * @hide 10233 */ 10234 @SystemApi 10235 @NonNull 10236 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10237 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) supplyIccLockPin(@onNull String pin)10238 public PinResult supplyIccLockPin(@NonNull String pin) { 10239 try { 10240 ITelephony telephony = getITelephony(); 10241 if (telephony != null) { 10242 int[] result = telephony.supplyPinReportResultForSubscriber(getSubId(), pin); 10243 return new PinResult(result[0], result[1]); 10244 } else { 10245 throw new IllegalStateException("telephony service is null."); 10246 } 10247 } catch (RemoteException e) { 10248 Log.e(TAG, "Error calling ITelephony#supplyIccLockPin", e); 10249 e.rethrowFromSystemServer(); 10250 } 10251 return PinResult.getDefaultFailedResult(); 10252 } 10253 10254 /** 10255 * Supplies a PUK and PIN to unlock the ICC and returns the corresponding {@link PinResult}. 10256 * Used when the user enters their ICC unlock PUK and PIN to attempt an unlock. 10257 * 10258 * @param puk The product unlocking key. 10259 * @param pin The user entered PIN. 10260 * @return The result of the PUK and PIN. 10261 * @throws SecurityException if the caller doesn't have the permission. 10262 * @throws IllegalStateException if the Telephony process is not currently available. 10263 * 10264 * <p>Requires Permission: 10265 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 10266 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 10267 * 10268 * @hide 10269 */ 10270 @SystemApi 10271 @NonNull 10272 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10273 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) supplyIccLockPuk(@onNull String puk, @NonNull String pin)10274 public PinResult supplyIccLockPuk(@NonNull String puk, @NonNull String pin) { 10275 try { 10276 ITelephony telephony = getITelephony(); 10277 if (telephony != null) { 10278 int[] result = telephony.supplyPukReportResultForSubscriber(getSubId(), puk, pin); 10279 return new PinResult(result[0], result[1]); 10280 } else { 10281 throw new IllegalStateException("telephony service is null."); 10282 } 10283 } catch (RemoteException e) { 10284 Log.e(TAG, "Error calling ITelephony#supplyIccLockPuk", e); 10285 e.rethrowFromSystemServer(); 10286 } 10287 return PinResult.getDefaultFailedResult(); 10288 } 10289 10290 /** 10291 * Used to notify callers of 10292 * {@link TelephonyManager#sendUssdRequest(String, UssdResponseCallback, Handler)} when the 10293 * network either successfully executes a USSD request, or if there was a failure while 10294 * executing the request. 10295 * <p> 10296 * {@link #onReceiveUssdResponse(TelephonyManager, String, CharSequence)} will be called if the 10297 * USSD request has succeeded. 10298 * {@link #onReceiveUssdResponseFailed(TelephonyManager, String, int)} will be called if the 10299 * USSD request has failed. 10300 */ 10301 public static abstract class UssdResponseCallback { 10302 /** 10303 * Called when a USSD request has succeeded. The {@code response} contains the USSD 10304 * response received from the network. The calling app can choose to either display the 10305 * response to the user or perform some operation based on the response. 10306 * <p> 10307 * USSD responses are unstructured text and their content is determined by the mobile network 10308 * operator. 10309 * 10310 * @param telephonyManager the TelephonyManager the callback is registered to. 10311 * @param request the USSD request sent to the mobile network. 10312 * @param response the response to the USSD request provided by the mobile network. 10313 **/ onReceiveUssdResponse(final TelephonyManager telephonyManager, String request, CharSequence response)10314 public void onReceiveUssdResponse(final TelephonyManager telephonyManager, 10315 String request, CharSequence response) {}; 10316 10317 /** 10318 * Called when a USSD request has failed to complete. 10319 * 10320 * @param telephonyManager the TelephonyManager the callback is registered to. 10321 * @param request the USSD request sent to the mobile network. 10322 * @param failureCode failure code indicating why the request failed. Will be either 10323 * {@link TelephonyManager#USSD_RETURN_FAILURE} or 10324 * {@link TelephonyManager#USSD_ERROR_SERVICE_UNAVAIL}. 10325 **/ onReceiveUssdResponseFailed(final TelephonyManager telephonyManager, String request, int failureCode)10326 public void onReceiveUssdResponseFailed(final TelephonyManager telephonyManager, 10327 String request, int failureCode) {}; 10328 } 10329 10330 /** 10331 * Sends an Unstructured Supplementary Service Data (USSD) request to the mobile network and 10332 * informs the caller of the response via the supplied {@code callback}. 10333 * <p>Carriers define USSD codes which can be sent by the user to request information such as 10334 * the user's current data balance or minutes balance. 10335 * <p>Requires permission: 10336 * {@link android.Manifest.permission#CALL_PHONE} 10337 * @param ussdRequest the USSD command to be executed. 10338 * @param callback called by the framework to inform the caller of the result of executing the 10339 * USSD request (see {@link UssdResponseCallback}). 10340 * @param handler the {@link Handler} to run the request on. 10341 */ 10342 @RequiresPermission(android.Manifest.permission.CALL_PHONE) 10343 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) sendUssdRequest(String ussdRequest, final UssdResponseCallback callback, Handler handler)10344 public void sendUssdRequest(String ussdRequest, 10345 final UssdResponseCallback callback, Handler handler) { 10346 checkNotNull(callback, "UssdResponseCallback cannot be null."); 10347 final TelephonyManager telephonyManager = this; 10348 10349 ResultReceiver wrappedCallback = new ResultReceiver(handler) { 10350 @Override 10351 protected void onReceiveResult(int resultCode, Bundle ussdResponse) { 10352 Rlog.d(TAG, "USSD:" + resultCode); 10353 checkNotNull(ussdResponse, "ussdResponse cannot be null."); 10354 UssdResponse response = ussdResponse.getParcelable(USSD_RESPONSE); 10355 10356 if (resultCode == USSD_RETURN_SUCCESS) { 10357 callback.onReceiveUssdResponse(telephonyManager, response.getUssdRequest(), 10358 response.getReturnMessage()); 10359 } else { 10360 callback.onReceiveUssdResponseFailed(telephonyManager, 10361 response.getUssdRequest(), resultCode); 10362 } 10363 } 10364 }; 10365 10366 try { 10367 ITelephony telephony = getITelephony(); 10368 if (telephony != null) { 10369 telephony.handleUssdRequest(getSubId(), ussdRequest, wrappedCallback); 10370 } 10371 } catch (RemoteException e) { 10372 Log.e(TAG, "Error calling ITelephony#sendUSSDCode", e); 10373 UssdResponse response = new UssdResponse(ussdRequest, ""); 10374 Bundle returnData = new Bundle(); 10375 returnData.putParcelable(USSD_RESPONSE, response); 10376 wrappedCallback.send(USSD_ERROR_SERVICE_UNAVAIL, returnData); 10377 } 10378 } 10379 10380 /** 10381 * Whether the device is currently on a technology (e.g. UMTS or LTE) which can support 10382 * voice and data simultaneously. This can change based on location or network condition. 10383 * 10384 * @return {@code true} if simultaneous voice and data supported, and {@code false} otherwise. 10385 */ 10386 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) isConcurrentVoiceAndDataSupported()10387 public boolean isConcurrentVoiceAndDataSupported() { 10388 try { 10389 ITelephony telephony = getITelephony(); 10390 return (telephony == null ? false : telephony.isConcurrentVoiceAndDataAllowed( 10391 getSubId())); 10392 } catch (RemoteException e) { 10393 Log.e(TAG, "Error calling ITelephony#isConcurrentVoiceAndDataAllowed", e); 10394 } 10395 return false; 10396 } 10397 10398 /** @hide */ 10399 @SystemApi 10400 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) handlePinMmi(String dialString)10401 public boolean handlePinMmi(String dialString) { 10402 try { 10403 ITelephony telephony = getITelephony(); 10404 if (telephony != null) 10405 return telephony.handlePinMmi(dialString); 10406 } catch (RemoteException e) { 10407 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 10408 } 10409 return false; 10410 } 10411 10412 /** @hide */ 10413 @SystemApi 10414 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) handlePinMmiForSubscriber(int subId, String dialString)10415 public boolean handlePinMmiForSubscriber(int subId, String dialString) { 10416 try { 10417 ITelephony telephony = getITelephony(); 10418 if (telephony != null) 10419 return telephony.handlePinMmiForSubscriber(subId, dialString); 10420 } catch (RemoteException e) { 10421 Log.e(TAG, "Error calling ITelephony#handlePinMmi", e); 10422 } 10423 return false; 10424 } 10425 10426 /** @hide */ 10427 @SystemApi 10428 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10429 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) toggleRadioOnOff()10430 public void toggleRadioOnOff() { 10431 try { 10432 ITelephony telephony = getITelephony(); 10433 if (telephony != null) 10434 telephony.toggleRadioOnOff(); 10435 } catch (RemoteException e) { 10436 Log.e(TAG, "Error calling ITelephony#toggleRadioOnOff", e); 10437 } 10438 } 10439 10440 /** @hide */ 10441 @SystemApi 10442 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10443 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) setRadio(boolean turnOn)10444 public boolean setRadio(boolean turnOn) { 10445 try { 10446 ITelephony telephony = getITelephony(); 10447 if (telephony != null) 10448 return telephony.setRadio(turnOn); 10449 } catch (RemoteException e) { 10450 Log.e(TAG, "Error calling ITelephony#setRadio", e); 10451 } 10452 return false; 10453 } 10454 10455 /** @hide */ 10456 @SystemApi 10457 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10458 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) setRadioPower(boolean turnOn)10459 public boolean setRadioPower(boolean turnOn) { 10460 try { 10461 ITelephony telephony = getITelephony(); 10462 if (telephony != null) 10463 return telephony.setRadioPower(turnOn); 10464 } catch (RemoteException e) { 10465 Log.e(TAG, "Error calling ITelephony#setRadioPower", e); 10466 } 10467 return false; 10468 } 10469 10470 /** 10471 * Shut down all the live radios over all the slot indexes. 10472 * 10473 * <p>To know when the radio has completed powering off, use 10474 * {@link PhoneStateListener#LISTEN_SERVICE_STATE LISTEN_SERVICE_STATE}. 10475 * 10476 * @hide 10477 */ 10478 @SystemApi 10479 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10480 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) shutdownAllRadios()10481 public void shutdownAllRadios() { 10482 try { 10483 ITelephony telephony = getITelephony(); 10484 if (telephony != null) { 10485 telephony.shutdownMobileRadios(); 10486 } 10487 } catch (RemoteException e) { 10488 Log.e(TAG, "Error calling ITelephony#shutdownAllRadios", e); 10489 e.rethrowAsRuntimeException(); 10490 } 10491 } 10492 10493 /** 10494 * Check if any radio is on over all the slot indexes. 10495 * 10496 * @return {@code true} if any radio is on over any slot index. 10497 * @hide 10498 */ 10499 @SystemApi 10500 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 10501 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) isAnyRadioPoweredOn()10502 public boolean isAnyRadioPoweredOn() { 10503 try { 10504 ITelephony telephony = getITelephony(); 10505 if (telephony != null) { 10506 return telephony.needMobileRadioShutdown(); 10507 } 10508 } catch (RemoteException e) { 10509 Log.e(TAG, "Error calling ITelephony#isAnyRadioPoweredOn", e); 10510 e.rethrowAsRuntimeException(); 10511 } 10512 return false; 10513 } 10514 10515 /** 10516 * Radio explicitly powered off (e.g, airplane mode). 10517 * @hide 10518 */ 10519 @SystemApi 10520 public static final int RADIO_POWER_OFF = 0; 10521 10522 /** 10523 * Radio power is on. 10524 * @hide 10525 */ 10526 @SystemApi 10527 public static final int RADIO_POWER_ON = 1; 10528 10529 /** 10530 * Radio power unavailable (eg, modem resetting or not booted). 10531 * @hide 10532 */ 10533 @SystemApi 10534 public static final int RADIO_POWER_UNAVAILABLE = 2; 10535 10536 /** 10537 * @return current modem radio state. 10538 * 10539 * <p>Requires permission: {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} or 10540 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling 10541 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 10542 * 10543 * @hide 10544 */ 10545 @SystemApi 10546 @RequiresPermission(anyOf = {android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 10547 android.Manifest.permission.READ_PHONE_STATE}) 10548 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) getRadioPowerState()10549 public @RadioPowerState int getRadioPowerState() { 10550 try { 10551 ITelephony telephony = getITelephony(); 10552 if (telephony != null) { 10553 return telephony.getRadioPowerState(getSlotIndex(), mContext.getOpPackageName(), 10554 mContext.getAttributionTag()); 10555 } 10556 } catch (RemoteException ex) { 10557 // This could happen if binder process crashes. 10558 } 10559 return RADIO_POWER_UNAVAILABLE; 10560 } 10561 10562 /** 10563 * This method should not be used due to privacy and stability concerns. 10564 * 10565 * @hide 10566 */ 10567 @SystemApi updateServiceLocation()10568 public void updateServiceLocation() { 10569 Log.e(TAG, "Do not call TelephonyManager#updateServiceLocation()"); 10570 } 10571 10572 /** @hide */ 10573 @SystemApi 10574 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10575 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) enableDataConnectivity()10576 public boolean enableDataConnectivity() { 10577 try { 10578 ITelephony telephony = getITelephony(); 10579 if (telephony != null) 10580 return telephony.enableDataConnectivity(getOpPackageName()); 10581 } catch (RemoteException e) { 10582 Log.e(TAG, "Error calling ITelephony#enableDataConnectivity", e); 10583 } 10584 return false; 10585 } 10586 10587 /** @hide */ 10588 @SystemApi 10589 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10590 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) disableDataConnectivity()10591 public boolean disableDataConnectivity() { 10592 try { 10593 ITelephony telephony = getITelephony(); 10594 if (telephony != null) 10595 return telephony.disableDataConnectivity(getOpPackageName()); 10596 } catch (RemoteException e) { 10597 Log.e(TAG, "Error calling ITelephony#disableDataConnectivity", e); 10598 } 10599 return false; 10600 } 10601 10602 /** @hide */ 10603 @SystemApi 10604 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) isDataConnectivityPossible()10605 public boolean isDataConnectivityPossible() { 10606 try { 10607 ITelephony telephony = getITelephony(); 10608 if (telephony != null) 10609 return telephony.isDataConnectivityPossible(getSubId(SubscriptionManager 10610 .getActiveDataSubscriptionId())); 10611 } catch (RemoteException e) { 10612 Log.e(TAG, "Error calling ITelephony#isDataAllowed", e); 10613 } 10614 return false; 10615 } 10616 10617 /** @hide */ 10618 @SystemApi 10619 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) needsOtaServiceProvisioning()10620 public boolean needsOtaServiceProvisioning() { 10621 try { 10622 ITelephony telephony = getITelephony(); 10623 if (telephony != null) 10624 return telephony.needsOtaServiceProvisioning(); 10625 } catch (RemoteException e) { 10626 Log.e(TAG, "Error calling ITelephony#needsOtaServiceProvisioning", e); 10627 } 10628 return false; 10629 } 10630 10631 /** 10632 * Get the mobile provisioning url that is used to launch a browser to allow users to manage 10633 * their mobile plan. 10634 * 10635 * <p>Requires Permission: 10636 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE}. 10637 * 10638 * TODO: The legacy design only supports single sim design. Ideally, this should support 10639 * multi-sim design in current world. 10640 * 10641 * {@hide} 10642 */ 10643 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getMobileProvisioningUrl()10644 public @Nullable String getMobileProvisioningUrl() { 10645 try { 10646 final ITelephony service = getITelephony(); 10647 if (service != null) { 10648 return service.getMobileProvisioningUrl(); 10649 } else { 10650 throw new IllegalStateException("telephony service is null."); 10651 } 10652 } catch (RemoteException ex) { 10653 Rlog.e(TAG, "Telephony#getMobileProvisioningUrl RemoteException" + ex); 10654 } 10655 return null; 10656 } 10657 10658 /** 10659 * Turns mobile data on or off. 10660 * If this object has been created with {@link #createForSubscriptionId}, applies to the given 10661 * subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 10662 * 10663 * <p>Requires Permission: 10664 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 10665 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 10666 * 10667 * @param enable Whether to enable mobile data. 10668 * @deprecated use setDataEnabledForReason with reason DATA_ENABLED_REASON_USER instead. 10669 * 10670 */ 10671 @Deprecated 10672 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 10673 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataEnabled(boolean enable)10674 public void setDataEnabled(boolean enable) { 10675 setDataEnabled(getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), enable); 10676 } 10677 10678 /** 10679 * @hide 10680 * @deprecated use {@link #setDataEnabledForReason(int, boolean)} instead. 10681 */ 10682 @SystemApi 10683 @Deprecated 10684 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setDataEnabled(int subId, boolean enable)10685 public void setDataEnabled(int subId, boolean enable) { 10686 try { 10687 setDataEnabledForReason(subId, DATA_ENABLED_REASON_USER, enable); 10688 } catch (RuntimeException e) { 10689 Log.e(TAG, "Error calling setDataEnabledForReason e:" + e); 10690 } 10691 } 10692 10693 /** 10694 * @deprecated use {@link #isDataEnabled()} instead. 10695 * @hide 10696 */ 10697 @SystemApi 10698 @Deprecated getDataEnabled()10699 public boolean getDataEnabled() { 10700 return isDataEnabled(); 10701 } 10702 10703 /** 10704 * Returns whether mobile data is enabled or not per user setting. There are other factors 10705 * that could disable mobile data, but they are not considered here. 10706 * 10707 * If this object has been created with {@link #createForSubscriptionId}, applies to the given 10708 * subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 10709 * 10710 * <p>Requires one of the following permissions: 10711 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, 10712 * {@link android.Manifest.permission#MODIFY_PHONE_STATE}, or 10713 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE 10714 * READ_BASIC_PHONE_STATE} or that the calling app has carrier 10715 * privileges (see {@link #hasCarrierPrivileges}). 10716 * 10717 * <p>Note that this does not take into account any data restrictions that may be present on the 10718 * calling app. Such restrictions may be inspected with 10719 * {@link ConnectivityManager#getRestrictBackgroundStatus}. 10720 * 10721 * @return true if mobile data is enabled. 10722 */ 10723 @RequiresPermission(anyOf = {android.Manifest.permission.ACCESS_NETWORK_STATE, 10724 android.Manifest.permission.MODIFY_PHONE_STATE, 10725 android.Manifest.permission.READ_PHONE_STATE, 10726 android.Manifest.permission.READ_BASIC_PHONE_STATE}) 10727 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) isDataEnabled()10728 public boolean isDataEnabled() { 10729 try { 10730 return isDataEnabledForReason(DATA_ENABLED_REASON_USER); 10731 } catch (IllegalStateException ise) { 10732 // TODO(b/176163590): Remove this catch once TelephonyManager is booting safely. 10733 Log.e(TAG, "Error calling #isDataEnabled, returning default (false).", ise); 10734 return false; 10735 } 10736 } 10737 10738 /** 10739 * Returns whether mobile data roaming is enabled on the subscription. 10740 * 10741 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 10742 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 10743 * 10744 * <p>Requires one of the following permissions: 10745 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, 10746 * {@link android.Manifest.permission#READ_PHONE_STATE} or 10747 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE 10748 * READ_BASIC_PHONE_STATE} or that the calling app 10749 * has carrier privileges (see {@link #hasCarrierPrivileges}). 10750 * 10751 * @return {@code true} if the data roaming is enabled on the subscription, otherwise return 10752 * {@code false}. 10753 */ 10754 @RequiresPermission(anyOf = {android.Manifest.permission.ACCESS_NETWORK_STATE, 10755 android.Manifest.permission.READ_PHONE_STATE, 10756 android.Manifest.permission.READ_BASIC_PHONE_STATE}) 10757 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) isDataRoamingEnabled()10758 public boolean isDataRoamingEnabled() { 10759 boolean isDataRoamingEnabled = false; 10760 try { 10761 ITelephony telephony = getITelephony(); 10762 if (telephony != null) { 10763 isDataRoamingEnabled = telephony.isDataRoamingEnabled( 10764 getSubId(SubscriptionManager.getDefaultDataSubscriptionId())); 10765 } 10766 } catch (RemoteException e) { 10767 Log.e(TAG, "Error calling ITelephony#isDataRoamingEnabled", e); 10768 } 10769 return isDataRoamingEnabled; 10770 } 10771 10772 /** 10773 * Gets the roaming mode for CDMA phone. 10774 * 10775 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 10776 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 10777 * 10778 * @return the CDMA roaming mode. 10779 * @throws SecurityException if the caller does not have the permission. 10780 * @throws IllegalStateException if the Telephony process is not currently available. 10781 * 10782 * @see #CDMA_ROAMING_MODE_RADIO_DEFAULT 10783 * @see #CDMA_ROAMING_MODE_HOME 10784 * @see #CDMA_ROAMING_MODE_AFFILIATED 10785 * @see #CDMA_ROAMING_MODE_ANY 10786 * 10787 * <p>Requires permission: 10788 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 10789 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 10790 * 10791 * @hide 10792 */ 10793 @SystemApi 10794 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 10795 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CDMA) getCdmaRoamingMode()10796 public @CdmaRoamingMode int getCdmaRoamingMode() { 10797 int mode = CDMA_ROAMING_MODE_RADIO_DEFAULT; 10798 try { 10799 ITelephony telephony = getITelephony(); 10800 if (telephony != null) { 10801 mode = telephony.getCdmaRoamingMode(getSubId()); 10802 } else { 10803 throw new IllegalStateException("telephony service is null."); 10804 } 10805 } catch (RemoteException ex) { 10806 Log.e(TAG, "Error calling ITelephony#getCdmaRoamingMode", ex); 10807 ex.rethrowFromSystemServer(); 10808 } 10809 return mode; 10810 } 10811 10812 /** 10813 * Sets the roaming mode for CDMA phone to the given mode {@code mode}. If the phone is not 10814 * CDMA capable, this method throws an IllegalStateException. 10815 * 10816 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 10817 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 10818 * 10819 * @param mode CDMA roaming mode. 10820 * @throws SecurityException if the caller does not have the permission. 10821 * @throws IllegalStateException if the Telephony process or radio is not currently available, 10822 * the device is not CDMA capable, or the request fails. 10823 * 10824 * @see #CDMA_ROAMING_MODE_RADIO_DEFAULT 10825 * @see #CDMA_ROAMING_MODE_HOME 10826 * @see #CDMA_ROAMING_MODE_AFFILIATED 10827 * @see #CDMA_ROAMING_MODE_ANY 10828 * 10829 * <p>Requires Permission: 10830 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 10831 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 10832 * 10833 * @hide 10834 */ 10835 @SystemApi 10836 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10837 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CDMA) setCdmaRoamingMode(@dmaRoamingMode int mode)10838 public void setCdmaRoamingMode(@CdmaRoamingMode int mode) { 10839 if (getPhoneType() != PHONE_TYPE_CDMA) { 10840 throw new IllegalStateException("Phone does not support CDMA."); 10841 } 10842 try { 10843 ITelephony telephony = getITelephony(); 10844 if (telephony != null) { 10845 boolean result = telephony.setCdmaRoamingMode(getSubId(), mode); 10846 if (!result) throw new IllegalStateException("radio is unavailable."); 10847 } else { 10848 throw new IllegalStateException("telephony service is null."); 10849 } 10850 } catch (RemoteException ex) { 10851 Log.e(TAG, "Error calling ITelephony#setCdmaRoamingMode", ex); 10852 ex.rethrowFromSystemServer(); 10853 } 10854 } 10855 10856 /** @hide */ 10857 @IntDef(prefix = { "CDMA_SUBSCRIPTION_" }, value = { 10858 CDMA_SUBSCRIPTION_UNKNOWN, 10859 CDMA_SUBSCRIPTION_RUIM_SIM, 10860 CDMA_SUBSCRIPTION_NV 10861 }) 10862 @Retention(RetentionPolicy.SOURCE) 10863 public @interface CdmaSubscription{} 10864 10865 /** 10866 * Used for CDMA subscription mode, it'll be UNKNOWN if there is no Subscription source. 10867 * @hide 10868 */ 10869 @SystemApi 10870 public static final int CDMA_SUBSCRIPTION_UNKNOWN = -1; 10871 10872 /** 10873 * Used for CDMA subscription mode: RUIM/SIM (default) 10874 * @hide 10875 */ 10876 @SystemApi 10877 public static final int CDMA_SUBSCRIPTION_RUIM_SIM = 0; 10878 10879 /** 10880 * Used for CDMA subscription mode: NV -> non-volatile memory 10881 * @hide 10882 */ 10883 @SystemApi 10884 public static final int CDMA_SUBSCRIPTION_NV = 1; 10885 10886 /** 10887 * Gets the subscription mode for CDMA phone. 10888 * 10889 * @return the CDMA subscription mode. 10890 * @throws SecurityException if the caller does not have the permission. 10891 * @throws IllegalStateException if the Telephony process or radio is not currently available. 10892 * 10893 * @see #CDMA_SUBSCRIPTION_UNKNOWN 10894 * @see #CDMA_SUBSCRIPTION_RUIM_SIM 10895 * @see #CDMA_SUBSCRIPTION_NV 10896 * 10897 * <p>Requires Permission: 10898 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 10899 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 10900 * 10901 * @hide 10902 */ 10903 @SystemApi 10904 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 10905 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CDMA) getCdmaSubscriptionMode()10906 public @CdmaSubscription int getCdmaSubscriptionMode() { 10907 int mode = CDMA_SUBSCRIPTION_RUIM_SIM; 10908 try { 10909 ITelephony telephony = getITelephony(); 10910 if (telephony != null) { 10911 mode = telephony.getCdmaSubscriptionMode(getSubId()); 10912 } else { 10913 throw new IllegalStateException("telephony service is null."); 10914 } 10915 } catch (RemoteException ex) { 10916 Log.e(TAG, "Error calling ITelephony#getCdmaSubscriptionMode", ex); 10917 ex.rethrowFromSystemServer(); 10918 } 10919 return mode; 10920 } 10921 10922 /** 10923 * Sets the subscription mode for CDMA phone to the given mode {@code mode}. If the phone is not 10924 * CDMA capable, this method throws an IllegalStateException. 10925 * 10926 * @param mode CDMA subscription mode. 10927 * @throws SecurityException if the caller does not have the permission. 10928 * @throws IllegalStateException if the Telephony process or radio is not currently available, 10929 * the device is not CDMA capable, or the request fails. 10930 * 10931 * @see #CDMA_SUBSCRIPTION_UNKNOWN 10932 * @see #CDMA_SUBSCRIPTION_RUIM_SIM 10933 * @see #CDMA_SUBSCRIPTION_NV 10934 * 10935 * <p>Requires Permission: 10936 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 10937 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 10938 * 10939 * @hide 10940 */ 10941 @SystemApi 10942 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10943 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CDMA) setCdmaSubscriptionMode(@dmaSubscription int mode)10944 public void setCdmaSubscriptionMode(@CdmaSubscription int mode) { 10945 if (getPhoneType() != PHONE_TYPE_CDMA) { 10946 throw new IllegalStateException("Phone does not support CDMA."); 10947 } 10948 try { 10949 ITelephony telephony = getITelephony(); 10950 if (telephony != null) { 10951 boolean result = telephony.setCdmaSubscriptionMode(getSubId(), mode); 10952 if (!result) throw new IllegalStateException("radio is unavailable."); 10953 } else { 10954 throw new IllegalStateException("telephony service is null."); 10955 } 10956 } catch (RemoteException ex) { 10957 Log.e(TAG, "Error calling ITelephony#setCdmaSubscriptionMode", ex); 10958 ex.rethrowFromSystemServer(); 10959 } 10960 } 10961 10962 /** 10963 * Enables/Disables the data roaming on the subscription. 10964 * 10965 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 10966 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 10967 * 10968 * <p> Requires permission: 10969 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier 10970 * privileges (see {@link #hasCarrierPrivileges}). 10971 * 10972 * @param isEnabled {@code true} to enable mobile data roaming, otherwise disable it. 10973 * 10974 * @hide 10975 */ 10976 @SystemApi 10977 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 10978 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) setDataRoamingEnabled(boolean isEnabled)10979 public void setDataRoamingEnabled(boolean isEnabled) { 10980 try { 10981 ITelephony telephony = getITelephony(); 10982 if (telephony != null) { 10983 telephony.setDataRoamingEnabled( 10984 getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), isEnabled); 10985 } 10986 } catch (RemoteException e) { 10987 Log.e(TAG, "Error calling ITelephony#setDataRoamingEnabled", e); 10988 } 10989 } 10990 10991 /** 10992 * @deprecated use {@link #isDataEnabled()} instead. 10993 * @hide 10994 */ 10995 @Deprecated 10996 @SystemApi getDataEnabled(int subId)10997 public boolean getDataEnabled(int subId) { 10998 try { 10999 return isDataEnabledForReason(subId, DATA_ENABLED_REASON_USER); 11000 } catch (RuntimeException e) { 11001 Log.e(TAG, "Error calling isDataEnabledForReason e:" + e); 11002 } 11003 return false; 11004 } 11005 11006 /** 11007 * Returns the result and response from RIL for oem request 11008 * 11009 * @param oemReq the data is sent to ril. 11010 * @param oemResp the respose data from RIL. 11011 * @return negative value request was not handled or get error 11012 * 0 request was handled succesfully, but no response data 11013 * positive value success, data length of response 11014 * @hide 11015 * @deprecated OEM needs a vendor-extension hal and their apps should use that instead 11016 */ 11017 @Deprecated invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp)11018 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { 11019 try { 11020 ITelephony telephony = getITelephony(); 11021 if (telephony != null) 11022 return telephony.invokeOemRilRequestRaw(oemReq, oemResp); 11023 } catch (RemoteException ex) { 11024 } catch (NullPointerException ex) { 11025 } 11026 return -1; 11027 } 11028 11029 /** 11030 * @deprecated Use {@link android.telephony.ims.ImsMmTelManager#setVtSettingEnabled(boolean)} 11031 * instead. 11032 * @hide 11033 */ 11034 @Deprecated 11035 @SystemApi 11036 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) enableVideoCalling(boolean enable)11037 public void enableVideoCalling(boolean enable) { 11038 try { 11039 ITelephony telephony = getITelephony(); 11040 if (telephony != null) 11041 telephony.enableVideoCalling(enable); 11042 } catch (RemoteException e) { 11043 Log.e(TAG, "Error calling ITelephony#enableVideoCalling", e); 11044 } 11045 } 11046 11047 /** 11048 * @deprecated Use {@link ImsMmTelManager#isVtSettingEnabled()} instead to check if the user 11049 * has enabled the Video Calling setting, {@link ImsMmTelManager#isAvailable(int, int)} to 11050 * determine if video calling is available, or {@link ImsMmTelManager#isCapable(int, int)} to 11051 * determine if video calling is capable. 11052 * @hide 11053 */ 11054 @Deprecated 11055 @SystemApi 11056 @RequiresPermission(anyOf = { 11057 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 11058 android.Manifest.permission.READ_PHONE_STATE 11059 }) isVideoCallingEnabled()11060 public boolean isVideoCallingEnabled() { 11061 try { 11062 ITelephony telephony = getITelephony(); 11063 if (telephony != null) 11064 return telephony.isVideoCallingEnabled(getOpPackageName(), getAttributionTag()); 11065 } catch (RemoteException e) { 11066 Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e); 11067 } 11068 return false; 11069 } 11070 11071 /** 11072 * Whether the device supports configuring the DTMF tone length. 11073 * 11074 * @return {@code true} if the DTMF tone length can be changed, and {@code false} otherwise. 11075 */ 11076 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) canChangeDtmfToneLength()11077 public boolean canChangeDtmfToneLength() { 11078 try { 11079 ITelephony telephony = getITelephony(); 11080 if (telephony != null) { 11081 return telephony.canChangeDtmfToneLength(mSubId, getOpPackageName(), 11082 getAttributionTag()); 11083 } 11084 } catch (RemoteException e) { 11085 Log.e(TAG, "Error calling ITelephony#canChangeDtmfToneLength", e); 11086 } catch (SecurityException e) { 11087 Log.e(TAG, "Permission error calling ITelephony#canChangeDtmfToneLength", e); 11088 } 11089 return false; 11090 } 11091 11092 /** 11093 * Whether the device is a world phone. 11094 * 11095 * @return {@code true} if the device is a world phone, and {@code false} otherwise. 11096 */ isWorldPhone()11097 public boolean isWorldPhone() { 11098 try { 11099 ITelephony telephony = getITelephony(); 11100 if (telephony != null) { 11101 return telephony.isWorldPhone(mSubId, getOpPackageName(), getAttributionTag()); 11102 } 11103 } catch (RemoteException e) { 11104 Log.e(TAG, "Error calling ITelephony#isWorldPhone", e); 11105 } catch (SecurityException e) { 11106 Log.e(TAG, "Permission error calling ITelephony#isWorldPhone", e); 11107 } 11108 return false; 11109 } 11110 11111 /** 11112 * @deprecated Use {@link TelecomManager#isTtySupported()} instead 11113 * Whether the phone supports TTY mode. 11114 * 11115 * @return {@code true} if the device supports TTY mode, and {@code false} otherwise. 11116 * 11117 */ 11118 @Deprecated isTtyModeSupported()11119 public boolean isTtyModeSupported() { 11120 try { 11121 TelecomManager telecomManager = null; 11122 if (mContext != null) { 11123 telecomManager = mContext.getSystemService(TelecomManager.class); 11124 } 11125 if (telecomManager != null) { 11126 return telecomManager.isTtySupported(); 11127 } 11128 } catch (SecurityException e) { 11129 Log.e(TAG, "Permission error calling TelecomManager#isTtySupported", e); 11130 } 11131 return false; 11132 } 11133 11134 /** 11135 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier 11136 * support for the feature and device firmware support. 11137 * 11138 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. 11139 */ 11140 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_IMS) isRttSupported()11141 public boolean isRttSupported() { 11142 try { 11143 ITelephony telephony = getITelephony(); 11144 if (telephony != null) { 11145 return telephony.isRttSupported(mSubId); 11146 } 11147 } catch (RemoteException e) { 11148 Log.e(TAG, "Error calling ITelephony#isRttSupported", e); 11149 } catch (SecurityException e) { 11150 Log.e(TAG, "Permission error calling ITelephony#isWorldPhone", e); 11151 } 11152 return false; 11153 } 11154 /** 11155 * Whether the phone supports hearing aid compatibility. 11156 * 11157 * @return {@code true} if the device supports hearing aid compatibility, and {@code false} 11158 * otherwise. 11159 */ 11160 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) isHearingAidCompatibilitySupported()11161 public boolean isHearingAidCompatibilitySupported() { 11162 try { 11163 ITelephony telephony = getITelephony(); 11164 if (telephony != null) { 11165 return telephony.isHearingAidCompatibilitySupported(); 11166 } 11167 } catch (RemoteException e) { 11168 Log.e(TAG, "Error calling ITelephony#isHearingAidCompatibilitySupported", e); 11169 } catch (SecurityException e) { 11170 Log.e(TAG, "Permission error calling ITelephony#isHearingAidCompatibilitySupported", e); 11171 } 11172 return false; 11173 } 11174 11175 /** 11176 * Returns the IMS Registration Status for a particular Subscription ID. 11177 * 11178 * @param subId Subscription ID 11179 * @return true if IMS status is registered, false if the IMS status is not registered or a 11180 * RemoteException occurred. 11181 * Use {@link ImsMmTelManager.RegistrationCallback} instead. 11182 * @hide 11183 */ isImsRegistered(int subId)11184 public boolean isImsRegistered(int subId) { 11185 try { 11186 return getITelephony().isImsRegistered(subId); 11187 } catch (RemoteException | NullPointerException ex) { 11188 return false; 11189 } 11190 } 11191 11192 /** 11193 * Returns the IMS Registration Status for a particular Subscription ID, which is determined 11194 * when the TelephonyManager is created using {@link #createForSubscriptionId(int)}. If an 11195 * invalid subscription ID is used during creation, will the default subscription ID will be 11196 * used. 11197 * 11198 * @return true if IMS status is registered, false if the IMS status is not registered or a 11199 * RemoteException occurred. 11200 * @see SubscriptionManager#getDefaultSubscriptionId() 11201 * @hide 11202 */ 11203 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) isImsRegistered()11204 public boolean isImsRegistered() { 11205 try { 11206 return getITelephony().isImsRegistered(getSubId()); 11207 } catch (RemoteException | NullPointerException ex) { 11208 return false; 11209 } 11210 } 11211 11212 /** 11213 * The current status of Voice over LTE for the subscription associated with this instance when 11214 * it was created using {@link #createForSubscriptionId(int)}. If an invalid subscription ID was 11215 * used during creation, the default subscription ID will be used. 11216 * @return true if Voice over LTE is available or false if it is unavailable or unknown. 11217 * @see SubscriptionManager#getDefaultSubscriptionId() 11218 * <p> 11219 * Use {@link ImsMmTelManager#isAvailable(int, int)} instead. 11220 * @hide 11221 */ 11222 @UnsupportedAppUsage isVolteAvailable()11223 public boolean isVolteAvailable() { 11224 try { 11225 return getITelephony().isAvailable(getSubId(), 11226 MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE, 11227 ImsRegistrationImplBase.REGISTRATION_TECH_LTE); 11228 } catch (RemoteException | NullPointerException ex) { 11229 return false; 11230 } 11231 } 11232 11233 /** 11234 * The availability of Video Telephony (VT) for the subscription ID specified when this instance 11235 * was created using {@link #createForSubscriptionId(int)}. If an invalid subscription ID was 11236 * used during creation, the default subscription ID will be used. To query the 11237 * underlying technology that VT is available on, use {@link #getImsRegTechnologyForMmTel}. 11238 * @return true if VT is available, or false if it is unavailable or unknown. 11239 * Use {@link ImsMmTelManager#isAvailable(int, int)} instead. 11240 * @hide 11241 */ 11242 @UnsupportedAppUsage isVideoTelephonyAvailable()11243 public boolean isVideoTelephonyAvailable() { 11244 try { 11245 return getITelephony().isVideoTelephonyAvailable(getSubId()); 11246 } catch (RemoteException | NullPointerException ex) { 11247 return false; 11248 } 11249 } 11250 11251 /** 11252 * Returns the Status of Wi-Fi calling (Voice over WiFi) for the subscription ID specified. 11253 * @param subId the subscription ID. 11254 * @return true if VoWiFi is available, or false if it is unavailable or unknown. 11255 * Use {@link ImsMmTelManager#isAvailable(int, int)} instead. 11256 * @hide 11257 */ 11258 @UnsupportedAppUsage isWifiCallingAvailable()11259 public boolean isWifiCallingAvailable() { 11260 try { 11261 return getITelephony().isWifiCallingAvailable(getSubId()); 11262 } catch (RemoteException | NullPointerException ex) { 11263 return false; 11264 } 11265 } 11266 11267 /** 11268 * The technology that IMS is registered for for the MMTEL feature. 11269 * @param subId subscription ID to get IMS registration technology for. 11270 * @return The IMS registration technology that IMS is registered to for the MMTEL feature. 11271 * Valid return results are: 11272 * - {@link ImsRegistrationImplBase#REGISTRATION_TECH_LTE} for LTE registration, 11273 * - {@link ImsRegistrationImplBase#REGISTRATION_TECH_IWLAN} for IWLAN registration, or 11274 * - {@link ImsRegistrationImplBase#REGISTRATION_TECH_CROSS_SIM} for registration over 11275 * other sim's internet, or 11276 * - {@link ImsRegistrationImplBase#REGISTRATION_TECH_NONE} if we are not registered or the 11277 * result is unavailable. 11278 * Use {@link ImsMmTelManager.RegistrationCallback} instead. 11279 * @hide 11280 */ getImsRegTechnologyForMmTel()11281 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel() { 11282 try { 11283 return getITelephony().getImsRegTechnologyForMmTel(getSubId()); 11284 } catch (RemoteException ex) { 11285 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; 11286 } 11287 } 11288 11289 /** 11290 * Set TelephonyProperties.icc_operator_numeric for the default phone. 11291 * 11292 * @hide 11293 */ setSimOperatorNumeric(String numeric)11294 public void setSimOperatorNumeric(String numeric) { 11295 int phoneId = getPhoneId(); 11296 setSimOperatorNumericForPhone(phoneId, numeric); 11297 } 11298 11299 /** 11300 * Set TelephonyProperties.icc_operator_numeric for the given phone. 11301 * 11302 * @hide 11303 */ 11304 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setSimOperatorNumericForPhone(int phoneId, String numeric)11305 public void setSimOperatorNumericForPhone(int phoneId, String numeric) { 11306 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11307 List<String> newList = updateTelephonyProperty( 11308 TelephonyProperties.icc_operator_numeric(), phoneId, numeric); 11309 TelephonyProperties.icc_operator_numeric(newList); 11310 } 11311 } 11312 11313 /** 11314 * Set TelephonyProperties.icc_operator_alpha for the default phone. 11315 * 11316 * @hide 11317 */ setSimOperatorName(String name)11318 public void setSimOperatorName(String name) { 11319 int phoneId = getPhoneId(); 11320 setSimOperatorNameForPhone(phoneId, name); 11321 } 11322 11323 /** 11324 * Set TelephonyProperties.icc_operator_alpha for the given phone. 11325 * 11326 * @hide 11327 */ 11328 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setSimOperatorNameForPhone(int phoneId, String name)11329 public void setSimOperatorNameForPhone(int phoneId, String name) { 11330 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11331 List<String> newList = updateTelephonyProperty( 11332 TelephonyProperties.icc_operator_alpha(), phoneId, name); 11333 TelephonyProperties.icc_operator_alpha(newList); 11334 } 11335 } 11336 11337 /** 11338 * Set TelephonyProperties.icc_operator_iso_country for the default phone. 11339 * 11340 * @hide 11341 */ setSimCountryIso(String iso)11342 public void setSimCountryIso(String iso) { 11343 int phoneId = getPhoneId(); 11344 setSimCountryIsoForPhone(phoneId, iso); 11345 } 11346 11347 /** 11348 * Set TelephonyProperties.icc_operator_iso_country for the given phone. 11349 * 11350 * @hide 11351 */ 11352 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setSimCountryIsoForPhone(int phoneId, String iso)11353 public void setSimCountryIsoForPhone(int phoneId, String iso) { 11354 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11355 List<String> newList = updateTelephonyProperty( 11356 TelephonyProperties.icc_operator_iso_country(), phoneId, iso); 11357 TelephonyProperties.icc_operator_iso_country(newList); 11358 } 11359 } 11360 11361 /** 11362 * Set TelephonyProperties.sim_state for the default phone. 11363 * 11364 * @hide 11365 */ setSimState(String state)11366 public void setSimState(String state) { 11367 int phoneId = getPhoneId(); 11368 setSimStateForPhone(phoneId, state); 11369 } 11370 11371 /** 11372 * Set TelephonyProperties.sim_state for the given phone. 11373 * 11374 * @hide 11375 */ 11376 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setSimStateForPhone(int phoneId, String state)11377 public void setSimStateForPhone(int phoneId, String state) { 11378 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11379 List<String> newList = updateTelephonyProperty( 11380 TelephonyProperties.sim_state(), phoneId, state); 11381 TelephonyProperties.sim_state(newList); 11382 } 11383 } 11384 11385 /** 11386 * Powers down the SIM. SIM must be up prior. 11387 * @hide 11388 */ 11389 public static final int CARD_POWER_DOWN = 0; 11390 11391 /** 11392 * Powers up the SIM normally. SIM must be down prior. 11393 * @hide 11394 */ 11395 public static final int CARD_POWER_UP = 1; 11396 11397 /** 11398 * Powers up the SIM in PASS_THROUGH mode. SIM must be down prior. 11399 * When SIM is powered up in PASS_THOUGH mode, the modem does not send 11400 * any command to it (for example SELECT of MF, or TERMINAL CAPABILITY), 11401 * and the SIM card is controlled completely by Telephony sending APDUs 11402 * directly. The SIM card state will be RIL_CARDSTATE_PRESENT and the 11403 * number of card apps will be 0. 11404 * No new error code is generated. Emergency calls are supported in the 11405 * same way as if the SIM card is absent. 11406 * The PASS_THROUGH mode is valid only for the specific card session where it 11407 * is activated, and normal behavior occurs at the next SIM initialization, 11408 * unless PASS_THROUGH mode is requested again. Hence, the last power-up mode 11409 * is NOT persistent across boots. On reboot, SIM will power up normally. 11410 * @hide 11411 */ 11412 public static final int CARD_POWER_UP_PASS_THROUGH = 2; 11413 11414 /** @hide */ 11415 @Retention(RetentionPolicy.SOURCE) 11416 @IntDef(prefix = {"CARD_POWER"}, 11417 value = { 11418 CARD_POWER_DOWN, 11419 CARD_POWER_UP, 11420 CARD_POWER_UP_PASS_THROUGH, 11421 }) 11422 public @interface SimPowerState {} 11423 11424 /** 11425 * Set SIM card power state. 11426 * 11427 * @param state State of SIM (power down, power up, pass through) 11428 * @see #CARD_POWER_DOWN 11429 * @see #CARD_POWER_UP 11430 * @see #CARD_POWER_UP_PASS_THROUGH 11431 * Callers should monitor for {@link TelephonyIntents#ACTION_SIM_STATE_CHANGED} 11432 * broadcasts to determine success or failure and timeout if needed. 11433 * 11434 * @deprecated prefer {@link setSimPowerState(int, Executor, Consumer<Integer>)}. 11435 * There is no guarantee that SIM power changes will trigger ACTION_SIM_STATE_CHANGED on new 11436 * devices. 11437 * 11438 * <p>Requires Permission: 11439 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 11440 * 11441 * {@hide} 11442 **/ 11443 @SystemApi 11444 @Deprecated 11445 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setSimPowerState(int state)11446 public void setSimPowerState(int state) { 11447 setSimPowerStateForSlot(getSlotIndex(), state); 11448 } 11449 11450 /** 11451 * Set SIM card power state. 11452 * 11453 * @param slotIndex SIM slot id 11454 * @param state State of SIM (power down, power up, pass through) 11455 * @see #CARD_POWER_DOWN 11456 * @see #CARD_POWER_UP 11457 * @see #CARD_POWER_UP_PASS_THROUGH 11458 * Callers should monitor for {@link TelephonyIntents#ACTION_SIM_STATE_CHANGED} 11459 * broadcasts to determine success or failure and timeout if needed. 11460 * 11461 * @deprecated prefer {@link setSimPowerStateForSlot(int, int, Executor, Consumer<Integer>)}. 11462 * changes will trigger ACTION_SIM_STATE_CHANGED on new devices. 11463 * 11464 * <p>Requires Permission: 11465 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 11466 * 11467 * {@hide} 11468 **/ 11469 @SystemApi 11470 @Deprecated 11471 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setSimPowerStateForSlot(int slotIndex, int state)11472 public void setSimPowerStateForSlot(int slotIndex, int state) { 11473 try { 11474 ITelephony telephony = getITelephony(); 11475 if (telephony != null) { 11476 telephony.setSimPowerStateForSlot(slotIndex, state); 11477 } 11478 } catch (RemoteException e) { 11479 Log.e(TAG, "Error calling ITelephony#setSimPowerStateForSlot", e); 11480 } catch (SecurityException e) { 11481 Log.e(TAG, "Permission error calling ITelephony#setSimPowerStateForSlot", e); 11482 } 11483 } 11484 11485 /** 11486 * Set SIM card power state. 11487 * 11488 * @param state State of SIM (power down, power up, pass through) 11489 * @see #CARD_POWER_DOWN 11490 * @see #CARD_POWER_UP 11491 * @see #CARD_POWER_UP_PASS_THROUGH 11492 * @param executor The executor of where the callback will execute. 11493 * @param callback Callback will be triggered once it succeeds or failed. 11494 * @see #SET_SIM_POWER_STATE_SUCCESS 11495 * @see #SET_SIM_POWER_STATE_ALREADY_IN_STATE 11496 * @see #SET_SIM_POWER_STATE_MODEM_ERROR 11497 * @see #SET_SIM_POWER_STATE_SIM_ERROR 11498 * @see #SET_SIM_POWER_STATE_NOT_SUPPORTED 11499 * @throws IllegalArgumentException if requested SIM state is invalid 11500 * 11501 * <p>Requires Permission: 11502 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 11503 * 11504 * {@hide} 11505 **/ 11506 @SystemApi 11507 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 11508 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) setSimPowerState(@imPowerState int state, @NonNull Executor executor, @NonNull @SetSimPowerStateResult Consumer<Integer> callback)11509 public void setSimPowerState(@SimPowerState int state, @NonNull Executor executor, 11510 @NonNull @SetSimPowerStateResult Consumer<Integer> callback) { 11511 setSimPowerStateForSlot(getSlotIndex(), state, executor, callback); 11512 } 11513 11514 /** 11515 * Set SIM card power state. 11516 * 11517 * @param slotIndex SIM slot id 11518 * @param state State of SIM (power down, power up, pass through) 11519 * @see #CARD_POWER_DOWN 11520 * @see #CARD_POWER_UP 11521 * @see #CARD_POWER_UP_PASS_THROUGH 11522 * @param executor The executor of where the callback will execute. 11523 * @param callback Callback will be triggered once it succeeds or failed. 11524 * @see #SET_SIM_POWER_STATE_SUCCESS 11525 * @see #SET_SIM_POWER_STATE_ALREADY_IN_STATE 11526 * @see #SET_SIM_POWER_STATE_MODEM_ERROR 11527 * @see #SET_SIM_POWER_STATE_SIM_ERROR 11528 * @see #SET_SIM_POWER_STATE_NOT_SUPPORTED 11529 * @throws IllegalArgumentException if requested SIM state is invalid 11530 * 11531 * <p>Requires Permission: 11532 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 11533 * 11534 * {@hide} 11535 **/ 11536 @SystemApi 11537 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 11538 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) setSimPowerStateForSlot(int slotIndex, @SimPowerState int state, @NonNull Executor executor, @NonNull @SetSimPowerStateResult Consumer<Integer> callback)11539 public void setSimPowerStateForSlot(int slotIndex, @SimPowerState int state, 11540 @NonNull Executor executor, 11541 @NonNull @SetSimPowerStateResult Consumer<Integer> callback) { 11542 if (state != CARD_POWER_DOWN && state != CARD_POWER_UP 11543 && state != CARD_POWER_UP_PASS_THROUGH) { 11544 throw new IllegalArgumentException("requested SIM state is invalid"); 11545 } 11546 try { 11547 ITelephony telephony = getITelephony(); 11548 if (telephony == null) throw new IllegalStateException("Telephony is null."); 11549 11550 IIntegerConsumer internalCallback = new IIntegerConsumer.Stub() { 11551 @Override 11552 public void accept(int result) { 11553 executor.execute(() -> 11554 Binder.withCleanCallingIdentity(() -> callback.accept(result))); 11555 } 11556 }; 11557 if (telephony == null) { 11558 if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) { 11559 throw new IllegalStateException("Telephony is null"); 11560 } else { 11561 return; 11562 } 11563 } 11564 telephony.setSimPowerStateForSlotWithCallback(slotIndex, state, internalCallback); 11565 } catch (RemoteException e) { 11566 Log.e(TAG, "Error calling ITelephony#setSimPowerStateForSlot", e); 11567 runOnBackgroundThread(() -> executor.execute( 11568 () -> callback.accept(SET_SIM_POWER_STATE_MODEM_ERROR))); 11569 } catch (SecurityException e) { 11570 Log.e(TAG, "Permission error calling ITelephony#setSimPowerStateForSlot", 11571 e); 11572 } 11573 } 11574 11575 /** 11576 * Set baseband version for the default phone. 11577 * 11578 * @param version baseband version 11579 * @hide 11580 */ setBasebandVersion(String version)11581 public void setBasebandVersion(String version) { 11582 int phoneId = getPhoneId(); 11583 setBasebandVersionForPhone(phoneId, version); 11584 } 11585 11586 /** 11587 * Set baseband version by phone id. 11588 * 11589 * @param phoneId for which baseband version is set 11590 * @param version baseband version 11591 * @hide 11592 */ 11593 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setBasebandVersionForPhone(int phoneId, String version)11594 public void setBasebandVersionForPhone(int phoneId, String version) { 11595 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11596 List<String> newList = updateTelephonyProperty( 11597 TelephonyProperties.baseband_version(), phoneId, version); 11598 TelephonyProperties.baseband_version(newList); 11599 } 11600 } 11601 11602 /** 11603 * Get baseband version for the default phone. 11604 * 11605 * @return baseband version. 11606 * @hide 11607 */ getBasebandVersion()11608 public String getBasebandVersion() { 11609 int phoneId = getPhoneId(); 11610 return getBasebandVersionForPhone(phoneId); 11611 } 11612 11613 /** 11614 * Get baseband version by phone id. 11615 * 11616 * @return baseband version. 11617 * @hide 11618 */ getBasebandVersionForPhone(int phoneId)11619 public String getBasebandVersionForPhone(int phoneId) { 11620 return getTelephonyProperty(phoneId, TelephonyProperties.baseband_version(), ""); 11621 } 11622 11623 /** 11624 * Set phone type for the default phone. 11625 * 11626 * @param type phone type 11627 * 11628 * @hide 11629 */ setPhoneType(int type)11630 public void setPhoneType(int type) { 11631 int phoneId = getPhoneId(); 11632 setPhoneType(phoneId, type); 11633 } 11634 11635 /** 11636 * Set phone type by phone id. 11637 * 11638 * @param phoneId for which phone type is set 11639 * @param type phone type 11640 * 11641 * @hide 11642 */ 11643 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) setPhoneType(int phoneId, int type)11644 public void setPhoneType(int phoneId, int type) { 11645 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11646 List<Integer> newList = updateTelephonyProperty( 11647 TelephonyProperties.current_active_phone(), phoneId, type); 11648 TelephonyProperties.current_active_phone(newList); 11649 } 11650 } 11651 11652 /** 11653 * Get OTASP number schema for the default phone. 11654 * 11655 * @param defaultValue default value 11656 * @return OTA SP number schema 11657 * 11658 * @hide 11659 */ getOtaSpNumberSchema(String defaultValue)11660 public String getOtaSpNumberSchema(String defaultValue) { 11661 int phoneId = getPhoneId(); 11662 return getOtaSpNumberSchemaForPhone(phoneId, defaultValue); 11663 } 11664 11665 /** 11666 * Get OTASP number schema by phone id. 11667 * 11668 * @param phoneId for which OTA SP number schema is get 11669 * @param defaultValue default value 11670 * @return OTA SP number schema 11671 * 11672 * @hide 11673 */ 11674 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue)11675 public String getOtaSpNumberSchemaForPhone(int phoneId, String defaultValue) { 11676 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11677 return getTelephonyProperty( 11678 phoneId, TelephonyProperties.otasp_num_schema(), defaultValue); 11679 } 11680 11681 return defaultValue; 11682 } 11683 11684 /** 11685 * Get SMS receive capable from system property for the default phone. 11686 * 11687 * @param defaultValue default value 11688 * @return SMS receive capable 11689 * 11690 * @hide 11691 */ getSmsReceiveCapable(boolean defaultValue)11692 public boolean getSmsReceiveCapable(boolean defaultValue) { 11693 int phoneId = getPhoneId(); 11694 return getSmsReceiveCapableForPhone(phoneId, defaultValue); 11695 } 11696 11697 /** 11698 * Get SMS receive capable from system property by phone id. 11699 * 11700 * @param phoneId for which SMS receive capable is get 11701 * @param defaultValue default value 11702 * @return SMS receive capable 11703 * 11704 * @hide 11705 */ getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue)11706 public boolean getSmsReceiveCapableForPhone(int phoneId, boolean defaultValue) { 11707 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11708 return getTelephonyProperty(phoneId, TelephonyProperties.sms_receive(), defaultValue); 11709 } 11710 11711 return defaultValue; 11712 } 11713 11714 /** 11715 * Get SMS send capable from system property for the default phone. 11716 * 11717 * @param defaultValue default value 11718 * @return SMS send capable 11719 * 11720 * @hide 11721 */ getSmsSendCapable(boolean defaultValue)11722 public boolean getSmsSendCapable(boolean defaultValue) { 11723 int phoneId = getPhoneId(); 11724 return getSmsSendCapableForPhone(phoneId, defaultValue); 11725 } 11726 11727 /** 11728 * Get SMS send capable from system property by phone id. 11729 * 11730 * @param phoneId for which SMS send capable is get 11731 * @param defaultValue default value 11732 * @return SMS send capable 11733 * 11734 * @hide 11735 */ getSmsSendCapableForPhone(int phoneId, boolean defaultValue)11736 public boolean getSmsSendCapableForPhone(int phoneId, boolean defaultValue) { 11737 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11738 return getTelephonyProperty(phoneId, TelephonyProperties.sms_send(), defaultValue); 11739 } 11740 11741 return defaultValue; 11742 } 11743 11744 /** 11745 * Gets the default Respond Via Message application, updating the cache if there is no 11746 * respond-via-message application currently configured. 11747 * @return component name of the app and class to direct Respond Via Message intent to, or 11748 * {@code null} if the functionality is not supported. 11749 * @hide 11750 */ 11751 @SystemApi 11752 @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS) 11753 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING) getAndUpdateDefaultRespondViaMessageApplication()11754 public @Nullable ComponentName getAndUpdateDefaultRespondViaMessageApplication() { 11755 return SmsApplication.getDefaultRespondViaMessageApplication(mContext, true); 11756 } 11757 11758 /** 11759 * Gets the default Respond Via Message application. 11760 * @return component name of the app and class to direct Respond Via Message intent to, or 11761 * {@code null} if the functionality is not supported. 11762 * @hide 11763 */ 11764 @SystemApi 11765 @RequiresPermission(Manifest.permission.INTERACT_ACROSS_USERS) 11766 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_MESSAGING) getDefaultRespondViaMessageApplication()11767 public @Nullable ComponentName getDefaultRespondViaMessageApplication() { 11768 return SmsApplication.getDefaultRespondViaMessageApplication(mContext, false); 11769 } 11770 11771 /** 11772 * Set the alphabetic name of current registered operator. 11773 * @param name the alphabetic name of current registered operator. 11774 * @hide 11775 */ setNetworkOperatorName(String name)11776 public void setNetworkOperatorName(String name) { 11777 int phoneId = getPhoneId(); 11778 setNetworkOperatorNameForPhone(phoneId, name); 11779 } 11780 11781 /** 11782 * Set the alphabetic name of current registered operator. 11783 * @param phoneId which phone you want to set 11784 * @param name the alphabetic name of current registered operator. 11785 * @hide 11786 */ 11787 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setNetworkOperatorNameForPhone(int phoneId, String name)11788 public void setNetworkOperatorNameForPhone(int phoneId, String name) { 11789 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11790 List<String> newList = updateTelephonyProperty( 11791 TelephonyProperties.operator_alpha(), phoneId, name); 11792 try { 11793 TelephonyProperties.operator_alpha(newList); 11794 } catch (IllegalArgumentException e) { //property value is longer than the byte limit 11795 Log.e(TAG, "setNetworkOperatorNameForPhone: ", e); 11796 11797 int numberOfEntries = newList.size(); 11798 int maxOperatorLength = //save 1 byte for joiner " , " 11799 (SystemProperties.PROP_VALUE_MAX - numberOfEntries) / numberOfEntries; 11800 11801 //examine and truncate every operator and retry 11802 for (int i = 0; i < newList.size(); i++) { 11803 if (newList.get(i) != null) { 11804 newList.set(i, TextUtils 11805 .truncateStringForUtf8Storage(newList.get(i), maxOperatorLength)); 11806 } 11807 } 11808 TelephonyProperties.operator_alpha(newList); 11809 Log.e(TAG, "successfully truncated operator_alpha: " + newList); 11810 } 11811 } 11812 } 11813 11814 /** 11815 * Set the numeric name (MCC+MNC) of current registered operator. 11816 * @param operator the numeric name (MCC+MNC) of current registered operator 11817 * @hide 11818 */ setNetworkOperatorNumeric(String numeric)11819 public void setNetworkOperatorNumeric(String numeric) { 11820 int phoneId = getPhoneId(); 11821 setNetworkOperatorNumericForPhone(phoneId, numeric); 11822 } 11823 11824 /** 11825 * Set the numeric name (MCC+MNC) of current registered operator. 11826 * @param phoneId for which phone type is set 11827 * @param operator the numeric name (MCC+MNC) of current registered operator 11828 * @hide 11829 */ 11830 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setNetworkOperatorNumericForPhone(int phoneId, String numeric)11831 public void setNetworkOperatorNumericForPhone(int phoneId, String numeric) { 11832 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11833 List<String> newList = updateTelephonyProperty( 11834 TelephonyProperties.operator_numeric(), phoneId, numeric); 11835 TelephonyProperties.operator_numeric(newList); 11836 } 11837 } 11838 11839 /** 11840 * Set roaming state of the current network, for GSM purposes. 11841 * @param isRoaming is network in romaing state or not 11842 * @hide 11843 */ setNetworkRoaming(boolean isRoaming)11844 public void setNetworkRoaming(boolean isRoaming) { 11845 int phoneId = getPhoneId(); 11846 setNetworkRoamingForPhone(phoneId, isRoaming); 11847 } 11848 11849 /** 11850 * Set roaming state of the current network, for GSM purposes. 11851 * @param phoneId which phone you want to set 11852 * @param isRoaming is network in romaing state or not 11853 * @hide 11854 */ 11855 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setNetworkRoamingForPhone(int phoneId, boolean isRoaming)11856 public void setNetworkRoamingForPhone(int phoneId, boolean isRoaming) { 11857 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11858 List<Boolean> newList = updateTelephonyProperty( 11859 TelephonyProperties.operator_is_roaming(), phoneId, isRoaming); 11860 TelephonyProperties.operator_is_roaming(newList); 11861 } 11862 } 11863 11864 /** 11865 * Set the network type currently in use on the device for data transmission. 11866 * 11867 * If this object has been created with {@link #createForSubscriptionId}, applies to the 11868 * phoneId associated with the given subId. Otherwise, applies to the phoneId associated with 11869 * {@link SubscriptionManager#getDefaultDataSubscriptionId()} 11870 * @param type the network type currently in use on the device for data transmission 11871 * @hide 11872 */ setDataNetworkType(int type)11873 public void setDataNetworkType(int type) { 11874 int phoneId = getPhoneId(SubscriptionManager.getDefaultDataSubscriptionId()); 11875 setDataNetworkTypeForPhone(phoneId, type); 11876 } 11877 11878 /** 11879 * Set the network type currently in use on the device for data transmission. 11880 * @param phoneId which phone you want to set 11881 * @param type the network type currently in use on the device for data transmission 11882 * @hide 11883 */ 11884 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) setDataNetworkTypeForPhone(int phoneId, int type)11885 public void setDataNetworkTypeForPhone(int phoneId, int type) { 11886 if (SubscriptionManager.isValidPhoneId(phoneId)) { 11887 List<String> newList = updateTelephonyProperty( 11888 TelephonyProperties.data_network_type(), phoneId, 11889 ServiceState.rilRadioTechnologyToString(type)); 11890 TelephonyProperties.data_network_type(newList); 11891 } 11892 } 11893 11894 /** 11895 * Returns the subscription ID for the given phone account. 11896 * @hide 11897 */ 11898 @UnsupportedAppUsage getSubIdForPhoneAccount(@ullable PhoneAccount phoneAccount)11899 public int getSubIdForPhoneAccount(@Nullable PhoneAccount phoneAccount) { 11900 int retval = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 11901 if (phoneAccount != null 11902 && phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) { 11903 retval = getSubscriptionId(phoneAccount.getAccountHandle()); 11904 } 11905 return retval; 11906 } 11907 11908 /** 11909 * Determines the {@link PhoneAccountHandle} associated with this TelephonyManager. 11910 * 11911 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 11912 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 11913 * 11914 * <p>Requires Permission android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE or that the 11915 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}) 11916 * 11917 * @return The {@link PhoneAccountHandle} associated with the TelphonyManager, or {@code null} 11918 * if there is no associated {@link PhoneAccountHandle}; this can happen if the subscription is 11919 * data-only or an opportunistic subscription. 11920 */ 11921 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 11922 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getPhoneAccountHandle()11923 public @Nullable PhoneAccountHandle getPhoneAccountHandle() { 11924 return getPhoneAccountHandleForSubscriptionId(getSubId()); 11925 } 11926 11927 /** 11928 * Determines the {@link PhoneAccountHandle} associated with a subscription Id. 11929 * 11930 * @param subscriptionId The subscription Id to check. 11931 * @return The {@link PhoneAccountHandle} associated with a subscription Id, or {@code null} if 11932 * there is no associated {@link PhoneAccountHandle}. 11933 * @hide 11934 */ getPhoneAccountHandleForSubscriptionId(int subscriptionId)11935 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { 11936 PhoneAccountHandle returnValue = null; 11937 try { 11938 ITelephony service = getITelephony(); 11939 if (service != null) { 11940 returnValue = service.getPhoneAccountHandleForSubscriptionId(subscriptionId); 11941 } 11942 } catch (RemoteException e) { 11943 } 11944 11945 return returnValue; 11946 } 11947 11948 /** 11949 * Returns the subscription ID for the given phone account handle. 11950 * 11951 * @param phoneAccountHandle the phone account handle for outgoing calls 11952 * @return subscription ID for the given phone account handle; or 11953 * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} 11954 * if not available; or throw a SecurityException if the caller doesn't have the 11955 * permission. 11956 */ 11957 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 11958 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSubscriptionId(@onNull PhoneAccountHandle phoneAccountHandle)11959 public int getSubscriptionId(@NonNull PhoneAccountHandle phoneAccountHandle) { 11960 return mPhoneAccountHandleToSubIdCache.query(phoneAccountHandle); 11961 } 11962 11963 /** 11964 * Resets telephony manager settings back to factory defaults. 11965 * 11966 * @hide 11967 */ factoryReset(int subId)11968 public void factoryReset(int subId) { 11969 try { 11970 Log.d(TAG, "factoryReset: subId=" + subId); 11971 ITelephony telephony = getITelephony(); 11972 if (telephony != null) { 11973 telephony.factoryReset(subId, getOpPackageName()); 11974 } 11975 } catch (RemoteException e) { 11976 } 11977 } 11978 11979 11980 /** 11981 * Resets Telephony and IMS settings back to factory defaults only for the subscription 11982 * associated with this instance. 11983 * @see #createForSubscriptionId(int) 11984 * @hide 11985 */ 11986 @SystemApi 11987 @RequiresPermission(Manifest.permission.CONNECTIVITY_INTERNAL) resetSettings()11988 public void resetSettings() { 11989 try { 11990 Log.d(TAG, "resetSettings: subId=" + getSubId()); 11991 ITelephony telephony = getITelephony(); 11992 if (telephony != null) { 11993 telephony.factoryReset(getSubId(), getOpPackageName()); 11994 } 11995 } catch (RemoteException e) { 11996 } 11997 } 11998 11999 12000 /** 12001 * Returns a locale based on the country and language from the SIM. Returns {@code null} if 12002 * no locale could be derived from subscriptions. 12003 * 12004 * <p>Requires Permission: 12005 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 12006 * 12007 * @see Locale#toLanguageTag() 12008 * 12009 * @hide 12010 */ 12011 @SystemApi 12012 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 12013 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimLocale()12014 @Nullable public Locale getSimLocale() { 12015 try { 12016 final ITelephony telephony = getITelephony(); 12017 if (telephony != null) { 12018 String languageTag = telephony.getSimLocaleForSubscriber(getSubId()); 12019 if (!TextUtils.isEmpty(languageTag)) { 12020 return Locale.forLanguageTag(languageTag); 12021 } 12022 } 12023 } catch (RemoteException ex) { 12024 } 12025 return null; 12026 } 12027 12028 /** 12029 * TODO delete after SuW migrates to new API. 12030 * @hide 12031 */ getLocaleFromDefaultSim()12032 public String getLocaleFromDefaultSim() { 12033 try { 12034 final ITelephony telephony = getITelephony(); 12035 if (telephony != null) { 12036 return telephony.getSimLocaleForSubscriber(getSubId()); 12037 } 12038 } catch (RemoteException ex) { 12039 } 12040 return null; 12041 } 12042 12043 /** 12044 * Exception that may be supplied to the callback provided in {@link #requestModemActivityInfo}. 12045 * @hide 12046 */ 12047 @SystemApi 12048 public static class ModemActivityInfoException extends Exception { 12049 /** Indicates that an unknown error occurred */ 12050 public static final int ERROR_UNKNOWN = 0; 12051 12052 /** 12053 * Indicates that the modem or phone processes are not available (such as when the device 12054 * is in airplane mode). 12055 */ 12056 public static final int ERROR_PHONE_NOT_AVAILABLE = 1; 12057 12058 /** 12059 * Indicates that the modem supplied an invalid instance of {@link ModemActivityInfo} 12060 */ 12061 public static final int ERROR_INVALID_INFO_RECEIVED = 2; 12062 12063 /** 12064 * Indicates that the modem encountered an internal failure when processing the request 12065 * for activity info. 12066 */ 12067 public static final int ERROR_MODEM_RESPONSE_ERROR = 3; 12068 12069 /** @hide */ 12070 @Retention(RetentionPolicy.SOURCE) 12071 @IntDef(prefix = {"ERROR_"}, 12072 value = { 12073 ERROR_UNKNOWN, 12074 ERROR_PHONE_NOT_AVAILABLE, 12075 ERROR_INVALID_INFO_RECEIVED, 12076 ERROR_MODEM_RESPONSE_ERROR, 12077 }) 12078 public @interface ModemActivityInfoError {} 12079 12080 private final int mErrorCode; 12081 12082 /** 12083 * An exception with ModemActivityInfo specific error codes. 12084 * 12085 * @param errorCode a ModemActivityInfoError code. 12086 */ ModemActivityInfoException(@odemActivityInfoError int errorCode)12087 public ModemActivityInfoException(@ModemActivityInfoError int errorCode) { 12088 mErrorCode = errorCode; 12089 } 12090 getErrorCode()12091 public @ModemActivityInfoError int getErrorCode() { 12092 return mErrorCode; 12093 } 12094 12095 @Override toString()12096 public String toString() { 12097 switch (mErrorCode) { 12098 case ERROR_UNKNOWN: return "ERROR_UNKNOWN"; 12099 case ERROR_PHONE_NOT_AVAILABLE: return "ERROR_PHONE_NOT_AVAILABLE"; 12100 case ERROR_INVALID_INFO_RECEIVED: return "ERROR_INVALID_INFO_RECEIVED"; 12101 case ERROR_MODEM_RESPONSE_ERROR: return "ERROR_MODEM_RESPONSE_ERROR"; 12102 default: return "UNDEFINED"; 12103 } 12104 } 12105 } 12106 12107 /** 12108 * Requests the current modem activity info. 12109 * 12110 * The provided instance of {@link ModemActivityInfo} represents the cumulative activity since 12111 * the last restart of the phone process. 12112 * 12113 * @param callback A callback object to which the result will be delivered. If there was an 12114 * error processing the request, {@link OutcomeReceiver#onError} will be called 12115 * with more details about the error. 12116 * @hide 12117 */ 12118 @SystemApi 12119 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) requestModemActivityInfo(@onNull @allbackExecutor Executor executor, @NonNull OutcomeReceiver<ModemActivityInfo, ModemActivityInfoException> callback)12120 public void requestModemActivityInfo(@NonNull @CallbackExecutor Executor executor, 12121 @NonNull OutcomeReceiver<ModemActivityInfo, ModemActivityInfoException> callback) { 12122 Objects.requireNonNull(executor); 12123 Objects.requireNonNull(callback); 12124 12125 // Pass no handler into the receiver, since we're going to be trampolining the call to the 12126 // listener onto the provided executor. 12127 ResultReceiver wrapperResultReceiver = new ResultReceiver(null) { 12128 @Override 12129 protected void onReceiveResult(int resultCode, Bundle data) { 12130 if (data == null) { 12131 Log.w(TAG, "requestModemActivityInfo: received null bundle"); 12132 sendErrorToListener(ModemActivityInfoException.ERROR_UNKNOWN); 12133 return; 12134 } 12135 data.setDefusable(true); 12136 if (data.containsKey(EXCEPTION_RESULT_KEY)) { 12137 int receivedErrorCode = data.getInt(EXCEPTION_RESULT_KEY); 12138 sendErrorToListener(receivedErrorCode); 12139 return; 12140 } 12141 12142 if (!data.containsKey(MODEM_ACTIVITY_RESULT_KEY)) { 12143 Log.w(TAG, "requestModemActivityInfo: Bundle did not contain expected key"); 12144 sendErrorToListener(ModemActivityInfoException.ERROR_UNKNOWN); 12145 return; 12146 } 12147 Parcelable receivedResult = data.getParcelable(MODEM_ACTIVITY_RESULT_KEY); 12148 if (!(receivedResult instanceof ModemActivityInfo)) { 12149 Log.w(TAG, "requestModemActivityInfo: Bundle contained something that wasn't " 12150 + "a ModemActivityInfo."); 12151 sendErrorToListener(ModemActivityInfoException.ERROR_UNKNOWN); 12152 return; 12153 } 12154 ModemActivityInfo modemActivityInfo = (ModemActivityInfo) receivedResult; 12155 if (!modemActivityInfo.isValid()) { 12156 Log.w(TAG, "requestModemActivityInfo: Received an invalid ModemActivityInfo"); 12157 sendErrorToListener(ModemActivityInfoException.ERROR_INVALID_INFO_RECEIVED); 12158 return; 12159 } 12160 Log.d(TAG, "requestModemActivityInfo: Sending result to app: " + modemActivityInfo); 12161 sendResultToListener(modemActivityInfo); 12162 } 12163 12164 private void sendResultToListener(ModemActivityInfo info) { 12165 Binder.withCleanCallingIdentity(() -> 12166 executor.execute(() -> 12167 callback.onResult(info))); 12168 } 12169 12170 private void sendErrorToListener(int code) { 12171 ModemActivityInfoException e = new ModemActivityInfoException(code); 12172 Binder.withCleanCallingIdentity(() -> 12173 executor.execute(() -> 12174 callback.onError(e))); 12175 } 12176 }; 12177 12178 try { 12179 ITelephony service = getITelephony(); 12180 if (service != null) { 12181 service.requestModemActivityInfo(wrapperResultReceiver); 12182 return; 12183 } 12184 } catch (RemoteException e) { 12185 Log.e(TAG, "Error calling ITelephony#getModemActivityInfo", e); 12186 } 12187 executor.execute(() -> callback.onError( 12188 new ModemActivityInfoException( 12189 ModemActivityInfoException.ERROR_PHONE_NOT_AVAILABLE))); 12190 } 12191 12192 /** 12193 * Returns the current {@link ServiceState} information. 12194 * 12195 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 12196 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 12197 * 12198 * If you want continuous updates of service state info, register a {@link PhoneStateListener} 12199 * via {@link #listen} with the {@link PhoneStateListener#LISTEN_SERVICE_STATE} event. 12200 * 12201 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 12202 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) 12203 * and {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 12204 * May return {@code null} when the subscription is inactive or when there was an error 12205 * communicating with the phone process. 12206 */ 12207 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 12208 @RequiresPermission(allOf = { 12209 Manifest.permission.READ_PHONE_STATE, 12210 Manifest.permission.ACCESS_COARSE_LOCATION 12211 }) 12212 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) getServiceState()12213 public @Nullable ServiceState getServiceState() { 12214 return getServiceState(getLocationData()); 12215 } 12216 12217 /** 12218 * Returns the current {@link ServiceState} information. 12219 * 12220 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 12221 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 12222 * 12223 * If you want continuous updates of service state info, register a {@link PhoneStateListener} 12224 * via {@link #listen} with the {@link PhoneStateListener#LISTEN_SERVICE_STATE} event. 12225 * 12226 * There's another way to renounce permissions with a custom context 12227 * {@code AttributionSource.Builder#setRenouncedPermissions(Set<String>)} but only for system 12228 * apps. To avoid confusion, calling this method supersede renouncing permissions with a 12229 * custom context. 12230 * 12231 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 12232 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}) 12233 * and {@link android.Manifest.permission#ACCESS_COARSE_LOCATION}. 12234 * @param includeLocationData Specifies if the caller would like to receive 12235 * location related information. 12236 * May return {@code null} when the subscription is inactive or when there was an error 12237 * communicating with the phone process. 12238 */ 12239 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 12240 @RequiresPermission(allOf = { 12241 Manifest.permission.READ_PHONE_STATE, 12242 Manifest.permission.ACCESS_COARSE_LOCATION 12243 }) getServiceState(@ncludeLocationData int includeLocationData)12244 public @Nullable ServiceState getServiceState(@IncludeLocationData int includeLocationData) { 12245 return getServiceStateForSubscriber(getSubId(), 12246 includeLocationData != INCLUDE_LOCATION_DATA_FINE, 12247 includeLocationData == INCLUDE_LOCATION_DATA_NONE); 12248 } 12249 12250 /** 12251 * Returns the service state information on specified subscription. Callers require 12252 * either READ_PRIVILEGED_PHONE_STATE or READ_PHONE_STATE to retrieve the information. 12253 * 12254 * May return {@code null} when the subscription is inactive or when there was an error 12255 * communicating with the phone process. 12256 * @param renounceFineLocationAccess Set this to true if the caller would not like to receive 12257 * location related information which will be sent if the caller already possess 12258 * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and do not renounce the permission 12259 * @param renounceCoarseLocationAccess Set this to true if the caller would not like to 12260 * receive location related information which will be sent if the caller already possess 12261 * {@link Manifest.permission#ACCESS_COARSE_LOCATION} and do not renounce the permissions. 12262 */ getServiceStateForSubscriber(int subId, boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess)12263 private ServiceState getServiceStateForSubscriber(int subId, 12264 boolean renounceFineLocationAccess, 12265 boolean renounceCoarseLocationAccess) { 12266 try { 12267 ITelephony service = getITelephony(); 12268 if (service != null) { 12269 return service.getServiceStateForSubscriber(subId, renounceFineLocationAccess, 12270 renounceCoarseLocationAccess, getOpPackageName(), getAttributionTag()); 12271 } 12272 } catch (RemoteException e) { 12273 Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e); 12274 } catch (NullPointerException e) { 12275 AnomalyReporter.reportAnomaly( 12276 UUID.fromString("e2bed88e-def9-476e-bd71-3e572a8de6d1"), 12277 "getServiceStateForSubscriber " + subId + " NPE"); 12278 } 12279 return null; 12280 } 12281 12282 /** 12283 * Returns the service state information on specified subscription. Callers require 12284 * either READ_PRIVILEGED_PHONE_STATE or READ_PHONE_STATE to retrieve the information. 12285 * 12286 * May return {@code null} when the subscription is inactive or when there was an error 12287 * communicating with the phone process. 12288 * @hide 12289 */ 12290 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P) getServiceStateForSubscriber(int subId)12291 public ServiceState getServiceStateForSubscriber(int subId) { 12292 return getServiceStateForSubscriber(getSubId(), false, false); 12293 } 12294 12295 /** 12296 * Returns the URI for the per-account voicemail ringtone set in Phone settings. 12297 * 12298 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the 12299 * voicemail ringtone. 12300 * @return The URI for the ringtone to play when receiving a voicemail from a specific 12301 * PhoneAccount. May be {@code null} if no ringtone is set. 12302 */ 12303 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) getVoicemailRingtoneUri(PhoneAccountHandle accountHandle)12304 public @Nullable Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { 12305 try { 12306 ITelephony service = getITelephony(); 12307 if (service != null) { 12308 return service.getVoicemailRingtoneUri(accountHandle); 12309 } 12310 } catch (RemoteException e) { 12311 Log.e(TAG, "Error calling ITelephony#getVoicemailRingtoneUri", e); 12312 } 12313 return null; 12314 } 12315 12316 /** 12317 * Sets the per-account voicemail ringtone. 12318 * 12319 * <p>Requires that the calling app is the default dialer, or has carrier privileges (see 12320 * {@link #hasCarrierPrivileges}, or has permission 12321 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 12322 * 12323 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the 12324 * voicemail ringtone. 12325 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific 12326 * PhoneAccount. 12327 * 12328 * @deprecated Use {@link android.provider.Settings#ACTION_CHANNEL_NOTIFICATION_SETTINGS} 12329 * instead. 12330 */ 12331 @Deprecated setVoicemailRingtoneUri(PhoneAccountHandle phoneAccountHandle, Uri uri)12332 public void setVoicemailRingtoneUri(PhoneAccountHandle phoneAccountHandle, Uri uri) { 12333 try { 12334 ITelephony service = getITelephony(); 12335 if (service != null) { 12336 service.setVoicemailRingtoneUri(getOpPackageName(), phoneAccountHandle, uri); 12337 } 12338 } catch (RemoteException e) { 12339 Log.e(TAG, "Error calling ITelephony#setVoicemailRingtoneUri", e); 12340 } 12341 } 12342 12343 /** 12344 * Returns whether vibration is set for voicemail notification in Phone settings. 12345 * 12346 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the 12347 * voicemail vibration setting. 12348 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. 12349 */ 12350 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle)12351 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { 12352 try { 12353 ITelephony service = getITelephony(); 12354 if (service != null) { 12355 return service.isVoicemailVibrationEnabled(accountHandle); 12356 } 12357 } catch (RemoteException e) { 12358 Log.e(TAG, "Error calling ITelephony#isVoicemailVibrationEnabled", e); 12359 } 12360 return false; 12361 } 12362 12363 /** 12364 * Sets the per-account preference whether vibration is enabled for voicemail notifications. 12365 * 12366 * <p>Requires that the calling app is the default dialer, or has carrier privileges (see 12367 * {@link #hasCarrierPrivileges}, or has permission 12368 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 12369 * 12370 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the 12371 * voicemail vibration setting. 12372 * @param enabled Whether to enable or disable vibration for voicemail notifications from a 12373 * specific PhoneAccount. 12374 * 12375 * @deprecated Use {@link android.provider.Settings#ACTION_CHANNEL_NOTIFICATION_SETTINGS} 12376 * instead. 12377 */ 12378 @Deprecated setVoicemailVibrationEnabled(PhoneAccountHandle phoneAccountHandle, boolean enabled)12379 public void setVoicemailVibrationEnabled(PhoneAccountHandle phoneAccountHandle, 12380 boolean enabled) { 12381 try { 12382 ITelephony service = getITelephony(); 12383 if (service != null) { 12384 service.setVoicemailVibrationEnabled(getOpPackageName(), phoneAccountHandle, 12385 enabled); 12386 } 12387 } catch (RemoteException e) { 12388 Log.e(TAG, "Error calling ITelephony#isVoicemailVibrationEnabled", e); 12389 } 12390 } 12391 12392 /** 12393 * Returns carrier id of the current subscription. 12394 * <p>To recognize a carrier (including MVNO) as a first-class identity, Android assigns each 12395 * carrier with a canonical integer a.k.a. carrier id. The carrier ID is an Android 12396 * platform-wide identifier for a carrier. AOSP maintains carrier ID assignments in 12397 * <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/latest_carrier_id/carrier_list.textpb">here</a> 12398 * 12399 * <p>Apps which have carrier-specific configurations or business logic can use the carrier id 12400 * as an Android platform-wide identifier for carriers. 12401 * 12402 * @return Carrier id of the current subscription. Return {@link #UNKNOWN_CARRIER_ID} if the 12403 * subscription is unavailable or the carrier cannot be identified. 12404 */ 12405 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimCarrierId()12406 public int getSimCarrierId() { 12407 try { 12408 ITelephony service = getITelephony(); 12409 if (service != null) { 12410 return service.getSubscriptionCarrierId(getSubId()); 12411 } 12412 } catch (RemoteException ex) { 12413 // This could happen if binder process crashes. 12414 } 12415 return UNKNOWN_CARRIER_ID; 12416 } 12417 12418 /** 12419 * Returns carrier id name of the current subscription. 12420 * <p>Carrier id name is a user-facing name of carrier id returned by 12421 * {@link #getSimCarrierId()}, usually the brand name of the subsidiary 12422 * (e.g. T-Mobile). Each carrier could configure multiple {@link #getSimOperatorName() SPN} but 12423 * should have a single carrier name. Carrier name is not a canonical identity, 12424 * use {@link #getSimCarrierId()} instead. 12425 * <p>The returned carrier name is unlocalized. 12426 * 12427 * @return Carrier name of the current subscription. Return {@code null} if the subscription is 12428 * unavailable or the carrier cannot be identified. 12429 */ 12430 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimCarrierIdName()12431 public @Nullable CharSequence getSimCarrierIdName() { 12432 try { 12433 ITelephony service = getITelephony(); 12434 if (service != null) { 12435 return service.getSubscriptionCarrierName(getSubId()); 12436 } 12437 } catch (RemoteException ex) { 12438 // This could happen if binder process crashes. 12439 } 12440 return null; 12441 } 12442 12443 /** 12444 * Returns fine-grained carrier ID of the current subscription. 12445 * 12446 * A specific carrier ID can represent the fact that a carrier may be in effect an aggregation 12447 * of other carriers (ie in an MVNO type scenario) where each of these specific carriers which 12448 * are used to make up the actual carrier service may have different carrier configurations. 12449 * A specific carrier ID could also be used, for example, in a scenario where a carrier requires 12450 * different carrier configuration for different service offering such as a prepaid plan. 12451 * 12452 * the specific carrier ID would be used for configuration purposes, but apps wishing to know 12453 * about the carrier itself should use the regular carrier ID returned by 12454 * {@link #getSimCarrierId()}. 12455 * 12456 * e.g, Tracfone SIMs could return different specific carrier ID based on IMSI from current 12457 * subscription while carrier ID remains the same. 12458 * 12459 * <p>For carriers without fine-grained specific carrier ids, return {@link #getSimCarrierId()} 12460 * <p>Specific carrier ids are defined in the same way as carrier id 12461 * <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/latest_carrier_id/carrier_list.textpb">here</a> 12462 * except each with a "parent" id linking to its top-level carrier id. 12463 * 12464 * @return Returns fine-grained carrier id of the current subscription. 12465 * Return {@link #UNKNOWN_CARRIER_ID} if the subscription is unavailable or the carrier cannot 12466 * be identified. 12467 */ 12468 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimSpecificCarrierId()12469 public int getSimSpecificCarrierId() { 12470 try { 12471 ITelephony service = getITelephony(); 12472 if (service != null) { 12473 return service.getSubscriptionSpecificCarrierId(getSubId()); 12474 } 12475 } catch (RemoteException ex) { 12476 // This could happen if binder process crashes. 12477 } 12478 return UNKNOWN_CARRIER_ID; 12479 } 12480 12481 /** 12482 * Similar like {@link #getSimCarrierIdName()}, returns user-facing name of the 12483 * specific carrier id returned by {@link #getSimSpecificCarrierId()}. 12484 * 12485 * The specific carrier ID would be used for configuration purposes, but apps wishing to know 12486 * about the carrier itself should use the regular carrier ID returned by 12487 * {@link #getSimCarrierIdName()}. 12488 * 12489 * <p>The returned name is unlocalized. 12490 * 12491 * @return user-facing name of the subscription specific carrier id. Return {@code null} if the 12492 * subscription is unavailable or the carrier cannot be identified. 12493 */ 12494 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getSimSpecificCarrierIdName()12495 public @Nullable CharSequence getSimSpecificCarrierIdName() { 12496 try { 12497 ITelephony service = getITelephony(); 12498 if (service != null) { 12499 return service.getSubscriptionSpecificCarrierName(getSubId()); 12500 } 12501 } catch (RemoteException ex) { 12502 // This could happen if binder process crashes. 12503 } 12504 return null; 12505 } 12506 12507 /** 12508 * Returns carrier id based on sim MCCMNC (returned by {@link #getSimOperator()}) only. 12509 * This is used for fallback when configurations/logic for exact carrier id 12510 * {@link #getSimCarrierId()} are not found. 12511 * 12512 * Android carrier id table <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/latest_carrier_id/carrier_list.textpb">here</a> 12513 * can be updated out-of-band, its possible a MVNO (Mobile Virtual Network Operator) carrier 12514 * was not fully recognized and assigned to its MNO (Mobile Network Operator) carrier id 12515 * by default. After carrier id table update, a new carrier id was assigned. If apps don't 12516 * take the update with the new id, it might be helpful to always fallback by using carrier 12517 * id based on MCCMNC if there is no match. 12518 * 12519 * @return matching carrier id from sim MCCMNC. Return {@link #UNKNOWN_CARRIER_ID} if the 12520 * subscription is unavailable or the carrier cannot be identified. 12521 */ 12522 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getCarrierIdFromSimMccMnc()12523 public int getCarrierIdFromSimMccMnc() { 12524 try { 12525 ITelephony service = getITelephony(); 12526 if (service != null) { 12527 return service.getCarrierIdFromMccMnc(getSlotIndex(), getSimOperator(), true); 12528 } 12529 } catch (RemoteException ex) { 12530 // This could happen if binder process crashes. 12531 } 12532 return UNKNOWN_CARRIER_ID; 12533 } 12534 12535 /** 12536 * Returns carrier id based on MCCMNC (returned by {@link #getSimOperator()}) only. This is 12537 * used for fallback when configurations/logic for exact carrier id {@link #getSimCarrierId()} 12538 * are not found. 12539 * 12540 * Android carrier id table <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/latest_carrier_id/carrier_list.textpb">here</a> 12541 * can be updated out-of-band, its possible a MVNO (Mobile Virtual Network Operator) carrier 12542 * was not fully recognized and assigned to its MNO (Mobile Network Operator) carrier id 12543 * by default. After carrier id table update, a new carrier id was assigned. If apps don't 12544 * take the update with the new id, it might be helpful to always fallback by using carrier 12545 * id based on MCCMNC if there is no match. 12546 * 12547 * @return matching carrier id from passing MCCMNC. Return {@link #UNKNOWN_CARRIER_ID} if the 12548 * subscription is unavailable or the carrier cannot be identified. 12549 * @hide 12550 */ 12551 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getCarrierIdFromMccMnc(String mccmnc)12552 public int getCarrierIdFromMccMnc(String mccmnc) { 12553 try { 12554 ITelephony service = getITelephony(); 12555 if (service != null) { 12556 return service.getCarrierIdFromMccMnc(getSlotIndex(), mccmnc, false); 12557 } 12558 } catch (RemoteException ex) { 12559 // This could happen if binder process crashes. 12560 } 12561 return UNKNOWN_CARRIER_ID; 12562 } 12563 12564 /** 12565 * Return a list of certs as hex strings from loaded carrier privileges access rules. 12566 * 12567 * @return a list of certificates as hex strings, or an empty list if there are no certs or 12568 * privilege rules are not loaded yet. 12569 * @hide 12570 */ 12571 @TestApi 12572 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 12573 @NonNull getCertsFromCarrierPrivilegeAccessRules()12574 public List<String> getCertsFromCarrierPrivilegeAccessRules() { 12575 List<String> certs = null; 12576 try { 12577 ITelephony service = getITelephony(); 12578 if (service != null) { 12579 certs = service.getCertsFromCarrierPrivilegeAccessRules(getSubId()); 12580 } 12581 } catch (RemoteException ex) { 12582 // This could happen if binder process crashes. 12583 } 12584 return certs == null ? Collections.emptyList() : certs; 12585 } 12586 12587 /** 12588 * Return the application ID for the uicc application type like {@link #APPTYPE_CSIM}. 12589 * All uicc applications are uniquely identified by application ID, represented by the hex 12590 * string. e.g, A00000015141434C00. See ETSI 102.221 and 101.220 12591 * <p>Requires Permission: 12592 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} 12593 * 12594 * @param appType the uicc app type. 12595 * @return Application ID for specified app type or {@code null} if no uicc or error. 12596 * @hide 12597 */ 12598 @Nullable 12599 @SystemApi 12600 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 12601 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getAidForAppType(@iccAppType int appType)12602 public String getAidForAppType(@UiccAppType int appType) { 12603 return getAidForAppType(getSubId(), appType); 12604 } 12605 12606 /** 12607 * same as {@link #getAidForAppType(int)} 12608 * @hide 12609 */ getAidForAppType(int subId, int appType)12610 public String getAidForAppType(int subId, int appType) { 12611 try { 12612 ITelephony service = getITelephony(); 12613 if (service != null) { 12614 return service.getAidForAppType(subId, appType); 12615 } 12616 } catch (RemoteException e) { 12617 Log.e(TAG, "Error calling ITelephony#getAidForAppType", e); 12618 } 12619 return null; 12620 } 12621 12622 /** 12623 * Return the Electronic Serial Number. 12624 * 12625 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 12626 * 12627 * @return ESN or null if error. 12628 * @hide 12629 */ getEsn()12630 public String getEsn() { 12631 return getEsn(getSubId()); 12632 } 12633 12634 /** 12635 * Return the Electronic Serial Number. 12636 * 12637 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 12638 * 12639 * @param subId the subscription ID that this request applies to. 12640 * @return ESN or null if error. 12641 * @hide 12642 */ getEsn(int subId)12643 public String getEsn(int subId) { 12644 try { 12645 ITelephony service = getITelephony(); 12646 if (service != null) { 12647 return service.getEsn(subId); 12648 } 12649 } catch (RemoteException e) { 12650 Log.e(TAG, "Error calling ITelephony#getEsn", e); 12651 } 12652 return null; 12653 } 12654 12655 /** 12656 * Return the Preferred Roaming List Version 12657 * 12658 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 12659 * 12660 * @return PRLVersion or null if error. 12661 * @hide 12662 */ 12663 @SystemApi 12664 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CDMA) getCdmaPrlVersion()12665 public String getCdmaPrlVersion() { 12666 return getCdmaPrlVersion(getSubId()); 12667 } 12668 12669 /** 12670 * Return the Preferred Roaming List Version 12671 * 12672 * Requires that the calling app has READ_PRIVILEGED_PHONE_STATE permission 12673 * 12674 * @param subId the subscription ID that this request applies to. 12675 * @return PRLVersion or null if error. 12676 * @hide 12677 */ getCdmaPrlVersion(int subId)12678 public String getCdmaPrlVersion(int subId) { 12679 try { 12680 ITelephony service = getITelephony(); 12681 if (service != null) { 12682 return service.getCdmaPrlVersion(subId); 12683 } 12684 } catch (RemoteException e) { 12685 Log.e(TAG, "Error calling ITelephony#getCdmaPrlVersion", e); 12686 } 12687 return null; 12688 } 12689 12690 /** 12691 * Get snapshot of Telephony histograms 12692 * @return List of Telephony histograms 12693 * Requires Permission: 12694 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 12695 * Or the calling app has carrier privileges. 12696 * @hide 12697 */ 12698 @SystemApi 12699 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) getTelephonyHistograms()12700 public List<TelephonyHistogram> getTelephonyHistograms() { 12701 try { 12702 ITelephony service = getITelephony(); 12703 if (service != null) { 12704 return service.getTelephonyHistograms(); 12705 } 12706 } catch (RemoteException e) { 12707 Log.e(TAG, "Error calling ITelephony#getTelephonyHistograms", e); 12708 } 12709 return null; 12710 } 12711 12712 /** 12713 * Set the allowed carrier list for slotIndex 12714 * Require system privileges. In the future we may add this to carrier APIs. 12715 * 12716 * <p>Requires Permission: 12717 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} 12718 * 12719 * <p>This method works only on devices with {@link 12720 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 12721 * 12722 * @deprecated use setCarrierRestrictionRules instead 12723 * 12724 * @return The number of carriers set successfully. Should be length of 12725 * carrierList on success; -1 if carrierList null or on error. 12726 * @hide 12727 */ 12728 @SystemApi 12729 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 12730 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CARRIERLOCK) setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers)12731 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) { 12732 if (carriers == null || !SubscriptionManager.isValidPhoneId(slotIndex)) { 12733 return -1; 12734 } 12735 // Execute the method setCarrierRestrictionRules with an empty excluded list. 12736 // If the allowed list is empty, it means that all carriers are allowed (default allowed), 12737 // otherwise it means that only specified carriers are allowed (default not allowed). 12738 CarrierRestrictionRules carrierRestrictionRules = CarrierRestrictionRules.newBuilder() 12739 .setAllowedCarriers(carriers) 12740 .setDefaultCarrierRestriction( 12741 carriers.isEmpty() 12742 ? CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_ALLOWED 12743 : CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED) 12744 .build(); 12745 12746 int result = setCarrierRestrictionRules(carrierRestrictionRules); 12747 12748 // Convert result into int, as required by this method. 12749 if (result == SET_CARRIER_RESTRICTION_SUCCESS) { 12750 return carriers.size(); 12751 } else { 12752 return -1; 12753 } 12754 } 12755 12756 /** 12757 * The carrier restrictions were successfully set. 12758 * @hide 12759 */ 12760 @SystemApi 12761 public static final int SET_CARRIER_RESTRICTION_SUCCESS = 0; 12762 12763 /** 12764 * The carrier restrictions were not set due to lack of support in the modem. This can happen 12765 * if the modem does not support setting the carrier restrictions or if the configuration 12766 * passed in the {@code setCarrierRestrictionRules} is not supported by the modem. 12767 * @hide 12768 */ 12769 @SystemApi 12770 public static final int SET_CARRIER_RESTRICTION_NOT_SUPPORTED = 1; 12771 12772 /** 12773 * The setting of carrier restrictions failed. 12774 * @hide 12775 */ 12776 @SystemApi 12777 public static final int SET_CARRIER_RESTRICTION_ERROR = 2; 12778 12779 /** @hide */ 12780 @Retention(RetentionPolicy.SOURCE) 12781 @IntDef(prefix = {"SET_CARRIER_RESTRICTION_"}, 12782 value = { 12783 SET_CARRIER_RESTRICTION_SUCCESS, 12784 SET_CARRIER_RESTRICTION_NOT_SUPPORTED, 12785 SET_CARRIER_RESTRICTION_ERROR 12786 }) 12787 public @interface SetCarrierRestrictionResult {} 12788 12789 /** 12790 * The SIM power state was successfully set. 12791 * @hide 12792 */ 12793 @SystemApi 12794 public static final int SET_SIM_POWER_STATE_SUCCESS = 0; 12795 12796 /** 12797 * The SIM is already in the requested power state. 12798 * @hide 12799 */ 12800 @SystemApi 12801 public static final int SET_SIM_POWER_STATE_ALREADY_IN_STATE = 1; 12802 12803 /** 12804 * Failed to connect to the modem to make the power state request. This may happen if the 12805 * modem has an error. The user may want to make the request again later. 12806 * @hide 12807 */ 12808 @SystemApi 12809 public static final int SET_SIM_POWER_STATE_MODEM_ERROR = 2; 12810 12811 /** 12812 * Failed to connect to the SIM to make the power state request. This may happen if the 12813 * SIM has been removed. The user may want to make the request again later. 12814 * @hide 12815 */ 12816 @SystemApi 12817 public static final int SET_SIM_POWER_STATE_SIM_ERROR = 3; 12818 12819 /** 12820 * The modem version does not support synchronous power. 12821 * @hide 12822 */ 12823 @SystemApi 12824 public static final int SET_SIM_POWER_STATE_NOT_SUPPORTED = 4; 12825 12826 /** @hide */ 12827 @Retention(RetentionPolicy.SOURCE) 12828 @IntDef(prefix = {"SET_SIM_POWER_STATE_"}, 12829 value = { 12830 SET_SIM_POWER_STATE_SUCCESS, 12831 SET_SIM_POWER_STATE_ALREADY_IN_STATE, 12832 SET_SIM_POWER_STATE_MODEM_ERROR, 12833 SET_SIM_POWER_STATE_SIM_ERROR, 12834 SET_SIM_POWER_STATE_NOT_SUPPORTED 12835 }) 12836 public @interface SetSimPowerStateResult {} 12837 12838 /** 12839 * Set the allowed carrier list and the excluded carrier list indicating the priority between 12840 * the two lists. 12841 * Requires system privileges. 12842 * 12843 * <p>Requires Permission: 12844 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} 12845 * 12846 * <p>This method works only on devices with {@link 12847 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 12848 * 12849 * @return {@link #SET_CARRIER_RESTRICTION_SUCCESS} in case of success. 12850 * {@link #SET_CARRIER_RESTRICTION_NOT_SUPPORTED} if the modem does not support the 12851 * configuration. {@link #SET_CARRIER_RESTRICTION_ERROR} in all other error cases. 12852 * @hide 12853 */ 12854 @SystemApi 12855 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 12856 @SetCarrierRestrictionResult 12857 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CARRIERLOCK) setCarrierRestrictionRules(@onNull CarrierRestrictionRules rules)12858 public int setCarrierRestrictionRules(@NonNull CarrierRestrictionRules rules) { 12859 try { 12860 ITelephony service = getITelephony(); 12861 if (service != null) { 12862 return service.setAllowedCarriers(rules); 12863 } 12864 } catch (RemoteException e) { 12865 Log.e(TAG, "Error calling ITelephony#setAllowedCarriers", e); 12866 } catch (NullPointerException e) { 12867 Log.e(TAG, "Error calling ITelephony#setAllowedCarriers", e); 12868 } 12869 return SET_CARRIER_RESTRICTION_ERROR; 12870 } 12871 12872 /** 12873 * Get the allowed carrier list for slotIndex. 12874 * Requires system privileges. 12875 * 12876 * <p>This method returns valid data on devices with {@link 12877 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 12878 * 12879 * @deprecated Apps should use {@link getCarriersRestrictionRules} to retrieve the list of 12880 * allowed and excliuded carriers, as the result of this API is valid only when the excluded 12881 * list is empty. This API could return an empty list, even if some restrictions are present. 12882 * 12883 * @return List of {@link android.telephony.CarrierIdentifier}; empty list 12884 * means all carriers are allowed. 12885 * @hide 12886 */ 12887 @Deprecated 12888 @SystemApi 12889 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getAllowedCarriers(int slotIndex)12890 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) { 12891 if (SubscriptionManager.isValidPhoneId(slotIndex)) { 12892 CarrierRestrictionRules carrierRestrictionRule = getCarrierRestrictionRules(); 12893 if (carrierRestrictionRule != null) { 12894 return carrierRestrictionRule.getAllowedCarriers(); 12895 } 12896 } 12897 return new ArrayList<CarrierIdentifier>(0); 12898 } 12899 12900 /** 12901 * Get the allowed carrier list and the excluded carrier list indicating the priority between 12902 * the two lists. 12903 * Require system privileges. In the future we may add this to carrier APIs. 12904 * 12905 * <p>This method returns valid data on devices with {@link 12906 * android.content.pm.PackageManager#FEATURE_TELEPHONY_CARRIERLOCK} enabled. 12907 * 12908 * @return {@link CarrierRestrictionRules} which contains the allowed carrier list and the 12909 * excluded carrier list with the priority between the two lists. Returns {@code null} 12910 * in case of error. 12911 * @hide 12912 */ 12913 @SystemApi 12914 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 12915 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CARRIERLOCK) 12916 @Nullable getCarrierRestrictionRules()12917 public CarrierRestrictionRules getCarrierRestrictionRules() { 12918 try { 12919 ITelephony service = getITelephony(); 12920 if (service != null) { 12921 return service.getAllowedCarriers(); 12922 } 12923 } catch (RemoteException e) { 12924 Log.e(TAG, "Error calling ITelephony#getAllowedCarriers", e); 12925 } catch (NullPointerException e) { 12926 Log.e(TAG, "Error calling ITelephony#getAllowedCarriers", e); 12927 } 12928 return null; 12929 } 12930 12931 /** 12932 * Used to enable or disable carrier data by the system based on carrier signalling or 12933 * carrier privileged apps. Different from {@link #setDataEnabled(boolean)} which is linked to 12934 * user settings, carrier data on/off won't affect user settings but will bypass the 12935 * settings and turns off data internally if set to {@code false}. 12936 * 12937 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 12938 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 12939 * 12940 * <p>Requires Permission: 12941 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 12942 * 12943 * @param enabled control enable or disable carrier data. 12944 * @see #resetAllCarrierActions() 12945 * @deprecated use {@link #setDataEnabledForReason(int, boolean) with 12946 * reason {@link #DATA_ENABLED_REASON_CARRIER}} instead. 12947 * @hide 12948 */ 12949 @Deprecated 12950 @SystemApi 12951 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setCarrierDataEnabled(boolean enabled)12952 public void setCarrierDataEnabled(boolean enabled) { 12953 try { 12954 setDataEnabledForReason(DATA_ENABLED_REASON_CARRIER, enabled); 12955 } catch (RuntimeException e) { 12956 Log.e(TAG, "Error calling setDataEnabledForReason e:" + e); 12957 } 12958 } 12959 12960 /** 12961 * Carrier action to enable or disable the radio. 12962 * 12963 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 12964 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 12965 * 12966 * <p>Requires Permission: 12967 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 12968 * 12969 * @param enabled control enable or disable radio. 12970 * @see #resetAllCarrierActions() 12971 * @hide 12972 */ 12973 @SystemApi 12974 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 12975 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) setRadioEnabled(boolean enabled)12976 public void setRadioEnabled(boolean enabled) { 12977 try { 12978 ITelephony service = getITelephony(); 12979 if (service != null) { 12980 service.carrierActionSetRadioEnabled( 12981 getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), enabled); 12982 } 12983 } catch (RemoteException e) { 12984 Log.e(TAG, "Error calling ITelephony#carrierActionSetRadioEnabled", e); 12985 } 12986 } 12987 12988 /** 12989 * No error. Operation succeeded. 12990 * @hide 12991 */ 12992 public static final int ENABLE_VONR_SUCCESS = 0; 12993 12994 /** 12995 * Radio is not available. 12996 * @hide 12997 */ 12998 public static final int ENABLE_VONR_RADIO_NOT_AVAILABLE = 2; 12999 13000 /** 13001 * Internal Radio error. 13002 * @hide 13003 */ 13004 public static final int ENABLE_VONR_RADIO_ERROR = 3; 13005 13006 /** 13007 * Voice over NR enable/disable request is received when system is in invalid state. 13008 * @hide 13009 */ 13010 public static final int ENABLE_VONR_RADIO_INVALID_STATE = 4; 13011 13012 /** 13013 * Voice over NR enable/disable request is not supported. 13014 * @hide 13015 */ 13016 public static final int ENABLE_VONR_REQUEST_NOT_SUPPORTED = 5; 13017 13018 /** @hide */ 13019 @Retention(RetentionPolicy.SOURCE) 13020 @IntDef(prefix = {"EnableVoNrResult"}, value = { 13021 ENABLE_VONR_SUCCESS, 13022 ENABLE_VONR_RADIO_NOT_AVAILABLE, 13023 ENABLE_VONR_RADIO_ERROR, 13024 ENABLE_VONR_RADIO_INVALID_STATE, 13025 ENABLE_VONR_REQUEST_NOT_SUPPORTED}) 13026 public @interface EnableVoNrResult {} 13027 13028 /** 13029 * Enable or disable Voice over NR (VoNR) 13030 * 13031 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 13032 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 13033 * 13034 * <p>Requires Permission: 13035 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 13036 * 13037 * @param enabled enable or disable VoNR. 13038 * @throws IllegalStateException if the Telephony process is not currently available. 13039 * @hide 13040 */ 13041 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) setVoNrEnabled(boolean enabled)13042 public @EnableVoNrResult int setVoNrEnabled(boolean enabled) { 13043 try { 13044 ITelephony service = getITelephony(); 13045 if (service != null) { 13046 return service.setVoNrEnabled( 13047 getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), enabled); 13048 } else { 13049 throw new IllegalStateException("telephony service is null."); 13050 } 13051 } catch (RemoteException e) { 13052 Log.e(TAG, "Error calling ITelephony#setVoNrEnabled", e); 13053 } 13054 13055 return ENABLE_VONR_RADIO_INVALID_STATE; 13056 } 13057 13058 /** 13059 * Is Voice over NR (VoNR) enabled. 13060 * @return true if Voice over NR (VoNR) is enabled else false. Enabled state does not mean 13061 * voice call over NR is active or voice ove NR is available. It means the device is allowed to 13062 * register IMS over NR. 13063 * @throws IllegalStateException if the Telephony process is not currently available. 13064 * @hide 13065 */ 13066 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) isVoNrEnabled()13067 public boolean isVoNrEnabled() { 13068 try { 13069 ITelephony telephony = getITelephony(); 13070 if (telephony != null) { 13071 return telephony.isVoNrEnabled(getSubId()); 13072 } else { 13073 throw new IllegalStateException("telephony service is null."); 13074 } 13075 } catch (RemoteException ex) { 13076 Rlog.e(TAG, "isVoNrEnabled RemoteException", ex); 13077 ex.rethrowFromSystemServer(); 13078 } 13079 return false; 13080 } 13081 13082 /** 13083 * Carrier action to start or stop reporting default network available events. 13084 * 13085 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 13086 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 13087 * 13088 * <p>Requires Permission: 13089 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 13090 * 13091 * @param report control start/stop reporting network status. 13092 * @see #resetAllCarrierActions() 13093 * @hide 13094 */ 13095 @SystemApi 13096 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 13097 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) reportDefaultNetworkStatus(boolean report)13098 public void reportDefaultNetworkStatus(boolean report) { 13099 try { 13100 ITelephony service = getITelephony(); 13101 if (service != null) { 13102 service.carrierActionReportDefaultNetworkStatus( 13103 getSubId(SubscriptionManager.getDefaultDataSubscriptionId()), report); 13104 } 13105 } catch (RemoteException e) { 13106 Log.e(TAG, "Error calling ITelephony#carrierActionReportDefaultNetworkStatus", e); 13107 } 13108 } 13109 13110 /** 13111 * Reset all carrier actions previously set by {@link #setRadioEnabled}, 13112 * {@link #reportDefaultNetworkStatus} and {@link #setCarrierDataEnabled}. 13113 * 13114 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 13115 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultDataSubscriptionId()} 13116 * 13117 * <p>Requires Permission: 13118 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 13119 * @hide 13120 */ 13121 @SystemApi 13122 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 13123 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) resetAllCarrierActions()13124 public void resetAllCarrierActions() { 13125 try { 13126 ITelephony service = getITelephony(); 13127 if (service != null) { 13128 service.carrierActionResetAll( 13129 getSubId(SubscriptionManager.getDefaultDataSubscriptionId())); 13130 } 13131 } catch (RemoteException e) { 13132 Log.e(TAG, "Error calling ITelephony#carrierActionResetAll", e); 13133 } 13134 } 13135 13136 /** 13137 * Policy control of data connection. Usually used when data limit is passed. 13138 * @param enabled True if enabling the data, otherwise disabling. 13139 * @deprecated use {@link #setDataEnabledForReason(int, boolean) with 13140 * reason {@link #DATA_ENABLED_REASON_POLICY}} instead. 13141 * @hide 13142 */ 13143 @Deprecated 13144 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) setPolicyDataEnabled(boolean enabled)13145 public void setPolicyDataEnabled(boolean enabled) { 13146 try { 13147 setDataEnabledForReason(DATA_ENABLED_REASON_POLICY, enabled); 13148 } catch (RuntimeException e) { 13149 Log.e(TAG, "Error calling setDataEnabledForReason e:" + e); 13150 } 13151 } 13152 13153 /** @hide */ 13154 @IntDef({ 13155 DATA_ENABLED_REASON_USER, 13156 DATA_ENABLED_REASON_POLICY, 13157 DATA_ENABLED_REASON_CARRIER, 13158 DATA_ENABLED_REASON_THERMAL 13159 }) 13160 @Retention(RetentionPolicy.SOURCE) 13161 public @interface DataEnabledReason{} 13162 13163 /** @hide */ 13164 @IntDef({ 13165 DATA_ENABLED_REASON_UNKNOWN, 13166 DATA_ENABLED_REASON_USER, 13167 DATA_ENABLED_REASON_POLICY, 13168 DATA_ENABLED_REASON_CARRIER, 13169 DATA_ENABLED_REASON_THERMAL, 13170 DATA_ENABLED_REASON_OVERRIDE 13171 }) 13172 @Retention(RetentionPolicy.SOURCE) 13173 public @interface DataEnabledChangedReason{} 13174 13175 /** 13176 * To indicate that data was enabled or disabled due to an unknown reason. 13177 * Note that this is not a valid reason for {@link #setDataEnabledForReason(int, boolean)} and 13178 * is only used to indicate that data enabled was changed. 13179 */ 13180 public static final int DATA_ENABLED_REASON_UNKNOWN = -1; 13181 13182 /** 13183 * To indicate that user enabled or disabled data. 13184 */ 13185 public static final int DATA_ENABLED_REASON_USER = 0; 13186 13187 /** 13188 * To indicate that data control due to policy. Usually used when data limit is passed. 13189 * Policy data on/off won't affect user settings but will bypass the 13190 * settings and turns off data internally if set to {@code false}. 13191 */ 13192 public static final int DATA_ENABLED_REASON_POLICY = 1; 13193 13194 /** 13195 * To indicate enable or disable carrier data by the system based on carrier signalling or 13196 * carrier privileged apps. Carrier data on/off won't affect user settings but will bypass the 13197 * settings and turns off data internally if set to {@code false}. 13198 */ 13199 public static final int DATA_ENABLED_REASON_CARRIER = 2; 13200 13201 /** 13202 * To indicate enable or disable data by thermal service. 13203 * Thermal data on/off won't affect user settings but will bypass the 13204 * settings and turns off data internally if set to {@code false}. 13205 */ 13206 public static final int DATA_ENABLED_REASON_THERMAL = 3; 13207 13208 /** 13209 * To indicate data was enabled or disabled due to {@link MobileDataPolicy} overrides. 13210 * Note that this is not a valid reason for {@link #setDataEnabledForReason(int, boolean)} and 13211 * is only used to indicate that data enabled was changed due to an override. 13212 */ 13213 public static final int DATA_ENABLED_REASON_OVERRIDE = 4; 13214 13215 /** 13216 * Control of data connection and provide the reason triggering the data connection control. 13217 * This can be called for following reasons 13218 * <ol> 13219 * <li>data limit is passed {@link #DATA_ENABLED_REASON_POLICY} 13220 * <li>data disabled by carrier {@link #DATA_ENABLED_REASON_CARRIER} 13221 * <li>data disabled by user {@link #DATA_ENABLED_REASON_USER} 13222 * <li>data disabled due to thermal {@link #DATA_ENABLED_REASON_THERMAL} 13223 * </ol> 13224 * If any of the reason is off, then it will result in 13225 * bypassing user preference and result in data to be turned off. 13226 * 13227 * <p>If this object has been created with {@link #createForSubscriptionId}, applies 13228 * to the given subId. Otherwise, applies to 13229 * {@link SubscriptionManager#getDefaultDataSubscriptionId()} 13230 * 13231 * 13232 * @param reason the reason the data enable change is taking place 13233 * @param enabled True if enabling the data, otherwise disabling. 13234 * 13235 * <p>Requires Permission: 13236 * The calling app has carrier privileges (see {@link #hasCarrierPrivileges}) if the reason is 13237 * {@link #DATA_ENABLED_REASON_USER} or {@link #DATA_ENABLED_REASON_CARRIER} or the call app 13238 * has {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} irrespective of 13239 * the reason. 13240 * @throws IllegalStateException if the Telephony process is not currently available. 13241 */ 13242 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 13243 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) setDataEnabledForReason(@ataEnabledReason int reason, boolean enabled)13244 public void setDataEnabledForReason(@DataEnabledReason int reason, boolean enabled) { 13245 setDataEnabledForReason(getSubId(), reason, enabled); 13246 } 13247 setDataEnabledForReason(int subId, @DataEnabledReason int reason, boolean enabled)13248 private void setDataEnabledForReason(int subId, @DataEnabledReason int reason, 13249 boolean enabled) { 13250 try { 13251 ITelephony service = getITelephony(); 13252 if (service != null) { 13253 service.setDataEnabledForReason(subId, reason, enabled, getOpPackageName()); 13254 } else { 13255 throw new IllegalStateException("telephony service is null."); 13256 } 13257 } catch (RemoteException ex) { 13258 Log.e(TAG, "Telephony#setDataEnabledForReason RemoteException", ex); 13259 ex.rethrowFromSystemServer(); 13260 } 13261 } 13262 13263 /** 13264 * Return whether data is enabled for certain reason . 13265 * 13266 * If {@link #isDataEnabledForReason} returns false, it means in data enablement for a 13267 * specific reason is turned off. If any of the reason is off, then it will result in 13268 * bypassing user preference and result in data to be turned off. Call 13269 * {@link #isDataConnectionAllowed} in order to know whether 13270 * data connection is allowed on the device. 13271 * 13272 * <p>If this object has been created with {@link #createForSubscriptionId}, applies 13273 * to the given subId. Otherwise, applies to 13274 * {@link SubscriptionManager#getDefaultDataSubscriptionId()} 13275 * @param reason the reason the data enable change is taking place 13276 * @return whether data is enabled for a reason. 13277 * <p>Requires Permission: 13278 * The calling app has carrier privileges (see {@link #hasCarrierPrivileges}) or 13279 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} or 13280 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE} or 13281 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} 13282 * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE} 13283 * @throws IllegalStateException if the Telephony process is not currently available. 13284 */ 13285 @RequiresPermission(anyOf = {android.Manifest.permission.ACCESS_NETWORK_STATE, 13286 android.Manifest.permission.READ_PHONE_STATE, 13287 android.Manifest.permission.MODIFY_PHONE_STATE, 13288 android.Manifest.permission.READ_BASIC_PHONE_STATE 13289 }) 13290 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) isDataEnabledForReason(@ataEnabledReason int reason)13291 public boolean isDataEnabledForReason(@DataEnabledReason int reason) { 13292 return isDataEnabledForReason(getSubId(), reason); 13293 } 13294 isDataEnabledForReason(int subId, @DataEnabledReason int reason)13295 private boolean isDataEnabledForReason(int subId, @DataEnabledReason int reason) { 13296 try { 13297 ITelephony service = getITelephony(); 13298 if (service != null) { 13299 return service.isDataEnabledForReason(subId, reason); 13300 } else { 13301 throw new IllegalStateException("telephony service is null."); 13302 } 13303 } catch (RemoteException ex) { 13304 Log.e(TAG, "Telephony#isDataEnabledForReason RemoteException", ex); 13305 ex.rethrowFromSystemServer(); 13306 } 13307 return false; 13308 } 13309 13310 /** 13311 * Get Client request stats which will contain statistical information 13312 * on each request made by client. 13313 * Callers require either READ_PRIVILEGED_PHONE_STATE or 13314 * READ_PHONE_STATE to retrieve the information. 13315 * @param subId sub id 13316 * @return List of Client Request Stats 13317 * @hide 13318 */ getClientRequestStats(int subId)13319 public List<ClientRequestStats> getClientRequestStats(int subId) { 13320 try { 13321 ITelephony service = getITelephony(); 13322 if (service != null) { 13323 return service.getClientRequestStats(getOpPackageName(), getAttributionTag(), 13324 subId); 13325 } 13326 } catch (RemoteException e) { 13327 Log.e(TAG, "Error calling ITelephony#getClientRequestStats", e); 13328 } 13329 13330 return null; 13331 } 13332 13333 /** 13334 * Checks if phone is in emergency callback mode. 13335 * 13336 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 13337 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()} 13338 * 13339 * @return true if phone is in emergency callback mode. 13340 * @hide 13341 */ 13342 @SystemApi 13343 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 13344 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) getEmergencyCallbackMode()13345 public boolean getEmergencyCallbackMode() { 13346 return getEmergencyCallbackMode(getSubId()); 13347 } 13348 13349 /** 13350 * Check if phone is in emergency callback mode 13351 * @return true if phone is in emergency callback mode 13352 * @param subId the subscription ID that this action applies to. 13353 * @hide 13354 */ getEmergencyCallbackMode(int subId)13355 public boolean getEmergencyCallbackMode(int subId) { 13356 try { 13357 ITelephony telephony = getITelephony(); 13358 if (telephony == null) { 13359 return false; 13360 } 13361 return telephony.getEmergencyCallbackMode(subId); 13362 } catch (RemoteException e) { 13363 Log.e(TAG, "Error calling ITelephony#getEmergencyCallbackMode", e); 13364 } 13365 return false; 13366 } 13367 13368 /** 13369 * Checks if manual network selection is allowed. 13370 * 13371 * <p>Requires Permission: {@link android.Manifest.permission#READ_PRECISE_PHONE_STATE 13372 * READ_PRECISE_PHONE_STATE} or that the calling app has carrier privileges 13373 * (see {@link #hasCarrierPrivileges}) 13374 * 13375 * <p>If this object has been created with {@link #createForSubscriptionId}, applies to the 13376 * given subId. Otherwise, applies to {@link SubscriptionManager#getDefaultSubscriptionId()}. 13377 * 13378 * @return {@code true} if manual network selection is allowed, otherwise return {@code false}. 13379 */ 13380 @SuppressAutoDoc // No support carrier privileges (b/72967236). 13381 @RequiresPermission(anyOf = {android.Manifest.permission.READ_PRECISE_PHONE_STATE, 13382 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE}) 13383 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) isManualNetworkSelectionAllowed()13384 public boolean isManualNetworkSelectionAllowed() { 13385 try { 13386 ITelephony telephony = getITelephony(); 13387 if (telephony != null) { 13388 return telephony.isManualNetworkSelectionAllowed(getSubId()); 13389 } 13390 } catch (RemoteException e) { 13391 Log.e(TAG, "Error calling ITelephony#isManualNetworkSelectionAllowed", e); 13392 } 13393 return true; 13394 } 13395 13396 /** 13397 * Get the most recently available signal strength information. 13398 * 13399 * Get the most recent SignalStrength information reported by the modem. Due 13400 * to power saving this information may not always be current. 13401 * @return the most recent cached signal strength info from the modem 13402 */ 13403 @Nullable 13404 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) getSignalStrength()13405 public SignalStrength getSignalStrength() { 13406 try { 13407 ITelephony service = getITelephony(); 13408 if (service != null) { 13409 return service.getSignalStrength(getSubId()); 13410 } 13411 } catch (RemoteException e) { 13412 Log.e(TAG, "Error calling ITelephony#getSignalStrength", e); 13413 } 13414 return null; 13415 } 13416 13417 /** 13418 * Checks whether cellular data connection is allowed in the device. 13419 * 13420 * <p>Whether cellular data connection is allowed considers all factors below: 13421 * <UL> 13422 * <LI>User turned on data setting {@link #isDataEnabled}.</LI> 13423 * <LI>Carrier allows data to be on.</LI> 13424 * <LI>Network policy.</LI> 13425 * <LI>And possibly others.</LI> 13426 * </UL> 13427 * @return {@code true} if the overall data connection is allowed; {@code false} if not. 13428 */ 13429 @RequiresPermission(anyOf = {android.Manifest.permission.ACCESS_NETWORK_STATE, 13430 android.Manifest.permission.READ_PHONE_STATE, 13431 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 13432 android.Manifest.permission.READ_BASIC_PHONE_STATE}) 13433 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) isDataConnectionAllowed()13434 public boolean isDataConnectionAllowed() { 13435 boolean retVal = false; 13436 try { 13437 int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId()); 13438 ITelephony telephony = getITelephony(); 13439 if (telephony != null) 13440 retVal = telephony.isDataEnabled(subId); 13441 } catch (RemoteException e) { 13442 Log.e(TAG, "Error isDataConnectionAllowed", e); 13443 } 13444 return retVal; 13445 } 13446 13447 /** 13448 * @return true if the current device is "data capable" over a radio on the device. 13449 * <p> 13450 * "Data capable" means that this device supports packet-switched 13451 * data connections over the telephony network. 13452 * <p> 13453 */ 13454 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) isDataCapable()13455 public boolean isDataCapable() { 13456 if (mContext == null) return true; 13457 return mContext.getResources().getBoolean( 13458 com.android.internal.R.bool.config_mobile_data_capable); 13459 } 13460 13461 /** 13462 * The indication for signal strength update. 13463 * @hide 13464 */ 13465 public static final int INDICATION_FILTER_SIGNAL_STRENGTH = 0x1; 13466 13467 /** 13468 * The indication for full network state update. 13469 * @hide 13470 */ 13471 public static final int INDICATION_FILTER_FULL_NETWORK_STATE = 0x2; 13472 13473 /** 13474 * The indication for data call dormancy changed update. 13475 * @hide 13476 */ 13477 public static final int INDICATION_FILTER_DATA_CALL_DORMANCY_CHANGED = 0x4; 13478 13479 /** 13480 * The indication for link capacity estimate update. 13481 * @hide 13482 */ 13483 public static final int INDICATION_FILTER_LINK_CAPACITY_ESTIMATE = 0x8; 13484 13485 /** 13486 * The indication for physical channel config update. 13487 * @hide 13488 */ 13489 public static final int INDICATION_FILTER_PHYSICAL_CHANNEL_CONFIG = 0x10; 13490 13491 /** 13492 * A test API to override carrier information including mccmnc, imsi, iccid, gid1, gid2, 13493 * plmn and spn. This would be handy for, eg, forcing a particular carrier id, carrier's config 13494 * (also any country or carrier overlays) to be loaded when using a test SIM with a call box. 13495 * 13496 * <p>Requires Permission: 13497 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 13498 * 13499 * 13500 * @deprecated 13501 * @hide 13502 */ 13503 @Deprecated 13504 @TestApi setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, String gid2, String plmn, String spn)13505 public void setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, 13506 String gid2, String plmn, String spn) { 13507 try { 13508 ITelephony telephony = getITelephony(); 13509 if (telephony != null) { 13510 telephony.setCarrierTestOverride( 13511 getSubId(), mccmnc, imsi, iccid, gid1, gid2, plmn, spn, 13512 null, null); 13513 } 13514 } catch (RemoteException ex) { 13515 // This could happen if binder process crashes. 13516 } 13517 } 13518 13519 /** 13520 * A test API to override carrier information including mccmnc, imsi, iccid, gid1, gid2, 13521 * plmn, spn, apn and carrier priviledge. This would be handy for, eg, forcing a particular 13522 * carrier id, carrier's config (also any country or carrier overlays) to be loaded when using 13523 * a test SIM with a call box. 13524 * 13525 * <p>Requires Permission: 13526 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 13527 * 13528 * @hide 13529 */ 13530 @TestApi setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, String gid2, String plmn, String spn, String carrierPriviledgeRules, String apn)13531 public void setCarrierTestOverride(String mccmnc, String imsi, String iccid, String gid1, 13532 String gid2, String plmn, String spn, 13533 String carrierPriviledgeRules, String apn) { 13534 try { 13535 ITelephony telephony = getITelephony(); 13536 if (telephony != null) { 13537 telephony.setCarrierTestOverride( 13538 getSubId(), mccmnc, imsi, iccid, gid1, gid2, plmn, spn, 13539 carrierPriviledgeRules, apn); 13540 } 13541 } catch (RemoteException ex) { 13542 // This could happen if binder process crashes. 13543 } 13544 } 13545 13546 /** 13547 * A test API to return installed carrier id list version 13548 * 13549 * <p>Requires Permission: 13550 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 13551 * 13552 * @hide 13553 */ 13554 @UnsupportedAppUsage 13555 @TestApi getCarrierIdListVersion()13556 public int getCarrierIdListVersion() { 13557 try { 13558 ITelephony telephony = getITelephony(); 13559 if (telephony != null) { 13560 return telephony.getCarrierIdListVersion(getSubId()); 13561 } 13562 } catch (RemoteException ex) { 13563 // This could happen if binder process crashes. 13564 } 13565 return UNKNOWN_CARRIER_ID_LIST_VERSION; 13566 } 13567 13568 /** 13569 * How many modems can have simultaneous data connections. 13570 * @hide 13571 */ 13572 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) getNumberOfModemsWithSimultaneousDataConnections()13573 public int getNumberOfModemsWithSimultaneousDataConnections() { 13574 try { 13575 ITelephony telephony = getITelephony(); 13576 if (telephony != null) { 13577 return telephony.getNumberOfModemsWithSimultaneousDataConnections( 13578 getSubId(), getOpPackageName(), getAttributionTag()); 13579 } 13580 } catch (RemoteException ex) { 13581 // This could happen if binder process crashes. 13582 } 13583 return 0; 13584 } 13585 13586 /** 13587 * Enable or disable OpportunisticNetworkService. 13588 * 13589 * This method should be called to enable or disable 13590 * OpportunisticNetwork service on the device. 13591 * 13592 * <p> 13593 * Requires Permission: 13594 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 13595 * 13596 * @param enable enable(True) or disable(False) 13597 * @return returns true if successfully set. 13598 * @hide 13599 */ 13600 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 13601 @SystemApi 13602 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) setOpportunisticNetworkState(boolean enable)13603 public boolean setOpportunisticNetworkState(boolean enable) { 13604 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 13605 boolean ret = false; 13606 try { 13607 IOns iOpportunisticNetworkService = getIOns(); 13608 if (iOpportunisticNetworkService != null) { 13609 ret = iOpportunisticNetworkService.setEnable(enable, pkgForDebug); 13610 } 13611 } catch (RemoteException ex) { 13612 Rlog.e(TAG, "enableOpportunisticNetwork RemoteException", ex); 13613 } 13614 13615 return ret; 13616 } 13617 13618 /** 13619 * is OpportunisticNetworkService enabled 13620 * 13621 * This method should be called to determine if the OpportunisticNetworkService is 13622 * enabled 13623 * 13624 * <p> 13625 * Requires Permission: 13626 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 13627 * @hide 13628 */ 13629 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 13630 @SystemApi 13631 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) isOpportunisticNetworkEnabled()13632 public boolean isOpportunisticNetworkEnabled() { 13633 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 13634 boolean isEnabled = false; 13635 13636 try { 13637 IOns iOpportunisticNetworkService = getIOns(); 13638 if (iOpportunisticNetworkService != null) { 13639 isEnabled = iOpportunisticNetworkService.isEnabled(pkgForDebug); 13640 } 13641 } catch (RemoteException ex) { 13642 Rlog.e(TAG, "enableOpportunisticNetwork RemoteException", ex); 13643 } 13644 13645 return isEnabled; 13646 } 13647 13648 /** @hide */ 13649 @Retention(RetentionPolicy.SOURCE) 13650 @LongDef(flag = true, prefix = {"NETWORK_TYPE_BITMASK_"}, 13651 value = {NETWORK_TYPE_BITMASK_UNKNOWN, 13652 NETWORK_TYPE_BITMASK_GSM, 13653 NETWORK_TYPE_BITMASK_GPRS, 13654 NETWORK_TYPE_BITMASK_EDGE, 13655 NETWORK_TYPE_BITMASK_CDMA, 13656 NETWORK_TYPE_BITMASK_1xRTT, 13657 NETWORK_TYPE_BITMASK_EVDO_0, 13658 NETWORK_TYPE_BITMASK_EVDO_A, 13659 NETWORK_TYPE_BITMASK_EVDO_B, 13660 NETWORK_TYPE_BITMASK_EHRPD, 13661 NETWORK_TYPE_BITMASK_HSUPA, 13662 NETWORK_TYPE_BITMASK_HSDPA, 13663 NETWORK_TYPE_BITMASK_HSPA, 13664 NETWORK_TYPE_BITMASK_HSPAP, 13665 NETWORK_TYPE_BITMASK_UMTS, 13666 NETWORK_TYPE_BITMASK_TD_SCDMA, 13667 NETWORK_TYPE_BITMASK_LTE, 13668 NETWORK_TYPE_BITMASK_LTE_CA, 13669 NETWORK_TYPE_BITMASK_NR, 13670 NETWORK_TYPE_BITMASK_IWLAN 13671 }) 13672 public @interface NetworkTypeBitMask {} 13673 13674 // 2G 13675 /** 13676 * network type bitmask unknown. 13677 */ 13678 public static final long NETWORK_TYPE_BITMASK_UNKNOWN = 0L; 13679 /** 13680 * network type bitmask indicating the support of radio tech GSM. 13681 */ 13682 public static final long NETWORK_TYPE_BITMASK_GSM = (1 << (NETWORK_TYPE_GSM -1)); 13683 /** 13684 * network type bitmask indicating the support of radio tech GPRS. 13685 */ 13686 public static final long NETWORK_TYPE_BITMASK_GPRS = (1 << (NETWORK_TYPE_GPRS -1)); 13687 /** 13688 * network type bitmask indicating the support of radio tech EDGE. 13689 */ 13690 public static final long NETWORK_TYPE_BITMASK_EDGE = (1 << (NETWORK_TYPE_EDGE -1)); 13691 /** 13692 * network type bitmask indicating the support of radio tech CDMA(IS95A/IS95B). 13693 */ 13694 public static final long NETWORK_TYPE_BITMASK_CDMA = (1 << (NETWORK_TYPE_CDMA -1)); 13695 /** 13696 * network type bitmask indicating the support of radio tech 1xRTT. 13697 */ 13698 @SuppressLint("AllUpper") 13699 public static final long NETWORK_TYPE_BITMASK_1xRTT = (1 << (NETWORK_TYPE_1xRTT - 1)); 13700 // 3G 13701 /** 13702 * network type bitmask indicating the support of radio tech EVDO 0. 13703 */ 13704 public static final long NETWORK_TYPE_BITMASK_EVDO_0 = (1 << (NETWORK_TYPE_EVDO_0 -1)); 13705 /** 13706 * network type bitmask indicating the support of radio tech EVDO A. 13707 */ 13708 public static final long NETWORK_TYPE_BITMASK_EVDO_A = (1 << (NETWORK_TYPE_EVDO_A - 1)); 13709 /** 13710 * network type bitmask indicating the support of radio tech EVDO B. 13711 */ 13712 public static final long NETWORK_TYPE_BITMASK_EVDO_B = (1 << (NETWORK_TYPE_EVDO_B -1)); 13713 /** 13714 * network type bitmask indicating the support of radio tech EHRPD. 13715 */ 13716 public static final long NETWORK_TYPE_BITMASK_EHRPD = (1 << (NETWORK_TYPE_EHRPD -1)); 13717 /** 13718 * network type bitmask indicating the support of radio tech HSUPA. 13719 */ 13720 public static final long NETWORK_TYPE_BITMASK_HSUPA = (1 << (NETWORK_TYPE_HSUPA -1)); 13721 /** 13722 * network type bitmask indicating the support of radio tech HSDPA. 13723 */ 13724 public static final long NETWORK_TYPE_BITMASK_HSDPA = (1 << (NETWORK_TYPE_HSDPA -1)); 13725 /** 13726 * network type bitmask indicating the support of radio tech HSPA. 13727 */ 13728 public static final long NETWORK_TYPE_BITMASK_HSPA = (1 << (NETWORK_TYPE_HSPA -1)); 13729 /** 13730 * network type bitmask indicating the support of radio tech HSPAP. 13731 */ 13732 public static final long NETWORK_TYPE_BITMASK_HSPAP = (1 << (NETWORK_TYPE_HSPAP -1)); 13733 /** 13734 * network type bitmask indicating the support of radio tech UMTS. 13735 */ 13736 public static final long NETWORK_TYPE_BITMASK_UMTS = (1 << (NETWORK_TYPE_UMTS -1)); 13737 /** 13738 * network type bitmask indicating the support of radio tech TD_SCDMA. 13739 */ 13740 public static final long NETWORK_TYPE_BITMASK_TD_SCDMA = (1 << (NETWORK_TYPE_TD_SCDMA -1)); 13741 // 4G 13742 /** 13743 * network type bitmask indicating the support of radio tech LTE. 13744 */ 13745 public static final long NETWORK_TYPE_BITMASK_LTE = (1 << (NETWORK_TYPE_LTE -1)); 13746 /** 13747 * NOT USED; this bitmask is exposed accidentally, will be deprecated in U. 13748 * If used, will be converted to {@link #NETWORK_TYPE_BITMASK_LTE}. 13749 * network type bitmask indicating the support of radio tech LTE CA (carrier aggregation). 13750 * 13751 * @see #NETWORK_TYPE_BITMASK_LTE 13752 */ 13753 public static final long NETWORK_TYPE_BITMASK_LTE_CA = (1 << (NETWORK_TYPE_LTE_CA -1)); 13754 13755 /** 13756 * network type bitmask indicating the support of radio tech NR(New Radio) 5G. 13757 */ 13758 public static final long NETWORK_TYPE_BITMASK_NR = (1 << (NETWORK_TYPE_NR -1)); 13759 13760 /** 13761 * network type bitmask indicating the support of radio tech IWLAN. 13762 */ 13763 public static final long NETWORK_TYPE_BITMASK_IWLAN = (1 << (NETWORK_TYPE_IWLAN -1)); 13764 13765 /** @hide */ 13766 public static final long NETWORK_CLASS_BITMASK_2G = NETWORK_TYPE_BITMASK_GSM 13767 | NETWORK_TYPE_BITMASK_GPRS 13768 | NETWORK_TYPE_BITMASK_EDGE 13769 | NETWORK_TYPE_BITMASK_CDMA 13770 | NETWORK_TYPE_BITMASK_1xRTT; 13771 13772 /** @hide */ 13773 public static final long NETWORK_CLASS_BITMASK_3G = NETWORK_TYPE_BITMASK_EVDO_0 13774 | NETWORK_TYPE_BITMASK_EVDO_A 13775 | NETWORK_TYPE_BITMASK_EVDO_B 13776 | NETWORK_TYPE_BITMASK_EHRPD 13777 | NETWORK_TYPE_BITMASK_HSUPA 13778 | NETWORK_TYPE_BITMASK_HSDPA 13779 | NETWORK_TYPE_BITMASK_HSPA 13780 | NETWORK_TYPE_BITMASK_HSPAP 13781 | NETWORK_TYPE_BITMASK_UMTS 13782 | NETWORK_TYPE_BITMASK_TD_SCDMA; 13783 13784 /** @hide */ 13785 public static final long NETWORK_CLASS_BITMASK_4G = NETWORK_TYPE_BITMASK_LTE 13786 | NETWORK_TYPE_BITMASK_LTE_CA 13787 | NETWORK_TYPE_BITMASK_IWLAN; 13788 13789 /** @hide */ 13790 public static final long NETWORK_CLASS_BITMASK_5G = NETWORK_TYPE_BITMASK_NR; 13791 13792 /** @hide */ 13793 public static final long NETWORK_STANDARDS_FAMILY_BITMASK_3GPP = NETWORK_TYPE_BITMASK_GSM 13794 | NETWORK_TYPE_BITMASK_GPRS 13795 | NETWORK_TYPE_BITMASK_EDGE 13796 | NETWORK_TYPE_BITMASK_HSUPA 13797 | NETWORK_TYPE_BITMASK_HSDPA 13798 | NETWORK_TYPE_BITMASK_HSPA 13799 | NETWORK_TYPE_BITMASK_HSPAP 13800 | NETWORK_TYPE_BITMASK_UMTS 13801 | NETWORK_TYPE_BITMASK_TD_SCDMA 13802 | NETWORK_TYPE_BITMASK_LTE 13803 | NETWORK_TYPE_BITMASK_LTE_CA 13804 | NETWORK_TYPE_BITMASK_NR; 13805 13806 /** @hide */ 13807 public static final long NETWORK_STANDARDS_FAMILY_BITMASK_3GPP2 = NETWORK_TYPE_BITMASK_CDMA 13808 | NETWORK_TYPE_BITMASK_1xRTT 13809 | NETWORK_TYPE_BITMASK_EVDO_0 13810 | NETWORK_TYPE_BITMASK_EVDO_A 13811 | NETWORK_TYPE_BITMASK_EVDO_B 13812 | NETWORK_TYPE_BITMASK_EHRPD; 13813 13814 /** 13815 * @return Modem supported radio access family bitmask 13816 * 13817 * <p>Requires permission: android.Manifest.READ_PRIVILEGED_PHONE_STATE or 13818 * that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 13819 * 13820 * @throws SecurityException if the caller does not have the required permission 13821 */ 13822 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 13823 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) getSupportedRadioAccessFamily()13824 public @NetworkTypeBitMask long getSupportedRadioAccessFamily() { 13825 try { 13826 ITelephony telephony = getITelephony(); 13827 if (telephony != null) { 13828 return telephony.getRadioAccessFamily(getSlotIndex(), getOpPackageName()); 13829 } else { 13830 // This can happen when the ITelephony interface is not up yet. 13831 return NETWORK_TYPE_BITMASK_UNKNOWN; 13832 } 13833 } catch (RemoteException ex) { 13834 // This shouldn't happen in the normal case 13835 return NETWORK_TYPE_BITMASK_UNKNOWN; 13836 } catch (NullPointerException ex) { 13837 // This could happen before phone restarts due to crashing 13838 return NETWORK_TYPE_BITMASK_UNKNOWN; 13839 } 13840 } 13841 13842 /** 13843 * Indicates Emergency number database version is invalid. 13844 * 13845 * @hide 13846 */ 13847 @SystemApi 13848 public static final int INVALID_EMERGENCY_NUMBER_DB_VERSION = -1; 13849 13850 /** 13851 * Notify Telephony for OTA emergency number database installation complete. 13852 * 13853 * <p> Requires permission: 13854 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 13855 * 13856 * @hide 13857 */ 13858 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 13859 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) 13860 @SystemApi notifyOtaEmergencyNumberDbInstalled()13861 public void notifyOtaEmergencyNumberDbInstalled() { 13862 try { 13863 ITelephony telephony = getITelephony(); 13864 if (telephony != null) { 13865 telephony.notifyOtaEmergencyNumberDbInstalled(); 13866 } else { 13867 throw new IllegalStateException("telephony service is null."); 13868 } 13869 } catch (RemoteException ex) { 13870 Log.e(TAG, "notifyOtaEmergencyNumberDatabaseInstalled RemoteException", ex); 13871 ex.rethrowAsRuntimeException(); 13872 } 13873 } 13874 13875 /** 13876 * Override the file path for OTA emergency number database in a file partition. 13877 * 13878 * @param otaParcelFileDescriptor parcelable file descriptor for OTA emergency number database. 13879 * 13880 * <p> Requires permission: 13881 * {@link android.Manifest.permission#READ_ACTIVE_EMERGENCY_SESSION} 13882 * 13883 * @hide 13884 */ 13885 @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) 13886 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) 13887 @SystemApi updateOtaEmergencyNumberDbFilePath( @onNull ParcelFileDescriptor otaParcelFileDescriptor)13888 public void updateOtaEmergencyNumberDbFilePath( 13889 @NonNull ParcelFileDescriptor otaParcelFileDescriptor) { 13890 try { 13891 ITelephony telephony = getITelephony(); 13892 if (telephony != null) { 13893 telephony.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); 13894 } else { 13895 throw new IllegalStateException("telephony service is null."); 13896 } 13897 } catch (RemoteException ex) { 13898 Log.e(TAG, "updateOtaEmergencyNumberDbFilePath RemoteException", ex); 13899 ex.rethrowAsRuntimeException(); 13900 } 13901 } 13902 13903 /** 13904 * Reset the file path to default for OTA emergency number database in a file partition. 13905 * 13906 * <p> Requires permission: 13907 * {@link android.Manifest.permission#READ_ACTIVE_EMERGENCY_SESSION} 13908 * 13909 * @hide 13910 */ 13911 @RequiresPermission(android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION) 13912 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) 13913 @SystemApi resetOtaEmergencyNumberDbFilePath()13914 public void resetOtaEmergencyNumberDbFilePath() { 13915 try { 13916 ITelephony telephony = getITelephony(); 13917 if (telephony != null) { 13918 telephony.resetOtaEmergencyNumberDbFilePath(); 13919 } else { 13920 throw new IllegalStateException("telephony service is null."); 13921 } 13922 } catch (RemoteException ex) { 13923 Log.e(TAG, "resetOtaEmergencyNumberDbFilePath RemoteException", ex); 13924 ex.rethrowAsRuntimeException(); 13925 } 13926 } 13927 13928 /** 13929 * Returns whether {@link TelephonyManager#ACTION_EMERGENCY_ASSISTANCE emergency assistance} is 13930 * available on the device. 13931 * <p> 13932 * Requires permission: {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} 13933 * 13934 * @return {@code true} if emergency assistance is available, {@code false} otherwise 13935 * 13936 * @hide 13937 */ 13938 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 13939 @SuppressWarnings("AndroidFrameworkClientSidePermissionCheck") 13940 @SystemApi isEmergencyAssistanceEnabled()13941 public boolean isEmergencyAssistanceEnabled() { 13942 mContext.enforceCallingOrSelfPermission( 13943 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 13944 "isEmergencyAssistanceEnabled"); 13945 return EMERGENCY_ASSISTANCE_ENABLED; 13946 } 13947 13948 /** 13949 * Get the emergency number list based on current locale, sim, default, modem and network. 13950 * 13951 * <p>In each returned list, the emergency number {@link EmergencyNumber} coming from higher 13952 * priority sources will be located at the smaller index; the priority order of sources are: 13953 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_NETWORK_SIGNALING} > 13954 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_SIM} > 13955 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_DATABASE} > 13956 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_DEFAULT} > 13957 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_MODEM_CONFIG} 13958 * 13959 * <p>The subscriptions which the returned list would be based on, are all the active 13960 * subscriptions, no matter which subscription could be used to create TelephonyManager. 13961 * 13962 * <p>Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling 13963 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 13964 * 13965 * @return Map including the keys as the active subscription IDs (Note: if there is no active 13966 * subscription, the key is {@link SubscriptionManager#getDefaultSubscriptionId}) and the value 13967 * as the list of {@link EmergencyNumber}; empty Map if this information is not available; 13968 * or throw a SecurityException if the caller does not have the permission. 13969 */ 13970 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 13971 @NonNull 13972 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) getEmergencyNumberList()13973 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList() { 13974 Map<Integer, List<EmergencyNumber>> emergencyNumberList = new HashMap<>(); 13975 try { 13976 ITelephony telephony = getITelephony(); 13977 if (telephony != null) { 13978 return telephony.getEmergencyNumberList(mContext.getOpPackageName(), 13979 mContext.getAttributionTag()); 13980 } else { 13981 throw new IllegalStateException("telephony service is null."); 13982 } 13983 } catch (RemoteException ex) { 13984 Log.e(TAG, "getEmergencyNumberList RemoteException", ex); 13985 ex.rethrowAsRuntimeException(); 13986 } 13987 return emergencyNumberList; 13988 } 13989 13990 /** 13991 * Get the per-category emergency number list based on current locale, sim, default, modem 13992 * and network. 13993 * 13994 * <p>In each returned list, the emergency number {@link EmergencyNumber} coming from higher 13995 * priority sources will be located at the smaller index; the priority order of sources are: 13996 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_NETWORK_SIGNALING} > 13997 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_SIM} > 13998 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_DATABASE} > 13999 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_DEFAULT} > 14000 * {@link EmergencyNumber#EMERGENCY_NUMBER_SOURCE_MODEM_CONFIG} 14001 * 14002 * <p>The subscriptions which the returned list would be based on, are all the active 14003 * subscriptions, no matter which subscription could be used to create TelephonyManager. 14004 * 14005 * <p>Requires permission {@link android.Manifest.permission#READ_PHONE_STATE} or the calling 14006 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 14007 * 14008 * @param categories the emergency service categories which are the bitwise-OR combination of 14009 * the following constants: 14010 * <ol> 14011 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED} </li> 14012 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_POLICE} </li> 14013 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_AMBULANCE} </li> 14014 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_FIRE_BRIGADE} </li> 14015 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_MARINE_GUARD} </li> 14016 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_MOUNTAIN_RESCUE} </li> 14017 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_MIEC} </li> 14018 * <li>{@link EmergencyNumber#EMERGENCY_SERVICE_CATEGORY_AIEC} </li> 14019 * </ol> 14020 * @return Map including the keys as the active subscription IDs (Note: if there is no active 14021 * subscription, the key is {@link SubscriptionManager#getDefaultSubscriptionId}) and the value 14022 * as the list of {@link EmergencyNumber}; empty Map if this information is not available; 14023 * or throw a SecurityException if the caller does not have the permission. 14024 * @throws IllegalStateException if the Telephony process is not currently available. 14025 */ 14026 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 14027 @NonNull 14028 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) getEmergencyNumberList( @mergencyServiceCategories int categories)14029 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( 14030 @EmergencyServiceCategories int categories) { 14031 Map<Integer, List<EmergencyNumber>> emergencyNumberListForCategories = new HashMap<>(); 14032 try { 14033 ITelephony telephony = getITelephony(); 14034 if (telephony != null) { 14035 Map<Integer, List<EmergencyNumber>> emergencyNumberList = 14036 telephony.getEmergencyNumberList(mContext.getOpPackageName(), 14037 mContext.getAttributionTag()); 14038 emergencyNumberListForCategories = 14039 filterEmergencyNumbersByCategories(emergencyNumberList, categories); 14040 } else { 14041 throw new IllegalStateException("telephony service is null."); 14042 } 14043 } catch (RemoteException ex) { 14044 Log.e(TAG, "getEmergencyNumberList with Categories RemoteException", ex); 14045 ex.rethrowAsRuntimeException(); 14046 } 14047 return emergencyNumberListForCategories; 14048 } 14049 14050 /** 14051 * Filter emergency numbers with categories. 14052 * 14053 * @hide 14054 */ 14055 @VisibleForTesting filterEmergencyNumbersByCategories( Map<Integer, List<EmergencyNumber>> emergencyNumberList, @EmergencyServiceCategories int categories)14056 public Map<Integer, List<EmergencyNumber>> filterEmergencyNumbersByCategories( 14057 Map<Integer, List<EmergencyNumber>> emergencyNumberList, 14058 @EmergencyServiceCategories int categories) { 14059 Map<Integer, List<EmergencyNumber>> emergencyNumberListForCategories = new HashMap<>(); 14060 if (emergencyNumberList != null) { 14061 for (Integer subscriptionId : emergencyNumberList.keySet()) { 14062 List<EmergencyNumber> allNumbersForSub = emergencyNumberList.get( 14063 subscriptionId); 14064 List<EmergencyNumber> numbersForCategoriesPerSub = new ArrayList<>(); 14065 for (EmergencyNumber number : allNumbersForSub) { 14066 if (number.isInEmergencyServiceCategories(categories)) { 14067 numbersForCategoriesPerSub.add(number); 14068 } 14069 } 14070 emergencyNumberListForCategories.put( 14071 subscriptionId, numbersForCategoriesPerSub); 14072 } 14073 } 14074 return emergencyNumberListForCategories; 14075 } 14076 14077 /** 14078 * Identifies if the supplied phone number is an emergency number that matches a known 14079 * emergency number based on current locale, SIM card(s), Android database, modem, network, 14080 * or defaults. 14081 * 14082 * <p>This method assumes that only dialable phone numbers are passed in; non-dialable 14083 * numbers are not considered emergency numbers. A dialable phone number consists only 14084 * of characters/digits identified by {@link PhoneNumberUtils#isDialable(char)}. 14085 * 14086 * <p>The subscriptions which the identification would be based on, are all the active 14087 * subscriptions, no matter which subscription could be used to create TelephonyManager. 14088 * 14089 * @param number - the number to look up 14090 * @return {@code true} if the given number is an emergency number based on current locale, 14091 * SIM card(s), Android database, modem, network or defaults; {@code false} otherwise. 14092 * @throws IllegalStateException if the Telephony process is not currently available. 14093 */ 14094 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) isEmergencyNumber(@onNull String number)14095 public boolean isEmergencyNumber(@NonNull String number) { 14096 try { 14097 ITelephony telephony = getITelephony(); 14098 if (telephony != null) { 14099 return telephony.isEmergencyNumber(number, true); 14100 } else { 14101 throw new IllegalStateException("telephony service is null."); 14102 } 14103 } catch (RemoteException ex) { 14104 Log.e(TAG, "isEmergencyNumber RemoteException", ex); 14105 ex.rethrowAsRuntimeException(); 14106 } 14107 return false; 14108 } 14109 14110 /** 14111 * Checks if the supplied number is an emergency number based on current locale, sim, default, 14112 * modem and network. 14113 * 14114 * <p> Specifically, this method will return {@code true} if the specified number is an 14115 * emergency number, *or* if the number simply starts with the same digits as any current 14116 * emergency number. 14117 * 14118 * <p>The subscriptions which the identification would be based on, are all the active 14119 * subscriptions, no matter which subscription could be used to create TelephonyManager. 14120 * 14121 * <p>Requires permission: {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE} or 14122 * that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 14123 * 14124 * @param number - the number to look up 14125 * @return {@code true} if the given number is an emergency number or it simply starts with 14126 * the same digits of any current emergency number based on current locale, sim, modem and 14127 * network; {@code false} if it is not; or throw an SecurityException if the caller does not 14128 * have the required permission/privileges 14129 * @throws IllegalStateException if the Telephony process is not currently available. 14130 * @hide 14131 */ 14132 @SystemApi 14133 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 14134 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) isPotentialEmergencyNumber(@onNull String number)14135 public boolean isPotentialEmergencyNumber(@NonNull String number) { 14136 try { 14137 ITelephony telephony = getITelephony(); 14138 if (telephony != null) { 14139 return telephony.isEmergencyNumber(number, false); 14140 } else { 14141 throw new IllegalStateException("telephony service is null."); 14142 } 14143 } catch (RemoteException ex) { 14144 Log.e(TAG, "isEmergencyNumber RemoteException", ex); 14145 ex.rethrowAsRuntimeException(); 14146 } 14147 return false; 14148 } 14149 14150 /** 14151 * Returns the emergency number database version. 14152 * 14153 * <p>Requires Permission: 14154 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 14155 * 14156 * @hide 14157 */ 14158 @SystemApi 14159 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 14160 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) getEmergencyNumberDbVersion()14161 public int getEmergencyNumberDbVersion() { 14162 try { 14163 ITelephony telephony = getITelephony(); 14164 if (telephony != null) { 14165 return telephony.getEmergencyNumberDbVersion(getSubId()); 14166 } 14167 } catch (RemoteException ex) { 14168 Log.e(TAG, "getEmergencyNumberDbVersion RemoteException", ex); 14169 ex.rethrowAsRuntimeException(); 14170 } 14171 return INVALID_EMERGENCY_NUMBER_DB_VERSION; 14172 } 14173 14174 /** @hide */ 14175 @Retention(RetentionPolicy.SOURCE) 14176 @IntDef(prefix = {"SET_OPPORTUNISTIC_SUB"}, value = { 14177 SET_OPPORTUNISTIC_SUB_SUCCESS, 14178 SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED, 14179 SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION, 14180 SET_OPPORTUNISTIC_SUB_NO_OPPORTUNISTIC_SUB_AVAILABLE, 14181 SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION}) 14182 public @interface SetOpportunisticSubscriptionResult {} 14183 14184 /** 14185 * No error. Operation succeeded. 14186 */ 14187 public static final int SET_OPPORTUNISTIC_SUB_SUCCESS = 0; 14188 14189 /** 14190 * Validation failed when trying to switch to preferred subscription. 14191 */ 14192 public static final int SET_OPPORTUNISTIC_SUB_VALIDATION_FAILED = 1; 14193 14194 /** 14195 * The subscription is not valid. It must be an active opportunistic subscription. 14196 */ 14197 public static final int SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION = 2; 14198 14199 /** 14200 * The subscription is not valid. It must be an opportunistic subscription. 14201 */ 14202 public static final int SET_OPPORTUNISTIC_SUB_NO_OPPORTUNISTIC_SUB_AVAILABLE = 3; 14203 14204 /** 14205 * Subscription service happened remote exception. 14206 */ 14207 public static final int SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION = 4; 14208 14209 14210 /** @hide */ 14211 @Retention(RetentionPolicy.SOURCE) 14212 @IntDef(prefix = {"UPDATE_AVAILABLE_NETWORKS"}, value = { 14213 UPDATE_AVAILABLE_NETWORKS_SUCCESS, 14214 UPDATE_AVAILABLE_NETWORKS_UNKNOWN_FAILURE, 14215 UPDATE_AVAILABLE_NETWORKS_ABORTED, 14216 UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS, 14217 UPDATE_AVAILABLE_NETWORKS_NO_CARRIER_PRIVILEGE, 14218 UPDATE_AVAILABLE_NETWORKS_DISABLE_MODEM_FAIL, 14219 UPDATE_AVAILABLE_NETWORKS_ENABLE_MODEM_FAIL, 14220 UPDATE_AVAILABLE_NETWORKS_MULTIPLE_NETWORKS_NOT_SUPPORTED, 14221 UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE, 14222 UPDATE_AVAILABLE_NETWORKS_REMOTE_SERVICE_EXCEPTION, 14223 UPDATE_AVAILABLE_NETWORKS_SERVICE_IS_DISABLED, 14224 UPDATE_AVAILABLE_NETWORKS_SIM_PORT_NOT_AVAILABLE}) 14225 public @interface UpdateAvailableNetworksResult {} 14226 14227 /** 14228 * No error. Operation succeeded. 14229 */ 14230 public static final int UPDATE_AVAILABLE_NETWORKS_SUCCESS = 0; 14231 14232 /** 14233 * There is a unknown failure happened. 14234 */ 14235 public static final int UPDATE_AVAILABLE_NETWORKS_UNKNOWN_FAILURE = 1; 14236 14237 /** 14238 * The request is aborted. 14239 */ 14240 public static final int UPDATE_AVAILABLE_NETWORKS_ABORTED = 2; 14241 14242 /** 14243 * The parameter passed in is invalid. 14244 */ 14245 public static final int UPDATE_AVAILABLE_NETWORKS_INVALID_ARGUMENTS = 3; 14246 14247 /** 14248 * No carrier privilege. 14249 */ 14250 public static final int UPDATE_AVAILABLE_NETWORKS_NO_CARRIER_PRIVILEGE = 4; 14251 14252 /** 14253 * Disable modem fail. 14254 */ 14255 public static final int UPDATE_AVAILABLE_NETWORKS_DISABLE_MODEM_FAIL = 5; 14256 14257 /** 14258 * Enable modem fail. 14259 */ 14260 public static final int UPDATE_AVAILABLE_NETWORKS_ENABLE_MODEM_FAIL = 6; 14261 14262 /** 14263 * Carrier app does not support multiple available networks. 14264 */ 14265 public static final int UPDATE_AVAILABLE_NETWORKS_MULTIPLE_NETWORKS_NOT_SUPPORTED = 7; 14266 14267 /** 14268 * The subscription is not valid. It must be an opportunistic subscription. 14269 */ 14270 public static final int UPDATE_AVAILABLE_NETWORKS_NO_OPPORTUNISTIC_SUB_AVAILABLE = 8; 14271 14272 /** 14273 * There is no OpportunisticNetworkService. 14274 */ 14275 public static final int UPDATE_AVAILABLE_NETWORKS_REMOTE_SERVICE_EXCEPTION = 9; 14276 14277 /** 14278 * OpportunisticNetworkService is disabled. 14279 */ 14280 public static final int UPDATE_AVAILABLE_NETWORKS_SERVICE_IS_DISABLED = 10; 14281 14282 /** 14283 * SIM port is not available to switch to opportunistic subscription. 14284 * @hide 14285 */ 14286 public static final int UPDATE_AVAILABLE_NETWORKS_SIM_PORT_NOT_AVAILABLE = 11; 14287 14288 /** 14289 * Set preferred opportunistic data subscription id. 14290 * 14291 * Switch internet data to preferred opportunistic data subscription id. This api 14292 * can result in lose of internet connectivity for short period of time while internet data 14293 * is handed over. 14294 * <p>Requires that the calling app has carrier privileges on both primary and 14295 * secondary subscriptions (see 14296 * {@link #hasCarrierPrivileges}), or has permission 14297 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 14298 * 14299 * @param subId which opportunistic subscription 14300 * {@link SubscriptionManager#getOpportunisticSubscriptions} is preferred for cellular data. 14301 * Pass {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} to unset the preference 14302 * @param needValidation whether validation is needed before switch happens. 14303 * @param executor The executor of where the callback will execute. 14304 * @param callback Callback will be triggered once it succeeds or failed. 14305 * See {@link TelephonyManager.SetOpportunisticSubscriptionResult} 14306 * for more details. Pass null if don't care about the result. 14307 */ 14308 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) setPreferredOpportunisticDataSubscription(int subId, boolean needValidation, @Nullable @CallbackExecutor Executor executor, @Nullable Consumer<Integer> callback)14309 public void setPreferredOpportunisticDataSubscription(int subId, boolean needValidation, 14310 @Nullable @CallbackExecutor Executor executor, @Nullable Consumer<Integer> callback) { 14311 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 14312 try { 14313 IOns iOpportunisticNetworkService = getIOns(); 14314 if (iOpportunisticNetworkService == null) { 14315 if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) { 14316 throw new IllegalStateException("Opportunistic Network Service is null"); 14317 } else { 14318 // Let the general remote exception handling catch this. 14319 throw new RemoteException("Null Opportunistic Network Service!"); 14320 } 14321 } 14322 ISetOpportunisticDataCallback callbackStub = new ISetOpportunisticDataCallback.Stub() { 14323 @Override 14324 public void onComplete(int result) { 14325 if (executor == null || callback == null) { 14326 return; 14327 } 14328 final long identity = Binder.clearCallingIdentity(); 14329 try { 14330 executor.execute(() -> { 14331 callback.accept(result); 14332 }); 14333 } finally { 14334 Binder.restoreCallingIdentity(identity); 14335 } 14336 } 14337 }; 14338 14339 iOpportunisticNetworkService 14340 .setPreferredDataSubscriptionId(subId, needValidation, callbackStub, 14341 pkgForDebug); 14342 } catch (RemoteException ex) { 14343 Rlog.e(TAG, "setPreferredOpportunisticDataSubscription RemoteException", ex); 14344 if (executor == null || callback == null) { 14345 return; 14346 } 14347 runOnBackgroundThread(() -> executor.execute(() -> { 14348 if (Compatibility.isChangeEnabled(CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { 14349 callback.accept(SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION); 14350 } else { 14351 callback.accept(SET_OPPORTUNISTIC_SUB_INACTIVE_SUBSCRIPTION); 14352 } 14353 })); 14354 } 14355 } 14356 14357 /** 14358 * Get preferred opportunistic data subscription Id 14359 * 14360 * <p>Requires that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}), 14361 * or has either READ_PRIVILEGED_PHONE_STATE 14362 * or {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} permission. 14363 * @return subId preferred opportunistic subscription id or 14364 * {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} if there are no preferred 14365 * subscription id 14366 * 14367 */ 14368 @RequiresPermission(anyOf = { 14369 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, 14370 android.Manifest.permission.READ_PHONE_STATE 14371 }) 14372 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) getPreferredOpportunisticDataSubscription()14373 public int getPreferredOpportunisticDataSubscription() { 14374 String packageName = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 14375 String attributionTag = mContext != null ? mContext.getAttributionTag() : null; 14376 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 14377 try { 14378 IOns iOpportunisticNetworkService = getIOns(); 14379 if (iOpportunisticNetworkService != null) { 14380 subId = iOpportunisticNetworkService.getPreferredDataSubscriptionId( 14381 packageName, attributionTag); 14382 } 14383 } catch (RemoteException ex) { 14384 Rlog.e(TAG, "getPreferredDataSubscriptionId RemoteException", ex); 14385 } 14386 return subId; 14387 } 14388 14389 /** 14390 * Update availability of a list of networks in the current location. 14391 * 14392 * This api should be called to inform OpportunisticNetwork Service about the availability 14393 * of a network at the current location. This information will be used by OpportunisticNetwork 14394 * service to enable modem stack and to attach to the network. If an empty list is passed, 14395 * it is assumed that no network is available and will result in disabling the modem stack 14396 * to save power. This api do not switch internet data once network attach is completed. 14397 * Use {@link TelephonyManager#setPreferredOpportunisticDataSubscription} 14398 * to switch internet data after network attach is complete. 14399 * Requires that the calling app has carrier privileges on both primary and 14400 * secondary subscriptions (see {@link #hasCarrierPrivileges}), or has permission 14401 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 14402 * @param availableNetworks is a list of available network information. 14403 * @param executor The executor of where the callback will execute. 14404 * @param callback Callback will be triggered once it succeeds or failed. 14405 * 14406 */ 14407 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 14408 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) updateAvailableNetworks(@onNull List<AvailableNetworkInfo> availableNetworks, @Nullable @CallbackExecutor Executor executor, @UpdateAvailableNetworksResult @Nullable Consumer<Integer> callback)14409 public void updateAvailableNetworks(@NonNull List<AvailableNetworkInfo> availableNetworks, 14410 @Nullable @CallbackExecutor Executor executor, 14411 @UpdateAvailableNetworksResult @Nullable Consumer<Integer> callback) { 14412 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 14413 Objects.requireNonNull(availableNetworks, "availableNetworks must not be null."); 14414 try { 14415 IOns iOpportunisticNetworkService = getIOns(); 14416 if (iOpportunisticNetworkService == null) { 14417 if (Compatibility.isChangeEnabled(NULL_TELEPHONY_THROW_NO_CB)) { 14418 throw new IllegalStateException("Opportunistic Network Service is null"); 14419 } else { 14420 // Let the general remote exception handling catch this. 14421 throw new RemoteException("Null Opportunistic Network Service!"); 14422 } 14423 } 14424 14425 IUpdateAvailableNetworksCallback callbackStub = 14426 new IUpdateAvailableNetworksCallback.Stub() { 14427 @Override 14428 public void onComplete(int result) { 14429 if (executor == null || callback == null) { 14430 return; 14431 } 14432 Binder.withCleanCallingIdentity(() -> { 14433 executor.execute(() -> callback.accept(result)); 14434 }); 14435 } 14436 }; 14437 iOpportunisticNetworkService 14438 .updateAvailableNetworks(availableNetworks, callbackStub, pkgForDebug); 14439 } catch (RemoteException ex) { 14440 Rlog.e(TAG, "updateAvailableNetworks RemoteException", ex); 14441 if (executor == null || callback == null) { 14442 return; 14443 } 14444 runOnBackgroundThread(() -> executor.execute(() -> { 14445 if (Compatibility.isChangeEnabled(CALLBACK_ON_MORE_ERROR_CODE_CHANGE)) { 14446 callback.accept(UPDATE_AVAILABLE_NETWORKS_REMOTE_SERVICE_EXCEPTION); 14447 } else { 14448 callback.accept(UPDATE_AVAILABLE_NETWORKS_UNKNOWN_FAILURE); 14449 } 14450 })); 14451 } 14452 } 14453 14454 /** 14455 * Enable or disable a logical modem stack. When a logical modem is disabled, the corresponding 14456 * SIM will still be visible to the user but its mapping modem will not have any radio activity. 14457 * For example, we will disable a modem when user or system believes the corresponding SIM 14458 * is temporarily not needed (e.g. out of coverage), and will enable it back on when needed. 14459 * 14460 * Requires that the calling app has permission 14461 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. 14462 * @param slotIndex which corresponding modem will operate on. 14463 * @param enable whether to enable or disable the modem stack. 14464 * @return whether the operation is successful. 14465 * 14466 * @hide 14467 */ 14468 @SystemApi 14469 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) enableModemForSlot(int slotIndex, boolean enable)14470 public boolean enableModemForSlot(int slotIndex, boolean enable) { 14471 boolean ret = false; 14472 try { 14473 ITelephony telephony = getITelephony(); 14474 if (telephony != null) { 14475 ret = telephony.enableModemForSlot(slotIndex, enable); 14476 } 14477 } catch (RemoteException ex) { 14478 Log.e(TAG, "enableModem RemoteException", ex); 14479 } 14480 return ret; 14481 } 14482 14483 /** 14484 * Indicates whether or not there is a modem stack enabled for the given SIM slot. 14485 * 14486 * <p>Requires Permission: 14487 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}, 14488 * READ_PRIVILEGED_PHONE_STATE or that the calling app has carrier privileges (see 14489 * {@link #hasCarrierPrivileges()}). 14490 * 14491 * @param slotIndex which slot it's checking. 14492 */ 14493 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 14494 @RequiresPermission(anyOf = {android.Manifest.permission.READ_PHONE_STATE, 14495 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE}) isModemEnabledForSlot(int slotIndex)14496 public boolean isModemEnabledForSlot(int slotIndex) { 14497 try { 14498 ITelephony telephony = getITelephony(); 14499 if (telephony != null) { 14500 return telephony.isModemEnabledForSlot(slotIndex, mContext.getOpPackageName(), 14501 mContext.getAttributionTag()); 14502 } 14503 } catch (RemoteException ex) { 14504 Log.e(TAG, "enableModem RemoteException", ex); 14505 } 14506 return false; 14507 } 14508 14509 /** 14510 * Broadcast intent action for network country code changes. 14511 * 14512 * <p> 14513 * The {@link #EXTRA_NETWORK_COUNTRY} extra indicates the country code of the current 14514 * network returned by {@link #getNetworkCountryIso()}. 14515 * 14516 * <p>There may be a delay of several minutes before reporting that no country is detected. 14517 * 14518 * @see #EXTRA_NETWORK_COUNTRY 14519 * @see #getNetworkCountryIso() 14520 */ 14521 public static final String ACTION_NETWORK_COUNTRY_CHANGED = 14522 "android.telephony.action.NETWORK_COUNTRY_CHANGED"; 14523 14524 /** 14525 * The extra used with an {@link #ACTION_NETWORK_COUNTRY_CHANGED} to specify the 14526 * the country code in ISO-3166-1 alpha-2 format. 14527 * <p class="note"> 14528 * Retrieve with {@link android.content.Intent#getStringExtra(String)}. 14529 */ 14530 public static final String EXTRA_NETWORK_COUNTRY = 14531 "android.telephony.extra.NETWORK_COUNTRY"; 14532 14533 /** 14534 * The extra used with an {@link #ACTION_NETWORK_COUNTRY_CHANGED} to specify the 14535 * last known the country code in ISO-3166-1 alpha-2 format. 14536 * <p class="note"> 14537 * Retrieve with {@link android.content.Intent#getStringExtra(String)}. 14538 * 14539 * @hide 14540 */ 14541 public static final String EXTRA_LAST_KNOWN_NETWORK_COUNTRY = 14542 "android.telephony.extra.LAST_KNOWN_NETWORK_COUNTRY"; 14543 14544 /** 14545 * Indicate if the user is allowed to use multiple SIM cards at the same time to register 14546 * on the network (e.g. Dual Standby or Dual Active) when the device supports it, or if the 14547 * usage is restricted. This API is used to prevent usage of multiple SIM card, based on 14548 * policies of the carrier. 14549 * <p>Note: the API does not prevent access to the SIM cards for operations that don't require 14550 * access to the network. 14551 * 14552 * @param isMultiSimCarrierRestricted true if usage of multiple SIMs is restricted, false 14553 * otherwise. 14554 * 14555 * @hide 14556 */ 14557 @SystemApi 14558 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 14559 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CARRIERLOCK) setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted)14560 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { 14561 try { 14562 ITelephony service = getITelephony(); 14563 if (service != null) { 14564 service.setMultiSimCarrierRestriction(isMultiSimCarrierRestricted); 14565 } 14566 } catch (RemoteException e) { 14567 Log.e(TAG, "setMultiSimCarrierRestriction RemoteException", e); 14568 } 14569 } 14570 14571 /** 14572 * The usage of multiple SIM cards at the same time to register on the network (e.g. Dual 14573 * Standby or Dual Active) is supported. 14574 */ 14575 public static final int MULTISIM_ALLOWED = 0; 14576 14577 /** 14578 * The usage of multiple SIM cards at the same time to register on the network (e.g. Dual 14579 * Standby or Dual Active) is not supported by the hardware. 14580 */ 14581 public static final int MULTISIM_NOT_SUPPORTED_BY_HARDWARE = 1; 14582 14583 /** 14584 * The usage of multiple SIM cards at the same time to register on the network (e.g. Dual 14585 * Standby or Dual Active) is supported by the hardware, but restricted by the carrier. 14586 */ 14587 public static final int MULTISIM_NOT_SUPPORTED_BY_CARRIER = 2; 14588 14589 /** @hide */ 14590 @Retention(RetentionPolicy.SOURCE) 14591 @IntDef(prefix = {"MULTISIM_"}, 14592 value = { 14593 MULTISIM_ALLOWED, 14594 MULTISIM_NOT_SUPPORTED_BY_HARDWARE, 14595 MULTISIM_NOT_SUPPORTED_BY_CARRIER 14596 }) 14597 public @interface IsMultiSimSupportedResult {} 14598 14599 /** 14600 * Returns if the usage of multiple SIM cards at the same time to register on the network 14601 * (e.g. Dual Standby or Dual Active) is supported by the device and by the carrier. 14602 * 14603 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 14604 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 14605 * 14606 * @return {@link #MULTISIM_ALLOWED} if the device supports multiple SIMs. 14607 * {@link #MULTISIM_NOT_SUPPORTED_BY_HARDWARE} if the device does not support multiple SIMs. 14608 * {@link #MULTISIM_NOT_SUPPORTED_BY_CARRIER} in the device supports multiple SIMs, but the 14609 * functionality is restricted by the carrier. 14610 */ 14611 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 14612 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 14613 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) 14614 @IsMultiSimSupportedResult isMultiSimSupported()14615 public int isMultiSimSupported() { 14616 if (getSupportedModemCount() < 2) { 14617 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; 14618 } 14619 try { 14620 ITelephony service = getITelephony(); 14621 if (service != null) { 14622 return service.isMultiSimSupported(getOpPackageName(), getAttributionTag()); 14623 } 14624 } catch (RemoteException e) { 14625 Log.e(TAG, "isMultiSimSupported RemoteException", e); 14626 } 14627 return MULTISIM_NOT_SUPPORTED_BY_HARDWARE; 14628 } 14629 14630 /** 14631 * Switch configs to enable multi-sim or switch back to single-sim 14632 * <p>Requires Permission: 14633 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the 14634 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 14635 * 14636 * Note: with only carrier privileges, it is not allowed to switch from multi-sim 14637 * to single-sim 14638 * 14639 * @param numOfSims number of live SIMs we want to switch to 14640 * @throws android.os.RemoteException 14641 */ 14642 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 14643 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 14644 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) switchMultiSimConfig(int numOfSims)14645 public void switchMultiSimConfig(int numOfSims) { 14646 try { 14647 ITelephony telephony = getITelephony(); 14648 if (telephony != null) { 14649 telephony.switchMultiSimConfig(numOfSims); 14650 } 14651 } catch (RemoteException ex) { 14652 Rlog.e(TAG, "switchMultiSimConfig RemoteException", ex); 14653 } 14654 } 14655 14656 /** 14657 * Get whether making changes to modem configurations by {@link #switchMultiSimConfig(int)} will 14658 * trigger device reboot. 14659 * The modem configuration change refers to switching from single SIM configuration to DSDS 14660 * or the other way around. 14661 * 14662 * <p>Requires Permission: 14663 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} or that the 14664 * calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 14665 * 14666 * @return {@code true} if reboot will be triggered after making changes to modem 14667 * configurations, otherwise return {@code false}. 14668 */ 14669 @RequiresPermission(Manifest.permission.READ_PHONE_STATE) 14670 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) doesSwitchMultiSimConfigTriggerReboot()14671 public boolean doesSwitchMultiSimConfigTriggerReboot() { 14672 try { 14673 ITelephony service = getITelephony(); 14674 if (service != null) { 14675 return service.doesSwitchMultiSimConfigTriggerReboot(getSubId(), 14676 getOpPackageName(), getAttributionTag()); 14677 } 14678 } catch (RemoteException e) { 14679 Log.e(TAG, "doesSwitchMultiSimConfigTriggerReboot RemoteException", e); 14680 } 14681 return false; 14682 } 14683 14684 /** 14685 * Retrieve the Radio HAL Version for this device. 14686 * 14687 * Get the HAL version for the IRadio interface for test purposes. 14688 * 14689 * @return a Pair of (major version, minor version) or (-1,-1) if unknown. 14690 * 14691 * @hide 14692 */ 14693 @UnsupportedAppUsage 14694 @TestApi getRadioHalVersion()14695 public Pair<Integer, Integer> getRadioHalVersion() { 14696 try { 14697 ITelephony service = getITelephony(); 14698 if (service != null) { 14699 int version = service.getRadioHalVersion(); 14700 if (version == -1) return new Pair<Integer, Integer>(-1, -1); 14701 return new Pair<Integer, Integer>(version / 100, version % 100); 14702 } 14703 } catch (RemoteException e) { 14704 Log.e(TAG, "getRadioHalVersion() RemoteException", e); 14705 } 14706 return new Pair<Integer, Integer>(-1, -1); 14707 } 14708 14709 /** 14710 * Get the calling application status about carrier privileges for the subscription created 14711 * in TelephonyManager. Used by Telephony Module for permission checking. 14712 * 14713 * @param uid Uid to check. 14714 * @return any value of {@link #CARRIER_PRIVILEGE_STATUS_HAS_ACCESS}, 14715 * {@link #CARRIER_PRIVILEGE_STATUS_NO_ACCESS}, 14716 * {@link #CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED}, or 14717 * {@link #CARRIER_PRIVILEGE_STATUS_ERROR_LOADING_RULES} 14718 * 14719 * @hide 14720 */ 14721 @SystemApi 14722 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 14723 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getCarrierPrivilegeStatus(int uid)14724 public @CarrierPrivilegeStatus int getCarrierPrivilegeStatus(int uid) { 14725 try { 14726 ITelephony telephony = getITelephony(); 14727 if (telephony != null) { 14728 return telephony.getCarrierPrivilegeStatusForUid(getSubId(), uid); 14729 } 14730 } catch (RemoteException ex) { 14731 Log.e(TAG, "getCarrierPrivilegeStatus RemoteException", ex); 14732 } 14733 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; 14734 } 14735 14736 /** 14737 * Returns a list of APNs set as overrides by the device policy manager via 14738 * {@link #addDevicePolicyOverrideApn}. 14739 * This method must only be called from the system or phone processes. 14740 * 14741 * @param context Context to use. 14742 * @return {@link List} of APNs that have been set as overrides. 14743 * @throws {@link SecurityException} if the caller is not the system or phone process. 14744 * @hide 14745 */ 14746 @TestApi 14747 // TODO: add new permission tag indicating that this is system-only. getDevicePolicyOverrideApns(@onNull Context context)14748 public @NonNull List<ApnSetting> getDevicePolicyOverrideApns(@NonNull Context context) { 14749 try (Cursor cursor = context.getContentResolver().query(DPC_URI, null, null, null, null)) { 14750 if (cursor == null) { 14751 return Collections.emptyList(); 14752 } 14753 List<ApnSetting> apnList = new ArrayList<ApnSetting>(); 14754 cursor.moveToPosition(-1); 14755 while (cursor.moveToNext()) { 14756 ApnSetting apn = ApnSetting.makeApnSetting(cursor); 14757 apnList.add(apn); 14758 } 14759 return apnList; 14760 } 14761 } 14762 14763 /** 14764 * Used by the device policy manager to add a new override APN. 14765 * This method must only be called from the system or phone processes. 14766 * 14767 * @param context Context to use. 14768 * @param apnSetting The {@link ApnSetting} describing the new APN. 14769 * @return An integer, corresponding to a primary key in a database, that allows the caller to 14770 * modify the APN in the future via {@link #modifyDevicePolicyOverrideApn}, or 14771 * {@link android.provider.Telephony.Carriers.INVALID_APN_ID} if the override operation 14772 * failed. 14773 * @throws {@link SecurityException} if the caller is not the system or phone process. 14774 * @hide 14775 */ 14776 @TestApi 14777 // TODO: add new permission tag indicating that this is system-only. addDevicePolicyOverrideApn(@onNull Context context, @NonNull ApnSetting apnSetting)14778 public int addDevicePolicyOverrideApn(@NonNull Context context, 14779 @NonNull ApnSetting apnSetting) { 14780 Uri resultUri = context.getContentResolver().insert(DPC_URI, apnSetting.toContentValues()); 14781 14782 int resultId = INVALID_APN_ID; 14783 if (resultUri != null) { 14784 try { 14785 resultId = Integer.parseInt(resultUri.getLastPathSegment()); 14786 } catch (NumberFormatException e) { 14787 Rlog.e(TAG, "Failed to parse inserted override APN id: " 14788 + resultUri.getLastPathSegment()); 14789 } 14790 } 14791 return resultId; 14792 } 14793 14794 /** 14795 * Used by the device policy manager to modify an override APN. 14796 * This method must only be called from the system or phone processes. 14797 * 14798 * @param context Context to use. 14799 * @param apnId The integer key of the APN to modify, as returned by 14800 * {@link #addDevicePolicyOverrideApn} 14801 * @param apnSetting The {@link ApnSetting} describing the updated APN. 14802 * @return {@code true} if successful, {@code false} otherwise. 14803 * @throws {@link SecurityException} if the caller is not the system or phone process. 14804 * @hide 14805 */ 14806 @TestApi 14807 // TODO: add new permission tag indicating that this is system-only. modifyDevicePolicyOverrideApn(@onNull Context context, int apnId, @NonNull ApnSetting apnSetting)14808 public boolean modifyDevicePolicyOverrideApn(@NonNull Context context, int apnId, 14809 @NonNull ApnSetting apnSetting) { 14810 return context.getContentResolver().update( 14811 Uri.withAppendedPath(DPC_URI, Integer.toString(apnId)), 14812 apnSetting.toContentValues(), null, null) > 0; 14813 } 14814 14815 /** 14816 * Return whether data is enabled for certain APN type. This will tell if framework will accept 14817 * corresponding network requests on a subId. 14818 * 14819 * {@link #isDataEnabled()} is directly associated with users' Mobile data toggle on / off. If 14820 * {@link #isDataEnabled()} returns false, it means in general all meter-ed data are disabled. 14821 * 14822 * This per APN type API gives a better idea whether data is allowed on a specific APN type. 14823 * It will return true if: 14824 * 14825 * 1) User data is turned on, or 14826 * 2) APN is un-metered for this subscription, or 14827 * 3) APN type is whitelisted. E.g. MMS is whitelisted if 14828 * {@link #MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. 14829 * 14830 * @param apnType Value indicating the apn type. Apn types are defined in {@link ApnSetting}. 14831 * @return whether data is enabled for a apn type. 14832 * 14833 * @hide 14834 */ 14835 @SystemApi 14836 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 14837 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) isDataEnabledForApn(@pnType int apnType)14838 public boolean isDataEnabledForApn(@ApnType int apnType) { 14839 String pkgForDebug = mContext != null ? mContext.getOpPackageName() : "<unknown>"; 14840 try { 14841 ITelephony service = getITelephony(); 14842 if (service != null) { 14843 return service.isDataEnabledForApn(apnType, getSubId(), pkgForDebug); 14844 } 14845 } catch (RemoteException ex) { 14846 Rlog.e(TAG, "Telephony#isDataEnabledForApn RemoteException" + ex); 14847 } 14848 return false; 14849 } 14850 14851 /** 14852 * Whether an APN type is metered or not. It will be evaluated with the subId associated 14853 * with the TelephonyManager instance. 14854 * 14855 * @hide 14856 */ 14857 @SystemApi 14858 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 14859 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) isApnMetered(@pnType int apnType)14860 public boolean isApnMetered(@ApnType int apnType) { 14861 try { 14862 ITelephony service = getITelephony(); 14863 if (service != null) { 14864 return service.isApnMetered(apnType, getSubId()); 14865 } 14866 } catch (RemoteException ex) { 14867 Rlog.e(TAG, "Telephony#isApnMetered RemoteException" + ex); 14868 } 14869 return true; 14870 } 14871 14872 /** 14873 * Specify which bands modem's background scan must act on. 14874 * If {@code specifiers} is non-empty, the scan will be restricted to the bands specified. 14875 * Otherwise, it scans all bands. 14876 * 14877 * For example, CBRS is only on LTE band 48. By specifying this band, 14878 * modem saves more power. 14879 * 14880 * @param specifiers which bands to scan. 14881 * @param executor The executor to execute the callback on 14882 * @param callback The callback that gets invoked when the radio responds to the request. Called 14883 * with {@code true} if the request succeeded, {@code false} otherwise. 14884 * @hide 14885 */ 14886 @SystemApi 14887 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 14888 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) setSystemSelectionChannels(@onNull List<RadioAccessSpecifier> specifiers, @NonNull @CallbackExecutor Executor executor, @NonNull Consumer<Boolean> callback)14889 public void setSystemSelectionChannels(@NonNull List<RadioAccessSpecifier> specifiers, 14890 @NonNull @CallbackExecutor Executor executor, 14891 @NonNull Consumer<Boolean> callback) { 14892 Objects.requireNonNull(specifiers, "Specifiers must not be null."); 14893 Objects.requireNonNull(executor, "Executor must not be null."); 14894 Objects.requireNonNull(callback, "Callback must not be null."); 14895 setSystemSelectionChannelsInternal(specifiers, executor, callback); 14896 } 14897 14898 /** 14899 * Same as {@link #setSystemSelectionChannels(List, Executor, Consumer<Boolean>)}, but to be 14900 * used when the caller does not need feedback on the results of the operation. 14901 * @param specifiers which bands to scan. 14902 * @hide 14903 */ 14904 @SystemApi 14905 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 14906 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) setSystemSelectionChannels(@onNull List<RadioAccessSpecifier> specifiers)14907 public void setSystemSelectionChannels(@NonNull List<RadioAccessSpecifier> specifiers) { 14908 Objects.requireNonNull(specifiers, "Specifiers must not be null."); 14909 setSystemSelectionChannelsInternal(specifiers, null, null); 14910 } 14911 14912 setSystemSelectionChannelsInternal(@onNull List<RadioAccessSpecifier> specifiers, @Nullable @CallbackExecutor Executor executor, @Nullable Consumer<Boolean> callback)14913 private void setSystemSelectionChannelsInternal(@NonNull List<RadioAccessSpecifier> specifiers, 14914 @Nullable @CallbackExecutor Executor executor, 14915 @Nullable Consumer<Boolean> callback) { 14916 IBooleanConsumer aidlConsumer = callback == null ? null : new IBooleanConsumer.Stub() { 14917 @Override 14918 public void accept(boolean result) { 14919 final long identity = Binder.clearCallingIdentity(); 14920 try { 14921 executor.execute(() -> callback.accept(result)); 14922 } finally { 14923 Binder.restoreCallingIdentity(identity); 14924 } 14925 } 14926 }; 14927 14928 try { 14929 ITelephony service = getITelephony(); 14930 if (service != null) { 14931 service.setSystemSelectionChannels(specifiers, getSubId(), aidlConsumer); 14932 } 14933 } catch (RemoteException ex) { 14934 Rlog.e(TAG, "Telephony#setSystemSelectionChannels RemoteException" + ex); 14935 } 14936 } 14937 14938 /** 14939 * Get which bands the modem's background scan is acting on, specified by 14940 * {@link #setSystemSelectionChannels}. 14941 * 14942 * <p>Requires Permission: 14943 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 14944 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 14945 * 14946 * @return a list of {@link RadioAccessSpecifier}, or an empty list if no bands are specified. 14947 * @throws IllegalStateException if the Telephony process is not currently available. 14948 * 14949 * @hide 14950 */ 14951 @SystemApi 14952 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 14953 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) getSystemSelectionChannels()14954 public @NonNull List<RadioAccessSpecifier> getSystemSelectionChannels() { 14955 try { 14956 ITelephony service = getITelephony(); 14957 if (service != null) { 14958 return service.getSystemSelectionChannels(getSubId()); 14959 } else { 14960 throw new IllegalStateException("telephony service is null."); 14961 } 14962 } catch (RemoteException ex) { 14963 Rlog.e(TAG, "Telephony#getSystemSelectionChannels RemoteException" + ex); 14964 } 14965 return new ArrayList<>(); 14966 } 14967 14968 /** 14969 * Verifies whether the input MCC/MNC and MVNO correspond to the current carrier. 14970 * 14971 * @param mccmnc the carrier's mccmnc that you want to match 14972 * @param mvnoType the mvnoType that defined in {@link ApnSetting} 14973 * @param mvnoMatchData the MVNO match data 14974 * @return {@code true} if input mccmnc and mvno matches with data from sim operator. 14975 * {@code false} otherwise. 14976 * 14977 * {@hide} 14978 */ 14979 @SystemApi 14980 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 14981 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) matchesCurrentSimOperator(@onNull String mccmnc, @MvnoType int mvnoType, @Nullable String mvnoMatchData)14982 public boolean matchesCurrentSimOperator(@NonNull String mccmnc, @MvnoType int mvnoType, 14983 @Nullable String mvnoMatchData) { 14984 try { 14985 if (!mccmnc.equals(getSimOperator())) { 14986 return false; 14987 } 14988 ITelephony service = getITelephony(); 14989 if (service != null) { 14990 return service.isMvnoMatched(getSlotIndex(), mvnoType, mvnoMatchData); 14991 } 14992 } catch (RemoteException ex) { 14993 Rlog.e(TAG, "Telephony#matchesCurrentSimOperator RemoteException" + ex); 14994 } 14995 return false; 14996 } 14997 14998 /** 14999 * Callback to be used with {@link #getCallForwarding} 15000 * @hide 15001 */ 15002 @SystemApi 15003 public interface CallForwardingInfoCallback { 15004 /** 15005 * Indicates that the operation was successful. 15006 */ 15007 int RESULT_SUCCESS = 0; 15008 15009 /** 15010 * Indicates that setting or retrieving the call forwarding info failed with an unknown 15011 * error. 15012 */ 15013 int RESULT_ERROR_UNKNOWN = 1; 15014 15015 /** 15016 * Indicates that call forwarding is not enabled because the recipient is not on a 15017 * Fixed Dialing Number (FDN) list. 15018 */ 15019 int RESULT_ERROR_FDN_CHECK_FAILURE = 2; 15020 15021 /** 15022 * Indicates that call forwarding is not supported on the network at this time. 15023 */ 15024 int RESULT_ERROR_NOT_SUPPORTED = 3; 15025 15026 /** 15027 * Call forwarding errors 15028 * @hide 15029 */ 15030 @IntDef(prefix = { "RESULT_ERROR_" }, value = { 15031 RESULT_ERROR_UNKNOWN, 15032 RESULT_ERROR_NOT_SUPPORTED, 15033 RESULT_ERROR_FDN_CHECK_FAILURE 15034 }) 15035 @Retention(RetentionPolicy.SOURCE) 15036 @interface CallForwardingError{ 15037 } 15038 /** 15039 * Called when the call forwarding info is successfully retrieved from the network. 15040 * @param info information about how calls are forwarded 15041 */ onCallForwardingInfoAvailable(@onNull CallForwardingInfo info)15042 void onCallForwardingInfoAvailable(@NonNull CallForwardingInfo info); 15043 15044 /** 15045 * Called when there was an error retrieving the call forwarding information. 15046 * @param error 15047 */ onError(@allForwardingError int error)15048 void onError(@CallForwardingError int error); 15049 } 15050 15051 /** 15052 * Gets the voice call forwarding info for a given call forwarding reason. 15053 * 15054 * This method queries the network for the currently set call forwarding configuration for the 15055 * provided call forwarding reason. When the network has provided its response, the result will 15056 * be supplied via the provided {@link Executor} on the provided 15057 * {@link CallForwardingInfoCallback}. 15058 * 15059 * @param callForwardingReason the call forwarding reason to query. 15060 * @param executor The executor on which to execute the callback once the result is ready. 15061 * @param callback The callback the results should be delivered on. 15062 * 15063 * @throws IllegalArgumentException if callForwardingReason is not any of 15064 * {@link CallForwardingInfo#REASON_UNCONDITIONAL}, {@link CallForwardingInfo#REASON_BUSY}, 15065 * {@link CallForwardingInfo#REASON_NO_REPLY}, {@link CallForwardingInfo#REASON_NOT_REACHABLE}, 15066 * {@link CallForwardingInfo#REASON_ALL}, or {@link CallForwardingInfo#REASON_ALL_CONDITIONAL} 15067 * 15068 * @hide 15069 */ 15070 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 15071 @SystemApi 15072 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) getCallForwarding(@allForwardingReason int callForwardingReason, @NonNull Executor executor, @NonNull CallForwardingInfoCallback callback)15073 public void getCallForwarding(@CallForwardingReason int callForwardingReason, 15074 @NonNull Executor executor, @NonNull CallForwardingInfoCallback callback) { 15075 if (callForwardingReason < CallForwardingInfo.REASON_UNCONDITIONAL 15076 || callForwardingReason > CallForwardingInfo.REASON_ALL_CONDITIONAL) { 15077 throw new IllegalArgumentException("callForwardingReason is out of range"); 15078 } 15079 15080 ICallForwardingInfoCallback internalCallback = new ICallForwardingInfoCallback.Stub() { 15081 @Override 15082 public void onCallForwardingInfoAvailable(CallForwardingInfo info) { 15083 executor.execute(() -> 15084 Binder.withCleanCallingIdentity(() -> 15085 callback.onCallForwardingInfoAvailable(info))); 15086 } 15087 15088 @Override 15089 public void onError(int error) { 15090 executor.execute(() -> 15091 Binder.withCleanCallingIdentity(() -> 15092 callback.onError(error))); 15093 } 15094 }; 15095 15096 try { 15097 ITelephony telephony = getITelephony(); 15098 if (telephony != null) { 15099 telephony.getCallForwarding(getSubId(), callForwardingReason, internalCallback); 15100 } 15101 } catch (RemoteException ex) { 15102 Rlog.e(TAG, "getCallForwarding RemoteException", ex); 15103 ex.rethrowAsRuntimeException(); 15104 } 15105 } 15106 15107 /** 15108 * Sets voice call forwarding behavior as described by the provided {@link CallForwardingInfo}. 15109 * 15110 * This method will enable call forwarding if the provided {@link CallForwardingInfo} returns 15111 * {@code true} from its {@link CallForwardingInfo#isEnabled()} method, and disables call 15112 * forwarding otherwise. 15113 * 15114 * If you wish to be notified about the results of this operation, provide an {@link Executor} 15115 * and {@link Consumer<Integer>} to be notified asynchronously when the operation completes. 15116 * 15117 * @param callForwardingInfo Info about whether calls should be forwarded and where they 15118 * should be forwarded to. 15119 * @param executor The executor on which the listener will be called. Must be non-null if 15120 * {@code listener} is non-null. 15121 * @param resultListener Asynchronous listener that'll be called when the operation completes. 15122 * Called with {@link CallForwardingInfoCallback#RESULT_SUCCESS} if the 15123 * operation succeeded and an error code from 15124 * {@link CallForwardingInfoCallback} it failed. 15125 * 15126 * @throws IllegalArgumentException if any of the following are true for the parameter 15127 * callForwardingInfo: 15128 * <ul> 15129 * <li>it is {@code null}.</li> 15130 * <li>{@link CallForwardingInfo#getReason()} is not any of: 15131 * <ul> 15132 * <li>{@link CallForwardingInfo#REASON_UNCONDITIONAL}</li> 15133 * <li>{@link CallForwardingInfo#REASON_BUSY}</li> 15134 * <li>{@link CallForwardingInfo#REASON_NO_REPLY}</li> 15135 * <li>{@link CallForwardingInfo#REASON_NOT_REACHABLE}</li> 15136 * <li>{@link CallForwardingInfo#REASON_ALL}</li> 15137 * <li>{@link CallForwardingInfo#REASON_ALL_CONDITIONAL}</li> 15138 * </ul> 15139 * <li>{@link CallForwardingInfo#getNumber()} returns {@code null} when enabling call 15140 * forwarding</li> 15141 * <li>{@link CallForwardingInfo#getTimeoutSeconds()} returns a non-positive value when 15142 * enabling call forwarding</li> 15143 * </ul> 15144 * @hide 15145 */ 15146 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 15147 @SystemApi 15148 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) setCallForwarding(@onNull CallForwardingInfo callForwardingInfo, @Nullable @CallbackExecutor Executor executor, @Nullable @CallForwardingInfoCallback.CallForwardingError Consumer<Integer> resultListener)15149 public void setCallForwarding(@NonNull CallForwardingInfo callForwardingInfo, 15150 @Nullable @CallbackExecutor Executor executor, 15151 @Nullable @CallForwardingInfoCallback.CallForwardingError 15152 Consumer<Integer> resultListener) { 15153 if (callForwardingInfo == null) { 15154 throw new IllegalArgumentException("callForwardingInfo is null"); 15155 } 15156 int callForwardingReason = callForwardingInfo.getReason(); 15157 if (callForwardingReason < CallForwardingInfo.REASON_UNCONDITIONAL 15158 || callForwardingReason > CallForwardingInfo.REASON_ALL_CONDITIONAL) { 15159 throw new IllegalArgumentException("callForwardingReason is out of range"); 15160 } 15161 if (callForwardingInfo.isEnabled()) { 15162 if (callForwardingInfo.getNumber() == null) { 15163 throw new IllegalArgumentException("callForwarding number is null"); 15164 } 15165 if (callForwardingReason == CallForwardingInfo.REASON_NO_REPLY 15166 && callForwardingInfo.getTimeoutSeconds() <= 0) { 15167 throw new IllegalArgumentException("callForwarding timeout isn't positive"); 15168 } 15169 } 15170 if (resultListener != null) { 15171 Objects.requireNonNull(executor); 15172 } 15173 15174 IIntegerConsumer internalCallback = new IIntegerConsumer.Stub() { 15175 @Override 15176 public void accept(int result) { 15177 executor.execute(() -> 15178 Binder.withCleanCallingIdentity(() -> resultListener.accept(result))); 15179 } 15180 }; 15181 15182 try { 15183 ITelephony telephony = getITelephony(); 15184 if (telephony != null) { 15185 telephony.setCallForwarding(getSubId(), callForwardingInfo, internalCallback); 15186 } 15187 } catch (RemoteException ex) { 15188 Rlog.e(TAG, "setCallForwarding RemoteException", ex); 15189 ex.rethrowAsRuntimeException(); 15190 } catch (NullPointerException ex) { 15191 Rlog.e(TAG, "setCallForwarding NPE", ex); 15192 throw ex; 15193 } 15194 } 15195 15196 /** 15197 * Indicates that call waiting is enabled. 15198 * 15199 * @hide 15200 */ 15201 @SystemApi 15202 public static final int CALL_WAITING_STATUS_ENABLED = 1; 15203 15204 /** 15205 * Indicates that call waiting is disabled. 15206 * 15207 * @hide 15208 */ 15209 @SystemApi 15210 public static final int CALL_WAITING_STATUS_DISABLED = 2; 15211 15212 /** 15213 * Indicates there was an unknown error retrieving the call waiting status. 15214 * 15215 * @hide 15216 */ 15217 @SystemApi 15218 public static final int CALL_WAITING_STATUS_UNKNOWN_ERROR = 3; 15219 15220 /** 15221 * Indicates the call waiting is not supported on the current network. 15222 * 15223 * @hide 15224 */ 15225 @SystemApi 15226 public static final int CALL_WAITING_STATUS_NOT_SUPPORTED = 4; 15227 15228 /** 15229 * Indicates the call waiting status could not be set or queried because the Fixed Dialing 15230 * Numbers (FDN) feature is enabled. 15231 * 15232 * @hide 15233 */ 15234 @SystemApi 15235 public static final int CALL_WAITING_STATUS_FDN_CHECK_FAILURE = 5; 15236 15237 /** 15238 * @hide 15239 */ 15240 @IntDef(prefix = { "CALL_WAITING_STATUS_" }, value = { 15241 CALL_WAITING_STATUS_ENABLED, 15242 CALL_WAITING_STATUS_DISABLED, 15243 CALL_WAITING_STATUS_UNKNOWN_ERROR, 15244 CALL_WAITING_STATUS_NOT_SUPPORTED, 15245 CALL_WAITING_STATUS_FDN_CHECK_FAILURE, 15246 }) 15247 @Retention(RetentionPolicy.SOURCE) 15248 public @interface CallWaitingStatus { 15249 } 15250 15251 /** 15252 * Retrieves the call waiting status of this device from the network. 15253 * 15254 * When call waiting is enabled, an incoming call that arrives when the user is already on 15255 * an active call will be held in a waiting state while the user is notified instead of being 15256 * rejected with a busy signal. 15257 * 15258 * @param executor The executor on which the result listener will be called. 15259 * @param resultListener A {@link Consumer} that will be called with the result fetched 15260 * from the network. The result will be one of: 15261 * <ul> 15262 * <li>{@link #CALL_WAITING_STATUS_ENABLED}}</li> 15263 * <li>{@link #CALL_WAITING_STATUS_DISABLED}}</li> 15264 * <li>{@link #CALL_WAITING_STATUS_UNKNOWN_ERROR}}</li> 15265 * <li>{@link #CALL_WAITING_STATUS_NOT_SUPPORTED}}</li> 15266 * <li>{@link #CALL_WAITING_STATUS_FDN_CHECK_FAILURE}}</li> 15267 * </ul> 15268 * @hide 15269 */ 15270 @SystemApi 15271 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 15272 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) getCallWaitingStatus(@onNull Executor executor, @NonNull @CallWaitingStatus Consumer<Integer> resultListener)15273 public void getCallWaitingStatus(@NonNull Executor executor, 15274 @NonNull @CallWaitingStatus Consumer<Integer> resultListener) { 15275 Objects.requireNonNull(executor); 15276 Objects.requireNonNull(resultListener); 15277 15278 IIntegerConsumer internalCallback = new IIntegerConsumer.Stub() { 15279 @Override 15280 public void accept(int result) { 15281 executor.execute(() -> Binder.withCleanCallingIdentity( 15282 () -> resultListener.accept(result))); 15283 } 15284 }; 15285 15286 try { 15287 ITelephony telephony = getITelephony(); 15288 if (telephony != null) { 15289 telephony.getCallWaitingStatus(getSubId(), internalCallback); 15290 } 15291 } catch (RemoteException ex) { 15292 Rlog.e(TAG, "getCallWaitingStatus RemoteException", ex); 15293 ex.rethrowAsRuntimeException(); 15294 } catch (NullPointerException ex) { 15295 Rlog.e(TAG, "getCallWaitingStatus NPE", ex); 15296 throw ex; 15297 } 15298 } 15299 15300 /** 15301 * Sets the call waiting status of this device with the network. 15302 * 15303 * If you wish to be notified about the results of this operation, provide an {@link Executor} 15304 * and {@link Consumer<Integer>} to be notified asynchronously when the operation completes. 15305 * 15306 * @see #getCallWaitingStatus for a description of the call waiting functionality. 15307 * 15308 * @param enabled {@code true} to enable; {@code false} to disable. 15309 * @param executor The executor on which the listener will be called. Must be non-null if 15310 * {@code listener} is non-null. 15311 * @param resultListener Asynchronous listener that'll be called when the operation completes. 15312 * Called with the new call waiting status (either 15313 * {@link #CALL_WAITING_STATUS_ENABLED} or 15314 * {@link #CALL_WAITING_STATUS_DISABLED} if the operation succeeded and 15315 * {@link #CALL_WAITING_STATUS_NOT_SUPPORTED} or 15316 * {@link #CALL_WAITING_STATUS_UNKNOWN_ERROR} or 15317 * {@link #CALL_WAITING_STATUS_FDN_CHECK_FAILURE} if it failed. 15318 * @hide 15319 */ 15320 @SystemApi 15321 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 15322 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_CALLING) setCallWaitingEnabled(boolean enabled, @Nullable Executor executor, @Nullable Consumer<Integer> resultListener)15323 public void setCallWaitingEnabled(boolean enabled, @Nullable Executor executor, 15324 @Nullable Consumer<Integer> resultListener) { 15325 if (resultListener != null) { 15326 Objects.requireNonNull(executor); 15327 } 15328 15329 IIntegerConsumer internalCallback = new IIntegerConsumer.Stub() { 15330 @Override 15331 public void accept(int result) { 15332 executor.execute(() -> 15333 Binder.withCleanCallingIdentity(() -> resultListener.accept(result))); 15334 } 15335 }; 15336 15337 try { 15338 ITelephony telephony = getITelephony(); 15339 if (telephony != null) { 15340 telephony.setCallWaitingStatus(getSubId(), enabled, internalCallback); 15341 } 15342 } catch (RemoteException ex) { 15343 Rlog.e(TAG, "setCallWaitingStatus RemoteException", ex); 15344 ex.rethrowAsRuntimeException(); 15345 } catch (NullPointerException ex) { 15346 Rlog.e(TAG, "setCallWaitingStatus NPE", ex); 15347 throw ex; 15348 } 15349 } 15350 15351 /** 15352 * Controls whether mobile data on the non-default SIM is allowed during a voice call. 15353 * 15354 * This is used for allowing data on the non-default data SIM when a voice call is placed on 15355 * the non-default data SIM on DSDS devices. If this policy is disabled, users will not be able 15356 * to use mobile data via the non-default data SIM during the call, which may mean no mobile 15357 * data at all since some modem implementations disallow mobile data via the default data SIM 15358 * during voice calls. 15359 * If this policy is enabled, data will be temporarily enabled on the non-default data SIM 15360 * during any voice calls. 15361 * 15362 * This policy can be enabled and disabled via {@link #setMobileDataPolicyEnabled}. 15363 * @hide 15364 */ 15365 @SystemApi 15366 public static final int MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL = 1; 15367 15368 /** 15369 * Controls whether MMS messages bypass the user-specified "mobile data" toggle. 15370 * 15371 * When enabled, requests for connections to the MMS APN will be accepted by telephony even if 15372 * the user has turned "mobile data" off on this specific sim card. {@link #isDataEnabledForApn} 15373 * will also return true for {@link ApnSetting#TYPE_MMS}. 15374 * When disabled, the MMS APN will be governed by the same rules as all other APNs. 15375 * 15376 * This policy can be enabled and disabled via {@link #setMobileDataPolicyEnabled}. 15377 * @hide 15378 */ 15379 @SystemApi 15380 public static final int MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED = 2; 15381 15382 /** 15383 * Allow switching mobile data to the non-default SIM if the non-default SIM has better 15384 * availability. 15385 * 15386 * This is used for temporarily allowing data on the non-default data SIM when on-default SIM 15387 * has better availability on DSDS devices, where better availability means strong 15388 * signal/connectivity. 15389 * If this policy is enabled, data will be temporarily enabled on the non-default data SIM, 15390 * including during any voice calls(equivalent to enabling 15391 * {@link #MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL}). 15392 * 15393 * This policy can be enabled and disabled via {@link #setMobileDataPolicyEnabled}. 15394 * @hide 15395 */ 15396 public static final int MOBILE_DATA_POLICY_AUTO_DATA_SWITCH = 3; 15397 15398 /** 15399 * @hide 15400 */ 15401 @IntDef(prefix = { "MOBILE_DATA_POLICY_" }, value = { 15402 MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL, 15403 MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED, 15404 MOBILE_DATA_POLICY_AUTO_DATA_SWITCH, 15405 }) 15406 @Retention(RetentionPolicy.SOURCE) 15407 public @interface MobileDataPolicy { } 15408 15409 /** 15410 * Enables or disables a piece of mobile data policy. 15411 * 15412 * Enables or disables the mobile data policy specified in {@code policy}. See the detailed 15413 * description of each policy constant for what they do. 15414 * 15415 * @param policy The data policy to enable. 15416 * @param enabled Whether to enable or disable the policy. 15417 * @hide 15418 */ 15419 @SystemApi 15420 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 15421 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) setMobileDataPolicyEnabled(@obileDataPolicy int policy, boolean enabled)15422 public void setMobileDataPolicyEnabled(@MobileDataPolicy int policy, boolean enabled) { 15423 try { 15424 ITelephony service = getITelephony(); 15425 if (service != null) { 15426 service.setMobileDataPolicyEnabled(getSubId(), policy, enabled); 15427 } 15428 } catch (RemoteException ex) { 15429 Rlog.e(TAG, "Telephony#setMobileDataPolicyEnabled RemoteException" + ex); 15430 } 15431 } 15432 15433 /** 15434 * Fetches the status of a piece of mobile data policy. 15435 * 15436 * @param policy The data policy that you want the status for. 15437 * @return {@code true} if enabled, {@code false} otherwise. 15438 * @hide 15439 */ 15440 @SystemApi 15441 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 15442 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_DATA) isMobileDataPolicyEnabled(@obileDataPolicy int policy)15443 public boolean isMobileDataPolicyEnabled(@MobileDataPolicy int policy) { 15444 try { 15445 ITelephony service = getITelephony(); 15446 if (service != null) { 15447 return service.isMobileDataPolicyEnabled(getSubId(), policy); 15448 } 15449 } catch (RemoteException ex) { 15450 Rlog.e(TAG, "Telephony#isMobileDataPolicyEnabled RemoteException" + ex); 15451 } 15452 return false; 15453 } 15454 15455 /** 15456 * Indicates that the ICC PIN lock state or PIN was changed successfully. 15457 * @hide 15458 */ 15459 public static final int CHANGE_ICC_LOCK_SUCCESS = Integer.MAX_VALUE; 15460 15461 /** 15462 * Check whether ICC PIN lock is enabled. 15463 * This is a sync call which returns the cached PIN enabled state. 15464 * 15465 * @return {@code true} if ICC PIN lock enabled, {@code false} if disabled. 15466 * @throws SecurityException if the caller doesn't have the permission. 15467 * @throws IllegalStateException if the Telephony process is not currently available. 15468 * 15469 * <p>Requires Permission: 15470 * {@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE READ_PRIVILEGED_PHONE_STATE} 15471 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 15472 * 15473 * @hide 15474 */ 15475 @WorkerThread 15476 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 15477 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) 15478 @SystemApi isIccLockEnabled()15479 public boolean isIccLockEnabled() { 15480 try { 15481 ITelephony telephony = getITelephony(); 15482 if (telephony != null) { 15483 return telephony.isIccLockEnabled(getSubId()); 15484 } else { 15485 throw new IllegalStateException("telephony service is null."); 15486 } 15487 } catch (RemoteException e) { 15488 Log.e(TAG, "isIccLockEnabled RemoteException", e); 15489 e.rethrowFromSystemServer(); 15490 } 15491 return false; 15492 } 15493 15494 /** 15495 * Enable or disable the ICC PIN lock. 15496 * 15497 * @param enabled "true" for locked, "false" for unlocked. 15498 * @param pin needed to change the ICC PIN lock, aka. Pin1. 15499 * @return the result of enabling or disabling the ICC PIN lock. 15500 * @throws SecurityException if the caller doesn't have the permission. 15501 * @throws IllegalStateException if the Telephony process is not currently available. 15502 * 15503 * <p>Requires Permission: 15504 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 15505 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 15506 * 15507 * @hide 15508 */ 15509 @SystemApi 15510 @NonNull 15511 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 15512 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) setIccLockEnabled(boolean enabled, @NonNull String pin)15513 public PinResult setIccLockEnabled(boolean enabled, @NonNull String pin) { 15514 checkNotNull(pin, "setIccLockEnabled pin can't be null."); 15515 try { 15516 ITelephony telephony = getITelephony(); 15517 if (telephony != null) { 15518 int result = telephony.setIccLockEnabled(getSubId(), enabled, pin); 15519 if (result == CHANGE_ICC_LOCK_SUCCESS) { 15520 return new PinResult(PinResult.PIN_RESULT_TYPE_SUCCESS, 0); 15521 } else if (result < 0) { 15522 return PinResult.getDefaultFailedResult(); 15523 } else { 15524 return new PinResult(PinResult.PIN_RESULT_TYPE_INCORRECT, result); 15525 } 15526 } else { 15527 throw new IllegalStateException("telephony service is null."); 15528 } 15529 } catch (RemoteException e) { 15530 Log.e(TAG, "setIccLockEnabled RemoteException", e); 15531 e.rethrowFromSystemServer(); 15532 } 15533 return PinResult.getDefaultFailedResult(); 15534 } 15535 15536 /** 15537 * Change the ICC lock PIN. 15538 * 15539 * @param oldPin is the old PIN 15540 * @param newPin is the new PIN 15541 * @return The result of changing the ICC lock PIN. 15542 * @throws SecurityException if the caller doesn't have the permission. 15543 * @throws IllegalStateException if the Telephony process is not currently available. 15544 * 15545 * <p>Requires Permission: 15546 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} or that the calling 15547 * app has carrier privileges (see {@link #hasCarrierPrivileges}). 15548 * 15549 * @hide 15550 */ 15551 @SystemApi 15552 @NonNull 15553 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 15554 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) changeIccLockPin(@onNull String oldPin, @NonNull String newPin)15555 public PinResult changeIccLockPin(@NonNull String oldPin, @NonNull String newPin) { 15556 checkNotNull(oldPin, "changeIccLockPin oldPin can't be null."); 15557 checkNotNull(newPin, "changeIccLockPin newPin can't be null."); 15558 try { 15559 ITelephony telephony = getITelephony(); 15560 if (telephony != null) { 15561 int result = telephony.changeIccLockPassword(getSubId(), oldPin, newPin); 15562 if (result == CHANGE_ICC_LOCK_SUCCESS) { 15563 return new PinResult(PinResult.PIN_RESULT_TYPE_SUCCESS, 0); 15564 } else if (result < 0) { 15565 return PinResult.getDefaultFailedResult(); 15566 } else { 15567 return new PinResult(PinResult.PIN_RESULT_TYPE_INCORRECT, result); 15568 } 15569 } else { 15570 throw new IllegalStateException("telephony service is null."); 15571 } 15572 } catch (RemoteException e) { 15573 Log.e(TAG, "changeIccLockPin RemoteException", e); 15574 e.rethrowFromSystemServer(); 15575 } 15576 return PinResult.getDefaultFailedResult(); 15577 } 15578 15579 /** 15580 * Called when userActivity is signalled in the power manager. 15581 * This should only be called from system Uid. 15582 * @hide 15583 */ 15584 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) notifyUserActivity()15585 public void notifyUserActivity() { 15586 try { 15587 ITelephony service = getITelephony(); 15588 if (service != null) { 15589 service.userActivity(); 15590 } 15591 } catch (RemoteException e) { 15592 // one-way notification, if telephony is not available, it is okay to not throw 15593 // exception here. 15594 Log.w(TAG, "notifyUserActivity exception: " + e.getMessage()); 15595 } 15596 } 15597 15598 /** 15599 * No error. Operation succeeded. 15600 * @hide 15601 */ 15602 @SystemApi 15603 public static final int ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS = 0; 15604 15605 /** 15606 * NR Dual connectivity enablement is not supported. 15607 * @hide 15608 */ 15609 @SystemApi 15610 public static final int ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED = 1; 15611 15612 /** 15613 * Radio is not available. 15614 * @hide 15615 */ 15616 @SystemApi 15617 public static final int ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE = 2; 15618 15619 /** 15620 * Internal Radio error. 15621 * @hide 15622 */ 15623 @SystemApi 15624 public static final int ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR = 3; 15625 15626 /** 15627 * Currently in invalid state. Not able to process the request. 15628 * @hide 15629 */ 15630 @SystemApi 15631 public static final int ENABLE_NR_DUAL_CONNECTIVITY_INVALID_STATE = 4; 15632 15633 /** @hide */ 15634 @Retention(RetentionPolicy.SOURCE) 15635 @IntDef(prefix = {"ENABLE_NR_DUAL_CONNECTIVITY"}, value = { 15636 ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS, 15637 ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED, 15638 ENABLE_NR_DUAL_CONNECTIVITY_INVALID_STATE, 15639 ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE, 15640 ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR}) 15641 public @interface EnableNrDualConnectivityResult {} 15642 15643 /** 15644 * Enable NR dual connectivity. Enabled state does not mean dual connectivity 15645 * is active. It means device is allowed to connect to both primary and secondary. 15646 * 15647 * @hide 15648 */ 15649 @SystemApi 15650 public static final int NR_DUAL_CONNECTIVITY_ENABLE = 1; 15651 15652 /** 15653 * Disable NR dual connectivity. Disabled state does not mean the secondary cell is released. 15654 * Modem will release it only if the current bearer is released to avoid radio link failure. 15655 * @hide 15656 */ 15657 @SystemApi 15658 public static final int NR_DUAL_CONNECTIVITY_DISABLE = 2; 15659 15660 /** 15661 * Disable NR dual connectivity and force the secondary cell to be released if dual connectivity 15662 * was active. This will result in radio link failure. 15663 * @hide 15664 */ 15665 @SystemApi 15666 public static final int NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE = 3; 15667 15668 /** 15669 * @hide 15670 */ 15671 @IntDef(prefix = { "NR_DUAL_CONNECTIVITY_" }, value = { 15672 NR_DUAL_CONNECTIVITY_ENABLE, 15673 NR_DUAL_CONNECTIVITY_DISABLE, 15674 NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE, 15675 }) 15676 @Retention(RetentionPolicy.SOURCE) 15677 public @interface NrDualConnectivityState { 15678 } 15679 15680 /** 15681 * Enable/Disable E-UTRA-NR Dual Connectivity. 15682 * 15683 * This api is supported only if 15684 * {@link android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported} 15685 * ({@link TelephonyManager#CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE}) 15686 * returns true. 15687 * @param nrDualConnectivityState expected NR dual connectivity state 15688 * This can be passed following states 15689 * <ol> 15690 * <li>Enable NR dual connectivity {@link #NR_DUAL_CONNECTIVITY_ENABLE} 15691 * <li>Disable NR dual connectivity {@link #NR_DUAL_CONNECTIVITY_DISABLE} 15692 * <li>Disable NR dual connectivity and force secondary cell to be released 15693 * {@link #NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} 15694 * </ol> 15695 * @return operation result. 15696 * @throws IllegalStateException if the Telephony process is not currently available. 15697 * @hide 15698 */ 15699 @SystemApi 15700 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 15701 @RequiresFeature( 15702 enforcement = "android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported", 15703 value = TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE) setNrDualConnectivityState( @rDualConnectivityState int nrDualConnectivityState)15704 public @EnableNrDualConnectivityResult int setNrDualConnectivityState( 15705 @NrDualConnectivityState int nrDualConnectivityState) { 15706 try { 15707 ITelephony telephony = getITelephony(); 15708 if (telephony != null) { 15709 return telephony.setNrDualConnectivityState(getSubId(), nrDualConnectivityState); 15710 } else { 15711 throw new IllegalStateException("telephony service is null."); 15712 } 15713 } catch (RemoteException ex) { 15714 Rlog.e(TAG, "setNrDualConnectivityState RemoteException", ex); 15715 ex.rethrowFromSystemServer(); 15716 } 15717 15718 return ENABLE_NR_DUAL_CONNECTIVITY_INVALID_STATE; 15719 } 15720 15721 /** 15722 * Is E-UTRA-NR Dual Connectivity enabled. 15723 * This api is supported only if 15724 * {@link android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported} 15725 * ({@link TelephonyManager#CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE}) 15726 * returns true. 15727 * @return true if dual connectivity is enabled else false. Enabled state does not mean dual 15728 * connectivity is active. It means the device is allowed to connect to both primary and 15729 * secondary cell. 15730 * @throws IllegalStateException if the Telephony process is not currently available. 15731 * @hide 15732 */ 15733 @SystemApi 15734 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 15735 @RequiresFeature( 15736 enforcement = "android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported", 15737 value = TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE) isNrDualConnectivityEnabled()15738 public boolean isNrDualConnectivityEnabled() { 15739 try { 15740 ITelephony telephony = getITelephony(); 15741 if (telephony != null) { 15742 return telephony.isNrDualConnectivityEnabled(getSubId()); 15743 } else { 15744 throw new IllegalStateException("telephony service is null."); 15745 } 15746 } catch (RemoteException ex) { 15747 Rlog.e(TAG, "isNRDualConnectivityEnabled RemoteException", ex); 15748 ex.rethrowFromSystemServer(); 15749 } 15750 return false; 15751 } 15752 15753 private static class DeathRecipient implements IBinder.DeathRecipient { 15754 @Override binderDied()15755 public void binderDied() { 15756 resetServiceCache(); 15757 } 15758 } 15759 15760 /** 15761 * Reset everything in the service cache; if one handle died then they are 15762 * all probably broken. 15763 * @hide 15764 */ resetServiceCache()15765 private static void resetServiceCache() { 15766 synchronized (sCacheLock) { 15767 if (sITelephony != null) { 15768 sITelephony.asBinder().unlinkToDeath(sServiceDeath, 0); 15769 sITelephony = null; 15770 } 15771 if (sISub != null) { 15772 sISub.asBinder().unlinkToDeath(sServiceDeath, 0); 15773 sISub = null; 15774 SubscriptionManager.clearCaches(); 15775 } 15776 if (sISms != null) { 15777 sISms.asBinder().unlinkToDeath(sServiceDeath, 0); 15778 sISms = null; 15779 } 15780 if (sIPhoneSubInfo != null) { 15781 sIPhoneSubInfo.asBinder().unlinkToDeath(sServiceDeath, 0); 15782 sIPhoneSubInfo = null; 15783 } 15784 } 15785 } 15786 15787 /** 15788 * @hide 15789 */ getSubscriberInfoService()15790 static IPhoneSubInfo getSubscriberInfoService() { 15791 // Keeps cache disabled until test fixes are checked into AOSP. 15792 if (!sServiceHandleCacheEnabled) { 15793 return IPhoneSubInfo.Stub.asInterface( 15794 TelephonyFrameworkInitializer 15795 .getTelephonyServiceManager() 15796 .getPhoneSubServiceRegisterer() 15797 .get()); 15798 } 15799 15800 if (sIPhoneSubInfo == null) { 15801 IPhoneSubInfo temp = IPhoneSubInfo.Stub.asInterface( 15802 TelephonyFrameworkInitializer 15803 .getTelephonyServiceManager() 15804 .getPhoneSubServiceRegisterer() 15805 .get()); 15806 synchronized (sCacheLock) { 15807 if (sIPhoneSubInfo == null && temp != null) { 15808 try { 15809 sIPhoneSubInfo = temp; 15810 sIPhoneSubInfo.asBinder().linkToDeath(sServiceDeath, 0); 15811 } catch (Exception e) { 15812 // something has gone horribly wrong 15813 sIPhoneSubInfo = null; 15814 } 15815 } 15816 } 15817 } 15818 return sIPhoneSubInfo; 15819 } 15820 15821 /** 15822 * @hide 15823 */ getSubscriptionService()15824 static ISub getSubscriptionService() { 15825 // Keeps cache disabled until test fixes are checked into AOSP. 15826 if (!sServiceHandleCacheEnabled) { 15827 return ISub.Stub.asInterface( 15828 TelephonyFrameworkInitializer 15829 .getTelephonyServiceManager() 15830 .getSubscriptionServiceRegisterer() 15831 .get()); 15832 } 15833 15834 if (sISub == null) { 15835 ISub temp = ISub.Stub.asInterface( 15836 TelephonyFrameworkInitializer 15837 .getTelephonyServiceManager() 15838 .getSubscriptionServiceRegisterer() 15839 .get()); 15840 synchronized (sCacheLock) { 15841 if (sISub == null && temp != null) { 15842 try { 15843 sISub = temp; 15844 sISub.asBinder().linkToDeath(sServiceDeath, 0); 15845 } catch (Exception e) { 15846 // something has gone horribly wrong 15847 sISub = null; 15848 } 15849 } 15850 } 15851 } 15852 return sISub; 15853 } 15854 15855 /** 15856 * @hide 15857 */ getSmsService()15858 static ISms getSmsService() { 15859 // Keeps cache disabled until test fixes are checked into AOSP. 15860 if (!sServiceHandleCacheEnabled) { 15861 return ISms.Stub.asInterface( 15862 TelephonyFrameworkInitializer 15863 .getTelephonyServiceManager() 15864 .getSmsServiceRegisterer() 15865 .get()); 15866 } 15867 15868 if (sISms == null) { 15869 ISms temp = ISms.Stub.asInterface( 15870 TelephonyFrameworkInitializer 15871 .getTelephonyServiceManager() 15872 .getSmsServiceRegisterer() 15873 .get()); 15874 synchronized (sCacheLock) { 15875 if (sISms == null && temp != null) { 15876 try { 15877 sISms = temp; 15878 sISms.asBinder().linkToDeath(sServiceDeath, 0); 15879 } catch (Exception e) { 15880 // something has gone horribly wrong 15881 sISms = null; 15882 } 15883 } 15884 } 15885 } 15886 return sISms; 15887 } 15888 15889 /** 15890 * Disables service handle caching for tests that utilize mock services. 15891 * @hide 15892 */ 15893 @VisibleForTesting disableServiceHandleCaching()15894 public static void disableServiceHandleCaching() { 15895 sServiceHandleCacheEnabled = false; 15896 } 15897 15898 /** 15899 * Reenables service handle caching. 15900 * @hide 15901 */ 15902 @VisibleForTesting enableServiceHandleCaching()15903 public static void enableServiceHandleCaching() { 15904 sServiceHandleCacheEnabled = true; 15905 } 15906 15907 /** 15908 * Setup sITelephony for testing. 15909 * @hide 15910 */ 15911 @VisibleForTesting setupITelephonyForTest(ITelephony telephony)15912 public static void setupITelephonyForTest(ITelephony telephony) { 15913 sITelephony = telephony; 15914 } 15915 15916 /** 15917 * Whether device can connect to 5G network when two SIMs are active. 15918 * @hide 15919 * TODO b/153669716: remove or make system API. 15920 */ canConnectTo5GInDsdsMode()15921 public boolean canConnectTo5GInDsdsMode() { 15922 ITelephony telephony = getITelephony(); 15923 if (telephony == null) return true; 15924 try { 15925 return telephony.canConnectTo5GInDsdsMode(); 15926 } catch (RemoteException ex) { 15927 return true; 15928 } catch (NullPointerException ex) { 15929 return true; 15930 } 15931 } 15932 15933 /** 15934 * Returns a list of the equivalent home PLMNs (EF_EHPLMN) from the USIM app. 15935 * 15936 * <p>Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} 15937 * or that the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 15938 * 15939 * @return A list of equivalent home PLMNs. Returns an empty list if EF_EHPLMN is empty or 15940 * does not exist on the SIM card. 15941 * 15942 * @throws IllegalStateException if the Telephony process is not currently available. 15943 * @throws SecurityException if the caller doesn't have the permission. 15944 * 15945 */ 15946 @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) 15947 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) getEquivalentHomePlmns()15948 public @NonNull List<String> getEquivalentHomePlmns() { 15949 try { 15950 ITelephony telephony = getITelephony(); 15951 if (telephony != null) { 15952 return telephony.getEquivalentHomePlmns(getSubId(), mContext.getOpPackageName(), 15953 getAttributionTag()); 15954 } else { 15955 throw new IllegalStateException("telephony service is null."); 15956 } 15957 } catch (RemoteException ex) { 15958 Rlog.e(TAG, "Telephony#getEquivalentHomePlmns RemoteException" + ex); 15959 } 15960 15961 return Collections.emptyList(); 15962 } 15963 15964 /** 15965 * Indicates whether {@link CarrierBandwidth#getSecondaryDownlinkCapacityKbps()} and 15966 * {@link CarrierBandwidth#getSecondaryUplinkCapacityKbps()} are visible. See comments 15967 * on respective methods for more information. 15968 * 15969 * @hide 15970 */ 15971 @SystemApi 15972 public static final String CAPABILITY_SECONDARY_LINK_BANDWIDTH_VISIBLE = 15973 "CAPABILITY_SECONDARY_LINK_BANDWIDTH_VISIBLE"; 15974 15975 /** 15976 * Indicates whether {@link #setPreferredNetworkType}, {@link 15977 * #setPreferredNetworkTypeBitmask}, {@link #setAllowedNetworkTypes} and 15978 * {@link #setAllowedNetworkTypesForReason} rely on 15979 * setAllowedNetworkTypesBitmap instead of setPreferredNetworkTypesBitmap on the radio 15980 * interface. 15981 * 15982 * @hide 15983 */ 15984 @SystemApi 15985 public static final String CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK = 15986 "CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK"; 15987 15988 /** 15989 * Indicates whether {@link #setNrDualConnectivityState()} and 15990 * {@link #isNrDualConnectivityEnabled()} ()} are available. See comments 15991 * on respective methods for more information. 15992 * 15993 * @hide 15994 */ 15995 @SystemApi 15996 public static final String CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE = 15997 "CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE"; 15998 15999 /** 16000 * Indicates whether a data throttling request sent with {@link #sendThermalMitigationRequest} 16001 * is supported. See comments on {@link #sendThermalMitigationRequest} for more information. 16002 * 16003 * @hide 16004 */ 16005 @SystemApi 16006 public static final String CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING = 16007 "CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING"; 16008 16009 /** 16010 * Indicates whether {@link #getNetworkSlicingConfiguration} is supported. See comments on 16011 * respective methods for more information. 16012 */ 16013 public static final String CAPABILITY_SLICING_CONFIG_SUPPORTED = 16014 "CAPABILITY_SLICING_CONFIG_SUPPORTED"; 16015 16016 /** 16017 * Indicates whether PHYSICAL_CHANNEL_CONFIG HAL1.6 is supported. See comments on 16018 * respective methods for more information. 16019 * 16020 * @hide 16021 */ 16022 public static final String CAPABILITY_PHYSICAL_CHANNEL_CONFIG_1_6_SUPPORTED = 16023 "CAPABILITY_PHYSICAL_CHANNEL_CONFIG_1_6_SUPPORTED"; 16024 16025 /** 16026 * Indicates whether modem supports handling parsed SIM phonebook records through the RIL, 16027 * both batched reads and individual writes. 16028 * 16029 * @hide 16030 */ 16031 public static final String CAPABILITY_SIM_PHONEBOOK_IN_MODEM = 16032 "CAPABILITY_SIM_PHONEBOOK_IN_MODEM"; 16033 16034 /** 16035 * A list of the radio interface capability values with public valid constants. 16036 * 16037 * Here is a related list for the systemapi-only valid constants: 16038 * CAPABILITY_SECONDARY_LINK_BANDWIDTH_VISIBLE 16039 * CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK 16040 * CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE 16041 * CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING 16042 * 16043 * @hide 16044 * TODO(b/185508047): Doc generation for mixed public/systemapi StringDefs formats badly. 16045 */ 16046 @Retention(RetentionPolicy.SOURCE) 16047 @StringDef(prefix = "CAPABILITY_", value = { 16048 CAPABILITY_SLICING_CONFIG_SUPPORTED, 16049 CAPABILITY_SIM_PHONEBOOK_IN_MODEM, 16050 }) 16051 public @interface RadioInterfaceCapability {} 16052 16053 /** 16054 * Whether the device supports a given capability on the radio interface. 16055 * 16056 * If the capability is not in the set of radio interface capabilities, false is returned. 16057 * 16058 * @param capability the name of the capability to check for 16059 * @return the availability of the capability 16060 */ 16061 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) isRadioInterfaceCapabilitySupported( @onNull @adioInterfaceCapability String capability)16062 public boolean isRadioInterfaceCapabilitySupported( 16063 @NonNull @RadioInterfaceCapability String capability) { 16064 try { 16065 if (capability == null) return false; 16066 16067 ITelephony telephony = getITelephony(); 16068 if (telephony != null) { 16069 return telephony.isRadioInterfaceCapabilitySupported(capability); 16070 } else { 16071 throw new IllegalStateException("telephony service is null."); 16072 } 16073 } catch (RemoteException ex) { 16074 Rlog.e(TAG, "Telephony#isRadioInterfaceCapabilitySupported RemoteException" + ex); 16075 } 16076 return false; 16077 } 16078 16079 /** 16080 * Indicates that the thermal mitigation request was completed successfully. 16081 * 16082 * @hide 16083 */ 16084 @SystemApi 16085 public static final int THERMAL_MITIGATION_RESULT_SUCCESS = 0; 16086 16087 /** 16088 * Indicates that the thermal mitigation request was not completed because of a modem error. 16089 * 16090 * @hide 16091 */ 16092 @SystemApi 16093 public static final int THERMAL_MITIGATION_RESULT_MODEM_ERROR = 1; 16094 16095 /** 16096 * Indicates that the thermal mitigation request was not completed because the modem is not 16097 * available. 16098 * 16099 * @hide 16100 */ 16101 @SystemApi 16102 public static final int THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE = 2; 16103 16104 /** 16105 * Indicates that the thermal mitigation request could not power off the radio due to the device 16106 * either being in an active emergency voice call, device pending an emergency call, or any 16107 * other state that would disallow powering off of radio. 16108 * 16109 * @hide 16110 */ 16111 @SystemApi 16112 public static final int THERMAL_MITIGATION_RESULT_INVALID_STATE = 3; 16113 16114 /** 16115 * Indicates that the thermal mitigation request resulted an unknown error. 16116 * 16117 * @hide 16118 */ 16119 @SystemApi 16120 public static final int THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR = 4; 16121 16122 /** 16123 * Thermal mitigation request to control functionalities at modem. Thermal mitigation is done 16124 * per-subscription. Caller must be sure to bind the TelephonyManager instance to subId by 16125 * calling {@link #createForSubscriptionId(int)} if they want thermal mitigation on a specific 16126 * subscription Id. Otherwise, TelephonyManager will use the default subscription. 16127 * 16128 * Calling this does not guarantee that the thermal mitigation action requested was done to 16129 * completion. A thermal module should actively monitor the temperature levels and request an 16130 * appropriate thermal mitigation action. Every action is assumed to be done 'on top of' the 16131 * previous action, where the order of actions from least thermal mitigation to most is as 16132 * follows: 16133 * <ol> 16134 * <li>{@link ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_DATA_THROTTLING}</li> 16135 * <ol> 16136 * <li>{@link DataThrottlingRequest#DATA_THROTTLING_ACTION_NO_DATA_THROTTLING}</li> 16137 * <li>{@link DataThrottlingRequest#DATA_THROTTLING_ACTION_THROTTLE_SECONDARY_CARRIER}</li> 16138 * <li>{@link DataThrottlingRequest#DATA_THROTTLING_ACTION_THROTTLE_PRIMARY_CARRIER}</li> 16139 * </ol> 16140 * <li>{@link ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_VOICE_ONLY}</li> 16141 * <li>{@link ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_RADIO_OFF}</li> 16142 * </ol> 16143 * 16144 * So, for example, requesting {@link 16145 * DataThrottlingRequest#DATA_THROTTLING_ACTION_THROTTLE_PRIMARY_CARRIER} will ensure that the 16146 * data on secondary carrier has been disabled before throttling on primary carrier. {@link 16147 * ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_VOICE_ONLY} will ensure that data on both 16148 * primary and secondary have been disabled. {@link 16149 * ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_RADIO_OFF} will ensure that voice is 16150 * disabled and that data on both primary and secondary carriers are disabled before turning 16151 * radio off. {@link DataThrottlingRequest#DATA_THROTTLING_ACTION_HOLD} is not part of the order 16152 * and can be used at any time during data throttling to hold onto the current level of data 16153 * throttling. 16154 * 16155 * <p> If {@link android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported}({@link 16156 * #CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING}) returns false, then sending a {@link 16157 * DataThrottlingRequest#DATA_THROTTLING_ACTION_HOLD}, {@link 16158 * DataThrottlingRequest#DATA_THROTTLING_ACTION_THROTTLE_SECONDARY_CARRIER}, or {@link 16159 * DataThrottlingRequest#DATA_THROTTLING_ACTION_THROTTLE_PRIMARY_CARRIER} will result in {@link 16160 * IllegalArgumentException} being thrown. However, on devices that do not 16161 * support data throttling, {@link 16162 * DataThrottlingRequest#DATA_THROTTLING_ACTION_NO_DATA_THROTTLING} can still be requested in 16163 * order to undo the mitigations above it (i.e {@link 16164 * ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_VOICE_ONLY} and/or {@link 16165 * ThermalMitigationRequest#THERMAL_MITIGATION_ACTION_RADIO_OFF}). </p> 16166 * 16167 * <p> In addition to the {@link Manifest.permission#MODIFY_PHONE_STATE} permission, callers of 16168 * this API must also be listed in the device configuration as an authorized app in 16169 * {@code packages/services/Telephony/res/values/config.xml} under the 16170 * {@code thermal_mitigation_allowlisted_packages} key. </p> 16171 * 16172 * @param thermalMitigationRequest Thermal mitigation request. See {@link 16173 * ThermalMitigationRequest} for details. 16174 * 16175 * @throws IllegalStateException if the Telephony process is not currently available. 16176 * @throws IllegalArgumentException if the thermalMitigationRequest had invalid parameters or 16177 * if the device's modem does not support data throttling. 16178 * 16179 * @hide 16180 */ 16181 @SystemApi 16182 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 16183 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) 16184 @ThermalMitigationResult sendThermalMitigationRequest( @onNull ThermalMitigationRequest thermalMitigationRequest)16185 public int sendThermalMitigationRequest( 16186 @NonNull ThermalMitigationRequest thermalMitigationRequest) { 16187 try { 16188 ITelephony telephony = getITelephony(); 16189 if (telephony != null) { 16190 return telephony.sendThermalMitigationRequest(getSubId(), thermalMitigationRequest, 16191 getOpPackageName()); 16192 } 16193 throw new IllegalStateException("telephony service is null."); 16194 } catch (RemoteException ex) { 16195 Log.e(TAG, "Telephony#thermalMitigationRequest RemoteException", ex); 16196 ex.rethrowFromSystemServer(); 16197 } 16198 return THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; 16199 } 16200 16201 /** 16202 * Registers a callback object to receive notification of changes in specified telephony states. 16203 * <p> 16204 * To register a callback, pass a {@link TelephonyCallback} which implements 16205 * interfaces of events. For example, 16206 * FakeServiceStateCallback extends {@link TelephonyCallback} implements 16207 * {@link TelephonyCallback.ServiceStateListener}. 16208 * 16209 * At registration, and when a specified telephony state changes, the telephony manager invokes 16210 * the appropriate callback method on the callback object and passes the current (updated) 16211 * values. 16212 * <p> 16213 * 16214 * If this TelephonyManager object has been created with {@link #createForSubscriptionId}, 16215 * applies to the given subId. Otherwise, applies to 16216 * {@link SubscriptionManager#getDefaultSubscriptionId()}. To register events for multiple 16217 * subIds, pass a separate callback object to each TelephonyManager object created with 16218 * {@link #createForSubscriptionId}. 16219 * 16220 * Note: if you call this method while in the middle of a binder transaction, you <b>must</b> 16221 * call {@link android.os.Binder#clearCallingIdentity()} before calling this method. A 16222 * {@link SecurityException} will be thrown otherwise. 16223 * 16224 * This API should be used sparingly -- large numbers of callbacks will cause system 16225 * instability. If a process has registered too many callbacks without unregistering them, it 16226 * may encounter an {@link IllegalStateException} when trying to register more callbacks. 16227 * 16228 * @param executor The executor of where the callback will execute. 16229 * @param callback The {@link TelephonyCallback} object to register. 16230 */ registerTelephonyCallback(@onNull @allbackExecutor Executor executor, @NonNull TelephonyCallback callback)16231 public void registerTelephonyCallback(@NonNull @CallbackExecutor Executor executor, 16232 @NonNull TelephonyCallback callback) { 16233 registerTelephonyCallback(getLocationData(), executor, callback); 16234 } 16235 getLocationData()16236 private int getLocationData() { 16237 boolean renounceCoarseLocation = 16238 getRenouncedPermissions().contains(Manifest.permission.ACCESS_COARSE_LOCATION); 16239 boolean renounceFineLocation = 16240 getRenouncedPermissions().contains(Manifest.permission.ACCESS_FINE_LOCATION); 16241 if (renounceCoarseLocation) { 16242 return INCLUDE_LOCATION_DATA_NONE; 16243 } else if (renounceFineLocation) { 16244 return INCLUDE_LOCATION_DATA_COARSE; 16245 } else { 16246 return INCLUDE_LOCATION_DATA_FINE; 16247 } 16248 } 16249 16250 /** @hide */ 16251 @Retention(RetentionPolicy.SOURCE) 16252 @IntDef(prefix = {"INCLUDE_LOCATION_DATA_"}, value = { 16253 INCLUDE_LOCATION_DATA_NONE, 16254 INCLUDE_LOCATION_DATA_COARSE, 16255 INCLUDE_LOCATION_DATA_FINE}) 16256 public @interface IncludeLocationData {} 16257 16258 /** 16259 * Specifies to not include any location related data. 16260 * 16261 * Indicates whether the caller would not like to receive 16262 * location related information which will be sent if the caller already possess 16263 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} and do not renounce the 16264 * permissions. 16265 */ 16266 public static final int INCLUDE_LOCATION_DATA_NONE = 0; 16267 16268 /** 16269 * Include coarse location data. 16270 * 16271 * Indicates whether the caller would not like to receive 16272 * location related information which will be sent if the caller already possess 16273 * {@link android.Manifest.permission#ACCESS_COARSE_LOCATION} and do not renounce the 16274 * permissions. 16275 */ 16276 public static final int INCLUDE_LOCATION_DATA_COARSE = 1; 16277 16278 /** 16279 * Include fine location data. 16280 * 16281 * Indicates whether the caller would not like to receive 16282 * location related information which will be sent if the caller already possess 16283 * {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and do not renounce the 16284 * permissions. 16285 */ 16286 public static final int INCLUDE_LOCATION_DATA_FINE = 2; 16287 16288 /** 16289 * Registers a callback object to receive notification of changes in specified telephony states. 16290 * <p> 16291 * To register a callback, pass a {@link TelephonyCallback} which implements 16292 * interfaces of events. For example, 16293 * FakeServiceStateCallback extends {@link TelephonyCallback} implements 16294 * {@link TelephonyCallback.ServiceStateListener}. 16295 * 16296 * At registration, and when a specified telephony state changes, the telephony manager invokes 16297 * the appropriate callback method on the callback object and passes the current (updated) 16298 * values. 16299 * <p> 16300 * 16301 * If this TelephonyManager object has been created with {@link #createForSubscriptionId}, 16302 * applies to the given subId. Otherwise, applies to 16303 * {@link SubscriptionManager#getDefaultSubscriptionId()}. To register events for multiple 16304 * subIds, pass a separate callback object to each TelephonyManager object created with 16305 * {@link #createForSubscriptionId}. 16306 * 16307 * Note: if you call this method while in the middle of a binder transaction, you <b>must</b> 16308 * call {@link android.os.Binder#clearCallingIdentity()} before calling this method. A 16309 * {@link SecurityException} will be thrown otherwise. 16310 * 16311 * This API should be used sparingly -- large numbers of callbacks will cause system 16312 * instability. If a process has registered too many callbacks without unregistering them, it 16313 * may encounter an {@link IllegalStateException} when trying to register more callbacks. 16314 * 16315 * <p> 16316 * There's another way to renounce permissions with a custom context 16317 * {@code AttributionSource.Builder#setRenouncedPermissions(Set<String>)} but only for system 16318 * apps. To avoid confusion, calling this method supersede renouncing permissions with a 16319 * custom context. 16320 * 16321 * @param includeLocationData Specifies if the caller would like to receive 16322 * location related information. 16323 * @param executor The executor of where the callback will execute. 16324 * @param callback The {@link TelephonyCallback} object to register. 16325 */ registerTelephonyCallback(@ncludeLocationData int includeLocationData, @NonNull @CallbackExecutor Executor executor, @NonNull TelephonyCallback callback)16326 public void registerTelephonyCallback(@IncludeLocationData int includeLocationData, 16327 @NonNull @CallbackExecutor Executor executor, 16328 @NonNull TelephonyCallback callback) { 16329 if (mContext == null) { 16330 throw new IllegalStateException("telephony service is null."); 16331 } 16332 16333 if (executor == null || callback == null) { 16334 throw new IllegalArgumentException("TelephonyCallback and executor must be non-null"); 16335 } 16336 mTelephonyRegistryMgr = (TelephonyRegistryManager) 16337 mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE); 16338 if (mTelephonyRegistryMgr != null) { 16339 mTelephonyRegistryMgr.registerTelephonyCallback( 16340 includeLocationData != INCLUDE_LOCATION_DATA_FINE, 16341 includeLocationData == INCLUDE_LOCATION_DATA_NONE, 16342 executor, mSubId, getOpPackageName(), 16343 getAttributionTag(), callback, getITelephony() != null); 16344 } else { 16345 throw new IllegalStateException("telephony service is null."); 16346 } 16347 } 16348 16349 /** 16350 * Unregister an existing {@link TelephonyCallback}. 16351 * 16352 * @param callback The {@link TelephonyCallback} object to unregister. 16353 */ unregisterTelephonyCallback(@onNull TelephonyCallback callback)16354 public void unregisterTelephonyCallback(@NonNull TelephonyCallback callback) { 16355 16356 if (mContext == null) { 16357 throw new IllegalStateException("telephony service is null."); 16358 } 16359 16360 if (callback.callback == null) { 16361 return; 16362 } 16363 16364 mTelephonyRegistryMgr = mContext.getSystemService(TelephonyRegistryManager.class); 16365 if (mTelephonyRegistryMgr != null) { 16366 mTelephonyRegistryMgr.unregisterTelephonyCallback(mSubId, getOpPackageName(), 16367 getAttributionTag(), callback, getITelephony() != null); 16368 } else { 16369 throw new IllegalStateException("telephony service is null."); 16370 } 16371 } 16372 16373 /** @hide */ 16374 @Retention(RetentionPolicy.SOURCE) 16375 @IntDef(prefix = {"GBA_FAILURE_REASON_"}, value = { 16376 GBA_FAILURE_REASON_UNKNOWN, 16377 GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED, 16378 GBA_FAILURE_REASON_FEATURE_NOT_READY, 16379 GBA_FAILURE_REASON_NETWORK_FAILURE, 16380 GBA_FAILURE_REASON_INCORRECT_NAF_ID, 16381 GBA_FAILURE_REASON_SECURITY_PROTOCOL_NOT_SUPPORTED}) 16382 public @interface AuthenticationFailureReason {} 16383 16384 /** 16385 * GBA Authentication has failed for an unknown reason. 16386 * 16387 * <p>The caller should retry a message that failed with this response. 16388 * @hide 16389 */ 16390 @SystemApi 16391 public static final int GBA_FAILURE_REASON_UNKNOWN = 0; 16392 16393 /** 16394 * GBA Authentication is not supported by the carrier, SIM or android. 16395 * 16396 * <p>Application should use other authentication mechanisms if possible. 16397 * @hide 16398 */ 16399 @SystemApi 16400 public static final int GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED = 1; 16401 16402 /** 16403 * GBA Authentication service is not ready for use. 16404 * 16405 * <p>Application could try again at a later time. 16406 * @hide 16407 */ 16408 @SystemApi 16409 public static final int GBA_FAILURE_REASON_FEATURE_NOT_READY = 2; 16410 16411 /** 16412 * GBA Authentication has been failed by the network. 16413 * @hide 16414 */ 16415 @SystemApi 16416 public static final int GBA_FAILURE_REASON_NETWORK_FAILURE = 3; 16417 16418 /** 16419 * GBA Authentication has failed due to incorrect NAF URL. 16420 * @hide 16421 */ 16422 @SystemApi 16423 public static final int GBA_FAILURE_REASON_INCORRECT_NAF_ID = 4; 16424 16425 /** 16426 * GBA Authentication has failed due to unsupported security protocol 16427 * @hide 16428 */ 16429 @SystemApi 16430 public static final int GBA_FAILURE_REASON_SECURITY_PROTOCOL_NOT_SUPPORTED = 5; 16431 16432 /** 16433 * The callback associated with a {@link #bootstrapAuthenticationRequest()}. 16434 * @hide 16435 */ 16436 @SystemApi 16437 public static class BootstrapAuthenticationCallback { 16438 16439 /** 16440 * Invoked when the previously requested GBA keys are available (@see 16441 * bootstrapAuthenticationRequest()). 16442 * @param gbaKey Ks_NAF/Ks_ext_NAF Response 16443 * @param transactionId Bootstrapping Transaction Identifier 16444 */ onKeysAvailable(@onNull byte[] gbaKey, @NonNull String transactionId)16445 public void onKeysAvailable(@NonNull byte[] gbaKey, @NonNull String transactionId) {} 16446 16447 /** 16448 * @param reason The reason for the authentication failure. 16449 */ onAuthenticationFailure(@uthenticationFailureReason int reason)16450 public void onAuthenticationFailure(@AuthenticationFailureReason int reason) {} 16451 } 16452 16453 /** 16454 * Used to get the Generic Bootstrapping Architecture authentication keys 16455 * KsNAF/Ks_ext_NAF for a particular NAF as defined in 3GPP spec TS 33.220 for 16456 * the specified sub id. 16457 * 16458 * <p>Application must be prepared to wait for receiving the Gba keys through the 16459 * registered callback and not invoke the API on the main application thread. 16460 * Application also must call the api to get the fresh key every time instead 16461 * of caching the key. 16462 * 16463 * Following steps may be invoked on the API call depending on the state of the 16464 * underlying GBA implementation: 16465 * <ol> 16466 * <li>Resolve and bind to a Gba implementation.</li> 16467 * <li>Run bootstrapping if no valid keys are available or bootstrapping is forced.</li> 16468 * <li>Generate the ks_NAF/ ks_Ext_NAF to be returned via the callback.</li> 16469 * </ol> 16470 * 16471 * <p> Requires Permission: 16472 * <ul> 16473 * <li>{@link android.Manifest.permission#MODIFY_PHONE_STATE},</li> 16474 * <li>{@link android.Manifest.permission#PERFORM_IMS_SINGLE_REGISTRATION},</li> 16475 * <li>or that the caller has carrier privileges (see 16476 * {@link TelephonyManager#hasCarrierPrivileges()}).</li> 16477 * </ul> 16478 * @param appType icc application type, like {@link #APPTYPE_USIM} or {@link 16479 * #APPTYPE_ISIM} or {@link#APPTYPE_UNKNOWN} 16480 * @param nafId A URI to specify Network Application Function(NAF) fully qualified domain 16481 * name (FQDN) and the selected GBA mode. The authority of the URI must contain two parts 16482 * delimited by "@" sign. The first part is the constant string "3GPP-bootstrapping" (GBA_ME), 16483 * "3GPP-bootstrapping-uicc" (GBA_ U), or "3GPP-bootstrapping-digest" (GBA_Digest). 16484 * The second part shall be the FQDN of the NAF. The scheme of the URI is not actually used 16485 * for the authentication, which may be set the same as the resource that the application is 16486 * going to access. For example, the nafId can be 16487 * "https://3GPP-bootstrapping@naf1.operator.com", 16488 * "https://3GPP-bootstrapping-uicc@naf1.operator.com", 16489 * "https://3GPP-bootstrapping-digest@naf1.operator.com", 16490 * "ftps://3GPP-bootstrapping-digest@naf1.operator.com". 16491 * @param securityProtocol Security protocol identifier between UE and NAF. See 16492 * 3GPP TS 33.220 Annex H. Application can use 16493 * {@link UaSecurityProtocolIdentifier#createDefaultUaSpId}, 16494 * {@link UaSecurityProtocolIdentifier#create3GppUaSpId}, 16495 * to create the ua security protocol identifier as needed 16496 * @param forceBootStrapping true=force bootstrapping, false=do not force 16497 * bootstrapping. Bootstrapping shouldn't be forced unless the application sees 16498 * authentication errors from the server. 16499 * @param e The {@link Executor} that will be used to call the Gba callback. 16500 * @param callback A callback called on the supplied {@link Executor} that will 16501 * contain the GBA Ks_NAF/Ks_ext_NAF when available. If the NAF keys are 16502 * available and valid at the time of call and bootstrapping is not requested, 16503 * then the callback shall be invoked with the available keys. 16504 * @hide 16505 */ 16506 @SystemApi 16507 @WorkerThread 16508 @RequiresPermission(anyOf = {android.Manifest.permission.MODIFY_PHONE_STATE, 16509 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION}) 16510 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_SUBSCRIPTION) bootstrapAuthenticationRequest( @iccAppTypeExt int appType, @NonNull Uri nafId, @NonNull UaSecurityProtocolIdentifier securityProtocol, boolean forceBootStrapping, @NonNull Executor e, @NonNull BootstrapAuthenticationCallback callback)16511 public void bootstrapAuthenticationRequest( 16512 @UiccAppTypeExt int appType, @NonNull Uri nafId, 16513 @NonNull UaSecurityProtocolIdentifier securityProtocol, 16514 boolean forceBootStrapping, @NonNull Executor e, 16515 @NonNull BootstrapAuthenticationCallback callback) { 16516 try { 16517 ITelephony service = getITelephony(); 16518 if (service == null) { 16519 e.execute(() -> callback.onAuthenticationFailure( 16520 GBA_FAILURE_REASON_FEATURE_NOT_READY)); 16521 return; 16522 } 16523 service.bootstrapAuthenticationRequest( 16524 getSubId(), appType, nafId, securityProtocol, forceBootStrapping, 16525 new IBootstrapAuthenticationCallback.Stub() { 16526 @Override 16527 public void onKeysAvailable(int token, byte[] gbaKey, 16528 String transactionId) { 16529 final long identity = Binder.clearCallingIdentity(); 16530 try { 16531 e.execute(() -> callback.onKeysAvailable(gbaKey, transactionId)); 16532 } finally { 16533 Binder.restoreCallingIdentity(identity); 16534 } 16535 } 16536 16537 @Override 16538 public void onAuthenticationFailure(int token, int reason) { 16539 final long identity = Binder.clearCallingIdentity(); 16540 try { 16541 e.execute(() -> callback.onAuthenticationFailure(reason)); 16542 } finally { 16543 Binder.restoreCallingIdentity(identity); 16544 } 16545 } 16546 }); 16547 } catch (RemoteException exception) { 16548 Log.e(TAG, "Error calling ITelephony#bootstrapAuthenticationRequest", exception); 16549 e.execute(() -> callback.onAuthenticationFailure(GBA_FAILURE_REASON_FEATURE_NOT_READY)); 16550 } 16551 } 16552 16553 /** 16554 * The network type is valid or not. 16555 * 16556 * @param networkType The network type {@link NetworkType}. 16557 * @return {@code true} if valid, {@code false} otherwise. 16558 * 16559 * @hide 16560 */ isNetworkTypeValid(@etworkType int networkType)16561 public static boolean isNetworkTypeValid(@NetworkType int networkType) { 16562 return networkType >= TelephonyManager.NETWORK_TYPE_UNKNOWN && 16563 networkType <= TelephonyManager.NETWORK_TYPE_NR; 16564 } 16565 16566 /** 16567 * Set a {@link SignalStrengthUpdateRequest} to receive notification when signal quality 16568 * measurements breach the specified thresholds. 16569 * 16570 * To be notified, set the signal strength update request and then register 16571 * {@link TelephonyManager#listen(PhoneStateListener, int)} with 16572 * {@link PhoneStateListener#LISTEN_SIGNAL_STRENGTHS}. The notification will arrive through 16573 * {@link PhoneStateListener#onSignalStrengthsChanged(SignalStrength)}. 16574 * 16575 * To stop receiving the notification over the specified thresholds, pass the same 16576 * {@link SignalStrengthUpdateRequest} object to 16577 * {@link #clearSignalStrengthUpdateRequest(SignalStrengthUpdateRequest)}. 16578 * 16579 * System will clean up the {@link SignalStrengthUpdateRequest} if the caller process died 16580 * without calling {@link #clearSignalStrengthUpdateRequest(SignalStrengthUpdateRequest)}. 16581 * 16582 * If this TelephonyManager object has been created with {@link #createForSubscriptionId}, 16583 * applies to the given subId. Otherwise, applies to 16584 * {@link SubscriptionManager#getDefaultSubscriptionId()}. To request for multiple subIds, 16585 * pass a request object to each TelephonyManager object created with 16586 * {@link #createForSubscriptionId}. 16587 * 16588 * <p>Requires Permission: 16589 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 16590 * or that the calling app has carrier privileges (see 16591 * {@link TelephonyManager#hasCarrierPrivileges}). 16592 * 16593 * Note that the thresholds in the request will be used on a best-effort basis; the system may 16594 * modify requests to multiplex various request sources or to optimize power consumption. The 16595 * caller should not expect to be notified with the exactly the same thresholds. 16596 * 16597 * @see #clearSignalStrengthUpdateRequest(SignalStrengthUpdateRequest) 16598 * 16599 * @param request the SignalStrengthUpdateRequest to be set into the System 16600 * 16601 * @throws IllegalStateException if a new request is set with same subId from the same caller 16602 */ 16603 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 16604 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 16605 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) setSignalStrengthUpdateRequest(@onNull SignalStrengthUpdateRequest request)16606 public void setSignalStrengthUpdateRequest(@NonNull SignalStrengthUpdateRequest request) { 16607 Objects.requireNonNull(request, "request must not be null"); 16608 16609 try { 16610 ITelephony service = getITelephony(); 16611 if (service != null) { 16612 service.setSignalStrengthUpdateRequest(getSubId(), request, getOpPackageName()); 16613 } 16614 } catch (RemoteException e) { 16615 Log.e(TAG, "Error calling ITelephony#setSignalStrengthUpdateRequest", e); 16616 } 16617 } 16618 16619 /** 16620 * Clear a {@link SignalStrengthUpdateRequest} from the system. 16621 * 16622 * <p>Requires Permission: 16623 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE} 16624 * or that the calling app has carrier privileges (see 16625 * {@link TelephonyManager#hasCarrierPrivileges}). 16626 * 16627 * <p>If the given request was not set before, this operation is a no-op. 16628 * 16629 * @see #setSignalStrengthUpdateRequest(SignalStrengthUpdateRequest) 16630 * 16631 * @param request the SignalStrengthUpdateRequest to be cleared from the System 16632 */ 16633 @SuppressAutoDoc // Blocked by b/72967236 - no support for carrier privileges 16634 @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) 16635 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_RADIO_ACCESS) clearSignalStrengthUpdateRequest(@onNull SignalStrengthUpdateRequest request)16636 public void clearSignalStrengthUpdateRequest(@NonNull SignalStrengthUpdateRequest request) { 16637 Objects.requireNonNull(request, "request must not be null"); 16638 16639 try { 16640 ITelephony service = getITelephony(); 16641 if (service != null) { 16642 service.clearSignalStrengthUpdateRequest(getSubId(), request, getOpPackageName()); 16643 } 16644 } catch (RemoteException e) { 16645 Log.e(TAG, "Error calling ITelephony#clearSignalStrengthUpdateRequest", e); 16646 } 16647 } 16648 16649 /** 16650 * Gets the current phone capability. 16651 * 16652 * @return the PhoneCapability which describes the data connection capability of modem. 16653 * It's used to evaluate possible phone config change, for example from single 16654 * SIM device to multi-SIM device. 16655 * @hide 16656 */ 16657 @SystemApi 16658 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getPhoneCapability()16659 public @NonNull PhoneCapability getPhoneCapability() { 16660 try { 16661 ITelephony telephony = getITelephony(); 16662 if (telephony != null) { 16663 return telephony.getPhoneCapability(); 16664 } else { 16665 throw new IllegalStateException("telephony service is null."); 16666 } 16667 } catch (RemoteException ex) { 16668 ex.rethrowAsRuntimeException(); 16669 } 16670 if (getActiveModemCount() > 1) { 16671 return PhoneCapability.DEFAULT_DSDS_CAPABILITY; 16672 } else { 16673 return PhoneCapability.DEFAULT_SSSS_CAPABILITY; 16674 } 16675 } 16676 16677 /** 16678 * The unattended reboot was prepared successfully. 16679 * @hide 16680 */ 16681 @SystemApi 16682 public static final int PREPARE_UNATTENDED_REBOOT_SUCCESS = 0; 16683 16684 /** 16685 * The unattended reboot was prepared, but the user will need to manually 16686 * enter the PIN code of at least one SIM card present in the device. 16687 * @hide 16688 */ 16689 @SystemApi 16690 public static final int PREPARE_UNATTENDED_REBOOT_PIN_REQUIRED = 1; 16691 16692 /** 16693 * The unattended reboot was not prepared due to a non-recoverable error. After this error, 16694 * the client that manages the unattended reboot should not try to invoke the API again 16695 * until the next power cycle. 16696 * @hide 16697 */ 16698 @SystemApi 16699 public static final int PREPARE_UNATTENDED_REBOOT_ERROR = 2; 16700 16701 /** @hide */ 16702 @Retention(RetentionPolicy.SOURCE) 16703 @IntDef(prefix = {"PREPARE_UNATTENDED_REBOOT_"}, 16704 value = { 16705 PREPARE_UNATTENDED_REBOOT_SUCCESS, 16706 PREPARE_UNATTENDED_REBOOT_PIN_REQUIRED, 16707 PREPARE_UNATTENDED_REBOOT_ERROR 16708 }) 16709 public @interface PrepareUnattendedRebootResult {} 16710 16711 /** 16712 * Prepare TelephonyManager for an unattended reboot. The reboot is required to be done 16713 * shortly (e.g. within 15 seconds) after the API is invoked. 16714 * 16715 * <p>Requires Permission: 16716 * {@link android.Manifest.permission#REBOOT} 16717 * 16718 * @return {@link #PREPARE_UNATTENDED_REBOOT_SUCCESS} in case of success. 16719 * {@link #PREPARE_UNATTENDED_REBOOT_PIN_REQUIRED} if the device contains 16720 * at least one SIM card for which the user needs to manually enter the PIN 16721 * code after the reboot. {@link #PREPARE_UNATTENDED_REBOOT_ERROR} in case 16722 * of error. 16723 * @hide 16724 */ 16725 @SystemApi 16726 @RequiresPermission(android.Manifest.permission.REBOOT) 16727 @PrepareUnattendedRebootResult prepareForUnattendedReboot()16728 public int prepareForUnattendedReboot() { 16729 try { 16730 ITelephony service = getITelephony(); 16731 if (service != null) { 16732 return service.prepareForUnattendedReboot(); 16733 } 16734 } catch (RemoteException e) { 16735 Log.e(TAG, "Telephony#prepareForUnattendedReboot RemoteException", e); 16736 e.rethrowFromSystemServer(); 16737 } 16738 return PREPARE_UNATTENDED_REBOOT_ERROR; 16739 } 16740 16741 /** 16742 * Exception that may be supplied to the callback in {@link #getNetworkSlicingConfiguration} if 16743 * something goes awry. 16744 */ 16745 public static class NetworkSlicingException extends Exception { 16746 /** 16747 * Getting the current slicing configuration successfully. Used internally only. 16748 * @hide 16749 */ 16750 public static final int SUCCESS = 0; 16751 16752 /** 16753 * The system timed out waiting for a response from the Radio. 16754 * @hide 16755 */ 16756 public static final int ERROR_TIMEOUT = 1; 16757 16758 /** 16759 * The modem returned a failure. 16760 * @hide 16761 */ 16762 public static final int ERROR_MODEM_ERROR = 2; 16763 16764 /** @hide */ 16765 @IntDef(prefix = {"ERROR_"}, value = { 16766 ERROR_TIMEOUT, 16767 ERROR_MODEM_ERROR, 16768 }) 16769 @Retention(RetentionPolicy.SOURCE) 16770 public @interface NetworkSlicingError {} 16771 16772 private final int mErrorCode; 16773 16774 /** @hide */ NetworkSlicingException(@etworkSlicingError int errorCode)16775 public NetworkSlicingException(@NetworkSlicingError int errorCode) { 16776 mErrorCode = errorCode; 16777 } 16778 16779 @Override toString()16780 public String toString() { 16781 switch (mErrorCode) { 16782 case ERROR_TIMEOUT: return "ERROR_TIMEOUT"; 16783 case ERROR_MODEM_ERROR: return "ERROR_MODEM_ERROR"; 16784 default: return "UNDEFINED"; 16785 } 16786 } 16787 } 16788 16789 /** 16790 * Exception that is supplied to the callback in {@link #getNetworkSlicingConfiguration} if the 16791 * system timed out waiting for a response from the Radio. 16792 */ 16793 public class TimeoutException extends NetworkSlicingException { 16794 /** @hide */ TimeoutException(int errorCode)16795 public TimeoutException(int errorCode) { 16796 super(errorCode); 16797 } 16798 } 16799 16800 /** 16801 * Exception that is supplied to the callback in {@link #getNetworkSlicingConfiguration} if the 16802 * modem returned a failure. 16803 */ 16804 public class ModemErrorException extends NetworkSlicingException { 16805 /** @hide */ ModemErrorException(int errorCode)16806 public ModemErrorException(int errorCode) { 16807 super(errorCode); 16808 } 16809 } 16810 16811 /** @hide */ 16812 public static final String KEY_SLICING_CONFIG_HANDLE = "slicing_config_handle"; 16813 16814 /** 16815 * Request to get the current slicing configuration including URSP rules and 16816 * NSSAIs (configured, allowed and rejected). 16817 * 16818 * This method can be invoked if one of the following requirements is met: 16819 * <ul> 16820 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 16821 * is a privileged permission that can only be granted to apps preloaded on the device. 16822 * <li>If the calling app has carrier privileges (see {@link #hasCarrierPrivileges}). 16823 * </ul> 16824 * 16825 * This will be invalid if the device does not support 16826 * android.telephony.TelephonyManager#CAPABILITY_SLICING_CONFIG_SUPPORTED. 16827 * 16828 * @param executor the executor on which callback will be invoked. 16829 * @param callback a callback to receive the current slicing configuration. 16830 */ 16831 @RequiresFeature( 16832 enforcement = "android.telephony.TelephonyManager#isRadioInterfaceCapabilitySupported", 16833 value = TelephonyManager.CAPABILITY_SLICING_CONFIG_SUPPORTED) 16834 @SuppressAutoDoc // No support for carrier privileges (b/72967236). 16835 @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getNetworkSlicingConfiguration( @onNull @allbackExecutor Executor executor, @NonNull OutcomeReceiver<NetworkSlicingConfig, NetworkSlicingException> callback)16836 public void getNetworkSlicingConfiguration( 16837 @NonNull @CallbackExecutor Executor executor, 16838 @NonNull OutcomeReceiver<NetworkSlicingConfig, NetworkSlicingException> callback) { 16839 Objects.requireNonNull(executor); 16840 Objects.requireNonNull(callback); 16841 16842 try { 16843 ITelephony telephony = getITelephony(); 16844 if (telephony == null) { 16845 throw new IllegalStateException("telephony service is null."); 16846 } 16847 telephony.getSlicingConfig(new ResultReceiver(null) { 16848 @Override 16849 protected void onReceiveResult(int resultCode, Bundle result) { 16850 if (resultCode == NetworkSlicingException.ERROR_TIMEOUT) { 16851 executor.execute(() -> callback.onError( 16852 new TimeoutException(resultCode))); 16853 return; 16854 } else if (resultCode == NetworkSlicingException.ERROR_MODEM_ERROR) { 16855 executor.execute(() -> callback.onError( 16856 new ModemErrorException(resultCode))); 16857 return; 16858 } 16859 16860 NetworkSlicingConfig slicingConfig = 16861 result.getParcelable(KEY_SLICING_CONFIG_HANDLE); 16862 executor.execute(() -> callback.onResult(slicingConfig)); 16863 } 16864 }); 16865 } catch (RemoteException ex) { 16866 ex.rethrowAsRuntimeException(); 16867 } 16868 } 16869 16870 /** 16871 * Get last known cell identity. 16872 * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and 16873 * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws SecurityException. 16874 * If there is current registered network this value will be same as the registered cell 16875 * identity. If the device goes out of service the previous cell identity is cached and 16876 * will be returned. If the cache age of the Cell identity is more than 24 hours 16877 * it will be cleared and null will be returned. 16878 * @return last known cell identity {@CellIdentity}. 16879 * @hide 16880 */ 16881 @RequiresPermission(allOf = {Manifest.permission.ACCESS_FINE_LOCATION, 16882 "com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID"}) getLastKnownCellIdentity()16883 public @Nullable CellIdentity getLastKnownCellIdentity() { 16884 try { 16885 ITelephony telephony = getITelephony(); 16886 if (telephony == null) { 16887 throw new IllegalStateException("telephony service is null."); 16888 } 16889 return telephony.getLastKnownCellIdentity(getSubId(), getOpPackageName(), 16890 getAttributionTag()); 16891 } catch (RemoteException ex) { 16892 ex.rethrowAsRuntimeException(); 16893 } 16894 return null; 16895 } 16896 16897 /** 16898 * Callbacks to listen for when the set of packages with carrier privileges for a SIM changes. 16899 * 16900 * <p>Of note, when multiple callbacks are registered, they may be triggered one after another. 16901 * The ordering of them is not guaranteed and thus should not be depend on. 16902 * 16903 * @hide 16904 */ 16905 @SystemApi 16906 public interface CarrierPrivilegesCallback { 16907 /** 16908 * Called when the set of packages with carrier privileges has changed. 16909 * 16910 * <p>Of note, this callback will <b>not</b> be fired if a carrier triggers a SIM profile 16911 * switch and the same set of packages remains privileged after the switch. 16912 * 16913 * <p>At registration, the callback will receive the current set of privileged packages. 16914 * 16915 * @param privilegedPackageNames The updated set of package names that have carrier 16916 * privileges 16917 * @param privilegedUids The updated set of UIDs that have carrier privileges 16918 */ onCarrierPrivilegesChanged( @onNull Set<String> privilegedPackageNames, @NonNull Set<Integer> privilegedUids)16919 void onCarrierPrivilegesChanged( 16920 @NonNull Set<String> privilegedPackageNames, @NonNull Set<Integer> privilegedUids); 16921 16922 /** 16923 * Called when the {@link CarrierService} for the current user profile has changed. 16924 * 16925 * <p>This method does nothing by default. Clients that are interested in the carrier 16926 * service change should override this method to get package name and UID info. 16927 * 16928 * <p>At registration, the callback will receive the current carrier service info. 16929 * 16930 * <p>Of note, this callback will <b>not</b> be fired if a carrier triggers a SIM profile 16931 * switch and the same carrier service remains after switch. 16932 * 16933 * @param carrierServicePackageName package name of the {@link CarrierService}. May be 16934 * {@code null} when no carrier service is detected. 16935 * @param carrierServiceUid UID of the {@link CarrierService}. May be 16936 * {@link android.os.Process#INVALID_UID} if no carrier 16937 * service is detected. 16938 */ onCarrierServiceChanged( @ullable String carrierServicePackageName, int carrierServiceUid)16939 default void onCarrierServiceChanged( 16940 @Nullable String carrierServicePackageName, int carrierServiceUid) { 16941 // do nothing by default 16942 } 16943 } 16944 16945 /** 16946 * Sets a voice service state override from telecom based on the current {@link PhoneAccount}s 16947 * registered. See {@link PhoneAccount#CAPABILITY_VOICE_CALLING_AVAILABLE}. 16948 * 16949 * <p>Currently, this API is only called to indicate over-the-top voice calling capability of 16950 * the SIM call manager, which will get merged into {@link ServiceState#getState} and propagated 16951 * to interested callers via {@link #getServiceState} and {@link 16952 * TelephonyCallback.ServiceStateListener}. 16953 * 16954 * <p>If callers are truly interested in the actual device <-> tower connection status and not 16955 * an overall "device can make voice calls" boolean, they can use {@link 16956 * ServiceState#getNetworkRegistrationInfo} to check CS registration state. 16957 * 16958 * <p>TODO(b/215240050) In the future, this API will be removed and replaced with a new superset 16959 * API to disentangle the "true" {@link ServiceState} meaning of "this is the connection status 16960 * to the tower" from IMS registration state and over-the-top voice calling capabilities. 16961 * 16962 * @hide 16963 */ 16964 @TestApi 16965 @RequiresPermission(Manifest.permission.BIND_TELECOM_CONNECTION_SERVICE) setVoiceServiceStateOverride(boolean hasService)16966 public void setVoiceServiceStateOverride(boolean hasService) { 16967 try { 16968 ITelephony telephony = getITelephony(); 16969 if (telephony == null) { 16970 throw new IllegalStateException("Telephony service is null"); 16971 } 16972 telephony.setVoiceServiceStateOverride(getSubId(), hasService, getOpPackageName()); 16973 } catch (RemoteException ex) { 16974 ex.rethrowAsRuntimeException(); 16975 } 16976 } 16977 16978 /** 16979 * Registers a {@link CarrierPrivilegesCallback} on the given {@code logicalSlotIndex} to 16980 * receive callbacks when the set of packages with carrier privileges changes. The callback will 16981 * immediately be called with the latest state. 16982 * 16983 * @param logicalSlotIndex The SIM slot to listen on 16984 * @param executor The executor where {@code callback} will be invoked 16985 * @param callback The callback to register 16986 * @hide 16987 */ 16988 @SystemApi 16989 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) registerCarrierPrivilegesCallback( int logicalSlotIndex, @NonNull @CallbackExecutor Executor executor, @NonNull CarrierPrivilegesCallback callback)16990 public void registerCarrierPrivilegesCallback( 16991 int logicalSlotIndex, 16992 @NonNull @CallbackExecutor Executor executor, 16993 @NonNull CarrierPrivilegesCallback callback) { 16994 if (mContext == null) { 16995 throw new IllegalStateException("Telephony service is null"); 16996 } else if (executor == null || callback == null) { 16997 throw new IllegalArgumentException( 16998 "CarrierPrivilegesCallback and executor must be non-null"); 16999 } 17000 mTelephonyRegistryMgr = mContext.getSystemService(TelephonyRegistryManager.class); 17001 if (mTelephonyRegistryMgr == null) { 17002 throw new IllegalStateException("Telephony registry service is null"); 17003 } 17004 mTelephonyRegistryMgr.addCarrierPrivilegesCallback(logicalSlotIndex, executor, callback); 17005 } 17006 17007 /** 17008 * Unregisters an existing {@link CarrierPrivilegesCallback}. 17009 * 17010 * @hide 17011 */ 17012 @SystemApi 17013 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) unregisterCarrierPrivilegesCallback(@onNull CarrierPrivilegesCallback callback)17014 public void unregisterCarrierPrivilegesCallback(@NonNull CarrierPrivilegesCallback callback) { 17015 if (mContext == null) { 17016 throw new IllegalStateException("Telephony service is null"); 17017 } else if (callback == null) { 17018 throw new IllegalArgumentException("CarrierPrivilegesCallback must be non-null"); 17019 } 17020 mTelephonyRegistryMgr = mContext.getSystemService(TelephonyRegistryManager.class); 17021 if (mTelephonyRegistryMgr == null) { 17022 throw new IllegalStateException("Telephony registry service is null"); 17023 } 17024 mTelephonyRegistryMgr.removeCarrierPrivilegesCallback(callback); 17025 } 17026 17027 /** 17028 * set removable eSIM as default eUICC. 17029 * 17030 * @hide 17031 */ 17032 @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) 17033 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_EUICC) setRemovableEsimAsDefaultEuicc(boolean isDefault)17034 public void setRemovableEsimAsDefaultEuicc(boolean isDefault) { 17035 try { 17036 ITelephony telephony = getITelephony(); 17037 if (telephony != null) { 17038 telephony.setRemovableEsimAsDefaultEuicc(isDefault, getOpPackageName()); 17039 } 17040 } catch (RemoteException e) { 17041 Log.e(TAG, "Error in setRemovableEsimAsDefault: " + e); 17042 } 17043 } 17044 17045 /** 17046 * Returns whether the removable eSIM is default eUICC or not. 17047 * 17048 * @hide 17049 */ 17050 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) 17051 @RequiresFeature(PackageManager.FEATURE_TELEPHONY_EUICC) isRemovableEsimDefaultEuicc()17052 public boolean isRemovableEsimDefaultEuicc() { 17053 try { 17054 ITelephony telephony = getITelephony(); 17055 if (telephony != null) { 17056 return telephony.isRemovableEsimDefaultEuicc(getOpPackageName()); 17057 } 17058 } catch (RemoteException e) { 17059 Log.e(TAG, "Error in isRemovableEsimDefaultEuicc: " + e); 17060 } 17061 return false; 17062 } 17063 } 17064