Search in sources :

Example 6 with BitwiseInputStream

use of com.android.internal.util.BitwiseInputStream in project platform_frameworks_base by android.

the class BitwiseStreamsTest method testThree.

@SmallTest
public void testThree() throws Exception {
    int offset = 4;
    byte[] inBuf = HexDump.hexStringToByteArray("00031040900112488ea794e0");
    BitwiseOutputStream outStream = new BitwiseOutputStream(30);
    outStream.skip(offset);
    for (int i = 0; i < inBuf.length; i++) outStream.write(8, inBuf[i]);
    BitwiseInputStream inStream = new BitwiseInputStream(outStream.toByteArray());
    inStream.skip(offset);
    byte[] inBufDup = new byte[inBuf.length];
    for (int i = 0; i < inBufDup.length; i++) inBufDup[i] = (byte) inStream.read(8);
    assertEquals(HexDump.toHexString(inBuf), HexDump.toHexString(inBufDup));
}
Also used : BitwiseOutputStream(com.android.internal.util.BitwiseOutputStream) BitwiseInputStream(com.android.internal.util.BitwiseInputStream) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 7 with BitwiseInputStream

use of com.android.internal.util.BitwiseInputStream in project XobotOS by xamarin.

the class BearerData method decodeIs91VoicemailStatus.

/**
     * IS-91 Voice Mail message decoding
     * (See 3GPP2 C.S0015-A, Table 4.3.1.4.1-1)
     * (For character encodings, see TIA/EIA/IS-91, Annex B)
     *
     * Protocol Summary: The user data payload may contain 3-14
     * characters.  The first two characters are parsed as a number
     * and indicate the number of voicemails.  The third character is
     * either a SPACE or '!' to indicate normal or urgent priority,
     * respectively.  Any following characters are treated as normal
     * text user data payload.
     *
     * Note that the characters encoding is 6-bit packed.
     */
private static void decodeIs91VoicemailStatus(BearerData bData) throws BitwiseInputStream.AccessException, CodingException {
    BitwiseInputStream inStream = new BitwiseInputStream(bData.userData.payload);
    // 6-bit packed character encoding.
    int dataLen = inStream.available() / 6;
    int numFields = bData.userData.numFields;
    if ((dataLen > 14) || (dataLen < 3) || (dataLen < numFields)) {
        throw new CodingException("IS-91 voicemail status decoding failed");
    }
    try {
        StringBuffer strbuf = new StringBuffer(dataLen);
        while (inStream.available() >= 6) {
            strbuf.append(UserData.ASCII_MAP[inStream.read(6)]);
        }
        String data = strbuf.toString();
        bData.numberOfMessages = Integer.parseInt(data.substring(0, 2));
        char prioCode = data.charAt(2);
        if (prioCode == ' ') {
            bData.priority = PRIORITY_NORMAL;
        } else if (prioCode == '!') {
            bData.priority = PRIORITY_URGENT;
        } else {
            throw new CodingException("IS-91 voicemail status decoding failed: " + "illegal priority setting (" + prioCode + ")");
        }
        bData.priorityIndicatorSet = true;
        bData.userData.payloadStr = data.substring(3, numFields - 3);
    } catch (java.lang.NumberFormatException ex) {
        throw new CodingException("IS-91 voicemail status decoding failed: " + ex);
    } catch (java.lang.IndexOutOfBoundsException ex) {
        throw new CodingException("IS-91 voicemail status decoding failed: " + ex);
    }
}
Also used : BitwiseInputStream(com.android.internal.util.BitwiseInputStream)

Example 8 with BitwiseInputStream

use of com.android.internal.util.BitwiseInputStream in project XobotOS by xamarin.

the class BearerData method decodeIs91ShortMessage.

/**
     * IS-91 Short Message decoding
     * (See 3GPP2 C.S0015-A, Table 4.3.1.4.1-1)
     * (For character encodings, see TIA/EIA/IS-91, Annex B)
     *
     * Protocol Summary: The user data payload may contain 1-14
     * characters, which are treated as normal text user data payload.
     * Note that the characters encoding is 6-bit packed.
     */
