diff options
| author | 2023-02-27 20:49:55 +0000 | |
|---|---|---|
| committer | 2023-02-27 20:49:55 +0000 | |
| commit | f3db9c87d38c67a4e5423511814df5a4d0af6799 (patch) | |
| tree | 1f56727a90c218d6584f52d02210bb54d88907e6 | |
| parent | e64ef5a13e7e8a8e463e335246ab180d95d49091 (diff) | |
| parent | 20f007c38c217ba76959925e21ae612547deb3fa (diff) | |
Merge changes from topics "subscriptionInfo_builder", "subscription_manager_service" am: 20f007c38c
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2457667
Change-Id: I5d7bbc92107cad09e1d109e1a85f5c8828dd18f9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | telephony/java/android/telephony/SubscriptionInfo.java | 1223 | ||||
| -rw-r--r-- | telephony/java/android/telephony/SubscriptionManager.java | 4 |
2 files changed, 932 insertions, 295 deletions
diff --git a/telephony/java/android/telephony/SubscriptionInfo.java b/telephony/java/android/telephony/SubscriptionInfo.java index cb985bf2cda5..eb96d3739119 100644 --- a/telephony/java/android/telephony/SubscriptionInfo.java +++ b/telephony/java/android/telephony/SubscriptionInfo.java @@ -18,6 +18,7 @@ package android.telephony; import static android.text.TextUtils.formatSimple; +import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; import android.compat.annotation.UnsupportedAppUsage; @@ -37,6 +38,9 @@ import android.os.Build; import android.os.Parcel; import android.os.ParcelUuid; import android.os.Parcelable; +import android.telephony.SubscriptionManager.ProfileClass; +import android.telephony.SubscriptionManager.SimDisplayNameSource; +import android.telephony.SubscriptionManager.SubscriptionType; import android.telephony.SubscriptionManager.UsageSetting; import android.text.TextUtils; import android.util.DisplayMetrics; @@ -55,7 +59,6 @@ import java.util.Objects; * A Parcelable class for Subscription Information. */ public class SubscriptionInfo implements Parcelable { - /** * Size of text to render on the icon. */ @@ -65,162 +68,180 @@ public class SubscriptionInfo implements Parcelable { * Subscription Identifier, this is a device unique number * and not an index into an array */ - private int mId; + private final int mId; /** - * The GID for a SIM that maybe associated with this subscription, empty if unknown + * The ICCID of the SIM that is associated with this subscription, empty if unknown. */ - private String mIccId; + @NonNull + private final String mIccId; /** - * The index of the slot that currently contains the subscription - * and not necessarily unique and maybe INVALID_SLOT_ID if unknown + * The index of the SIM slot that currently contains the subscription and not necessarily unique + * and maybe {@link SubscriptionManager#INVALID_SIM_SLOT_INDEX} if unknown or the subscription + * is inactive. */ - private int mSimSlotIndex; + private final int mSimSlotIndex; /** - * The name displayed to the user that identifies this subscription + * The name displayed to the user that identifies this subscription. This name is used + * in Settings page and can be renamed by the user. */ - private CharSequence mDisplayName; + @NonNull + private final CharSequence mDisplayName; /** - * String that identifies SPN/PLMN - * TODO : Add a new field that identifies only SPN for a sim + * The name displayed to the user that identifies subscription provider name. This name is the + * SPN displayed in status bar and many other places. Can't be renamed by the user. */ - private CharSequence mCarrierName; + @NonNull + private final CharSequence mCarrierName; /** * The subscription carrier id. + * * @see TelephonyManager#getSimCarrierId() */ - private int mCarrierId; + private final int mCarrierId; /** - * The source of the name, NAME_SOURCE_DEFAULT_SOURCE, NAME_SOURCE_SIM_SPN, - * NAME_SOURCE_SIM_PNN, or NAME_SOURCE_USER_INPUT. + * The source of the {@link #mCarrierName}. */ - private int mNameSource; + @SimDisplayNameSource + private final int mNameSource; /** - * The color to be used for tinting the icon when displaying to the user + * The color to be used for tinting the icon when displaying to the user. */ - private int mIconTint; + private final int mIconTint; /** - * A number presented to the user identify this subscription + * The number presented to the user identify this subscription. */ - private String mNumber; + @NonNull + private final String mNumber; /** - * Data roaming state, DATA_ROAMING_ENABLE, DATA_ROAMING_DISABLE + * Whether user enables data roaming for this subscription or not. Either + * {@link SubscriptionManager#DATA_ROAMING_ENABLE} or + * {@link SubscriptionManager#DATA_ROAMING_DISABLE}. */ - private int mDataRoaming; + private final int mDataRoaming; /** - * SIM icon bitmap cache + * SIM icon bitmap cache. */ - @Nullable private Bitmap mIconBitmap; + @Nullable + private Bitmap mIconBitmap; /** - * Mobile Country Code + * Mobile Country Code. */ - private String mMcc; + @Nullable + private final String mMcc; /** - * Mobile Network Code + * Mobile Network Code. */ - private String mMnc; + @Nullable + private final String mMnc; /** - * EHPLMNs associated with the subscription + * EHPLMNs associated with the subscription. */ - private String[] mEhplmns; + @NonNull + private final String[] mEhplmns; /** - * HPLMNs associated with the subscription + * HPLMNs associated with the subscription. */ - private String[] mHplmns; + @NonNull + private final String[] mHplmns; /** - * ISO Country code for the subscription's provider + * ISO Country code for the subscription's provider. */ - private String mCountryIso; + @NonNull + private final String mCountryIso; /** - * Whether the subscription is an embedded one. + * Whether the subscription is from eSIM. */ - private boolean mIsEmbedded; + private final boolean mIsEmbedded; /** - * The access rules for this subscription, if it is embedded and defines any. - * This does not include access rules for non-embedded subscriptions. + * The access rules for this subscription, if it is embedded and defines any. This does not + * include access rules for non-embedded subscriptions. */ @Nullable - private UiccAccessRule[] mNativeAccessRules; + private final UiccAccessRule[] mNativeAccessRules; /** * The carrier certificates for this subscription that are saved in carrier configs. * This does not include access rules from the Uicc, whether embedded or non-embedded. */ @Nullable - private UiccAccessRule[] mCarrierConfigAccessRules; + private final UiccAccessRule[] mCarrierConfigAccessRules; /** * The string ID of the SIM card. It is the ICCID of the active profile for a UICC card and the * EID for an eUICC card. */ - private String mCardString; + @NonNull + private final String mCardString; /** - * The card ID of the SIM card. This maps uniquely to the card string. + * The card ID of the SIM card. This maps uniquely to {@link #mCardString}. */ - private int mCardId; + private final int mCardId; /** * Whether the subscription is opportunistic. */ - private boolean mIsOpportunistic; + private final boolean mIsOpportunistic; /** - * A UUID assigned to the subscription group. It returns null if not assigned. - * Check {@link SubscriptionManager#createSubscriptionGroup(List)} for more details. + * A UUID assigned to the subscription group. {@code null} if not assigned. + * + * @see SubscriptionManager#createSubscriptionGroup(List) */ @Nullable - private ParcelUuid mGroupUUID; + private final ParcelUuid mGroupUuid; /** - * A package name that specifies who created the group. Null if mGroupUUID is null. + * A package name that specifies who created the group. Empty if not available. */ - private String mGroupOwner; + @NonNull + private final String mGroupOwner; /** - * Whether group of the subscription is disabled. - * This is only useful if it's a grouped opportunistic subscription. In this case, if all - * primary (non-opportunistic) subscriptions in the group are deactivated (unplugged pSIM - * or deactivated eSIM profile), we should disable this opportunistic subscription. + * Whether group of the subscription is disabled. This is only useful if it's a grouped + * opportunistic subscription. In this case, if all primary (non-opportunistic) subscriptions + * in the group are deactivated (unplugged pSIM or deactivated eSIM profile), we should disable + * this opportunistic subscription. */ - private boolean mIsGroupDisabled = false; + private final boolean mIsGroupDisabled; /** - * Profile class, PROFILE_CLASS_TESTING, PROFILE_CLASS_OPERATIONAL - * PROFILE_CLASS_PROVISIONING, or PROFILE_CLASS_UNSET. - * A profile on the eUICC can be defined as test, operational, provisioning, or unset. - * The profile class will be populated from the profile metadata if present. Otherwise, - * the profile class defaults to unset if there is no profile metadata or the subscription - * is not on an eUICC ({@link #isEmbedded} returns false). + * The profile class populated from the profile metadata if present. Otherwise, + * the profile class defaults to {@link SubscriptionManager#PROFILE_CLASS_UNSET} if there is no + * profile metadata or the subscription is not on an eUICC ({@link #isEmbedded} returns + * {@code false}). */ - private int mProfileClass; + @ProfileClass + private final int mProfileClass; /** - * Type of subscription + * Type of the subscription. */ - private int mSubscriptionType; + @SubscriptionType + private final int mType; /** * Whether uicc applications are configured to enable or disable. * By default it's true. */ - private boolean mAreUiccApplicationsEnabled = true; + private final boolean mAreUiccApplicationsEnabled; /** * The port index of the Uicc card. @@ -230,25 +251,16 @@ public class SubscriptionInfo implements Parcelable { /** * Subscription's preferred usage setting. */ - private @UsageSetting int mUsageSetting = SubscriptionManager.USAGE_SETTING_UNKNOWN; - - /** - * Public copy constructor. - * @hide - */ - public SubscriptionInfo(SubscriptionInfo info) { - this(info.mId, info.mIccId, info.mSimSlotIndex, info.mDisplayName, info.mCarrierName, - info.mNameSource, info.mIconTint, info.mNumber, info.mDataRoaming, info.mIconBitmap, - info.mMcc, info.mMnc, info.mCountryIso, info.mIsEmbedded, info.mNativeAccessRules, - info.mCardString, info.mCardId, info.mIsOpportunistic, - info.mGroupUUID == null ? null : info.mGroupUUID.toString(), info.mIsGroupDisabled, - info.mCarrierId, info.mProfileClass, info.mSubscriptionType, info.mGroupOwner, - info.mCarrierConfigAccessRules, info.mAreUiccApplicationsEnabled); - } + @UsageSetting + private final int mUsageSetting; /** * @hide + * + * @deprecated Use {@link SubscriptionInfo.Builder}. */ + // TODO: Clean up after external usages moved to builder model. + @Deprecated public 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, @@ -262,7 +274,11 @@ public class SubscriptionInfo implements Parcelable { /** * @hide + * + * @deprecated Use {@link SubscriptionInfo.Builder}. */ + // TODO: Clean up after external usages moved to builder model. + @Deprecated public 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, @@ -276,7 +292,11 @@ public class SubscriptionInfo implements Parcelable { /** * @hide + * + * @deprecated Use {@link SubscriptionInfo.Builder}. */ + // TODO: Clean up after external usages moved to builder model. + @Deprecated public 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, @@ -293,7 +313,11 @@ public class SubscriptionInfo implements Parcelable { /** * @hide + * + * @deprecated Use {@link SubscriptionInfo.Builder}. */ + // TODO: Clean up after external usages moved to builder model. + @Deprecated public 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, @@ -311,49 +335,94 @@ public class SubscriptionInfo implements Parcelable { /** * @hide + * + * @deprecated Use {@link SubscriptionInfo.Builder}. */ + // TODO: Clean up after external usages moved to builder model. + @Deprecated public 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, + 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) { this.mId = id; this.mIccId = iccId; this.mSimSlotIndex = simSlotIndex; - this.mDisplayName = displayName; + this.mDisplayName = displayName; this.mCarrierName = carrierName; this.mNameSource = nameSource; this.mIconTint = iconTint; this.mNumber = number; this.mDataRoaming = roaming; this.mIconBitmap = icon; - this.mMcc = mcc; - this.mMnc = mnc; - this.mCountryIso = countryIso; + this.mMcc = TextUtils.emptyIfNull(mcc); + this.mMnc = TextUtils.emptyIfNull(mnc); + this.mHplmns = null; + this.mEhplmns = null; + this.mCountryIso = TextUtils.emptyIfNull(countryIso); this.mIsEmbedded = isEmbedded; this.mNativeAccessRules = nativeAccessRules; - this.mCardString = cardString; + this.mCardString = TextUtils.emptyIfNull(cardString); this.mCardId = cardId; this.mIsOpportunistic = isOpportunistic; - this.mGroupUUID = groupUUID == null ? null : ParcelUuid.fromString(groupUUID); + this.mGroupUuid = groupUuid == null ? null : ParcelUuid.fromString(groupUuid); this.mIsGroupDisabled = isGroupDisabled; this.mCarrierId = carrierId; this.mProfileClass = profileClass; - this.mSubscriptionType = subType; - this.mGroupOwner = groupOwner; + this.mType = subType; + this.mGroupOwner = TextUtils.emptyIfNull(groupOwner); this.mCarrierConfigAccessRules = carrierConfigAccessRules; this.mAreUiccApplicationsEnabled = areUiccApplicationsEnabled; this.mPortIndex = portIndex; this.mUsageSetting = usageSetting; } + /** - * @return the subscription ID. + * Constructor from builder. + * + * @param builder Builder of {@link SubscriptionInfo}. + */ + private SubscriptionInfo(@NonNull Builder builder) { + this.mId = builder.mId; + this.mIccId = builder.mIccId; + this.mSimSlotIndex = builder.mSimSlotIndex; + this.mDisplayName = builder.mDisplayName; + this.mCarrierName = builder.mCarrierName; + this.mNameSource = builder.mNameSource; + this.mIconTint = builder.mIconTint; + this.mNumber = builder.mNumber; + this.mDataRoaming = builder.mDataRoaming; + this.mIconBitmap = builder.mIconBitmap; + this.mMcc = builder.mMcc; + this.mMnc = builder.mMnc; + this.mEhplmns = builder.mEhplmns; + this.mHplmns = builder.mHplmns; + this.mCountryIso = builder.mCountryIso; + this.mIsEmbedded = builder.mIsEmbedded; + this.mNativeAccessRules = builder.mNativeAccessRules; + this.mCardString = builder.mCardString; + this.mCardId = builder.mCardId; + this.mIsOpportunistic = builder.mIsOpportunistic; + this.mGroupUuid = builder.mGroupUuid; + this.mIsGroupDisabled = builder.mIsGroupDisabled; + this.mCarrierId = builder.mCarrierId; + this.mProfileClass = builder.mProfileClass; + this.mType = builder.mType; + this.mGroupOwner = builder.mGroupOwner; + this.mCarrierConfigAccessRules = builder.mCarrierConfigAccessRules; + this.mAreUiccApplicationsEnabled = builder.mAreUiccApplicationsEnabled; + this.mPortIndex = builder.mPortIndex; + this.mUsageSetting = builder.mUsageSetting; + } + + /** + * @return The subscription ID. */ public int getSubscriptionId() { - return this.mId; + return mId; } /** @@ -370,78 +439,56 @@ public class SubscriptionInfo implements Parcelable { * @return the ICC ID, or an empty string if one of these requirements is not met */ public String getIccId() { - return this.mIccId; + return mIccId; } /** - * @hide - */ - public void clearIccId() { - this.mIccId = ""; - } - - /** - * @return the slot index of this Subscription's SIM card. + * @return The index of the SIM slot that currently contains the subscription and not + * necessarily unique and maybe {@link SubscriptionManager#INVALID_SIM_SLOT_INDEX} if unknown or + * the subscription is inactive. */ public int getSimSlotIndex() { - return this.mSimSlotIndex; + return mSimSlotIndex; } /** - * @return the carrier id of this Subscription carrier. + * @return The carrier id of this subscription carrier. + * * @see TelephonyManager#getSimCarrierId() */ public int getCarrierId() { - return this.mCarrierId; + return mCarrierId; } /** - * @return the name displayed to the user that identifies this subscription + * @return The name displayed to the user that identifies this subscription. This name is + * used in Settings page and can be renamed by the user. + * + * @see #getCarrierName() */ public CharSequence getDisplayName() { - return this.mDisplayName; + return mDisplayName; } /** - * Sets the name displayed to the user that identifies this subscription - * @hide - */ - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) - public void setDisplayName(CharSequence name) { - this.mDisplayName = name; - } - - /** - * @return the name displayed to the user that identifies Subscription provider name + * @return The name displayed to the user that identifies subscription provider name. This name + * is the SPN displayed in status bar and many other places. Can't be renamed by the user. + * + * @see #getDisplayName() */ public CharSequence getCarrierName() { - return this.mCarrierName; - } - - /** - * Sets the name displayed to the user that identifies Subscription provider name - * @hide - */ - public void setCarrierName(CharSequence name) { - this.mCarrierName = name; + return mCarrierName; } /** - * @return the source of the name, eg NAME_SOURCE_DEFAULT_SOURCE, NAME_SOURCE_SIM_SPN or - * NAME_SOURCE_USER_INPUT. + * @return The source of the {@link #getCarrierName()}. + * * @hide */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + @SimDisplayNameSource public int getNameSource() { - return this.mNameSource; - } - - /** - * @hide - */ - public void setAssociatedPlmns(String[] ehplmns, String[] hplmns) { - mEhplmns = ehplmns; - mHplmns = hplmns; + return mNameSource; } /** @@ -499,15 +546,6 @@ public class SubscriptionInfo implements Parcelable { } /** - * Sets the color displayed to the user that identifies this subscription - * @hide - */ - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) - public void setIconTint(int iconTint) { - this.mIconTint = iconTint; - } - - /** * Returns the number of this subscription. * * Starting with API level 30, returns the number of this subscription if the calling app meets @@ -533,28 +571,23 @@ public class SubscriptionInfo implements Parcelable { } /** - * @hide - */ - public void clearNumber() { - mNumber = ""; - } - - /** - * @return the data roaming state for this subscription, either - * {@link SubscriptionManager#DATA_ROAMING_ENABLE} or {@link SubscriptionManager#DATA_ROAMING_DISABLE}. + * Whether user enables data roaming for this subscription or not. Either + * {@link SubscriptionManager#DATA_ROAMING_ENABLE} or + * {@link SubscriptionManager#DATA_ROAMING_DISABLE}. */ public int getDataRoaming() { - return this.mDataRoaming; + return mDataRoaming; } /** - * @return the MCC. + * @return The mobile country code. + * * @deprecated Use {@link #getMccString()} instead. */ @Deprecated public int getMcc() { try { - return this.mMcc == null ? 0 : Integer.valueOf(this.mMcc); + return mMcc == null ? 0 : Integer.parseInt(mMcc); } catch (NumberFormatException e) { Log.w(SubscriptionInfo.class.getSimpleName(), "MCC string is not a number"); return 0; @@ -562,13 +595,14 @@ public class SubscriptionInfo implements Parcelable { } /** - * @return the MNC. + * @return The mobile network code. + * * @deprecated Use {@link #getMncString()} instead. */ @Deprecated public int getMnc() { try { - return this.mMnc == null ? 0 : Integer.valueOf(this.mMnc); + return mMnc == null ? 0 : Integer.parseInt(mMnc); } catch (NumberFormatException e) { Log.w(SubscriptionInfo.class.getSimpleName(), "MNC string is not a number"); return 0; @@ -576,36 +610,40 @@ public class SubscriptionInfo implements Parcelable { } /** - * @return The MCC, as a string. + * @return The mobile country code. */ - public @Nullable String getMccString() { - return this.mMcc; + @Nullable + public String getMccString() { + return mMcc; } /** - * @return The MNC, as a string. + * @return The mobile network code. */ - public @Nullable String getMncString() { - return this.mMnc; + @Nullable + public String getMncString() { + return mMnc; } /** - * @return the ISO country code + * @return The ISO country code. Empty if not available. */ public String getCountryIso() { - return this.mCountryIso; + return mCountryIso; } - /** @return whether the subscription is an eUICC one. */ + /** + * @return {@code true} if the subscription is from eSIM. + */ public boolean isEmbedded() { - return this.mIsEmbedded; + return mIsEmbedded; } /** * An opportunistic subscription connects to a network that is * limited in functionality and / or coverage. * - * @return whether subscription is opportunistic. + * @return Whether subscription is opportunistic. */ public boolean isOpportunistic() { return mIsOpportunistic; @@ -617,23 +655,18 @@ public class SubscriptionInfo implements Parcelable { * Such that those subscriptions will have some affiliated behaviors such as opportunistic * subscription may be invisible to the user. * - * @return group UUID a String of group UUID if it belongs to a group. Otherwise - * it will return null. + * @return Group UUID a String of group UUID if it belongs to a group. Otherwise + * {@code null}. */ - public @Nullable ParcelUuid getGroupUuid() { - return mGroupUUID; - } - - /** - * @hide - */ - public void clearGroupUuid() { - this.mGroupUUID = null; + @Nullable + public ParcelUuid getGroupUuid() { + return mGroupUuid; } /** * @hide */ + @NonNull public List<String> getEhplmns() { return mEhplmns == null ? Collections.emptyList() : Arrays.asList(mEhplmns); } @@ -641,36 +674,45 @@ public class SubscriptionInfo implements Parcelable { /** * @hide */ + @NonNull public List<String> getHplmns() { return mHplmns == null ? Collections.emptyList() : Arrays.asList(mHplmns); } /** - * Return owner package of group the subscription belongs to. + * @return The owner package of group the subscription belongs to. * * @hide */ - public @Nullable String getGroupOwner() { + @NonNull + public String getGroupOwner() { return mGroupOwner; } /** - * @return the profile class of this subscription. + * @return The profile class populated from the profile metadata if present. Otherwise, + * the profile class defaults to {@link SubscriptionManager#PROFILE_CLASS_UNSET} if there is no + * profile metadata or the subscription is not on an eUICC ({@link #isEmbedded} return + * {@code false}). + * * @hide */ @SystemApi - public @SubscriptionManager.ProfileClass int getProfileClass() { - return this.mProfileClass; + @ProfileClass + public int getProfileClass() { + return mProfileClass; } /** * This method returns the type of a subscription. It can be * {@link SubscriptionManager#SUBSCRIPTION_TYPE_LOCAL_SIM} or * {@link SubscriptionManager#SUBSCRIPTION_TYPE_REMOTE_SIM}. - * @return the type of subscription + * + * @return The type of the subscription. */ - public @SubscriptionManager.SubscriptionType int getSubscriptionType() { - return mSubscriptionType; + @SubscriptionType + public int getSubscriptionType() { + return mType; } /** @@ -679,7 +721,7 @@ public class SubscriptionInfo implements Parcelable { * returns true). * * @param context Context of the application to check. - * @return whether the app is authorized to manage this subscription per its metadata. + * @return Whether the app is authorized to manage this subscription per its metadata. * @hide * @deprecated - Do not use. */ @@ -700,7 +742,7 @@ public class SubscriptionInfo implements Parcelable { */ @Deprecated public boolean canManageSubscription(Context context, String packageName) { - List<UiccAccessRule> allAccessRules = getAllAccessRules(); + List<UiccAccessRule> allAccessRules = getAccessRules(); if (allAccessRules == null) { return false; } @@ -723,27 +765,17 @@ public class SubscriptionInfo implements Parcelable { } /** - * @return the {@link UiccAccessRule}s that are stored in Uicc, dictating who - * is authorized to manage this subscription. - * TODO and fix it properly in R / master: either deprecate this and have 3 APIs - * native + carrier + all, or have this return all by default. + * @return The {@link UiccAccessRule}s that are stored in Uicc, dictating who is authorized to + * manage this subscription. + * * @hide */ @SystemApi - public @Nullable List<UiccAccessRule> getAccessRules() { - if (mNativeAccessRules == null) return null; - return Arrays.asList(mNativeAccessRules); - } - - /** - * @return the {@link UiccAccessRule}s that are both stored on Uicc and in carrierConfigs - * dictating who is authorized to manage this subscription. - * @hide - */ - public @Nullable List<UiccAccessRule> getAllAccessRules() { + @Nullable + public List<UiccAccessRule> getAccessRules() { List<UiccAccessRule> merged = new ArrayList<>(); if (mNativeAccessRules != null) { - merged.addAll(getAccessRules()); + merged.addAll(Arrays.asList(mNativeAccessRules)); } if (mCarrierConfigAccessRules != null) { merged.addAll(Arrays.asList(mCarrierConfigAccessRules)); @@ -762,50 +794,38 @@ public class SubscriptionInfo implements Parcelable { * href="https://developer.android.com/work/managed-profiles">Work profiles</a>. Profile * owner access is deprecated and will be removed in a future release. * - * @return the card string of the SIM card which contains the subscription or an empty string + * @return The card string of the SIM card which contains the subscription or an empty string * if these requirements are not met. The card string is the ICCID for UICCs or the EID for * eUICCs. + * * @hide - * //TODO rename usages in LPA: UiccSlotUtil.java, UiccSlotsManager.java, UiccSlotInfoTest.java */ + @NonNull public String getCardString() { - return this.mCardString; + return mCardString; } /** - * @hide - */ - public void clearCardString() { - this.mCardString = ""; - } - - /** - * Returns the card ID of the SIM card which contains the subscription (see - * {@link UiccCardInfo#getCardId()}. - * @return the cardId + * @return The card ID of the SIM card which contains the subscription. + * + * @see UiccCardInfo#getCardId(). */ public int getCardId() { - return this.mCardId; + return mCardId; } /** - * Returns the port index of the SIM card which contains the subscription. - * - * @return the portIndex + * @return The port index of the SIM card which contains the subscription. */ public int getPortIndex() { - return this.mPortIndex; - } - - /** - * Set whether the subscription's group is disabled. - * @hide - */ - public void setGroupDisabled(boolean isGroupDisabled) { - this.mIsGroupDisabled = isGroupDisabled; + return mPortIndex; } /** - * Return whether the subscription's group is disabled. + * @return {@code true} if the group of the subscription is disabled. This is only useful if + * it's a grouped opportunistic subscription. In this case, if all primary (non-opportunistic) + * subscriptions in the group are deactivated (unplugged pSIM or deactivated eSIM profile), we + * should disable this opportunistic subscription. + * * @hide */ @SystemApi @@ -814,7 +834,7 @@ public class SubscriptionInfo implements Parcelable { } /** - * Return whether uicc applications are set to be enabled or disabled. + * @return {@code true} if Uicc applications are set to be enabled or disabled. * @hide */ @SystemApi @@ -825,56 +845,50 @@ public class SubscriptionInfo implements Parcelable { /** * Get the usage setting for this subscription. * - * @return the usage setting used for this subscription. + * @return The usage setting used for this subscription. */ - public @UsageSetting int getUsageSetting() { + @UsageSetting + public int getUsageSetting() { return mUsageSetting; } - public static final @android.annotation.NonNull - Parcelable.Creator<SubscriptionInfo> CREATOR = - new Parcelable.Creator<SubscriptionInfo>() { + @NonNull + public static final Parcelable.Creator<SubscriptionInfo> CREATOR = + new Parcelable.Creator<SubscriptionInfo>() { @Override public SubscriptionInfo createFromParcel(Parcel source) { - int id = source.readInt(); - String iccId = source.readString(); - int simSlotIndex = source.readInt(); - CharSequence displayName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); - CharSequence carrierName = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); - int nameSource = source.readInt(); - int iconTint = source.readInt(); - String number = source.readString(); - int dataRoaming = source.readInt(); - String mcc = source.readString(); - String mnc = source.readString(); - String countryIso = source.readString(); - boolean isEmbedded = source.readBoolean(); - UiccAccessRule[] nativeAccessRules = source.createTypedArray(UiccAccessRule.CREATOR); - String cardString = source.readString(); - int cardId = source.readInt(); - int portId = source.readInt(); - boolean isOpportunistic = source.readBoolean(); - String groupUUID = source.readString(); - boolean isGroupDisabled = source.readBoolean(); - int carrierid = source.readInt(); - int profileClass = source.readInt(); - int subType = source.readInt(); - String[] ehplmns = source.createStringArray(); - String[] hplmns = source.createStringArray(); - String groupOwner = source.readString(); - UiccAccessRule[] carrierConfigAccessRules = source.createTypedArray( - UiccAccessRule.CREATOR); - boolean areUiccApplicationsEnabled = source.readBoolean(); - int usageSetting = source.readInt(); - - SubscriptionInfo info = new SubscriptionInfo(id, iccId, simSlotIndex, displayName, - carrierName, nameSource, iconTint, number, dataRoaming, /* icon= */ null, - mcc, mnc, countryIso, isEmbedded, nativeAccessRules, cardString, cardId, - isOpportunistic, groupUUID, isGroupDisabled, carrierid, profileClass, subType, - groupOwner, carrierConfigAccessRules, areUiccApplicationsEnabled, - portId, usageSetting); - info.setAssociatedPlmns(ehplmns, hplmns); - return info; + return new Builder() + .setId(source.readInt()) + .setIccId(source.readString()) + .setSimSlotIndex(source.readInt()) + .setDisplayName(TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source)) + .setCarrierName(TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source)) + .setNameSource(source.readInt()) + .setIconTint(source.readInt()) + .setNumber(source.readString()) + .setDataRoaming(source.readInt()) + .setMcc(source.readString()) + .setMnc(source.readString()) + .setCountryIso(source.readString()) + .setEmbedded(source.readBoolean()) + .setNativeAccessRules(source.createTypedArray(UiccAccessRule.CREATOR)) + .setCardString(source.readString()) + .setCardId(source.readInt()) + .setPortIndex(source.readInt()) + .setOpportunistic(source.readBoolean()) + .setGroupUuid(source.readString8()) + .setGroupDisabled(source.readBoolean()) + .setCarrierId(source.readInt()) + .setProfileClass(source.readInt()) + .setType(source.readInt()) + .setEhplmns(source.createStringArray()) + .setHplmns(source.createStringArray()) + .setGroupOwner(source.readString()) + .setCarrierConfigAccessRules(source.createTypedArray( + UiccAccessRule.CREATOR)) + .setUiccApplicationsEnabled(source.readBoolean()) + .setUsageSetting(source.readInt()) + .build(); } @Override @@ -904,11 +918,11 @@ public class SubscriptionInfo implements Parcelable { dest.writeInt(mCardId); dest.writeInt(mPortIndex); dest.writeBoolean(mIsOpportunistic); - dest.writeString(mGroupUUID == null ? null : mGroupUUID.toString()); + dest.writeString8(mGroupUuid == null ? null : mGroupUuid.toString()); dest.writeBoolean(mIsGroupDisabled); dest.writeInt(mCarrierId); dest.writeInt(mProfileClass); - dest.writeInt(mSubscriptionType); + dest.writeInt(mType); dest.writeStringArray(mEhplmns); dest.writeStringArray(mHplmns); dest.writeString(mGroupOwner); @@ -923,6 +937,11 @@ public class SubscriptionInfo implements Parcelable { } /** + * Get ICCID stripped PII information on user build. + * + * @param iccId The original ICCID. + * @return The stripped string. + * * @hide */ public static String givePrintableIccid(String iccId) { @@ -951,12 +970,12 @@ public class SubscriptionInfo implements Parcelable { + " nativeAccessRules=" + Arrays.toString(mNativeAccessRules) + " cardString=" + cardStringToPrint + " cardId=" + mCardId + " portIndex=" + mPortIndex - + " isOpportunistic=" + mIsOpportunistic + " groupUUID=" + mGroupUUID + + " isOpportunistic=" + mIsOpportunistic + " groupUuid=" + mGroupUuid + " isGroupDisabled=" + mIsGroupDisabled + " profileClass=" + mProfileClass + " ehplmns=" + Arrays.toString(mEhplmns) + " hplmns=" + Arrays.toString(mHplmns) - + " subscriptionType=" + mSubscriptionType + + " mType=" + mType + " groupOwner=" + mGroupOwner + " carrierConfigAccessRules=" + Arrays.toString(mCarrierConfigAccessRules) + " areUiccApplicationsEnabled=" + mAreUiccApplicationsEnabled @@ -966,7 +985,7 @@ public class SubscriptionInfo implements Parcelable { @Override public int hashCode() { return Objects.hash(mId, mSimSlotIndex, mNameSource, mIconTint, mDataRoaming, mIsEmbedded, - mIsOpportunistic, mGroupUUID, mIccId, mNumber, mMcc, mMnc, mCountryIso, mCardString, + mIsOpportunistic, mGroupUuid, mIccId, mNumber, mMcc, mMnc, mCountryIso, mCardString, mCardId, mDisplayName, mCarrierName, Arrays.hashCode(mNativeAccessRules), mIsGroupDisabled, mCarrierId, mProfileClass, mGroupOwner, mAreUiccApplicationsEnabled, mPortIndex, mUsageSetting); @@ -974,16 +993,9 @@ public class SubscriptionInfo implements Parcelable { @Override public boolean equals(Object obj) { - if (obj == null) return false; - if (obj == this) return true; - - SubscriptionInfo toCompare; - try { - toCompare = (SubscriptionInfo) obj; - } catch (ClassCastException ex) { - return false; - } - + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + SubscriptionInfo toCompare = (SubscriptionInfo) obj; return mId == toCompare.mId && mSimSlotIndex == toCompare.mSimSlotIndex && mNameSource == toCompare.mNameSource @@ -994,7 +1006,7 @@ public class SubscriptionInfo implements Parcelable { && mIsGroupDisabled == toCompare.mIsGroupDisabled && mAreUiccApplicationsEnabled == toCompare.mAreUiccApplicationsEnabled && mCarrierId == toCompare.mCarrierId - && Objects.equals(mGroupUUID, toCompare.mGroupUUID) + && Objects.equals(mGroupUuid, toCompare.mGroupUuid) && Objects.equals(mIccId, toCompare.mIccId) && Objects.equals(mNumber, toCompare.mNumber) && Objects.equals(mMcc, toCompare.mMcc) @@ -1012,4 +1024,629 @@ public class SubscriptionInfo implements Parcelable { && Arrays.equals(mHplmns, toCompare.mHplmns) && mUsageSetting == toCompare.mUsageSetting; } + + /** + * The builder class of {@link SubscriptionInfo}. + * + * @hide + */ + public static class Builder { + /** + * The subscription id. + */ + private int mId = 0; + + /** + * The ICCID of the SIM that is associated with this subscription, empty if unknown. + */ + @NonNull + private String mIccId = ""; + + /** + * The index of the SIM slot that currently contains the subscription and not necessarily + * unique and maybe {@link SubscriptionManager#INVALID_SIM_SLOT_INDEX} if unknown or the + * subscription is inactive. + */ + private int mSimSlotIndex = SubscriptionManager.INVALID_SIM_SLOT_INDEX; + + /** + * The name displayed to the user that identifies this subscription. This name is used + * in Settings page and can be renamed by the user. + */ + @NonNull + private CharSequence mDisplayName = ""; + + /** + * The name displayed to the user that identifies subscription provider name. This name + * is the SPN displayed in status bar and many other places. Can't be renamed by the user. + */ + @NonNull + private CharSequence mCarrierName = ""; + + /** + * The source of the carrier name. + */ + @SimDisplayNameSource + private int mNameSource = SubscriptionManager.NAME_SOURCE_CARRIER_ID; + + /** + * The color to be used for tinting the icon when displaying to the user. + */ + private int mIconTint = 0; + + /** + * The number presented to the user identify this subscription. + */ + @NonNull + private String mNumber = ""; + + /** + * Whether user enables data roaming for this subscription or not. Either + * {@link SubscriptionManager#DATA_ROAMING_ENABLE} or + * {@link SubscriptionManager#DATA_ROAMING_DISABLE}. + */ + private int mDataRoaming = SubscriptionManager.DATA_ROAMING_DISABLE; + + /** + * SIM icon bitmap cache. + */ + @Nullable + private Bitmap mIconBitmap = null; + + /** + * The mobile country code. + */ + @Nullable + private String mMcc = null; + + /** + * The mobile network code. + */ + @Nullable + private String mMnc = null; + + /** + * EHPLMNs associated with the subscription. + */ + @NonNull + private String[] mEhplmns = new String[0]; + + /** + * HPLMNs associated with the subscription. + */ + @NonNull + private String[] mHplmns = new String[0]; + + /** + * The ISO Country code for the subscription's provider. + */ + @NonNull + private String mCountryIso = ""; + + /** + * Whether the subscription is from eSIM. + */ + private boolean mIsEmbedded = false; + + /** + * The native access rules for this subscription, if it is embedded and defines any. This + * does not include access rules for non-embedded subscriptions. + */ + @Nullable + private UiccAccessRule[] mNativeAccessRules = null; + + /** + * The card string of the SIM card. + */ + @NonNull + private String mCardString = ""; + + /** + * The card ID of the SIM card which contains the subscription. + */ + private int mCardId = -1; + + /** + * Whether the subscription is opportunistic or not. + */ + private boolean mIsOpportunistic = false; + + /** + * The group UUID of the subscription group. + */ + @Nullable + private ParcelUuid mGroupUuid = null; + + /** + * Whether group of the subscription is disabled. This is only useful if it's a grouped + * opportunistic subscription. In this case, if all primary (non-opportunistic) + * subscriptions in the group are deactivated (unplugged pSIM or deactivated eSIM profile), + * we should disable this opportunistic subscription. + */ + private boolean mIsGroupDisabled = false; + + /** + * The carrier id. + * + * @see TelephonyManager#getSimCarrierId() + */ + private int mCarrierId = TelephonyManager.UNKNOWN_CARRIER_ID; + + /** + * The profile class populated from the profile metadata if present. Otherwise, the profile + * class defaults to {@link SubscriptionManager#PROFILE_CLASS_UNSET} if there is no profile + * metadata or the subscription is not on an eUICC ({@link #isEmbedded} returns + * {@code false}). + */ + @ProfileClass + private int mProfileClass = SubscriptionManager.PROFILE_CLASS_UNSET; + + /** + * The subscription type. + */ + @SubscriptionType + private int mType = SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM; + + /** + * The owner package of group the subscription belongs to. + */ + @NonNull + private String mGroupOwner = ""; + + /** + * The carrier certificates for this subscription that are saved in carrier configs. + * This does not include access rules from the Uicc, whether embedded or non-embedded. + */ + @Nullable + private UiccAccessRule[] mCarrierConfigAccessRules = null; + + /** + * Whether Uicc applications are configured to enable or not. + */ + private boolean mAreUiccApplicationsEnabled = true; + + /** + * the port index of the Uicc card. + */ + private int mPortIndex = 0; + + /** + * Subscription's preferred usage setting. + */ + @UsageSetting + private int mUsageSetting = SubscriptionManager.USAGE_SETTING_UNKNOWN; + + /** + * Default constructor. + */ + public Builder() { + } + + /** + * Constructor from {@link SubscriptionInfo}. + * + * @param info The subscription info. + */ + public Builder(@NonNull SubscriptionInfo info) { + mId = info.mId; + mIccId = info.mIccId; + mSimSlotIndex = info.mSimSlotIndex; + mDisplayName = info.mDisplayName; + mCarrierName = info.mCarrierName; + mNameSource = info.mNameSource; + mIconTint = info.mIconTint; + mNumber = info.mNumber; + mDataRoaming = info.mDataRoaming; + mIconBitmap = info.mIconBitmap; + mMcc = info.mMcc; + mMnc = info.mMnc; + mEhplmns = info.mEhplmns; + mHplmns = info.mHplmns; + mCountryIso = info.mCountryIso; + mIsEmbedded = info.mIsEmbedded; + mNativeAccessRules = info.mNativeAccessRules; + mCardString = info.mCardString; + mCardId = info.mCardId; + mIsOpportunistic = info.mIsOpportunistic; + mGroupUuid = info.mGroupUuid; + mIsGroupDisabled = info.mIsGroupDisabled; + mCarrierId = info.mCarrierId; + mProfileClass = info.mProfileClass; + mType = info.mType; + mGroupOwner = info.mGroupOwner; + mCarrierConfigAccessRules = info.mCarrierConfigAccessRules; + mAreUiccApplicationsEnabled = info.mAreUiccApplicationsEnabled; + mPortIndex = info.mPortIndex; + mUsageSetting = info.mUsageSetting; + } + + /** + * Set the subscription id. + * + * @param id The subscription id. + * @return The builder. + */ + @NonNull + public Builder setId(int id) { + mId = id; + return this; + } + + /** + * Set the ICCID of the SIM that is associated with this subscription. + * + * @param iccId The ICCID of the SIM that is associated with this subscription. + * @return The builder. + */ + @NonNull + public Builder setIccId(@Nullable String iccId) { + mIccId = TextUtils.emptyIfNull(iccId); + return this; + } + + /** + * Set the SIM index of the slot that currently contains the subscription. Set to + * {@link SubscriptionManager#INVALID_SIM_SLOT_INDEX} if the subscription is inactive. + * + * @param simSlotIndex The SIM slot index. + * @return The builder. + */ + @NonNull + public Builder setSimSlotIndex(int simSlotIndex) { + mSimSlotIndex = simSlotIndex; + return this; + } + + /** + * The name displayed to the user that identifies this subscription. This name is used + * in Settings page and can be renamed by the user. + * + * @param displayName The display name. + * @return The builder. + */ + @NonNull + public Builder setDisplayName(@Nullable CharSequence displayName) { + mDisplayName = displayName == null ? "" : displayName; + return this; + } + + /** + * The name displayed to the user that identifies subscription provider name. This name + * is the SPN displayed in status bar and many other places. Can't be renamed by the user. + * + * @param carrierName The carrier name. + * @return The builder. + */ + @NonNull + public Builder setCarrierName(@Nullable CharSequence carrierName) { + mCarrierName = carrierName == null ? "" : carrierName; + return this; + } + + /** + * Set the source of the carrier name. + * + * @param nameSource The source of the carrier name. + * @return The builder. + */ + @NonNull + public Builder setNameSource(@SimDisplayNameSource int nameSource) { + mNameSource = nameSource; + return this; + } + + /** + * Set the color to be used for tinting the icon when displaying to the user. + * + * @param iconTint The color to be used for tinting the icon when displaying to the user. + * @return The builder. + */ + @NonNull + public Builder setIconTint(int iconTint) { + mIconTint = iconTint; + return this; + } + + /** + * Set the number presented to the user identify this subscription. + * + * @param number the number presented to the user identify this subscription. + * @return The builder. + */ + @NonNull + public Builder setNumber(@Nullable String number) { + mNumber = TextUtils.emptyIfNull(number); + return this; + } + + /** + * Set whether user enables data roaming for this subscription or not. + * + * @param dataRoaming Data roaming mode. Either + * {@link SubscriptionManager#DATA_ROAMING_ENABLE} or + * {@link SubscriptionManager#DATA_ROAMING_DISABLE} + * @return The builder. + */ + @NonNull + public Builder setDataRoaming(int dataRoaming) { + mDataRoaming = dataRoaming; + return this; + } + + /** + * Set SIM icon bitmap cache. + * + * @param iconBitmap SIM icon bitmap cache. + * @return The builder. + */ + @NonNull + public Builder setIcon(@Nullable Bitmap iconBitmap) { + mIconBitmap = iconBitmap; + return this; + } + + /** + * Set the mobile country code. + * + * @param mcc The mobile country code. + * @return The builder. + */ + @NonNull + public Builder setMcc(@Nullable String mcc) { + mMcc = mcc; + return this; + } + + /** + * Set the mobile network code. + * + * @param mnc Mobile network code. + * @return The builder. + */ + @NonNull + public Builder setMnc(@Nullable String mnc) { + mMnc = mnc; + return this; + } + + /** + * Set EHPLMNs associated with the subscription. + * + * @param ehplmns EHPLMNs associated with the subscription. + * @return The builder. + */ + @NonNull + public Builder setEhplmns(@Nullable String[] ehplmns) { + mEhplmns = ehplmns == null ? new String[0] : ehplmns; + return this; + } + + /** + * Set HPLMNs associated with the subscription. + * + * @param hplmns HPLMNs associated with the subscription. + * @return The builder. + */ + @NonNull + public Builder setHplmns(@Nullable String[] hplmns) { + mHplmns = hplmns == null ? new String[0] : hplmns; + return this; + } + + /** + * Set the ISO Country code for the subscription's provider. + * + * @param countryIso The ISO Country code for the subscription's provider. + * @return The builder. + */ + @NonNull + public Builder setCountryIso(@Nullable String countryIso) { + mCountryIso = TextUtils.emptyIfNull(countryIso); + return this; + } + + /** + * Set whether the subscription is from eSIM or not. + * + * @param isEmbedded {@code true} if the subscription is from eSIM. + * @return The builder. + */ + @NonNull + public Builder setEmbedded(boolean isEmbedded) { + mIsEmbedded = isEmbedded; + return this; + } + + /** + * Set the native access rules for this subscription, if it is embedded and defines any. + * This does not include access rules for non-embedded subscriptions. + * + * @param nativeAccessRules The native access rules for this subscription. + * @return The builder. + */ + @NonNull + public Builder setNativeAccessRules(@Nullable UiccAccessRule[] nativeAccessRules) { + mNativeAccessRules = nativeAccessRules; + return this; + } + + /** + * Set the card string of the SIM card. + * + * @param cardString The card string of the SIM card. + * @return The builder. + * + * @see #getCardString() + */ + @NonNull + public Builder setCardString(@Nullable String cardString) { + mCardString = TextUtils.emptyIfNull(cardString); + return this; + } + + /** + * Set the card ID of the SIM card which contains the subscription. + * + * @param cardId The card ID of the SIM card which contains the subscription. + * @return The builder. + */ + @NonNull + public Builder setCardId(int cardId) { + mCardId = cardId; + return this; + } + + /** + * Set whether the subscription is opportunistic or not. + * + * @param isOpportunistic {@code true} if the subscription is opportunistic. + * @return The builder. + */ + @NonNull + public Builder setOpportunistic(boolean isOpportunistic) { + mIsOpportunistic = isOpportunistic; + return this; + } + + /** + * Set the group UUID of the subscription group. + * + * @param groupUuid The group UUID. + * @return The builder. + * + * @see #getGroupUuid() + */ + @NonNull + public Builder setGroupUuid(@Nullable String groupUuid) { + mGroupUuid = groupUuid == null ? null : ParcelUuid.fromString(groupUuid); + return this; + } + + /** + * Whether group of the subscription is disabled. This is only useful if it's a grouped + * opportunistic subscription. In this case, if all primary (non-opportunistic) + * subscriptions in the group are deactivated (unplugged pSIM or deactivated eSIM profile), + * we should disable this opportunistic subscription. + * + * @param isGroupDisabled {@code true} if group of the subscription is disabled. + * @return The builder. + */ + @NonNull + public Builder setGroupDisabled(boolean isGroupDisabled) { + mIsGroupDisabled = isGroupDisabled; + return this; + } + + /** + * Set the subscription carrier id. + * + * @param carrierId The carrier id. + * @return The builder + * + * @see TelephonyManager#getSimCarrierId() + */ + @NonNull + public Builder setCarrierId(int carrierId) { + mCarrierId = carrierId; + return this; + } + + /** + * Set the profile class populated from the profile metadata if present. + * + * @param profileClass the profile class populated from the profile metadata if present. + * @return The builder + * + * @see #getProfileClass() + */ + @NonNull + public Builder setProfileClass(@ProfileClass int profileClass) { + mProfileClass = profileClass; + return this; + } + + /** + * Set the subscription type. + * + * @param type Subscription type. + * @return The builder. + */ + @NonNull + public Builder setType(@SubscriptionType int type) { + mType = type; + return this; + } + + /** + * Set the owner package of group the subscription belongs to. + * + * @param groupOwner Owner package of group the subscription belongs to. + * @return The builder. + */ + @NonNull + public Builder setGroupOwner(@Nullable String groupOwner) { + mGroupOwner = TextUtils.emptyIfNull(groupOwner); + return this; + } + + /** + * Set the carrier certificates for this subscription that are saved in carrier configs. + * This does not include access rules from the Uicc, whether embedded or non-embedded. + * + * @param carrierConfigAccessRules The carrier certificates for this subscription + * @return The builder. + */ + @NonNull + public Builder setCarrierConfigAccessRules( + @Nullable UiccAccessRule[] carrierConfigAccessRules) { + mCarrierConfigAccessRules = carrierConfigAccessRules; + return this; + } + + /** + * Set whether Uicc applications are configured to enable or not. + * + * @param uiccApplicationsEnabled {@code true} if Uicc applications are configured to + * enable. + * @return The builder. + */ + @NonNull + public Builder setUiccApplicationsEnabled(boolean uiccApplicationsEnabled) { + mAreUiccApplicationsEnabled = uiccApplicationsEnabled; + return this; + } + + /** + * Set the port index of the Uicc card. + * + * @param portIndex The port index of the Uicc card. + * @return The builder. + */ + @NonNull + public Builder setPortIndex(int portIndex) { + mPortIndex = portIndex; + return this; + } + + /** + * Set subscription's preferred usage setting. + * + * @param usageSetting Subscription's preferred usage setting. + * @return The builder. + */ + @NonNull + public Builder setUsageSetting(@UsageSetting int usageSetting) { + mUsageSetting = usageSetting; + return this; + } + + /** + * Build the {@link SubscriptionInfo}. + * + * @return The {@link SubscriptionInfo} instance. + */ + public SubscriptionInfo build() { + return new SubscriptionInfo(this); + } + } } diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index dc8286febbe5..49a949c9b2ad 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -3079,7 +3079,7 @@ public class SubscriptionManager { @SystemApi public boolean canManageSubscription(@NonNull SubscriptionInfo info, @NonNull String packageName) { - if (info == null || info.getAllAccessRules() == null || packageName == null) { + if (info == null || info.getAccessRules() == null || packageName == null) { return false; } PackageManager packageManager = mContext.getPackageManager(); @@ -3091,7 +3091,7 @@ public class SubscriptionManager { logd("Unknown package: " + packageName); return false; } - for (UiccAccessRule rule : info.getAllAccessRules()) { + for (UiccAccessRule rule : info.getAccessRules()) { if (rule.getCarrierPrivilegeStatus(packageInfo) == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { return true; |