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

Commit f4f779d5 authored by Eric Schwarzenbach's avatar Eric Schwarzenbach Committed by android-build-merger
Browse files

Merge "Sort APs by Speed label value instead of ranking score." into oc-mr1-dev

am: 3b8ce7c6

Change-Id: I43772768b4fe58de3a6b4fa1af909ed06122f802
parents a35b6960 3b8ce7c6
Loading
Loading
Loading
Loading
+10 −29
Original line number Original line Diff line number Diff line
@@ -178,7 +178,6 @@ public class AccessPoint implements Comparable<AccessPoint> {


    private Object mTag;
    private Object mTag;


    private int mRankingScore = Integer.MIN_VALUE;
    private int mSpeed = Speed.NONE;
    private int mSpeed = Speed.NONE;
    private boolean mIsScoredNetworkMetered = false;
    private boolean mIsScoredNetworkMetered = false;


@@ -284,7 +283,6 @@ public class AccessPoint implements Comparable<AccessPoint> {
        this.mId = that.mId;
        this.mId = that.mId;
        this.mSpeed = that.mSpeed;
        this.mSpeed = that.mSpeed;
        this.mIsScoredNetworkMetered = that.mIsScoredNetworkMetered;
        this.mIsScoredNetworkMetered = that.mIsScoredNetworkMetered;
        this.mRankingScore = that.mRankingScore;
    }
    }


    /**
    /**
@@ -295,7 +293,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
    *   1. Active before inactive
    *   1. Active before inactive
    *   2. Reachable before unreachable
    *   2. Reachable before unreachable
    *   3. Saved before unsaved
    *   3. Saved before unsaved
    *   4. (Internal only) Network ranking score
    *   4. Network speed value
    *   5. Stronger signal before weaker signal
    *   5. Stronger signal before weaker signal
    *   6. SSID alphabetically
    *   6. SSID alphabetically
    *
    *
@@ -316,9 +314,9 @@ public class AccessPoint implements Comparable<AccessPoint> {
        if (isSaved() && !other.isSaved()) return -1;
        if (isSaved() && !other.isSaved()) return -1;
        if (!isSaved() && other.isSaved()) return 1;
        if (!isSaved() && other.isSaved()) return 1;


        // Higher scores go before lower scores
        // Faster speeds go before slower speeds
        if (getRankingScore() != other.getRankingScore()) {
        if (getSpeed() != other.getSpeed()) {
            return (getRankingScore() > other.getRankingScore()) ? -1 : 1;
            return other.getSpeed() - getSpeed();
        }
        }


        // Sort by signal strength, bucketed by level
        // Sort by signal strength, bucketed by level
@@ -377,9 +375,6 @@ public class AccessPoint implements Comparable<AccessPoint> {
            builder.append(',').append(securityToString(security, pskType));
            builder.append(',').append(securityToString(security, pskType));
        }
        }
        builder.append(",level=").append(getLevel());
        builder.append(",level=").append(getLevel());
        if (mRankingScore != Integer.MIN_VALUE) {
            builder.append(",rankingScore=").append(mRankingScore);
        }
        if (mSpeed != Speed.NONE) {
        if (mSpeed != Speed.NONE) {
            builder.append(",speed=").append(mSpeed);
            builder.append(",speed=").append(mSpeed);
        }
        }
@@ -410,9 +405,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
     */
     */
    private boolean updateScores(WifiNetworkScoreCache scoreCache) {
    private boolean updateScores(WifiNetworkScoreCache scoreCache) {
        int oldSpeed = mSpeed;
        int oldSpeed = mSpeed;
        int oldRankingScore = mRankingScore;
        mSpeed = Speed.NONE;
        mSpeed = Speed.NONE;
        mRankingScore = Integer.MIN_VALUE;


        if (isActive() && mInfo != null) {
        if (isActive() && mInfo != null) {
            NetworkKey key = new NetworkKey(new WifiKey(
            NetworkKey key = new NetworkKey(new WifiKey(
@@ -420,9 +413,6 @@ public class AccessPoint implements Comparable<AccessPoint> {
            ScoredNetwork score = scoreCache.getScoredNetwork(key);
            ScoredNetwork score = scoreCache.getScoredNetwork(key);
            if (score != null) {
            if (score != null) {
                mSpeed = score.calculateBadge(mInfo.getRssi());
                mSpeed = score.calculateBadge(mInfo.getRssi());
                if (score.hasRankingScore()) {
                    mRankingScore = score.calculateRankingScore(mInfo.getRssi());
                }
            }
            }
        } else {
        } else {
            for (ScanResult result : mScanResultCache.values()) {
            for (ScanResult result : mScanResultCache.values()) {
@@ -430,11 +420,6 @@ public class AccessPoint implements Comparable<AccessPoint> {
                if (score == null) {
                if (score == null) {
                    continue;
                    continue;
                }
                }

                if (score.hasRankingScore()) {
                    mRankingScore =
                            Math.max(mRankingScore, score.calculateRankingScore(result.level));
                }
                // TODO(sghuman): Rename calculateBadge API
                // TODO(sghuman): Rename calculateBadge API
                mSpeed = Math.max(mSpeed, score.calculateBadge(result.level));
                mSpeed = Math.max(mSpeed, score.calculateBadge(result.level));
            }
            }
@@ -444,7 +429,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
            Log.i(TAG, String.format("%s: Set speed to %d", ssid, mSpeed));
            Log.i(TAG, String.format("%s: Set speed to %d", ssid, mSpeed));
        }
        }


        return (oldSpeed != mSpeed || oldRankingScore != mRankingScore);
        return oldSpeed != mSpeed;
    }
    }


    /**
    /**
@@ -804,12 +789,15 @@ public class AccessPoint implements Comparable<AccessPoint> {
            }
            }
        }
        }


        // If Speed label is present, use the preference combination to prepend it to the summary.
        // If Speed label and summary are both present, use the preference combination to combine
        if (mSpeed != Speed.NONE) {
        // the two, else return the non-null one.
        if (getSpeedLabel() != null && summary.length() != 0) {
            return mContext.getResources().getString(
            return mContext.getResources().getString(
                    R.string.preference_summary_default_combination,
                    R.string.preference_summary_default_combination,
                    getSpeedLabel(),
                    getSpeedLabel(),
                    summary.toString());
                    summary.toString());
        } else if (getSpeedLabel() != null) {
            return getSpeedLabel();
        } else {
        } else {
            return summary.toString();
            return summary.toString();
        }
        }
@@ -839,9 +827,6 @@ public class AccessPoint implements Comparable<AccessPoint> {
            visibility.append(" rssi=").append(mInfo.getRssi());
            visibility.append(" rssi=").append(mInfo.getRssi());
            visibility.append(" ");
            visibility.append(" ");
            visibility.append(" score=").append(mInfo.score);
            visibility.append(" score=").append(mInfo.score);
            if (mRankingScore != Integer.MIN_VALUE) {
                visibility.append(" rankingScore=").append(getRankingScore());
            }
            if (mSpeed != Speed.NONE) {
            if (mSpeed != Speed.NONE) {
                visibility.append(" speed=").append(getSpeedLabel());
                visibility.append(" speed=").append(getSpeedLabel());
            }
            }
@@ -1146,10 +1131,6 @@ public class AccessPoint implements Comparable<AccessPoint> {
        setRssi(AccessPoint.UNREACHABLE_RSSI);
        setRssi(AccessPoint.UNREACHABLE_RSSI);
    }
    }


    int getRankingScore() {
        return mRankingScore;
    }

    int getSpeed() { return mSpeed;}
    int getSpeed() { return mSpeed;}


    @Nullable
    @Nullable
+8 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiInfo;
import android.os.Bundle;
import android.os.Bundle;
import com.android.settingslib.wifi.AccessPoint.Speed;


import java.util.ArrayList;
import java.util.ArrayList;


@@ -40,6 +41,7 @@ public class TestAccessPointBuilder {


    // set some sensible defaults
    // set some sensible defaults
    private String mBssid = null;
    private String mBssid = null;
    private int mSpeed = Speed.NONE;
    private int mRssi = AccessPoint.UNREACHABLE_RSSI;
    private int mRssi = AccessPoint.UNREACHABLE_RSSI;
    private int mNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
    private int mNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
    private String ssid = "TestSsid";
    private String ssid = "TestSsid";
@@ -78,6 +80,7 @@ public class TestAccessPointBuilder {
            bundle.putParcelableArrayList(AccessPoint.KEY_SCANRESULTCACHE, mScanResultCache);
            bundle.putParcelableArrayList(AccessPoint.KEY_SCANRESULTCACHE, mScanResultCache);
        }
        }
        bundle.putInt(AccessPoint.KEY_SECURITY, mSecurity);
        bundle.putInt(AccessPoint.KEY_SECURITY, mSecurity);
        bundle.putInt(AccessPoint.KEY_SPEED, mSpeed);


        AccessPoint ap = new AccessPoint(mContext, bundle);
        AccessPoint ap = new AccessPoint(mContext, bundle);
        ap.setRssi(mRssi);
        ap.setRssi(mRssi);
@@ -127,6 +130,11 @@ public class TestAccessPointBuilder {
        return this;
        return this;
    }
    }


    public TestAccessPointBuilder setSpeed(int speed) {
        mSpeed = speed;
        return this;
    }

    /**
    /**
    * Set whether the AccessPoint is reachable.
    * Set whether the AccessPoint is reachable.
    * Side effect: if the signal level was not previously set,
    * Side effect: if the signal level was not previously set,
+9 −2
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@ import android.text.style.TtsSpan;


import com.android.settingslib.R;
import com.android.settingslib.R;


import com.android.settingslib.wifi.AccessPoint.Speed;
import org.junit.Before;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
@@ -145,7 +146,13 @@ public class AccessPointTest {
        assertSortingWorks(savedAp, notSavedAp);
        assertSortingWorks(savedAp, notSavedAp);
    }
    }


    //TODO: add tests for mRankingScore sort order if ranking is exposed
    @Test
    public void testCompareTo_GivesHighSpeedBeforeLowSpeed() {
        AccessPoint fastAp = new TestAccessPointBuilder(mContext).setSpeed(Speed.FAST).build();
        AccessPoint slowAp = new TestAccessPointBuilder(mContext).setSpeed(Speed.SLOW).build();

        assertSortingWorks(fastAp, slowAp);
    }


    @Test
    @Test
    public void testCompareTo_GivesHighLevelBeforeLowLevel() {
    public void testCompareTo_GivesHighLevelBeforeLowLevel() {
@@ -505,7 +512,7 @@ public class AccessPointTest {
    }
    }


    /**
    /**
    * Assert that the first AccessPoint appears after the second AccessPoint
    * Assert that the first AccessPoint appears before the second AccessPoint
    * once sorting has been completed.
    * once sorting has been completed.
    */
    */
    private void assertSortingWorks(AccessPoint first, AccessPoint second) {
    private void assertSortingWorks(AccessPoint first, AccessPoint second) {