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

Commit 6b473f7b authored by Tobias Thierer's avatar Tobias Thierer Committed by android-build-merger
Browse files

Merge \\"Changes for upgrade to OkHttp 2.7.5\\" am: a31247bd

am: f6bcab7f

Change-Id: I7a1c9838a22cb7e8228e77bde68283fda57c83d6
parents 791de14f f6bcab7f
Loading
Loading
Loading
Loading
+13 −10
Original line number Original line Diff line number Diff line
@@ -34,9 +34,13 @@ import java.net.SocketException;
import java.net.UnknownHostException;
import java.net.UnknownHostException;
import java.net.URL;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLConnection;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.net.SocketFactory;
import javax.net.SocketFactory;


import com.android.okhttp.ConnectionPool;
import com.android.okhttp.ConnectionPool;
import com.android.okhttp.Dns;
import com.android.okhttp.HttpHandler;
import com.android.okhttp.HttpHandler;
import com.android.okhttp.HttpsHandler;
import com.android.okhttp.HttpsHandler;
import com.android.okhttp.OkHttpClient;
import com.android.okhttp.OkHttpClient;
@@ -62,10 +66,10 @@ public class Network implements Parcelable {
    // Objects used to perform per-network operations such as getSocketFactory
    // Objects used to perform per-network operations such as getSocketFactory
    // and openConnection, and a lock to protect access to them.
    // and openConnection, and a lock to protect access to them.
    private volatile NetworkBoundSocketFactory mNetworkBoundSocketFactory = null;
    private volatile NetworkBoundSocketFactory mNetworkBoundSocketFactory = null;
    // mLock should be used to control write access to mConnectionPool and mNetwork.
    // mLock should be used to control write access to mConnectionPool and mDns.
    // maybeInitHttpClient() must be called prior to reading either variable.
    // maybeInitHttpClient() must be called prior to reading either variable.
    private volatile ConnectionPool mConnectionPool = null;
    private volatile ConnectionPool mConnectionPool = null;
    private volatile com.android.okhttp.internal.Network mNetwork = null;
    private volatile Dns mDns = null;
    private final Object mLock = new Object();
    private final Object mLock = new Object();


    // Default connection pool values. These are evaluated at startup, just
    // Default connection pool values. These are evaluated at startup, just
@@ -219,17 +223,17 @@ public class Network implements Parcelable {
    // out) ConnectionPools.
    // out) ConnectionPools.
    private void maybeInitHttpClient() {
    private void maybeInitHttpClient() {
        synchronized (mLock) {
        synchronized (mLock) {
            if (mNetwork == null) {
            if (mDns == null) {
                mNetwork = new com.android.okhttp.internal.Network() {
                mDns = new Dns() {
                    @Override
                    @Override
                    public InetAddress[] resolveInetAddresses(String host) throws UnknownHostException {
                    public List<InetAddress> lookup(String hostname) throws UnknownHostException {
                        return Network.this.getAllByName(host);
                        return Arrays.asList(Network.this.getAllByName(hostname));
                    }
                    }
                };
                };
            }
            }
            if (mConnectionPool == null) {
            if (mConnectionPool == null) {
                mConnectionPool = new ConnectionPool(httpMaxConnections,
                mConnectionPool = new ConnectionPool(httpMaxConnections,
                        httpKeepAliveDurationMs);
                        httpKeepAliveDurationMs, TimeUnit.MILLISECONDS);
            }
            }
        }
        }
    }
    }
@@ -288,9 +292,8 @@ public class Network implements Parcelable {
        }
        }
        OkHttpClient client = okUrlFactory.client();
        OkHttpClient client = okUrlFactory.client();
        client.setSocketFactory(getSocketFactory()).setConnectionPool(mConnectionPool);
        client.setSocketFactory(getSocketFactory()).setConnectionPool(mConnectionPool);

        // Let network traffic go via mDns
        // Use internal APIs to change the Network.
        client.setDns(mDns);
        Internal.instance.setNetwork(client, mNetwork);


        return okUrlFactory.open(url);
        return okUrlFactory.open(url);
    }
    }