Check wifi password length by byte, not char.
Change-Id: Ie6dc441780660c52ff01a2bced79a4e95200d731 Fixes: 79209073 Test: robotest
This commit is contained in:
@@ -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.
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user