Search in sources :

Example 6 with CdmaSmsMessage

use of android.hardware.radio.V1_0.CdmaSmsMessage 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)

Example 7 with CdmaSmsMessage

use of android.hardware.radio.V1_0.CdmaSmsMessage in project android_frameworks_opt_telephony by LineageOS.

the class CdmaSmsCbTest method createBroadcastParcel.

/**
 * Initialize a Parcel for an incoming CDMA cell broadcast. The caller will write the
 * bearer data and then convert it to an SmsMessage.
 * @param serviceCategory the CDMA service category
 * @return the initialized Parcel
 */
private static CdmaSmsMessage createBroadcastParcel(int serviceCategory) {
    CdmaSmsMessage msg = new CdmaSmsMessage();
    msg.teleserviceId = SmsEnvelope.TELESERVICE_NOT_SET;
    msg.isServicePresent = true;
    msg.serviceCategory = serviceCategory;
    // dummy address (RIL may generate a different dummy address for broadcasts)
    msg.address.digitMode = CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF;
    msg.address.numberMode = CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK;
    msg.address.numberType = CdmaSmsAddress.TON_UNKNOWN;
    msg.address.numberPlan = CdmaSmsAddress.NUMBERING_PLAN_ISDN_TELEPHONY;
    msg.subAddress.subaddressType = 0;
    msg.subAddress.odd = false;
    return msg;
}
Also used : CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage)

Example 8 with CdmaSmsMessage

use of android.hardware.radio.V1_0.CdmaSmsMessage in project android_frameworks_opt_telephony by LineageOS.

the class CdmaSmsCbTest method createServiceCategoryProgramDataParcel.

/**
 * Initialize a Parcel for incoming Service Category Program Data teleservice. The caller will
 * write the bearer data and then convert it to an SmsMessage.
 * @return the initialized Parcel
 */
private static CdmaSmsMessage createServiceCategoryProgramDataParcel() {
    CdmaSmsMessage msg = new CdmaSmsMessage();
    msg.teleserviceId = SmsEnvelope.TELESERVICE_SCPT;
    msg.isServicePresent = false;
    msg.serviceCategory = 0;
    // dummy address (RIL may generate a different dummy address for broadcasts)
    msg.address.digitMode = CdmaSmsAddress.DIGIT_MODE_4BIT_DTMF;
    msg.address.numberMode = CdmaSmsAddress.NUMBER_MODE_NOT_DATA_NETWORK;
    msg.address.numberType = CdmaSmsAddress.TON_UNKNOWN;
    msg.address.numberPlan = CdmaSmsAddress.NUMBERING_PLAN_ISDN_TELEPHONY;
    msg.subAddress.subaddressType = 0;
    msg.subAddress.odd = false;
    return msg;
}
Also used : CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage)

Example 9 with CdmaSmsMessage

use of android.hardware.radio.V1_0.CdmaSmsMessage 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) FlakyTest(androidx.test.filters.FlakyTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 10 with CdmaSmsMessage

use of android.hardware.radio.V1_0.CdmaSmsMessage 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)

Aggregations

CdmaSmsMessage (android.hardware.radio.V1_0.CdmaSmsMessage)15 FlakyTest (androidx.test.filters.FlakyTest)6 Test (org.junit.Test)6 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 BitwiseOutputStream (com.android.internal.util.BitwiseOutputStream)5 IRadio (android.hardware.radio.V1_0.IRadio)3 RemoteException (android.os.RemoteException)3 SmsCbMessage (android.telephony.SmsCbMessage)3 ImsSmsMessage (android.hardware.radio.V1_0.ImsSmsMessage)2 CdmaSmsCbProgramData (android.telephony.cdma.CdmaSmsCbProgramData)2 Random (java.util.Random)2 AsyncResult (android.os.AsyncResult)1 SmsCbCmasInfo (android.telephony.SmsCbCmasInfo)1 SmsMessage (android.telephony.SmsMessage)1 CdmaSmsAddress (com.android.internal.telephony.cdma.sms.CdmaSmsAddress)1 CdmaSmsSubaddress (com.android.internal.telephony.cdma.sms.CdmaSmsSubaddress)1 SmsEnvelope (com.android.internal.telephony.cdma.sms.SmsEnvelope)1