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

AdnRecordCache

public final class AdnRecordCache extends android.os.Handler implements SimConstants
{@hide}

Fields Summary
GSMPhone
phone
android.util.SparseArray
adnLikeFiles
android.util.SparseArray
adnLikeWaiters
android.util.SparseArray
userWriteResponse
static final int
EVENT_LOAD_ALL_ADN_LIKE_DONE
static final int
EVENT_UPDATE_ADN_DONE
Constructors Summary
AdnRecordCache(GSMPhone phone)


    //***** Constructor


    /*package*/
     
    
        this.phone = phone;
    
Methods Summary
private voidclearUserWriters()

        int size = userWriteResponse.size();
        for (int i = 0; i < size; i++) {
            sendErrorResponse(userWriteResponse.valueAt(i), "AdnCace reset");
        }
        userWriteResponse.clear();
    
private voidclearWaiters()

        int size = adnLikeWaiters.size();
        for (int i = 0; i < size; i++) {
            ArrayList<Message> waiters = adnLikeWaiters.valueAt(i);
            AsyncResult ar = new AsyncResult(null, null, new RuntimeException("AdnCache reset"));
            notifyWaiters(waiters, ar);
        }
        adnLikeWaiters.clear();
    
private intextensionEfForEf(int efid)
Returns extension ef associated with ADN-like EF or -1 if we don't know. See 3GPP TS 51.011 for this mapping

        switch (efid) {
            case EF_MBDN: return EF_EXT6;
            case EF_ADN: return EF_EXT1;
            case EF_SDN: return EF_EXT3;
            case EF_FDN: return EF_EXT2;
            case EF_MSISDN: return EF_EXT1;          
            default: return -1;
        } 
    
java.util.ArrayListgetRecordsIfLoaded(int efid)

return
List of AdnRecords for efid if we've already loaded them this radio session, or null if we haven't

        return adnLikeFiles.get(efid);
    
public voidhandleMessage(android.os.Message msg)

        AsyncResult ar;
        int efid;

        switch(msg.what) {
            case EVENT_LOAD_ALL_ADN_LIKE_DONE:
                /* arg1 is efid, obj.result is ArrayList<AdnRecord>*/
                ar = (AsyncResult) msg.obj;
                efid = msg.arg1;
                ArrayList<Message> waiters;

                waiters = adnLikeWaiters.get(efid);
                adnLikeWaiters.delete(efid);

                if (ar.exception == null) {
                    adnLikeFiles.put(efid, (ArrayList<AdnRecord>) (ar.result));
                }
                notifyWaiters(waiters, ar);
                break;
            case EVENT_UPDATE_ADN_DONE:
                ar = (AsyncResult)msg.obj;
                efid = msg.arg1;
                int index = msg.arg2;
                AdnRecord adn = (AdnRecord) (ar.userObj);

                if (ar.exception == null) {
                    adnLikeFiles.get(efid).set(index - 1, adn);
                }

                Message response = userWriteResponse.get(efid);
                userWriteResponse.delete(efid);

                AsyncResult.forMessage(response, null, ar.exception);
                response.sendToTarget();
                break;
        }

    
private voidnotifyWaiters(java.util.ArrayList waiters, android.os.AsyncResult ar)


        if (waiters == null) {
            return;
        }

        for (int i = 0, s = waiters.size() ; i < s ; i++) {
            Message waiter = waiters.get(i);

            AsyncResult.forMessage(waiter, ar.result, ar.exception);
            waiter.sendToTarget();
        }
    
