@@ -50,12 +50,11 @@ internal data class LivenessState(
5050) {
5151 var videoViewportSize: VideoViewportSize ? by mutableStateOf(null )
5252 var livenessCheckState = mutableStateOf<LivenessCheckState >(
53- LivenessCheckState .Initial .withHoldFaceMessage ()
53+ LivenessCheckState .Initial ()
5454 )
5555 var runningFreshness by mutableStateOf(false )
5656 var faceGuideRect: RectF ? by mutableStateOf(null )
5757 var faceMatchPercentage: Float by mutableStateOf(0.25f )
58- var countdownRunning by mutableStateOf(false )
5958 var initialFaceDistanceCheckPassed by mutableStateOf(false )
6059 var initialLocalFaceFound by mutableStateOf(false )
6160
@@ -84,12 +83,6 @@ internal data class LivenessState(
8483 }
8584 }
8685
87- fun onCountdownComplete () {
88- livenessCheckState.value = LivenessCheckState .Running ()
89- countdownRunning = false
90- readyForOval = true
91- }
92-
9386 fun onError (stopLivenessSession : Boolean ) {
9487 livenessCheckState.value = LivenessCheckState .Error
9588 readyForOval = false
@@ -101,13 +94,13 @@ internal data class LivenessState(
10194 }
10295
10396 fun onLivenessSessionReady (faceLivenessSession : FaceLivenessSession ) {
104- livenessCheckState.value = LivenessCheckState .Initial .withHoldFaceMessage()
10597 livenessSessionInfo = faceLivenessSession
10698 faceTargetChallenge = faceLivenessSession.challenges
10799 .filterIsInstance<FaceTargetChallenge >().firstOrNull()
108100 colorChallenge = faceLivenessSession.challenges
109101 .filterIsInstance<ColorChallenge >().firstOrNull()
110- countdownRunning = true
102+ livenessCheckState.value = LivenessCheckState .Running ()
103+ readyForOval = true
111104 }
112105
113106 fun onFullChallengeComplete () {
@@ -164,18 +157,8 @@ internal data class LivenessState(
164157 }
165158 when (faceCount) {
166159 0 -> {
167- if (! initialLocalFaceFound ||
168- (! countdownRunning && livenessCheckState.value is LivenessCheckState .Initial )
169- ) {
160+ if (! initialLocalFaceFound || livenessCheckState.value is LivenessCheckState .Initial ) {
170161 livenessCheckState.value = LivenessCheckState .Initial .withMoveFaceMessage()
171- } else if (
172- countdownRunning && livenessCheckState.value is LivenessCheckState .Initial
173- ) {
174- val error = FaceLivenessDetectionException (
175- message = " Check failed during countdown." ,
176- recoverySuggestion = " No face detected during the countdown."
177- )
178- onSessionError(error, true )
179162 } else if (livenessCheckState.value is LivenessCheckState .Running ) {
180163 livenessCheckState.value = LivenessCheckState .Running .withMoveFaceMessage()
181164 }
@@ -186,18 +169,8 @@ internal data class LivenessState(
186169 }
187170 }
188171 else -> {
189- if (! initialLocalFaceFound ||
190- (! countdownRunning && livenessCheckState.value is LivenessCheckState .Initial )
191- ) {
172+ if (! initialLocalFaceFound || livenessCheckState.value is LivenessCheckState .Initial ) {
192173 livenessCheckState.value = LivenessCheckState .Initial .withMultipleFaceMessage()
193- } else if (countdownRunning &&
194- livenessCheckState.value is LivenessCheckState .Initial
195- ) {
196- val error = FaceLivenessDetectionException (
197- message = " Check failed during countdown." ,
198- recoverySuggestion = " Multiple faces detected during the countdown."
199- )
200- onSessionError(error, true )
201174 } else if (livenessCheckState.value is LivenessCheckState .Running ) {
202175 livenessCheckState.value = LivenessCheckState .Running .withMultipleFaceMessage()
203176 }
@@ -211,7 +184,7 @@ internal data class LivenessState(
211184 rightEye : FaceDetector .Landmark ,
212185 mouth : FaceDetector .Landmark
213186 ) {
214- if (! countdownRunning && ! initialFaceDistanceCheckPassed) {
187+ if (! initialFaceDistanceCheckPassed) {
215188 val faceDistance = FaceDetector .calculateFaceDistance(
216189 leftEye, rightEye, mouth,
217190 LivenessCoordinator .TARGET_WIDTH , LivenessCoordinator .TARGET_HEIGHT
@@ -225,20 +198,6 @@ internal data class LivenessState(
225198 }
226199 }
227200
228- if (countdownRunning && livenessCheckState.value is LivenessCheckState .Initial ) {
229- val faceDistance = FaceDetector .calculateFaceDistance(
230- leftEye, rightEye, mouth,
231- LivenessCoordinator .TARGET_WIDTH , LivenessCoordinator .TARGET_HEIGHT
232- )
233- if (faceDistance >= FaceDetector .FACE_DISTANCE_THRESHOLD_COUNTDOWN ) {
234- val error = FaceLivenessDetectionException (
235- message = " Check failed during countdown." ,
236- recoverySuggestion = " User should not move closer during the countdown."
237- )
238- onSessionError(error, true )
239- }
240- }
241-
242201 if (readyForOval) {
243202 if (initialStreamFace == null ) {
244203 val face = InitialStreamFace (faceRect, System .currentTimeMillis())
0 commit comments