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

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

Merge "Check wifi password length by byte, not char."

parents db6d667e b6584d0a
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import android.net.wifi.WifiConfiguration;
import android.provider.Settings;
import android.text.TextUtils;

import java.nio.charset.StandardCharsets;

public class WifiUtils {

    private static final int SSID_ASCII_MIN_LENGTH = 1;
@@ -38,7 +40,7 @@ public class WifiUtils {
        if (TextUtils.isEmpty(ssid)) {
            return false;
        }
        return ssid.length() > SSID_ASCII_MAX_LENGTH;
        return ssid.getBytes(StandardCharsets.UTF_8).length > SSID_ASCII_MAX_LENGTH;
    }

    public static boolean isSSIDTooShort(String ssid) {
@@ -59,6 +61,7 @@ public class WifiUtils {

    /**
     * This method is a stripped and negated version of WifiConfigStore.canModifyNetwork.
     *
     * @param context Context of caller
     * @param config  The WiFi config.
     * @return true if Settings cannot modify the config due to lockDown.
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ public class WifiUtilsTest {
    @Test
    public void testSSID() {
        assertThat(WifiUtils.isSSIDTooLong("123")).isFalse();
        assertThat(WifiUtils.isSSIDTooLong("☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎")).isTrue();
        assertThat(WifiUtils.isSSIDTooLong("☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎")).isTrue();

        assertThat(WifiUtils.isSSIDTooShort("123")).isFalse();
        assertThat(WifiUtils.isSSIDTooShort("")).isTrue();