Allow us back on the network after carrier-detatch
Robert Greenwalt [Tue, 18 Aug 2015 21:00:17 +0000 (14:00 -0700)]
We had code in DcTracker to deal with this but the MR1-originating
DcSwitchStateMachine interceeds.  Exposing the switch so
DSSM can access it and behave appropriately.

bug:23069223
Change-Id: I7a674d3b662aa0a7eec5a54889a784a2b64d662c

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

index c11cd5b..68d3f50 100644 (file)
@@ -193,6 +193,13 @@ public class DcSwitchStateMachine extends StateMachine {
             final PhoneBase pb = (PhoneBase)((PhoneProxy)mPhone).getActivePhone();
             pb.mCi.setDataAllowed(true, obtainMessage(EVENT_DATA_ALLOWED,
                     ++mCurrentAllowedSequence, 0));
+            // if we're on a carrier that unattaches us if we're idle for too long
+            // (on wifi) and they won't re-attach until we poke them.  Poke them!
+            // essentially react as Attached does here in Attaching.
+            if (pb.mDcTracker.getAutoAttachOnCreation()) {
+                if (DBG) log("AttachingState executeAll due to autoAttach");
+                DctController.getInstance().executeAllRequests(mId);
+            }
         }
 
         @Override
@@ -205,11 +212,16 @@ public class DcSwitchStateMachine extends StateMachine {
                     apnRequest.log("DcSwitchStateMachine.AttachingState: REQ_CONNECT");
                     if (DBG) log("AttachingState: REQ_CONNECT, apnRequest=" + apnRequest);
 
-                    // do nothing - wait til we attach and then we'll execute all requests
+                    final PhoneBase pb = (PhoneBase)((PhoneProxy)mPhone).getActivePhone();
+                    if (pb.mDcTracker.getAutoAttachOnCreation() == false) {
+                        // do nothing - wait til we attach and then we'll execute all requests
+                    } else {
+                        apnRequest.log("DcSwitchStateMachine processing due to autoAttach");
+                        DctController.getInstance().executeRequest(apnRequest);
+                    }
                     retVal = HANDLED;
                     break;
                 }
-
                 case EVENT_DATA_ALLOWED: {
                     AsyncResult ar = (AsyncResult)msg.obj;
                     if (mCurrentAllowedSequence != msg.arg1) {
@@ -253,6 +265,14 @@ public class DcSwitchStateMachine extends StateMachine {
                     if (DBG) {
                         log("AttachingState: REQ_DISCONNECT_ALL" );
                     }
+                    final PhoneBase pb = (PhoneBase)((PhoneProxy)mPhone).getActivePhone();
+                    if (pb.mDcTracker.getAutoAttachOnCreation()) {
+                        // if AutoAttachOnCreation, then we may have executed requests
+                        // without ever actually getting to Attached, so release the request
+                        // here in that case.
+                        if (DBG) log("releasingAll due to autoAttach");
+                        DctController.getInstance().releaseAllRequests(mId);
+                    }
 
                     // modem gets unhappy if we try to detach while attaching
                     // wait til attach finishes.
index 8d02de9..0a453b0 100644 (file)
@@ -695,7 +695,7 @@ public final class DcTracker extends DcTrackerBase {
             notifyOffApnsOfAvailability(Phone.REASON_DATA_ATTACHED);
         }
         if (mAutoAttachOnCreationConfig) {
-            mAutoAttachOnCreation = true;
+            mAutoAttachOnCreation.set(true);
         }
         setupDataOnConnectableApns(Phone.REASON_DATA_ATTACHED);
     }
@@ -742,7 +742,7 @@ public final class DcTracker extends DcTrackerBase {
             state = mPhone.getCallTracker().getState();
         }
         boolean allowed =
-                    (attachedState || mAutoAttachOnCreation) &&
+                    (attachedState || mAutoAttachOnCreation.get()) &&
                     recordsLoaded &&
                     (state == PhoneConstants.State.IDLE ||
                      mPhone.getServiceStateTracker().isConcurrentVoiceAndDataAllowed()) &&
@@ -754,7 +754,7 @@ public final class DcTracker extends DcTrackerBase {
                     desiredPowerState;
         if (!allowed && DBG) {
             String reason = "";
-            if (!(attachedState || mAutoAttachOnCreation)) {
+            if (!(attachedState || mAutoAttachOnCreation.get())) {
                 reason += " - Attached= " + attachedState;
             }
             if (!recordsLoaded) reason += " - SIM not loaded";
@@ -1313,8 +1313,8 @@ public final class DcTracker extends DcTrackerBase {
         Message msg = obtainMessage();
         msg.what = DctConstants.EVENT_DATA_SETUP_COMPLETE;
         msg.obj = apnContext;
-        dcac.bringUp(apnContext, getInitialMaxRetry(), profileId, radioTech, mAutoAttachOnCreation,
-                msg);
+        dcac.bringUp(apnContext, getInitialMaxRetry(), profileId, radioTech,
+                mAutoAttachOnCreation.get(), msg);
 
         if (DBG) log("setupData: initing!");
         return true;
index 8d1323a..5c0226e 100644 (file)
@@ -71,6 +71,7 @@ import java.util.List;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.PriorityQueue;
@@ -235,7 +236,7 @@ public abstract class DcTrackerBase extends Handler {
 
     // When false we will not auto attach and manually attaching is required.
     protected boolean mAutoAttachOnCreationConfig = false;
-    protected boolean mAutoAttachOnCreation = false;
+    protected AtomicBoolean mAutoAttachOnCreation = new AtomicBoolean(false);
 
     // State of screen
     // (TODO: Reconsider tying directly to screen, maybe this is
@@ -617,7 +618,7 @@ public abstract class DcTrackerBase extends Handler {
         }
 
         SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
-        mAutoAttachOnCreation = sp.getBoolean(PhoneBase.DATA_DISABLED_ON_BOOT_KEY, false);
+        mAutoAttachOnCreation.set(sp.getBoolean(PhoneBase.DATA_DISABLED_ON_BOOT_KEY, false));
 
         mSubscriptionManager = SubscriptionManager.from(mPhone.getContext());
         mSubscriptionManager
@@ -1914,6 +1915,10 @@ public abstract class DcTrackerBase extends Handler {
         sendMessage(msg);
     }
 
+    public boolean getAutoAttachOnCreation() {
+        return mAutoAttachOnCreation.get();
+    }
+
     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
         pw.println("DcTrackerBase:");
         pw.println(" RADIO_TESTS=" + RADIO_TESTS);
@@ -1943,7 +1948,7 @@ public abstract class DcTrackerBase extends Handler {
         pw.println(" mIsWifiConnected=" + mIsWifiConnected);
         pw.println(" mReconnectIntent=" + mReconnectIntent);
         pw.println(" mCidActive=" + mCidActive);
-        pw.println(" mAutoAttachOnCreation=" + mAutoAttachOnCreation);
+        pw.println(" mAutoAttachOnCreation=" + mAutoAttachOnCreation.get());
         pw.println(" mIsScreenOn=" + mIsScreenOn);
         pw.println(" mUniqueIdGenerator=" + mUniqueIdGenerator);
         pw.flush();