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

Commit c0398031 authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE - Support disconnecting while trying to connect." into lmp-preview-dev

parents b9a65de1 38fe3984
Loading
Loading
Loading
Loading
+29 −17
Original line number Diff line number Diff line
@@ -257,17 +257,19 @@ public abstract class NetworkAgent extends Handler {
    }

    /**
     * called to go through our list of requests and see if we're
     * good enough to try connecting.
     * Called to go through our list of requests and see if we're
     * good enough to try connecting, or if we have gotten worse and
     * need to disconnect.
     *
     * Only does connects - we disconnect when requested via
     * Once we are registered, does nothing: we disconnect when requested via
     * CMD_CHANNEL_DISCONNECTED, generated by either a loss of connection
     * between modules (bearer or ConnectivityService dies) or more commonly
     * when the NetworkInfo reports to ConnectivityService it is disconnected.
     */
    private void evalScores() {
        if (mConnectionRequested) {
            if (VDBG) log("evalScores - already trying - size=" + mNetworkRequests.size());
        synchronized(mLockObj) {
            if (mRegistered) {
                if (VDBG) log("evalScores - already connected - size=" + mNetworkRequests.size());
                // already trying
                return;
            }
@@ -277,12 +279,22 @@ public abstract class NetworkAgent extends Handler {
                if (VDBG) log(" checking request Min " + score + " vs my score " + mNetworkScore);
                if (score < mNetworkScore) {
                    // have a request that has a lower scored network servicing it
                // (or no network) than we could provide, so lets connect!
                    // (or no network) than we could provide, so let's connect!
                    mConnectionRequested = true;
                    connect();
                    return;
                }
            }
            // Our score is not high enough to satisfy any current request.
            // This can happen if our score goes down after a connection is
            // requested but before we actually connect. In this case, disconnect
            // rather than continue trying - there's no point connecting if we know
            // we'll just be torn down as soon as we do.
            if (mConnectionRequested) {
                mConnectionRequested = false;
                disconnect();
            }
        }
    }

    public void addNetworkRequest(NetworkRequest networkRequest, int score) {