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

Commit 84307b8d authored by Amit Mahajan's avatar Amit Mahajan Committed by Gerrit Code Review
Browse files

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

parents f3996ac0 32d1c182
Loading
Loading
Loading
Loading
+24 −6
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.Handler;
import android.os.Message;
import android.os.Message;
import android.provider.Telephony;
import android.provider.Telephony;
import android.service.carrier.CarrierIdentifier;
import android.service.carrier.CarrierIdentifier;
import android.telephony.CarrierConfigManager;
import android.telephony.PhoneStateListener;
import android.telephony.PhoneStateListener;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
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");
            loge("mIccRecords is null on SIM_LOAD_EVENT, could not get SPN");
        }
        }
        mPreferApn = getPreferApn();
        mPreferApn = getPreferApn();
        loadCarrierMatchingRulesOnMccMnc();
        loadCarrierMatchingRulesOnMccMnc(false /* update carrier config */);
    }
    }


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


    private void loadCarrierMatchingRulesOnMccMnc() {
    private void loadCarrierMatchingRulesOnMccMnc(boolean updateCarrierConfig) {
        try {
        try {
            String mccmnc = mTelephonyMgr.getSimOperatorNumericForPhone(mPhone.getPhoneId());
            String mccmnc = mTelephonyMgr.getSimOperatorNumericForPhone(mPhone.getPhoneId());
            Cursor cursor = mContext.getContentResolver().query(
            Cursor cursor = mContext.getContentResolver().query(
@@ -325,7 +326,7 @@ public class CarrierResolver extends Handler {
                    while (cursor.moveToNext()) {
                    while (cursor.moveToNext()) {
                        mCarrierMatchingRulesOnMccMnc.add(makeCarrierMatchingRule(cursor));
                        mCarrierMatchingRulesOnMccMnc.add(makeCarrierMatchingRule(cursor));
                    }
                    }
                    matchSubscriptionCarrier();
                    matchSubscriptionCarrier(updateCarrierConfig);
                }
                }
            } finally {
            } finally {
                if (cursor != null) {
                if (cursor != null) {
@@ -804,10 +805,22 @@ public class CarrierResolver extends Handler {
                TelephonyManager.UNKNOWN_CARRIER_ID);
                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.
     * find the best matching carrier from candidates with matched subscription MCCMNC.
     */
     */
    private void matchSubscriptionCarrier() {
    private void matchSubscriptionCarrier(boolean updateCarrierConfig) {
        if (!SubscriptionManager.isValidSubscriptionId(mPhone.getSubId())) {
        if (!SubscriptionManager.isValidSubscriptionId(mPhone.getSubId())) {
            logd("[matchSubscriptionCarrier]" + "skip before sim records loaded");
            logd("[matchSubscriptionCarrier]" + "skip before sim records loaded");
            return;
            return;
@@ -865,6 +878,11 @@ public class CarrierResolver extends Handler {
            updateCarrierIdAndName(maxRuleParent.mCid, maxRuleParent.mName,
            updateCarrierIdAndName(maxRuleParent.mCid, maxRuleParent.mName,
                    maxRule.mCid, maxRule.mName,
                    maxRule.mCid, maxRule.mName,
                    (mnoRule == null) ? maxRule.mCid : mnoRule.mCid);
                    (mnoRule == null) ? maxRule.mCid : mnoRule.mCid);

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


        /*
        /*
+7 −1
Original line number Original line 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) {
        switch (state) {
            case ABSENT: return IccCardConstants.INTENT_VALUE_ICC_ABSENT;
            case ABSENT: return IccCardConstants.INTENT_VALUE_ICC_ABSENT;
            case PIN_REQUIRED: return IccCardConstants.INTENT_VALUE_ICC_LOCKED;
            case PIN_REQUIRED: return IccCardConstants.INTENT_VALUE_ICC_LOCKED;
+4 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;


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


    private class CarrierIdContentProvider extends MockContentProvider {
    private class CarrierIdContentProvider extends MockContentProvider {