From 74ecbfe0d7d08957e0306280be4f4030ed332141 Mon Sep 17 00:00:00 2001 From: Marten Rebane <54431068+martenrebane@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:39:03 +0300 Subject: [PATCH] Fix showing message on different buttons --- .../signature/update/SignatureUpdateView.java | 12 +++++++-- .../signature/update/nfc/NFCOnSubscribe.java | 27 +++++++++++++------ .../signature/update/nfc/NFCResponse.java | 3 --- app/src/main/res/values/strings.xml | 4 +-- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/ee/ria/DigiDoc/android/signature/update/SignatureUpdateView.java b/app/src/main/java/ee/ria/DigiDoc/android/signature/update/SignatureUpdateView.java index c960900aa..c283faf3d 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/signature/update/SignatureUpdateView.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/signature/update/SignatureUpdateView.java @@ -49,9 +49,9 @@ import ee.ria.DigiDoc.android.ApplicationApp; import ee.ria.DigiDoc.android.accessibility.AccessibilityUtils; import ee.ria.DigiDoc.android.signature.update.mobileid.MobileIdResponse; -import ee.ria.DigiDoc.android.signature.update.smartid.SmartIdResponse; import ee.ria.DigiDoc.android.signature.update.nfc.NFCDialog; import ee.ria.DigiDoc.android.signature.update.nfc.NFCResponse; +import ee.ria.DigiDoc.android.signature.update.smartid.SmartIdResponse; import ee.ria.DigiDoc.android.utils.DateUtil; import ee.ria.DigiDoc.android.utils.ToastUtil; import ee.ria.DigiDoc.android.utils.ViewDisposables; @@ -587,10 +587,14 @@ public void render(ViewState state) { if (signatureAddResponse instanceof NFCResponse) { NFCResponse nfcResponse = (NFCResponse) signatureAddResponse; - Timber.log(Log.DEBUG, "NFC:SignatureUpdateView.render, status %s", nfcResponse.status().toString()); + if (nfcResponse.status() != null) { + Timber.log(Log.DEBUG, "NFC:SignatureUpdateView.render, status %s", nfcResponse.status().toString()); + } nfcDialog.showStatus(nfcResponse); nfcDialog.show(); } + } else { + nfcDialog.dismiss(); } setupAccessibilityTabs(); @@ -741,15 +745,19 @@ private void sendMethodSelectionAccessibilityEvent(int method) { if (signatureMethod.equalsIgnoreCase(getResources().getString(R.string.signature_update_signature_add_method_mobile_id))) { AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_WINDOW_STATE_CHANGED, getResources().getString(R.string.signature_update_signature_chosen_method_mobile_id)); + AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_ANNOUNCEMENT, getResources().getString(R.string.signature_update_signature_selected_method_mobile_id, 1, 4)); } else if (signatureMethod.equalsIgnoreCase(getResources().getString(R.string.signature_update_signature_add_method_smart_id))) { AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_WINDOW_STATE_CHANGED, getResources().getString(R.string.signature_update_signature_chosen_method_smart_id)); + AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_ANNOUNCEMENT, getResources().getString(R.string.signature_update_signature_selected_method_smart_id, 2, 4)); } else if (signatureMethod.equalsIgnoreCase(getResources().getString(R.string.signature_update_signature_add_method_id_card))) { AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_WINDOW_STATE_CHANGED, getResources().getString(R.string.signature_update_signature_chosen_method_id_card)); + AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_ANNOUNCEMENT, getResources().getString(R.string.signature_update_signature_selected_method_id_card, 3, 4)); } else if (signatureMethod.equalsIgnoreCase(getResources().getString(R.string.signature_update_signature_add_method_nfc))) { AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_WINDOW_STATE_CHANGED, getResources().getString(R.string.signature_update_signature_chosen_method_nfc)); + AccessibilityUtils.sendAccessibilityEvent(getContext(), TYPE_ANNOUNCEMENT, getResources().getString(R.string.signature_update_signature_selected_method_nfc, 4, 4)); } } } diff --git a/app/src/main/java/ee/ria/DigiDoc/android/signature/update/nfc/NFCOnSubscribe.java b/app/src/main/java/ee/ria/DigiDoc/android/signature/update/nfc/NFCOnSubscribe.java index 05fc5e91a..2a014f162 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/signature/update/nfc/NFCOnSubscribe.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/signature/update/nfc/NFCOnSubscribe.java @@ -64,8 +64,18 @@ public void subscribe(ObservableEmitter emitter) { emitter.onNext(NFCResponse.createWithStatus(SessionStatusResponse.ProcessStatus.OK, navigator.activity().getString(R.string.signature_update_nfc_detected))); NFCResponse response = onTagDiscovered(adapter, tag); Timber.log(Log.DEBUG, "NFC::completed"); - emitter.onNext((response != null) ? response : NFCResponse.success(container)); - emitter.onComplete(); + if (response != null) { + if (response.status() != SessionStatusResponse.ProcessStatus.OK) { + Timber.log(Log.ERROR, String.format("NFC status: %s", response.status())); + emitter.onError(new NFC.NFCException(response.message())); + } else { + emitter.onNext(response); + emitter.onComplete(); + } + } else { + emitter.onNext(NFCResponse.success(container)); + emitter.onComplete(); + } }, NfcAdapter.FLAG_READER_NFC_A, null); } } @@ -94,14 +104,14 @@ private NFCResponse onTagDiscovered(NfcAdapter adapter, Tag tag) { byte[] certificate = nfc.readCertificate(); if (certificate == null) { Timber.log(Log.ERROR, "Failed to read certificate. Certificate is null"); - throw new RuntimeException("Unable to read certificate for NFC"); + throw new RuntimeException(navigator.activity().getString(R.string.signature_update_nfc_technical_error)); } - Timber.log(Log.DEBUG, "CERT:%s", Hex.toHexString(certificate)); + Timber.log(Log.DEBUG, "CERT: %s", Hex.toHexString(certificate)); Certificate cert = Certificate.create(ByteString.of(certificate, 0, certificate.length)); // Step 2 - verify PIN2 NFC.Result r = nfc.communicateSecure(SEL_QSCD_CMD, SEL_QSCD); - Timber.log(Log.DEBUG, "Select QSCD AID:%x %s", r.code, Hex.toHexString(r.data)); + Timber.log(Log.DEBUG, "Select QSCD AID: %x %s", r.code, Hex.toHexString(r.data)); // pad the PIN and use the chip for verification byte[] paddedPIN = Hex.decode("ffffffffffffffffffffffff"); @@ -110,19 +120,20 @@ private NFCResponse onTagDiscovered(NfcAdapter adapter, Tag tag) { if (null != pin2 && pin2.length > 0) { Arrays.fill(pin2, (byte) 0); } - Timber.log(Log.DEBUG, "Verify PIN2:%x %s", r.code, Hex.toHexString(r.data)); + Timber.log(Log.DEBUG, "Verify PIN2: %x %s", r.code, Hex.toHexString(r.data)); if (r.code != 0x9000) { if (r.code == 0x6983) { throw new RuntimeException(navigator.activity().getString(R.string.signature_update_id_card_sign_pin2_locked)); } else if ((r.code & 0xfff0) == 0x63c0) { throw new RuntimeException(String.format(navigator.activity().getString(R.string.signature_update_id_card_sign_pin2_invalid), r.code & 0xf)); } else { - throw new RuntimeException("Verification error"); + Timber.log(Log.ERROR, "PIN2 verification error"); + throw new RuntimeException(navigator.activity().getString(R.string.signature_update_nfc_technical_error)); } } r = nfc.communicateSecure(CMD_SET_ENV_SIGN, SET_ENV_SIGN); - Timber.log(Log.DEBUG, "Set ENV:%x %s", r.code, Hex.toHexString(r.data)); + Timber.log(Log.DEBUG, "Set ENV: %x %s", r.code, Hex.toHexString(r.data)); container.sign(cert.data(), signData -> ByteString.of(nfc.calculateSignature(signData.toByteArray())), role); diff --git a/app/src/main/java/ee/ria/DigiDoc/android/signature/update/nfc/NFCResponse.java b/app/src/main/java/ee/ria/DigiDoc/android/signature/update/nfc/NFCResponse.java index a527bc03d..8eafe4e70 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/signature/update/nfc/NFCResponse.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/signature/update/nfc/NFCResponse.java @@ -4,10 +4,7 @@ import com.google.auto.value.AutoValue; -import ee.ria.DigiDoc.android.model.idcard.IdCardDataResponse; -import ee.ria.DigiDoc.android.model.idcard.IdCardSignResponse; import ee.ria.DigiDoc.android.signature.update.SignatureAddResponse; -import ee.ria.DigiDoc.android.signature.update.smartid.SmartIdResponse; import ee.ria.DigiDoc.sign.SignedContainer; import ee.ria.DigiDoc.smartid.dto.response.SessionStatusResponse; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8e7b4475a..ca7cda203 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -214,7 +214,7 @@ Signing option Mobile-ID, tab %1$d of %2$d Signing option Smart-ID, tab %1$d of %2$d Signing option ID-card, tab %1$d of %2$d - Signing option NFC, tab %1$d / %2$d + Signing option NFC, tab %1$d of %2$d Signing method Mobile-ID, selected Signing method Smart-ID, selected @@ -303,7 +303,7 @@ Enter your ID-card access number (CAN) and PIN2 code to sign with ID-card ID-card access number (CAN) PIN2 code - This device does not support NFC + This device does not support contactless connection or NFC is turned off NFC connection lost Technical error Hold your phone near the ID-card