diff options
| author | Paul Jensen <pauljensen@google.com> | 2014-05-29 10:12:39 -0400 |
|---|---|---|
| committer | Robert Greenwalt <rgreenwalt@google.com> | 2014-06-08 12:09:18 -0700 |
| commit | 6d3ff9ea3a542a18ca5da055418a7b9eff130d93 (patch) | |
| tree | 9c28ef98c047a87732b775e297f997e21fbf9359 /core/java/android/net/ConnectivityManager.java | |
| parent | 915c8d58414cb9c2dd97459cacf9eefbe22267a1 (diff) | |
| download | frameworks_base-6d3ff9ea3a542a18ca5da055418a7b9eff130d93.zip frameworks_base-6d3ff9ea3a542a18ca5da055418a7b9eff130d93.tar.gz frameworks_base-6d3ff9ea3a542a18ca5da055418a7b9eff130d93.tar.bz2 | |
Apply API review to android.net.Network:
- socketFactory() renamed to getSocketFactory()
- Make sure bindProcess() documentation points developers to getSocketFactory() as the preferred approach
- Move bindProcess() and unbindProcess() to ConnectivityManager.setProcessBoundNetwork() -- passing null clears it.
- Move getProcessBoundNetwork() to ConnectivityManager.getProcessBoundNetwork().
Bug:15142362
Bug:13885501
Change-Id: Ia55c59d52e1ec8bf10dd0d9d037bd04c0998bc71
Diffstat (limited to 'core/java/android/net/ConnectivityManager.java')
| -rw-r--r-- | core/java/android/net/ConnectivityManager.java | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 59732ee..27402668 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -22,6 +22,7 @@ import android.annotation.SdkConstant.SdkConstantType; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.net.NetworkUtils; import android.os.Binder; import android.os.Build.VERSION_CODES; import android.os.Handler; @@ -982,13 +983,13 @@ public class ConnectivityManager { public void onAvailable(NetworkRequest request, Network network) { currentNetwork = network; Log.d(TAG, "startUsingNetworkFeature got Network:" + network); - network.bindProcessForHostResolution(); + setProcessDefaultNetworkForHostResolution(network); } @Override public void onLost(NetworkRequest request, Network network) { if (network.equals(currentNetwork)) { currentNetwork = null; - network.unbindProcessForHostResolution(); + setProcessDefaultNetworkForHostResolution(null); } Log.d(TAG, "startUsingNetworkFeature lost Network:" + network); } @@ -1072,7 +1073,7 @@ public class ConnectivityManager { * @return {@code true} on success, {@code false} on failure * * @deprecated Deprecated in favor of the {@link #requestNetwork}, - * {@link Network#bindProcess} and {@link Network#socketFactory} api. + * {@link #setProcessDefaultNetwork} and {@link Network#getSocketFactory} api. */ public boolean requestRouteToHost(int networkType, int hostAddress) { InetAddress inetAddress = NetworkUtils.intToInetAddress(hostAddress); @@ -1096,7 +1097,7 @@ public class ConnectivityManager { * @return {@code true} on success, {@code false} on failure * @hide * @deprecated Deprecated in favor of the {@link #requestNetwork} and - * {@link Network#bindProcess} api. + * {@link #setProcessDefaultNetwork} api. */ public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) { byte[] address = hostAddress.getAddress(); @@ -2348,4 +2349,64 @@ public class ConnectivityManager { mService.releaseNetworkRequest(networkRequest); } catch (RemoteException e) {} } + + /** + * Binds the current process to {@code network}. All Sockets created in the future + * (and not explicitly bound via a bound SocketFactory from + * {@link Network#getSocketFactory() Network.getSocketFactory()}) will be bound to + * {@code network}. All host name resolutions will be limited to {@code network} as well. + * Note that if {@code network} ever disconnects, all Sockets created in this way will cease to + * work and all host name resolutions will fail. This is by design so an application doesn't + * accidentally use Sockets it thinks are still bound to a particular {@link Network}. + * To clear binding pass {@code null} for {@code network}. Using individually bound + * Sockets created by Network.getSocketFactory().createSocket() and + * performing network-specific host name resolutions via + * {@link Network#getAllByName Network.getAllByName} is preferred to calling + * {@code setProcessDefaultNetwork}. + * + * @param network The {@link Network} to bind the current process to, or {@code null} to clear + * the current binding. + * @return {@code true} on success, {@code false} if the {@link Network} is no longer valid. + */ + public static boolean setProcessDefaultNetwork(Network network) { + if (network == null) { + NetworkUtils.unbindProcessToNetwork(); + } else { + NetworkUtils.bindProcessToNetwork(network.netId); + } + // TODO fix return value + return true; + } + + /** + * Returns the {@link Network} currently bound to this process via + * {@link #setProcessDefaultNetwork}, or {@code null} if no {@link Network} is explicitly bound. + * + * @return {@code Network} to which this process is bound, or {@code null}. + */ + public static Network getProcessDefaultNetwork() { + int netId = NetworkUtils.getNetworkBoundToProcess(); + if (netId == 0) return null; + return new Network(netId); + } + + /** + * Binds host resolutions performed by this process to {@code network}. + * {@link #setProcessDefaultNetwork} takes precedence over this setting. + * + * @param network The {@link Network} to bind host resolutions from the current process to, or + * {@code null} to clear the current binding. + * @return {@code true} on success, {@code false} if the {@link Network} is no longer valid. + * @hide + * @deprecated This is strictly for legacy usage to support {@link #startUsingNetworkFeature}. + */ + public static boolean setProcessDefaultNetworkForHostResolution(Network network) { + if (network == null) { + NetworkUtils.unbindProcessToNetworkForHostResolution(); + } else { + NetworkUtils.bindProcessToNetworkForHostResolution(network.netId); + } + // TODO hook up the return value. + return true; + } } |
