blob: 8d9303c491205b6e7d77645006c49e3adf325398 [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*/);
63
Jeff Pu3e7448d2023-12-07 17:25:22 +000064 virtual std::string toString() const {
65 std::ostringstream os;
66 os << "----- FakeFaceEngine:: -----" << std::endl;
67 os << mLockoutTracker.toString();
68 return os.str();
69 }
70
Joshua McCloskeydb009a52022-05-10 05:18:20 +000071 std::mt19937 mRandom;
Jeff Pu484d2e72023-09-25 15:11:19 +000072
73 private:
74 static constexpr int32_t FACE_ACQUIRED_VENDOR_BASE = 1000;
75 static constexpr int32_t FACE_ERROR_VENDOR_BASE = 1000;
76 std::pair<AcquiredInfo, int32_t> convertAcquiredInfo(int32_t code);
77 std::pair<Error, int32_t> convertError(int32_t code);
Jeff Pu3e7448d2023-12-07 17:25:22 +000078 FakeLockoutTracker mLockoutTracker;
Joshua McCloskeydb009a52022-05-10 05:18:20 +000079};
80
Jeff Pu4b5e5ce2023-09-06 14:47:49 +000081} // namespace aidl::android::hardware::biometrics::face