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

Commit 329c289b authored by Xiangyu/Malcolm Chen's avatar Xiangyu/Malcolm Chen Committed by Gerrit Code Review
Browse files

Merge "Allow addSubscriptionsIntoGroup with grouUuid that isn't assigned."

parents 65056969 b318c6fc
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -3055,12 +3055,6 @@ public class SubscriptionController extends ISub.Stub {
            throw new IllegalArgumentException("Invalid groupUuid");
        }

        // TODO: Revisit whether we need this restriction in R. There's no technical need for it,
        // but we don't want to change the API behavior at this time.
        if (getSubscriptionsInGroup(groupUuid, callingPackage).isEmpty()) {
            throw new IllegalArgumentException("Cannot add subscriptions to a non-existent group!");
        }

        // Makes sure calling package matches caller UID.
        mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
        // If it doesn't have modify phone state permission, or carrier privilege permission,
+61 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class SubscriptionControllerTest extends TelephonyTest {
    private static final int SINGLE_SIM = 1;
@@ -727,6 +728,57 @@ public class SubscriptionControllerTest extends TelephonyTest {
        assertNotEquals(groupId, newGroupId);
    }

    @Test
    @SmallTest
    public void testAddSubscriptionIntoGroupWithCarrierPrivilegePermission() throws Exception {
        testInsertSim();
        // Adding a second profile and mark as embedded.
        // TODO b/123300875 slot index 1 is not expected to be valid
        mSubscriptionControllerUT.addSubInfoRecord("test2", 1);
        ContentValues values = new ContentValues();
        values.put(SubscriptionManager.IS_EMBEDDED, 1);
        mFakeTelephonyProvider.update(SubscriptionManager.CONTENT_URI, values,
                SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID + "=" + 2, null);
        mSubscriptionControllerUT.refreshCachedActiveSubscriptionInfoList();

        mContextFixture.removeCallingOrSelfPermission(ContextFixture.PERMISSION_ENABLE_ALL);
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE);

        // Create group for sub 1.
        int[] subIdList = new int[] {1};
        doReturn(true).when(mTelephonyManager).hasCarrierPrivileges(1);
        ParcelUuid groupId = mSubscriptionControllerUT.createSubscriptionGroup(
                subIdList, "packageName1");

        // Try to add sub 2 into group of sub 1.
        // Should fail as it doesn't have carrier privilege on sub 2.
        try {
            mSubscriptionControllerUT.addSubscriptionsIntoGroup(
                    new int[] {2}, groupId, "packageName1");
            fail("addSubscriptionsIntoGroup should fail with no permission on sub 2.");
        } catch (SecurityException e) {
            // Expected result.
        }

        doReturn(false).when(mTelephonyManager).hasCarrierPrivileges(1);
        doReturn(true).when(mTelephonyManager).hasCarrierPrivileges(2);
        // Try to add sub 2 into group of sub 1.
        // Should fail as it doesn't have carrier privilege on sub 1.
        try {
            mSubscriptionControllerUT.addSubscriptionsIntoGroup(
                    new int[] {2}, groupId, "packageName2");
            fail("addSubscriptionsIntoGroup should fail with no permission on the group (sub 1).");
        } catch (SecurityException e) {
            // Expected result.
        }

        doReturn(true).when(mTelephonyManager).hasCarrierPrivileges(1);
        mSubscriptionControllerUT.addSubscriptionsIntoGroup(new int[] {2}, groupId, "packageName2");
        List<SubscriptionInfo> infoList = mSubscriptionControllerUT
                .getSubscriptionsInGroup(groupId, "packageName2");
        assertEquals(2, infoList.size());
    }

    @Test
    @SmallTest
    public void testUpdateSubscriptionGroupWithCarrierPrivilegePermission() throws Exception {
@@ -893,6 +945,15 @@ public class SubscriptionControllerTest extends TelephonyTest {
                .getSubscriptionsInGroup(groupUuid, mContext.getOpPackageName());
        assertEquals(1, infoList.size());
        assertEquals(2, infoList.get(0).getSubscriptionId());

        // Adding sub 1 into a non-existing UUID, which should be granted.
        groupUuid = new ParcelUuid(UUID.randomUUID());
        mSubscriptionControllerUT.addSubscriptionsIntoGroup(
                subIdList, groupUuid, mContext.getOpPackageName());
        infoList = mSubscriptionControllerUT
                .getSubscriptionsInGroup(groupUuid, mContext.getOpPackageName());
        assertEquals(1, infoList.size());
        assertEquals(1, infoList.get(0).getSubscriptionId());
    }

    private void registerMockTelephonyRegistry() {