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

Commit 640e5643 authored by Malcolm Chen's avatar Malcolm Chen
Browse files

Remove logic to manually search inactive pSIM.

Nowe inserted inactive pSIM will be included in Telephony's get
available and get selectable subInfo list so that logic is no longer
needed.

Bug: 147128878
Test: unittest
Change-Id: Icd131f133e47dae0770a4da71c51de3c2a94b42b
parent 3225b325
Loading
Loading
Loading
Loading
+0 −29
Original line number Diff line number Diff line
@@ -80,39 +80,10 @@ public class SubscriptionUtil {
            return sAvailableResultsForTesting;
        }
        final SubscriptionManager subMgr = context.getSystemService(SubscriptionManager.class);
        final TelephonyManager telMgr = context.getSystemService(TelephonyManager.class);

        final List<SubscriptionInfo> subscriptions =
                new ArrayList<>(emptyIfNull(subMgr.getSelectableSubscriptionInfoList()));

        // Look for inactive but present physical SIMs that are missing from the selectable list.
        final List<UiccSlotInfo> missing = new ArrayList<>();
        final UiccSlotInfo[] slotsInfo = telMgr.getUiccSlotsInfo();
        for (int i = 0; slotsInfo != null && i < slotsInfo.length; i++) {
            final UiccSlotInfo slotInfo = slotsInfo[i];
            if (isInactiveInsertedPSim(slotInfo)) {
                final int index = slotInfo.getLogicalSlotIdx();
                final String cardId = slotInfo.getCardId();

                final boolean found = subscriptions.stream().anyMatch(info ->
                        index == info.getSimSlotIndex() && cardId.equals(info.getCardString()));
                if (!found) {
                    missing.add(slotInfo);
                }
            }
        }
        if (missing.isEmpty()) {
            return subscriptions;
        }
        for (SubscriptionInfo info : subMgr.getAllSubscriptionInfoList()) {
            for (UiccSlotInfo slotInfo : missing) {
                if (info.getSimSlotIndex() == slotInfo.getLogicalSlotIdx()
                        && info.getCardString().equals(slotInfo.getCardId())) {
                    subscriptions.add(info);
                    break;
                }
            }
        }
        return subscriptions;
    }

+0 −32
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@@ -87,37 +86,6 @@ public class SubscriptionUtilTest {
        assertThat(subs).hasSize(2);
    }

    @Test
    public void getAvailableSubscriptions_oneSelectableOneDisabledPSim_twoResults() {
        final SubscriptionInfo info1 = mock(SubscriptionInfo.class);
        final SubscriptionInfo info2 = mock(SubscriptionInfo.class);

        when(info1.getSubscriptionId()).thenReturn(111);
        when(info1.getSimSlotIndex()).thenReturn(-1);
        when(info1.getCardString()).thenReturn("info1_cardid");

        when(info2.getSubscriptionId()).thenReturn(222);
        when(info2.getSimSlotIndex()).thenReturn(0);
        when(info2.getCardString()).thenReturn("info2_cardid");

        when(mSubMgr.getSelectableSubscriptionInfoList()).thenReturn(Arrays.asList(info1));
        when(mSubMgr.getAllSubscriptionInfoList()).thenReturn(Arrays.asList(info1, info2));

        final UiccSlotInfo info2slot = mock(UiccSlotInfo.class);
        when(info2slot.getCardStateInfo()).thenReturn(CARD_STATE_INFO_PRESENT);
        when(info2slot.getLogicalSlotIdx()).thenReturn(0);
        when(info2slot.getCardId()).thenReturn("info2_cardid");

        final UiccSlotInfo[] slotInfos = {info2slot};
        when(mTelMgr.getUiccSlotsInfo()).thenReturn(slotInfos);

        final List<SubscriptionInfo> subs = SubscriptionUtil.getAvailableSubscriptions(mContext);
        assertThat(subs).hasSize(2);
        assertThat(subs.get(0).getSubscriptionId()).isEqualTo(111);
        assertThat(subs.get(1).getSubscriptionId()).isEqualTo(222);
    }


    @Test
    public void getAvailableSubscriptions_oneSelectableTwoDisabledPSimsOneAbsent_twoResults() {
        final SubscriptionInfo info1 = mock(SubscriptionInfo.class);