From e7061101822740be3a0c878025ec39a6d8a6251d Mon Sep 17 00:00:00 2001 From: Andreas Abraham Date: Wed, 27 Jan 2021 11:05:12 +0100 Subject: added timeout check for polling (5min) --- .../gui/workflow/states/MobileBKUState.java | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java index 36d29e49..e224ce78 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java @@ -19,9 +19,11 @@ import java.io.IOException; import java.io.InputStream; import java.util.Timer; import java.util.TimerTask; +import java.util.concurrent.TimeoutException; // Imports import at.asit.pdfover.gui.exceptions.ATrustConnectionException; +import at.asit.pdfover.signator.SignatureException; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.slf4j.Logger; @@ -451,7 +453,7 @@ public class MobileBKUState extends State { /** * This composite notifies the user to open the signature-app */ - public void showOpenAppMessageWithSMSandCancel() { + public void showOpenAppMessageWithSMSandCancel() throws SignatureException { final ATrustStatus status = (ATrustStatus) this.getStatus(); @@ -461,9 +463,10 @@ public class MobileBKUState extends State { Display display = getStateMachine().getGUIProvider().getMainShell().getDisplay(); undecidedPolling(); + long startTime = System.nanoTime(); while (!waitingForAppcomposite.getUserCancel() && !waitingForAppcomposite.getUserSMS() - && !waitingForAppcomposite.getIsDone()) { + && !waitingForAppcomposite.getIsDone() && !isTimout(startTime)) { if (!display.readAndDispatch()) { display.sleep(); } @@ -488,6 +491,14 @@ public class MobileBKUState extends State { if (waitingForAppcomposite.getIsDone()) waitingForAppcomposite.setIsDone(false); + + if (isTimout(startTime)){ + log.warn("The undecided polling got a timeout"); + status.setQRCode(null); + status.setErrorMessage("Polling Timeout"); + + + } }); } @@ -583,7 +594,15 @@ public class MobileBKUState extends State { return this.getMobileBKUFingerprintComposite().isUserSMS(); } - + + + private boolean isTimout(long startTime){ + long NANOSEC_PER_SEC = 1000l*1000*1000; + if ((System.nanoTime()-startTime)< 5*60*NANOSEC_PER_SEC){ + return false; + } + return true; + } /* * (non-Javadoc) -- cgit v1.2.3