Move the request type from NetworkRequestInfo to NetworkRequest.
This will allow us to simplify code that deals with NetworkRequests outside ConnectivityService. Bug: 23113288 Change-Id: I9b3a859d0c68cad73d7f6baa4b584d13ffd2ae36
This commit is contained in:
@@ -47,15 +47,55 @@ public class NetworkRequest implements Parcelable {
|
|||||||
public final int legacyType;
|
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
|
* @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) {
|
if (nc == null) {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
requestId = rId;
|
requestId = rId;
|
||||||
networkCapabilities = nc;
|
networkCapabilities = nc;
|
||||||
this.legacyType = legacyType;
|
this.legacyType = legacyType;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,6 +105,7 @@ public class NetworkRequest implements Parcelable {
|
|||||||
networkCapabilities = new NetworkCapabilities(that.networkCapabilities);
|
networkCapabilities = new NetworkCapabilities(that.networkCapabilities);
|
||||||
requestId = that.requestId;
|
requestId = that.requestId;
|
||||||
this.legacyType = that.legacyType;
|
this.legacyType = that.legacyType;
|
||||||
|
this.type = that.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,7 +131,7 @@ public class NetworkRequest implements Parcelable {
|
|||||||
final NetworkCapabilities nc = new NetworkCapabilities(mNetworkCapabilities);
|
final NetworkCapabilities nc = new NetworkCapabilities(mNetworkCapabilities);
|
||||||
nc.maybeMarkCapabilitiesRestricted();
|
nc.maybeMarkCapabilitiesRestricted();
|
||||||
return new NetworkRequest(nc, ConnectivityManager.TYPE_NONE,
|
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.writeParcelable(networkCapabilities, flags);
|
||||||
dest.writeInt(legacyType);
|
dest.writeInt(legacyType);
|
||||||
dest.writeInt(requestId);
|
dest.writeInt(requestId);
|
||||||
|
// type intentionally not preserved across process boundaries.
|
||||||
}
|
}
|
||||||
public static final Creator<NetworkRequest> CREATOR =
|
public static final Creator<NetworkRequest> CREATOR =
|
||||||
new Creator<NetworkRequest>() {
|
new Creator<NetworkRequest>() {
|
||||||
@@ -230,7 +272,8 @@ public class NetworkRequest implements Parcelable {
|
|||||||
NetworkCapabilities nc = (NetworkCapabilities)in.readParcelable(null);
|
NetworkCapabilities nc = (NetworkCapabilities)in.readParcelable(null);
|
||||||
int legacyType = in.readInt();
|
int legacyType = in.readInt();
|
||||||
int requestId = 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;
|
return result;
|
||||||
}
|
}
|
||||||
public NetworkRequest[] newArray(int size) {
|
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() {
|
public String toString() {
|
||||||
return "NetworkRequest [ id=" + requestId + ", legacyType=" + legacyType +
|
return "NetworkRequest [ " + type + " id=" + requestId +
|
||||||
|
(legacyType != ConnectivityManager.TYPE_NONE ? ", legacyType=" + legacyType : "") +
|
||||||
", " + networkCapabilities.toString() + " ]";
|
", " + networkCapabilities.toString() + " ]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,6 +310,7 @@ public class NetworkRequest implements Parcelable {
|
|||||||
NetworkRequest that = (NetworkRequest)obj;
|
NetworkRequest that = (NetworkRequest)obj;
|
||||||
return (that.legacyType == this.legacyType &&
|
return (that.legacyType == this.legacyType &&
|
||||||
that.requestId == this.requestId &&
|
that.requestId == this.requestId &&
|
||||||
|
that.type == this.type &&
|
||||||
((that.networkCapabilities == null && this.networkCapabilities == null) ||
|
((that.networkCapabilities == null && this.networkCapabilities == null) ||
|
||||||
(that.networkCapabilities != null &&
|
(that.networkCapabilities != null &&
|
||||||
that.networkCapabilities.equals(this.networkCapabilities))));
|
that.networkCapabilities.equals(this.networkCapabilities))));
|
||||||
@@ -255,6 +318,6 @@ public class NetworkRequest implements Parcelable {
|
|||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return requestId + (legacyType * 1013) +
|
return requestId + (legacyType * 1013) +
|
||||||
(networkCapabilities.hashCode() * 1051);
|
(networkCapabilities.hashCode() * 1051) + type.hashCode() * 17;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -656,8 +656,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (DBG) log("ConnectivityService starting up");
|
if (DBG) log("ConnectivityService starting up");
|
||||||
|
|
||||||
mDefaultRequest = createInternetRequestForTransport(-1);
|
mDefaultRequest = createInternetRequestForTransport(-1);
|
||||||
NetworkRequestInfo defaultNRI = new NetworkRequestInfo(null, mDefaultRequest,
|
NetworkRequestInfo defaultNRI = new NetworkRequestInfo(null, mDefaultRequest, new Binder());
|
||||||
new Binder(), NetworkRequestType.REQUEST);
|
|
||||||
mNetworkRequests.put(mDefaultRequest, defaultNRI);
|
mNetworkRequests.put(mDefaultRequest, defaultNRI);
|
||||||
mNetworkRequestInfoLogs.log("REGISTER " + defaultNRI);
|
mNetworkRequestInfoLogs.log("REGISTER " + defaultNRI);
|
||||||
|
|
||||||
@@ -808,7 +807,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (transportType > -1) {
|
if (transportType > -1) {
|
||||||
netCap.addTransportType(transportType);
|
netCap.addTransportType(transportType);
|
||||||
}
|
}
|
||||||
return new NetworkRequest(netCap, TYPE_NONE, nextNetworkRequestId());
|
return new NetworkRequest(netCap, TYPE_NONE, nextNetworkRequestId(),
|
||||||
|
NetworkRequest.Type.REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used only for testing.
|
// Used only for testing.
|
||||||
@@ -832,7 +832,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
handleRegisterNetworkRequest(new NetworkRequestInfo(
|
handleRegisterNetworkRequest(new NetworkRequestInfo(
|
||||||
null, mDefaultMobileDataRequest, new Binder(), NetworkRequestType.REQUEST));
|
null, mDefaultMobileDataRequest, new Binder()));
|
||||||
} else {
|
} else {
|
||||||
handleReleaseNetworkRequest(mDefaultMobileDataRequest, Process.SYSTEM_UID);
|
handleReleaseNetworkRequest(mDefaultMobileDataRequest, Process.SYSTEM_UID);
|
||||||
}
|
}
|
||||||
@@ -2014,10 +2014,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isRequest(NetworkRequest request) {
|
|
||||||
return mNetworkRequests.get(request).isRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
// must be stateless - things change under us.
|
// must be stateless - things change under us.
|
||||||
private class NetworkStateTrackerHandler extends Handler {
|
private class NetworkStateTrackerHandler extends Handler {
|
||||||
public NetworkStateTrackerHandler(Looper looper) {
|
public NetworkStateTrackerHandler(Looper looper) {
|
||||||
@@ -2234,7 +2230,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (VDBG) log("NetworkFactory connected");
|
if (VDBG) log("NetworkFactory connected");
|
||||||
// A network factory has connected. Send it all current NetworkRequests.
|
// A network factory has connected. Send it all current NetworkRequests.
|
||||||
for (NetworkRequestInfo nri : mNetworkRequests.values()) {
|
for (NetworkRequestInfo nri : mNetworkRequests.values()) {
|
||||||
if (!nri.isRequest()) continue;
|
if (!nri.request.isRequest()) continue;
|
||||||
NetworkAgentInfo nai = mNetworkForRequestId.get(nri.request.requestId);
|
NetworkAgentInfo nai = mNetworkForRequestId.get(nri.request.requestId);
|
||||||
ac.sendMessage(android.net.NetworkFactory.CMD_REQUEST_NETWORK,
|
ac.sendMessage(android.net.NetworkFactory.CMD_REQUEST_NETWORK,
|
||||||
(nai != null ? nai.getCurrentScore() : 0), 0, nri.request);
|
(nai != null ? nai.getCurrentScore() : 0), 0, nri.request);
|
||||||
@@ -2375,7 +2371,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
private void handleRegisterNetworkRequest(NetworkRequestInfo nri) {
|
private void handleRegisterNetworkRequest(NetworkRequestInfo nri) {
|
||||||
mNetworkRequests.put(nri.request, nri);
|
mNetworkRequests.put(nri.request, nri);
|
||||||
mNetworkRequestInfoLogs.log("REGISTER " + nri);
|
mNetworkRequestInfoLogs.log("REGISTER " + nri);
|
||||||
if (!nri.isRequest()) {
|
if (!nri.request.isRequest()) {
|
||||||
for (NetworkAgentInfo network : mNetworkAgentInfos.values()) {
|
for (NetworkAgentInfo network : mNetworkAgentInfos.values()) {
|
||||||
if (nri.request.networkCapabilities.hasSignalStrength() &&
|
if (nri.request.networkCapabilities.hasSignalStrength() &&
|
||||||
network.satisfiesImmutableCapabilitiesOf(nri.request)) {
|
network.satisfiesImmutableCapabilitiesOf(nri.request)) {
|
||||||
@@ -2384,7 +2380,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
rematchAllNetworksAndRequests(null, 0);
|
rematchAllNetworksAndRequests(null, 0);
|
||||||
if (nri.isRequest() && mNetworkForRequestId.get(nri.request.requestId) == null) {
|
if (nri.request.isRequest() && mNetworkForRequestId.get(nri.request.requestId) == null) {
|
||||||
sendUpdatedScoreToFactories(nri.request, 0);
|
sendUpdatedScoreToFactories(nri.request, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2405,7 +2401,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
for (NetworkRequestInfo nri : mNetworkRequests.values()) {
|
for (NetworkRequestInfo nri : mNetworkRequests.values()) {
|
||||||
// If this Network is already the highest scoring Network for a request, or if
|
// If this Network is already the highest scoring Network for a request, or if
|
||||||
// there is hope for it to become one if it validated, then it is needed.
|
// there is hope for it to become one if it validated, then it is needed.
|
||||||
if (nri.isRequest() && nai.satisfies(nri.request) &&
|
if (nri.request.isRequest() && nai.satisfies(nri.request) &&
|
||||||
(nai.networkRequests.get(nri.request.requestId) != null ||
|
(nai.networkRequests.get(nri.request.requestId) != null ||
|
||||||
// Note that this catches two important cases:
|
// Note that this catches two important cases:
|
||||||
// 1. Unvalidated cellular will not be reaped when unvalidated WiFi
|
// 1. Unvalidated cellular will not be reaped when unvalidated WiFi
|
||||||
@@ -2429,7 +2425,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (DBG) log("Attempt to release unowned NetworkRequest " + request);
|
if (DBG) log("Attempt to release unowned NetworkRequest " + request);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (VDBG || (DBG && nri.isRequest())) log("releasing NetworkRequest " + request);
|
if (VDBG || (DBG && nri.request.isRequest())) log("releasing " + request);
|
||||||
nri.unlinkDeathRecipient();
|
nri.unlinkDeathRecipient();
|
||||||
mNetworkRequests.remove(request);
|
mNetworkRequests.remove(request);
|
||||||
synchronized (mUidToNetworkRequestCount) {
|
synchronized (mUidToNetworkRequestCount) {
|
||||||
@@ -2445,7 +2441,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
mNetworkRequestInfoLogs.log("RELEASE " + nri);
|
mNetworkRequestInfoLogs.log("RELEASE " + nri);
|
||||||
if (nri.isRequest()) {
|
if (nri.request.isRequest()) {
|
||||||
// Find all networks that are satisfying this request and remove the request
|
// Find all networks that are satisfying this request and remove the request
|
||||||
// from their request lists.
|
// from their request lists.
|
||||||
// TODO - it's my understanding that for a request there is only a single
|
// TODO - it's my understanding that for a request there is only a single
|
||||||
@@ -2487,7 +2483,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
for (int i = 0; i < nai.networkRequests.size(); i++) {
|
for (int i = 0; i < nai.networkRequests.size(); i++) {
|
||||||
NetworkRequest otherRequest = nai.networkRequests.valueAt(i);
|
NetworkRequest otherRequest = nai.networkRequests.valueAt(i);
|
||||||
if (otherRequest.legacyType == nri.request.legacyType &&
|
if (otherRequest.legacyType == nri.request.legacyType &&
|
||||||
isRequest(otherRequest)) {
|
otherRequest.isRequest()) {
|
||||||
if (DBG) log(" still have other legacy request - leaving");
|
if (DBG) log(" still have other legacy request - leaving");
|
||||||
doRemove = false;
|
doRemove = false;
|
||||||
}
|
}
|
||||||
@@ -3823,32 +3819,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A NetworkRequest as registered by an application 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 the default network", 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.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static enum NetworkRequestType {
|
|
||||||
LISTEN,
|
|
||||||
TRACK_DEFAULT,
|
|
||||||
REQUEST
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks info about the requester.
|
* Tracks info about the requester.
|
||||||
* Also used to notice when the calling process dies so we can self-expire
|
* Also used to notice when the calling process dies so we can self-expire
|
||||||
@@ -3861,27 +3831,26 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
final int mPid;
|
final int mPid;
|
||||||
final int mUid;
|
final int mUid;
|
||||||
final Messenger messenger;
|
final Messenger messenger;
|
||||||
private final NetworkRequestType mType;
|
|
||||||
|
|
||||||
NetworkRequestInfo(NetworkRequest r, PendingIntent pi, NetworkRequestType type) {
|
NetworkRequestInfo(NetworkRequest r, PendingIntent pi) {
|
||||||
request = r;
|
request = r;
|
||||||
|
ensureRequestHasType();
|
||||||
mPendingIntent = pi;
|
mPendingIntent = pi;
|
||||||
messenger = null;
|
messenger = null;
|
||||||
mBinder = null;
|
mBinder = null;
|
||||||
mPid = getCallingPid();
|
mPid = getCallingPid();
|
||||||
mUid = getCallingUid();
|
mUid = getCallingUid();
|
||||||
mType = type;
|
|
||||||
enforceRequestCountLimit();
|
enforceRequestCountLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRequestInfo(Messenger m, NetworkRequest r, IBinder binder, NetworkRequestType type) {
|
NetworkRequestInfo(Messenger m, NetworkRequest r, IBinder binder) {
|
||||||
super();
|
super();
|
||||||
messenger = m;
|
messenger = m;
|
||||||
request = r;
|
request = r;
|
||||||
|
ensureRequestHasType();
|
||||||
mBinder = binder;
|
mBinder = binder;
|
||||||
mPid = getCallingPid();
|
mPid = getCallingPid();
|
||||||
mUid = getCallingUid();
|
mUid = getCallingUid();
|
||||||
mType = type;
|
|
||||||
mPendingIntent = null;
|
mPendingIntent = null;
|
||||||
enforceRequestCountLimit();
|
enforceRequestCountLimit();
|
||||||
|
|
||||||
@@ -3892,6 +3861,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ensureRequestHasType() {
|
||||||
|
if (request.type == NetworkRequest.Type.NONE) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"All NetworkRequests in ConnectivityService must have a type");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void enforceRequestCountLimit() {
|
private void enforceRequestCountLimit() {
|
||||||
synchronized (mUidToNetworkRequestCount) {
|
synchronized (mUidToNetworkRequestCount) {
|
||||||
int networkRequests = mUidToNetworkRequestCount.get(mUid, 0) + 1;
|
int networkRequests = mUidToNetworkRequestCount.get(mUid, 0) + 1;
|
||||||
@@ -3902,16 +3878,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String typeString() {
|
|
||||||
switch (mType) {
|
|
||||||
case LISTEN: return "Listen";
|
|
||||||
case REQUEST: return "Request";
|
|
||||||
case TRACK_DEFAULT: return "Track default";
|
|
||||||
default:
|
|
||||||
return "unknown type";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void unlinkDeathRecipient() {
|
void unlinkDeathRecipient() {
|
||||||
if (mBinder != null) {
|
if (mBinder != null) {
|
||||||
mBinder.unlinkToDeath(this, 0);
|
mBinder.unlinkToDeath(this, 0);
|
||||||
@@ -3924,29 +3890,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
releaseNetworkRequest(request);
|
releaseNetworkRequest(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 only network
|
|
||||||
* which can satisfy the NetworkReqeust.
|
|
||||||
*
|
|
||||||
* For full detail of how isRequest() is used for pairing Networks with
|
|
||||||
* NetworkRequests read rematchNetworkAndRequests().
|
|
||||||
*
|
|
||||||
* TODO: Rename to something more properly descriptive.
|
|
||||||
*/
|
|
||||||
public boolean isRequest() {
|
|
||||||
return (mType == NetworkRequestType.TRACK_DEFAULT) ||
|
|
||||||
(mType == NetworkRequestType.REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return typeString() +
|
return "uid/pid:" + mUid + "/" + mPid + " " + request +
|
||||||
" from uid/pid:" + mUid + "/" + mPid +
|
|
||||||
" for " + request +
|
|
||||||
(mPendingIntent == null ? "" : " to trigger " + mPendingIntent);
|
(mPendingIntent == null ? "" : " to trigger " + mPendingIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3996,13 +3941,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
@Override
|
@Override
|
||||||
public NetworkRequest requestNetwork(NetworkCapabilities networkCapabilities,
|
public NetworkRequest requestNetwork(NetworkCapabilities networkCapabilities,
|
||||||
Messenger messenger, int timeoutMs, IBinder binder, int legacyType) {
|
Messenger messenger, int timeoutMs, IBinder binder, int legacyType) {
|
||||||
final NetworkRequestType type = (networkCapabilities == null)
|
final NetworkRequest.Type type = (networkCapabilities == null)
|
||||||
? NetworkRequestType.TRACK_DEFAULT
|
? NetworkRequest.Type.TRACK_DEFAULT
|
||||||
: NetworkRequestType.REQUEST;
|
: NetworkRequest.Type.REQUEST;
|
||||||
// If the requested networkCapabilities is null, take them instead from
|
// If the requested networkCapabilities is null, take them instead from
|
||||||
// the default network request. This allows callers to keep track of
|
// the default network request. This allows callers to keep track of
|
||||||
// the system default network.
|
// the system default network.
|
||||||
if (type == NetworkRequestType.TRACK_DEFAULT) {
|
if (type == NetworkRequest.Type.TRACK_DEFAULT) {
|
||||||
networkCapabilities = new NetworkCapabilities(mDefaultRequest.networkCapabilities);
|
networkCapabilities = new NetworkCapabilities(mDefaultRequest.networkCapabilities);
|
||||||
enforceAccessPermission();
|
enforceAccessPermission();
|
||||||
} else {
|
} else {
|
||||||
@@ -4023,8 +3968,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
NetworkRequest networkRequest = new NetworkRequest(networkCapabilities, legacyType,
|
NetworkRequest networkRequest = new NetworkRequest(networkCapabilities, legacyType,
|
||||||
nextNetworkRequestId());
|
nextNetworkRequestId(), type);
|
||||||
NetworkRequestInfo nri = new NetworkRequestInfo(messenger, networkRequest, binder, type);
|
NetworkRequestInfo nri = new NetworkRequestInfo(messenger, networkRequest, binder);
|
||||||
if (DBG) log("requestNetwork for " + nri);
|
if (DBG) log("requestNetwork for " + nri);
|
||||||
|
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_REQUEST, nri));
|
mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_REQUEST, nri));
|
||||||
@@ -4094,9 +4039,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
ensureRequestableCapabilities(networkCapabilities);
|
ensureRequestableCapabilities(networkCapabilities);
|
||||||
|
|
||||||
NetworkRequest networkRequest = new NetworkRequest(networkCapabilities, TYPE_NONE,
|
NetworkRequest networkRequest = new NetworkRequest(networkCapabilities, TYPE_NONE,
|
||||||
nextNetworkRequestId());
|
nextNetworkRequestId(), NetworkRequest.Type.REQUEST);
|
||||||
NetworkRequestInfo nri = new NetworkRequestInfo(networkRequest, operation,
|
NetworkRequestInfo nri = new NetworkRequestInfo(networkRequest, operation);
|
||||||
NetworkRequestType.REQUEST);
|
|
||||||
if (DBG) log("pendingRequest for " + nri);
|
if (DBG) log("pendingRequest for " + nri);
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_REQUEST_WITH_INTENT,
|
mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_REQUEST_WITH_INTENT,
|
||||||
nri));
|
nri));
|
||||||
@@ -4146,9 +4090,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
NetworkRequest networkRequest = new NetworkRequest(
|
NetworkRequest networkRequest = new NetworkRequest(
|
||||||
new NetworkCapabilities(networkCapabilities), TYPE_NONE, nextNetworkRequestId());
|
new NetworkCapabilities(networkCapabilities), TYPE_NONE, nextNetworkRequestId(),
|
||||||
NetworkRequestInfo nri = new NetworkRequestInfo(messenger, networkRequest, binder,
|
NetworkRequest.Type.LISTEN);
|
||||||
NetworkRequestType.LISTEN);
|
NetworkRequestInfo nri = new NetworkRequestInfo(messenger, networkRequest, binder);
|
||||||
if (VDBG) log("listenForNetwork for " + nri);
|
if (VDBG) log("listenForNetwork for " + nri);
|
||||||
|
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_LISTENER, nri));
|
mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_LISTENER, nri));
|
||||||
@@ -4164,9 +4108,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
NetworkRequest networkRequest = new NetworkRequest(
|
NetworkRequest networkRequest = new NetworkRequest(
|
||||||
new NetworkCapabilities(networkCapabilities), TYPE_NONE, nextNetworkRequestId());
|
new NetworkCapabilities(networkCapabilities), TYPE_NONE, nextNetworkRequestId(),
|
||||||
NetworkRequestInfo nri = new NetworkRequestInfo(networkRequest, operation,
|
NetworkRequest.Type.LISTEN);
|
||||||
NetworkRequestType.LISTEN);
|
NetworkRequestInfo nri = new NetworkRequestInfo(networkRequest, operation);
|
||||||
if (VDBG) log("pendingListenForNetwork for " + nri);
|
if (VDBG) log("pendingListenForNetwork for " + nri);
|
||||||
|
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_LISTENER, nri));
|
mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_LISTENER, nri));
|
||||||
@@ -4485,7 +4429,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
for (int i = 0; i < nai.networkRequests.size(); i++) {
|
for (int i = 0; i < nai.networkRequests.size(); i++) {
|
||||||
NetworkRequest nr = nai.networkRequests.valueAt(i);
|
NetworkRequest nr = nai.networkRequests.valueAt(i);
|
||||||
// Don't send listening requests to factories. b/17393458
|
// Don't send listening requests to factories. b/17393458
|
||||||
if (!isRequest(nr)) continue;
|
if (!nr.isRequest()) continue;
|
||||||
sendUpdatedScoreToFactories(nr, nai.getCurrentScore());
|
sendUpdatedScoreToFactories(nr, nai.getCurrentScore());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4578,7 +4522,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
for (int i = 0; i < nai.networkRequests.size(); i++) {
|
for (int i = 0; i < nai.networkRequests.size(); i++) {
|
||||||
NetworkRequest nr = nai.networkRequests.valueAt(i);
|
NetworkRequest nr = nai.networkRequests.valueAt(i);
|
||||||
// Ignore listening requests.
|
// Ignore listening requests.
|
||||||
if (!isRequest(nr)) continue;
|
if (!nr.isRequest()) continue;
|
||||||
loge("Dead network still had at least " + nr);
|
loge("Dead network still had at least " + nr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -4662,7 +4606,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// check if it satisfies the NetworkCapabilities
|
// check if it satisfies the NetworkCapabilities
|
||||||
if (VDBG) log(" checking if request is satisfied: " + nri.request);
|
if (VDBG) log(" checking if request is satisfied: " + nri.request);
|
||||||
if (satisfies) {
|
if (satisfies) {
|
||||||
if (!nri.isRequest()) {
|
if (!nri.request.isRequest()) {
|
||||||
// This is not a request, it's a callback listener.
|
// This is not a request, it's a callback listener.
|
||||||
// Add it to newNetwork regardless of score.
|
// Add it to newNetwork regardless of score.
|
||||||
if (newNetwork.addRequest(nri.request)) addedRequests.add(nri);
|
if (newNetwork.addRequest(nri.request)) addedRequests.add(nri);
|
||||||
@@ -4722,7 +4666,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
mNetworkForRequestId.remove(nri.request.requestId);
|
mNetworkForRequestId.remove(nri.request.requestId);
|
||||||
sendUpdatedScoreToFactories(nri.request, 0);
|
sendUpdatedScoreToFactories(nri.request, 0);
|
||||||
} else {
|
} else {
|
||||||
if (nri.isRequest()) {
|
if (nri.request.isRequest()) {
|
||||||
Slog.wtf(TAG, "BUG: Removing request " + nri.request.requestId + " from " +
|
Slog.wtf(TAG, "BUG: Removing request " + nri.request.requestId + " from " +
|
||||||
newNetwork.name() +
|
newNetwork.name() +
|
||||||
" without updating mNetworkForRequestId or factories!");
|
" without updating mNetworkForRequestId or factories!");
|
||||||
@@ -4824,7 +4768,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// This is on top of the multiple intent sequencing referenced in the todo above.
|
// This is on top of the multiple intent sequencing referenced in the todo above.
|
||||||
for (int i = 0; i < newNetwork.networkRequests.size(); i++) {
|
for (int i = 0; i < newNetwork.networkRequests.size(); i++) {
|
||||||
NetworkRequest nr = newNetwork.networkRequests.valueAt(i);
|
NetworkRequest nr = newNetwork.networkRequests.valueAt(i);
|
||||||
if (nr.legacyType != TYPE_NONE && isRequest(nr)) {
|
if (nr.legacyType != TYPE_NONE && nr.isRequest()) {
|
||||||
// legacy type tracker filters out repeat adds
|
// legacy type tracker filters out repeat adds
|
||||||
mLegacyTypeTracker.add(nr.legacyType, newNetwork);
|
mLegacyTypeTracker.add(nr.legacyType, newNetwork);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user