Search in sources :

Example 1 with InboundSmsTracker

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

the class CdmaInboundSmsHandler method processCdmaWapPdu.

/**
 * Processes inbound messages that are in the WAP-WDP PDU format. See
 * wap-259-wdp-20010614-a section 6.5 for details on the WAP-WDP PDU format.
 * WDP segments are gathered until a datagram completes and gets dispatched.
 *
 * @param pdu The WAP-WDP PDU segment
 * @return a result code from {@link android.provider.Telephony.Sms.Intents}, or
 * {@link Activity#RESULT_OK} if the message has been broadcast
 * to applications
 */
private int processCdmaWapPdu(byte[] pdu, int referenceNumber, String address, String dispAddr, long timestamp) {
    int index = 0;
    int msgType = (0xFF & pdu[index++]);
    if (msgType != 0) {
        log("Received a WAP SMS which is not WDP. Discard.");
        return Intents.RESULT_SMS_HANDLED;
    }
    // >= 1
    int totalSegments = (0xFF & pdu[index++]);
    // >= 0
    int segment = (0xFF & pdu[index++]);
    if (segment >= totalSegments) {
        loge("WDP bad segment #" + segment + " expecting 0-" + (totalSegments - 1));
        return Intents.RESULT_SMS_HANDLED;
    }
    // Only the first segment contains sourcePort and destination Port
    int sourcePort = 0;
    int destinationPort = 0;
    if (segment == 0) {
        // process WDP segment
        sourcePort = (0xFF & pdu[index++]) << 8;
        sourcePort |= 0xFF & pdu[index++];
        destinationPort = (0xFF & pdu[index++]) << 8;
        destinationPort |= 0xFF & pdu[index++];
        // If configured, check for that here
        if (mCheckForDuplicatePortsInOmadmWapPush) {
            if (checkDuplicatePortOmadmWapPush(pdu, index)) {
                // skip duplicate port fields
                index = index + 4;
            }
        }
    }
    // Lookup all other related parts
    log("Received WAP PDU. Type = " + msgType + ", originator = " + address + ", src-port = " + sourcePort + ", dst-port = " + destinationPort + ", ID = " + referenceNumber + ", segment# = " + segment + '/' + totalSegments);
    // pass the user data portion of the PDU to the shared handler in SMSDispatcher
    byte[] userData = new byte[pdu.length - index];
    System.arraycopy(pdu, index, userData, 0, pdu.length - index);
    InboundSmsTracker tracker = TelephonyComponentFactory.getInstance().inject(InboundSmsTracker.class.getName()).makeInboundSmsTracker(mContext, userData, timestamp, destinationPort, true, address, dispAddr, referenceNumber, segment, totalSegments, true, HexDump.toHexString(userData), false, /* isClass0 */
    mPhone.getSubId());
    // de-duping is done only for text messages
    return addTrackerToRawTableAndSendMessage(tracker, false);
}
Also used : InboundSmsTracker(com.android.internal.telephony.InboundSmsTracker)

Example 2 with InboundSmsTracker

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

the class GsmInboundSmsHandlerTest method testMultiPartSmsWithInvalidSeqNumber.

@Test
@MediumTest
public void testMultiPartSmsWithInvalidSeqNumber() {
    transitionFromStartupToIdle();
    // prepare SMS part 1 and part 2
    prepareMultiPartSms(false);
    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();
    // verify the message is stored in the raw table
    assertEquals(1, mContentProvider.getNumRows());
    // State machine should go back to idle and wait for second part
    assertEquals("IdleState", getCurrentState().getName());
    // change seqNumber in part 2 to an invalid value
    int invalidSeqNumber = -1;
    mInboundSmsTrackerPart2 = new InboundSmsTracker(mContext, mSmsPdu, /* pdu */
    System.currentTimeMillis(), /* timestamp */
    -1, /* destPort */
    false, /* is3gpp2 */
    "1234567890", /* address */
    "1234567890", /* displayAddress */
    1, /* referenceNumber */
    invalidSeqNumber, /* sequenceNumber */
    2, /* messageCount */
    false, /* is3gpp2WapPdu */
    mMessageBodyPart2, /* messageBody */
    false, /* isClass0 */
    mSubId0);
    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 no broadcasts sent
    verify(mContext, never()).sendBroadcast(any(Intent.class));
    // State machine should go back to idle
    assertEquals("IdleState", getCurrentState().getName());
    verifySmsFiltersInvoked(never());
}
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 3 with InboundSmsTracker

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

the class GsmInboundSmsHandlerTest method testMultiPartIncompleteSms.

