From 1296c3ec399201beb9d9a9207f06940bc17149f0 Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Tue, 14 Aug 2018 17:22:53 +0200 Subject: [PATCH] Troubleshoot device previously claimed issues --- .../ddroid/fragments/ConfirmInfoFragment.kt | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/depau/ddroid/fragments/ConfirmInfoFragment.kt b/app/src/main/java/eu/depau/ddroid/fragments/ConfirmInfoFragment.kt index 33cc0e0..46c4f08 100644 --- a/app/src/main/java/eu/depau/ddroid/fragments/ConfirmInfoFragment.kt +++ b/app/src/main/java/eu/depau/ddroid/fragments/ConfirmInfoFragment.kt @@ -64,25 +64,33 @@ class ConfirmInfoFragment : WizardFragment() { view.confirm_sel_usbdev.text = StateKeeper.usbDevice?.name - try { - StateKeeper.usbMassStorageDevice!!.init() - val blockDev = StateKeeper.usbMassStorageDevice?.blockDevice + for (trial in 0..1) { + try { + StateKeeper.usbMassStorageDevice!!.init() + val blockDev = StateKeeper.usbMassStorageDevice?.blockDevice - if (blockDev != null) { - val devSize = (blockDev.size.toLong() * blockDev.blockSize.toLong()) - view.confirm_sel_usbdev_size.text = devSize.toHRSize() + if (blockDev != null) { + val devSize = (blockDev.size.toLong() * blockDev.blockSize.toLong()) + view.confirm_sel_usbdev_size.text = devSize.toHRSize() - if (imgSize!! > devSize) - view.confirm_extra_info.text = getString(R.string.image_bigger_than_usb) - else { - view.confirm_extra_info.text = getString(R.string.tap_next_to_write) - canContinue = true + if (imgSize!! > devSize) + view.confirm_extra_info.text = getString(R.string.image_bigger_than_usb) + else { + view.confirm_extra_info.text = getString(R.string.tap_next_to_write) + canContinue = true + } + } else { + view.confirm_extra_info.text = getString(R.string.cant_read_usbdev) + } + } catch (e: IOException) { + if (trial == 0) { + StateKeeper.usbMassStorageDevice!!.close() + continue + } else { + view.confirm_extra_info.text = "Could not access USB device. Maybe you ran the app previously and it crashed? Remove and reinsert the USB drive, then restart the app." + break } - } else { - view.confirm_extra_info.text = getString(R.string.cant_read_usbdev) } - } catch (e: IOException) { - view.confirm_extra_info.text = "Could not access USB device. Maybe you ran the app previously and it crashed? Remove and reinsert the USB drive, then restart the app." } return view