use of com.android.internal.telephony.DataConnectionAc in project XobotOS by xamarin.
the class GsmDataConnectionTracker method setupData.
private boolean setupData(ApnContext apnContext) {
if (DBG)
log("setupData: apnContext=" + apnContext);
ApnSetting apn;
GsmDataConnection dc;
int profileId = getApnProfileID(apnContext.getApnType());
apn = apnContext.getNextWaitingApn();
if (apn == null) {
if (DBG)
log("setupData: return for no apn found!");
return false;
}
// First, check to see if ApnContext already has DC.
// This could happen if the retries are currently engaged.
dc = (GsmDataConnection) apnContext.getDataConnection();
if (dc == null) {
dc = (GsmDataConnection) checkForConnectionForApnContext(apnContext);
if (dc == null) {
dc = findReadyDataConnection(apn);
}
if (dc == null) {
if (DBG)
log("setupData: No ready GsmDataConnection found!");
// TODO: When allocating you are mapping type to id. If more than 1 free,
// then could findFreeDataConnection get the wrong one??
dc = findFreeDataConnection();
}
if (dc == null) {
dc = createDataConnection();
}
if (dc == null) {
if (DBG)
log("setupData: No free GsmDataConnection found!");
return false;
}
DataConnectionAc dcac = mDataConnectionAsyncChannels.get(dc.getDataConnectionId());
dc.setProfileId(profileId);
dc.setActiveApnType(apnContext.getApnType());
int refCount = dcac.getRefCountSync();
if (DBG)
log("setupData: init dc and apnContext refCount=" + refCount);
// configure retry count if no other Apn is using the same connection.
if (refCount == 0) {
configureRetry(dc, apn.canHandleType(Phone.APN_TYPE_DEFAULT));
}
apnContext.setDataConnectionAc(dcac);
apnContext.setDataConnection(dc);
}
apnContext.setApnSetting(apn);
apnContext.setState(State.INITING);
mPhone.notifyDataConnection(apnContext.getReason(), apnContext.getApnType());
// fired so that we don't disruppt data retry pattern engaged.
if (apnContext.getDataConnectionAc().getReconnectIntentSync() != null) {
if (DBG)
log("setupData: data reconnection pending");
apnContext.setState(State.FAILED);
mPhone.notifyDataConnection(apnContext.getReason(), apnContext.getApnType());
return true;
}
Message msg = obtainMessage();
msg.what = EVENT_DATA_SETUP_COMPLETE;
msg.obj = apnContext;
dc.bringUp(msg, apn);
if (DBG)
log("setupData: initing!");
return true;
}
use of com.android.internal.telephony.DataConnectionAc in project XobotOS by xamarin.
the class GsmDataConnectionTracker method onDataStateChanged.
/**
* @param ar is the result of RIL_REQUEST_DATA_CALL_LIST
* or RIL_UNSOL_DATA_CALL_LIST_CHANGED
*/
private void onDataStateChanged(AsyncResult ar) {
ArrayList<DataCallState> dataCallStates;
if (DBG)
log("onDataStateChanged(ar): E");
dataCallStates = (ArrayList<DataCallState>) (ar.result);
if (ar.exception != null) {
// to come down soon anyway
if (DBG)
log("onDataStateChanged(ar): exception; likely radio not available, ignore");
return;
}
if (DBG)
log("onDataStateChanged(ar): DataCallState size=" + dataCallStates.size());
// Create a hash map to store the dataCallState of each DataConnectionAc
HashMap<DataCallState, DataConnectionAc> dataCallStateToDcac;
dataCallStateToDcac = new HashMap<DataCallState, DataConnectionAc>();
for (DataCallState dataCallState : dataCallStates) {
DataConnectionAc dcac = findDataConnectionAcByCid(dataCallState.cid);
if (dcac != null)
dataCallStateToDcac.put(dataCallState, dcac);
}
// A list of apns to cleanup, those that aren't in the list we know we have to cleanup
List<ApnContext> apnsToCleanup = findApnContextToClean(dataCallStateToDcac.values());
// Find which connections have changed state and send a notification or cleanup
for (DataCallState newState : dataCallStates) {
DataConnectionAc dcac = dataCallStateToDcac.get(newState);
if (dcac == null) {
loge("onDataStateChanged(ar): No associated DataConnection ignore");
continue;
}
// The list of apn's associated with this DataConnection
Collection<ApnContext> apns = dcac.getApnListSync();
// Find which ApnContexts of this DC are in the "Connected/Connecting" state.
ArrayList<ApnContext> connectedApns = new ArrayList<ApnContext>();
for (ApnContext apnContext : apns) {
if (apnContext.getState() == State.CONNECTED || apnContext.getState() == State.CONNECTING || apnContext.getState() == State.INITING) {
connectedApns.add(apnContext);
}
}
if (connectedApns.size() == 0) {
if (DBG)
log("onDataStateChanged(ar): no connected apns");
} else {
// or just a notification should be sent out.
if (DBG)
log("onDataStateChanged(ar): Found ConnId=" + newState.cid + " newState=" + newState.toString());
if (newState.active == 0) {
if (DBG) {
log("onDataStateChanged(ar): inactive, cleanup apns=" + connectedApns);
}
apnsToCleanup.addAll(connectedApns);
} else {
// Its active so update the DataConnections link properties
UpdateLinkPropertyResult result = dcac.updateLinkPropertiesDataCallStateSync(newState);
if (result.oldLp.equals(result.newLp)) {
if (DBG)
log("onDataStateChanged(ar): no change");
} else {
if (result.oldLp.isIdenticalInterfaceName(result.newLp)) {
if (!result.oldLp.isIdenticalDnses(result.newLp) || !result.oldLp.isIdenticalRoutes(result.newLp) || !result.oldLp.isIdenticalHttpProxy(result.newLp) || !result.oldLp.isIdenticalAddresses(result.newLp)) {
// If the same address type was removed and added we need to cleanup
CompareResult<LinkAddress> car = result.oldLp.compareAddresses(result.newLp);
boolean needToClean = false;
for (LinkAddress added : car.added) {
for (LinkAddress removed : car.removed) {
if (NetworkUtils.addressTypeMatches(removed.getAddress(), added.getAddress())) {
needToClean = true;
break;
}
}
}
if (needToClean) {
if (DBG) {
log("onDataStateChanged(ar): addr change, cleanup apns=" + connectedApns);
}
apnsToCleanup.addAll(connectedApns);
} else {
if (DBG)
log("onDataStateChanged(ar): simple change");
for (ApnContext apnContext : connectedApns) {
mPhone.notifyDataConnection(Phone.REASON_LINK_PROPERTIES_CHANGED, apnContext.getApnType());
}
}
} else {
if (DBG) {
log("onDataStateChanged(ar): no changes");
}
}
} else {
if (DBG) {
log("onDataStateChanged(ar): interface change, cleanup apns=" + connectedApns);
}
apnsToCleanup.addAll(connectedApns);
}
}
}
}
}
if (apnsToCleanup.size() != 0) {
// Add an event log when the network drops PDP
int cid = getCellLocationId();
EventLog.writeEvent(EventLogTags.PDP_NETWORK_DROP, cid, TelephonyManager.getDefault().getNetworkType());
}
// Cleanup those dropped connections
for (ApnContext apnContext : apnsToCleanup) {
cleanUpConnection(true, apnContext);
}
if (DBG)
log("onDataStateChanged(ar): X");
}
use of com.android.internal.telephony.DataConnectionAc in project XobotOS by xamarin.
the class GsmDataConnectionTracker method cleanUpConnection.
private void cleanUpConnection(boolean tearDown, ApnContext apnContext) {
if (apnContext == null) {
if (DBG)
log("cleanUpConnection: apn context is null");
return;
}
if (DBG) {
log("cleanUpConnection: tearDown=" + tearDown + " reason=" + apnContext.getReason());
}
DataConnectionAc dcac = apnContext.getDataConnectionAc();
if (tearDown) {
if (apnContext.isDisconnected()) {
// The request is tearDown and but ApnContext is not connected.
// If apnContext is not enabled anymore, break the linkage to the DCAC/DC.
apnContext.setState(State.IDLE);
if (!apnContext.isReady()) {
apnContext.setDataConnection(null);
apnContext.setDataConnectionAc(null);
}
} else {
// Connection is still there. Try to clean up.
if (dcac != null) {
if (apnContext.getState() != State.DISCONNECTING) {
if (DBG)
log("cleanUpConnection: tearing down");
Message msg = obtainMessage(EVENT_DISCONNECT_DONE, apnContext);
apnContext.getDataConnection().tearDown(apnContext.getReason(), msg);
apnContext.setState(State.DISCONNECTING);
}
} else {
// apn is connected but no reference to dcac.
// Should not be happen, but reset the state in case.
apnContext.setState(State.IDLE);
mPhone.notifyDataConnection(apnContext.getReason(), apnContext.getApnType());
}
}
} else {
// force clean up the data connection.
if (dcac != null)
dcac.resetSync();
apnContext.setState(State.IDLE);
mPhone.notifyDataConnection(apnContext.getReason(), apnContext.getApnType());
apnContext.setDataConnection(null);
apnContext.setDataConnectionAc(null);
}
// associated to the connection.
if (dcac != null) {
Collection<ApnContext> apnList = dcac.getApnListSync();
if (apnList.isEmpty()) {
cancelReconnectAlarm(dcac);
}
}
}
use of com.android.internal.telephony.DataConnectionAc in project XobotOS by xamarin.
the class GsmDataConnectionTracker method setupDataOnReadyApns.
private void setupDataOnReadyApns(String reason) {
// retry. Reset ApnContext state to IDLE.
for (DataConnectionAc dcac : mDataConnectionAsyncChannels.values()) {
if (dcac.getReconnectIntentSync() != null) {
cancelReconnectAlarm(dcac);
}
// ones for the new RAT.
if (dcac.dataConnection != null) {
Collection<ApnContext> apns = dcac.getApnListSync();
boolean hasDefault = false;
for (ApnContext apnContext : apns) {
if (apnContext.getApnType().equals(Phone.APN_TYPE_DEFAULT)) {
hasDefault = true;
break;
}
}
configureRetry(dcac.dataConnection, hasDefault);
}
}
// Only check for default APN state
for (ApnContext apnContext : mApnContexts.values()) {
if (apnContext.getState() == State.FAILED) {
// By this time, alarms for all failed Apns
// should be stopped if any.
// Make sure to set the state back to IDLE
// so that setup data can happen.
apnContext.setState(State.IDLE);
}
if (apnContext.isReady()) {
if (apnContext.getState() == State.IDLE) {
apnContext.setReason(reason);
trySetupData(apnContext);
}
}
}
}
use of com.android.internal.telephony.DataConnectionAc in project XobotOS by xamarin.
the class GsmDataConnectionTracker method createDataConnection.
/** Return the id for a new data connection */
private GsmDataConnection createDataConnection() {
if (DBG)
log("createDataConnection E");
RetryManager rm = new RetryManager();
int id = mUniqueIdGenerator.getAndIncrement();
GsmDataConnection conn = GsmDataConnection.makeDataConnection(mPhone, id, rm);
mDataConnections.put(id, conn);
DataConnectionAc dcac = new DataConnectionAc(conn, LOG_TAG);
int status = dcac.fullyConnectSync(mPhone.getContext(), this, conn.getHandler());
if (status == AsyncChannel.STATUS_SUCCESSFUL) {
mDataConnectionAsyncChannels.put(dcac.dataConnection.getDataConnectionId(), dcac);
} else {
loge("createDataConnection: Could not connect to dcac.mDc=" + dcac.dataConnection + " status=" + status);
}
// install reconnect intent filter for this data connection.
IntentFilter filter = new IntentFilter();
filter.addAction(INTENT_RECONNECT_ALARM + '.' + id);
mPhone.getContext().registerReceiver(mIntentReceiver, filter, null, mPhone);
if (DBG)
log("createDataConnection() X id=" + id);
return conn;
}
Aggregations