@Test
@MediumTest
public void testMultiPartIncompleteSms() {
    /**
     * Test scenario: 2 messages are received with same address, ref number, count, and
     * seqNumber, with count = 2 and seqNumber = 1. We should not try to merge these.
     */
    transitionFromStartupToIdle();
    // prepare SMS part 1 and part 2
    prepareMultiPartSms(false);
    // change seqNumber in part 2 to 1
    mInboundSmsTrackerPart2 = new InboundSmsTracker(mContext, mSmsPdu, /* pdu */
    System.currentTimeMillis(), /* timestamp */
    -1, /* destPort */
    false, /* is3gpp2 */
    "1234567890", /* address */
    "1234567890", /* displayAddress */
    1, /* referenceNumber */
    1, /* sequenceNumber */
    2, /* messageCount */
    false, /* is3gpp2WapPdu */
    mMessageBodyPart2, /* 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 no broadcasts sent
    verify(mContext, never()).sendBroadcast(any(Intent.class));
    // verify there's only 1 of the segments in the db (other should be discarded as dup)
    assertEquals(1, mContentProvider.getNumRows());
    // verify the first one is discarded, and second message is present in the db
    Cursor c = mContentProvider.query(sRawUri, null, null, null, null);
    c.moveToFirst();
    assertEquals(mMessageBodyPart2, c.getString(c.getColumnIndex("message_body")));
    // State machine should go back to idle
    assertEquals("IdleState", getCurrentState().getName());
    verifySmsFiltersInvoked(never());
}
Also used : SmsHeader(com.android.internal.telephony.SmsHeader) Context(android.content.Context) Intent(android.content.Intent) Cursor(android.database.Cursor) 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 4 with InboundSmsTracker

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

the class CdmaInboundSmsHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp("CdmaInboundSmsHandlerTest");
    Field field = SmsMessage.class.getDeclaredField("mEnvelope");
    field.setAccessible(true);
    field.set(mCdmaSmsMessage, mSmsEnvelope);
    UserManager userManager = (UserManager) mContextFixture.getTestDouble().getSystemService(Context.USER_SERVICE);
    doReturn(true).when(userManager).isUserUnlocked();
    try {
        doReturn(new int[] { UserHandle.USER_SYSTEM }).when(mIActivityManager).getRunningUserIds();
    } catch (RemoteException re) {
        fail("Unexpected RemoteException: " + re.getStackTrace());
    }
    mSmsMessage.mWrappedSmsMessage = mCdmaSmsMessage;
    doReturn(mSmsPdu).when(mCdmaSmsMessage).getPdu();
    doReturn(true).when(mTelephonyManager).getSmsReceiveCapableForPhone(anyInt(), anyBoolean());
    doReturn(true).when(mSmsStorageMonitor).isStorageAvailable();
    mInboundSmsTracker = new InboundSmsTracker(mContext, mSmsPdu, /* pdu */
    System.currentTimeMillis(), /* timestamp */
    -1, /* destPort */
    true, /* is3gpp2 */
    false, /* is3gpp2WapPdu */
    "1234567890", /* address */
    "1234567890", /* displayAddress */
    "This is the message body of a single-part message", /* 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());
    doReturn(mInboundSmsTracker).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());
    doReturn(mInboundSmsTracker).when(mTelephonyComponentFactory).makeInboundSmsTracker(any(Context.class), nullable(Cursor.class), anyBoolean());
    mContentProvider = new FakeSmsContentProvider();
    ((MockContentResolver) mContext.getContentResolver()).addProvider(Telephony.Sms.CONTENT_URI.getAuthority(), mContentProvider);
    mCdmaInboundSmsHandler = CdmaInboundSmsHandler.makeInboundSmsHandler(mContext, mSmsStorageMonitor, mPhone, null);
    monitorTestableLooper(new TestableLooper(mCdmaInboundSmsHandler.getHandler().getLooper()));
    processAllMessages();
}
Also used : Context(android.content.Context) FakeSmsContentProvider(com.android.internal.telephony.FakeSmsContentProvider) Field(java.lang.reflect.Field) UserManager(android.os.UserManager) RemoteException(android.os.RemoteException) Cursor(android.database.Cursor) MockContentResolver(android.test.mock.MockContentResolver) TestableLooper(android.testing.TestableLooper) InboundSmsTracker(com.android.internal.telephony.InboundSmsTracker) Before(org.junit.Before)

Example 5 with InboundSmsTracker

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

the class CdmaInboundSmsHandlerTest method testNewSmsFromBlockedNumber_noBroadcastsSent.

@FlakyTest
/* flakes 0.43% of the time */
@Test
@MediumTest
public void testNewSmsFromBlockedNumber_noBroadcastsSent() {
    String blockedNumber = "123456789";
    mInboundSmsTracker = new InboundSmsTracker(mContext, mSmsPdu, /* pdu */
    System.currentTimeMillis(), /* timestamp */
    -1, /* destPort */
    true, /* is3gpp2 */
    false, /* is3gpp2WapPdu */
    "1234567890", /* address */
    blockedNumber, /* displayAddress */
    "This is the message body of a single-part message", /* 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());
    mFakeBlockedNumberContentProvider.mBlockedNumbers.add(blockedNumber);
    transitionFromStartupToIdle();
    doReturn(SmsEnvelope.TELESERVICE_WMT).when(mCdmaSmsMessage).getTeleService();
    mCdmaInboundSmsHandler.sendMessage(InboundSmsHandler.EVENT_NEW_SMS, new AsyncResult(null, mSmsMessage, null));
    processAllMessages();
    verify(mContext, never()).sendBroadcast(any(Intent.class));
    assertEquals("IdleState", getCurrentState().getName());
}
Also used : Context(android.content.Context) Intent(android.content.Intent) AsyncResult(android.os.AsyncResult) InboundSmsTracker(com.android.internal.telephony.InboundSmsTracker) FlakyTest(androidx.test.filters.FlakyTest) FlakyTest(androidx.test.filters.FlakyTest) TelephonyTest(com.android.internal.telephony.TelephonyTest) MediumTest(android.test.suitebuilder.annotation.MediumTest) Test(org.junit.Test) MediumTest(android.test.suitebuilder.annotation.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