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

Commit 0f6b8826 authored by Nikhil Kumar's avatar Nikhil Kumar
Browse files

Refactored tests for calling user propagation in outgoing SMS

New parameter callingUser is added in the outgoing SMS flow updated the tests to add new params using the context user id.

Bug: 353351921
Test: atest TelephonyFrameworkTests
Flag: com.android.internal.telephony.flags.sms_mms_deliver_broadcasts_redirect_to_main_user
Change-Id: Ie4083cdef1b31257c0e3751ed3db029b5f95c940
parent 73f8b3f4
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.os.Binder;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SmsMessage;
@@ -71,6 +72,7 @@ public class ImsSmsDispatcherTest extends TelephonyTest {
    PersistableBundle mBundle = new PersistableBundle();
    private static final int SUB_0 = 0;
    private static final String TAG = "ImsSmsDispatcherTest";
    private int mCallingUserId;

    @Before
    public void setUp() throws Exception {
@@ -94,6 +96,7 @@ public class ImsSmsDispatcherTest extends TelephonyTest {
        mTrackerData = new HashMap<>(1);
        when(mSmsTracker.getData()).thenReturn(mTrackerData);
        verify(mSmsDispatchersController).setImsManager(mImsManager);
        mCallingUserId = Binder.getCallingUserHandle().getIdentifier();
    }

    @After
@@ -333,8 +336,7 @@ public class ImsSmsDispatcherTest extends TelephonyTest {
        doReturn(mSmsUsageMonitor).when(mSmsDispatchersController).getUsageMonitor();

        mImsSmsDispatcher.sendText("+15555551212", null, "MessageRef test",
                null, null, null, null, false,
                -1, false, -1, false, 0);
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0);
        verify(mImsManager).sendSms(eq(token + 1), eq(messageRef), eq(SmsMessage.FORMAT_3GPP),
                nullable(String.class), eq(false), (byte[]) any());
    }
@@ -349,8 +351,7 @@ public class ImsSmsDispatcherTest extends TelephonyTest {
        doReturn(mSmsUsageMonitor).when(mSmsDispatchersController).getUsageMonitor();

        mImsSmsDispatcher.sendText("+15555551212", null, "MessageRef test",
                null, null, null, null, false,
                -1, false, -1, false, 0);
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0);
        verify(mImsManager).sendSms(eq(token + 1), eq(messageRef), eq(SmsMessage.FORMAT_3GPP),
                nullable(String.class), eq(false), (byte[]) any());

@@ -384,8 +385,7 @@ public class ImsSmsDispatcherTest extends TelephonyTest {
        doReturn(mSmsUsageMonitor).when(mSmsDispatchersController).getUsageMonitor();

        mImsSmsDispatcher.sendText("+15555551212", null, "MessageRef test",
                null, null, null, null, false,
                -1, false, -1, false, 0);
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0);
        verify(mImsManager).sendSms(eq(token + 1), eq(messageRef), eq(SmsMessage.FORMAT_3GPP),
                nullable(String.class), eq(false), (byte[]) any());

@@ -423,8 +423,7 @@ public class ImsSmsDispatcherTest extends TelephonyTest {
        when(mPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM);
        doReturn(mSmsUsageMonitor).when(mSmsDispatchersController).getUsageMonitor();
        mImsSmsDispatcher.sendText("+15555551212", null, "Retry test",
                null, null, null, null, false,
                -1, false, -1, false, 0);
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0);
        verify(mImsManager).sendSms(eq(token + 1), eq(messageRef), eq(SmsMessage.FORMAT_3GPP),
                nullable(String.class), eq(false), (byte[]) any());
        assertEquals(2, mImsSmsDispatcher.getMaxRetryCountOverIms());
+18 −10
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import static org.mockito.Mockito.verify;

import android.compat.testing.PlatformCompatChangeRule;
import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.testing.AndroidTestingRunner;
@@ -67,6 +68,7 @@ public class SmsControllerTest extends TelephonyTest {
    private SmsController mSmsControllerUT;
    private final String smscAddrStr = "+1206313004";
    private String mCallingPackage;
    private int mCallingUserId;

    @Before
    public void setUp() throws Exception {
@@ -74,6 +76,7 @@ public class SmsControllerTest extends TelephonyTest {
        mAdnRecordCache = Mockito.mock(AdnRecordCache.class);
        mSmsControllerUT = new SmsController(mContext, mFeatureFlags);
        mCallingPackage = mContext.getOpPackageName();
        mCallingUserId = Binder.getCallingUserHandle().getIdentifier();

        doReturn(true).when(mPackageManager).hasSystemFeature(
                PackageManager.FEATURE_TELEPHONY_MESSAGING);
@@ -196,9 +199,9 @@ public class SmsControllerTest extends TelephonyTest {
        doReturn(true).when(mSubscriptionManager)
                .isSubscriptionAssociatedWithUser(eq(subId), any());

        mSmsControllerUT.sendVisualVoicemailSmsForSubscriber(mCallingPackage,null ,
                subId, null, 0, null, null);
        verify(mIccSmsInterfaceManager).sendTextWithSelfPermissions(any(),
        mSmsControllerUT.sendVisualVoicemailSmsForSubscriber(mCallingPackage, mCallingUserId,
                null , subId, null, 0, null, null);
        verify(mIccSmsInterfaceManager).sendTextWithSelfPermissions(any(), eq(mCallingUserId),
                any(), any(), any(), any(), any(), any(), eq(false), eq(true));
    }

@@ -206,10 +209,11 @@ public class SmsControllerTest extends TelephonyTest {
    public void sendVisualVoicemailSmsForSubscriber_phoneIsInEcm() {
        doReturn(true).when(mPhone).isInEcm();

        mSmsControllerUT.sendVisualVoicemailSmsForSubscriber(mCallingPackage,null ,
                1, null, 0, null, null);
        mSmsControllerUT.sendVisualVoicemailSmsForSubscriber(mCallingPackage, mCallingUserId,
                null , 1, null, 0, null, null);
        verify(mIccSmsInterfaceManager, never()).sendTextWithSelfPermissions(any(),
                any(), any(), any(), any(), any(), any(), eq(false), eq(true));
                eq(mCallingUserId), any(), any(), any(), any(), any(), any(),
                eq(false), eq(true));

        doReturn(false).when(mPhone).isInEcm();
    }
@@ -223,7 +227,8 @@ public class SmsControllerTest extends TelephonyTest {
        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);
                .sendText(mCallingPackage, mCallingUserId,
                        "1234", null, "text", null, null, false, 0L, true);
    }

    @Test
@@ -239,7 +244,8 @@ public class SmsControllerTest extends TelephonyTest {
        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);
                .sendText(mCallingPackage, mCallingUserId,
                        "1234", null, "text", null, null, false, 0L, true);
    }

    @Test
@@ -255,7 +261,8 @@ public class SmsControllerTest extends TelephonyTest {
        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);
                .sendText(mCallingPackage, mCallingUserId,
                        "1234", null, "text", null, null, false, 0L, true);
    }

    @Test
@@ -320,6 +327,7 @@ public class SmsControllerTest extends TelephonyTest {
        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);
                .sendText(mCallingPackage, mCallingUserId,
                        "1234", null, "text", null, null, false, 0L, true);
    }
}
 No newline at end of file
