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

Commit be498427 authored by Fairphone ODM's avatar Fairphone ODM Committed by Rohit Sekhar
Browse files

telephony: Broadcast country code information from cellinfo

Change-Id: Ib726a6300deec9ecab05cb928953aab446ae1934
parent 065fa911
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -323,6 +323,12 @@ public class GsmCdmaPhone extends Phone {
    // N1 mode, this value will be initialized before any attempt to set the value in the modem.
    private Boolean mModemN1Mode = null;

    //[FEATURE]-Add- Begin by shaopan.tang 2025-08-12 FPS-3324 Broadcast country code information
    private String mLastMcc = "";
    // NA carrier MCC group
    private static final ArrayList<String> NA_MCC = new ArrayList<String>(Arrays.asList("310", "311","312","313", "314", "315", "316", "302"));
    //[FEATURE]-Add-End by shaopan.tang

    // Constructors

    public GsmCdmaPhone(Context context, CommandsInterface ci, PhoneNotifier notifier, int phoneId,
@@ -3502,6 +3508,38 @@ public class GsmCdmaPhone extends Phone {
                RegistrationFailedEvent rfe = (RegistrationFailedEvent) ar.result;
                mNotifier.notifyRegistrationFailed(this, rfe.cellIdentity, rfe.chosenPlmn,
                        rfe.domain, rfe.causeCode, rfe.additionalCauseCode);

                //[FEATURE]-Add-Begin by shaopan.tang 2025-08-12 FPS-3324 Broadcast country code information from cellinfo
                String mCurrentMcc;
                if (rfe.cellIdentity == null){
                    mCurrentMcc = "";
                } else {
                    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";
                    }

                    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());

                    Intent intent = new Intent("android.intent.action.NETWORK_COUNTRYCODE_UPDATED");
                    intent.putExtra("countrycode", networkCountry);
                    SubscriptionManager.putPhoneIdAndSubIdExtra(intent, getPhoneId());
                    mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
                }
                //[FEATURE]-Add-End by shaopan.tang
                break;

            case EVENT_BARRING_INFO_CHANGED:
+40 −0
Original line number Diff line number Diff line
@@ -128,6 +128,7 @@ import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
@@ -360,6 +361,8 @@ public class ServiceStateTracker extends Handler {
    private Pattern mOperatorNameStringPattern;
    private PersistableBundle mCarrierConfig;

    private String mLastMcc = "";//[FEATURE]-Add by shaopan.tang 2025-08-12 FPS-3324 Broadcast country code information

    private class SstSubscriptionsChangedListener extends OnSubscriptionsChangedListener {

        /**
@@ -5866,7 +5869,44 @@ public class ServiceStateTracker extends Handler {
        if (cellInfos == null || cellInfos.isEmpty()) {
            return;
        }

        //[FEATURE]-Add-Begin by shaopan.tang 2025-08-12 FPS-3324 Broadcast country code information from cellinfo
        String mCurrentMcc;
        boolean isMCCUpdated = 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();
            }
            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);
                mLastMcc = mCurrentMcc;
                isMCCUpdated = true;

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

                SystemProperties.set("persist.radio.network_countrycode", networkCountry);
                log("updateOperatorNameForCellInfo: read property : " + SystemProperties.get("persist.radio.network_countrycode", ""));
                log("updateOperatorNameForCellInfo: mLastMcc= " + mLastMcc + " for phoneid " + mPhone.getPhoneId());

                Intent intent = new Intent("android.intent.action.NETWORK_COUNTRYCODE_UPDATED");
                intent.putExtra("countrycode", networkCountry);
                SubscriptionManager.putPhoneIdAndSubIdExtra(intent, mPhone.getPhoneId());
                mPhone.getContext().sendStickyBroadcastAsUser(intent, UserHandle.ALL);
            }
        //[FEATURE]-Add-End by shaopan.tang

            if (cellInfo.isRegistered()) {
                updateOperatorNameForCellIdentity(cellInfo.getCellIdentity());
            }