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

Commit 32d1c182 authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Trigger carrier config update if carrier id changes.

It is triggered only if carrier id change is not due to normal
SIM loading sequence, that is in case of APN or carrier id db
change.

Test: manually verified failing scenario works correctly now
Test: atest CarrierResolverTest
Bug: 155426801
Merged-in: I614edc291db7962ea0559ef571f98cab67869e44
Change-Id: I614edc291db7962ea0559ef571f98cab67869e44
(cherry picked from commit aee2f3c1)
parent f798f8e7
Loading
Loading
Loading
Loading
+24 −6
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.Handler;
import android.os.Message;
import android.provider.Telephony;
import android.service.carrier.CarrierIdentifier;
import android.telephony.CarrierConfigManager;
import android.telephony.PhoneStateListener;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -229,7 +230,7 @@ public class CarrierResolver extends Handler {
            loge("mIccRecords is null on SIM_LOAD_EVENT, could not get SPN");
        }
        mPreferApn = getPreferApn();
        loadCarrierMatchingRulesOnMccMnc();
        loadCarrierMatchingRulesOnMccMnc(false /* update carrier config */);
    }

    private void handleSimAbsent() {
@@ -274,14 +275,14 @@ public class CarrierResolver extends Handler {
                handleSimLoaded();
                break;
            case CARRIER_ID_DB_UPDATE_EVENT:
                loadCarrierMatchingRulesOnMccMnc();
                loadCarrierMatchingRulesOnMccMnc(true /* update carrier config*/);
                break;
            case PREFER_APN_UPDATE_EVENT:
                String preferApn = getPreferApn();
                if (!equals(mPreferApn, preferApn, true)) {
                    logd("[updatePreferApn] from:" + mPreferApn + " to:" + preferApn);
                    mPreferApn = preferApn;
                    matchSubscriptionCarrier();
                    matchSubscriptionCarrier(true /* update carrier config*/);
                }
                break;
            case ICC_CHANGED_EVENT:
@@ -307,7 +308,7 @@ public class CarrierResolver extends Handler {
        }
    }

    private void loadCarrierMatchingRulesOnMccMnc() {
    private void loadCarrierMatchingRulesOnMccMnc(boolean updateCarrierConfig) {
        try {
            String mccmnc = mTelephonyMgr.getSimOperatorNumericForPhone(mPhone.getPhoneId());
            Cursor cursor = mContext.getContentResolver().query(
@@ -325,7 +326,7 @@ public class CarrierResolver extends Handler {
                    while (cursor.moveToNext()) {
                        mCarrierMatchingRulesOnMccMnc.add(makeCarrierMatchingRule(cursor));
                    }
                    matchSubscriptionCarrier();
                    matchSubscriptionCarrier(updateCarrierConfig);
                }
            } finally {
                if (cursor != null) {
@@ -804,10 +805,22 @@ public class CarrierResolver extends Handler {
                TelephonyManager.UNKNOWN_CARRIER_ID);
    }

    private void updateCarrierConfig() {
        IccCard iccCard = mPhone.getIccCard();
        IccCardConstants.State simState = IccCardConstants.State.UNKNOWN;
        if (iccCard != null) {
            simState = iccCard.getState();
        }
        CarrierConfigManager configManager = (CarrierConfigManager)
                mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
        configManager.updateConfigForPhoneId(mPhone.getPhoneId(),
                UiccController.getIccStateIntentString(simState));
    }

    /**
     * find the best matching carrier from candidates with matched subscription MCCMNC.
     */
    private void matchSubscriptionCarrier() {
    private void matchSubscriptionCarrier(boolean updateCarrierConfig) {
        if (!SubscriptionManager.isValidSubscriptionId(mPhone.getSubId())) {
            logd("[matchSubscriptionCarrier]" + "skip before sim records loaded");
            return;
@@ -865,6 +878,11 @@ public class CarrierResolver extends Handler {
            updateCarrierIdAndName(maxRuleParent.mCid, maxRuleParent.mName,
                    maxRule.mCid, maxRule.mName,
                    (mnoRule == null) ? maxRule.mCid : mnoRule.mCid);

            if (updateCarrierConfig) {
                logd("[matchSubscriptionCarrier] - Calling updateCarrierConfig()");
                updateCarrierConfig();
            }
        }

        /*
+7 −1
Original line number Diff line number Diff line
@@ -624,7 +624,13 @@ public class UiccController extends Handler {
        }
    }

    static String getIccStateIntentString(IccCardConstants.State state) {
    /**
     * Convert IccCardConstants.State enum values to corresponding IccCardConstants String
     * constants
     * @param state IccCardConstants.State enum value
     * @return IccCardConstants String constant representing ICC state
     */
    public static String getIccStateIntentString(IccCardConstants.State state) {
        switch (state) {
            case ABSENT: return IccCardConstants.INTENT_VALUE_ICC_ABSENT;
            case PIN_REQUIRED: return IccCardConstants.INTENT_VALUE_ICC_LOCKED;
+4 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;

import android.database.Cursor;
import android.database.MatrixCursor;
@@ -257,12 +258,15 @@ public class CarrierResolverTest extends TelephonyTest {
        assertEquals(CID_VZW, mCarrierResolver.getCarrierId());
        assertEquals(NAME, mCarrierResolver.getCarrierName());
        // mock apn
        doReturn(IccCardConstants.State.LOADED).when(mUiccProfile).getState();
        ((MockContentResolver) mContext.getContentResolver()).addProvider(
                Carriers.CONTENT_URI.getAuthority(), new CarrierIdContentProvider());
        mCarrierResolver.sendEmptyMessage(PREFER_APN_SET_EVENT);
        processAllMessages();
        assertEquals(CID_DOCOMO, mCarrierResolver.getCarrierId());
        assertEquals(NAME_DOCOMO, mCarrierResolver.getCarrierName());
        verify(mCarrierConfigManager).updateConfigForPhoneId(phoneId,
                IccCardConstants.INTENT_VALUE_ICC_LOADED);
    }

    private class CarrierIdContentProvider extends MockContentProvider {