Check wifi password length by byte, not char.

Change-Id: Ie6dc441780660c52ff01a2bced79a4e95200d731
Fixes: 79209073
Test: robotest
This commit is contained in:
Fan Zhang
2018-06-08 13:18:07 -07:00
parent 7bc2f98188
commit b6584d0a5a
2 changed files with 6 additions and 3 deletions

View File

@@ -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.

View File

@@ -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();