FileDocCategorySizeDatePackage
SmsHeader.javaAPI DocAndroid 1.5 API7501Wed May 06 22:42:02 BST 2009com.android.internal.telephony.gsm

SmsHeader

public class SmsHeader extends Object
This class represents a SMS user data header.

Fields Summary
public static final int
CONCATENATED_8_BIT_REFERENCE
See TS 23.040 9.2.3.24 for description of this element ID.
public static final int
SPECIAL_SMS_MESSAGE_INDICATION
See TS 23.040 9.2.3.24 for description of this element ID.
public static final int
APPLICATION_PORT_ADDRESSING_8_BIT
See TS 23.040 9.2.3.24 for description of this element ID.
public static final int
APPLICATION_PORT_ADDRESSING_16_BIT
See TS 23.040 9.2.3.24 for description of this element ID.
public static final int
CONCATENATED_16_BIT_REFERENCE
See TS 23.040 9.2.3.24 for description of this element ID.
public static final int
PORT_WAP_PUSH
public static final int
PORT_WAP_WSP
private byte[]
m_data
private ArrayList
m_elements
Constructors Summary
public SmsHeader()

    
Methods Summary
public voidadd(com.android.internal.telephony.gsm.SmsHeader$Element element)
Add an element to the SmsHeader.

param
element to add.

        m_elements.add(element);
    
private intcalcSize()

        int size = 1; // +1 for the UDHL field
        for (Element e : m_elements) {
            size += e.getData().length;
            size += 2; // 1 byte ID, 1 byte length
        }

        return size;
    
public java.util.ArrayListgetElements()
Returns the list of SmsHeader Elements that make up the header.

return
the list of SmsHeader Elements.

        return m_elements;
    
public static com.android.internal.telephony.gsm.SmsHeaderparse(byte[] data)
Creates an SmsHeader object from raw user data header bytes.

param
data is user data header bytes
return
an SmsHeader object


                              
        
    
        SmsHeader header = new SmsHeader();
        header.m_data = data;

        int index = 0;
        while (index < data.length)
        {
            int id = data[index++] & 0xff;
            int length = data[index++] & 0xff;
            byte[] elementData = new byte[length];
            System.arraycopy(data, index, elementData, 0, length);
            header.add(new Element(id, elementData));
            index += length;
        }

        return header;
    
public byte[]toByteArray()
Converts SmsHeader object to a byte array as specified in TS 23.040 9.2.3.24.

return
Byte array representing the SmsHeader

        if (m_elements.size() == 0) return null;

        if (m_data == null) {
            int size = calcSize();
            int cur = 1;
            m_data = new byte[size];

            m_data[0] = (byte) (size-1);  // UDHL does not include itself

            for (Element e : m_elements) {
                int length = e.getData().length;
                m_data[cur++] = (byte) e.getID();
                m_data[cur++] = (byte) length;
                System.arraycopy(e.getData(), 0, m_data, cur, length);
                cur += length;
            }
        }

        return m_data;
    
public java.lang.StringtoString()

        StringBuilder builder = new StringBuilder();

        builder.append("UDH LENGTH: " + m_data.length + " octets");
        builder.append("UDH: ");
        builder.append(HexDump.toHexString(m_data));
        builder.append("\n");

        for (Element e : getElements()) {
            builder.append("  0x" + HexDump.toHexString((byte)e.getID()) + " - ");
            switch (e.getID())
            {
                case CONCATENATED_8_BIT_REFERENCE:
                {
                    builder.append("Concatenated Short Message 8bit ref\n");
                    byte[] data = e.getData();
                    builder.append("    " + data.length + " (0x");
                    builder.append(HexDump.toHexString((byte)data.length)+") Bytes - Information Element\n");
                    builder.append("      " + data[0] + " : SM reference number\n");
                    builder.append("      " + data[1] + " : number of messages\n");
                    builder.append("      " + data[2] + " : this SM sequence number\n");
                    break;
                }

                case CONCATENATED_16_BIT_REFERENCE:
                {
                    builder.append("Concatenated Short Message 16bit ref\n");
                    byte[] data = e.getData();
                    builder.append("    " + data.length + " (0x");
                    builder.append(HexDump.toHexString((byte)data.length)+") Bytes - Information Element\n");
                    builder.append("      " + (data[0] & 0xff) * 256 + (data[1] & 0xff) +
                                   " : SM reference number\n");
                    builder.append("      " + data[2] + " : number of messages\n");
                    builder.append("      " + data[3] + " : this SM sequence number\n");
                    break;
                }

                case APPLICATION_PORT_ADDRESSING_16_BIT:
                {
                    builder.append("Application port addressing 16bit\n");
                    byte[] data = e.getData();

                    builder.append("    " + data.length + " (0x");
                    builder.append(HexDump.toHexString((byte)data.length)+") Bytes - Information Element\n");

                    int source = (data[0] & 0xff) << 8;
                    source |= (data[1] & 0xff);
                    builder.append("      " + source + " : DESTINATION port\n");

                    int dest = (data[2] & 0xff) << 8;
                    dest |= (data[3] & 0xff);
                    builder.append("      " + dest + " : SOURCE port\n");
                    break;
                }

                default:
                {
                    builder.append("Unknown element\n");
                    break;
                }
            }
        }

        return builder.toString();