blob: 984a1a99dc0fd1e7667c7c64d303197c95b90834 [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#include <aidl/android/hardware/biometrics/common/BnCancellationSignal.h>
Kevin Chyn146f6c82021-02-10 11:32:35 -080018#include <android-base/logging.h>
Ilya Matyukhin09166982020-10-12 13:41:03 -070019
20#include "Session.h"
21
22namespace aidl::android::hardware::biometrics::face {
23
24class CancellationSignal : public common::BnCancellationSignal {
Kevin Chyncfb54992020-11-17 13:06:23 -080025 private:
26 std::shared_ptr<ISessionCallback> cb_;
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -080027
Ilya Matyukhin09166982020-10-12 13:41:03 -070028 public:
Kevin Chyncfb54992020-11-17 13:06:23 -080029 explicit CancellationSignal(std::shared_ptr<ISessionCallback> cb) : cb_(std::move(cb)) {}
30
31 ndk::ScopedAStatus cancel() override {
32 cb_->onError(Error::CANCELED, 0 /* vendorCode */);
Kevin Chyncfb54992020-11-17 13:06:23 -080033 return ndk::ScopedAStatus::ok();
34 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070035};
36
Ilya Matyukhin60406be2021-07-03 00:04:43 +000037Session::Session(std::shared_ptr<ISessionCallback> cb)
38 : cb_(std::move(cb)), mRandom(std::mt19937::default_seed) {}
Ilya Matyukhin09166982020-10-12 13:41:03 -070039
Ilya Matyukhin66c64642021-03-23 22:33:31 -070040ndk::ScopedAStatus Session::generateChallenge() {
Kevin Chyn146f6c82021-02-10 11:32:35 -080041 LOG(INFO) << "generateChallenge";
Kevin Chyncfb54992020-11-17 13:06:23 -080042 if (cb_) {
Ilya Matyukhin60406be2021-07-03 00:04:43 +000043 std::uniform_int_distribution<int64_t> dist;
44 auto challenge = dist(mRandom);
45 cb_->onChallengeGenerated(challenge);
Kevin Chyncfb54992020-11-17 13:06:23 -080046 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070047 return ndk::ScopedAStatus::ok();
48}
49
Ilya Matyukhin66c64642021-03-23 22:33:31 -070050ndk::ScopedAStatus Session::revokeChallenge(int64_t challenge) {
Kevin Chyn146f6c82021-02-10 11:32:35 -080051 LOG(INFO) << "revokeChallenge";
Kevin Chyncfb54992020-11-17 13:06:23 -080052 if (cb_) {
Kevin Chyncfb54992020-11-17 13:06:23 -080053 cb_->onChallengeRevoked(challenge);
Kevin Chyncfb54992020-11-17 13:06:23 -080054 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070055 return ndk::ScopedAStatus::ok();
56}
57
Ilya Matyukhin929146e2021-04-22 00:29:01 -070058ndk::ScopedAStatus Session::getEnrollmentConfig(EnrollmentType /*enrollmentType*/,
59 std::vector<EnrollmentStageConfig>* return_val) {
60 *return_val = {};
61 return ndk::ScopedAStatus::ok();
62}
63
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -080064ndk::ScopedAStatus Session::enroll(
Ilya Matyukhin66c64642021-03-23 22:33:31 -070065 const keymaster::HardwareAuthToken& /*hat*/, EnrollmentType /*enrollmentType*/,
Ilya Matyukhinbde61ca2021-07-21 19:01:07 -070066 const std::vector<Feature>& /*features*/,
67 const std::optional<NativeHandle>& /*previewSurface*/,
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -080068 std::shared_ptr<biometrics::common::ICancellationSignal>* /*return_val*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -080069 LOG(INFO) << "enroll";
Ilya Matyukhin60406be2021-07-03 00:04:43 +000070 if (cb_) {
71 cb_->onError(Error::UNABLE_TO_PROCESS, 0 /* vendorError */);
72 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070073 return ndk::ScopedAStatus::ok();
74}
75
Ilya Matyukhin66c64642021-03-23 22:33:31 -070076ndk::ScopedAStatus Session::authenticate(int64_t /*keystoreOperationId*/,
Ilya Matyukhin09166982020-10-12 13:41:03 -070077 std::shared_ptr<common::ICancellationSignal>* return_val) {
Kevin Chyn146f6c82021-02-10 11:32:35 -080078 LOG(INFO) << "authenticate";
Ilya Matyukhin09166982020-10-12 13:41:03 -070079 if (cb_) {
Ilya Matyukhin66c64642021-03-23 22:33:31 -070080 cb_->onError(Error::UNABLE_TO_PROCESS, 0 /* vendorCode */);
Ilya Matyukhin09166982020-10-12 13:41:03 -070081 }
Kevin Chyncfb54992020-11-17 13:06:23 -080082 *return_val = SharedRefBase::make<CancellationSignal>(cb_);
Ilya Matyukhin09166982020-10-12 13:41:03 -070083 return ndk::ScopedAStatus::ok();
84}
85
86ndk::ScopedAStatus Session::detectInteraction(
Ilya Matyukhin66c64642021-03-23 22:33:31 -070087 std::shared_ptr<common::ICancellationSignal>* /*return_val*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -080088 LOG(INFO) << "detectInteraction";
Ilya Matyukhin09166982020-10-12 13:41:03 -070089 return ndk::ScopedAStatus::ok();
90}
91
Ilya Matyukhin66c64642021-03-23 22:33:31 -070092ndk::ScopedAStatus Session::enumerateEnrollments() {
Kevin Chyn146f6c82021-02-10 11:32:35 -080093 LOG(INFO) << "enumerateEnrollments";
Kevin Chyncfb54992020-11-17 13:06:23 -080094 if (cb_) {
Kevin Chyncfb54992020-11-17 13:06:23 -080095 cb_->onEnrollmentsEnumerated(std::vector<int32_t>());
Kevin Chyncfb54992020-11-17 13:06:23 -080096 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070097 return ndk::ScopedAStatus::ok();
98}
99
Ilya Matyukhin66c64642021-03-23 22:33:31 -0700100ndk::ScopedAStatus Session::removeEnrollments(const std::vector<int32_t>& /*enrollmentIds*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -0800101 LOG(INFO) << "removeEnrollments";
Kevin Chyncfb54992020-11-17 13:06:23 -0800102 if (cb_) {
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -0800103 cb_->onEnrollmentsRemoved(std::vector<int32_t>());
Kevin Chyncfb54992020-11-17 13:06:23 -0800104 }
Ilya Matyukhin09166982020-10-12 13:41:03 -0700105 return ndk::ScopedAStatus::ok();
106}
107
Ilya Matyukhin9fcf6b12021-04-14 13:43:06 -0700108ndk::ScopedAStatus Session::getFeatures() {
Kevin Chyn146f6c82021-02-10 11:32:35 -0800109 LOG(INFO) << "getFeatures";
Ilya Matyukhin60406be2021-07-03 00:04:43 +0000110 if (cb_) {
Ilya Matyukhin9208a092021-07-21 23:13:12 +0000111 // Must error out with UNABLE_TO_PROCESS when no faces are enrolled.
112 cb_->onError(Error::UNABLE_TO_PROCESS, 0 /* vendorCode */);
Ilya Matyukhin60406be2021-07-03 00:04:43 +0000113 }
Ilya Matyukhin26b20b92021-01-22 11:39:49 -0800114 return ndk::ScopedAStatus::ok();
115}
116
Ilya Matyukhin66c64642021-03-23 22:33:31 -0700117ndk::ScopedAStatus Session::setFeature(const keymaster::HardwareAuthToken& /*hat*/,
Ilya Matyukhin9fcf6b12021-04-14 13:43:06 -0700118 Feature /*feature*/, bool /*enabled*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -0800119 LOG(INFO) << "setFeature";
Ilya Matyukhin26b20b92021-01-22 11:39:49 -0800120 return ndk::ScopedAStatus::ok();
121}
122
Ilya Matyukhin66c64642021-03-23 22:33:31 -0700123ndk::ScopedAStatus Session::getAuthenticatorId() {
Kevin Chyn146f6c82021-02-10 11:32:35 -0800124 LOG(INFO) << "getAuthenticatorId";
Kevin Chyncfb54992020-11-17 13:06:23 -0800125 if (cb_) {
Kevin Chyncfb54992020-11-17 13:06:23 -0800126 cb_->onAuthenticatorIdRetrieved(0 /* authenticatorId */);
Kevin Chyncfb54992020-11-17 13:06:23 -0800127 }
Ilya Matyukhin09166982020-10-12 13:41:03 -0700128 return ndk::ScopedAStatus::ok();
129}
130
Ilya Matyukhin66c64642021-03-23 22:33:31 -0700131ndk::ScopedAStatus Session::invalidateAuthenticatorId() {
Kevin Chyn146f6c82021-02-10 11:32:35 -0800132 LOG(INFO) << "invalidateAuthenticatorId";
Ilya Matyukhin60406be2021-07-03 00:04:43 +0000133 if (cb_) {
134 cb_->onAuthenticatorIdInvalidated(0);
135 }
Ilya Matyukhin09166982020-10-12 13:41:03 -0700136 return ndk::ScopedAStatus::ok();
137}
138
Ilya Matyukhin66c64642021-03-23 22:33:31 -0700139ndk::ScopedAStatus Session::resetLockout(const keymaster::HardwareAuthToken& /*hat*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -0800140 LOG(INFO) << "resetLockout";
Kevin Chyncfb54992020-11-17 13:06:23 -0800141 if (cb_) {
Kevin Chyncfb54992020-11-17 13:06:23 -0800142 cb_->onLockoutCleared();
Kevin Chyncfb54992020-11-17 13:06:23 -0800143 }
Ilya Matyukhin09166982020-10-12 13:41:03 -0700144 return ndk::ScopedAStatus::ok();
145}
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -0800146
Ilya Matyukhin66c64642021-03-23 22:33:31 -0700147ndk::ScopedAStatus Session::close() {
148 if (cb_) {
149 cb_->onSessionClosed();
150 }
Ilya Matyukhine52cae02021-02-17 16:38:56 -0800151 return ndk::ScopedAStatus::ok();
152}
153
Joe Bolinger7bd42e12022-01-12 16:27:03 -0800154ndk::ScopedAStatus Session::authenticateWithContext(
155 int64_t operationId, const common::OperationContext& /*context*/,
156 std::shared_ptr<common::ICancellationSignal>* out) {
157 return authenticate(operationId, out);
158}
159
160ndk::ScopedAStatus Session::enrollWithContext(const keymaster::HardwareAuthToken& hat,
161 EnrollmentType enrollmentType,
162 const std::vector<Feature>& features,
163 const std::optional<NativeHandle>& previewSurface,
164 const common::OperationContext& /*context*/,
165 std::shared_ptr<common::ICancellationSignal>* out) {
166 return enroll(hat, enrollmentType, features, previewSurface, out);
167}
168
169ndk::ScopedAStatus Session::detectInteractionWithContext(
170 const common::OperationContext& /*context*/,
171 std::shared_ptr<common::ICancellationSignal>* out) {
172 return detectInteraction(out);
173}
174
Joe Bolinger25e98232022-01-24 18:56:23 +0000175ndk::ScopedAStatus Session::onContextChanged(const common::OperationContext& /*context*/) {
176 return ndk::ScopedAStatus::ok();
177}
178
Ilya Matyukhin09166982020-10-12 13:41:03 -0700179} // namespace aidl::android::hardware::biometrics::face