Fixed that APN context stuck in SCANNING state
Jack Yu [Thu, 11 May 2017 20:47:56 +0000 (13:47 -0700)]
1. When data retry fails at trySetupData, we should apply
   FAILED state to the APN context otherwise it will be
   in SCANNING state forever since we are not going to
   schedule for the next retry.
2. When we get a new network request in applyNewState,
   if the APN is in SCANNING state, we should trySetupData
   immediately instead of waiting for the next retry,
   which might still minutes/hours away from now.

Test: Telephony sanity tests
bug: 38113800
Merged-In: I6edd7555327f41ee713a256edfe641a41ca6f969
Change-Id: I6edd7555327f41ee713a256edfe641a41ca6f969

src/java/com/android/internal/telephony/dataconnection/DcTracker.java

index ac60188..46572f8 100644 (file)
@@ -1664,33 +1664,39 @@ public class DcTracker extends Handler {
             str.append("trySetupData failed. apnContext = [type=" + apnContext.getApnType() +
                     ", mState=" + apnContext.getState() + ", mDataEnabled=" +
                     apnContext.isEnabled() + ", mDependencyMet=" +
-                    apnContext.getDependencyMet() + "] ");
+                    apnContext.getDependencyMet() + "].");
 
             if (!apnContext.isConnectable()) {
-                str.append("isConnectable = false. ");
+                str.append(" isConnectable = false.");
             }
             if (!isDataAllowed) {
-                str.append("data not allowed: " + failureReason.getDataAllowFailReason() + ". ");
+                str.append(" data not allowed: " + failureReason.getDataAllowFailReason() + ".");
             }
             if (!isDataAllowedForApn(apnContext)) {
-                str.append("isDataAllowedForApn = false. RAT = " +
-                        mPhone.getServiceState().getRilDataRadioTechnology());
+                str.append(" isDataAllowedForApn = false. RAT = "
+                        + mPhone.getServiceState().getRilDataRadioTechnology() + ".");
             }
             if (!mDataEnabledSettings.isDataEnabled()) {
-                str.append("isDataEnabled() = false. "
+                str.append(" isDataEnabled() = false. "
                         + "isInternalDataEnabled = " + mDataEnabledSettings.isInternalDataEnabled()
                         + ", userDataEnabled = " + mDataEnabledSettings.isUserDataEnabled()
                         + ", isPolicyDataEnabled = " + mDataEnabledSettings.isPolicyDataEnabled()
                         + ", isCarrierDataEnabled = "
-                        + mDataEnabledSettings.isCarrierDataEnabled());
+                        + mDataEnabledSettings.isCarrierDataEnabled() + ".");
             }
             if (isEmergency()) {
-                str.append("emergency = true");
+                str.append(" emergency = true.");
+            }
+
+            // If this is a data retry, we should set the APN state to FAILED so it won't stay
+            // in SCANNING forever.
+            if (apnContext.getState() == DctConstants.State.SCANNING) {
+                apnContext.setState(DctConstants.State.FAILED);
+                str.append(" Stop retrying.");
             }
 
             if (DBG) log(str.toString());
             apnContext.requestLog(str.toString());
-
             return false;
         }
     }
@@ -2553,7 +2559,6 @@ public class DcTracker extends Handler {
                 DctConstants.State state = apnContext.getState();
                 switch(state) {
                     case CONNECTING:
-                    case SCANNING:
                     case CONNECTED:
                     case DISCONNECTING:
                         // We're "READY" and active so just return
@@ -2563,6 +2568,7 @@ public class DcTracker extends Handler {
                     case IDLE:
                         // fall through: this is unexpected but if it happens cleanup and try setup
                     case FAILED:
+                    case SCANNING:
                     case RETRYING: {
                         // We're "READY" but not active so disconnect (cleanup = true) and
                         // connect (trySetup = true) to be sure we retry the connection.