Merge "[Wi-Fi] Check if domain field is not empty when users choose a ca certificate" into rvc-qpr-dev am: f833684e28

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/12248953

Change-Id: I20946b3619d96eefbb23d48ba4b43b2bc68ed115
This commit is contained in:
Arc Wang
2020-08-01 02:57:37 +00:00
committed by Automerger Merge Worker
4 changed files with 72 additions and 18 deletions

View File

@@ -554,12 +554,11 @@ public class WifiConfigController implements TextWatcher,
// Disallow submit if the user has not selected a CA certificate for an EAP network
// configuration.
enabled = false;
}
if (caCertSelection.equals(mUseSystemCertsString)
} else if (!caCertSelection.equals(mDoNotValidateEapServerString)
&& mEapDomainView != null
&& mView.findViewById(R.id.l_domain).getVisibility() != View.GONE
&& TextUtils.isEmpty(mEapDomainView.getText().toString())) {
// Disallow submit if the user chooses to use system certificates for EAP server
// Disallow submit if the user chooses to use a certificate for EAP server
// validation, but does not provide a domain.
enabled = false;
}
@@ -595,14 +594,12 @@ public class WifiConfigController implements TextWatcher,
// Display warning if user chooses not to validate the EAP server with a
// user-supplied CA certificate in an EAP network configuration.
mView.findViewById(R.id.no_ca_cert_warning).setVisibility(View.VISIBLE);
}
if (caCertSelection.equals(mUseSystemCertsString)
} else if (!caCertSelection.equals(mUnspecifiedCertString)
&& mEapDomainView != null
&& mView.findViewById(R.id.l_domain).getVisibility() != View.GONE
&& TextUtils.isEmpty(mEapDomainView.getText().toString())) {
// Display warning if user chooses to use pre-installed public CA certificates
// without restricting the server domain that these certificates can be used to
// validate.
// Display warning if user chooses to use a certificate without restricting the
// server domain that these certificates can be used to validate.
mView.findViewById(R.id.no_domain_warning).setVisibility(View.VISIBLE);
}
}
@@ -1713,7 +1710,8 @@ public class WifiConfigController implements TextWatcher,
mContext.getResources().getStringArray(contentStringArrayResId));
}
private ArrayAdapter<CharSequence> getSpinnerAdapter(
@VisibleForTesting
ArrayAdapter<CharSequence> getSpinnerAdapter(
String[] contentStringArray) {
ArrayAdapter<CharSequence> spinnerAdapter = new ArrayAdapter<>(mContext,
android.R.layout.simple_spinner_item, contentStringArray);

View File

@@ -533,12 +533,11 @@ public class WifiConfigController2 implements TextWatcher,
// Disallow submit if the user has not selected a CA certificate for an EAP network
// configuration.
enabled = false;
}
if (caCertSelection.equals(mUseSystemCertsString)
} else if (!caCertSelection.equals(mDoNotValidateEapServerString)
&& mEapDomainView != null
&& mView.findViewById(R.id.l_domain).getVisibility() != View.GONE
&& TextUtils.isEmpty(mEapDomainView.getText().toString())) {
// Disallow submit if the user chooses to use system certificates for EAP server
// Disallow submit if the user chooses to use a certificate for EAP server
// validation, but does not provide a domain.
enabled = false;
}
@@ -574,14 +573,12 @@ public class WifiConfigController2 implements TextWatcher,
// Display warning if user chooses not to validate the EAP server with a
// user-supplied CA certificate in an EAP network configuration.
mView.findViewById(R.id.no_ca_cert_warning).setVisibility(View.VISIBLE);
}
if (caCertSelection.equals(mUseSystemCertsString)
} else if (!caCertSelection.equals(mUnspecifiedCertString)
&& mEapDomainView != null
&& mView.findViewById(R.id.l_domain).getVisibility() != View.GONE
&& TextUtils.isEmpty(mEapDomainView.getText().toString())) {
// Display warning if user chooses to use pre-installed public CA certificates
// without restricting the server domain that these certificates can be used to
// validate.
// Display warning if user chooses to use a certificate without restricting the
// server domain that these certificates can be used to validate.
mView.findViewById(R.id.no_domain_warning).setVisibility(View.VISIBLE);
}
}
@@ -1696,7 +1693,8 @@ public class WifiConfigController2 implements TextWatcher,
mContext.getResources().getStringArray(contentStringArrayResId));
}
private ArrayAdapter<CharSequence> getSpinnerAdapter(
@VisibleForTesting
ArrayAdapter<CharSequence> getSpinnerAdapter(
String[] contentStringArray) {
ArrayAdapter<CharSequence> spinnerAdapter = new ArrayAdapter<>(mContext,
android.R.layout.simple_spinner_item, contentStringArray);

View File

@@ -224,6 +224,35 @@ public class WifiConfigController2Test {
assertThat(mController.isSubmittable()).isTrue();
}
@Test
public void isSubmittable_caCertWithoutDomain_shouldReturnFalse() {
when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
WifiConfigUiBase2.MODE_CONNECT);
mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
final Spinner eapCaCertSpinner = mView.findViewById(R.id.ca_cert);
eapCaCertSpinner.setAdapter(mController.getSpinnerAdapter(new String[]{"certificate"}));
eapCaCertSpinner.setSelection(0);
mView.findViewById(R.id.l_domain).setVisibility(View.VISIBLE);
assertThat(mController.isSubmittable()).isFalse();
}
@Test
public void isSubmittable_caCertWithDomain_shouldReturnTrue() {
when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
WifiConfigUiBase2.MODE_CONNECT);
mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
final Spinner eapCaCertSpinner = mView.findViewById(R.id.ca_cert);
eapCaCertSpinner.setAdapter(mController.getSpinnerAdapter(new String[]{"certificate"}));
eapCaCertSpinner.setSelection(0);
mView.findViewById(R.id.l_domain).setVisibility(View.VISIBLE);
((TextView) mView.findViewById(R.id.domain)).setText("fakeDomain");
assertThat(mController.isSubmittable()).isTrue();
}
@Test
public void getSignalString_notReachable_shouldHaveNoSignalString() {
when(mWifiEntry.getLevel()).thenReturn(WifiEntry.WIFI_LEVEL_UNREACHABLE);

View File

@@ -218,6 +218,35 @@ public class WifiConfigControllerTest {
assertThat(mController.isSubmittable()).isTrue();
}
@Test
public void isSubmittable_caCertWithoutDomain_shouldReturnFalse() {
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_EAP);
mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
WifiConfigUiBase.MODE_CONNECT);
mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
final Spinner eapCaCertSpinner = mView.findViewById(R.id.ca_cert);
eapCaCertSpinner.setAdapter(mController.getSpinnerAdapter(new String[]{"certificate"}));
eapCaCertSpinner.setSelection(0);
mView.findViewById(R.id.l_domain).setVisibility(View.VISIBLE);
assertThat(mController.isSubmittable()).isFalse();
}
@Test
public void isSubmittable_caCertWithDomain_shouldReturnTrue() {
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_EAP);
mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
WifiConfigUiBase.MODE_CONNECT);
mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
final Spinner eapCaCertSpinner = mView.findViewById(R.id.ca_cert);
eapCaCertSpinner.setAdapter(mController.getSpinnerAdapter(new String[]{"certificate"}));
eapCaCertSpinner.setSelection(0);
mView.findViewById(R.id.l_domain).setVisibility(View.VISIBLE);
((TextView) mView.findViewById(R.id.domain)).setText("fakeDomain");
assertThat(mController.isSubmittable()).isTrue();
}
@Test
public void getSignalString_notReachable_shouldHaveNoSignalString() {
when(mAccessPoint.isReachable()).thenReturn(false);