blob: 06dd396c7074f2e83441651ac77f703960570e10 [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
Jeff Pu4b5e5ce2023-09-06 14:47:49 +000019#define LOG_TAG "FaceVirtualHal"
20
Joshua McCloskeydb009a52022-05-10 05:18:20 +000021#include <aidl/android/hardware/biometrics/common/SensorStrength.h>
22#include <aidl/android/hardware/biometrics/face/BnSession.h>
23#include <aidl/android/hardware/biometrics/face/FaceSensorType.h>
24#include <aidl/android/hardware/biometrics/face/ISessionCallback.h>
25
26#include <random>
27
28#include <future>
29#include <vector>
30
31namespace aidl::android::hardware::biometrics::face {
32
33namespace face = aidl::android::hardware::biometrics::face;
34namespace common = aidl::android::hardware::biometrics::common;
35namespace keymaster = aidl::android::hardware::keymaster;
36
37using aidl::android::hardware::common::NativeHandle;
38// A fake engine that is backed by system properties instead of hardware.
39class FakeFaceEngine {
40 public:
41 FakeFaceEngine() : mRandom(std::mt19937::default_seed) {}
42
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*/);
63
64 std::mt19937 mRandom;
Jeff Pu484d2e72023-09-25 15:11:19 +000065
66 private:
67 static constexpr int32_t FACE_ACQUIRED_VENDOR_BASE = 1000;
68 static constexpr int32_t FACE_ERROR_VENDOR_BASE = 1000;
69 std::pair<AcquiredInfo, int32_t> convertAcquiredInfo(int32_t code);
70 std::pair<Error, int32_t> convertError(int32_t code);
Joshua McCloskeydb009a52022-05-10 05:18:20 +000071};
72
Jeff Pu4b5e5ce2023-09-06 14:47:49 +000073} // namespace aidl::android::hardware::biometrics::face