diff options
author | Randy Pan <zpan@google.com> | 2017-03-28 15:26:30 -0700 |
---|---|---|
committer | Randy Pan <zpan@google.com> | 2017-03-29 20:51:19 -0700 |
commit | 13fb8e99c1a793c42e102e4f16f63de02f6eeed3 (patch) | |
tree | 49eb39bc2b053745bd9a85f73a1ebebc2bc298c8 | |
parent | 6490231d83f30b48ac48e62e707ed68e1f3ef730 (diff) |
Clean up saved network score calculation
1) Apply band specific RSSI saturation threshold.
2) Remove the no internet penalty since the network should have
been blacklisted because of DISABLED_NO_INTERNET.
3) Clean up a couple of line indents.
Bug: 36223866
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Change-Id: I9e5a9dda5ba38248ae0d6ed3ac64c46d655c4280
-rw-r--r-- | service/java/com/android/server/wifi/SavedNetworkEvaluator.java | 28 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java | 87 |
2 files changed, 96 insertions, 19 deletions
diff --git a/service/java/com/android/server/wifi/SavedNetworkEvaluator.java b/service/java/com/android/server/wifi/SavedNetworkEvaluator.java index f70d12d1d..62df61028 100644 --- a/service/java/com/android/server/wifi/SavedNetworkEvaluator.java +++ b/service/java/com/android/server/wifi/SavedNetworkEvaluator.java @@ -49,8 +49,8 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat private final int mBand5GHzAward; private final int mLastSelectionAward; private final int mSecurityAward; - private final int mNoInternetPenalty; private final int mThresholdSaturatedRssi24; + private final int mThresholdSaturatedRssi5; private final ContentObserver mContentObserver; private boolean mCurateSavedOpenNetworks; @@ -78,9 +78,8 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat R.integer.config_wifi_framework_5GHz_preference_boost_factor); mThresholdSaturatedRssi24 = context.getResources().getInteger( R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_24GHz); - mNoInternetPenalty = (mThresholdSaturatedRssi24 + mRssiScoreOffset) - * mRssiScoreSlope + mBand5GHzAward + mSameNetworkAward - + mSameBssidAward + mSecurityAward; + mThresholdSaturatedRssi5 = context.getResources().getInteger( + R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_5GHz); mContentObserver = new ContentObserver(new Handler(looper)) { @Override public void onChange(boolean selfChange) { @@ -155,8 +154,8 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat sbuf.append(status.getDisableReasonCounter(index)).append(" "); } sbuf.append("Connect Choice: ").append(status.getConnectChoice()) - .append(" set time: ").append(status.getConnectChoiceTimestamp()) - .append("\n"); + .append(" set time: ").append(status.getConnectChoiceTimestamp()) + .append("\n"); } localLog(sbuf.toString()); } @@ -172,19 +171,20 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat WifiConfiguration currentNetwork, String currentBssid, StringBuffer sbuf) { int score = 0; + boolean is5GHz = scanResult.is5GHz(); sbuf.append("[ ").append(scanResult).append("] "); // Calculate the RSSI score. - int rssi = scanResult.level <= mThresholdSaturatedRssi24 - ? scanResult.level : mThresholdSaturatedRssi24; + int rssiSaturationThreshold = is5GHz ? mThresholdSaturatedRssi5 : mThresholdSaturatedRssi24; + int rssi = scanResult.level < rssiSaturationThreshold ? scanResult.level + : rssiSaturationThreshold; score += (rssi + mRssiScoreOffset) * mRssiScoreSlope; sbuf.append(" RSSI score: ").append(score).append(","); // 5GHz band bonus. - if (scanResult.is5GHz()) { + if (is5GHz) { score += mBand5GHzAward; - sbuf.append(" 5GHz bonus: ").append(mBand5GHzAward) - .append(","); + sbuf.append(" 5GHz bonus: ").append(mBand5GHzAward).append(","); } // Last user selection award. @@ -232,12 +232,6 @@ public class SavedNetworkEvaluator implements WifiNetworkSelector.NetworkEvaluat sbuf.append(" Secure network bonus: ").append(mSecurityAward).append(","); } - // No internet penalty. - if (network.numNoInternetAccessReports > 0 && !network.validatedInternetAccess) { - score -= mNoInternetPenalty; - sbuf.append(" No internet penalty: -").append(mNoInternetPenalty).append(","); - } - sbuf.append(" ## Total score: ").append(score).append("\n"); return score; diff --git a/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java b/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java index 242607db7..54fc60a41 100644 --- a/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SavedNetworkEvaluatorTest.java @@ -126,10 +126,10 @@ public class SavedNetworkEvaluatorTest { private void setupResource() { when(mResource.getInteger( R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_5GHz)) - .thenReturn(-70); + .thenReturn(-57); when(mResource.getInteger( R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_24GHz)) - .thenReturn(-73); + .thenReturn(-60); when(mResource.getInteger( R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_5GHz)) .thenReturn(-70); @@ -502,4 +502,87 @@ public class SavedNetworkEvaluatorTest { WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, chosenScanResult, candidate); } + + /** + * One 2.4GHz network and one 5GHz network have the same security type. Perform + * the following tests to verify that once across the RSSI saturation threshold + * stronger RSSI value doesn't increase network score. + * + * 1) Both 2.4GHz network and 5GHz network have the same RSSI value, + * mThresholdQualifiedRssi2G, which is below the saturation threshold. 5GHz + * network is chosen because of the 5G band award. + * 2) Bump up 2.4GHz network RSSI 20dBm higher. Verify that it helps the 2.4GHz network + * score and it gets chosen over the 5GHz network. + * 3) Bring both 2.4GHz network and 5GHz network RSSI value to mThresholdSaturatedRssi2G. + * Verify that 5GHz network is chosen because of the 5G band award. + * 4) Bump up 2.4GHz network RSSI to be 20dBm higher than mThresholdSaturatedRssi2G. + * Verify that the incresed RSSI doesn't help 2.4GHz network score and 5GHz network + * is still chosen. + */ + @Test + public void saturatedRssiAddsNoWeightToNetwork() { + String[] ssids = {"\"test1\"", "\"test2\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; + int[] freqs = {2437, 5400}; + String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]"}; + int[] securities = {SECURITY_PSK, SECURITY_PSK}; + + // 1) The RSSI of both networks is mThresholdQualifiedRssi2G + int[] levels = {mThresholdQualifiedRssi2G, mThresholdQualifiedRssi2G}; + ScanDetailsAndWifiConfigs scanDetailsAndConfigs = + WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, + freqs, caps, levels, securities, mWifiConfigManager, mClock); + List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); + WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); + WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, + null, null, false, false, null); + // Verify that 5GHz network is chosen because of 5G band award + ScanResult chosenScanResult = scanDetails.get(1).getScanResult(); + WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate); + WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, + chosenScanResult, candidate); + + // 2) Bump up 2.4GHz network RSSI by 20dBm. + levels[0] = mThresholdQualifiedRssi2G + 20; + scanDetailsAndConfigs = WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, + bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); + scanDetails = scanDetailsAndConfigs.getScanDetails(); + savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); + candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, null, null, false, + false, null); + // Verify that 2.4GHz network is chosen because of much higher RSSI value + chosenScanResult = scanDetails.get(0).getScanResult(); + WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate); + WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, + chosenScanResult, candidate); + + // 3) Bring both 2.4GHz network and 5GHz network RSSI to mThresholdSaturatedRssi2G + levels[0] = levels[1] = mThresholdSaturatedRssi2G; + scanDetailsAndConfigs = WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, + bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); + scanDetails = scanDetailsAndConfigs.getScanDetails(); + savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); + candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, null, null, false, + false, null); + // Verify that 5GHz network is chosen because of 5G band award + chosenScanResult = scanDetails.get(1).getScanResult(); + WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate); + WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, + chosenScanResult, candidate); + + // 4) Bump 2.4GHz network RSSI to be 20dBm higher than mThresholdSaturatedRssi2G + levels[0] = mThresholdSaturatedRssi2G + 20; + scanDetailsAndConfigs = WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, + bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); + scanDetails = scanDetailsAndConfigs.getScanDetails(); + savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); + candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, null, null, false, + false, null); + // Verify that the increased RSSI doesn't help 2.4GHz network and 5GHz network + // is still chosen + chosenScanResult = scanDetails.get(1).getScanResult(); + WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate); + WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, + chosenScanResult, candidate); + } } |