blob: df5187955f8614ecda0acc25ce61b39ae77b16bb [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(
58 int32_t /*cookie*/, biometrics::face::EnrollmentType /*enrollmentType*/,
59 const keymaster::HardwareAuthToken& /*hat*/, const NativeHandle& /*previewSurface*/,
60 std::shared_ptr<biometrics::common::ICancellationSignal>* /*return_val*/) {
Ilya Matyukhin09166982020-10-12 13:41:03 -070061 return ndk::ScopedAStatus::ok();
62}
63
64ndk::ScopedAStatus Session::authenticate(int32_t /*cookie*/, int64_t /*keystoreOperationId*/,
65 std::shared_ptr<common::ICancellationSignal>* return_val) {
66 if (cb_) {
67 cb_->onStateChanged(0, SessionState::AUTHENTICATING);
68 }
Kevin Chyncfb54992020-11-17 13:06:23 -080069 *return_val = SharedRefBase::make<CancellationSignal>(cb_);
Ilya Matyukhin09166982020-10-12 13:41:03 -070070 return ndk::ScopedAStatus::ok();
71}
72
73ndk::ScopedAStatus Session::detectInteraction(
74 int32_t /*cookie*/, std::shared_ptr<common::ICancellationSignal>* /*return_val*/) {
75 return ndk::ScopedAStatus::ok();
76}
77
78ndk::ScopedAStatus Session::enumerateEnrollments(int32_t /*cookie*/) {
Kevin Chyncfb54992020-11-17 13:06:23 -080079 if (cb_) {
80 cb_->onStateChanged(0, SessionState::ENUMERATING_ENROLLMENTS);
81 cb_->onEnrollmentsEnumerated(std::vector<int32_t>());
82 cb_->onStateChanged(0, SessionState::IDLING);
83 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070084 return ndk::ScopedAStatus::ok();
85}
86
87ndk::ScopedAStatus Session::removeEnrollments(int32_t /*cookie*/,
88 const std::vector<int32_t>& /*enrollmentIds*/) {
Kevin Chyncfb54992020-11-17 13:06:23 -080089 if (cb_) {
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -080090 cb_->onStateChanged(0, SessionState::REMOVING_ENROLLMENTS);
91 cb_->onEnrollmentsRemoved(std::vector<int32_t>());
92 cb_->onStateChanged(0, SessionState::IDLING);
Kevin Chyncfb54992020-11-17 13:06:23 -080093 }
Ilya Matyukhin09166982020-10-12 13:41:03 -070094 return ndk::ScopedAStatus::ok();
95}
96
97ndk::ScopedAStatus Session::getAuthenticatorId(int32_t /*cookie*/) {
Kevin Chyncfb54992020-11-17 13:06:23 -080098 if (cb_) {
99 cb_->onStateChanged(0, SessionState::GETTING_AUTHENTICATOR_ID);
100 cb_->onAuthenticatorIdRetrieved(0 /* authenticatorId */);
101 cb_->onStateChanged(0, SessionState::IDLING);
102 }
Ilya Matyukhin09166982020-10-12 13:41:03 -0700103 return ndk::ScopedAStatus::ok();
104}
105
106ndk::ScopedAStatus Session::invalidateAuthenticatorId(int32_t /*cookie*/) {
107 return ndk::ScopedAStatus::ok();
108}
109
110ndk::ScopedAStatus Session::resetLockout(int32_t /*cookie*/,
111 const keymaster::HardwareAuthToken& /*hat*/) {
Kevin Chyncfb54992020-11-17 13:06:23 -0800112 if (cb_) {
113 cb_->onStateChanged(0, SessionState::RESETTING_LOCKOUT);
114 cb_->onLockoutCleared();
115 cb_->onStateChanged(0, SessionState::IDLING);
116 }
Ilya Matyukhin09166982020-10-12 13:41:03 -0700117 return ndk::ScopedAStatus::ok();
118}
Ilya Matyukhinaf30cde2021-01-08 09:42:50 -0800119
Ilya Matyukhin09166982020-10-12 13:41:03 -0700120} // namespace aidl::android::hardware::biometrics::face