android: Report an error for invalid integer values
Previously we'd just ignore the invalid values without notifying the user.
This commit is contained in:
+27
-4
@@ -496,14 +496,12 @@ public class VpnProfileDetailActivity extends AppCompatActivity
|
|||||||
showCertificateAlert();
|
showCertificateAlert();
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
Integer mtu = getInteger(mMTU);
|
if (!validateInteger(mMTU, MTU_MIN, MTU_MAX))
|
||||||
if (mtu != null && (mtu < MTU_MIN || mtu > MTU_MAX))
|
|
||||||
{
|
{
|
||||||
mMTUWrap.setError(String.format(getString(R.string.alert_text_out_of_range), MTU_MIN, MTU_MAX));
|
mMTUWrap.setError(String.format(getString(R.string.alert_text_out_of_range), MTU_MIN, MTU_MAX));
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
Integer port = getInteger(mPort);
|
if (!validateInteger(mPort, 1, 65535))
|
||||||
if (port != null && (port < 1 || port > 65535))
|
|
||||||
{
|
{
|
||||||
mPortWrap.setError(String.format(getString(R.string.alert_text_out_of_range), 1, 65535));
|
mPortWrap.setError(String.format(getString(R.string.alert_text_out_of_range), 1, 65535));
|
||||||
valid = false;
|
valid = false;
|
||||||
@@ -633,6 +631,31 @@ public class VpnProfileDetailActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the value in the given text box is a valid integer in the given range
|
||||||
|
*
|
||||||
|
* @param view text box (numeric entry assumed)
|
||||||
|
* @param min minimum value (inclusive)
|
||||||
|
* @param max maximum value (inclusive)
|
||||||
|
*/
|
||||||
|
private boolean validateInteger(EditText view, Integer min, Integer max)
|
||||||
|
{
|
||||||
|
String value = view.getText().toString().trim();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (value.isEmpty())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Integer val = Integer.valueOf(value);
|
||||||
|
return min <= val && val <= max;
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class SelectUserCertOnClickListener implements OnClickListener, KeyChainAliasCallback
|
private class SelectUserCertOnClickListener implements OnClickListener, KeyChainAliasCallback
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user