Merge changes from topic 'networkrequest_private' into nyc-mr1-dev
* changes: Make the NetworkRequest list private to NetworkAgentInfo. Move the request type from NetworkRequestInfo to NetworkRequest.
This commit is contained in:
committed by
Android (Google) Code Review
commit
0317e03dc3
@@ -47,15 +47,55 @@ public class NetworkRequest implements Parcelable {
|
||||
public final int legacyType;
|
||||
|
||||
/**
|
||||
* A NetworkRequest as used by the system can be one of three types:
|
||||
*
|
||||
* - LISTEN, for which the framework will issue callbacks about any
|
||||
* and all networks that match the specified NetworkCapabilities,
|
||||
*
|
||||
* - REQUEST, capable of causing a specific network to be created
|
||||
* first (e.g. a telephony DUN request), the framework will issue
|
||||
* callbacks about the single, highest scoring current network
|
||||
* (if any) that matches the specified NetworkCapabilities, or
|
||||
*
|
||||
* - TRACK_DEFAULT, a hybrid of the two designed such that the
|
||||
* framework will issue callbacks for the single, highest scoring
|
||||
* 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.
|
||||
*
|
||||
* - The value NONE is used only by applications. When an application
|
||||
* creates a NetworkRequest, it does not have a type; the type is set
|
||||
* by the system depending on the method used to file the request
|
||||
* (requestNetwork, registerNetworkCallback, etc.).
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public NetworkRequest(NetworkCapabilities nc, int legacyType, int rId) {
|
||||
public static enum Type {
|
||||
NONE,
|
||||
LISTEN,
|
||||
TRACK_DEFAULT,
|
||||
REQUEST
|
||||
};
|
||||
|
||||
/**
|
||||
* The type of the request. This is only used by the system and is always NONE elsewhere.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public final Type type;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public NetworkRequest(NetworkCapabilities nc, int legacyType, int rId, Type type) {
|
||||
if (nc == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
requestId = rId;
|
||||
networkCapabilities = nc;
|
||||
this.legacyType = legacyType;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,6 +105,7 @@ public class NetworkRequest implements Parcelable {
|
||||
networkCapabilities = new NetworkCapabilities(that.networkCapabilities);
|
||||
requestId = that.requestId;
|
||||
this.legacyType = that.legacyType;
|
||||
this.type = that.type;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +131,7 @@ public class NetworkRequest implements Parcelable {
|
||||
final NetworkCapabilities nc = new NetworkCapabilities(mNetworkCapabilities);
|
||||
nc.maybeMarkCapabilitiesRestricted();
|
||||
return new NetworkRequest(nc, ConnectivityManager.TYPE_NONE,
|
||||
ConnectivityManager.REQUEST_ID_UNSET);
|
||||
ConnectivityManager.REQUEST_ID_UNSET, Type.NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,6 +264,7 @@ public class NetworkRequest implements Parcelable {
|
||||
dest.writeParcelable(networkCapabilities, flags);
|
||||
dest.writeInt(legacyType);
|
||||
dest.writeInt(requestId);
|
||||
// type intentionally not preserved across process boundaries.
|
||||
}
|
||||
public static final Creator<NetworkRequest> CREATOR =
|
||||
new Creator<NetworkRequest>() {
|
||||
@@ -230,7 +272,8 @@ public class NetworkRequest implements Parcelable {
|
||||
NetworkCapabilities nc = (NetworkCapabilities)in.readParcelable(null);
|
||||
int legacyType = in.readInt();
|
||||
int requestId = in.readInt();
|
||||
NetworkRequest result = new NetworkRequest(nc, legacyType, requestId);
|
||||
// type intentionally not preserved across process boundaries.
|
||||
NetworkRequest result = new NetworkRequest(nc, legacyType, requestId, Type.NONE);
|
||||
return result;
|
||||
}
|
||||
public NetworkRequest[] newArray(int size) {
|
||||
@@ -238,8 +281,27 @@ public class NetworkRequest implements Parcelable {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 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 isRequest() {
|
||||
return type == Type.TRACK_DEFAULT || type == Type.REQUEST;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "NetworkRequest [ id=" + requestId + ", legacyType=" + legacyType +
|
||||
return "NetworkRequest [ " + type + " id=" + requestId +
|
||||
(legacyType != ConnectivityManager.TYPE_NONE ? ", legacyType=" + legacyType : "") +
|
||||
", " + networkCapabilities.toString() + " ]";
|
||||
}
|
||||
|
||||
@@ -248,6 +310,7 @@ public class NetworkRequest implements Parcelable {
|
||||
NetworkRequest that = (NetworkRequest)obj;
|
||||
return (that.legacyType == this.legacyType &&
|
||||
that.requestId == this.requestId &&
|
||||
that.type == this.type &&
|
||||
((that.networkCapabilities == null && this.networkCapabilities == null) ||
|
||||
(that.networkCapabilities != null &&
|
||||
that.networkCapabilities.equals(this.networkCapabilities))));
|
||||
@@ -255,6 +318,6 @@ public class NetworkRequest implements Parcelable {
|
||||
|
||||
public int hashCode() {
|
||||
return requestId + (legacyType * 1013) +
|
||||
(networkCapabilities.hashCode() * 1051);
|
||||
(networkCapabilities.hashCode() * 1051) + type.hashCode() * 17;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user