From 32982caae643889be8f5a9073dc915b10f2a08ac Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Fri, 7 Oct 2022 16:36:59 -0700 Subject: [PATCH 1/3] Renamed name source to display name source Bug: 239607619 Test: Build Merged-In: Icc370d5ad5c2a15fc4f4d7ad0c039a2421fb9bf5 Change-Id: Icc370d5ad5c2a15fc4f4d7ad0c039a2421fb9bf5 --- .../android/telephony/SubscriptionInfo.java | 57 +++++++++---------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/telephony/java/android/telephony/SubscriptionInfo.java b/telephony/java/android/telephony/SubscriptionInfo.java index eb96d37391190..4d58b22080cd0 100644 --- a/telephony/java/android/telephony/SubscriptionInfo.java +++ b/telephony/java/android/telephony/SubscriptionInfo.java @@ -21,7 +21,6 @@ import static android.text.TextUtils.formatSimple; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; -import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; @@ -34,7 +33,6 @@ import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.graphics.Rect; import android.graphics.Typeface; -import android.os.Build; import android.os.Parcel; import android.os.ParcelUuid; import android.os.Parcelable; @@ -105,10 +103,10 @@ public class SubscriptionInfo implements Parcelable { private final int mCarrierId; /** - * The source of the {@link #mCarrierName}. + * The source of the {@link #mDisplayName}. */ @SimDisplayNameSource - private final int mNameSource; + private final int mDisplayNameSource; /** * The color to be used for tinting the icon when displaying to the user. @@ -319,14 +317,14 @@ public class SubscriptionInfo implements Parcelable { // 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, + 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) { - this(id, iccId, simSlotIndex, displayName, carrierName, nameSource, iconTint, number, + this(id, iccId, simSlotIndex, displayName, carrierName, displayNameSource, iconTint, number, roaming, icon, mcc, mnc, countryIso, isEmbedded, nativeAccessRules, cardString, cardId, isOpportunistic, groupUUID, isGroupDisabled, carrierId, profileClass, subType, groupOwner, carrierConfigAccessRules, areUiccApplicationsEnabled, @@ -353,7 +351,7 @@ public class SubscriptionInfo implements Parcelable { this.mSimSlotIndex = simSlotIndex; this.mDisplayName = displayName; this.mCarrierName = carrierName; - this.mNameSource = nameSource; + this.mDisplayNameSource = nameSource; this.mIconTint = iconTint; this.mNumber = number; this.mDataRoaming = roaming; @@ -391,7 +389,7 @@ public class SubscriptionInfo implements Parcelable { this.mSimSlotIndex = builder.mSimSlotIndex; this.mDisplayName = builder.mDisplayName; this.mCarrierName = builder.mCarrierName; - this.mNameSource = builder.mNameSource; + this.mDisplayNameSource = builder.mDisplayNameSource; this.mIconTint = builder.mIconTint; this.mNumber = builder.mNumber; this.mDataRoaming = builder.mDataRoaming; @@ -481,14 +479,13 @@ public class SubscriptionInfo implements Parcelable { } /** - * @return The source of the {@link #getCarrierName()}. + * @return The source of the {@link #getDisplayName()}. * * @hide */ - @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) @SimDisplayNameSource - public int getNameSource() { - return mNameSource; + public int getDisplayNameSource() { + return mDisplayNameSource; } /** @@ -863,7 +860,7 @@ public class SubscriptionInfo implements Parcelable { .setSimSlotIndex(source.readInt()) .setDisplayName(TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source)) .setCarrierName(TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source)) - .setNameSource(source.readInt()) + .setDisplayNameSource(source.readInt()) .setIconTint(source.readInt()) .setNumber(source.readString()) .setDataRoaming(source.readInt()) @@ -904,7 +901,7 @@ public class SubscriptionInfo implements Parcelable { dest.writeInt(mSimSlotIndex); TextUtils.writeToParcel(mDisplayName, dest, 0); TextUtils.writeToParcel(mCarrierName, dest, 0); - dest.writeInt(mNameSource); + dest.writeInt(mDisplayNameSource); dest.writeInt(mIconTint); dest.writeString(mNumber); dest.writeInt(mDataRoaming); @@ -962,7 +959,7 @@ public class SubscriptionInfo implements Parcelable { String cardStringToPrint = givePrintableIccid(mCardString); return "{id=" + mId + " iccId=" + iccIdToPrint + " simSlotIndex=" + mSimSlotIndex + " carrierId=" + mCarrierId + " displayName=" + mDisplayName - + " carrierName=" + mCarrierName + " nameSource=" + mNameSource + + " carrierName=" + mCarrierName + " nameSource=" + mDisplayNameSource + " iconTint=" + mIconTint + " number=" + Rlog.pii(TelephonyUtils.IS_DEBUGGABLE, mNumber) + " dataRoaming=" + mDataRoaming + " iconBitmap=" + mIconBitmap + " mcc=" + mMcc @@ -984,11 +981,11 @@ 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, - mCardId, mDisplayName, mCarrierName, Arrays.hashCode(mNativeAccessRules), - mIsGroupDisabled, mCarrierId, mProfileClass, mGroupOwner, - mAreUiccApplicationsEnabled, mPortIndex, mUsageSetting); + return Objects.hash(mId, mSimSlotIndex, mDisplayNameSource, mIconTint, mDataRoaming, + mIsEmbedded, mIsOpportunistic, mGroupUuid, mIccId, mNumber, mMcc, mMnc, mCountryIso, + mCardString, mCardId, mDisplayName, mCarrierName, + Arrays.hashCode(mNativeAccessRules), mIsGroupDisabled, mCarrierId, mProfileClass, + mGroupOwner, mAreUiccApplicationsEnabled, mPortIndex, mUsageSetting); } @Override @@ -998,7 +995,7 @@ public class SubscriptionInfo implements Parcelable { SubscriptionInfo toCompare = (SubscriptionInfo) obj; return mId == toCompare.mId && mSimSlotIndex == toCompare.mSimSlotIndex - && mNameSource == toCompare.mNameSource + && mDisplayNameSource == toCompare.mDisplayNameSource && mIconTint == toCompare.mIconTint && mDataRoaming == toCompare.mDataRoaming && mIsEmbedded == toCompare.mIsEmbedded @@ -1064,10 +1061,10 @@ public class SubscriptionInfo implements Parcelable { private CharSequence mCarrierName = ""; /** - * The source of the carrier name. + * The source of the display name. */ @SimDisplayNameSource - private int mNameSource = SubscriptionManager.NAME_SOURCE_CARRIER_ID; + private int mDisplayNameSource = SubscriptionManager.NAME_SOURCE_CARRIER_ID; /** * The color to be used for tinting the icon when displaying to the user. @@ -1233,7 +1230,7 @@ public class SubscriptionInfo implements Parcelable { mSimSlotIndex = info.mSimSlotIndex; mDisplayName = info.mDisplayName; mCarrierName = info.mCarrierName; - mNameSource = info.mNameSource; + mDisplayNameSource = info.mDisplayNameSource; mIconTint = info.mIconTint; mNumber = info.mNumber; mDataRoaming = info.mDataRoaming; @@ -1324,14 +1321,16 @@ public class SubscriptionInfo implements Parcelable { } /** - * Set the source of the carrier name. + * Set the source of the display name. * - * @param nameSource The source of the carrier name. + * @param displayNameSource The source of the display name. * @return The builder. + * + * @see SubscriptionInfo#getDisplayName() */ @NonNull - public Builder setNameSource(@SimDisplayNameSource int nameSource) { - mNameSource = nameSource; + public Builder setDisplayNameSource(@SimDisplayNameSource int displayNameSource) { + mDisplayNameSource = displayNameSource; return this; } From 9edb93ce73c2ca69389895ac88ab7250e526ecb5 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Fri, 7 Oct 2022 23:06:20 -0700 Subject: [PATCH 2/3] Fixed equals and hashCode 1. Used Android Studio to auto generate the equals and hashCode method. 2. e-order the field to match the database column order. 3. Better readability for toString(). Bug: 239607619 Test: atest SubscriptionDatabaseManagerTest Merged-In: Ibc80d41f3019a4ebb012358f3369d69222925214 Change-Id: Ibc80d41f3019a4ebb012358f3369d69222925214 --- core/java/android/provider/Telephony.java | 88 ++++++++ .../telephony/util/TelephonyUtils.java | 56 +++++ .../android/telephony/SubscriptionInfo.java | 212 +++++++++--------- .../telephony/SubscriptionManager.java | 7 + 4 files changed, 262 insertions(+), 101 deletions(-) diff --git a/core/java/android/provider/Telephony.java b/core/java/android/provider/Telephony.java index 001a25d8be8fb..3dc805e03f9da 100644 --- a/core/java/android/provider/Telephony.java +++ b/core/java/android/provider/Telephony.java @@ -53,6 +53,7 @@ import com.android.internal.telephony.SmsApplication; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -4353,6 +4354,12 @@ public final class Telephony { */ public static final String COLUMN_NAME_SOURCE = "name_source"; + /** + * The name source is unknown. + * @hide + */ + public static final int NAME_SOURCE_UNKNOWN = -1; + /** The name_source is from the carrier id. {@hide} */ public static final int NAME_SOURCE_CARRIER_ID = 0; @@ -4834,5 +4841,86 @@ public final class Telephony { * @hide */ public static final String COLUMN_USER_HANDLE = "user_handle"; + + /** All columns in {@link SimInfo} table. */ + private static final List ALL_COLUMNS = List.of( + COLUMN_UNIQUE_KEY_SUBSCRIPTION_ID, + COLUMN_ICC_ID, + COLUMN_SIM_SLOT_INDEX, + COLUMN_DISPLAY_NAME, + COLUMN_CARRIER_NAME, + COLUMN_NAME_SOURCE, + COLUMN_COLOR, + COLUMN_NUMBER, + COLUMN_DISPLAY_NUMBER_FORMAT, + COLUMN_DATA_ROAMING, + COLUMN_MCC, + COLUMN_MNC, + COLUMN_MCC_STRING, + COLUMN_MNC_STRING, + COLUMN_EHPLMNS, + COLUMN_HPLMNS, + COLUMN_SIM_PROVISIONING_STATUS, + COLUMN_IS_EMBEDDED, + COLUMN_CARD_ID, + COLUMN_ACCESS_RULES, + COLUMN_ACCESS_RULES_FROM_CARRIER_CONFIGS, + COLUMN_IS_REMOVABLE, + COLUMN_CB_EXTREME_THREAT_ALERT, + COLUMN_CB_SEVERE_THREAT_ALERT, + COLUMN_CB_AMBER_ALERT, + COLUMN_CB_EMERGENCY_ALERT, + COLUMN_CB_ALERT_SOUND_DURATION, + COLUMN_CB_ALERT_REMINDER_INTERVAL, + COLUMN_CB_ALERT_VIBRATE, + COLUMN_CB_ALERT_SPEECH, + COLUMN_CB_ETWS_TEST_ALERT, + COLUMN_CB_CHANNEL_50_ALERT, + COLUMN_CB_CMAS_TEST_ALERT, + COLUMN_CB_OPT_OUT_DIALOG, + COLUMN_ENHANCED_4G_MODE_ENABLED, + COLUMN_VT_IMS_ENABLED, + COLUMN_WFC_IMS_ENABLED, + COLUMN_WFC_IMS_MODE, + COLUMN_WFC_IMS_ROAMING_MODE, + COLUMN_WFC_IMS_ROAMING_ENABLED, + COLUMN_IS_OPPORTUNISTIC, + COLUMN_GROUP_UUID, + COLUMN_IS_METERED, + COLUMN_ISO_COUNTRY_CODE, + COLUMN_CARRIER_ID, + COLUMN_PROFILE_CLASS, + COLUMN_SUBSCRIPTION_TYPE, + COLUMN_GROUP_OWNER, + COLUMN_DATA_ENABLED_OVERRIDE_RULES, + COLUMN_ENABLED_MOBILE_DATA_POLICIES, + COLUMN_IMSI, + COLUMN_UICC_APPLICATIONS_ENABLED, + COLUMN_ALLOWED_NETWORK_TYPES, + COLUMN_IMS_RCS_UCE_ENABLED, + COLUMN_CROSS_SIM_CALLING_ENABLED, + COLUMN_RCS_CONFIG, + COLUMN_ALLOWED_NETWORK_TYPES_FOR_REASONS, + COLUMN_D2D_STATUS_SHARING, + COLUMN_VOIMS_OPT_IN_STATUS, + COLUMN_D2D_STATUS_SHARING_SELECTED_CONTACTS, + COLUMN_NR_ADVANCED_CALLING_ENABLED, + COLUMN_PHONE_NUMBER_SOURCE_CARRIER, + COLUMN_PHONE_NUMBER_SOURCE_IMS, + COLUMN_PORT_INDEX, + COLUMN_USAGE_SETTING, + COLUMN_TP_MESSAGE_REF, + COLUMN_USER_HANDLE + ); + + /** + * @return All columns in {@link SimInfo} table. + * + * @hide + */ + @NonNull + public static List getAllColumns() { + return ALL_COLUMNS; + } } } diff --git a/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java b/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java index de70dcb9b29cd..79ab009d3b922 100644 --- a/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java +++ b/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java @@ -27,6 +27,7 @@ import android.os.Binder; import android.os.Bundle; import android.os.PersistableBundle; import android.os.SystemProperties; +import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import java.io.PrintWriter; @@ -192,4 +193,59 @@ public final class TelephonyUtils { // This is the error case. The well-defined value for UNKNOWN is -1. return "UNKNOWN(" + state + ")"; } + + /** + * Convert display name source to string. + * + * @param source The display name source. + * @return The display name source in string format. + */ + @NonNull + public static String displayNameSourceToString( + @SubscriptionManager.SimDisplayNameSource int source) { + switch (source) { + case SubscriptionManager.NAME_SOURCE_UNKNOWN: return "UNKNOWN"; + case SubscriptionManager.NAME_SOURCE_CARRIER_ID: return "CARRIER_ID"; + case SubscriptionManager.NAME_SOURCE_SIM_SPN: return "SIM_SPN"; + case SubscriptionManager.NAME_SOURCE_USER_INPUT: return "USER_INPUT"; + case SubscriptionManager.NAME_SOURCE_CARRIER: return "CARRIER"; + case SubscriptionManager.NAME_SOURCE_SIM_PNN: return "SIM_PNN"; + default: + return "UNKNOWN(" + source + ")"; + } + } + + /** + * Convert subscription type to string. + * + * @param type The subscription type. + * @return The subscription type in string format. + */ + @NonNull + public static String subscriptionTypeToString(@SubscriptionManager.SubscriptionType int type) { + switch (type) { + case SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM: return "LOCAL_SIM"; + case SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM: return "REMOTE_SIM"; + default: + return "UNKNOWN(" + type + ")"; + } + } + + /** + * Convert usage setting to string. + * + * @param usageSetting Usage setting. + * @return The usage setting in string format. + */ + @NonNull + public static String usageSettingToString(@SubscriptionManager.UsageSetting int usageSetting) { + switch (usageSetting) { + case SubscriptionManager.USAGE_SETTING_UNKNOWN: return "UNKNOWN"; + case SubscriptionManager.USAGE_SETTING_DEFAULT: return "DEFAULT"; + case SubscriptionManager.USAGE_SETTING_VOICE_CENTRIC: return "VOICE_CENTRIC"; + case SubscriptionManager.USAGE_SETTING_DATA_CENTRIC: return "DATA_CENTRIC"; + default: + return "UNKNOWN(" + usageSetting + ")"; + } + } } diff --git a/telephony/java/android/telephony/SubscriptionInfo.java b/telephony/java/android/telephony/SubscriptionInfo.java index 4d58b22080cd0..0d3c80fd88870 100644 --- a/telephony/java/android/telephony/SubscriptionInfo.java +++ b/telephony/java/android/telephony/SubscriptionInfo.java @@ -95,13 +95,6 @@ public class SubscriptionInfo implements Parcelable { @NonNull private final CharSequence mCarrierName; - /** - * The subscription carrier id. - * - * @see TelephonyManager#getSimCarrierId() - */ - private final int mCarrierId; - /** * The source of the {@link #mDisplayName}. */ @@ -126,12 +119,6 @@ public class SubscriptionInfo implements Parcelable { */ private final int mDataRoaming; - /** - * SIM icon bitmap cache. - */ - @Nullable - private Bitmap mIconBitmap; - /** * Mobile Country Code. */ @@ -156,17 +143,18 @@ public class SubscriptionInfo implements Parcelable { @NonNull private final String[] mHplmns; - /** - * ISO Country code for the subscription's provider. - */ - @NonNull - private final String mCountryIso; - /** * Whether the subscription is from eSIM. */ private final boolean mIsEmbedded; + /** + * 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. + */ + @NonNull + private final String mCardString; + /** * The access rules for this subscription, if it is embedded and defines any. This does not * include access rules for non-embedded subscriptions. @@ -181,18 +169,6 @@ public class SubscriptionInfo implements Parcelable { @Nullable 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. - */ - @NonNull - private final String mCardString; - - /** - * The card ID of the SIM card. This maps uniquely to {@link #mCardString}. - */ - private final int mCardId; - /** * Whether the subscription is opportunistic. */ @@ -207,18 +183,17 @@ public class SubscriptionInfo implements Parcelable { private final ParcelUuid mGroupUuid; /** - * A package name that specifies who created the group. Empty if not available. + * ISO Country code for the subscription's provider. */ @NonNull - private final String mGroupOwner; + private final String mCountryIso; /** - * 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. + * The subscription carrier id. + * + * @see TelephonyManager#getSimCarrierId() */ - private final boolean mIsGroupDisabled; + private final int mCarrierId; /** * The profile class populated from the profile metadata if present. Otherwise, @@ -235,6 +210,12 @@ public class SubscriptionInfo implements Parcelable { @SubscriptionType private final int mType; + /** + * A package name that specifies who created the group. Empty if not available. + */ + @NonNull + private final String mGroupOwner; + /** * Whether uicc applications are configured to enable or disable. * By default it's true. @@ -252,6 +233,27 @@ public class SubscriptionInfo implements Parcelable { @UsageSetting private final int mUsageSetting; + // Below are the fields that do not exist in the database. + + /** + * SIM icon bitmap cache. + */ + @Nullable + private Bitmap mIconBitmap; + + /** + * The card ID of the SIM card. This maps uniquely to {@link #mCardString}. + */ + private final int mCardId; + + /** + * 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 final boolean mIsGroupDisabled; + /** * @hide * @@ -665,7 +667,8 @@ public class SubscriptionInfo implements Parcelable { */ @NonNull public List getEhplmns() { - return mEhplmns == null ? Collections.emptyList() : Arrays.asList(mEhplmns); + return Collections.unmodifiableList(mEhplmns == null + ? Collections.emptyList() : Arrays.asList(mEhplmns)); } /** @@ -673,7 +676,8 @@ public class SubscriptionInfo implements Parcelable { */ @NonNull public List getHplmns() { - return mHplmns == null ? Collections.emptyList() : Arrays.asList(mHplmns); + return Collections.unmodifiableList(mHplmns == null + ? Collections.emptyList() : Arrays.asList(mHplmns)); } /** @@ -777,7 +781,7 @@ public class SubscriptionInfo implements Parcelable { if (mCarrierConfigAccessRules != null) { merged.addAll(Arrays.asList(mCarrierConfigAccessRules)); } - return merged.isEmpty() ? null : merged; + return merged.isEmpty() ? null : Collections.unmodifiableList(merged); } /** @@ -957,69 +961,75 @@ public class SubscriptionInfo implements Parcelable { public String toString() { String iccIdToPrint = givePrintableIccid(mIccId); String cardStringToPrint = givePrintableIccid(mCardString); - return "{id=" + mId + " iccId=" + iccIdToPrint + " simSlotIndex=" + mSimSlotIndex - + " carrierId=" + mCarrierId + " displayName=" + mDisplayName - + " carrierName=" + mCarrierName + " nameSource=" + mDisplayNameSource + return "[SubscriptionInfo: id=" + mId + + " iccId=" + iccIdToPrint + + " simSlotIndex=" + mSimSlotIndex + + " portIndex=" + mPortIndex + + " isEmbedded=" + mIsEmbedded + + " carrierId=" + mCarrierId + + " displayName=" + mDisplayName + + " carrierName=" + mCarrierName + + " isOpportunistic=" + mIsOpportunistic + + " groupUuid=" + mGroupUuid + + " groupOwner=" + mGroupOwner + + " isGroupDisabled=" + mIsGroupDisabled + + " displayNameSource=" + + TelephonyUtils.displayNameSourceToString(mDisplayNameSource) + " iconTint=" + mIconTint + " number=" + Rlog.pii(TelephonyUtils.IS_DEBUGGABLE, mNumber) - + " dataRoaming=" + mDataRoaming + " iconBitmap=" + mIconBitmap + " mcc=" + mMcc - + " mnc=" + mMnc + " countryIso=" + mCountryIso + " isEmbedded=" + mIsEmbedded - + " nativeAccessRules=" + Arrays.toString(mNativeAccessRules) - + " cardString=" + cardStringToPrint + " cardId=" + mCardId - + " portIndex=" + mPortIndex - + " isOpportunistic=" + mIsOpportunistic + " groupUuid=" + mGroupUuid - + " isGroupDisabled=" + mIsGroupDisabled - + " profileClass=" + mProfileClass + + " dataRoaming=" + mDataRoaming + + " mcc=" + mMcc + + " mnc=" + mMnc + " ehplmns=" + Arrays.toString(mEhplmns) + " hplmns=" + Arrays.toString(mHplmns) - + " mType=" + mType - + " groupOwner=" + mGroupOwner + + " cardString=" + cardStringToPrint + + " cardId=" + mCardId + + " nativeAccessRules=" + Arrays.toString(mNativeAccessRules) + " carrierConfigAccessRules=" + Arrays.toString(mCarrierConfigAccessRules) + + " countryIso=" + mCountryIso + + " profileClass=" + mProfileClass + + " mType=" + TelephonyUtils.subscriptionTypeToString(mType) + " areUiccApplicationsEnabled=" + mAreUiccApplicationsEnabled - + " usageSetting=" + mUsageSetting + "}"; + + " usageSetting=" + TelephonyUtils.usageSettingToString(mUsageSetting) + + "]"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SubscriptionInfo that = (SubscriptionInfo) o; + return mId == that.mId && mSimSlotIndex == that.mSimSlotIndex + && mDisplayNameSource == that.mDisplayNameSource && mIconTint == that.mIconTint + && mDataRoaming == that.mDataRoaming && mIsEmbedded == that.mIsEmbedded + && mIsOpportunistic == that.mIsOpportunistic && mCarrierId == that.mCarrierId + && mProfileClass == that.mProfileClass && mType == that.mType + && mAreUiccApplicationsEnabled == that.mAreUiccApplicationsEnabled + && mPortIndex == that.mPortIndex && mUsageSetting == that.mUsageSetting + && mCardId == that.mCardId && mIsGroupDisabled == that.mIsGroupDisabled + && mIccId.equals(that.mIccId) && mDisplayName.equals(that.mDisplayName) + && mCarrierName.equals(that.mCarrierName) && mNumber.equals(that.mNumber) + && Objects.equals(mMcc, that.mMcc) && Objects.equals(mMnc, + that.mMnc) && Arrays.equals(mEhplmns, that.mEhplmns) + && Arrays.equals(mHplmns, that.mHplmns) && mCardString.equals( + that.mCardString) && Arrays.equals(mNativeAccessRules, + that.mNativeAccessRules) && Arrays.equals(mCarrierConfigAccessRules, + that.mCarrierConfigAccessRules) && Objects.equals(mGroupUuid, that.mGroupUuid) + && mCountryIso.equals(that.mCountryIso) && mGroupOwner.equals(that.mGroupOwner); } @Override public int hashCode() { - return Objects.hash(mId, mSimSlotIndex, mDisplayNameSource, mIconTint, mDataRoaming, - mIsEmbedded, mIsOpportunistic, mGroupUuid, mIccId, mNumber, mMcc, mMnc, mCountryIso, - mCardString, mCardId, mDisplayName, mCarrierName, - Arrays.hashCode(mNativeAccessRules), mIsGroupDisabled, mCarrierId, mProfileClass, - mGroupOwner, mAreUiccApplicationsEnabled, mPortIndex, mUsageSetting); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - SubscriptionInfo toCompare = (SubscriptionInfo) obj; - return mId == toCompare.mId - && mSimSlotIndex == toCompare.mSimSlotIndex - && mDisplayNameSource == toCompare.mDisplayNameSource - && mIconTint == toCompare.mIconTint - && mDataRoaming == toCompare.mDataRoaming - && mIsEmbedded == toCompare.mIsEmbedded - && mIsOpportunistic == toCompare.mIsOpportunistic - && mIsGroupDisabled == toCompare.mIsGroupDisabled - && mAreUiccApplicationsEnabled == toCompare.mAreUiccApplicationsEnabled - && mCarrierId == toCompare.mCarrierId - && Objects.equals(mGroupUuid, toCompare.mGroupUuid) - && Objects.equals(mIccId, toCompare.mIccId) - && Objects.equals(mNumber, toCompare.mNumber) - && Objects.equals(mMcc, toCompare.mMcc) - && Objects.equals(mMnc, toCompare.mMnc) - && Objects.equals(mCountryIso, toCompare.mCountryIso) - && Objects.equals(mCardString, toCompare.mCardString) - && Objects.equals(mCardId, toCompare.mCardId) - && mPortIndex == toCompare.mPortIndex - && Objects.equals(mGroupOwner, toCompare.mGroupOwner) - && TextUtils.equals(mDisplayName, toCompare.mDisplayName) - && TextUtils.equals(mCarrierName, toCompare.mCarrierName) - && Arrays.equals(mNativeAccessRules, toCompare.mNativeAccessRules) - && mProfileClass == toCompare.mProfileClass - && Arrays.equals(mEhplmns, toCompare.mEhplmns) - && Arrays.equals(mHplmns, toCompare.mHplmns) - && mUsageSetting == toCompare.mUsageSetting; + int result = Objects.hash(mId, mIccId, mSimSlotIndex, mDisplayName, mCarrierName, + mDisplayNameSource, mIconTint, mNumber, mDataRoaming, mMcc, mMnc, mIsEmbedded, + mCardString, mIsOpportunistic, mGroupUuid, mCountryIso, mCarrierId, mProfileClass, + mType, mGroupOwner, mAreUiccApplicationsEnabled, mPortIndex, mUsageSetting, mCardId, + mIsGroupDisabled); + result = 31 * result + Arrays.hashCode(mEhplmns); + result = 31 * result + Arrays.hashCode(mHplmns); + result = 31 * result + Arrays.hashCode(mNativeAccessRules); + result = 31 * result + Arrays.hashCode(mCarrierConfigAccessRules); + return result; } /** @@ -1031,7 +1041,7 @@ public class SubscriptionInfo implements Parcelable { /** * The subscription id. */ - private int mId = 0; + private int mId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; /** * The ICCID of the SIM that is associated with this subscription, empty if unknown. @@ -1064,7 +1074,7 @@ public class SubscriptionInfo implements Parcelable { * The source of the display name. */ @SimDisplayNameSource - private int mDisplayNameSource = SubscriptionManager.NAME_SOURCE_CARRIER_ID; + private int mDisplayNameSource = SubscriptionManager.NAME_SOURCE_UNKNOWN; /** * The color to be used for tinting the icon when displaying to the user. @@ -1141,7 +1151,7 @@ public class SubscriptionInfo implements Parcelable { /** * The card ID of the SIM card which contains the subscription. */ - private int mCardId = -1; + private int mCardId = TelephonyManager.UNINITIALIZED_CARD_ID; /** * Whether the subscription is opportunistic or not. @@ -1205,7 +1215,7 @@ public class SubscriptionInfo implements Parcelable { /** * the port index of the Uicc card. */ - private int mPortIndex = 0; + private int mPortIndex = TelephonyManager.INVALID_PORT_INDEX; /** * Subscription's preferred usage setting. @@ -1433,9 +1443,9 @@ public class SubscriptionInfo implements Parcelable { } /** - * Set the ISO Country code for the subscription's provider. + * Set the ISO country code for the subscription's provider. * - * @param countryIso The ISO Country code for the subscription's provider. + * @param countryIso The ISO country code for the subscription's provider. * @return The builder. */ @NonNull @@ -1592,7 +1602,7 @@ public class SubscriptionInfo implements Parcelable { * 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 + * @param carrierConfigAccessRules The carrier certificates for this subscription. * @return The builder. */ @NonNull diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 94ff7f920816d..2a86c41b5d77e 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -565,6 +565,12 @@ public class SubscriptionManager { */ public static final String NAME_SOURCE = SimInfo.COLUMN_NAME_SOURCE; + /** + * The name_source is unknown. (for initialization) + * @hide + */ + public static final int NAME_SOURCE_UNKNOWN = SimInfo.NAME_SOURCE_UNKNOWN; + /** * The name_source is from the carrier id. * @hide @@ -600,6 +606,7 @@ public class SubscriptionManager { @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"NAME_SOURCE_"}, value = { + NAME_SOURCE_UNKNOWN, NAME_SOURCE_CARRIER_ID, NAME_SOURCE_SIM_SPN, NAME_SOURCE_USER_INPUT, From dd99c8055c92fc42e30c8df9f5c9cdca0a62a32f Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Thu, 13 Oct 2022 01:59:43 -0700 Subject: [PATCH 3/3] Improved debug message Improved subscription info toString readability. Bug: 239607619 Test: Build Merged-In: I852e952a0ceeb4e16a1f63687935544a8d99e543 Change-Id: I852e952a0ceeb4e16a1f63687935544a8d99e543 --- .../telephony/util/TelephonyUtils.java | 60 ++++-------------- .../android/telephony/SubscriptionInfo.java | 6 +- .../telephony/SubscriptionManager.java | 61 +++++++++++++++++++ .../telephony/ims/ImsMmTelManager.java | 27 ++++++++ 4 files changed, 102 insertions(+), 52 deletions(-) diff --git a/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java b/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java index 79ab009d3b922..5179babbd31d7 100644 --- a/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java +++ b/telephony/common/com/android/internal/telephony/util/TelephonyUtils.java @@ -27,7 +27,6 @@ import android.os.Binder; import android.os.Bundle; import android.os.PersistableBundle; import android.os.SystemProperties; -import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import java.io.PrintWriter; @@ -195,57 +194,20 @@ public final class TelephonyUtils { } /** - * Convert display name source to string. + * Convert mobile data policy to string. * - * @param source The display name source. - * @return The display name source in string format. + * @param mobileDataPolicy The mobile data policy. + * @return The mobile data policy in string format. */ - @NonNull - public static String displayNameSourceToString( - @SubscriptionManager.SimDisplayNameSource int source) { - switch (source) { - case SubscriptionManager.NAME_SOURCE_UNKNOWN: return "UNKNOWN"; - case SubscriptionManager.NAME_SOURCE_CARRIER_ID: return "CARRIER_ID"; - case SubscriptionManager.NAME_SOURCE_SIM_SPN: return "SIM_SPN"; - case SubscriptionManager.NAME_SOURCE_USER_INPUT: return "USER_INPUT"; - case SubscriptionManager.NAME_SOURCE_CARRIER: return "CARRIER"; - case SubscriptionManager.NAME_SOURCE_SIM_PNN: return "SIM_PNN"; + public static @NonNull String mobileDataPolicyToString( + @TelephonyManager.MobileDataPolicy int mobileDataPolicy) { + switch (mobileDataPolicy) { + case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: + return "DATA_ON_NON_DEFAULT_DURING_VOICE_CALL"; + case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: + return "MMS_ALWAYS_ALLOWED"; default: - return "UNKNOWN(" + source + ")"; - } - } - - /** - * Convert subscription type to string. - * - * @param type The subscription type. - * @return The subscription type in string format. - */ - @NonNull - public static String subscriptionTypeToString(@SubscriptionManager.SubscriptionType int type) { - switch (type) { - case SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM: return "LOCAL_SIM"; - case SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM: return "REMOTE_SIM"; - default: - return "UNKNOWN(" + type + ")"; - } - } - - /** - * Convert usage setting to string. - * - * @param usageSetting Usage setting. - * @return The usage setting in string format. - */ - @NonNull - public static String usageSettingToString(@SubscriptionManager.UsageSetting int usageSetting) { - switch (usageSetting) { - case SubscriptionManager.USAGE_SETTING_UNKNOWN: return "UNKNOWN"; - case SubscriptionManager.USAGE_SETTING_DEFAULT: return "DEFAULT"; - case SubscriptionManager.USAGE_SETTING_VOICE_CENTRIC: return "VOICE_CENTRIC"; - case SubscriptionManager.USAGE_SETTING_DATA_CENTRIC: return "DATA_CENTRIC"; - default: - return "UNKNOWN(" + usageSetting + ")"; + return "UNKNOWN(" + mobileDataPolicy + ")"; } } } diff --git a/telephony/java/android/telephony/SubscriptionInfo.java b/telephony/java/android/telephony/SubscriptionInfo.java index 0d3c80fd88870..e055f637b72cc 100644 --- a/telephony/java/android/telephony/SubscriptionInfo.java +++ b/telephony/java/android/telephony/SubscriptionInfo.java @@ -974,7 +974,7 @@ public class SubscriptionInfo implements Parcelable { + " groupOwner=" + mGroupOwner + " isGroupDisabled=" + mIsGroupDisabled + " displayNameSource=" - + TelephonyUtils.displayNameSourceToString(mDisplayNameSource) + + SubscriptionManager.displayNameSourceToString(mDisplayNameSource) + " iconTint=" + mIconTint + " number=" + Rlog.pii(TelephonyUtils.IS_DEBUGGABLE, mNumber) + " dataRoaming=" + mDataRoaming @@ -988,9 +988,9 @@ public class SubscriptionInfo implements Parcelable { + " carrierConfigAccessRules=" + Arrays.toString(mCarrierConfigAccessRules) + " countryIso=" + mCountryIso + " profileClass=" + mProfileClass - + " mType=" + TelephonyUtils.subscriptionTypeToString(mType) + + " mType=" + SubscriptionManager.subscriptionTypeToString(mType) + " areUiccApplicationsEnabled=" + mAreUiccApplicationsEnabled - + " usageSetting=" + TelephonyUtils.usageSettingToString(mUsageSetting) + + " usageSetting=" + SubscriptionManager.usageSettingToString(mUsageSetting) + "]"; } diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java index 2a86c41b5d77e..50bb407ec574c 100644 --- a/telephony/java/android/telephony/SubscriptionManager.java +++ b/telephony/java/android/telephony/SubscriptionManager.java @@ -4136,5 +4136,66 @@ public class SubscriptionManager { (iSub)-> iSub.setUsageSetting( usageSetting, subscriptionId, mContext.getOpPackageName())); } + + /** + * Convert display name source to string. + * + * @param source The display name source. + * @return The display name source in string format. + * + * @hide + */ + @NonNull + public static String displayNameSourceToString( + @SubscriptionManager.SimDisplayNameSource int source) { + switch (source) { + case SubscriptionManager.NAME_SOURCE_UNKNOWN: return "UNKNOWN"; + case SubscriptionManager.NAME_SOURCE_CARRIER_ID: return "CARRIER_ID"; + case SubscriptionManager.NAME_SOURCE_SIM_SPN: return "SIM_SPN"; + case SubscriptionManager.NAME_SOURCE_USER_INPUT: return "USER_INPUT"; + case SubscriptionManager.NAME_SOURCE_CARRIER: return "CARRIER"; + case SubscriptionManager.NAME_SOURCE_SIM_PNN: return "SIM_PNN"; + default: + return "UNKNOWN(" + source + ")"; + } + } + + /** + * Convert subscription type to string. + * + * @param type The subscription type. + * @return The subscription type in string format. + * + * @hide + */ + @NonNull + public static String subscriptionTypeToString(@SubscriptionManager.SubscriptionType int type) { + switch (type) { + case SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM: return "LOCAL_SIM"; + case SubscriptionManager.SUBSCRIPTION_TYPE_REMOTE_SIM: return "REMOTE_SIM"; + default: + return "UNKNOWN(" + type + ")"; + } + } + + /** + * Convert usage setting to string. + * + * @param usageSetting Usage setting. + * @return The usage setting in string format. + * + * @hide + */ + @NonNull + public static String usageSettingToString(@SubscriptionManager.UsageSetting int usageSetting) { + switch (usageSetting) { + case SubscriptionManager.USAGE_SETTING_UNKNOWN: return "UNKNOWN"; + case SubscriptionManager.USAGE_SETTING_DEFAULT: return "DEFAULT"; + case SubscriptionManager.USAGE_SETTING_VOICE_CENTRIC: return "VOICE_CENTRIC"; + case SubscriptionManager.USAGE_SETTING_DATA_CENTRIC: return "DATA_CENTRIC"; + default: + return "UNKNOWN(" + usageSetting + ")"; + } + } } diff --git a/telephony/java/android/telephony/ims/ImsMmTelManager.java b/telephony/java/android/telephony/ims/ImsMmTelManager.java index a6ccb220d74e4..883824ffc889e 100644 --- a/telephony/java/android/telephony/ims/ImsMmTelManager.java +++ b/telephony/java/android/telephony/ims/ImsMmTelManager.java @@ -72,12 +72,19 @@ public class ImsMmTelManager implements RegistrationManager { */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = "WIFI_MODE_", value = { + WIFI_MODE_UNKNOWN, WIFI_MODE_WIFI_ONLY, WIFI_MODE_CELLULAR_PREFERRED, WIFI_MODE_WIFI_PREFERRED }) public @interface WiFiCallingMode {} + /** + * Wifi calling mode is unknown. This is for initialization only. + * @hide + */ + public static final int WIFI_MODE_UNKNOWN = -1; + /** * Register for IMS over IWLAN if WiFi signal quality is high enough. Do not hand over to LTE * registration if signal quality degrades. @@ -1581,4 +1588,24 @@ public class ImsMmTelManager implements RegistrationManager { .get()); return binder; } + + /** + * Convert Wi-Fi calling mode to string. + * + * @param mode Wi-Fi calling mode. + * @return The Wi-Fi calling mode in string format. + * + * @hide + */ + @NonNull + public static String wifiCallingModeToString(@ImsMmTelManager.WiFiCallingMode int mode) { + switch (mode) { + case ImsMmTelManager.WIFI_MODE_UNKNOWN: return "UNKNOWN"; + case ImsMmTelManager.WIFI_MODE_WIFI_ONLY: return "WIFI_ONLY"; + case ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED: return "CELLULAR_PREFERRED"; + case ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED: return "WIFI_PREFERRED"; + default: + return "UNKNOWN(" + mode + ")"; + } + } }