Loading packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java +8 −3 Original line number Diff line number Diff line Loading @@ -394,8 +394,9 @@ public class AccessPoint implements Comparable<AccessPoint> { * * <p>If the given connection is active, the existing value of {@link #mRssi} will be returned. * If the given AccessPoint is not active, a value will be calculated from previous scan * results, returning the best RSSI for all matching AccessPoints. If the access point is not * connected and there are no scan results, the rssi will be set to {@link #UNREACHABLE_RSSI}. * results, returning the best RSSI for all matching AccessPoints averaged with the previous * value. If the access point is not connected and there are no scan results, the rssi will be * set to {@link #UNREACHABLE_RSSI}. * * <p>Old scan results will be evicted from the cache when this method is invoked. */ Loading @@ -413,8 +414,12 @@ public class AccessPoint implements Comparable<AccessPoint> { } } if (rssi != UNREACHABLE_RSSI && mRssi != UNREACHABLE_RSSI) { mRssi = (mRssi + rssi) / 2; // half-life previous value } else { mRssi = rssi; } } /** * Updates {@link #mSeen} based on the scan result cache. Loading packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -195,6 +195,26 @@ public class AccessPointTest { assertThat(ap.getRssi()).isEqualTo(newRssi); } @Test public void testUpdateWithScanResultShouldAverageRssi() { String ssid = "ssid"; int originalRssi = -65; int newRssi = -80; int expectedRssi = (originalRssi + newRssi) / 2; AccessPoint ap = new TestAccessPointBuilder(mContext).setSsid(ssid).setRssi(originalRssi).build(); ScanResult scanResult = new ScanResult(); scanResult.SSID = ssid; scanResult.level = newRssi; scanResult.BSSID = "bssid"; scanResult.timestamp = SystemClock.elapsedRealtime() * 1000; scanResult.capabilities = ""; assertThat(ap.update(scanResult)).isTrue(); assertThat(ap.getRssi()).isEqualTo(expectedRssi); } private AccessPoint createAccessPointWithScanResultCache() { Bundle bundle = new Bundle(); ArrayList<ScanResult> scanResults = new ArrayList<>(); Loading @@ -203,6 +223,7 @@ public class AccessPointTest { scanResult.level = i; scanResult.BSSID = "bssid-" + i; scanResult.timestamp = SystemClock.elapsedRealtime() * 1000; scanResult.capabilities = ""; scanResults.add(scanResult); } Loading packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/TestAccessPointBuilder.java +17 −14 Original line number Diff line number Diff line Loading @@ -73,25 +73,28 @@ public class TestAccessPointBuilder { return this; } public TestAccessPointBuilder setRssi(int rssi) { mRssi = rssi; return this; } /** * Set the signal level. * Side effect: if this AccessPoint was previously unreachable, * Set the rssi based upon the desired signal level. * * <p>Side effect: if this AccessPoint was previously unreachable, * setting the level will also make it reachable. */ public TestAccessPointBuilder setLevel(int level) { int outputRange = AccessPoint.SIGNAL_LEVELS - 1; if (level > outputRange) { level = outputRange; } else if (level < 0) { level = 0; // Reversal of WifiManager.calculateSignalLevels if (level == 0) { mRssi = MIN_RSSI; } else if (level >= AccessPoint.SIGNAL_LEVELS) { mRssi = MAX_RSSI; } else { float inputRange = MAX_RSSI - MIN_RSSI; float outputRange = AccessPoint.SIGNAL_LEVELS - 1; mRssi = (int) (level * inputRange / outputRange + MIN_RSSI); } int inputRange = MAX_RSSI - MIN_RSSI; // calculate the rssi required to get the level we want. // this is a rearrangement of the formula from WifiManager.calculateSignalLevel() mRssi = (int)((float)(level * inputRange) / (float)outputRange) + MIN_RSSI; return this; } Loading Loading
packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java +8 −3 Original line number Diff line number Diff line Loading @@ -394,8 +394,9 @@ public class AccessPoint implements Comparable<AccessPoint> { * * <p>If the given connection is active, the existing value of {@link #mRssi} will be returned. * If the given AccessPoint is not active, a value will be calculated from previous scan * results, returning the best RSSI for all matching AccessPoints. If the access point is not * connected and there are no scan results, the rssi will be set to {@link #UNREACHABLE_RSSI}. * results, returning the best RSSI for all matching AccessPoints averaged with the previous * value. If the access point is not connected and there are no scan results, the rssi will be * set to {@link #UNREACHABLE_RSSI}. * * <p>Old scan results will be evicted from the cache when this method is invoked. */ Loading @@ -413,8 +414,12 @@ public class AccessPoint implements Comparable<AccessPoint> { } } if (rssi != UNREACHABLE_RSSI && mRssi != UNREACHABLE_RSSI) { mRssi = (mRssi + rssi) / 2; // half-life previous value } else { mRssi = rssi; } } /** * Updates {@link #mSeen} based on the scan result cache. Loading
packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java +21 −0 Original line number Diff line number Diff line Loading @@ -195,6 +195,26 @@ public class AccessPointTest { assertThat(ap.getRssi()).isEqualTo(newRssi); } @Test public void testUpdateWithScanResultShouldAverageRssi() { String ssid = "ssid"; int originalRssi = -65; int newRssi = -80; int expectedRssi = (originalRssi + newRssi) / 2; AccessPoint ap = new TestAccessPointBuilder(mContext).setSsid(ssid).setRssi(originalRssi).build(); ScanResult scanResult = new ScanResult(); scanResult.SSID = ssid; scanResult.level = newRssi; scanResult.BSSID = "bssid"; scanResult.timestamp = SystemClock.elapsedRealtime() * 1000; scanResult.capabilities = ""; assertThat(ap.update(scanResult)).isTrue(); assertThat(ap.getRssi()).isEqualTo(expectedRssi); } private AccessPoint createAccessPointWithScanResultCache() { Bundle bundle = new Bundle(); ArrayList<ScanResult> scanResults = new ArrayList<>(); Loading @@ -203,6 +223,7 @@ public class AccessPointTest { scanResult.level = i; scanResult.BSSID = "bssid-" + i; scanResult.timestamp = SystemClock.elapsedRealtime() * 1000; scanResult.capabilities = ""; scanResults.add(scanResult); } Loading
packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/TestAccessPointBuilder.java +17 −14 Original line number Diff line number Diff line Loading @@ -73,25 +73,28 @@ public class TestAccessPointBuilder { return this; } public TestAccessPointBuilder setRssi(int rssi) { mRssi = rssi; return this; } /** * Set the signal level. * Side effect: if this AccessPoint was previously unreachable, * Set the rssi based upon the desired signal level. * * <p>Side effect: if this AccessPoint was previously unreachable, * setting the level will also make it reachable. */ public TestAccessPointBuilder setLevel(int level) { int outputRange = AccessPoint.SIGNAL_LEVELS - 1; if (level > outputRange) { level = outputRange; } else if (level < 0) { level = 0; // Reversal of WifiManager.calculateSignalLevels if (level == 0) { mRssi = MIN_RSSI; } else if (level >= AccessPoint.SIGNAL_LEVELS) { mRssi = MAX_RSSI; } else { float inputRange = MAX_RSSI - MIN_RSSI; float outputRange = AccessPoint.SIGNAL_LEVELS - 1; mRssi = (int) (level * inputRange / outputRange + MIN_RSSI); } int inputRange = MAX_RSSI - MIN_RSSI; // calculate the rssi required to get the level we want. // this is a rearrangement of the formula from WifiManager.calculateSignalLevel() mRssi = (int)((float)(level * inputRange) / (float)outputRange) + MIN_RSSI; return this; } Loading