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

Commit 6909e798 authored by Jack Yu's avatar Jack Yu Committed by Automerger Merge Worker
Browse files

Fixed eSIM deletion issue am: 6b81835e

parents f933006c 6b81835e
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -1002,6 +1002,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
@@ -1078,11 +1079,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
@@ -1825,4 +1825,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();
    }
}