1 /* 2 * Copyright (C) 2014 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.text.TextUtils.formatSimple; 20 21 import android.annotation.NonNull; 22 import android.annotation.Nullable; 23 import android.annotation.SystemApi; 24 import android.content.Context; 25 import android.content.pm.PackageInfo; 26 import android.content.pm.PackageManager; 27 import android.graphics.Bitmap; 28 import android.graphics.BitmapFactory; 29 import android.graphics.Canvas; 30 import android.graphics.Color; 31 import android.graphics.Paint; 32 import android.graphics.PorterDuff; 33 import android.graphics.PorterDuffColorFilter; 34 import android.graphics.Rect; 35 import android.graphics.Typeface; 36 import android.os.Parcel; 37 import android.os.ParcelUuid; 38 import android.os.Parcelable; 39 import android.telephony.SubscriptionManager.ProfileClass; 40 import android.telephony.SubscriptionManager.SimDisplayNameSource; 41 import android.telephony.SubscriptionManager.SubscriptionType; 42 import android.telephony.SubscriptionManager.UsageSetting; 43 import android.text.TextUtils; 44 import android.util.DisplayMetrics; 45 import android.util.Log; 46 47 import com.android.internal.telephony.util.TelephonyUtils; 48 import com.android.telephony.Rlog; 49 50 import java.util.ArrayList; 51 import java.util.Arrays; 52 import java.util.Collections; 53 import java.util.List; 54 import java.util.Objects; 55 56 /** 57 * A Parcelable class for Subscription Information. 58 */ 59 public class SubscriptionInfo implements Parcelable { 60 /** 61 * Size of text to render on the icon. 62 */ 63 private static final int TEXT_SIZE = 16; 64 65 /** 66 * Subscription Identifier, this is a device unique number 67 * and not an index into an array 68 */ 69 private final int mId; 70 71 /** 72 * The ICCID of the SIM that is associated with this subscription, empty if unknown. 73 */ 74 @NonNull 75 private final String mIccId; 76 77 /** 78 * The index of the SIM slot that currently contains the subscription and not necessarily unique 79 * and maybe {@link SubscriptionManager#INVALID_SIM_SLOT_INDEX} if unknown or the subscription 80 * is inactive. 81 */ 82 private final int mSimSlotIndex; 83 84 /** 85 * The name displayed to the user that identifies this subscription. This name is used 86 * in Settings page and can be renamed by the user. 87 */ 88 @NonNull 89 private final CharSequence mDisplayName; 90 91 /** 92 * The name displayed to the user that identifies subscription provider name. This name is the 93 * SPN displayed in status bar and many other places. Can't be renamed by the user. 94 */ 95 @NonNull 96 private final CharSequence mCarrierName; 97 98 /** 99 * The source of the {@link #mDisplayName}. 100 */ 101 @SimDisplayNameSource 102 private final int mDisplayNameSource; 103 104 /** 105 * The color to be used for tinting the icon when displaying to the user. 106 */ 107 private final int mIconTint; 108 109 /** 110 * The number presented to the user identify this subscription. 111 */ 112 @NonNull 113 private final String mNumber; 114 115 /** 116 * Whether user enables data roaming for this subscription or not. Either 117 * {@link SubscriptionManager#DATA_ROAMING_ENABLE} or 118 * {@link SubscriptionManager#DATA_ROAMING_DISABLE}. 119 */ 120 private final int mDataRoaming; 121 122 /** 123 * Mobile Country Code. 124 */ 125 @Nullable 126 private final String mMcc; 127 128 /** 129 * Mobile Network Code. 130 */ 131 @Nullable 132 private final String mMnc; 133 134 /** 135 * EHPLMNs associated with the subscription. 136 */ 137 @NonNull 138 private final String[] mEhplmns; 139 140 /** 141 * HPLMNs associated with the subscription. 142 */ 143 @NonNull 144 private final String[] mHplmns; 145 146 /** 147 * Whether the subscription is from eSIM. 148 */ 149 private final boolean mIsEmbedded; 150 151 /** 152 * The string ID of the SIM card. It is the ICCID of the active profile for a UICC card and the 153 * EID for an eUICC card. 154 */ 155 @NonNull 156 private final String mCardString; 157 158 /** 159 * The access rules for this subscription, if it is embedded and defines any. This does not 160 * include access rules for non-embedded subscriptions. 161 */ 162 @Nullable 163 private final UiccAccessRule[] mNativeAccessRules; 164 165 /** 166 * The carrier certificates for this subscription that are saved in carrier configs. 167 * This does not include access rules from the Uicc, whether embedded or non-embedded. 168 */ 169 @Nullable 170 private final UiccAccessRule[] mCarrierConfigAccessRules; 171 172 /** 173 * Whether the subscription is opportunistic. 174 */ 175 private final boolean mIsOpportunistic; 176 177 /** 178 * A UUID assigned to the subscription group. {@code null} if not assigned. 179 * 180 * @see SubscriptionManager#createSubscriptionGroup(List) 181 */ 182 @Nullable 183 private final ParcelUuid mGroupUuid; 184 185 /** 186 * ISO Country code for the subscription's provider. 187 */ 188 @NonNull 189 private final String mCountryIso; 190 191 /** 192 * The subscription carrier id. 193 * 194 * @see TelephonyManager#getSimCarrierId() 195 */ 196 private final int mCarrierId; 197 198 /** 199 * The profile class populated from the profile metadata if present. Otherwise, 200 * the profile class defaults to {@link SubscriptionManager#PROFILE_CLASS_UNSET} if there is no 201 * profile metadata or the subscription is not on an eUICC ({@link #isEmbedded} returns 202 * {@code false}). 203 */ 204 @ProfileClass 205 private final int mProfileClass; 206 207 /** 208 * Type of the subscription. 209 */ 210 @SubscriptionType 211 private final int mType; 212 213 /** 214 * A package name that specifies who created the group. Empty if not available. 215 */ 216 @NonNull 217 private final String mGroupOwner; 218 219 /** 220 * Whether uicc applications are configured to enable or disable. 221 * By default it's true. 222 */ 223 private final boolean mAreUiccApplicationsEnabled; 224 225 /** 226 * The port index of the Uicc card. 227 */ 228 private final int mPortIndex; 229 230 /** 231 * Subscription's preferred usage setting. 232 */ 233 @UsageSetting 234 private final int mUsageSetting; 235 236 // Below are the fields that do not exist in the database. 237 238 /** 239 * SIM icon bitmap cache. 240 */ 241 @Nullable 242 private Bitmap mIconBitmap; 243 244 /** 245 * The card ID of the SIM card. This maps uniquely to {@link #mCardString}. 246 */ 247 private final int mCardId; 248 249 /** 250 * Whether group of the subscription is disabled. This is only useful if it's a grouped 251 * opportunistic subscription. In this case, if all primary (non-opportunistic) subscriptions 252 * in the group are deactivated (unplugged pSIM or deactivated eSIM profile), we should disable 253 * this opportunistic subscription. 254 */ 255 private final boolean mIsGroupDisabled; 256 257 /** 258 * @hide 259 * 260 * @deprecated Use {@link SubscriptionInfo.Builder}. 261 */ 262 // TODO: Clean up after external usages moved to builder model. 263 @Deprecated SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName, CharSequence carrierName, int nameSource, int iconTint, String number, int roaming, Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded, @Nullable UiccAccessRule[] nativeAccessRules, String cardString)264 public SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName, 265 CharSequence carrierName, int nameSource, int iconTint, String number, int roaming, 266 Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded, 267 @Nullable UiccAccessRule[] nativeAccessRules, String cardString) { 268 this(id, iccId, simSlotIndex, displayName, carrierName, nameSource, iconTint, number, 269 roaming, icon, mcc, mnc, countryIso, isEmbedded, nativeAccessRules, cardString, -1, 270 false, null, false, TelephonyManager.UNKNOWN_CARRIER_ID, 271 SubscriptionManager.PROFILE_CLASS_UNSET, 272 SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM, null, null, true); 273 } 274 275 /** 276 * @hide 277 * 278 * @deprecated Use {@link SubscriptionInfo.Builder}. 279 */ 280 // TODO: Clean up after external usages moved to builder model. 281 @Deprecated SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName, CharSequence carrierName, int nameSource, int iconTint, String number, int roaming, Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded, @Nullable UiccAccessRule[] nativeAccessRules, String cardString, boolean isOpportunistic, @Nullable String groupUUID, int carrierId, int profileClass)282 public SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName, 283 CharSequence carrierName, int nameSource, int iconTint, String number, int roaming, 284 Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded, 285 @Nullable UiccAccessRule[] nativeAccessRules, String cardString, 286 boolean isOpportunistic, @Nullable String groupUUID, int carrierId, int profileClass) { 287 this(id, iccId, simSlotIndex, displayName, carrierName, nameSource, iconTint, number, 288 roaming, icon, mcc, mnc, countryIso, isEmbedded, nativeAccessRules, cardString, -1, 289 isOpportunistic, groupUUID, false, carrierId, profileClass, 290 SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM, null, null, true); 291 } 292 293 /** 294 * @hide 295 * 296 * @deprecated Use {@link SubscriptionInfo.Builder}. 297 */ 298 // TODO: Clean up after external usages moved to builder model. 299 @Deprecated SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName, CharSequence carrierName, int nameSource, int iconTint, String number, int roaming, Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded, @Nullable UiccAccessRule[] nativeAccessRules, String cardString, int cardId, boolean isOpportunistic, @Nullable String groupUUID, boolean isGroupDisabled, int carrierId, int profileClass, int subType, @Nullable String groupOwner, @Nullable UiccAccessRule[] carrierConfigAccessRules, boolean areUiccApplicationsEnabled)300 public SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName, 301 CharSequence carrierName, int nameSource, int iconTint, String number, int roaming, 302 Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded, 303 @Nullable UiccAccessRule[] nativeAccessRules, String cardString, int cardId, 304 boolean isOpportunistic, @Nullable String groupUUID, boolean isGroupDisabled, 305 int carrierId, int profileClass, int subType, @Nullable String groupOwner, 306 @Nullable UiccAccessRule[] carrierConfigAccessRules, 307 boolean areUiccApplicationsEnabled) { 308 this(id, iccId, simSlotIndex, displayName, carrierName, nameSource, iconTint, number, 309 roaming, icon, mcc, mnc, countryIso, isEmbedded, nativeAccessRules, cardString, 310 cardId, isOpportunistic, groupUUID, isGroupDisabled, carrierId, profileClass, 311 subType, groupOwner, carrierConfigAccessRules, areUiccApplicationsEnabled, 0); 312 } 313 314 /** 315 * @hide 316 * 317 * @deprecated Use {@link SubscriptionInfo.Builder}. 318 */ 319 // TODO: Clean up after external usages moved to builder model. 320 @Deprecated SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName, CharSequence carrierName, int displayNameSource, int iconTint, String number, int roaming, Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded, @Nullable UiccAccessRule[] nativeAccessRules, String cardString, int cardId, boolean isOpportunistic, @Nullable String groupUUID, boolean isGroupDisabled, int carrierId, int profileClass, int subType, @Nullable String groupOwner, @Nullable UiccAccessRule[] carrierConfigAccessRules, boolean areUiccApplicationsEnabled, int portIndex)321 public SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName, 322 CharSequence carrierName, int displayNameSource, int iconTint, String number, 323 int roaming, Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded, 324 @Nullable UiccAccessRule[] nativeAccessRules, String cardString, int cardId, 325 boolean isOpportunistic, @Nullable String groupUUID, boolean isGroupDisabled, 326 int carrierId, int profileClass, int subType, @Nullable String groupOwner, 327 @Nullable UiccAccessRule[] carrierConfigAccessRules, 328 boolean areUiccApplicationsEnabled, int portIndex) { 329 this(id, iccId, simSlotIndex, displayName, carrierName, displayNameSource, iconTint, number, 330 roaming, icon, mcc, mnc, countryIso, isEmbedded, nativeAccessRules, cardString, 331 cardId, isOpportunistic, groupUUID, isGroupDisabled, carrierId, profileClass, 332 subType, groupOwner, carrierConfigAccessRules, areUiccApplicationsEnabled, 333 portIndex, SubscriptionManager.USAGE_SETTING_DEFAULT); 334 } 335 336 /** 337 * @hide 338 * 339 * @deprecated Use {@link SubscriptionInfo.Builder}. 340 */ 341 // TODO: Clean up after external usages moved to builder model. 342 @Deprecated SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName, CharSequence carrierName, int nameSource, int iconTint, String number, int roaming, Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded, @Nullable UiccAccessRule[] nativeAccessRules, String cardString, int cardId, boolean isOpportunistic, @Nullable String groupUuid, boolean isGroupDisabled, int carrierId, int profileClass, int subType, @Nullable String groupOwner, @Nullable UiccAccessRule[] carrierConfigAccessRules, boolean areUiccApplicationsEnabled, int portIndex, @UsageSetting int usageSetting)343 public SubscriptionInfo(int id, String iccId, int simSlotIndex, CharSequence displayName, 344 CharSequence carrierName, int nameSource, int iconTint, String number, int roaming, 345 Bitmap icon, String mcc, String mnc, String countryIso, boolean isEmbedded, 346 @Nullable UiccAccessRule[] nativeAccessRules, String cardString, int cardId, 347 boolean isOpportunistic, @Nullable String groupUuid, boolean isGroupDisabled, 348 int carrierId, int profileClass, int subType, @Nullable String groupOwner, 349 @Nullable UiccAccessRule[] carrierConfigAccessRules, 350 boolean areUiccApplicationsEnabled, int portIndex, @UsageSetting int usageSetting) { 351 this.mId = id; 352 this.mIccId = iccId; 353 this.mSimSlotIndex = simSlotIndex; 354 this.mDisplayName = displayName; 355 this.mCarrierName = carrierName; 356 this.mDisplayNameSource = nameSource; 357 this.mIconTint = iconTint; 358 this.mNumber = number; 359 this.mDataRoaming = roaming; 360 this.mIconBitmap = icon; 361 this.mMcc = TextUtils.emptyIfNull(mcc); 362 this.mMnc = TextUtils.emptyIfNull(mnc); 363 this.mHplmns = null; 364 this.mEhplmns = null; 365 this.mCountryIso = TextUtils.emptyIfNull(countryIso); 366 this.mIsEmbedded = isEmbedded; 367 this.mNativeAccessRules = nativeAccessRules; 368 this.mCardString = TextUtils.emptyIfNull(cardString); 369 this.mCardId = cardId; 370 this.mIsOpportunistic = isOpportunistic; 371 this.mGroupUuid = groupUuid == null ? null : ParcelUuid.fromString(groupUuid); 372 this.mIsGroupDisabled = isGroupDisabled; 373 this.mCarrierId = carrierId; 374 this.mProfileClass = profileClass; 375 this.mType = subType; 376 this.mGroupOwner = TextUtils.emptyIfNull(groupOwner); 377 this.mCarrierConfigAccessRules = carrierConfigAccessRules; 378 this.mAreUiccApplicationsEnabled = areUiccApplicationsEnabled; 379 this.mPortIndex = portIndex; 380 this.mUsageSetting = usageSetting; 381 } 382 383 /** 384 * Constructor from builder. 385 * 386 * @param builder Builder of {@link SubscriptionInfo}. 387 */ SubscriptionInfo(@onNull Builder builder)388 private SubscriptionInfo(@NonNull Builder builder) { 389 this.mId = builder.mId; 390 this.mIccId = builder.mIccId; 391 this.mSimSlotIndex = builder.mSimSlotIndex; 392 this.mDisplayName = builder.mDisplayName; 393 this.mCarrierName = builder.mCarrierName; 394 this.mDisplayNameSource = builder.mDisplayNameSource; 395 this.mIconTint = builder.mIconTint; 396 this.mNumber = builder.mNumber; 397 this.mDataRoaming = builder.mDataRoaming; 398 this.mIconBitmap = builder.mIconBitmap; 399 this.mMcc = builder.mMcc; 400 this.mMnc = builder.mMnc; 401 this.mEhplmns = builder.mEhplmns; 402 this.mHplmns = builder.mHplmns; 403 this.mCountryIso = builder.mCountryIso; 404 this.mIsEmbedded = builder.mIsEmbedded; 405 this.mNativeAccessRules = builder.mNativeAccessRules; 406 this.mCardString = builder.mCardString; 407 this.mCardId = builder.mCardId; 408 this.mIsOpportunistic = builder.mIsOpportunistic; 409 this.mGroupUuid = builder.mGroupUuid; 410 this.mIsGroupDisabled = builder.mIsGroupDisabled; 411 this.mCarrierId = builder.mCarrierId; 412 this.mProfileClass = builder.mProfileClass; 413 this.mType = builder.mType; 414 this.mGroupOwner = builder.mGroupOwner; 415 this.mCarrierConfigAccessRules = builder.mCarrierConfigAccessRules; 416 this.mAreUiccApplicationsEnabled = builder.mAreUiccApplicationsEnabled; 417 this.mPortIndex = builder.mPortIndex; 418 this.mUsageSetting = builder.mUsageSetting; 419 } 420 421 /** 422 * @return The subscription ID. 423 */ getSubscriptionId()424 public int getSubscriptionId() { 425 return mId; 426 } 427 428 /** 429 * Returns the ICC ID. 430 * 431 * Starting with API level 29 Security Patch 2021-04-05, returns the ICC ID if the calling app 432 * has been granted the READ_PRIVILEGED_PHONE_STATE permission, has carrier privileges (see 433 * {@link TelephonyManager#hasCarrierPrivileges}), or is a device owner or profile owner that 434 * has been granted the READ_PHONE_STATE permission. The profile owner is an app that owns a 435 * managed profile on the device; for more details see <a 436 * href="https://developer.android.com/work/managed-profiles">Work profiles</a>. Profile 437 * owner access is deprecated and will be removed in a future release. 438 * 439 * @return the ICC ID, or an empty string if one of these requirements is not met 440 */ getIccId()441 public String getIccId() { 442 return mIccId; 443 } 444 445 /** 446 * @return The index of the SIM slot that currently contains the subscription and not 447 * necessarily unique and maybe {@link SubscriptionManager#INVALID_SIM_SLOT_INDEX} if unknown or 448 * the subscription is inactive. 449 */ getSimSlotIndex()450 public int getSimSlotIndex() { 451 return mSimSlotIndex; 452 } 453 454 /** 455 * @return The carrier id of this subscription carrier. 456 * 457 * @see TelephonyManager#getSimCarrierId() 458 */ getCarrierId()459 public int getCarrierId() { 460 return mCarrierId; 461 } 462 463 /** 464 * @return The name displayed to the user that identifies this subscription. This name is 465 * used in Settings page and can be renamed by the user. 466 * 467 * @see #getCarrierName() 468 */ getDisplayName()469 public CharSequence getDisplayName() { 470 return mDisplayName; 471 } 472 473 /** 474 * @return The name displayed to the user that identifies subscription provider name. This name 475 * is the SPN displayed in status bar and many other places. Can't be renamed by the user. 476 * 477 * @see #getDisplayName() 478 */ getCarrierName()479 public CharSequence getCarrierName() { 480 return mCarrierName; 481 } 482 483 /** 484 * @return The source of the {@link #getDisplayName()}. 485 * 486 * @hide 487 */ 488 @SimDisplayNameSource getDisplayNameSource()489 public int getDisplayNameSource() { 490 return mDisplayNameSource; 491 } 492 493 /** 494 * Creates and returns an icon {@code Bitmap} to represent this {@code SubscriptionInfo} in a 495 * user interface. 496 * 497 * @param context A {@code Context} to get the {@code DisplayMetrics}s from. 498 * 499 * @return A bitmap icon for this {@code SubscriptionInfo}. 500 */ createIconBitmap(Context context)501 public Bitmap createIconBitmap(Context context) { 502 if (mIconBitmap == null) { 503 mIconBitmap = BitmapFactory.decodeResource(context.getResources(), 504 com.android.internal.R.drawable.ic_sim_card_multi_24px_clr); 505 } 506 int width = mIconBitmap.getWidth(); 507 int height = mIconBitmap.getHeight(); 508 DisplayMetrics metrics = context.getResources().getDisplayMetrics(); 509 510 // Create a new bitmap of the same size because it will be modified. 511 Bitmap workingBitmap = Bitmap.createBitmap(metrics, width, height, mIconBitmap.getConfig()); 512 513 Canvas canvas = new Canvas(workingBitmap); 514 Paint paint = new Paint(); 515 516 // Tint the icon with the color. 517 paint.setColorFilter(new PorterDuffColorFilter(mIconTint, PorterDuff.Mode.SRC_ATOP)); 518 canvas.drawBitmap(mIconBitmap, 0, 0, paint); 519 paint.setColorFilter(null); 520 521 // Write the sim slot index. 522 paint.setAntiAlias(true); 523 paint.setTypeface(Typeface.create("sans-serif", Typeface.NORMAL)); 524 paint.setColor(Color.WHITE); 525 // Set text size scaled by density 526 paint.setTextSize(TEXT_SIZE * metrics.density); 527 // Convert sim slot index to localized string 528 final String index = formatSimple("%d", mSimSlotIndex + 1); 529 final Rect textBound = new Rect(); 530 paint.getTextBounds(index, 0, 1, textBound); 531 final float xOffset = (width / 2.f) - textBound.centerX(); 532 final float yOffset = (height / 2.f) - textBound.centerY(); 533 canvas.drawText(index, xOffset, yOffset, paint); 534 535 return workingBitmap; 536 } 537 538 /** 539 * A highlight color to use in displaying information about this {@code PhoneAccount}. 540 * 541 * @return A hexadecimal color value. 542 */ getIconTint()543 public int getIconTint() { 544 return mIconTint; 545 } 546 547 /** 548 * Returns the number of this subscription. 549 * 550 * Starting with API level 30, returns the number of this subscription if the calling app meets 551 * one of the following requirements: 552 * <ul> 553 * <li>If the calling app's target SDK is API level 29 or lower and the app has been granted 554 * the READ_PHONE_STATE permission. 555 * <li>If the calling app has been granted any of READ_PRIVILEGED_PHONE_STATE, 556 * READ_PHONE_NUMBERS, or READ_SMS. 557 * <li>If the calling app has carrier privileges (see {@link 558 * TelephonyManager#hasCarrierPrivileges}). 559 * <li>If the calling app is the default SMS role holder. 560 * </ul> 561 * 562 * @return the number of this subscription, or an empty string if one of these requirements is 563 * not met 564 * @deprecated use {@link SubscriptionManager#getPhoneNumber(int)} instead, which takes a 565 * {@link #getSubscriptionId() subscription ID}. 566 */ 567 @Deprecated getNumber()568 public String getNumber() { 569 return mNumber; 570 } 571 572 /** 573 * Whether user enables data roaming for this subscription or not. Either 574 * {@link SubscriptionManager#DATA_ROAMING_ENABLE} or 575 * {@link SubscriptionManager#DATA_ROAMING_DISABLE}. 576 */ getDataRoaming()577 public int getDataRoaming() { 578 return mDataRoaming; 579 } 580 581 /** 582 * @return The mobile country code. 583 * 584 * @deprecated Use {@link #getMccString()} instead. 585 */ 586 @Deprecated getMcc()587 public int getMcc() { 588 try { 589 return mMcc == null ? 0 : Integer.parseInt(mMcc); 590 } catch (NumberFormatException e) { 591 Log.w(SubscriptionInfo.class.getSimpleName(), "MCC string is not a number"); 592 return 0; 593 } 594 } 595 596 /** 597 * @return The mobile network code. 598 * 599 * @deprecated Use {@link #getMncString()} instead. 600 */ 601 @Deprecated getMnc()602 public int getMnc() { 603 try { 604 return mMnc == null ? 0 : Integer.parseInt(mMnc); 605 } catch (NumberFormatException e) { 606 Log.w(SubscriptionInfo.class.getSimpleName(), "MNC string is not a number"); 607 return 0; 608 } 609 } 610 611 /** 612 * @return The mobile country code. 613 */ 614 @Nullable getMccString()615 public String getMccString() { 616 return mMcc; 617 } 618 619 /** 620 * @return The mobile network code. 621 */ 622 @Nullable getMncString()623 public String getMncString() { 624 return mMnc; 625 } 626 627 /** 628 * @return The ISO country code. Empty if not available. 629 */ getCountryIso()630 public String getCountryIso() { 631 return mCountryIso; 632 } 633 634 /** 635 * @return {@code true} if the subscription is from eSIM. 636 */ isEmbedded()637 public boolean isEmbedded() { 638 return mIsEmbedded; 639 } 640 641 /** 642 * An opportunistic subscription connects to a network that is 643 * limited in functionality and / or coverage. 644 * 645 * @return Whether subscription is opportunistic. 646 */ isOpportunistic()647 public boolean isOpportunistic() { 648 return mIsOpportunistic; 649 } 650 651 /** 652 * @return {@code true} if the subscription is from the actively used SIM. 653 * 654 * @hide 655 */ isActive()656 public boolean isActive() { 657 return mSimSlotIndex >= 0 || mType == SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM; 658 } 659 660 /** 661 * Used in scenarios where different subscriptions are bundled as a group. 662 * It's typically a primary and an opportunistic subscription. (see {@link #isOpportunistic()}) 663 * Such that those subscriptions will have some affiliated behaviors such as opportunistic 664 * subscription may be invisible to the user. 665 * 666 * @return Group UUID a String of group UUID if it belongs to a group. Otherwise 667 * {@code null}. 668 */ 669 @Nullable getGroupUuid()670 public ParcelUuid getGroupUuid() { 671 return mGroupUuid; 672 } 673 674 /** 675 * @hide 676 */ 677 @NonNull getEhplmns()678 public List<String> getEhplmns() { 679 return Collections.unmodifiableList(mEhplmns == null 680 ? Collections.emptyList() : Arrays.asList(mEhplmns)); 681 } 682 683 /** 684 * @hide 685 */ 686 @NonNull getHplmns()687 public List<String> getHplmns() { 688 return Collections.unmodifiableList(mHplmns == null 689 ? Collections.emptyList() : Arrays.asList(mHplmns)); 690 } 691 692 /** 693 * @return The owner package of group the subscription belongs to. 694 * 695 * @hide 696 */ 697 @NonNull getGroupOwner()698 public String getGroupOwner() { 699 return mGroupOwner; 700 } 701 702 /** 703 * @return The profile class populated from the profile metadata if present. Otherwise, 704 * the profile class defaults to {@link SubscriptionManager#PROFILE_CLASS_UNSET} if there is no 705 * profile metadata or the subscription is not on an eUICC ({@link #isEmbedded} return 706 * {@code false}). 707 * 708 * @hide 709 */ 710 @SystemApi 711 @ProfileClass getProfileClass()712 public int getProfileClass() { 713 return mProfileClass; 714 } 715 716 /** 717 * This method returns the type of a subscription. It can be 718 * {@link SubscriptionManager#SUBSCRIPTION_TYPE_LOCAL_SIM} or 719 * {@link SubscriptionManager#SUBSCRIPTION_TYPE_REMOTE_SIM}. 720 * 721 * @return The type of the subscription. 722 */ 723 @SubscriptionType getSubscriptionType()724 public int getSubscriptionType() { 725 return mType; 726 } 727 728 /** 729 * Checks whether the app with the given context is authorized to manage this subscription 730 * according to its metadata. Only supported for embedded subscriptions (if {@link #isEmbedded} 731 * returns true). 732 * 733 * @param context Context of the application to check. 734 * @return Whether the app is authorized to manage this subscription per its metadata. 735 * @hide 736 * @deprecated - Do not use. 737 */ 738 @Deprecated canManageSubscription(Context context)739 public boolean canManageSubscription(Context context) { 740 return canManageSubscription(context, context.getPackageName()); 741 } 742 743 /** 744 * Checks whether the given app is authorized to manage this subscription according to its 745 * metadata. Only supported for embedded subscriptions (if {@link #isEmbedded} returns true). 746 * 747 * @param context Any context. 748 * @param packageName Package name of the app to check. 749 * @return whether the app is authorized to manage this subscription per its metadata. 750 * @hide 751 * @deprecated - Do not use. 752 */ 753 @Deprecated canManageSubscription(Context context, String packageName)754 public boolean canManageSubscription(Context context, String packageName) { 755 List<UiccAccessRule> allAccessRules = getAccessRules(); 756 if (allAccessRules == null) { 757 return false; 758 } 759 PackageManager packageManager = context.getPackageManager(); 760 PackageInfo packageInfo; 761 try { 762 packageInfo = packageManager.getPackageInfo(packageName, 763 PackageManager.GET_SIGNING_CERTIFICATES); 764 } catch (PackageManager.NameNotFoundException e) { 765 Log.d("SubscriptionInfo", "canManageSubscription: Unknown package: " + packageName, e); 766 return false; 767 } 768 for (UiccAccessRule rule : allAccessRules) { 769 if (rule.getCarrierPrivilegeStatus(packageInfo) 770 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { 771 return true; 772 } 773 } 774 return false; 775 } 776 777 /** 778 * @return The {@link UiccAccessRule}s that are stored in Uicc, dictating who is authorized to 779 * manage this subscription. 780 * 781 * @hide 782 */ 783 @SystemApi 784 @Nullable getAccessRules()785 public List<UiccAccessRule> getAccessRules() { 786 List<UiccAccessRule> merged = new ArrayList<>(); 787 if (mNativeAccessRules != null) { 788 merged.addAll(Arrays.asList(mNativeAccessRules)); 789 } 790 if (mCarrierConfigAccessRules != null) { 791 merged.addAll(Arrays.asList(mCarrierConfigAccessRules)); 792 } 793 return merged.isEmpty() ? null : Collections.unmodifiableList(merged); 794 } 795 796 /** 797 * Returns the card string of the SIM card which contains the subscription. 798 * 799 * Starting with API level 29 Security Patch 2021-04-05, returns the card string if the calling 800 * app has been granted the READ_PRIVILEGED_PHONE_STATE permission, has carrier privileges (see 801 * {@link TelephonyManager#hasCarrierPrivileges}), or is a device owner or profile owner that 802 * has been granted the READ_PHONE_STATE permission. The profile owner is an app that owns a 803 * managed profile on the device; for more details see <a 804 * href="https://developer.android.com/work/managed-profiles">Work profiles</a>. Profile 805 * owner access is deprecated and will be removed in a future release. 806 * 807 * @return The card string of the SIM card which contains the subscription or an empty string 808 * if these requirements are not met. The card string is the ICCID for UICCs or the EID for 809 * eUICCs. 810 * 811 * @hide 812 */ 813 @NonNull getCardString()814 public String getCardString() { 815 return mCardString; 816 } 817 818 /** 819 * @return The card ID of the SIM card which contains the subscription. 820 * 821 * @see UiccCardInfo#getCardId(). 822 */ getCardId()823 public int getCardId() { 824 return mCardId; 825 } 826 /** 827 * @return The port index of the SIM card which contains the subscription. 828 */ getPortIndex()829 public int getPortIndex() { 830 return mPortIndex; 831 } 832 833 /** 834 * @return {@code true} if the group of the subscription is disabled. This is only useful if 835 * it's a grouped opportunistic subscription. In this case, if all primary (non-opportunistic) 836 * subscriptions in the group are deactivated (unplugged pSIM or deactivated eSIM profile), we 837 * should disable this opportunistic subscription. 838 * 839 * @hide 840 */ 841 @SystemApi isGroupDisabled()842 public boolean isGroupDisabled() { 843 return mIsGroupDisabled; 844 } 845 846 /** 847 * @return {@code true} if Uicc applications are set to be enabled or disabled. 848 * @hide 849 */ 850 @SystemApi areUiccApplicationsEnabled()851 public boolean areUiccApplicationsEnabled() { 852 return mAreUiccApplicationsEnabled; 853 } 854 855 /** 856 * Get the usage setting for this subscription. 857 * 858 * @return The usage setting used for this subscription. 859 */ 860 @UsageSetting getUsageSetting()861 public int getUsageSetting() { 862 return mUsageSetting; 863 } 864 865 @NonNull 866 public static final Parcelable.Creator<SubscriptionInfo> CREATOR = 867 new Parcelable.Creator<SubscriptionInfo>() { 868 @Override 869 public SubscriptionInfo createFromParcel(Parcel source) { 870 return new Builder() 871 .setId(source.readInt()) 872 .setIccId(source.readString()) 873 .setSimSlotIndex(source.readInt()) 874 .setDisplayName(TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source)) 875 .setCarrierName(TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source)) 876 .setDisplayNameSource(source.readInt()) 877 .setIconTint(source.readInt()) 878 .setNumber(source.readString()) 879 .setDataRoaming(source.readInt()) 880 .setMcc(source.readString()) 881 .setMnc(source.readString()) 882 .setCountryIso(source.readString()) 883 .setEmbedded(source.readBoolean()) 884 .setNativeAccessRules(source.createTypedArray(UiccAccessRule.CREATOR)) 885 .setCardString(source.readString()) 886 .setCardId(source.readInt()) 887 .setPortIndex(source.readInt()) 888 .setOpportunistic(source.readBoolean()) 889 .setGroupUuid(source.readString8()) 890 .setGroupDisabled(source.readBoolean()) 891 .setCarrierId(source.readInt()) 892 .setProfileClass(source.readInt()) 893 .setType(source.readInt()) 894 .setEhplmns(source.createStringArray()) 895 .setHplmns(source.createStringArray()) 896 .setGroupOwner(source.readString()) 897 .setCarrierConfigAccessRules(source.createTypedArray( 898 UiccAccessRule.CREATOR)) 899 .setUiccApplicationsEnabled(source.readBoolean()) 900 .setUsageSetting(source.readInt()) 901 .build(); 902 } 903 904 @Override 905 public SubscriptionInfo[] newArray(int size) { 906 return new SubscriptionInfo[size]; 907 } 908 }; 909 910 @Override writeToParcel(Parcel dest, int flags)911 public void writeToParcel(Parcel dest, int flags) { 912 dest.writeInt(mId); 913 dest.writeString(mIccId); 914 dest.writeInt(mSimSlotIndex); 915 TextUtils.writeToParcel(mDisplayName, dest, 0); 916 TextUtils.writeToParcel(mCarrierName, dest, 0); 917 dest.writeInt(mDisplayNameSource); 918 dest.writeInt(mIconTint); 919 dest.writeString(mNumber); 920 dest.writeInt(mDataRoaming); 921 dest.writeString(mMcc); 922 dest.writeString(mMnc); 923 dest.writeString(mCountryIso); 924 // Do not write mIconBitmap since it should be lazily loaded on first usage 925 dest.writeBoolean(mIsEmbedded); 926 dest.writeTypedArray(mNativeAccessRules, flags); 927 dest.writeString(mCardString); 928 dest.writeInt(mCardId); 929 dest.writeInt(mPortIndex); 930 dest.writeBoolean(mIsOpportunistic); 931 dest.writeString8(mGroupUuid == null ? null : mGroupUuid.toString()); 932 dest.writeBoolean(mIsGroupDisabled); 933 dest.writeInt(mCarrierId); 934 dest.writeInt(mProfileClass); 935 dest.writeInt(mType); 936 dest.writeStringArray(mEhplmns); 937 dest.writeStringArray(mHplmns); 938 dest.writeString(mGroupOwner); 939 dest.writeTypedArray(mCarrierConfigAccessRules, flags); 940 dest.writeBoolean(mAreUiccApplicationsEnabled); 941 dest.writeInt(mUsageSetting); 942 } 943 944 @Override describeContents()945 public int describeContents() { 946 return 0; 947 } 948 949 /** 950 * Get stripped PII information from the id. 951 * 952 * @param id The raw id (e.g. ICCID, IMSI, etc...). 953 * @return The stripped string. 954 * 955 * @hide 956 */ 957 @Nullable getPrintableId(@ullable String id)958 public static String getPrintableId(@Nullable String id) { 959 String idToPrint = null; 960 if (id != null) { 961 if (id.length() > 9 && !TelephonyUtils.IS_DEBUGGABLE) { 962 idToPrint = id.substring(0, 9) + Rlog.pii(false, id.substring(9)); 963 } else { 964 idToPrint = id; 965 } 966 } 967 return idToPrint; 968 } 969 970 @Override toString()971 public String toString() { 972 String iccIdToPrint = getPrintableId(mIccId); 973 String cardStringToPrint = getPrintableId(mCardString); 974 return "[SubscriptionInfo: id=" + mId 975 + " iccId=" + iccIdToPrint 976 + " simSlotIndex=" + mSimSlotIndex 977 + " portIndex=" + mPortIndex 978 + " isEmbedded=" + mIsEmbedded 979 + " carrierId=" + mCarrierId 980 + " displayName=" + mDisplayName 981 + " carrierName=" + mCarrierName 982 + " isOpportunistic=" + mIsOpportunistic 983 + " groupUuid=" + mGroupUuid 984 + " groupOwner=" + mGroupOwner 985 + " isGroupDisabled=" + mIsGroupDisabled 986 + " displayNameSource=" 987 + SubscriptionManager.displayNameSourceToString(mDisplayNameSource) 988 + " iconTint=" + mIconTint 989 + " number=" + Rlog.pii(TelephonyUtils.IS_DEBUGGABLE, mNumber) 990 + " dataRoaming=" + mDataRoaming 991 + " mcc=" + mMcc 992 + " mnc=" + mMnc 993 + " ehplmns=" + Arrays.toString(mEhplmns) 994 + " hplmns=" + Arrays.toString(mHplmns) 995 + " cardString=" + cardStringToPrint 996 + " cardId=" + mCardId 997 + " nativeAccessRules=" + Arrays.toString(mNativeAccessRules) 998 + " carrierConfigAccessRules=" + Arrays.toString(mCarrierConfigAccessRules) 999 + " countryIso=" + mCountryIso 1000 + " profileClass=" + mProfileClass 1001 + " mType=" + SubscriptionManager.subscriptionTypeToString(mType) 1002 + " areUiccApplicationsEnabled=" + mAreUiccApplicationsEnabled 1003 + " usageSetting=" + SubscriptionManager.usageSettingToString(mUsageSetting) 1004 + "]"; 1005 } 1006 1007 @Override equals(Object o)1008 public boolean equals(Object o) { 1009 if (this == o) return true; 1010 if (o == null || getClass() != o.getClass()) return false; 1011 SubscriptionInfo that = (SubscriptionInfo) o; 1012 return mId == that.mId && mSimSlotIndex == that.mSimSlotIndex 1013 && mDisplayNameSource == that.mDisplayNameSource && mIconTint == that.mIconTint 1014 && mDataRoaming == that.mDataRoaming && mIsEmbedded == that.mIsEmbedded 1015 && mIsOpportunistic == that.mIsOpportunistic && mCarrierId == that.mCarrierId 1016 && mProfileClass == that.mProfileClass && mType == that.mType 1017 && mAreUiccApplicationsEnabled == that.mAreUiccApplicationsEnabled 1018 && mPortIndex == that.mPortIndex && mUsageSetting == that.mUsageSetting 1019 && mCardId == that.mCardId && mIsGroupDisabled == that.mIsGroupDisabled 1020 && mIccId.equals(that.mIccId) && mDisplayName.equals(that.mDisplayName) 1021 && mCarrierName.equals(that.mCarrierName) && mNumber.equals(that.mNumber) 1022 && Objects.equals(mMcc, that.mMcc) && Objects.equals(mMnc, 1023 that.mMnc) && Arrays.equals(mEhplmns, that.mEhplmns) 1024 && Arrays.equals(mHplmns, that.mHplmns) && mCardString.equals( 1025 that.mCardString) && Arrays.equals(mNativeAccessRules, 1026 that.mNativeAccessRules) && Arrays.equals(mCarrierConfigAccessRules, 1027 that.mCarrierConfigAccessRules) && Objects.equals(mGroupUuid, that.mGroupUuid) 1028 && mCountryIso.equals(that.mCountryIso) && mGroupOwner.equals(that.mGroupOwner); 1029 } 1030 1031 @Override hashCode()1032 public int hashCode() { 1033 int result = Objects.hash(mId, mIccId, mSimSlotIndex, mDisplayName, mCarrierName, 1034 mDisplayNameSource, mIconTint, mNumber, mDataRoaming, mMcc, mMnc, mIsEmbedded, 1035 mCardString, mIsOpportunistic, mGroupUuid, mCountryIso, mCarrierId, mProfileClass, 1036 mType, mGroupOwner, mAreUiccApplicationsEnabled, mPortIndex, mUsageSetting, mCardId, 1037 mIsGroupDisabled); 1038 result = 31 * result + Arrays.hashCode(mEhplmns); 1039 result = 31 * result + Arrays.hashCode(mHplmns); 1040 result = 31 * result + Arrays.hashCode(mNativeAccessRules); 1041 result = 31 * result + Arrays.hashCode(mCarrierConfigAccessRules); 1042 return result; 1043 } 1044 1045 /** 1046 * The builder class of {@link SubscriptionInfo}. 1047 * 1048 * @hide 1049 */ 1050 public static class Builder { 1051 /** 1052 * The subscription id. 1053 */ 1054 private int mId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; 1055 1056 /** 1057 * The ICCID of the SIM that is associated with this subscription, empty if unknown. 1058 */ 1059 @NonNull 1060 private String mIccId = ""; 1061 1062 /** 1063 * The index of the SIM slot that currently contains the subscription and not necessarily 1064 * unique and maybe {@link SubscriptionManager#INVALID_SIM_SLOT_INDEX} if unknown or the 1065 * subscription is inactive. 1066 */ 1067 private int mSimSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX; 1068 1069 /** 1070 * The name displayed to the user that identifies this subscription. This name is used 1071 * in Settings page and can be renamed by the user. 1072 */ 1073 @NonNull 1074 private CharSequence mDisplayName = ""; 1075 1076 /** 1077 * The name displayed to the user that identifies subscription provider name. This name 1078 * is the SPN displayed in status bar and many other places. Can't be renamed by the user. 1079 */ 1080 @NonNull 1081 private CharSequence mCarrierName = ""; 1082 1083 /** 1084 * The source of the display name. 1085 */ 1086 @SimDisplayNameSource 1087 private int mDisplayNameSource = SubscriptionManager.NAME_SOURCE_UNKNOWN; 1088 1089 /** 1090 * The color to be used for tinting the icon when displaying to the user. 1091 */ 1092 private int mIconTint = 0; 1093 1094 /** 1095 * The number presented to the user identify this subscription. 1096 */ 1097 @NonNull 1098 private String mNumber = ""; 1099 1100 /** 1101 * Whether user enables data roaming for this subscription or not. Either 1102 * {@link SubscriptionManager#DATA_ROAMING_ENABLE} or 1103 * {@link SubscriptionManager#DATA_ROAMING_DISABLE}. 1104 */ 1105 private int mDataRoaming = SubscriptionManager.DATA_ROAMING_DISABLE; 1106 1107 /** 1108 * SIM icon bitmap cache. 1109 */ 1110 @Nullable 1111 private Bitmap mIconBitmap = null; 1112 1113 /** 1114 * The mobile country code. 1115 */ 1116 @Nullable 1117 private String mMcc = null; 1118 1119 /** 1120 * The mobile network code. 1121 */ 1122 @Nullable 1123 private String mMnc = null; 1124 1125 /** 1126 * EHPLMNs associated with the subscription. 1127 */ 1128 @NonNull 1129 private String[] mEhplmns = new String[0]; 1130 1131 /** 1132 * HPLMNs associated with the subscription. 1133 */ 1134 @NonNull 1135 private String[] mHplmns = new String[0]; 1136 1137 /** 1138 * The ISO Country code for the subscription's provider. 1139 */ 1140 @NonNull 1141 private String mCountryIso = ""; 1142 1143 /** 1144 * Whether the subscription is from eSIM. 1145 */ 1146 private boolean mIsEmbedded = false; 1147 1148 /** 1149 * The native access rules for this subscription, if it is embedded and defines any. This 1150 * does not include access rules for non-embedded subscriptions. 1151 */ 1152 @Nullable 1153 private UiccAccessRule[] mNativeAccessRules = null; 1154 1155 /** 1156 * The card string of the SIM card. 1157 */ 1158 @NonNull 1159 private String mCardString = ""; 1160 1161 /** 1162 * The card ID of the SIM card which contains the subscription. 1163 */ 1164 private int mCardId = TelephonyManager.UNINITIALIZED_CARD_ID; 1165 1166 /** 1167 * Whether the subscription is opportunistic or not. 1168 */ 1169 private boolean mIsOpportunistic = false; 1170 1171 /** 1172 * The group UUID of the subscription group. 1173 */ 1174 @Nullable 1175 private ParcelUuid mGroupUuid = null; 1176 1177 /** 1178 * Whether group of the subscription is disabled. This is only useful if it's a grouped 1179 * opportunistic subscription. In this case, if all primary (non-opportunistic) 1180 * subscriptions in the group are deactivated (unplugged pSIM or deactivated eSIM profile), 1181 * we should disable this opportunistic subscription. 1182 */ 1183 private boolean mIsGroupDisabled = false; 1184 1185 /** 1186 * The carrier id. 1187 * 1188 * @see TelephonyManager#getSimCarrierId() 1189 */ 1190 private int mCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID; 1191 1192 /** 1193 * The profile class populated from the profile metadata if present. Otherwise, the profile 1194 * class defaults to {@link SubscriptionManager#PROFILE_CLASS_UNSET} if there is no profile 1195 * metadata or the subscription is not on an eUICC ({@link #isEmbedded} returns 1196 * {@code false}). 1197 */ 1198 @ProfileClass 1199 private int mProfileClass = SubscriptionManager.PROFILE_CLASS_UNSET; 1200 1201 /** 1202 * The subscription type. 1203 */ 1204 @SubscriptionType 1205 private int mType = SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM; 1206 1207 /** 1208 * The owner package of group the subscription belongs to. 1209 */ 1210 @NonNull 1211 private String mGroupOwner = ""; 1212 1213 /** 1214 * The carrier certificates for this subscription that are saved in carrier configs. 1215 * This does not include access rules from the Uicc, whether embedded or non-embedded. 1216 */ 1217 @Nullable 1218 private UiccAccessRule[] mCarrierConfigAccessRules = null; 1219 1220 /** 1221 * Whether Uicc applications are configured to enable or not. 1222 */ 1223 private boolean mAreUiccApplicationsEnabled = true; 1224 1225 /** 1226 * the port index of the Uicc card. 1227 */ 1228 private int mPortIndex = TelephonyManager.INVALID_PORT_INDEX; 1229 1230 /** 1231 * Subscription's preferred usage setting. 1232 */ 1233 @UsageSetting 1234 private int mUsageSetting = SubscriptionManager.USAGE_SETTING_UNKNOWN; 1235 1236 /** 1237 * Default constructor. 1238 */ Builder()1239 public Builder() { 1240 } 1241 1242 /** 1243 * Constructor from {@link SubscriptionInfo}. 1244 * 1245 * @param info The subscription info. 1246 */ Builder(@onNull SubscriptionInfo info)1247 public Builder(@NonNull SubscriptionInfo info) { 1248 mId = info.mId; 1249 mIccId = info.mIccId; 1250 mSimSlotIndex = info.mSimSlotIndex; 1251 mDisplayName = info.mDisplayName; 1252 mCarrierName = info.mCarrierName; 1253 mDisplayNameSource = info.mDisplayNameSource; 1254 mIconTint = info.mIconTint; 1255 mNumber = info.mNumber; 1256 mDataRoaming = info.mDataRoaming; 1257 mIconBitmap = info.mIconBitmap; 1258 mMcc = info.mMcc; 1259 mMnc = info.mMnc; 1260 mEhplmns = info.mEhplmns; 1261 mHplmns = info.mHplmns; 1262 mCountryIso = info.mCountryIso; 1263 mIsEmbedded = info.mIsEmbedded; 1264 mNativeAccessRules = info.mNativeAccessRules; 1265 mCardString = info.mCardString; 1266 mCardId = info.mCardId; 1267 mIsOpportunistic = info.mIsOpportunistic; 1268 mGroupUuid = info.mGroupUuid; 1269 mIsGroupDisabled = info.mIsGroupDisabled; 1270 mCarrierId = info.mCarrierId; 1271 mProfileClass = info.mProfileClass; 1272 mType = info.mType; 1273 mGroupOwner = info.mGroupOwner; 1274 mCarrierConfigAccessRules = info.mCarrierConfigAccessRules; 1275 mAreUiccApplicationsEnabled = info.mAreUiccApplicationsEnabled; 1276 mPortIndex = info.mPortIndex; 1277 mUsageSetting = info.mUsageSetting; 1278 } 1279 1280 /** 1281 * Set the subscription id. 1282 * 1283 * @param id The subscription id. 1284 * @return The builder. 1285 */ 1286 @NonNull setId(int id)1287 public Builder setId(int id) { 1288 mId = id; 1289 return this; 1290 } 1291 1292 /** 1293 * Set the ICCID of the SIM that is associated with this subscription. 1294 * 1295 * @param iccId The ICCID of the SIM that is associated with this subscription. 1296 * @return The builder. 1297 */ 1298 @NonNull setIccId(@ullable String iccId)1299 public Builder setIccId(@Nullable String iccId) { 1300 mIccId = TextUtils.emptyIfNull(iccId); 1301 return this; 1302 } 1303 1304 /** 1305 * Set the SIM index of the slot that currently contains the subscription. Set to 1306 * {@link SubscriptionManager#INVALID_SIM_SLOT_INDEX} if the subscription is inactive. 1307 * 1308 * @param simSlotIndex The SIM slot index. 1309 * @return The builder. 1310 */ 1311 @NonNull setSimSlotIndex(int simSlotIndex)1312 public Builder setSimSlotIndex(int simSlotIndex) { 1313 mSimSlotIndex = simSlotIndex; 1314 return this; 1315 } 1316 1317 /** 1318 * The name displayed to the user that identifies this subscription. This name is used 1319 * in Settings page and can be renamed by the user. 1320 * 1321 * @param displayName The display name. 1322 * @return The builder. 1323 */ 1324 @NonNull setDisplayName(@ullable CharSequence displayName)1325 public Builder setDisplayName(@Nullable CharSequence displayName) { 1326 mDisplayName = displayName == null ? "" : displayName; 1327 return this; 1328 } 1329 1330 /** 1331 * The name displayed to the user that identifies subscription provider name. This name 1332 * is the SPN displayed in status bar and many other places. Can't be renamed by the user. 1333 * 1334 * @param carrierName The carrier name. 1335 * @return The builder. 1336 */ 1337 @NonNull setCarrierName(@ullable CharSequence carrierName)1338 public Builder setCarrierName(@Nullable CharSequence carrierName) { 1339 mCarrierName = carrierName == null ? "" : carrierName; 1340 return this; 1341 } 1342 1343 /** 1344 * Set the source of the display name. 1345 * 1346 * @param displayNameSource The source of the display name. 1347 * @return The builder. 1348 * 1349 * @see SubscriptionInfo#getDisplayName() 1350 */ 1351 @NonNull setDisplayNameSource(@imDisplayNameSource int displayNameSource)1352 public Builder setDisplayNameSource(@SimDisplayNameSource int displayNameSource) { 1353 mDisplayNameSource = displayNameSource; 1354 return this; 1355 } 1356 1357 /** 1358 * Set the color to be used for tinting the icon when displaying to the user. 1359 * 1360 * @param iconTint The color to be used for tinting the icon when displaying to the user. 1361 * @return The builder. 1362 */ 1363 @NonNull setIconTint(int iconTint)1364 public Builder setIconTint(int iconTint) { 1365 mIconTint = iconTint; 1366 return this; 1367 } 1368 1369 /** 1370 * Set the number presented to the user identify this subscription. 1371 * 1372 * @param number the number presented to the user identify this subscription. 1373 * @return The builder. 1374 */ 1375 @NonNull setNumber(@ullable String number)1376 public Builder setNumber(@Nullable String number) { 1377 mNumber = TextUtils.emptyIfNull(number); 1378 return this; 1379 } 1380 1381 /** 1382 * Set whether user enables data roaming for this subscription or not. 1383 * 1384 * @param dataRoaming Data roaming mode. Either 1385 * {@link SubscriptionManager#DATA_ROAMING_ENABLE} or 1386 * {@link SubscriptionManager#DATA_ROAMING_DISABLE} 1387 * @return The builder. 1388 */ 1389 @NonNull setDataRoaming(int dataRoaming)1390 public Builder setDataRoaming(int dataRoaming) { 1391 mDataRoaming = dataRoaming; 1392 return this; 1393 } 1394 1395 /** 1396 * Set SIM icon bitmap cache. 1397 * 1398 * @param iconBitmap SIM icon bitmap cache. 1399 * @return The builder. 1400 */ 1401 @NonNull setIcon(@ullable Bitmap iconBitmap)1402 public Builder setIcon(@Nullable Bitmap iconBitmap) { 1403 mIconBitmap = iconBitmap; 1404 return this; 1405 } 1406 1407 /** 1408 * Set the mobile country code. 1409 * 1410 * @param mcc The mobile country code. 1411 * @return The builder. 1412 */ 1413 @NonNull setMcc(@ullable String mcc)1414 public Builder setMcc(@Nullable String mcc) { 1415 mMcc = mcc; 1416 return this; 1417 } 1418 1419 /** 1420 * Set the mobile network code. 1421 * 1422 * @param mnc Mobile network code. 1423 * @return The builder. 1424 */ 1425 @NonNull setMnc(@ullable String mnc)1426 public Builder setMnc(@Nullable String mnc) { 1427 mMnc = mnc; 1428 return this; 1429 } 1430 1431 /** 1432 * Set EHPLMNs associated with the subscription. 1433 * 1434 * @param ehplmns EHPLMNs associated with the subscription. 1435 * @return The builder. 1436 */ 1437 @NonNull setEhplmns(@ullable String[] ehplmns)1438 public Builder setEhplmns(@Nullable String[] ehplmns) { 1439 mEhplmns = ehplmns == null ? new String[0] : ehplmns; 1440 return this; 1441 } 1442 1443 /** 1444 * Set HPLMNs associated with the subscription. 1445 * 1446 * @param hplmns HPLMNs associated with the subscription. 1447 * @return The builder. 1448 */ 1449 @NonNull setHplmns(@ullable String[] hplmns)1450 public Builder setHplmns(@Nullable String[] hplmns) { 1451 mHplmns = hplmns == null ? new String[0] : hplmns; 1452 return this; 1453 } 1454 1455 /** 1456 * Set the ISO country code for the subscription's provider. 1457 * 1458 * @param countryIso The ISO country code for the subscription's provider. 1459 * @return The builder. 1460 */ 1461 @NonNull setCountryIso(@ullable String countryIso)1462 public Builder setCountryIso(@Nullable String countryIso) { 1463 mCountryIso = TextUtils.emptyIfNull(countryIso); 1464 return this; 1465 } 1466 1467 /** 1468 * Set whether the subscription is from eSIM or not. 1469 * 1470 * @param isEmbedded {@code true} if the subscription is from eSIM. 1471 * @return The builder. 1472 */ 1473 @NonNull setEmbedded(boolean isEmbedded)1474 public Builder setEmbedded(boolean isEmbedded) { 1475 mIsEmbedded = isEmbedded; 1476 return this; 1477 } 1478 1479 /** 1480 * Set the native access rules for this subscription, if it is embedded and defines any. 1481 * This does not include access rules for non-embedded subscriptions. 1482 * 1483 * @param nativeAccessRules The native access rules for this subscription. 1484 * @return The builder. 1485 */ 1486 @NonNull setNativeAccessRules(@ullable UiccAccessRule[] nativeAccessRules)1487 public Builder setNativeAccessRules(@Nullable UiccAccessRule[] nativeAccessRules) { 1488 mNativeAccessRules = nativeAccessRules; 1489 return this; 1490 } 1491 1492 /** 1493 * Set the card string of the SIM card. 1494 * 1495 * @param cardString The card string of the SIM card. 1496 * @return The builder. 1497 * 1498 * @see #getCardString() 1499 */ 1500 @NonNull setCardString(@ullable String cardString)1501 public Builder setCardString(@Nullable String cardString) { 1502 mCardString = TextUtils.emptyIfNull(cardString); 1503 return this; 1504 } 1505 1506 /** 1507 * Set the card ID of the SIM card which contains the subscription. 1508 * 1509 * @param cardId The card ID of the SIM card which contains the subscription. 1510 * @return The builder. 1511 */ 1512 @NonNull setCardId(int cardId)1513 public Builder setCardId(int cardId) { 1514 mCardId = cardId; 1515 return this; 1516 } 1517 1518 /** 1519 * Set whether the subscription is opportunistic or not. 1520 * 1521 * @param isOpportunistic {@code true} if the subscription is opportunistic. 1522 * @return The builder. 1523 */ 1524 @NonNull setOpportunistic(boolean isOpportunistic)1525 public Builder setOpportunistic(boolean isOpportunistic) { 1526 mIsOpportunistic = isOpportunistic; 1527 return this; 1528 } 1529 1530 /** 1531 * Set the group UUID of the subscription group. 1532 * 1533 * @param groupUuid The group UUID. 1534 * @return The builder. 1535 * 1536 * @see #getGroupUuid() 1537 */ 1538 @NonNull setGroupUuid(@ullable String groupUuid)1539 public Builder setGroupUuid(@Nullable String groupUuid) { 1540 mGroupUuid = TextUtils.isEmpty(groupUuid) ? null : ParcelUuid.fromString(groupUuid); 1541 return this; 1542 } 1543 1544 /** 1545 * Whether group of the subscription is disabled. This is only useful if it's a grouped 1546 * opportunistic subscription. In this case, if all primary (non-opportunistic) 1547 * subscriptions in the group are deactivated (unplugged pSIM or deactivated eSIM profile), 1548 * we should disable this opportunistic subscription. 1549 * 1550 * @param isGroupDisabled {@code true} if group of the subscription is disabled. 1551 * @return The builder. 1552 */ 1553 @NonNull setGroupDisabled(boolean isGroupDisabled)1554 public Builder setGroupDisabled(boolean isGroupDisabled) { 1555 mIsGroupDisabled = isGroupDisabled; 1556 return this; 1557 } 1558 1559 /** 1560 * Set the subscription carrier id. 1561 * 1562 * @param carrierId The carrier id. 1563 * @return The builder 1564 * 1565 * @see TelephonyManager#getSimCarrierId() 1566 */ 1567 @NonNull setCarrierId(int carrierId)1568 public Builder setCarrierId(int carrierId) { 1569 mCarrierId = carrierId; 1570 return this; 1571 } 1572 1573 /** 1574 * Set the profile class populated from the profile metadata if present. 1575 * 1576 * @param profileClass the profile class populated from the profile metadata if present. 1577 * @return The builder 1578 * 1579 * @see #getProfileClass() 1580 */ 1581 @NonNull setProfileClass(@rofileClass int profileClass)1582 public Builder setProfileClass(@ProfileClass int profileClass) { 1583 mProfileClass = profileClass; 1584 return this; 1585 } 1586 1587 /** 1588 * Set the subscription type. 1589 * 1590 * @param type Subscription type. 1591 * @return The builder. 1592 */ 1593 @NonNull setType(@ubscriptionType int type)1594 public Builder setType(@SubscriptionType int type) { 1595 mType = type; 1596 return this; 1597 } 1598 1599 /** 1600 * Set the owner package of group the subscription belongs to. 1601 * 1602 * @param groupOwner Owner package of group the subscription belongs to. 1603 * @return The builder. 1604 */ 1605 @NonNull setGroupOwner(@ullable String groupOwner)1606 public Builder setGroupOwner(@Nullable String groupOwner) { 1607 mGroupOwner = TextUtils.emptyIfNull(groupOwner); 1608 return this; 1609 } 1610 1611 /** 1612 * Set the carrier certificates for this subscription that are saved in carrier configs. 1613 * This does not include access rules from the Uicc, whether embedded or non-embedded. 1614 * 1615 * @param carrierConfigAccessRules The carrier certificates for this subscription. 1616 * @return The builder. 1617 */ 1618 @NonNull setCarrierConfigAccessRules( @ullable UiccAccessRule[] carrierConfigAccessRules)1619 public Builder setCarrierConfigAccessRules( 1620 @Nullable UiccAccessRule[] carrierConfigAccessRules) { 1621 mCarrierConfigAccessRules = carrierConfigAccessRules; 1622 return this; 1623 } 1624 1625 /** 1626 * Set whether Uicc applications are configured to enable or not. 1627 * 1628 * @param uiccApplicationsEnabled {@code true} if Uicc applications are configured to 1629 * enable. 1630 * @return The builder. 1631 */ 1632 @NonNull setUiccApplicationsEnabled(boolean uiccApplicationsEnabled)1633 public Builder setUiccApplicationsEnabled(boolean uiccApplicationsEnabled) { 1634 mAreUiccApplicationsEnabled = uiccApplicationsEnabled; 1635 return this; 1636 } 1637 1638 /** 1639 * Set the port index of the Uicc card. 1640 * 1641 * @param portIndex The port index of the Uicc card. 1642 * @return The builder. 1643 */ 1644 @NonNull setPortIndex(int portIndex)1645 public Builder setPortIndex(int portIndex) { 1646 mPortIndex = portIndex; 1647 return this; 1648 } 1649 1650 /** 1651 * Set subscription's preferred usage setting. 1652 * 1653 * @param usageSetting Subscription's preferred usage setting. 1654 * @return The builder. 1655 */ 1656 @NonNull setUsageSetting(@sageSetting int usageSetting)1657 public Builder setUsageSetting(@UsageSetting int usageSetting) { 1658 mUsageSetting = usageSetting; 1659 return this; 1660 } 1661 1662 /** 1663 * Build the {@link SubscriptionInfo}. 1664 * 1665 * @return The {@link SubscriptionInfo} instance. 1666 */ build()1667 public SubscriptionInfo build() { 1668 return new SubscriptionInfo(this); 1669 } 1670 } 1671 } 1672