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

Commit eaec0595 authored by SongFerngWang's avatar SongFerngWang Committed by SongFerng Wang
Browse files

[MEP] disable enabled esim profile before set simSlotMapping

This is the modem request to disable enabled esim profile before
set simSlotMapping.
Since the framework still do API refactor ag/16494924. The
switchToSub API will be changed, so here modify two callback.
the one of callback will be removed after the framework complete
the API refactor.

Bug: 210063749
Test: Build pass. Local test: do sim switch in SS mode and DSDS mode.
Change-Id: Iee650897b81c96b5febb0413649629b1a1971b18
Merged-In: Iee650897b81c96b5febb0413649629b1a1971b18
parent ba9d2669
Loading
Loading
Loading
Loading
+45 −6
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.FragmentManager;
import android.app.PendingIntent;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.Intent;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.UiccCardInfo;
import android.telephony.UiccCardInfo;
import android.telephony.UiccSlotMapping;
import android.telephony.UiccSlotMapping;
import android.telephony.euicc.EuiccManager;
import android.telephony.euicc.EuiccManager;
@@ -34,7 +35,7 @@ import java.util.stream.Collectors;


/** A headless fragment encapsulating long-running eSIM enabling/disabling operations. */
/** A headless fragment encapsulating long-running eSIM enabling/disabling operations. */
public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
    private static final String TAG = "SwitchToEuiccSubscriptionSidecar";
    private static final String TAG = "SwitchToEuiccSidecar";
    private static final String ACTION_SWITCH_TO_SUBSCRIPTION =
    private static final String ACTION_SWITCH_TO_SUBSCRIPTION =
            "com.android.settings.network.SWITCH_TO_SUBSCRIPTION";
            "com.android.settings.network.SWITCH_TO_SUBSCRIPTION";
    private static final int ESIM_SLOT_ID = 1;
    private static final int ESIM_SLOT_ID = 1;
