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

Commit e12193c1 authored by Jack Yu's avatar Jack Yu Committed by Gerrit Code Review
Browse files

Merge changes I16f94ee3,I071fdb62 into main

* changes:
  Fixed eSIM activation failed issue
  Fixed incorrect phone number from inactive subscription
parents 150c815e 5f17e943
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -1390,7 +1390,7 @@ public class SubscriptionManagerService extends ISub.Stub {
                        loge("updateSubscription: sim country iso is null");
                        loge("updateSubscription: sim country iso is null");
                    }
                    }


                    String msisdn = mTelephonyManager.getLine1Number(subId);
                    String msisdn = PhoneFactory.getPhone(phoneId).getLine1Number();
                    if (!TextUtils.isEmpty(msisdn)) {
                    if (!TextUtils.isEmpty(msisdn)) {
                        setDisplayNumber(msisdn, subId);
                        setDisplayNumber(msisdn, subId);
                    }
                    }
@@ -3390,7 +3390,7 @@ public class SubscriptionManagerService extends ISub.Stub {
        try {
        try {
            switch(source) {
            switch(source) {
                case SubscriptionManager.PHONE_NUMBER_SOURCE_UICC:
                case SubscriptionManager.PHONE_NUMBER_SOURCE_UICC:
                    Phone phone = PhoneFactory.getPhone(getPhoneId(subId));
                    Phone phone = PhoneFactory.getPhone(getSlotIndex(subId));
                    if (phone != null) {
                    if (phone != null) {
                        return TextUtils.emptyIfNull(phone.getLine1Number());
                        return TextUtils.emptyIfNull(phone.getLine1Number());
                    } else {
                    } else {
@@ -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:
+101 −1
Original line number Original line Diff line number Diff line
@@ -166,6 +166,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        // Dual-SIM configuration
        // Dual-SIM configuration
        mPhones = new Phone[] {mPhone, mPhone2};
        mPhones = new Phone[] {mPhone, mPhone2};
        replaceInstance(PhoneFactory.class, "sPhones", null, mPhones);
        replaceInstance(PhoneFactory.class, "sPhones", null, mPhones);
        doReturn(FAKE_PHONE_NUMBER1).when(mPhone).getLine1Number();
        doReturn(2).when(mTelephonyManager).getActiveModemCount();
        doReturn(2).when(mTelephonyManager).getActiveModemCount();
        doReturn(2).when(mTelephonyManager).getSupportedModemCount();
        doReturn(2).when(mTelephonyManager).getSupportedModemCount();
        doReturn(mUiccProfile).when(mPhone2).getIccCard();
        doReturn(mUiccProfile).when(mPhone2).getIccCard();
@@ -1851,7 +1852,6 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {


        doReturn(FAKE_IMSI1).when(mTelephonyManager).getSubscriberId();
        doReturn(FAKE_IMSI1).when(mTelephonyManager).getSubscriberId();
        doReturn(FAKE_MCC1 + FAKE_MNC1).when(mTelephonyManager).getSimOperatorNumeric(anyInt());
        doReturn(FAKE_MCC1 + FAKE_MNC1).when(mTelephonyManager).getSimOperatorNumeric(anyInt());
        doReturn(FAKE_PHONE_NUMBER1).when(mTelephonyManager).getLine1Number(anyInt());
        doReturn(FAKE_EHPLMNS1.split(",")).when(mSimRecords).getEhplmns();
        doReturn(FAKE_EHPLMNS1.split(",")).when(mSimRecords).getEhplmns();
        doReturn(FAKE_HPLMNS1.split(",")).when(mSimRecords).getPlmnsFromHplmnActRecord();
        doReturn(FAKE_HPLMNS1.split(",")).when(mSimRecords).getPlmnsFromHplmnActRecord();
        doReturn(0).when(mUiccSlot).getPortIndexFromIccId(anyString());
        doReturn(0).when(mUiccSlot).getPortIndexFromIccId(anyString());
@@ -1925,6 +1925,105 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
                .isEmpty();
                .isEmpty();
    }
    }


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

        int subId = insertSubscription(FAKE_SUBSCRIPTION_INFO1);
        assertThat(subId).isEqualTo(2);
        assertThat(mSubscriptionManagerServiceUT.getActiveSubIdList(false)).hasLength(1);
        assertThat(mSubscriptionManagerServiceUT.getAllSubInfoList(CALLING_PACKAGE,
                CALLING_FEATURE)).hasSize(2);

        assertThat(mSubscriptionManagerServiceUT.getPhoneNumberFromFirstAvailableSource(1,
                CALLING_PACKAGE, CALLING_FEATURE)).isEqualTo(FAKE_PHONE_NUMBER2);
        assertThat(mSubscriptionManagerServiceUT.getPhoneNumber(1,
                SubscriptionManager.PHONE_NUMBER_SOURCE_UICC, CALLING_PACKAGE, CALLING_FEATURE))
                .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);
@@ -2013,6 +2112,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
                0, TelephonyManager.SIM_STATE_READY, null, null);
                0, TelephonyManager.SIM_STATE_READY, null, null);
        processAllMessages();
        processAllMessages();


        mContextFixture.addCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE);
        mSubscriptionManagerServiceUT.updateSimState(
        mSubscriptionManagerServiceUT.updateSimState(
                0, TelephonyManager.SIM_STATE_LOADED, null, null);
                0, TelephonyManager.SIM_STATE_LOADED, null, null);
        processAllMessages();
        processAllMessages();