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

Commit 6d246a9d authored by Robert Greenwalt's avatar Robert Greenwalt Committed by Android (Google) Code Review
Browse files

Merge "Make a network the default when it connects if we have no default." into lmp-dev

parents a0ee004a 27b02b7a
Loading
Loading
Loading
Loading
+19 −10
Original line number Diff line number Diff line
@@ -5720,6 +5720,17 @@ public class ConnectivityService extends IConnectivityManager.Stub {
        oldNetwork.asyncChannel.disconnect();
    }

    private void makeDefault(NetworkAgentInfo newNetwork) {
        if (VDBG) log("Switching to new default network: " + newNetwork);
        setupDataActivityTracking(newNetwork);
        try {
            mNetd.setDefaultNetId(newNetwork.network.netId);
        } catch (Exception e) {
            loge("Exception setting default network :" + e);
        }
        handleApplyDefaultProxy(newNetwork.linkProperties.getHttpProxy());
    }

    private void handleConnectionValidated(NetworkAgentInfo newNetwork) {
        if (newNetwork == null) {
            loge("Unknown NetworkAgentInfo in handleConnectionValidated");
@@ -5813,16 +5824,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
        }
        if (keep) {
            if (isNewDefault) {
                if (VDBG) log("Switching to new default network: " + newNetwork);
                setupDataActivityTracking(newNetwork);
                try {
                    mNetd.setDefaultNetId(newNetwork.network.netId);
                } catch (Exception e) {
                    loge("Exception setting default network :" + e);
                }
                if (newNetwork.equals(mNetworkForRequestId.get(mDefaultRequest.requestId))) {
                    handleApplyDefaultProxy(newNetwork.linkProperties.getHttpProxy());
                }
                makeDefault(newNetwork);
                synchronized (ConnectivityService.this) {
                    // have a new default network, release the transition wakelock in
                    // a second if it's held.  The second pause is to allow apps
@@ -5919,6 +5921,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                }
                // TODO: support proxy per network.
            }
            // Make default network if we have no default.  Any network is better than no network.
            if (mNetworkForRequestId.get(mDefaultRequest.requestId) == null &&
                    networkAgent.isVPN() == false &&
                    mDefaultRequest.networkCapabilities.satisfiedByNetworkCapabilities(
                    networkAgent.networkCapabilities)) {
                makeDefault(networkAgent);
            }
        } else if (state == NetworkInfo.State.DISCONNECTED ||
                state == NetworkInfo.State.SUSPENDED) {
            networkAgent.asyncChannel.disconnect();