Loading src/com/android/settings/wifi/WifiUtils.java +10 −7 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.Context; import android.content.pm.PackageManager; import android.net.NetworkCapabilities; import android.net.wifi.ScanResult; import android.net.wifi.SoftApConfiguration; import android.net.wifi.WifiConfiguration; import android.os.UserHandle; import android.os.UserManager; Loading @@ -38,8 +39,6 @@ public class WifiUtils { private static final int SSID_ASCII_MIN_LENGTH = 1; private static final int SSID_ASCII_MAX_LENGTH = 32; private static final int PASSWORD_MIN_LENGTH = 8; private static final int PASSWORD_MAX_LENGTH = 63; public static boolean isSSIDTooLong(String ssid) { Loading @@ -56,13 +55,17 @@ public class WifiUtils { return ssid.length() < SSID_ASCII_MIN_LENGTH; } public static boolean isHotspotPasswordValid(String password) { if (TextUtils.isEmpty(password)) { /** * Check if the WPA2-PSK hotspot password is valid. */ public static boolean isHotspotWpa2PasswordValid(String password) { final SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder(); try { configBuilder.setPassphrase(password, SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); } catch (IllegalArgumentException e) { return false; } final int length = password.length(); return length >= PASSWORD_MIN_LENGTH && length <= PASSWORD_MAX_LENGTH; return true; } /** Loading src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java +1 −1 Original line number Diff line number Diff line Loading @@ -118,7 +118,7 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer @Override public boolean isTextValid(String value) { return WifiUtils.isHotspotPasswordValid(value); return WifiUtils.isHotspotWpa2PasswordValid(value); } private static String generateRandomPassword() { Loading tests/robotests/src/com/android/settings/wifi/WifiUtilsTest.java +10 −10 Original line number Diff line number Diff line Loading @@ -18,10 +18,6 @@ package com.android.settings.wifi; import static com.google.common.truth.Truth.assertThat; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import static org.mockito.Mockito.spy; import android.content.Context; Loading @@ -30,6 +26,9 @@ import android.os.Bundle; import com.android.settingslib.wifi.AccessPoint; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) Loading @@ -48,11 +47,12 @@ public class WifiUtilsTest { public void testPassword() { final String longPassword = "123456789012345678901234567890" + "1234567890123456789012345678901234567890"; assertThat(WifiUtils.isHotspotPasswordValid("123")).isFalse(); assertThat(WifiUtils.isHotspotPasswordValid("12345678")).isTrue(); assertThat(WifiUtils.isHotspotPasswordValid("1234567890")).isTrue(); assertThat(WifiUtils.isHotspotPasswordValid(longPassword)).isFalse(); assertThat(WifiUtils.isHotspotPasswordValid("")).isFalse(); assertThat(WifiUtils.isHotspotWpa2PasswordValid("123")).isFalse(); assertThat(WifiUtils.isHotspotWpa2PasswordValid("12345678")).isTrue(); assertThat(WifiUtils.isHotspotWpa2PasswordValid("1234567890")).isTrue(); assertThat(WifiUtils.isHotspotWpa2PasswordValid(longPassword)).isFalse(); assertThat(WifiUtils.isHotspotWpa2PasswordValid("")).isFalse(); assertThat(WifiUtils.isHotspotWpa2PasswordValid("€¥£")).isFalse(); } @Test Loading Loading
src/com/android/settings/wifi/WifiUtils.java +10 −7 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.Context; import android.content.pm.PackageManager; import android.net.NetworkCapabilities; import android.net.wifi.ScanResult; import android.net.wifi.SoftApConfiguration; import android.net.wifi.WifiConfiguration; import android.os.UserHandle; import android.os.UserManager; Loading @@ -38,8 +39,6 @@ public class WifiUtils { private static final int SSID_ASCII_MIN_LENGTH = 1; private static final int SSID_ASCII_MAX_LENGTH = 32; private static final int PASSWORD_MIN_LENGTH = 8; private static final int PASSWORD_MAX_LENGTH = 63; public static boolean isSSIDTooLong(String ssid) { Loading @@ -56,13 +55,17 @@ public class WifiUtils { return ssid.length() < SSID_ASCII_MIN_LENGTH; } public static boolean isHotspotPasswordValid(String password) { if (TextUtils.isEmpty(password)) { /** * Check if the WPA2-PSK hotspot password is valid. */ public static boolean isHotspotWpa2PasswordValid(String password) { final SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder(); try { configBuilder.setPassphrase(password, SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); } catch (IllegalArgumentException e) { return false; } final int length = password.length(); return length >= PASSWORD_MIN_LENGTH && length <= PASSWORD_MAX_LENGTH; return true; } /** Loading
src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java +1 −1 Original line number Diff line number Diff line Loading @@ -118,7 +118,7 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer @Override public boolean isTextValid(String value) { return WifiUtils.isHotspotPasswordValid(value); return WifiUtils.isHotspotWpa2PasswordValid(value); } private static String generateRandomPassword() { Loading
tests/robotests/src/com/android/settings/wifi/WifiUtilsTest.java +10 −10 Original line number Diff line number Diff line Loading @@ -18,10 +18,6 @@ package com.android.settings.wifi; import static com.google.common.truth.Truth.assertThat; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import static org.mockito.Mockito.spy; import android.content.Context; Loading @@ -30,6 +26,9 @@ import android.os.Bundle; import com.android.settingslib.wifi.AccessPoint; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) Loading @@ -48,11 +47,12 @@ public class WifiUtilsTest { public void testPassword() { final String longPassword = "123456789012345678901234567890" + "1234567890123456789012345678901234567890"; assertThat(WifiUtils.isHotspotPasswordValid("123")).isFalse(); assertThat(WifiUtils.isHotspotPasswordValid("12345678")).isTrue(); assertThat(WifiUtils.isHotspotPasswordValid("1234567890")).isTrue(); assertThat(WifiUtils.isHotspotPasswordValid(longPassword)).isFalse(); assertThat(WifiUtils.isHotspotPasswordValid("")).isFalse(); assertThat(WifiUtils.isHotspotWpa2PasswordValid("123")).isFalse(); assertThat(WifiUtils.isHotspotWpa2PasswordValid("12345678")).isTrue(); assertThat(WifiUtils.isHotspotWpa2PasswordValid("1234567890")).isTrue(); assertThat(WifiUtils.isHotspotWpa2PasswordValid(longPassword)).isFalse(); assertThat(WifiUtils.isHotspotWpa2PasswordValid("")).isFalse(); assertThat(WifiUtils.isHotspotWpa2PasswordValid("€¥£")).isFalse(); } @Test Loading