Skip to content

Commit 5e892a8

Browse files
authored
fix(liveness): Catch unhandled exceptions in coordinator (#141)
1 parent 3f20493 commit 5e892a8

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

liveness/src/main/java/com/amplifyframework/ui/liveness/camera/LivenessCoordinator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ internal class LivenessCoordinator(
120120
onMuxedSegment = { bytes, time ->
121121
livenessState.livenessSessionInfo?.sendVideoEvent(VideoEvent(bytes, Date(time)))
122122
}
123-
)!!
123+
) ?: throw IllegalStateException("Failed to start the encoder.")
124124

125125
private val renderer = OpenGLRenderer()
126126
.apply {

liveness/src/main/java/com/amplifyframework/ui/liveness/ui/FaceLivenessDetector.kt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,25 @@ internal fun ChallengeView(
166166
val showPhotosensitivityAlert = remember { mutableStateOf(false) }
167167

168168
DisposableEffect(key) {
169-
coordinator = LivenessCoordinator(
170-
context,
171-
lifecycleOwner,
172-
sessionId,
173-
region,
174-
credentialsProvider,
175-
disableStartView,
176-
onChallengeComplete = { currentOnChallengeComplete() },
177-
onChallengeFailed = { currentOnChallengeFailed.accept(it) }
178-
)
169+
try {
170+
coordinator = LivenessCoordinator(
171+
context,
172+
lifecycleOwner,
173+
sessionId,
174+
region,
175+
credentialsProvider,
176+
disableStartView,
177+
onChallengeComplete = { currentOnChallengeComplete() },
178+
onChallengeFailed = { currentOnChallengeFailed.accept(it) }
179+
)
180+
} catch (e: Exception) {
181+
currentOnChallengeFailed.accept(
182+
FaceLivenessDetectionException(
183+
message = "Failed to initialize video components required for Liveness check.",
184+
throwable = e
185+
)
186+
)
187+
}
179188

180189
onDispose {
181190
coordinator?.destroy(context)

0 commit comments

Comments
 (0)