diff options
author | Ilya Matyukhin <ilyamaty@google.com> | 2020-01-17 22:45:44 -0800 |
---|---|---|
committer | Ilya Matyukhin <ilyamaty@google.com> | 2020-01-23 23:15:25 -0800 |
commit | 366cc5371401070753150e685e07e100f837dbe4 (patch) | |
tree | a0fbaa97e3e57bbe6aaadae246815bd56e416096 /biometrics | |
parent | d711c1087c69e2e44ef2ee29bf1fdf7b2817b78a (diff) | |
download | platform_hardware_interfaces-366cc5371401070753150e685e07e100f837dbe4.tar.gz platform_hardware_interfaces-366cc5371401070753150e685e07e100f837dbe4.tar.bz2 platform_hardware_interfaces-366cc5371401070753150e685e07e100f837dbe4.zip |
Add default implementation for biometrics.face@1.1
Bug: 145027036
Test: vts-tradefed run commandAndExit vts-hal -m VtsHalBiometricsFaceV1_0Target
Test: vts-tradefed run commandAndExit vts-hal -m VtsHalBiometricsFaceV1_1Target
Change-Id: I1aa682644b9b60705a1a8bf40867414b9fc99cd6
Diffstat (limited to 'biometrics')
-rw-r--r-- | biometrics/face/1.1/default/Android.bp | 36 | ||||
-rw-r--r-- | biometrics/face/1.1/default/BiometricsFace.cpp | 121 | ||||
-rw-r--r-- | biometrics/face/1.1/default/BiometricsFace.h | 84 | ||||
-rw-r--r-- | biometrics/face/1.1/default/android.hardware.biometrics.face@1.1-service.rc | 10 | ||||
-rw-r--r-- | biometrics/face/1.1/default/manifest_face_default.xml | 11 | ||||
-rw-r--r-- | biometrics/face/1.1/default/service.cpp | 50 |
6 files changed, 312 insertions, 0 deletions
diff --git a/biometrics/face/1.1/default/Android.bp b/biometrics/face/1.1/default/Android.bp new file mode 100644 index 0000000000..360071f3dd --- /dev/null +++ b/biometrics/face/1.1/default/Android.bp @@ -0,0 +1,36 @@ +/* + * Copyright 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. + */ + +cc_binary { + name: "android.hardware.biometrics.face@1.1-service.example", + defaults: ["hidl_defaults"], + vendor: true, + init_rc: ["android.hardware.biometrics.face@1.1-service.rc"], + vintf_fragments: ["manifest_face_default.xml"], + relative_install_path: "hw", + proprietary: true, + srcs: [ + "BiometricsFace.cpp", + "service.cpp", + ], + shared_libs: [ + "libhidlbase", + "libutils", + "liblog", + "android.hardware.biometrics.face@1.0", + "android.hardware.biometrics.face@1.1", + ], +} diff --git a/biometrics/face/1.1/default/BiometricsFace.cpp b/biometrics/face/1.1/default/BiometricsFace.cpp new file mode 100644 index 0000000000..7bda57fb7f --- /dev/null +++ b/biometrics/face/1.1/default/BiometricsFace.cpp @@ -0,0 +1,121 @@ +/* + * Copyright 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. + */ + +#include "BiometricsFace.h" + +namespace android::hardware::biometrics::face::implementation { +using android::hardware::biometrics::face::V1_0::FaceError; +using android::hardware::biometrics::face::V1_0::OptionalUint64; + +// Arbitrary value. +constexpr uint64_t kDeviceId = 123; +// Arbitrary value. +constexpr uint64_t kAuthenticatorId = 987; +// Arbitrary value. +constexpr uint64_t kLockoutDuration = 555; + +BiometricsFace::BiometricsFace() : mRandom(std::mt19937::default_seed) {} + +// Methods from IBiometricsFace follow. +Return<void> BiometricsFace::setCallback(const sp<IBiometricsFaceClientCallback>& clientCallback, + setCallback_cb _hidl_cb) { + mClientCallback = clientCallback; + _hidl_cb({Status::OK, kDeviceId}); + return Void(); +} + +Return<Status> BiometricsFace::setActiveUser(int32_t userId, const hidl_string& storePath) { + if (userId < 0 || storePath.empty() || std::string(storePath).find("/data") != 0) { + return Status::ILLEGAL_ARGUMENT; + } + mUserId = userId; + mClientCallback->onLockoutChanged(kLockoutDuration); + return Status::OK; +} + +Return<void> BiometricsFace::generateChallenge(uint32_t /* challengeTimeoutSec */, + generateChallenge_cb _hidl_cb) { + std::uniform_int_distribution<uint64_t> dist; + _hidl_cb({Status::OK, dist(mRandom)}); + return Void(); +} + +Return<Status> BiometricsFace::enroll(const hidl_vec<uint8_t>& /* hat */, uint32_t /* timeoutSec */, + const hidl_vec<Feature>& /* disabledFeatures */) { + // hat can never be valid in this implementation. + mClientCallback->onError(kDeviceId, mUserId, FaceError::UNABLE_TO_PROCESS, 0 /* vendorCode */); + return Status::OK; +} + +Return<Status> BiometricsFace::revokeChallenge() { + return Status::OK; +} + +Return<Status> BiometricsFace::setFeature(Feature /* feature */, bool /* enabled */, + const hidl_vec<uint8_t>& /* hat */, + uint32_t /* faceId */) { + // hat can never be valid in this implementation. + return Status::ILLEGAL_ARGUMENT; +} + +Return<void> BiometricsFace::getFeature(Feature /* feature */, uint32_t /* faceId */, + getFeature_cb _hidl_cb) { + // hat can never be valid in this implementation. + _hidl_cb({Status::ILLEGAL_ARGUMENT, false}); + return Void(); +} + +Return<void> BiometricsFace::getAuthenticatorId(getAuthenticatorId_cb _hidl_cb) { + _hidl_cb({Status::OK, kAuthenticatorId}); + return Void(); +} + +Return<Status> BiometricsFace::cancel() { + mClientCallback->onError(kDeviceId, mUserId, FaceError::CANCELED, 0 /* vendorCode */); + return Status::OK; +} + +Return<Status> BiometricsFace::enumerate() { + mClientCallback->onEnumerate(kDeviceId, {}, mUserId); + return Status::OK; +} + +Return<Status> BiometricsFace::remove(uint32_t /* faceId */) { + return Status::OK; +} + +Return<Status> BiometricsFace::authenticate(uint64_t /* operationId */) { + mClientCallback->onError(kDeviceId, mUserId, FaceError::HW_UNAVAILABLE, 0 /* vendorCode */); + return Status::OK; +} + +Return<Status> BiometricsFace::userActivity() { + return Status::OK; +} + +Return<Status> BiometricsFace::resetLockout(const hidl_vec<uint8_t>& /* hat */) { + return Status::OK; +} + +// Methods from ::android::hardware::biometrics::face::V1_1::IBiometricsFace follow. +Return<Status> BiometricsFace::enrollRemotely(const hidl_vec<uint8_t>& /* hat */, + uint32_t /* timeoutSec */, + const hidl_vec<Feature>& /* disabledFeatures */) { + mClientCallback->onError(kDeviceId, mUserId, FaceError::UNABLE_TO_PROCESS, 0 /* vendorCode */); + return Status::OK; +} + +} // namespace android::hardware::biometrics::face::implementation diff --git a/biometrics/face/1.1/default/BiometricsFace.h b/biometrics/face/1.1/default/BiometricsFace.h new file mode 100644 index 0000000000..5620b45a43 --- /dev/null +++ b/biometrics/face/1.1/default/BiometricsFace.h @@ -0,0 +1,84 @@ +/* + * Copyright 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. + */ + +#pragma once + +#include <android/hardware/biometrics/face/1.1/IBiometricsFace.h> +#include <hidl/MQDescriptor.h> +#include <hidl/Status.h> +#include <random> + +namespace android::hardware::biometrics::face::implementation { + +using ::android::sp; +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::biometrics::face::V1_0::Feature; +using ::android::hardware::biometrics::face::V1_0::IBiometricsFaceClientCallback; +using ::android::hardware::biometrics::face::V1_0::Status; + +class BiometricsFace : public V1_1::IBiometricsFace { + public: + BiometricsFace(); + + // Methods from ::android::hardware::biometrics::face::V1_0::IBiometricsFace follow. + Return<void> setCallback(const sp<IBiometricsFaceClientCallback>& clientCallback, + setCallback_cb _hidl_cb) override; + + Return<Status> setActiveUser(int32_t userId, const hidl_string& storePath) override; + + Return<void> generateChallenge(uint32_t challengeTimeoutSec, + generateChallenge_cb _hidl_cb) override; + + Return<Status> enroll(const hidl_vec<uint8_t>& hat, uint32_t timeoutSec, + const hidl_vec<Feature>& disabledFeatures) override; + + Return<Status> revokeChallenge() override; + + Return<Status> setFeature(Feature feature, bool enabled, const hidl_vec<uint8_t>& hat, + uint32_t faceId) override; + + Return<void> getFeature(Feature feature, uint32_t faceId, getFeature_cb _hidl_cb) override; + + Return<void> getAuthenticatorId(getAuthenticatorId_cb _hidl_cb) override; + + Return<Status> cancel() override; + + Return<Status> enumerate() override; + + Return<Status> remove(uint32_t faceId) override; + + Return<Status> authenticate(uint64_t operationId) override; + + Return<Status> userActivity() override; + + Return<Status> resetLockout(const hidl_vec<uint8_t>& hat) override; + + // Methods from ::android::hardware::biometrics::face::V1_1::IBiometricsFace follow. + Return<Status> enrollRemotely(const hidl_vec<uint8_t>& hat, uint32_t timeoutSec, + const hidl_vec<Feature>& disabledFeatures) override; + + private: + std::mt19937 mRandom; + int32_t mUserId; + sp<IBiometricsFaceClientCallback> mClientCallback; +}; + +} // namespace android::hardware::biometrics::face::implementation diff --git a/biometrics/face/1.1/default/android.hardware.biometrics.face@1.1-service.rc b/biometrics/face/1.1/default/android.hardware.biometrics.face@1.1-service.rc new file mode 100644 index 0000000000..687e2d8c86 --- /dev/null +++ b/biometrics/face/1.1/default/android.hardware.biometrics.face@1.1-service.rc @@ -0,0 +1,10 @@ +service vendor.face-hal-1-1-default /vendor/bin/hw/android.hardware.biometrics.face@1.1-service.example + # "class hal" causes a race condition on some devices due to files created + # in /data. As a workaround, postpone startup until later in boot once + # /data is mounted. + class late_start + user system + group system + writepid /dev/cpuset/foreground/tasks + capabilities SYS_NICE + rlimit rtprio 10 10 diff --git a/biometrics/face/1.1/default/manifest_face_default.xml b/biometrics/face/1.1/default/manifest_face_default.xml new file mode 100644 index 0000000000..ec71d9c92b --- /dev/null +++ b/biometrics/face/1.1/default/manifest_face_default.xml @@ -0,0 +1,11 @@ +<manifest version="2.0" type="device"> + <hal format="hidl"> + <name>android.hardware.biometrics.face</name> + <transport>hwbinder</transport> + <version>1.1</version> + <interface> + <name>IBiometricsFace</name> + <instance>default</instance> + </interface> + </hal> +</manifest> diff --git a/biometrics/face/1.1/default/service.cpp b/biometrics/face/1.1/default/service.cpp new file mode 100644 index 0000000000..344bdb99b4 --- /dev/null +++ b/biometrics/face/1.1/default/service.cpp @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#define LOG_TAG "android.hardware.biometrics.face@1.1-service" + +#include <android/hardware/biometrics/face/1.0/types.h> +#include <android/hardware/biometrics/face/1.1/IBiometricsFace.h> +#include <android/log.h> +#include <hidl/HidlSupport.h> +#include <hidl/HidlTransportSupport.h> +#include "BiometricsFace.h" + +using android::sp; +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; +using android::hardware::biometrics::face::implementation::BiometricsFace; +using android::hardware::biometrics::face::V1_1::IBiometricsFace; + +int main() { + ALOGI("BiometricsFace HAL is being started."); + + configureRpcThreadpool(1, true /*callerWillJoin*/); + + android::sp<IBiometricsFace> face = new BiometricsFace(); + const android::status_t status = face->registerAsService(); + + if (status != android::OK) { + ALOGE("Error starting the BiometricsFace HAL."); + return 1; + } + + ALOGI("BiometricsFace HAL has started successfully."); + joinRpcThreadpool(); + + ALOGI("BiometricsFace HAL is terminating."); + return 1; // should never get here +} |