From a59fc22754be2caacb7a56c2f1d4d52463e4f51c Mon Sep 17 00:00:00 2001 From: Marten Rebane <54431068+martenrebane@users.noreply.github.com> Date: Mon, 5 Aug 2024 20:29:33 +0300 Subject: [PATCH] Fix opening DDOC containers --- .../detail/SignatureDetailScreen.java | 10 +++++---- .../signature/detail/SignatureDetailView.java | 21 +++++++++++++------ .../android/signature/update/Processor.java | 2 +- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/ee/ria/DigiDoc/android/signature/detail/SignatureDetailScreen.java b/app/src/main/java/ee/ria/DigiDoc/android/signature/detail/SignatureDetailScreen.java index 3fe423a80..baa13b88b 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/signature/detail/SignatureDetailScreen.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/signature/detail/SignatureDetailScreen.java @@ -13,15 +13,17 @@ public final class SignatureDetailScreen extends ConductorScreen { private static final int SIGNATURE_DETAIL_SCREEN_ID = R.id.signatureDetailScreen; private Signature userSignature; private SignedContainer userSignedContainer; + boolean isSivaConfirmed; - public SignatureDetailScreen(int id, Signature signature, SignedContainer signedContainer) { + public SignatureDetailScreen(int id, Signature signature, SignedContainer signedContainer, boolean isSivaConfirmed) { super(id); this.userSignature = signature; this.userSignedContainer = signedContainer; + this.isSivaConfirmed = isSivaConfirmed; } - public static SignatureDetailScreen create(Signature signature, SignedContainer signedContainer) { - return new SignatureDetailScreen(SIGNATURE_DETAIL_SCREEN_ID, signature, signedContainer); + public static SignatureDetailScreen create(Signature signature, SignedContainer signedContainer, boolean isSivaConfirmed) { + return new SignatureDetailScreen(SIGNATURE_DETAIL_SCREEN_ID, signature, signedContainer, isSivaConfirmed); } @SuppressWarnings("WeakerAccess") @@ -31,6 +33,6 @@ public SignatureDetailScreen() { @Override protected View view(Context context) { - return new SignatureDetailView(context, userSignature, userSignedContainer); + return new SignatureDetailView(context, userSignature, userSignedContainer, isSivaConfirmed); } } diff --git a/app/src/main/java/ee/ria/DigiDoc/android/signature/detail/SignatureDetailView.java b/app/src/main/java/ee/ria/DigiDoc/android/signature/detail/SignatureDetailView.java index 4a8676298..74e2a7710 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/signature/detail/SignatureDetailView.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/signature/detail/SignatureDetailView.java @@ -55,6 +55,8 @@ public final class SignatureDetailView extends CoordinatorLayout implements Cont private final Navigator navigator; private final Toolbar toolbarView; + private final boolean isSivaConfirmed; + private final LinearLayout errorContainer; private final TextView errorTitle; private final TextView errorDetails; @@ -66,7 +68,7 @@ public final class SignatureDetailView extends CoordinatorLayout implements Cont private final ViewDisposables disposables = new ViewDisposables(); - public SignatureDetailView(Context context, Signature signature, SignedContainer signedContainer) { + public SignatureDetailView(Context context, Signature signature, SignedContainer signedContainer, boolean isSivaConfirmed) { super(context); inflate(context, R.layout.signature_detail_screen, this); @@ -75,6 +77,8 @@ public SignatureDetailView(Context context, Signature signature, SignedContainer navigator = ApplicationApp.component(context).navigator(); toolbarView = findViewById(R.id.toolbar); + this.isSivaConfirmed = isSivaConfirmed; + errorContainer = findViewById(R.id.signersCertificateErrorContainer); errorTitle = findViewById(R.id.signersCertificateErrorTitle); errorDetails = findViewById(R.id.signersCertificateErrorDetails); @@ -117,12 +121,17 @@ public SignatureDetailView(Context context, Signature signature, SignedContainer ContentView.addInvisibleElement(context, this); } - private String getContainerMimeType(SignedContainer signedContainer) { - Container container = Container.open(signedContainer.file().getAbsolutePath(), new DigidocContainerOpenCB(false)); - if (container == null) { + private String getContainerMimeType(SignedContainer signedContainer, boolean isSivaConfirmed) { + try { + Container container = Container.open(signedContainer.file().getAbsolutePath(), new DigidocContainerOpenCB(isSivaConfirmed)); + if (container == null) { + return ""; + } + return container.mediaType(); + } catch (Exception e) { + Timber.log(Log.ERROR, e, String.format("Unable to get container mimetype. %s", e.getLocalizedMessage())); return ""; } - return container.mediaType(); } private int getNumberOfFilesInContainer(SignedContainer signedContainer) { @@ -133,7 +142,7 @@ private void setData(Signature signature, SignedContainer signedContainer) { TextUtil.handleDetailText((signature.signersCertificateIssuer()), findViewById(R.id.signatureDetailSignersCertificateIssuer)); TextUtil.handleDetailText((signature.name()).replace(",", ", "), findViewById(R.id.signersCertificateButton)); TextUtil.handleDetailText((signature.signatureMethod()), findViewById(R.id.signatureDetailMethod)); - TextUtil.handleDetailText((getContainerMimeType(signedContainer)), findViewById(R.id.containerDetailFormat)); + TextUtil.handleDetailText((getContainerMimeType(signedContainer, isSivaConfirmed)), findViewById(R.id.containerDetailFormat)); TextUtil.handleDetailText((signature.signatureFormat()), findViewById(R.id.signatureDetailFormat)); TextUtil.handleDetailText((String.valueOf(getNumberOfFilesInContainer(signedContainer))), findViewById(R.id.containerDetailSignedFileCount)); TextUtil.handleDetailText((signature.signatureTimestamp()), findViewById(R.id.signatureDetailTimestamp)); diff --git a/app/src/main/java/ee/ria/DigiDoc/android/signature/update/Processor.java b/app/src/main/java/ee/ria/DigiDoc/android/signature/update/Processor.java index 22dfb9213..d06fc5a19 100644 --- a/app/src/main/java/ee/ria/DigiDoc/android/signature/update/Processor.java +++ b/app/src/main/java/ee/ria/DigiDoc/android/signature/update/Processor.java @@ -373,7 +373,7 @@ final class Processor implements ObservableTransformer { .map(signedContainerFile -> { Transaction transaction; transaction = Transaction.push(SignatureDetailScreen - .create(action.signature(), signedContainerFile)); + .create(action.signature(), signedContainerFile, action.isSivaConfirmed())); navigator.execute(transaction); return Result.SignatureViewResult.idle(); })