Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 1 | /* |
Jeff Pu | 5265318 | 2022-10-12 16:27:23 -0400 | [diff] [blame] | 2 | * Copyright (C) 2022 The Android Open Source Project |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 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 |
Jeff Pu | 5265318 | 2022-10-12 16:27:23 -0400 | [diff] [blame] | 18 | |
| 19 | #define LOG_TAG "FingerprintVirtualHal" |
| 20 | |
Joshua McCloskey | c8c0bad | 2022-05-10 05:17:44 +0000 | [diff] [blame] | 21 | #include <aidl/android/hardware/biometrics/common/SensorStrength.h> |
Joe Bolinger | de94aa0 | 2021-12-09 17:00:32 -0800 | [diff] [blame] | 22 | #include <aidl/android/hardware/biometrics/fingerprint/ISessionCallback.h> |
Jeff Pu | 5265318 | 2022-10-12 16:27:23 -0400 | [diff] [blame] | 23 | #include <android/binder_to_string.h> |
| 24 | #include <string> |
Joe Bolinger | de94aa0 | 2021-12-09 17:00:32 -0800 | [diff] [blame] | 25 | |
Ilya Matyukhin | 1d52438 | 2021-07-02 20:33:51 +0000 | [diff] [blame] | 26 | #include <random> |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 27 | |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 28 | #include <aidl/android/hardware/biometrics/fingerprint/SensorLocation.h> |
Joshua McCloskey | c8c0bad | 2022-05-10 05:17:44 +0000 | [diff] [blame] | 29 | #include <future> |
| 30 | #include <vector> |
Joe Bolinger | de94aa0 | 2021-12-09 17:00:32 -0800 | [diff] [blame] | 31 | |
Jeff Pu | 5265318 | 2022-10-12 16:27:23 -0400 | [diff] [blame] | 32 | #include "FakeLockoutTracker.h" |
| 33 | |
Joe Bolinger | de94aa0 | 2021-12-09 17:00:32 -0800 | [diff] [blame] | 34 | using namespace ::aidl::android::hardware::biometrics::common; |
| 35 | |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 36 | namespace aidl::android::hardware::biometrics::fingerprint { |
| 37 | |
Joe Bolinger | de94aa0 | 2021-12-09 17:00:32 -0800 | [diff] [blame] | 38 | // A fake engine that is backed by system properties instead of hardware. |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 39 | class FakeFingerprintEngine { |
| 40 | public: |
Ilya Matyukhin | 1d52438 | 2021-07-02 20:33:51 +0000 | [diff] [blame] | 41 | FakeFingerprintEngine() : mRandom(std::mt19937::default_seed) {} |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 42 | virtual ~FakeFingerprintEngine() {} |
Ilya Matyukhin | 1d52438 | 2021-07-02 20:33:51 +0000 | [diff] [blame] | 43 | |
Joe Bolinger | de94aa0 | 2021-12-09 17:00:32 -0800 | [diff] [blame] | 44 | void generateChallengeImpl(ISessionCallback* cb); |
| 45 | void revokeChallengeImpl(ISessionCallback* cb, int64_t challenge); |
Jeff Pu | 5265318 | 2022-10-12 16:27:23 -0400 | [diff] [blame] | 46 | virtual void enrollImpl(ISessionCallback* cb, const keymaster::HardwareAuthToken& hat, |
| 47 | const std::future<void>& cancel); |
| 48 | virtual void authenticateImpl(ISessionCallback* cb, int64_t operationId, |
| 49 | const std::future<void>& cancel); |
| 50 | virtual void detectInteractionImpl(ISessionCallback* cb, const std::future<void>& cancel); |
Joe Bolinger | de94aa0 | 2021-12-09 17:00:32 -0800 | [diff] [blame] | 51 | void enumerateEnrollmentsImpl(ISessionCallback* cb); |
| 52 | void removeEnrollmentsImpl(ISessionCallback* cb, const std::vector<int32_t>& enrollmentIds); |
| 53 | void getAuthenticatorIdImpl(ISessionCallback* cb); |
| 54 | void invalidateAuthenticatorIdImpl(ISessionCallback* cb); |
| 55 | void resetLockoutImpl(ISessionCallback* cb, const keymaster::HardwareAuthToken& /*hat*/); |
Jeff Pu | 63f33c7 | 2022-07-28 16:06:23 -0400 | [diff] [blame] | 56 | bool getSensorLocationConfig(SensorLocation& out); |
| 57 | |
| 58 | virtual ndk::ScopedAStatus onPointerDownImpl(int32_t pointerId, int32_t x, int32_t y, |
| 59 | float minor, float major); |
| 60 | |
| 61 | virtual ndk::ScopedAStatus onPointerUpImpl(int32_t pointerId); |
| 62 | |
| 63 | virtual ndk::ScopedAStatus onUiReadyImpl(); |
| 64 | |
| 65 | virtual SensorLocation getSensorLocation(); |
| 66 | |
| 67 | virtual SensorLocation defaultSensorLocation(); |
Ilya Matyukhin | 1d52438 | 2021-07-02 20:33:51 +0000 | [diff] [blame] | 68 | |
Jeff Pu | 343ca94 | 2022-09-14 15:56:30 -0400 | [diff] [blame] | 69 | std::vector<int32_t> parseIntSequence(const std::string& str, const std::string& sep = ","); |
| 70 | |
| 71 | std::vector<std::vector<int32_t>> parseEnrollmentCapture(const std::string& str); |
| 72 | |
Jeff Pu | 5265318 | 2022-10-12 16:27:23 -0400 | [diff] [blame] | 73 | int32_t getLatency(const std::vector<std::optional<std::int32_t>>& latencyVec); |
| 74 | |
Ilya Matyukhin | 1d52438 | 2021-07-02 20:33:51 +0000 | [diff] [blame] | 75 | std::mt19937 mRandom; |
Jeff Pu | 343ca94 | 2022-09-14 15:56:30 -0400 | [diff] [blame] | 76 | |
Jeff Pu | 5265318 | 2022-10-12 16:27:23 -0400 | [diff] [blame] | 77 | virtual std::string toString() const { |
| 78 | std::ostringstream os; |
| 79 | os << "----- FakeFingerprintEngine:: -----" << std::endl; |
| 80 | os << "acquiredVendorInfoBase:" << FINGERPRINT_ACQUIRED_VENDOR_BASE; |
| 81 | os << ", errorVendorBase:" << FINGERPRINT_ERROR_VENDOR_BASE << std::endl; |
| 82 | os << mLockoutTracker.toString(); |
| 83 | return os.str(); |
| 84 | } |
| 85 | |
Jeff Pu | 343ca94 | 2022-09-14 15:56:30 -0400 | [diff] [blame] | 86 | private: |
| 87 | static constexpr int32_t FINGERPRINT_ACQUIRED_VENDOR_BASE = 1000; |
| 88 | static constexpr int32_t FINGERPRINT_ERROR_VENDOR_BASE = 1000; |
| 89 | std::pair<AcquiredInfo, int32_t> convertAcquiredInfo(int32_t code); |
| 90 | std::pair<Error, int32_t> convertError(int32_t code); |
Jeff Pu | 5265318 | 2022-10-12 16:27:23 -0400 | [diff] [blame] | 91 | bool parseEnrollmentCaptureSingle(const std::string& str, |
| 92 | std::vector<std::vector<int32_t>>& res); |
| 93 | int32_t getRandomInRange(int32_t bound1, int32_t bound2); |
| 94 | |
| 95 | FakeLockoutTracker mLockoutTracker; |
Ilya Matyukhin | 48ff896 | 2021-02-22 13:13:13 -0800 | [diff] [blame] | 96 | }; |
| 97 | |
f | 8c8e4c6 | 2021-03-05 05:12:58 +0000 | [diff] [blame] | 98 | } // namespace aidl::android::hardware::biometrics::fingerprint |