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

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

Fix the number of levels returned by getLevels().

This was previously out of sync with WifiManager.RSSI_LEVELS which
caused UI issues where the wrong number of bars were shown in various
places. This is the permanent fix to a previous temporary fix.

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

Change-Id: Iadb2a6131ee9fbc4f297766d0bc3bc82eca40a4d
parent 54bdcfa0
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -113,9 +113,14 @@ public class AccessPoint implements Comparable<AccessPoint> {
    private static final int PSK_WPA2 = 2;
    private static final int PSK_WPA_WPA2 = 3;

    public static final int SIGNAL_LEVELS = 4;
    /**
     * The number of distinct wifi levels.
     *
     * <p>Must keep in sync with {@link R.array.wifi_signal} and {@link WifiManager#RSSI_LEVELS}.
     */
    public static final int SIGNAL_LEVELS = 5;

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

    private final Context mContext;

@@ -370,10 +375,13 @@ public class AccessPoint implements Comparable<AccessPoint> {
        return mInfo;
    }

    /**
     * Returns the number of levels to show for a Wifi icon, from 0 to {@link #SIGNAL_LEVELS}-1.
     *
     * <p>Use {@#isReachable()} to determine if an AccessPoint is in range, as this method will
     * always return at least 0.
     */
    public int getLevel() {
        if (!isReachable()) {
            return -1;
        }
        return WifiManager.calculateSignalLevel(mRssi, SIGNAL_LEVELS);
    }

@@ -923,7 +931,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
    }

    /** Return true if the current RSSI is reachable, and false otherwise. */
    boolean isReachable() {
    public boolean isReachable() {
        return mRssi != UNREACHABLE_RSSI;
    }

+1 −2
Original line number Diff line number Diff line
@@ -223,8 +223,7 @@ public class AccessPointPreference extends Preference {
        }

        final Context context = getContext();
        int level = WifiManager.calculateSignalLevel(
                mAccessPoint.getRssi(), WifiManager.RSSI_LEVELS);
        int level = mAccessPoint.getLevel();
        int wifiBadge = mAccessPoint.getBadge();
        if (level != mLevel || wifiBadge != mWifiBadge) {
            mLevel = level;