From 99dbb240677e22394fd8755343d7f4f2c269e810 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Wed, 27 Feb 2019 10:52:36 +0300 Subject: [PATCH] increase read timeout --- .../java/im/status/keycard/desktop/LedgerUSBChannel.java | 3 ++- .../java/im/status/keycard/desktop/LedgerUSBManager.java | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/desktop/src/main/java/im/status/keycard/desktop/LedgerUSBChannel.java b/desktop/src/main/java/im/status/keycard/desktop/LedgerUSBChannel.java index 7f8e781..1eca6e2 100644 --- a/desktop/src/main/java/im/status/keycard/desktop/LedgerUSBChannel.java +++ b/desktop/src/main/java/im/status/keycard/desktop/LedgerUSBChannel.java @@ -12,6 +12,7 @@ public class LedgerUSBChannel implements CardChannel { private static final int HID_BUFFER_SIZE = 64; private static final int LEDGER_DEFAULT_CHANNEL = 1; private static final int TAG_APDU = 0x05; + private static final int READ_TIMEOUT = 20000; private HidDevice hidDevice; @@ -44,7 +45,7 @@ public class LedgerUSBChannel implements CardChannel { byte[] responseData = null; while ((responseData = unwrapResponseAPDU(response.toByteArray())) == null) { - if (hidDevice.read(chunk, 500) < 0) { + if (hidDevice.read(chunk, READ_TIMEOUT) < 0) { throw new IOException("Read failed"); } diff --git a/desktop/src/main/java/im/status/keycard/desktop/LedgerUSBManager.java b/desktop/src/main/java/im/status/keycard/desktop/LedgerUSBManager.java index ad767b3..42520bc 100644 --- a/desktop/src/main/java/im/status/keycard/desktop/LedgerUSBManager.java +++ b/desktop/src/main/java/im/status/keycard/desktop/LedgerUSBManager.java @@ -12,6 +12,8 @@ public class LedgerUSBManager implements HidServicesListener { private static final int VID = 0x2c97; private static final int PID = 0x0001; + private static final int SCAN_INTERVAL_MS = 500; + private static final int PAUSE_INTERVAL_MS = 5000; private HidServices hidServices; private CardListener listener; @@ -21,8 +23,8 @@ public class LedgerUSBManager implements HidServicesListener { HidServicesSpecification hidServicesSpecification = new HidServicesSpecification(); hidServicesSpecification.setAutoShutdown(true); - hidServicesSpecification.setScanInterval(500); - hidServicesSpecification.setPauseInterval(5000); + hidServicesSpecification.setScanInterval(SCAN_INTERVAL_MS); + hidServicesSpecification.setPauseInterval(PAUSE_INTERVAL_MS); hidServicesSpecification.setScanMode(ScanMode.SCAN_AT_FIXED_INTERVAL_WITH_PAUSE_AFTER_WRITE); hidServices = HidManager.getHidServices(hidServicesSpecification);