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

Commit 591c3b22 authored by Chen Xu's avatar Chen Xu Committed by android-build-merger
Browse files

Merge "use carrier id based iso country code to override MccTable"

am: 161a5586

Change-Id: Ie28eb8d13033656186459171f307219483c29458
parents 4da6eead 161a5586
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -369,6 +369,7 @@ public class GsmCdmaPhone extends Phone {
        if (TextUtils.isEmpty(operatorNumeric)) {
            logd("setIsoCountryProperty: clear 'gsm.sim.operator.iso-country'");
            tm.setSimCountryIsoForPhone(mPhoneId, "");
            SubscriptionController.getInstance().setCountryIso("", getSubId());
        } else {
            String iso = "";
            try {
@@ -379,6 +380,7 @@ public class GsmCdmaPhone extends Phone {

            logd("setIsoCountryProperty: set 'gsm.sim.operator.iso-country' to iso=" + iso);
            tm.setSimCountryIsoForPhone(mPhoneId, iso);
            SubscriptionController.getInstance().setCountryIso(iso, getSubId());
        }
    }

+23 −16
Original line number Diff line number Diff line
@@ -303,8 +303,8 @@ public class SubscriptionController extends ISub.Stub {
                SubscriptionManager.MNC_STRING));
        String cardId = cursor.getString(cursor.getColumnIndexOrThrow(
                SubscriptionManager.CARD_ID));
        // FIXME: consider stick this into database too
        String countryIso = getSubscriptionCountryIso(id);
        String countryIso = cursor.getString(cursor.getColumnIndexOrThrow(
                SubscriptionManager.ISO_COUNTRY_CODE));
        boolean isEmbedded = cursor.getInt(cursor.getColumnIndexOrThrow(
                SubscriptionManager.IS_EMBEDDED)) == 1;
        UiccAccessRule[] accessRules;
@@ -343,20 +343,6 @@ public class SubscriptionController extends ISub.Stub {
                isEmbedded, accessRules, cardId, isOpportunistic, groupUUID, isMetered);
    }

    /**
     * Get ISO country code for the subscription's provider
     *
     * @param subId The subscription ID
     * @return The ISO country code for the subscription's provider
     */
    private String getSubscriptionCountryIso(int subId) {
        final int phoneId = getPhoneId(subId);
        if (phoneId < 0) {
            return "";
        }
        return mTelephonyManager.getSimCountryIsoForPhone(phoneId);
    }

    /**
     * Query SubInfoRecord(s) from subinfo database
     * @param selection A filter declaring which rows to return
@@ -1388,6 +1374,27 @@ public class SubscriptionController extends ISub.Stub {
        return result;
    }

    /**
     * Set ISO country code by subscription ID
     * @param iso iso country code associated with the subscription
     * @param subId the unique SubInfoRecord index in database
     * @return the number of records updated
     */
    public int setCountryIso(String iso, int subId) {
        if (DBG) logd("[setCountryIso]+ iso:" + iso + " subId:" + subId);
        ContentValues value = new ContentValues();
        value.put(SubscriptionManager.ISO_COUNTRY_CODE, iso);

        int result = mContext.getContentResolver().update(
                SubscriptionManager.getUriForSubscriptionId(subId), value, null, null);

        // Refresh the Cache of Active Subscription Info List
        refreshCachedActiveSubscriptionInfoList();

        notifySubscriptionInfoChanged();
        return result;
    }

    @Override
    public int getSlotIndex(int subId) {
        if (VDBG) printStackTrace("[getSlotIndex] subId=" + subId);
+8 −0
Original line number Diff line number Diff line
@@ -400,6 +400,14 @@ public class SubscriptionInfoUpdater extends Handler {
                    logd("EVENT_RECORDS_LOADED Operator name is null");
                }

                String iso = tm.getSimCountryIsoForPhone(slotId);

                if (!TextUtils.isEmpty(iso)) {
                    SubscriptionController.getInstance().setCountryIso(iso, subId);
                } else {
                    logd("EVENT_RECORDS_LOADED sim country iso is null");
                }

                String msisdn = tm.getLine1Number(subId);
                ContentResolver contentResolver = mContext.getContentResolver();

+36 −0
Original line number Diff line number Diff line
@@ -205,6 +205,7 @@ public class UiccProfile extends IccCard {

                case EVENT_CARRIER_CONFIG_CHANGED:
                    handleCarrierNameOverride();
                    handleSimCountryIsoOverride();
                    break;

                case EVENT_OPEN_LOGICAL_CHANNEL_DONE:
@@ -353,6 +354,41 @@ public class UiccProfile extends IccCard {
        updateCarrierNameForSubscription(subCon, subId);
    }

    /**
     * Override sim country iso based on carrier config.
     * Telephony country iso is based on MCC table which is coarse and doesn't work with dual IMSI
     * SIM. e.g, a US carrier might have a roaming agreement with carriers from Europe. Devices
     * will switch to different IMSI (differnt mccmnc) when enter roaming state. As a result, sim
     * country iso (locale) will change to non-US.
     *
     * Each sim carrier should have a single country code. We should improve the accuracy of
     * SIM country code look-up by using carrierid-to-countrycode table as an override on top of
     * MCC table
     */
    private void handleSimCountryIsoOverride() {
        SubscriptionController subCon = SubscriptionController.getInstance();
        final int subId = subCon.getSubIdUsingPhoneId(mPhoneId);
        if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
            loge("subId not valid for Phone " + mPhoneId);
            return;
        }

        CarrierConfigManager configLoader = (CarrierConfigManager)
                mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
        if (configLoader == null) {
            loge("Failed to load a Carrier Config");
            return;
        }

        PersistableBundle config = configLoader.getConfigForSubId(subId);
        String iso = config.getString(CarrierConfigManager.KEY_SIM_COUNTRY_ISO_OVERRIDE_STRING);
        if (!TextUtils.isEmpty(iso) &&
                !iso.equals(mTelephonyManager.getSimCountryIsoForPhone(mPhoneId))) {
            mTelephonyManager.setSimCountryIsoForPhone(mPhoneId, iso);
            SubscriptionController.getInstance().setCountryIso(iso, subId);
        }
    }

    private void updateCarrierNameForSubscription(SubscriptionController subCon, int subId) {
        /* update display name with carrier override */
        SubscriptionInfo subInfo = subCon.getActiveSubscriptionInfo(
+2 −1
Original line number Diff line number Diff line
@@ -98,7 +98,8 @@ public class FakeTelephonyProvider extends MockContentProvider {
                    + SubscriptionManager.WFC_IMS_ROAMING_ENABLED + " INTEGER DEFAULT -1,"
                    + SubscriptionManager.IS_OPPORTUNISTIC + " INTEGER DEFAULT 0,"
                    + SubscriptionManager.GROUP_UUID + " TEXT,"
                    + SubscriptionManager.IS_METERED + " INTEGER DEFAULT 1"
                    + SubscriptionManager.IS_METERED + " INTEGER DEFAULT 1,"
                    + SubscriptionManager.ISO_COUNTRY_CODE + " TEXT"
                    + ");";
        }