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

Commit fb80960b authored by Amit Mahajan's avatar Amit Mahajan
Browse files

eSIM profiles nickname should not override user input display name.

Test: manual
Bug: 131803649
Merged-in: I12391945bde4278a4cee5942cf05322db215b515
Change-Id: I12391945bde4278a4cee5942cf05322db215b515
(cherry picked from commit 963bfe99)
parent 411dd507
Loading
Loading
Loading
Loading
+28 −1
Original line number Diff line number Diff line
@@ -1535,12 +1535,32 @@ public class SubscriptionController extends ISub.Stub {
        }
    }

    /**
     * This is only for internal use and the returned priority is arbitrary. The idea is to give a
     * higher value to name source that has higher priority to override other name sources.
     * @param nameSource Source of display name
     * @return int representing the priority. Higher value means higher priority.
     */
    public static int getNameSourcePriority(int nameSource) {
        switch (nameSource) {
            case SubscriptionManager.NAME_SOURCE_USER_INPUT:
                return 3;
            case SubscriptionManager.NAME_SOURCE_CARRIER:
                return 2;
            case SubscriptionManager.NAME_SOURCE_SIM_SOURCE:
                return 1;
            case SubscriptionManager.NAME_SOURCE_DEFAULT_SOURCE:
            default:
                return 0;
        }
    }

    /**
     * Set display name by simInfo index with name source
     * @param displayName the display name of SIM card
     * @param subId the unique SubInfoRecord index in database
     * @param nameSource 0: NAME_SOURCE_DEFAULT_SOURCE, 1: NAME_SOURCE_SIM_SOURCE,
     *                   2: NAME_SOURCE_USER_INPUT
     *                   2: NAME_SOURCE_USER_INPUT, 3: NAME_SOURCE_CARRIER
     * @return the number of records updated
     */
    @Override
@@ -1556,6 +1576,13 @@ public class SubscriptionController extends ISub.Stub {
        final long identity = Binder.clearCallingIdentity();
        try {
            validateSubId(subId);
            for (SubscriptionInfo subInfo : mCacheActiveSubInfoList) {
                if (subInfo.getSubscriptionId() == subId
                        && getNameSourcePriority(subInfo.getNameSource())
                                > getNameSourcePriority(nameSource)) {
                    return 0;
                }
            }
            String nameToSet;
            if (displayName == null) {
                nameToSet = mContext.getString(SubscriptionManager.DEFAULT_NAME_RES);
+10 −2
Original line number Diff line number Diff line
@@ -701,11 +701,13 @@ public class SubscriptionInfoUpdater extends Handler {
        for (EuiccProfileInfo embeddedProfile : embeddedProfiles) {
            int index =
                    findSubscriptionInfoForIccid(existingSubscriptions, embeddedProfile.getIccid());
            int nameSource = SubscriptionManager.NAME_SOURCE_DEFAULT_SOURCE;
            if (index < 0) {
                // No existing entry for this ICCID; create an empty one.
                SubscriptionController.getInstance().insertEmptySubInfoRecord(
                        embeddedProfile.getIccid(), SubscriptionManager.SIM_NOT_INSERTED);
            } else {
                nameSource = existingSubscriptions.get(index).getNameSource();
                existingSubscriptions.remove(index);
            }

@@ -725,8 +727,14 @@ public class SubscriptionInfoUpdater extends Handler {
                    isRuleListEmpty ? null : UiccAccessRule.encodeRules(
                            ruleList.toArray(new UiccAccessRule[ruleList.size()])));
            values.put(SubscriptionManager.IS_REMOVABLE, isRemovable);
            // override DISPLAY_NAME if the priority of existing nameSource is <= carrier
            if (SubscriptionController.getNameSourcePriority(nameSource)
                    <= SubscriptionController.getNameSourcePriority(
                            SubscriptionManager.NAME_SOURCE_CARRIER)) {
                values.put(SubscriptionManager.DISPLAY_NAME, embeddedProfile.getNickname());
            values.put(SubscriptionManager.NAME_SOURCE, SubscriptionManager.NAME_SOURCE_USER_INPUT);
                values.put(SubscriptionManager.NAME_SOURCE,
                        SubscriptionManager.NAME_SOURCE_CARRIER);
            }
            values.put(SubscriptionManager.PROFILE_CLASS, embeddedProfile.getProfileClass());
            CarrierIdentifier cid = embeddedProfile.getCarrierIdentifier();
            if (cid != null) {
+8 −8
Original line number Diff line number Diff line
@@ -341,12 +341,14 @@ public class UiccProfile extends IccCard {

        String newCarrierName = null;
        String currSpn = getServiceProviderName();
        int nameSource = SubscriptionManager.NAME_SOURCE_SIM_SOURCE;
        // If carrier config is priority, use it regardless - the preference
        // and the name were both set by the carrier, so this is safe;
        // otherwise, if the SPN is priority but we don't have one *and* we have
        // a name in carrier config, use the carrier config name as a backup.
        if (preferCcName || (TextUtils.isEmpty(currSpn) && !TextUtils.isEmpty(ccName))) {
            newCarrierName = ccName;
            nameSource = SubscriptionManager.NAME_SOURCE_CARRIER;
        } else if (TextUtils.isEmpty(currSpn)) {
            // currSpn is empty and could not get name from carrier config; get name from carrier id
            Phone phone = PhoneFactory.getPhone(mPhoneId);
@@ -360,7 +362,7 @@ public class UiccProfile extends IccCard {
            mOperatorBrandOverrideRegistrants.notifyRegistrants();
        }

        updateCarrierNameForSubscription(subCon, subId);
        updateCarrierNameForSubscription(subCon, subId, nameSource);
    }

    /**
@@ -394,18 +396,17 @@ public class UiccProfile extends IccCard {
        if (!TextUtils.isEmpty(iso) &&
                !iso.equals(mTelephonyManager.getSimCountryIsoForPhone(mPhoneId))) {
            mTelephonyManager.setSimCountryIsoForPhone(mPhoneId, iso);
            SubscriptionController.getInstance().setCountryIso(iso, subId);
            subCon.setCountryIso(iso, subId);
        }
    }

    private void updateCarrierNameForSubscription(SubscriptionController subCon, int subId) {
    private void updateCarrierNameForSubscription(SubscriptionController subCon, int subId,
            int nameSource) {
        /* update display name with carrier override */
        SubscriptionInfo subInfo = subCon.getActiveSubscriptionInfo(
                subId, mContext.getOpPackageName());

        if (subInfo == null || subInfo.getNameSource()
                == SubscriptionManager.NAME_SOURCE_USER_INPUT) {
            // either way, there is no subinfo to update
        if (subInfo == null) {
            return;
        }

@@ -414,8 +415,7 @@ public class UiccProfile extends IccCard {

        if (!TextUtils.isEmpty(newCarrierName) && !newCarrierName.equals(oldSubName)) {
            log("sim name[" + mPhoneId + "] = " + newCarrierName);
            subCon.setDisplayNameUsingSrc(newCarrierName, subId,
                    SubscriptionManager.NAME_SOURCE_SIM_SOURCE);
            subCon.setDisplayNameUsingSrc(newCarrierName, subId, nameSource);
        }
    }