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

Commit 3580187e authored by Sandeep Gutta's avatar Sandeep Gutta Committed by Linux Build Service Account
Browse files

MSIM: Trigger DDS during card removals and sub deactivate

- When card removed(hotswap), trigger DDS switch
  on next available sub.
- Modify the code logic to not trigger DDS
  request multiple times when user deactivate
  subscription from UI.
- Add fix to send data allow request when device
  powered-up first time.
- Add few log statements.

Change-Id: Ib93a60f7d575373b11a38f65e021e6f0ce77075d
parent 1b36abf3
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -260,7 +260,7 @@ public class SubInfoRecordUpdater extends Handler {
            case EVENT_STACK_READY:
                logd("EVENT_STACK_READY" );
                if (isAllIccIdQueryDone() && PROJECT_SIM_NUM > 1) {
                    SubscriptionHelper.getInstance().updateSubActivation();
                    SubscriptionHelper.getInstance().updateSubActivation(sInsertSimState, true);
                }
                break;
            default:
@@ -450,9 +450,9 @@ public class SubInfoRecordUpdater extends Handler {
                sInsertSimState[i] = SIM_REPOSITION;
            }
        }
        SubscriptionHelper.getInstance().updateSimState(sInsertSimState);
        SubscriptionHelper.getInstance().updateNwMode();
        if (ModemStackController.getInstance().isStackReady() && PROJECT_SIM_NUM > 1) {
            SubscriptionHelper.getInstance().updateSubActivation();
            SubscriptionHelper.getInstance().updateSubActivation(sInsertSimState, false);
        }

        List<SubInfoRecord> subInfos = SubscriptionManager.getActiveSubInfoList();
