use of com.android.internal.telephony.DataCallState 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");
}
Aggregations