Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee83b99d authored by Daniel Bright's avatar Daniel Bright
Browse files

Fix concurrency bug w\ all apn list in DcTracker

Concurrency issue was caused by modifications to the all apn
list while being read from within getPreferredApn() on a
thread handler other than dcHandlerThread.  We are now
calling getPreferredApn() on dcHandlerThread and passing the
result to dataConnection.bringUp through ConnectionParams

Test: Accessed internet through mobile and wifi
Test: Popped sim and out while testing data connection
Test: Placed \ Received voice call
Test: Send \ Received sms
Bug: 147260061
Change-Id: I927fd5ac5783d601e21f9c7af508524246bbd699
parent 1f8d2a6e
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -198,10 +198,12 @@ public class DataConnection extends StateMachine {
        @RequestNetworkType
        final int mRequestType;
        final int mSubId;
        final boolean mIsPreferredApn;

        ConnectionParams(ApnContext apnContext, int profileId, int rilRadioTechnology,
                         Message onCompletedMsg, int connectionGeneration,
                         @RequestNetworkType int requestType, int subId) {
                         @RequestNetworkType int requestType, int subId,
                         boolean isPreferredApn) {
            mApnContext = apnContext;
            mProfileId = profileId;
            mRilRat = rilRadioTechnology;
@@ -209,6 +211,7 @@ public class DataConnection extends StateMachine {
            mConnectionGeneration = connectionGeneration;
            mRequestType = requestType;
            mSubId = subId;
            mIsPreferredApn = isPreferredApn;
        }

        @Override
@@ -219,6 +222,7 @@ public class DataConnection extends StateMachine {
                    + " mOnCompletedMsg=" + msgToString(mOnCompletedMsg)
                    + " mRequestType=" + DcTracker.requestTypeToString(mRequestType)
                    + " mSubId=" + mSubId
                    + " mIsPreferredApn=" + mIsPreferredApn
                    + "}";
        }
    }
@@ -673,7 +677,7 @@ public class DataConnection extends StateMachine {
        msg.obj = cp;

        DataProfile dp = DcTracker.createDataProfile(mApnSetting, cp.mProfileId,
                mApnSetting.equals(mDct.getPreferredApn()));
                cp.mIsPreferredApn);

        // We need to use the actual modem roaming state instead of the framework roaming state
        // here. This flag is only passed down to ril_service for picking the correct protocol (for
@@ -2616,16 +2620,17 @@ public class DataConnection extends StateMachine {
     *                             ignored if obsolete.
     * @param requestType Data request type
     * @param subId the subscription id associated with this data connection.
     * @param isApnPreferred whether or not the apn is preferred.
     */
    public void bringUp(ApnContext apnContext, int profileId, int rilRadioTechnology,
                        Message onCompletedMsg, int connectionGeneration,
                        @RequestNetworkType int requestType, int subId) {
                        @RequestNetworkType int requestType, int subId, boolean isApnPreferred) {
        if (DBG) {
            log("bringUp: apnContext=" + apnContext + " onCompletedMsg=" + onCompletedMsg);
        }
        sendMessage(DataConnection.EVENT_CONNECT,
                new ConnectionParams(apnContext, profileId, rilRadioTechnology, onCompletedMsg,
                        connectionGeneration, requestType, subId));
                        connectionGeneration, requestType, subId, isApnPreferred));
    }

    /**
+17 −2
Original line number Diff line number Diff line
@@ -2056,10 +2056,23 @@ public class DcTracker extends Handler {
        Message msg = obtainMessage();
        msg.what = DctConstants.EVENT_DATA_SETUP_COMPLETE;
        msg.obj = new Pair<ApnContext, Integer>(apnContext, generation);

        ApnSetting preferredApn = getPreferredApn();
        boolean isPreferredApn = apnSetting.equals(preferredApn);
        dataConnection.bringUp(apnContext, profileId, radioTech, msg, generation, requestType,
                mPhone.getSubId());
                mPhone.getSubId(), isPreferredApn);

        if (DBG) log("setupData: initing!");
        if (DBG) {
            if (isPreferredApn) {
                log("setupData: initing! isPreferredApn=" + isPreferredApn
                        + ", apnSetting={" + apnSetting.toString() + "}");
            } else {
                String preferredApnStr = preferredApn == null ? "null" : preferredApn.toString();
                log("setupData: initing! isPreferredApn=" + isPreferredApn
                        + ", apnSetting={" + apnSetting + "}"
                        + ", preferredApn={" + preferredApnStr + "}");
            }
        }
        return true;
    }

@@ -3430,7 +3443,9 @@ public class DcTracker extends Handler {
        }
    }

    @Nullable
    ApnSetting getPreferredApn() {
        //Only call this method from main thread
        if (mAllApnSettings == null || mAllApnSettings.isEmpty()) {
            log("getPreferredApn: mAllApnSettings is empty");
            return null;