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

Commit 7b8ddf72 authored by Jordan Liu's avatar Jordan Liu
Browse files

Add EuiccCard.isRemovable

Also add the resource non_removable_euicc_slots, an int-array of the
slot indexes which we know contain non-removable embedded eUICC chips.

Bug: 122738148
Test: EuiccCardTest, UiccControllerTest, UiccSlotTest
Change-Id: If9c0e2d72866e683034a06f8401d1d98daf1a84e
parent 455b1672
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -569,7 +569,7 @@ public class UiccController extends Handler {
            mUiccSlots[slotId] = new UiccSlot(mContext, true);
        }

        mUiccSlots[slotId].update(mCis[index], status, index);
        mUiccSlots[slotId].update(mCis[index], status, index, slotId);

        UiccCard card = mUiccSlots[slotId].getUiccCard();
        if (card == null) {
@@ -665,6 +665,7 @@ public class UiccController extends Handler {
            }
            String iccid = card.getIccId();
            int cardId;
            boolean isRemovable = slot.isRemovable();
            if (isEuicc) {
                eid = card.getCardId();
                cardId = convertToPublicCardId(eid);
@@ -672,7 +673,8 @@ public class UiccController extends Handler {
                // leave eid null if the UICC is not embedded
                cardId = convertToPublicCardId(iccid);
            }
            UiccCardInfo info = new UiccCardInfo(isEuicc, cardId, eid, iccid, slotIndex);
            UiccCardInfo info = new UiccCardInfo(isEuicc, cardId, eid, iccid, slotIndex,
                    isRemovable);
            infos.add(info);
        }
        return infos;
@@ -763,9 +765,10 @@ public class UiccController extends Handler {
            }

            if (!isValidPhoneIndex(iss.logicalSlotIndex)) {
                mUiccSlots[i].update(null, iss);
                mUiccSlots[i].update(null, iss, i /* slotIndex */);
            } else {
                mUiccSlots[i].update(isActive ? mCis[iss.logicalSlotIndex] : null, iss);
                mUiccSlots[i].update(isActive ? mCis[iss.logicalSlotIndex] : null, iss,
                        i /* slotIndex */);
            }

            if (mUiccSlots[i].isEuicc()) {
+25 −2
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ public class UiccSlot extends Handler {
    private String mIccId;
    private AnswerToReset mAtr;
    private int mPhoneId = INVALID_PHONE_ID;
    private boolean mIsRemovable;

    private static final int EVENT_CARD_REMOVED = 13;
    private static final int EVENT_CARD_ADDED = 14;
@@ -77,7 +78,7 @@ public class UiccSlot extends Handler {
    /**
     * Update slot. The main trigger for this is a change in the ICC Card status.
     */
    public void update(CommandsInterface ci, IccCardStatus ics, int phoneId) {
    public void update(CommandsInterface ci, IccCardStatus ics, int phoneId, int slotIndex) {
        if (DBG) log("cardStatus update: " + ics.toString());
        synchronized (mLock) {
            CardState oldState = mCardState;
@@ -86,6 +87,7 @@ public class UiccSlot extends Handler {
            mPhoneId = phoneId;
            parseAtr(ics.atr);
            mCi = ci;
            mIsRemovable = isSlotRemovable(slotIndex);

            int radioState = mCi.getRadioState();
            if (DBG) {
@@ -135,7 +137,7 @@ public class UiccSlot extends Handler {
    /**
     * Update slot based on IccSlotStatus.
     */
    public void update(CommandsInterface ci, IccSlotStatus iss) {
    public void update(CommandsInterface ci, IccSlotStatus iss, int slotIndex) {
        if (DBG) log("slotStatus update: " + iss.toString());
        synchronized (mLock) {
            CardState oldState = mCardState;
@@ -143,6 +145,7 @@ public class UiccSlot extends Handler {
            parseAtr(iss.atr);
            mCardState = iss.cardState;
            mIccId = iss.iccid;
            mIsRemovable = isSlotRemovable(slotIndex);
            if (iss.slotState == IccSlotStatus.SlotState.SLOTSTATE_INACTIVE) {
                // TODO: (b/79432584) evaluate whether should broadcast card state change
                // even if it's inactive.
@@ -211,6 +214,22 @@ public class UiccSlot extends Handler {
        return mUiccCard == null;
    }

    // Return true if a slot index is for removable UICCs or eUICCs
    private boolean isSlotRemovable(int slotIndex) {
        int[] euiccSlots = mContext.getResources()
                .getIntArray(com.android.internal.R.array.non_removable_euicc_slots);
        if (euiccSlots == null) {
            return true;
        }
        for (int euiccSlot : euiccSlots) {
            if (euiccSlot == slotIndex) {
                return false;
            }
        }

        return true;
    }

    private void checkIsEuiccSupported() {
        if (mAtr != null && mAtr.isEuiccSupported()) {
            mIsEuicc = true;
@@ -236,6 +255,10 @@ public class UiccSlot extends Handler {
        return mPhoneId;
    }

    public boolean isRemovable() {
        return mIsRemovable;
    }

    public String getIccId() {
        if (mIccId != null) {
            return mIccId;
+1 −1
Original line number Diff line number Diff line
@@ -779,7 +779,7 @@ public class SubscriptionControllerTest extends TelephonyTest {
    public void testEnableDisableSubscriptionSingleSim() throws Exception {
        testInsertSim();
        // UiccSlotInfo that maps logicalSlotIndex 0 to physicalSlotIndex 0.
        UiccSlotInfo slotInfo = new UiccSlotInfo(true, false, "", 0, 0, false);
        UiccSlotInfo slotInfo = new UiccSlotInfo(true, false, "", 0, 0, false, false);
        UiccSlotInfo[] slotInfos = new UiccSlotInfo[] {slotInfo};
        doReturn(slotInfos).when(mTelephonyManager).getUiccSlotsInfo();

+3 −2
Original line number Diff line number Diff line
@@ -990,9 +990,10 @@ public class EuiccControllerTest extends TelephonyTest {

    private void setCanManageSubscriptionOnTargetSim(boolean isTargetEuicc, boolean hasPrivileges)
            throws Exception {
        UiccCardInfo cardInfo1 = new UiccCardInfo(isTargetEuicc, CARD_ID, "", "", 0);
        UiccCardInfo cardInfo1 = new UiccCardInfo(isTargetEuicc, CARD_ID, "", "", 0,
                false /* isRemovable */);
        UiccCardInfo cardInfo2 = new UiccCardInfo(true /* isEuicc */, 1 /* cardId */,
                "", "", 0);
                "", "", 0, false /* isRemovable */);
        ArrayList<UiccCardInfo> cardInfos = new ArrayList<>();
        cardInfos.add(cardInfo1);
        cardInfos.add(cardInfo2);
+4 −1
Original line number Diff line number Diff line
@@ -314,6 +314,8 @@ public class UiccControllerTest extends TelephonyTest {
        doReturn(false).when(mMockSlot).isEuicc();
        doReturn(mMockCard).when(mMockSlot).getUiccCard();
        doReturn("ASDF1234").when(mMockCard).getCardId();
        doReturn(true).when(mMockSlot).isRemovable();
        doReturn("A1B2C3D4").when(mMockCard).getCardId();
        doReturn("123451234567890").when(mMockCard).getIccId();
        doReturn(IccCardStatus.CardState.CARDSTATE_PRESENT).when(mMockCard).getCardState();

@@ -333,7 +335,8 @@ public class UiccControllerTest extends TelephonyTest {
                0,         // cardId
                null,      // eid
                ics.iccid, // iccid is unknown
                0);        // slotIndex
                0,         // slotIndex
                true);     // isRemovable
        assertEquals(uiccCardInfo, mUiccControllerUT.getAllUiccCardInfos().get(0));
    }

Loading