Loading src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java +17 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) { Loading tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionManagerServiceTest.java +41 −0 Original line number Diff line number Diff line Loading @@ -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(); } } Loading
src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java +17 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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) { Loading
tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionManagerServiceTest.java +41 −0 Original line number Diff line number Diff line Loading @@ -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(); } }