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

AdnRecordLoader

public class AdnRecordLoader extends android.os.Handler

Fields Summary
static final String
LOG_TAG
GSMPhone
phone
int
ef
int
extensionEF
int
pendingExtLoads
android.os.Message
userResponse
String
pin2
int
recordNumber
ArrayList
adns
Object
result
static final int
EVENT_ADN_LOAD_DONE
static final int
EVENT_EXT_RECORD_LOAD_DONE
static final int
EVENT_ADN_LOAD_ALL_DONE
static final int
EVENT_EF_LINEAR_RECORD_SIZE_DONE
static final int
EVENT_UPDATE_RECORD_DONE
Constructors Summary
AdnRecordLoader(GSMPhone phone)


    //***** Constructor

     
    
        // The telephony unit-test cases may create AdnRecords
        // in secondary threads
        super(phone.h.getLooper());

        this.phone = phone;
    
Methods Summary
public voidhandleMessage(android.os.Message msg)

        AsyncResult ar;
        byte data[];
        AdnRecord adn;

        try {
            switch (msg.what) {
                case EVENT_EF_LINEAR_RECORD_SIZE_DONE:
                    ar = (AsyncResult)(msg.obj);
                    adn = (AdnRecord)(ar.userObj);

                    if (ar.exception != null) {
                        throw new RuntimeException("get EF record size failed",
                                ar.exception);
                    }

                    int[] recordSize = (int[])ar.result;
                    // recordSize is int[3] array
                    // int[0]  is the record length
                    // int[1]  is the total length of the EF file
                    // int[2]  is the number of records in the EF file
                    // So int[0] * int[2] = int[1]
                   if (recordSize.length != 3 || recordNumber > recordSize[2]) {
                        throw new RuntimeException("get wrong EF record size format",
                                ar.exception);
                    }

                    data = adn.buildAdnString(recordSize[0]);

                    if(data == null) {
                        throw new RuntimeException("worong ADN format",
                                ar.exception);
                    }

                    phone.mSIMFileHandler.updateEFLinearFixed(ef, recordNumber,
                            data, pin2, obtainMessage(EVENT_UPDATE_RECORD_DONE));

                    pendingExtLoads = 1;

                    break;
                case EVENT_UPDATE_RECORD_DONE:
                    ar = (AsyncResult)(msg.obj);
                    if (ar.exception != null) {
                        throw new RuntimeException("update EF adn record failed",
                                ar.exception);
                    }
                    pendingExtLoads = 0;
                    result = null;
                    break;
                case EVENT_ADN_LOAD_DONE:
                    ar = (AsyncResult)(msg.obj);
                    data = (byte[])(ar.result);
     
                    if (ar.exception != null) {
                        throw new RuntimeException("load failed", ar.exception);
                    }

                    if (false) {
                        Log.d(LOG_TAG,"ADN EF: 0x" 
                            + Integer.toHexString(ef)
                            + ":" + recordNumber
                            + "\n" + SimUtils.bytesToHexString(data));
                    }
                    
                    adn = new AdnRecord(ef, recordNumber, data);
                    result = adn;

                    if (adn.hasExtendedRecord()) {
                        // If we have a valid value in the ext record field,
                        // we're not done yet: we need to read the corresponding
                        // ext record and append it

                        pendingExtLoads = 1;
                        
                        phone.mSIMFileHandler.loadEFLinearFixed(
                            extensionEF, adn.extRecord, 
                            obtainMessage(EVENT_EXT_RECORD_LOAD_DONE, adn)); 
                    }
                break;

                case EVENT_EXT_RECORD_LOAD_DONE:
                    ar = (AsyncResult)(msg.obj);
                    data = (byte[])(ar.result);
                    adn = (AdnRecord)(ar.userObj);
     
                    if (ar.exception != null) {
                        throw new RuntimeException("load failed", ar.exception);
                    }

                    Log.d(LOG_TAG,"ADN extention EF: 0x" 
                        + Integer.toHexString(extensionEF)
                        + ":" + adn.extRecord
                        + "\n" + SimUtils.bytesToHexString(data));

                    adn.appendExtRecord(data);

                    pendingExtLoads--;
                    // result should have been set in 
                    // EVENT_ADN_LOAD_DONE or EVENT_ADN_LOAD_ALL_DONE
                break;            

                case EVENT_ADN_LOAD_ALL_DONE:
                    ar = (AsyncResult)(msg.obj);
                    ArrayList<byte[]> datas = (ArrayList<byte[]>)(ar.result);
     
                    if (ar.exception != null) {
                        throw new RuntimeException("load failed", ar.exception);
                    }

                    adns = new ArrayList<AdnRecord>(datas.size());
                    result = adns;
                    pendingExtLoads = 0;

                    for(int i = 0, s = datas.size() ; i < s ; i++) {
                        adn = new AdnRecord(ef, 1 + i, datas.get(i));
                        adns.add(adn);

                        if (adn.hasExtendedRecord()) {
                            // If we have a valid value in the ext record field,
                            // we're not done yet: we need to read the corresponding
                            // ext record and append it

                            pendingExtLoads++;
                            
                            phone.mSIMFileHandler.loadEFLinearFixed(
                                extensionEF, adn.extRecord, 
                                obtainMessage(EVENT_EXT_RECORD_LOAD_DONE, adn)); 
                        }
                    }
                break;
            }
        } catch (RuntimeException exc) {            
            if (userResponse != null) {
                AsyncResult.forMessage(userResponse) 
                                .exception = exc;
                userResponse.sendToTarget();
                // Loading is all or nothing--either every load succeeds
                // or we fail the whole thing.
                userResponse = null;
            }
            return;
        }

        if (userResponse != null && pendingExtLoads == 0) {
            AsyncResult.forMessage(userResponse).result 
                = result;

            userResponse.sendToTarget();
            userResponse = null;
        }
    
voidloadAllFromEF(int ef, int extensionEF, android.os.Message response)
Resulting ArrayList<adnRecord> is placed in response.obj.result or response.obj.exception is set

        this.ef = ef;
        this.extensionEF = extensionEF;
        this.userResponse = response;
        
        phone.mSIMFileHandler.loadEFLinearFixedAll(
                    ef, 
                    obtainMessage(EVENT_ADN_LOAD_ALL_DONE)); 

    
voidloadFromEF(int ef, int extensionEF, int recordNumber, android.os.Message response)
Resulting AdnRecord is placed in response.obj.result or response.obj.exception is set

        this.ef = ef;
        this.extensionEF = extensionEF;
        this.recordNumber = recordNumber;
        this.userResponse = response;
        
        phone.mSIMFileHandler.loadEFLinearFixed(
                    ef, recordNumber, 
                    obtainMessage(EVENT_ADN_LOAD_DONE)); 

    
voidupdateEF(com.android.internal.telephony.gsm.AdnRecord adn, int ef, int extensionEF, int recordNumber, java.lang.String pin2, android.os.Message response)
Write adn to a EF SIM record It will get the record size of EF record and compose hex adn array then write the hex array to EF record

param
adn is set with alphaTag and phoneNubmer
param
ef EF fileid
param
extensionEF extension EF fileid
param
recordNumber 1-based record index
param
pin2 for CHV2 operations, must be null if pin2 is not needed
param
response will be sent to its handler when completed

        this.ef = ef;
        this.extensionEF = extensionEF;
        this.recordNumber = recordNumber;
        this.userResponse = response;
        this.pin2 = pin2;

        phone.mSIMFileHandler.getEFLinearRecordSize( ef,
            obtainMessage(EVENT_EF_LINEAR_RECORD_SIZE_DONE, adn));