Make the NetworkRequest list private to NetworkAgentInfo.
This allows us to keep track of how many live requests a network is satisfying without having to count them every time. Bug: 23113288 Change-Id: Ic4756676491e09071dbf80b7c48da3be028d68eb
This commit is contained in:
@@ -1904,8 +1904,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
pw.increaseIndent();
|
pw.increaseIndent();
|
||||||
pw.println("Requests:");
|
pw.println("Requests:");
|
||||||
pw.increaseIndent();
|
pw.increaseIndent();
|
||||||
for (int i = 0; i < nai.networkRequests.size(); i++) {
|
for (int i = 0; i < nai.numNetworkRequests(); i++) {
|
||||||
pw.println(nai.networkRequests.valueAt(i).toString());
|
pw.println(nai.requestAt(i).toString());
|
||||||
}
|
}
|
||||||
pw.decreaseIndent();
|
pw.decreaseIndent();
|
||||||
pw.println("Lingered:");
|
pw.println("Lingered:");
|
||||||
@@ -2265,7 +2265,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
NetworkAgentInfo nai = mNetworkAgentInfos.get(msg.replyTo);
|
NetworkAgentInfo nai = mNetworkAgentInfos.get(msg.replyTo);
|
||||||
if (nai != null) {
|
if (nai != null) {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
log(nai.name() + " got DISCONNECTED, was satisfying " + nai.networkRequests.size());
|
log(nai.name() + " got DISCONNECTED, was satisfying " + nai.numNetworkRequests());
|
||||||
}
|
}
|
||||||
// A network agent has disconnected.
|
// A network agent has disconnected.
|
||||||
// TODO - if we move the logic to the network agent (have them disconnect
|
// TODO - if we move the logic to the network agent (have them disconnect
|
||||||
@@ -2302,15 +2302,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
mNetworkForNetId.remove(nai.network.netId);
|
mNetworkForNetId.remove(nai.network.netId);
|
||||||
}
|
}
|
||||||
// Remove all previously satisfied requests.
|
// Remove all previously satisfied requests.
|
||||||
for (int i = 0; i < nai.networkRequests.size(); i++) {
|
for (int i = 0; i < nai.numNetworkRequests(); i++) {
|
||||||
NetworkRequest request = nai.networkRequests.valueAt(i);
|
NetworkRequest request = nai.requestAt(i);
|
||||||
NetworkAgentInfo currentNetwork = mNetworkForRequestId.get(request.requestId);
|
NetworkAgentInfo currentNetwork = mNetworkForRequestId.get(request.requestId);
|
||||||
if (currentNetwork != null && currentNetwork.network.netId == nai.network.netId) {
|
if (currentNetwork != null && currentNetwork.network.netId == nai.network.netId) {
|
||||||
mNetworkForRequestId.remove(request.requestId);
|
mNetworkForRequestId.remove(request.requestId);
|
||||||
sendUpdatedScoreToFactories(request, 0);
|
sendUpdatedScoreToFactories(request, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nai.networkRequests.get(mDefaultRequest.requestId) != null) {
|
if (nai.isSatisfyingRequest(mDefaultRequest.requestId)) {
|
||||||
removeDataActivityTracking(nai);
|
removeDataActivityTracking(nai);
|
||||||
notifyLockdownVpn(nai);
|
notifyLockdownVpn(nai);
|
||||||
requestNetworkTransitionWakelock(nai.name());
|
requestNetworkTransitionWakelock(nai.name());
|
||||||
@@ -2402,7 +2402,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// 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.request.isRequest() && nai.satisfies(nri.request) &&
|
if (nri.request.isRequest() && nai.satisfies(nri.request) &&
|
||||||
(nai.networkRequests.get(nri.request.requestId) != null ||
|
(nai.isSatisfyingRequest(nri.request.requestId) ||
|
||||||
// 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
|
||||||
// is currently satisfying the request. This is desirable when
|
// is currently satisfying the request. This is desirable when
|
||||||
@@ -2448,12 +2448,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// network satisfying it, so this loop is wasteful
|
// network satisfying it, so this loop is wasteful
|
||||||
boolean wasKept = false;
|
boolean wasKept = false;
|
||||||
for (NetworkAgentInfo nai : mNetworkAgentInfos.values()) {
|
for (NetworkAgentInfo nai : mNetworkAgentInfos.values()) {
|
||||||
if (nai.networkRequests.get(nri.request.requestId) != null) {
|
if (nai.isSatisfyingRequest(nri.request.requestId)) {
|
||||||
nai.networkRequests.remove(nri.request.requestId);
|
nai.removeRequest(nri.request.requestId);
|
||||||
if (VDBG) {
|
if (VDBG) {
|
||||||
log(" Removing from current network " + nai.name() +
|
log(" Removing from current network " + nai.name() +
|
||||||
", leaving " + nai.networkRequests.size() +
|
", leaving " + nai.numNetworkRequests() + " requests.");
|
||||||
" requests.");
|
|
||||||
}
|
}
|
||||||
if (unneeded(nai)) {
|
if (unneeded(nai)) {
|
||||||
if (DBG) log("no live requests for " + nai.name() + "; disconnecting");
|
if (DBG) log("no live requests for " + nai.name() + "; disconnecting");
|
||||||
@@ -2480,8 +2479,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (wasKept) {
|
if (wasKept) {
|
||||||
// check if any of the remaining requests for this network are for the
|
// check if any of the remaining requests for this network are for the
|
||||||
// same legacy type - if so, don't remove the nai
|
// same legacy type - if so, don't remove the nai
|
||||||
for (int i = 0; i < nai.networkRequests.size(); i++) {
|
for (int i = 0; i < nai.numNetworkRequests(); i++) {
|
||||||
NetworkRequest otherRequest = nai.networkRequests.valueAt(i);
|
NetworkRequest otherRequest = nai.requestAt(i);
|
||||||
if (otherRequest.legacyType == nri.request.legacyType &&
|
if (otherRequest.legacyType == nri.request.legacyType &&
|
||||||
otherRequest.isRequest()) {
|
otherRequest.isRequest()) {
|
||||||
if (DBG) log(" still have other legacy request - leaving");
|
if (DBG) log(" still have other legacy request - leaving");
|
||||||
@@ -2503,7 +2502,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// listens don't have a singular affectedNetwork. Check all networks to see
|
// listens don't have a singular affectedNetwork. Check all networks to see
|
||||||
// if this listen request applies and remove it.
|
// if this listen request applies and remove it.
|
||||||
for (NetworkAgentInfo nai : mNetworkAgentInfos.values()) {
|
for (NetworkAgentInfo nai : mNetworkAgentInfos.values()) {
|
||||||
nai.networkRequests.remove(nri.request.requestId);
|
nai.removeRequest(nri.request.requestId);
|
||||||
if (nri.request.networkCapabilities.hasSignalStrength() &&
|
if (nri.request.networkCapabilities.hasSignalStrength() &&
|
||||||
nai.satisfiesImmutableCapabilitiesOf(nri.request)) {
|
nai.satisfiesImmutableCapabilitiesOf(nri.request)) {
|
||||||
updateSignalStrengthThresholds(nai, "RELEASE", nri.request);
|
updateSignalStrengthThresholds(nai, "RELEASE", nri.request);
|
||||||
@@ -4426,8 +4425,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendUpdatedScoreToFactories(NetworkAgentInfo nai) {
|
private void sendUpdatedScoreToFactories(NetworkAgentInfo nai) {
|
||||||
for (int i = 0; i < nai.networkRequests.size(); i++) {
|
for (int i = 0; i < nai.numNetworkRequests(); i++) {
|
||||||
NetworkRequest nr = nai.networkRequests.valueAt(i);
|
NetworkRequest nr = nai.requestAt(i);
|
||||||
// Don't send listening requests to factories. b/17393458
|
// Don't send listening requests to factories. b/17393458
|
||||||
if (!nr.isRequest()) continue;
|
if (!nr.isRequest()) continue;
|
||||||
sendUpdatedScoreToFactories(nr, nai.getCurrentScore());
|
sendUpdatedScoreToFactories(nr, nai.getCurrentScore());
|
||||||
@@ -4519,13 +4518,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void teardownUnneededNetwork(NetworkAgentInfo nai) {
|
private void teardownUnneededNetwork(NetworkAgentInfo nai) {
|
||||||
for (int i = 0; i < nai.networkRequests.size(); i++) {
|
if (nai.numRequestNetworkRequests() != 0) {
|
||||||
NetworkRequest nr = nai.networkRequests.valueAt(i);
|
for (int i = 0; i < nai.numNetworkRequests(); i++) {
|
||||||
|
NetworkRequest nr = nai.requestAt(i);
|
||||||
// Ignore listening requests.
|
// Ignore listening requests.
|
||||||
if (!nr.isRequest()) continue;
|
if (!nr.isRequest()) continue;
|
||||||
loge("Dead network still had at least " + nr);
|
loge("Dead network still had at least " + nr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
nai.asyncChannel.disconnect();
|
nai.asyncChannel.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4625,7 +4626,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (VDBG) log("rematch for " + newNetwork.name());
|
if (VDBG) log("rematch for " + newNetwork.name());
|
||||||
if (currentNetwork != null) {
|
if (currentNetwork != null) {
|
||||||
if (VDBG) log(" accepting network in place of " + currentNetwork.name());
|
if (VDBG) log(" accepting network in place of " + currentNetwork.name());
|
||||||
currentNetwork.networkRequests.remove(nri.request.requestId);
|
currentNetwork.removeRequest(nri.request.requestId);
|
||||||
currentNetwork.networkLingered.add(nri.request);
|
currentNetwork.networkLingered.add(nri.request);
|
||||||
affectedNetworks.add(currentNetwork);
|
affectedNetworks.add(currentNetwork);
|
||||||
} else {
|
} else {
|
||||||
@@ -4649,7 +4650,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
oldDefaultNetwork = currentNetwork;
|
oldDefaultNetwork = currentNetwork;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (newNetwork.networkRequests.get(nri.request.requestId) != null) {
|
} else if (newNetwork.isSatisfyingRequest(nri.request.requestId)) {
|
||||||
// If "newNetwork" is listed as satisfying "nri" but no longer satisfies "nri",
|
// If "newNetwork" is listed as satisfying "nri" but no longer satisfies "nri",
|
||||||
// mark it as no longer satisfying "nri". Because networks are processed by
|
// mark it as no longer satisfying "nri". Because networks are processed by
|
||||||
// rematchAllNetworkAndRequests() in descending score order, "currentNetwork" will
|
// rematchAllNetworkAndRequests() in descending score order, "currentNetwork" will
|
||||||
@@ -4661,7 +4662,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
log("Network " + newNetwork.name() + " stopped satisfying" +
|
log("Network " + newNetwork.name() + " stopped satisfying" +
|
||||||
" request " + nri.request.requestId);
|
" request " + nri.request.requestId);
|
||||||
}
|
}
|
||||||
newNetwork.networkRequests.remove(nri.request.requestId);
|
newNetwork.removeRequest(nri.request.requestId);
|
||||||
if (currentNetwork == newNetwork) {
|
if (currentNetwork == newNetwork) {
|
||||||
mNetworkForRequestId.remove(nri.request.requestId);
|
mNetworkForRequestId.remove(nri.request.requestId);
|
||||||
sendUpdatedScoreToFactories(nri.request, 0);
|
sendUpdatedScoreToFactories(nri.request, 0);
|
||||||
@@ -4766,8 +4767,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// (notification callbacks) and then uses the old api (getNetworkInfo(type))
|
// (notification callbacks) and then uses the old api (getNetworkInfo(type))
|
||||||
// they may get old info. Reverse this after the old startUsing api is removed.
|
// they may get old info. Reverse this after the old startUsing api is removed.
|
||||||
// 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.numNetworkRequests(); i++) {
|
||||||
NetworkRequest nr = newNetwork.networkRequests.valueAt(i);
|
NetworkRequest nr = newNetwork.requestAt(i);
|
||||||
if (nr.legacyType != TYPE_NONE && nr.isRequest()) {
|
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);
|
||||||
@@ -5027,7 +5028,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO, info.getExtraInfo());
|
intent.putExtra(ConnectivityManager.EXTRA_EXTRA_INFO, info.getExtraInfo());
|
||||||
}
|
}
|
||||||
NetworkAgentInfo newDefaultAgent = null;
|
NetworkAgentInfo newDefaultAgent = null;
|
||||||
if (nai.networkRequests.get(mDefaultRequest.requestId) != null) {
|
if (nai.isSatisfyingRequest(mDefaultRequest.requestId)) {
|
||||||
newDefaultAgent = getDefaultNetwork();
|
newDefaultAgent = getDefaultNetwork();
|
||||||
if (newDefaultAgent != null) {
|
if (newDefaultAgent != null) {
|
||||||
intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO,
|
intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO,
|
||||||
@@ -5047,8 +5048,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
|
|
||||||
protected void notifyNetworkCallbacks(NetworkAgentInfo networkAgent, int notifyType) {
|
protected void notifyNetworkCallbacks(NetworkAgentInfo networkAgent, int notifyType) {
|
||||||
if (VDBG) log("notifyType " + notifyTypeToName(notifyType) + " for " + networkAgent.name());
|
if (VDBG) log("notifyType " + notifyTypeToName(notifyType) + " for " + networkAgent.name());
|
||||||
for (int i = 0; i < networkAgent.networkRequests.size(); i++) {
|
for (int i = 0; i < networkAgent.numNetworkRequests(); i++) {
|
||||||
NetworkRequest nr = networkAgent.networkRequests.valueAt(i);
|
NetworkRequest nr = networkAgent.requestAt(i);
|
||||||
NetworkRequestInfo nri = mNetworkRequests.get(nr);
|
NetworkRequestInfo nri = mNetworkRequests.get(nr);
|
||||||
if (VDBG) log(" sending notification for " + nr);
|
if (VDBG) log(" sending notification for " + nr);
|
||||||
if (nri.mPendingIntent == null) {
|
if (nri.mPendingIntent == null) {
|
||||||
|
|||||||
@@ -162,11 +162,13 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
|||||||
private static final int MAXIMUM_NETWORK_SCORE = 100;
|
private static final int MAXIMUM_NETWORK_SCORE = 100;
|
||||||
|
|
||||||
// The list of NetworkRequests being satisfied by this Network.
|
// The list of NetworkRequests being satisfied by this Network.
|
||||||
public final SparseArray<NetworkRequest> networkRequests = new SparseArray<NetworkRequest>();
|
private final SparseArray<NetworkRequest> mNetworkRequests = new SparseArray<>();
|
||||||
// The list of NetworkRequests that this Network previously satisfied with the highest
|
// The list of NetworkRequests that this Network previously satisfied with the highest
|
||||||
// score. A non-empty list indicates that if this Network was validated it is lingered.
|
// score. A non-empty list indicates that if this Network was validated it is lingered.
|
||||||
// NOTE: This list is only used for debugging.
|
// NOTE: This list is only used for debugging.
|
||||||
public final ArrayList<NetworkRequest> networkLingered = new ArrayList<NetworkRequest>();
|
public final ArrayList<NetworkRequest> networkLingered = new ArrayList<NetworkRequest>();
|
||||||
|
// How many of the satisfied requests are actual requests and not listens.
|
||||||
|
private int mNumRequestNetworkRequests = 0;
|
||||||
|
|
||||||
public final Messenger messenger;
|
public final Messenger messenger;
|
||||||
public final AsyncChannel asyncChannel;
|
public final AsyncChannel asyncChannel;
|
||||||
@@ -188,18 +190,63 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
|
|||||||
networkMisc = misc;
|
networkMisc = misc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Functions for manipulating the requests satisfied by this network.
|
||||||
|
//
|
||||||
|
// These functions must only called on ConnectivityService's main thread.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add {@code networkRequest} to this network as it's satisfied by this network.
|
* Add {@code networkRequest} to this network as it's satisfied by this network.
|
||||||
* NOTE: This function must only be called on ConnectivityService's main thread.
|
|
||||||
* @return true if {@code networkRequest} was added or false if {@code networkRequest} was
|
* @return true if {@code networkRequest} was added or false if {@code networkRequest} was
|
||||||
* already present.
|
* already present.
|
||||||
*/
|
*/
|
||||||
public boolean addRequest(NetworkRequest networkRequest) {
|
public boolean addRequest(NetworkRequest networkRequest) {
|
||||||
if (networkRequests.get(networkRequest.requestId) == networkRequest) return false;
|
NetworkRequest existing = mNetworkRequests.get(networkRequest.requestId);
|
||||||
networkRequests.put(networkRequest.requestId, networkRequest);
|
if (existing == networkRequest) return false;
|
||||||
|
if (existing != null && existing.isRequest()) mNumRequestNetworkRequests--;
|
||||||
|
mNetworkRequests.put(networkRequest.requestId, networkRequest);
|
||||||
|
if (networkRequest.isRequest()) mNumRequestNetworkRequests++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the specified request from this network.
|
||||||
|
*/
|
||||||
|
public void removeRequest(int requestId) {
|
||||||
|
NetworkRequest existing = mNetworkRequests.get(requestId);
|
||||||
|
if (existing != null && existing.isRequest()) mNumRequestNetworkRequests--;
|
||||||
|
mNetworkRequests.remove(requestId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this network is currently satisfying the request with the specified ID.
|
||||||
|
*/
|
||||||
|
public boolean isSatisfyingRequest(int id) {
|
||||||
|
return mNetworkRequests.get(id) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the request at the specified position in the list of requests satisfied by this
|
||||||
|
* network.
|
||||||
|
*/
|
||||||
|
public NetworkRequest requestAt(int index) {
|
||||||
|
return mNetworkRequests.valueAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of requests currently satisfied by this network for which
|
||||||
|
* {@link android.net.NetworkRequest#isRequest} returns {@code true}.
|
||||||
|
*/
|
||||||
|
public int numRequestNetworkRequests() {
|
||||||
|
return mNumRequestNetworkRequests;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of requests of any type currently satisfied by this network.
|
||||||
|
*/
|
||||||
|
public int numNetworkRequests() {
|
||||||
|
return mNetworkRequests.size();
|
||||||
|
}
|
||||||
|
|
||||||
// Does this network satisfy request?
|
// Does this network satisfy request?
|
||||||
public boolean satisfies(NetworkRequest request) {
|
public boolean satisfies(NetworkRequest request) {
|
||||||
return created &&
|
return created &&
|
||||||
|
|||||||
Reference in New Issue
Block a user