From ba8a2ea69139a7a5d1bcd75663ced544e6c5795f Mon Sep 17 00:00:00 2001 From: Alpar Szotyori Date: Wed, 30 Aug 2023 14:18:38 +0200 Subject: [PATCH] fix(capture-sdk): Discard QR code detections after the `PaymentQRCodeReader` is released PIA-4414 --- .../android/capture/camera/CameraFragmentImpl.java | 12 ++++++------ .../capture/internal/qrcode/PaymentQRCodeReader.java | 5 +++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/camera/CameraFragmentImpl.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/camera/CameraFragmentImpl.java index c46d47a277..4f63ec07ce 100644 --- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/camera/CameraFragmentImpl.java +++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/camera/CameraFragmentImpl.java @@ -437,12 +437,6 @@ private void initFlashButton() { * @suppress */ public void onResume() { - if (mPaymentQRCodePopup != null) { - mPaymentQRCodePopup.hide(); - } - if (mUnsupportedQRCodePopup != null) { - mUnsupportedQRCodePopup.hide(); - } initMultiPageDocument(); } @@ -584,6 +578,12 @@ void onSaveInstanceState(@NonNull final Bundle outState) { void onStop() { closeCamera(); + if (mPaymentQRCodePopup != null) { + mPaymentQRCodePopup.hide(); + } + if (mUnsupportedQRCodePopup != null) { + mUnsupportedQRCodePopup.hide(); + } } void onDestroy() { diff --git a/capture-sdk/sdk/src/main/java/net/gini/android/capture/internal/qrcode/PaymentQRCodeReader.java b/capture-sdk/sdk/src/main/java/net/gini/android/capture/internal/qrcode/PaymentQRCodeReader.java index 1c91000066..b7b8b70b74 100644 --- a/capture-sdk/sdk/src/main/java/net/gini/android/capture/internal/qrcode/PaymentQRCodeReader.java +++ b/capture-sdk/sdk/src/main/java/net/gini/android/capture/internal/qrcode/PaymentQRCodeReader.java @@ -43,6 +43,7 @@ public void onNonPaymentQRCodeDetected(@NonNull final String qrCodeContent) { public void onQRCodeReaderFail() { } }; + private boolean isReleased = false; /** * Create a new instance which uses the provided {@link QRCodeDetectorTask} to do QRCode @@ -66,6 +67,9 @@ private PaymentQRCodeReader( mDetector.setListener(new QRCodeDetector.Listener() { @Override public void onQRCodesDetected(@NonNull final List qrCodes) { + if (isReleased) { + return; + } for (final String qrCodeContent : qrCodes) { try { final PaymentQRCodeData paymentData = mParser.parse(qrCodeContent); @@ -119,6 +123,7 @@ public void readFromByteArray(@NonNull final byte[] image, @NonNull final Size i * Release all resources. Detection not possible after this has been called. */ public void release() { + isReleased = true; mDetector.release(); }