Fix bug in Add network fragment

After we switch secutiry from EAP to WPA, add button will become
disabled forever. Main reason is that we use view visibility to decide
which security type it is. In this case target view is visible while its
parent view is gone. So even though UI shows correctly however we still
think it is in EAP mode.

This CL check the mAccessPointSecurity directly instead of depending on
fragile view.

Fixes: 114689178
Test: RunSettingsRoboTests

Change-Id: I4284d25e6bf86ee7c5e7c0e17f0834c719d8d587
This commit is contained in:
jackqdyulei
2018-09-13 13:46:16 -07:00
parent e5791f3c99
commit 0c6f8065c2
2 changed files with 19 additions and 6 deletions

View File

@@ -465,8 +465,7 @@ public class WifiConfigController implements TextWatcher,
} else { } else {
enabled = ipAndProxyFieldsAreValid(); enabled = ipAndProxyFieldsAreValid();
} }
if (mEapCaCertSpinner != null if (mAccessPointSecurity == AccessPoint.SECURITY_EAP) {
&& mView.findViewById(R.id.l_ca_cert).getVisibility() != View.GONE) {
String caCertSelection = (String) mEapCaCertSpinner.getSelectedItem(); String caCertSelection = (String) mEapCaCertSpinner.getSelectedItem();
if (caCertSelection.equals(mUnspecifiedCertString)) { if (caCertSelection.equals(mUnspecifiedCertString)) {
// Disallow submit if the user has not selected a CA certificate for an EAP network // Disallow submit if the user has not selected a CA certificate for an EAP network
@@ -482,10 +481,8 @@ public class WifiConfigController implements TextWatcher,
enabled = false; enabled = false;
} }
} }
if (mEapUserCertSpinner != null if (mAccessPointSecurity == AccessPoint.SECURITY_EAP
&& mView.findViewById(R.id.l_user_cert).getVisibility() != View.GONE && mEapUserCertSpinner.getSelectedItem().equals(mUnspecifiedCertString)) {
&& ((String) mEapUserCertSpinner.getSelectedItem())
.equals(mUnspecifiedCertString)) {
// Disallow submit if the user has not selected a user certificate for an EAP network // Disallow submit if the user has not selected a user certificate for an EAP network
// configuration. // configuration.
enabled = false; enabled = false;

View File

@@ -183,6 +183,22 @@ public class WifiConfigControllerTest {
mController.isSubmittable(); mController.isSubmittable();
} }
@Test
public void isSubmittable_EapToPskWithValidPassword_shouldReturnTrue() {
final TextView password = mView.findViewById(R.id.password);
final Spinner securitySpinner = mView.findViewById(R.id.security);
assertThat(password).isNotNull();
assertThat(securitySpinner).isNotNull();
when(mAccessPoint.isSaved()).thenReturn(true);
// Change it from EAP to PSK
mController.onItemSelected(securitySpinner, null, AccessPoint.SECURITY_EAP, 0);
mController.onItemSelected(securitySpinner, null, AccessPoint.SECURITY_PSK, 0);
password.setText(GOOD_PSK);
assertThat(mController.isSubmittable()).isTrue();
}
@Test @Test
public void getSignalString_notReachable_shouldHaveNoSignalString() { public void getSignalString_notReachable_shouldHaveNoSignalString() {
when(mAccessPoint.isReachable()).thenReturn(false); when(mAccessPoint.isReachable()).thenReturn(false);