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

Commit 7143905b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix Wi-Fi level out of range crash" into tm-dev am: 8146cd00 am: 77abe668

parents dc8692bd 77abe668
Loading
Loading
Loading
Loading
+11 −4
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.net.wifi.WifiConfiguration.NetworkSelectionStatus;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiInfo;
import android.os.Bundle;
import android.os.Bundle;
import android.os.SystemClock;
import android.os.SystemClock;
import android.util.Log;


import androidx.annotation.VisibleForTesting;
import androidx.annotation.VisibleForTesting;


@@ -40,6 +41,8 @@ import java.util.Map;


public class WifiUtils {
public class WifiUtils {


    private static final String TAG = "WifiUtils";

    private static final int INVALID_RSSI = -127;
    private static final int INVALID_RSSI = -127;


    /**
    /**
@@ -314,13 +317,17 @@ public class WifiUtils {
     *
     *
     * @param level The number of bars to show (0-4)
     * @param level The number of bars to show (0-4)
     * @param noInternet True if a connected Wi-Fi network cannot access the Internet
     * @param noInternet True if a connected Wi-Fi network cannot access the Internet
     * @throws IllegalArgumentException if an invalid RSSI level is given.
     */
     */
    public static int getInternetIconResource(int level, boolean noInternet) {
    public static int getInternetIconResource(int level, boolean noInternet) {
        if (level < 0 || level >= WIFI_PIE.length) {
        int wifiLevel = level;
            throw new IllegalArgumentException("No Wifi icon found for level: " + level);
        if (wifiLevel < 0) {
        }
            Log.e(TAG, "Wi-Fi level is out of range! level:" + level);
        return noInternet ? NO_INTERNET_WIFI_PIE[level] : WIFI_PIE[level];
            wifiLevel = 0;
        } else if (level >= WIFI_PIE.length) {
            Log.e(TAG, "Wi-Fi level is out of range! level:" + level);
            wifiLevel = WIFI_PIE.length - 1;
        }
        return noInternet ? NO_INTERNET_WIFI_PIE[wifiLevel] : WIFI_PIE[wifiLevel];
    }
    }


    /**
    /**
+13 −0
Original line number Original line Diff line number Diff line
@@ -187,6 +187,19 @@ public class WifiUtilsTest {
        assertThat(bundle.getString(WifiUtils.KEY_CHOSEN_WIFIENTRY_KEY)).isEqualTo(key);
        assertThat(bundle.getString(WifiUtils.KEY_CHOSEN_WIFIENTRY_KEY)).isEqualTo(key);
    }
    }


    @Test
    public void getInternetIconResource_levelOutOfRange_shouldNotCrash() {
        // Verify that Wi-Fi level is less than the minimum level (0)
        int level = -1;
        WifiUtils.getInternetIconResource(level, false /* noInternet*/);
        WifiUtils.getInternetIconResource(level, true /* noInternet*/);

        // Verify that Wi-Fi level is greater than the maximum level (4)
        level = WifiUtils.WIFI_PIE.length;
        WifiUtils.getInternetIconResource(level, false /* noInternet*/);
        WifiUtils.getInternetIconResource(level, true /* noInternet*/);
    }

    @Test
    @Test
    public void testInternetIconInjector_getIcon_returnsCorrectValues() {
    public void testInternetIconInjector_getIcon_returnsCorrectValues() {
        WifiUtils.InternetIconInjector iconInjector = new WifiUtils.InternetIconInjector(mContext);
        WifiUtils.InternetIconInjector iconInjector = new WifiUtils.InternetIconInjector(mContext);