use of com.android.internal.telephony.AdnRecord in project XobotOS by xamarin.
the class IccProvider method loadFromEf.
private ArrayList<ArrayList> loadFromEf(int efType) {
ArrayList<ArrayList> results = new ArrayList<ArrayList>();
List<AdnRecord> adnRecords = null;
if (DBG)
log("loadFromEf: efType=" + efType);
try {
IIccPhoneBook iccIpb = IIccPhoneBook.Stub.asInterface(ServiceManager.getService("simphonebook"));
if (iccIpb != null) {
adnRecords = iccIpb.getAdnRecordsInEf(efType);
}
} catch (RemoteException ex) {
// ignore it
} catch (SecurityException ex) {
if (DBG)
log(ex.toString());
}
if (adnRecords != null) {
// Load the results
int N = adnRecords.size();
if (DBG)
log("adnRecords.size=" + N);
for (int i = 0; i < N; i++) {
loadRecord(adnRecords.get(i), results);
}
} else {
// No results to load
Log.w(TAG, "Cannot load ADN records");
results.clear();
}
if (DBG)
log("loadFromEf: return results");
return results;
}
use of com.android.internal.telephony.AdnRecord in project XobotOS by xamarin.
the class SIMRecords method handleMessage.
// ***** Overridden from Handler
public void handleMessage(Message msg) {
AsyncResult ar;
AdnRecord adn;
byte[] data;
boolean isRecordLoadResponse = false;
try {
switch(msg.what) {
case EVENT_SIM_READY:
onSimReady();
break;
case EVENT_RADIO_OFF_OR_NOT_AVAILABLE:
onRadioOffOrNotAvailable();
break;
/* IO events */
case EVENT_GET_IMSI_DONE:
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
if (ar.exception != null) {
Log.e(LOG_TAG, "Exception querying IMSI, Exception:" + ar.exception);
break;
}
imsi = (String) ar.result;
// than 15 (and usually 15).
if (imsi != null && (imsi.length() < 6 || imsi.length() > 15)) {
Log.e(LOG_TAG, "invalid IMSI " + imsi);
imsi = null;
}
Log.d(LOG_TAG, "IMSI: " + /* imsi.substring(0, 6) +*/
"xxxxxxx");
if (((mncLength == UNKNOWN) || (mncLength == 2)) && ((imsi != null) && (imsi.length() >= 6))) {
String mccmncCode = imsi.substring(0, 6);
for (String mccmnc : MCCMNC_CODES_HAVING_3DIGITS_MNC) {
if (mccmnc.equals(mccmncCode)) {
mncLength = 3;
break;
}
}
}
if (mncLength == UNKNOWN) {
// guess using the mcc
try {
int mcc = Integer.parseInt(imsi.substring(0, 3));
mncLength = MccTable.smallestDigitsMccForMnc(mcc);
} catch (NumberFormatException e) {
mncLength = UNKNOWN;
Log.e(LOG_TAG, "SIMRecords: Corrupt IMSI!");
}
}
if (mncLength != UNKNOWN && mncLength != UNINITIALIZED) {
// finally have both the imsi and the mncLength and can parse the imsi properly
MccTable.updateMccMncConfiguration(phone, imsi.substring(0, 3 + mncLength));
}
phone.mIccCard.broadcastIccStateChangedIntent(SimCard.INTENT_VALUE_ICC_IMSI, null);
break;
case EVENT_GET_MBI_DONE:
boolean isValidMbdn;
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
data = (byte[]) ar.result;
isValidMbdn = false;
if (ar.exception == null) {
// Refer TS 51.011 Section 10.3.44 for content details
Log.d(LOG_TAG, "EF_MBI: " + IccUtils.bytesToHexString(data));
// Voice mail record number stored first
mailboxIndex = (int) data[0] & 0xff;
// check if dailing numbe id valid
if (mailboxIndex != 0 && mailboxIndex != 0xff) {
Log.d(LOG_TAG, "Got valid mailbox number for MBDN");
isValidMbdn = true;
}
}
// one more record to load
recordsToLoad += 1;
if (isValidMbdn) {
// Note: MBDN was not included in NUM_OF_SIM_RECORDS_LOADED
new AdnRecordLoader(phone).loadFromEF(EF_MBDN, EF_EXT6, mailboxIndex, obtainMessage(EVENT_GET_MBDN_DONE));
} else {
// If this EF not present, try mailbox as in CPHS standard
// CPHS (CPHS4_2.WW6) is a european standard.
new AdnRecordLoader(phone).loadFromEF(EF_MAILBOX_CPHS, EF_EXT1, 1, obtainMessage(EVENT_GET_CPHS_MAILBOX_DONE));
}
break;
case EVENT_GET_CPHS_MAILBOX_DONE:
case EVENT_GET_MBDN_DONE:
//Resetting the voice mail number and voice mail tag to null
//as these should be updated from the data read from EF_MBDN.
//If they are not reset, incase of invalid data/exception these
//variables are retaining their previous values and are
//causing invalid voice mailbox info display to user.
voiceMailNum = null;
voiceMailTag = null;
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
if (ar.exception != null) {
Log.d(LOG_TAG, "Invalid or missing EF" + ((msg.what == EVENT_GET_CPHS_MAILBOX_DONE) ? "[MAILBOX]" : "[MBDN]"));
if (msg.what == EVENT_GET_MBDN_DONE) {
//load CPHS on fail...
// FIXME right now, only load line1's CPHS voice mail entry
recordsToLoad += 1;
new AdnRecordLoader(phone).loadFromEF(EF_MAILBOX_CPHS, EF_EXT1, 1, obtainMessage(EVENT_GET_CPHS_MAILBOX_DONE));
}
break;
}
adn = (AdnRecord) ar.result;
Log.d(LOG_TAG, "VM: " + adn + ((msg.what == EVENT_GET_CPHS_MAILBOX_DONE) ? " EF[MAILBOX]" : " EF[MBDN]"));
if (adn.isEmpty() && msg.what == EVENT_GET_MBDN_DONE) {
// Bug #645770 fall back to CPHS
// FIXME should use SST to decide
// FIXME right now, only load line1's CPHS voice mail entry
recordsToLoad += 1;
new AdnRecordLoader(phone).loadFromEF(EF_MAILBOX_CPHS, EF_EXT1, 1, obtainMessage(EVENT_GET_CPHS_MAILBOX_DONE));
break;
}
voiceMailNum = adn.getNumber();
voiceMailTag = adn.getAlphaTag();
break;
case EVENT_GET_MSISDN_DONE:
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
if (ar.exception != null) {
Log.d(LOG_TAG, "Invalid or missing EF[MSISDN]");
break;
}
adn = (AdnRecord) ar.result;
msisdn = adn.getNumber();
msisdnTag = adn.getAlphaTag();
Log.d(LOG_TAG, "MSISDN: " + /*msisdn*/
"xxxxxxx");
break;
case EVENT_SET_MSISDN_DONE:
isRecordLoadResponse = false;
ar = (AsyncResult) msg.obj;
if (ar.userObj != null) {
AsyncResult.forMessage(((Message) ar.userObj)).exception = ar.exception;
((Message) ar.userObj).sendToTarget();
}
break;
case EVENT_GET_MWIS_DONE:
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
data = (byte[]) ar.result;
if (ar.exception != null) {
break;
}
Log.d(LOG_TAG, "EF_MWIS: " + IccUtils.bytesToHexString(data));
efMWIS = data;
if ((data[0] & 0xff) == 0xff) {
Log.d(LOG_TAG, "SIMRecords: Uninitialized record MWIS");
break;
}
// Refer TS 51.011 Section 10.3.45 for the content description
boolean voiceMailWaiting = ((data[0] & 0x01) != 0);
countVoiceMessages = data[1] & 0xff;
if (voiceMailWaiting && countVoiceMessages == 0) {
// Unknown count = -1
countVoiceMessages = -1;
}
phone.notifyMessageWaitingIndicator();
break;
case EVENT_GET_VOICE_MAIL_INDICATOR_CPHS_DONE:
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
data = (byte[]) ar.result;
if (ar.exception != null) {
break;
}
efCPHS_MWI = data;
if (efMWIS == null) {
int indicator = (int) (data[0] & 0xf);
// Refer CPHS4_2.WW6 B4.2.3
if (indicator == 0xA) {
// Unknown count = -1
countVoiceMessages = -1;
} else if (indicator == 0x5) {
countVoiceMessages = 0;
}
phone.notifyMessageWaitingIndicator();
}
break;
case EVENT_GET_ICCID_DONE:
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
data = (byte[]) ar.result;
if (ar.exception != null) {
break;
}
iccid = IccUtils.bcdToString(data, 0, data.length);
Log.d(LOG_TAG, "iccid: " + iccid);
break;
case EVENT_GET_AD_DONE:
try {
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
data = (byte[]) ar.result;
if (ar.exception != null) {
break;
}
Log.d(LOG_TAG, "EF_AD: " + IccUtils.bytesToHexString(data));
if (data.length < 3) {
Log.d(LOG_TAG, "SIMRecords: Corrupt AD data on SIM");
break;
}
if (data.length == 3) {
Log.d(LOG_TAG, "SIMRecords: MNC length not present in EF_AD");
break;
}
mncLength = (int) data[3] & 0xf;
if (mncLength == 0xf) {
mncLength = UNKNOWN;
}
} finally {
if (((mncLength == UNINITIALIZED) || (mncLength == UNKNOWN) || (mncLength == 2)) && ((imsi != null) && (imsi.length() >= 6))) {
String mccmncCode = imsi.substring(0, 6);
for (String mccmnc : MCCMNC_CODES_HAVING_3DIGITS_MNC) {
if (mccmnc.equals(mccmncCode)) {
mncLength = 3;
break;
}
}
}
if (mncLength == UNKNOWN || mncLength == UNINITIALIZED) {
if (imsi != null) {
try {
int mcc = Integer.parseInt(imsi.substring(0, 3));
mncLength = MccTable.smallestDigitsMccForMnc(mcc);
} catch (NumberFormatException e) {
mncLength = UNKNOWN;
Log.e(LOG_TAG, "SIMRecords: Corrupt IMSI!");
}
} else {
// Indicate we got this info, but it didn't contain the length.
mncLength = UNKNOWN;
Log.d(LOG_TAG, "SIMRecords: MNC length not present in EF_AD");
}
}
if (imsi != null && mncLength != UNKNOWN) {
// finally have both imsi and the length of the mnc and can parse
// the imsi properly
MccTable.updateMccMncConfiguration(phone, imsi.substring(0, 3 + mncLength));
}
}
break;
case EVENT_GET_SPN_DONE:
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
getSpnFsm(false, ar);
break;
case EVENT_GET_CFF_DONE:
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
data = (byte[]) ar.result;
if (ar.exception != null) {
break;
}
Log.d(LOG_TAG, "EF_CFF_CPHS: " + IccUtils.bytesToHexString(data));
mEfCff = data;
if (mEfCfis == null) {
callForwardingEnabled = ((data[0] & CFF_LINE1_MASK) == CFF_UNCONDITIONAL_ACTIVE);
phone.notifyCallForwardingIndicator();
}
break;
case EVENT_GET_SPDI_DONE:
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
data = (byte[]) ar.result;
if (ar.exception != null) {
break;
}
parseEfSpdi(data);
break;
case EVENT_UPDATE_DONE:
ar = (AsyncResult) msg.obj;
if (ar.exception != null) {
Log.i(LOG_TAG, "SIMRecords update failed", ar.exception);
}
break;
case EVENT_GET_PNN_DONE:
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
data = (byte[]) ar.result;
if (ar.exception != null) {
break;
}
SimTlv tlv = new SimTlv(data, 0, data.length);
for (; tlv.isValidObject(); tlv.nextObject()) {
if (tlv.getTag() == TAG_FULL_NETWORK_NAME) {
pnnHomeName = IccUtils.networkNameToString(tlv.getData(), 0, tlv.getData().length);
break;
}
}
break;
case EVENT_GET_ALL_SMS_DONE:
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
if (ar.exception != null)
break;
handleSmses((ArrayList) ar.result);
break;
case EVENT_MARK_SMS_READ_DONE:
Log.i("ENF", "marked read: sms " + msg.arg1);
break;
case EVENT_SMS_ON_SIM:
isRecordLoadResponse = false;
ar = (AsyncResult) msg.obj;
int[] index = (int[]) ar.result;
if (ar.exception != null || index.length != 1) {
Log.e(LOG_TAG, "[SIMRecords] Error on SMS_ON_SIM with exp " + ar.exception + " length " + index.length);
} else {
Log.d(LOG_TAG, "READ EF_SMS RECORD index=" + index[0]);
phone.getIccFileHandler().loadEFLinearFixed(EF_SMS, index[0], obtainMessage(EVENT_GET_SMS_DONE));
}
break;
case EVENT_GET_SMS_DONE:
isRecordLoadResponse = false;
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
handleSms((byte[]) ar.result);
} else {
Log.e(LOG_TAG, "[SIMRecords] Error on GET_SMS with exp " + ar.exception);
}
break;
case EVENT_GET_SST_DONE:
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
data = (byte[]) ar.result;
if (ar.exception != null) {
break;
}
//Log.d(LOG_TAG, "SST: " + IccUtils.bytesToHexString(data));
break;
case EVENT_GET_INFO_CPHS_DONE:
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
if (ar.exception != null) {
break;
}
mCphsInfo = (byte[]) ar.result;
if (DBG)
log("iCPHS: " + IccUtils.bytesToHexString(mCphsInfo));
break;
case EVENT_SET_MBDN_DONE:
isRecordLoadResponse = false;
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
voiceMailNum = newVoiceMailNum;
voiceMailTag = newVoiceMailTag;
}
if (isCphsMailboxEnabled()) {
adn = new AdnRecord(voiceMailTag, voiceMailNum);
Message onCphsCompleted = (Message) ar.userObj;
/* write to cphs mailbox whenever it is available but
* we only need notify caller once if both updating are
* successful.
*
* so if set_mbdn successful, notify caller here and set
* onCphsCompleted to null
*/
if (ar.exception == null && ar.userObj != null) {
AsyncResult.forMessage(((Message) ar.userObj)).exception = null;
((Message) ar.userObj).sendToTarget();
if (DBG)
log("Callback with MBDN successful.");
onCphsCompleted = null;
}
new AdnRecordLoader(phone).updateEF(adn, EF_MAILBOX_CPHS, EF_EXT1, 1, null, obtainMessage(EVENT_SET_CPHS_MAILBOX_DONE, onCphsCompleted));
} else {
if (ar.userObj != null) {
AsyncResult.forMessage(((Message) ar.userObj)).exception = ar.exception;
((Message) ar.userObj).sendToTarget();
}
}
break;
case EVENT_SET_CPHS_MAILBOX_DONE:
isRecordLoadResponse = false;
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
voiceMailNum = newVoiceMailNum;
voiceMailTag = newVoiceMailTag;
} else {
if (DBG)
log("Set CPHS MailBox with exception: " + ar.exception);
}
if (ar.userObj != null) {
if (DBG)
log("Callback with CPHS MB successful.");
AsyncResult.forMessage(((Message) ar.userObj)).exception = ar.exception;
((Message) ar.userObj).sendToTarget();
}
break;
case EVENT_SIM_REFRESH:
isRecordLoadResponse = false;
ar = (AsyncResult) msg.obj;
if (DBG)
log("Sim REFRESH with exception: " + ar.exception);
if (ar.exception == null) {
handleSimRefresh((int[]) (ar.result));
}
break;
case EVENT_GET_CFIS_DONE:
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
data = (byte[]) ar.result;
if (ar.exception != null) {
break;
}
Log.d(LOG_TAG, "EF_CFIS: " + IccUtils.bytesToHexString(data));
mEfCfis = data;
// Refer TS 51.011 Section 10.3.46 for the content description
callForwardingEnabled = ((data[1] & 0x01) != 0);
phone.notifyCallForwardingIndicator();
break;
case EVENT_GET_CSP_CPHS_DONE:
isRecordLoadResponse = true;
ar = (AsyncResult) msg.obj;
if (ar.exception != null) {
Log.e(LOG_TAG, "Exception in fetching EF_CSP data " + ar.exception);
break;
}
data = (byte[]) ar.result;
Log.i(LOG_TAG, "EF_CSP: " + IccUtils.bytesToHexString(data));
handleEfCspData(data);
break;
default:
// IccRecords handles generic record load responses
super.handleMessage(msg);
}
} catch (RuntimeException exc) {
// I don't want these exceptions to be fatal
Log.w(LOG_TAG, "Exception parsing SIM record", exc);
} finally {
// Count up record load responses even if they are fails
if (isRecordLoadResponse) {
onRecordLoaded();
}
}
}
use of com.android.internal.telephony.AdnRecord in project XobotOS by xamarin.
the class UsimPhoneBookManager method updatePhoneAdnRecord.
private void updatePhoneAdnRecord() {
if (mEmailFileRecord == null)
return;
int numAdnRecs = mPhoneBookRecords.size();
if (mIapFileRecord != null) {
for (int i = 0; i < numAdnRecs; i++) {
byte[] record = null;
try {
record = mIapFileRecord.get(i);
} catch (IndexOutOfBoundsException e) {
Log.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();
// 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);
}
}
use of com.android.internal.telephony.AdnRecord in project XobotOS by xamarin.
the class SIMRecords method setMsisdnNumber.
/**
* Set subscriber number to SIM record
*
* The subscriber number is stored in EF_MSISDN (TS 51.011)
*
* When the operation is complete, onComplete will be sent to its handler
*
* @param alphaTag alpha-tagging of the dailing nubmer (up to 10 characters)
* @param number dailing nubmer (up to 20 digits)
* if the number starts with '+', then set to international TOA
* @param onComplete
* onComplete.obj will be an AsyncResult
* ((AsyncResult)onComplete.obj).exception == null on success
* ((AsyncResult)onComplete.obj).exception != null on fail
*/
public void setMsisdnNumber(String alphaTag, String number, Message onComplete) {
msisdn = number;
msisdnTag = alphaTag;
if (DBG)
log("Set MSISDN: " + msisdnTag + " " + /*msisdn*/
"xxxxxxx");
AdnRecord adn = new AdnRecord(msisdnTag, msisdn);
new AdnRecordLoader(phone).updateEF(adn, EF_MSISDN, EF_EXT1, 1, null, obtainMessage(EVENT_SET_MSISDN_DONE, onComplete));
}
use of com.android.internal.telephony.AdnRecord in project XobotOS by xamarin.
the class SIMRecords method setVoiceMailNumber.
/**
* Set voice mail number to SIM record
*
* The voice mail number can be stored either in EF_MBDN (TS 51.011) or
* EF_MAILBOX_CPHS (CPHS 4.2)
*
* If EF_MBDN is available, store the voice mail number to EF_MBDN
*
* If EF_MAILBOX_CPHS is enabled, store the voice mail number to EF_CHPS
*
* So the voice mail number will be stored in both EFs if both are available
*
* Return error only if both EF_MBDN and EF_MAILBOX_CPHS fail.
*
* When the operation is complete, onComplete will be sent to its handler
*
* @param alphaTag alpha-tagging of the dailing nubmer (upto 10 characters)
* @param voiceNumber dailing nubmer (upto 20 digits)
* if the number is start with '+', then set to international TOA
* @param onComplete
* onComplete.obj will be an AsyncResult
* ((AsyncResult)onComplete.obj).exception == null on success
* ((AsyncResult)onComplete.obj).exception != null on fail
*/
public void setVoiceMailNumber(String alphaTag, String voiceNumber, Message onComplete) {
if (isVoiceMailFixed) {
AsyncResult.forMessage((onComplete)).exception = new IccVmFixedException("Voicemail number is fixed by operator");
onComplete.sendToTarget();
return;
}
newVoiceMailNum = voiceNumber;
newVoiceMailTag = alphaTag;
AdnRecord adn = new AdnRecord(newVoiceMailTag, newVoiceMailNum);
if (mailboxIndex != 0 && mailboxIndex != 0xff) {
new AdnRecordLoader(phone).updateEF(adn, EF_MBDN, EF_EXT6, mailboxIndex, null, obtainMessage(EVENT_SET_MBDN_DONE, onComplete));
} else if (isCphsMailboxEnabled()) {
new AdnRecordLoader(phone).updateEF(adn, EF_MAILBOX_CPHS, EF_EXT1, 1, null, obtainMessage(EVENT_SET_CPHS_MAILBOX_DONE, onComplete));
} else {
AsyncResult.forMessage((onComplete)).exception = new IccVmNotSupportedException("Update SIM voice mailbox error");
onComplete.sendToTarget();
}
}
Aggregations