FileDocCategorySizeDatePackage
WspTypeDecoder.javaAPI DocAndroid 1.5 API12132Wed May 06 22:42:02 BST 2009com.android.internal.telephony

WspTypeDecoder

public class WspTypeDecoder extends Object
Implement the WSP data type decoder.
hide

Fields Summary
private static final int
WAP_PDU_SHORT_LENGTH_MAX
private static final int
WAP_PDU_LENGTH_QUOTE
public static final int
PDU_TYPE_PUSH
public static final int
PDU_TYPE_CONFIRMED_PUSH
public static final int
CONTENT_TYPE_B_DRM_RIGHTS_XML
public static final int
CONTENT_TYPE_B_DRM_RIGHTS_WBXML
public static final int
CONTENT_TYPE_B_PUSH_SI
public static final int
CONTENT_TYPE_B_PUSH_SL
public static final int
CONTENT_TYPE_B_PUSH_CO
public static final int
CONTENT_TYPE_B_MMS
public static final String
CONTENT_MIME_TYPE_B_DRM_RIGHTS_XML
public static final String
CONTENT_MIME_TYPE_B_DRM_RIGHTS_WBXML
public static final String
CONTENT_MIME_TYPE_B_PUSH_SI
public static final String
CONTENT_MIME_TYPE_B_PUSH_SL
public static final String
CONTENT_MIME_TYPE_B_PUSH_CO
public static final String
CONTENT_MIME_TYPE_B_MMS
public static final int
PARAMETER_ID_X_WAP_APPLICATION_ID
byte[]
wspData
int
dataLength
long
unsigned32bit
String
stringValue
Constructors Summary
public WspTypeDecoder(byte[] pdu)


       
        wspData = pdu;
    
Methods Summary
public booleandecodeConstrainedEncoding(int startIndex)
Decode the "Constrained-encoding" type for WSP pdu

param
startIndex The starting position of the "Constrained-encoding" in this pdu
return
false when error(not a Constrained-encoding) occur return value can be retrieved first by getValueString() and second by getValue32() method length of data in pdu can be retrieved by getValue32() method

        if (decodeShortInteger(startIndex) == true) {
            stringValue = null;
            return true;
        }
        return decodeExtensionMedia(startIndex);
    
public booleandecodeContentLength(int startIndex)
Decode the "Content length" type for WSP pdu

param
startIndex The starting position of the "Content length" in this pdu
return
false when error(not a Content length) occur return value can be retrieved by getValue32() method length of data in pdu can be retrieved by getValue32() method

        return decodeIntegerValue(startIndex);
    
public booleandecodeContentLocation(int startIndex)
Decode the "Content location" type for WSP pdu

param
startIndex The starting position of the "Content location" in this pdu
return
false when error(not a Content location) occur return value can be retrieved by getValueString() method length of data in pdu can be retrieved by getValue32() method

        return decodeTextString(startIndex);
    
public booleandecodeContentType(int startIndex)
Decode the "Content-type" type for WSP pdu

param
startIndex The starting position of the "Content-type" in this pdu
return
false when error(not a Content-type) occur return value can be retrieved first by getValueString() and second by getValue32() method length of data in pdu can be retrieved by getValue32() method

        int mediaPrefixLength;
        long mediaFieldLength;

        if (decodeValueLength(startIndex) == false) {
            return decodeConstrainedEncoding(startIndex);
        }
        mediaPrefixLength = getDecodedDataLength();
        mediaFieldLength = getValue32();
        if (decodeIntegerValue(startIndex + mediaPrefixLength) == true) {
            dataLength += mediaPrefixLength;
            stringValue = null;
            return true;
        }
        if (decodeExtensionMedia(startIndex + mediaPrefixLength) == true) {
            dataLength += mediaPrefixLength;
            return true;
        }
        return false;
    
public booleandecodeExtensionMedia(int startIndex)
Decode the "Extension-media" type for WSP pdu

param
startIndex The starting position of the "Extension-media" in this pdu
return
false when error(not a Extension-media) occur return value can be retrieved by getValueString() method length of data in pdu can be retrieved by getValue32() method

        int index = startIndex;
        while (wspData[index] != 0) {
            index++;
        }
        dataLength  = index - startIndex + 1;
        stringValue = new String(wspData, startIndex, dataLength - 1);
        return true;
    
public booleandecodeIntegerValue(int startIndex)
Decode the "Integer-Value" type for WSP pdu

param
startIndex The starting position of the "Integer-Value" in this pdu
return
false when error(not a Integer-Value) occur return value can be retrieved by getValue32() method length of data in pdu can be retrieved by getValue32() method

        if (decodeShortInteger(startIndex) == true) {
            return true;
        }
        return decodeLongInteger(startIndex);
    
public booleandecodeLongInteger(int startIndex)
Decode the "Long-integer" type for WSP pdu

