Skip to content

Commit 01ce277

Browse files
mahibibackportbot[bot]
authored andcommitted
fix(chat): avoid main-thread deadlock in ChatActivity onStart media controller connect
The onStart() listener re-read the mutable mediaControllerFuture field instead of the future it was registered against. If onStart() ran again before a prior connection attempt's listener fired, that listener could end up blocking get() on a newer, not-yet-completed future, deadlocking the main thread and causing an ANR. Capture the future in a local val and ignore the callback if it's no longer the current connection attempt. Assisted-by: Claude Code:claude-sonnet-5 Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
1 parent b360738 commit 01ce277

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,11 +1400,16 @@ class ChatActivity :
14001400
this.lifecycle.addObserver(chatViewModel)
14011401

14021402
val sessionToken = SessionToken(this, ComponentName(this, VoiceMessageMediaService::class.java))
1403-
mediaControllerFuture = MediaController.Builder(this, sessionToken).buildAsync()
1403+
val future = MediaController.Builder(this, sessionToken).buildAsync()
1404+
mediaControllerFuture = future
1405+
1406+
future.addListener({
1407+
if (future !== mediaControllerFuture) {
1408+
return@addListener
1409+
}
14041410

1405-
mediaControllerFuture?.addListener({
14061411
mediaController = try {
1407-
mediaControllerFuture?.get()
1412+
future.get()
14081413
} catch (_: CancellationException) {
14091414
null
14101415
}

0 commit comments

Comments
 (0)