blob: a7130e62d08f79abaa2323aa6b0de878b2b0ccef [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 */);
33 cb_->onStateChanged(0, SessionState::IDLING);
34 return ndk::ScopedAStatus::ok();
35 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070036};
37
38Session::Session(std::shared_ptr<ISessionCallback> cb) : cb_(std::move(cb)) {}
39
Ilya Matyukhine5034812020-10-15 21:45:56 -070040ndk::ScopedAStatus Session::generateChallenge(int32_t /*cookie*/, int32_t /*timeoutSec*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -080041 LOG(INFO) << "generateChallenge";
Kevin Chyncfb54992020-11-17 13:06:23 -080042 if (cb_) {
43 cb_->onStateChanged(0, SessionState::GENERATING_CHALLENGE);
44 cb_->onChallengeGenerated(0);
45 cb_->onStateChanged(0, SessionState::IDLING);
46 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070047 return ndk::ScopedAStatus::ok();
48}
49
Kevin Chyncfb54992020-11-17 13:06:23 -080050ndk::ScopedAStatus Session::revokeChallenge(int32_t /*cookie*/, int64_t challenge) {
Kevin Chyn146f6c82021-02-10 11:32:35 -080051 LOG(INFO) << "revokeChallenge";
Kevin Chyncfb54992020-11-17 13:06:23 -080052 if (cb_) {
53 cb_->onStateChanged(0, SessionState::REVOKING_CHALLENGE);
54 cb_->onChallengeRevoked(challenge);
55 cb_->onStateChanged(0, SessionState::IDLING);
56 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070057 return ndk::ScopedAStatus::ok();
58}
59
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -080060ndk::ScopedAStatus Session::enroll(
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080061 int32_t /*cookie*/, const keymaster::HardwareAuthToken& /*hat*/,
62 EnrollmentType /*enrollmentType*/, const std::vector<Feature>& /*features*/,
63 const NativeHandle& /*previewSurface*/,
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -080064 std::shared_ptr<biometrics::common::ICancellationSignal>* /*return_val*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -080065 LOG(INFO) << "enroll";
Ilya Matyukhin09166982020-10-12 13:41:03 -070066 return ndk::ScopedAStatus::ok();
67}
68
69ndk::ScopedAStatus Session::authenticate(int32_t /*cookie*/, int64_t /*keystoreOperationId*/,
70 std::shared_ptr<common::ICancellationSignal>* return_val) {
Kevin Chyn146f6c82021-02-10 11:32:35 -080071 LOG(INFO) << "authenticate";
Ilya Matyukhin09166982020-10-12 13:41:03 -070072 if (cb_) {
73 cb_->onStateChanged(0, SessionState::AUTHENTICATING);
74 }
Kevin Chyncfb54992020-11-17 13:06:23 -080075 *return_val = SharedRefBase::make<CancellationSignal>(cb_);
Ilya Matyukhin09166982020-10-12 13:41:03 -070076 return ndk::ScopedAStatus::ok();
77}
78
79ndk::ScopedAStatus Session::detectInteraction(
80 int32_t /*cookie*/, std::shared_ptr<common::ICancellationSignal>* /*return_val*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -080081 LOG(INFO) << "detectInteraction";
Ilya Matyukhin09166982020-10-12 13:41:03 -070082 return ndk::ScopedAStatus::ok();
83}
84
85ndk::ScopedAStatus Session::enumerateEnrollments(int32_t /*cookie*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -080086 LOG(INFO) << "enumerateEnrollments";
Kevin Chyncfb54992020-11-17 13:06:23 -080087 if (cb_) {
88 cb_->onStateChanged(0, SessionState::ENUMERATING_ENROLLMENTS);
89 cb_->onEnrollmentsEnumerated(std::vector<int32_t>());
90 cb_->onStateChanged(0, SessionState::IDLING);
91 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070092 return ndk::ScopedAStatus::ok();
93}
94
95ndk::ScopedAStatus Session::removeEnrollments(int32_t /*cookie*/,
96 const std::vector<int32_t>& /*enrollmentIds*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -080097 LOG(INFO) << "removeEnrollments";
Kevin Chyncfb54992020-11-17 13:06:23 -080098 if (cb_) {
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -080099 cb_->onStateChanged(0, SessionState::REMOVING_ENROLLMENTS);
100 cb_->onEnrollmentsRemoved(std::vector<int32_t>());
101 cb_->onStateChanged(0, SessionState::IDLING);
Kevin Chyncfb54992020-11-17 13:06:23 -0800102 }
Ilya Matyukhin09166982020-10-12 13:41:03 -0700103 return ndk::ScopedAStatus::ok();
104}
105
Ilya Matyukhin26b20b92021-01-22 11:39:49 -0800106ndk::ScopedAStatus Session::getFeatures(int32_t /*cookie*/, int32_t /*enrollmentId*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -0800107 LOG(INFO) << "getFeatures";
Ilya Matyukhin26b20b92021-01-22 11:39:49 -0800108 return ndk::ScopedAStatus::ok();
109}
110
111ndk::ScopedAStatus Session::setFeature(int32_t /*cookie*/,
112 const keymaster::HardwareAuthToken& /*hat*/,
113 int32_t /*enrollmentId*/, Feature /*feature*/,
114 bool /*enabled*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -0800115 LOG(INFO) << "setFeature";
Ilya Matyukhin26b20b92021-01-22 11:39:49 -0800116 return ndk::ScopedAStatus::ok();
117}
118
Ilya Matyukhin09166982020-10-12 13:41:03 -0700119ndk::ScopedAStatus Session::getAuthenticatorId(int32_t /*cookie*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -0800120 LOG(INFO) << "getAuthenticatorId";
Kevin Chyncfb54992020-11-17 13:06:23 -0800121 if (cb_) {
122 cb_->onStateChanged(0, SessionState::GETTING_AUTHENTICATOR_ID);
123 cb_->onAuthenticatorIdRetrieved(0 /* authenticatorId */);
124 cb_->onStateChanged(0, SessionState::IDLING);
125 }
Ilya Matyukhin09166982020-10-12 13:41:03 -0700126 return ndk::ScopedAStatus::ok();
127}
128
129ndk::ScopedAStatus Session::invalidateAuthenticatorId(int32_t /*cookie*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -0800130 LOG(INFO) << "invalidateAuthenticatorId";
Ilya Matyukhin09166982020-10-12 13:41:03 -0700131 return ndk::ScopedAStatus::ok();
132}
133
134ndk::ScopedAStatus Session::resetLockout(int32_t /*cookie*/,
135 const keymaster::HardwareAuthToken& /*hat*/) {
Kevin Chyn146f6c82021-02-10 11:32:35 -0800136 LOG(INFO) << "resetLockout";
Kevin Chyncfb54992020-11-17 13:06:23 -0800137 if (cb_) {
138 cb_->onStateChanged(0, SessionState::RESETTING_LOCKOUT);
139 cb_->onLockoutCleared();
140 cb_->onStateChanged(0, SessionState::IDLING);
141 }
Ilya Matyukhin09166982020-10-12 13:41:03 -0700142 return ndk::ScopedAStatus::ok();
143}
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -0800144
Ilya Matyukhine52cae02021-02-17 16:38:56 -0800145ndk::ScopedAStatus Session::close(int32_t /*cookie*/) {
146 return ndk::ScopedAStatus::ok();
147}
148
Ilya Matyukhin09166982020-10-12 13:41:03 -0700149} // namespace aidl::android::hardware::biometrics::face