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

Commit 620ca2c1 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Improve carrier id GTS performance" into sc-qpr1-dev am: 3523a30b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/15773320

Change-Id: I932e8093c5558998e4b337f8e73ab64924d108ce
parents 01fcb06a 3523a30b
Loading
Loading
Loading
Loading
+27 −16
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.IntentFilter;
import android.database.ContentObserver;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.Cursor;
import android.net.Uri;
import android.net.Uri;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.Handler;
import android.os.Message;
import android.os.Message;
import android.provider.Telephony;
import android.provider.Telephony;
@@ -164,7 +165,7 @@ public class CarrierResolver extends Handler {
                updateCarrierIdAndName(
                updateCarrierIdAndName(
                    carrierId, carrierName != null ? carrierName : "",
                    carrierId, carrierName != null ? carrierName : "",
                    specificCarrierId, specificCarrierName != null ? carrierName : "",
                    specificCarrierId, specificCarrierName != null ? carrierName : "",
                    mnoCarrierId);
                    mnoCarrierId, false);
            }
            }
        }
        }
    };
    };
@@ -215,12 +216,12 @@ public class CarrierResolver extends Handler {
                handleSimAbsent();
                handleSimAbsent();
                break;
                break;
            case IccCardConstants.INTENT_VALUE_ICC_LOADED:
            case IccCardConstants.INTENT_VALUE_ICC_LOADED:
                handleSimLoaded();
                handleSimLoaded(false);
                break;
                break;
        }
        }
    }
    }


    private void handleSimLoaded() {
    private void handleSimLoaded(boolean isSimOverride) {
        if (mIccRecords != null) {
        if (mIccRecords != null) {
            /**
            /**
             * returns empty string to be consistent with
             * returns empty string to be consistent with
@@ -232,7 +233,9 @@ 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(false /* update carrier config */);
        loadCarrierMatchingRulesOnMccMnc(
                false /* update carrier config */,
                isSimOverride);
    }
    }


    private void handleSimAbsent() {
    private void handleSimAbsent() {
@@ -241,7 +244,7 @@ public class CarrierResolver extends Handler {
        mPreferApn = null;
        mPreferApn = null;
        updateCarrierIdAndName(TelephonyManager.UNKNOWN_CARRIER_ID, null,
        updateCarrierIdAndName(TelephonyManager.UNKNOWN_CARRIER_ID, null,
                TelephonyManager.UNKNOWN_CARRIER_ID, null,
                TelephonyManager.UNKNOWN_CARRIER_ID, null,
                TelephonyManager.UNKNOWN_CARRIER_ID);
                TelephonyManager.UNKNOWN_CARRIER_ID, false);
    }
    }


    private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
    private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
@@ -274,19 +277,24 @@ public class CarrierResolver extends Handler {
        if (DBG) logd("handleMessage: " + msg.what);
        if (DBG) logd("handleMessage: " + msg.what);
        switch (msg.what) {
        switch (msg.what) {
            case SIM_LOAD_EVENT:
            case SIM_LOAD_EVENT:
                handleSimLoaded();
                AsyncResult result = (AsyncResult) msg.obj;
                boolean isSimOverride = false;
                if (result != null) {
                    isSimOverride = result.userObj instanceof Boolean && (Boolean) result.userObj;
                }
                handleSimLoaded(isSimOverride);
                break;
                break;
            case CARRIER_ID_DB_UPDATE_EVENT:
            case CARRIER_ID_DB_UPDATE_EVENT:
                // clean the cached carrier list version, so that a new one will be queried.
                // clean the cached carrier list version, so that a new one will be queried.
                mCarrierListVersion = null;
                mCarrierListVersion = null;
                loadCarrierMatchingRulesOnMccMnc(true /* update carrier config*/);
                loadCarrierMatchingRulesOnMccMnc(true /* update carrier config*/, false);
                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(true /* update carrier config*/);
                    matchSubscriptionCarrier(true /* update carrier config*/, false);
                }
                }
                break;
                break;
            case ICC_CHANGED_EVENT:
            case ICC_CHANGED_EVENT:
@@ -301,7 +309,8 @@ public class CarrierResolver extends Handler {
                    }
                    }
                    if (newIccRecords != null) {
                    if (newIccRecords != null) {
                        logd("new Icc object");
                        logd("new Icc object");
                        newIccRecords.registerForRecordsOverride(this, SIM_LOAD_EVENT, null);
                        newIccRecords.registerForRecordsOverride(this, SIM_LOAD_EVENT,
                                /* is sim override*/true);
                        mIccRecords = newIccRecords;
                        mIccRecords = newIccRecords;
                    }
                    }
                }
                }
