Skip to content

Commit d1934fa

Browse files
committed
fix the crash with device connection not closing successfully; add more accurate error messages for connection issues
1 parent fef8491 commit d1934fa

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

app/src/main/java/org/kabiri/android/usbterminal/arduino/ArduinoHelper.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,17 @@ class ArduinoHelper(private val context: Context,
6262
_liveInfoOutput.postValue(context.getString(R.string.helper_info_usb_permission_requested))
6363
} else {
6464
_liveErrorOutput.postValue(context.getString(R.string.helper_error_device_not_found))
65-
connection.close()
65+
try {
66+
connection.close()
67+
} catch (e: UninitializedPropertyAccessException) {
68+
_liveErrorOutput.postValue(context.getString(
69+
R.string.helper_error_connection_not_ready_to_close))
70+
_liveErrorOutput.postValue(e.message)
71+
} catch (e: Exception) {
72+
_liveErrorOutput.postValue(context.getString(
73+
R.string.helper_error_connection_failed_to_close))
74+
_liveErrorOutput.postValue(e.message)
75+
}
6676
}
6777
}
6878
} else {

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<string name="helper_error_serial_connection_not_opened">\nPort not opened - There might be a problem with the serial connection to Arduino</string>
1919
<string name="helper_error_write_problem">Serial Write encountered an error:</string>
2020
<string name="helper_error_connection_closed_unexpectedly">Device connection was closed unexpectedly</string>
21+
<string name="helper_error_connection_not_ready_to_close">No device connection to close</string>
22+
<string name="helper_error_connection_failed_to_close">Device connection failed to close</string>
2123
<string name="helper_info_serial_connection_opened">\nSerial Connection Opened</string>
2224
<string name="helper_info_usb_permission_requested">Requested permission to access the USB device…</string>
2325
<string name="helper_info_checking_attached_usb_devices">\nChecking attached USB devices…</string>

0 commit comments

Comments
 (0)