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

SimPhoneBookInterfaceManager

public class SimPhoneBookInterfaceManager extends ISimPhoneBook.Stub
SimPhoneBookInterfaceManager to provide an inter-process communication to access ADN-like SIM records.

Fields Summary
static final String
LOG_TAG
static final boolean
DBG
private GSMPhone
phone
private AdnRecordCache
adnCache
private final Object
mLock
private int[]
recordSize
private boolean
success
private List
records
private static final boolean
ALLOW_SIM_OP_IN_UI_THREAD
private static final int
EVENT_GET_SIZE_DONE
private static final int
EVENT_LOAD_DONE
private static final int
EVENT_UPDATE_DONE
android.os.Handler
mHandler
Constructors Summary
public SimPhoneBookInterfaceManager(GSMPhone phone)


       
        this.phone = phone;
        adnCache = phone.mSIMRecords.getAdnCache();
        publish();
    
Methods Summary
private voidcheckThread()

        if (!ALLOW_SIM_OP_IN_UI_THREAD) {
            // Make sure this isn't the UI thread, since it will block
            if (mHandler.getLooper().equals(Looper.myLooper())) {
                Log.e(LOG_TAG, "query() called on the main UI thread!");
                throw new IllegalStateException("You cannot call query on this provder from the main UI thread.");
            }
        }
    
public java.util.ListgetAdnRecordsInEf(int efid)
Loads the AdnRecords in efid and returns them as a List of AdnRecords throws SecurityException if no READ_CONTACTS permission

param
efid the EF id of a ADN-like SIM
return
List of AdnRecord


        if (phone.getContext().checkCallingOrSelfPermission(
                android.Manifest.permission.READ_CONTACTS)
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException(
                    "Requires android.permission.READ_CONTACTS permission");
        }

        if (DBG) log("getAdnRecordsInEF: efid=" + efid);

        synchronized(mLock) {
            checkThread();
            Message response = mHandler.obtainMessage(EVENT_LOAD_DONE);
            adnCache.requestLoadAllAdnLike(efid, response);
            try {
                mLock.wait();
            } catch (InterruptedException e) {
                log("interrupted while trying to load from the SIM");
            }
        }
            return records;
    
public int[]getAdnRecordsSize(int efid)
Get the capacity of records in efid

param
efid the EF id of a ADN-like SIM
return
int[3] array recordSizes[0] is the single record length recordSizes[1] is the total length of the EF file recordSizes[2] is the number of records in the EF file

        if (DBG) log("getAdnRecordsSize: efid=" + efid);
        synchronized(mLock) {
            checkThread();
            recordSize = new int[3];
            Message response = mHandler.obtainMessage(EVENT_GET_SIZE_DONE);
            phone.mSIMFileHandler.getEFLinearRecordSize(efid, response);
            try {
                mLock.wait();
            } catch (InterruptedException e) {
                log("interrupted while trying to load from the SIM");
            }
        }

        return recordSize;
    
private voidlog(java.lang.String msg)

        Log.d(LOG_TAG, "[SpbInterfaceManager] " + msg);
    
private voidpublish()

        ServiceManager.addService("simphonebook", this);
    
public booleanupdateAdnRecordsInEfByIndex(int efid, java.lang.String newTag, java.lang.String newPhoneNumber, int index, java.lang.String pin2)
Update an ADN-like EF record by record index This is useful for iteration the whole ADN file, such as write the whole phone book or erase/format the whole phonebook throws SecurityException if no WRITE_CONTACTS permission

param
efid must be one among EF_ADN, EF_FDN, and EF_SDN
param
newTag adn tag to be stored
param
newPhoneNumber adn number to be stored Set both newTag and newPhoneNubmer to "" means to replace the old record with empty one, aka, delete old record
param
index is 1-based adn record index to be updated
param
pin2 required to update EF_FDN, otherwise must be null
return
true for success


        if (phone.getContext().checkCallingOrSelfPermission(
                android.Manifest.permission.WRITE_CONTACTS)
                != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException(
                    "Requires android.permission.WRITE_CONTACTS permission");
        }

        if (DBG) log("updateAdnRecordsInEfByIndex: efid=" + efid +
                " Index=" + index + " ==> " +
                "("+ newTag + "," + newPhoneNumber + ")"+ " pin2=" + pin2);
        synchronized(mLock) {
            checkThread();
            success = false;
            Message response = mHandler.obtainMessage(EVENT_UPDATE_DONE);
            AdnRecord newAdn = new AdnRecord(newTag, newPhoneNumber);
            adnCache.updateAdnByIndex(efid, newAdn, index, pin2, response);
            try {
                mLock.wait();
            } catch (InterruptedException e) {
                log("interrupted while trying to update by index");
            }
        }
        return success;
    
public booleanupdateAdnRecordsInEfBySearch(int efid, java.lang.String oldTag, java.lang.String oldPhoneNumber, java.lang.String newTag, java.lang.String newPhoneNumber, java.lang.String pin2)
Replace oldAdn with newAdn in ADN-like record in EF getAdnRecordsInEf must be called at least once before this function, otherwise an error will be returned throws SecurityException if no WRITE_CONTACTS permission

param
efid must be one among EF_ADN, EF_FDN, and EF_SDN
param
oldTag adn tag to be replaced
param
oldPhoneNumber adn number to be replaced Set both oldTag and oldPhoneNubmer to "" means to replace an empty record, aka, insert new record
param
newTag adn tag to be stored
param
newPhoneNumber adn number ot be stored Set both newTag and newPhoneNubmer to "" means to replace the old record with empty one, aka, delete old record
param
pin2 required to update EF_FDN, otherwise must be null
return
true for success



        if (phone.getContext().checkCallingOrSelfPermission(
                android.Manifest.permission.WRITE_CONTACTS)
            != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException(
                    "Requires android.permission.WRITE_CONTACTS permission");
        }

        
        if (DBG) log("updateAdnRecordsInEfBySearch: efid=" + efid +
                " ("+ oldTag + "," + oldPhoneNumber + ")"+ "==>" +
                " ("+ newTag + "," + newPhoneNumber + ")"+ " pin2=" + pin2);
        synchronized(mLock) {
            checkThread();
            success = false;
            Message response = mHandler.obtainMessage(EVENT_UPDATE_DONE);
            AdnRecord oldAdn = new AdnRecord(oldTag, oldPhoneNumber);
            AdnRecord newAdn = new AdnRecord(newTag, newPhoneNumber);
            adnCache.updateAdnBySearch(efid, oldAdn, newAdn, pin2, response);
            try {
                mLock.wait();
            } catch (InterruptedException e) {
                log("interrupted while trying to update by search");
            }
        }
        return success;