use of android.os.AsyncResult in project XobotOS by xamarin.
the class SIMRecords method onAllRecordsLoaded.
protected void onAllRecordsLoaded() {
Log.d(LOG_TAG, "SIMRecords: record load complete");
String operator = getOperatorNumeric();
// Some fields require more than one SIM record to set
phone.setSystemProperty(PROPERTY_ICC_OPERATOR_NUMERIC, operator);
if (imsi != null) {
phone.setSystemProperty(PROPERTY_ICC_OPERATOR_ISO_COUNTRY, MccTable.countryCodeForMcc(Integer.parseInt(imsi.substring(0, 3))));
} else {
Log.e("SIM", "[SIMRecords] onAllRecordsLoaded: imsi is NULL!");
}
setVoiceMailByCountry(operator);
setSpnFromConfig(operator);
recordsLoadedRegistrants.notifyRegistrants(new AsyncResult(null, null, null));
phone.mIccCard.broadcastIccStateChangedIntent(SimCard.INTENT_VALUE_ICC_LOADED, null);
}
use of android.os.AsyncResult 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 android.os.AsyncResult in project XobotOS by xamarin.
the class GsmServiceStateTracker method handleMessage.
public void handleMessage(Message msg) {
AsyncResult ar;
int[] ints;
String[] strings;
Message message;
switch(msg.what) {
case EVENT_RADIO_AVAILABLE:
//setPowerStateToDesired();
break;
case EVENT_SIM_READY:
// powered on.
if (mNeedToRegForSimLoaded) {
phone.mIccRecords.registerForRecordsLoaded(this, EVENT_SIM_RECORDS_LOADED, null);
mNeedToRegForSimLoaded = false;
}
boolean skipRestoringSelection = phone.getContext().getResources().getBoolean(com.android.internal.R.bool.skip_restoring_network_selection);
if (!skipRestoringSelection) {
// restore the previous network selection.
phone.restoreSavedNetworkSelection(null);
}
pollState();
// Signal strength polling stops when radio is off
queueNextSignalStrengthPoll();
break;
case EVENT_RADIO_STATE_CHANGED:
// This will do nothing in the radio not
// available case
setPowerStateToDesired();
pollState();
break;
case EVENT_NETWORK_STATE_CHANGED:
pollState();
break;
case EVENT_GET_SIGNAL_STRENGTH:
if (!(cm.getRadioState().isOn()) || (cm.getRadioState().isCdma())) {
// Polling will continue when radio turns back on and not CDMA
return;
}
ar = (AsyncResult) msg.obj;
onSignalStrengthResult(ar);
queueNextSignalStrengthPoll();
break;
case EVENT_GET_LOC_DONE:
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
String[] states = (String[]) ar.result;
int lac = -1;
int cid = -1;
if (states.length >= 3) {
try {
if (states[1] != null && states[1].length() > 0) {
lac = Integer.parseInt(states[1], 16);
}
if (states[2] != null && states[2].length() > 0) {
cid = Integer.parseInt(states[2], 16);
}
} catch (NumberFormatException ex) {
Log.w(LOG_TAG, "error parsing location: " + ex);
}
}
cellLoc.setLacAndCid(lac, cid);
phone.notifyLocationChanged();
}
// Release any temporary cell lock, which could have been
// acquired to allow a single-shot location update.
disableSingleLocationUpdate();
break;
case EVENT_POLL_STATE_REGISTRATION:
case EVENT_POLL_STATE_GPRS:
case EVENT_POLL_STATE_OPERATOR:
case EVENT_POLL_STATE_NETWORK_SELECTION_MODE:
ar = (AsyncResult) msg.obj;
handlePollStateResult(msg.what, ar);
break;
case EVENT_POLL_SIGNAL_STRENGTH:
// Just poll signal strength...not part of pollState()
cm.getSignalStrength(obtainMessage(EVENT_GET_SIGNAL_STRENGTH));
break;
case EVENT_NITZ_TIME:
ar = (AsyncResult) msg.obj;
String nitzString = (String) ((Object[]) ar.result)[0];
long nitzReceiveTime = ((Long) ((Object[]) ar.result)[1]).longValue();
setTimeFromNITZString(nitzString, nitzReceiveTime);
break;
case EVENT_SIGNAL_STRENGTH_UPDATE:
// This is a notification from
// CommandsInterface.setOnSignalStrengthUpdate
ar = (AsyncResult) msg.obj;
// The radio is telling us about signal strength changes
// we don't have to ask it
dontPollSignalStrength = true;
onSignalStrengthResult(ar);
break;
case EVENT_SIM_RECORDS_LOADED:
updateSpnDisplay();
break;
case EVENT_LOCATION_UPDATES_ENABLED:
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
cm.getVoiceRegistrationState(obtainMessage(EVENT_GET_LOC_DONE, null));
}
break;
case EVENT_SET_PREFERRED_NETWORK_TYPE:
ar = (AsyncResult) msg.obj;
// Don't care the result, only use for dereg network (COPS=2)
message = obtainMessage(EVENT_RESET_PREFERRED_NETWORK_TYPE, ar.userObj);
cm.setPreferredNetworkType(mPreferredNetworkType, message);
break;
case EVENT_RESET_PREFERRED_NETWORK_TYPE:
ar = (AsyncResult) msg.obj;
if (ar.userObj != null) {
AsyncResult.forMessage(((Message) ar.userObj)).exception = ar.exception;
((Message) ar.userObj).sendToTarget();
}
break;
case EVENT_GET_PREFERRED_NETWORK_TYPE:
ar = (AsyncResult) msg.obj;
if (ar.exception == null) {
mPreferredNetworkType = ((int[]) ar.result)[0];
} else {
mPreferredNetworkType = RILConstants.NETWORK_MODE_GLOBAL;
}
message = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE, ar.userObj);
int toggledNetworkType = RILConstants.NETWORK_MODE_GLOBAL;
cm.setPreferredNetworkType(toggledNetworkType, message);
break;
case EVENT_CHECK_REPORT_GPRS:
if (ss != null && !isGprsConsistent(gprsState, ss.getState())) {
// Can't register data service while voice service is ok
// i.e. CREG is ok while CGREG is not
// possible a network or baseband side error
GsmCellLocation loc = ((GsmCellLocation) phone.getCellLocation());
EventLog.writeEvent(EventLogTags.DATA_NETWORK_REGISTRATION_FAIL, ss.getOperatorNumeric(), loc != null ? loc.getCid() : -1);
mReportedGprsNoReg = true;
}
mStartedGprsRegCheck = false;
break;
case EVENT_RESTRICTED_STATE_CHANGED:
if (DBG)
log("EVENT_RESTRICTED_STATE_CHANGED");
ar = (AsyncResult) msg.obj;
onRestrictedStateChanged(ar);
break;
default:
super.handleMessage(msg);
break;
}
}
use of android.os.AsyncResult in project XobotOS by xamarin.
the class GSMPhone method handlePinMmi.
public boolean handlePinMmi(String dialString) {
GsmMmiCode mmi = GsmMmiCode.newFromDialString(dialString, this);
if (mmi != null && mmi.isPinCommand()) {
mPendingMMIs.add(mmi);
mMmiRegistrants.notifyRegistrants(new AsyncResult(null, mmi, null));
mmi.processCode();
return true;
}
return false;
}
use of android.os.AsyncResult in project XobotOS by xamarin.
the class GSMPhone method sendUssdResponse.
public void sendUssdResponse(String ussdMessge) {
GsmMmiCode mmi = GsmMmiCode.newFromUssdUserInput(ussdMessge, this);
mPendingMMIs.add(mmi);
mMmiRegistrants.notifyRegistrants(new AsyncResult(null, mmi, null));
mmi.sendUssd(ussdMessge);
}
Aggregations