blob: ce6e7f1b888ddfacabe39b0165ca18f5a850cfa6 [file] [log] [blame]
Ilya Matyukhin09166982020-10-12 13:41:03 -07001/*
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 Matyukhin60406be2021-07-03 00:04:43 +000019#include <random>
20
Ilya Matyukhin09166982020-10-12 13:41:03 -070021#include <aidl/android/hardware/biometrics/face/BnSession.h>
Joshua McCloskey67310c32023-11-01 15:57:55 +000022#include <aidl/android/hardware/biometrics/face/FaceEnrollOptions.h>
Ilya Matyukhin09166982020-10-12 13:41:03 -070023#include <aidl/android/hardware/biometrics/face/ISessionCallback.h>
24
Joshua McCloskeydb009a52022-05-10 05:18:20 +000025#include "FakeFaceEngine.h"
26#include "thread/WorkerThread.h"
27#include "util/CancellationSignal.h"
28
Ilya Matyukhin09166982020-10-12 13:41:03 -070029namespace aidl::android::hardware::biometrics::face {
30
31namespace common = aidl::android::hardware::biometrics::common;
32namespace keymaster = aidl::android::hardware::keymaster;
33
34using aidl::android::hardware::common::NativeHandle;
35
36class Session : public BnSession {
37 public:
Joshua McCloskeydb009a52022-05-10 05:18:20 +000038 explicit Session(std::unique_ptr<FakeFaceEngine> engine, std::shared_ptr<ISessionCallback> cb);
Ilya Matyukhin09166982020-10-12 13:41:03 -070039
Ilya Matyukhin66c64642021-03-23 22:33:31 -070040 ndk::ScopedAStatus generateChallenge() override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070041
Ilya Matyukhin66c64642021-03-23 22:33:31 -070042 ndk::ScopedAStatus revokeChallenge(int64_t challenge) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070043
Ilya Matyukhin929146e2021-04-22 00:29:01 -070044 ndk::ScopedAStatus getEnrollmentConfig(EnrollmentType enrollmentType,
45 std::vector<EnrollmentStageConfig>* return_val) override;
46
Ilya Matyukhin66c64642021-03-23 22:33:31 -070047 ndk::ScopedAStatus enroll(const keymaster::HardwareAuthToken& hat,
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080048 EnrollmentType enrollmentType, const std::vector<Feature>& features,
Ilya Matyukhinbde61ca2021-07-21 19:01:07 -070049 const std::optional<NativeHandle>& previewSurface,
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080050 std::shared_ptr<common::ICancellationSignal>* return_val) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070051
52 ndk::ScopedAStatus authenticate(
Ilya Matyukhin66c64642021-03-23 22:33:31 -070053 int64_t keystoreOperationId,
Ilya Matyukhin09166982020-10-12 13:41:03 -070054 std::shared_ptr<common::ICancellationSignal>* returnVal) override;
55
56 ndk::ScopedAStatus detectInteraction(
Ilya Matyukhin66c64642021-03-23 22:33:31 -070057 std::shared_ptr<common::ICancellationSignal>* returnVal) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070058
Ilya Matyukhin66c64642021-03-23 22:33:31 -070059 ndk::ScopedAStatus enumerateEnrollments() override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070060
Ilya Matyukhin66c64642021-03-23 22:33:31 -070061 ndk::ScopedAStatus removeEnrollments(const std::vector<int32_t>& enrollmentIds) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070062
Ilya Matyukhin9fcf6b12021-04-14 13:43:06 -070063 ndk::ScopedAStatus getFeatures() override;
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080064
Ilya Matyukhin9fcf6b12021-04-14 13:43:06 -070065 ndk::ScopedAStatus setFeature(const keymaster::HardwareAuthToken& hat, Feature feature,
66 bool enabled) override;
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080067
Ilya Matyukhin66c64642021-03-23 22:33:31 -070068 ndk::ScopedAStatus getAuthenticatorId() override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070069
Ilya Matyukhin66c64642021-03-23 22:33:31 -070070 ndk::ScopedAStatus invalidateAuthenticatorId() override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070071
Ilya Matyukhin66c64642021-03-23 22:33:31 -070072 ndk::ScopedAStatus resetLockout(const keymaster::HardwareAuthToken& hat) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070073
Ilya Matyukhin66c64642021-03-23 22:33:31 -070074 ndk::ScopedAStatus close() override;
Ilya Matyukhine52cae02021-02-17 16:38:56 -080075
Joe Bolinger7bd42e12022-01-12 16:27:03 -080076 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 Bolinger25e98232022-01-24 18:56:23 +000090 ndk::ScopedAStatus onContextChanged(const common::OperationContext& context) override;
91
Joshua McCloskey67310c32023-11-01 15:57:55 +000092 ndk::ScopedAStatus enrollWithOptions(
93 const FaceEnrollOptions& options,
94 std::shared_ptr<common::ICancellationSignal>* out) override;
95
Ilya Matyukhin09166982020-10-12 13:41:03 -070096 private:
Joshua McCloskeydb009a52022-05-10 05:18:20 +000097 std::unique_ptr<FakeFaceEngine> mEngine;
98 std::shared_ptr<ISessionCallback> mCb;
Ilya Matyukhin60406be2021-07-03 00:04:43 +000099 std::mt19937 mRandom;
Joshua McCloskeydb009a52022-05-10 05:18:20 +0000100 std::unique_ptr<WorkerThread> mThread;
101 std::shared_ptr<CancellationSignal> mCancellationSignal;
Ilya Matyukhin09166982020-10-12 13:41:03 -0700102};
103
104} // namespace aidl::android::hardware::biometrics::face