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

Commit 3de0fada authored by Holly Jiuyu Sun's avatar Holly Jiuyu Sun
Browse files

Let canManageActiveSubscriptionOnTargetSim pass if cardId=-1.

If the passed in cardId is -1 (UNSUPPORTED_CARD_ID), we assume it does
not support multiple eSIMs. Let
canManageActiveSubscriptionOnTargetSim() pass if the cardId is
unsupported.

Bug: 124337485
Test: test on walleye and Tycho activation works
Change-Id: I05610080dc9e3317622c91d1ad517f78aea21a26
parent d4ddbe3d
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -1178,7 +1178,12 @@ public class EuiccController extends IEuiccController.Stub {
            return false;
        }
        for (SubscriptionInfo subInfo : subInfoList) {
            if (subInfo.getCardId() == cardId && subInfo.isEmbedded()
            // If cardId == TelephonyManager.UNSUPPORTED_CARD_ID, we assume it does not support
            // multiple eSIMs. There are older multi-active SIM devices which do not implement HAL
            // 1.2 and if they have multiple eSIMs, we let it pass if the app can manage an active
            // subscription on any eSIM. That's the best we can do here.
            if ((cardId == TelephonyManager.UNSUPPORTED_CARD_ID || subInfo.getCardId() == cardId)
                    && subInfo.isEmbedded()
                    && mSubscriptionManager.canManageSubscription(subInfo, callingPackage)) {
                return true;
            }
@@ -1199,6 +1204,10 @@ public class EuiccController extends IEuiccController.Stub {
        if (subInfoList == null || subInfoList.size() == 0) {
            return false;
        }
        // If it's a multi-active SIM device, we assume it's above HAL 1.2 which supports cardId.
        // There are older multi-active SIM devices but don't implement HAL 1.2. In this case,
        // platform can't even detect UiccCardInfo#isEuicc as true for eSIM, which won't let the
        // below check pass. That's the best we can do here.
        if (supportMultiActiveSlots()) {
            // The target card should be an eUICC.
            List<UiccCardInfo> cardInfos = mTelephonyManager.getUiccCardsInfo();
+15 −7
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.service.euicc.GetDefaultDownloadableSubscriptionListResult;
import android.service.euicc.GetDownloadableSubscriptionMetadataResult;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.UiccAccessRule;
import android.telephony.UiccCardInfo;
import android.telephony.euicc.DownloadableSubscription;
@@ -197,31 +198,38 @@ public class EuiccControllerTest extends TelephonyTest {
    @Test(expected = SecurityException.class)
    public void testGetEid_noPrivileges() throws Exception {
        setGetEidPermissions(false /* hasPhoneStatePrivileged */, false /* hasCarrierPrivileges */);
        callGetEid(true /* success */, "ABCDE" /* eid */);
        callGetEid(true /* success */, "ABCDE" /* eid */, CARD_ID);
    }

    @Test
    public void testGetEid_withPhoneStatePrivileged() throws Exception {
        setGetEidPermissions(true /* hasPhoneStatePrivileged */, false /* hasCarrierPrivileges */);
        assertEquals("ABCDE", callGetEid(true /* success */, "ABCDE" /* eid */));
        assertEquals("ABCDE", callGetEid(true /* success */, "ABCDE" /* eid */, CARD_ID));
    }

    @Test
    public void testGetEid_withCarrierPrivileges() throws Exception {
        setGetEidPermissions(false /* hasPhoneStatePrivileged */, true /* hasCarrierPrivileges */);
        assertEquals("ABCDE", callGetEid(true /* success */, "ABCDE" /* eid */));
        assertEquals("ABCDE", callGetEid(true /* success */, "ABCDE" /* eid */, CARD_ID));
    }

    @Test
    public void testGetEid_failure() throws Exception {
        setGetEidPermissions(true /* hasPhoneStatePrivileged */, false /* hasCarrierPrivileges */);
        assertNull(callGetEid(false /* success */, null /* eid */));
        assertNull(callGetEid(false /* success */, null /* eid */, CARD_ID));
    }

    @Test
    public void testGetEid_nullReturnValue() throws Exception {
        setGetEidPermissions(true /* hasPhoneStatePrivileged */, false /* hasCarrierPrivileges */);
        assertNull(callGetEid(true /* success */, null /* eid */));
        assertNull(callGetEid(true /* success */, null /* eid */, CARD_ID));
    }

    @Test
    public void testGetEid_unsupportedCardId() throws Exception {
        setGetEidPermissions(false /* hasPhoneStatePrivileged */, true /* hasCarrierPrivileges */);
        assertEquals("ABCDE", callGetEid(true /* success */, "ABCDE" /* eid */,
                TelephonyManager.UNSUPPORTED_CARD_ID));
    }

    @Test(expected = SecurityException.class)
@@ -1017,7 +1025,7 @@ public class EuiccControllerTest extends TelephonyTest {
                Collections.singletonList(subInfo));
    }

    private String callGetEid(final boolean success, final @Nullable String eid) {
    private String callGetEid(final boolean success, final @Nullable String eid, int cardId) {
        doAnswer(new Answer<Void>() {
            @Override
            public Void answer(InvocationOnMock invocation) throws Exception {
@@ -1032,7 +1040,7 @@ public class EuiccControllerTest extends TelephonyTest {
            }
        }).when(mMockConnector).getEid(anyInt(),
                Mockito.<EuiccConnector.GetEidCommandCallback>any());
        return mController.getEid(CARD_ID, PACKAGE_NAME);
        return mController.getEid(cardId, PACKAGE_NAME);
    }

    private int callGetOtaStatus(final boolean success, final int status) {