From 22c90c7e61406b7aec3f9cf626e1a5ce02c48ede Mon Sep 17 00:00:00 2001 From: Erfan Abdi Date: Thu, 26 Sep 2019 19:40:20 +0330 Subject: [PATCH] sdm710-common: Write Fingerprint HAL Adapter vendor.oppo.hardware.biometrics.fingerprint@2.1 -> android.hardware.biometrics.fingerprint@2.1 Change-Id: Id33db73425bb5e92ef5c45e2f8d40fa462942af3 Signed-off-by: SagarMakhar --- fingerprint/Android.bp | 24 +++ fingerprint/BiometricsFingerprint.cpp | 180 ++++++++++++++++++ fingerprint/BiometricsFingerprint.h | 77 ++++++++ ...s.fingerprint@2.1-service.realme_sdm710.rc | 8 + fingerprint/service.cpp | 61 ++++++ framework_manifest.xml | 9 + sdm710.mk | 7 + 7 files changed, 366 insertions(+) create mode 100644 fingerprint/Android.bp create mode 100644 fingerprint/BiometricsFingerprint.cpp create mode 100644 fingerprint/BiometricsFingerprint.h create mode 100644 fingerprint/android.hardware.biometrics.fingerprint@2.1-service.realme_sdm710.rc create mode 100644 fingerprint/service.cpp diff --git a/fingerprint/Android.bp b/fingerprint/Android.bp new file mode 100644 index 0000000..db26560 --- /dev/null +++ b/fingerprint/Android.bp @@ -0,0 +1,24 @@ +cc_binary { + name: "android.hardware.biometrics.fingerprint@2.1-service.realme_sdm710", + defaults: ["hidl_defaults"], + init_rc: ["android.hardware.biometrics.fingerprint@2.1-service.realme_sdm710.rc"], + relative_install_path: "hw", + srcs: [ + "BiometricsFingerprint.cpp", + "service.cpp", + ], + cflags: [ + "-Wno-unused-parameter", + ], + shared_libs: [ + "libcutils", + "liblog", + "libhidlbase", + "libhidltransport", + "libhardware", + "libutils", + "libbase", + "android.hardware.biometrics.fingerprint@2.1", + "vendor.oppo.hardware.biometrics.fingerprint@2.1", + ], +} diff --git a/fingerprint/BiometricsFingerprint.cpp b/fingerprint/BiometricsFingerprint.cpp new file mode 100644 index 0000000..43d1779 --- /dev/null +++ b/fingerprint/BiometricsFingerprint.cpp @@ -0,0 +1,180 @@ +/* + * Copyright (C) 2017 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.fingerprint@2.1-service.realme_sdm710" +#define LOG_VERBOSE "android.hardware.biometrics.fingerprint@2.1-service.realme_sdm710" + +#include +#include +#include "BiometricsFingerprint.h" + +#include +#include + +namespace android { +namespace hardware { +namespace biometrics { +namespace fingerprint { +namespace V2_1 { +namespace implementation { + +BiometricsFingerprint::BiometricsFingerprint() { + mOppoBiometricsFingerprint = vendor::oppo::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprint::getService(); +} + +class OppoClientCallback : public vendor::oppo::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprintClientCallback { +public: + OppoClientCallback(sp clientCallback) : mClientCallback(clientCallback) {} + Return onEnrollResult(uint64_t deviceId, uint32_t fingerId, + uint32_t groupId, uint32_t remaining) { + return mClientCallback->onEnrollResult(deviceId, fingerId, groupId, remaining); + } + + Return onAcquired(uint64_t deviceId, vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo acquiredInfo, + int32_t vendorCode) { + return mClientCallback->onAcquired(deviceId, OppoToAOSPFingerprintAcquiredInfo(acquiredInfo), vendorCode); + } + + Return onAuthenticated(uint64_t deviceId, uint32_t fingerId, uint32_t groupId, + const hidl_vec& token) { + return mClientCallback->onAuthenticated(deviceId, fingerId, groupId, token); + } + + Return onError(uint64_t deviceId, vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintError error, int32_t vendorCode) { + return mClientCallback->onError(deviceId, OppoToAOSPFingerprintError(error), vendorCode); + } + + Return onRemoved(uint64_t deviceId, uint32_t fingerId, uint32_t groupId, + uint32_t remaining) { + return mClientCallback->onRemoved(deviceId, fingerId, groupId, remaining); + } + + Return onEnumerate(uint64_t deviceId, uint32_t fingerId, uint32_t groupId, + uint32_t remaining) { + return mClientCallback->onEnumerate(deviceId, fingerId, groupId, remaining); + } + + Return onTouchUp(uint64_t deviceId) { return Void(); } + Return onTouchDown(uint64_t deviceId) { return Void(); } + Return onSyncTemplates(uint64_t deviceId, const hidl_vec& fingerId, uint32_t remaining) { return Void(); } + Return onFingerprintCmd(int32_t deviceId, const hidl_vec& groupId, uint32_t remaining) { return Void(); } + Return onImageInfoAcquired(uint32_t type, uint32_t quality, uint32_t match_score) { return Void(); } + Return onMonitorEventTriggered(uint32_t type, const hidl_string& data) { return Void(); } + Return onEngineeringInfoUpdated(uint32_t length, const hidl_vec& keys, const hidl_vec& values) { return Void(); } + +private: + sp mClientCallback; + + Return OppoToAOSPFingerprintAcquiredInfo(vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo info) { + switch(info) { + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_GOOD: return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_GOOD; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_PARTIAL: return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_PARTIAL; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_INSUFFICIENT: return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_INSUFFICIENT; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_IMAGER_DIRTY: return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_IMAGER_DIRTY; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_TOO_SLOW: return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_TOO_SLOW; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_TOO_FAST: return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_TOO_FAST; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_VENDOR: return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_VENDOR; + default: + return android::hardware::biometrics::fingerprint::V2_1::FingerprintAcquiredInfo::ACQUIRED_GOOD; + } + } + + Return OppoToAOSPFingerprintError(vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintError error) { + switch(error) { + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_NO_ERROR: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_NO_ERROR; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_HW_UNAVAILABLE: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_HW_UNAVAILABLE; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_UNABLE_TO_PROCESS: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_UNABLE_TO_PROCESS; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_TIMEOUT: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_TIMEOUT; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_NO_SPACE: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_NO_SPACE; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_CANCELED: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_CANCELED; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_UNABLE_TO_REMOVE: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_UNABLE_TO_REMOVE; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_LOCKOUT: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_LOCKOUT; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_VENDOR: return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_VENDOR; + default: + return android::hardware::biometrics::fingerprint::V2_1::FingerprintError::ERROR_NO_ERROR; + } + } +}; + +Return BiometricsFingerprint::setNotify( + const sp& clientCallback) { + mOppoClientCallback = new OppoClientCallback(clientCallback); + return mOppoBiometricsFingerprint->setNotify(mOppoClientCallback); +} + +Return BiometricsFingerprint::OppoToAOSPRequestStatus(vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus req) { + switch(req) { + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_UNKNOWN: return RequestStatus::SYS_UNKNOWN; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_OK: return RequestStatus::SYS_OK; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_ENOENT: return RequestStatus::SYS_ENOENT; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_EINTR: return RequestStatus::SYS_EINTR; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_EIO: return RequestStatus::SYS_EIO; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_EAGAIN: return RequestStatus::SYS_EAGAIN; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_ENOMEM: return RequestStatus::SYS_ENOMEM; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_EACCES: return RequestStatus::SYS_EACCES; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_EFAULT: return RequestStatus::SYS_EFAULT; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_EBUSY: return RequestStatus::SYS_EBUSY; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_EINVAL: return RequestStatus::SYS_EINVAL; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_ENOSPC: return RequestStatus::SYS_ENOSPC; + case vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus::SYS_ETIMEDOUT: return RequestStatus::SYS_ETIMEDOUT; + default: + return RequestStatus::SYS_UNKNOWN; + } +} + +Return BiometricsFingerprint::preEnroll() { + return mOppoBiometricsFingerprint->preEnroll(); +} + +Return BiometricsFingerprint::enroll(const hidl_array& hat, + uint32_t gid, uint32_t timeoutSec) { + return OppoToAOSPRequestStatus(mOppoBiometricsFingerprint->enroll(hat, gid, timeoutSec)); +} + +Return BiometricsFingerprint::postEnroll() { + return OppoToAOSPRequestStatus(mOppoBiometricsFingerprint->postEnroll()); +} + +Return BiometricsFingerprint::getAuthenticatorId() { + return mOppoBiometricsFingerprint->getAuthenticatorId(); +} + +Return BiometricsFingerprint::cancel() { + return OppoToAOSPRequestStatus(mOppoBiometricsFingerprint->cancel()); +} + +Return BiometricsFingerprint::enumerate() { + return OppoToAOSPRequestStatus(mOppoBiometricsFingerprint->enumerate()); +} + +Return BiometricsFingerprint::remove(uint32_t gid, uint32_t fid) { + return OppoToAOSPRequestStatus(mOppoBiometricsFingerprint->remove(gid, fid)); +} + +Return BiometricsFingerprint::setActiveGroup(uint32_t gid, + const hidl_string& storePath) { + return OppoToAOSPRequestStatus(mOppoBiometricsFingerprint->setActiveGroup(gid, storePath)); +} + +Return BiometricsFingerprint::authenticate(uint64_t operationId, uint32_t gid) { + return OppoToAOSPRequestStatus(mOppoBiometricsFingerprint->authenticate(operationId, gid)); +} + +} // namespace implementation +} // namespace V2_1 +} // namespace fingerprint +} // namespace biometrics +} // namespace hardware +} // namespace android diff --git a/fingerprint/BiometricsFingerprint.h b/fingerprint/BiometricsFingerprint.h new file mode 100644 index 0000000..ae7dd3b --- /dev/null +++ b/fingerprint/BiometricsFingerprint.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2017 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. + */ + +#ifndef ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_1_BIOMETRICSFINGERPRINT_H +#define ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_1_BIOMETRICSFINGERPRINT_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace biometrics { +namespace fingerprint { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprint; +using ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprintClientCallback; +using ::android::hardware::biometrics::fingerprint::V2_1::RequestStatus; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; +using ::android::hardware::hidl_string; +using ::android::OK; +using ::android::sp; +using ::android::status_t; + +struct BiometricsFingerprint : public IBiometricsFingerprint { +public: + BiometricsFingerprint(); + + // Methods from ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprint follow. + Return setNotify(const sp& clientCallback) override; + Return preEnroll() override; + Return enroll(const hidl_array& hat, uint32_t gid, uint32_t timeoutSec) override; + Return postEnroll() override; + Return getAuthenticatorId() override; + Return cancel() override; + Return enumerate() override; + Return remove(uint32_t gid, uint32_t fid) override; + Return setActiveGroup(uint32_t gid, const hidl_string& storePath) override; + Return authenticate(uint64_t operationId, uint32_t gid) override; + +private: + sp mOppoBiometricsFingerprint; + sp mOppoClientCallback; + static Return OppoToAOSPRequestStatus(vendor::oppo::hardware::biometrics::fingerprint::V2_1::RequestStatus req); +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace fingerprint +} // namespace biometrics +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_1_BIOMETRICSFINGERPRINT_H diff --git a/fingerprint/android.hardware.biometrics.fingerprint@2.1-service.realme_sdm710.rc b/fingerprint/android.hardware.biometrics.fingerprint@2.1-service.realme_sdm710.rc new file mode 100644 index 0000000..8afd669 --- /dev/null +++ b/fingerprint/android.hardware.biometrics.fingerprint@2.1-service.realme_sdm710.rc @@ -0,0 +1,8 @@ +service fps_hal.realme_sdm710 /system/bin/hw/android.hardware.biometrics.fingerprint@2.1-service.realme_sdm710 + # "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 input uhid + writepid /dev/cpuset/system-background/tasks diff --git a/fingerprint/service.cpp b/fingerprint/service.cpp new file mode 100644 index 0000000..4b7623e --- /dev/null +++ b/fingerprint/service.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2017 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.fingerprint@2.1-service.realme_sdm710" + +#include +#include + +#include "BiometricsFingerprint.h" + +using android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprint; +using android::hardware::biometrics::fingerprint::V2_1::implementation::BiometricsFingerprint; +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; +using android::OK; +using android::sp; +using android::status_t; + +int main() { + sp biometricsFingerprint; + status_t status; + + LOG(INFO) << "Fingerprint HAL Adapter service is starting."; + + biometricsFingerprint = new BiometricsFingerprint(); + if (biometricsFingerprint == nullptr) { + LOG(ERROR) << "Can not create an instance of Fingerprint HAL Adapter BiometricsFingerprint Iface, exiting."; + goto shutdown; + } + + configureRpcThreadpool(1, true /*callerWillJoin*/); + + status = biometricsFingerprint->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Could not register service for Fingerprint HAL Adapter BiometricsFingerprint Iface (" + << status << ")"; + goto shutdown; + } + + LOG(INFO) << "Fingerprint HAL Adapter service is ready."; + joinRpcThreadpool(); + // Should not pass this line + +shutdown: + // In normal operation, we don't expect the thread pool to shutdown + LOG(ERROR) << "Fingerprint HAL Adapter service is shutting down."; + return 1; +} diff --git a/framework_manifest.xml b/framework_manifest.xml index 6544df3..8a817f6 100644 --- a/framework_manifest.xml +++ b/framework_manifest.xml @@ -35,4 +35,13 @@ default + + android.hardware.biometrics.fingerprint + hwbinder + 2.1 + + IBiometricsFingerprint + default + + diff --git a/sdm710.mk b/sdm710.mk index a038d8e..0eebe32 100644 --- a/sdm710.mk +++ b/sdm710.mk @@ -45,6 +45,13 @@ PRODUCT_PACKAGES += \ libvulkan \ vendor.display.config@1.0 +# Fingerprint +PRODUCT_PACKAGES += \ + android.hardware.biometrics.fingerprint@2.1-service.realme_sdm710 + +PRODUCT_COPY_FILES += \ + frameworks/native/data/etc/android.hardware.fingerprint.xml:system/etc/permissions/android.hardware.fingerprint.xml + # Doze PRODUCT_PACKAGES += \ OppoDoze