From da69155588d2db6fbc9c441ece5a1ae9912ebbf1 Mon Sep 17 00:00:00 2001 From: SGCMarkus Date: Wed, 5 Jul 2023 23:18:48 +0200 Subject: [PATCH] rtwo: wrap 2.1 fingerprint service with 2.3 source built --- Android.bp | 1 + device.mk | 4 + fingerprint/.clang-format | 14 ++ fingerprint/Android.bp | 23 +++ fingerprint/BiometricsFingerprint.cpp | 154 ++++++++++++++++++ fingerprint/BiometricsFingerprint.h | 85 ++++++++++ ...biometrics.fingerprint@2.3-service.rtwo.rc | 11 ++ ...iometrics.fingerprint@2.3-service.rtwo.xml | 20 +++ fingerprint/service.cpp | 49 ++++++ 9 files changed, 361 insertions(+) create mode 100644 fingerprint/.clang-format 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.3-service.rtwo.rc create mode 100644 fingerprint/android.hardware.biometrics.fingerprint@2.3-service.rtwo.xml create mode 100644 fingerprint/service.cpp diff --git a/Android.bp b/Android.bp index 9515b25..4532942 100644 --- a/Android.bp +++ b/Android.bp @@ -1,2 +1,3 @@ soong_namespace { + imports: ["device/motorola/sm8550-common"], } diff --git a/device.mk b/device.mk index 6ad8bb1..bea66d1 100644 --- a/device.mk +++ b/device.mk @@ -59,6 +59,10 @@ PRODUCT_COPY_FILES += \ $(LOCAL_PATH)/audio/usecaseKvManager_prc.xml:$(TARGET_COPY_OUT_VENDOR)/etc/usecaseKvManager_prc.xml \ $(LOCAL_PATH)/audio/usecaseKvManager_tmo.xml:$(TARGET_COPY_OUT_VENDOR)/etc/usecaseKvManager_tmo.xml +# Fingerprint +PRODUCT_PACKAGES += \ + android.hardware.biometrics.fingerprint@2.3-service.rtwo + # Init $(foreach f,$(wildcard $(LOCAL_PATH)/rootdir/etc/init/hw/*.rc),\ $(eval PRODUCT_COPY_FILES += $(f):$(TARGET_COPY_OUT_VENDOR)/etc/init/hw/$(notdir $f))) diff --git a/fingerprint/.clang-format b/fingerprint/.clang-format new file mode 100644 index 0000000..5d8d909 --- /dev/null +++ b/fingerprint/.clang-format @@ -0,0 +1,14 @@ +BasedOnStyle: Google +AccessModifierOffset: -2 +AllowShortFunctionsOnASingleLine: Inline +ColumnLimit: 99 +CommentPragmas: NOLINT:.* +DerivePointerAlignment: false +IndentWidth: 4 +PointerAlignment: Right +TabWidth: 4 +UseTab: Never +PenaltyExcessCharacter: 32 +AllowShortIfStatementsOnASingleLine: false +SpacesBeforeTrailingComments: 2 + diff --git a/fingerprint/Android.bp b/fingerprint/Android.bp new file mode 100644 index 0000000..9145ca0 --- /dev/null +++ b/fingerprint/Android.bp @@ -0,0 +1,23 @@ +cc_binary { + name: "android.hardware.biometrics.fingerprint@2.3-service.rtwo", + defaults: ["hidl_defaults"], + init_rc: ["android.hardware.biometrics.fingerprint@2.3-service.rtwo.rc"], + vintf_fragments: ["android.hardware.biometrics.fingerprint@2.3-service.rtwo.xml"], + relative_install_path: "hw", + srcs: [ + "service.cpp", + "BiometricsFingerprint.cpp", + ], + vendor: true, + shared_libs: [ + "libbase", + "libhidlbase", + "libMotoPanelFeature", + "liblog", + "libutils", + "android.hardware.biometrics.fingerprint@2.1", + "android.hardware.biometrics.fingerprint@2.2", + "android.hardware.biometrics.fingerprint@2.3", + "com.motorola.hardware.biometric.fingerprint@1.0", + ], +} diff --git a/fingerprint/BiometricsFingerprint.cpp b/fingerprint/BiometricsFingerprint.cpp new file mode 100644 index 0000000..8b40d63 --- /dev/null +++ b/fingerprint/BiometricsFingerprint.cpp @@ -0,0 +1,154 @@ +/* + * 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 "fingerprint@2.3-service.rtwo" + +#include "BiometricsFingerprint.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#define NOTIFY_FINGER_UP IMotFodEventType::FINGER_UP +#define NOTIFY_FINGER_DOWN IMotFodEventType::FINGER_DOWN + +namespace android { +namespace hardware { +namespace biometrics { +namespace fingerprint { +namespace V2_3 { +namespace implementation { + +void setFodHbm(bool status) { + setFodHbmState(status); +} + +void BiometricsFingerprint::disableHighBrightFod() { + std::lock_guard lock(mSetHbmFodMutex); + + if (!hbmFodEnabled) + return; + + mMotoFingerprint->sendFodEvent(NOTIFY_FINGER_UP, {}, + [](IMotFodEventResult, const hidl_vec &) {}); + setFodHbm(false); + + hbmFodEnabled = false; +} + +void BiometricsFingerprint::enableHighBrightFod() { + std::lock_guard lock(mSetHbmFodMutex); + + if (hbmFodEnabled) + return; + + setFodHbm(true); + mMotoFingerprint->sendFodEvent(NOTIFY_FINGER_DOWN, {}, + [](IMotFodEventResult, const hidl_vec &) {}); + + hbmFodEnabled = true; +} + +BiometricsFingerprint::BiometricsFingerprint() { + biometrics_2_1_service = IBiometricsFingerprint_2_1::getService(); + mMotoFingerprint = IMotoFingerPrint::getService(); + + hbmFodEnabled = false; +} + +Return BiometricsFingerprint::setNotify( + const sp &clientCallback) { + return biometrics_2_1_service->setNotify(clientCallback); +} + +Return BiometricsFingerprint::preEnroll() { + return biometrics_2_1_service->preEnroll(); +} + +Return BiometricsFingerprint::enroll(const hidl_array &hat, + uint32_t gid, uint32_t timeoutSec) { + return biometrics_2_1_service->enroll(hat, gid, timeoutSec); +} + +Return BiometricsFingerprint::postEnroll() { + return biometrics_2_1_service->postEnroll(); +} + +Return BiometricsFingerprint::getAuthenticatorId() { + return biometrics_2_1_service->getAuthenticatorId(); +} + +Return BiometricsFingerprint::cancel() { + auto ret = biometrics_2_1_service->cancel(); + BiometricsFingerprint::onFingerUp(); + return ret; +} + +Return BiometricsFingerprint::enumerate() { + return biometrics_2_1_service->enumerate(); +} + +Return BiometricsFingerprint::remove(uint32_t gid, uint32_t fid) { + return biometrics_2_1_service->remove(gid, fid); +} + +Return BiometricsFingerprint::setActiveGroup(uint32_t gid, + const hidl_string &storePath) { + return biometrics_2_1_service->setActiveGroup(gid, storePath); +} + +Return BiometricsFingerprint::authenticate(uint64_t operationId, uint32_t gid) { + auto ret = biometrics_2_1_service->authenticate(operationId, gid); + BiometricsFingerprint::onFingerUp(); + return ret; +} + +Return BiometricsFingerprint::isUdfps(uint32_t) { + return true; +} + +Return BiometricsFingerprint::onFingerDown(uint32_t, uint32_t, float, float) { + BiometricsFingerprint::enableHighBrightFod(); + + std::thread([this]() { + std::this_thread::sleep_for(std::chrono::milliseconds(200)); + BiometricsFingerprint::onFingerUp(); + }).detach(); + + return Void(); +} + +Return BiometricsFingerprint::onFingerUp() { + BiometricsFingerprint::disableHighBrightFod(); + + return Void(); +} + +} // namespace implementation +} // namespace V2_3 +} // namespace fingerprint +} // namespace biometrics +} // namespace hardware +} // namespace android diff --git a/fingerprint/BiometricsFingerprint.h b/fingerprint/BiometricsFingerprint.h new file mode 100644 index 0000000..a76a20e --- /dev/null +++ b/fingerprint/BiometricsFingerprint.h @@ -0,0 +1,85 @@ +/* + * 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_3_BIOMETRICSFINGERPRINT_H +#define ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_3_BIOMETRICSFINGERPRINT_H + +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace biometrics { +namespace fingerprint { +namespace V2_3 { +namespace implementation { + +using IBiometricsFingerprint_2_1 = + ::android::hardware::biometrics::fingerprint::V2_1::IBiometricsFingerprint; +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::fingerprint::V2_1::IBiometricsFingerprintClientCallback; +using ::android::hardware::biometrics::fingerprint::V2_1::RequestStatus; +using ::com::motorola::hardware::biometric::fingerprint::V1_0::IMotFodEventResult; +using ::com::motorola::hardware::biometric::fingerprint::V1_0::IMotFodEventType; +using ::com::motorola::hardware::biometric::fingerprint::V1_0::IMotoFingerPrint; + +struct BiometricsFingerprint : public IBiometricsFingerprint { + BiometricsFingerprint(); + // Methods from ::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; + + // ::V2_3::IBiometricsFingerprint follow. + Return isUdfps(uint32_t sensorId) override; + Return onFingerDown(uint32_t x, uint32_t y, float minor, float major) override; + Return onFingerUp() override; + + private: + void disableHighBrightFod(); + void enableHighBrightFod(); + + bool hbmFodEnabled; + std::mutex mSetHbmFodMutex; + + sp biometrics_2_1_service; + sp mMotoFingerprint; +}; + +} // namespace implementation +} // namespace V2_3 +} // namespace fingerprint +} // namespace biometrics +} // namespace hardware +} // namespace android +#endif // ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_3_BIOMETRICSFINGERPRINT_H diff --git a/fingerprint/android.hardware.biometrics.fingerprint@2.3-service.rtwo.rc b/fingerprint/android.hardware.biometrics.fingerprint@2.3-service.rtwo.rc new file mode 100644 index 0000000..164f955 --- /dev/null +++ b/fingerprint/android.hardware.biometrics.fingerprint@2.3-service.rtwo.rc @@ -0,0 +1,11 @@ +#on init +# chown system system /sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_hbm + +service fps_hal.rtwo /vendor/bin/hw/android.hardware.biometrics.fingerprint@2.3-service.rtwo + # "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/android.hardware.biometrics.fingerprint@2.3-service.rtwo.xml b/fingerprint/android.hardware.biometrics.fingerprint@2.3-service.rtwo.xml new file mode 100644 index 0000000..40ff58f --- /dev/null +++ b/fingerprint/android.hardware.biometrics.fingerprint@2.3-service.rtwo.xml @@ -0,0 +1,20 @@ + + + android.hardware.biometrics.fingerprint + hwbinder + 2.3 + + IBiometricsFingerprint + default + + + + vendor.goodix.hardware.biometrics.fingerprint + hwbinder + 2.1 + + IGoodixFingerprintDaemon + default + + + diff --git a/fingerprint/service.cpp b/fingerprint/service.cpp new file mode 100644 index 0000000..5cb7a48 --- /dev/null +++ b/fingerprint/service.cpp @@ -0,0 +1,49 @@ +/* + * 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.3-service.rtwo" +#include +#include + +#include "BiometricsFingerprint.h" + +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; + +using android::hardware::biometrics::fingerprint::V2_3::IBiometricsFingerprint; +using android::hardware::biometrics::fingerprint::V2_3::implementation::BiometricsFingerprint; + +using android::OK; +using android::status_t; + +int main() { + android::sp service = new BiometricsFingerprint(); + + configureRpcThreadpool(1, true); + + status_t status = service->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Cannot register Biometrics 2.3 HAL service."; + return 1; + } + + LOG(INFO) << "Biometrics 2.3 HAL service ready."; + + joinRpcThreadpool(); + + LOG(ERROR) << "Biometrics 2.3 HAL service failed to join thread pool."; + return 1; +}