mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
fix(input): a failing BLE disconnect no longer ends the app or the unit test run (#2670)
This commit is contained in:
1 parent
fb14b99d50
commit
605f85b4b9
2 files changed
+13
-5
No files matched your search
@@ -129,8 +129,9 @@ class SteamControllerBle(private val context: Context, router: InputRouter? = nu
|
||||
}
|
||||
}
|
||||
}
|
||||
g.disconnect()
|
||||
g.close()
|
||||
// Android can refuse these (BLUETOOTH_CONNECT revoked); an exception on this thread would end the app.
|
||||
runCatching { g.disconnect() }.onFailure { Log.w(TAG, "disconnect failed", it) }
|
||||
runCatching { g.close() }.onFailure { Log.w(TAG, "close failed", it) }
|
||||
Log.i(TAG, "disconnected: $why")
|
||||
listener?.invoke()
|
||||
}
|
||||
|
||||
@@ -48,9 +48,16 @@ class SteamControllerBleTest {
|
||||
controller.start()
|
||||
}
|
||||
|
||||
/** Runs what stop() posted unless stop() already quit the looper, then quits it. */
|
||||
private fun drain(looper: android.os.Looper) {
|
||||
runCatching { shadowOf(looper).idle() }
|
||||
looper.quit()
|
||||
}
|
||||
|
||||
@After fun close() {
|
||||
controller.stop()
|
||||
handler.looper.quit()
|
||||
// The stop posts a disconnect; run it now, while Robolectric's environment still exists.
|
||||
drain(handler.looper)
|
||||
}
|
||||
|
||||
@Test fun stopReleasesAndDetachesInputBeforeQueuedCallbacksCanPublish() {
|
||||
@@ -126,7 +133,7 @@ class SteamControllerBleTest {
|
||||
assertTrue(Writer.reports.last().all { it == 0.toByte() })
|
||||
} finally {
|
||||
replacement.stop()
|
||||
replacementHandler.looper.quit()
|
||||
drain(replacementHandler.looper)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +149,7 @@ class SteamControllerBleTest {
|
||||
assertEquals(reports, Writer.reports.size)
|
||||
} finally {
|
||||
unused.stop()
|
||||
ReflectionHelpers.getField<Handler>(unused, "handler").looper.quit()
|
||||
drain(ReflectionHelpers.getField<Handler>(unused, "handler").looper)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user