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

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

Fixed eSIM deletion issue

Fixed tje issue that eSIM cannot be deleted from settings. The
problem is that the deleted eSIM looks like inactive eSIM in the
database. Fixed by marking the removed eSIM as removed pSIM, which
is the pre-U behavior.

Fix: 269229150
Test: Boot up + basic phone functionality
Test: atest SubscriptionManagerServiceTest
Test: Manually deleted eSIM from Settings page and saw it removed.
Change-Id: Ib40aa8294dd10433b6a68b4f793d8c00ab66d9c0
parent 88f6ed6b
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -1027,6 +1027,7 @@ public class SubscriptionManagerService extends ISub.Stub {
                return;
            }

            Set<Integer> embeddedSubs = new ArraySet<>();
            log("updateEmbeddedSubscriptions: start to get euicc profiles.");
            for (int cardId : cardIds) {
                GetEuiccProfileInfoListResult result = mEuiccController
@@ -1103,11 +1104,27 @@ public class SubscriptionManagerService extends ISub.Stub {
                        builder.setCardString(mUiccController.convertToCardString(cardId));
                    }

                    embeddedSubs.add(subInfo.getSubscriptionId());
                    subInfo = builder.build();
                    log("updateEmbeddedSubscriptions: update subscription " + subInfo);
                    mSubscriptionDatabaseManager.updateSubscription(subInfo);
                }
            }

            // 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.
            mSubscriptionDatabaseManager.getAllSubscriptions().stream()
                    .filter(SubscriptionInfoInternal::isEmbedded)
                    .filter(subInfo -> !embeddedSubs.contains(subInfo.getSubscriptionId()))
                    .forEach(subInfo -> {
                        logl("updateEmbeddedSubscriptions: Mark the deleted sub "
                                + subInfo.getSubscriptionId() + " as non-embedded.");
                        mSubscriptionDatabaseManager.setEmbedded(
                                subInfo.getSubscriptionId(), false);
                    });
        });
        log("updateEmbeddedSubscriptions: Finished embedded subscription update.");
        if (callback != null) {
+41 −0
Original line number Diff line number Diff line
@@ -1817,4 +1817,45 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
                SubscriptionManager.PHONE_NUMBER_SOURCE_CARRIER, CALLING_PACKAGE, CALLING_FEATURE))
                .isEmpty();
    }

    @Test
    public void testDeleteEsim() {
        // pSIM
        insertSubscription(FAKE_SUBSCRIPTION_INFO2);

        EuiccProfileInfo profileInfo1 = new EuiccProfileInfo.Builder(FAKE_ICCID1)
                .setIccid(FAKE_ICCID1)
                .setNickname(FAKE_CARRIER_NAME1)
                .setProfileClass(SubscriptionManager.PROFILE_CLASS_OPERATIONAL)
                .setCarrierIdentifier(new CarrierIdentifier(FAKE_MCC1, FAKE_MNC1, null, null, null,
                        null, FAKE_CARRIER_ID1, FAKE_CARRIER_ID1))
                .setUiccAccessRule(Arrays.asList(UiccAccessRule.decodeRules(
                        FAKE_NATIVE_ACCESS_RULES1)))
                .build();

        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();

        // Now we should have two subscriptions in the database. One for pSIM, one for eSIM.
        assertThat(mSubscriptionManagerServiceUT.getSubscriptionInfo(1).isEmbedded()).isFalse();
        assertThat(mSubscriptionManagerServiceUT.getSubscriptionInfo(2).isEmbedded()).isTrue();

        // Delete the eSIM. blockingGetEuiccProfileInfoList will return an empty list.
        result = new GetEuiccProfileInfoListResult(
                EuiccService.RESULT_OK, new EuiccProfileInfo[0], false);
        doReturn(result).when(mEuiccController).blockingGetEuiccProfileInfoList(eq(1));

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

        // The original pSIM is still pSIM
        assertThat(mSubscriptionManagerServiceUT.getSubscriptionInfo(1).isEmbedded()).isFalse();
        // The original eSIM becomes removed pSIM ¯\_(ツ)_/¯
        assertThat(mSubscriptionManagerServiceUT.getSubscriptionInfo(2).isEmbedded()).isFalse();
    }
}