diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2015-05-01 03:45:12 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-01 03:45:14 +0000 |
commit | b57f236e30d87bdfa69bb99e6b3f5ec6a3cc07c7 (patch) | |
tree | 3ba6063b4483f72838d855cd13de420183dfd0e0 | |
parent | f12071222fcf7c762bb8d28800ae693ec58347f4 (diff) | |
parent | f7058f5d1d9df1c5c49b06d8693a49e36ce358ca (diff) | |
download | frameworks_base-b57f236e30d87bdfa69bb99e6b3f5ec6a3cc07c7.zip frameworks_base-b57f236e30d87bdfa69bb99e6b3f5ec6a3cc07c7.tar.gz frameworks_base-b57f236e30d87bdfa69bb99e6b3f5ec6a3cc07c7.tar.bz2 |
Merge changes Icf7d67e2,Ia914ec88,I2490ad75,Ie79f2d28 into mnc-dev
* changes:
Add a hidden method to clear NetworkCapabilities.
Fix javadoc error for requestNetwork.
Simplify network callback handling code.
Document and unhide CALLBACK_PRECHECK.
-rw-r--r-- | api/current.txt | 1 | ||||
-rw-r--r-- | api/system-current.txt | 1 | ||||
-rw-r--r-- | core/java/android/net/ConnectivityManager.java | 145 | ||||
-rw-r--r-- | core/java/android/net/NetworkCapabilities.java | 19 |
4 files changed, 84 insertions, 82 deletions
diff --git a/api/current.txt b/api/current.txt index b41493a..88b219c 100644 --- a/api/current.txt +++ b/api/current.txt @@ -18438,6 +18438,7 @@ package android.net { method public void onLinkPropertiesChanged(android.net.Network, android.net.LinkProperties); method public void onLosing(android.net.Network, int); method public void onLost(android.net.Network); + method public void onPreCheck(android.net.Network); } public static abstract interface ConnectivityManager.OnNetworkActiveListener { diff --git a/api/system-current.txt b/api/system-current.txt index 09411db..9b7d15c 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -19906,6 +19906,7 @@ package android.net { method public void onLinkPropertiesChanged(android.net.Network, android.net.LinkProperties); method public void onLosing(android.net.Network, int); method public void onLost(android.net.Network); + method public void onPreCheck(android.net.Network); } public static abstract interface ConnectivityManager.OnNetworkActiveListener { diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index c531e7e..2d63e3f 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -341,7 +341,8 @@ public class ConnectivityManager { * one. This is used by applications needing to talk to the carrier's * Multimedia Messaging Service servers. * - * @deprecated Applications should instead use {@link #requestNetwork} to request a network that + * @deprecated Applications should instead use + * {@link #requestNetwork(NetworkRequest, NetworkCallback)} to request a network that * provides the {@link NetworkCapabilities#NET_CAPABILITY_MMS} capability. */ public static final int TYPE_MOBILE_MMS = 2; @@ -351,7 +352,8 @@ public class ConnectivityManager { * one. This is used by applications needing to talk to the carrier's * Secure User Plane Location servers for help locating the device. * - * @deprecated Applications should instead use {@link #requestNetwork} to request a network that + * @deprecated Applications should instead use + * {@link #requestNetwork(NetworkRequest, NetworkCallback)} to request a network that * provides the {@link NetworkCapabilities#NET_CAPABILITY_SUPL} capability. */ public static final int TYPE_MOBILE_SUPL = 3; @@ -367,7 +369,8 @@ public class ConnectivityManager { * same network interface as {@link #TYPE_MOBILE} but the routing setup * is different. * - * @deprecated Applications should instead use {@link #requestNetwork} to request a network that + * @deprecated Applications should instead use + * {@link #requestNetwork(NetworkRequest, NetworkCallback)} to request a network that * uses the {@link NetworkCapabilities#TRANSPORT_CELLULAR} transport. */ public static final int TYPE_MOBILE_HIPRI = 5; @@ -910,7 +913,8 @@ public class ConnectivityManager { * implementation+feature combination, except that the value {@code -1} * always indicates failure. * - * @deprecated Deprecated in favor of the cleaner {@link #requestNetwork} api. + * @deprecated Deprecated in favor of the cleaner + * {@link #requestNetwork(NetworkRequest, NetworkCallback)} API. * @removed */ public int startUsingNetworkFeature(int networkType, String feature) { @@ -958,7 +962,7 @@ public class ConnectivityManager { * implementation+feature combination, except that the value {@code -1} * always indicates failure. * - * @deprecated Deprecated in favor of the cleaner {@link #requestNetwork} api. + * @deprecated Deprecated in favor of the cleaner {@link unregisterNetworkCallback} API. * @removed */ public int stopUsingNetworkFeature(int networkType, String feature) { @@ -1236,8 +1240,9 @@ public class ConnectivityManager { * @param hostAddress the IP address of the host to which the route is desired * @return {@code true} on success, {@code false} on failure * - * @deprecated Deprecated in favor of the {@link #requestNetwork}, - * {@link #bindProcessToNetwork} and {@link Network#getSocketFactory} api. + * @deprecated Deprecated in favor of the + * {@link #requestNetwork(NetworkRequest, NetworkCallback)}, + * {@link #bindProcessToNetwork} and {@link Network#getSocketFactory} API. * @removed */ public boolean requestRouteToHost(int networkType, int hostAddress) { @@ -1256,7 +1261,7 @@ public class ConnectivityManager { * @return {@code true} on success, {@code false} on failure * @hide * @deprecated Deprecated in favor of the {@link #requestNetwork} and - * {@link #bindProcessToNetwork} api. + * {@link #bindProcessToNetwork} API. * @removed */ public boolean requestRouteToHostAddress(int networkType, InetAddress hostAddress) { @@ -2144,14 +2149,22 @@ public class ConnectivityManager { public static final int CANCELED = 8; /** - * @hide - * Called whenever the framework connects to a network that it may use to - * satisfy this request + * Called when the framework connects to a new network to evaluate whether it satisfies this + * request. If evaluation succeeds, this callback may be followed by an {@link #onAvailable} + * callback. There is no guarantee that this new network will satisfy any requests, or that + * the network will stay connected for longer than the time necessary to evaluate it. + * <p> + * Most applications <b>should not</b> act on this callback, and should instead use + * {@link #onAvailable}. This callback is intended for use by applications that can assist + * the framework in properly evaluating the network — for example, an application that + * can automatically log in to a captive portal without user intervention. + * + * @param network The {@link Network} of the network that is being evaluated. */ public void onPreCheck(Network network) {} /** - * Called when the framework connects and has declared new network ready for use. + * Called when the framework connects and has declared a new network ready for use. * This callback may be called more than once if the {@link Network} that is * satisfying the request changes. * @@ -2251,116 +2264,82 @@ public class ConnectivityManager { @Override public void handleMessage(Message message) { Log.d(TAG, "CM callback handler got msg " + message.what); + NetworkRequest request = (NetworkRequest) getObject(message, NetworkRequest.class); + Network network = (Network) getObject(message, Network.class); switch (message.what) { case CALLBACK_PRECHECK: { - NetworkRequest request = (NetworkRequest)getObject(message, - NetworkRequest.class); - NetworkCallback callbacks = getCallbacks(request); - if (callbacks != null) { - callbacks.onPreCheck((Network)getObject(message, Network.class)); - } else { - Log.e(TAG, "callback not found for PRECHECK message"); + NetworkCallback callback = getCallback(request, "PRECHECK"); + if (callback != null) { + callback.onPreCheck(network); } break; } case CALLBACK_AVAILABLE: { - NetworkRequest request = (NetworkRequest)getObject(message, - NetworkRequest.class); - NetworkCallback callbacks = getCallbacks(request); - if (callbacks != null) { - callbacks.onAvailable((Network)getObject(message, Network.class)); - } else { - Log.e(TAG, "callback not found for AVAILABLE message"); + NetworkCallback callback = getCallback(request, "AVAILABLE"); + if (callback != null) { + callback.onAvailable(network); } break; } case CALLBACK_LOSING: { - NetworkRequest request = (NetworkRequest)getObject(message, - NetworkRequest.class); - NetworkCallback callbacks = getCallbacks(request); - if (callbacks != null) { - callbacks.onLosing((Network)getObject(message, Network.class), - message.arg1); - } else { - Log.e(TAG, "callback not found for LOSING message"); + NetworkCallback callback = getCallback(request, "LOSING"); + if (callback != null) { + callback.onLosing(network, message.arg1); } break; } case CALLBACK_LOST: { - NetworkRequest request = (NetworkRequest)getObject(message, - NetworkRequest.class); - - NetworkCallback callbacks = getCallbacks(request); - if (callbacks != null) { - callbacks.onLost((Network)getObject(message, Network.class)); - } else { - Log.e(TAG, "callback not found for LOST message"); + NetworkCallback callback = getCallback(request, "LOST"); + if (callback != null) { + callback.onLost(network); } break; } case CALLBACK_UNAVAIL: { - NetworkRequest request = (NetworkRequest)getObject(message, - NetworkRequest.class); - NetworkCallback callbacks = null; - synchronized(mCallbackMap) { - callbacks = mCallbackMap.get(request); - } - if (callbacks != null) { - callbacks.onUnavailable(); - } else { - Log.e(TAG, "callback not found for UNAVAIL message"); + NetworkCallback callback = getCallback(request, "UNAVAIL"); + if (callback != null) { + callback.onUnavailable(); } break; } case CALLBACK_CAP_CHANGED: { - NetworkRequest request = (NetworkRequest)getObject(message, - NetworkRequest.class); - NetworkCallback callbacks = getCallbacks(request); - if (callbacks != null) { - Network network = (Network)getObject(message, Network.class); + NetworkCallback callback = getCallback(request, "CAP_CHANGED"); + if (callback != null) { NetworkCapabilities cap = (NetworkCapabilities)getObject(message, NetworkCapabilities.class); - callbacks.onCapabilitiesChanged(network, cap); - } else { - Log.e(TAG, "callback not found for CAP_CHANGED message"); + callback.onCapabilitiesChanged(network, cap); } break; } case CALLBACK_IP_CHANGED: { - NetworkRequest request = (NetworkRequest)getObject(message, - NetworkRequest.class); - NetworkCallback callbacks = getCallbacks(request); - if (callbacks != null) { - Network network = (Network)getObject(message, Network.class); + NetworkCallback callback = getCallback(request, "IP_CHANGED"); + if (callback != null) { LinkProperties lp = (LinkProperties)getObject(message, LinkProperties.class); - callbacks.onLinkPropertiesChanged(network, lp); - } else { - Log.e(TAG, "callback not found for IP_CHANGED message"); + callback.onLinkPropertiesChanged(network, lp); } break; } case CALLBACK_RELEASED: { - NetworkRequest req = (NetworkRequest)getObject(message, NetworkRequest.class); - NetworkCallback callbacks = null; + NetworkCallback callback = null; synchronized(mCallbackMap) { - callbacks = mCallbackMap.remove(req); + callback = mCallbackMap.remove(request); } - if (callbacks != null) { + if (callback != null) { synchronized(mRefCount) { if (mRefCount.decrementAndGet() == 0) { getLooper().quit(); } } } else { - Log.e(TAG, "callback not found for CANCELED message"); + Log.e(TAG, "callback not found for RELEASED message"); } break; } case CALLBACK_EXIT: { - Log.d(TAG, "Listener quiting"); + Log.d(TAG, "Listener quitting"); getLooper().quit(); break; } @@ -2374,10 +2353,16 @@ public class ConnectivityManager { private Object getObject(Message msg, Class c) { return msg.getData().getParcelable(c.getSimpleName()); } - private NetworkCallback getCallbacks(NetworkRequest req) { + + private NetworkCallback getCallback(NetworkRequest req, String name) { + NetworkCallback callback; synchronized(mCallbackMap) { - return mCallbackMap.get(req); + callback = mCallbackMap.get(req); + } + if (callback == null) { + Log.e(TAG, "callback not found for " + name + " message"); } + return callback; } } @@ -2601,10 +2586,10 @@ public class ConnectivityManager { /** * Unregisters callbacks about and possibly releases networks originating from - * {@link #requestNetwork} and {@link #registerNetworkCallback} calls. If the - * given {@code NetworkCallback} had previously been used with {@code #requestNetwork}, - * any networks that had been connected to only to satisfy that request will be - * disconnected. + * {@link #requestNetwork(NetworkRequest, NetworkCallback)} and {@link #registerNetworkCallback} + * calls. If the given {@code NetworkCallback} had previously been used with + * {@code #requestNetwork}, any networks that had been connected to only to satisfy that request + * will be disconnected. * * @param networkCallback The {@link NetworkCallback} used when making the request. */ diff --git a/core/java/android/net/NetworkCapabilities.java b/core/java/android/net/NetworkCapabilities.java index 8c8bfab..ab70485 100644 --- a/core/java/android/net/NetworkCapabilities.java +++ b/core/java/android/net/NetworkCapabilities.java @@ -37,6 +37,11 @@ public final class NetworkCapabilities implements Parcelable { * @hide */ public NetworkCapabilities() { + clearAll(); + mNetworkCapabilities = + (1 << NET_CAPABILITY_NOT_RESTRICTED) | + (1 << NET_CAPABILITY_TRUSTED) | + (1 << NET_CAPABILITY_NOT_VPN); } public NetworkCapabilities(NetworkCapabilities nc) { @@ -50,11 +55,21 @@ public final class NetworkCapabilities implements Parcelable { } /** + * Completely clears the contents of this object, removing even the capabilities that are set + * by default when the object is constructed. + * @hide + */ + public void clearAll() { + mNetworkCapabilities = mTransportTypes = 0; + mLinkUpBandwidthKbps = mLinkDownBandwidthKbps = 0; + mNetworkSpecifier = null; + } + + /** * Represents the network's capabilities. If any are specified they will be satisfied * by any Network that matches all of them. */ - private long mNetworkCapabilities = (1 << NET_CAPABILITY_NOT_RESTRICTED) | - (1 << NET_CAPABILITY_TRUSTED) | (1 << NET_CAPABILITY_NOT_VPN); + private long mNetworkCapabilities; /** * Indicates this is a network that has the ability to reach the |