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

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

Fixed crash in getPhoneNumber

getPhoneNumber used to return empty string when
passed in subscription id is invalid. Adapted the
behavior to avoid clients crash.

Fix: 268535693
Test: *#*#4646#*#* without SIM inserted
Test: atest SubscriptionManagerServiceTest
Change-Id: Ifae48a1d358892797dd51b84baf923d1b4321dba
parent 81b9ebc8
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -3234,15 +3234,12 @@ public class SubscriptionManagerService extends ISub.Stub {
     *
     * @return The phone number, or an empty string if not available.
     *
     * @throws IllegalArgumentException if {@code source} or {@code subId} is invalid.
     * @throws IllegalArgumentException if {@code source} is invalid.
     * @throws SecurityException if the caller doesn't have permissions required.
     *
     * @see SubscriptionManager#PHONE_NUMBER_SOURCE_UICC
     * @see SubscriptionManager#PHONE_NUMBER_SOURCE_CARRIER
     * @see SubscriptionManager#PHONE_NUMBER_SOURCE_IMS
     *
     * @throws IllegalArgumentException if {@code subId} is invalid.
     * @throws SecurityException if callers do not hold the required permission.
     */
    @Override
    @NonNull
@@ -3264,7 +3261,8 @@ public class SubscriptionManagerService extends ISub.Stub {
                .getSubscriptionInfoInternal(subId);

        if (subInfo == null) {
            throw new IllegalArgumentException("Invalid sub id " + subId);
            loge("Invalid sub id " + subId + ", callingPackage=" + callingPackage);
            return "";
        }

        try {
+13 −0
Original line number Diff line number Diff line
@@ -1809,4 +1809,17 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        assertThat(mSubscriptionManagerServiceUT.getSubscriptionInfo(2).isGroupDisabled())
                .isFalse();
    }

    @Test
    public void testGetPhoneNumber() {
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
        testSetPhoneNumber();
        assertThat(mSubscriptionManagerServiceUT.getPhoneNumber(1,
                SubscriptionManager.PHONE_NUMBER_SOURCE_CARRIER, CALLING_PACKAGE, CALLING_FEATURE))
                .isEqualTo(FAKE_PHONE_NUMBER2);
        assertThat(mSubscriptionManagerServiceUT.getPhoneNumber(
                SubscriptionManager.INVALID_SUBSCRIPTION_ID,
                SubscriptionManager.PHONE_NUMBER_SOURCE_CARRIER, CALLING_PACKAGE, CALLING_FEATURE))
                .isEmpty();
    }
}