Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 1 | /* |
| 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 Matyukhin | 1d52438 | 2021-07-02 20:33:51 +0000 | [diff] [blame^] | 20 | #include <random> |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 21 | |
| 22 | namespace aidl::android::hardware::biometrics::fingerprint { |
| 23 | |
| 24 | class FakeFingerprintEngine { |
| 25 | public: |
Ilya Matyukhin | 1d52438 | 2021-07-02 20:33:51 +0000 | [diff] [blame^] | 26 | FakeFingerprintEngine() : mRandom(std::mt19937::default_seed) {} |
| 27 | |
f | 8c8e4c6 | 2021-03-05 05:12:58 +0000 | [diff] [blame] | 28 | void generateChallengeImpl(ISessionCallback* cb) { |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 29 | LOG(INFO) << "generateChallengeImpl"; |
Ilya Matyukhin | 1d52438 | 2021-07-02 20:33:51 +0000 | [diff] [blame^] | 30 | std::uniform_int_distribution<int64_t> dist; |
| 31 | auto challenge = dist(mRandom); |
| 32 | cb->onChallengeGenerated(challenge); |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | void revokeChallengeImpl(ISessionCallback* cb, int64_t challenge) { |
| 36 | LOG(INFO) << "revokeChallengeImpl"; |
| 37 | cb->onChallengeRevoked(challenge); |
| 38 | } |
| 39 | |
Ilya Matyukhin | 1d52438 | 2021-07-02 20:33:51 +0000 | [diff] [blame^] | 40 | void enrollImpl(ISessionCallback* cb, const keymaster::HardwareAuthToken& hat) { |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 41 | LOG(INFO) << "enrollImpl"; |
Ilya Matyukhin | 1d52438 | 2021-07-02 20:33:51 +0000 | [diff] [blame^] | 42 | // 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 Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 47 | cb->onEnrollmentProgress(0 /* enrollmentId */, 0 /* remaining */); |
| 48 | } |
| 49 | |
Ilya Matyukhin | aea213b | 2021-03-23 19:01:42 -0700 | [diff] [blame] | 50 | void authenticateImpl(ISessionCallback* cb, int64_t /* operationId */) { |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 51 | 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 Matyukhin | 1d52438 | 2021-07-02 20:33:51 +0000 | [diff] [blame^] | 84 | |
| 85 | std::mt19937 mRandom; |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 86 | }; |
| 87 | |
f | 8c8e4c6 | 2021-03-05 05:12:58 +0000 | [diff] [blame] | 88 | } // namespace aidl::android::hardware::biometrics::fingerprint |