private static void decodeIs91ShortMessage(BearerData bData) throws BitwiseInputStream.AccessException, CodingException {
    BitwiseInputStream inStream = new BitwiseInputStream(bData.userData.payload);
    // 6-bit packed character encoding.
    int dataLen = inStream.available() / 6;
    int numFields = bData.userData.numFields;
    if ((dataLen > 14) || (dataLen < numFields)) {
        throw new CodingException("IS-91 voicemail status decoding failed");
    }
    StringBuffer strbuf = new StringBuffer(dataLen);
    for (int i = 0; i < numFields; i++) {
        strbuf.append(UserData.ASCII_MAP[inStream.read(6)]);
    }
    bData.userData.payloadStr = strbuf.toString();
}
Also used : BitwiseInputStream(com.android.internal.util.BitwiseInputStream)

Example 9 with BitwiseInputStream

use of com.android.internal.util.BitwiseInputStream in project XobotOS by xamarin.

the class BearerData method decode.

/**
     * Create BearerData object from serialized representation.
     * (See 3GPP2 C.R1001-F, v1.0, section 4.5 for layout details)
     *
     * @param smsData byte array of raw encoded SMS bearer data.
     *
     * @return an instance of BearerData.
     */
public static BearerData decode(byte[] smsData) {
    try {
        BitwiseInputStream inStream = new BitwiseInputStream(smsData);
        BearerData bData = new BearerData();
        int foundSubparamMask = 0;
        while (inStream.available() > 0) {
            boolean decodeSuccess = false;
            int subparamId = inStream.read(8);
            int subparamIdBit = 1 << subparamId;
            if ((foundSubparamMask & subparamIdBit) != 0) {
                throw new CodingException("illegal duplicate subparameter (" + subparamId + ")");
            }
            switch(subparamId) {
                case SUBPARAM_MESSAGE_IDENTIFIER:
                    decodeSuccess = decodeMessageId(bData, inStream);
                    break;
                case SUBPARAM_USER_DATA:
                    decodeSuccess = decodeUserData(bData, inStream);
                    break;
                case SUBPARAM_USER_RESPONSE_CODE:
                    decodeSuccess = decodeUserResponseCode(bData, inStream);
                    break;
                case SUBPARAM_REPLY_OPTION:
                    decodeSuccess = decodeReplyOption(bData, inStream);
                    break;
                case SUBPARAM_NUMBER_OF_MESSAGES:
                    decodeSuccess = decodeMsgCount(bData, inStream);
                    break;
                case SUBPARAM_CALLBACK_NUMBER:
                    decodeSuccess = decodeCallbackNumber(bData, inStream);
                    break;
                case SUBPARAM_MESSAGE_STATUS:
                    decodeSuccess = decodeMsgStatus(bData, inStream);
                    break;
                case SUBPARAM_MESSAGE_CENTER_TIME_STAMP:
                    decodeSuccess = decodeMsgCenterTimeStamp(bData, inStream);
                    break;
                case SUBPARAM_VALIDITY_PERIOD_ABSOLUTE:
                    decodeSuccess = decodeValidityAbs(bData, inStream);
                    break;
                case SUBPARAM_VALIDITY_PERIOD_RELATIVE:
                    decodeSuccess = decodeValidityRel(bData, inStream);
                    break;
                case SUBPARAM_DEFERRED_DELIVERY_TIME_ABSOLUTE:
                    decodeSuccess = decodeDeferredDeliveryAbs(bData, inStream);
                    break;
                case SUBPARAM_DEFERRED_DELIVERY_TIME_RELATIVE:
                    decodeSuccess = decodeDeferredDeliveryRel(bData, inStream);
                    break;
                case SUBPARAM_PRIVACY_INDICATOR:
                    decodeSuccess = decodePrivacyIndicator(bData, inStream);
                    break;
                case SUBPARAM_LANGUAGE_INDICATOR:
                    decodeSuccess = decodeLanguageIndicator(bData, inStream);
                    break;
                case SUBPARAM_MESSAGE_DISPLAY_MODE:
                    decodeSuccess = decodeDisplayMode(bData, inStream);
                    break;
                case SUBPARAM_PRIORITY_INDICATOR:
                    decodeSuccess = decodePriorityIndicator(bData, inStream);
                    break;
                case SUBPARAM_ALERT_ON_MESSAGE_DELIVERY:
                    decodeSuccess = decodeMsgDeliveryAlert(bData, inStream);
                    break;
                case SUBPARAM_MESSAGE_DEPOSIT_INDEX:
                    decodeSuccess = decodeDepositIndex(bData, inStream);
                    break;
                default:
                    throw new CodingException("unsupported bearer data subparameter (" + subparamId + ")");
            }
            if (decodeSuccess)
                foundSubparamMask |= subparamIdBit;
        }
        if ((foundSubparamMask & (1 << SUBPARAM_MESSAGE_IDENTIFIER)) == 0) {
            throw new CodingException("missing MESSAGE_IDENTIFIER subparam");
        }
        if (bData.userData != null) {
            if (bData.userData.msgEncoding == UserData.ENCODING_IS91_EXTENDED_PROTOCOL) {
                if ((foundSubparamMask ^ (1 << SUBPARAM_MESSAGE_IDENTIFIER) ^ (1 << SUBPARAM_USER_DATA)) != 0) {
                    Log.e(LOG_TAG, "IS-91 must occur without extra subparams (" + foundSubparamMask + ")");
                }
                decodeIs91(bData);
            } else {
                decodeUserDataPayload(bData.userData, bData.hasUserDataHeader);
            }
        }
        return bData;
    } catch (BitwiseInputStream.AccessException ex) {
        Log.e(LOG_TAG, "BearerData decode failed: " + ex);
    } catch (CodingException ex) {
        Log.e(LOG_TAG, "BearerData decode failed: " + ex);
    }
    return null;
}
Also used : BitwiseInputStream(com.android.internal.util.BitwiseInputStream)

