use of com.android.internal.telephony.ApnSetting in project XobotOS by xamarin.
the class GsmDataConnectionTracker method buildWaitingApns.
/**
* Build a list of APNs to be used to create PDP's.
*
* @param requestedApnType
* @return waitingApns list to be used to create PDP
* error when waitingApns.isEmpty()
*/
private ArrayList<ApnSetting> buildWaitingApns(String requestedApnType) {
ArrayList<ApnSetting> apnList = new ArrayList<ApnSetting>();
if (requestedApnType.equals(Phone.APN_TYPE_DUN)) {
ApnSetting dun = fetchDunApn();
if (dun != null) {
apnList.add(dun);
if (DBG)
log("buildWaitingApns: X added APN_TYPE_DUN apnList=" + apnList);
return apnList;
}
}
String operator = mPhone.mIccRecords.getOperatorNumeric();
int radioTech = mPhone.getServiceState().getRadioTechnology();
if (requestedApnType.equals(Phone.APN_TYPE_DEFAULT)) {
if (canSetPreferApn && mPreferredApn != null) {
if (DBG) {
log("buildWaitingApns: Preferred APN:" + operator + ":" + mPreferredApn.numeric + ":" + mPreferredApn);
}
if (mPreferredApn.numeric.equals(operator)) {
if (mPreferredApn.bearer == 0 || mPreferredApn.bearer == radioTech) {
apnList.add(mPreferredApn);
if (DBG)
log("buildWaitingApns: X added preferred apnList=" + apnList);
return apnList;
} else {
if (DBG)
log("buildWaitingApns: no preferred APN");
setPreferredApn(-1);
mPreferredApn = null;
}
} else {
if (DBG)
log("buildWaitingApns: no preferred APN");
setPreferredApn(-1);
mPreferredApn = null;
}
}
}
if (mAllApns != null) {
for (ApnSetting apn : mAllApns) {
if (apn.canHandleType(requestedApnType)) {
if (apn.bearer == 0 || apn.bearer == radioTech) {
if (DBG)
log("apn info : " + apn.toString());
apnList.add(apn);
}
}
}
} else {
loge("mAllApns is empty!");
}
if (DBG)
log("buildWaitingApns: X apnList=" + apnList);
return apnList;
}
use of com.android.internal.telephony.ApnSetting in project XobotOS by xamarin.
the class GsmDataConnectionTracker method onDataSetupComplete.
@Override
protected void onDataSetupComplete(AsyncResult ar) {
ApnContext apnContext = null;
if (ar.userObj instanceof ApnContext) {
apnContext = (ApnContext) ar.userObj;
} else {
throw new RuntimeException("onDataSetupComplete: No apnContext");
}
if (isDataSetupCompleteOk(ar)) {
DataConnectionAc dcac = apnContext.getDataConnectionAc();
if (dcac == null) {
throw new RuntimeException("onDataSetupCompete: No dcac");
}
DataConnection dc = apnContext.getDataConnection();
if (DBG) {
log(String.format("onDataSetupComplete: success apn=%s", apnContext.getWaitingApns().get(0).apn));
}
ApnSetting apn = apnContext.getApnSetting();
if (apn.proxy != null && apn.proxy.length() != 0) {
try {
String port = apn.port;
if (TextUtils.isEmpty(port))
port = "8080";
ProxyProperties proxy = new ProxyProperties(apn.proxy, Integer.parseInt(port), null);
dcac.setLinkPropertiesHttpProxySync(proxy);
} catch (NumberFormatException e) {
loge("onDataSetupComplete: NumberFormatException making ProxyProperties (" + apn.port + "): " + e);
}
}
// everything is setup
if (TextUtils.equals(apnContext.getApnType(), Phone.APN_TYPE_DEFAULT)) {
SystemProperties.set("gsm.defaultpdpcontext.active", "true");
if (canSetPreferApn && mPreferredApn == null) {
if (DBG)
log("onDataSetupComplete: PREFERED APN is null");
mPreferredApn = apnContext.getApnSetting();
if (mPreferredApn != null) {
setPreferredApn(mPreferredApn.id);
}
}
} else {
SystemProperties.set("gsm.defaultpdpcontext.active", "false");
}
notifyDefaultData(apnContext);
} else {
String apnString;
DataConnection.FailCause cause;
cause = (DataConnection.FailCause) (ar.result);
if (DBG) {
try {
apnString = apnContext.getWaitingApns().get(0).apn;
} catch (Exception e) {
apnString = "<unknown>";
}
log(String.format("onDataSetupComplete: error apn=%s cause=%s", apnString, cause));
}
if (cause.isEventLoggable()) {
// Log this failure to the Event Logs.
int cid = getCellLocationId();
EventLog.writeEvent(EventLogTags.PDP_SETUP_FAIL, cause.ordinal(), cid, TelephonyManager.getDefault().getNetworkType());
}
// Count permanent failures and remove the APN we just tried
if (cause.isPermanentFail())
apnContext.decWaitingApnsPermFailCount();
apnContext.removeNextWaitingApn();
if (DBG) {
log(String.format("onDataSetupComplete: WaitingApns.size=%d" + " WaitingApnsPermFailureCountDown=%d", apnContext.getWaitingApns().size(), apnContext.getWaitingApnsPermFailCount()));
}
// See if there are more APN's to try
if (apnContext.getWaitingApns().isEmpty()) {
if (apnContext.getWaitingApnsPermFailCount() == 0) {
if (DBG) {
log("onDataSetupComplete: All APN's had permanent failures, stop retrying");
}
apnContext.setState(State.FAILED);
mPhone.notifyDataConnection(Phone.REASON_APN_FAILED, apnContext.getApnType());
apnContext.setDataConnection(null);
apnContext.setDataConnectionAc(null);
if (DBG) {
log("onDataSetupComplete: permanent error apn=%s" + apnString);
}
} else {
if (DBG)
log("onDataSetupComplete: Not all permanent failures, retry");
// check to see if retry should be overridden for this failure.
int retryOverride = -1;
if (ar.exception instanceof DataConnection.CallSetupException) {
retryOverride = ((DataConnection.CallSetupException) ar.exception).getRetryOverride();
}
if (retryOverride == RILConstants.MAX_INT) {
if (DBG)
log("No retry is suggested.");
} else {
startDelayedRetry(cause, apnContext, retryOverride);
}
}
} else {
if (DBG)
log("onDataSetupComplete: Try next APN");
apnContext.setState(State.SCANNING);
// Wait a bit before trying the next APN, so that
// we're not tying up the RIL command channel
startAlarmForReconnect(APN_DELAY_MILLIS, apnContext);
}
}
}
Aggregations