Allow NetworkAgent "immutable updates" to NetworkCapabilities

This patch loosens the validation checks when a NetworkAgent updates it
NetworkCapabilities: instead of checking that capabilities labeled as
"immutable" stay identical across updates, it is now accepted to change
immutable capabilities in a way that the new NetworkCapabilities
satisfies the old NetworkCapabilities.

This allows a NetworkAgent to update itself in order to match more
requests, but will still catch NetworkAgents that sends degradation
updates causing potentially requests to not match anymore.

Bug: 64125969
Test: runtest frameworks-net
Change-Id: I2a1b3f9c0be6415e40edc989d0c1b03b5631f7b1
This commit is contained in:
Hugo Benichi
2017-08-16 13:19:04 +09:00
parent 39a0b6b58e
commit 1ebf219ed9
2 changed files with 7 additions and 4 deletions

View File

@@ -770,7 +770,6 @@ public final class NetworkCapabilities implements Parcelable {
StringJoiner joiner = new StringJoiner(", "); StringJoiner joiner = new StringJoiner(", ");
// TODO: consider only enforcing that capabilities are not removed, allowing addition.
// Ignore NOT_METERED being added or removed as it is effectively dynamic. http://b/63326103 // Ignore NOT_METERED being added or removed as it is effectively dynamic. http://b/63326103
// TODO: properly support NOT_METERED as a mutable and requestable capability. // TODO: properly support NOT_METERED as a mutable and requestable capability.
final long mask = ~MUTABLE_CAPABILITIES & ~(1 << NET_CAPABILITY_NOT_METERED); final long mask = ~MUTABLE_CAPABILITIES & ~(1 << NET_CAPABILITY_NOT_METERED);

View File

@@ -4702,11 +4702,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
*/ */
private void updateCapabilities( private void updateCapabilities(
int oldScore, NetworkAgentInfo nai, NetworkCapabilities networkCapabilities) { int oldScore, NetworkAgentInfo nai, NetworkCapabilities networkCapabilities) {
// Sanity check: a NetworkAgent should not change its static capabilities or parameters. // Once a NetworkAgent is connected, complain if some immutable capabilities are removed.
if (nai.everConnected) { if (nai.everConnected &&
!nai.networkCapabilities.satisfiedByNetworkCapabilities(networkCapabilities)) {
// TODO: consider not complaining when a network agent degrade its capabilities if this
// does not cause any request (that is not a listen) currently matching that agent to
// stop being matched by the updated agent.
String diff = nai.networkCapabilities.describeImmutableDifferences(networkCapabilities); String diff = nai.networkCapabilities.describeImmutableDifferences(networkCapabilities);
if (!TextUtils.isEmpty(diff)) { if (!TextUtils.isEmpty(diff)) {
Slog.wtf(TAG, "BUG: " + nai + " changed immutable capabilities:" + diff); Slog.wtf(TAG, "BUG: " + nai + " lost immutable capabilities:" + diff);
} }
} }