Skip to content

Commit d4fb0c3

Browse files
authored
feat(liveness): Remove countdown (#56)
1 parent e73c923 commit d4fb0c3

File tree

8 files changed

+15
-263
lines changed

8 files changed

+15
-263
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,6 @@ internal class LivenessCoordinator(
217217
onChallengeFailed.accept(faceLivenessException)
218218
}
219219

220-
fun processCountdownComplete() {
221-
livenessState.onCountdownComplete()
222-
}
223-
224220
fun processColorDisplayed(
225221
currentColor: RgbColor,
226222
previousColor: RgbColor,

liveness/src/main/java/com/amplifyframework/ui/liveness/ml/FaceDetector.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ internal class FaceDetector(private val livenessState: LivenessState) {
426426
*/
427427
const val NUM_COORDS = 16
428428
const val INITIAL_FACE_DISTANCE_THRESHOLD = 0.32f
429-
const val FACE_DISTANCE_THRESHOLD_COUNTDOWN = 0.37f
430429

431430
fun loadModel(context: Context): Interpreter {
432431
val modelFileDescriptor =

liveness/src/main/java/com/amplifyframework/ui/liveness/model/LivenessCheckState.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@ import com.amplifyframework.ui.liveness.R
2020
import com.amplifyframework.ui.liveness.ml.FaceDetector
2121

2222
internal sealed class LivenessCheckState(val instructionId: Int? = null) {
23-
class Initial(instructionId: Int) : LivenessCheckState(instructionId) {
23+
class Initial(instructionId: Int? = null) : LivenessCheckState(instructionId) {
2424
companion object {
2525
fun withMoveFaceMessage() =
2626
Initial(R.string.amplify_ui_liveness_challenge_instruction_move_face)
2727
fun withMultipleFaceMessage() =
2828
Initial(R.string.amplify_ui_liveness_challenge_instruction_multiple_faces_detected)
29-
fun withHoldFaceMessage() = Initial(
30-
R.string.amplify_ui_liveness_challenge_instruction_hold_face_during_countdown
31-
)
3229
fun withMoveFaceFurtherAwayMessage() =
3330
Initial(R.string.amplify_ui_liveness_challenge_instruction_move_face_further)
3431
fun withConnectingMessage() =

liveness/src/main/java/com/amplifyframework/ui/liveness/state/LivenessState.kt

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -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())

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

Lines changed: 0 additions & 154 deletions
This file was deleted.

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import com.amplifyframework.ui.liveness.camera.LivenessCoordinator
5656
import com.amplifyframework.ui.liveness.camera.OnChallengeComplete
5757
import com.amplifyframework.ui.liveness.ml.FaceDetector
5858
import com.amplifyframework.ui.liveness.model.FaceLivenessDetectionException
59-
import com.amplifyframework.ui.liveness.model.LivenessCheckState
6059
import com.amplifyframework.ui.liveness.ui.helper.VideoViewportSize
6160
import com.amplifyframework.ui.liveness.util.hasCameraPermission
6261
import kotlinx.coroutines.launch
@@ -309,16 +308,6 @@ internal fun ChallengeView(
309308
horizontalAlignment = Alignment.CenterHorizontally
310309
) {
311310
InstructionMessage(livenessState.livenessCheckState.value)
312-
if (livenessState.livenessCheckState.value is
313-
LivenessCheckState.Initial && livenessState.countdownRunning
314-
) {
315-
CountdownView(
316-
key = key,
317-
durationInSeconds = 3f
318-
) {
319-
livenessCoordinator.processCountdownComplete()
320-
}
321-
}
322311
}
323312
}
324313
}

liveness/src/main/res/values/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
<string name="amplify_ui_liveness_get_ready_step_3">Move to a well-lit place that is not in direct sunlight.</string>
3535
<string name="amplify_ui_liveness_get_ready_begin_check">Begin check</string>
3636
<string name="amplify_ui_liveness_challenge_recording_indicator_label">REC</string>
37-
<string name="amplify_ui_liveness_challenge_instruction_hold_face_during_countdown">Hold face position during countdown</string>
3837
<string name="amplify_ui_liveness_challenge_instruction_hold_face_during_freshness">Hold still</string>
3938
<string name="amplify_ui_liveness_challenge_instruction_move_face_further">Move back</string>
4039
<string name="amplify_ui_liveness_challenge_instruction_move_face_closer">Move closer</string>

0 commit comments

Comments
 (0)