@@ -42,6 +43,8 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
    private PendingIntent mCallbackIntent;
    private PendingIntent mCallbackIntent;
    private int mSubId;
    private int mSubId;
    private int mPort;
    private int mPort;
    private SubscriptionInfo mRemovedSubInfo;
    private boolean mIsDuringSimSlotMapping;


    /** Returns a SwitchToEuiccSubscriptionSidecar sidecar instance. */
    /** Returns a SwitchToEuiccSubscriptionSidecar sidecar instance. */
    public static SwitchToEuiccSubscriptionSidecar get(FragmentManager fm) {
    public static SwitchToEuiccSubscriptionSidecar get(FragmentManager fm) {
@@ -93,10 +96,35 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
        // To check whether the esim slot's port is active. If yes, skip setSlotMapping. If no,
        // To check whether the esim slot's port is active. If yes, skip setSlotMapping. If no,
        // set this slot+port into setSimSlotMapping.
        // set this slot+port into setSimSlotMapping.
        mPort = (port < 0) ? getTargetPortId(removedSubInfo) : port;
        mPort = (port < 0) ? getTargetPortId(removedSubInfo) : port;
        Log.i(TAG, "The SubId is " + mSubId + "The port is " + mPort);
        mRemovedSubInfo = removedSubInfo;

        Log.i(TAG, "The SubId is " + mSubId + ". The port is " + mPort);

        if (mTelephonyManager.isMultiSimEnabled() && removedSubInfo != null
                && removedSubInfo.isEmbedded()) {
            // In DSDS mode+MEP, if the replaced esim is active, then it should be disabled esim
            // profile before changing SimSlotMapping process.
            // Use INVALID_SUBSCRIPTION_ID to disable the esim profile.
            // The SimSlotMapping is ready, then to execute activate/inactivate esim.
            mIsDuringSimSlotMapping = true;
            EuiccManager.ResultListener callback = new EuiccManager.ResultListener() {
                @Override
                public void onComplete(int resultCode, Intent resultIntent) {
                    Log.i(TAG, String.format("Result code : %d;", resultCode));
                    if (resultCode == EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK) {
                        mSwitchSlotSidecar.runSwitchToEuiccSlot(getTargetSlot(), mPort,
                                removedSubInfo);
                    } else {
                        setState(State.ERROR, resultCode);
                    }
                }
            };
            mEuiccManager.switchToSubscription(SubscriptionManager.INVALID_SUBSCRIPTION_ID, mPort,
                    getContext().getMainExecutor(),
                    callback);
        } else {
            mSwitchSlotSidecar.runSwitchToEuiccSlot(getTargetSlot(), mPort, removedSubInfo);
            mSwitchSlotSidecar.runSwitchToEuiccSlot(getTargetSlot(), mPort, removedSubInfo);
        }
        }
    }


    private int getTargetPortId(SubscriptionInfo removedSubInfo) {
    private int getTargetPortId(SubscriptionInfo removedSubInfo) {
        if (!mTelephonyManager.isMultiSimEnabled() || !isMultipleEnabledProfilesSupported()) {
        if (!mTelephonyManager.isMultiSimEnabled() || !isMultipleEnabledProfilesSupported()) {
@@ -136,8 +164,7 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
        switch (mSwitchSlotSidecar.getState()) {
        switch (mSwitchSlotSidecar.getState()) {
            case State.SUCCESS:
            case State.SUCCESS:
                mSwitchSlotSidecar.reset();
                mSwitchSlotSidecar.reset();
                Log.i(TAG,
                Log.i(TAG, "Successfully SimSlotMapping. Start to enable/disable esim");
                        "Successfully SimSlotMapping. Start to enable/disable esim");
                switchToSubscription();
                switchToSubscription();
                break;
                break;
            case State.ERROR:
            case State.ERROR:
@@ -174,4 +201,16 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
        mEuiccManager.switchToSubscription(mSubId, mPort, getContext().getMainExecutor(),
        mEuiccManager.switchToSubscription(mSubId, mPort, getContext().getMainExecutor(),
                callback);
                callback);
    }
    }

    @Override
    protected void onActionReceived() {
        if (getResultCode() == EuiccManager.EMBEDDED_SUBSCRIPTION_RESULT_OK
                && mIsDuringSimSlotMapping) {
            // Continue to switch the SimSlotMapping, after the esim is disabled.
            mIsDuringSimSlotMapping = false;
            mSwitchSlotSidecar.runSwitchToEuiccSlot(getTargetSlot(), mPort, mRemovedSubInfo);
        } else {
            super.onActionReceived();
        }
    }
}
}
+20 −5
Original line number Original line Diff line number Diff line
@@ -31,8 +31,7 @@ import com.android.settings.network.telephony.EuiccOperationSidecar;
 */
 */
public class SwitchToRemovableSlotSidecar extends EuiccOperationSidecar
public class SwitchToRemovableSlotSidecar extends EuiccOperationSidecar
        implements SidecarFragment.Listener {
        implements SidecarFragment.Listener {

    private static final String TAG = "SwitchRemovableSidecar";
    private static final String TAG = "DisableSubscriptionAndSwitchSlotSidecar";
    private static final String ACTION_DISABLE_SUBSCRIPTION_AND_SWITCH_SLOT =
    private static final String ACTION_DISABLE_SUBSCRIPTION_AND_SWITCH_SLOT =
            "disable_subscription_and_switch_slot_sidecar";
            "disable_subscription_and_switch_slot_sidecar";


@@ -115,10 +114,26 @@ public class SwitchToRemovableSlotSidecar extends EuiccOperationSidecar
    public void run(int physicalSlotId, SubscriptionInfo removedSubInfo) {
    public void run(int physicalSlotId, SubscriptionInfo removedSubInfo) {
        mPhysicalSlotId = physicalSlotId;
        mPhysicalSlotId = physicalSlotId;
        mRemovedSubInfo = removedSubInfo;
        mRemovedSubInfo = removedSubInfo;

        SubscriptionManager subscriptionManager =
                getContext().getSystemService(SubscriptionManager.class);
        if (!mTelephonyManager.isMultiSimEnabled()
                && SubscriptionUtil.getActiveSubscriptions(subscriptionManager).stream().anyMatch(
                SubscriptionInfo::isEmbedded)) {
            // In SS mode, the esim is active, then inactivate the esim.
            Log.i(TAG, "There is an active eSIM profile. Disable the profile first.");
            // Use INVALID_SUBSCRIPTION_ID to disable the only active profile.
            mSwitchToSubscriptionSidecar.run(SubscriptionManager.INVALID_SUBSCRIPTION_ID, 0, null);
        } else if (mTelephonyManager.isMultiSimEnabled() && mRemovedSubInfo != null) {
            // In DSDS mode+MEP, if the replaced esim is active, then it should be disabled esim
            // profile before changing SimSlotMapping process.
            // Use INVALID_SUBSCRIPTION_ID to disable the esim profile.
            mSwitchToSubscriptionSidecar.run(SubscriptionManager.INVALID_SUBSCRIPTION_ID,
                    mRemovedSubInfo.getPortIndex(), null);
        } else {
            Log.i(TAG, "Start to switch to removable slot.");
            Log.i(TAG, "Start to switch to removable slot.");
            mSwitchSlotSidecar.runSwitchToRemovableSlot(mPhysicalSlotId, mRemovedSubInfo);
            mSwitchSlotSidecar.runSwitchToRemovableSlot(mPhysicalSlotId, mRemovedSubInfo);
        }
        }
    }


    private void onSwitchToSubscriptionSidecarStateChange() {
    private void onSwitchToSubscriptionSidecarStateChange() {
        switch (mSwitchToSubscriptionSidecar.getState()) {
        switch (mSwitchToSubscriptionSidecar.getState()) {