diff options
| author | Lorenzo Colitti <lorenzo@google.com> | 2016-09-12 13:30:19 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-09-12 13:30:21 +0000 |
| commit | d6feb6038311dda746b74ce237c9e1cc56151250 (patch) | |
| tree | 947cb44f8403b9dfd3733449b918c1e47b6124cd /core/java | |
| parent | 6708b64797660067f9bb50f09806746d4f590e71 (diff) | |
| parent | 3d4a10617c6d967aa0f07e129264e07320e99073 (diff) | |
Merge changes I40f73526,Ia08900c5 into nyc-mr1-dev
* changes:
Add a background NetworkRequest type for mobile data always on.
Rematch requests first and listens second.
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/net/NetworkRequest.java | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/core/java/android/net/NetworkRequest.java b/core/java/android/net/NetworkRequest.java index 4501f7b089b9..ae724709c6c6 100644 --- a/core/java/android/net/NetworkRequest.java +++ b/core/java/android/net/NetworkRequest.java @@ -49,7 +49,7 @@ public class NetworkRequest implements Parcelable { public final int legacyType; /** - * A NetworkRequest as used by the system can be one of three types: + * A NetworkRequest as used by the system can be one of the following types: * * - LISTEN, for which the framework will issue callbacks about any * and all networks that match the specified NetworkCapabilities, @@ -64,7 +64,20 @@ public class NetworkRequest implements Parcelable { * current network (if any) that matches the capabilities of the * default Internet request (mDefaultRequest), but which cannot cause * the framework to either create or retain the existence of any - * specific network. + * specific network. Note that from the point of view of the request + * matching code, TRACK_DEFAULT is identical to REQUEST: its special + * behaviour is not due to different semantics, but to the fact that + * the system will only ever create a TRACK_DEFAULT with capabilities + * that are identical to the default request's capabilities, thus + * causing it to share fate in every way with the default request. + * + * - BACKGROUND_REQUEST, like REQUEST but does not cause any networks + * to retain the NET_CAPABILITY_FOREGROUND capability. A network with + * no foreground requests is in the background. A network that has + * one or more background requests and loses its last foreground + * request to a higher-scoring network will not go into the + * background immediately, but will linger and go into the background + * after the linger timeout. * * - The value NONE is used only by applications. When an application * creates a NetworkRequest, it does not have a type; the type is set @@ -77,7 +90,8 @@ public class NetworkRequest implements Parcelable { NONE, LISTEN, TRACK_DEFAULT, - REQUEST + REQUEST, + BACKGROUND_REQUEST, }; /** @@ -140,7 +154,7 @@ public class NetworkRequest implements Parcelable { * Add the given capability requirement to this builder. These represent * the requested network's required capabilities. Note that when searching * for a network to satisfy a request, all capabilities requested must be - * satisfied. See {@link NetworkCapabilities} for {@code NET_CAPABILITIY_*} + * satisfied. See {@link NetworkCapabilities} for {@code NET_CAPABILITY_*} * definitions. * * @param capability The {@code NetworkCapabilities.NET_CAPABILITY_*} to add. @@ -284,7 +298,7 @@ public class NetworkRequest implements Parcelable { }; /** - * Returns true iff. the contained NetworkRequest is of type LISTEN. + * Returns true iff. this NetworkRequest is of type LISTEN. * * @hide */ @@ -298,8 +312,9 @@ public class NetworkRequest implements Parcelable { * - should be associated with at most one satisfying network * at a time; * - * - should cause a network to be kept up if it is the best network - * which can satisfy the NetworkRequest. + * - should cause a network to be kept up, but not necessarily in + * the foreground, if it is the best network which can satisfy the + * NetworkRequest. * * For full detail of how isRequest() is used for pairing Networks with * NetworkRequests read rematchNetworkAndRequests(). @@ -307,9 +322,36 @@ public class NetworkRequest implements Parcelable { * @hide */ public boolean isRequest() { + return isForegroundRequest() || isBackgroundRequest(); + } + + /** + * Returns true iff. the contained NetworkRequest is one that: + * + * - should be associated with at most one satisfying network + * at a time; + * + * - should cause a network to be kept up and in the foreground if + * it is the best network which can satisfy the NetworkRequest. + * + * For full detail of how isRequest() is used for pairing Networks with + * NetworkRequests read rematchNetworkAndRequests(). + * + * @hide + */ + public boolean isForegroundRequest() { return type == Type.TRACK_DEFAULT || type == Type.REQUEST; } + /** + * Returns true iff. this NetworkRequest is of type BACKGROUND_REQUEST. + * + * @hide + */ + public boolean isBackgroundRequest() { + return type == Type.BACKGROUND_REQUEST; + } + public String toString() { return "NetworkRequest [ " + type + " id=" + requestId + (legacyType != ConnectivityManager.TYPE_NONE ? ", legacyType=" + legacyType : "") + |
