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

Commit fbb6f784 authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Fix quick response not sending via work profile.

Telecom calls into SmsController to send the SMS message over
the work sim. However, the calling user is always User 0,
which results in the message failing to send since the work sim is not
associated with the primary profile.

To reduce the scope of impact to other APIs, we will bypass the
validation check only in SmsController#sendTextForSubscriber if the
calling user has granted the INTERACT_ACROSS_USERS_FULL permission.
Adding log (debug level) to track when validation is bypassed.

Fixes: 275115413
Test: Manual (can see that the text message was sent to caller)
Change-Id: Ie992df943b452c85aebc816b0c85145426c24201
parent b7b74a20
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -260,7 +260,12 @@ public class SmsController extends ISmsImplBase {
        }

        // Check if user is associated with the subscription
        if (!TelephonyPermissions.checkSubscriptionAssociatedWithUser(mContext, subId,
        boolean crossUserFullGranted = mContext.checkCallingOrSelfPermission(
                android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) == PERMISSION_GRANTED;
        Rlog.d(LOG_TAG, "sendTextForSubscriber: caller has INTERACT_ACROSS_USERS_FULL? "
                + crossUserFullGranted);
        if (!crossUserFullGranted
                && !TelephonyPermissions.checkSubscriptionAssociatedWithUser(mContext, subId,
                Binder.getCallingUserHandle(), destAddr)) {
            TelephonyUtils.showSwitchToManagedProfileDialogIfAppropriate(mContext, subId,
                    Binder.getCallingUid(), callingPackage);
+32 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import android.content.pm.PackageManager;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

@@ -207,4 +208,35 @@ public class SmsControllerTest extends TelephonyTest {
                .sendText(mCallingPackage, "1234", null, "text", null, null, false, 0L, true);
    }

    @Test
    public void sendTextForSubscriberTest_InteractAcrossUsers() {
        int subId = 1;
        // Sending text to subscriber should not fail when the caller has the
        // INTERACT_ACROSS_USERS_FULL permission.
        doReturn(false).when(mSubscriptionManager)
                .isSubscriptionAssociatedWithUser(eq(subId), any());
        doReturn(PackageManager.PERMISSION_GRANTED).when(mContext).checkCallingOrSelfPermission(
                eq(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL));

        mSmsControllerUT.sendTextForSubscriber(subId, mCallingPackage, null, "1234",
                null, "text", null, null, false, 0L, true, true);
        verify(mIccSmsInterfaceManager, Mockito.times(1))
                .sendText(mCallingPackage, "1234", null, "text", null, null, false, 0L, true);
    }

    @Test
    public void sendTextForSubscriberTestFail() {
        int subId = 1;
        // Sending text to subscriber should fail when the caller does not have the
        // INTERACT_ACROSS_USERS_FULL permission and is not associated with the subscription.
        doReturn(false).when(mSubscriptionManager)
                .isSubscriptionAssociatedWithUser(eq(subId), any());
        doReturn(PackageManager.PERMISSION_DENIED).when(mContext).checkCallingOrSelfPermission(
                eq(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL));

        mSmsControllerUT.sendTextForSubscriber(subId, mCallingPackage, null, "1234",
                null, "text", null, null, false, 0L, true, true);
        verify(mIccSmsInterfaceManager, Mockito.times(0))
                .sendText(mCallingPackage, "1234", null, "text", null, null, false, 0L, true);
    }
}
 No newline at end of file