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 | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 26 | public: |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 27 | 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 Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | Session::Session(std::shared_ptr<ISessionCallback> cb) : cb_(std::move(cb)) {} |
| 37 | |
Ilya Matyukhin | e503481 | 2020-10-15 21:45:56 -0700 | [diff] [blame] | 38 | ndk::ScopedAStatus Session::generateChallenge(int32_t /*cookie*/, int32_t /*timeoutSec*/) { |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 39 | if (cb_) { |
| 40 | cb_->onStateChanged(0, SessionState::GENERATING_CHALLENGE); |
| 41 | cb_->onChallengeGenerated(0); |
| 42 | cb_->onStateChanged(0, SessionState::IDLING); |
| 43 | } |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 44 | return ndk::ScopedAStatus::ok(); |
| 45 | } |
| 46 | |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 47 | ndk::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 Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 53 | return ndk::ScopedAStatus::ok(); |
| 54 | } |
| 55 | |
| 56 | ndk::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 | |
| 63 | ndk::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 Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 68 | *return_val = SharedRefBase::make<CancellationSignal>(cb_); |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 69 | return ndk::ScopedAStatus::ok(); |
| 70 | } |
| 71 | |
| 72 | ndk::ScopedAStatus Session::detectInteraction( |
| 73 | int32_t /*cookie*/, std::shared_ptr<common::ICancellationSignal>* /*return_val*/) { |
| 74 | return ndk::ScopedAStatus::ok(); |
| 75 | } |
| 76 | |
| 77 | ndk::ScopedAStatus Session::enumerateEnrollments(int32_t /*cookie*/) { |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 78 | if (cb_) { |
| 79 | cb_->onStateChanged(0, SessionState::ENUMERATING_ENROLLMENTS); |
| 80 | cb_->onEnrollmentsEnumerated(std::vector<int32_t>()); |
| 81 | cb_->onStateChanged(0, SessionState::IDLING); |
| 82 | } |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 83 | return ndk::ScopedAStatus::ok(); |
| 84 | } |
| 85 | |
| 86 | ndk::ScopedAStatus Session::removeEnrollments(int32_t /*cookie*/, |
| 87 | const std::vector<int32_t>& /*enrollmentIds*/) { |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 88 | if (cb_) { |
| 89 | cb_->onStateChanged(0, SessionState::REMOVING_ENROLLMENTS); |
| 90 | cb_->onEnrollmentsRemoved(std::vector<int32_t>()); |
| 91 | cb_->onStateChanged(0, SessionState::IDLING); |
| 92 | } |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 93 | return ndk::ScopedAStatus::ok(); |
| 94 | } |
| 95 | |
| 96 | ndk::ScopedAStatus Session::getAuthenticatorId(int32_t /*cookie*/) { |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 97 | if (cb_) { |
| 98 | cb_->onStateChanged(0, SessionState::GETTING_AUTHENTICATOR_ID); |
| 99 | cb_->onAuthenticatorIdRetrieved(0 /* authenticatorId */); |
| 100 | cb_->onStateChanged(0, SessionState::IDLING); |
| 101 | } |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 102 | return ndk::ScopedAStatus::ok(); |
| 103 | } |
| 104 | |
| 105 | ndk::ScopedAStatus Session::invalidateAuthenticatorId(int32_t /*cookie*/) { |
| 106 | return ndk::ScopedAStatus::ok(); |
| 107 | } |
| 108 | |
| 109 | ndk::ScopedAStatus Session::resetLockout(int32_t /*cookie*/, |
| 110 | const keymaster::HardwareAuthToken& /*hat*/) { |
Kevin Chyn | cfb5499 | 2020-11-17 13:06:23 -0800 | [diff] [blame] | 111 | if (cb_) { |
| 112 | cb_->onStateChanged(0, SessionState::RESETTING_LOCKOUT); |
| 113 | cb_->onLockoutCleared(); |
| 114 | cb_->onStateChanged(0, SessionState::IDLING); |
| 115 | } |
Ilya Matyukhin | 0916698 | 2020-10-12 13:41:03 -0700 | [diff] [blame] | 116 | return ndk::ScopedAStatus::ok(); |
| 117 | } |
| 118 | } // namespace aidl::android::hardware::biometrics::face |