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

SimTlv

public class SimTlv extends Object
SIM Tag-Length-Value record TS 102 223 Annex C {@hide}

Fields Summary
byte[]
record
int
tlvOffset
int
tlvLength
int
curOffset
int
curDataOffset
int
curDataLength
boolean
hasValidTlvObject
Constructors Summary
public SimTlv(byte[] record, int offset, int length)

        this.record = record;

        this.tlvOffset = offset;
        this.tlvLength = length;
        curOffset = offset;

        hasValidTlvObject = parseCurrentTlvObject();
    
Methods Summary
public byte[]getData()
Returns data associated with current TLV object returns null if !isValidObject()

        if (!hasValidTlvObject) return null;

        byte[] ret = new byte[curDataLength];
        System.arraycopy(record, curDataOffset, ret, 0, curDataLength);
        return ret;
    
public intgetTag()
Returns the tag for the current TLV object Return 0 if !isValidObject() 0 and 0xff are invalid tag values valid tags range from 1 - 0xfe

        if (!hasValidTlvObject) return 0;
        return record[curOffset] & 0xff;
    
public booleanisValidObject()

        return hasValidTlvObject;
    
public booleannextObject()

        if (!hasValidTlvObject) return false;

        curOffset = curDataOffset + curDataLength;
        hasValidTlvObject = parseCurrentTlvObject(); 
        return hasValidTlvObject;
    
private booleanparseCurrentTlvObject()
Updates curDataLength and curDataOffset

return
false on invalid record, true on valid record

   
        // 0x00 and 0xff are invalid tag values
        if (record[curOffset] == 0 || (record[curOffset] & 0xff) == 0xff) {
            return false;
        }
        
        try {
            if ((record[curOffset + 1] & 0xff) < 0x80) {
                // one byte length 0 - 0x7f
                curDataLength = record[curOffset + 1] & 0xff;
                curDataOffset = curOffset + 2;
            } else if ((record[curOffset + 1] & 0xff) == 0x81) {
                // two byte length 0x80 - 0xff
                curDataLength = record[curOffset + 2] & 0xff;
                curDataOffset = curOffset + 3;
            } else {
                return false;
            }
        } catch (ArrayIndexOutOfBoundsException ex) {
            return false;
        }

        if (curDataLength + curDataOffset > tlvOffset + tlvLength) {
            return false;
        }

        return true;