<string name="vpn_no_ca_cert">(don\u2019t verify server)</string>
<!-- Option to use the server certificate received from the VPN server. [CHAR LIMIT=40] -->
<string name="vpn_no_server_cert">(received from server)</string>
+ <!-- Reason for Always-on VPN checkbox being disabled: the selected VPN type doesn't support always-on. [CHAR LIMIT=120] -->
+ <string name="vpn_always_on_invalid_reason_type">The selected VPN type can\u2019t be always on</string>
+ <!-- Reason for Always-on VPN checkbox being disabled: the server address is invalid. [CHAR LIMIT=120] -->
+ <string name="vpn_always_on_invalid_reason_server">Always-on VPN only supports numeric server addresses</string>
+ <!-- Reason for Always-on VPN checkbox being disabled: no DNS is found. [CHAR LIMIT=120] -->
+ <string name="vpn_always_on_invalid_reason_no_dns">A DNS server must be specified for always-on VPN</string>
+ <!-- Reason for Always-on VPN checkbox being disabled: DNS server addresses are invalid. [CHAR LIMIT=120] -->
+ <string name="vpn_always_on_invalid_reason_dns">DNS server addresses must be numeric for always-on VPN</string>
+ <!-- Reason for Always-on VPN checkbox being disabled: generic reason. [CHAR LIMIT=120] -->
+ <string name="vpn_always_on_invalid_reason_other">The information entered doesn\u2019t support always-on VPN</string>
<!-- Button label to cancel changing a VPN profile. [CHAR LIMIT=40] -->
<string name="vpn_cancel">Cancel</string>
private CheckBox mSaveLogin;
private CheckBox mShowOptions;
private CheckBox mAlwaysOnVpn;
+ private TextView mAlwaysOnInvalidReason;
ConfigDialog(Context context, DialogInterface.OnClickListener listener,
VpnProfile profile, boolean editing, boolean exists) {
mSaveLogin = (CheckBox) mView.findViewById(R.id.save_login);
mShowOptions = (CheckBox) mView.findViewById(R.id.show_options);
mAlwaysOnVpn = (CheckBox) mView.findViewById(R.id.always_on_vpn);
+ mAlwaysOnInvalidReason = (TextView) mView.findViewById(R.id.always_on_invalid_reason);
// Second, copy values from the profile.
mName.setText(mProfile.name);
R.string.vpn_no_server_cert, mProfile.ipsecServerCert);
mSaveLogin.setChecked(mProfile.saveLogin);
mAlwaysOnVpn.setChecked(mProfile.key.equals(VpnUtils.getLockdownVpn()));
- mAlwaysOnVpn.setOnCheckedChangeListener(this);
- // Update SaveLogin checkbox after Always-on checkbox is updated
- updateSaveLoginStatus();
// Hide lockdown VPN on devices that require IMS authentication
if (SystemProperties.getBoolean("persist.radio.imsregrequired", false)) {
mIpsecSecret.addTextChangedListener(this);
mIpsecUserCert.setOnItemSelectedListener(this);
mShowOptions.setOnClickListener(this);
+ mAlwaysOnVpn.setOnCheckedChangeListener(this);
// Fourth, determine whether to do editing or connecting.
- boolean valid = validate(true);
- mEditing = mEditing || !valid;
+ mEditing = mEditing || !validate(true /*editing*/);
if (mEditing) {
setTitle(R.string.vpn_edit);
// Let AlertDialog create everything.
super.onCreate(savedState);
- // Disable the action button if necessary.
- getButton(DialogInterface.BUTTON_POSITIVE)
- .setEnabled(mEditing ? valid : validate(false));
+ // Update UI controls according to the current configuration.
+ updateUiControls();
// Workaround to resize the dialog for the input method.
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
@Override
public void afterTextChanged(Editable field) {
- getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(validate(mEditing));
+ updateUiControls();
}
@Override
if (parent == mType) {
changeType(position);
}
- getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(validate(mEditing));
+ updateUiControls();
}
@Override
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (compoundButton == mAlwaysOnVpn) {
- updateSaveLoginStatus();
- getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(validate(mEditing));
+ updateUiControls();
}
}
return mAlwaysOnVpn.isChecked();
}
- private void updateSaveLoginStatus() {
+ /**
+ * Updates the UI according to the current configuration entered by the user.
+ *
+ * These include:
+ * "Always-on VPN" checkbox
+ * Reason for "Always-on VPN" being disabled, when necessary
+ * "Save account information" checkbox
+ * "Save" and "Connect" buttons
+ */
+ private void updateUiControls() {
+ VpnProfile profile = getProfile();
+
+ // Always-on VPN
+ if (profile.isValidLockdownProfile()) {
+ mAlwaysOnVpn.setEnabled(true);
+ mAlwaysOnInvalidReason.setVisibility(View.GONE);
+ } else {
+ mAlwaysOnVpn.setChecked(false);
+ mAlwaysOnVpn.setEnabled(false);
+ if (!profile.isTypeValidForLockdown()) {
+ mAlwaysOnInvalidReason.setText(R.string.vpn_always_on_invalid_reason_type);
+ } else if (!profile.isServerAddressNumeric()) {
+ mAlwaysOnInvalidReason.setText(R.string.vpn_always_on_invalid_reason_server);
+ } else if (!profile.hasDns()) {
+ mAlwaysOnInvalidReason.setText(R.string.vpn_always_on_invalid_reason_no_dns);
+ } else if (!profile.areDnsAddressesNumeric()) {
+ mAlwaysOnInvalidReason.setText(R.string.vpn_always_on_invalid_reason_dns);
+ } else {
+ mAlwaysOnInvalidReason.setText(R.string.vpn_always_on_invalid_reason_other);
+ }
+ mAlwaysOnInvalidReason.setVisibility(View.VISIBLE);
+ }
+
+ // Save account information
if (mAlwaysOnVpn.isChecked()) {
mSaveLogin.setChecked(true);
mSaveLogin.setEnabled(false);
mSaveLogin.setChecked(mProfile.saveLogin);
mSaveLogin.setEnabled(true);
}
+
+ // Save or Connect button
+ getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(validate(mEditing));
}
private void showAdvancedOptions() {