Methods Summary |
---|
public void | add(com.android.internal.telephony.gsm.SmsHeader$Element element)Add an element to the SmsHeader.
m_elements.add(element);
|
private int | calcSize()
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.ArrayList | getElements()Returns the list of SmsHeader Elements that make up the header.
return m_elements;
|
public static com.android.internal.telephony.gsm.SmsHeader | parse(byte[] data)Creates an SmsHeader object from raw user data header bytes.
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.
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.String | toString()
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();
|