File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
liveness/src/main/java/com/amplifyframework/ui/liveness/camera Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ import java.util.concurrent.Executors
5050import kotlin.coroutines.resume
5151import kotlin.coroutines.suspendCoroutine
5252import kotlinx.coroutines.MainScope
53+ import kotlinx.coroutines.delay
5354import kotlinx.coroutines.launch
5455
5556internal typealias OnMuxedSegment = (bytes: ByteArray , timestamp: Long ) -> Unit
@@ -137,6 +138,16 @@ internal class LivenessCoordinator(
137138 private var disconnectEventReceived = false
138139
139140 init {
141+ MainScope ().launch {
142+ delay(5_000 )
143+ if (! previewTextureView.hasReceivedUpdate) {
144+ val faceLivenessException = FaceLivenessDetectionException (
145+ " The camera failed to open within the allowed time limit." ,
146+ " Ensure the camera is available to use and that no other apps are using it."
147+ )
148+ processSessionError(faceLivenessException, true )
149+ }
150+ }
140151 MainScope ().launch {
141152 getCameraProvider(context).apply {
142153 if (lifecycleOwner.lifecycle.currentState != Lifecycle .State .DESTROYED ) {
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ internal class PreviewTextureView(
3131) : TextureView(context) {
3232
3333 private var surface: Surface ? = null
34+ internal var hasReceivedUpdate = false
3435
3536 init {
3637 surfaceTextureListener = object : SurfaceTextureListener {
@@ -48,7 +49,11 @@ internal class PreviewTextureView(
4849 }
4950 }
5051
51- override fun onSurfaceTextureUpdated (surfaceTexture : SurfaceTexture ) {}
52+ override fun onSurfaceTextureUpdated (surfaceTexture : SurfaceTexture ) {
53+ if (! hasReceivedUpdate) {
54+ hasReceivedUpdate = true
55+ }
56+ }
5257
5358 override fun onSurfaceTextureSizeChanged (
5459 surfaceTexture : SurfaceTexture ,
You can’t perform that action at this time.
0 commit comments