+84 −76

File changed.

Preview size limit exceeded, changes collapsed.

+5 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.internal.telephony.cdma;

import static org.mockito.Mockito.*;

import android.os.Binder;
import android.os.HandlerThread;
import android.os.Message;

@@ -38,6 +39,7 @@ public class CdmaSmsDispatcherTest extends TelephonyTest {

    private CdmaSMSDispatcher mCdmaSmsDispatcher;
    private CdmaSmsDispatcherTestHandler mCdmaSmsDispatcherTestHandler;
    private int mCallingUserId;

    private class CdmaSmsDispatcherTestHandler extends HandlerThread {

@@ -63,6 +65,7 @@ public class CdmaSmsDispatcherTest extends TelephonyTest {
        mCdmaSmsDispatcherTestHandler = new CdmaSmsDispatcherTestHandler(TAG);
        mCdmaSmsDispatcherTestHandler.start();
        waitUntilReady();
        mCallingUserId = Binder.getCallingUserHandle().getIdentifier();
    }

    @After
@@ -84,14 +87,14 @@ public class CdmaSmsDispatcherTest extends TelephonyTest {
    @Test @SmallTest
    public void testSendText() {
        mCdmaSmsDispatcher.sendText("111"/* desAddr*/, "222" /*scAddr*/, TAG,
                null, null, null, null, false, -1, false, -1, false, 0L);
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0L);
        verify(mSimulatedCommandsVerifier).sendCdmaSms(any(byte[].class), any(Message.class));
    }

    @Test @SmallTest
    public void testSendTextWithOutDesAddr() {
        mCdmaSmsDispatcher.sendText(null, "222" /*scAddr*/, TAG,
                null, null, null, null, false, -1, false, -1, false, 0L);
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0L);
        verify(mSimulatedCommandsVerifier, times(0)).sendImsGsmSms(anyString(), anyString(),
                anyInt(), anyInt(), any(Message.class));
    }
+16 −12
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.content.IntentFilter;
import android.content.pm.ServiceInfo;
import android.location.Country;
import android.location.CountryDetector;
import android.os.Binder;
import android.os.HandlerThread;
import android.os.Message;
import android.os.RemoteException;
@@ -114,6 +115,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {

    private GsmSMSDispatcher mGsmSmsDispatcher;
    private GsmSmsDispatcherTestHandler mGsmSmsDispatcherTestHandler;
    private int mCallingUserId;

    private class GsmSmsDispatcherTestHandler extends HandlerThread {

@@ -149,6 +151,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        waitUntilReady();
        mGsmSmsDispatcher = new GsmSMSDispatcher(mPhone, mSmsDispatchersController,
                mGsmInboundSmsHandler);
        mCallingUserId = Binder.getCallingUserHandle().getIdentifier();
        processAllMessages();
    }

@@ -177,7 +180,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
                .thenReturn(new Country("US", Country.COUNTRY_SOURCE_SIM));

        mGsmSmsDispatcher.sendText("6501002000", "121" /*scAddr*/, "test sms",
                null, null, null, null, false, -1, false, -1, false, 0L);
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0L);

        verify(mSimulatedCommandsVerifier).sendSMS(anyString(), anyString(), any(Message.class));
        // Blocked number provider is notified about the emergency contact asynchronously.
@@ -197,7 +200,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {

        mGsmSmsDispatcher.sendText(
                getEmergencyNumberFromSystemPropertiesOrDefault(), "121" /*scAddr*/, "test sms",
                null, null, null, null, false, -1, false, -1, false, 0L);
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0L);

        verify(mSimulatedCommandsVerifier).sendSMS(anyString(), anyString(), any(Message.class));
        // Blocked number provider is notified about the emergency contact asynchronously.
@@ -245,7 +248,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        // send invalid dest address: +
        mReceivedTestIntent = false;
        mGsmSmsDispatcher.sendText("+", "222" /*scAddr*/, TAG,
                pendingIntent, null, null, null, false, -1, false, -1, false, 0L);
                pendingIntent, null, null, null, mCallingUserId, false, -1, false, -1, false, 0L);
        waitForMs(500);
        verify(mSimulatedCommandsVerifier, times(0)).sendSMS(anyString(), anyString(),
                any(Message.class));
