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

Commit 157aa77b authored by Xiangyu/Malcolm Chen's avatar Xiangyu/Malcolm Chen Committed by Gerrit Code Review
Browse files

Merge changes Ifb9e5594,I2ed64610,I1e60405e

* changes:
  Add a subscription record in simTable for inactive SIM.
  Don't send data enable change if subId is not valid.
  Use correct activeModemCount upon onMultiSimConfigChanged.
parents eb5d84b2 b3515e55
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -200,15 +200,19 @@ public class MultiSimSettingController extends Handler {
     * Notify MOBILE_DATA of a subscription is changed.
     */
    public void notifyUserDataEnabled(int subId, boolean enable) {
        if (SubscriptionManager.isValidSubscriptionId(subId)) {
            obtainMessage(EVENT_USER_DATA_ENABLED, subId, enable ? 1 : 0).sendToTarget();
        }
    }

    /**
     * Notify DATA_ROAMING of a subscription is changed.
     */
    public void notifyRoamingDataEnabled(int subId, boolean enable) {
        if (SubscriptionManager.isValidSubscriptionId(subId)) {
            obtainMessage(EVENT_ROAMING_DATA_ENABLED, subId, enable ? 1 : 0).sendToTarget();
        }
    }

    /**
     * Notify that, for the first time after boot, SIMs are initialized.
+3 −2
Original line number Diff line number Diff line
@@ -1431,9 +1431,10 @@ public class SubscriptionController extends ISub.Stub {
        value.put(SubscriptionManager.CARRIER_NAME, "");
        value.put(SubscriptionManager.CARD_ID, uniqueId);
        value.put(SubscriptionManager.SUBSCRIPTION_TYPE, subscriptionType);
        if (isSubscriptionForRemoteSim(subscriptionType)) {
        if (!TextUtils.isEmpty(displayName)) {
            value.put(SubscriptionManager.DISPLAY_NAME, displayName);
        } else {
        }
        if (!isSubscriptionForRemoteSim(subscriptionType)) {
            UiccCard card = mUiccController.getUiccCardForPhone(slotIndex);
            if (card != null) {
                String cardId = card.getCardId();
+59 −15
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ public class SubscriptionInfoUpdater extends Handler {
    private static final int EVENT_SIM_IMSI = 11;
    private static final int EVENT_REFRESH_EMBEDDED_SUBSCRIPTIONS = 12;
    private static final int EVENT_MULTI_SIM_CONFIG_CHANGED = 13;
    private static final int EVENT_INACTIVE_SLOT_ICC_STATE_CHANGED = 14;

    private static final String ICCID_STRING_FOR_NO_SIM = "";

@@ -198,16 +199,26 @@ public class SubscriptionInfoUpdater extends Handler {
    /**
     * Update subscriptions when given a new ICC state.
     */
    public void updateInternalIccState(String simStatus, String reason, int phoneId,
            boolean absentAndInactive) {
    public void updateInternalIccState(String simStatus, String reason, int phoneId) {
        logd("updateInternalIccState to simStatus " + simStatus + " reason " + reason
                + " phoneId " + phoneId);
        int message = internalIccStateToMessage(simStatus);
        if (message != EVENT_INVALID) {
            sendMessage(obtainMessage(message, phoneId, absentAndInactive ? 1 : 0, reason));
            sendMessage(obtainMessage(message, phoneId, 0, reason));
        }
    }

    /**
     * Update subscriptions if needed when there's a change in inactive slot.
     * @param prevActivePhoneId is the corresponding phoneId of the slot if slot was previously
     *                          active. It could be INVALID if it was already inactive.
     * @param iccId iccId in that slot, if any.
     */
    public void updateInternalIccStateForInactiveSlot(int prevActivePhoneId, String iccId) {
        sendMessage(obtainMessage(EVENT_INACTIVE_SLOT_ICC_STATE_CHANGED, prevActivePhoneId,
                0, iccId));
    }

    private int internalIccStateToMessage(String simStatus) {
        switch(simStatus) {
            case IccCardConstants.INTENT_VALUE_ICC_ABSENT: return EVENT_SIM_ABSENT;
@@ -268,7 +279,11 @@ public class SubscriptionInfoUpdater extends Handler {
                break;

            case EVENT_SIM_ABSENT:
                handleSimAbsent(msg.arg1, msg.arg2);
                handleSimAbsent(msg.arg1);
                break;

            case EVENT_INACTIVE_SLOT_ICC_STATE_CHANGED:
                handleInactiveSlotIccStateChange(msg.arg1, (String) msg.obj);
                break;

            case EVENT_SIM_LOCKED:
@@ -605,10 +620,31 @@ public class SubscriptionInfoUpdater extends Handler {
        }
    }

    private void handleSimAbsent(int phoneId, int absentAndInactive) {
    /**
     * PhoneId is the corresponding phoneId of the slot if slot was previously active.
     * It could be INVALID if it was already inactive.
     */
    private void handleInactiveSlotIccStateChange(int phoneId, String iccId) {
        // If phoneId is valid, it means the physical slot was active in that phoneId. In this case,
        // we clear (mark inactive) the subscription in db on that phone.
        if (SubscriptionManager.isValidPhoneId(phoneId)) {
            if (sIccId[phoneId] != null && !sIccId[phoneId].equals(ICCID_STRING_FOR_NO_SIM)) {
            logd("SIM" + (phoneId + 1) + " hot plug out, absentAndInactive=" + absentAndInactive);
                logd("Slot of SIM" + (phoneId + 1) + " becomes inactive");
            }
            cleanSubscriptionInPhone(phoneId);
        }
        if (!TextUtils.isEmpty(iccId)) {
            // If iccId is new, add a subscription record in the db.
            String strippedIccId = IccUtils.stripTrailingFs(iccId);
            if (SubscriptionController.getInstance().getSubInfoForIccId(strippedIccId) == null) {
                SubscriptionController.getInstance().insertEmptySubInfoRecord(
                        strippedIccId, "CARD", SubscriptionManager.INVALID_PHONE_INDEX,
                        SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM);
            }
        }
    }

    private void cleanSubscriptionInPhone(int phoneId) {
        sIccId[phoneId] = ICCID_STRING_FOR_NO_SIM;
        int[] subIds = SubscriptionController.getInstance().getSubId(phoneId);
        if (subIds != null && subIds.length > 0) {
@@ -620,16 +656,24 @@ public class SubscriptionInfoUpdater extends Handler {
                    SubscriptionController.getSelectionForSubIdList(subIds), null);
        }
        updateSubscriptionInfoByIccId(phoneId, true /* updateEmbeddedSubs */);
        // Do not broadcast if the SIM is absent and inactive, because the logical phoneId here is
        // no longer correct
        if (absentAndInactive == 0) {
    }

    private void handleSimAbsent(int phoneId) {
        if (!SubscriptionManager.isValidPhoneId(phoneId)) {
            logd("handleSimAbsent on invalid phoneId");
            return;
        }
        if (sIccId[phoneId] != null && !sIccId[phoneId].equals(ICCID_STRING_FOR_NO_SIM)) {
            logd("SIM" + (phoneId + 1) + " hot plug out");
        }
        cleanSubscriptionInPhone(phoneId);

        broadcastSimStateChanged(phoneId, IccCardConstants.INTENT_VALUE_ICC_ABSENT, null);
        broadcastSimCardStateChanged(phoneId, TelephonyManager.SIM_STATE_ABSENT);
        broadcastSimApplicationStateChanged(phoneId, TelephonyManager.SIM_STATE_UNKNOWN);
        updateSubscriptionCarrierId(phoneId, IccCardConstants.INTENT_VALUE_ICC_ABSENT);
        updateCarrierServices(phoneId, IccCardConstants.INTENT_VALUE_ICC_ABSENT);
    }
    }

    private void handleSimError(int phoneId) {
        if (sIccId[phoneId] != null && !sIccId[phoneId].equals(ICCID_STRING_FOR_NO_SIM)) {
+23 −11
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.os.storage.StorageManager;
import android.preference.PreferenceManager;
import android.sysprop.TelephonyProperties;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.UiccCardInfo;
import android.text.TextUtils;
@@ -533,7 +534,9 @@ public class UiccController extends Handler {
                    break;
                case EVENT_MULTI_SIM_CONFIG_CHANGED:
                    if (DBG) log("Received EVENT_MULTI_SIM_CONFIG_CHANGED");
                    onMultiSimConfigChanged();
                    int activeModemCount = (int) ((AsyncResult) msg.obj).result;
                    onMultiSimConfigChanged(activeModemCount);
                    break;
                default:
                    Rlog.e(LOG_TAG, " Unknown Event " + msg.what);
                    break;
@@ -541,10 +544,9 @@ public class UiccController extends Handler {
        }
    }

    private void onMultiSimConfigChanged() {
    private void onMultiSimConfigChanged(int newActiveModemCount) {
        int prevActiveModemCount = mCis.length;
        mCis = PhoneFactory.getCommandsInterfaces();
        int newActiveModemCount = mCis.length;

        logWithLocalLog("onMultiSimConfigChanged: prevActiveModemCount " + prevActiveModemCount
                + ", newActiveModemCount " + newActiveModemCount);
@@ -641,23 +643,33 @@ public class UiccController extends Handler {
        }
    }

    static void updateInternalIccState(Context context, IccCardConstants.State state, String reason,
            int phoneId) {
        updateInternalIccState(context, state, reason, phoneId, false);
    static void updateInternalIccStateForInactiveSlot(
            Context context, int prevActivePhoneId, String iccId) {
        if (SubscriptionManager.isValidPhoneId(prevActivePhoneId)) {
            // Mark SIM state as ABSENT on previously phoneId.
            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(
                    Context.TELEPHONY_SERVICE);
            telephonyManager.setSimStateForPhone(prevActivePhoneId,
                    IccCardConstants.State.ABSENT.toString());
        }

        SubscriptionInfoUpdater subInfoUpdator = PhoneFactory.getSubscriptionInfoUpdater();
        if (subInfoUpdator != null) {
            subInfoUpdator.updateInternalIccStateForInactiveSlot(prevActivePhoneId, iccId);
        } else {
            Rlog.e(LOG_TAG, "subInfoUpdate is null.");
        }
    }

    // absentAndInactive is a special case when we need to update subscriptions but don't want to
    // broadcast a state change
    static void updateInternalIccState(Context context, IccCardConstants.State state, String reason,
            int phoneId, boolean absentAndInactive) {
            int phoneId) {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(
                Context.TELEPHONY_SERVICE);
        telephonyManager.setSimStateForPhone(phoneId, state.toString());

        SubscriptionInfoUpdater subInfoUpdator = PhoneFactory.getSubscriptionInfoUpdater();
        if (subInfoUpdator != null) {
            subInfoUpdator.updateInternalIccState(getIccStateIntentString(state),
                    reason, phoneId, absentAndInactive);
            subInfoUpdator.updateInternalIccState(getIccStateIntentString(state), reason, phoneId);
        } else {
            Rlog.e(LOG_TAG, "subInfoUpdate is null.");
        }
+1 −3
Original line number Diff line number Diff line
@@ -154,12 +154,10 @@ public class UiccSlot extends Handler {
            if (iss.slotState == IccSlotStatus.SlotState.SLOTSTATE_INACTIVE) {
                // TODO: (b/79432584) evaluate whether should broadcast card state change
                // even if it's inactive.
                UiccController.updateInternalIccStateForInactiveSlot(mContext, mPhoneId, mIccId);
                if (mActive) {
                    mActive = false;
                    mLastRadioState = TelephonyManager.RADIO_POWER_UNAVAILABLE;
                    UiccController.updateInternalIccState(
                            mContext, IccCardConstants.State.ABSENT, null, mPhoneId,
                            true /* special notification for absent card in an inactive slot */);
                    mPhoneId = INVALID_PHONE_ID;
                    nullifyUiccCard(true /* sim state is unknown */);
                }
Loading