From a0574222cbbddec609b234f6150d6fc0645c79cd Mon Sep 17 00:00:00 2001 From: yanas Date: Fri, 23 Aug 2024 12:21:44 +0200 Subject: [PATCH] fix(react-native-usb): close all opened devices without exception --- .../main/java/io/trezor/rnusb/ReactNativeUsbModule.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/react-native-usb/android/src/main/java/io/trezor/rnusb/ReactNativeUsbModule.kt b/packages/react-native-usb/android/src/main/java/io/trezor/rnusb/ReactNativeUsbModule.kt index f77c1abf7ba..e87aa1508dd 100644 --- a/packages/react-native-usb/android/src/main/java/io/trezor/rnusb/ReactNativeUsbModule.kt +++ b/packages/react-native-usb/android/src/main/java/io/trezor/rnusb/ReactNativeUsbModule.kt @@ -234,15 +234,17 @@ class ReactNativeUsbModule : Module() { private fun closeDevice(deviceName: String) { Log.d(LOG_TAG, "Closing device $deviceName") - val usbConnection = getOpenedConnection(deviceName) - usbConnection.close() + getOpenedConnection(deviceName).close() openedConnections.remove(deviceName) } private fun closeAllOpenedDevices() { Log.d(LOG_TAG, "Closing all devices") - openedConnections.forEach { (deviceName, _) -> - closeDevice(deviceName) + with(openedConnections.iterator()) { + forEach { + it.value.close() + remove() + } } }