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

Commit 1b36abf3 authored by Rakesh Pallerla's avatar Rakesh Pallerla Committed by Linux Build Service Account
Browse files

Store Network Mode selected in subId Table.

Store the user prefered network mode for a sub
in simInfo table so that on subsequent bootups user
preference is retreived and same is set for that sub.

Change-Id: I6d06c0cee19b2396406a09442eb10e6aef16c6c8
parent ffcbbb38
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.os.RegistrantList;
import android.provider.Settings.SettingNotFoundException;
import android.telephony.Rlog;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;

import com.android.internal.telephony.CommandException;
@@ -249,6 +250,51 @@ public class ModemBindingPolicyHandler extends Handler {
            }
        }
    }

    /*
    * updatePrefNwTypeIfRequired: Method used to set pref network type if required.
    *
    * Description: If Network mode for a subid in simInfo table is valid and and is not
    * equal to value in DB, then update the DB value and send request to RIL.
    */
    public void updatePrefNwTypeIfRequired(){
        boolean updateRequired = false;
        int[] nwModeinSubIdTable = new int[mNumPhones];
        syncPreferredNwModeFromDB();
        SubscriptionController subCtrlr = SubscriptionController.getInstance();
        for (int i=0; i < mNumPhones; i++ ) {
            long[] subIdList = subCtrlr.getSubId(i);
            if (subIdList != null && subIdList[0] > 0) {
                long subId = subIdList[0];
                nwModeinSubIdTable[i] = subCtrlr.getNwMode(subId);
                if (nwModeinSubIdTable[i] == SubscriptionManager.DEFAULT_NW_MODE){
                    updateRequired = false;
                    break;
                }
                if (nwModeinSubIdTable[i] != mPrefNwMode[i]) {
                    updateRequired = true;
                }
            }
        }

        if (updateRequired) {
            for (int i=0; i < mNumPhones; i++ ) {
                logd("Updating Value in DB for slot[" + i + "] with " + nwModeinSubIdTable[i]);
                TelephonyManager.putIntAtIndex( mContext.getContentResolver(),
                        android.provider.Settings.Global.PREFERRED_NETWORK_MODE,
                        i, nwModeinSubIdTable[i]);
            }
            if (FAILURE == updateStackBindingIfRequired(false)) {
                //In case of Update Stack Binding not required or failure, send setPrefNwType to
                //RIL immediately. In case of success after stack binding completed setPrefNwType
                //request is anyways sent.
                for (int i=0; i < mNumPhones; i++ ) {
                    mCi[i].setPreferredNetworkType(nwModeinSubIdTable[i], null);
                }
            }
       }
    }

    private void handleModemRatCapsAvailable() {
        mModemRatCapabilitiesAvailable = true;
        //Initialization sequence: Need to send Bind request always, so override is true.
+6 −5
Original line number Diff line number Diff line
@@ -259,8 +259,8 @@ public class SubInfoRecordUpdater extends Handler {
                break;
            case EVENT_STACK_READY:
                logd("EVENT_STACK_READY" );
                if (isAllIccIdQueryDone()) {
                    updateSimInfoByIccId();
                if (isAllIccIdQueryDone() && PROJECT_SIM_NUM > 1) {
                    SubscriptionHelper.getInstance().updateSubActivation();
                }
                break;
            default:
@@ -342,7 +342,6 @@ public class SubInfoRecordUpdater extends Handler {

    synchronized public void updateSimInfoByIccId() {
        logd("[updateSimInfoByIccId]+ Start");
        if (!ModemStackController.getInstance().isStackReady()) return;
        sNeedUpdate = false;

        SubscriptionManager.clearSubInfo();
@@ -450,8 +449,10 @@ public class SubInfoRecordUpdater extends Handler {
            if (sInsertSimState[i] == SIM_CHANGED) {
                sInsertSimState[i] = SIM_REPOSITION;
            }
            logd("sInsertSimState[" + i + "] = " + sInsertSimState[i]);
            SubscriptionHelper.getInstance().updateSimState(i, sInsertSimState[i]);
        }
        SubscriptionHelper.getInstance().updateSimState(sInsertSimState);
        if (ModemStackController.getInstance().isStackReady() && PROJECT_SIM_NUM > 1) {
            SubscriptionHelper.getInstance().updateSubActivation();
        }

        List<SubInfoRecord> subInfos = SubscriptionManager.getActiveSubInfoList();
+22 −1
Original line number Diff line number Diff line
@@ -337,10 +337,13 @@ public class SubscriptionController extends ISub.Stub {
                    SubscriptionManager.MNC));
            info.mStatus = cursor.getInt(cursor.getColumnIndexOrThrow(
                    SubscriptionManager.SUB_STATE));
            info.mNwMode = cursor.getInt(cursor.getColumnIndexOrThrow(
                    SubscriptionManager.NETWORK_MODE));

            logd("[getSubInfoRecord] SubId:" + info.subId + " iccid:" + info.iccId + " slotId:" +
                    info.slotId + " displayName:" + info.displayName + " color:" + info.color +
                    " mcc/mnc:" + info.mcc + "/" + info.mnc + " subStatus: " + info.mStatus);
                    " mcc/mnc:" + info.mcc + "/" + info.mnc + " subStatus: " + info.mStatus
                    + " Nwmode: " + info.mNwMode);

            return info;
    }
@@ -1553,6 +1556,24 @@ public class SubscriptionController extends ISub.Stub {
        SubscriptionHelper.getInstance().setUiccSubscription(slotId, SubscriptionManager.INACTIVE);
    }

    public void setNwMode(long subId, int nwMode) {
        logd("setNwMode, nwMode: " + nwMode + " subId: " + subId);
        ContentValues value = new ContentValues(1);
        value.put(SubscriptionManager.NETWORK_MODE, nwMode);
        mContext.getContentResolver().update(SubscriptionManager.CONTENT_URI,
                value, BaseColumns._ID + "=" + Long.toString(subId), null);
    }

    public int getNwMode(long subId) {
        SubInfoRecord subInfo = getSubInfoForSubscriber(subId);
        if (subInfo != null)  {
            return subInfo.mNwMode;
        } else {
            loge("getSubState: invalid subId = " + subId);
            return SubscriptionManager.DEFAULT_NW_MODE;
        }
    }

    @Override
    public int setSubState(long subId, int subStatus) {
        int result = 0;
+79 −19
Original line number Diff line number Diff line
@@ -33,12 +33,17 @@ package com.android.internal.telephony;

import android.telephony.Rlog;
import android.content.Context;
import android.database.ContentObserver;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.Message;
import android.telephony.TelephonyManager;
import android.telephony.SubscriptionManager;
import android.util.Log;

import com.android.internal.telephony.ModemBindingPolicyHandler;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.uicc.UiccController;
import com.android.internal.telephony.uicc.UiccCard;
@@ -52,11 +57,25 @@ class SubscriptionHelper extends Handler {
    private Context mContext;
    private CommandsInterface[] mCi;
    private int[] mSubStatus;
    private static int mNumPhones;

    private static final int EVENT_SET_UICC_SUBSCRIPTION_DONE = 1;

    public static final int SUB_SIM_NOT_INSERTED = -99;
    public static final int SUB_INIT_STATE = -1;
    private static boolean mNwModeUpdated = false;

    private final ContentObserver nwModeObserver =
        new ContentObserver(new Handler()) {
            @Override
            public void onChange(boolean selfUpdate) {
                logd("NwMode Observer onChange hit !!!");
                if (!mNwModeUpdated) return;
                //get nwMode from all slots in Db and update to subId table.
                updateNwModesInSubIdTable(true);
            }
        };


    public static SubscriptionHelper init(Context c, CommandsInterface[] ci) {
        synchronized (SubscriptionHelper.class) {
@@ -80,15 +99,45 @@ class SubscriptionHelper extends Handler {
    private SubscriptionHelper(Context c, CommandsInterface[] ci) {
        mContext = c;
        mCi = ci;
        int numPhones = TelephonyManager.getDefault().getPhoneCount();
        mSubStatus = new int[numPhones];
        for (int i=0; i< numPhones; i++ ) {
        mNumPhones = TelephonyManager.getDefault().getPhoneCount();
        mSubStatus = new int[mNumPhones];
        for (int i=0; i < mNumPhones; i++ ) {
            mSubStatus[i] = SUB_INIT_STATE;
        }
        mContext.getContentResolver().registerContentObserver(Settings.Global.getUriFor(
                Settings.Global.PREFERRED_NETWORK_MODE), false, nwModeObserver);


        logd("SubscriptionHelper init by Context");
    }

    private void updateNwModesInSubIdTable(boolean override) {
        SubscriptionController subCtrlr = SubscriptionController.getInstance();
        for (int i=0; i < mNumPhones; i++ ) {
            long[] subIdList = subCtrlr.getSubId(i);
            if (subIdList != null && subIdList[0] > 0) {
                int nwModeInDb;
                try {
                    nwModeInDb = TelephonyManager.getIntAtIndex(mContext.getContentResolver(),
                            Settings.Global.PREFERRED_NETWORK_MODE, i);
                } catch (SettingNotFoundException snfe) {
                    loge("Settings Exception Reading Value At Index[" + i +
                            "] Settings.Global.PREFERRED_NETWORK_MODE");
                    nwModeInDb = RILConstants.PREFERRED_NETWORK_MODE;
                }
                int nwModeinSubIdTable = subCtrlr.getNwMode(subIdList[0]);
                logd("updateNwModesInSubIdTable: nwModeinSubIdTable: " + nwModeinSubIdTable
                        + ", nwModeInDb: " + nwModeInDb);

                //store Db value to table only if value in table is default
                //OR if override is set to True.
                if (override || nwModeinSubIdTable == SubscriptionManager.DEFAULT_NW_MODE) {
                    subCtrlr.setNwMode(subIdList[0], nwModeInDb);
                }
            }
        }
    }

    @Override
    public void handleMessage(Message msg) {
        switch(msg.what) {
@@ -101,9 +150,9 @@ class SubscriptionHelper extends Handler {
        }
    }

    public void updateSimState(int slotId, int simStatus) {
    public void updateSubActivation() {
        SubscriptionController subCtrlr = SubscriptionController.getInstance();
        mSubStatus[slotId] = simStatus;
        for (int slotId = 0; slotId < mNumPhones; slotId++) {
            if (mSubStatus[slotId] == SUB_SIM_NOT_INSERTED) {
                if (isAllSubsAvailable()) {
                    logd("Received all sim info, now update user preferred subs");
@@ -120,6 +169,18 @@ class SubscriptionHelper extends Handler {
            // perform the activation/deactivation of subscription
            setUiccSubscription(slotId, subState);
        }
        //set DDS explicitly after setUicc is sent on stack ready.
        subCtrlr.setDefaultDataSubId(subCtrlr.getDefaultDataSubId());
    }

    public void updateSimState(int[] simStatus) {
        for (int slotId = 0; slotId < mNumPhones; slotId++) {
            mSubStatus[slotId] = simStatus[slotId];
        }
        updateNwModesInSubIdTable(false);
        ModemBindingPolicyHandler.getInstance().updatePrefNwTypeIfRequired();
        mNwModeUpdated = true;
    }

    public void setUiccSubscription(int slotId, int subStatus) {
        mSubStatus[slotId] = subStatus;
@@ -183,9 +244,8 @@ class SubscriptionHelper extends Handler {

    private boolean isAllSubsAvailable() {
        boolean allSubsAvailable = true;
        int numPhones = TelephonyManager.getDefault().getPhoneCount();

        for (int i=0; i < numPhones; i++) {
        for (int i=0; i < mNumPhones; i++) {
            if (mSubStatus[i] == SUB_INIT_STATE) {
                allSubsAvailable = false;
            }