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

Commit 158e9fd7 authored by Adnan Begovic's avatar Adnan Begovic
Browse files

telephony: Respect user nw mode, handle DSDS non-multi-rat.

Change-Id: I2244729de6297e423a4c467fc66910895589508b
parent e041ee0d
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.preference.PreferenceManager;
import android.provider.BaseColumns;
import android.provider.Settings;
import android.telephony.RadioAccessFamily;
import android.telephony.Rlog;
@@ -1779,6 +1780,26 @@ public class SubscriptionController extends ISub.Stub {
        return result;
    }

    /* {@hide} */
    public void setUserNwMode(int subId, int nwMode) {
        logd("setUserNwMode, nwMode: " + nwMode + " subId: " + subId);
        ContentValues value = new ContentValues(1);
        value.put(SubscriptionManager.USER_NETWORK_MODE, nwMode);
        mContext.getContentResolver().update(SubscriptionManager.CONTENT_URI,
                value, BaseColumns._ID + "=" + Integer.toString(subId), null);
    }

    /* {@hide} */
    public int getUserNwMode(int subId) {
        SubscriptionInfo subInfo = getActiveSubscriptionInfo(subId, mContext.getOpPackageName());
        if (subInfo != null)  {
            return subInfo.mUserNwMode;
        } else {
            loge("getUserNwMode: invalid subId = " + subId);
            return SubscriptionManager.DEFAULT_NW_MODE;
        }
    }

    /**
     * Store properties associated with SubscriptionInfo in database
     * @param subId Subscription Id of Subscription
+85 −31
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.os.IRemoteCallback;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.preference.PreferenceManager;
import android.provider.Settings;
@@ -62,6 +63,8 @@ public class SubscriptionInfoUpdater extends Handler {
    private static final String LOG_TAG = "SubscriptionInfoUpdater";
    private static final int PROJECT_SIM_NUM = TelephonyManager.getDefault().getPhoneCount();

    private static final boolean DBG = false;

    private static final int EVENT_SIM_LOCKED_QUERY_ICCID_DONE = 1;
    private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 2;
    private static final int EVENT_SIM_LOADED = 3;
@@ -429,6 +432,30 @@ public class SubscriptionInfoUpdater extends Handler {
            int storedSubId = sp.getInt(CURR_SUBID + slotId, -1);

            if (storedSubId != subId) {
                setDefaultDataSubNetworkType(slotId, subId);
                // Update stored subId
                SharedPreferences.Editor editor = sp.edit();
                editor.putInt(CURR_SUBID + slotId, subId);
                editor.apply();
            }
        } else {
            logd("Invalid subId, could not update ContentResolver");
        }

        // Update set of enabled carrier apps now that the privilege rules may have changed.
        CarrierAppUtils.disableCarrierAppsUntilPrivileged(mContext.getOpPackageName(),
                mPackageManager, TelephonyManager.getDefault(), mCurrentlyActiveUserId);

        broadcastSimStateChanged(slotId, IccCardConstants.INTENT_VALUE_ICC_LOADED, null);
        updateCarrierServices(slotId, IccCardConstants.INTENT_VALUE_ICC_LOADED);
    }

    private void setDefaultDataSubNetworkType(int slotId, int subId) {
        if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) {
            Rlog.e(LOG_TAG, "setDefaultDataSubNetworkType called with DEFAULT_SUB_ID");
            return;
        }

        int networkType = RILConstants.PREFERRED_NETWORK_MODE;
        //Get previous network mode for this slot,
        //to be more relevant instead of default mode
@@ -445,38 +472,65 @@ public class SubscriptionInfoUpdater extends Handler {
                        mContext.getContentResolver(),
                        Settings.Global.PREFERRED_NETWORK_MODE, slotId);
            } catch (SettingNotFoundException retrySnfe) {
                        Rlog.e(LOG_TAG, "Settings Exception Reading Value At Index for"+
                Rlog.d(LOG_TAG, "Settings Exception Reading Value At Index for"+
                        " Settings.Global.PREFERRED_NETWORK_MODE");
            }
        }

        // Get users NW type, let it override if its not the default NW mode (-1)
        int userNwType = SubscriptionController.getInstance().getUserNwMode(subId);
        if (userNwType != SubscriptionManager.DEFAULT_NW_MODE && userNwType != networkType) {
            networkType = userNwType;
        }
        boolean isDsds = TelephonyManager.getDefault().getMultiSimConfiguration()
                == TelephonyManager.MultiSimVariants.DSDS;
        if (DBG) Rlog.d(LOG_TAG, "[setDefaultDataSubNetworkType] subId=" + subId);
        if (DBG) Rlog.d(LOG_TAG, "[setDefaultDataSubNetworkType] isDSDS=" + isDsds);
        boolean isMultiRat = SystemProperties.getBoolean("ro.ril.multi_rat_capable", false);

        if (isDsds && !isMultiRat) {
            int networkType2 = Phone.NT_MODE_GSM_ONLY; // Hardcoded due to modem limitation
            int slotId1 = SubscriptionManager.DEFAULT_SIM_SLOT_INDEX;
            int slotId2 = SubscriptionManager.DEFAULT_SIM_SLOT_INDEX;
            int subId1 = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
            int subId2 = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
            // Since this is DSDS, there are 2 phones
            for (int targetSlotId = 0; targetSlotId < PROJECT_SIM_NUM; targetSlotId++) {
                Phone phone = mPhone[targetSlotId];
                int id = phone.getSubId();

                if (id == subId) {
                    slotId1 = targetSlotId;
                    subId1 = id;
                    if (DBG) Rlog.d(LOG_TAG, "[setDefaultDataSubNetworkType] networkType1: "
                            + networkType + ", slotId1: " + slotId1);
                } else {
                    subId2 = id;
                    slotId2 = targetSlotId;
                    if (DBG) Rlog.d(LOG_TAG, "[setDefaultDataSubNetworkType] networkType2: "
                            + networkType2 + ", slotId2: " + slotId2);
                }
            }
            setPreferredNwModeForSlot(slotId1, subId1, networkType);
            setPreferredNwModeForSlot(slotId2, subId2, networkType2);
        } else {
            // Set the modem network mode
                mPhone[slotId].setPreferredNetworkType(networkType, null);
                Settings.Global.putInt(mPhone[slotId].getContext().getContentResolver(),
                        Settings.Global.PREFERRED_NETWORK_MODE + subId,
                        networkType);
            setPreferredNwModeForSlot(slotId, subId, networkType);
        }

        // Only support automatic selection mode on SIM change.
        mPhone[slotId].getNetworkSelectionMode(
                obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, new Integer(slotId)));

                // Update stored subId
                SharedPreferences.Editor editor = sp.edit();
                editor.putInt(CURR_SUBID + slotId, subId);
                editor.apply();
            }
        } else {
            logd("Invalid subId, could not update ContentResolver");
    }

        // Update set of enabled carrier apps now that the privilege rules may have changed.
        CarrierAppUtils.disableCarrierAppsUntilPrivileged(mContext.getOpPackageName(),
                mPackageManager, TelephonyManager.getDefault(), mCurrentlyActiveUserId);

        broadcastSimStateChanged(slotId, IccCardConstants.INTENT_VALUE_ICC_LOADED, null);
        updateCarrierServices(slotId, IccCardConstants.INTENT_VALUE_ICC_LOADED);
    private void setPreferredNwModeForSlot(int slotId, int subId, int networkType) {
        mPhone[slotId].setPreferredNetworkType(networkType, null);
        Settings.Global.putInt(mPhone[slotId].getContext().getContentResolver(),
                Settings.Global.PREFERRED_NETWORK_MODE + subId,
                networkType);
    }


    private void updateCarrierServices(int slotId, String simState) {
        CarrierConfigManager configManager = (CarrierConfigManager)
                mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);