Skip to content

Commit 6a755be

Browse files
Fixed ScreenCaptureConnection hanging forever and crashing on cancellation
1 parent c07d159 commit 6a755be

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"client-sdk-android": patch
3+
---
4+
5+
Fixed ScreenCaptureConnection suspending forever when bindService fails and crashing when resuming canceled continuations.

livekit-android-sdk/src/main/java/io/livekit/android/room/track/screencapture/ScreenCaptureConnection.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,21 @@ internal class ScreenCaptureConnection(private val context: Context) {
5757
}
5858

5959
val intent = Intent(context, ScreenCaptureService::class.java)
60-
context.bindService(intent, connection, BIND_AUTO_CREATE)
61-
return suspendCancellableCoroutine {
60+
val bound = context.bindService(intent, connection, BIND_AUTO_CREATE)
61+
if (!bound) {
62+
throw IllegalStateException("Failed to bind ScreenCaptureService.")
63+
}
64+
return suspendCancellableCoroutine { cont ->
65+
cont.invokeOnCancellation {
66+
synchronized(this) {
67+
queuedConnects.remove(cont)
68+
}
69+
}
6270
synchronized(this) {
6371
if (isBound) {
64-
it.resume(Unit)
72+
cont.resume(Unit)
6573
} else {
66-
queuedConnects.add(it)
74+
queuedConnects.add(cont)
6775
}
6876
}
6977
}

0 commit comments

Comments
 (0)