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

Commit f753b305 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'WifiDetails'

* changes:
  Consolidate getRssi logic to return mRssi.
  Necessary AccessPoint visibility change for WifiNetworkDetailsFragment.
parents eb4be4d3 54bdcfa0
Loading
Loading
Loading
Loading
+46 −13
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.text.TextUtils;
import android.text.style.TtsSpan;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settingslib.R;

import java.util.ArrayList;
@@ -114,7 +115,7 @@ public class AccessPoint implements Comparable<AccessPoint> {

    public static final int SIGNAL_LEVELS = 4;

    static final int UNREACHABLE_RSSI = Integer.MAX_VALUE;
    static final int UNREACHABLE_RSSI = Integer.MIN_VALUE;

    private final Context mContext;

@@ -170,8 +171,8 @@ public class AccessPoint implements Comparable<AccessPoint> {
            }
        }
        update(mConfig, mInfo, mNetworkInfo);
        mRssi = getRssi();
        mSeen = getSeen();
        updateRssi();
        updateSeen();
        mId = sLastId.incrementAndGet();
    }

@@ -377,19 +378,46 @@ public class AccessPoint implements Comparable<AccessPoint> {
    }

    public int getRssi() {
        return mRssi;
    }

    /**
     * Updates {@link #mRssi}.
     *
     * <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}.
     *
     * <p>Old scan results will be evicted from the cache when this method is invoked.
     */
    private void updateRssi() {
        evictOldScanResults();
        int rssi = Integer.MIN_VALUE;

        if (this.isActive()) {
            return;
        }

        int rssi = UNREACHABLE_RSSI;
        for (ScanResult result : mScanResultCache.values()) {
            if (result.level > rssi) {
                rssi = result.level;
            }
        }

        return rssi;
        mRssi = rssi;
    }

    public long getSeen() {
    /**
     * Updates {@link #mSeen} based on the scan result cache.
     *
     * <p>Old scan results will be evicted from the cache when this method is invoked.
     */
    private void updateSeen() {
        evictOldScanResults();

        // TODO(sghuman): Set to now if connected

        long seen = 0;
        for (ScanResult result : mScanResultCache.values()) {
            if (result.timestamp > seen) {
@@ -397,7 +425,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
            }
        }

        return seen;
        mSeen = seen;
    }

    public NetworkInfo getNetworkInfo() {
@@ -822,13 +850,12 @@ public class AccessPoint implements Comparable<AccessPoint> {

    boolean update(ScanResult result) {
        if (matches(result)) {
            int oldLevel = getLevel();

            /* Add or update the scan result for the BSSID */
            mScanResultCache.put(result.BSSID, result);

            int oldLevel = getLevel();
            int oldRssi = getRssi();
            mSeen = getSeen();
            mRssi = (getRssi() + oldRssi)/2;
            updateSeen();
            updateRssi();
            int newLevel = getLevel();

            if (newLevel > 0 && newLevel != oldLevel && mAccessPointListener != null) {
@@ -848,7 +875,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
        return false;
    }

    boolean update(WifiConfiguration config, WifiInfo info, NetworkInfo networkInfo) {
    public boolean update(WifiConfiguration config, WifiInfo info, NetworkInfo networkInfo) {
        boolean reorder = false;
        if (info != null && isInfoForThisAccessPoint(config, info)) {
            reorder = (mInfo == null);
@@ -877,10 +904,16 @@ public class AccessPoint implements Comparable<AccessPoint> {
        }
    }

    @VisibleForTesting
    void setRssi(int rssi) {
        mRssi = rssi;
    }

    /** Sets the rssi to {@link #UNREACHABLE_RSSI}. */
    void setUnreachable() {
        setRssi(AccessPoint.UNREACHABLE_RSSI);
    }

    int getRankingScore() {
        return mRankingScore;
    }
+3 −2
Original line number Diff line number Diff line
@@ -471,7 +471,8 @@ public class WifiTracker {
                    accessPoint.update(connectionConfig, mLastInfo, mLastNetworkInfo);
                }
                if (mIncludeSaved) {
                    // If saved network not present in scan result then set its Rssi to MAX_VALUE
                    // If saved network not present in scan result then set its Rssi to
                    // UNREACHABLE_RSSI
                    boolean apFound = false;
                    for (ScanResult result : results) {
                        if (result.SSID.equals(accessPoint.getSsidStr())) {
@@ -480,7 +481,7 @@ public class WifiTracker {
                        }
                    }
                    if (!apFound) {
                        accessPoint.setRssi(Integer.MAX_VALUE);
                        accessPoint.setUnreachable();
                    }
                    accessPoints.add(accessPoint);
                    apMap.put(accessPoint.getSsidStr(), accessPoint);
+33 −13
Original line number Diff line number Diff line
@@ -89,21 +89,10 @@ public class AccessPointTest {

    @Test
    public void testThatCopyAccessPoint_scanCacheShouldMatch() {
        Bundle bundle = new Bundle();
        ArrayList<ScanResult> scanResults = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            ScanResult scanResult = new ScanResult();
            scanResult.level = i;
            scanResult.BSSID = "bssid-" + i;
            scanResult.timestamp = SystemClock.elapsedRealtime() * 1000;
            scanResults.add(scanResult);
        }

        bundle.putParcelableArrayList("key_scanresultcache", scanResults);
        AccessPoint original = new AccessPoint(mContext, bundle);
        AccessPoint original = createAccessPointWithScanResultCache();
        assertThat(original.getRssi()).isEqualTo(4);
        AccessPoint copy = new AccessPoint(mContext, createWifiConfiguration());
        assertThat(copy.getRssi()).isEqualTo(Integer.MIN_VALUE);
        assertThat(copy.getRssi()).isEqualTo(AccessPoint.UNREACHABLE_RSSI);
        copy.copyFrom(original);
        assertThat(original.getRssi()).isEqualTo(copy.getRssi());
    }
@@ -190,6 +179,37 @@ public class AccessPointTest {
        assertThat(points.indexOf(firstName)).isLessThan(points.indexOf(lastname));
    }

    @Test
    public void testRssiIsSetFromScanResults() {
        AccessPoint ap = createAccessPointWithScanResultCache();
        int originalRssi = ap.getRssi();
        assertThat(originalRssi).isNotEqualTo(AccessPoint.UNREACHABLE_RSSI);
    }

    @Test
    public void testGetRssiShouldReturnSetRssiValue() {
        AccessPoint ap = createAccessPointWithScanResultCache();
        int originalRssi = ap.getRssi();
        int newRssi = originalRssi - 10;
        ap.setRssi(newRssi);
        assertThat(ap.getRssi()).isEqualTo(newRssi);
    }

    private AccessPoint createAccessPointWithScanResultCache() {
        Bundle bundle = new Bundle();
        ArrayList<ScanResult> scanResults = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            ScanResult scanResult = new ScanResult();
            scanResult.level = i;
            scanResult.BSSID = "bssid-" + i;
            scanResult.timestamp = SystemClock.elapsedRealtime() * 1000;
            scanResults.add(scanResult);
        }

        bundle.putParcelableArrayList("key_scanresultcache", scanResults);
        return new AccessPoint(mContext, bundle);
    }

    private WifiConfiguration createWifiConfiguration() {
        WifiConfiguration configuration = new WifiConfiguration();
        configuration.BSSID = "bssid";