Methods Summary |
---|
public void | bindSocket(java.net.Socket socket)Binds the specified {@link Socket} to this {@code Network}. All data traffic on the socket
will be sent on this {@code Network}, irrespective of any process-wide network binding set by
{@link ConnectivityManager#setProcessDefaultNetwork}. The socket must not be connected.
// Apparently, the kernel doesn't update a connected TCP socket's routing upon mark changes.
if (socket.isConnected()) {
throw new SocketException("Socket is connected");
}
// Query a property of the underlying socket to ensure that the socket's file descriptor
// exists, is available to bind to a network and is not closed.
socket.getReuseAddress();
bindSocketFd(socket.getFileDescriptor$());
|
public void | bindSocket(java.net.DatagramSocket socket)Binds the specified {@link DatagramSocket} to this {@code Network}. All data traffic on the
socket will be sent on this {@code Network}, irrespective of any process-wide network binding
set by {@link ConnectivityManager#setProcessDefaultNetwork}. The socket must not be
connected.
// Apparently, the kernel doesn't update a connected UDP socket's routing upon mark changes.
if (socket.isConnected()) {
throw new SocketException("Socket is connected");
}
// Query a property of the underlying socket to ensure that the socket's file descriptor
// exists, is available to bind to a network and is not closed.
socket.getReuseAddress();
bindSocketFd(socket.getFileDescriptor$());
|
private void | bindSocketFd(java.io.FileDescriptor fd)
int err = NetworkUtils.bindSocketToNetwork(fd.getInt$(), netId);
if (err != 0) {
// bindSocketToNetwork returns negative errno.
throw new ErrnoException("Binding socket to network " + netId, -err)
.rethrowAsSocketException();
}
|
public int | describeContents()
return 0;
|
public boolean | equals(java.lang.Object obj)
if (obj instanceof Network == false) return false;
Network other = (Network)obj;
return this.netId == other.netId;
|
public java.net.InetAddress[] | getAllByName(java.lang.String host)Operates the same as {@code InetAddress.getAllByName} except that host
resolution is done on this network.
return InetAddress.getAllByNameOnNet(host, netId);
|
public java.net.InetAddress | getByName(java.lang.String host)Operates the same as {@code InetAddress.getByName} except that host
resolution is done on this network.
return InetAddress.getByNameOnNet(host, netId);
|
public javax.net.SocketFactory | getSocketFactory()Returns a {@link SocketFactory} bound to this network. Any {@link Socket} created by
this factory will have its traffic sent over this {@code Network}. Note that if this
{@code Network} ever disconnects, this factory and any {@link Socket} it produced in the
past or future will cease to work.
if (mNetworkBoundSocketFactory == null) {
synchronized (mLock) {
if (mNetworkBoundSocketFactory == null) {
mNetworkBoundSocketFactory = new NetworkBoundSocketFactory(netId);
}
}
}
return mNetworkBoundSocketFactory;
|
public int | hashCode()
return netId * 11;
|
private void | maybeInitHttpClient()
synchronized (mLock) {
if (mHostResolver == null) {
mHostResolver = new HostResolver() {
@Override
public InetAddress[] getAllByName(String host) throws UnknownHostException {
return Network.this.getAllByName(host);
}
};
}
if (mConnectionPool == null) {
mConnectionPool = new ConnectionPool(httpMaxConnections,
httpKeepAliveDurationMs);
}
}
|
public java.net.URLConnection | openConnection(java.net.URL url)Opens the specified {@link URL} on this {@code Network}, such that all traffic will be sent
on this Network. The URL protocol must be {@code HTTP} or {@code HTTPS}.
final ConnectivityManager cm = ConnectivityManager.getInstance();
// TODO: Should this be optimized to avoid fetching the global proxy for every request?
ProxyInfo proxyInfo = cm.getGlobalProxy();
if (proxyInfo == null) {
// TODO: Should this be optimized to avoid fetching LinkProperties for every request?
final LinkProperties lp = cm.getLinkProperties(this);
if (lp != null) proxyInfo = lp.getHttpProxy();
}
java.net.Proxy proxy = null;
if (proxyInfo != null) {
proxy = proxyInfo.makeProxy();
} else {
proxy = java.net.Proxy.NO_PROXY;
}
return openConnection(url, proxy);
|
public java.net.URLConnection | openConnection(java.net.URL url, java.net.Proxy proxy)Opens the specified {@link URL} on this {@code Network}, such that all traffic will be sent
on this Network. The URL protocol must be {@code HTTP} or {@code HTTPS}.
if (proxy == null) throw new IllegalArgumentException("proxy is null");
maybeInitHttpClient();
String protocol = url.getProtocol();
OkHttpClient client;
// TODO: HttpHandler creates OkHttpClients that share the default ResponseCache.
// Could this cause unexpected behavior?
if (protocol.equals("http")) {
client = HttpHandler.createHttpOkHttpClient(proxy);
} else if (protocol.equals("https")) {
client = HttpsHandler.createHttpsOkHttpClient(proxy);
} else {
// OkHttpClient only supports HTTP and HTTPS and returns a null URLStreamHandler if
// passed another protocol.
throw new MalformedURLException("Invalid URL or unrecognized protocol " + protocol);
}
return client.setSocketFactory(getSocketFactory())
.setHostResolver(mHostResolver)
.setConnectionPool(mConnectionPool)
.open(url);
|
public java.lang.String | toString()
return Integer.toString(netId);
|
public void | writeToParcel(android.os.Parcel dest, int flags)
dest.writeInt(netId);
|