Loading src/java/com/android/internal/telephony/SmsController.java +6 −1 Original line number Diff line number Diff line Loading @@ -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); Loading tests/telephonytests/src/com/android/internal/telephony/SmsControllerTest.java +32 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading
src/java/com/android/internal/telephony/SmsController.java +6 −1 Original line number Diff line number Diff line Loading @@ -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); Loading
tests/telephonytests/src/com/android/internal/telephony/SmsControllerTest.java +32 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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