+28 −12
Original line number Diff line number Diff line
@@ -404,7 +404,7 @@ public class SubscriptionController extends ISub.Stub {
            subId = getDefaultSubId();
        }
        if (!SubscriptionManager.isValidSubId(subId) || !isSubInfoReady()) {
            logd("[getSubInfoForSubscriberx]- invalid subId or not ready");
            logd("[getSubInfoForSubscriberx]- invalid subId or not ready, subId = " + subId);
            return null;
        }
        Cursor cursor = mContext.getContentResolver().query(SubscriptionManager.CONTENT_URI,
@@ -1538,7 +1538,7 @@ public class SubscriptionController extends ISub.Stub {
    @Override
    public void activateSubId(long subId) {
        if (getSubState(subId) == SubscriptionManager.ACTIVE) {
            logd("activateSubId: subscription already active");
            logd("activateSubId: subscription already active, subId = " + subId);
            return;
        }

@@ -1549,6 +1549,7 @@ public class SubscriptionController extends ISub.Stub {
    @Override
    public void deactivateSubId(long subId) {
        if (getSubState(subId) == SubscriptionManager.INACTIVE) {
            logd("activateSubId: subscription already deactivated, subId = " + subId);
            return;
        }

@@ -1584,7 +1585,6 @@ public class SubscriptionController extends ISub.Stub {
            result = mContext.getContentResolver().update(SubscriptionManager.CONTENT_URI,
                    value, BaseColumns._ID + "=" + Long.toString(subId), null);

            if (subStatus == SubscriptionManager.INACTIVE) updateUserPrefs();
        }
        broadcastSimInfoContentChanged(subId,
                SubscriptionManager.SUB_STATE, subStatus, SubscriptionManager.DEFAULT_STRING_VALUE);
@@ -1594,22 +1594,27 @@ public class SubscriptionController extends ISub.Stub {
    @Override
    public int getSubState(long subId) {
        SubInfoRecord subInfo = getSubInfoForSubscriber(subId);
        int subStatus = SubscriptionManager.INACTIVE;

        if (subInfo != null)  {
            return subInfo.mStatus;
        } else {
            loge("getSubState: invalid subId = " + subId);
            return SubscriptionManager.INACTIVE;
        // Consider the subStatus from subInfo record only if the
        //  record is associated with a valid slot Id.
        if ((subInfo != null) && (subInfo.slotId >= 0)) {
            subStatus = subInfo.mStatus;
        }
        return subStatus;
    }

    public void updateUserPrefs() {
    /* setDds flag is used to trigger DDS switch request during
      device powerUp and when flex map performed */
    public void updateUserPrefs(boolean setDds) {
        List<SubInfoRecord> subInfoList = getActiveSubInfoList();
        int mActCount = 0;
        SubInfoRecord mNextActivatedSub = null;

        if (subInfoList == null) {
            logd("updateUserPrefs: subscription are not avaiable ");
            logd("updateUserPrefs: subscription are not avaiable dds = " + getDefaultDataSubId()
                     + " voice = " + getDefaultVoiceSubId() + " sms = " + getDefaultSmsSubId() +
                     " setDDs = " + setDds);
            return;
        }

@@ -1620,6 +1625,10 @@ public class SubscriptionController extends ISub.Stub {
                if (mNextActivatedSub == null) mNextActivatedSub = subInfo;
            }
        }

        logd("updateUserPrefs: active sub count = " + mActCount + " dds = " + getDefaultDataSubId()
                 + " voice = " + getDefaultVoiceSubId() + " sms = "
                 + getDefaultSmsSubId() + " setDDs = " + setDds);
        //if activated sub count is less than 2, disable prompt.
        if (mActCount < 2) {
            setSMSPromptEnabled(false);
@@ -1629,9 +1638,12 @@ public class SubscriptionController extends ISub.Stub {
        //if there are no activated subs available, no need to update. EXIT.
        if (mNextActivatedSub == null) return;

        long ddsSubId = getDefaultDataSubId();
        int ddsSubState = getSubState(ddsSubId);
        //if current data sub is not active, fallback to next active sub.
        if (getSubState(getDefaultDataSubId()) == SubscriptionManager.INACTIVE) {
            setDefaultDataSubId(mNextActivatedSub.subId);
        if (setDds || (ddsSubState == SubscriptionManager.INACTIVE)) {
            if (ddsSubState == SubscriptionManager.INACTIVE) ddsSubId = mNextActivatedSub.subId;
            setDefaultDataSubId(ddsSubId);
        }
        //if current voice sub is not active and prompt not enabled, fallback to next active sub.
        if (getSubState(getDefaultVoiceSubId()) == SubscriptionManager.INACTIVE &&
@@ -1643,6 +1655,10 @@ public class SubscriptionController extends ISub.Stub {
            !isSMSPromptEnabled()) {
            setDefaultSmsSubId(mNextActivatedSub.subId);
        }
        logd("updateUserPrefs: after currentDds = " + getDefaultDataSubId() + " voice = " +
                 getDefaultVoiceSubId() + " sms = " + getDefaultSmsSubId() +
                 " newDds = " + ddsSubId);

    }

    /* Returns User Voice Prompt property,  enabled or not */
+53 −38
Original line number Diff line number Diff line
@@ -57,7 +57,10 @@ class SubscriptionHelper extends Handler {
    private Context mContext;
    private CommandsInterface[] mCi;
    private int[] mSubStatus;
    private static int mNumPhones;
    private static int sNumPhones;
    // This flag is used to trigger Dds during boot-up
    // and when flex mapping performed
    private static boolean sTriggerDds = true;

    private static final int EVENT_SET_UICC_SUBSCRIPTION_DONE = 1;

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


        logd("SubscriptionHelper init by Context");
        logd("SubscriptionHelper init by Context, num phones = " + sNumPhones);
    }

    private void updateNwModesInSubIdTable(boolean override) {
        SubscriptionController subCtrlr = SubscriptionController.getInstance();
        for (int i=0; i < mNumPhones; i++ ) {
        for (int i=0; i < sNumPhones; i++ ) {
            long[] subIdList = subCtrlr.getSubId(i);
            if (subIdList != null && subIdList[0] > 0) {
                int nwModeInDb;
@@ -143,47 +146,55 @@ class SubscriptionHelper extends Handler {
        switch(msg.what) {
            case EVENT_SET_UICC_SUBSCRIPTION_DONE:
                logd("EVENT_SET_UICC_SUBSCRIPTION_DONE");
                processSetUiccSubscriptionDone((AsyncResult)msg.obj);
                processSetUiccSubscriptionDone(msg);
                break;
           default:
           break;
        }
    }

    public void updateSubActivation() {
    public void updateSubActivation(int[] simStatus, boolean isStackReadyEvent) {
        SubscriptionController subCtrlr = SubscriptionController.getInstance();
        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");
                    subCtrlr.updateUserPrefs();
        boolean setUiccSent = false;
        if (isStackReadyEvent) {
            sTriggerDds = true;
        }
                return;

        for (int slotId = 0; slotId < sNumPhones; slotId++) {
            if (simStatus[slotId] == SUB_SIM_NOT_INSERTED) {
                mSubStatus[slotId] = simStatus[slotId];
                logd(" Sim not inserted in slot [" + slotId + "] simStatus= " + simStatus[slotId]);
                continue;
            }
            long[] subId = subCtrlr.getSubId(slotId);
            int subState = subCtrlr.getSubState(subId[0]);

            logd("setUicc for [" + slotId + "] = " + subState + "subId = " + subId[0]);

            logd("setUicc for [" + slotId + "] = " + subState + "subId = " + subId[0] +
                    " prev subState = " + mSubStatus[slotId] + " stackReady " + isStackReadyEvent);
            // Do not send SET_UICC if its already sent with same state
            if ((mSubStatus[slotId] != subState) || isStackReadyEvent) {
                // If sim card present in the slot, get the stored sub status and
                // perform the activation/deactivation of subscription
                setUiccSubscription(slotId, subState);
                setUiccSent = true;
            }
        //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];
        // If at least one uiccrequest sent, updateUserPrefs() will be called
        // from processSetUiccSubscriptionDone()
        if (isAllSubsAvailable() && (!setUiccSent)) {
            logd("Received all sim info, update user pref subs, triggerDds= " + sTriggerDds);
            subCtrlr.updateUserPrefs(sTriggerDds);
            sTriggerDds = false;
        }
    }

    public void updateNwMode() {
        updateNwModesInSubIdTable(false);
        ModemBindingPolicyHandler.getInstance().updatePrefNwTypeIfRequired();
        mNwModeUpdated = true;
    }

    public void setUiccSubscription(int slotId, int subStatus) {
        mSubStatus[slotId] = subStatus;
        boolean set3GPPDone = false, set3GPP2Done = false;
        UiccCard uiccCard = UiccController.getInstance().getUiccCard(slotId);
        if (uiccCard == null) {
@@ -197,13 +208,13 @@ class SubscriptionHelper extends Handler {
            if (set3GPPDone == false && (appType == PhoneConstants.APPTYPE_USIM ||
                    appType == PhoneConstants.APPTYPE_SIM)) {
                Message msgSetUiccSubDone = Message.obtain(
                        this, EVENT_SET_UICC_SUBSCRIPTION_DONE, new Integer(slotId));
                        this, EVENT_SET_UICC_SUBSCRIPTION_DONE, slotId, subStatus);
                mCi[slotId].setUiccSubscription(slotId, i, slotId, subStatus, msgSetUiccSubDone);
                set3GPPDone = true;
            } else if (set3GPP2Done == false && (appType == PhoneConstants.APPTYPE_CSIM ||
                    appType == PhoneConstants.APPTYPE_RUIM)) {
                Message msgSetUiccSubDone = Message.obtain(
                        this, EVENT_SET_UICC_SUBSCRIPTION_DONE, new Integer(slotId));
                        this, EVENT_SET_UICC_SUBSCRIPTION_DONE, slotId, subStatus);
                mCi[slotId].setUiccSubscription(slotId, i, slotId, subStatus, msgSetUiccSubDone);
                set3GPP2Done = true;
            }
@@ -216,11 +227,13 @@ class SubscriptionHelper extends Handler {
     * Handles the EVENT_SET_UICC_SUBSCRPTION_DONE.
     * @param ar
     */
    private void processSetUiccSubscriptionDone(AsyncResult ar) {
        Integer slotId = (Integer)ar.userObj;
        boolean saveGlobalSettings = false;
    private void processSetUiccSubscriptionDone(Message msg) {
        AsyncResult ar = (AsyncResult)msg.obj;
        int slotId = msg.arg1;
        int newSubState = msg.arg2;

        if (ar.exception != null) {
            logd("Exception in SET_UICC_SUBSCRIPTION, slotId = " + slotId);
            return;
        }

@@ -229,23 +242,25 @@ class SubscriptionHelper extends Handler {
            long[] subId = subCtrlr.getSubIdUsingSlotId(slotId);
            int subStatus = subCtrlr.getSubState(subId[0]);

            if (mSubStatus[slotId] != subStatus) {
                subCtrlr.setSubState(subId[0], mSubStatus[slotId]);
            if (newSubState != subStatus) {
                subCtrlr.setSubState(subId[0], newSubState);
            }
        }

        mSubStatus[slotId] = newSubState;
        // After activating all subs, updated the user preferred sub values
        if (isAllSubsAvailable()) {
            logd("Received all subs, now update user preferred subs");
            subCtrlr.updateUserPrefs();
            logd("Received all subs, now update user preferred subs, slotid = " + slotId
                    + " newSubState = " + newSubState + " sTriggerDds = " + sTriggerDds);
            subCtrlr.updateUserPrefs(sTriggerDds);
            sTriggerDds = false;
        }

    }

    private boolean isAllSubsAvailable() {
        boolean allSubsAvailable = true;

        for (int i=0; i < mNumPhones; i++) {
        for (int i=0; i < sNumPhones; i++) {
            if (mSubStatus[i] == SUB_INIT_STATE) {
                allSubsAvailable = false;
            }
+21 −15
Original line number Diff line number Diff line
@@ -444,19 +444,19 @@ public class DctController extends Handler {
    }

    private static void logv(String s) {
        Log.v(LOG_TAG, "[DctController] " + s);
        Rlog.v(LOG_TAG, "[DctController] " + s);
    }

    private static void logd(String s) {
        Log.d(LOG_TAG, "[DctController] " + s);
        Rlog.d(LOG_TAG, "[DctController] " + s);
    }

    private static void logw(String s) {
        Log.w(LOG_TAG, "[DctController] " + s);
        Rlog.w(LOG_TAG, "[DctController] " + s);
    }

    private static void loge(String s) {
        Log.e(LOG_TAG, "[DctController] " + s);
        Rlog.e(LOG_TAG, "[DctController] " + s);
    }

    private class SwitchInfo {
@@ -508,22 +508,21 @@ public class DctController extends Handler {
        }
    }
    public void setDefaultDataSubId(long subId) {
        Rlog.d(LOG_TAG, "setDefaultDataSubId subId :" + subId);
        int phoneId = mSubController.getPhoneId(subId);
        SwitchInfo s = new SwitchInfo(new Integer(phoneId), true);
        int prefPhoneId = mSubController.getPhoneId(mSubController.getCurrentDds());
        if (prefPhoneId < 0 || prefPhoneId >= mPhoneNum) {
            // If Current dds subId is invalid set the received subId as curretn DDS
            // and return from here.
            // DcSwitchState will take care of sending allowData on latet dds subId
            // once it receives valid data registration state
            // If Current dds subId is invalid set the received subId as current DDS
            // This generally happens when device power-up first time.
            logd(" setDefaultDataSubId,  subId = " + subId + " phoneId  " + prefPhoneId);
            Settings.Global.putLong(mContext.getContentResolver(),
                    Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION, subId);
            return;
        }
        Rlog.d(LOG_TAG, "setDefaultDataSubId subId :" + subId + " phoneId = " + phoneId);

        if (subId != mSubController.getDefaultDataSubId()) {
        // Check for phoneId and prefPhoneId here, to avoid sending
        //  data allow false and true on same sub.
        if ((subId != mSubController.getDefaultDataSubId()) && (phoneId != prefPhoneId)) {
            doDetach(prefPhoneId);
        } else {
            logd("setDefaultDataSubId for default DDS, skip PS detach on DDS subs");
@@ -615,19 +614,26 @@ public class DctController extends Handler {

    @Override
        public void handleMessage (Message msg) {
            boolean isLegacySetDds = false;
            Rlog.d(LOG_TAG, "handleMessage msg=" + msg);

            switch (msg.what) {
                case EVENT_LEGACY_SET_DATA_SUBSCRIPTION:
                    isLegacySetDds = true;
                    //intentional fall through, no break.
                case EVENT_ALL_DATA_DISCONNECTED: {
                    AsyncResult ar = (AsyncResult)msg.obj;
                    SwitchInfo s = (SwitchInfo)ar.userObj;
                    Integer phoneId = s.mPhoneId;
                    Rlog.d(LOG_TAG, "EVENT_ALL_DATA_DISCONNECTED switchInfo :" + s +
                            " isLegacySetDds = " + isLegacySetDds);
                    // In this case prefPhoneId points to the newDds we are trying to
                    // set, hence we do not need to call unregister for data disconnected
                    if (!isLegacySetDds) {
                        int prefPhoneId = mSubController.getPhoneId(
                                 mSubController.getCurrentDds());
                    Rlog.d(LOG_TAG, "EVENT_ALL_DATA_DISCONNECTED switchInfo :" + s);
                        mPhones[prefPhoneId].unregisterForAllDataDisconnected(this);
                    }
                    Message allowedDataDone = Message.obtain(this,
                            EVENT_SET_DATA_ALLOW_DONE, s);
                    Phone phone = mPhones[phoneId].getActivePhone();