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

Commit 1f0239fc authored by Jack Yu's avatar Jack Yu
Browse files

Passed request/release type all the way down

This is the prelimanary change to support completion
messages in telephony network factory.

Test: Telephony sanity tests + unit tests
Bug: 73659459
Change-Id: Ic31ba081be43f6bf719f5d08ed0fde3918450461
parent 7abde456
Loading
Loading
Loading
Loading
+32 −22
Original line number Diff line number Diff line
@@ -68,6 +68,8 @@ import com.android.internal.telephony.RILConstants;
import com.android.internal.telephony.RetryManager;
import com.android.internal.telephony.ServiceStateTracker;
import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.dataconnection.DcTracker.ReleaseNetworkType;
import com.android.internal.telephony.dataconnection.DcTracker.RequestNetworkType;
import com.android.internal.telephony.metrics.TelephonyMetrics;
import com.android.internal.util.AsyncChannel;
import com.android.internal.util.IndentingPrintWriter;
@@ -142,16 +144,18 @@ public class DataConnection extends StateMachine {
        int mRilRat;
        Message mOnCompletedMsg;
        final int mConnectionGeneration;
        final boolean mIsHandover;
        @RequestNetworkType
        final int mRequestType;

        ConnectionParams(ApnContext apnContext, int profileId, int rilRadioTechnology,
                         Message onCompletedMsg, int connectionGeneration, boolean isHandover) {
                         Message onCompletedMsg, int connectionGeneration,
                         @RequestNetworkType int requestType) {
            mApnContext = apnContext;
            mProfileId = profileId;
            mRilRat = rilRadioTechnology;
            mOnCompletedMsg = onCompletedMsg;
            mConnectionGeneration = connectionGeneration;
            mIsHandover = isHandover;
            mRequestType = requestType;
        }

        @Override
@@ -160,7 +164,7 @@ public class DataConnection extends StateMachine {
                    + " mProfileId=" + mProfileId
                    + " mRat=" + mRilRat
                    + " mOnCompletedMsg=" + msgToString(mOnCompletedMsg)
                    + " mIsHandover=" + mIsHandover
                    + " mRequestType=" + DcTracker.requestTypeToString(mRequestType)
                    + "}";
        }
    }
