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

Commit d1c5c851 authored by Malcolm Chen's avatar Malcolm Chen
Browse files

Include inserted pSIM (possibily inactive) in available sub list.

Bug: 147128878
Test: unittest
Change-Id: Ic5b5396e3bba43005f46eb8af7720355c10c240a
Merged-In: Ic5b5396e3bba43005f46eb8af7720355c10c240a
parent af1e8860
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import com.android.internal.telephony.metrics.TelephonyMetrics;
import com.android.internal.telephony.uicc.IccUtils;
import com.android.internal.telephony.uicc.UiccCard;
import com.android.internal.telephony.uicc.UiccController;
import com.android.internal.telephony.uicc.UiccSlot;
import com.android.internal.telephony.util.ArrayUtils;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.telephony.Rlog;
@@ -896,6 +897,12 @@ public class SubscriptionController extends ISub.Stub {
                selection += " OR " + SubscriptionManager.IS_EMBEDDED + "=1";
            }

            List<String> iccIds = getIccIdsOfInsertedSims();
            if (!iccIds.isEmpty()) {
                selection += " OR ("  + getSelectionForIccIdList(iccIds.toArray(new String[0]))
                        + ")";
            }

            List<SubscriptionInfo> subList = getSubInfo(selection, null /* queryKey */);

            if (subList != null) {
@@ -912,6 +919,22 @@ public class SubscriptionController extends ISub.Stub {
        }
    }

    private List<String> getIccIdsOfInsertedSims() {
        List<String> ret = new ArrayList<>();
        UiccSlot[] uiccSlots = UiccController.getInstance().getUiccSlots();
        if (uiccSlots == null) return ret;

        for (UiccSlot uiccSlot : uiccSlots) {
            if (uiccSlot != null && uiccSlot.getCardState() != null
                    && uiccSlot.getCardState().isCardPresent()
                    && !TextUtils.isEmpty(uiccSlot.getIccId())) {
                ret.add(uiccSlot.getIccId());
            }
        }

        return ret;
    }

    @Override
    public List<SubscriptionInfo> getAccessibleSubscriptionInfoList(String callingPackage) {
        EuiccManager euiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE);
@@ -3371,6 +3394,23 @@ public class SubscriptionController extends ISub.Stub {
        return selection.toString();
    }

    /**
     * Helper function to create selection argument of a list of subId.
     * The result should be: "in (iccId1, iccId2, ...)".
     */
    private String getSelectionForIccIdList(String[] iccIds) {
        StringBuilder selection = new StringBuilder();
        selection.append(SubscriptionManager.ICC_ID);
        selection.append(" IN (");
        for (int i = 0; i < iccIds.length - 1; i++) {
            selection.append("\"" + iccIds[i] + "\", ");
        }
        selection.append("\"" + iccIds[iccIds.length - 1] + "\"");
        selection.append(")");

        return selection.toString();
    }

    /**
     * Get subscriptionInfo list of subscriptions that are in the same group of given subId.
     * See {@link #createSubscriptionGroup(int[], String)} for more details.
+39 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@ package com.android.internal.telephony;

import static android.telephony.TelephonyManager.SET_OPPORTUNISTIC_SUB_REMOTE_SERVICE_EXCEPTION;

import static com.android.internal.telephony.uicc.IccCardStatus.CardState.CARDSTATE_PRESENT;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -50,6 +52,7 @@ import android.test.suitebuilder.annotation.SmallTest;

import androidx.test.filters.FlakyTest;

import com.android.internal.telephony.uicc.IccCardStatus;
import com.android.internal.telephony.uicc.UiccController;
import com.android.internal.telephony.uicc.UiccSlot;

@@ -1136,4 +1139,40 @@ public class SubscriptionControllerTest extends TelephonyTest {
        assertFalse(mSubscriptionControllerUT.getActiveSubscriptionInfo(
                1, mContext.getOpPackageName(), null).areUiccApplicationsEnabled());
    }


    @Test
    @SmallTest
    public void testGetAvailableSubscriptionList() throws Exception {
        // TODO b/123300875 slot index 1 is not expected to be valid
        mSubscriptionControllerUT.addSubInfoRecord("123", 1);   // sub 1
        mSubscriptionControllerUT.addSubInfoRecord("456", 0);   // sub 2

        List<SubscriptionInfo> infoList = mSubscriptionControllerUT
                .getAvailableSubscriptionInfoList(mCallingPackage, mCallingFeature);
        assertEquals(2, infoList.size());
        assertEquals("456", infoList.get(0).getIccId());
        assertEquals("123", infoList.get(1).getIccId());

        // Remove "123" from active sim list but have it inserted.
        UiccSlot[] uiccSlots = {mUiccSlot};
        IccCardStatus.CardState cardState = CARDSTATE_PRESENT;
        doReturn(uiccSlots).when(mUiccController).getUiccSlots();
        doReturn(cardState).when(mUiccSlot).getCardState();
        doReturn("123").when(mUiccSlot).getIccId();
        mSubscriptionControllerUT.clearSubInfoRecord(1);

        // Active sub list should return 1 now.
        infoList = mSubscriptionControllerUT
                .getActiveSubscriptionInfoList(mCallingPackage, mCallingFeature);
        assertEquals(1, infoList.size());
        assertEquals("456", infoList.get(0).getIccId());

        // Available sub list should still return two.
        infoList = mSubscriptionControllerUT
                .getAvailableSubscriptionInfoList(mCallingPackage, mCallingFeature);
        assertEquals(2, infoList.size());
        assertEquals("123", infoList.get(0).getIccId());
        assertEquals("456", infoList.get(1).getIccId());
    }
}