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

Commit 204dc65f authored by Paul Jensen's avatar Paul Jensen Committed by Android (Google) Code Review
Browse files

Merge "Flush HTTP socket pools and DNS cache when binding process to a Network." into lmp-dev

parents 5236971b c91b5348
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ import java.net.InetAddress;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.HashMap;

import libcore.net.event.NetworkEventDispatcher;

/**
 * Class that answers queries about the state of network connectivity. It also
 * notifies applications when network connectivity changes. Get an instance
@@ -2467,7 +2469,20 @@ public class ConnectivityManager {
     * @return {@code true} on success, {@code false} if the {@link Network} is no longer valid.
     */
    public static boolean setProcessDefaultNetwork(Network network) {
        return NetworkUtils.bindProcessToNetwork(network == null ? NETID_UNSET : network.netId);
        int netId = (network == null) ? NETID_UNSET : network.netId;
        if (netId == NetworkUtils.getNetworkBoundToProcess()) {
            return true;
        }
        if (NetworkUtils.bindProcessToNetwork(netId)) {
            // Must flush DNS cache as new network may have different DNS resolutions.
            InetAddress.clearDnsCache();
            // Must flush socket pool as idle sockets will be bound to previous network and may
            // cause subsequent fetches to be performed on old network.
            NetworkEventDispatcher.getInstance().onNetworkConfigurationChanged();
            return true;
        } else {
            return false;
        }
    }

    /**