Skip to content

fix(liveness): Detect failed camera opening #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import java.util.concurrent.Executors
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

internal typealias OnMuxedSegment = (bytes: ByteArray, timestamp: Long) -> Unit
Expand Down Expand Up @@ -137,6 +138,16 @@ internal class LivenessCoordinator(
private var disconnectEventReceived = false

init {
MainScope().launch {
delay(5_000)
if (!previewTextureView.hasReceivedUpdate) {
val faceLivenessException = FaceLivenessDetectionException(
"The camera failed to open within the allowed time limit.",
"Ensure the camera is available to use and that no other apps are using it."
)
processSessionError(faceLivenessException, true)
}
}
MainScope().launch {
getCameraProvider(context).apply {
if (lifecycleOwner.lifecycle.currentState != Lifecycle.State.DESTROYED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal class PreviewTextureView(
) : TextureView(context) {

private var surface: Surface? = null
internal var hasReceivedUpdate = false

init {
surfaceTextureListener = object : SurfaceTextureListener {
Expand All @@ -48,7 +49,11 @@ internal class PreviewTextureView(
}
}

override fun onSurfaceTextureUpdated(surfaceTexture: SurfaceTexture) {}
override fun onSurfaceTextureUpdated(surfaceTexture: SurfaceTexture) {
if (!hasReceivedUpdate) {
hasReceivedUpdate = true
}
}

override fun onSurfaceTextureSizeChanged(
surfaceTexture: SurfaceTexture,
Expand Down
Loading