diff options
author | Randy Pan <zpan@google.com> | 2017-03-02 16:05:11 -0800 |
---|---|---|
committer | Randy Pan <zpan@google.com> | 2017-03-28 12:00:07 -0700 |
commit | c22ad7f19888f7967edcf30080543bb632ddd68d (patch) | |
tree | c801fd447a0ee57bb326c40a9c33814a43b572cf | |
parent | 17c2a7b30e5680b11fc0073ce322ee7bc14ef2c5 (diff) |
Same BSSID award
When firmware roaming is supported, apply the same BSSID award to
all of the BSSIDs under the same network as the currently connected
BSSID. This is under the assumption that firmware will roam to that
better BSSID.
This might save a disconnection triggered by network switch when
the score of the currently connected BSSID is lower than a network
with a different SSID, but within the currently connected network
there is a BSSID better than the currently connected BSSID.
Bug: 35642269
Test: runtest.sh
Change-Id: Ie09170d0cb11565f72e3b45b702d39c88ababba9
4 files changed, 98 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/SavedNetworkEvaluator.java b/service/java/com/android/server/wifi/SavedNetworkEvaluator.java index ff880f510..f70d12d1d 100644 --- a/service/java/com/android/server/wifi/SavedNetworkEvaluator.java +++ b/service/java/com/android/server/wifi/SavedNetworkEvaluator.java @@ -41,6 +41,7 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat private final WifiConfigManager mWifiConfigManager; private final Clock mClock; private final LocalLog mLocalLog; + private final WifiConnectivityHelper mConnectivityHelper; private final int mRssiScoreSlope; private final int mRssiScoreOffset; private final int mSameBssidAward; @@ -54,10 +55,12 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat private boolean mCurateSavedOpenNetworks; SavedNetworkEvaluator(final Context context, WifiConfigManager configManager, Clock clock, - LocalLog localLog, Looper looper, final FrameworkFacade frameworkFacade) { + LocalLog localLog, Looper looper, final FrameworkFacade frameworkFacade, + WifiConnectivityHelper connectivityHelper) { mWifiConfigManager = configManager; mClock = clock; mLocalLog = localLog; + mConnectivityHelper = connectivityHelper; mRssiScoreSlope = context.getResources().getInteger( R.integer.config_wifi_framework_RSSI_SCORE_SLOPE); @@ -205,13 +208,22 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat score += mSameNetworkAward; sbuf.append(" Same network the current one bonus: ") .append(mSameNetworkAward).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 += mSameBssidAward; + sbuf.append(" Firmware roaming equivalent BSSID bonus: ") + .append(mSameBssidAward).append(","); + } } // Same BSSID award. if (currentBssid != null && currentBssid.equals(scanResult.BSSID)) { score += mSameBssidAward; sbuf.append(" Same BSSID as the current one bonus: ").append(mSameBssidAward) - .append(","); + .append(","); } // Security award. diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index 5fa0ee9ac..af470eee8 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -200,7 +200,7 @@ public class WifiInjector { mConnectivityLocalLog); mSavedNetworkEvaluator = new SavedNetworkEvaluator(mContext, mWifiConfigManager, mClock, mConnectivityLocalLog, wifiStateMachineLooper, - mFrameworkFacade); + mFrameworkFacade, mWifiConnectivityHelper); mRecommendedNetworkEvaluator = new RecommendedNetworkEvaluator(context, context.getContentResolver(), wifiStateMachineLooper, mFrameworkFacade, mNetworkScoreManager, mWifiConfigManager, mConnectivityLocalLog); diff --git a/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java index ec19e038c..242607db7 100644 --- a/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java @@ -62,6 +62,7 @@ public class SavedNetworkEvaluatorTest { setupWifiConfigManager(); mLocalLog = new LocalLog(512); + when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(false); when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime()); when(mFrameworkFacade.getIntegerSetting(mContext, Settings.Global.CURATE_SAVED_OPEN_NETWORKS, 0)).thenReturn(0); @@ -85,7 +86,8 @@ public class SavedNetworkEvaluatorTest { ArgumentCaptor.forClass(ContentObserver.class); mSavedNetworkEvaluator = new SavedNetworkEvaluator(mContext, mWifiConfigManager, - mClock, mLocalLog, Looper.getMainLooper(), mFrameworkFacade); + mClock, mLocalLog, Looper.getMainLooper(), mFrameworkFacade, + mWifiConnectivityHelper); verify(mFrameworkFacade, times(2)).registerContentObserver(eq(mContext), any(Uri.class), eq(false), observerCaptor.capture()); // SavedNetworkEvaluator uses a single ContentObserver for two registrations, we only need @@ -101,6 +103,7 @@ public class SavedNetworkEvaluatorTest { private SavedNetworkEvaluator mSavedNetworkEvaluator; @Mock private WifiConfigManager mWifiConfigManager; + @Mock private WifiConnectivityHelper mWifiConnectivityHelper; @Mock private Context mContext; @Mock private ContentResolver mContentResolver; @Mock private FrameworkFacade mFrameworkFacade; @@ -114,7 +117,6 @@ public class SavedNetworkEvaluatorTest { private int mThresholdSaturatedRssi2G; private int mThresholdSaturatedRssi5G; private ContentObserver mContentObserver; - private static final String TAG = "Saved Network Evaluator Unit Test"; private void setupContext() { when(mContext.getResources()).thenReturn(mResource); @@ -447,4 +449,57 @@ public class SavedNetworkEvaluatorTest { ScanResult chosenScanResult = scanDetails.get(0).getScanResult(); WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate); } + + /** + * Verify that the same BSSID award is applied to all the BSSIDs which are under the same + * network as the currently connected BSSID. + */ + @Test + public void currentBssidAwardForAllBssidsWithinTheSameNetworkWhenFirmwareRoamingSupported() { + // Three BSSIDs are carefully setup there: + // BSSID_0 and BSSID_1 have the same SSID and security type, so they are considered under + // the same 2.4 GHz network. BSSID_1 RSSI is stronger than BSSID_0. + // BSSID_2 is under a 5GHz network different from BSSID_0 and BSSID_1. Its RSSI is + // slightly stronger than BSSID_1. + // + // When firmware roaming is not supported, BSSID_2 has higher score than BSSID_0 and + // BSSID_1. + // When firmware roaming is suported, BSSID_1 has higher score than BSSID_2 because the + // same BSSID award is now applied to both BSSID_0 and BSSID_1. + String[] ssids = {"\"test1\"", "\"test1\"", "\"test2\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4", "6c:f3:7f:ae:8c:f5"}; + int[] freqs = {2470, 2437, 5200}; + String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]"}; + int[] levels = {mThresholdMinimumRssi2G + 2, mThresholdMinimumRssi2G + 5, + mThresholdMinimumRssi5G + 7}; + int[] securities = {SECURITY_PSK, SECURITY_PSK, SECURITY_PSK}; + + ScanDetailsAndWifiConfigs scanDetailsAndConfigs = + WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, + freqs, caps, levels, securities, mWifiConfigManager, mClock); + List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); + + // Firmware roaming is not supported. + when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(false); + // Simuluate we are connected to BSSID_0 already. + WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, + savedConfigs[0], bssids[0], true, false, null); + // Verify that BSSID_2 is chosen. + ScanResult chosenScanResult = scanDetails.get(2).getScanResult(); + WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[2], candidate); + WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, + chosenScanResult, candidate); + + // Firmware roaming is supported. + when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(true); + // Simuluate we are connected to BSSID_0 already. + candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, + savedConfigs[0], bssids[0], true, false, null); + // Verify that BSSID_1 is chosen. + chosenScanResult = scanDetails.get(1).getScanResult(); + WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate); + WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, + chosenScanResult, candidate); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java index 865344506..1e255c86c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTestUtil.java @@ -37,7 +37,9 @@ import android.text.TextUtils; import com.android.server.wifi.util.ScanResultUtil; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * Helper for WifiNetworkSelector unit tests. @@ -132,7 +134,7 @@ public class WifiNetworkSelectorTestUtil { /** * Generate an array of {@link android.net.wifi.WifiConfiguration} based on the caller - * supplied network SSID and sencurity information. + * supplied network SSID and security information. * * @param ssids an array of SSIDs * @param securities an array of the network's security setting @@ -145,10 +147,23 @@ public class WifiNetworkSelectorTestUtil { return null; } + Map<String, Integer> netIdMap = new HashMap<>(); + int netId = 0; + WifiConfiguration[] configs = new WifiConfiguration[ssids.length]; for (int index = 0; index < ssids.length; index++) { - configs[index] = generateWifiConfig(index, 0, ssids[index], false, true, null, null, - securities[index]); + String configKey = ssids[index] + Integer.toString(securities[index]); + Integer id; + + id = netIdMap.get(configKey); + if (id == null) { + id = new Integer(netId); + netIdMap.put(configKey, id); + netId++; + } + + configs[index] = generateWifiConfig(id.intValue(), 0, ssids[index], false, true, null, + null, securities[index]); } return configs; @@ -167,19 +182,20 @@ public class WifiNetworkSelectorTestUtil { when(wifiConfigManager.getConfiguredNetwork(anyInt())) .then(new AnswerWithArguments() { public WifiConfiguration answer(int netId) { - if (netId >= 0 && netId < configs.length) { - return new WifiConfiguration(configs[netId]); - } else { - return null; + for (WifiConfiguration config : configs) { + if (netId == config.networkId) { + return new WifiConfiguration(config); + } } + return null; } }); when(wifiConfigManager.getConfiguredNetwork(anyString())) .then(new AnswerWithArguments() { public WifiConfiguration answer(String configKey) { - for (int netId = 0; netId < configs.length; netId++) { - if (TextUtils.equals(configs[netId].configKey(), configKey)) { - return new WifiConfiguration(configs[netId]); + for (WifiConfiguration config : configs) { + if (TextUtils.equals(config.configKey(), configKey)) { + return new WifiConfiguration(config); } } return null; |