2020-10-12 13:41:03 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2020 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-02-10 11:32:35 -08:00
|
|
|
#include <android-base/logging.h>
|
2020-10-12 13:41:03 -07:00
|
|
|
|
|
|
|
|
#include "Session.h"
|
|
|
|
|
|
2023-09-06 14:47:49 +00:00
|
|
|
#undef LOG_TAG
|
|
|
|
|
#define LOG_TAG "FaceVirtualHalSession"
|
|
|
|
|
|
2020-10-12 13:41:03 -07:00
|
|
|
namespace aidl::android::hardware::biometrics::face {
|
|
|
|
|
|
2022-05-10 05:18:20 +00:00
|
|
|
constexpr size_t MAX_WORKER_QUEUE_SIZE = 5;
|
2021-01-08 09:42:50 -08:00
|
|
|
|
2022-05-10 05:18:20 +00:00
|
|
|
Session::Session(std::unique_ptr<FakeFaceEngine> engine, std::shared_ptr<ISessionCallback> cb)
|
|
|
|
|
: mEngine(std::move(engine)), mCb(std::move(cb)), mRandom(std::mt19937::default_seed) {
|
|
|
|
|
mThread = std::make_unique<WorkerThread>(MAX_WORKER_QUEUE_SIZE);
|
|
|
|
|
}
|
2020-10-12 13:41:03 -07:00
|
|
|
|
2021-03-23 22:33:31 -07:00
|
|
|
ndk::ScopedAStatus Session::generateChallenge() {
|
2021-02-10 11:32:35 -08:00
|
|
|
LOG(INFO) << "generateChallenge";
|
2022-05-10 05:18:20 +00:00
|
|
|
mThread->schedule(Callable::from([this] { mEngine->generateChallengeImpl(mCb.get()); }));
|
2020-10-12 13:41:03 -07:00
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 22:33:31 -07:00
|
|
|
ndk::ScopedAStatus Session::revokeChallenge(int64_t challenge) {
|
2021-02-10 11:32:35 -08:00
|
|
|
LOG(INFO) << "revokeChallenge";
|
2022-05-10 05:18:20 +00:00
|
|
|
mThread->schedule(Callable::from(
|
|
|
|
|
[this, challenge] { mEngine->revokeChallengeImpl(mCb.get(), challenge); }));
|
2020-10-12 13:41:03 -07:00
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 05:18:20 +00:00
|
|
|
ndk::ScopedAStatus Session::getEnrollmentConfig(
|
|
|
|
|
EnrollmentType /*enrollmentType*/, std::vector<EnrollmentStageConfig>* cancellationSignal) {
|
|
|
|
|
*cancellationSignal = {};
|
2021-04-22 00:29:01 -07:00
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-08 09:42:50 -08:00
|
|
|
ndk::ScopedAStatus Session::enroll(
|
2022-05-10 05:18:20 +00:00
|
|
|
const keymaster::HardwareAuthToken& hat, EnrollmentType enrollmentType,
|
|
|
|
|
const std::vector<Feature>& features, const std::optional<NativeHandle>& /*previewSurface*/,
|
|
|
|
|
std::shared_ptr<biometrics::common::ICancellationSignal>* cancellationSignal) {
|
2021-02-10 11:32:35 -08:00
|
|
|
LOG(INFO) << "enroll";
|
2022-05-10 05:18:20 +00:00
|
|
|
std::promise<void> cancellationPromise;
|
|
|
|
|
auto cancFuture = cancellationPromise.get_future();
|
|
|
|
|
|
|
|
|
|
mThread->schedule(Callable::from(
|
|
|
|
|
[this, hat, enrollmentType, features, cancFuture = std::move(cancFuture)] {
|
|
|
|
|
mEngine->enrollImpl(mCb.get(), hat, enrollmentType, features, cancFuture);
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
*cancellationSignal = SharedRefBase::make<CancellationSignal>(std::move(cancellationPromise));
|
2020-10-12 13:41:03 -07:00
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 05:18:20 +00:00
|
|
|
ndk::ScopedAStatus Session::authenticate(
|
|
|
|
|
int64_t keystoreOperationId,
|
|
|
|
|
std::shared_ptr<common::ICancellationSignal>* cancellationSignal) {
|
2021-02-10 11:32:35 -08:00
|
|
|
LOG(INFO) << "authenticate";
|
2022-05-10 05:18:20 +00:00
|
|
|
std::promise<void> cancellationPromise;
|
|
|
|
|
auto cancFuture = cancellationPromise.get_future();
|
|
|
|
|
|
|
|
|
|
mThread->schedule(
|
|
|
|
|
Callable::from([this, keystoreOperationId, cancFuture = std::move(cancFuture)] {
|
|
|
|
|
mEngine->authenticateImpl(mCb.get(), keystoreOperationId, cancFuture);
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
*cancellationSignal = SharedRefBase::make<CancellationSignal>(std::move(cancellationPromise));
|
2020-10-12 13:41:03 -07:00
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ndk::ScopedAStatus Session::detectInteraction(
|
2022-05-10 05:18:20 +00:00
|
|
|
std::shared_ptr<common::ICancellationSignal>* cancellationSignal) {
|
2021-02-10 11:32:35 -08:00
|
|
|
LOG(INFO) << "detectInteraction";
|
2022-05-10 05:18:20 +00:00
|
|
|
std::promise<void> cancellationPromise;
|
|
|
|
|
auto cancFuture = cancellationPromise.get_future();
|
|
|
|
|
|
|
|
|
|
mThread->schedule(Callable::from([this, cancFuture = std::move(cancFuture)] {
|
|
|
|
|
mEngine->detectInteractionImpl(mCb.get(), cancFuture);
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
*cancellationSignal = SharedRefBase::make<CancellationSignal>(std::move(cancellationPromise));
|
2020-10-12 13:41:03 -07:00
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 22:33:31 -07:00
|
|
|
ndk::ScopedAStatus Session::enumerateEnrollments() {
|
2021-02-10 11:32:35 -08:00
|
|
|
LOG(INFO) << "enumerateEnrollments";
|
2022-05-10 05:18:20 +00:00
|
|
|
mThread->schedule(Callable::from([this] { mEngine->enumerateEnrollmentsImpl(mCb.get()); }));
|
2020-10-12 13:41:03 -07:00
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 05:18:20 +00:00
|
|
|
ndk::ScopedAStatus Session::removeEnrollments(const std::vector<int32_t>& enrollmentIds) {
|
2021-02-10 11:32:35 -08:00
|
|
|
LOG(INFO) << "removeEnrollments";
|
2022-05-10 05:18:20 +00:00
|
|
|
mThread->schedule(Callable::from(
|
|
|
|
|
[this, enrollmentIds] { mEngine->removeEnrollmentsImpl(mCb.get(), enrollmentIds); }));
|
2020-10-12 13:41:03 -07:00
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-14 13:43:06 -07:00
|
|
|
ndk::ScopedAStatus Session::getFeatures() {
|
2021-02-10 11:32:35 -08:00
|
|
|
LOG(INFO) << "getFeatures";
|
2022-05-10 05:18:20 +00:00
|
|
|
mThread->schedule(Callable::from([this] { mEngine->getFeaturesImpl(mCb.get()); }));
|
2021-01-22 11:39:49 -08:00
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 05:18:20 +00:00
|
|
|
ndk::ScopedAStatus Session::setFeature(const keymaster::HardwareAuthToken& hat, Feature feature,
|
|
|
|
|
bool enabled) {
|
2021-02-10 11:32:35 -08:00
|
|
|
LOG(INFO) << "setFeature";
|
2022-05-10 05:18:20 +00:00
|
|
|
mThread->schedule(Callable::from([this, hat, feature, enabled] {
|
|
|
|
|
mEngine->setFeatureImpl(mCb.get(), hat, feature, enabled);
|
|
|
|
|
}));
|
2021-01-22 11:39:49 -08:00
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 22:33:31 -07:00
|
|
|
ndk::ScopedAStatus Session::getAuthenticatorId() {
|
2021-02-10 11:32:35 -08:00
|
|
|
LOG(INFO) << "getAuthenticatorId";
|
2022-05-10 05:18:20 +00:00
|
|
|
mThread->schedule(Callable::from([this] { mEngine->getAuthenticatorIdImpl(mCb.get()); }));
|
2020-10-12 13:41:03 -07:00
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 22:33:31 -07:00
|
|
|
ndk::ScopedAStatus Session::invalidateAuthenticatorId() {
|
2021-02-10 11:32:35 -08:00
|
|
|
LOG(INFO) << "invalidateAuthenticatorId";
|
2022-05-10 05:18:20 +00:00
|
|
|
mThread->schedule(
|
|
|
|
|
Callable::from([this] { mEngine->invalidateAuthenticatorIdImpl(mCb.get()); }));
|
2020-10-12 13:41:03 -07:00
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 05:18:20 +00:00
|
|
|
ndk::ScopedAStatus Session::resetLockout(const keymaster::HardwareAuthToken& hat) {
|
2021-02-10 11:32:35 -08:00
|
|
|
LOG(INFO) << "resetLockout";
|
2022-05-10 05:18:20 +00:00
|
|
|
mThread->schedule(Callable::from([this, hat] { mEngine->resetLockoutImpl(mCb.get(), hat); }));
|
2020-10-12 13:41:03 -07:00
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
2021-01-08 09:42:50 -08:00
|
|
|
|
2021-03-23 22:33:31 -07:00
|
|
|
ndk::ScopedAStatus Session::close() {
|
2022-05-10 05:18:20 +00:00
|
|
|
if (mCb) {
|
|
|
|
|
mCb->onSessionClosed();
|
2021-03-23 22:33:31 -07:00
|
|
|
}
|
2021-02-17 16:38:56 -08:00
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 16:27:03 -08:00
|
|
|
ndk::ScopedAStatus Session::authenticateWithContext(
|
|
|
|
|
int64_t operationId, const common::OperationContext& /*context*/,
|
|
|
|
|
std::shared_ptr<common::ICancellationSignal>* out) {
|
|
|
|
|
return authenticate(operationId, out);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ndk::ScopedAStatus Session::enrollWithContext(const keymaster::HardwareAuthToken& hat,
|
|
|
|
|
EnrollmentType enrollmentType,
|
|
|
|
|
const std::vector<Feature>& features,
|
|
|
|
|
const std::optional<NativeHandle>& previewSurface,
|
|
|
|
|
const common::OperationContext& /*context*/,
|
|
|
|
|
std::shared_ptr<common::ICancellationSignal>* out) {
|
|
|
|
|
return enroll(hat, enrollmentType, features, previewSurface, out);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ndk::ScopedAStatus Session::detectInteractionWithContext(
|
|
|
|
|
const common::OperationContext& /*context*/,
|
|
|
|
|
std::shared_ptr<common::ICancellationSignal>* out) {
|
|
|
|
|
return detectInteraction(out);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-24 18:56:23 +00:00
|
|
|
ndk::ScopedAStatus Session::onContextChanged(const common::OperationContext& /*context*/) {
|
|
|
|
|
return ndk::ScopedAStatus::ok();
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-01 15:57:55 +00:00
|
|
|
ndk::ScopedAStatus Session::enrollWithOptions(const FaceEnrollOptions& options,
|
|
|
|
|
std::shared_ptr<common::ICancellationSignal>* out) {
|
|
|
|
|
return enroll(options.hardwareAuthToken, options.enrollmentType, options.features,
|
|
|
|
|
options.nativeHandlePreview, out);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 13:41:03 -07:00
|
|
|
} // namespace aidl::android::hardware::biometrics::face
|