YADESK-613 - don't crash when SKY is usb connected

This commit is contained in:
Adam Velebil 2022-04-07 15:32:56 +02:00
parent 437731143a
commit 68b47bd1c7
No known key found for this signature in database
GPG Key ID: AC6D6B9D715FC084

View File

@ -18,6 +18,7 @@ import com.yubico.yubikit.core.util.Result
import com.yubico.yubikit.oath.*
import com.yubico.yubikit.support.DeviceUtil
import kotlinx.coroutines.*
import java.lang.IllegalStateException
import java.net.URI
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
@ -157,29 +158,30 @@ class MainViewModel : ViewModel() {
_isUsbKey = device is UsbYubiKeyDevice
withContext(Dispatchers.IO) {
if (pendingYubiKeyAction.value != null) {
provideYubiKey(Result.success(device))
} else {
withContext(Dispatchers.Main) {
when (_operationContext) {
OperationContext.Oath -> {
try {
sendDeviceInfo(device)
} catch (cause: Throwable) {
Logger.e("Failed to send device info", cause)
}
sendOathInfo(device)
sendOathCodes(device)
}
OperationContext.Yubikey -> {
sendDeviceInfo(device)
}
try {
else -> {}
withContext(Dispatchers.IO) {
if (pendingYubiKeyAction.value != null) {
provideYubiKey(Result.success(device))
} else {
withContext(Dispatchers.Main) {
when (_operationContext) {
OperationContext.Oath -> {
sendDeviceInfo(device)
sendOathInfo(device)
sendOathCodes(device)
}
OperationContext.Yubikey -> {
sendDeviceInfo(device)
}
else -> {}
}
}
}
}
} catch (illegalStateException: IllegalStateException) {
// ignored
}
}