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

Commit f4e42037 authored by Robert Greenwalt's avatar Robert Greenwalt Committed by Android (Google) Code Review
Browse files

Merge "Don't send unnecessary setNetworkSelectionMode cmd" into mnc-dev

parents 56f004ca a9031ce0
Loading
Loading
Loading
Loading
+48 −14
Original line number Diff line number Diff line
@@ -171,7 +171,9 @@ public abstract class PhoneBase extends Handler implements Phone {
    protected static final int EVENT_GET_RADIO_CAPABILITY           = 35;
    protected static final int EVENT_SS                             = 36;
    protected static final int EVENT_CONFIG_LCE                     = 37;
    protected static final int EVENT_LAST                           = EVENT_CONFIG_LCE;
    private static final int EVENT_CHECK_FOR_NETWORK_AUTOMATIC      = 38;
    protected static final int EVENT_LAST                           =
            EVENT_CHECK_FOR_NETWORK_AUTOMATIC;

    // For shared prefs.
    private static final String GSM_ROAMING_LIST_OVERRIDE_PREFIX = "gsm_roaming_list_";
@@ -660,6 +662,10 @@ public abstract class PhoneBase extends Handler implements Phone {
                }
                break;

            case EVENT_CHECK_FOR_NETWORK_AUTOMATIC: {
                onCheckForNetworkSelectionModeAutomatic(msg);
                break;
            }
            default:
                throw new RuntimeException("unexpected event not handled");
        }
@@ -966,6 +972,31 @@ public abstract class PhoneBase extends Handler implements Phone {

    @Override
    public void setNetworkSelectionModeAutomatic(Message response) {
        Rlog.d(LOG_TAG, "setNetworkSelectionModeAutomatic, querying current mode");
        // we don't want to do this unecesarily - it acutally causes
        // the radio to repeate network selection and is costly
        // first check if we're already in automatic mode
        Message msg = obtainMessage(EVENT_CHECK_FOR_NETWORK_AUTOMATIC);
        msg.obj = response;
        mCi.getNetworkSelectionMode(msg);
    }

    private void onCheckForNetworkSelectionModeAutomatic(Message fromRil) {
        AsyncResult ar = (AsyncResult)fromRil.obj;
        Message response = (Message)ar.userObj;
        boolean doAutomatic = true;
        if (ar.exception == null && ar.result != null) {
            try {
                int[] modes = (int[])ar.result;
                if (modes[0] == 0) {
                    // already confirmed to be in automatic mode - don't resend
                    doAutomatic = false;
                }
            } catch (Exception e) {
                // send the setting on error
            }
        }
        if (doAutomatic) {
            // wrap the response message in our own message along with
            // an empty string (to indicate automatic selection) for the
            // operator's id.
@@ -979,6 +1010,9 @@ public abstract class PhoneBase extends Handler implements Phone {
            mCi.setNetworkSelectionModeAutomatic(msg);

            updateSavedNetworkOperator(nsm);
        } else {
            Rlog.d(LOG_TAG, "setNetworkSelectionModeAutomatic - already auto, ignoring");
        }
    }

    @Override