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

Commit 3bc32aa4 authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Change to use subId with PREFERRED_NETWORK_MODE in all places.

MobileNetworkSettings already does that; it was the mismatch that was
causing the issue.

Bug: 18424733
Change-Id: Ib1c6d55c5bf2cff8986c740e96881f34e536b43f
parent d3b1fc2d
Loading
Loading
Loading
Loading
+9 −36
Original line number Diff line number Diff line
@@ -117,12 +117,6 @@ public class PhoneFactory {

                sPhoneNotifier = new DefaultPhoneNotifier();

                // Get preferred network mode
                int preferredNetworkMode = RILConstants.PREFERRED_NETWORK_MODE;
                if (TelephonyManager.getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) {
                    preferredNetworkMode = Phone.NT_MODE_GLOBAL;
                }

                int cdmaSubscription = CdmaSubscriptionSourceManager.getDefault(context);
                Rlog.i(LOG_TAG, "Cdma Subscription set to " + cdmaSubscription);

@@ -136,20 +130,8 @@ public class PhoneFactory {

                for (int i = 0; i < numPhones; i++) {
                    // reads the system properties and makes commandsinterface
                    try {
//                        // Get preferred network type.
//                        TODO: Sishir added this code to but we need a new technique for MSim
//                        int networkType = calculatePreferredNetworkType(context);
//                        Rlog.i(LOG_TAG, "Network Type set to " + Integer.toString(networkType));

                        networkModes[i]  = TelephonyManager.getIntAtIndex(
                                context.getContentResolver(),
                                Settings.Global.PREFERRED_NETWORK_MODE, i);
                    } catch (SettingNotFoundException snfe) {
                        Rlog.e(LOG_TAG, "Settings Exception Reading Value At Index for"+
                                " Settings.Global.PREFERRED_NETWORK_MODE");
                        networkModes[i] = preferredNetworkMode;
                    }
                    // Get preferred network type.
                    networkModes[i] = RILConstants.PREFERRED_NETWORK_MODE;

                    Rlog.i(LOG_TAG, "Network Mode set to " + Integer.toString(networkModes[i]));
                    sCommandsInterfaces[i] = new RIL(context, networkModes[i],
@@ -310,21 +292,12 @@ public class PhoneFactory {
     * @return the preferred network mode that should be set.
     */
    // TODO: Fix when we "properly" have TelephonyDevController/SubscriptionController ..
    public static int calculatePreferredNetworkType(Context context, int phoneId) {
        int preferredNetworkType = RILConstants.PREFERRED_NETWORK_MODE;
        if (TelephonyManager.getLteOnCdmaModeStatic() == PhoneConstants.LTE_ON_CDMA_TRUE) {
            preferredNetworkType = Phone.NT_MODE_GLOBAL;
        }
        int networkType = preferredNetworkType;
        try {
            networkType = TelephonyManager.getIntAtIndex(
                    context.getContentResolver(),
                    Settings.Global.PREFERRED_NETWORK_MODE, phoneId);
        } catch (SettingNotFoundException snfe) {
            Rlog.e(LOG_TAG, "Settings Exception Reading Value At Index for"
                    + " Settings.Global.PREFERRED_NETWORK_MODE");
        }
        Rlog.d(LOG_TAG, "calculatePreferredNetworkType: phoneId = " + phoneId);
    public static int calculatePreferredNetworkType(Context context, int phoneSubId) {
        int networkType = android.provider.Settings.Global.getInt(context.getContentResolver(),
                android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
                RILConstants.PREFERRED_NETWORK_MODE);
        Rlog.d(LOG_TAG, "calculatePreferredNetworkType: phoneSubId = " + phoneSubId +
                " networkType = " + networkType);
        return networkType;
    }

+21 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import android.telephony.CellInfo;
import android.telephony.Rlog;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionListener;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Pair;
@@ -214,6 +216,22 @@ public abstract class ServiceStateTracker extends Handler {
    protected boolean mPowerOffDelayNeed = true;
    protected boolean mDeviceShuttingDown = false;

    protected final SubscriptionListener mSubscriptionListener = new SubscriptionListener() {
        /*
         * Callback invoked when there is any change to any SubscriptionInfo.
         * @see android.telephony.SubscriptionListener#onSubscriptionInfoChanged()
         */
        @Override
        public void onSubscriptionInfoChanged() {
            if (DBG) log("SubscriptionListener.onSubscriptionInfoChanged");
            // Set the network type, in case the radio does not restore it.
            if (mPhoneBase.getSubId() != SubscriptionManager.INVALID_SUB_ID) {
                int networkType = PhoneFactory.calculatePreferredNetworkType(
                        mPhoneBase.getContext(), mPhoneBase.getSubId());
                mCi.setPreferredNetworkType(networkType, null);
            }
        }
    };

    protected ServiceStateTracker(PhoneBase phoneBase, CommandsInterface ci, CellInfo cellInfo) {
        mPhoneBase = phoneBase;
@@ -226,6 +244,9 @@ public abstract class ServiceStateTracker extends Handler {
        mCi.setOnSignalStrengthUpdate(this, EVENT_SIGNAL_STRENGTH_UPDATE, null);
        mCi.registerForCellInfoList(this, EVENT_UNSOL_CELL_INFO_LIST, null);

        SubscriptionManager.register(phoneBase.getContext(), mSubscriptionListener,
                SubscriptionListener.LISTEN_SUBSCRIPTION_INFO_LIST_CHANGED);

        mPhoneBase.setSystemProperty(TelephonyProperties.PROPERTY_DATA_NETWORK_TYPE,
            ServiceState.rilRadioTechnologyToString(ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN));
    }
+2 −1
Original line number Diff line number Diff line
@@ -193,7 +193,8 @@ public class SubscriptionInfoUpdater extends Handler {
                            // Set the modem network mode
                            sPhone[slotId].setPreferredNetworkType(networkType, null);
                            Settings.Global.putInt(sPhone[slotId].getContext().getContentResolver(),
                                    Settings.Global.PREFERRED_NETWORK_MODE, networkType);
                                    Settings.Global.PREFERRED_NETWORK_MODE + sPhone[slotId].getSubId(),
                                    networkType);

                            // Only support automatic selection mode on IMSI change.
                            sPhone[slotId].getNetworkSelectionMode(
+0 −4
Original line number Diff line number Diff line
@@ -298,10 +298,6 @@ public class CdmaServiceStateTracker extends ServiceStateTracker {
            break;

        case EVENT_RUIM_READY:
            int networkType = PhoneFactory.calculatePreferredNetworkType(
                    mPhone.getContext(), mPhone.getPhoneId());
            mCi.setPreferredNetworkType(networkType, null);

            if (mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE) {
                // Subscription will be read from SIM I/O
                if (DBG) log("Receive EVENT_RUIM_READY");
+0 −5
Original line number Diff line number Diff line
@@ -320,11 +320,6 @@ final class GsmServiceStateTracker extends ServiceStateTracker {
                break;

            case EVENT_SIM_READY:
                // Set the network type, in case the radio does not restore it.
                int networkType = PhoneFactory.calculatePreferredNetworkType(
                        mPhone.getContext(), mPhone.getPhoneId());
                mCi.setPreferredNetworkType(networkType, null);

                boolean skipRestoringSelection = mPhone.getContext().getResources().getBoolean(
                        com.android.internal.R.bool.skip_restoring_network_selection);