diff options
author | Michael Plass <mplass@google.com> | 2019-10-08 15:40:20 -0700 |
---|---|---|
committer | Michael Plass <mplass@google.com> | 2019-10-24 17:21:37 -0700 |
commit | a50d9fa7c2ed677a494b471a8f94d2920681b283 (patch) | |
tree | 9ff2f6fece7f72aa8e78bfb536a89995f70de7f1 /service | |
parent | 83a3850789d254d566a7f4108d83c76e650e60a4 (diff) |
[WifiCandidates] Simpler scoreCandidates interface
There's no real advantage in grouping the candidates by network before
passing them to CandidateScorer.scoreCandidates, and potentially more
flexibility in presenting all candidates together.
Bug: 136675430
Test: atest FrameworksWifiTests
Change-Id: I0dc8773540fab428b7a4243442c83ca65a6fe34d
Diffstat (limited to 'service')
4 files changed, 12 insertions, 18 deletions
diff --git a/service/java/com/android/server/wifi/BubbleFunScorer.java b/service/java/com/android/server/wifi/BubbleFunScorer.java index e5bda737c..b5da5f03e 100644 --- a/service/java/com/android/server/wifi/BubbleFunScorer.java +++ b/service/java/com/android/server/wifi/BubbleFunScorer.java @@ -117,9 +117,9 @@ final class BubbleFunScorer implements WifiCandidates.CandidateScorer { } @Override - public ScoredCandidate scoreCandidates(@NonNull Collection<Candidate> group) { + public ScoredCandidate scoreCandidates(@NonNull Collection<Candidate> candidates) { ScoredCandidate choice = ScoredCandidate.NONE; - for (Candidate candidate : group) { + for (Candidate candidate : candidates) { ScoredCandidate scoredCandidate = scoreCandidate(candidate); if (scoredCandidate.value > choice.value) { choice = scoredCandidate; diff --git a/service/java/com/android/server/wifi/CompatibilityScorer.java b/service/java/com/android/server/wifi/CompatibilityScorer.java index 26ff1c293..1bb55b9a2 100644 --- a/service/java/com/android/server/wifi/CompatibilityScorer.java +++ b/service/java/com/android/server/wifi/CompatibilityScorer.java @@ -102,9 +102,9 @@ final class CompatibilityScorer implements WifiCandidates.CandidateScorer { } @Override - public ScoredCandidate scoreCandidates(@NonNull Collection<Candidate> group) { + public ScoredCandidate scoreCandidates(@NonNull Collection<Candidate> candidates) { ScoredCandidate choice = ScoredCandidate.NONE; - for (Candidate candidate : group) { + for (Candidate candidate : candidates) { ScoredCandidate scoredCandidate = scoreCandidate(candidate); if (scoredCandidate.value > choice.value) { choice = scoredCandidate; diff --git a/service/java/com/android/server/wifi/ScoreCardBasedScorer.java b/service/java/com/android/server/wifi/ScoreCardBasedScorer.java index 7e290caca..96c8e6c09 100644 --- a/service/java/com/android/server/wifi/ScoreCardBasedScorer.java +++ b/service/java/com/android/server/wifi/ScoreCardBasedScorer.java @@ -124,9 +124,9 @@ final class ScoreCardBasedScorer implements WifiCandidates.CandidateScorer { } @Override - public ScoredCandidate scoreCandidates(@NonNull Collection<Candidate> group) { + public ScoredCandidate scoreCandidates(@NonNull Collection<Candidate> candidates) { ScoredCandidate choice = ScoredCandidate.NONE; - for (Candidate candidate : group) { + for (Candidate candidate : candidates) { ScoredCandidate scoredCandidate = scoreCandidate(candidate); if (scoredCandidate.value > choice.value) { choice = scoredCandidate; diff --git a/service/java/com/android/server/wifi/WifiCandidates.java b/service/java/com/android/server/wifi/WifiCandidates.java index 334b8d83b..ec34b6ece 100644 --- a/service/java/com/android/server/wifi/WifiCandidates.java +++ b/service/java/com/android/server/wifi/WifiCandidates.java @@ -260,10 +260,9 @@ public class WifiCandidates { String getIdentifier(); /** - * Calculates the score for a group of candidates that belong - * to the same network. + * Calculates the best score for a collection of candidates. */ - @Nullable ScoredCandidate scoreCandidates(@NonNull Collection<Candidate> group); + @Nullable ScoredCandidate scoreCandidates(@NonNull Collection<Candidate> candidates); } @@ -404,7 +403,7 @@ public class WifiCandidates { */ public boolean remove(Candidate candidate) { if (!(candidate instanceof CandidateImpl)) return failure(); - return mCandidates.remove(((CandidateImpl) candidate).key, (CandidateImpl) candidate); + return mCandidates.remove(((CandidateImpl) candidate).key, candidate); } /** @@ -437,14 +436,9 @@ public class WifiCandidates { */ public @NonNull ScoredCandidate choose(@NonNull CandidateScorer candidateScorer) { Preconditions.checkNotNull(candidateScorer); - ScoredCandidate choice = ScoredCandidate.NONE; - for (Collection<Candidate> group : getGroupedCandidates()) { - ScoredCandidate scoredCandidate = candidateScorer.scoreCandidates(group); - if (scoredCandidate != null && scoredCandidate.value > choice.value) { - choice = scoredCandidate; - } - } - return choice; + Collection<Candidate> candidates = new ArrayList<>(mCandidates.values()); + ScoredCandidate choice = candidateScorer.scoreCandidates(candidates); + return choice == null ? ScoredCandidate.NONE : choice; } /** |