Search in sources :

Example 11 with CdmaSmsMessage

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

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

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

Example 14 with CdmaSmsMessage

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

the class RIL method sendCdmaSms.

@Override
public void sendCdmaSms(byte[] pdu, Message result) {
    IRadio radioProxy = getRadioProxy(result);
    if (radioProxy != null) {
        RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SEND_SMS, result, mRILDefaultWorkSource);
        // Do not log function arg for privacy
        if (RILJ_LOGD)
            riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
        CdmaSmsMessage msg = new CdmaSmsMessage();
        constructCdmaSendSmsRilRequest(msg, pdu);
        try {
            radioProxy.sendCdmaSms(rr.mSerial, msg);
            mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_CDMA, SmsSession.Event.Format.SMS_FORMAT_3GPP2);
        } catch (RemoteException | RuntimeException e) {
            handleRadioProxyExceptionForRR(rr, "sendCdmaSms", e);
        }
    }
}
Also used : IRadio(android.hardware.radio.V1_0.IRadio) CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage) RemoteException(android.os.RemoteException)

Example 15 with CdmaSmsMessage

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

the class RIL method sendCdmaSMSExpectMore.

@Override
public void sendCdmaSMSExpectMore(byte[] pdu, Message result) {
    if (mRadioVersion.greaterOrEqual(RADIO_HAL_VERSION_1_5)) {
        IRadio radioProxy = getRadioProxy(result);
        // IRadio V1.5
        android.hardware.radio.V1_5.IRadio radioProxy15 = (android.hardware.radio.V1_5.IRadio) radioProxy;
        if (radioProxy15 != null) {
            RILRequest rr = obtainRequest(RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE, result, mRILDefaultWorkSource);
            // Do not log function arg for privacy
            if (RILJ_LOGD)
                riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));
            CdmaSmsMessage msg = new CdmaSmsMessage();
            constructCdmaSendSmsRilRequest(msg, pdu);
            try {
                radioProxy15.sendCdmaSmsExpectMore(rr.mSerial, msg);
                mMetrics.writeRilSendSms(mPhoneId, rr.mSerial, SmsSession.Event.Tech.SMS_CDMA, SmsSession.Event.Format.SMS_FORMAT_3GPP2);
            } catch (RemoteException | RuntimeException e) {
                handleRadioProxyExceptionForRR(rr, "sendCdmaSMSExpectMore", e);
            }
        }
    } else {
        sendCdmaSms(pdu, result);
    }
}
Also used : IRadio(android.hardware.radio.V1_0.IRadio) CdmaSmsMessage(android.hardware.radio.V1_0.CdmaSmsMessage) RemoteException(android.os.RemoteException)

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