Search in sources :

Example 6 with InboundSmsTracker

use of com.android.internal.telephony.InboundSmsTracker in project android_frameworks_opt_telephony by LineageOS.

the class GsmInboundSmsHandlerTest method testMultipartSmsFromBlockedEmail_noBroadcastsSent.

@Test
@MediumTest
public void testMultipartSmsFromBlockedEmail_noBroadcastsSent() {
    mFakeBlockedNumberContentProvider.mBlockedNumbers.add("1234567890@test.com");
    transitionFromStartupToIdle();
    // prepare SMS part 1 and part 2
    prepareMultiPartSms(false);
    // only the first SMS is configured with the display originating email address
    mInboundSmsTrackerPart1 = new InboundSmsTracker(mContext, mSmsPdu, /* pdu */
    System.currentTimeMillis(), /* timestamp */
    -1, /* destPort */
    false, /* is3gpp2 */
    "1234567890", /* address */
    "1234567890@test.com", /* displayAddress */
    1, /* referenceNumber */
    1, /* sequenceNumber */
    2, /* messageCount */
    false, /* is3gpp2WapPdu */
    mMessageBodyPart1, /* messageBody */
    false, /* isClass0 */
    mSubId0);
    mSmsHeader.concatRef = new SmsHeader.ConcatRef();
    doReturn(mSmsHeader).when(mGsmSmsMessage).getUserDataHeader();
    doReturn(mInboundSmsTrackerPart1).when(mTelephonyComponentFactory).makeInboundSmsTracker(any(Context.class), nullable(byte[].class), anyLong(), anyInt(), anyBoolean(), nullable(String.class), nullable(String.class), anyInt(), anyInt(), anyInt(), anyBoolean(), nullable(String.class), anyBoolean(), anyInt());
    sendNewSms();
    // State machine should go back to idle and wait for second part
    assertEquals("IdleState", getCurrentState().getName());
    doReturn(mInboundSmsTrackerPart2).when(mTelephonyComponentFactory).makeInboundSmsTracker(any(Context.class), nullable(byte[].class), anyLong(), anyInt(), anyBoolean(), nullable(String.class), nullable(String.class), anyInt(), anyInt(), anyInt(), anyBoolean(), nullable(String.class), anyBoolean(), anyInt());
    sendNewSms();
    verify(mContext, never()).sendBroadcast(any(Intent.class));
    assertEquals("IdleState", getCurrentState().getName());
    // Filter should still be invoked.
    verifySmsFiltersInvoked(times(1));
}
Also used : SmsHeader(com.android.internal.telephony.SmsHeader) Context(android.content.Context) Intent(android.content.Intent) InboundSmsTracker(com.android.internal.telephony.InboundSmsTracker) FlakyTest(androidx.test.filters.FlakyTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test) MediumTest(androidx.test.filters.MediumTest)

Example 7 with InboundSmsTracker

use of com.android.internal.telephony.InboundSmsTracker in project android_frameworks_opt_telephony by LineageOS.

