resolved conflicts for merge of 7382c02d to lmp-mr1-dev-plus-aosp
Change-Id: Idfa2750230aa56e7ae34fcc33d62558df942abd0
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
import android.net.NetworkUtils;
|
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.system.ErrnoException;
|
import android.system.ErrnoException;
|
||||||
@@ -34,15 +33,14 @@ 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.net.URLStreamHandler;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
import com.android.okhttp.ConnectionPool;
|
import com.android.okhttp.ConnectionPool;
|
||||||
import com.android.okhttp.HostResolver;
|
|
||||||
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;
|
||||||
|
import com.android.okhttp.OkUrlFactory;
|
||||||
|
import com.android.okhttp.internal.Internal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Identifies a {@code Network}. This is supplied to applications via
|
* Identifies a {@code Network}. This is supplied to applications via
|
||||||
@@ -63,10 +61,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 mHostResolver.
|
// mLock should be used to control write access to mConnectionPool and mNetwork.
|
||||||
// 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 HostResolver mHostResolver = null;
|
private volatile com.android.okhttp.internal.Network mNetwork = null;
|
||||||
private Object mLock = new Object();
|
private Object mLock = new Object();
|
||||||
|
|
||||||
// Default connection pool values. These are evaluated at startup, just
|
// Default connection pool values. These are evaluated at startup, just
|
||||||
@@ -220,10 +218,10 @@ public class Network implements Parcelable {
|
|||||||
// out) ConnectionPools.
|
// out) ConnectionPools.
|
||||||
private void maybeInitHttpClient() {
|
private void maybeInitHttpClient() {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
if (mHostResolver == null) {
|
if (mNetwork == null) {
|
||||||
mHostResolver = new HostResolver() {
|
mNetwork = new com.android.okhttp.internal.Network() {
|
||||||
@Override
|
@Override
|
||||||
public InetAddress[] getAllByName(String host) throws UnknownHostException {
|
public InetAddress[] resolveInetAddresses(String host) throws UnknownHostException {
|
||||||
return Network.this.getAllByName(host);
|
return Network.this.getAllByName(host);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -278,22 +276,25 @@ public class Network implements Parcelable {
|
|||||||
if (proxy == null) throw new IllegalArgumentException("proxy is null");
|
if (proxy == null) throw new IllegalArgumentException("proxy is null");
|
||||||
maybeInitHttpClient();
|
maybeInitHttpClient();
|
||||||
String protocol = url.getProtocol();
|
String protocol = url.getProtocol();
|
||||||
OkHttpClient client;
|
OkUrlFactory okUrlFactory;
|
||||||
// TODO: HttpHandler creates OkHttpClients that share the default ResponseCache.
|
// TODO: HttpHandler creates OkUrlFactory instances that share the default ResponseCache.
|
||||||
// Could this cause unexpected behavior?
|
// Could this cause unexpected behavior?
|
||||||
if (protocol.equals("http")) {
|
if (protocol.equals("http")) {
|
||||||
client = HttpHandler.createHttpOkHttpClient(proxy);
|
okUrlFactory = HttpHandler.createHttpOkUrlFactory(proxy);
|
||||||
} else if (protocol.equals("https")) {
|
} else if (protocol.equals("https")) {
|
||||||
client = HttpsHandler.createHttpsOkHttpClient(proxy);
|
okUrlFactory = HttpsHandler.createHttpsOkUrlFactory(proxy);
|
||||||
} else {
|
} else {
|
||||||
// OkHttpClient only supports HTTP and HTTPS and returns a null URLStreamHandler if
|
// OkHttp only supports HTTP and HTTPS and returns a null URLStreamHandler if
|
||||||
// passed another protocol.
|
// passed another protocol.
|
||||||
throw new MalformedURLException("Invalid URL or unrecognized protocol " + protocol);
|
throw new MalformedURLException("Invalid URL or unrecognized protocol " + protocol);
|
||||||
}
|
}
|
||||||
return client.setSocketFactory(getSocketFactory())
|
OkHttpClient client = okUrlFactory.client();
|
||||||
.setHostResolver(mHostResolver)
|
client.setSocketFactory(getSocketFactory()).setConnectionPool(mConnectionPool);
|
||||||
.setConnectionPool(mConnectionPool)
|
|
||||||
.open(url);
|
// Use internal APIs to change the Network.
|
||||||
|
Internal.instance.setNetwork(client, mNetwork);
|
||||||
|
|
||||||
|
return okUrlFactory.open(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user