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

Commit f2386bbd authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Trigger carrier config update if carrier id changes."

parents d56ecb1a aee2f3c1
Loading
Loading
Loading
Loading
+24 −6
Original line number Diff line number Diff line
@@ -31,6 +31,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;
@@ -231,7 +232,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() {
@@ -278,14 +279,14 @@ public class CarrierResolver extends Handler {
            case CARRIER_ID_DB_UPDATE_EVENT:
                // clean the cached carrier list version, so that a new one will be queried.
                mCarrierListVersion = null;
                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:
@@ -311,7 +312,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(
@@ -329,7 +330,7 @@ public class CarrierResolver extends Handler {
                    while (cursor.moveToNext()) {
                        mCarrierMatchingRulesOnMccMnc.add(makeCarrierMatchingRule(cursor));
                    }
                    matchSubscriptionCarrier();
                    matchSubscriptionCarrier(updateCarrierConfig);

                    // Generate metrics related to carrier ID table version.
                    CarrierIdMatchStats.sendCarrierIdTableVersion(getCarrierListVersion());
@@ -811,10 +812,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;
@@ -872,6 +885,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 {