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

Commit 2b66eec2 authored by Rohit Sekhar's avatar Rohit Sekhar Committed by Nishith Khanna
Browse files

telephony: Avoid country code broadcasts on unknown MCC



* Ignore null/empty MCC values when deriving network country
  to prevent false "EU" broadcasts during attach/search.

Co-authored-by: default avatarDaniel Jacob Chittoor <djchittoor47@gmail.com>
Change-Id: Ic035c4bd316876d5555932537781e3541b5735e4
parent 3aa16243
Loading
Loading
Loading
Loading
+11 −16
Original line number Diff line number Diff line
@@ -3507,26 +3507,21 @@ public class GsmCdmaPhone extends Phone {
                mNotifier.notifyRegistrationFailed(this, rfe.cellIdentity, rfe.chosenPlmn,
                        rfe.domain, rfe.causeCode, rfe.additionalCauseCode);

                String mCurrentMcc;
                if (rfe.cellIdentity == null){
                    mCurrentMcc = "";
                } else {
                    mCurrentMcc = rfe.cellIdentity.getMccString();
                }
                if (rfe.cellIdentity == null) break;

                final String mCurrentMcc = rfe.cellIdentity.getMccString();
                logd("EVENT_REGISTRATION_FAILED: mCurrentMcc: " + mCurrentMcc + " mLastMcc: " + mLastMcc);
                if (mLastMcc != null && !mLastMcc.equals(mCurrentMcc)){
                    logd("EVENT_REGISTRATION_FAILED: Broadcast country code changed event mCurrentMcc: " + mCurrentMcc + " mLastMcc: " + mLastMcc);
                    mLastMcc = mCurrentMcc;

                    String networkCountry;
                    if (mCurrentMcc != null && NA_MCC.contains(mCurrentMcc)){
                        networkCountry = "US";
                    } else if (mCurrentMcc != null && mCurrentMcc.equals("")){
                        networkCountry = "OTHERS";
                    } else {
                        networkCountry = "EU";
                if (TextUtils.isEmpty(mCurrentMcc)) {
                    break;
                }

                if (!TextUtils.equals(mLastMcc, mCurrentMcc)) {
                    logd("EVENT_REGISTRATION_FAILED: Broadcasting country code change mCurrentMcc: " + mCurrentMcc + " mLastMcc: " + mLastMcc);
                    mLastMcc = mCurrentMcc;

                    final String networkCountry = NA_MCC.contains(mCurrentMcc) ? "US" : "EU";

                    SystemProperties.set("persist.radio.network_countrycode", networkCountry);
                    logd("EVENT_REGISTRATION_FAILED: read property : " + SystemProperties.get("persist.radio.network_countrycode", ""));
                    logd("EVENT_REGISTRATION_FAILED: mLastMcc= " + mLastMcc + " for phoneid " + getPhoneId());
+18 −18
Original line number Diff line number Diff line
@@ -5871,29 +5871,29 @@ public class ServiceStateTracker extends Handler {
        }

        String mCurrentMcc;
        boolean isMCCUpdated = false;
        boolean isMCCUpdatedThisPass = false;
        // NA carrier MCC group
        ArrayList<String> NA_MCC = new ArrayList<String>(Arrays.asList("310", "311", "312", "313", "314", "315", "316", "302"));

        for (CellInfo cellInfo : cellInfos) {
            if (cellInfo.getCellIdentity() == null){
                mCurrentMcc = "";
            } else {
                mCurrentMcc = cellInfo.getCellIdentity().getMccString();
            mCurrentMcc = (cellInfo.getCellIdentity() != null)
                    ? cellInfo.getCellIdentity().getMccString()
                    : null;

            if (TextUtils.isEmpty(mCurrentMcc)) {
                log("updateOperatorNameForCellInfo: MCC unknown; skipping (mCurrentMcc=" + mCurrentMcc + ")");
                continue;
            }
            log("updateOperatorNameForCellInfo: mCurrentMcc: " + mCurrentMcc + " mLastMcc: " + mLastMcc + " isMCCUpdated: " + isMCCUpdated);
            if (mLastMcc != null && !mLastMcc.equals(mCurrentMcc) && !isMCCUpdated){
                log("updateOperatorNameForCellInfo: Broadcast country code changed event mCurrentMcc: " + mCurrentMcc + " mLastMcc: " + mLastMcc);

            log("updateOperatorNameForCellInfo: mCurrentMcc: " + mCurrentMcc + " mLastMcc: " + mLastMcc + " isMCCUpdatedThisPass: " + isMCCUpdatedThisPass);

            // Only react once per pass
            if (!TextUtils.equals(mLastMcc, mCurrentMcc) && !isMCCUpdatedThisPass) {
                log("updateOperatorNameForCellInfo: Broadcasting country code change mCurrentMcc: " + mCurrentMcc + " mLastMcc: " + mLastMcc);
                mLastMcc = mCurrentMcc;
                isMCCUpdated = true;
                isMCCUpdatedThisPass = true;

                String networkCountry;
                if (mCurrentMcc != null && NA_MCC.contains(mCurrentMcc)){
                    networkCountry = "US";
                } else if (mCurrentMcc != null && mCurrentMcc.equals("")){
                    networkCountry = "OTHERS";
                } else {
                    networkCountry = "EU";
                }
                final String networkCountry = NA_MCC.contains(mCurrentMcc) ? "US" : "EU";

                SystemProperties.set("persist.radio.network_countrycode", networkCountry);
                log("updateOperatorNameForCellInfo: read property : " + SystemProperties.get("persist.radio.network_countrycode", ""));