Methods Summary |
---|
private void | createPbrFile(java.util.ArrayList records)
if (records == null) {
mPbrFile = null;
mIsPbrPresent = false;
return;
}
mPbrFile = new PbrFile(records);
|
public void | handleMessage(android.os.Message msg)
AsyncResult ar;
switch(msg.what) {
case EVENT_PBR_LOAD_DONE:
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
createPbrFile((ArrayList<byte[]>)ar.result);
}
synchronized (mLock) {
mLock.notify();
}
break;
case EVENT_USIM_ADN_LOAD_DONE:
log("Loading USIM ADN records done");
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
mPhoneBookRecords.addAll((ArrayList<AdnRecord>)ar.result);
}
synchronized (mLock) {
mLock.notify();
}
break;
case EVENT_IAP_LOAD_DONE:
log("Loading USIM IAP records done");
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
mIapFileRecord = ((ArrayList<byte[]>)ar.result);
}
synchronized (mLock) {
mLock.notify();
}
break;
case EVENT_EMAIL_LOAD_DONE:
log("Loading USIM Email records done");
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
mEmailFileRecord = ((ArrayList<byte[]>)ar.result);
}
synchronized (mLock) {
mLock.notify();
}
break;
}
|
public void | invalidateCache()
mRefreshCache = true;
|
public java.util.ArrayList | loadEfFilesFromUsim()
synchronized (mLock) {
if (!mPhoneBookRecords.isEmpty()) {
if (mRefreshCache) {
mRefreshCache = false;
refreshCache();
}
return mPhoneBookRecords;
}
if (!mIsPbrPresent) return null;
// Check if the PBR file is present in the cache, if not read it
// from the USIM.
if (mPbrFile == null) {
readPbrFileAndWait();
}
if (mPbrFile == null) return null;
int numRecs = mPbrFile.mFileIds.size();
for (int i = 0; i < numRecs; i++) {
readAdnFileAndWait(i);
readEmailFileAndWait(i);
}
// All EF files are loaded, post the response.
}
return mPhoneBookRecords;
|
private void | log(java.lang.String msg)
if(DBG) Rlog.d(LOG_TAG, msg);
|
void | parseType1EmailFile(int numRecs)
mEmailsForAdnRec = new HashMap<Integer, ArrayList<String>>();
byte[] emailRec = null;
for (int i = 0; i < numRecs; i++) {
try {
emailRec = mEmailFileRecord.get(i);
} catch (IndexOutOfBoundsException e) {
Rlog.e(LOG_TAG, "Error: Improper ICC card: No email record for ADN, continuing");
break;
}
int adnRecNum = emailRec[emailRec.length - 1];
if (adnRecNum == -1) {
continue;
}
String email = readEmailRecord(i);
if (email == null || email.equals("")) {
continue;
}
// SIM record numbers are 1 based.
ArrayList<String> val = mEmailsForAdnRec.get(adnRecNum - 1);
if (val == null) {
val = new ArrayList<String>();
}
val.add(email);
// SIM record numbers are 1 based.
mEmailsForAdnRec.put(adnRecNum - 1, val);
}
|
private void | readAdnFileAndWait(int recNum)
Map <Integer,Integer> fileIds;
fileIds = mPbrFile.mFileIds.get(recNum);
if (fileIds == null || fileIds.isEmpty()) return;
int extEf = 0;
// Only call fileIds.get while EFEXT1_TAG is available
if (fileIds.containsKey(USIM_EFEXT1_TAG)) {
extEf = fileIds.get(USIM_EFEXT1_TAG);
}
mAdnCache.requestLoadAllAdnLike(fileIds.get(USIM_EFADN_TAG),
extEf, obtainMessage(EVENT_USIM_ADN_LOAD_DONE));
try {
mLock.wait();
} catch (InterruptedException e) {
Rlog.e(LOG_TAG, "Interrupted Exception in readAdnFileAndWait");
}
|
private void | readEmailFileAndWait(int recNum)
Map <Integer,Integer> fileIds;
fileIds = mPbrFile.mFileIds.get(recNum);
if (fileIds == null) return;
if (fileIds.containsKey(USIM_EFEMAIL_TAG)) {
int efid = fileIds.get(USIM_EFEMAIL_TAG);
// Check if the EFEmail is a Type 1 file or a type 2 file.
// If mEmailPresentInIap is true, its a type 2 file.
// So we read the IAP file and then read the email records.
// instead of reading directly.
if (mEmailPresentInIap) {
readIapFileAndWait(fileIds.get(USIM_EFIAP_TAG));
if (mIapFileRecord == null) {
Rlog.e(LOG_TAG, "Error: IAP file is empty");
return;
}
}
// Read the EFEmail file.
mFh.loadEFLinearFixedAll(fileIds.get(USIM_EFEMAIL_TAG),
obtainMessage(EVENT_EMAIL_LOAD_DONE));
try {
mLock.wait();
} catch (InterruptedException e) {
Rlog.e(LOG_TAG, "Interrupted Exception in readEmailFileAndWait");
}
if (mEmailFileRecord == null) {
Rlog.e(LOG_TAG, "Error: Email file is empty");
return;
}
updatePhoneAdnRecord();
}
|
private java.lang.String | readEmailRecord(int recNum)
byte[] emailRec = null;
try {
emailRec = mEmailFileRecord.get(recNum);
} catch (IndexOutOfBoundsException e) {
return null;
}
// The length of the record is X+2 byte, where X bytes is the email address
String email = IccUtils.adnStringFieldToString(emailRec, 0, emailRec.length - 2);
return email;
|
private void | readIapFileAndWait(int efid)
mFh.loadEFLinearFixedAll(efid, obtainMessage(EVENT_IAP_LOAD_DONE));
try {
mLock.wait();
} catch (InterruptedException e) {
Rlog.e(LOG_TAG, "Interrupted Exception in readIapFileAndWait");
}
|
private void | readPbrFileAndWait()
mFh.loadEFLinearFixedAll(EF_PBR, obtainMessage(EVENT_PBR_LOAD_DONE));
try {
mLock.wait();
} catch (InterruptedException e) {
Rlog.e(LOG_TAG, "Interrupted Exception in readAdnFileAndWait");
}
|
private void | refreshCache()
if (mPbrFile == null) return;
mPhoneBookRecords.clear();
int numRecs = mPbrFile.mFileIds.size();
for (int i = 0; i < numRecs; i++) {
readAdnFileAndWait(i);
}
|
public void | reset()
mPhoneBookRecords.clear();
mIapFileRecord = null;
mEmailFileRecord = null;
mPbrFile = null;
mIsPbrPresent = true;
mRefreshCache = false;
|
private void | updatePhoneAdnRecord()
if (mEmailFileRecord == null) return;
int numAdnRecs = mPhoneBookRecords.size();
if (mIapFileRecord != null) {
// The number of records in the IAP file is same as the number of records in ADN file.
// The order of the pointers in an EFIAP shall be the same as the order of file IDs
// that appear in the TLV object indicated by Tag 'A9' in the reference file record.
// i.e value of mEmailTagNumberInIap
for (int i = 0; i < numAdnRecs; i++) {
byte[] record = null;
try {
record = mIapFileRecord.get(i);
} catch (IndexOutOfBoundsException e) {
Rlog.e(LOG_TAG, "Error: Improper ICC card: No IAP record for ADN, continuing");
break;
}
int recNum = record[mEmailTagNumberInIap];
if (recNum != -1) {
String[] emails = new String[1];
// SIM record numbers are 1 based
emails[0] = readEmailRecord(recNum - 1);
AdnRecord rec = mPhoneBookRecords.get(i);
if (rec != null) {
rec.setEmails(emails);
} else {
// might be a record with only email
rec = new AdnRecord("", "", emails);
}
mPhoneBookRecords.set(i, rec);
}
}
}
// ICC cards can be made such that they have an IAP file but all
// records are empty. So we read both type 1 and type 2 file
// email records, just to be sure.
int len = mPhoneBookRecords.size();
// Type 1 file, the number of records is the same as the number of
// records in the ADN file.
if (mEmailsForAdnRec == null) {
parseType1EmailFile(len);
}
for (int i = 0; i < numAdnRecs; i++) {
ArrayList<String> emailList = null;
try {
emailList = mEmailsForAdnRec.get(i);
} catch (IndexOutOfBoundsException e) {
break;
}
if (emailList == null) continue;
AdnRecord rec = mPhoneBookRecords.get(i);
String[] emails = new String[emailList.size()];
System.arraycopy(emailList.toArray(), 0, emails, 0, emailList.size());
rec.setEmails(emails);
mPhoneBookRecords.set(i, rec);
}
|