Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ce78a5f2 authored by Sundeep Ghuman's avatar Sundeep Ghuman
Browse files

Average scan results for AccessPoints.

This reduces jitter in the WifiTracker and is modeled after a prior
broken implementation which attempted to half-life the rssi each time
AccessPoint.update(ScanResult) is called.

Bug: 34774783
Test: runtest --path
frameworks/base/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java

Change-Id: Iab3f9914af40f2fd56e8ae7b45dcbd62176c8a67
parent b9647ebb
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -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.
     */
@@ -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.
+21 −0
Original line number Diff line number Diff line
@@ -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<>();
@@ -203,6 +223,7 @@ public class AccessPointTest {
            scanResult.level = i;
            scanResult.BSSID = "bssid-" + i;
            scanResult.timestamp = SystemClock.elapsedRealtime() * 1000;
            scanResult.capabilities = "";
            scanResults.add(scanResult);
        }

+8 −2
Original line number Diff line number Diff line
@@ -73,9 +73,15 @@ 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) {