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

Unverified Commit b2568ba3 authored by LuK1337's avatar LuK1337 Committed by Michael Bestas
Browse files

RIL: Squash changes to default SIM handling



commit 2b0a61abcb3547f502b31316eaf79bd07426338e
Author: Roman Birg <roman@cyngn.com>
Date:   Wed Jun 22 15:12:01 2016 -0700

    Subscription updater: don't turn data off if we've never set a deafult

    In the case of an MSIM device that has only had 1 SIM and then you swap
    the sim to another slot, the data will turn off, but it's the same SIM
    and should not.

    Change-Id: I77ed8c22663aa10d211e6f4de06b791c1a8f0971
    Signed-off-by: default avatarRoman Birg <roman@cyngn.com>

commit 4be12e4b8cfa05e78ebc5b8e6145e43b1068ee83
Author: Roman Birg <roman@cyngn.com>
Date:   Mon Jun 20 11:13:54 2016 -0700

    Telephony: handle 3rd party sms apps + 'always ask'

    3rd party SMS apps may not be able to handle our always ask behavior, so
    they may get stuck in a bad state. An example of this is Hangouts, which
    just ends up never sending messages when always ask is selected.

    TIcket: CYNGNOS-3068

    Change-Id: I8a0f1f6bf7a5010438e40eb0be9aa178d2141f3c
    Signed-off-by: default avatarRoman Birg <roman@cyngn.com>

commit 600a58b4cdfb5fe58428dc81a50629d0802f686b
Author: Roman Birg <roman@cyngn.com>
Date:   Tue May 17 17:14:44 2016 -0700

    SubscriptionInfoUpdater: improved sim swap

    We now keep track of the last number of inserted SIMs updated for. So
    when the number of SIMs has changed we do the following:

     1 sim: Clear stale defaults
            Disable SMS prompt, SMS app will default to current sim
            Disable data if the SIM left in the tray is not the one chosen

     m sim: Enable SMS prompt if we don't have a valid default (aka always
            ask)

    Furthermore, when we detect the device is an MSIM device and there is
    only one active sub, return the active sub to the UI layers (so SIM
    selection screen displays proper, grayed out, current settings).

    Ticket: CYNGNOS-2185, CYNGNOS-2570

    Change-Id: Ib1b4f4d87640e4b20722295304c58dff7dbeecbb
    Signed-off-by: default avatarRoman Birg <roman@cyngn.com>

commit c8bdbb118f25dcc264b0a1c0e0fa4fbabc507f57
Author: Roman Birg <roman@cyngn.com>
Date:   Mon May 16 11:15:26 2016 -0700

    SubscriptionController: fix subscription updating

    We need to only repost messages on events we have handled, not
    prematurely posting them for every single eveng incoming.

    Furthermore, getMaxActive should return the MAX, not the current max.

    The previous fixed dual sim insertion and removal ONLY if there were two
    sims, but switching from two to one would break.

    Ticket: CYNGNOS-2185, CYNGNOS-2570

    Change-Id: I5b829662b466f609cd22adfa7d3b754757258463
    Signed-off-by: default avatarRoman Birg <roman@cyngn.com>

commit 7cfda9d340bdfbb290fedf4ba378fde6c7ae2086
Author: Roman Birg <roman@cyngn.com>
Date:   Mon May 9 08:52:42 2016 -0700

    SubscriptionController: load all subs before setting defaults

    Switch the whole class to use the new inserted SIM logic added in
    change id Iab1225c83b508e055d8a8de55c1e21e2aa153ca5. The previous patch
    fixed scenarios going from two sims to one, but going from one to two
    (or switching between two sims) is still not working right as the
    addSubInfoRecord() still used getActiveSubInfoCountMax() to determine
    the number of SIMS.

     - Update getActiveSubInfoCountMax() to return the correct number of SIMs.

     - Furthermore, we need to _only_ update our subscription defaults if we
       are sure we are not in the middle of an update.

     - Let the subscription controller set defaults for 1 SIM device after
       we're done loading

    Change-Id: I28eefaff61ae7c75732641465ca59eb67cf3e198
    Ticket: CYNGNOS-2185, CYNGNOS-2570

