Never satisfy requests with networks that aren't connected.
Currently, NetworkAgentInfo#satisfies determines whether a network exists (and should satisfy requests) based on |created|, not |everConnected|. This is theoretically incorrect because networks in CONNECTING state or similar must never satisfy requests or call callbacks. This cannot happen for requests. New requests are only added to networks by NetworkAgentInfo#addRequest, which is only called by computeNetworkReassignment via updateSatisfiersForRematchRequest, which skips any network with everConnected = false. It can potentially happen to listens though. Also, this cannot ever happen for physical networks, because for physical networks, created is set at the same time as everConnected, the first time they enter CONNECTED state. In theory, this can happen for VPNs since ag/988402 , which changed the code to create VPN networks as soon as they enter CONNECTING state. That CL added the everConnected boolean to NetworkAgentInfo but did not update the satisfies and satisfiesImmutableCapabilitiesOf checks to use everConnected. In practice, even for VPNs this is very unlikely, since VPNs advance from CONNECTING to CONNECTED essentially immediately. Even if they didn't, sending callbacks before they enter CONNECTED state would be incorrect because the app receiving the callback would have no way of knowing that the network is actually not yet connected. With this change, some checks for everConnected become spurious, because a network with everConnected=false cannot satisfy either requests or listens. Remove these checks. Test: extensively tested by existing ConnectivityServiceTest Change-Id: I024bb2b85bc57228d53e69a7707c7ce7ac756259
This commit is contained in:
@@ -7495,9 +7495,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
notifyIfacesChangedForNetworkStats();
|
notifyIfacesChangedForNetworkStats();
|
||||||
networkAgent.networkMonitor().notifyLinkPropertiesChanged(
|
networkAgent.networkMonitor().notifyLinkPropertiesChanged(
|
||||||
new LinkProperties(newLp, true /* parcelSensitiveFields */));
|
new LinkProperties(newLp, true /* parcelSensitiveFields */));
|
||||||
if (networkAgent.everConnected) {
|
notifyNetworkCallbacks(networkAgent, ConnectivityManager.CALLBACK_IP_CHANGED);
|
||||||
notifyNetworkCallbacks(networkAgent, ConnectivityManager.CALLBACK_IP_CHANGED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mKeepaliveTracker.handleCheckKeepalivesStillValid(networkAgent);
|
mKeepaliveTracker.handleCheckKeepalivesStillValid(networkAgent);
|
||||||
@@ -8749,9 +8747,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// Gather the list of all relevant agents.
|
// Gather the list of all relevant agents.
|
||||||
final ArrayList<NetworkAgentInfo> nais = new ArrayList<>();
|
final ArrayList<NetworkAgentInfo> nais = new ArrayList<>();
|
||||||
for (final NetworkAgentInfo nai : mNetworkAgentInfos) {
|
for (final NetworkAgentInfo nai : mNetworkAgentInfos) {
|
||||||
if (!nai.everConnected) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
nais.add(nai);
|
nais.add(nai);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8875,7 +8870,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (final NetworkAgentInfo nai : nais) {
|
for (final NetworkAgentInfo nai : nais) {
|
||||||
if (!nai.everConnected) continue;
|
|
||||||
final boolean oldBackground = oldBgNetworks.contains(nai);
|
final boolean oldBackground = oldBgNetworks.contains(nai);
|
||||||
// Process listen requests and update capabilities if the background state has
|
// Process listen requests and update capabilities if the background state has
|
||||||
// changed for this network. For consistency with previous behavior, send onLost
|
// changed for this network. For consistency with previous behavior, send onLost
|
||||||
@@ -9468,7 +9462,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (NetworkAgentInfo nai : mNetworkAgentInfos) {
|
for (NetworkAgentInfo nai : mNetworkAgentInfos) {
|
||||||
if (nai.everConnected && (activeNetIds.contains(nai.network().netId) || nai.isVPN())) {
|
if (activeNetIds.contains(nai.network().netId) || nai.isVPN()) {
|
||||||
defaultNetworks.add(nai.network);
|
defaultNetworks.add(nai.network);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -983,14 +983,13 @@ public class NetworkAgentInfo implements NetworkRanker.Scoreable {
|
|||||||
|
|
||||||
// Does this network satisfy request?
|
// Does this network satisfy request?
|
||||||
public boolean satisfies(NetworkRequest request) {
|
public boolean satisfies(NetworkRequest request) {
|
||||||
return created &&
|
return everConnected
|
||||||
request.networkCapabilities.satisfiedByNetworkCapabilities(networkCapabilities);
|
&& request.networkCapabilities.satisfiedByNetworkCapabilities(networkCapabilities);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean satisfiesImmutableCapabilitiesOf(NetworkRequest request) {
|
public boolean satisfiesImmutableCapabilitiesOf(NetworkRequest request) {
|
||||||
return created &&
|
return everConnected && request.networkCapabilities.satisfiedByImmutableNetworkCapabilities(
|
||||||
request.networkCapabilities.satisfiedByImmutableNetworkCapabilities(
|
networkCapabilities);
|
||||||
networkCapabilities);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Whether this network is a VPN. */
|
/** Whether this network is a VPN. */
|
||||||
|
|||||||
Reference in New Issue
Block a user