Search in sources :

Example 46 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream in project android_frameworks_opt_telephony by LineageOS.

the class CdmaSmsCbTest method testServiceCategoryProgramDataAddCategory.

@Test
@SmallTest
public void testServiceCategoryProgramDataAddCategory() throws Exception {
    CdmaSmsMessage cdmaSmsMessage = createServiceCategoryProgramDataParcel();
    BitwiseOutputStream bos = createBearerDataStream(123, -1, -1);
    int categoryNameLength = CAT_EXTREME_THREAT.length();
    int subparamLengthBits = (53 + (categoryNameLength * 7));
    int subparamLengthBytes = (subparamLengthBits + 7) / 8;
    int subparamPadBits = (subparamLengthBytes * 8) - subparamLengthBits;
    bos.write(8, SUBPARAM_SERVICE_CATEGORY_PROGRAM_DATA);
    bos.write(8, subparamLengthBytes);
    bos.write(5, UserData.ENCODING_7BIT_ASCII);
    bos.write(4, CdmaSmsCbProgramData.OPERATION_ADD_CATEGORY);
    bos.write(8, (SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT >>> 8));
    bos.write(8, (SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT & 0xff));
    bos.write(8, BearerData.LANGUAGE_ENGLISH);
    // max messages
    bos.write(8, 100);
    bos.write(4, CdmaSmsCbProgramData.ALERT_OPTION_DEFAULT_ALERT);
    bos.write(8, categoryNameLength);
    for (int i = 0; i < categoryNameLength; i++) {
        bos.write(7, CAT_EXTREME_THREAT.charAt(i));
    }
    bos.write(subparamPadBits, 0);
    SmsMessage msg = createMessageFromParcel(cdmaSmsMessage, bos.toByteArray());
    assertNotNull(msg);
    msg.parseSms();
    List<CdmaSmsCbProgramData> programDataList = msg.getSmsCbProgramData();
    assertNotNull(programDataList);
    assertEquals(1, programDataList.size());
    CdmaSmsCbProgramData programData = programDataList.get(0);
    assertEquals(CdmaSmsCbProgramData.OPERATION_ADD_CATEGORY, programData.getOperation());
    assertEquals(SmsEnvelope.SERVICE_CATEGORY_CMAS_EXTREME_THREAT, programData.getCategory());
    assertEquals(CAT_EXTREME_THREAT, programData.getCategoryName());
    assertEquals(BearerData.LANGUAGE_ENGLISH, programData.getLanguage());
    assertEquals(100, programData.getMaxMessages());
    assertEquals(CdmaSmsCbProgramData.ALERT_OPTION_DEFAULT_ALERT, programData.getAlertOption());
}
Also used : CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage) BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream) CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage) CdmaSmsCbProgramData(android.telephony.cdma.CdmaSmsCbProgramData) SmallTest(android.test.suitebuilder.annotation.SmallTest) FlakyTest(android.support.test.filters.FlakyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 47 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream in project android_frameworks_opt_telephony by LineageOS.

the class CdmaSmsCbTest method testServiceCategoryProgramDataDeleteTwoCategories.

@Test
@SmallTest
public void testServiceCategoryProgramDataDeleteTwoCategories() throws Exception {
    CdmaSmsMessage cdmaSmsMessage = createServiceCategoryProgramDataParcel();
    BitwiseOutputStream bos = createBearerDataStream(456, -1, -1);
    int category1NameLength = CAT_SEVERE_THREAT.length();
    int category2NameLength = CAT_AMBER_ALERTS.length();
    int subparamLengthBits = (101 + (category1NameLength * 7) + (category2NameLength * 7));
    int subparamLengthBytes = (subparamLengthBits + 7) / 8;
    int subparamPadBits = (subparamLengthBytes * 8) - subparamLengthBits;
    bos.write(8, SUBPARAM_SERVICE_CATEGORY_PROGRAM_DATA);
    bos.write(8, subparamLengthBytes);
    bos.write(5, UserData.ENCODING_7BIT_ASCII);
    bos.write(4, CdmaSmsCbProgramData.OPERATION_DELETE_CATEGORY);
    bos.write(8, (SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT >>> 8));
    bos.write(8, (SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT & 0xff));
    bos.write(8, BearerData.LANGUAGE_ENGLISH);
    // max messages
    bos.write(8, 0);
    bos.write(4, CdmaSmsCbProgramData.ALERT_OPTION_NO_ALERT);
    bos.write(8, category1NameLength);
    for (int i = 0; i < category1NameLength; i++) {
        bos.write(7, CAT_SEVERE_THREAT.charAt(i));
    }
    bos.write(4, CdmaSmsCbProgramData.OPERATION_DELETE_CATEGORY);
    bos.write(8, (SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY >>> 8));
    bos.write(8, (SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY & 0xff));
    bos.write(8, BearerData.LANGUAGE_ENGLISH);
    // max messages
    bos.write(8, 0);
    bos.write(4, CdmaSmsCbProgramData.ALERT_OPTION_NO_ALERT);
    bos.write(8, category2NameLength);
    for (int i = 0; i < category2NameLength; i++) {
        bos.write(7, CAT_AMBER_ALERTS.charAt(i));
    }
    bos.write(subparamPadBits, 0);
    SmsMessage msg = createMessageFromParcel(cdmaSmsMessage, bos.toByteArray());
    assertNotNull(msg);
    msg.parseSms();
    List<CdmaSmsCbProgramData> programDataList = msg.getSmsCbProgramData();
    assertNotNull(programDataList);
    assertEquals(2, programDataList.size());
    CdmaSmsCbProgramData programData = programDataList.get(0);
    assertEquals(CdmaSmsCbProgramData.OPERATION_DELETE_CATEGORY, programData.getOperation());
    assertEquals(SmsEnvelope.SERVICE_CATEGORY_CMAS_SEVERE_THREAT, programData.getCategory());
    assertEquals(CAT_SEVERE_THREAT, programData.getCategoryName());
    assertEquals(BearerData.LANGUAGE_ENGLISH, programData.getLanguage());
    assertEquals(0, programData.getMaxMessages());
    assertEquals(CdmaSmsCbProgramData.ALERT_OPTION_NO_ALERT, programData.getAlertOption());
    programData = programDataList.get(1);
    assertEquals(CdmaSmsCbProgramData.OPERATION_DELETE_CATEGORY, programData.getOperation());
    assertEquals(SmsEnvelope.SERVICE_CATEGORY_CMAS_CHILD_ABDUCTION_EMERGENCY, programData.getCategory());
    assertEquals(CAT_AMBER_ALERTS, programData.getCategoryName());
    assertEquals(BearerData.LANGUAGE_ENGLISH, programData.getLanguage());
    assertEquals(0, programData.getMaxMessages());
    assertEquals(CdmaSmsCbProgramData.ALERT_OPTION_NO_ALERT, programData.getAlertOption());
}
Also used : CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage) BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream) CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage) CdmaSmsCbProgramData(android.telephony.cdma.CdmaSmsCbProgramData) SmallTest(android.test.suitebuilder.annotation.SmallTest) FlakyTest(android.support.test.filters.FlakyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 48 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream in project android_frameworks_opt_telephony by LineageOS.

the class CdmaSmsCbTest method createBroadcastSmsMessage.

/**
 * Create a parcel for an incoming CDMA cell broadcast, then return a new SmsMessage created
 * from the parcel.
 * @param serviceCategory the CDMA service category
 * @param messageId the 16-bit message identifier
 * @param priority message priority
 * @param language message language code
 * @param encoding user data encoding method
 * @param body the message body
 * @return the newly created SmsMessage object
 */
private static SmsMessage createBroadcastSmsMessage(int serviceCategory, int messageId, int priority, int language, int encoding, String body) throws Exception {
    CdmaSmsMessage msg = createBroadcastParcel(serviceCategory);
    BitwiseOutputStream bos = createBearerDataStream(messageId, priority, language);
    bos.write(8, SUBPARAM_USER_DATA);
    encodeBody(encoding, body, false, bos);
    return createMessageFromParcel(msg, bos.toByteArray());
}
Also used : CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage) BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream)

