From cda8b63bb4c4c38065f76b7db474188e478e5b23 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Thu, 11 Jun 2015 11:52:09 -0400 Subject: Replace AssertionErrors with snackbar notifications, fix style issues. --- .../keychain/ui/base/BaseNfcActivity.java | 82 +++++++++++----------- OpenKeychain/src/main/res/values/strings.xml | 19 ++--- 2 files changed, 51 insertions(+), 50 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseNfcActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseNfcActivity.java index 3e9ed282e..a28a5ea59 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseNfcActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseNfcActivity.java @@ -122,63 +122,61 @@ public abstract class BaseNfcActivity extends BaseActivity { // Otherwise, all status codes are fixed values. switch (status) { // These errors should not occur in everyday use; if they are returned, it means we - // made a mistake sending data to the card. - case 0x6A80: - throw new AssertionError("Card returned 'Wrong Data' status; this is a programming error!"); - 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(); + // made a mistake sending data to the card, or the card is misbehaving. + case 0x6A80: { + Notify.create(this, getString(R.string.error_nfc_bad_data), Style.WARN).show(); break; } - case 0x6700: - { - Notify.create(this, getString(R.string.error_nfc, - getString(R.string.error_nfc_wrong_length)), Style.WARN).show(); + case 0x6883: { + Notify.create(this, getString(R.string.error_nfc_chaining_error), Style.WARN).show(); break; } - case 0x6982: - { - Notify.create(this, getString(R.string.error_nfc, - getString(R.string.error_nfc_security_not_satisfied)), Style.WARN).show(); + case 0x6B00: { + Notify.create(this, getString(R.string.error_nfc_header, "P1/P2"), Style.WARN).show(); break; } - case 0x6983: - { - Notify.create(this, getString(R.string.error_nfc, - getString(R.string.error_nfc_authentication_blocked)), Style.WARN).show(); + case 0x6D00: { + Notify.create(this, getString(R.string.error_nfc_header, "INS"), Style.WARN).show(); break; } - case 0x6985: - { - Notify.create(this, getString(R.string.error_nfc, - getString(R.string.error_nfc_conditions_not_satisfied)), Style.WARN).show(); + case 0x6E00: { + Notify.create(this, getString(R.string.error_nfc_header, "CLA"), Style.WARN).show(); 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 0x6A83: - { - Notify.create(this, getString(R.string.error_nfc, - getString(R.string.error_nfc_data_not_found)), Style.WARN).show(); + case 0x6A83: { + Notify.create(this, getString(R.string.error_nfc_data_not_found), Style.WARN).show(); break; } // 6F00 is a JavaCard proprietary status code, SW_UNKNOWN, and usually represents an // unhandled exception on the smart card. - case 0x6F00: - { - Notify.create(this, getString(R.string.error_nfc, - getString(R.string.error_nfc_unknown)), Style.WARN).show(); + case 0x6F00: { + Notify.create(this, getString(R.string.error_nfc_unknown), Style.WARN).show(); break; } default: diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index 8e2f0f5e2..88d44d2e4 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -1309,14 +1309,17 @@ "Import" Different key stored on YubiKey! "NFC Error: %s" - "Incorrect PIN; %d tries remaining." - "Smart card in termination state" - "Wrong length for sent / received data" - "Conditions of use not satisfied" - "Security status not satisfied" - "PIN blocked after too many attempts" - "Key or object not found" - "Unknown Error" + "NFC: Incorrect PIN; %d tries remaining." + "NFC: Smart card in termination state" + "NFC: Wrong length for sent / received data" + "NFC: Conditions of use not satisfied" + "NFC: Security status not satisfied" + "NFC: PIN blocked after too many attempts" + "NFC: Key or object not found" + "NFC: Unknown Error" + "NFC: Card reported invalid data" + "NFC: Card expected last command in a chain" + "NFC: Card reported invalid %s byte" Default PIN was rejected! Error creating temporary file. Bluetooth sharing will fail. "Filenames are encrypted." -- cgit v1.2.3