Store phoneId in network requestInfo.
Amit Mahajan [Tue, 18 Aug 2015 22:32:17 +0000 (15:32 -0700)]
If the SIM is removed, phoneId returned by subscription controller
based on subId is MAX_INT leading to a crash.

Bug: 23315629
Change-Id: I8809cfaaeb6ff78b1e24915e350329b8133d99e9

src/java/com/android/internal/telephony/dataconnection/DcSwitchAsyncChannel.java
src/java/com/android/internal/telephony/dataconnection/DctController.java

index ca4656c..461249a 100644 (file)
@@ -67,13 +67,15 @@ public class DcSwitchAsyncChannel extends AsyncChannel {
         boolean executed;
         final NetworkRequest request;
         final int priority;
+        final int phoneId;
         private final LocalLog requestLog;
 
-        public RequestInfo(NetworkRequest request, int priority, LocalLog l) {
+        public RequestInfo(NetworkRequest request, int priority, LocalLog l, int phoneId) {
             this.request = request;
             this.priority = priority;
             this.requestLog = l;
             this.executed = false;
+            this.phoneId = phoneId;
         }
 
         public void log(String str) {
@@ -87,7 +89,7 @@ public class DcSwitchAsyncChannel extends AsyncChannel {
         @Override
         public String toString() {
             return "[ request=" + request + ", executed=" + executed +
-                ", priority=" + priority + "]";
+                ", priority=" + priority + ", phoneId=" + phoneId + "]";
         }
     }
 
index 90793db..fdeb77e 100644 (file)
@@ -307,12 +307,12 @@ public class DctController extends Handler {
         }
     }
 
-    private int requestNetwork(NetworkRequest request, int priority, LocalLog l) {
+    private int requestNetwork(NetworkRequest request, int priority, LocalLog l, int phoneId) {
         logd("requestNetwork request=" + request
                 + ", priority=" + priority);
         l.log("Dctc.requestNetwork, priority=" + priority);
 
-        RequestInfo requestInfo = new RequestInfo(request, priority, l);
+        RequestInfo requestInfo = new RequestInfo(request, priority, l, phoneId);
         mRequestInfos.put(request.requestId, requestInfo);
         processRequests();
 
@@ -386,7 +386,7 @@ public class DctController extends Handler {
             Iterator<Integer> iterator = mRequestInfos.keySet().iterator();
             while (iterator.hasNext()) {
                 RequestInfo requestInfo = mRequestInfos.get(iterator.next());
-                if (getRequestPhoneId(requestInfo.request) == phoneId && !requestInfo.executed) {
+                if (requestInfo.phoneId == phoneId && !requestInfo.executed) {
                     mDcSwitchAsyncChannel[phoneId].connect(requestInfo);
                 }
             }
@@ -401,7 +401,7 @@ public class DctController extends Handler {
             requestInfo.log("DctController.onExecuteRequest - executed=" + requestInfo.executed);
             requestInfo.executed = true;
             String apn = apnForNetworkRequest(requestInfo.request);
-            int phoneId = getRequestPhoneId(requestInfo.request);
+            int phoneId = requestInfo.phoneId;
             PhoneBase phoneBase = (PhoneBase)mPhones[phoneId].getActivePhone();
             DcTrackerBase dcTracker = phoneBase.mDcTracker;
             dcTracker.incApnRefCount(apn, requestInfo.getLog());
@@ -413,7 +413,7 @@ public class DctController extends Handler {
         Iterator<Integer> iterator = mRequestInfos.keySet().iterator();
         while (iterator.hasNext()) {
             RequestInfo requestInfo = mRequestInfos.get(iterator.next());
-            if (getRequestPhoneId(requestInfo.request) == phoneId) {
+            if (requestInfo.phoneId == phoneId) {
                 onExecuteRequest(requestInfo);
             }
         }
@@ -425,7 +425,7 @@ public class DctController extends Handler {
             requestInfo.log("DctController.onReleaseRequest");
             if (requestInfo.executed) {
                 String apn = apnForNetworkRequest(requestInfo.request);
-                int phoneId = getRequestPhoneId(requestInfo.request);
+                int phoneId = requestInfo.phoneId;
                 PhoneBase phoneBase = (PhoneBase)mPhones[phoneId].getActivePhone();
                 DcTrackerBase dcTracker = phoneBase.mDcTracker;
                 dcTracker.decApnRefCount(apn, requestInfo.getLog());
@@ -439,7 +439,7 @@ public class DctController extends Handler {
         Iterator<Integer> iterator = mRequestInfos.keySet().iterator();
         while (iterator.hasNext()) {
             RequestInfo requestInfo = mRequestInfos.get(iterator.next());
-            if (getRequestPhoneId(requestInfo.request) == phoneId) {
+            if (requestInfo.phoneId == phoneId) {
                 onReleaseRequest(requestInfo);
             }
         }
@@ -514,7 +514,7 @@ public class DctController extends Handler {
             while (iterator.hasNext()) {
                 RequestInfo requestInfo = mRequestInfos.get(iterator.next());
                 logd("selectExecPhone requestInfo = " + requestInfo);
-                if (getRequestPhoneId(requestInfo.request) == i &&
+                if (requestInfo.phoneId == i &&
                         priority < requestInfo.priority) {
                     priority = requestInfo.priority;
                     retRequestInfo = requestInfo;
@@ -731,7 +731,8 @@ public class DctController extends Handler {
             DcTrackerBase dcTracker =((PhoneBase)mPhone).mDcTracker;
             String apn = apnForNetworkRequest(networkRequest);
             if (dcTracker.isApnSupported(apn)) {
-                requestNetwork(networkRequest, dcTracker.getApnPriority(apn), l);
+                requestNetwork(networkRequest, dcTracker.getApnPriority(apn), l,
+                        mPhone.getPhoneId());
             } else {
                 final String str = "Unsupported APN";
                 log(str);