FileDocCategorySizeDatePackage
AdnRecord.javaAPI DocAndroid 5.1 API9865Thu Mar 12 22:22:54 GMT 2015com.android.internal.telephony.uicc

AdnRecord

public class AdnRecord extends Object implements android.os.Parcelable
Used to load or store ADNs (Abbreviated Dialing Numbers). {@hide}

Fields Summary
static final String
LOG_TAG
String
mAlphaTag
String
mNumber
String[]
mEmails
int
mExtRecord
int
mEfid
int
mRecordNumber
static final int
FOOTER_SIZE_BYTES
static final int
MAX_NUMBER_SIZE_BYTES
static final int
EXT_RECORD_LENGTH_BYTES
static final int
EXT_RECORD_TYPE_ADDITIONAL_DATA
static final int
EXT_RECORD_TYPE_MASK
static final int
MAX_EXT_CALLED_PARTY_LENGTH
static final int
ADN_BCD_NUMBER_LENGTH
static final int
ADN_TON_AND_NPI
static final int
ADN_DIALING_NUMBER_START
static final int
ADN_DIALING_NUMBER_END
static final int
ADN_CAPABILITY_ID
static final int
ADN_EXTENSION_ID
public static final Parcelable.Creator
CREATOR
Constructors Summary
public AdnRecord(byte[] record)



    //***** Constructor
        
        this(0, 0, record);
    
public AdnRecord(int efid, int recordNumber, byte[] record)

        this.mEfid = efid;
        this.mRecordNumber = recordNumber;
        parseRecord(record);
    
public AdnRecord(String alphaTag, String number)

        this(0, 0, alphaTag, number);
    
public AdnRecord(String alphaTag, String number, String[] emails)

        this(0, 0, alphaTag, number, emails);
    
public AdnRecord(int efid, int recordNumber, String alphaTag, String number, String[] emails)

        this.mEfid = efid;
        this.mRecordNumber = recordNumber;
        this.mAlphaTag = alphaTag;
        this.mNumber = number;
        this.mEmails = emails;
    
public AdnRecord(int efid, int recordNumber, String alphaTag, String number)

        this.mEfid = efid;
        this.mRecordNumber = recordNumber;
        this.mAlphaTag = alphaTag;
        this.mNumber = number;
        this.mEmails = null;
    
Methods Summary
public voidappendExtRecord(byte[] extRecord)
See TS 51.011 10.5.10

        try {
            if (extRecord.length != EXT_RECORD_LENGTH_BYTES) {
                return;
            }

            if ((extRecord[0] & EXT_RECORD_TYPE_MASK)
                    != EXT_RECORD_TYPE_ADDITIONAL_DATA) {
                return;
            }

            if ((0xff & extRecord[1]) > MAX_EXT_CALLED_PARTY_LENGTH) {
                // invalid or empty record
                return;
            }

            mNumber += PhoneNumberUtils.calledPartyBCDFragmentToString(
                                        extRecord, 2, 0xff & extRecord[1]);

            // We don't support ext record chaining.

        } catch (RuntimeException ex) {
            Rlog.w(LOG_TAG, "Error parsing AdnRecord ext record", ex);
        }
    
public byte[]buildAdnString(int recordSize)
Build adn hex byte array based on record size The format of byte array is defined in 51.011 10.5.1