@@ -172,14 +176,15 @@ public class DataConnection extends StateMachine {
        int mTag;
        public ApnContext mApnContext;
        String mReason;
        final boolean mIsHandover;
        @ReleaseNetworkType
        final int mReleaseType;
        Message mOnCompletedMsg;

        DisconnectParams(ApnContext apnContext, String reason, boolean isHandover,
        DisconnectParams(ApnContext apnContext, String reason, @ReleaseNetworkType int releaseType,
                         Message onCompletedMsg) {
            mApnContext = apnContext;
            mReason = reason;
            mIsHandover = isHandover;
            mReleaseType = releaseType;
            mOnCompletedMsg = onCompletedMsg;
        }

@@ -187,7 +192,7 @@ public class DataConnection extends StateMachine {
        public String toString() {
            return "{mTag=" + mTag + " mApnContext=" + mApnContext
                    + " mReason=" + mReason
                    + " mIsHandover=" + mIsHandover
                    + " mReleaseType=" + DcTracker.releaseTypeToString(mReleaseType)
                    + " mOnCompletedMsg=" + msgToString(mOnCompletedMsg) + "}";
        }
    }
@@ -598,7 +603,7 @@ public class DataConnection extends StateMachine {
        // Check if this data setup is a handover.
        LinkProperties linkProperties = null;
        int reason = DataService.REQUEST_REASON_NORMAL;
        if (cp.mIsHandover) {
        if (cp.mRequestType == DcTracker.REQUEST_TYPE_HANDOVER) {
            // If this is a data setup for handover, we need to pass the link properties
            // of the existing data connection to the modem.
            DcTracker dcTracker = getHandoverDcTracker();
@@ -658,7 +663,7 @@ public class DataConnection extends StateMachine {
            if (TextUtils.equals(dp.mReason, Phone.REASON_RADIO_TURNED_OFF)
                    || TextUtils.equals(dp.mReason, Phone.REASON_PDP_RESET)) {
                discReason = DataService.REQUEST_REASON_SHUTDOWN;
            } else if (dp.mIsHandover) {
            } else if (dp.mReleaseType == DcTracker.RELEASE_TYPE_HANDOVER) {
                discReason = DataService.REQUEST_REASON_HANDOVER;
            }
        }
@@ -678,7 +683,7 @@ public class DataConnection extends StateMachine {
            if (apnContext == alreadySent) continue;
            if (reason != null) apnContext.setReason(reason);
            Pair<ApnContext, Integer> pair = new Pair<>(apnContext, cp.mConnectionGeneration);
            Message msg = mDct.obtainMessage(event, mCid, cp.mIsHandover ? 1 : 0, pair);
            Message msg = mDct.obtainMessage(event, mCid, cp.mRequestType, pair);
            AsyncResult.forMessage(msg);
            msg.sendToTarget();
        }
@@ -703,7 +708,7 @@ public class DataConnection extends StateMachine {

            long timeStamp = System.currentTimeMillis();
            connectionCompletedMsg.arg1 = mCid;
            connectionCompletedMsg.arg2 = cp.mIsHandover ? 1 : 0;
            connectionCompletedMsg.arg2 = cp.mRequestType;

            if (cause == DataFailCause.NONE) {
                mCreateTime = timeStamp;
@@ -1806,7 +1811,8 @@ public class DataConnection extends StateMachine {
                        + ", mUnmeteredUseOnly = " + mUnmeteredUseOnly);
            }

            if (mConnectionParams != null && mConnectionParams.mIsHandover) {
            if (mConnectionParams != null
                    && mConnectionParams.mRequestType == DcTracker.REQUEST_TYPE_HANDOVER) {
                // If this is a data setup for handover, we need to reuse the existing network agent
                // instead of creating a new one. This should be transparent to connectivity
                // service.
@@ -1864,7 +1870,8 @@ public class DataConnection extends StateMachine {
                // cases we need to update connectivity service with the latest network info.
                //
                // For handover, the network agent is transferred to the other data connection.
                if (mDisconnectParams == null || !mDisconnectParams.mIsHandover) {
                if (mDisconnectParams == null
                        || mDisconnectParams.mReleaseType != DcTracker.RELEASE_TYPE_HANDOVER) {
                    mNetworkAgent.sendNetworkInfo(mNetworkInfo);
                }
                mNetworkAgent = null;
@@ -2295,7 +2302,7 @@ public class DataConnection extends StateMachine {
                log("DcNetworkAgent: [unwanted]: disconnect apnContext=" + apnContext);
                Message msg = mDct.obtainMessage(DctConstants.EVENT_DISCONNECT_DONE, pair);
                DisconnectParams dp = new DisconnectParams(apnContext, apnContext.getReason(),
                        false, msg);
                        DcTracker.RELEASE_TYPE_DETACH, msg);
                DataConnection.this.sendMessage(DataConnection.this.
                        obtainMessage(EVENT_DISCONNECT, dp));
            }
@@ -2477,16 +2484,17 @@ public class DataConnection extends StateMachine {
     *                       AsyncResult.result = FailCause and AsyncResult.exception = Exception().
     * @param connectionGeneration used to track a single connection request so disconnects can get
     *                             ignored if obsolete.
     * @param isHandover {@code true} if this request is for handover.
     * @param requestType Data request type
     */
    public void bringUp(ApnContext apnContext, int profileId, int rilRadioTechnology,
                        Message onCompletedMsg, int connectionGeneration, boolean isHandover) {
                        Message onCompletedMsg, int connectionGeneration,
                        @RequestNetworkType int requestType) {
        if (DBG) {
            log("bringUp: apnContext=" + apnContext + " onCompletedMsg=" + onCompletedMsg);
        }
        sendMessage(DataConnection.EVENT_CONNECT,
                new ConnectionParams(apnContext, profileId, rilRadioTechnology, onCompletedMsg,
                        connectionGeneration, isHandover));
                        connectionGeneration, requestType));
    }

    /**
@@ -2503,7 +2511,8 @@ public class DataConnection extends StateMachine {
                    + onCompletedMsg);
        }
        sendMessage(DataConnection.EVENT_DISCONNECT,
                new DisconnectParams(apnContext, reason, false, onCompletedMsg));
                new DisconnectParams(apnContext, reason, DcTracker.RELEASE_TYPE_DETACH,
                        onCompletedMsg));
    }

    // ******* "public" interface
@@ -2520,14 +2529,15 @@ public class DataConnection extends StateMachine {
     * Tear down the connection through the apn on the network.  Ignores reference count and
     * and always tears down.
     *
     * @param isHandover {@code true} if this is for handover
     * @param releaseType Data release type
     * @param onCompletedMsg is sent with its msg.obj as an AsyncResult object.
     *        With AsyncResult.userObj set to the original msg.obj.
     */
    public void tearDownAll(String reason, boolean isHandover, Message onCompletedMsg) {
    public void tearDownAll(String reason, @ReleaseNetworkType int releaseType,
                            Message onCompletedMsg) {
        if (DBG) log("tearDownAll: reason=" + reason + " onCompletedMsg=" + onCompletedMsg);
        sendMessage(DataConnection.EVENT_DISCONNECT_ALL,
                new DisconnectParams(null, reason, isHandover, onCompletedMsg));
                new DisconnectParams(null, reason, releaseType, onCompletedMsg));
    }

    /**
+41 −37
Original line number Diff line number Diff line
@@ -1380,7 +1380,7 @@ public class DcTracker extends Handler {
            if (apnContext.isConnectable()) {
                log("isConnectable() call trySetupData");
                apnContext.setReason(reason);
                trySetupData(apnContext, false);
                trySetupData(apnContext, REQUEST_TYPE_NORMAL);
            }
        }
    }
@@ -1391,7 +1391,7 @@ public class DcTracker extends Handler {
        return result;
    }

    private boolean trySetupData(ApnContext apnContext, boolean isHandover) {
    private boolean trySetupData(ApnContext apnContext, @RequestNetworkType int requestType) {

        if (mPhone.getSimulatedRadioControl() != null) {
            // Assume data is connected on the simulator
@@ -1406,8 +1406,8 @@ public class DcTracker extends Handler {
        DataConnectionReasons dataConnectionReasons = new DataConnectionReasons();
        boolean isDataAllowed = isDataAllowed(apnContext, dataConnectionReasons);
        String logStr = "trySetupData for APN type " + apnContext.getApnType() + ", reason: "
                + apnContext.getReason() + ", isHandover=" + isHandover + ". "
                + dataConnectionReasons.toString();
                + apnContext.getReason() + ", requestType=" + requestTypeToString(requestType)
                + ". " + dataConnectionReasons.toString();
        if (DBG) log(logStr);
        apnContext.requestLog(logStr);
        if (isDataAllowed) {
@@ -1439,7 +1439,7 @@ public class DcTracker extends Handler {
                }
            }

            boolean retValue = setupData(apnContext, radioTech, isHandover);
            boolean retValue = setupData(apnContext, radioTech, requestType);
            notifyOffApnsOfAvailability();

            if (DBG) log("trySetupData: X retValue=" + retValue);
@@ -1540,7 +1540,7 @@ public class DcTracker extends Handler {
                    if (apnContext.isDisconnected() == false) didDisconnect = true;
                    if (DBG) log("clean up metered ApnContext Type: " + apnContext.getApnType());
                    apnContext.setReason(reason);
                    cleanUpConnectionInternal(detach, false, apnContext);
                    cleanUpConnectionInternal(detach, RELEASE_TYPE_DETACH, apnContext);
                }
            } else {
                // Exclude the IMS APN from single data connection case.
@@ -1551,7 +1551,7 @@ public class DcTracker extends Handler {
                // TODO - only do cleanup if not disconnected
                if (apnContext.isDisconnected() == false) didDisconnect = true;
                apnContext.setReason(reason);
                cleanUpConnectionInternal(detach, false, apnContext);
                cleanUpConnectionInternal(detach, RELEASE_TYPE_DETACH, apnContext);
            }
        }

@@ -1590,11 +1590,10 @@ public class DcTracker extends Handler {
     * @param detach {@code true} if detaching APN context from the underlying data connection (when
     * no other APN context is attached to the data connection, the data connection will be torn
     * down.) {@code false} to only reset the data connection's state machine.
     * @param isHandover {@code true} if this is a handover request. When this is set to
     * {@code true}, {@code detach} also needs to be set to {@code true}.
     * @param releaseType Data release type.
     * @param apnContext The APN context to be detached.
     */
    private void cleanUpConnectionInternal(boolean detach, boolean isHandover,
    private void cleanUpConnectionInternal(boolean detach, @ReleaseNetworkType int releaseType,
                                           ApnContext apnContext) {
        if (apnContext == null) {
            if (DBG) log("cleanUpConnectionInternal: apn context is null");
@@ -1638,8 +1637,8 @@ public class DcTracker extends Handler {
                        Pair<ApnContext, Integer> pair = new Pair<>(apnContext, generation);
                        Message msg = obtainMessage(DctConstants.EVENT_DISCONNECT_DONE, pair);

                        if (disconnectAll || isHandover) {
                            dataConnection.tearDownAll(apnContext.getReason(), isHandover, msg);
                        if (disconnectAll || releaseType == RELEASE_TYPE_HANDOVER) {
                            dataConnection.tearDownAll(apnContext.getReason(), releaseType, msg);
                        } else {
                            dataConnection.tearDown(apnContext, apnContext.getReason(), msg);
                        }
@@ -1831,12 +1830,16 @@ public class DcTracker extends Handler {
     *
     * @param apnContext APN context
     * @param radioTech RAT of the data connection
     * @param isHandover {@code true} if this is for data handover
     * @param requestType Data request type
     * @return True if successful, otherwise false.
     */
    private boolean setupData(ApnContext apnContext, int radioTech, boolean isHandover) {
        if (DBG) log("setupData: apnContext=" + apnContext + ", isHandover=" + isHandover);
        apnContext.requestLog("setupData. handover=" + isHandover);
    private boolean setupData(ApnContext apnContext, int radioTech,
                              @RequestNetworkType int requestType) {
        if (DBG) {
            log("setupData: apnContext=" + apnContext + ", requestType="
                    + requestTypeToString(requestType));
        }
        apnContext.requestLog("setupData. requestType=" + requestTypeToString(requestType));
        ApnSetting apnSetting;
        DataConnection dataConnection = null;

@@ -1924,7 +1927,7 @@ public class DcTracker extends Handler {
        Message msg = obtainMessage();
        msg.what = DctConstants.EVENT_DATA_SETUP_COMPLETE;
        msg.obj = new Pair<ApnContext, Integer>(apnContext, generation);
        dataConnection.bringUp(apnContext, profileId, radioTech, msg, generation, isHandover);
        dataConnection.bringUp(apnContext, profileId, radioTech, msg, generation, requestType);

        if (DBG) log("setupData: initing!");
        return true;
@@ -2326,7 +2329,7 @@ public class DcTracker extends Handler {
        apnContext.setEnabled(true);
        if (trySetup) {
            apnContext.resetErrorCodeRetries();
            trySetupData(apnContext, requestType == REQUEST_TYPE_HANDOVER);
            trySetupData(apnContext, requestType);
        }
    }

@@ -2378,7 +2381,7 @@ public class DcTracker extends Handler {

        apnContext.setEnabled(false);
        if (cleanup) {
            cleanUpConnectionInternal(true, releaseType == RELEASE_TYPE_HANDOVER, apnContext);
            cleanUpConnectionInternal(true, releaseType, apnContext);
        }

        if (isOnlySingleDcAllowed(mPhone.getServiceState().getRilDataRadioTechnology())
@@ -2607,7 +2610,7 @@ public class DcTracker extends Handler {
        }

        if (getOverallState() != DctConstants.State.IDLE) {
            cleanUpConnectionInternal(true, false, null);
            cleanUpConnectionInternal(true, RELEASE_TYPE_DETACH, null);
        }
    }

@@ -2668,7 +2671,7 @@ public class DcTracker extends Handler {
     * there is an error this method will call {@link #onDataSetupCompleteError}.
     */
    private void onDataSetupComplete(ApnContext apnContext, boolean success, int cause,
                                     boolean isHandover) {
                                     @RequestNetworkType int requestType) {
        if (success) {
            DataConnection dataConnection = apnContext.getDataConnection();

@@ -2692,7 +2695,7 @@ public class DcTracker extends Handler {
            }
            if (dataConnection == null) {
                log("onDataSetupComplete: no connection to DC, handle as error");
                onDataSetupCompleteError(apnContext, isHandover);
                onDataSetupCompleteError(apnContext, requestType);
            } else {
                ApnSetting apn = apnContext.getApnSetting();
                if (DBG) {
@@ -2806,7 +2809,7 @@ public class DcTracker extends Handler {
            if (DBG) {
                ApnSetting apn = apnContext.getApnSetting();
                log("onDataSetupComplete: error apn=" + apn.getApnName() + ", cause=" + cause
                        + ", isHandover=" + isHandover);
                        + ", requestType=" + requestTypeToString(requestType));
            }
            if (DataFailCause.isEventLoggable(cause)) {
                // Log this failure to the Event Logs.
@@ -2838,7 +2841,7 @@ public class DcTracker extends Handler {
                log("cause = " + cause + ", mark apn as permanent failed. apn = " + apn);
                apnContext.markApnPermanentFailed(apn);
            }
            onDataSetupCompleteError(apnContext, isHandover);
            onDataSetupCompleteError(apnContext, requestType);
        }
    }

@@ -2848,12 +2851,13 @@ public class DcTracker extends Handler {
     * beginning if the list is empty. Between each SETUP request there will
     * be a delay defined by {@link #getApnDelay()}.
     */
    private void onDataSetupCompleteError(ApnContext apnContext, boolean isHandover) {
    private void onDataSetupCompleteError(ApnContext apnContext,
                                          @RequestNetworkType int requestType) {
        long delay = apnContext.getDelayForNextApn(mFailFast);

        // Check if we need to retry or not.
        // TODO: We should support handover retry in the future.
        if (delay >= 0 && !isHandover) {
        if (delay >= 0 && requestType != REQUEST_TYPE_HANDOVER) {
            if (DBG) log("onDataSetupCompleteError: Try next APN. delay = " + delay);
            apnContext.setState(DctConstants.State.RETRYING);
            // Wait a bit before trying the next APN, so that
@@ -2867,7 +2871,7 @@ public class DcTracker extends Handler {
            mPhone.notifyDataConnection(apnContext.getApnType());
            apnContext.setDataConnection(null);
            log("onDataSetupCompleteError: Stop retrying APNs. delay=" + delay
                    + ", isHandover=" + isHandover);
                    + ", requestType=" + requestTypeToString(requestType));
        }
    }

@@ -3398,7 +3402,7 @@ public class DcTracker extends Handler {
        Pair<ApnContext, Integer> pair;
        ApnContext apnContext;
        int generation;
        boolean isHandover;
        int requestType;
        switch (msg.what) {
            case DctConstants.EVENT_RECORDS_LOADED:
                // If onRecordsLoadedOrSubIdChanged() is not called here, it should be called on
@@ -3459,7 +3463,7 @@ public class DcTracker extends Handler {
                    apnContext = mApnContextsByType.get(ApnSetting.TYPE_DEFAULT);
                    if (apnContext != null) {
                        apnContext.setReason(Phone.REASON_PS_RESTRICT_ENABLED);
                        trySetupData(apnContext, false);
                        trySetupData(apnContext, REQUEST_TYPE_NORMAL);
                    } else {
                        loge("**** Default ApnContext not found ****");
                        if (Build.IS_DEBUGGABLE) {
@@ -3470,12 +3474,12 @@ public class DcTracker extends Handler {
                break;

            case DctConstants.EVENT_TRY_SETUP_DATA:
                trySetupData((ApnContext) msg.obj, false);
                trySetupData((ApnContext) msg.obj, REQUEST_TYPE_NORMAL);
                break;

            case DctConstants.EVENT_CLEAN_UP_CONNECTION:
                if (DBG) log("EVENT_CLEAN_UP_CONNECTION");
                cleanUpConnectionInternal(true, false, (ApnContext) msg.obj);
                cleanUpConnectionInternal(true, RELEASE_TYPE_DETACH, (ApnContext) msg.obj);
                break;
            case DctConstants.EVENT_CLEAN_UP_ALL_CONNECTIONS:
                if ((msg.obj != null) && (msg.obj instanceof String == false)) {
@@ -3558,7 +3562,7 @@ public class DcTracker extends Handler {
                pair = (Pair<ApnContext, Integer>) ar.userObj;
                apnContext = pair.first;
                generation = pair.second;
                isHandover = msg.arg2 != 0;
                requestType = msg.arg2;
                if (apnContext.getConnectionGeneration() == generation) {
                    boolean success = true;
                    int cause = DataFailCause.UNKNOWN;
@@ -3566,7 +3570,7 @@ public class DcTracker extends Handler {
                        success = false;
                        cause = (int) ar.result;
                    }
                    onDataSetupComplete(apnContext, success, cause, isHandover);
                    onDataSetupComplete(apnContext, success, cause, requestType);
                } else {
                    loge("EVENT_DATA_SETUP_COMPLETE: Dropped the event because generation "
                            + "did not match.");
@@ -3578,9 +3582,9 @@ public class DcTracker extends Handler {
                pair = (Pair<ApnContext, Integer>) ar.userObj;
                apnContext = pair.first;
                generation = pair.second;
                isHandover = msg.arg1 != 0;
                requestType = msg.arg2;
                if (apnContext.getConnectionGeneration() == generation) {
                    onDataSetupCompleteError(apnContext, isHandover);
                    onDataSetupCompleteError(apnContext, requestType);
                } else {
                    loge("EVENT_DATA_SETUP_COMPLETE_ERROR: Dropped the event because generation "
                            + "did not match.");
@@ -3675,7 +3679,7 @@ public class DcTracker extends Handler {
                        mIsProvisioning = false;
                        mProvisioningUrl = null;
                        stopProvisioningApnAlarm();
                        cleanUpConnectionInternal(true, false, apnCtx);
                        cleanUpConnectionInternal(true, RELEASE_TYPE_DETACH, apnCtx);
                    } else {
                        if (DBG) {
                            log("EVENT_PROVISIONING_APN_ALARM: ignore stale tag,"
@@ -4120,7 +4124,7 @@ public class DcTracker extends Handler {
                    if (!apnContext.isDisconnected()) {
                        if (VDBG) log("cleanUpConnectionsOnUpdatedApns for " + apnContext);
                        apnContext.setReason(reason);
                        cleanUpConnectionInternal(true, false, apnContext);
                        cleanUpConnectionInternal(true, RELEASE_TYPE_DETACH, apnContext);
                    }
                }
            }