Use return values from JNI functions binding sockets and processes to networks.
bug:15757549 Change-Id: If23b14febc923b9a0348f0cf9029fd4bf6e8d725
This commit is contained in:
parent
824fc15bab
commit
e25e76c300
3 changed files with 32 additions and 30 deletions
|
|
@ -2372,12 +2372,10 @@ public class ConnectivityManager {
|
|||
*/
|
||||
public static boolean setProcessDefaultNetwork(Network network) {
|
||||
if (network == null) {
|
||||
NetworkUtils.unbindProcessToNetwork();
|
||||
return NetworkUtils.unbindProcessToNetwork();
|
||||
} else {
|
||||
NetworkUtils.bindProcessToNetwork(network.netId);
|
||||
return NetworkUtils.bindProcessToNetwork(network.netId);
|
||||
}
|
||||
// TODO fix return value
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -2404,11 +2402,9 @@ public class ConnectivityManager {
|
|||
*/
|
||||
public static boolean setProcessDefaultNetworkForHostResolution(Network network) {
|
||||
if (network == null) {
|
||||
NetworkUtils.unbindProcessToNetworkForHostResolution();
|
||||
return NetworkUtils.unbindProcessToNetworkForHostResolution();
|
||||
} else {
|
||||
NetworkUtils.bindProcessToNetworkForHostResolution(network.netId);
|
||||
return NetworkUtils.bindProcessToNetworkForHostResolution(network.netId);
|
||||
}
|
||||
// TODO hook up the return value.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.io.IOException;
|
|||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
|
|
@ -148,7 +149,9 @@ public class Network implements Parcelable {
|
|||
// Query a property of the underlying socket to ensure the underlying
|
||||
// socket exists so a file descriptor is available to bind to a network.
|
||||
socket.getReuseAddress();
|
||||
NetworkUtils.bindSocketToNetwork(socket.getFileDescriptor$().getInt$(), mNetId);
|
||||
if (!NetworkUtils.bindSocketToNetwork(socket.getFileDescriptor$().getInt$(), mNetId)) {
|
||||
throw new SocketException("Failed to bind socket to network.");
|
||||
}
|
||||
return socket;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,13 +118,13 @@ public class NetworkUtils {
|
|||
* is by design so an application doesn't accidentally use sockets it thinks are still bound to
|
||||
* a particular {@code Network}.
|
||||
*/
|
||||
public native static void bindProcessToNetwork(int netId);
|
||||
public native static boolean bindProcessToNetwork(int netId);
|
||||
|
||||
/**
|
||||
* Clear any process specific {@code Network} binding. This reverts a call to
|
||||
* {@link #bindProcessToNetwork}.
|
||||
*/
|
||||
public native static void unbindProcessToNetwork();
|
||||
public native static boolean unbindProcessToNetwork();
|
||||
|
||||
/**
|
||||
* Return the netId last passed to {@link #bindProcessToNetwork}, or NETID_UNSET if
|
||||
|
|
@ -138,7 +138,7 @@ public class NetworkUtils {
|
|||
*
|
||||
* @deprecated This is strictly for legacy usage to support startUsingNetworkFeature().
|
||||
*/
|
||||
public native static void bindProcessToNetworkForHostResolution(int netId);
|
||||
public native static boolean bindProcessToNetworkForHostResolution(int netId);
|
||||
|
||||
/**
|
||||
* Clears any process specific {@link Network} binding for host resolution. This does
|
||||
|
|
@ -146,13 +146,13 @@ public class NetworkUtils {
|
|||
*
|
||||
* @deprecated This is strictly for legacy usage to support startUsingNetworkFeature().
|
||||
*/
|
||||
public native static void unbindProcessToNetworkForHostResolution();
|
||||
public native static boolean unbindProcessToNetworkForHostResolution();
|
||||
|
||||
/**
|
||||
* Explicitly binds {@code socketfd} to the network designated by {@code netId}. This
|
||||
* overrides any binding via {@link #bindProcessToNetwork}.
|
||||
*/
|
||||
public native static void bindSocketToNetwork(int socketfd, int netId);
|
||||
public native static boolean bindSocketToNetwork(int socketfd, int netId);
|
||||
|
||||
/**
|
||||
* Convert a IPv4 address from an integer to an InetAddress.
|
||||
|
|
|
|||
Loading…
Reference in a new issue