Search in sources :

Example 36 with SmsCbMessage

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

the class CdmaSmsCbTest method testRandomUserData.

// Make sure we don't throw an exception if we put random data in the UserData subparam.
@Test
@SmallTest
public void testRandomUserData() {
    Random r = new Random(94040);
    for (int run = 0; run < 1000; run++) {
        // half CMAS, half non-CMAS
        int category = 0x0ff0 + r.nextInt(32);
        CdmaSmsMessage cdmaSmsMessage = createBroadcastParcel(category);
        int len = r.nextInt(140);
        try {
            BitwiseOutputStream bos = createBearerDataStream(r.nextInt(65536), r.nextInt(4), r.nextInt(256));
            bos.write(8, SUBPARAM_USER_DATA);
            bos.write(8, len);
            for (int i = 0; i < len; i++) {
                bos.write(8, r.nextInt(256));
            }
            SmsMessage msg = createMessageFromParcel(cdmaSmsMessage, bos.toByteArray());
            SmsCbMessage cbMessage = msg.parseBroadcastSms("", 0, 1);
        } 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) BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream) 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)

Example 37 with SmsCbMessage

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

the class CdmaSmsCbTest method testCmasExtremeAlertType1Elements.

@Test
@SmallTest
public void testCmasExtremeAlertType1Elements() throws Exception {
    SmsMessage msg = createCmasSmsMessage(SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT, 5678, BearerData.PRIORITY_EMERGENCY, BearerData.LANGUAGE_ENGLISH, UserData.ENCODING_7BIT_ASCII, EXTREME_ALERT, SmsCbCmasInfo.CMAS_CATEGORY_ENV, SmsCbCmasInfo.CMAS_RESPONSE_TYPE_MONITOR, SmsCbCmasInfo.CMAS_SEVERITY_SEVERE, SmsCbCmasInfo.CMAS_URGENCY_EXPECTED, SmsCbCmasInfo.CMAS_CERTAINTY_LIKELY);
    SmsCbMessage cbMessage = msg.parseBroadcastSms("", 0, 1);
    verifyCbValues(cbMessage);
    assertEquals(SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT, cbMessage.getServiceCategory());
    assertEquals(5678, cbMessage.getSerialNumber());
    assertEquals(SmsCbMessage.MESSAGE_PRIORITY_EMERGENCY, cbMessage.getMessagePriority());
    assertEquals("en", cbMessage.getLanguageCode());
    assertEquals(EXTREME_ALERT, cbMessage.getMessageBody());
    assertEquals(true, cbMessage.isEmergencyMessage());
    assertEquals(true, cbMessage.isCmasMessage());
    SmsCbCmasInfo cmasInfo = cbMessage.getCmasWarningInfo();
    assertEquals(SmsCbCmasInfo.CMAS_CLASS_EXTREME_THREAT, cmasInfo.getMessageClass());
    assertEquals(SmsCbCmasInfo.CMAS_CATEGORY_ENV, cmasInfo.getCategory());
    assertEquals(SmsCbCmasInfo.CMAS_RESPONSE_TYPE_MONITOR, cmasInfo.getResponseType());
    assertEquals(SmsCbCmasInfo.CMAS_SEVERITY_SEVERE, cmasInfo.getSeverity());
    assertEquals(SmsCbCmasInfo.CMAS_URGENCY_EXPECTED, cmasInfo.getUrgency());
    assertEquals(SmsCbCmasInfo.CMAS_CERTAINTY_LIKELY, cmasInfo.getCertainty());
}
Also used : 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 38 with SmsCbMessage

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

the class CdmaSmsCbTest method testCmasUnsupportedCharSet2.

// VZW requirement is to discard message with unsupported charset. Verify that we return null
// for this unsupported character set.
@Test
@SmallTest
public void testCmasUnsupportedCharSet2() throws Exception {
    SmsMessage msg = createCmasSmsMessage(SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT, 67890, BearerData.PRIORITY_EMERGENCY, BearerData.LANGUAGE_ENGLISH, UserData.ENCODING_KOREAN, EXTREME_ALERT, -1, -1, -1, -1, -1);
    SmsCbMessage cbMessage = msg.parseBroadcastSms("", 0, 1);
    assertNull("expected null for unsupported charset", cbMessage);
}
Also used : CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage) 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)

Example 39 with SmsCbMessage

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

the class CdmaSmsCbTest method testCmasNoRecordType0.

// VZW requirement is to discard message without record type 0. The framework will decode it
// and the app will discard it.
@Test
@SmallTest
public void testCmasNoRecordType0() throws Exception {
    SmsMessage msg = createCmasSmsMessage(SmsEnvelope.SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT, 1234, BearerData.PRIORITY_EMERGENCY, BearerData.LANGUAGE_ENGLISH, UserData.ENCODING_7BIT_ASCII, null, -1, -1, -1, -1, -1);
    SmsCbMessage cbMessage = msg.parseBroadcastSms("", 0, 1);
    verifyCbValues(cbMessage);
    assertEquals(SmsEnvelope.SERVICE_CATEGORY_CMAS_PRESIDENTIAL_LEVEL_ALERT, cbMessage.getServiceCategory());
    assertEquals(1234, cbMessage.getSerialNumber());
    assertEquals(SmsCbMessage.MESSAGE_PRIORITY_EMERGENCY, cbMessage.getMessagePriority());
    assertEquals("en", cbMessage.getLanguageCode());
    assertEquals(null, cbMessage.getMessageBody());
    assertEquals(true, cbMessage.isEmergencyMessage());
    assertEquals(true, cbMessage.isCmasMessage());
    SmsCbCmasInfo cmasInfo = cbMessage.getCmasWarningInfo();
    assertEquals(SmsCbCmasInfo.CMAS_CLASS_PRESIDENTIAL_LEVEL_ALERT, cmasInfo.getMessageClass());
    assertEquals(SmsCbCmasInfo.CMAS_CATEGORY_UNKNOWN, cmasInfo.getCategory());
    assertEquals(SmsCbCmasInfo.CMAS_RESPONSE_TYPE_UNKNOWN, cmasInfo.getResponseType());
    assertEquals(SmsCbCmasInfo.CMAS_SEVERITY_UNKNOWN, cmasInfo.getSeverity());
    assertEquals(SmsCbCmasInfo.CMAS_URGENCY_UNKNOWN, cmasInfo.getUrgency());
    assertEquals(SmsCbCmasInfo.CMAS_CERTAINTY_UNKNOWN, cmasInfo.getCertainty());
}
Also used : 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)

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