Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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 | |
Ilya Matyukhin | 60406be | 2021-07-03 00:04:43 +0000 | [diff] [blame] | 19 | #include <random> |
| 20 | |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 21 | #include <aidl/android/hardware/biometrics/face/BnSession.h> |
Joshua McCloskey | 67310c3 | 2023-11-01 15:57:55 +0000 | [diff] [blame^] | 22 | #include <aidl/android/hardware/biometrics/face/FaceEnrollOptions.h> |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 23 | #include <aidl/android/hardware/biometrics/face/ISessionCallback.h> |
| 24 | |
Joshua McCloskey | db009a5 | 2022-05-10 05:18:20 +0000 | [diff] [blame] | 25 | #include "FakeFaceEngine.h" |
| 26 | #include "thread/WorkerThread.h" |
| 27 | #include "util/CancellationSignal.h" |
| 28 | |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 29 | namespace aidl::android::hardware::biometrics::face { |
| 30 | |
| 31 | namespace common = aidl::android::hardware::biometrics::common; |
| 32 | namespace keymaster = aidl::android::hardware::keymaster; |
| 33 | |
| 34 | using aidl::android::hardware::common::NativeHandle; |
| 35 | |
| 36 | class Session : public BnSession { |
| 37 | public: |
Joshua McCloskey | db009a5 | 2022-05-10 05:18:20 +0000 | [diff] [blame] | 38 | explicit Session(std::unique_ptr<FakeFaceEngine> engine, std::shared_ptr<ISessionCallback> cb); |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 39 | |
Ilya Matyukhin | 66c6464 | 2021-03-23 22:33:31 -0700 | [diff] [blame] | 40 | ndk::ScopedAStatus generateChallenge() override; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 41 | |
Ilya Matyukhin | 66c6464 | 2021-03-23 22:33:31 -0700 | [diff] [blame] | 42 | ndk::ScopedAStatus revokeChallenge(int64_t challenge) override; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 43 | |
Ilya Matyukhin | 929146e | 2021-04-22 00:29:01 -0700 | [diff] [blame] | 44 | ndk::ScopedAStatus getEnrollmentConfig(EnrollmentType enrollmentType, |
| 45 | std::vector<EnrollmentStageConfig>* return_val) override; |
| 46 | |
Ilya Matyukhin | 66c6464 | 2021-03-23 22:33:31 -0700 | [diff] [blame] | 47 | ndk::ScopedAStatus enroll(const keymaster::HardwareAuthToken& hat, |
Ilya Matyukhin | 26b20b9 | 2021-01-22 11:39:49 -0800 | [diff] [blame] | 48 | EnrollmentType enrollmentType, const std::vector<Feature>& features, |
Ilya Matyukhin | bde61ca | 2021-07-21 19:01:07 -0700 | [diff] [blame] | 49 | const std::optional<NativeHandle>& previewSurface, |
Ilya Matyukhin | 26b20b9 | 2021-01-22 11:39:49 -0800 | [diff] [blame] | 50 | std::shared_ptr<common::ICancellationSignal>* return_val) override; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 51 | |
| 52 | ndk::ScopedAStatus authenticate( |
Ilya Matyukhin | 66c6464 | 2021-03-23 22:33:31 -0700 | [diff] [blame] | 53 | int64_t keystoreOperationId, |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 54 | std::shared_ptr<common::ICancellationSignal>* returnVal) override; |
| 55 | |
| 56 | ndk::ScopedAStatus detectInteraction( |
Ilya Matyukhin | 66c6464 | 2021-03-23 22:33:31 -0700 | [diff] [blame] | 57 | std::shared_ptr<common::ICancellationSignal>* returnVal) override; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 58 | |
Ilya Matyukhin | 66c6464 | 2021-03-23 22:33:31 -0700 | [diff] [blame] | 59 | ndk::ScopedAStatus enumerateEnrollments() override; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 60 | |
Ilya Matyukhin | 66c6464 | 2021-03-23 22:33:31 -0700 | [diff] [blame] | 61 | ndk::ScopedAStatus removeEnrollments(const std::vector<int32_t>& enrollmentIds) override; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 62 | |
Ilya Matyukhin | 9fcf6b1 | 2021-04-14 13:43:06 -0700 | [diff] [blame] | 63 | ndk::ScopedAStatus getFeatures() override; |
Ilya Matyukhin | 26b20b9 | 2021-01-22 11:39:49 -0800 | [diff] [blame] | 64 | |
Ilya Matyukhin | 9fcf6b1 | 2021-04-14 13:43:06 -0700 | [diff] [blame] | 65 | ndk::ScopedAStatus setFeature(const keymaster::HardwareAuthToken& hat, Feature feature, |
| 66 | bool enabled) override; |
Ilya Matyukhin | 26b20b9 | 2021-01-22 11:39:49 -0800 | [diff] [blame] | 67 | |
Ilya Matyukhin | 66c6464 | 2021-03-23 22:33:31 -0700 | [diff] [blame] | 68 | ndk::ScopedAStatus getAuthenticatorId() override; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 69 | |
Ilya Matyukhin | 66c6464 | 2021-03-23 22:33:31 -0700 | [diff] [blame] | 70 | ndk::ScopedAStatus invalidateAuthenticatorId() override; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 71 | |
Ilya Matyukhin | 66c6464 | 2021-03-23 22:33:31 -0700 | [diff] [blame] | 72 | ndk::ScopedAStatus resetLockout(const keymaster::HardwareAuthToken& hat) override; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 73 | |
Ilya Matyukhin | 66c6464 | 2021-03-23 22:33:31 -0700 | [diff] [blame] | 74 | ndk::ScopedAStatus close() override; |
Ilya Matyukhin | e52cae0 | 2021-02-17 16:38:56 -0800 | [diff] [blame] | 75 | |
Joe Bolinger | 7bd42e1 | 2022-01-12 16:27:03 -0800 | [diff] [blame] | 76 | ndk::ScopedAStatus authenticateWithContext( |
| 77 | int64_t operationId, const common::OperationContext& context, |
| 78 | std::shared_ptr<common::ICancellationSignal>* out) override; |
| 79 | |
| 80 | ndk::ScopedAStatus enrollWithContext( |
| 81 | const keymaster::HardwareAuthToken& hat, EnrollmentType enrollmentType, |
| 82 | const std::vector<Feature>& features, const std::optional<NativeHandle>& previewSurface, |
| 83 | const common::OperationContext& context, |
| 84 | std::shared_ptr<common::ICancellationSignal>* out) override; |
| 85 | |
| 86 | ndk::ScopedAStatus detectInteractionWithContext( |
| 87 | const common::OperationContext& context, |
| 88 | std::shared_ptr<common::ICancellationSignal>* out) override; |
| 89 | |
Joe Bolinger | 25e9823 | 2022-01-24 18:56:23 +0000 | [diff] [blame] | 90 | ndk::ScopedAStatus onContextChanged(const common::OperationContext& context) override; |
| 91 | |
Joshua McCloskey | 67310c3 | 2023-11-01 15:57:55 +0000 | [diff] [blame^] | 92 | ndk::ScopedAStatus enrollWithOptions( |
| 93 | const FaceEnrollOptions& options, |
| 94 | std::shared_ptr<common::ICancellationSignal>* out) override; |
| 95 | |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 96 | private: |
Joshua McCloskey | db009a5 | 2022-05-10 05:18:20 +0000 | [diff] [blame] | 97 | std::unique_ptr<FakeFaceEngine> mEngine; |
| 98 | std::shared_ptr<ISessionCallback> mCb; |
Ilya Matyukhin | 60406be | 2021-07-03 00:04:43 +0000 | [diff] [blame] | 99 | std::mt19937 mRandom; |
Joshua McCloskey | db009a5 | 2022-05-10 05:18:20 +0000 | [diff] [blame] | 100 | std::unique_ptr<WorkerThread> mThread; |
| 101 | std::shared_ptr<CancellationSignal> mCancellationSignal; |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | } // namespace aidl::android::hardware::biometrics::face |