Rematch requests first and listens second. am: 0c38d7c8cd
am: 836a5db809 Change-Id: Ia57cd548b2920efaee733f5cb0df66139a6e55e6
This commit is contained in:
@@ -4631,6 +4631,27 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
setDefaultDnsSystemProperties(newNetwork.linkProperties.getDnsServers());
|
setDefaultDnsSystemProperties(newNetwork.linkProperties.getDnsServers());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void processListenRequests(NetworkAgentInfo nai) {
|
||||||
|
// For consistency with previous behaviour, send onLost callbacks before onAvailable.
|
||||||
|
for (NetworkRequestInfo nri : mNetworkRequests.values()) {
|
||||||
|
NetworkRequest nr = nri.request;
|
||||||
|
if (!nr.isListen()) continue;
|
||||||
|
if (nai.isSatisfyingRequest(nr.requestId) && !nai.satisfies(nr)) {
|
||||||
|
nai.removeRequest(nri.request.requestId);
|
||||||
|
callCallbackForRequest(nri, nai, ConnectivityManager.CALLBACK_LOST, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (NetworkRequestInfo nri : mNetworkRequests.values()) {
|
||||||
|
NetworkRequest nr = nri.request;
|
||||||
|
if (!nr.isListen()) continue;
|
||||||
|
if (nai.satisfies(nr) && !nai.isSatisfyingRequest(nr.requestId)) {
|
||||||
|
nai.addRequest(nr);
|
||||||
|
notifyNetworkCallback(nai, nri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handles a network appearing or improving its score.
|
// Handles a network appearing or improving its score.
|
||||||
//
|
//
|
||||||
// - Evaluates all current NetworkRequests that can be
|
// - Evaluates all current NetworkRequests that can be
|
||||||
@@ -4671,6 +4692,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
ArrayList<NetworkRequestInfo> addedRequests = new ArrayList<NetworkRequestInfo>();
|
ArrayList<NetworkRequestInfo> addedRequests = new ArrayList<NetworkRequestInfo>();
|
||||||
if (VDBG) log(" network has: " + newNetwork.networkCapabilities);
|
if (VDBG) log(" network has: " + newNetwork.networkCapabilities);
|
||||||
for (NetworkRequestInfo nri : mNetworkRequests.values()) {
|
for (NetworkRequestInfo nri : mNetworkRequests.values()) {
|
||||||
|
// Process requests in the first pass and listens in the second pass. This allows us to
|
||||||
|
// change a network's capabilities depending on which requests it has. This is only
|
||||||
|
// correct if the change in capabilities doesn't affect whether the network satisfies
|
||||||
|
// requests or not, and doesn't affect the network's score.
|
||||||
|
if (nri.request.isListen()) continue;
|
||||||
|
|
||||||
final NetworkAgentInfo currentNetwork = mNetworkForRequestId.get(nri.request.requestId);
|
final NetworkAgentInfo currentNetwork = mNetworkForRequestId.get(nri.request.requestId);
|
||||||
final boolean satisfies = newNetwork.satisfies(nri.request);
|
final boolean satisfies = newNetwork.satisfies(nri.request);
|
||||||
if (newNetwork == currentNetwork && satisfies) {
|
if (newNetwork == currentNetwork && satisfies) {
|
||||||
@@ -4685,13 +4712,6 @@ 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.request.isListen()) {
|
|
||||||
// This is not a request, it's a callback listener.
|
|
||||||
// Add it to newNetwork regardless of score.
|
|
||||||
if (newNetwork.addRequest(nri.request)) addedRequests.add(nri);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// next check if it's better than any current network we're using for
|
// next check if it's better than any current network we're using for
|
||||||
// this request
|
// this request
|
||||||
if (VDBG) {
|
if (VDBG) {
|
||||||
@@ -4748,16 +4768,14 @@ 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.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!");
|
||||||
}
|
}
|
||||||
}
|
// TODO: Technically, sending CALLBACK_LOST here is
|
||||||
// TODO: technically, sending CALLBACK_LOST here is
|
// incorrect if there is a replacement network currently
|
||||||
// incorrect if nri is a request (not a listen) and there
|
// connected that can satisfy nri, which is a request
|
||||||
// is a replacement network currently connected that can
|
// (not a listen). However, the only capability that can both
|
||||||
// satisfy it. However, the only capability that can both
|
|
||||||
// a) be requested and b) change is NET_CAPABILITY_TRUSTED,
|
// a) be requested and b) change is NET_CAPABILITY_TRUSTED,
|
||||||
// so this code is only incorrect for a network that loses
|
// so this code is only incorrect for a network that loses
|
||||||
// the TRUSTED capability, which is a rare case.
|
// the TRUSTED capability, which is a rare case.
|
||||||
@@ -4782,6 +4800,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Second pass: process all listens.
|
||||||
|
processListenRequests(newNetwork);
|
||||||
|
|
||||||
// do this after the default net is switched, but
|
// do this after the default net is switched, but
|
||||||
// before LegacyTypeTracker sends legacy broadcasts
|
// before LegacyTypeTracker sends legacy broadcasts
|
||||||
for (NetworkRequestInfo nri : addedRequests) notifyNetworkCallback(newNetwork, nri);
|
for (NetworkRequestInfo nri : addedRequests) notifyNetworkCallback(newNetwork, nri);
|
||||||
|
|||||||
Reference in New Issue
Block a user