commit bd7064dab2eebdb2d12d7d475939d733df00ff11
Author: Roman Birg <roman@cyngn.com>
Date:   Thu May 5 16:21:11 2016 -0700

    SubscriptionController: properly detect when MSIM has 1 SIM

    We cannot use sSlotIdxToSubId to determine when to turn the SIM dialog
    off, because when subscription information gets reloaded (on data change
    for instance), we may add one, then disable SMS prompt, then add the
    other, which is incorrect. Query the total number of SIMs from the info
    updater.

    Ticket: CYNGNOS-2185, CYNGNOS-2570

    Change-Id: Iab1225c83b508e055d8a8de55c1e21e2aa153ca5
    Signed-off-by: default avatarRoman Birg <roman@cyngn.com>

commit ffbc7f853204869462b366b871bbd68750d30b8b
Author: Chaitanya Saggurthi <csaggurt@codeaurora.org>
Date:   Thu Feb 5 18:37:59 2015 +0530

    Add dummy SUB record in CDMA NV mode

    Add dummy SUB info record when NV is ready in CDMA NV mode.

    CRs-Fixed: 789989

    Change-Id: Ie658087efaa9f93a329773d2d8f0601d083f3701

commit 310241770efe75afcb9c8e2f219349bb90c7830f
Author: Adnan Begovic <adnan@cyngn.com>
Date:   Tue Apr 5 08:14:29 2016 -0700

    telephony: Only set prompt enabled if available subscriptions > 1.

    TICKET: CRACKLING-1026
    Change-Id: I8a7555a41a52476af5236c03b4d410dd155db390

commit b6a60870dc07640b7d4d2827de35ada3f6b289d1
Author: Adnan Begovic <adnan@cyngn.com>
Date:   Wed Mar 30 15:16:12 2016 -0700

    telephony: Workaround default sms sub id not being set.

      In the scenario where default sms sub id isn't set externally
      the user can be stuck in an endless loop of prompts if they
      select "Always Ask". This is bandaid to fix bad UX..

    TICKET: CYNGNOS-2185
    Change-Id: I70ef343eccc289d0ca58c59646f88b292ca03ca9

commit a9d1d89a3200f140cedf84e8cba97ad0ba445591
Author: LuK1337 <priv.luk@gmail.com>
Date:   Sun Sep 4 00:30:57 2016 +0200

    Readd setSMSPromptEnabled()

    Change-Id: I100a73af1c4caf68ea2c7a6a75e1f3b081947316

