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

Commit 0aa98389 authored by Jordan Liu's avatar Jordan Liu
Browse files

Distinguish between uninitialized and unsupported

UNINITIALIZED_CARD_ID is returned before the card ID is ready. On
HAL<1.2 we may also use UNSUPPORTED_CARD_ID once we verify that the card
ID will never be ready because its backing ID (EID in this case) is not
supported.

Bug: 122978614
Test: atest UiccControllerTest SubscriptionControllerTest
Change-Id: Ifb7b932a31c976a6b11e97a16494c043571f3540
parent d4376dc8
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -3335,7 +3335,8 @@ public class SubscriptionController extends ISub.Stub {
    private void deactivateSubscription(SubscriptionInfo info) {
        // TODO: b/120439488 deactivate pSIM.
        if (info.isEmbedded()) {
            EuiccManager euiccManager = new EuiccManager(mContext);
            EuiccManager euiccManager = (EuiccManager)
                    mContext.getSystemService(Context.EUICC_SERVICE);
            euiccManager.switchToSubscription(SubscriptionManager.INVALID_SUBSCRIPTION_ID,
                    PendingIntent.getService(mContext, 0, new Intent(), 0));
        }
+2 −4
Original line number Diff line number Diff line
@@ -676,9 +676,7 @@ public class EuiccConnector extends StateMachine implements ServiceConnection {
                final BaseEuiccCommandCallback callback = getCallback(message);
                onCommandStart(callback);
                final int cardId = message.arg1;
                // TODO(b/122978614) restore slotId from cardId once cardId is ready
                final int slotId = SubscriptionManager.INVALID_SIM_SLOT_INDEX;
                // final int slotId = getSlotIdFromCardId(cardId);
                final int slotId = getSlotIdFromCardId(cardId);
                try {
                    switch (message.what) {
                        case CMD_GET_EID: {
@@ -956,7 +954,7 @@ public class EuiccConnector extends StateMachine implements ServiceConnection {
     * Gets the slot ID from the card ID.
     */
    private int getSlotIdFromCardId(int cardId) {
        if (cardId == TelephonyManager.INVALID_CARD_ID) {
        if (cardId == TelephonyManager.UNSUPPORTED_CARD_ID) {
            return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
        }
        TelephonyManager tm = (TelephonyManager)
+30 −12
Original line number Diff line number Diff line
@@ -130,12 +130,12 @@ public class UiccController extends Handler {
    // considered sensetive information.
    private ArrayList<String> mCardStrings;

    // This is the card ID of the default eUICC. Whenever we receive slot status, we set it to the
    // eUICC with the lowest slot index
    // This is the card ID of the default eUICC. It starts as UNINITIALIZED_CARD_ID.
    // When we load the EID (either with slot status or from the EuiccCard), we set it to the eUICC
    // with the lowest slot index.
    // If EID is not supported (e.g. on HAL version < 1.2), we set it to UNSUPPORTED_CARD_ID
    private int mDefaultEuiccCardId;

    private static final int INVALID_CARD_ID = TelephonyManager.INVALID_CARD_ID;

    // GSM SGP.02 section 2.2.2 states that the EID is always 32 digits long
    private static final int EID_LENGTH = 32;

@@ -213,7 +213,7 @@ public class UiccController extends Handler {

        mLauncher = new UiccStateChangedLauncher(c, this);
        mCardStrings = loadCardStrings();
        mDefaultEuiccCardId = INVALID_CARD_ID;
        mDefaultEuiccCardId = TelephonyManager.UNINITIALIZED_CARD_ID;
    }

    private int getSlotIdFromPhoneId(int phoneId) {
@@ -552,6 +552,11 @@ public class UiccController extends Handler {
        if (slotId == INVALID_SLOT_ID) {
            slotId = index;
        }

        if (eidIsNotSupported(status)) {
            // we will never get EID from the HAL, so set mDefaultEuiccCardId to UNSUPPORTED_CARD_ID
            mDefaultEuiccCardId = TelephonyManager.UNSUPPORTED_CARD_ID;
        }
        mPhoneIdToSlotId[index] = slotId;

        if (VDBG) logPhoneIdToSlotIdMapping();
@@ -583,9 +588,12 @@ public class UiccController extends Handler {

        // EID may be unpopulated if RadioConfig<1.2
        // If so, just register for EID loaded and skip this stuff
        if (isEuicc && cardString == null) {
        if (isEuicc && cardString == null
                && mDefaultEuiccCardId != TelephonyManager.UNSUPPORTED_CARD_ID) {
            ((EuiccCard) card).registerForEidReady(this, EVENT_EID_READY, index);
        } else {
        }

        if (cardString != null) {
            addCardId(cardString);
        }

@@ -593,6 +601,15 @@ public class UiccController extends Handler {
        mIccChangedRegistrants.notifyRegistrants(new AsyncResult(null, index, null));
    }

    /**
     * Returns true if EID is not supproted.
     */
    private boolean eidIsNotSupported(IccCardStatus status) {
        // if card status does not contain slot ID, we know we are on HAL < 1.2, so EID will never
        // be available
        return status.physicalSlotIndex == INVALID_SLOT_ID;
    }

    /**
     * Add a cardString to mCardStrings. If this is an ICCID, trailing Fs will be automatically
     * stripped.
@@ -615,18 +632,19 @@ public class UiccController extends Handler {
     * If the given cardString is an ICCID, trailing Fs will be automatically stripped before trying
     * to match to a card ID.
     *
     * @return the matching cardId, or INVALID_CARD_ID if the card string does not map to a cardId
     * @return the matching cardId, or UNINITIALIZED_CARD_ID if the card string does not map to a
     * currently loaded cardId
     */
    public int convertToPublicCardId(String cardString) {
        if (TextUtils.isEmpty(cardString)) {
            return INVALID_CARD_ID;
            return TelephonyManager.UNINITIALIZED_CARD_ID;
        }
        if (cardString.length() < EID_LENGTH) {
            cardString = IccUtils.stripTrailingFs(cardString);
        }
        int id = mCardStrings.indexOf(cardString);
        if (id == -1) {
            return INVALID_CARD_ID;
            return TelephonyManager.UNINITIALIZED_CARD_ID;
        } else {
            return id;
        }
@@ -646,7 +664,7 @@ public class UiccController extends Handler {
                continue;
            }
            String iccid = card.getIccId();
            int cardId = INVALID_CARD_ID;
            int cardId;
            if (isEuicc) {
                eid = card.getCardId();
                cardId = convertToPublicCardId(eid);
@@ -895,7 +913,7 @@ public class UiccController extends Handler {
        // set mCardStrings and the defaultEuiccCardId using the now available EID
        String eid = ((EuiccCard) card).getEid();
        addCardId(eid);
        if (mDefaultEuiccCardId == INVALID_CARD_ID) {
        if (mDefaultEuiccCardId == TelephonyManager.UNINITIALIZED_CARD_ID) {
            // TODO(b/122738148) the default eUICC should not be removable
            mDefaultEuiccCardId = convertToPublicCardId(eid);
            log("onEidReady: eid=" + eid + " slot=" + slotId + " mDefaultEuiccCardId="
+38 −12
Original line number Diff line number Diff line
@@ -246,14 +246,14 @@ public class UiccControllerTest extends TelephonyTest {
    @Test
    public void testConvertNullCardId() {
        // trying to convert a null string should return -1
        assertEquals(TelephonyManager.INVALID_CARD_ID,
        assertEquals(TelephonyManager.UNINITIALIZED_CARD_ID,
                mUiccControllerUT.convertToPublicCardId(null));
    }

    @Test
    public void testConvertEmptyCardId() {
        // trying to convert an empty string should return -1
        assertEquals(TelephonyManager.INVALID_CARD_ID,
        assertEquals(TelephonyManager.UNINITIALIZED_CARD_ID,
                mUiccControllerUT.convertToPublicCardId(""));
    }

@@ -292,7 +292,7 @@ public class UiccControllerTest extends TelephonyTest {
        // simulate slot status loaded so that the UiccController sets the card ID
        IccSlotStatus iss = new IccSlotStatus();
        iss.setSlotState(1 /* active */);
        iss.eid = "ABADACB";
        iss.eid = "AB123456";
        ArrayList<IccSlotStatus> status = new ArrayList<IccSlotStatus>();
        status.add(iss);
        AsyncResult ar = new AsyncResult(null, status, null);
@@ -311,12 +311,11 @@ public class UiccControllerTest extends TelephonyTest {

        // Mock out UiccSlots
        mUiccControllerUT.mUiccSlots[0] = mMockSlot;
        doReturn(true).when(mMockSlot).isEuicc();
        doReturn(mMockEuiccCard).when(mMockSlot).getUiccCard();
        doReturn("A1B2C3D4").when(mMockEuiccCard).getCardId();
        doReturn("A1B2C3D4").when(mMockEuiccCard).getEid();
        doReturn("123451234567890").when(mMockEuiccCard).getIccId();
        doReturn(IccCardStatus.CardState.CARDSTATE_PRESENT).when(mMockEuiccCard).getCardState();
        doReturn(false).when(mMockSlot).isEuicc();
        doReturn(mMockCard).when(mMockSlot).getUiccCard();
        doReturn("ASDF1234").when(mMockCard).getCardId();
        doReturn("123451234567890").when(mMockCard).getIccId();
        doReturn(IccCardStatus.CardState.CARDSTATE_PRESENT).when(mMockCard).getCardState();

        // simulate card status loaded so that the UiccController sets the card ID
        IccCardStatus ics = new IccCardStatus();
@@ -324,16 +323,15 @@ public class UiccControllerTest extends TelephonyTest {
        ics.setUniversalPinState(3 /* disabled */);
        ics.atr = "abcdef0123456789abcdef";
        ics.iccid = "123451234567890";
        ics.eid = "A1B2C3D4";
        AsyncResult ar = new AsyncResult(null, ics, null);
        Message msg = Message.obtain(mUiccControllerUT, EVENT_GET_ICC_STATUS_DONE, ar);
        mUiccControllerUT.handleMessage(msg);

        // assert that the default cardId is the slot with the lowest slot index, even if inactive
        UiccCardInfo uiccCardInfo = new UiccCardInfo(
                true,      // isEuicc
                false,     // isEuicc
                0,         // cardId
                ics.eid,   // eid
                null,      // eid
                ics.iccid, // iccid is unknown
                0);        // slotIndex
        assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0));
@@ -363,4 +361,32 @@ public class UiccControllerTest extends TelephonyTest {
        // assert that the getAllUiccCardInfos returns an empty list without crashing
        assertEquals(0, mUiccControllerUT.getAllUiccCardInfos().size());
    }

    @Test
    public void testEidNotSupported() {
        // Give UiccController a real context so it can use shared preferences
        mUiccControllerUT.mContext = InstrumentationRegistry.getContext();

        // Mock out UiccSlots
        mUiccControllerUT.mUiccSlots[0] = mMockSlot;
        doReturn(true).when(mMockSlot).isEuicc();
        doReturn(mMockEuiccCard).when(mMockSlot).getUiccCard();
        doReturn(null).when(mMockEuiccCard).getEid();

        // simulate card status loaded so that the UiccController sets the card ID
        IccCardStatus ics = new IccCardStatus();
        ics.setCardState(1 /* present */);
        ics.setUniversalPinState(3 /* disabled */);
        ics.atr = "abcdef0123456789abcdef";
        ics.iccid = "123451234567890";
        // make it seem like EID is not supported by setting physical slot = -1 like on HAL < 1.2
        ics.physicalSlotIndex = UiccController.INVALID_SLOT_ID;
        AsyncResult ar = new AsyncResult(null, ics, null);
        Message msg = Message.obtain(mUiccControllerUT, EVENT_GET_ICC_STATUS_DONE, ar);
        mUiccControllerUT.handleMessage(msg);

        // assert that the default eUICC card Id is UNSUPPORTED_CARD_ID
        assertEquals(TelephonyManager.UNSUPPORTED_CARD_ID,
                mUiccControllerUT.getCardIdForDefaultEuicc());
    }
}