[NS12] Address comments on NS09 am: 29cb06a3e0
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1727813 Change-Id: I7fc08dfe2babc2e0eea526436a52a8c2658f3624
This commit is contained in:
@@ -894,7 +894,7 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo>, NetworkRa
|
||||
// Caller must not mutate. This method is called frequently and making a defensive copy
|
||||
// would be too expensive. This is used by NetworkRanker.Scoreable, so it can be compared
|
||||
// against other scoreables.
|
||||
@Override public NetworkCapabilities getCaps() {
|
||||
@Override public NetworkCapabilities getCapsNoCopy() {
|
||||
return networkCapabilities;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ public class NetworkOffer implements NetworkRanker.Scoreable {
|
||||
/**
|
||||
* Get the capabilities filter of this offer
|
||||
*/
|
||||
@Override @NonNull public NetworkCapabilities getCaps() {
|
||||
@Override @NonNull public NetworkCapabilities getCapsNoCopy() {
|
||||
return caps;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public class NetworkRanker {
|
||||
/** Get score of this scoreable */
|
||||
FullScore getScore();
|
||||
/** Get capabilities of this scoreable */
|
||||
NetworkCapabilities getCaps();
|
||||
NetworkCapabilities getCapsNoCopy();
|
||||
}
|
||||
|
||||
private static final boolean USE_POLICY_RANKING = false;
|
||||
@@ -159,11 +159,12 @@ public class NetworkRanker {
|
||||
if (accepted.size() == 1) return accepted.get(0);
|
||||
if (accepted.size() > 0 && rejected.size() > 0) candidates = new ArrayList<>(accepted);
|
||||
|
||||
// Yield to bad wifi policy : if any wifi has ever been validated, keep only networks
|
||||
// that don't yield to such a wifi network.
|
||||
// Yield to bad wifi policy : if any wifi has ever been validated (even if it's now
|
||||
// unvalidated), and unless it's been explicitly avoided when bad in UI, then keep only
|
||||
// networks that don't yield to such a wifi network.
|
||||
final boolean anyWiFiEverValidated = CollectionUtils.any(candidates,
|
||||
nai -> nai.getScore().hasPolicy(POLICY_EVER_VALIDATED_NOT_AVOIDED_WHEN_BAD)
|
||||
&& nai.getCaps().hasTransport(TRANSPORT_WIFI));
|
||||
&& nai.getCapsNoCopy().hasTransport(TRANSPORT_WIFI));
|
||||
if (anyWiFiEverValidated) {
|
||||
partitionInto(candidates, nai -> !nai.getScore().hasPolicy(POLICY_YIELD_TO_BAD_WIFI),
|
||||
accepted, rejected);
|
||||
@@ -207,18 +208,18 @@ public class NetworkRanker {
|
||||
for (final Scoreable defaultSubNai : accepted) {
|
||||
// Remove all networks without the DEFAULT_SUBSCRIPTION policy and the same transports
|
||||
// as a network that has it.
|
||||
final int[] transports = defaultSubNai.getCaps().getTransportTypes();
|
||||
final int[] transports = defaultSubNai.getCapsNoCopy().getTransportTypes();
|
||||
candidates.removeIf(nai -> !nai.getScore().hasPolicy(POLICY_TRANSPORT_PRIMARY)
|
||||
&& Arrays.equals(transports, nai.getCaps().getTransportTypes()));
|
||||
&& Arrays.equals(transports, nai.getCapsNoCopy().getTransportTypes()));
|
||||
}
|
||||
if (1 == candidates.size()) return candidates.get(0);
|
||||
// It's guaranteed candidates.size() > 0 because there is at least one with DEFAULT_SUB
|
||||
// policy and only those without it were removed.
|
||||
// It's guaranteed candidates.size() > 0 because there is at least one with the
|
||||
// TRANSPORT_PRIMARY policy and only those without it were removed.
|
||||
|
||||
// If some of the networks have a better transport than others, keep only the ones with
|
||||
// the best transports.
|
||||
for (final int transport : PREFERRED_TRANSPORTS_ORDER) {
|
||||
partitionInto(candidates, nai -> nai.getCaps().hasTransport(transport),
|
||||
partitionInto(candidates, nai -> nai.getCapsNoCopy().hasTransport(transport),
|
||||
accepted, rejected);
|
||||
if (accepted.size() == 1) return accepted.get(0);
|
||||
if (accepted.size() > 0 && rejected.size() > 0) {
|
||||
|
||||
Reference in New Issue
Block a user