From e39cc9a1db280b76f5dd7eed25440f3fd07edf8d Mon Sep 17 00:00:00 2001 From: Curtis Belmonte Date: Mon, 5 Apr 2021 15:08:16 -0700 Subject: Send AIDL face enrollment frame info to clients Test: Manually tested grid and traffic light face enrollment Bug: 181374571 Change-Id: If742c6c32547d56be417d4eb0cbb729ed90552a5 --- .../android/hardware/face/FaceEnrollFrame.java | 1 + .../android/hardware/face/FaceEnrollStage.java | 74 ------------------- .../android/hardware/face/FaceEnrollStages.java | 84 ++++++++++++++++++++++ core/java/android/hardware/face/FaceManager.java | 45 ++++++++++-- 4 files changed, 125 insertions(+), 79 deletions(-) delete mode 100644 core/java/android/hardware/face/FaceEnrollStage.java create mode 100644 core/java/android/hardware/face/FaceEnrollStages.java (limited to 'core/java/android') diff --git a/core/java/android/hardware/face/FaceEnrollFrame.java b/core/java/android/hardware/face/FaceEnrollFrame.java index 551139d240a3..822a57944449 100644 --- a/core/java/android/hardware/face/FaceEnrollFrame.java +++ b/core/java/android/hardware/face/FaceEnrollFrame.java @@ -18,6 +18,7 @@ package android.hardware.face; import android.annotation.NonNull; import android.annotation.Nullable; +import android.hardware.face.FaceEnrollStages.FaceEnrollStage; import android.os.Parcel; import android.os.Parcelable; diff --git a/core/java/android/hardware/face/FaceEnrollStage.java b/core/java/android/hardware/face/FaceEnrollStage.java deleted file mode 100644 index de717fbe46b4..000000000000 --- a/core/java/android/hardware/face/FaceEnrollStage.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.hardware.face; - -import android.annotation.IntDef; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -/** - * A stage that may occur during face enrollment. - * - * @hide - */ -@Retention(RetentionPolicy.SOURCE) -@IntDef({ - FaceEnrollStage.UNKNOWN, - FaceEnrollStage.FIRST_FRAME_RECEIVED, - FaceEnrollStage.WAITING_FOR_CENTERING, - FaceEnrollStage.HOLD_STILL_IN_CENTER, - FaceEnrollStage.ENROLLING_MOVEMENT_1, - FaceEnrollStage.ENROLLING_MOVEMENT_2, - FaceEnrollStage.ENROLLMENT_FINISHED -}) -public @interface FaceEnrollStage { - /** - * The current enrollment stage is not known. - */ - int UNKNOWN = -1; - - /** - * Enrollment has just begun. No action is needed from the user yet. - */ - int FIRST_FRAME_RECEIVED = 0; - - /** - * The user must center their face in the frame. - */ - int WAITING_FOR_CENTERING = 1; - - /** - * The user must keep their face centered in the frame. - */ - int HOLD_STILL_IN_CENTER = 2; - - /** - * The user must follow a first set of movement instructions. - */ - int ENROLLING_MOVEMENT_1 = 3; - - /** - * The user must follow a second set of movement instructions. - */ - int ENROLLING_MOVEMENT_2 = 4; - - /** - * Enrollment has completed. No more action is needed from the user. - */ - int ENROLLMENT_FINISHED = 5; -} diff --git a/core/java/android/hardware/face/FaceEnrollStages.java b/core/java/android/hardware/face/FaceEnrollStages.java new file mode 100644 index 000000000000..de374b319ff9 --- /dev/null +++ b/core/java/android/hardware/face/FaceEnrollStages.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.face; + +import android.annotation.IntDef; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * A collection of constants representing different stages of face enrollment. + * + * @hide + */ +public final class FaceEnrollStages { + // Prevent instantiation. + private FaceEnrollStages() {} + + /** + * A stage that may occur during face enrollment. + * + * @hide + */ + @IntDef({ + UNKNOWN, + FIRST_FRAME_RECEIVED, + WAITING_FOR_CENTERING, + HOLD_STILL_IN_CENTER, + ENROLLING_MOVEMENT_1, + ENROLLING_MOVEMENT_2, + ENROLLMENT_FINISHED + }) + @Retention(RetentionPolicy.SOURCE) + public @interface FaceEnrollStage {} + + /** + * The current enrollment stage is not known. + */ + public static final int UNKNOWN = 0; + + /** + * Enrollment has just begun. No action is needed from the user yet. + */ + public static final int FIRST_FRAME_RECEIVED = 1; + + /** + * The user must center their face in the frame. + */ + public static final int WAITING_FOR_CENTERING = 2; + + /** + * The user must keep their face centered in the frame. + */ + public static final int HOLD_STILL_IN_CENTER = 3; + + /** + * The user must follow a first set of movement instructions. + */ + public static final int ENROLLING_MOVEMENT_1 = 4; + + /** + * The user must follow a second set of movement instructions. + */ + public static final int ENROLLING_MOVEMENT_2 = 5; + + /** + * Enrollment has completed. No more action is needed from the user. + */ + public static final int ENROLLMENT_FINISHED = 6; +} diff --git a/core/java/android/hardware/face/FaceManager.java b/core/java/android/hardware/face/FaceManager.java index 5f8789993a5e..9a27a99437bc 100644 --- a/core/java/android/hardware/face/FaceManager.java +++ b/core/java/android/hardware/face/FaceManager.java @@ -1022,6 +1022,34 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) { } + /** + * Called each time a single frame is captured during enrollment. + * + *

For older, non-AIDL implementations, only {@code helpCode} and {@code helpMessage} are + * supported. Sensible default values will be provided for all other arguments. + * + * @param helpCode An integer identifying the capture status for this frame. + * @param helpMessage A human-readable help string that can be shown in UI. + * @param cell The cell captured during this frame of enrollment, if any. + * @param stage An integer representing the current stage of enrollment. + * @param pan The horizontal pan of the detected face. Values in the range [-1, 1] + * indicate a good capture. + * @param tilt The vertical tilt of the detected face. Values in the range [-1, 1] + * indicate a good capture. + * @param distance The distance of the detected face from the device. Values in + * the range [-1, 1] indicate a good capture. + */ + public void onEnrollmentFrame( + int helpCode, + @Nullable CharSequence helpMessage, + @Nullable FaceEnrollCell cell, + @FaceEnrollStages.FaceEnrollStage int stage, + float pan, + float tilt, + float distance) { + onEnrollmentHelp(helpCode, helpMessage); + } + /** * Called as each enrollment step progresses. Enrollment is considered complete when * remaining reaches 0. This function will not be called if enrollment fails. See @@ -1305,7 +1333,7 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan } else if (mEnrollmentCallback != null) { final FaceEnrollFrame frame = new FaceEnrollFrame( null /* cell */, - FaceEnrollStage.UNKNOWN, + FaceEnrollStages.UNKNOWN, new FaceDataFrame(acquireInfo, vendorCode)); sendEnrollmentFrame(frame); } @@ -1333,12 +1361,19 @@ public class FaceManager implements BiometricAuthenticator, BiometricFaceConstan if (frame == null) { Slog.w(TAG, "Received null enrollment frame"); } else if (mEnrollmentCallback != null) { - // TODO(b/178414967): Send additional frame data to callback - final int acquireInfo = frame.getData().getAcquiredInfo(); - final int vendorCode = frame.getData().getVendorCode(); + final FaceDataFrame data = frame.getData(); + final int acquireInfo = data.getAcquiredInfo(); + final int vendorCode = data.getVendorCode(); final int helpCode = getHelpCode(acquireInfo, vendorCode); final String helpMessage = getEnrollHelpMessage(mContext, acquireInfo, vendorCode); - mEnrollmentCallback.onEnrollmentHelp(helpCode, helpMessage); + mEnrollmentCallback.onEnrollmentFrame( + helpCode, + helpMessage, + frame.getCell(), + frame.getStage(), + data.getPan(), + data.getTilt(), + data.getDistance()); } } -- cgit v1.2.3