Example 49 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream in project android_frameworks_opt_telephony by LineageOS.

the class CdmaSmsCbTest method createCmasSmsMessage.

/**
 * Create a parcel for an incoming CMAS broadcast, then return a new SmsMessage created
 * from the parcel.
 * @param serviceCategory the CDMA service category
 * @param messageId the 16-bit message identifier
 * @param priority message priority
 * @param language message language code
 * @param body message body
 * @param cmasCategory CMAS category (or -1 to skip adding CMAS type 1 elements record)
 * @param responseType CMAS response type
 * @param severity CMAS severity
 * @param urgency CMAS urgency
 * @param certainty CMAS certainty
 * @return the newly created SmsMessage object
 */
private static SmsMessage createCmasSmsMessage(int serviceCategory, int messageId, int priority, int language, int encoding, String body, int cmasCategory, int responseType, int severity, int urgency, int certainty) throws Exception {
    BitwiseOutputStream cmasBos = new BitwiseOutputStream(10);
    // CMAE protocol version 0
    cmasBos.write(8, 0);
    if (body != null) {
        // Type 0 elements (alert text)
        cmasBos.write(8, 0);
        encodeBody(encoding, body, true, cmasBos);
    }
    if (cmasCategory != SmsCbCmasInfo.CMAS_CATEGORY_UNKNOWN) {
        // Type 1 elements
        cmasBos.write(8, 1);
        // length: 4 bytes
        cmasBos.write(8, 4);
        cmasBos.write(8, (cmasCategory & 0xff));
        cmasBos.write(8, (responseType & 0xff));
        cmasBos.write(4, (severity & 0x0f));
        cmasBos.write(4, (urgency & 0x0f));
        cmasBos.write(4, (certainty & 0x0f));
        // pad to octet boundary
        cmasBos.write(4, 0);
    }
    byte[] cmasUserData = cmasBos.toByteArray();
    CdmaSmsMessage msg = createBroadcastParcel(serviceCategory);
    BitwiseOutputStream bos = createBearerDataStream(messageId, priority, language);
    bos.write(8, SUBPARAM_USER_DATA);
    // add 2 bytes for msg_encoding and num_fields
    bos.write(8, cmasUserData.length + 2);
    bos.write(5, UserData.ENCODING_OCTET);
    bos.write(8, cmasUserData.length);
    bos.writeByteArray(cmasUserData.length * 8, cmasUserData);
    // pad to byte boundary
    bos.write(3, 0);
    return createMessageFromParcel(msg, bos.toByteArray());
}
Also used : CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage) BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream)

Example 50 with BitwiseOutputStream

use of com.android.internal.util.BitwiseOutputStream 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();
        } 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) SmallTest(android.test.suitebuilder.annotation.SmallTest) FlakyTest(android.support.test.filters.FlakyTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

BitwiseOutputStream (com.android.internal.util.BitwiseOutputStream)50 SmallTest (android.test.suitebuilder.annotation.SmallTest)45 BitwiseInputStream (com.android.internal.util.BitwiseInputStream)42 Random (java.util.Random)13 CdmaSmsMessage (android.hardware.radio.V1_0.CdmaSmsMessage)5 FlakyTest (android.support.test.filters.FlakyTest)3 Test (org.junit.Test)3 CdmaSmsCbProgramData (android.telephony.cdma.CdmaSmsCbProgramData)2 SmsCbMessage (android.telephony.SmsCbMessage)1