@@ -310,7 +313,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        // send SMS and check sentIntent
        mReceivedTestIntent = false;
        mGsmSmsDispatcher.sendMultipartText("+123" /*destAddr*/, "222" /*scAddr*/, parts,
                sentIntents, null, null, null, false, -1, false, -1, 0L);
                sentIntents, null, null, null, mCallingUserId, false, -1, false, -1, 0L);

        waitForMs(500);
        synchronized (mLock) {
@@ -390,7 +393,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        mReceivedTestIntent = false;

        mGsmSmsDispatcher.sendText("6501002000", "121" /*scAddr*/, "test sms",
                pendingIntent, null, null, null, false, -1, false, -1, false, 0L);
                pendingIntent, null, null, null, mCallingUserId, false, -1, false, -1, false, 0L);
        processAllMessages();
        synchronized (mLock) {
            if (!mReceivedTestIntent) {
@@ -414,7 +417,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        mGsmSmsDispatcher.mCarrierMessagingTimeout = 100;

        mGsmSmsDispatcher.sendText("6501002000", "121" /*scAddr*/, "test sms",
                null, null, null, null, false, -1, false, -1, false, 0L);
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0L);
        // wait for timeout
        waitForMs(150);
        verify(mSimulatedCommandsVerifier).sendSMS(anyString(), anyString(), any(Message.class));
@@ -428,7 +431,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        mockUiccWithCarrierApp();

        mGsmSmsDispatcher.sendText("6501002000", "121" /*scAddr*/, "test sms",
                null, null, null, null, false, -1, false, -1, false, 0L);
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0L);
        processAllMessages();
        verify(mSimulatedCommandsVerifier).sendSMS(anyString(), anyString(), any(Message.class));
    }
