Face Virtual HAL lockout support

Bug: 294254230
Test: atest android.hardware.biometrics.face.FakeFaceEngineTest
Test: atest android.hardware.biometrics.face.FakeLockoutTrackerTest
Change-Id: I4ed3ada4734f595d5f9ac70cf5ed2a94bed378c6
diff --git a/biometrics/face/aidl/default/FakeFaceEngine.cpp b/biometrics/face/aidl/default/FakeFaceEngine.cpp
index dc524bb..7380611 100644
--- a/biometrics/face/aidl/default/FakeFaceEngine.cpp
+++ b/biometrics/face/aidl/default/FakeFaceEngine.cpp
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2023 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.
+ */
+
+#define LOG_TAG "FaceVirtualHalEngine"
+
 #include "FakeFaceEngine.h"
 
 #include <android-base/logging.h>
@@ -186,6 +204,10 @@
         return;
     }
 
+    if (mLockoutTracker.checkIfLockout(cb)) {
+        return;
+    }
+
     int i = 0;
     do {
         if (FaceHalProperties::lockout().value_or(false)) {
@@ -197,6 +219,7 @@
 
         if (FaceHalProperties::operation_authenticate_fails().value_or(false)) {
             LOG(ERROR) << "Fail: operation_authenticate_fails";
+            mLockoutTracker.addFailedAttempt(cb);
             cb->onAuthenticationFailed();
             return;
         }
@@ -231,10 +254,12 @@
     } while (!Util::hasElapsed(now, duration));
 
     if (id > 0 && isEnrolled) {
+        mLockoutTracker.reset();
         cb->onAuthenticationSucceeded(id, {} /* hat */);
         return;
     } else {
         LOG(ERROR) << "Fail: face not enrolled";
+        mLockoutTracker.addFailedAttempt(cb);
         cb->onAuthenticationFailed();
         cb->onError(Error::TIMEOUT, 0 /* vendorError*/);
         return;
@@ -389,6 +414,7 @@
                                       const keymaster::HardwareAuthToken& /*hat*/) {
     BEGIN_OP(0);
     FaceHalProperties::lockout(false);
+    mLockoutTracker.reset();
     cb->onLockoutCleared();
 }