blob: 22b1744134c0c734abae8584c869eb7628e7ec2b [file] [log] [blame]
Ilya Matyukhin48ff8962021-02-22 13:13:13 -08001/*
2 * Copyright (C) 2021 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
Joshua McCloskeyc8c0bad2022-05-10 05:17:44 +000018#include <aidl/android/hardware/biometrics/common/SensorStrength.h>
Joe Bolingerde94aa02021-12-09 17:00:32 -080019#include <aidl/android/hardware/biometrics/fingerprint/ISessionCallback.h>
20
Ilya Matyukhin1d524382021-07-02 20:33:51 +000021#include <random>
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080022
Jeff Pu63f33c72022-07-28 16:06:23 -040023#include <aidl/android/hardware/biometrics/fingerprint/SensorLocation.h>
Joshua McCloskeyc8c0bad2022-05-10 05:17:44 +000024#include <future>
25#include <vector>
Joe Bolingerde94aa02021-12-09 17:00:32 -080026
27using namespace ::aidl::android::hardware::biometrics::common;
28
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080029namespace aidl::android::hardware::biometrics::fingerprint {
30
Joe Bolingerde94aa02021-12-09 17:00:32 -080031// A fake engine that is backed by system properties instead of hardware.
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080032class FakeFingerprintEngine {
33 public:
Ilya Matyukhin1d524382021-07-02 20:33:51 +000034 FakeFingerprintEngine() : mRandom(std::mt19937::default_seed) {}
Jeff Pu63f33c72022-07-28 16:06:23 -040035 virtual ~FakeFingerprintEngine() {}
Ilya Matyukhin1d524382021-07-02 20:33:51 +000036
Joe Bolingerde94aa02021-12-09 17:00:32 -080037 void generateChallengeImpl(ISessionCallback* cb);
38 void revokeChallengeImpl(ISessionCallback* cb, int64_t challenge);
39 void enrollImpl(ISessionCallback* cb, const keymaster::HardwareAuthToken& hat,
40 const std::future<void>& cancel);
41 void authenticateImpl(ISessionCallback* cb, int64_t operationId,
42 const std::future<void>& cancel);
43 void detectInteractionImpl(ISessionCallback* cb, const std::future<void>& cancel);
44 void enumerateEnrollmentsImpl(ISessionCallback* cb);
45 void removeEnrollmentsImpl(ISessionCallback* cb, const std::vector<int32_t>& enrollmentIds);
46 void getAuthenticatorIdImpl(ISessionCallback* cb);
47 void invalidateAuthenticatorIdImpl(ISessionCallback* cb);
48 void resetLockoutImpl(ISessionCallback* cb, const keymaster::HardwareAuthToken& /*hat*/);
Jeff Pu63f33c72022-07-28 16:06:23 -040049 bool getSensorLocationConfig(SensorLocation& out);
50
51 virtual ndk::ScopedAStatus onPointerDownImpl(int32_t pointerId, int32_t x, int32_t y,
52 float minor, float major);
53
54 virtual ndk::ScopedAStatus onPointerUpImpl(int32_t pointerId);
55
56 virtual ndk::ScopedAStatus onUiReadyImpl();
57
58 virtual SensorLocation getSensorLocation();
59
60 virtual SensorLocation defaultSensorLocation();
Ilya Matyukhin1d524382021-07-02 20:33:51 +000061
Jeff Pu343ca942022-09-14 15:56:30 -040062 std::vector<int32_t> parseIntSequence(const std::string& str, const std::string& sep = ",");
63
64 std::vector<std::vector<int32_t>> parseEnrollmentCapture(const std::string& str);
65
Ilya Matyukhin1d524382021-07-02 20:33:51 +000066 std::mt19937 mRandom;
Jeff Pu343ca942022-09-14 15:56:30 -040067
68 private:
69 static constexpr int32_t FINGERPRINT_ACQUIRED_VENDOR_BASE = 1000;
70 static constexpr int32_t FINGERPRINT_ERROR_VENDOR_BASE = 1000;
71 std::pair<AcquiredInfo, int32_t> convertAcquiredInfo(int32_t code);
72 std::pair<Error, int32_t> convertError(int32_t code);
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080073};
74
f8c8e4c62021-03-05 05:12:58 +000075} // namespace aidl::android::hardware::biometrics::fingerprint