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

Commit 38155c89 authored by Aishwarya Mallampati's avatar Aishwarya Mallampati
Browse files

Do not throw InvalidArgumentException.

If subId is invalid, getSubscriptionUserHandle throws
InvalidArgumentException which results in a crash. Instead, return null
when subId is invalid.

Bug:289137152
Test: Flashed build on raven-userdebug and performed basic functionality tests,
- atest SubscriptionManagerServiceTest
- QA confirmed that crash is not reproduced with the fix in b/289137152#comment13

Change-Id: Ib4f4972c931c019558e3c5459c4431cb4b124524
parent 3a6b7ea6
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -3546,10 +3546,10 @@ public class SubscriptionManagerService extends ISub.Stub {
     *
     * @param subId the unique SubscriptionInfo index in database
     * @return userHandle associated with this subscription
     * or {@code null} if subscription is not associated with any user.
     * or {@code null} if subscription is not associated with any user
     * or {code null} if subscripiton is not available on the device.
     *
     * @throws SecurityException if doesn't have required permission.
     * @throws IllegalArgumentException if {@code subId} is invalid.
     */
    @Override
    @Nullable
@@ -3562,8 +3562,7 @@ public class SubscriptionManagerService extends ISub.Stub {
            SubscriptionInfoInternal subInfo = mSubscriptionDatabaseManager
                    .getSubscriptionInfoInternal(subId);
            if (subInfo == null) {
                throw new IllegalArgumentException("getSubscriptionUserHandle: Invalid subId: "
                        + subId);
                return null;
            }

            UserHandle userHandle = UserHandle.of(subInfo.getUserId());
+13 −0
Original line number Diff line number Diff line
@@ -1063,6 +1063,19 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
                .isEqualTo(FAKE_USER_HANDLE);
    }

    @Test
    public void testGetSubscriptionUserHandleUnknownSubscription() {
        mContextFixture.addCallingOrSelfPermission(
                Manifest.permission.MANAGE_SUBSCRIPTION_USER_ASSOCIATION);

        // getSubscriptionUserHandle() returns null when subscription is not available on the device
        assertThat(mSubscriptionManagerServiceUT.getSubscriptionUserHandle(10))
                .isEqualTo(null);

        mContextFixture.removeCallingOrSelfPermission(
                Manifest.permission.MANAGE_SUBSCRIPTION_USER_ASSOCIATION);
    }

    @Test
    public void testIsSubscriptionAssociatedWithUser() {
        insertSubscription(FAKE_SUBSCRIPTION_INFO1);