[NS12] Address comments on NS09

Test: ConnectivityServiceTest
Fixes: 184507247
Merged-In: I3c2563d4ae4e3715d0c6270344ba8f7ef067872f
Merged-In: Ic4500dc85507fa68538c9ec179ec6eb4f44c5022
Change-Id: Ic4500dc85507fa68538c9ec179ec6eb4f44c5022
  (cherry-picked from ag/14091168)
This commit is contained in:
Chalard Jean
2021-04-05 17:35:32 +09:00
committed by Junyu Lai
parent 142f0fe4d4
commit 29cb06a3e0
3 changed files with 12 additions and 11 deletions

View File

@@ -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 // 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 // would be too expensive. This is used by NetworkRanker.Scoreable, so it can be compared
// against other scoreables. // against other scoreables.
@Override public NetworkCapabilities getCaps() { @Override public NetworkCapabilities getCapsNoCopy() {
return networkCapabilities; return networkCapabilities;
} }

View File

@@ -76,7 +76,7 @@ public class NetworkOffer implements NetworkRanker.Scoreable {
/** /**
* Get the capabilities filter of this offer * Get the capabilities filter of this offer
*/ */
@Override @NonNull public NetworkCapabilities getCaps() { @Override @NonNull public NetworkCapabilities getCapsNoCopy() {
return caps; return caps;
} }

View File

@@ -59,7 +59,7 @@ public class NetworkRanker {
/** Get score of this scoreable */ /** Get score of this scoreable */
FullScore getScore(); FullScore getScore();
/** Get capabilities of this scoreable */ /** Get capabilities of this scoreable */
NetworkCapabilities getCaps(); NetworkCapabilities getCapsNoCopy();
} }
private static final boolean USE_POLICY_RANKING = false; 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() == 1) return accepted.get(0);
if (accepted.size() > 0 && rejected.size() > 0) candidates = new ArrayList<>(accepted); 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 // Yield to bad wifi policy : if any wifi has ever been validated (even if it's now
// that don't yield to such a wifi network. // 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, final boolean anyWiFiEverValidated = CollectionUtils.any(candidates,
nai -> nai.getScore().hasPolicy(POLICY_EVER_VALIDATED_NOT_AVOIDED_WHEN_BAD) nai -> nai.getScore().hasPolicy(POLICY_EVER_VALIDATED_NOT_AVOIDED_WHEN_BAD)
&& nai.getCaps().hasTransport(TRANSPORT_WIFI)); && nai.getCapsNoCopy().hasTransport(TRANSPORT_WIFI));
if (anyWiFiEverValidated) { if (anyWiFiEverValidated) {
partitionInto(candidates, nai -> !nai.getScore().hasPolicy(POLICY_YIELD_TO_BAD_WIFI), partitionInto(candidates, nai -> !nai.getScore().hasPolicy(POLICY_YIELD_TO_BAD_WIFI),
accepted, rejected); accepted, rejected);
@@ -207,18 +208,18 @@ public class NetworkRanker {
for (final Scoreable defaultSubNai : accepted) { for (final Scoreable defaultSubNai : accepted) {
// Remove all networks without the DEFAULT_SUBSCRIPTION policy and the same transports // Remove all networks without the DEFAULT_SUBSCRIPTION policy and the same transports
// as a network that has it. // 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) 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); if (1 == candidates.size()) return candidates.get(0);
// It's guaranteed candidates.size() > 0 because there is at least one with DEFAULT_SUB // It's guaranteed candidates.size() > 0 because there is at least one with the
// policy and only those without it were removed. // 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 // If some of the networks have a better transport than others, keep only the ones with
// the best transports. // the best transports.
for (final int transport : PREFERRED_TRANSPORTS_ORDER) { for (final int transport : PREFERRED_TRANSPORTS_ORDER) {
partitionInto(candidates, nai -> nai.getCaps().hasTransport(transport), partitionInto(candidates, nai -> nai.getCapsNoCopy().hasTransport(transport),
accepted, rejected); accepted, rejected);
if (accepted.size() == 1) return accepted.get(0); if (accepted.size() == 1) return accepted.get(0);
if (accepted.size() > 0 && rejected.size() > 0) { if (accepted.size() > 0 && rejected.size() > 0) {