@@ -452,7 +455,8 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        sentIntents.add(sentIntent2);

        mGsmSmsDispatcher.sendMultipartText("6501002000" /*destAddr*/, "222" /*scAddr*/, parts,
                withSentIntents ? sentIntents : null, null, null, null, false, -1, false, -1, 0L);
                withSentIntents ? sentIntents : null, null, null, null, mCallingUserId,
                false, -1, false, -1, 0L);
    }

    @Test
@@ -524,7 +528,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        }

        mGsmSmsDispatcher.sendText("111", "222" /*scAddr*/, TAG,
                null, null, null, null, false, -1, false, -1, false, 0L);
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0L);

        ArgumentCaptor<String> pduCaptor = ArgumentCaptor.forClass(String.class);
        verify(mSimulatedCommandsVerifier).sendSMS(anyString(), pduCaptor.capture(),
@@ -545,7 +549,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
            messageRef += parts.size();
        }
        mGsmSmsDispatcher.sendMultipartText("6501002000" /*destAddr*/, "222" /*scAddr*/, parts,
                null, null, null, null, false, -1, false, -1, 0L);
                null, null, null, null, mCallingUserId, false, -1, false, -1, 0L);
        waitForMs(150);
        ArgumentCaptor<String> pduCaptor = ArgumentCaptor.forClass(String.class);

@@ -568,7 +572,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        mSubscriptionManagerService.setLastUsedTPMessageReference(mPhone.getSubId(), -1);

        mGsmSmsDispatcher.sendText("111", "222" /*scAddr*/, TAG,
                null, null, null, null, false, -1, false, -1, false, 0L);
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0L);

        ArgumentCaptor<String> pduCaptor = ArgumentCaptor.forClass(String.class);
        verify(mSimulatedCommandsVerifier).sendSMS(anyString(), pduCaptor.capture(),
@@ -585,7 +589,7 @@ public class GsmSmsDispatcherTest extends TelephonyTest {
        Message msg = mGsmSmsDispatcher.obtainMessage(17);
        mPhone.getIccRecords().setSmssTpmrValue(255, msg);
        mGsmSmsDispatcher.sendText("111", "222" /*scAddr*/, TAG,
                null, null, null, null, false, -1, false, -1, false, 0L);
                null, null, null, null, mCallingUserId, false, -1, false, -1, false, 0L);

        ArgumentCaptor<String> pduCaptor = ArgumentCaptor.forClass(String.class);
        verify(mSimulatedCommandsVerifier).sendSMS(anyString(), pduCaptor.capture(),
Loading