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

Commit b6584d0a authored by Fan Zhang's avatar Fan Zhang
Browse files

Check wifi password length by byte, not char.

Change-Id: Ie6dc441780660c52ff01a2bced79a4e95200d731
Fixes: 79209073
Test: robotest
parent 7bc2f981
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();