voidrequestLoadAllAdnLike(int efid, android.os.Message response)
Responds with exception (in response) if efid is not a known ADN-like record

        ArrayList<Message> waiters;
        ArrayList<AdnRecord> result;

        result = getRecordsIfLoaded(efid);

        // Have we already loaded this efid?
        if (result != null) {
            if (response != null) {
                AsyncResult.forMessage(response).result = result;
                response.sendToTarget();
            }

            return;
        }

        // Have we already *started* loading this efid?

        waiters = adnLikeWaiters.get(efid);

        if (waiters != null) {
            // There's a pending request for this EF already
            // just add ourselves to it

            waiters.add(response);
            return;
        }
        
        // Start loading efid
        
        waiters = new ArrayList<Message>();
        waiters.add(response);

        adnLikeWaiters.put(efid, waiters);

        int extensionEF = extensionEfForEf(efid);
    
        if (extensionEF < 0) {
            // respond with error if not known ADN-like record

            if (response != null) {
                AsyncResult.forMessage(response).exception 
                    = new RuntimeException("EF is not known ADN-like EF:" + efid);
                response.sendToTarget();
            }
            
            return;
        }

        new AdnRecordLoader(phone).loadAllFromEF(efid, extensionEF,
            obtainMessage(EVENT_LOAD_ALL_ADN_LIKE_DONE, efid, 0));
    
voidreset()
Called from SIMRecords.onRadioNotAvailable and SIMRecords.handleSimRefresh.

        adnLikeFiles.clear();

        clearWaiters();
        clearUserWriters();
        
    
private voidsendErrorResponse(android.os.Message response, java.lang.String errString)

        if (response != null) {
            Exception e = new RuntimeException(errString);
            AsyncResult.forMessage(response).exception = e;
            response.sendToTarget();
        }
    
voidupdateAdnByIndex(int efid, AdnRecord adn, int recordIndex, java.lang.String pin2, android.os.Message response)
Update an ADN-like record in EF by record index

param
efid must be one among EF_ADN, EF_FDN, and EF_SDN
param
adn is the new adn to be stored
param
recordIndex is the 1-based adn record index
param
pin2 is required to update EF_FDN, otherwise must be null
param
response message to be posted when done response.exception hold the exception in error


        int extensionEF = extensionEfForEf(efid);
        if (extensionEF < 0) {
            sendErrorResponse(response, "EF is not known ADN-like EF:" + efid);
            return;
        }

        Message pendingResponse = userWriteResponse.get(efid);
        if (pendingResponse != null) {
            sendErrorResponse(response, "Have pending update for EF:" + efid);
            return;
        }

        userWriteResponse.put(efid, response);

        new AdnRecordLoader(phone).updateEF(adn, efid, extensionEF,
                recordIndex, pin2,
                obtainMessage(EVENT_UPDATE_ADN_DONE, efid, recordIndex, adn));
    
voidupdateAdnBySearch(int efid, AdnRecord oldAdn, AdnRecord newAdn, java.lang.String pin2, android.os.Message response)
Replace oldAdn with newAdn in ADN-like record in EF The ADN-like records must be read through requestLoadAllAdnLike() before

param
efid must be one of EF_ADN, EF_FDN, and EF_SDN
param
oldAdn is the adn to be replaced If oldAdn.isEmpty() is ture, it insert the newAdn
param
newAdn is the adn to be stored If newAdn.isEmpty() is true, it delete the oldAdn
param
pin2 is required to update EF_FDN, otherwise must be null
param
response message to be posted when done response.exception hold the exception in error


        int extensionEF;
        extensionEF = extensionEfForEf(efid);

        if (extensionEF < 0) {
            sendErrorResponse(response, "EF is not known ADN-like EF:" + efid);
            return;
        }

        ArrayList<AdnRecord>  oldAdnList;
        oldAdnList = getRecordsIfLoaded(efid);

        if (oldAdnList == null) {
            sendErrorResponse(response, "Adn list not exist for EF:" + efid);
            return;
        }

        int index = -1;
        int count = 1;
        for (Iterator<AdnRecord> it = oldAdnList.iterator(); it.hasNext(); ) {
            if (oldAdn.isEqual(it.next())) {
                index = count;
                break;
            }
            count++;
        }

        if (index == -1) {
            sendErrorResponse(response, "Adn record don't exist for " + oldAdn);
            return;
        }

        Message pendingResponse = userWriteResponse.get(efid);

        if (pendingResponse != null) {
            sendErrorResponse(response, "Have pending update for EF:" + efid);
            return;
        }

        userWriteResponse.put(efid, response);

        new AdnRecordLoader(phone).updateEF(newAdn, efid, extensionEF,
                index, pin2,
                obtainMessage(EVENT_UPDATE_ADN_DONE, efid, index, newAdn));