Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 004ad82f authored by Jack Yu's avatar Jack Yu Committed by Automerger Merge Worker
Browse files

Fixed equals and hashCode am: 9edb93ce

parents 91f71e17 9edb93ce
Loading
Loading
Loading
Loading
+88 −0
Original line number Diff line number Diff line
@@ -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<String> 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<String> getAllColumns() {
            return ALL_COLUMNS;
        }
    }
}
+56 −0
Original line number Diff line number Diff line
@@ -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 + ")";
        }
    }
}
+108 −98
Original line number Diff line number Diff line
@@ -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.
     */
@@ -157,15 +144,16 @@ public class SubscriptionInfo implements Parcelable {
    private final String[] mHplmns;

    /**
     * ISO Country code for the subscription's provider.
     * Whether the subscription is from eSIM.
     */
    @NonNull
    private final String mCountryIso;
    private final boolean mIsEmbedded;

    /**
     * Whether the subscription is from eSIM.
     * 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 final boolean mIsEmbedded;
    @NonNull
    private final String mCardString;

    /**
     * The access rules for this subscription, if it is embedded and defines any. This does not
@@ -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<String> 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<String> 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
                + " 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
        return "[SubscriptionInfo: id=" + mId
                + " iccId=" + iccIdToPrint
                + " simSlotIndex=" + mSimSlotIndex
                + " portIndex=" + mPortIndex
                + " isOpportunistic=" + mIsOpportunistic + " groupUuid=" + mGroupUuid
                + " isEmbedded=" + mIsEmbedded
                + " carrierId=" + mCarrierId
                + " displayName=" + mDisplayName
                + " carrierName=" + mCarrierName
                + " isOpportunistic=" + mIsOpportunistic
                + " groupUuid=" + mGroupUuid
                + " groupOwner=" + mGroupOwner
                + " isGroupDisabled=" + mIsGroupDisabled
                + " profileClass=" + mProfileClass
                + " displayNameSource="
                + TelephonyUtils.displayNameSourceToString(mDisplayNameSource)
                + " iconTint=" + mIconTint
                + " number=" + Rlog.pii(TelephonyUtils.IS_DEBUGGABLE, mNumber)
                + " 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 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);
    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 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;
    public int hashCode() {
        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
+7 −0
Original line number Diff line number Diff line
@@ -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,