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

Commit 2d119eda authored by Jack Yu's avatar Jack Yu Committed by android-build-merger
Browse files

Merge "Fixed dangling network agent issue"

am: 437a02b3

Change-Id: Ic3e88af1fbcae8c92d1dd15637184352989e075a
parents b3de8a8c 437a02b3
Loading
Loading
Loading
Loading
+21 −7
Original line number Diff line number Diff line
@@ -1694,7 +1694,7 @@ public class DataConnection extends StateMachine {
                    mApnSetting != null
                        ? mApnSetting.canHandleType(ApnSetting.TYPE_DEFAULT) : false);
            if (mHandoverState == HANDOVER_STATE_BEING_TRANSFERRED) {
                mHandoverState = HANDOVER_STATE_COMPLETED;
                setHandoverState(HANDOVER_STATE_COMPLETED);
            }

            // Check for dangling agent. Ideally the handover source agent should be null if
@@ -1707,7 +1707,8 @@ public class DataConnection extends StateMachine {
                    // If the source data connection still owns this agent, then just reset the
                    // handover state back to idle because handover is already failed.
                    mHandoverLocalLog.log(
                            "Handover failed. Reset the source dc state to idle");
                            "Handover failed. Reset the source dc " + sourceDc.getName()
                                    + " state to idle");
                    sourceDc.setHandoverState(HANDOVER_STATE_IDLE);
                } else {
                    // The agent is now a dangling agent. No data connection owns this agent.
@@ -1716,7 +1717,17 @@ public class DataConnection extends StateMachine {
                            "Handover failed and dangling agent found.");
                    mHandoverSourceNetworkAgent.acquireOwnership(
                            DataConnection.this, mTransportType);
                    mHandoverSourceNetworkAgent.sendNetworkInfo(mNetworkInfo, DataConnection.this);
                    NetworkInfo networkInfo = mHandoverSourceNetworkAgent.getNetworkInfo();
                    if (networkInfo != null) {
                        networkInfo.setDetailedState(NetworkInfo.DetailedState.DISCONNECTED,
                                "dangling clean up", networkInfo.getExtraInfo());
                        mHandoverSourceNetworkAgent.sendNetworkInfo(networkInfo,
                                DataConnection.this);
                    } else {
                        String str = "Failed to get network info.";
                        loge(str);
                        mHandoverLocalLog.log(str);
                    }
                    mHandoverSourceNetworkAgent.releaseOwnership(DataConnection.this);
                }
                mHandoverSourceNetworkAgent = null;
@@ -2003,7 +2014,8 @@ public class DataConnection extends StateMachine {
                }

                if (mHandoverSourceNetworkAgent != null) {
                    String logStr = "Transfer network agent successfully.";
                    String logStr = "Transfer network agent " + mHandoverSourceNetworkAgent.getTag()
                            + " successfully.";
                    log(logStr);
                    mHandoverLocalLog.log(logStr);
                    mNetworkAgent = mHandoverSourceNetworkAgent;
@@ -2637,10 +2649,12 @@ public class DataConnection extends StateMachine {
    }

    void setHandoverState(@HandoverState int state) {
        if (mHandoverState != state) {
            mHandoverLocalLog.log("State changed from " + handoverStateToString(mHandoverState)
                    + " to " + handoverStateToString(state));
            mHandoverState = state;
        }
    }

    /**
     * @return the string for msg.what as our info.
+21 −1
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 * different {@link DataConnection}. Thus each method in this class needs to be synchronized.
 */
public class DcNetworkAgent extends NetworkAgent {
    private String mTag;
    private final String mTag;

    private Phone mPhone;

@@ -67,6 +67,8 @@ public class DcNetworkAgent extends NetworkAgent {

    private static AtomicInteger sSerialNumber = new AtomicInteger(0);

    private NetworkInfo mNetworkInfo;

    private DcNetworkAgent(DataConnection dc, String tag, Phone phone, NetworkInfo ni,
                           int score, NetworkMisc misc, int factorySerialNumber,
                           int transportType) {
@@ -78,9 +80,17 @@ public class DcNetworkAgent extends NetworkAgent {
        mNetworkCapabilities = dc.getNetworkCapabilities();
        mTransportType = transportType;
        mDataConnection = dc;
        mNetworkInfo = ni;
        logd(tag + " created for data connection " + dc.getName());
    }

    /**
     * @return The tag
     */
    String getTag() {
        return mTag;
    }

    /**
     * Constructor
     *
@@ -263,9 +273,19 @@ public class DcNetworkAgent extends NetworkAgent {
                    + mDataConnection.getName() + ", ignored the request from " + dc.getName());
            return;
        }
        mNetworkInfo = networkInfo;
        sendNetworkInfo(networkInfo);
    }

    /**
     * Get the latest sent network info.
     *
     * @return network info
     */
    public synchronized NetworkInfo getNetworkInfo() {
        return mNetworkInfo;
    }

    @Override
    protected synchronized void startSocketKeepalive(Message msg) {
        if (mDataConnection == null) {