blob: c5d7d23ecbaf000315c7f6da9ec434134ceae8cd [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 Matyukhin09166982020-10-12 13:41:03 -070026 public:
Kevin Chyncfb54992020-11-17 13:06:23 -080027 explicit CancellationSignal(std::shared_ptr<ISessionCallback> cb) : cb_(std::move(cb)) {}
28
29 ndk::ScopedAStatus cancel() override {
30 cb_->onError(Error::CANCELED, 0 /* vendorCode */);
31 cb_->onStateChanged(0, SessionState::IDLING);
32 return ndk::ScopedAStatus::ok();
33 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070034};
35
36Session::Session(std::shared_ptr<ISessionCallback> cb) : cb_(std::move(cb)) {}
37
Ilya Matyukhine5034812020-10-15 21:45:56 -070038ndk::ScopedAStatus Session::generateChallenge(int32_t /*cookie*/, int32_t /*timeoutSec*/) {
Kevin Chyncfb54992020-11-17 13:06:23 -080039 if (cb_) {
40 cb_->onStateChanged(0, SessionState::GENERATING_CHALLENGE);
41 cb_->onChallengeGenerated(0);
42 cb_->onStateChanged(0, SessionState::IDLING);
43 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070044 return ndk::ScopedAStatus::ok();
45}
46
Kevin Chyncfb54992020-11-17 13:06:23 -080047ndk::ScopedAStatus Session::revokeChallenge(int32_t /*cookie*/, int64_t challenge) {
48 if (cb_) {
49 cb_->onStateChanged(0, SessionState::REVOKING_CHALLENGE);
50 cb_->onChallengeRevoked(challenge);
51 cb_->onStateChanged(0, SessionState::IDLING);
52 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070053 return ndk::ScopedAStatus::ok();
54}
55
56ndk::ScopedAStatus Session::enroll(int32_t /*cookie*/, const keymaster::HardwareAuthToken& /*hat*/,
57 const NativeHandle& /*previewSurface*/,
58 std::shared_ptr<biometrics::common::ICancellationSignal>*
59 /*returnVal*/) {
60 return ndk::ScopedAStatus::ok();
61}
62
63ndk::ScopedAStatus Session::authenticate(int32_t /*cookie*/, int64_t /*keystoreOperationId*/,
64 std::shared_ptr<common::ICancellationSignal>* return_val) {
65 if (cb_) {
66 cb_->onStateChanged(0, SessionState::AUTHENTICATING);
67 }
Kevin Chyncfb54992020-11-17 13:06:23 -080068 *return_val = SharedRefBase::make<CancellationSignal>(cb_);
Ilya Matyukhin09166982020-10-12 13:41:03 -070069 return ndk::ScopedAStatus::ok();
70}
71
72ndk::ScopedAStatus Session::detectInteraction(
73 int32_t /*cookie*/, std::shared_ptr<common::ICancellationSignal>* /*return_val*/) {
74 return ndk::ScopedAStatus::ok();
75}
76
77ndk::ScopedAStatus Session::enumerateEnrollments(int32_t /*cookie*/) {
Kevin Chyncfb54992020-11-17 13:06:23 -080078 if (cb_) {
79 cb_->onStateChanged(0, SessionState::ENUMERATING_ENROLLMENTS);
80 cb_->onEnrollmentsEnumerated(std::vector<int32_t>());
81 cb_->onStateChanged(0, SessionState::IDLING);
82 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070083 return ndk::ScopedAStatus::ok();
84}
85
86ndk::ScopedAStatus Session::removeEnrollments(int32_t /*cookie*/,
87 const std::vector<int32_t>& /*enrollmentIds*/) {
Kevin Chyncfb54992020-11-17 13:06:23 -080088 if (cb_) {
89 cb_->onStateChanged(0, SessionState::REMOVING_ENROLLMENTS);
90 cb_->onEnrollmentsRemoved(std::vector<int32_t>());
91 cb_->onStateChanged(0, SessionState::IDLING);
92 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070093 return ndk::ScopedAStatus::ok();
94}
95
96ndk::ScopedAStatus Session::getAuthenticatorId(int32_t /*cookie*/) {
Kevin Chyncfb54992020-11-17 13:06:23 -080097 if (cb_) {
98 cb_->onStateChanged(0, SessionState::GETTING_AUTHENTICATOR_ID);
99 cb_->onAuthenticatorIdRetrieved(0 /* authenticatorId */);
100 cb_->onStateChanged(0, SessionState::IDLING);
101 }
Ilya Matyukhin09166982020-10-12 13:41:03 -0700102 return ndk::ScopedAStatus::ok();
103}
104
105ndk::ScopedAStatus Session::invalidateAuthenticatorId(int32_t /*cookie*/) {
106 return ndk::ScopedAStatus::ok();
107}
108
109ndk::ScopedAStatus Session::resetLockout(int32_t /*cookie*/,
110 const keymaster::HardwareAuthToken& /*hat*/) {
Kevin Chyncfb54992020-11-17 13:06:23 -0800111 if (cb_) {
112 cb_->onStateChanged(0, SessionState::RESETTING_LOCKOUT);
113 cb_->onLockoutCleared();
114 cb_->onStateChanged(0, SessionState::IDLING);
115 }
Ilya Matyukhin09166982020-10-12 13:41:03 -0700116 return ndk::ScopedAStatus::ok();
117}
118} // namespace aidl::android::hardware::biometrics::face