Example 10 with BitwiseInputStream

use of com.android.internal.util.BitwiseInputStream in project XobotOS by xamarin.

the class BearerData method decode7bitAscii.

private static String decode7bitAscii(byte[] data, int offset, int numFields) throws CodingException {
    try {
        offset *= 8;
        StringBuffer strBuf = new StringBuffer(numFields);
        BitwiseInputStream inStream = new BitwiseInputStream(data);
        int wantedBits = (offset * 8) + (numFields * 7);
        if (inStream.available() < wantedBits) {
            throw new CodingException("insufficient data (wanted " + wantedBits + " bits, but only have " + inStream.available() + ")");
        }
        inStream.skip(offset);
        for (int i = 0; i < numFields; i++) {
            int charCode = inStream.read(7);
            if ((charCode >= UserData.ASCII_MAP_BASE_INDEX) && (charCode <= UserData.ASCII_MAP_MAX_INDEX)) {
                strBuf.append(UserData.ASCII_MAP[charCode - UserData.ASCII_MAP_BASE_INDEX]);
            } else if (charCode == UserData.ASCII_NL_INDEX) {
                strBuf.append('\n');
            } else if (charCode == UserData.ASCII_CR_INDEX) {
                strBuf.append('\r');
            } else {
                /* For other charCodes, they are unprintable, and so simply use SPACE. */
                strBuf.append(' ');
            }
        }
        return strBuf.toString();
    } catch (BitwiseInputStream.AccessException ex) {
        throw new CodingException("7bit ASCII decode failed: " + ex);
    }
}
Also used : BitwiseInputStream(com.android.internal.util.BitwiseInputStream)

Aggregations

BitwiseInputStream (com.android.internal.util.BitwiseInputStream)48 SmallTest (android.test.suitebuilder.annotation.SmallTest)42 BitwiseOutputStream (com.android.internal.util.BitwiseOutputStream)42 Random (java.util.Random)12 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 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1