blob: b92777068c187717b1b267aca8b7a63c1a7ca86b [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
18
19#include <android-base/logging.h>
Ilya Matyukhin1d524382021-07-02 20:33:51 +000020#include <random>
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080021
22namespace aidl::android::hardware::biometrics::fingerprint {
23
24class FakeFingerprintEngine {
25 public:
Ilya Matyukhin1d524382021-07-02 20:33:51 +000026 FakeFingerprintEngine() : mRandom(std::mt19937::default_seed) {}
27
f8c8e4c62021-03-05 05:12:58 +000028 void generateChallengeImpl(ISessionCallback* cb) {
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080029 LOG(INFO) << "generateChallengeImpl";
Ilya Matyukhin1d524382021-07-02 20:33:51 +000030 std::uniform_int_distribution<int64_t> dist;
31 auto challenge = dist(mRandom);
32 cb->onChallengeGenerated(challenge);
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080033 }
34
35 void revokeChallengeImpl(ISessionCallback* cb, int64_t challenge) {
36 LOG(INFO) << "revokeChallengeImpl";
37 cb->onChallengeRevoked(challenge);
38 }
39
Ilya Matyukhin1d524382021-07-02 20:33:51 +000040 void enrollImpl(ISessionCallback* cb, const keymaster::HardwareAuthToken& hat) {
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080041 LOG(INFO) << "enrollImpl";
Ilya Matyukhin1d524382021-07-02 20:33:51 +000042 // Do proper HAT verification in the real implementation.
43 if (hat.mac.empty()) {
44 cb->onError(Error::UNABLE_TO_PROCESS, 0 /* vendorError */);
45 return;
46 }
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080047 cb->onEnrollmentProgress(0 /* enrollmentId */, 0 /* remaining */);
48 }
49
Ilya Matyukhinaea213b2021-03-23 19:01:42 -070050 void authenticateImpl(ISessionCallback* cb, int64_t /* operationId */) {
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080051 LOG(INFO) << "authenticateImpl";
52 cb->onAuthenticationSucceeded(0 /* enrollmentId */, {} /* hat */);
53 }
54
55 void detectInteractionImpl(ISessionCallback* cb) {
56 LOG(INFO) << "detectInteractionImpl";
57 cb->onInteractionDetected();
58 }
59
60 void enumerateEnrollmentsImpl(ISessionCallback* cb) {
61 LOG(INFO) << "enumerateEnrollmentsImpl";
62 cb->onEnrollmentsEnumerated({} /* enrollmentIds */);
63 }
64
65 void removeEnrollmentsImpl(ISessionCallback* cb, const std::vector<int32_t>& enrollmentIds) {
66 LOG(INFO) << "removeEnrollmentsImpl";
67 cb->onEnrollmentsRemoved(enrollmentIds);
68 }
69
70 void getAuthenticatorIdImpl(ISessionCallback* cb) {
71 LOG(INFO) << "getAuthenticatorIdImpl";
72 cb->onAuthenticatorIdRetrieved(0 /* authenticatorId */);
73 }
74
75 void invalidateAuthenticatorIdImpl(ISessionCallback* cb) {
76 LOG(INFO) << "invalidateAuthenticatorIdImpl";
77 cb->onAuthenticatorIdInvalidated(0 /* newAuthenticatorId */);
78 }
79
80 void resetLockoutImpl(ISessionCallback* cb, const keymaster::HardwareAuthToken& /*hat*/) {
81 LOG(INFO) << "resetLockoutImpl";
82 cb->onLockoutCleared();
83 }
Ilya Matyukhin1d524382021-07-02 20:33:51 +000084
85 std::mt19937 mRandom;
Ilya Matyukhin48ff8962021-02-22 13:13:13 -080086};
87
f8c8e4c62021-03-05 05:12:58 +000088} // namespace aidl::android::hardware::biometrics::fingerprint