blob: 82cc3133b1f2acdc51228fd8dd5e86fee9662181 [file] [log] [blame]
Jeff Pu3e7448d2023-12-07 17:25:22 +00001/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <aidl/android/hardware/biometrics/face/ISessionCallback.h>
20#include <android/binder_to_string.h>
21#include <stdint.h>
22#include <string>
23
24namespace aidl::android::hardware::biometrics::face {
25
26// Lockout implementation for Face Virtual HAL
27class FakeLockoutTracker {
28 public:
29 FakeLockoutTracker()
30 : mFailedCount(0),
Jeff Pu4aca35e2024-01-04 22:40:33 +000031 mTimedFailedCount(0),
Jeff Pu3e7448d2023-12-07 17:25:22 +000032 mLastFailedTime(0),
Jeff Pu4aca35e2024-01-04 22:40:33 +000033 mCurrentMode(LockoutMode::kNone),
Jeff Pu3e7448d2023-12-07 17:25:22 +000034 mIsLockoutTimerStarted(false),
35 mIsLockoutTimerAborted(false) {}
36 ~FakeLockoutTracker() {}
37
38 enum class LockoutMode : int8_t { kNone = 0, kTimed, kPermanent };
39
40 bool checkIfLockout(ISessionCallback*);
41 void addFailedAttempt(ISessionCallback*);
42 int64_t getLockoutTimeLeft();
43 LockoutMode getMode();
44 void reset(bool dueToTimerExpire = false);
45 inline std::string toString() const {
46 std::ostringstream os;
47 os << "----- FakeLockoutTracker:: -----" << std::endl;
48 os << "mFailedCount:" << mFailedCount;
49 os << ", mCurrentMode:" << (int)mCurrentMode;
50 os << ", mLastFailedTime:" << (int)(mLastFailedTime / 1000000LL);
51 os << ", mIsLockoutTimerStarted:" << mIsLockoutTimerStarted;
52 os << ", mIsLockoutTimerAborted:" << mIsLockoutTimerAborted;
53 os << std::endl;
54 return os.str();
55 }
56
57 private:
58 void startLockoutTimer(int64_t timeout, ISessionCallback* cb);
59 void lockoutTimerExpired(ISessionCallback* cb);
60 int32_t getTimedLockoutDuration();
61 void abortTimer();
62
63 private:
64 int32_t mFailedCount;
65 int32_t mTimedFailedCount;
66 int64_t mLastFailedTime;
67 LockoutMode mCurrentMode;
68 bool mIsLockoutTimerStarted;
69 bool mIsLockoutTimerAborted;
70};
71
72} // namespace aidl::android::hardware::biometrics::face