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

Commit 5f17e943 authored by Jack Yu's avatar Jack Yu
Browse files

Fixed eSIM activation failed issue

In some cases, subscription manager service fails
to get eSIM information from EuiccController during
boot up, or phone process is up too late so miss the
trigger point to update eSIM profile.

Fixed by querying EuiccController again when
SIM state moves to READY or NOT_READY.

Fix: 276955800
Fix: 290194966
Fix: 291964927
Test: Verified in b/290194966#comment6
Test: Verified in b/276955800#comment67
Test: atest SubscriptionManagerServiceTest
Change-Id: I16f94ee3d3f79c1fbbabe22a8596c8c31724fca2
parent 71898cc5
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -3875,10 +3875,13 @@ public class SubscriptionManagerService extends ISub.Stub {
                case TelephonyManager.SIM_STATE_PUK_REQUIRED:
                case TelephonyManager.SIM_STATE_PUK_REQUIRED:
                case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
                case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
                case TelephonyManager.SIM_STATE_PERM_DISABLED:
                case TelephonyManager.SIM_STATE_PERM_DISABLED:
                case TelephonyManager.SIM_STATE_READY:
                case TelephonyManager.SIM_STATE_CARD_IO_ERROR:
                case TelephonyManager.SIM_STATE_CARD_IO_ERROR:
                case TelephonyManager.SIM_STATE_LOADED:
                case TelephonyManager.SIM_STATE_LOADED:
                    updateSubscription(slotIndex);
                    break;
                case TelephonyManager.SIM_STATE_NOT_READY:
                case TelephonyManager.SIM_STATE_NOT_READY:
                case TelephonyManager.SIM_STATE_READY:
                    updateEmbeddedSubscriptions();
                    updateSubscription(slotIndex);
                    updateSubscription(slotIndex);
                    break;
                    break;
                case TelephonyManager.SIM_STATE_CARD_RESTRICTED:
                case TelephonyManager.SIM_STATE_CARD_RESTRICTED:
+81 −0
Original line number Original line Diff line number Diff line
@@ -1943,6 +1943,87 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
                .isEqualTo(FAKE_PHONE_NUMBER2);
                .isEqualTo(FAKE_PHONE_NUMBER2);
    }
    }


    @Test
    public void testEsimActivation() {
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE);
        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));

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

        SubscriptionInfoInternal subInfo = mSubscriptionManagerServiceUT
                .getSubscriptionInfoInternal(1);
        assertThat(subInfo.getSubscriptionId()).isEqualTo(1);
        assertThat(subInfo.isActive()).isFalse();
        assertThat(subInfo.getIccId()).isEqualTo(FAKE_ICCID1);
        assertThat(subInfo.getDisplayName()).isEqualTo(FAKE_CARRIER_NAME1);

        Mockito.clearInvocations(mEuiccController);

        mSubscriptionManagerServiceUT.updateSimState(
                0, TelephonyManager.SIM_STATE_ABSENT, null, null);
        mSubscriptionManagerServiceUT.updateSimState(
                1, TelephonyManager.SIM_STATE_UNKNOWN, null, null);
        processAllMessages();

        doReturn(FAKE_IMSI1).when(mTelephonyManager).getSubscriberId();
        doReturn(FAKE_MCC1 + FAKE_MNC1).when(mTelephonyManager).getSimOperatorNumeric(anyInt());
        doReturn(FAKE_PHONE_NUMBER1).when(mPhone2).getLine1Number();
        doReturn(FAKE_EHPLMNS1.split(",")).when(mSimRecords).getEhplmns();
        doReturn(FAKE_HPLMNS1.split(",")).when(mSimRecords).getPlmnsFromHplmnActRecord();
        doReturn(0).when(mUiccSlot).getPortIndexFromIccId(anyString());
        doReturn(true).when(mUiccSlot).isEuicc();
        doReturn(1).when(mUiccController).convertToPublicCardId(eq(FAKE_ICCID1));

        mSubscriptionManagerServiceUT.updateSimState(
                1, TelephonyManager.SIM_STATE_READY, null, null);
        processAllMessages();

        mSubscriptionManagerServiceUT.updateSimState(
                1, TelephonyManager.SIM_STATE_LOADED, null, null);
        processAllMessages();

        // Verify if SMSVC is refreshing eSIM profiles when moving into READY state.
        verify(mEuiccController).blockingGetEuiccProfileInfoList(eq(1));

        List<SubscriptionInfo> subInfoList = mSubscriptionManagerServiceUT
                .getActiveSubscriptionInfoList(CALLING_PACKAGE, CALLING_FEATURE);
        assertThat(subInfoList).hasSize(1);
        assertThat(subInfoList.get(0).getSimSlotIndex()).isEqualTo(1);
        assertThat(subInfoList.get(0).getSubscriptionId()).isEqualTo(1);

        subInfo = mSubscriptionManagerServiceUT.getSubscriptionInfoInternal(1);
        assertThat(subInfo.isActive()).isTrue();
        assertThat(subInfo.getSimSlotIndex()).isEqualTo(1);
        assertThat(subInfo.getPortIndex()).isEqualTo(0);
        assertThat(subInfo.isEmbedded()).isTrue();
        assertThat(subInfo.getCarrierId()).isEqualTo(TelephonyManager.UNKNOWN_CARRIER_ID);
        assertThat(subInfo.getDisplayName()).isEqualTo(FAKE_CARRIER_NAME1);
        assertThat(subInfo.isOpportunistic()).isFalse();
        assertThat(subInfo.getNumber()).isEqualTo(FAKE_PHONE_NUMBER1);
        assertThat(subInfo.getMcc()).isEqualTo(FAKE_MCC1);
        assertThat(subInfo.getMnc()).isEqualTo(FAKE_MNC1);
        assertThat(subInfo.getEhplmns()).isEqualTo(FAKE_EHPLMNS1);
        assertThat(subInfo.getHplmns()).isEqualTo(FAKE_HPLMNS1);
        assertThat(subInfo.getCardString()).isEqualTo(FAKE_ICCID1);
        assertThat(subInfo.getCardId()).isEqualTo(1);
        assertThat(subInfo.getSubscriptionType()).isEqualTo(
                SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM);
    }

    @Test
    @Test
    public void testDeleteEsim() {
    public void testDeleteEsim() {
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE);