Search in sources :

Example 11 with SmsCbMessage

use of android.telephony.SmsCbMessage in project android_frameworks_opt_telephony by LineageOS.

the class GsmSmsCbTest method testGetMessageCodeUmts.

@Test
@SmallTest
public void testGetMessageCodeUmts() {
    byte[] pdu = { (byte) 0x01, (byte) 0x30, (byte) 0x39, (byte) 0x2A, (byte) 0xA5, (byte) 0x40, (byte) 0x01, (byte) 0x41, (byte) 0xD0, (byte) 0x71, (byte) 0xDA, (byte) 0x04, (byte) 0x91, (byte) 0xCB, (byte) 0xE6, (byte) 0x70, (byte) 0x9D, (byte) 0x4D, (byte) 0x07, (byte) 0x85, (byte) 0xD9, (byte) 0x70, (byte) 0x74, (byte) 0x58, (byte) 0x5C, (byte) 0xA6, (byte) 0x83, (byte) 0xDA, (byte) 0xE5, (byte) 0xF9, (byte) 0x3C, (byte) 0x7C, (byte) 0x2E, (byte) 0x83, (byte) 0xEE, (byte) 0x69, (byte) 0x3A, (byte) 0x1A, (byte) 0x34, (byte) 0x0E, (byte) 0xCB, (byte) 0xE5, (byte) 0xE9, (byte) 0xF0, (byte) 0xB9, (byte) 0x0C, (byte) 0x92, (byte) 0x97, (byte) 0xE9, (byte) 0x75, (byte) 0xB9, (byte) 0x1B, (byte) 0x04, (byte) 0x0F, (byte) 0x93, (byte) 0xC9, (byte) 0x69, (byte) 0xF7, (byte) 0xB9, (byte) 0xD1, (byte) 0x68, (byte) 0x34, (byte) 0x1A, (byte) 0x8D, (byte) 0x46, (byte) 0xA3, (byte) 0xD1, (byte) 0x68, (byte) 0x34, (byte) 0x1A, (byte) 0x8D, (byte) 0x46, (byte) 0xA3, (byte) 0xD1, (byte) 0x68, (byte) 0x34, (byte) 0x1A, (byte) 0x8D, (byte) 0x46, (byte) 0xA3, (byte) 0xD1, (byte) 0x68, (byte) 0x34, (byte) 0x1A, (byte) 0x8D, (byte) 0x46, (byte) 0xA3, (byte) 0xD1, (byte) 0x00, (byte) 0x34 };
    SmsCbMessage msg = createFromPdu(pdu);
    int messageCode = (msg.getSerialNumber() & 0x3ff0) >> 4;
    assertEquals("Unexpected message code decoded", 682, messageCode);
}
Also used : SmsCbMessage(android.telephony.SmsCbMessage) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 12 with SmsCbMessage

use of android.telephony.SmsCbMessage in project android_frameworks_opt_telephony by LineageOS.

the class GsmSmsCbTest method testGetMessageBody8Bit.

@Test
@SmallTest
public void testGetMessageBody8Bit() {
    byte[] pdu = { (byte) 0xC0, (byte) 0x00, (byte) 0x00, (byte) 0x32, (byte) 0x44, (byte) 0x11, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46, (byte) 0x47, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45 };
    SmsCbMessage msg = createFromPdu(pdu);
    assertEquals("8-bit message body should be empty", "", msg.getMessageBody());
}
Also used : SmsCbMessage(android.telephony.SmsCbMessage) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 13 with SmsCbMessage

use of android.telephony.SmsCbMessage in project android_frameworks_opt_telephony by LineageOS.

the class CdmaSmsCbTest method testDecodeRawBearerData.

// Test case for CMAS test message received on the Sprint network.
@Test
@SmallTest
public void testDecodeRawBearerData() throws Exception {
    CdmaSmsMessage cdmaSmsMessage = createBroadcastParcel(SmsEnvelope.SERVICE_CATEGORY_CMAS_TEST_MESSAGE);
    SmsMessage msg = createMessageFromParcel(cdmaSmsMessage, CMAS_TEST_BEARER_DATA);
    SmsCbMessage cbMessage = msg.parseBroadcastSms("", 0, 1);
    assertNotNull("expected non-null for bearer data", cbMessage);
    assertEquals("geoScope", cbMessage.getGeographicalScope(), 1);
    assertEquals("serialNumber", cbMessage.getSerialNumber(), 51072);
    assertEquals("serviceCategory", cbMessage.getServiceCategory(), SmsEnvelope.SERVICE_CATEGORY_CMAS_TEST_MESSAGE);
    assertEquals("payload", cbMessage.getMessageBody(), "This is a test of the Commercial Mobile Alert System. This is only a test.");
    SmsCbCmasInfo cmasInfo = cbMessage.getCmasWarningInfo();
    assertNotNull("expected non-null for CMAS info", cmasInfo);
    assertEquals("category", cmasInfo.getCategory(), SmsCbCmasInfo.CMAS_CATEGORY_OTHER);
    assertEquals("responseType", cmasInfo.getResponseType(), SmsCbCmasInfo.CMAS_RESPONSE_TYPE_NONE);
    assertEquals("severity", cmasInfo.getSeverity(), SmsCbCmasInfo.CMAS_SEVERITY_SEVERE);
    assertEquals("urgency", cmasInfo.getUrgency(), SmsCbCmasInfo.CMAS_URGENCY_EXPECTED);
    assertEquals("certainty", cmasInfo.getCertainty(), SmsCbCmasInfo.CMAS_CERTAINTY_LIKELY);
}
Also used : CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage) CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage) SmsCbMessage(android.telephony.SmsCbMessage) SmsCbCmasInfo(android.telephony.SmsCbCmasInfo) FlakyTest(androidx.test.filters.FlakyTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 14 with SmsCbMessage

use of android.telephony.SmsCbMessage in project android_frameworks_opt_telephony by LineageOS.

the class CdmaSmsCbTest method doTestNonEmergencyBroadcast.

private static void doTestNonEmergencyBroadcast(int encoding) throws Exception {
    SmsMessage msg = createBroadcastSmsMessage(123, 456, BearerData.PRIORITY_NORMAL, BearerData.LANGUAGE_ENGLISH, encoding, TEST_TEXT);
    SmsCbMessage cbMessage = msg.parseBroadcastSms("", 0, 1);
    verifyCbValues(cbMessage);
    assertEquals(123, cbMessage.getServiceCategory());
    assertEquals(456, cbMessage.getSerialNumber());
    assertEquals(SmsCbMessage.MESSAGE_PRIORITY_NORMAL, cbMessage.getMessagePriority());
    assertEquals("en", cbMessage.getLanguageCode());
    assertEquals(TEST_TEXT, cbMessage.getMessageBody());
    assertEquals(false, cbMessage.isEmergencyMessage());
    assertEquals(false, cbMessage.isCmasMessage());
}
Also used : CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage) SmsCbMessage(android.telephony.SmsCbMessage)

Example 15 with SmsCbMessage

use of android.telephony.SmsCbMessage in project android_frameworks_opt_telephony by LineageOS.

the class CdmaSmsCbTest method testRandomBearerStreamData.

// Make sure we don't throw an exception if we feed completely random data to BearerStream.
@Test
@SmallTest
public void testRandomBearerStreamData() {
    Random r = new Random(54321);
    for (int run = 0; run < 1000; run++) {
        int len = r.nextInt(140);
        byte[] data = new byte[len];
        for (int i = 0; i < len; i++) {
            data[i] = (byte) r.nextInt(256);
        }
        // Rlog.d("CdmaSmsCbTest", "trying random bearer data run " + run + " length " + len);
        try {
            // half CMAS, half non-CMAS
            int category = 0x0ff0 + r.nextInt(32);
            CdmaSmsMessage cdmaSmsMessage = createBroadcastParcel(category);
            SmsMessage msg = createMessageFromParcel(cdmaSmsMessage, data);
            SmsCbMessage cbMessage = msg.parseBroadcastSms("", 0, 1);
            // with random input, cbMessage will almost always be null (log when it isn't)
            if (cbMessage != null) {
                Rlog.d("CdmaSmsCbTest", "success: " + cbMessage);
            }
        } catch (Exception e) {
            Rlog.d("CdmaSmsCbTest", "exception thrown", e);
            fail("Exception in decoder at run " + run + " length " + len + ": " + e);
        }
    }
}
Also used : CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage) CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage) Random(java.util.Random) SmsCbMessage(android.telephony.SmsCbMessage) FlakyTest(androidx.test.filters.FlakyTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

SmsCbMessage (android.telephony.SmsCbMessage)39 SmallTest (android.test.suitebuilder.annotation.SmallTest)35 Test (org.junit.Test)35 CdmaSmsMessage (android.hardware.radio.V1_0.CdmaSmsMessage)10 FlakyTest (androidx.test.filters.FlakyTest)8 SmsCbCmasInfo (android.telephony.SmsCbCmasInfo)4 Random (java.util.Random)3 BitwiseOutputStream (com.android.internal.util.BitwiseOutputStream)1 Ignore (org.junit.Ignore)1