blob: 63d17213142ee17d53e1996bb09121cbd838dbaa [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>
18
19#include "Session.h"
20
21namespace aidl::android::hardware::biometrics::face {
22
23class CancellationSignal : public common::BnCancellationSignal {
Kevin Chyncfb54992020-11-17 13:06:23 -080024 private:
25 std::shared_ptr<ISessionCallback> cb_;
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -080026
Ilya Matyukhin09166982020-10-12 13:41:03 -070027 public:
Kevin Chyncfb54992020-11-17 13:06:23 -080028 explicit CancellationSignal(std::shared_ptr<ISessionCallback> cb) : cb_(std::move(cb)) {}
29
30 ndk::ScopedAStatus cancel() override {
31 cb_->onError(Error::CANCELED, 0 /* vendorCode */);
32 cb_->onStateChanged(0, SessionState::IDLING);
33 return ndk::ScopedAStatus::ok();
34 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070035};
36
37Session::Session(std::shared_ptr<ISessionCallback> cb) : cb_(std::move(cb)) {}
38
Ilya Matyukhine5034812020-10-15 21:45:56 -070039ndk::ScopedAStatus Session::generateChallenge(int32_t /*cookie*/, int32_t /*timeoutSec*/) {
Kevin Chyncfb54992020-11-17 13:06:23 -080040 if (cb_) {
41 cb_->onStateChanged(0, SessionState::GENERATING_CHALLENGE);
42 cb_->onChallengeGenerated(0);
43 cb_->onStateChanged(0, SessionState::IDLING);
44 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070045 return ndk::ScopedAStatus::ok();
46}
47
Kevin Chyncfb54992020-11-17 13:06:23 -080048ndk::ScopedAStatus Session::revokeChallenge(int32_t /*cookie*/, int64_t challenge) {
49 if (cb_) {
50 cb_->onStateChanged(0, SessionState::REVOKING_CHALLENGE);
51 cb_->onChallengeRevoked(challenge);
52 cb_->onStateChanged(0, SessionState::IDLING);
53 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070054 return ndk::ScopedAStatus::ok();
55}
56
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -080057ndk::ScopedAStatus Session::enroll(
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080058 int32_t /*cookie*/, const keymaster::HardwareAuthToken& /*hat*/,
59 EnrollmentType /*enrollmentType*/, const std::vector<Feature>& /*features*/,
60 const NativeHandle& /*previewSurface*/,
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -080061 std::shared_ptr<biometrics::common::ICancellationSignal>* /*return_val*/) {
Ilya Matyukhin09166982020-10-12 13:41:03 -070062 return ndk::ScopedAStatus::ok();
63}
64
65ndk::ScopedAStatus Session::authenticate(int32_t /*cookie*/, int64_t /*keystoreOperationId*/,
66 std::shared_ptr<common::ICancellationSignal>* return_val) {
67 if (cb_) {
68 cb_->onStateChanged(0, SessionState::AUTHENTICATING);
69 }
Kevin Chyncfb54992020-11-17 13:06:23 -080070 *return_val = SharedRefBase::make<CancellationSignal>(cb_);
Ilya Matyukhin09166982020-10-12 13:41:03 -070071 return ndk::ScopedAStatus::ok();
72}
73
74ndk::ScopedAStatus Session::detectInteraction(
75 int32_t /*cookie*/, std::shared_ptr<common::ICancellationSignal>* /*return_val*/) {
76 return ndk::ScopedAStatus::ok();
77}
78
79ndk::ScopedAStatus Session::enumerateEnrollments(int32_t /*cookie*/) {
Kevin Chyncfb54992020-11-17 13:06:23 -080080 if (cb_) {
81 cb_->onStateChanged(0, SessionState::ENUMERATING_ENROLLMENTS);
82 cb_->onEnrollmentsEnumerated(std::vector<int32_t>());
83 cb_->onStateChanged(0, SessionState::IDLING);
84 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070085 return ndk::ScopedAStatus::ok();
86}
87
88ndk::ScopedAStatus Session::removeEnrollments(int32_t /*cookie*/,
89 const std::vector<int32_t>& /*enrollmentIds*/) {
Kevin Chyncfb54992020-11-17 13:06:23 -080090 if (cb_) {
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -080091 cb_->onStateChanged(0, SessionState::REMOVING_ENROLLMENTS);
92 cb_->onEnrollmentsRemoved(std::vector<int32_t>());
93 cb_->onStateChanged(0, SessionState::IDLING);
Kevin Chyncfb54992020-11-17 13:06:23 -080094 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070095 return ndk::ScopedAStatus::ok();
96}
97
Ilya Matyukhin26b20b92021-01-22 11:39:49 -080098ndk::ScopedAStatus Session::getFeatures(int32_t /*cookie*/, int32_t /*enrollmentId*/) {
99 return ndk::ScopedAStatus::ok();
100}
101
102ndk::ScopedAStatus Session::setFeature(int32_t /*cookie*/,
103 const keymaster::HardwareAuthToken& /*hat*/,
104 int32_t /*enrollmentId*/, Feature /*feature*/,
105 bool /*enabled*/) {
106 return ndk::ScopedAStatus::ok();
107}
108
Ilya Matyukhin09166982020-10-12 13:41:03 -0700109ndk::ScopedAStatus Session::getAuthenticatorId(int32_t /*cookie*/) {
Kevin Chyncfb54992020-11-17 13:06:23 -0800110 if (cb_) {
111 cb_->onStateChanged(0, SessionState::GETTING_AUTHENTICATOR_ID);
112 cb_->onAuthenticatorIdRetrieved(0 /* authenticatorId */);
113 cb_->onStateChanged(0, SessionState::IDLING);
114 }
Ilya Matyukhin09166982020-10-12 13:41:03 -0700115 return ndk::ScopedAStatus::ok();
116}
117
118ndk::ScopedAStatus Session::invalidateAuthenticatorId(int32_t /*cookie*/) {
119 return ndk::ScopedAStatus::ok();
120}
121
122ndk::ScopedAStatus Session::resetLockout(int32_t /*cookie*/,
123 const keymaster::HardwareAuthToken& /*hat*/) {
Kevin Chyncfb54992020-11-17 13:06:23 -0800124 if (cb_) {
125 cb_->onStateChanged(0, SessionState::RESETTING_LOCKOUT);
126 cb_->onLockoutCleared();
127 cb_->onStateChanged(0, SessionState::IDLING);
128 }
Ilya Matyukhin09166982020-10-12 13:41:03 -0700129 return ndk::ScopedAStatus::ok();
130}
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -0800131
Ilya Matyukhin09166982020-10-12 13:41:03 -0700132} // namespace aidl::android::hardware::biometrics::face