Replace AssertionErrors with snackbar notifications, fix style issues.

This commit is contained in:
Joey Castillo 2015-06-11 11:52:09 -04:00
parent 14226461c1
commit cda8b63bb4
2 changed files with 51 additions and 50 deletions

View File

@ -122,63 +122,61 @@ public abstract class BaseNfcActivity extends BaseActivity {
// Otherwise, all status codes are fixed values. // Otherwise, all status codes are fixed values.
switch (status) { switch (status) {
// These errors should not occur in everyday use; if they are returned, it means we // These errors should not occur in everyday use; if they are returned, it means we
// made a mistake sending data to the card. // made a mistake sending data to the card, or the card is misbehaving.
case 0x6A80: case 0x6A80: {
throw new AssertionError("Card returned 'Wrong Data' status; this is a programming error!"); Notify.create(this, getString(R.string.error_nfc_bad_data), Style.WARN).show();
case 0x6883:
throw new AssertionError("Card expected last command in a chain; this is a programming error!");
case 0x6B00:
throw new AssertionError("Card reported invalid P1/P2 parameter; this is a programming error!");
case 0x6D00:
throw new AssertionError("Instruction (INS) not supported by smart card; this is a programming error!");
case 0x6E00:
throw new AssertionError("Class (CLA) not supported by smart card; this is a programming error!");
// These errors might be encountered in everyday use, and should display a localized
// error message to the user.
case 0x6285:
{
Notify.create(this, getString(R.string.error_nfc,
getString(R.string.error_nfc_terminated)), Style.WARN).show();
break; break;
} }
case 0x6700: case 0x6883: {
{ Notify.create(this, getString(R.string.error_nfc_chaining_error), Style.WARN).show();
Notify.create(this, getString(R.string.error_nfc,
getString(R.string.error_nfc_wrong_length)), Style.WARN).show();
break; break;
} }
case 0x6982: case 0x6B00: {
{ Notify.create(this, getString(R.string.error_nfc_header, "P1/P2"), Style.WARN).show();
Notify.create(this, getString(R.string.error_nfc,
getString(R.string.error_nfc_security_not_satisfied)), Style.WARN).show();
break; break;
} }
case 0x6983: case 0x6D00: {
{ Notify.create(this, getString(R.string.error_nfc_header, "INS"), Style.WARN).show();
Notify.create(this, getString(R.string.error_nfc,
getString(R.string.error_nfc_authentication_blocked)), Style.WARN).show();
break; break;
} }
case 0x6985: case 0x6E00: {
{ Notify.create(this, getString(R.string.error_nfc_header, "CLA"), Style.WARN).show();
Notify.create(this, getString(R.string.error_nfc,
getString(R.string.error_nfc_conditions_not_satisfied)), Style.WARN).show();
break; break;
} }
// These error conditions are more likely to be experienced by an end user.
case 0x6285: {
Notify.create(this, getString(R.string.error_nfc_terminated), Style.WARN).show();
break;
}
case 0x6700: {
Notify.create(this, getString(R.string.error_nfc_wrong_length), Style.WARN).show();
break;
}
case 0x6982: {
Notify.create(this, getString(R.string.error_nfc_security_not_satisfied),
Style.WARN).show();
break;
}
case 0x6983: {
Notify.create(this, getString(R.string.error_nfc_authentication_blocked),
Style.WARN).show();
break;
}
case 0x6985: {
Notify.create(this, getString(R.string.error_nfc_conditions_not_satisfied),
Style.WARN).show();
break;
}
// 6A88 is "Not Found" in the spec, but Yubikey also returns 6A83 for this in some cases.
case 0x6A88: case 0x6A88:
case 0x6A83: case 0x6A83: {
{ Notify.create(this, getString(R.string.error_nfc_data_not_found), Style.WARN).show();
Notify.create(this, getString(R.string.error_nfc,
getString(R.string.error_nfc_data_not_found)), Style.WARN).show();
break; break;
} }
// 6F00 is a JavaCard proprietary status code, SW_UNKNOWN, and usually represents an // 6F00 is a JavaCard proprietary status code, SW_UNKNOWN, and usually represents an
// unhandled exception on the smart card. // unhandled exception on the smart card.
case 0x6F00: case 0x6F00: {
{ Notify.create(this, getString(R.string.error_nfc_unknown), Style.WARN).show();
Notify.create(this, getString(R.string.error_nfc,
getString(R.string.error_nfc_unknown)), Style.WARN).show();
break; break;
} }
default: default:

View File

@ -1309,14 +1309,17 @@
<string name="btn_import">"Import"</string> <string name="btn_import">"Import"</string>
<string name="snack_yubi_other">Different key stored on YubiKey!</string> <string name="snack_yubi_other">Different key stored on YubiKey!</string>
<string name="error_nfc">"NFC Error: %s"</string> <string name="error_nfc">"NFC Error: %s"</string>
<string name="error_pin">"Incorrect PIN; %d tries remaining."</string> <string name="error_pin">"NFC: Incorrect PIN; %d tries remaining."</string>
<string name="error_nfc_terminated">"Smart card in termination state"</string> <string name="error_nfc_terminated">"NFC: Smart card in termination state"</string>
<string name="error_nfc_wrong_length">"Wrong length for sent / received data"</string> <string name="error_nfc_wrong_length">"NFC: Wrong length for sent / received data"</string>
<string name="error_nfc_conditions_not_satisfied">"Conditions of use not satisfied"</string> <string name="error_nfc_conditions_not_satisfied">"NFC: Conditions of use not satisfied"</string>
<string name="error_nfc_security_not_satisfied">"Security status not satisfied"</string> <string name="error_nfc_security_not_satisfied">"NFC: Security status not satisfied"</string>
<string name="error_nfc_authentication_blocked">"PIN blocked after too many attempts"</string> <string name="error_nfc_authentication_blocked">"NFC: PIN blocked after too many attempts"</string>
<string name="error_nfc_data_not_found">"Key or object not found"</string> <string name="error_nfc_data_not_found">"NFC: Key or object not found"</string>
<string name="error_nfc_unknown">"Unknown Error"</string> <string name="error_nfc_unknown">"NFC: Unknown Error"</string>
<string name="error_nfc_bad_data">"NFC: Card reported invalid data"</string>
<string name="error_nfc_chaining_error">"NFC: Card expected last command in a chain"</string>
<string name="error_nfc_header">"NFC: Card reported invalid %s byte"</string>
<string name="error_pin_nodefault">Default PIN was rejected!</string> <string name="error_pin_nodefault">Default PIN was rejected!</string>
<string name="error_bluetooth_file">Error creating temporary file. Bluetooth sharing will fail.</string> <string name="error_bluetooth_file">Error creating temporary file. Bluetooth sharing will fail.</string>
<string name="snack_encrypt_filenames_on">"Filenames <b>are</b> encrypted."</string> <string name="snack_encrypt_filenames_on">"Filenames <b>are</b> encrypted."</string>