use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.
the class DcTracker method setupData.
/**
* Setup a data connection based on given APN type.
*
* @param apnContext APN context
* @param radioTech RAT of the data connection
* @param requestType Data request type
* @return True if successful, otherwise false.
*/
private boolean setupData(ApnContext apnContext, int radioTech, @RequestNetworkType int requestType) {
if (DBG) {
log("setupData: apnContext=" + apnContext + ", requestType=" + requestTypeToString(requestType));
}
apnContext.requestLog("setupData. requestType=" + requestTypeToString(requestType));
ApnSetting apnSetting;
DataConnection dataConnection = null;
apnSetting = apnContext.getNextApnSetting();
if (apnSetting == null) {
if (DBG)
log("setupData: return for no apn found!");
return false;
}
// profile id is only meaningful when the profile is persistent on the modem.
int profileId = DATA_PROFILE_INVALID;
if (apnSetting.isPersistent()) {
profileId = apnSetting.getProfileId();
if (profileId == DATA_PROFILE_DEFAULT) {
profileId = getApnProfileID(apnContext.getApnType());
}
}
// this type.
if (!apnContext.getApnType().equals(PhoneConstants.APN_TYPE_DUN) || ServiceState.isGsm(getDataRat())) {
dataConnection = checkForCompatibleDataConnection(apnContext, apnSetting);
if (dataConnection != null) {
// Get the apn setting used by the data connection
ApnSetting dataConnectionApnSetting = dataConnection.getApnSetting();
if (dataConnectionApnSetting != null) {
// Setting is good, so use it.
apnSetting = dataConnectionApnSetting;
}
}
}
if (dataConnection == null) {
if (isOnlySingleDcAllowed(radioTech)) {
if (isHigherPriorityApnContextActive(apnContext)) {
if (DBG) {
log("setupData: Higher priority ApnContext active. Ignoring call");
}
return false;
}
// or retry of same APN(State==RETRYING).
if (!apnContext.getApnType().equals(PhoneConstants.APN_TYPE_IMS) && (apnContext.getState() != DctConstants.State.RETRYING)) {
// response for deactivate request for the calls we are about to disconnect
if (cleanUpAllConnectionsInternal(true, Phone.REASON_SINGLE_PDN_ARBITRATION)) {
// to be disconnected.
if (DBG)
log("setupData: Some calls are disconnecting first." + " Wait and retry");
return false;
}
}
// No other calls are active, so proceed
if (DBG)
log("setupData: Single pdp. Continue setting up data call.");
}
dataConnection = findFreeDataConnection();
if (dataConnection == null) {
dataConnection = createDataConnection();
}
if (dataConnection == null) {
if (DBG)
log("setupData: No free DataConnection and couldn't create one, WEIRD");
return false;
}
}
final int generation = apnContext.incAndGetConnectionGeneration();
if (DBG) {
log("setupData: dc=" + dataConnection + " apnSetting=" + apnSetting + " gen#=" + generation);
}
apnContext.setDataConnection(dataConnection);
apnContext.setApnSetting(apnSetting);
apnContext.setState(DctConstants.State.CONNECTING);
mPhone.notifyDataConnection(apnContext.getApnType());
Message msg = obtainMessage();
msg.what = DctConstants.EVENT_DATA_SETUP_COMPLETE;
msg.obj = new Pair<ApnContext, Integer>(apnContext, generation);
ApnSetting preferredApn = getPreferredApn();
boolean isPreferredApn = apnSetting.equals(preferredApn);
dataConnection.bringUp(apnContext, profileId, radioTech, msg, generation, requestType, mPhone.getSubId(), isPreferredApn);
if (DBG) {
if (isPreferredApn) {
log("setupData: initing! isPreferredApn=" + isPreferredApn + ", apnSetting={" + apnSetting.toString() + "}");
} else {
String preferredApnStr = preferredApn == null ? "null" : preferredApn.toString();
log("setupData: initing! isPreferredApn=" + isPreferredApn + ", apnSetting={" + apnSetting + "}" + ", preferredApn={" + preferredApnStr + "}");
}
}
return true;
}
use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.
the class DcTracker method setInitialAttachApn.
protected void setInitialAttachApn() {
ApnSetting iaApnSetting = null;
ApnSetting defaultApnSetting = null;
ApnSetting firstNonEmergencyApnSetting = null;
log("setInitialApn: E mPreferredApn=" + mPreferredApn);
if (mPreferredApn != null && mPreferredApn.canHandleType(ApnSetting.TYPE_IA)) {
iaApnSetting = mPreferredApn;
} else if (!mAllApnSettings.isEmpty()) {
// Search for Initial APN setting and the first apn that can handle default
int preferredApnSetId = getPreferredApnSetId();
for (ApnSetting apn : mAllApnSettings) {
if (preferredApnSetId != apn.getApnSetId()) {
if (VDBG) {
log("setInitialApn: APN set id " + apn.getApnSetId() + " does not match the preferred set id " + preferredApnSetId);
}
continue;
}
if (firstNonEmergencyApnSetting == null && !apn.isEmergencyApn()) {
firstNonEmergencyApnSetting = apn;
log("setInitialApn: firstNonEmergencyApnSetting=" + firstNonEmergencyApnSetting);
}
if (apn.canHandleType(ApnSetting.TYPE_IA)) {
// The Initial Attach APN is highest priority so use it if there is one
log("setInitialApn: iaApnSetting=" + apn);
iaApnSetting = apn;
break;
} else if ((defaultApnSetting == null) && (apn.canHandleType(ApnSetting.TYPE_DEFAULT))) {
// Use the first default apn if no better choice
log("setInitialApn: defaultApnSetting=" + apn);
defaultApnSetting = apn;
}
}
}
if ((iaApnSetting == null) && (defaultApnSetting == null) && !allowInitialAttachForOperator()) {
log("Abort Initial attach");
return;
}
// The priority of apn candidates from highest to lowest is:
// 1) APN_TYPE_IA (Initial Attach)
// 2) mPreferredApn, i.e. the current preferred apn
// 3) The first apn that than handle APN_TYPE_DEFAULT
// 4) The first APN we can find.
ApnSetting initialAttachApnSetting = null;
if (iaApnSetting != null) {
if (DBG)
log("setInitialAttachApn: using iaApnSetting");
initialAttachApnSetting = iaApnSetting;
} else if (mPreferredApn != null) {
if (DBG)
log("setInitialAttachApn: using mPreferredApn");
initialAttachApnSetting = mPreferredApn;
} else if (defaultApnSetting != null) {
if (DBG)
log("setInitialAttachApn: using defaultApnSetting");
initialAttachApnSetting = defaultApnSetting;
} else if (firstNonEmergencyApnSetting != null) {
if (DBG)
log("setInitialAttachApn: using firstNonEmergencyApnSetting");
initialAttachApnSetting = firstNonEmergencyApnSetting;
}
if (initialAttachApnSetting == null) {
if (DBG)
log("setInitialAttachApn: X There in no available apn");
} else {
if (DBG)
log("setInitialAttachApn: X selected Apn=" + initialAttachApnSetting);
mDataServiceManager.setInitialAttachApn(createDataProfile(initialAttachApnSetting, initialAttachApnSetting.equals(getPreferredApn())), mPhone.getServiceState().getDataRoamingFromRegistration(), null);
}
}
use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.
the class DcTracker method createAllApnList.
/**
* Based on the sim operator numeric, create a list for all possible
* Data Connections and setup the preferredApn.
*/
protected void createAllApnList() {
mAllApnSettings.clear();
String operator = mPhone.getOperatorNumeric();
// ORDER BY Telephony.Carriers._ID ("_id")
Cursor cursor = mPhone.getContext().getContentResolver().query(Uri.withAppendedPath(Telephony.Carriers.SIM_APN_URI, "filtered/subId/" + mPhone.getSubId()), null, null, null, Telephony.Carriers._ID);
if (cursor != null) {
while (cursor.moveToNext()) {
ApnSetting apn = ApnSetting.makeApnSetting(cursor);
if (apn == null) {
continue;
}
mAllApnSettings.add(apn);
}
cursor.close();
} else {
if (DBG)
log("createAllApnList: cursor is null");
mApnSettingsInitializationLog.log("cursor is null for carrier, operator: " + operator);
}
addEmergencyApnSetting();
dedupeApnSettings();
if (mAllApnSettings.isEmpty()) {
log("createAllApnList: No APN found for carrier, operator: " + operator);
mApnSettingsInitializationLog.log("no APN found for carrier, operator: " + operator);
mPreferredApn = null;
// Notify that there are no APN Settings,
mPhone.notifyDataConnectionFailed(null, null, DataFailCause.MISSING_UNKNOWN_APN);
} else {
mPreferredApn = getPreferredApn();
if (mPreferredApn != null && !mPreferredApn.getOperatorNumeric().equals(operator)) {
mPreferredApn = null;
setPreferredApn(-1);
}
if (DBG)
log("createAllApnList: mPreferredApn=" + mPreferredApn);
}
if (DBG)
log("createAllApnList: X mAllApnSettings=" + mAllApnSettings);
}
use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.
the class DcTracker method getPreferredApn.
@Nullable
ApnSetting getPreferredApn() {
// Only call this method from main thread
if (mAllApnSettings == null || mAllApnSettings.isEmpty()) {
log("getPreferredApn: mAllApnSettings is empty");
return null;
}
String subId = Long.toString(mPhone.getSubId());
Uri uri = Uri.withAppendedPath(PREFERAPN_NO_UPDATE_URI_USING_SUBID, subId);
Cursor cursor = mPhone.getContext().getContentResolver().query(uri, new String[] { "_id", "name", "apn" }, null, null, Telephony.Carriers.DEFAULT_SORT_ORDER);
if (cursor != null) {
mCanSetPreferApn = true;
} else {
mCanSetPreferApn = false;
}
if (VDBG) {
log("getPreferredApn: mRequestedApnType=" + mRequestedApnType + " cursor=" + cursor + " cursor.count=" + ((cursor != null) ? cursor.getCount() : 0));
}
if (mCanSetPreferApn && cursor.getCount() > 0) {
int pos;
cursor.moveToFirst();
pos = cursor.getInt(cursor.getColumnIndexOrThrow(Telephony.Carriers._ID));
for (ApnSetting p : mAllApnSettings) {
if (p.getId() == pos && p.canHandleType(mRequestedApnType)) {
log("getPreferredApn: For APN type " + ApnSetting.getApnTypeString(mRequestedApnType) + " found apnSetting " + p);
cursor.close();
return p;
}
}
}
if (cursor != null) {
cursor.close();
}
log("getPreferredApn: X not found");
return null;
}
use of android.telephony.data.ApnSetting in project android_frameworks_opt_telephony by LineageOS.
the class DcTracker method cleanUpConnectionsOnUpdatedApns.
private void cleanUpConnectionsOnUpdatedApns(boolean detach, String reason) {
if (DBG)
log("cleanUpConnectionsOnUpdatedApns: detach=" + detach);
if (mAllApnSettings.isEmpty()) {
cleanUpAllConnectionsInternal(detach, Phone.REASON_APN_CHANGED);
} else {
if (getDataRat() == ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN) {
// of waiting apn list and keep the data connection on.
return;
}
for (ApnContext apnContext : mApnContexts.values()) {
boolean cleanupRequired = true;
if (!apnContext.isDisconnected()) {
ArrayList<ApnSetting> waitingApns = buildWaitingApns(apnContext.getApnType(), getDataRat());
apnContext.setWaitingApns(waitingApns);
for (ApnSetting apnSetting : waitingApns) {
if (areCompatible(apnSetting, apnContext.getApnSetting())) {
cleanupRequired = false;
break;
}
}
if (cleanupRequired) {
if (DBG) {
log("cleanUpConnectionsOnUpdatedApns: APN type " + apnContext.getApnType() + " clean up is required. The new " + "waiting APN list " + waitingApns + " does not cover " + apnContext.getApnSetting());
}
apnContext.setReason(reason);
cleanUpConnectionInternal(true, RELEASE_TYPE_DETACH, apnContext);
}
}
}
}
if (!isAnyDataConnected()) {
stopNetStatPoll();
stopDataStallAlarm();
}
mRequestedApnType = ApnSetting.TYPE_DEFAULT;
if (DBG)
log("mDisconnectPendingCount = " + mDisconnectPendingCount);
if (detach && mDisconnectPendingCount == 0) {
notifyAllDataDisconnected();
}
}
Aggregations