diff options
author | Michael Plass <mplass@google.com> | 2019-03-25 14:12:55 -0700 |
---|---|---|
committer | Michael Plass <mplass@google.com> | 2019-03-27 17:35:20 -0700 |
commit | 8b6340ca165e81a4f03b2f47f391fb75810142cb (patch) | |
tree | a270607080ece5ea7aaef930eb4dd627ef29d0c9 /service | |
parent | 05cb38257f509998b8945828c05671a7dc07622a (diff) |
WifiNetworkSelector: Allow default CandidateScorer
Allow a CandidateScorer to be used as the default.
This CL leaves the legacy scorer active. A follow-on will
use CompatibilityScorer as the default.
Also, the active CandidateScorer may now choose "none of the above".
Bug: 128937950
Bug: 126273496
Test: atest FrameworksWifiTests
Change-Id: Ia518e7c8a9d383de59985aa186de1e4fab990054
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiNetworkSelector.java | 137 |
1 files changed, 74 insertions, 63 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java index 0cb4dc055..a96f457bd 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSelector.java +++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java @@ -80,6 +80,11 @@ public class WifiNetworkSelector { public static final int WIFI_POOR_SCORE = ConnectedScore.WIFI_TRANSITION_SCORE - 10; /** + * The identifier string of the CandidateScorer to use (in the absence of overrides). + */ + public static final String PRESET_CANDIDATE_SCORER_NAME = null; + + /** * Experiment ID for the legacy scorer. */ public static final int LEGACY_CANDIDATE_SCORER_EXP_ID = 0; @@ -718,61 +723,60 @@ public class WifiNetworkSelector { } } - boolean legacyOverrideWanted = true; + ArrayMap<Integer, Integer> experimentNetworkSelections = new ArrayMap<>(); // for metrics - // Run any (experimental) CandidateScorers we have - try { - int activeExperimentId = LEGACY_CANDIDATE_SCORER_EXP_ID; // default legacy - ArrayMap<Integer, WifiConfiguration> experimentNetworkSelections = new ArrayMap<>(); - experimentNetworkSelections.put(activeExperimentId, selectedNetwork); + final int legacySelectedNetworkId = selectedNetwork == null + ? WifiConfiguration.INVALID_NETWORK_ID + : selectedNetwork.networkId; - for (WifiCandidates.CandidateScorer candidateScorer : mCandidateScorers.values()) { - String id = candidateScorer.getIdentifier(); - int expid = experimentIdFromIdentifier(id); - WifiCandidates.ScoredCandidate choice = wifiCandidates.choose(candidateScorer); - if (choice.candidateKey != null) { - boolean thisOne = (expid == mScoringParams.getExperimentIdentifier()); - localLog(id + (thisOne ? " chooses " : " would choose ") - + choice.candidateKey.networkId - + " score " + choice.value + "+/-" + choice.err - + " expid " + expid); - int networkId = choice.candidateKey.networkId; - WifiConfiguration thisSelectedNetwork = - mWifiConfigManager.getConfiguredNetwork(networkId); - experimentNetworkSelections.put(expid, thisSelectedNetwork); - if (thisOne) { // update selected network only if this experiment is active - activeExperimentId = expid; // ensures that experiment id actually exists - selectedNetwork = thisSelectedNetwork; - legacyOverrideWanted = candidateScorer.userConnectChoiceOverrideWanted(); - Log.i(TAG, id + " chooses " + networkId); - } - } else { - localLog(candidateScorer.getIdentifier() + " found no candidates"); - experimentNetworkSelections.put(expid, null); - } - } + int selectedNetworkId = legacySelectedNetworkId; - for (Map.Entry<Integer, WifiConfiguration> entry : - experimentNetworkSelections.entrySet()) { - int experimentId = entry.getKey(); - if (experimentId == activeExperimentId) continue; - WifiConfiguration thisSelectedNetwork = entry.getValue(); - mWifiMetrics.logNetworkSelectionDecision(experimentId, activeExperimentId, - isSameNetworkSelection(selectedNetwork, thisSelectedNetwork), - groupedCandidates.size()); + // Run all the CandidateScorers + boolean legacyOverrideWanted = true; + final WifiCandidates.CandidateScorer activeScorer = getActiveCandidateScorer(); + for (WifiCandidates.CandidateScorer candidateScorer : mCandidateScorers.values()) { + WifiCandidates.ScoredCandidate choice; + try { + choice = wifiCandidates.choose(candidateScorer); + } catch (RuntimeException e) { + Log.wtf(TAG, "Exception running a CandidateScorer", e); + continue; } - } catch (RuntimeException e) { - Log.wtf(TAG, "Exception running a CandidateScorer, disabling", e); - mCandidateScorers.clear(); - } - - if (selectedNetwork != null) { - // Update the copy of WifiConfiguration to reflect the scan result candidate update - // above. - selectedNetwork = mWifiConfigManager.getConfiguredNetwork(selectedNetwork.networkId); - if (selectedNetwork != null && legacyOverrideWanted) { - selectedNetwork = overrideCandidateWithUserConnectChoice(selectedNetwork); + int networkId = choice.candidateKey == null + ? WifiConfiguration.INVALID_NETWORK_ID + : choice.candidateKey.networkId; + String chooses = " would choose "; + if (candidateScorer == activeScorer) { + chooses = " chooses "; + legacyOverrideWanted = candidateScorer.userConnectChoiceOverrideWanted(); + selectedNetworkId = networkId; } + String id = candidateScorer.getIdentifier(); + int expid = experimentIdFromIdentifier(id); + localLog(id + chooses + networkId + + " score " + choice.value + "+/-" + choice.err + + " expid " + expid); + experimentNetworkSelections.put(expid, networkId); + } + + // Update metrics about differences in the selections made by various methods + final int activeExperimentId = activeScorer == null ? LEGACY_CANDIDATE_SCORER_EXP_ID + : experimentIdFromIdentifier(activeScorer.getIdentifier()); + experimentNetworkSelections.put(LEGACY_CANDIDATE_SCORER_EXP_ID, legacySelectedNetworkId); + for (Map.Entry<Integer, Integer> entry : + experimentNetworkSelections.entrySet()) { + int experimentId = entry.getKey(); + if (experimentId == activeExperimentId) continue; + int thisSelectedNetworkId = entry.getValue(); + mWifiMetrics.logNetworkSelectionDecision(experimentId, activeExperimentId, + selectedNetworkId == thisSelectedNetworkId, + groupedCandidates.size()); + } + + // Get a fresh copy of WifiConfiguration reflecting any scan result updates + selectedNetwork = mWifiConfigManager.getConfiguredNetwork(selectedNetworkId); + if (selectedNetwork != null && legacyOverrideWanted) { + selectedNetwork = overrideCandidateWithUserConnectChoice(selectedNetwork); mLastNetworkSelectionTimeStamp = mClock.getElapsedSinceBootMillis(); } return selectedNetwork; @@ -796,18 +800,6 @@ public class WifiNetworkSelector { } } - private static boolean isSameNetworkSelection(WifiConfiguration c1, WifiConfiguration c2) { - if (c1 == null && c2 == null) { - return true; - } else if (c1 == null && c2 != null) { - return false; - } else if (c1 != null && c2 == null) { - return false; - } else { - return c1.networkId == c2.networkId; - } - } - private double calculateLastSelectionWeight() { final int lastUserSelectedNetworkId = mWifiConfigManager.getLastSelectedNetwork(); double lastSelectionWeight = 0.0; @@ -820,6 +812,24 @@ public class WifiNetworkSelector { return lastSelectionWeight; } + private WifiCandidates.CandidateScorer getActiveCandidateScorer() { + WifiCandidates.CandidateScorer ans = mCandidateScorers.get(PRESET_CANDIDATE_SCORER_NAME); + int overrideExperimentId = mScoringParams.getExperimentIdentifier(); + if (overrideExperimentId >= MIN_SCORER_EXP_ID) { + for (WifiCandidates.CandidateScorer candidateScorer : mCandidateScorers.values()) { + int expId = experimentIdFromIdentifier(candidateScorer.getIdentifier()); + if (expId == overrideExperimentId) { + ans = candidateScorer; + break; + } + } + } + if (ans == null && PRESET_CANDIDATE_SCORER_NAME != null) { + Log.wtf(TAG, PRESET_CANDIDATE_SCORER_NAME + " is not registered!"); + } + return ans; + } + /** * Register a network evaluator * @@ -853,7 +863,7 @@ public class WifiNetworkSelector { } /** - * Derives a numeric experiment identifer from a CandidateScorer's identifier. + * Derives a numeric experiment identifier from a CandidateScorer's identifier. * * @returns a positive number that starts with the decimal digits ID_PREFIX */ @@ -863,6 +873,7 @@ public class WifiNetworkSelector { } private static final int ID_SUFFIX_MOD = 1_000_000; private static final int ID_PREFIX = 42; + private static final int MIN_SCORER_EXP_ID = ID_PREFIX * ID_SUFFIX_MOD; WifiNetworkSelector(Context context, WifiScoreCard wifiScoreCard, ScoringParams scoringParams, WifiConfigManager configManager, Clock clock, LocalLog localLog, |