blob: f79ad00ab63491750aa81bcf2f6461cb42c87286 [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
Jeff Pu1e93ca62024-01-24 10:51:31 -050036enum class SessionState {
37 IDLING,
38 CLOSED,
39};
40
Ilya Matyukhin09166982020-10-12 13:41:03 -070041class Session : public BnSession {
42 public:
Joshua McCloskeydb009a52022-05-10 05:18:20 +000043 explicit Session(std::unique_ptr<FakeFaceEngine> engine, std::shared_ptr<ISessionCallback> cb);
Ilya Matyukhin09166982020-10-12 13:41:03 -070044
Ilya Matyukhin66c64642021-03-23 22:33:31 -070045 ndk::ScopedAStatus generateChallenge() override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070046
Ilya Matyukhin66c64642021-03-23 22:33:31 -070047 ndk::ScopedAStatus revokeChallenge(int64_t challenge) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070048
Ilya Matyukhin929146e2021-04-22 00:29:01 -070049 ndk::ScopedAStatus getEnrollmentConfig(EnrollmentType enrollmentType,
50 std::vector<EnrollmentStageConfig>* return_val) override;
51
Ilya Matyukhin66c64642021-03-23 22:33:31 -070052 ndk::ScopedAStatus enroll(const keymaster::HardwareAuthToken& hat,
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080053 EnrollmentType enrollmentType, const std::vector<Feature>& features,
Ilya Matyukhinbde61ca2021-07-21 19:01:07 -070054 const std::optional<NativeHandle>& previewSurface,
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080055 std::shared_ptr<common::ICancellationSignal>* return_val) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070056
57 ndk::ScopedAStatus authenticate(
Ilya Matyukhin66c64642021-03-23 22:33:31 -070058 int64_t keystoreOperationId,
Ilya Matyukhin09166982020-10-12 13:41:03 -070059 std::shared_ptr<common::ICancellationSignal>* returnVal) override;
60
61 ndk::ScopedAStatus detectInteraction(
Ilya Matyukhin66c64642021-03-23 22:33:31 -070062 std::shared_ptr<common::ICancellationSignal>* returnVal) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070063
Ilya Matyukhin66c64642021-03-23 22:33:31 -070064 ndk::ScopedAStatus enumerateEnrollments() override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070065
Ilya Matyukhin66c64642021-03-23 22:33:31 -070066 ndk::ScopedAStatus removeEnrollments(const std::vector<int32_t>& enrollmentIds) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070067
Ilya Matyukhin9fcf6b12021-04-14 13:43:06 -070068 ndk::ScopedAStatus getFeatures() override;
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080069
Ilya Matyukhin9fcf6b12021-04-14 13:43:06 -070070 ndk::ScopedAStatus setFeature(const keymaster::HardwareAuthToken& hat, Feature feature,
71 bool enabled) override;
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080072
Ilya Matyukhin66c64642021-03-23 22:33:31 -070073 ndk::ScopedAStatus getAuthenticatorId() override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070074
Ilya Matyukhin66c64642021-03-23 22:33:31 -070075 ndk::ScopedAStatus invalidateAuthenticatorId() override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070076
Ilya Matyukhin66c64642021-03-23 22:33:31 -070077 ndk::ScopedAStatus resetLockout(const keymaster::HardwareAuthToken& hat) override;
Ilya Matyukhin09166982020-10-12 13:41:03 -070078
Ilya Matyukhin66c64642021-03-23 22:33:31 -070079 ndk::ScopedAStatus close() override;
Ilya Matyukhine52cae02021-02-17 16:38:56 -080080
Joe Bolinger7bd42e12022-01-12 16:27:03 -080081 ndk::ScopedAStatus authenticateWithContext(
82 int64_t operationId, const common::OperationContext& context,
83 std::shared_ptr<common::ICancellationSignal>* out) override;
84
85 ndk::ScopedAStatus enrollWithContext(
86 const keymaster::HardwareAuthToken& hat, EnrollmentType enrollmentType,
87 const std::vector<Feature>& features, const std::optional<NativeHandle>& previewSurface,
88 const common::OperationContext& context,
89 std::shared_ptr<common::ICancellationSignal>* out) override;
90
91 ndk::ScopedAStatus detectInteractionWithContext(
92 const common::OperationContext& context,
93 std::shared_ptr<common::ICancellationSignal>* out) override;
94
Joe Bolinger25e98232022-01-24 18:56:23 +000095 ndk::ScopedAStatus onContextChanged(const common::OperationContext& context) override;
96
Joshua McCloskey67310c32023-11-01 15:57:55 +000097 ndk::ScopedAStatus enrollWithOptions(
98 const FaceEnrollOptions& options,
99 std::shared_ptr<common::ICancellationSignal>* out) override;
100
Jeff Pu1e93ca62024-01-24 10:51:31 -0500101 binder_status_t linkToDeath(AIBinder* binder);
102
103 virtual std::string toString() const {
104 std::ostringstream os;
105 os << std::endl << "----- Face::Session:: -----" << std::endl;
106 os << "mStateClosed:" << mStateClosed << std::endl;
107 os << mEngine->toString();
108
109 return os.str();
110 }
111
112 bool isClosed() { return mStateClosed; }
113
Ilya Matyukhin09166982020-10-12 13:41:03 -0700114 private:
Joshua McCloskeydb009a52022-05-10 05:18:20 +0000115 std::unique_ptr<FakeFaceEngine> mEngine;
116 std::shared_ptr<ISessionCallback> mCb;
Ilya Matyukhin60406be2021-07-03 00:04:43 +0000117 std::mt19937 mRandom;
Joshua McCloskeydb009a52022-05-10 05:18:20 +0000118 std::unique_ptr<WorkerThread> mThread;
Jeff Pu1e93ca62024-01-24 10:51:31 -0500119
120 // Binder death handler.
121 AIBinder_DeathRecipient* mDeathRecipient;
122 bool mStateClosed;
Ilya Matyukhin09166982020-10-12 13:41:03 -0700123};
124
125} // namespace aidl::android::hardware::biometrics::face