summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorNate(Qiang) Jiang <qiangjiang@google.com>2019-11-15 10:58:28 -0800
committerNate(Qiang) Jiang <qiangjiang@google.com>2019-12-09 10:23:17 -0800
commit86a674e2d4fa10e36d3897c61ea827338ef9903b (patch)
tree29acaee52f2e56a60535baddf74011a1552f85cf /service
parenta669e034decb682f145e089cec6c204b09e0c07c (diff)
[Evaluator] evaluator will only nominate candidates
As all score will be handles by scorer, remove the evaluate function from each evaluator. evaluator will only nominate candidates to the scorer. Bug: 141019662 Test: atest android.net.wifi Test: atest com.android.server.wifi Change-Id: I996dd19aa0e67051fe8003d7c621e4f75f73db38
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/CarrierNetworkEvaluator.java19
-rw-r--r--service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java51
-rw-r--r--service/java/com/android/server/wifi/SavedNetworkEvaluator.java158
-rw-r--r--service/java/com/android/server/wifi/ScoredNetworkEvaluator.java12
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java5
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkSelector.java51
-rw-r--r--service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java89
7 files changed, 49 insertions, 336 deletions
diff --git a/service/java/com/android/server/wifi/CarrierNetworkEvaluator.java b/service/java/com/android/server/wifi/CarrierNetworkEvaluator.java
index c9f567e89..e9f6a48ca 100644
--- a/service/java/com/android/server/wifi/CarrierNetworkEvaluator.java
+++ b/service/java/com/android/server/wifi/CarrierNetworkEvaluator.java
@@ -37,10 +37,7 @@ import javax.annotation.concurrent.NotThreadSafe;
*
* 1. Filtering: figure out which of the networks is a Carrier Wi-Fi network (using the
* {@link CarrierNetworkConfig} APIs).
- * 2. Evaluation: current evaluator API has 2 outputs (effectively):
- * - Connectable networks: all networks which match #1 will be fed to this API
- * - Selected network: a single network 'selected' by the evaluator. A simple max(RSSI) will be
- * used to pick one network from among the connectable networks.
+ * 2. Nominating: Connectable networks: all networks which match #1 will be fed to this API
*
* Note: This class is not thread safe and meant to be used only from {@link WifiNetworkSelector}.
*/
@@ -86,15 +83,13 @@ public class CarrierNetworkEvaluator implements NetworkEvaluator {
}
@Override
- public WifiConfiguration evaluateNetworks(List<ScanDetail> scanDetails,
+ public void evaluateNetworks(List<ScanDetail> scanDetails,
WifiConfiguration currentNetwork, String currentBssid, boolean connected,
boolean untrustedNetworkAllowed, OnConnectableListener onConnectableListener) {
if (!mCarrierNetworkConfig.isCarrierEncryptionInfoAvailable()) {
- return null;
+ return;
}
- int currentMaxRssi = Integer.MIN_VALUE;
- WifiConfiguration configWithMaxRssi = null;
for (ScanDetail scanDetail : scanDetails) {
ScanResult scanResult = scanDetail.getScanResult();
@@ -168,13 +163,7 @@ public class CarrierNetworkEvaluator implements NetworkEvaluator {
mWifiConfigManager.updateScanDetailForNetwork(result.getNetworkId(), scanDetail);
}
- onConnectableListener.onConnectable(scanDetail, config, 0);
- if (scanResult.level > currentMaxRssi) {
- configWithMaxRssi = config;
- currentMaxRssi = scanResult.level;
- }
+ onConnectableListener.onConnectable(scanDetail, config);
}
-
- return configWithMaxRssi;
}
}
diff --git a/service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java b/service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java
index c8f370bcc..9d13e3c56 100644
--- a/service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java
+++ b/service/java/com/android/server/wifi/NetworkSuggestionEvaluator.java
@@ -28,7 +28,6 @@ import com.android.server.wifi.util.ScanResultUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -39,20 +38,11 @@ import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;
/**
- * Evaluator to pick the best network to connect to from the list of active network suggestions
- * provided by apps.
+ * Evaluator nominate the highest available suggestion candidates.
* Note:
* <li> This class is not thread safe and meant to be used only from {@link WifiNetworkSelector}.
* </li>
*
- * This is a non-optimal implementation which picks any network suggestion which matches
- * the scan result with the highest RSSI.
- * TODO: More advanced implementation will follow!
- * Params to consider for evaluating network suggestions:
- * - Regular network evaluator params like security, band, RSSI, etc.
- * - Priority of suggestions provided by a single app.
- * - Whether the network suggestions requires user/app interaction or if it is metered.
- * - Historical quality of suggestions provided by the corresponding app.
*/
@NotThreadSafe
public class NetworkSuggestionEvaluator implements WifiNetworkSelector.NetworkEvaluator {
@@ -75,7 +65,7 @@ public class NetworkSuggestionEvaluator implements WifiNetworkSelector.NetworkEv
}
@Override
- public WifiConfiguration evaluateNetworks(List<ScanDetail> scanDetails,
+ public void evaluateNetworks(List<ScanDetail> scanDetails,
WifiConfiguration currentNetwork, String currentBssid, boolean connected,
boolean untrustedNetworkAllowed,
@NonNull OnConnectableListener onConnectableListener) {
@@ -133,17 +123,9 @@ public class NetworkSuggestionEvaluator implements WifiNetworkSelector.NetworkEv
// Return early on no match.
if (matchMetaInfo.isEmpty()) {
mLocalLog.log("did not see any matching network suggestions.");
- return null;
- }
- // Note: These matched sets should be very small & hence these additional manipulations that
- // follow should not be very expensive.
- PerNetworkSuggestionMatchMetaInfo candidate =
- matchMetaInfo.findConnectableNetworksAndPickBest(onConnectableListener);
- if (candidate == null) { // should never happen.
- Log.wtf(TAG, "Unexepectedly got null");
- return null;
+ return;
}
- return candidate.wCmConfiguredNetwork;
+ matchMetaInfo.findConnectableNetworksAndHighestPriority(onConnectableListener);
}
// Add and enable this network to the central database (i.e WifiConfigManager).
@@ -263,16 +245,11 @@ public class NetworkSuggestionEvaluator implements WifiNetworkSelector.NetworkEv
}
/**
- * Find all the connectable networks and pick the best network among the current match info
- * candidates.
- *
- * Among the highest priority suggestions from different packages, choose the suggestion
- * with the highest RSSI.
- * Note: This should need to be replaced by a more sophisticated algorithm.
+ * Run through all connectable suggestions and nominate highest priority networks from each
+ * app as candidates to {@link WifiNetworkSelector}.
*/
- public PerNetworkSuggestionMatchMetaInfo findConnectableNetworksAndPickBest(
+ public void findConnectableNetworksAndHighestPriority(
@NonNull OnConnectableListener onConnectableListener) {
- List<PerNetworkSuggestionMatchMetaInfo> allMatchedNetworkInfos = new ArrayList<>();
for (PerAppMatchMetaInfo appInfo : mAppInfos.values()) {
List<PerNetworkSuggestionMatchMetaInfo> matchedNetworkInfos =
appInfo.getHighestPriorityNetworks();
@@ -292,23 +269,11 @@ public class NetworkSuggestionEvaluator implements WifiNetworkSelector.NetworkEv
WifiNetworkSelector.toNetworkString(
matchedNetworkInfo.wCmConfiguredNetwork)));
}
- allMatchedNetworkInfos.add(matchedNetworkInfo);
- // Invoke onConnectable for the best networks from each app.
onConnectableListener.onConnectable(
matchedNetworkInfo.matchingScanDetail,
- matchedNetworkInfo.wCmConfiguredNetwork,
- 0);
+ matchedNetworkInfo.wCmConfiguredNetwork);
}
}
- PerNetworkSuggestionMatchMetaInfo networkInfo = allMatchedNetworkInfos
- .stream()
- .max(Comparator.comparing(e -> e.matchingScanDetail.getScanResult().level))
- .orElse(null);
- if (networkInfo == null) { // should never happen.
- Log.wtf(TAG, "Unexepectedly got null");
- return null;
- }
- return networkInfo;
}
}
diff --git a/service/java/com/android/server/wifi/SavedNetworkEvaluator.java b/service/java/com/android/server/wifi/SavedNetworkEvaluator.java
index d3254790b..3ceafc8e6 100644
--- a/service/java/com/android/server/wifi/SavedNetworkEvaluator.java
+++ b/service/java/com/android/server/wifi/SavedNetworkEvaluator.java
@@ -17,14 +17,11 @@
package com.android.server.wifi;
import android.annotation.NonNull;
-import android.content.Context;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.util.LocalLog;
-import com.android.internal.annotations.VisibleForTesting;
import com.android.server.wifi.util.TelephonyUtil;
-import com.android.wifi.resources.R;
import java.util.List;
@@ -35,32 +32,14 @@ import java.util.List;
public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluator {
private static final String NAME = "SavedNetworkEvaluator";
private final WifiConfigManager mWifiConfigManager;
- private final Context mContext;
- private final Clock mClock;
private final LocalLog mLocalLog;
- private final WifiConnectivityHelper mConnectivityHelper;
private final TelephonyUtil mTelephonyUtil;
- private final ScoringParams mScoringParams;
- /**
- * Time it takes for the lastSelectionAward to decay by one point, in milliseconds
- */
- @VisibleForTesting
- public static final int LAST_SELECTION_AWARD_DECAY_MSEC = 60 * 1000;
-
-
- SavedNetworkEvaluator(final Context context, ScoringParams scoringParams,
- WifiConfigManager configManager, Clock clock,
- LocalLog localLog, WifiConnectivityHelper connectivityHelper,
+ SavedNetworkEvaluator(WifiConfigManager configManager, LocalLog localLog,
TelephonyUtil telephonyUtil) {
- mContext = context;
- mScoringParams = scoringParams;
mWifiConfigManager = configManager;
- mClock = clock;
mLocalLog = localLog;
- mConnectivityHelper = connectivityHelper;
mTelephonyUtil = telephonyUtil;
-
}
private void localLog(String log) {
@@ -89,109 +68,15 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat
@Override
public void update(List<ScanDetail> scanDetails) { }
- private int calculateBssidScore(ScanResult scanResult, WifiConfiguration network,
- WifiConfiguration currentNetwork, String currentBssid,
- StringBuffer sbuf) {
- int score = 0;
- boolean is5GHz = scanResult.is5GHz();
- boolean is6GHz = scanResult.is6GHz();
-
- final int rssiScoreSlope = mContext.getResources().getInteger(
- R.integer.config_wifi_framework_RSSI_SCORE_SLOPE);
- final int rssiScoreOffset = mContext.getResources().getInteger(
- R.integer.config_wifi_framework_RSSI_SCORE_OFFSET);
- final int sameBssidAward = mContext.getResources().getInteger(
- R.integer.config_wifi_framework_SAME_BSSID_AWARD);
- final int sameNetworkAward = mContext.getResources().getInteger(
- R.integer.config_wifi_framework_current_network_boost);
- final int lastSelectionAward = mContext.getResources().getInteger(
- R.integer.config_wifi_framework_LAST_SELECTION_AWARD);
- final int securityAward = mContext.getResources().getInteger(
- R.integer.config_wifi_framework_SECURITY_AWARD);
- final int band5GHzAward = mContext.getResources().getInteger(
- R.integer.config_wifi_framework_5GHz_preference_boost_factor);
- final int band6GHzAward = mContext.getResources().getInteger(
- R.integer.config_wifiFramework6ghzPreferenceBoostFactor);
-
- sbuf.append("[ ").append(scanResult.SSID).append(" ").append(scanResult.BSSID)
- .append(" RSSI:").append(scanResult.level).append(" ] ");
- // Calculate the RSSI score.
- int rssiSaturationThreshold = mScoringParams.getGoodRssi(scanResult.frequency);
- int rssi = Math.min(scanResult.level, rssiSaturationThreshold);
- score += (rssi + rssiScoreOffset) * rssiScoreSlope;
- sbuf.append(" RSSI score: ").append(score).append(",");
-
- // 5GHz band bonus.
- if (is5GHz) {
- score += band5GHzAward;
- sbuf.append(" 5GHz bonus: ").append(band5GHzAward).append(",");
- } else if (is6GHz) {
- score += band6GHzAward;
- sbuf.append(" 6GHz bonus: ").append(band6GHzAward).append(",");
- }
-
- // Last user selection award.
- int lastUserSelectedNetworkId = mWifiConfigManager.getLastSelectedNetwork();
- if (lastUserSelectedNetworkId != WifiConfiguration.INVALID_NETWORK_ID
- && lastUserSelectedNetworkId == network.networkId) {
- long timeDifference = mClock.getElapsedSinceBootMillis()
- - mWifiConfigManager.getLastSelectedTimeStamp();
- if (timeDifference > 0) {
- int decay = (int) (timeDifference / LAST_SELECTION_AWARD_DECAY_MSEC);
- int bonus = Math.max(lastSelectionAward - decay, 0);
- score += bonus;
- sbuf.append(" User selection ").append(timeDifference)
- .append(" ms ago, bonus: ").append(bonus).append(",");
- }
- }
-
- // Same network award.
- if (currentNetwork != null && network.networkId == currentNetwork.networkId) {
- score += sameNetworkAward;
- sbuf.append(" Same network bonus: ").append(sameNetworkAward).append(",");
-
- // When firmware roaming is supported, equivalent BSSIDs (the ones under the
- // same network as the currently connected one) get the same BSSID award.
- if (mConnectivityHelper.isFirmwareRoamingSupported()
- && currentBssid != null && !currentBssid.equals(scanResult.BSSID)) {
- score += sameBssidAward;
- sbuf.append(" Equivalent BSSID bonus: ").append(sameBssidAward).append(",");
- }
- }
-
- // Same BSSID award.
- if (currentBssid != null && currentBssid.equals(scanResult.BSSID)) {
- score += sameBssidAward;
- sbuf.append(" Same BSSID bonus: ").append(sameBssidAward).append(",");
- }
-
- // Security award.
- if (!WifiConfigurationUtil.isConfigForOpenNetwork(network)) {
- score += securityAward;
- sbuf.append(" Secure network bonus: ").append(securityAward).append(",");
- }
-
- sbuf.append(" ## Total score: ").append(score).append("\n");
-
- return score;
- }
-
/**
- * Evaluate all the networks from the scan results and return
- * the WifiConfiguration of the network chosen for connection.
+ * Run through all scanDetails and nominate all connectable network as candidates.
*
- * @return configuration of the chosen network;
- * null if no network in this category is available.
*/
@Override
- public WifiConfiguration evaluateNetworks(List<ScanDetail> scanDetails,
+ public void evaluateNetworks(List<ScanDetail> scanDetails,
WifiConfiguration currentNetwork, String currentBssid, boolean connected,
boolean untrustedNetworkAllowed,
@NonNull OnConnectableListener onConnectableListener) {
- int highestScore = Integer.MIN_VALUE;
- ScanResult scanResultCandidate = null;
- WifiConfiguration candidate = null;
- StringBuffer scoreHistory = new StringBuffer();
for (ScanDetail scanDetail : scanDetails) {
ScanResult scanResult = scanDetail.getScanResult();
@@ -247,19 +132,6 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat
}
}
- int score = calculateBssidScore(scanResult, network, currentNetwork, currentBssid,
- scoreHistory);
-
- // Set candidate ScanResult for all saved networks to ensure that users can
- // override network selection. See WifiNetworkSelector#setUserConnectChoice.
- if (score > status.getCandidateScore()
- || (score == status.getCandidateScore()
- && status.getCandidate() != null
- && scanResult.level > status.getCandidate().level)) {
- mWifiConfigManager.setNetworkCandidateScanResult(
- network.networkId, scanResult, score);
- }
-
// If the network is marked to use external scores, or is an open network with
// curate saved open networks enabled, do not consider it for network selection.
if (network.useExternalScores) {
@@ -269,29 +141,7 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat
}
onConnectableListener.onConnectable(scanDetail,
- mWifiConfigManager.getConfiguredNetwork(network.networkId), score);
-
- // TODO(b/112196799) - pull into common code
- if (score > highestScore
- || (score == highestScore
- && scanResultCandidate != null
- && scanResult.level > scanResultCandidate.level)) {
- highestScore = score;
- scanResultCandidate = scanResult;
- mWifiConfigManager.setNetworkCandidateScanResult(
- network.networkId, scanResultCandidate, highestScore);
- // Reload the network config with the updated info.
- candidate = mWifiConfigManager.getConfiguredNetwork(network.networkId);
- }
- }
-
- if (scoreHistory.length() > 0) {
- localLog("\n" + scoreHistory.toString());
- }
-
- if (scanResultCandidate == null) {
- localLog("did not see any good candidates.");
+ mWifiConfigManager.getConfiguredNetwork(network.networkId));
}
- return candidate;
}
}
diff --git a/service/java/com/android/server/wifi/ScoredNetworkEvaluator.java b/service/java/com/android/server/wifi/ScoredNetworkEvaluator.java
index 000d1f69e..60bbd5b82 100644
--- a/service/java/com/android/server/wifi/ScoredNetworkEvaluator.java
+++ b/service/java/com/android/server/wifi/ScoredNetworkEvaluator.java
@@ -131,13 +131,13 @@ public class ScoredNetworkEvaluator implements WifiNetworkSelector.NetworkEvalua
}
@Override
- public WifiConfiguration evaluateNetworks(List<ScanDetail> scanDetails,
+ public void evaluateNetworks(List<ScanDetail> scanDetails,
WifiConfiguration currentNetwork, String currentBssid, boolean connected,
boolean untrustedNetworkAllowed,
@NonNull OnConnectableListener onConnectableListener) {
if (!mNetworkRecommendationsEnabled) {
mLocalLog.log("Skipping evaluateNetworks; Network recommendations disabled.");
- return null;
+ return;
}
final ScoreTracker scoreTracker = new ScoreTracker();
@@ -188,11 +188,9 @@ public class ScoredNetworkEvaluator implements WifiNetworkSelector.NetworkEvalua
scoreTracker.trackExternallyScoredCandidate(
scanResult, configuredNetwork, isCurrentNetwork);
}
- onConnectableListener.onConnectable(scanDetail, configuredNetwork, 0);
+ onConnectableListener.onConnectable(scanDetail, configuredNetwork);
}
-
-
- return scoreTracker.getCandidateConfiguration(onConnectableListener);
+ scoreTracker.getCandidateConfiguration(onConnectableListener);
}
/** Used to track the network with the highest score. */
@@ -347,7 +345,7 @@ public class ScoredNetworkEvaluator implements WifiNetworkSelector.NetworkEvalua
candidateNetworkId);
if (ans != null && mScanDetailCandidate != null) {
// This is a newly created config, so we need to call onConnectable.
- onConnectableListener.onConnectable(mScanDetailCandidate, ans, 0);
+ onConnectableListener.onConnectable(mScanDetailCandidate, ans);
}
return ans;
}
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index bd2a435d1..aab7905a2 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -288,9 +288,8 @@ public class WifiInjector {
ThroughputScorer throughputScorer = new ThroughputScorer(mScoringParams);
mWifiNetworkSelector.registerCandidateScorer(throughputScorer);
mWifiMetrics.setWifiNetworkSelector(mWifiNetworkSelector);
- mSavedNetworkEvaluator = new SavedNetworkEvaluator(mContext, mScoringParams,
- mWifiConfigManager, mClock, mConnectivityLocalLog, mWifiConnectivityHelper,
- mTelephonyUtil);
+ mSavedNetworkEvaluator = new SavedNetworkEvaluator(
+ mWifiConfigManager, mConnectivityLocalLog, mTelephonyUtil);
mWifiNetworkSuggestionsManager = new WifiNetworkSuggestionsManager(mContext, wifiHandler,
this, mWifiPermissionsUtil, mWifiConfigManager, mWifiConfigStore, mWifiMetrics,
mTelephonyUtil);
diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java
index 433fd0b01..27e874a85 100644
--- a/service/java/com/android/server/wifi/WifiNetworkSelector.java
+++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java
@@ -29,7 +29,6 @@ import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.text.TextUtils;
import android.util.ArrayMap;
-import android.util.ArraySet;
import android.util.LocalLog;
import android.util.Log;
import android.util.Pair;
@@ -125,8 +124,7 @@ public class WifiNetworkSelector {
/**
* WiFi Network Selector supports various categories of networks. Each category
- * has an evaluator to choose the best WiFi network to connect to. Evaluators
- * should be registered in order, by decreasing importance.
+ * has an evaluator to choose the best WiFi network to connect to.
* Wifi Network Selector iterates through the registered scorers in registration order
* before making a final selection from among the candidates.
*/
@@ -134,8 +132,7 @@ public class WifiNetworkSelector {
/**
* Interface for WiFi Network Evaluator
*
- * A network evaluator examines the scan results and recommends the
- * best network in its category to connect to; it also reports the
+ * A network evaluator examines the scan results reports the
* connectable candidates in its category for further consideration.
*/
public interface NetworkEvaluator {
@@ -189,11 +186,8 @@ public class WifiNetworkSelector {
* ephemeral networks are allowed
* @param onConnectableListener callback to record all of the connectable networks
*
- * @return configuration of the chosen network;
- * null if no network in this category is available.
*/
- @Nullable
- WifiConfiguration evaluateNetworks(List<ScanDetail> scanDetails,
+ @Nullable void evaluateNetworks(List<ScanDetail> scanDetails,
WifiConfiguration currentNetwork, String currentBssid,
boolean connected, boolean untrustedNetworkAllowed,
OnConnectableListener onConnectableListener);
@@ -207,9 +201,8 @@ public class WifiNetworkSelector {
*
* @param scanDetail describes the specific access point
* @param config is the WifiConfiguration for the network
- * @param score is the score assigned by the evaluator
*/
- void onConnectable(ScanDetail scanDetail, WifiConfiguration config, int score);
+ void onConnectable(ScanDetail scanDetail, WifiConfiguration config);
}
}
@@ -380,8 +373,8 @@ public class WifiNetworkSelector {
private List<ScanDetail> filterScanResults(List<ScanDetail> scanDetails,
Set<String> bssidBlacklist, boolean isConnected, String currentBssid) {
- ArrayList<NetworkKey> unscoredNetworks = new ArrayList<NetworkKey>();
- List<ScanDetail> validScanDetails = new ArrayList<ScanDetail>();
+ ArrayList<NetworkKey> unscoredNetworks = new ArrayList<>();
+ List<ScanDetail> validScanDetails = new ArrayList<>();
StringBuffer noValidSsid = new StringBuffer();
StringBuffer blacklistedBssid = new StringBuffer();
StringBuffer lowRssi = new StringBuffer();
@@ -730,26 +723,22 @@ public class WifiNetworkSelector {
// Determine the weight for the last user selection
final int lastUserSelectedNetworkId = mWifiConfigManager.getLastSelectedNetwork();
final double lastSelectionWeight = calculateLastSelectionWeight();
- final ArraySet<Integer> mNetworkIds = new ArraySet<>();
- // Go through the registered network evaluators in order
- WifiConfiguration selectedNetwork = null;
WifiCandidates wifiCandidates = new WifiCandidates(mWifiScoreCard);
if (currentNetwork != null) {
wifiCandidates.setCurrent(currentNetwork.networkId, currentBssid);
}
for (NetworkEvaluator registeredEvaluator : mEvaluators) {
localLog("About to run " + registeredEvaluator.getName() + " :");
- WifiConfiguration choice = registeredEvaluator.evaluateNetworks(
+ registeredEvaluator.evaluateNetworks(
new ArrayList<>(mFilteredNetworks), currentNetwork, currentBssid, connected,
untrustedNetworkAllowed,
- (scanDetail, config, score) -> {
+ (scanDetail, config) -> {
if (config != null) {
mConnectableNetworks.add(Pair.create(scanDetail, config));
- mNetworkIds.add(config.networkId);
wifiCandidates.add(scanDetail, config,
registeredEvaluator.getId(),
- score,
+ 0,
(config.networkId == lastUserSelectedNetworkId)
? lastSelectionWeight : 0.0,
WifiConfiguration.isMetered(config, wifiInfo),
@@ -758,15 +747,6 @@ public class WifiNetworkSelector {
evaluatorIdToNominatorId(registeredEvaluator.getId()));
}
});
- if (choice != null && !mNetworkIds.contains(choice.networkId)) {
- Log.wtf(TAG, registeredEvaluator.getName()
- + " failed to report choice with noConnectibleListener");
- }
- if (selectedNetwork == null && choice != null) {
- selectedNetwork = choice; // First one wins
- localLog(registeredEvaluator.getName() + " selects "
- + WifiNetworkSelector.toNetworkString(selectedNetwork));
- }
}
if (mConnectableNetworks.size() != wifiCandidates.size()) {
@@ -802,11 +782,7 @@ public class WifiNetworkSelector {
ArrayMap<Integer, Integer> experimentNetworkSelections = new ArrayMap<>(); // for metrics
- final int legacySelectedNetworkId = selectedNetwork == null
- ? WifiConfiguration.INVALID_NETWORK_ID
- : selectedNetwork.networkId;
-
- int selectedNetworkId = legacySelectedNetworkId;
+ int selectedNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
// Run all the CandidateScorers
boolean legacyOverrideWanted = true;
@@ -837,9 +813,7 @@ public class WifiNetworkSelector {
}
// 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);
+ final int activeExperimentId = experimentIdFromIdentifier(activeScorer.getIdentifier());
for (Map.Entry<Integer, Integer> entry :
experimentNetworkSelections.entrySet()) {
int experimentId = entry.getKey();
@@ -851,7 +825,8 @@ public class WifiNetworkSelector {
}
// Get a fresh copy of WifiConfiguration reflecting any scan result updates
- selectedNetwork = mWifiConfigManager.getConfiguredNetwork(selectedNetworkId);
+ WifiConfiguration selectedNetwork =
+ mWifiConfigManager.getConfiguredNetwork(selectedNetworkId);
if (selectedNetwork != null && legacyOverrideWanted) {
selectedNetwork = overrideCandidateWithUserConnectChoice(selectedNetwork);
mLastNetworkSelectionTimeStamp = mClock.getElapsedSinceBootMillis();
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java
index 6396f2c7c..1a0a7096f 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointNetworkEvaluator.java
@@ -21,7 +21,6 @@ import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.os.Process;
import android.telephony.SubscriptionManager;
-import android.text.TextUtils;
import android.util.LocalLog;
import android.util.Pair;
@@ -32,7 +31,6 @@ import com.android.server.wifi.WifiInjector;
import com.android.server.wifi.WifiNetworkSelector;
import com.android.server.wifi.util.ScanResultUtil;
-import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@@ -88,7 +86,7 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva
public void update(List<ScanDetail> scanDetails) {}
@Override
- public WifiConfiguration evaluateNetworks(List<ScanDetail> scanDetails,
+ public void evaluateNetworks(List<ScanDetail> scanDetails,
WifiConfiguration currentNetwork, String currentBssid,
boolean connected, boolean untrustedNetworkAllowed,
@NonNull OnConnectableListener onConnectableListener) {
@@ -109,7 +107,6 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva
}).collect(Collectors.toList());
// Go through each ScanDetail and find the best provider for each ScanDetail.
- List<PasspointNetworkCandidate> candidateList = new ArrayList<>();
for (ScanDetail scanDetail : filteredScanDetails) {
ScanResult scanResult = scanDetail.getScanResult();
@@ -117,41 +114,13 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva
Pair<PasspointProvider, PasspointMatch> bestProvider =
mPasspointManager.matchProvider(scanResult);
if (bestProvider != null) {
- candidateList.add(new PasspointNetworkCandidate(
- bestProvider.first, bestProvider.second, scanDetail));
+ WifiConfiguration candidate = createWifiConfigForProvider(bestProvider, scanDetail);
+ if (candidate == null) {
+ continue;
+ }
+ onConnectableListener.onConnectable(scanDetail, candidate);
}
}
-
- // Done if no candidate is found.
- if (candidateList.isEmpty()) {
- localLog("No suitable Passpoint network found");
- return null;
- }
-
- // Find the best Passpoint network among all candidates.
- PasspointNetworkCandidate bestNetwork =
- findBestNetwork(candidateList, currentNetwork == null ? null : currentNetwork.SSID);
-
- // Return the configuration for the current connected network if it is the best network.
- if (currentNetwork != null && TextUtils.equals(currentNetwork.SSID,
- ScanResultUtil.createQuotedSSID(bestNetwork.mScanDetail.getSSID()))) {
- localLog("Staying with current Passpoint network " + currentNetwork.SSID);
-
- // Update current network with the latest scan info. TODO - pull into common code
- mWifiConfigManager.setNetworkCandidateScanResult(currentNetwork.networkId,
- bestNetwork.mScanDetail.getScanResult(), 0);
- mWifiConfigManager.updateScanDetailForNetwork(currentNetwork.networkId,
- bestNetwork.mScanDetail);
- onConnectableListener.onConnectable(bestNetwork.mScanDetail, currentNetwork, 0);
- return currentNetwork;
- }
-
- WifiConfiguration config = createWifiConfigForProvider(bestNetwork);
- if (config != null) {
- onConnectableListener.onConnectable(bestNetwork.mScanDetail, config, 0);
- localLog("Passpoint network to connect to: " + config.SSID);
- }
- return config;
}
/**
@@ -161,10 +130,11 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva
* @param networkInfo Contained information for the Passpoint network to connect to
* @return {@link WifiConfiguration}
*/
- private WifiConfiguration createWifiConfigForProvider(PasspointNetworkCandidate networkInfo) {
- WifiConfiguration config = networkInfo.mProvider.getWifiConfig();
- config.SSID = ScanResultUtil.createQuotedSSID(networkInfo.mScanDetail.getSSID());
- if (networkInfo.mMatchStatus == PasspointMatch.HomeProvider) {
+ private WifiConfiguration createWifiConfigForProvider(
+ Pair<PasspointProvider, PasspointMatch> bestProvider, ScanDetail scanDetail) {
+ WifiConfiguration config = bestProvider.first.getWifiConfig();
+ config.SSID = ScanResultUtil.createQuotedSSID(scanDetail.getSSID());
+ if (bestProvider.second == PasspointMatch.HomeProvider) {
config.isHomeProviderNetwork = true;
}
@@ -196,45 +166,12 @@ public class PasspointNetworkEvaluator implements WifiNetworkSelector.NetworkEva
mWifiConfigManager.enableNetwork(result.getNetworkId(), false, Process.WIFI_UID, null);
mWifiConfigManager.setNetworkCandidateScanResult(result.getNetworkId(),
- networkInfo.mScanDetail.getScanResult(), 0);
+ scanDetail.getScanResult(), 0);
mWifiConfigManager.updateScanDetailForNetwork(
- result.getNetworkId(), networkInfo.mScanDetail);
+ result.getNetworkId(), scanDetail);
return mWifiConfigManager.getConfiguredNetwork(result.getNetworkId());
}
- /**
- * Given a list of Passpoint networks (with both provider and scan info), find and return
- * the one with highest score. The score is calculated using
- * {@link PasspointNetworkScore#calculateScore}.
- *
- * @param networkList List of Passpoint networks
- * @param currentNetworkSsid The SSID of the currently connected network, null if not connected
- * @return {@link PasspointNetworkCandidate}
- */
- private PasspointNetworkCandidate findBestNetwork(
- List<PasspointNetworkCandidate> networkList, String currentNetworkSsid) {
- PasspointNetworkCandidate bestCandidate = null;
- int bestScore = Integer.MIN_VALUE;
- for (PasspointNetworkCandidate candidate : networkList) {
- ScanDetail scanDetail = candidate.mScanDetail;
- PasspointMatch match = candidate.mMatchStatus;
-
- boolean isActiveNetwork = TextUtils.equals(currentNetworkSsid,
- ScanResultUtil.createQuotedSSID(scanDetail.getSSID()));
- int score = PasspointNetworkScore.calculateScore(match == PasspointMatch.HomeProvider,
- scanDetail, mPasspointManager.getANQPElements(scanDetail.getScanResult()),
- isActiveNetwork);
-
- if (score > bestScore) {
- bestCandidate = candidate;
- bestScore = score;
- }
- }
- localLog("Best Passpoint network " + bestCandidate.mScanDetail.getSSID() + " provided by "
- + bestCandidate.mProvider.getConfig().getHomeSp().getFqdn());
- return bestCandidate;
- }
-
private void localLog(String log) {
mLocalLog.log(log);
}