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

Commit e4d4fe8f authored by Chen Xu's avatar Chen Xu
Browse files

Do not resolve port index for apps which are not target on T

Bug: 224562872
Test: Manual
Change-Id: I8547ab2f0a5a65cc40c1a3752902ce33ea115852
parent b75ebf5e
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -555,13 +555,19 @@ public class EuiccController extends IEuiccController.Stub {
            Bundle resolvedBundle, PendingIntent callbackIntent) {
        boolean callerCanWriteEmbeddedSubscriptions = callerCanWriteEmbeddedSubscriptions();
        mAppOpsManager.checkPackage(Binder.getCallingUid(), callingPackage);
        // Don't try to resolve the port index for apps which are not targeting on T for backward
        // compatibility. instead always use default port 0.
        boolean shouldResolvePortIndex = isCompatChangeEnabled(callingPackage,
                EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS);

        long token = Binder.clearCallingIdentity();
        try {
            boolean isConsentNeededToResolvePortIndex = false;
            if (switchAfterDownload && portIndex == TelephonyManager.INVALID_PORT_INDEX) {
                // If switchAfterDownload is true, resolve the portIndex
                portIndex = getResolvedPortIndexForSubscriptionSwitch(cardId);
                portIndex = shouldResolvePortIndex ?
                        getResolvedPortIndexForSubscriptionSwitch(cardId)
                        : TelephonyManager.DEFAULT_PORT_INDEX;
                isConsentNeededToResolvePortIndex = (portIndex
                        == TelephonyManager.INVALID_PORT_INDEX);
            }
@@ -569,7 +575,8 @@ public class EuiccController extends IEuiccController.Stub {
                    + switchAfterDownload + " portIndex: " + portIndex
                    + " forceDeactivateSim: " + forceDeactivateSim + " callingPackage: "
                    + callingPackage
                    + " isConsentNeededToResolvePortIndex: " + isConsentNeededToResolvePortIndex);
                    + " isConsentNeededToResolvePortIndex: " + isConsentNeededToResolvePortIndex
                    + " shouldResolvePortIndex:" + shouldResolvePortIndex);
            if (!isConsentNeededToResolvePortIndex && callerCanWriteEmbeddedSubscriptions) {
                // With WRITE_EMBEDDED_SUBSCRIPTIONS, we can skip profile-specific permission checks
                // and move straight to the profile download.
@@ -1023,9 +1030,14 @@ public class EuiccController extends IEuiccController.Stub {
            boolean usePortIndex) {
        boolean callerCanWriteEmbeddedSubscriptions = callerCanWriteEmbeddedSubscriptions();
        mAppOpsManager.checkPackage(Binder.getCallingUid(), callingPackage);
        // Resolve the portIndex internally if apps targeting T and beyond are calling
        // switchToSubscription API without portIndex.
        boolean shouldResolvePortIndex = isCompatChangeEnabled(callingPackage,
                EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS);
        Log.d(TAG, " subId: " + subscriptionId + " portIndex: " + portIndex
                + " forceDeactivateSim: " + forceDeactivateSim + " usePortIndex: " + usePortIndex
                + " callingPackage: " + callingPackage);
                + " callingPackage: " + callingPackage + " shouldResolvePortIndex: "
                + shouldResolvePortIndex);
        long token = Binder.clearCallingIdentity();
        try {
            if (callerCanWriteEmbeddedSubscriptions) {
@@ -1096,9 +1108,11 @@ public class EuiccController extends IEuiccController.Stub {
                        return;
                    }
                } else {
                    // Resolve the portIndex internally if apps are calling switchToSubscription
                    // API without portIndex.
                    portIndex = getResolvedPortIndexForSubscriptionSwitch(cardId);
                    // Resolve the portIndex internally if apps targeting T and beyond are calling
                    // switchToSubscription API without portIndex.
                    portIndex = shouldResolvePortIndex ?
                            getResolvedPortIndexForSubscriptionSwitch(cardId)
                            : TelephonyManager.DEFAULT_PORT_INDEX;
                    isConsentNeededToResolvePortIndex = (portIndex
                            == TelephonyManager.INVALID_PORT_INDEX);
                    usePortIndex = true;
+32 −0
Original line number Diff line number Diff line
@@ -415,6 +415,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_serviceUnavailable() throws Exception {
        setHasWriteEmbeddedPermission(true);
        setUpUiccSlotData();
@@ -428,6 +429,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_error() throws Exception {
        setHasWriteEmbeddedPermission(true);
        callDownloadSubscription(SUBSCRIPTION, false /* switchAfterDownload */, true /* complete */,
@@ -437,6 +439,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_mustDeactivateSim() throws Exception {
        setHasWriteEmbeddedPermission(true);
        callDownloadSubscription(SUBSCRIPTION, false /* switchAfterDownload */, true /* complete */,
@@ -449,6 +452,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_needConfirmationCode() throws Exception {
        setHasWriteEmbeddedPermission(true);
        callDownloadSubscription(SUBSCRIPTION, false /* switchAfterDownload */, true /* complete */,
@@ -461,6 +465,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_success() throws Exception {
        setHasWriteEmbeddedPermission(true);
        setUpUiccSlotData();
@@ -472,6 +477,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_noSwitch_success() throws Exception {
        setHasWriteEmbeddedPermission(true);
        callDownloadSubscription(SUBSCRIPTION, false /* switchAfterDownload */, true /* complete */,
@@ -481,6 +487,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_noPrivileges_getMetadata_serviceUnavailable()
            throws Exception {
        setHasWriteEmbeddedPermission(false);
@@ -495,6 +502,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_noPrivileges_getMetadata_serviceUnavailable_canManageSim()
            throws Exception {
        setHasWriteEmbeddedPermission(false);
@@ -510,6 +518,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_noPrivileges_getMetadata_error()
            throws Exception {
        setHasWriteEmbeddedPermission(false);
@@ -526,6 +535,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_noPrivileges_getMetadata_error_canManageSim()
            throws Exception {
        setHasWriteEmbeddedPermission(false);
@@ -543,6 +553,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_noPrivileges_getMetadata_mustDeactivateSim()
            throws Exception {
        setHasWriteEmbeddedPermission(false);
@@ -562,6 +573,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_noPrivileges_getMetadata_mustDeactivateSim_canManageSim()
            throws Exception {
        setHasWriteEmbeddedPermission(false);
@@ -582,6 +594,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_noPrivileges_hasCarrierPrivileges() throws Exception {
        setHasWriteEmbeddedPermission(false);
        setUpUiccSlotData();
@@ -599,6 +612,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_noPrivileges_hasCarrierPrivileges_multiSim()
            throws Exception {
        setHasWriteEmbeddedPermission(false);
@@ -617,6 +631,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_noPrivileges_hasCarrierPrivileges_needsConsent()
            throws Exception {
        setHasWriteEmbeddedPermission(false);
@@ -638,6 +653,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_noPrivileges_hasCarrierPrivileges_needsConsent_multiSim()
            throws Exception {
        setHasWriteEmbeddedPermission(false);
@@ -659,6 +675,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_noPriv_hasCarrierPrivi_needsConsent_multiSim_targetPsim()
            throws Exception {
        setHasWriteEmbeddedPermission(false);
@@ -680,6 +697,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_noPrivileges_noCarrierPrivileges() throws Exception {
        setHasWriteEmbeddedPermission(false);
        setUpUiccSlotData();
@@ -701,6 +719,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testDownloadSubscription_noPrivileges_noCarrierPrivileges_canManagerTargetSim()
            throws Exception {
        setHasWriteEmbeddedPermission(false);
@@ -790,6 +809,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testSwitchToSubscription_noSuchSubscription() throws Exception {
        setHasWriteEmbeddedPermission(true);
        callSwitchToSubscription(
@@ -802,6 +822,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testSwitchToSubscription_emptySubscription_noPrivileges() throws Exception {
        setHasWriteEmbeddedPermission(false);
        callSwitchToSubscription(
@@ -814,6 +835,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testSwitchToSubscription_serviceUnavailable() throws Exception {
        setHasWriteEmbeddedPermission(true);
        prepareOperationSubscription(false /* hasPrivileges */);
@@ -828,6 +850,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testSwitchToSubscription_error() throws Exception {
        setHasWriteEmbeddedPermission(true);
        prepareOperationSubscription(false /* hasPrivileges */);
@@ -840,6 +863,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testSwitchToSubscription_success() throws Exception {
        setHasWriteEmbeddedPermission(true);
        prepareOperationSubscription(false /* hasPrivileges */);
@@ -851,6 +875,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testSwitchToSubscription_emptySubscription_noActiveSubscription() throws Exception {
        setHasWriteEmbeddedPermission(true);
        callSwitchToSubscription(
@@ -863,6 +888,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testSwitchToSubscription_emptySubscription_success() throws Exception {
        setHasWriteEmbeddedPermission(true);
        setHasCarrierPrivilegesOnActiveSubscription(false);
@@ -873,6 +899,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testSwitchToSubscription_noPrivileges() throws Exception {
        setHasWriteEmbeddedPermission(false);
        prepareOperationSubscription(false /* hasPrivileges */);
@@ -886,6 +913,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testSwitchToSubscription_hasCarrierPrivileges() throws Exception {
        setHasWriteEmbeddedPermission(false);
        prepareOperationSubscription(true /* hasPrivileges */);
@@ -898,6 +926,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testSwitchToSubscription_hasCarrierPrivileges_multiSim() throws Exception {
        setHasWriteEmbeddedPermission(false);
        prepareOperationSubscription(true /* hasPrivileges */);
@@ -910,6 +939,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testSwitchToSubscription_hasCarrierPrivileges_needsConsent() throws Exception {
        setHasWriteEmbeddedPermission(false);
        prepareOperationSubscription(true /* hasPrivileges */);
@@ -927,6 +957,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testSwitchToSubscription_hasCarrierPrivileges_needsConsent_multiSim()
            throws Exception {
        setHasWriteEmbeddedPermission(false);
@@ -945,6 +976,7 @@ public class EuiccControllerTest extends TelephonyTest {
    }

    @Test
    @DisableCompatChanges({EuiccManager.SHOULD_RESOLVE_PORT_INDEX_FOR_APPS})
    public void testSwitchToSubscription_hasCarrierPrivileges_needsConsent_multiSim_targetPsim()
            throws Exception {
        setHasWriteEmbeddedPermission(false);