FileDocCategorySizeDatePackage
SimTlv.javaAPI DocAndroid 5.1 API3254Thu Mar 12 22:22:54 GMT 2015com.android.internal.telephony.gsm

SimTlv

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

Fields Summary
byte[]
mRecord
int
mTlvOffset
int
mTlvLength
int
mCurOffset
int
mCurDataOffset
int
mCurDataLength
boolean
mHasValidTlvObject
Constructors Summary
public SimTlv(byte[] record, int offset, int length)

        mRecord = record;

        mTlvOffset = offset;
        mTlvLength = length;
        mCurOffset = offset;

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

        if (!mHasValidTlvObject) return null;

        byte[] ret = new byte[mCurDataLength];
        System.arraycopy(mRecord, mCurDataOffset, ret, 0, mCurDataLength);
        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 (!mHasValidTlvObject) return 0;
        return mRecord[mCurOffset] & 0xff;
    
public booleanisValidObject()

        return mHasValidTlvObject;
    
public booleannextObject()

        if (!mHasValidTlvObject) return false;
        mCurOffset = mCurDataOffset + mCurDataLength;
        mHasValidTlvObject = parseCurrentTlvObject();
        return mHasValidTlvObject;
    
private booleanparseCurrentTlvObject()
Updates curDataLength and curDataOffset

return
false on invalid record, true on valid record

        // 0x00 and 0xff are invalid tag values

        try {
            if (mRecord[mCurOffset] == 0 || (mRecord[mCurOffset] & 0xff) == 0xff) {
                return false;
            }

            if ((mRecord[mCurOffset + 1] & 0xff) < 0x80) {
                // one byte length 0 - 0x7f
                mCurDataLength = mRecord[mCurOffset + 1] & 0xff;
                mCurDataOffset = mCurOffset + 2;
            } else if ((mRecord[mCurOffset + 1] & 0xff) == 0x81) {
                // two byte length 0x80 - 0xff
                mCurDataLength = mRecord[mCurOffset + 2] & 0xff;
                mCurDataOffset = mCurOffset + 3;
            } else {
                return false;
            }
        } catch (ArrayIndexOutOfBoundsException ex) {
            return false;
        }

        if (mCurDataLength + mCurDataOffset > mTlvOffset + mTlvLength) {
            return false;
        }

        return true;