blob: 7ca6a1f4ffffa464b5bf5366d2e21588b0763b2d [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>
22#include <aidl/android/hardware/biometrics/face/ISessionCallback.h>
23
Joshua McCloskeydb009a52022-05-10 05:18:20 +000024#include "FakeFaceEngine.h"
25#include "thread/WorkerThread.h"
26#include "util/CancellationSignal.h"
27
Ilya Matyukhin09166982020-10-12 13:41:03 -070028namespace aidl::android::hardware::biometrics::face {
29
30namespace common = aidl::android::hardware::biometrics::common;
31namespace keymaster = aidl::android::hardware::keymaster;
32
33using aidl::android::hardware::common::NativeHandle;
34
35class Session : public BnSession {
36 public:
Joshua McCloskeydb009a52022-05-10 05:18:20 +000037 explicit Session(std::unique_ptr<FakeFaceEngine> engine, std::shared_ptr<ISessionCallback> cb);
Ilya Matyukhin09166982020-10-12 13:41:03 -070038
Ilya Matyukhin66c64642021-03-23 22:33:31 -070039 ndk::ScopedAStatus generateChallenge() override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070040
Ilya Matyukhin66c64642021-03-23 22:33:31 -070041 ndk::ScopedAStatus revokeChallenge(int64_t challenge) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070042
Ilya Matyukhin929146e2021-04-22 00:29:01 -070043 ndk::ScopedAStatus getEnrollmentConfig(EnrollmentType enrollmentType,
44 std::vector<EnrollmentStageConfig>* return_val) override;
45
Ilya Matyukhin66c64642021-03-23 22:33:31 -070046 ndk::ScopedAStatus enroll(const keymaster::HardwareAuthToken& hat,
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080047 EnrollmentType enrollmentType, const std::vector<Feature>& features,
Ilya Matyukhinbde61ca2021-07-21 19:01:07 -070048 const std::optional<NativeHandle>& previewSurface,
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080049 std::shared_ptr<common::ICancellationSignal>* return_val) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070050
51 ndk::ScopedAStatus authenticate(
Ilya Matyukhin66c64642021-03-23 22:33:31 -070052 int64_t keystoreOperationId,
Ilya Matyukhin09166982020-10-12 13:41:03 -070053 std::shared_ptr<common::ICancellationSignal>* returnVal) override;
54
55 ndk::ScopedAStatus detectInteraction(
Ilya Matyukhin66c64642021-03-23 22:33:31 -070056 std::shared_ptr<common::ICancellationSignal>* returnVal) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070057
Ilya Matyukhin66c64642021-03-23 22:33:31 -070058 ndk::ScopedAStatus enumerateEnrollments() override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070059
Ilya Matyukhin66c64642021-03-23 22:33:31 -070060 ndk::ScopedAStatus removeEnrollments(const std::vector<int32_t>& enrollmentIds) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070061
Ilya Matyukhin9fcf6b12021-04-14 13:43:06 -070062 ndk::ScopedAStatus getFeatures() override;
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080063
Ilya Matyukhin9fcf6b12021-04-14 13:43:06 -070064 ndk::ScopedAStatus setFeature(const keymaster::HardwareAuthToken& hat, Feature feature,
65 bool enabled) override;
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080066
Ilya Matyukhin66c64642021-03-23 22:33:31 -070067 ndk::ScopedAStatus getAuthenticatorId() override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070068
Ilya Matyukhin66c64642021-03-23 22:33:31 -070069 ndk::ScopedAStatus invalidateAuthenticatorId() override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070070
Ilya Matyukhin66c64642021-03-23 22:33:31 -070071 ndk::ScopedAStatus resetLockout(const keymaster::HardwareAuthToken& hat) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070072
Ilya Matyukhin66c64642021-03-23 22:33:31 -070073 ndk::ScopedAStatus close() override;
Ilya Matyukhine52cae02021-02-17 16:38:56 -080074
Joe Bolinger7bd42e12022-01-12 16:27:03 -080075 ndk::ScopedAStatus authenticateWithContext(
76 int64_t operationId, const common::OperationContext& context,
77 std::shared_ptr<common::ICancellationSignal>* out) override;
78
79 ndk::ScopedAStatus enrollWithContext(
80 const keymaster::HardwareAuthToken& hat, EnrollmentType enrollmentType,
81 const std::vector<Feature>& features, const std::optional<NativeHandle>& previewSurface,
82 const common::OperationContext& context,
83 std::shared_ptr<common::ICancellationSignal>* out) override;
84
85 ndk::ScopedAStatus detectInteractionWithContext(
86 const common::OperationContext& context,
87 std::shared_ptr<common::ICancellationSignal>* out) override;
88
Joe Bolinger25e98232022-01-24 18:56:23 +000089 ndk::ScopedAStatus onContextChanged(const common::OperationContext& context) override;
90
Ilya Matyukhin09166982020-10-12 13:41:03 -070091 private:
Joshua McCloskeydb009a52022-05-10 05:18:20 +000092 std::unique_ptr<FakeFaceEngine> mEngine;
93 std::shared_ptr<ISessionCallback> mCb;
Ilya Matyukhin60406be2021-07-03 00:04:43 +000094 std::mt19937 mRandom;
Joshua McCloskeydb009a52022-05-10 05:18:20 +000095 std::unique_ptr<WorkerThread> mThread;
96 std::shared_ptr<CancellationSignal> mCancellationSignal;
Ilya Matyukhin09166982020-10-12 13:41:03 -070097};
98
99} // namespace aidl::android::hardware::biometrics::face