diff options
3 files changed, 95 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index 66a6685da..755a80fb6 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -254,7 +254,7 @@ public class WifiInjector { new Handler(clientModeImplLooper)); mWifiMetrics.setScoringParams(mScoringParams); mWifiNetworkSelector = new WifiNetworkSelector(mContext, mWifiScoreCard, mScoringParams, - mWifiConfigManager, mClock, mConnectivityLocalLog, mWifiMetrics); + mWifiConfigManager, mClock, mConnectivityLocalLog, mWifiMetrics, mWifiNative); CompatibilityScorer compatibilityScorer = new CompatibilityScorer(mScoringParams); mWifiNetworkSelector.registerCandidateScorer(compatibilityScorer); ScoreCardBasedScorer scoreCardBasedScorer = new ScoreCardBasedScorer(mScoringParams); diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java index e7608ed78..79176fd0b 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSelector.java +++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java @@ -16,6 +16,8 @@ package com.android.server.wifi; +import static android.net.wifi.WifiManager.WIFI_FEATURE_OWE; + import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; @@ -96,8 +98,11 @@ public class WifiNetworkSelector { private final int mStayOnNetworkMinimumTxRate; private final int mStayOnNetworkMinimumRxRate; private final boolean mEnableAutoJoinWhenAssociated; + private final WifiNative mWifiNative; private final Map<String, WifiCandidates.CandidateScorer> mCandidateScorers = new ArrayMap<>(); + private boolean mIsEasyConnectSupportedInitialized = false; + private boolean mIsEasyConnectSupported; /** * WiFi Network Selector supports various categories of networks. Each category @@ -407,6 +412,17 @@ public class WifiNetworkSelector { return validScanDetails; } + private boolean isEnhancedOpenSupported() { + if (mIsEasyConnectSupportedInitialized) { + return mIsEasyConnectSupported; + } + + mIsEasyConnectSupportedInitialized = true; + mIsEasyConnectSupported = (mWifiNative.getSupportedFeatureSet( + mWifiNative.getClientInterfaceName()) & WIFI_FEATURE_OWE) != 0; + return mIsEasyConnectSupported; + } + /** * This returns a list of ScanDetails that were filtered in the process of network selection. * The list is further filtered for only open unsaved networks. @@ -417,6 +433,7 @@ public class WifiNetworkSelector { */ public List<ScanDetail> getFilteredScanDetailsForOpenUnsavedNetworks() { List<ScanDetail> openUnsavedNetworks = new ArrayList<>(); + boolean enhancedOpenSupported = isEnhancedOpenSupported(); for (ScanDetail scanDetail : mFilteredNetworks) { ScanResult scanResult = scanDetail.getScanResult(); @@ -424,6 +441,12 @@ public class WifiNetworkSelector { continue; } + // Filter out Enhanced Open networks on devices that do not support it + if (ScanResultUtil.isScanResultForOweNetwork(scanResult) + && !enhancedOpenSupported) { + continue; + } + // Skip saved networks if (mWifiConfigManager.getConfiguredNetworkForScanDetailAndCache(scanDetail) != null) { continue; @@ -820,13 +843,14 @@ public class WifiNetworkSelector { WifiNetworkSelector(Context context, WifiScoreCard wifiScoreCard, ScoringParams scoringParams, WifiConfigManager configManager, Clock clock, LocalLog localLog, - WifiMetrics wifiMetrics) { + WifiMetrics wifiMetrics, WifiNative wifiNative) { mWifiConfigManager = configManager; mClock = clock; mWifiScoreCard = wifiScoreCard; mScoringParams = scoringParams; mLocalLog = localLog; mWifiMetrics = wifiMetrics; + mWifiNative = wifiNative; mEnableAutoJoinWhenAssociated = context.getResources().getBoolean( R.bool.config_wifi_framework_enable_associated_network_selection); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java index 9cefc2e3b..6e3517246 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java @@ -16,6 +16,8 @@ package com.android.server.wifi; +import static android.net.wifi.WifiManager.WIFI_FEATURE_OWE; + import static com.android.server.wifi.WifiConfigurationTestUtil.SECURITY_EAP; import static com.android.server.wifi.WifiConfigurationTestUtil.SECURITY_NONE; import static com.android.server.wifi.WifiConfigurationTestUtil.SECURITY_PSK; @@ -81,7 +83,8 @@ public class WifiNetworkSelectorTest { mScoringParams, mWifiConfigManager, mClock, mLocalLog, - mWifiMetrics); + mWifiMetrics, + mWifiNative); mWifiNetworkSelector.registerNetworkEvaluator(mDummyEvaluator); mDummyEvaluator.setEvaluatorToSelectCandidate(true); when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime()); @@ -89,6 +92,7 @@ public class WifiNetworkSelectorTest { when(mWifiScoreCard.lookupBssid(any(), any())).thenReturn(mPerBssid); mCompatibilityScorer = new CompatibilityScorer(mScoringParams); mScoreCardBasedScorer = new ScoreCardBasedScorer(mScoringParams); + when(mWifiNative.getClientInterfaceName()).thenReturn("wlan0"); } /** Cleans up test. */ @@ -179,6 +183,7 @@ public class WifiNetworkSelectorTest { @Mock private WifiScoreCard.PerBssid mPerBssid; @Mock private WifiCandidates.CandidateScorer mCandidateScorer; @Mock private WifiMetrics mWifiMetrics; + @Mock private WifiNative mWifiNative; // For simulating the resources, we use a Spy on a MockResource // (which is really more of a stub than a mock, in spite if its name). @@ -1172,6 +1177,69 @@ public class WifiNetworkSelectorTest { } /** + * {@link WifiNetworkSelector#getFilteredScanDetailsForOpenUnsavedNetworks()} for device that + * supports enhanced open networks, should filter out networks that are not open and not + * enhanced open after network selection is made. + * + * Expected behavior: return open and enhanced open networks only + */ + @Test + public void getfilterOpenUnsavedNetworks_filtersForOpenAndOweNetworksOweSupported() { + String[] ssids = {"\"test1\"", "\"test2\"", "\"test3\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4", "6c:f3:7f:ae:8c:f5"}; + int[] freqs = {2437, 5180, 2414}; + String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[ESS]", "[RSN-OWE-CCMP][ESS]"}; + int[] levels = {mThresholdMinimumRssi2G, mThresholdMinimumRssi5G + RSSI_BUMP, + mThresholdMinimumRssi2G + RSSI_BUMP}; + mDummyEvaluator.setEvaluatorToSelectCandidate(false); + when(mWifiNative.getSupportedFeatureSet(anyString())) + .thenReturn(new Long(WIFI_FEATURE_OWE)); + + List<ScanDetail> scanDetails = WifiNetworkSelectorTestUtil.buildScanDetails( + ssids, bssids, freqs, caps, levels, mClock); + HashSet<String> blacklist = new HashSet<>(); + + mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + List<ScanDetail> expectedOpenUnsavedNetworks = new ArrayList<>(); + expectedOpenUnsavedNetworks.add(scanDetails.get(1)); + expectedOpenUnsavedNetworks.add(scanDetails.get(2)); + assertEquals("Expect open unsaved networks", + expectedOpenUnsavedNetworks, + mWifiNetworkSelector.getFilteredScanDetailsForOpenUnsavedNetworks()); + } + + /** + * {@link WifiNetworkSelector#getFilteredScanDetailsForOpenUnsavedNetworks()} for device that + * does not support enhanced open networks, should filter out both networks that are not open + * and enhanced open after network selection is made. + * + * Expected behavior: return open networks only + */ + @Test + public void getfilterOpenUnsavedNetworks_filtersForOpenAndOweNetworksOweNotSupported() { + String[] ssids = {"\"test1\"", "\"test2\"", "\"test3\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4", "6c:f3:7f:ae:8c:f5"}; + int[] freqs = {2437, 5180, 2414}; + String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[ESS]", "[RSN-OWE-CCMP][ESS]"}; + int[] levels = {mThresholdMinimumRssi2G, mThresholdMinimumRssi5G + RSSI_BUMP, + mThresholdMinimumRssi2G + RSSI_BUMP}; + mDummyEvaluator.setEvaluatorToSelectCandidate(false); + when(mWifiNative.getSupportedFeatureSet(anyString())) + .thenReturn(new Long(~WIFI_FEATURE_OWE)); + + List<ScanDetail> scanDetails = WifiNetworkSelectorTestUtil.buildScanDetails( + ssids, bssids, freqs, caps, levels, mClock); + HashSet<String> blacklist = new HashSet<>(); + + mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + List<ScanDetail> expectedOpenUnsavedNetworks = new ArrayList<>(); + expectedOpenUnsavedNetworks.add(scanDetails.get(1)); + assertEquals("Expect open unsaved networks", + expectedOpenUnsavedNetworks, + mWifiNetworkSelector.getFilteredScanDetailsForOpenUnsavedNetworks()); + } + + /** * {@link WifiNetworkSelector#getFilteredScanDetailsForCarrierUnsavedNetworks()} should filter * out networks that are not EAP after network selection is made. * |