blob: b1e1388186b9ae3988fc3a1c83bf9ff5d1ec33a9 [file] [log] [blame]
Joshua McCloskeydb009a52022-05-10 05:18:20 +00001/*
2 * Copyright (C) 2022 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/common/SensorStrength.h>
20#include <aidl/android/hardware/biometrics/face/BnSession.h>
21#include <aidl/android/hardware/biometrics/face/FaceSensorType.h>
22#include <aidl/android/hardware/biometrics/face/ISessionCallback.h>
23
Joshua McCloskeydb009a52022-05-10 05:18:20 +000024#include <future>
Jeff Pu3e7448d2023-12-07 17:25:22 +000025#include <random>
Joshua McCloskeydb009a52022-05-10 05:18:20 +000026#include <vector>
27
Jeff Pu3e7448d2023-12-07 17:25:22 +000028#include "FakeLockoutTracker.h"
29
Joshua McCloskeydb009a52022-05-10 05:18:20 +000030namespace aidl::android::hardware::biometrics::face {
31
32namespace face = aidl::android::hardware::biometrics::face;
33namespace common = aidl::android::hardware::biometrics::common;
34namespace keymaster = aidl::android::hardware::keymaster;
35
36using aidl::android::hardware::common::NativeHandle;
37// A fake engine that is backed by system properties instead of hardware.
38class FakeFaceEngine {
39 public:
40 FakeFaceEngine() : mRandom(std::mt19937::default_seed) {}
Jeff Pu3e7448d2023-12-07 17:25:22 +000041 virtual ~FakeFaceEngine() {}
Joshua McCloskeydb009a52022-05-10 05:18:20 +000042
43 static face::FaceSensorType GetSensorType();
44 static common::SensorStrength GetSensorStrength();
45 void generateChallengeImpl(ISessionCallback* cb);
46 void revokeChallengeImpl(ISessionCallback* cb, int64_t challenge);
47 void getEnrollmentConfigImpl(ISessionCallback* cb,
48 std::vector<EnrollmentStageConfig>* return_val);
49 void enrollImpl(ISessionCallback* cb, const keymaster::HardwareAuthToken& hat,
50 EnrollmentType enrollmentType, const std::vector<Feature>& features,
51 const std::future<void>& cancel);
52 void authenticateImpl(ISessionCallback* cb, int64_t operationId,
53 const std::future<void>& cancel);
54 void detectInteractionImpl(ISessionCallback* cb, const std::future<void>& cancel);
55 void enumerateEnrollmentsImpl(ISessionCallback* cb);
56 void removeEnrollmentsImpl(ISessionCallback* cb, const std::vector<int32_t>& enrollmentIds);
57 void getFeaturesImpl(ISessionCallback* cb);
58 void setFeatureImpl(ISessionCallback* cb, const keymaster::HardwareAuthToken& hat,
59 Feature feature, bool enabled);
60 void getAuthenticatorIdImpl(ISessionCallback* cb);
61 void invalidateAuthenticatorIdImpl(ISessionCallback* cb);
62 void resetLockoutImpl(ISessionCallback* cb, const keymaster::HardwareAuthToken& /*hat*/);
Jeff Pu4aca35e2024-01-04 22:40:33 +000063 int32_t getLatency(const std::vector<std::optional<std::int32_t>>& latencyVec);
Joshua McCloskeydb009a52022-05-10 05:18:20 +000064
Jeff Pu3e7448d2023-12-07 17:25:22 +000065 virtual std::string toString() const {
66 std::ostringstream os;
67 os << "----- FakeFaceEngine:: -----" << std::endl;
68 os << mLockoutTracker.toString();
69 return os.str();
70 }
71
Joshua McCloskeydb009a52022-05-10 05:18:20 +000072 std::mt19937 mRandom;
Jeff Pu484d2e72023-09-25 15:11:19 +000073
74 private:
Jeff Pu4aca35e2024-01-04 22:40:33 +000075 int32_t getRandomInRange(int32_t bound1, int32_t bound2);
Jeff Pu484d2e72023-09-25 15:11:19 +000076 static constexpr int32_t FACE_ACQUIRED_VENDOR_BASE = 1000;
77 static constexpr int32_t FACE_ERROR_VENDOR_BASE = 1000;
78 std::pair<AcquiredInfo, int32_t> convertAcquiredInfo(int32_t code);
79 std::pair<Error, int32_t> convertError(int32_t code);
Jeff Pu3e7448d2023-12-07 17:25:22 +000080 FakeLockoutTracker mLockoutTracker;
Joshua McCloskeydb009a52022-05-10 05:18:20 +000081};
82
Jeff Pu4b5e5ce2023-09-06 14:47:49 +000083} // namespace aidl::android::hardware::biometrics::face