Have all connections disconnected before turning off radio.
Bug: 5306201
Change-Id: I8a121e5ed951f286b6f3edc70c468e86ccedfbf0
diff --git a/telephony/java/com/android/internal/telephony/ApnContext.java b/telephony/java/com/android/internal/telephony/ApnContext.java
index a52f1ca..8aeee87 100644
--- a/telephony/java/com/android/internal/telephony/ApnContext.java
+++ b/telephony/java/com/android/internal/telephony/ApnContext.java
@@ -154,6 +154,12 @@
return mState;
}
+ public boolean isDisconnected() {
+ DataConnectionTracker.State currentState = getState();
+ return ((currentState == DataConnectionTracker.State.IDLE) ||
+ currentState == DataConnectionTracker.State.FAILED);
+ }
+
public synchronized void setReason(String reason) {
if (DBG) {
log("set reason as " + reason + ", for type " + mApnType + ",current state " + mState);
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
index 6d0b696..dd8a60a 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
@@ -787,9 +787,7 @@
}
DataConnectionAc dcac = apnContext.getDataConnectionAc();
if (tearDown) {
- boolean isConnected = (apnContext.getState() != State.IDLE
- && apnContext.getState() != State.FAILED);
- if (!isConnected) {
+ 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);
@@ -1019,11 +1017,9 @@
*/
private void onApnChanged() {
// TODO: How to handle when multiple APNs are active?
- boolean isConnected;
ApnContext defaultApnContext = mApnContexts.get(Phone.APN_TYPE_DEFAULT);
- isConnected = (defaultApnContext.getState() != State.IDLE
- && defaultApnContext.getState() != State.FAILED);
+ boolean defaultApnIsDisconnected = defaultApnContext.isDisconnected();
if (mPhone instanceof GSMPhone) {
// The "current" may no longer be valid. MMS depends on this to send properly. TBD
@@ -1034,8 +1030,8 @@
// match the current operator.
if (DBG) log("onApnChanged: createAllApnList and cleanUpAllConnections");
createAllApnList();
- cleanUpAllConnections(isConnected, Phone.REASON_APN_CHANGED);
- if (!isConnected) {
+ cleanUpAllConnections(!defaultApnIsDisconnected, Phone.REASON_APN_CHANGED);
+ if (defaultApnIsDisconnected) {
setupDataOnReadyApns(Phone.REASON_APN_CHANGED);
}
}
@@ -1885,7 +1881,7 @@
// if all data connection are gone, check whether Airplane mode request was
// pending.
- if (!isConnected()) {
+ if (isDisconnected()) {
if (mPhone.getServiceStateTracker().processPendingRadioPowerOffAfterDataOff()) {
// Radio will be turned off. No need to retry data setup
apnContext.setApnSetting(null);
@@ -1957,12 +1953,25 @@
protected boolean isConnected() {
for (ApnContext apnContext : mApnContexts.values()) {
if (apnContext.getState() == State.CONNECTED) {
- return true;
+ // At least one context is connected, return true
+ return true;
}
}
+ // There are not any contexts connected, return false
return false;
}
+ protected boolean isDisconnected() {
+ for (ApnContext apnContext : mApnContexts.values()) {
+ if (!apnContext.isDisconnected()) {
+ // At least one context was not disconnected return false
+ return false;
+ }
+ }
+ // All contexts were disconnected so return true
+ return true;
+ }
+
@Override
protected void notifyDataConnection(String reason) {
if (DBG) log("notifyDataConnection: reason=" + reason);