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

Commit 8048c4a7 authored by Steve Kondik's avatar Steve Kondik
Browse files

Revert "RIL: Squash changes to default SIM handling"

This reverts commit 04824aa5.

Change-Id: I70ddee6f0d5ec38773db000f76ac2d528ef62d61
parent 04824aa5
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -366,14 +366,6 @@ 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
@@ -513,8 +505,4 @@ public class PhoneFactory {
        }
        pw.decreaseIndent();
    }

    public static SubscriptionInfoUpdater getSubscriptionInfoUpdater() {
        return sSubInfoRecordUpdater;
    }
}
+0 −12
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ 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,7 +61,6 @@ 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";
@@ -900,16 +898,6 @@ 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) {
+9 −36
Original line number Diff line number Diff line
@@ -186,14 +186,7 @@ public class SubscriptionController extends ISub.Stub {
    }

    private boolean isSubInfoReady() {
        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;
        return sSlotIdxToSubId.size() > 0;
    }

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

    /**
@@ -763,28 +756,22 @@ 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 simCount = PhoneFactory.getSubscriptionInfoUpdater()
                                    .getInsertedSimCount();
                            int subIdCountMax = getActiveSubInfoCountMax();
                            int defaultSubId = getDefaultSubId();
                            if (DBG) {
                                logdl("[addSubInfoRecord]"
                                        + " sSlotIdxToSubId.size=" + sSlotIdxToSubId.size()
                                        + " slotId=" + slotId + " subId=" + subId
                                        + " defaultSubId=" + defaultSubId + " simCount=" + simCount);
                            }

                            if (!isSubInfoReady()) {
                                continue;
                                        + " defaultSubId=" + defaultSubId + " simCount=" + subIdCountMax);
                            }

                            // Set the default sub if not set or if single sim device
                            if (!SubscriptionManager.isValidSubscriptionId(defaultSubId)
                                    || simCount == 1 || (!isActiveSubId(defaultSubId))) {
                                    || subIdCountMax == 1 || (!isActiveSubId(defaultSubId))) {
                                setDefaultFallbackSubId(subId);
                            }
                            // If single sim device, set this subscription as the default for everything
                            if (simCount == 1
                                    && TelephonyManager.getDefault().getSimCount() == 1) {
                            if (subIdCountMax == 1) {
                                if (DBG) {
                                    logdl("[addSubInfoRecord] one sim set defaults to subId=" + subId);
                                }
@@ -1414,10 +1401,6 @@ 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);
@@ -1449,10 +1432,6 @@ 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);
@@ -1462,10 +1441,6 @@ 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);
@@ -1518,10 +1493,8 @@ 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);
    }

@@ -1556,7 +1529,7 @@ public class SubscriptionController extends ISub.Stub {
        if (SubscriptionManager.isValidSubscriptionId(subId)) {
            int phoneId = getPhoneId(subId);
            if (phoneId >= 0 && (phoneId < mTelephonyManager.getPhoneCount()
                    || isSingleSimActiveOnMSIM())) {
                    || mTelephonyManager.getSimCount() == 1)) {
                if (DBG) logdl("[setDefaultFallbackSubId] set mDefaultFallbackSubId=" + subId);
                mDefaultFallbackSubId = subId;
                // Update MCC MNC device configuration information
+19 −112
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ 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,9 +74,6 @@ public class SubscriptionInfoUpdater extends Handler {
    private static final int EVENT_SIM_LOCKED = 5;
    private static final int EVENT_SIM_IO_ERROR = 6;
    private static final int EVENT_SIM_UNKNOWN = 7;
    private static final int EVENT_UPDATE_INSERTED_SIM_COUNT = 8;

    private static final int DELAY_MILLIS = 500;

    private static final String ICCID_STRING_FOR_NO_SIM = "";
    /**
@@ -105,8 +101,6 @@ 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;
@@ -120,9 +114,6 @@ 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");
@@ -132,12 +123,10 @@ 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);
@@ -210,11 +199,6 @@ 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;
@@ -251,16 +235,6 @@ 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]-");
        }
    };
@@ -320,7 +294,9 @@ public class SubscriptionInfoUpdater extends Handler {
                    logd("Query IccId fail: " + ar.exception);
                }
                logd("sIccId[" + slotId + "] = " + mIccId[slotId]);
                update(slotId);
                if (isAllIccIdQueryDone()) {
                    updateSubscriptionInfoByIccId();
                }
                broadcastSimStateChanged(slotId, IccCardConstants.INTENT_VALUE_ICC_LOCKED,
                                         uObj.reason);
                if (!ICCID_STRING_FOR_NO_SIM.equals(mIccId[slotId])) {
@@ -363,14 +339,6 @@ public class SubscriptionInfoUpdater extends Handler {
                handleSimAbsentOrError(msg.arg1, IccCardConstants.INTENT_VALUE_ICC_CARD_IO_ERROR);
                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);
        }
@@ -392,6 +360,7 @@ public class SubscriptionInfoUpdater extends Handler {
            mIccId[slotId] = null;
        }


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

@@ -410,14 +379,6 @@ 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) {
@@ -436,7 +397,10 @@ public class SubscriptionInfoUpdater extends Handler {
            return;
        }
        mIccId[slotId] = records.getIccId();
        update(slotId);

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

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

@@ -567,11 +533,7 @@ 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;
@@ -585,7 +547,6 @@ public class SubscriptionInfoUpdater extends Handler {
            }
        }
        logd("insertedSimCount = " + insertedSimCount);
        mCurrentSimCount = insertedSimCount;

        int index = 0;
        for (int i = 0; i < PROJECT_SIM_NUM; i++) {
@@ -646,13 +607,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 && update) {
                if (mInsertSimState[i] > 0) {
                    //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 (update)/*if (sInsertSimState[i] != SIM_NOT_INSERT)*/ {
                } else /*if (sInsertSimState[i] != SIM_NOT_INSERT)*/ {
                    mSubscriptionManager.addSubscriptionInfoRecord(mIccId[i], i);
                }
                if (isNewSim(mIccId[i], oldIccId)) {
@@ -703,68 +664,14 @@ public class SubscriptionInfoUpdater extends Handler {
            }
        }

        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
        mSubscriptionManager.setDefaultDataSubId(
                mSubscriptionManager.getDefaultDataSubscriptionId());

        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++) {
+1 −14
Original line number Diff line number Diff line
@@ -292,13 +292,6 @@ 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;
@@ -322,17 +315,11 @@ 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 !canCurrentAppHandleAlwaysAsk;
        return false;
    }

    @Override