the class GsmInboundSmsHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp("GsmInboundSmsHandlerTest");
    doReturn(true).when(mTelephonyManager).getSmsReceiveCapableForPhone(anyInt(), anyBoolean());
    doReturn(true).when(mSmsStorageMonitor).isStorageAvailable();
    UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    doReturn(true).when(userManager).isUserUnlocked();
    doReturn(true).when(userManager).isUserRunning(any(UserHandle.class));
    List<UserHandle> userHandles = new ArrayList();
    userHandles.add(UserHandle.SYSTEM);
    doReturn(userHandles).when(userManager).getUserHandles(anyBoolean());
    mSmsMessage.mWrappedSmsMessage = mGsmSmsMessage;
    mInboundSmsTracker = new InboundSmsTracker(mContext, mSmsPdu, /* pdu */
    System.currentTimeMillis(), /* timestamp */
    -1, /* destPort */
    false, /* is3gpp2 */
    false, /* is3gpp2WapPdu */
    "1234567890", /* address */
    "1234567890", /* displayAddress */
    mMessageBody, /* messageBody */
    false, /* isClass0 */
    mSubId0);
    doReturn(mInboundSmsTracker).when(mTelephonyComponentFactory).makeInboundSmsTracker(any(Context.class), nullable(byte[].class), anyLong(), anyInt(), anyBoolean(), anyBoolean(), nullable(String.class), nullable(String.class), nullable(String.class), anyBoolean(), anyInt());
    createMockInboundSmsTracker();
    mContentProvider = new FakeSmsContentProvider();
    ((MockContentResolver) mContext.getContentResolver()).addProvider(Telephony.Sms.CONTENT_URI.getAuthority(), mContentProvider);
    mGsmInboundSmsHandler = GsmInboundSmsHandler.makeInboundSmsHandler(mContext, mSmsStorageMonitor, mPhone);
    mSmsFilters = new ArrayList<>();
    mSmsFilters.add(mSmsFilter);
    mSmsFilters.add(mSmsFilter2);
    mGsmInboundSmsHandler.setSmsFiltersForTesting(mSmsFilters);
    monitorTestableLooper(new TestableLooper(mGsmInboundSmsHandler.getHandler().getLooper()));
    processAllMessages();
}
Also used : Context(android.content.Context) FakeSmsContentProvider(com.android.internal.telephony.FakeSmsContentProvider) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) MockContentResolver(android.test.mock.MockContentResolver) TestableLooper(android.testing.TestableLooper) InboundSmsTracker(com.android.internal.telephony.InboundSmsTracker) Before(org.junit.Before)

Example 8 with InboundSmsTracker

use of com.android.internal.telephony.InboundSmsTracker in project android_frameworks_opt_telephony by LineageOS.

the class GsmInboundSmsHandlerTest method testClass0Sms.

@Test
@MediumTest
public void testClass0Sms() {
    transitionFromStartupToIdle();
    mInboundSmsTracker = new InboundSmsTracker(mContext, mSmsPdu, /* pdu */
    System.currentTimeMillis(), /* timestamp */
    -1, /* destPort */
    false, /* is3gpp2 */
    false, /* is3gpp2WapPdu */
    "1234567890", /* address */
    "1234567890", /* displayAddress */
    mMessageBody, /* messageBody */
    true, /* isClass0 */
    mSubId0);
    doReturn(mInboundSmsTracker).when(mTelephonyComponentFactory).makeInboundSmsTracker(any(Context.class), nullable(byte[].class), anyLong(), anyInt(), anyBoolean(), anyBoolean(), nullable(String.class), nullable(String.class), nullable(String.class), anyBoolean(), anyInt());
    mGsmInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_BROADCAST_SMS, mInboundSmsTracker);
    processAllMessages();
    verifySmsIntentBroadcasts(0, true);
    verifySmsFiltersInvoked(times(1));
}
Also used : Context(android.content.Context) InboundSmsTracker(com.android.internal.telephony.InboundSmsTracker) FlakyTest(androidx.test.filters.FlakyTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test) MediumTest(androidx.test.filters.MediumTest)

Example 9 with InboundSmsTracker

use of com.android.internal.telephony.InboundSmsTracker in project android_frameworks_opt_telephony by LineageOS.

the class GsmInboundSmsHandlerTest method prepareMultiPartSms.

private void prepareMultiPartSms(boolean is3gpp2WapPush) {
    // Part 1
    mInboundSmsTrackerPart1 = new InboundSmsTracker(mContext, mSmsPdu, /* pdu */
    System.currentTimeMillis(), /* timestamp */
    -1, /* destPort */
    is3gpp2WapPush, /* is3gpp2 */
    "1234567890", /* address */
    "1234567890", /* displayAddress */
    1, /* referenceNumber */
    1, /* sequenceNumber */
    2, /* messageCount */
    is3gpp2WapPush, /* is3gpp2WapPdu */
    mMessageBodyPart1, /* messageBody */
    false, /* isClass0 */
    mSubId0);
    // Part 2
    mInboundSmsTrackerPart2 = new InboundSmsTracker(mContext, mSmsPdu, /* pdu */
    System.currentTimeMillis(), /* timestamp */
    -1, /* destPort */
    is3gpp2WapPush, /* is3gpp2 */
    "1234567890", /* address */
    "1234567890", /* displayAddress */
    1, /* referenceNumber */
    2, /* sequenceNumber */
    2, /* messageCount */
    is3gpp2WapPush, /* is3gpp2WapPdu */
    mMessageBodyPart2, /* messageBody */
    false, /* isClass0 */
    mSubId0);
}
Also used : InboundSmsTracker(com.android.internal.telephony.InboundSmsTracker)

