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

Commit f8e30e78 authored by Ayush Sharma's avatar Ayush Sharma Committed by Android (Google) Code Review
Browse files

Merge "Add hidden api to set ownership for subscription" into main

parents bfd99e29 84493d17
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -933,9 +933,13 @@ public class SubscriptionManagerService extends ISub.Stub {
     *
     * @param subId Subscription id.
     * @param groupOwner The group owner to assign to the subscription
     *
     * @throws SecurityException if the caller does not have required permissions.
     */
    @Override
    @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
    public void setGroupOwner(int subId, @NonNull String groupOwner) {
        // This can throw IllegalArgumentException if the subscription does not exist.
        enforcePermissions("setGroupOwner", Manifest.permission.MODIFY_PHONE_STATE);
        try {
            mSubscriptionDatabaseManager.setGroupOwner(
                    subId,
+18 −4
Original line number Diff line number Diff line
@@ -425,20 +425,34 @@ public class SubscriptionManagerServiceTest extends TelephonyTest {
    @Test
    public void testSetAdminOwned() {
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE);
        mSubscriptionManagerServiceUT.addSubInfo(FAKE_ICCID1, FAKE_CARRIER_NAME1,
                0, SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM);
        mSubscriptionManagerServiceUT.addSubInfo(FAKE_ICCID1, FAKE_CARRIER_NAME1, 0,
                SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM);
        processAllMessages();
        String groupOwner = "test";

        mSubscriptionManagerServiceUT.setGroupOwner(1, groupOwner);

        SubscriptionInfoInternal subInfo = mSubscriptionManagerServiceUT
                .getSubscriptionInfoInternal(1);
        SubscriptionInfoInternal subInfo =
                mSubscriptionManagerServiceUT.getSubscriptionInfoInternal(1);
        assertThat(subInfo).isNotNull();
        assertThat(subInfo.getGroupOwner()).isEqualTo(groupOwner);
        verify(mMockedSubscriptionManagerServiceCallback).onSubscriptionChanged(eq(1));
    }

    @Test
    public void testSetGroupOwner_callerMissingpPermission_throws() {
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE);
        mSubscriptionManagerServiceUT.addSubInfo(FAKE_ICCID1, FAKE_CARRIER_NAME1, 0,
                SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM);
        processAllMessages();
        String groupOwner = "test";
        // Remove MODIFY_PHONE_STATE
        mContextFixture.removeCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE);

        assertThrows(SecurityException.class,
                () -> mSubscriptionManagerServiceUT.setGroupOwner(1, groupOwner));
    }

    @Test
    @DisableCompatChanges({TelephonyManager.ENABLE_FEATURE_MAPPING})
    public void testSetPhoneNumber() {