@@ -312,7 +321,9 @@ public class CarrierResolver extends Handler {
        }
        }
    }
    }


    private void loadCarrierMatchingRulesOnMccMnc(boolean updateCarrierConfig) {
    private void loadCarrierMatchingRulesOnMccMnc(
            boolean updateCarrierConfig,
            boolean isSimOverride) {
        try {
        try {
            String mccmnc = mTelephonyMgr.getSimOperatorNumericForPhone(mPhone.getPhoneId());
            String mccmnc = mTelephonyMgr.getSimOperatorNumericForPhone(mPhone.getPhoneId());
            Cursor cursor = mContext.getContentResolver().query(
            Cursor cursor = mContext.getContentResolver().query(
@@ -330,7 +341,7 @@ public class CarrierResolver extends Handler {
                    while (cursor.moveToNext()) {
                    while (cursor.moveToNext()) {
                        mCarrierMatchingRulesOnMccMnc.add(makeCarrierMatchingRule(cursor));
                        mCarrierMatchingRulesOnMccMnc.add(makeCarrierMatchingRule(cursor));
                    }
                    }
                    matchSubscriptionCarrier(updateCarrierConfig);
                    matchSubscriptionCarrier(updateCarrierConfig, isSimOverride);


                    // Generate metrics related to carrier ID table version.
                    // Generate metrics related to carrier ID table version.
                    CarrierIdMatchStats.sendCarrierIdTableVersion(getCarrierListVersion());
                    CarrierIdMatchStats.sendCarrierIdTableVersion(getCarrierListVersion());
@@ -465,7 +476,7 @@ public class CarrierResolver extends Handler {


    private void updateCarrierIdAndName(int cid, String name,
    private void updateCarrierIdAndName(int cid, String name,
                                        int specificCarrierId, String specificCarrierName,
                                        int specificCarrierId, String specificCarrierName,
                                        int mnoCid) {
                                        int mnoCid, boolean isSimOverride) {
        boolean update = false;
        boolean update = false;
        if (specificCarrierId != mSpecificCarrierId) {
        if (specificCarrierId != mSpecificCarrierId) {
            logd("[updateSpecificCarrierId] from:" + mSpecificCarrierId + " to:"
            logd("[updateSpecificCarrierId] from:" + mSpecificCarrierId + " to:"
@@ -534,7 +545,7 @@ public class CarrierResolver extends Handler {
        // during esim profile switch, there is no sim absent thus carrier id will persist and
        // during esim profile switch, there is no sim absent thus carrier id will persist and
        // might not trigger an update if switch profiles for the same carrier. thus always update
        // might not trigger an update if switch profiles for the same carrier. thus always update
        // subscriptioninfo db to make sure we have correct carrier id set.
        // subscriptioninfo db to make sure we have correct carrier id set.
        if (SubscriptionManager.isValidSubscriptionId(mPhone.getSubId())) {
        if (SubscriptionManager.isValidSubscriptionId(mPhone.getSubId()) && !isSimOverride) {
            // only persist carrier id to simInfo db when subId is valid.
            // only persist carrier id to simInfo db when subId is valid.
            SubscriptionController.getInstance().setCarrierId(mCarrierId, mPhone.getSubId());
            SubscriptionController.getInstance().setCarrierId(mCarrierId, mPhone.getSubId());
        }
        }
@@ -827,7 +838,7 @@ public class CarrierResolver extends Handler {
    /**
    /**
     * 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(boolean updateCarrierConfig) {
    private void matchSubscriptionCarrier(boolean updateCarrierConfig, boolean isSimOverride) {
        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;
@@ -870,7 +881,7 @@ public class CarrierResolver extends Handler {
                    + " name: " + null);
                    + " name: " + null);
            updateCarrierIdAndName(TelephonyManager.UNKNOWN_CARRIER_ID, null,
            updateCarrierIdAndName(TelephonyManager.UNKNOWN_CARRIER_ID, null,
                    TelephonyManager.UNKNOWN_CARRIER_ID, null,
                    TelephonyManager.UNKNOWN_CARRIER_ID, null,
                    TelephonyManager.UNKNOWN_CARRIER_ID);
                    TelephonyManager.UNKNOWN_CARRIER_ID, isSimOverride);
        } else {
        } else {
            // if there is a single matching result, check if this rule has parent cid assigned.
            // if there is a single matching result, check if this rule has parent cid assigned.
            if ((maxRule == maxRuleParent)
            if ((maxRule == maxRuleParent)
@@ -884,7 +895,7 @@ public class CarrierResolver extends Handler {
                    + " name: " + maxRuleParent.mName);
                    + " name: " + maxRuleParent.mName);
            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, isSimOverride);


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