Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 21 | namespace aidl::android::hardware::biometrics::face { |
| 22 | |
| 23 | class CancellationSignal : public common::BnCancellationSignal { |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 24 | private: |
| 25 | std::shared_ptr<ISessionCallback> cb_; |
Ilya Matyukhin | af30cde | 2021-01-08 09:42:50 -0800 | [diff] [blame] | 26 | |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 27 | public: |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 28 | 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 Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | Session::Session(std::shared_ptr<ISessionCallback> cb) : cb_(std::move(cb)) {} |
| 38 | |
Ilya Matyukhin | e503481 | 2020-10-15 21:45:56 -0700 | [diff] [blame] | 39 | ndk::ScopedAStatus Session::generateChallenge(int32_t /*cookie*/, int32_t /*timeoutSec*/) { |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 40 | if (cb_) { |
| 41 | cb_->onStateChanged(0, SessionState::GENERATING_CHALLENGE); |
| 42 | cb_->onChallengeGenerated(0); |
| 43 | cb_->onStateChanged(0, SessionState::IDLING); |
| 44 | } |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 45 | return ndk::ScopedAStatus::ok(); |
| 46 | } |
| 47 | |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 48 | ndk::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 Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 54 | return ndk::ScopedAStatus::ok(); |
| 55 | } |
| 56 | |
Ilya Matyukhin | af30cde | 2021-01-08 09:42:50 -0800 | [diff] [blame] | 57 | ndk::ScopedAStatus Session::enroll( |
Ilya Matyukhin | 26b20b9 | 2021-01-22 11:39:49 -0800 | [diff] [blame^] | 58 | int32_t /*cookie*/, const keymaster::HardwareAuthToken& /*hat*/, |
| 59 | EnrollmentType /*enrollmentType*/, const std::vector<Feature>& /*features*/, |
| 60 | const NativeHandle& /*previewSurface*/, |
Ilya Matyukhin | af30cde | 2021-01-08 09:42:50 -0800 | [diff] [blame] | 61 | std::shared_ptr<biometrics::common::ICancellationSignal>* /*return_val*/) { |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 62 | return ndk::ScopedAStatus::ok(); |
| 63 | } |
| 64 | |
| 65 | ndk::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 Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 70 | *return_val = SharedRefBase::make<CancellationSignal>(cb_); |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 71 | return ndk::ScopedAStatus::ok(); |
| 72 | } |
| 73 | |
| 74 | ndk::ScopedAStatus Session::detectInteraction( |
| 75 | int32_t /*cookie*/, std::shared_ptr<common::ICancellationSignal>* /*return_val*/) { |
| 76 | return ndk::ScopedAStatus::ok(); |
| 77 | } |
| 78 | |
| 79 | ndk::ScopedAStatus Session::enumerateEnrollments(int32_t /*cookie*/) { |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 80 | if (cb_) { |
| 81 | cb_->onStateChanged(0, SessionState::ENUMERATING_ENROLLMENTS); |
| 82 | cb_->onEnrollmentsEnumerated(std::vector<int32_t>()); |
| 83 | cb_->onStateChanged(0, SessionState::IDLING); |
| 84 | } |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 85 | return ndk::ScopedAStatus::ok(); |
| 86 | } |
| 87 | |
| 88 | ndk::ScopedAStatus Session::removeEnrollments(int32_t /*cookie*/, |
| 89 | const std::vector<int32_t>& /*enrollmentIds*/) { |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 90 | if (cb_) { |
Ilya Matyukhin | af30cde | 2021-01-08 09:42:50 -0800 | [diff] [blame] | 91 | cb_->onStateChanged(0, SessionState::REMOVING_ENROLLMENTS); |
| 92 | cb_->onEnrollmentsRemoved(std::vector<int32_t>()); |
| 93 | cb_->onStateChanged(0, SessionState::IDLING); |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 94 | } |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 95 | return ndk::ScopedAStatus::ok(); |
| 96 | } |
| 97 | |
Ilya Matyukhin | 26b20b9 | 2021-01-22 11:39:49 -0800 | [diff] [blame^] | 98 | ndk::ScopedAStatus Session::getFeatures(int32_t /*cookie*/, int32_t /*enrollmentId*/) { |
| 99 | return ndk::ScopedAStatus::ok(); |
| 100 | } |
| 101 | |
| 102 | ndk::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 Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 109 | ndk::ScopedAStatus Session::getAuthenticatorId(int32_t /*cookie*/) { |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 110 | if (cb_) { |
| 111 | cb_->onStateChanged(0, SessionState::GETTING_AUTHENTICATOR_ID); |
| 112 | cb_->onAuthenticatorIdRetrieved(0 /* authenticatorId */); |
| 113 | cb_->onStateChanged(0, SessionState::IDLING); |
| 114 | } |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 115 | return ndk::ScopedAStatus::ok(); |
| 116 | } |
| 117 | |
| 118 | ndk::ScopedAStatus Session::invalidateAuthenticatorId(int32_t /*cookie*/) { |
| 119 | return ndk::ScopedAStatus::ok(); |
| 120 | } |
| 121 | |
| 122 | ndk::ScopedAStatus Session::resetLockout(int32_t /*cookie*/, |
| 123 | const keymaster::HardwareAuthToken& /*hat*/) { |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 124 | if (cb_) { |
| 125 | cb_->onStateChanged(0, SessionState::RESETTING_LOCKOUT); |
| 126 | cb_->onLockoutCleared(); |
| 127 | cb_->onStateChanged(0, SessionState::IDLING); |
| 128 | } |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 129 | return ndk::ScopedAStatus::ok(); |
| 130 | } |
Ilya Matyukhin | af30cde | 2021-01-08 09:42:50 -0800 | [diff] [blame] | 131 | |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 132 | } // namespace aidl::android::hardware::biometrics::face |