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

Commit 887bb592 authored by SongFerngWang's avatar SongFerngWang
Browse files

Reuse the active esim slot

If there is the active esim slot in SS mode, the settings should
reuse it and does not change the sim slot mapping.

Bug: 229803628
Test: manually test.
Change-Id: I6daa38f54abfaf67c7640d9dc8be0da02eb59554
Merged-In: I6daa38f54abfaf67c7640d9dc8be0da02eb59554
parent faf9baf9
Loading
Loading
Loading
Loading
+18 −4
Original line number Diff line number Diff line
@@ -21,12 +21,14 @@ import android.app.PendingIntent;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.UiccCardInfo;
import android.telephony.UiccSlotMapping;
import android.telephony.euicc.EuiccManager;
import android.util.Log;

import com.android.settings.SidecarFragment;
import com.android.settings.network.telephony.EuiccOperationSidecar;

import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
@@ -94,7 +96,7 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {

        // To check whether the esim slot's port is active. If yes, skip setSlotMapping. If no,
        // set this slot+port into setSimSlotMapping.
        mPort = (port < 0) ? getTargetPortId(removedSubInfo) : port;
        mPort = (port < 0) ? getTargetPortId(targetSlot, removedSubInfo) : port;
        mRemovedSubInfo = removedSubInfo;
        Log.d(TAG,
                String.format("set esim into the SubId%d Slot%d:Port%d",
@@ -114,12 +116,24 @@ public class SwitchToEuiccSubscriptionSidecar extends EuiccOperationSidecar {
        }
    }

    private int getTargetPortId(SubscriptionInfo removedSubInfo) {
        if (!mTelephonyManager.isMultiSimEnabled() || !isMultipleEnabledProfilesSupported()) {
            // In the 'SS mode' or 'DSDS+no MEP', the port is 0.
    private int getTargetPortId(int physicalEsimSlotIndex, SubscriptionInfo removedSubInfo) {
        if (!isMultipleEnabledProfilesSupported()) {
            Log.d(TAG, "The device is no MEP, port is 0");
            return 0;
        }

        if (!mTelephonyManager.isMultiSimEnabled()) {
            // In the 'SS mode'
            // If there is the esim slot is active, the port is from the current esim slot.
            // If there is no esim slot in device, then the esim's port is 0.
            Collection<UiccSlotMapping> uiccSlotMappings = mTelephonyManager.getSimSlotMapping();
            Log.d(TAG, "In SS mode, the UiccSlotMapping: " + uiccSlotMappings);
            return uiccSlotMappings.stream()
                    .filter(i -> i.getPhysicalSlotIndex() == physicalEsimSlotIndex)
                    .mapToInt(i -> i.getPortIndex())
                    .findFirst().orElse(0);
        }

        // In the 'DSDS+MEP', if the removedSubInfo is esim, then the port is
        // removedSubInfo's port.
        if (removedSubInfo != null && removedSubInfo.isEmbedded()) {
+15 −0
Original line number Diff line number Diff line
@@ -282,6 +282,21 @@ public class UiccSlotUtil {
    // 1. pSIM's logical slots always is [RIL 0].
    // 2. assign the new active port to the same stack that will be de-activated
    //    For example: mode#3->mode#4
    // 3. Add an eSIM carrier or enable eSIM carrier. The cases are at the below.
    //    1) 1   => 2 / 2.1 / 3 / 3.1
    //    2) 2   => 1 / 3 / 3.2
    //    3) 2.1 => 3.1 / 4
    //    4) 3   => 4
    //    5) 3.1 => 3.2
    //    Note:
    //        1) 2 <=> 2.1  blocked by LPA (reason: existing active port in SS so just re-use)
    //        2) 3 <=> 3.1 blocked by LPA (reason: if pSIM+an active port, re-use the active port)
    // 4. pSIM insertion or enabling
    //     1) 2   => 1 / 3
    //     2) 2.1 => 1 / 3.1
    //     3) 3.2 => 3 / 3.1
    //     4) 4   => 3 / 3.1


    @VisibleForTesting
    static Collection<UiccSlotMapping> prepareUiccSlotMappings(