Example 10 with InboundSmsTracker

use of com.android.internal.telephony.InboundSmsTracker in project android_frameworks_opt_telephony by LineageOS.

the class GsmInboundSmsHandlerTest method testBroadcastUndeliveredDeleted.

@Test
@MediumTest
public void testBroadcastUndeliveredDeleted() throws Exception {
    replaceInstance(SmsBroadcastUndelivered.class, "instance", null, null);
    SmsBroadcastUndelivered.initialize(mContext, mGsmInboundSmsHandler, mCdmaInboundSmsHandler);
    mInboundSmsTracker = new InboundSmsTracker(mContext, mSmsPdu, /* pdu */
    System.currentTimeMillis(), /* timestamp */
    0, /* destPort */
    false, /* is3gpp2 */
    false, /* is3gpp2WapPdu */
    "1234567890", /* address */
    "1234567890", /* displayAddress */
    mMessageBody, /* messageBody */
    false, /* isClass0 */
    mSubId0);
    doReturn(mInboundSmsTracker).when(mTelephonyComponentFactory).makeInboundSmsTracker(any(Context.class), nullable(byte[].class), anyLong(), anyInt(), anyBoolean(), anyBoolean(), nullable(String.class), nullable(String.class), nullable(String.class), anyBoolean(), anyInt());
    // add a fake entry to db
    ContentValues rawSms = new ContentValues();
    rawSms.put("deleted", 1);
    mContentProvider.insert(sRawUri, rawSms);
    // when user unlocks the device, broadcast should not be sent for new message
    mContext.sendBroadcast(new Intent(Intent.ACTION_USER_UNLOCKED));
    // wait for ScanRawTableThread
    waitForMs(100);
    processAllMessages();
    verify(mContext, times(1)).sendBroadcast(any(Intent.class));
    assertEquals("IdleState", getCurrentState().getName());
    verifySmsFiltersInvoked(never());
}
Also used : Context(android.content.Context) ContentValues(android.content.ContentValues) Intent(android.content.Intent) InboundSmsTracker(com.android.internal.telephony.InboundSmsTracker) FlakyTest(androidx.test.filters.FlakyTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) MediumTest(androidx.test.filters.MediumTest) Test(org.junit.Test) MediumTest(androidx.test.filters.MediumTest)

Aggregations

InboundSmsTracker (com.android.internal.telephony.InboundSmsTracker)10 Context (android.content.Context)8 FlakyTest (androidx.test.filters.FlakyTest)6 TelephonyTest (com.android.internal.telephony.TelephonyTest)6 Test (org.junit.Test)6 Intent (android.content.Intent)5 MediumTest (androidx.test.filters.MediumTest)5 SmsHeader (com.android.internal.telephony.SmsHeader)3 Cursor (android.database.Cursor)2 UserManager (android.os.UserManager)2 MockContentResolver (android.test.mock.MockContentResolver)2 TestableLooper (android.testing.TestableLooper)2 FakeSmsContentProvider (com.android.internal.telephony.FakeSmsContentProvider)2 Before (org.junit.Before)2 ContentValues (android.content.ContentValues)1 AsyncResult (android.os.AsyncResult)1 RemoteException (android.os.RemoteException)1 UserHandle (android.os.UserHandle)1 MediumTest (android.test.suitebuilder.annotation.MediumTest)1 Field (java.lang.reflect.Field)1