diff options
author | Roshan Pius <rpius@google.com> | 2019-05-17 14:04:48 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2019-05-21 13:26:56 -0700 |
commit | 641e23cc3366b5b3b41727b932f8222afe11f0c9 (patch) | |
tree | 1a5f97df055c9c8b0a34157bfe9c3b469374cb48 | |
parent | ba6afe1adbb6afed25bd78e88b541326d969dba2 (diff) |
WifiNetworkSelector: Clear all configured network status
Currently, only the SaveNetworkEvaluator clears status for each saved
network before network selction is performed. This pre-selection step is
required to
a) Try and re-enable any temporarily disabled networks.
b) Clear the candidate field in the NetworkSelectionStatus object for
each network.
This pre-selection step is needed for all configured networks (not just
saved) since ephemeral networks are no longer removed after disconnect.
Changes in the CL:
a) Move the pre-selection network reset to the common
WifiNetworkSelector from SavedNetworkEvaluator.
b) Ensure that all configured networks (including ephemeral & passpoint
networks) are reset in this common method.
a) was done to avoid duplicating this logic in all of the evaluators.
Bug: 132979765
Test: Manual verification of the steps mentioned in the bug.
Test: Unit tests
Change-Id: Id2e629712958b04356367985ef41e2094bbeb712
4 files changed, 110 insertions, 79 deletions
diff --git a/service/java/com/android/server/wifi/SavedNetworkEvaluator.java b/service/java/com/android/server/wifi/SavedNetworkEvaluator.java index f77403b80..062fa5354 100644 --- a/service/java/com/android/server/wifi/SavedNetworkEvaluator.java +++ b/service/java/com/android/server/wifi/SavedNetworkEvaluator.java @@ -20,7 +20,6 @@ import android.annotation.NonNull; import android.content.Context; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; -import android.os.Process; import android.telephony.SubscriptionManager; import android.util.LocalLog; @@ -105,73 +104,10 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat } /** - * Update all the saved networks' selection status - */ - private void updateSavedNetworkSelectionStatus() { - List<WifiConfiguration> savedNetworks = mWifiConfigManager.getSavedNetworks( - Process.WIFI_UID); - if (savedNetworks.size() == 0) { - localLog("No saved networks."); - return; - } - - StringBuffer sbuf = new StringBuffer(); - for (WifiConfiguration network : savedNetworks) { - /** - * Ignore Passpoint networks. Passpoint networks are also considered as "saved" - * network, but without being persisted to the storage. They are managed - * by {@link PasspointNetworkEvaluator}. - */ - if (network.isPasspoint()) { - continue; - } - - // If a configuration is temporarily disabled, re-enable it before trying - // to connect to it. - mWifiConfigManager.tryEnableNetwork(network.networkId); - - //TODO(b/112196799): Enable "permanently" disabled networks if we are in DISCONNECTED - // state. See also 30928589 - - // Clear the cached candidate, score and seen. - mWifiConfigManager.clearNetworkCandidateScanResult(network.networkId); - - // Log disabled network. - WifiConfiguration.NetworkSelectionStatus status = network.getNetworkSelectionStatus(); - if (!status.isNetworkEnabled()) { - sbuf.append(" ").append(WifiNetworkSelector.toNetworkString(network)).append(" "); - for (int index = WifiConfiguration.NetworkSelectionStatus - .NETWORK_SELECTION_DISABLED_STARTING_INDEX; - index < WifiConfiguration.NetworkSelectionStatus - .NETWORK_SELECTION_DISABLED_MAX; - index++) { - int count = status.getDisableReasonCounter(index); - // Here we log the reason as long as its count is greater than zero. The - // network may not be disabled because of this particular reason. Logging - // this information anyway to help understand what happened to the network. - if (count > 0) { - sbuf.append("reason=") - .append(WifiConfiguration.NetworkSelectionStatus - .getNetworkDisableReasonString(index)) - .append(", count=").append(count).append("; "); - } - } - sbuf.append("\n"); - } - } - - if (sbuf.length() > 0) { - localLog("Disabled saved networks:"); - localLog(sbuf.toString()); - } - } - - /** * Update the evaluator. */ - public void update(List<ScanDetail> scanDetails) { - updateSavedNetworkSelectionStatus(); - } + @Override + public void update(List<ScanDetail> scanDetails) { } private int calculateBssidScore(ScanResult scanResult, WifiConfiguration network, WifiConfiguration currentNetwork, String currentBssid, @@ -246,6 +182,7 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat * @return configuration of the chosen network; * null if no network in this category is available. */ + @Override public WifiConfiguration evaluateNetworks(List<ScanDetail> scanDetails, WifiConfiguration currentNetwork, String currentBssid, boolean connected, boolean untrustedNetworkAllowed, diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java index 00d245893..4b7e3f02b 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSelector.java +++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java @@ -27,7 +27,6 @@ import android.net.wifi.ScanResult; import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; -import android.os.Process; import android.text.TextUtils; import android.util.ArrayMap; import android.util.ArraySet; @@ -544,10 +543,9 @@ public class WifiNetworkSelector { String key = selected.configKey(); // This is only used for setting the connect choice timestamp for debugging purposes. long currentTime = mClock.getWallClockMillis(); - List<WifiConfiguration> savedNetworks = mWifiConfigManager.getSavedNetworks( - Process.WIFI_UID); + List<WifiConfiguration> configuredNetworks = mWifiConfigManager.getConfiguredNetworks(); - for (WifiConfiguration network : savedNetworks) { + for (WifiConfiguration network : configuredNetworks) { WifiConfiguration.NetworkSelectionStatus status = network.getNetworkSelectionStatus(); if (network.networkId == selected.networkId) { if (status.getConnectChoice() != null) { @@ -572,6 +570,61 @@ public class WifiNetworkSelector { return change; } + + /** + * Iterate thru the list of configured networks (includes all saved network configurations + + * any ephemeral network configurations created for passpoint networks, suggestions, carrier + * networks, etc) and do the following: + * a) Try to re-enable any temporarily enabled networks (if the blacklist duration has expired). + * b) Clear the {@link WifiConfiguration.NetworkSelectionStatus#getCandidate()} field for all + * of them to identify networks that are present in the current scan result. + * c) Log any disabled networks. + */ + private void updateConfiguredNetworks() { + List<WifiConfiguration> configuredNetworks = mWifiConfigManager.getConfiguredNetworks(); + if (configuredNetworks.size() == 0) { + localLog("No configured networks."); + return; + } + + StringBuffer sbuf = new StringBuffer(); + for (WifiConfiguration network : configuredNetworks) { + // If a configuration is temporarily disabled, re-enable it before trying + // to connect to it. + mWifiConfigManager.tryEnableNetwork(network.networkId); + // Clear the cached candidate, score and seen. + mWifiConfigManager.clearNetworkCandidateScanResult(network.networkId); + + // Log disabled network. + WifiConfiguration.NetworkSelectionStatus status = network.getNetworkSelectionStatus(); + if (!status.isNetworkEnabled()) { + sbuf.append(" ").append(toNetworkString(network)).append(" "); + for (int index = WifiConfiguration.NetworkSelectionStatus + .NETWORK_SELECTION_DISABLED_STARTING_INDEX; + index < WifiConfiguration.NetworkSelectionStatus + .NETWORK_SELECTION_DISABLED_MAX; + index++) { + int count = status.getDisableReasonCounter(index); + // Here we log the reason as long as its count is greater than zero. The + // network may not be disabled because of this particular reason. Logging + // this information anyway to help understand what happened to the network. + if (count > 0) { + sbuf.append("reason=") + .append(WifiConfiguration.NetworkSelectionStatus + .getNetworkDisableReasonString(index)) + .append(", count=").append(count).append("; "); + } + } + sbuf.append("\n"); + } + } + + if (sbuf.length() > 0) { + localLog("Disabled configured networks:"); + localLog(sbuf.toString()); + } + } + /** * Overrides the {@code candidate} chosen by the {@link #mEvaluators} with the user chosen * {@link WifiConfiguration} if one exists. @@ -645,6 +698,9 @@ public class WifiNetworkSelector { return null; } + // Update all configured networks before initiating network selection. + updateConfiguredNetworks(); + // Update the registered network evaluators. for (NetworkEvaluator registeredEvaluator : mEvaluators) { registeredEvaluator.update(scanDetails); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java index cda5d626b..53dae5229 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java @@ -167,13 +167,19 @@ public class WifiNetworkSelectorTest { if (!mEvaluatorShouldSelectCandidate) { return null; } - ScanDetail scanDetail = scanDetails.get(mNetworkIndexToReturn); - mWifiConfigManager.setNetworkCandidateScanResult(0, scanDetail.getScanResult(), 100); - WifiConfiguration config = - mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(scanDetail); - assertNotNull("Saved network must not be null", config); - onConnectableListener.onConnectable(scanDetail, config, 100); - return config; + for (ScanDetail scanDetail : scanDetails) { + WifiConfiguration config = + mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(scanDetail); + mWifiConfigManager.setNetworkCandidateScanResult( + config.networkId, scanDetail.getScanResult(), 100); + } + ScanDetail scanDetailToReturn = scanDetails.get(mNetworkIndexToReturn); + WifiConfiguration configToReturn = + mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache( + scanDetailToReturn); + assertNotNull("Saved network must not be null", configToReturn); + onConnectableListener.onConnectable(scanDetailToReturn, configToReturn, 100); + return configToReturn; } } @@ -540,6 +546,38 @@ public class WifiNetworkSelectorTest { } /** + * Ensure that network selector update's network selection status for all configured + * networks before performing network selection. + * + * Expected behavior: the first network is recommended by Network Selector + */ + @Test + public void updateConfiguredNetworks() { + String[] ssids = {"\"test1\"", "\"test2\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; + int[] freqs = {2437, 2457}; + String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-PSK][ESS]"}; + int[] levels = {mThresholdMinimumRssi2G + 20, mThresholdMinimumRssi2G + RSSI_BUMP}; + int[] securities = {SECURITY_EAP, SECURITY_PSK}; + + ScanDetailsAndWifiConfigs scanDetailsAndConfigs = + WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, + freqs, caps, levels, securities, mWifiConfigManager, mClock); + List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + HashSet<String> blacklist = new HashSet<String>(); + WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); + + // Do network selection. + mWifiNetworkSelector.selectNetwork(scanDetails, + blacklist, mWifiInfo, true, false, false); + + verify(mWifiConfigManager).getConfiguredNetworks(); + verify(mWifiConfigManager, times(savedConfigs.length)).tryEnableNetwork(anyInt()); + verify(mWifiConfigManager, times(savedConfigs.length)) + .clearNetworkCandidateScanResult(anyInt()); + } + + /** * Blacklisted BSSID is filtered out for network selection. * * ClientModeImpl is disconnected. diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java index 4f795ad03..74d6cb747 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java @@ -218,9 +218,9 @@ public class WifiNetworkSelectorTestUtil { return null; } }); - when(wifiConfigManager.getSavedNetworks(anyInt())) + when(wifiConfigManager.getConfiguredNetworks()) .then(new AnswerWithArguments() { - public List<WifiConfiguration> answer(int uid) { + public List<WifiConfiguration> answer() { List<WifiConfiguration> savedNetworks = new ArrayList<>(); for (int netId = 0; netId < configs.length; netId++) { savedNetworks.add(new WifiConfiguration(configs[netId])); |