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

Commit 71898cc5 authored by Jack Yu's avatar Jack Yu
Browse files

Fixed incorrect phone number from inactive subscription

When the subscription inactive, SubscriptionManager.getPhoneNumber()
returns incorrect phone number from the active subscription.

Fixed by using getSlotIndex which would not give default phone id
when subscription is inactive.

Fix: 286124301
Test: atest SubscriptionManagerServiceTest
Test: Basic telephony functionality tests
Test: eSIM transfer and confirmed the phone number was displayed properly (b/293623063#comment6)
Merged-In: I071fdb62fcb3a754dfaf32e7198cdfb6f762eaac
Change-Id: I071fdb62fcb3a754dfaf32e7198cdfb6f762eaac
parent ca02bd47
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1390,7 +1390,7 @@ public class SubscriptionManagerService extends ISub.Stub {
                        loge("updateSubscription: sim country iso is null");
                    }

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

        doReturn(FAKE_IMSI1).when(mTelephonyManager).getSubscriberId();
        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_HPLMNS1.split(",")).when(mSimRecords).getPlmnsFromHplmnActRecord();
        doReturn(0).when(mUiccSlot).getPortIndexFromIccId(anyString());
@@ -1925,6 +1925,24 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
                .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 testDeleteEsim() {
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
@@ -2013,6 +2031,7 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
                0, TelephonyManager.SIM_STATE_READY, null, null);
        processAllMessages();

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