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);
}
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());
}
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());
}
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();
}
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());
}
Aggregations