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

Commit fc0b8566 authored by Jack Yu's avatar Jack Yu
Browse files

Fixed eSIM subscription disappeared

Fixed an issue that after eSIM profile update failed,
the original eSIM subscription got marked as non-embedded
so it disappeared from settings.

Fix: 276707965
Test: atest SubscriptionManagerServiceTest
Test: Basic phone functionality tests
Change-Id: I77dfddf70022e4337298c6fe183879c0150b9f57
parent 83a0e702
Loading
Loading
Loading
Loading
+37 −26
Original line number Diff line number Diff line
@@ -1050,6 +1050,9 @@ public class SubscriptionManagerService extends ISub.Stub {
                }
            }

            // The flag indicating getting successful result from EuiccController.
            boolean isProfileUpdateSuccessful = false;

            for (int cardId : cardIds) {
                GetEuiccProfileInfoListResult result = mEuiccController
                        .blockingGetEuiccProfileInfoList(cardId);
@@ -1066,6 +1069,8 @@ public class SubscriptionManagerService extends ISub.Stub {
                    continue;
                }

                isProfileUpdateSuccessful = true;

                if (result.getProfiles() == null || result.getProfiles().isEmpty()) {
                    loge("No profiles returned.");
                    continue;
@@ -1137,11 +1142,14 @@ public class SubscriptionManagerService extends ISub.Stub {
                }
            }

            // Marked the previous embedded subscriptions non-embedded if the latest profiles do
            // not include them anymore.
            if (isProfileUpdateSuccessful) {
                // embeddedSubs contains all the existing embedded subs queried from EuiccManager,
            // including active or inactive. If there are any embedded subscription in the database
            // that is not in embeddedSubs, mark them as non-embedded. These were deleted embedded
            // subscriptions, so we treated them as non-embedded (pre-U behavior) and they don't
            // show up in Settings SIM page.
                // including active or inactive. If there are any embedded subscription in the
                // database that is not in embeddedSubs, mark them as non-embedded. These were
                // deleted embedded subscriptions, so we treated them as non-embedded (pre-U
                // behavior) and they don't show up in Settings SIM page.
                mSubscriptionDatabaseManager.getAllSubscriptions().stream()
                        .filter(SubscriptionInfoInternal::isEmbedded)
                        .filter(subInfo -> !embeddedSubs.contains(subInfo.getSubscriptionId()))
@@ -1164,6 +1172,9 @@ public class SubscriptionManagerService extends ISub.Stub {
                            "SubscriptionManagerService: Found Invalid portIndex"
                                    + " in active subscriptions");
                }
            } else {
                loge("The eSIM profiles update was not successful.");
            }
        });
        log("updateEmbeddedSubscriptions: Finished embedded subscription update.");
        if (callback != null) {
+44 −4
Original line number Diff line number Diff line
@@ -183,6 +183,8 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        doReturn(FAKE_ICCID1).when(mUiccCard).getCardId();
        doReturn(FAKE_ICCID1).when(mUiccPort).getIccId();
        doReturn(true).when(mUiccSlot).isActive();
        doReturn(FAKE_ICCID1).when(mUiccController).convertToCardString(eq(1));
        doReturn(FAKE_ICCID2).when(mUiccController).convertToCardString(eq(2));

        doReturn(new int[0]).when(mSubscriptionManager).getCompleteActiveSubscriptionIdList();

@@ -799,8 +801,6 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        result = new GetEuiccProfileInfoListResult(EuiccService.RESULT_OK,
                new EuiccProfileInfo[]{profileInfo2}, false);
        doReturn(result).when(mEuiccController).blockingGetEuiccProfileInfoList(eq(2));
        doReturn(FAKE_ICCID1).when(mUiccController).convertToCardString(eq(1));
        doReturn(FAKE_ICCID2).when(mUiccController).convertToCardString(eq(2));
        doReturn(TelephonyManager.INVALID_PORT_INDEX).when(mUiccSlot)
                .getPortIndexFromIccId(anyString());

@@ -1810,7 +1810,6 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        GetEuiccProfileInfoListResult result = new GetEuiccProfileInfoListResult(
                EuiccService.RESULT_OK, new EuiccProfileInfo[]{profileInfo1}, false);
        doReturn(result).when(mEuiccController).blockingGetEuiccProfileInfoList(eq(1));
        doReturn(FAKE_ICCID1).when(mUiccController).convertToCardString(eq(1));

        mContext.sendBroadcast(new Intent(Intent.ACTION_USER_UNLOCKED));
        processAllMessages();
@@ -1937,7 +1936,6 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        GetEuiccProfileInfoListResult result = new GetEuiccProfileInfoListResult(
                EuiccService.RESULT_OK, new EuiccProfileInfo[]{profileInfo1}, false);
        doReturn(result).when(mEuiccController).blockingGetEuiccProfileInfoList(eq(1));
        doReturn(FAKE_ICCID1).when(mUiccController).convertToCardString(eq(1));

        mSubscriptionManagerServiceUT.updateEmbeddedSubscriptions(List.of(1), null);
        processAllMessages();
@@ -2246,4 +2244,46 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        assertThat(mSubscriptionManagerServiceUT.getAvailableSubscriptionInfoList(
                CALLING_PACKAGE, CALLING_FEATURE)).isEmpty();
    }

    @Test
    public void testEmbeddedProfilesUpdateFailed() {
        insertSubscription(FAKE_SUBSCRIPTION_INFO1);

        GetEuiccProfileInfoListResult result = new GetEuiccProfileInfoListResult(
                EuiccService.RESULT_MUST_DEACTIVATE_SIM, null, false);
        doReturn(result).when(mEuiccController).blockingGetEuiccProfileInfoList(eq(1));

        mSubscriptionManagerServiceUT.updateEmbeddedSubscriptions(List.of(1), null);
        processAllMessages();

        // The existing subscription should not be altered if the previous update failed.
        assertThat(mSubscriptionManagerServiceUT.getSubscriptionInfoInternal(1))
                .isEqualTo(FAKE_SUBSCRIPTION_INFO1);

        EuiccProfileInfo profileInfo = new EuiccProfileInfo.Builder(FAKE_ICCID2)
                .setIccid(FAKE_ICCID2)
                .setNickname(FAKE_CARRIER_NAME2)
                .setProfileClass(SubscriptionManager.PROFILE_CLASS_OPERATIONAL)
                .setCarrierIdentifier(new CarrierIdentifier(FAKE_MCC2, FAKE_MNC2, null, null, null,
                        null, FAKE_CARRIER_ID2, FAKE_CARRIER_ID2))
                .setUiccAccessRule(Arrays.asList(UiccAccessRule.decodeRules(
                        FAKE_NATIVE_ACCESS_RULES2)))
                .build();
        result = new GetEuiccProfileInfoListResult(EuiccService.RESULT_OK,
                new EuiccProfileInfo[]{profileInfo}, false);
        doReturn(result).when(mEuiccController).blockingGetEuiccProfileInfoList(eq(1));

        // Update for the 2nd time.
        mSubscriptionManagerServiceUT.updateEmbeddedSubscriptions(List.of(1), null);
        processAllMessages();

        // The previous subscription should be marked as non-embedded.
        assertThat(mSubscriptionManagerServiceUT.getSubscriptionInfo(1).isEmbedded())
                .isEqualTo(false);

        assertThat(mSubscriptionManagerServiceUT.getSubscriptionInfo(2).getIccId())
                .isEqualTo(FAKE_ICCID2);
        assertThat(mSubscriptionManagerServiceUT.getSubscriptionInfo(2).isEmbedded())
                .isEqualTo(true);
    }
}