commit 78ef72eb88f02b4b8898d82488e5ce0af617acff
Author: Christian Morlok <ChristianMorlok@gmail.com>
Date:   Wed Jan 20 08:31:10 2016 +0100

    telephony: Do not set default subscriptions on shutdown

    On some devices the SIM slots are not deactivated at the same time
    when the phone is shut down or rebooted. This means that at some point
    only one SIM is activated, and all default subscriptions are set to
    this SIM (a feature introduced in http://review.cyanogenmod.org/#/c/121239/).

    Change-Id: Ief36004619b75530a21b23efc767e1beb1fb0750

commit 8f188ba4a878890d5c933a533162447d915494c4
Author: Ethan Chen <intervigil@gmail.com>
Date:   Mon Nov 23 17:12:47 2015 -0800

    Set default subscriptions when single SIM is available

    * Subscriptions are not updated when SIM cards are swapped. If there is
      ever a SIM count of 1, direct all defaults to point at that
      subscription, since there is no other option.

    Change-Id: Idb84140b65f3355e29cbdebcaff804318d826fe7

Change-Id: I9255eff036f3dae7607484b7f263fabbe0df813b
parent 4eb40915
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -363,6 +363,14 @@ public class PhoneFactory {
       return prompt;
    }

    /* Sets User SMS Prompt property,  enable or not */
    public static void setSMSPromptEnabled(boolean enabled) {
        int value = (enabled == false) ? 0 : 1;
        Settings.Global.putInt(sContext.getContentResolver(),
                Settings.Global.MULTI_SIM_SMS_PROMPT, value);
        Rlog.d(LOG_TAG, "setSMSPromptOption to " + enabled);
    }

    /**
     * Makes a {@link ImsPhone} object.
     * @return the {@code ImsPhone} object or null if the exception occured
@@ -502,4 +510,8 @@ public class PhoneFactory {
        }
        pw.decreaseIndent();
    }

    public static SubscriptionInfoUpdater getSubscriptionInfoUpdater() {
        return sSubInfoRecordUpdater;
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.provider.Telephony.Sms.Intents;
import android.telephony.Rlog;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

import com.android.internal.content.PackageMonitor;
@@ -62,6 +63,7 @@ public final class SmsApplication {
    private static final String BLUETOOTH_PACKAGE_NAME = "com.android.bluetooth";
    private static final String MMS_SERVICE_PACKAGE_NAME = "com.android.mms.service";
    private static final String TELEPHONY_PROVIDER_PACKAGE_NAME = "com.android.providers.telephony";
    private static final String DEFAULT_SYSTEM_MMS_PACKAGE_NAME = "com.android.messaging";

    private static final String SCHEME_SMS = "sms";
    private static final String SCHEME_SMSTO = "smsto";
@@ -914,6 +916,16 @@ public final class SmsApplication {
        return false;
    }

    /**
     * @hide
     */
    public static boolean canSmsAppHandleAlwaysAsk(Context context) {
        final ComponentName defaultMmsApplication = SmsApplication.getDefaultMmsApplication(context,
                false);
        return TextUtils.equals(DEFAULT_SYSTEM_MMS_PACKAGE_NAME,
                defaultMmsApplication.getPackageName());
    }

    private static String getDefaultSmsApplicationPackageName(Context context) {
        final ComponentName component = getDefaultSmsApplication(context, false);
        if (component != null) {
+36 −9
Original line number Diff line number Diff line
@@ -186,7 +186,14 @@ public class SubscriptionController extends ISub.Stub {
    }

    private boolean isSubInfoReady() {
        return sSlotIdxToSubId.size() > 0;
        final SubscriptionInfoUpdater subUpdater = PhoneFactory.getSubscriptionInfoUpdater();
        return subUpdater != null && sSlotIdxToSubId.size() == subUpdater.getInsertedSimCount();
    }

    private boolean isSingleSimActiveOnMSIM() {
        final SubscriptionInfoUpdater subUpdater = PhoneFactory.getSubscriptionInfoUpdater();
        return subUpdater != null && subUpdater.getInsertedSimCount() == 1
                && getActiveSubInfoCountMax() > 1;
    }

    private SubscriptionController(Phone phone) {
@@ -680,7 +687,7 @@ public class SubscriptionController extends ISub.Stub {
    @Override
    public int getActiveSubInfoCountMax() {
        // FIXME: This valid now but change to use TelephonyDevController in the future
        return mTelephonyManager.getSimCount();
        return TelephonyManager.getDefault().getSimCount();
    }

    /**
@@ -771,22 +778,28 @@ public class SubscriptionController extends ISub.Stub {
                            // may not be true, for instance with multiple subs per slot.
                            // But is true at the moment.
                            sSlotIdxToSubId.put(slotId, subId);
                            int subIdCountMax = getActiveSubInfoCountMax();
                            int simCount = PhoneFactory.getSubscriptionInfoUpdater()
                                    .getInsertedSimCount();
                            int defaultSubId = getDefaultSubId();
                            if (DBG) {
                                logdl("[addSubInfoRecord]"
                                        + " sSlotIdxToSubId.size=" + sSlotIdxToSubId.size()
                                        + " slotId=" + slotId + " subId=" + subId
                                        + " defaultSubId=" + defaultSubId + " simCount=" + subIdCountMax);
                                        + " defaultSubId=" + defaultSubId + " simCount=" + simCount);
                            }

                            if (!isSubInfoReady()) {
                                continue;
                            }

                            // Set the default sub if not set or if single sim device
                            if (!SubscriptionManager.isValidSubscriptionId(defaultSubId)
                                    || subIdCountMax == 1 || (!isActiveSubId(defaultSubId))) {
                                    || simCount == 1 || (!isActiveSubId(defaultSubId))) {
                                setDefaultFallbackSubId(subId);
                            }
                            // If single sim device, set this subscription as the default for everything
                            if (subIdCountMax == 1) {
                            if (simCount == 1
                                    && TelephonyManager.getDefault().getSimCount() == 1) {
                                if (DBG) {
                                    logdl("[addSubInfoRecord] one sim set defaults to subId=" + subId);
                                }
@@ -1375,6 +1388,10 @@ public class SubscriptionController extends ISub.Stub {

    @Override
    public int getDefaultSmsSubId() {
        if (isSingleSimActiveOnMSIM()) {
            if (VDBG) logd("[getDefaultSmsSubId] overridden to current single active sim");
            return mDefaultFallbackSubId;
        }
        int subId = Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.MULTI_SIM_SMS_SUBSCRIPTION,
                SubscriptionManager.INVALID_SUBSCRIPTION_ID);
@@ -1406,6 +1423,10 @@ public class SubscriptionController extends ISub.Stub {

    @Override
    public int getDefaultVoiceSubId() {
        if (isSingleSimActiveOnMSIM()) {
            if (VDBG) logd("[getDefaultVoiceSubId] overridden to current single active sim");
            return mDefaultFallbackSubId;
        }
        int subId = Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION,
                SubscriptionManager.INVALID_SUBSCRIPTION_ID);
@@ -1415,6 +1436,10 @@ public class SubscriptionController extends ISub.Stub {

    @Override
    public int getDefaultDataSubId() {
        if (isSingleSimActiveOnMSIM()) {
            if (VDBG) logd("[getDefaultDataSubId] overridden to current single active sim");
            return mDefaultFallbackSubId;
        }
        int subId = Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION,
                SubscriptionManager.INVALID_SUBSCRIPTION_ID);
@@ -1467,8 +1492,10 @@ public class SubscriptionController extends ISub.Stub {
        // FIXME is this still needed?
        updateAllDataConnectionTrackers();

        if (!isSingleSimActiveOnMSIM()) {
            Settings.Global.putInt(mContext.getContentResolver(),
                    Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION, subId);
        }
        broadcastDefaultDataSubIdChanged(subId);
    }

@@ -1503,7 +1530,7 @@ public class SubscriptionController extends ISub.Stub {
        if (SubscriptionManager.isValidSubscriptionId(subId)) {
            int phoneId = getPhoneId(subId);
            if (phoneId >= 0 && (phoneId < mTelephonyManager.getPhoneCount()
                    || mTelephonyManager.getSimCount() == 1)) {
                    || isSingleSimActiveOnMSIM())) {
                if (DBG) logdl("[setDefaultFallbackSubId] set mDefaultFallbackSubId=" + subId);
                mDefaultFallbackSubId = subId;
                // Update MCC MNC device configuration information
+112 −19
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import com.android.internal.telephony.uicc.IccUtils;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -75,6 +76,9 @@ public class SubscriptionInfoUpdater extends Handler {
    private static final int EVENT_SIM_IO_ERROR = 6;
    private static final int EVENT_SIM_UNKNOWN = 7;
    private static final int EVENT_SIM_RESTRICTED = 8;
    private static final int EVENT_UPDATE_INSERTED_SIM_COUNT = 9;

    private static final int DELAY_MILLIS = 500;

    private static final String ICCID_STRING_FOR_NO_SIM = "";
    /**
@@ -102,6 +106,8 @@ public class SubscriptionInfoUpdater extends Handler {

    // Key used to read/write the current IMSI. Updated on SIM_STATE_CHANGED - LOADED.
    public static final String CURR_SUBID = "curr_subid";
    // Key used to determine if the number of sims in the device has changed
    private static final String PREF_LAST_SEEN_SIM_COUNT = "previous_update_sim_count";

    private static Phone[] mPhone;
    private static Context mContext = null;
@@ -115,6 +121,9 @@ public class SubscriptionInfoUpdater extends Handler {
    // The current foreground user ID.
    private int mCurrentlyActiveUserId;
    private CarrierServiceBindHelper mCarrierServiceBindHelper;
    private boolean mIsShutdown;
    private int mCurrentSimCount = 0;
    private BitSet mLockedSims = new BitSet(PROJECT_SIM_NUM);

    public SubscriptionInfoUpdater(Context context, Phone[] phone, CommandsInterface[] ci) {
        logd("Constructor invoked");
@@ -124,10 +133,12 @@ public class SubscriptionInfoUpdater extends Handler {
        mSubscriptionManager = SubscriptionManager.from(mContext);
        mPackageManager = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
        mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        mIsShutdown = false;

        IntentFilter intentFilter = new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
        intentFilter.addAction(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED);
        intentFilter.addAction(Intent.ACTION_USER_UNLOCKED);
        intentFilter.addAction(Intent.ACTION_SHUTDOWN);
        mContext.registerReceiver(sReceiver, intentFilter);

        mCarrierServiceBindHelper = new CarrierServiceBindHelper(mContext);
@@ -201,6 +212,11 @@ public class SubscriptionInfoUpdater extends Handler {
                return;
            }

            if (action.equals(Intent.ACTION_SHUTDOWN)) {
                mIsShutdown = true;
                return;
            }

            if (!action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED) &&
                    !action.equals(IccCardProxy.ACTION_INTERNAL_SIM_STATE_CHANGED)) {
                return;
@@ -240,6 +256,16 @@ public class SubscriptionInfoUpdater extends Handler {
                    logd("Ignoring simStatus: " + simStatus);
                }
            }

            if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(simStatus)) {
                mLockedSims.set(slotId);
                update(slotId);
            } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(simStatus)
                    || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(simStatus)) {
                mLockedSims.clear(slotId);
                update(slotId);
            }

            logd("[Receiver]-");
        }
    };
@@ -299,9 +325,7 @@ public class SubscriptionInfoUpdater extends Handler {
                    logd("Query IccId fail: " + ar.exception);
                }
                logd("sIccId[" + slotId + "] = " + mIccId[slotId]);
                if (isAllIccIdQueryDone()) {
                    updateSubscriptionInfoByIccId();
                }
                update(slotId);
                broadcastSimStateChanged(slotId, IccCardConstants.INTENT_VALUE_ICC_LOCKED,
                                         uObj.reason);
                if (!ICCID_STRING_FOR_NO_SIM.equals(mIccId[slotId])) {
@@ -348,6 +372,14 @@ public class SubscriptionInfoUpdater extends Handler {
                updateCarrierServices(msg.arg1, IccCardConstants.INTENT_VALUE_ICC_CARD_RESTRICTED);
                break;

            case EVENT_UPDATE_INSERTED_SIM_COUNT:
                logd("EVENT_UPDATE_INSERTED_SIM_COUNT: locked sims: " + mLockedSims.cardinality());
                if (isAllIccIdQueryDone() && !hasMessages(EVENT_UPDATE_INSERTED_SIM_COUNT)) {
                    updateSubscriptionInfoByIccId();
                    logd("update inserted sim count, current sim count: " + mCurrentSimCount);
                }
                break;

            default:
                logd("Unknown msg:" + msg.what);
        }
@@ -369,7 +401,6 @@ public class SubscriptionInfoUpdater extends Handler {
            mIccId[slotId] = null;
        }


        IccFileHandler fileHandler = mPhone[slotId].getIccCard() == null ? null :
                mPhone[slotId].getIccCard().getIccFileHandler();

@@ -388,6 +419,14 @@ public class SubscriptionInfoUpdater extends Handler {
        } else {
            logd("sFh[" + slotId + "] is null, ignore");
        }
        update(slotId);
    }

    private void update(int slotId) {
        sendMessageDelayed(obtainMessage(EVENT_UPDATE_INSERTED_SIM_COUNT, slotId), DELAY_MILLIS);
        if (isAllIccIdQueryDone()) {
            updateSubscriptionInfoByIccId();
        }
    }

    protected void handleSimLoaded(int slotId) {
@@ -406,10 +445,7 @@ public class SubscriptionInfoUpdater extends Handler {
            return;
        }
        mIccId[slotId] = records.getIccId();

        if (isAllIccIdQueryDone()) {
            updateSubscriptionInfoByIccId();
        }
        update(slotId);

        int subId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
        int[] subIds = SubscriptionController.getInstance().getSubId(slotId);
@@ -522,9 +558,7 @@ public class SubscriptionInfoUpdater extends Handler {
            logd("SIM" + (slotId + 1) + " hot plug out or error");
        }
        mIccId[slotId] = ICCID_STRING_FOR_NO_SIM;
        if (isAllIccIdQueryDone()) {
            updateSubscriptionInfoByIccId();
        }
        update(slotId);
        updateCarrierServices(slotId, simState);
    }

@@ -535,7 +569,11 @@ public class SubscriptionInfoUpdater extends Handler {
    synchronized protected void updateSubscriptionInfoByIccId() {
        logd("updateSubscriptionInfoByIccId:+ Start");

        // only update external state if we have no pending updates pending
        boolean update = !hasMessages(EVENT_UPDATE_INSERTED_SIM_COUNT);
        if (update) {
            mSubscriptionManager.clearSubscriptionInfo();
        }

        for (int i = 0; i < PROJECT_SIM_NUM; i++) {
            mInsertSimState[i] = SIM_NOT_CHANGE;
@@ -549,6 +587,7 @@ public class SubscriptionInfoUpdater extends Handler {
            }
        }
        logd("insertedSimCount = " + insertedSimCount);
        mCurrentSimCount = insertedSimCount;

        int index = 0;
        for (int i = 0; i < PROJECT_SIM_NUM; i++) {
@@ -609,13 +648,13 @@ public class SubscriptionInfoUpdater extends Handler {
            if (mInsertSimState[i] == SIM_NOT_INSERT) {
                logd("updateSubscriptionInfoByIccId: No SIM inserted in slot " + i + " this time");
            } else {
                if (mInsertSimState[i] > 0) {
                if (mInsertSimState[i] > 0 && update) {
                    //some special SIMs may have the same IccIds, add suffix to distinguish them
                    //FIXME: addSubInfoRecord can return an error.
                    mSubscriptionManager.addSubscriptionInfoRecord(mIccId[i]
                            + Integer.toString(mInsertSimState[i]), i);
                    logd("SUB" + (i + 1) + " has invalid IccId");
                } else /*if (sInsertSimState[i] != SIM_NOT_INSERT)*/ {
                } else if (update)/*if (sInsertSimState[i] != SIM_NOT_INSERT)*/ {
                    mSubscriptionManager.addSubscriptionInfoRecord(mIccId[i], i);
                }
                if (isNewSim(mIccId[i], oldIccId)) {
@@ -666,14 +705,68 @@ public class SubscriptionInfoUpdater extends Handler {
            }
        }

        // Ensure the modems are mapped correctly
        mSubscriptionManager.setDefaultDataSubId(
                mSubscriptionManager.getDefaultDataSubscriptionId());
        if (update && !mIsShutdown && mLockedSims.cardinality() == 0) {
            final int previousUpdateSimCount = previousUpdateSimCount();
            if (previousUpdateSimCount != insertedSimCount) {
                logd("number of sims changed, resetting sms prompt, old sim count: "
                        + previousUpdateSimCount);
                if (insertedSimCount == 1 && PROJECT_SIM_NUM > 1) {
                    // 1 sim, msim device: clear stale defaults (doesn't clear inactive subs)
                    mSubscriptionManager.clearDefaultsForInactiveSubIds();

                    // then disable sms prompt (sms app will default to inserted sim)
                    PhoneFactory.setSMSPromptEnabled(false); // can't prompt for 1 sim

                    // finally, disable data if this single sim isn't our our selected data sim previously
                    int realStoredDataSub = Settings.Global.getInt(mContext.getContentResolver(),
                            Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION,
                            SubscriptionManager.INVALID_SUBSCRIPTION_ID);

                    if (realStoredDataSub != SubscriptionManager.INVALID_SUBSCRIPTION_ID &&
                            realStoredDataSub != SubscriptionManager.getDefaultDataSubscriptionId()) {
                        logd("switching data off; real stored sub: " + realStoredDataSub
                                + ", and we think the default sub id is now: "
                                + SubscriptionManager.getDefaultDataSubscriptionId());
                        PhoneFactory.getDefaultPhone().setDataEnabled(false);
                    }
                } else if (insertedSimCount > 1) {
                    // we now have multiple sims, maybe enable the SMS prompt if no valid
                    // sub is ready to handle SMS
                    PhoneFactory.setSMSPromptEnabled(!SubscriptionManager.isValidSubscriptionId(
                            SubscriptionManager.getDefaultSmsSubscriptionId()));
                }
                setPreviousUpdateSimCount(insertedSimCount);
            }
            // Ensure the modems are mapped correctly
            // will not override MSIM settings with 1 sim in the device.
            mSubscriptionManager.setDefaultDataSubId(SubscriptionManager.getDefaultDataSubscriptionId());
            SubscriptionController.getInstance().notifySubscriptionInfoChanged();
        } else if (update && !mIsShutdown) {
            // we have locked sims, need to update so we can unlock them
            SubscriptionController.getInstance().notifySubscriptionInfoChanged();
        }
        logd("updateSubscriptionInfoByIccId:- SsubscriptionInfo update complete");
    }

    private int previousUpdateSimCount() {
        return PreferenceManager.getDefaultSharedPreferences(mContext)
                .getInt(PREF_LAST_SEEN_SIM_COUNT, 0);
    }

    private void setPreviousUpdateSimCount(int simCount) {
        PreferenceManager.getDefaultSharedPreferences(mContext)
                .edit()
                .putInt(PREF_LAST_SEEN_SIM_COUNT, simCount)
                .apply();
    }

    protected int getInsertedSimCount() {
        if (!isAllIccIdQueryDone()) {
            return 0;
        }
        return mCurrentSimCount;
    }

    private boolean isNewSim(String iccId, String[] oldIccId) {
        boolean newSim = true;
        for(int i = 0; i < PROJECT_SIM_NUM; i++) {
+14 −1
Original line number Diff line number Diff line
@@ -292,6 +292,13 @@ public class UiccSmsController extends ISms.Stub {
    @Override
    public boolean isSmsSimPickActivityNeeded(int subId) {
        final Context context = ActivityThread.currentApplication().getApplicationContext();
        boolean canCurrentAppHandleAlwaysAsk = SmsApplication.canSmsAppHandleAlwaysAsk(context);
        if (!isSMSPromptEnabled() && canCurrentAppHandleAlwaysAsk) {
            Rlog.d(LOG_TAG, "isSmsSimPickActivityNeeded: false, sms prompt disabled.");
            // user knows best
            return false;
        }

        TelephonyManager telephonyManager =
                (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        List<SubscriptionInfo> subInfoList;
@@ -315,11 +322,17 @@ public class UiccSmsController extends ISms.Stub {

            // If reached here and multiple SIMs and subs present, sms sim pick activity is needed
            if (subInfoLength > 0 && telephonyManager.getSimCount() > 1) {
                final SubscriptionInfoUpdater subscriptionInfoUpdater
                        = PhoneFactory.getSubscriptionInfoUpdater();
                if (subscriptionInfoUpdater != null) {
                    // use the *real* inserted sim count if we can
                    return subscriptionInfoUpdater.getInsertedSimCount() > 1;
                }
                return true;
            }
        }

        return false;
        return !canCurrentAppHandleAlwaysAsk;
    }

    @Override