Merge "Send availability info more reliably" into ics-mr0

This commit is contained in:
Robert Greenwalt
2011-10-18 09:42:33 -07:00
committed by Android (Google) Code Review
5 changed files with 36 additions and 45 deletions

View File

@@ -197,7 +197,10 @@ public class MobileDataStateTracker implements NetworkStateTracker {
String apnName = intent.getStringExtra(Phone.DATA_APN_KEY); String apnName = intent.getStringExtra(Phone.DATA_APN_KEY);
mNetworkInfo.setRoaming(intent.getBooleanExtra(Phone.DATA_NETWORK_ROAMING_KEY, mNetworkInfo.setRoaming(intent.getBooleanExtra(Phone.DATA_NETWORK_ROAMING_KEY,
false)); false));
if (VDBG) {
log(mApnType + " setting isAvailable to " +
intent.getBooleanExtra(Phone.NETWORK_UNAVAILABLE_KEY,false));
}
mNetworkInfo.setIsAvailable(!intent.getBooleanExtra(Phone.NETWORK_UNAVAILABLE_KEY, mNetworkInfo.setIsAvailable(!intent.getBooleanExtra(Phone.NETWORK_UNAVAILABLE_KEY,
false)); false));

View File

@@ -132,6 +132,9 @@ public interface NetworkStateTracker {
* Returns an indication of whether this network is available for * Returns an indication of whether this network is available for
* connections. A value of {@code false} means that some quasi-permanent * connections. A value of {@code false} means that some quasi-permanent
* condition prevents connectivity to this network. * condition prevents connectivity to this network.
*
* NOTE that this is broken on multi-connection devices. Should be fixed in J release
* TODO - fix on multi-pdp devices
*/ */
public boolean isAvailable(); public boolean isAvailable();

View File

@@ -254,9 +254,6 @@ public abstract class DataConnectionTracker extends Handler {
/** CID of active data connection */ /** CID of active data connection */
protected int mCidActive; protected int mCidActive;
/** indication of our availability (preconditions to trysetupData are met) **/
protected boolean mAvailability = false;
// When false we will not auto attach and manually attaching is required. // When false we will not auto attach and manually attaching is required.
protected boolean mAutoAttachOnCreation = false; protected boolean mAutoAttachOnCreation = false;
@@ -755,7 +752,7 @@ public abstract class DataConnectionTracker extends Handler {
mPhone.notifyDataConnection(reason, apnIdToType(id)); mPhone.notifyDataConnection(reason, apnIdToType(id));
} }
} }
notifyDataAvailability(reason); notifyOffApnsOfAvailability(reason);
} }
// a new APN has gone active and needs to send events to catch up with the // a new APN has gone active and needs to send events to catch up with the
@@ -783,15 +780,8 @@ public abstract class DataConnectionTracker extends Handler {
} }
// disabled apn's still need avail/unavail notificiations - send them out // disabled apn's still need avail/unavail notificiations - send them out
protected void notifyOffApnsOfAvailability(String reason, boolean availability) { protected void notifyOffApnsOfAvailability(String reason) {
if (mAvailability == availability) { if (DBG) log("notifyOffApnsOfAvailability - reason= " + reason);
if (DBG) {
log("notifyOffApnsOfAvailability: no change in availability, " +
"not nofitying about reason='" + reason + "' availability=" + availability);
}
return;
}
mAvailability = availability;
for (int id = 0; id < APN_NUM_TYPES; id++) { for (int id = 0; id < APN_NUM_TYPES; id++) {
if (!isApnIdEnabled(id)) { if (!isApnIdEnabled(id)) {
notifyApnIdDisconnected(reason, id); notifyApnIdDisconnected(reason, id);
@@ -799,13 +789,6 @@ public abstract class DataConnectionTracker extends Handler {
} }
} }
// we had an availability change - tell the listeners
protected void notifyDataAvailability(String reason) {
// note that we either just turned all off because we lost availability
// or all were off and could now go on, so only have off apns to worry about
notifyOffApnsOfAvailability(reason, isDataPossible(Phone.APN_TYPE_DEFAULT));
}
public boolean isApnTypeEnabled(String apnType) { public boolean isApnTypeEnabled(String apnType) {
if (apnType == null) { if (apnType == null) {
return false; return false;

View File

@@ -237,7 +237,7 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
// FIXME this can be improved // FIXME this can be improved
setState(State.CONNECTED); setState(State.CONNECTED);
notifyDataConnection(reason); notifyDataConnection(reason);
notifyOffApnsOfAvailability(reason, true); notifyOffApnsOfAvailability(reason);
log("(fix?) We're on the simulator; assuming data is connected"); log("(fix?) We're on the simulator; assuming data is connected");
return true; return true;
@@ -250,10 +250,10 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
if ((mState == State.IDLE || mState == State.SCANNING) && if ((mState == State.IDLE || mState == State.SCANNING) &&
isDataAllowed() && getAnyDataEnabled()) { isDataAllowed() && getAnyDataEnabled()) {
boolean retValue = setupData(reason); boolean retValue = setupData(reason);
notifyOffApnsOfAvailability(reason, retValue); notifyOffApnsOfAvailability(reason);
return retValue; return retValue;
} else { } else {
notifyOffApnsOfAvailability(reason, false); notifyOffApnsOfAvailability(reason);
return false; return false;
} }
} }
@@ -276,7 +276,7 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
} }
setState(State.DISCONNECTING); setState(State.DISCONNECTING);
notifyDataAvailability(reason); notifyOffApnsOfAvailability(reason);
boolean notificationDeferred = false; boolean notificationDeferred = false;
for (DataConnection conn : mDataConnections.values()) { for (DataConnection conn : mDataConnections.values()) {
@@ -536,7 +536,7 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
private void notifyNoData(FailCause lastFailCauseCode) { private void notifyNoData(FailCause lastFailCauseCode) {
setState(State.FAILED); setState(State.FAILED);
notifyDataAvailability(null); notifyOffApnsOfAvailability(null);
} }
protected void gotoIdleAndNotifyDataConnection(String reason) { protected void gotoIdleAndNotifyDataConnection(String reason) {
@@ -583,7 +583,7 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
@Override @Override
protected void onRoamingOff() { protected void onRoamingOff() {
if (getDataOnRoamingEnabled() == false) { if (getDataOnRoamingEnabled() == false) {
notifyDataAvailability(Phone.REASON_ROAMING_OFF); notifyOffApnsOfAvailability(Phone.REASON_ROAMING_OFF);
trySetupData(Phone.REASON_ROAMING_OFF); trySetupData(Phone.REASON_ROAMING_OFF);
} else { } else {
notifyDataConnection(Phone.REASON_ROAMING_OFF); notifyDataConnection(Phone.REASON_ROAMING_OFF);
@@ -601,7 +601,7 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
} else { } else {
if (DBG) log("Tear down data connection on roaming."); if (DBG) log("Tear down data connection on roaming.");
cleanUpAllConnections(null); cleanUpAllConnections(null);
notifyDataAvailability(Phone.REASON_ROAMING_ON); notifyOffApnsOfAvailability(Phone.REASON_ROAMING_ON);
} }
} }
@@ -619,7 +619,7 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
log("We're on the simulator; assuming data is connected"); log("We're on the simulator; assuming data is connected");
} }
notifyDataAvailability(null); notifyOffApnsOfAvailability(null);
if (mState != State.IDLE) { if (mState != State.IDLE) {
cleanUpAllConnections(null); cleanUpAllConnections(null);
@@ -710,7 +710,7 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
if (mState == State.CONNECTED && !mCdmaPhone.mSST.isConcurrentVoiceAndDataAllowed()) { if (mState == State.CONNECTED && !mCdmaPhone.mSST.isConcurrentVoiceAndDataAllowed()) {
stopNetStatPoll(); stopNetStatPoll();
notifyDataConnection(Phone.REASON_VOICE_CALL_STARTED); notifyDataConnection(Phone.REASON_VOICE_CALL_STARTED);
notifyDataAvailability(Phone.REASON_VOICE_CALL_STARTED); notifyOffApnsOfAvailability(Phone.REASON_VOICE_CALL_STARTED);
} }
} }
@@ -727,7 +727,7 @@ public final class CdmaDataConnectionTracker extends DataConnectionTracker {
// clean slate after call end. // clean slate after call end.
resetPollStats(); resetPollStats();
} }
notifyDataAvailability(Phone.REASON_VOICE_CALL_ENDED); notifyOffApnsOfAvailability(Phone.REASON_VOICE_CALL_ENDED);
} else { } else {
mDataConnections.get(0).resetRetryCount(); mDataConnections.get(0).resetRetryCount();
// in case data setup was attempted when we were on a voice call // in case data setup was attempted when we were on a voice call

View File

@@ -556,7 +556,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
notifyDataConnection(Phone.REASON_DATA_ATTACHED); notifyDataConnection(Phone.REASON_DATA_ATTACHED);
} else { } else {
// update APN availability so that APN can be enabled. // update APN availability so that APN can be enabled.
notifyDataAvailability(Phone.REASON_DATA_ATTACHED); notifyOffApnsOfAvailability(Phone.REASON_DATA_ATTACHED);
} }
setupDataOnReadyApns(Phone.REASON_DATA_ATTACHED); setupDataOnReadyApns(Phone.REASON_DATA_ATTACHED);
@@ -693,7 +693,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
if (waitingApns.isEmpty()) { if (waitingApns.isEmpty()) {
if (DBG) log("trySetupData: No APN found"); if (DBG) log("trySetupData: No APN found");
notifyNoData(GsmDataConnection.FailCause.MISSING_UNKNOWN_APN, apnContext); notifyNoData(GsmDataConnection.FailCause.MISSING_UNKNOWN_APN, apnContext);
notifyOffApnsOfAvailability(apnContext.getReason(), false); notifyOffApnsOfAvailability(apnContext.getReason());
return false; return false;
} else { } else {
apnContext.setWaitingApns(waitingApns); apnContext.setWaitingApns(waitingApns);
@@ -708,7 +708,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
} }
// apnContext.setReason(apnContext.getReason()); // apnContext.setReason(apnContext.getReason());
boolean retValue = setupData(apnContext); boolean retValue = setupData(apnContext);
notifyOffApnsOfAvailability(apnContext.getReason(), retValue); notifyOffApnsOfAvailability(apnContext.getReason());
return retValue; return retValue;
} else { } else {
// TODO: check the condition. // TODO: check the condition.
@@ -716,23 +716,25 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
&& (apnContext.getState() == State.IDLE && (apnContext.getState() == State.IDLE
|| apnContext.getState() == State.SCANNING)) || apnContext.getState() == State.SCANNING))
mPhone.notifyDataConnectionFailed(apnContext.getReason(), apnContext.getApnType()); mPhone.notifyDataConnectionFailed(apnContext.getReason(), apnContext.getApnType());
notifyOffApnsOfAvailability(apnContext.getReason(), false); notifyOffApnsOfAvailability(apnContext.getReason());
return false; return false;
} }
} }
@Override @Override
// Disabled apn's still need avail/unavail notificiations - send them out // Disabled apn's still need avail/unavail notificiations - send them out
protected void notifyOffApnsOfAvailability(String reason, boolean availability) { protected void notifyOffApnsOfAvailability(String reason) {
if (mAvailability == availability) return;
mAvailability = availability;
for (ApnContext apnContext : mApnContexts.values()) { for (ApnContext apnContext : mApnContexts.values()) {
if (!apnContext.isReady()) { if (!apnContext.isReady()) {
if (DBG) log("notifyOffApnOfAvailability type:" + apnContext.getApnType()); if (DBG) log("notifyOffApnOfAvailability type:" + apnContext.getApnType());
mPhone.notifyDataConnection(reason != null ? reason : apnContext.getReason(), mPhone.notifyDataConnection(reason != null ? reason : apnContext.getReason(),
apnContext.getApnType(), apnContext.getApnType(),
Phone.DataState.DISCONNECTED); Phone.DataState.DISCONNECTED);
} else {
if (DBG) {
log("notifyOffApnsOfAvailability skipped apn due to isReady==false: " +
apnContext.toString());
}
} }
} }
} }
@@ -1572,7 +1574,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
createAllApnList(); createAllApnList();
if (mPhone.mCM.getRadioState().isOn()) { if (mPhone.mCM.getRadioState().isOn()) {
if (DBG) log("onRecordsLoaded: notifying data availability"); if (DBG) log("onRecordsLoaded: notifying data availability");
notifyDataAvailability(Phone.REASON_SIM_LOADED); notifyOffApnsOfAvailability(Phone.REASON_SIM_LOADED);
} }
setupDataOnReadyApns(Phone.REASON_SIM_LOADED); setupDataOnReadyApns(Phone.REASON_SIM_LOADED);
} }
@@ -1681,7 +1683,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
if (DBG) log("onRoamingOff"); if (DBG) log("onRoamingOff");
if (getDataOnRoamingEnabled() == false) { if (getDataOnRoamingEnabled() == false) {
notifyDataAvailability(Phone.REASON_ROAMING_OFF); notifyOffApnsOfAvailability(Phone.REASON_ROAMING_OFF);
setupDataOnReadyApns(Phone.REASON_ROAMING_OFF); setupDataOnReadyApns(Phone.REASON_ROAMING_OFF);
} else { } else {
notifyDataConnection(Phone.REASON_ROAMING_OFF); notifyDataConnection(Phone.REASON_ROAMING_OFF);
@@ -1697,7 +1699,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
} else { } else {
if (DBG) log("onRoamingOn: Tear down data connection on roaming."); if (DBG) log("onRoamingOn: Tear down data connection on roaming.");
cleanUpAllConnections(true, Phone.REASON_ROAMING_ON); cleanUpAllConnections(true, Phone.REASON_ROAMING_ON);
notifyDataAvailability(Phone.REASON_ROAMING_ON); notifyOffApnsOfAvailability(Phone.REASON_ROAMING_ON);
} }
} }
@@ -1714,7 +1716,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
} }
if (mPhone.mIccRecords.getRecordsLoaded()) { if (mPhone.mIccRecords.getRecordsLoaded()) {
notifyDataAvailability(null); notifyOffApnsOfAvailability(null);
} }
if (getOverallState() != State.IDLE) { if (getOverallState() != State.IDLE) {
@@ -1740,7 +1742,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
if (DBG) log("onRadioOffOrNotAvailable: is off and clean up all connections"); if (DBG) log("onRadioOffOrNotAvailable: is off and clean up all connections");
cleanUpAllConnections(false, Phone.REASON_RADIO_TURNED_OFF); cleanUpAllConnections(false, Phone.REASON_RADIO_TURNED_OFF);
} }
notifyDataAvailability(null); notifyOffApnsOfAvailability(null);
} }
@Override @Override
@@ -1985,7 +1987,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
apnContext.getApnType()); apnContext.getApnType());
} }
} }
notifyDataAvailability(reason); notifyOffApnsOfAvailability(reason);
} }
/** /**