Skip to content

Commit

Permalink
Hopefully catch disconnection exceptions better
Browse files Browse the repository at this point in the history
  • Loading branch information
hufman committed Oct 23, 2024
1 parent 5ccc652 commit 74ac6ea
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/src/main/java/me/hufman/androidautoidrive/CarThread.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,23 @@ class CarThread(name: String, var runnable: () -> (Unit)): Thread(name) {
} catch (e: IllegalStateException) {
// posted to a dead handler
Log.i(TAG, "Shutting down thread $name due to IllegalStateException: $e", e)
} catch (e: RuntimeException) {
// phone was unplugged during an RPC command
Log.i(TAG, "Shutting down thread $name due to RuntimeException: $e", e)
} catch (e: org.apache.etch.util.TimeoutException) {
// phone was unplugged during an RPC command
Log.i(TAG, "Shutting down thread $name due to Etch TimeoutException")
} catch (e: RuntimeException) {
// phone was unplugged during an RPC command
Log.i(TAG, "Shutting down thread $name due to RuntimeException: $e", e)
} catch (e: IOException) {
val bmwException = e.cause as? BMWRemoting.ServiceException
val cause = e.cause
if (!iDriveConnectionObserver.isConnected) {
// the car is no longer connected
// so this is most likely a crash caused by the closed connection
Log.i(TAG, "Shutting down thread $name due to disconnection")
} else if (bmwException?.errorMsg?.contains("RHMI application was already connected") == true) {
} else if (cause is org.apache.etch.util.TimeoutException) {
Log.i(TAG, "Shutting down thread $name due to Etch TimeoutException")
} else if (cause is RuntimeException) {
Log.i(TAG, "Shutting down thread $name due to RuntimeException: $cause", cause)
} else if (cause is BMWRemoting.ServiceException && cause.errorMsg.contains("RHMI application was already connected")) {
// sometimes, the BCL tunnel blips during the start of the connection
// and so previously-initialized apps are still "in the car" though the tunnel has since restarted
// and so the car complains that the app is already connected
Expand Down

0 comments on commit 74ac6ea

Please sign in to comment.