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

Commit 1c39854a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Validate slot index in addSubInfo" into main

parents 8a83fe5e 0af5dfdc
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -2166,6 +2166,7 @@ public class SubscriptionManagerService extends ISub.Stub {
     * @return 0 if success, < 0 on error
     *
     * @throws SecurityException if the caller does not have required permissions.
     * @throws IllegalArgumentException if {@code slotIndex} is invalid.
     */
    @Override
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
@@ -2179,6 +2180,11 @@ public class SubscriptionManagerService extends ISub.Stub {

        enforceTelephonyFeatureWithException(getCurrentPackageName(), "addSubInfo");

        if (!SubscriptionManager.isValidSlotIndex(slotIndex)
                && slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
            throw new IllegalArgumentException("Invalid slotIndex " + slotIndex);
        }

        // Now that all security checks passes, perform the operation as ourselves.
        final long identity = Binder.clearCallingIdentity();
        try {
+5 −0
Original line number Diff line number Diff line
@@ -353,6 +353,11 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
        assertThat(subInfo.getSimSlotIndex()).isEqualTo(0);
        assertThat(subInfo.getSubscriptionType()).isEqualTo(
                SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM);

        // Invalid slot index should trigger IllegalArgumentException
        assertThrows(IllegalArgumentException.class,
                () -> mSubscriptionManagerServiceUT.addSubInfo(FAKE_ICCID1, FAKE_CARRIER_NAME1,
                        2, SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM));
    }

    @Test