param
recordSize is the size X of EF record
return
hex byte[recordSize] to be written to EF record return null for wrong format of dialing number or tag

        byte[] bcdNumber;
        byte[] byteTag;
        byte[] adnString;
        int footerOffset = recordSize - FOOTER_SIZE_BYTES;

        // create an empty record
        adnString = new byte[recordSize];
        for (int i = 0; i < recordSize; i++) {
            adnString[i] = (byte) 0xFF;
        }

        if (TextUtils.isEmpty(mNumber)) {
            Rlog.w(LOG_TAG, "[buildAdnString] Empty dialing number");
            return adnString;   // return the empty record (for delete)
        } else if (mNumber.length()
                > (ADN_DIALING_NUMBER_END - ADN_DIALING_NUMBER_START + 1) * 2) {
            Rlog.w(LOG_TAG,
                    "[buildAdnString] Max length of dialing number is 20");
            return null;
        } else if (mAlphaTag != null && mAlphaTag.length() > footerOffset) {
            Rlog.w(LOG_TAG,
                    "[buildAdnString] Max length of tag is " + footerOffset);
            return null;
        } else {
            bcdNumber = PhoneNumberUtils.numberToCalledPartyBCD(mNumber);

            System.arraycopy(bcdNumber, 0, adnString,
                    footerOffset + ADN_TON_AND_NPI, bcdNumber.length);

            adnString[footerOffset + ADN_BCD_NUMBER_LENGTH]
                    = (byte) (bcdNumber.length);
            adnString[footerOffset + ADN_CAPABILITY_ID]
                    = (byte) 0xFF; // Capability Id
            adnString[footerOffset + ADN_EXTENSION_ID]
                    = (byte) 0xFF; // Extension Record Id

            if (!TextUtils.isEmpty(mAlphaTag)) {
                byteTag = GsmAlphabet.stringToGsm8BitPacked(mAlphaTag);
                System.arraycopy(byteTag, 0, adnString, 0, byteTag.length);
            }

            return adnString;
        }
    
public intdescribeContents()

        return 0;
    
public java.lang.StringgetAlphaTag()

        return mAlphaTag;
    
public java.lang.String[]getEmails()

        return mEmails;
    
public java.lang.StringgetNumber()

        return mNumber;
    
public booleanhasExtendedRecord()

        return mExtRecord != 0 && mExtRecord != 0xff;
    
public booleanisEmpty()

        return TextUtils.isEmpty(mAlphaTag) && TextUtils.isEmpty(mNumber) && mEmails == null;
    
public booleanisEqual(com.android.internal.telephony.uicc.AdnRecord adn)

        return ( stringCompareNullEqualsEmpty(mAlphaTag, adn.mAlphaTag) &&
                stringCompareNullEqualsEmpty(mNumber, adn.mNumber) &&
                Arrays.equals(mEmails, adn.mEmails));
    
private voidparseRecord(byte[] record)
alphaTag and number are set to null on invalid format

        try {
            mAlphaTag = IccUtils.adnStringFieldToString(
                            record, 0, record.length - FOOTER_SIZE_BYTES);

            int footerOffset = record.length - FOOTER_SIZE_BYTES;

            int numberLength = 0xff & record[footerOffset];

            if (numberLength > MAX_NUMBER_SIZE_BYTES) {
                // Invalid number length
                mNumber = "";
                return;
            }

            // Please note 51.011 10.5.1:
            //
            // "If the Dialling Number/SSC String does not contain
            // a dialling number, e.g. a control string deactivating
            // a service, the TON/NPI byte shall be set to 'FF' by
            // the ME (see note 2)."

            mNumber = PhoneNumberUtils.calledPartyBCDToString(
                            record, footerOffset + 1, numberLength);


            mExtRecord = 0xff & record[record.length - 1];

            mEmails = null;

        } catch (RuntimeException ex) {
            Rlog.w(LOG_TAG, "Error parsing AdnRecord", ex);
            mNumber = "";
            mAlphaTag = "";
            mEmails = null;
        }
    
public voidsetEmails(java.lang.String[] emails)

        this.mEmails = emails;
    
private static booleanstringCompareNullEqualsEmpty(java.lang.String s1, java.lang.String s2)
Helper function for {@link #isEqual}.

        if (s1 == s2) {
            return true;
        }
        if (s1 == null) {
            s1 = "";
        }
        if (s2 == null) {
            s2 = "";
        }
        return (s1.equals(s2));
    
public java.lang.StringtoString()

        return "ADN Record '" + mAlphaTag + "' '" + mNumber + " " + mEmails + "'";
    
public voidwriteToParcel(android.os.Parcel dest, int flags)

        dest.writeInt(mEfid);
        dest.writeInt(mRecordNumber);
        dest.writeString(mAlphaTag);
        dest.writeString(mNumber);
        dest.writeStringArray(mEmails);