param
startIndex The starting position of the "Long-integer" in this pdu
return
false when error(not a Long-integer) occur return value can be retrieved by getValue32() method length of data in pdu can be retrieved by getValue32() method

        int lengthMultiOctet = wspData[startIndex] & 0xff;

        if (lengthMultiOctet > WAP_PDU_SHORT_LENGTH_MAX) {
            return false;
        }
        unsigned32bit = 0;
        for (int i=1; i<=lengthMultiOctet; i++) {
            unsigned32bit = (unsigned32bit << 8) | (wspData[startIndex+i] & 0xff);
        }
        dataLength = 1+lengthMultiOctet;
        return true;
    
public booleandecodeShortInteger(int startIndex)
Decode the "Short-integer" type for WSP pdu

param
startIndex The starting position of the "Short-integer" in this pdu
return
false when error(not a Short-integer) occur return value can be retrieved by getValue32() method length of data in pdu can be retrieved by getValue32() method

        if ((wspData[startIndex] & 0x80) == 0) {
            return false;
        }
        unsigned32bit = wspData[startIndex] & 0x7f;
        dataLength = 1;
        return true;
    
public booleandecodeTextString(int startIndex)
Decode the "Text-string" type for WSP pdu

param
startIndex The starting position of the "Text-string" in this pdu
return
false when error(not a Text-string) occur return value can be retrieved by getValueString() method length of data in pdu can be retrieved by getValue32() method

        int index = startIndex;
        while (wspData[index] != 0) {
            index++;
        }
        dataLength  = index - startIndex + 1;
        if (wspData[startIndex] == 127) {
            stringValue = new String(wspData, startIndex+1, dataLength - 2);
        } else {
            stringValue = new String(wspData, startIndex, dataLength - 1);
        }
        return true;
    
public booleandecodeUintvarInteger(int startIndex)
Decode the "Uintvar-integer" type for WSP pdu

param
startIndex The starting position of the "Uintvar-integer" in this pdu
return
false when error(not a Uintvar-integer) occur return value can be retrieved by getValue32() method length of data in pdu can be retrieved by getValue32() method

        int  index = startIndex;

        unsigned32bit = 0;
        while ((wspData[index] & 0x80) != 0) {
            if ((index - startIndex) >= 4) {
                return false;
            }
            unsigned32bit = (unsigned32bit << 7) | (wspData[index] & 0x7f);
            index++;
        }
        unsigned32bit = (unsigned32bit << 7) | (wspData[index] & 0x7f);
        dataLength = index - startIndex + 1;
        return true;
    
public booleandecodeValueLength(int startIndex)
Decode the "Value-length" type for WSP pdu

param
startIndex The starting position of the "Value-length" in this pdu
return
false when error(not a Value-length) occur return value can be retrieved by getValue32() method length of data in pdu can be retrieved by getValue32() method

        if ((wspData[startIndex] & 0xff) > WAP_PDU_LENGTH_QUOTE) {
            return false;
        }
        if (wspData[startIndex] < WAP_PDU_LENGTH_QUOTE) {
            unsigned32bit = wspData[startIndex];
            dataLength = 1;
        } else {
            decodeUintvarInteger(startIndex+1);
            dataLength ++;
        }
        return true;
    
public booleandecodeXWapApplicationId(int startIndex)
Decode the "X-Wap-Application-Id" type for WSP pdu

param
startIndex The starting position of the "X-Wap-Application-Id" in this pdu
return
false when error(not a X-Wap-Application-Id) occur return value can be retrieved first by getValueString() and second by getValue32() method length of data in pdu can be retrieved by getValue32() method

        if (decodeIntegerValue(startIndex) == true) {
            stringValue = null;
            return true;
        }
        return decodeTextString(startIndex);
    
public booleandecodeXWapContentURI(int startIndex)
Decode the "X-Wap-Content-URI" type for WSP pdu

param
startIndex The starting position of the "X-Wap-Content-URI" in this pdu
return
false when error(not a X-Wap-Content-URI) occur return value can be retrieved by getValueString() method length of data in pdu can be retrieved by getValue32() method

        return decodeTextString(startIndex);
    
public booleandecodeXWapInitiatorURI(int startIndex)
Decode the "X-Wap-Initiator-URI" type for WSP pdu

param
startIndex The starting position of the "X-Wap-Initiator-URI" in this pdu
return
false when error(not a X-Wap-Initiator-URI) occur return value can be retrieved by getValueString() method length of data in pdu can be retrieved by getValue32() method

        return decodeTextString(startIndex);
    
public intgetDecodedDataLength()
The data length of latest operation.

        return dataLength;
    
public longgetValue32()
The 32-bits result of latest operation.

        return unsigned32bit;
    
public java.lang.StringgetValueString()
The String result of latest operation.

        return stringValue;