From 904a71bb023bc725355b32b6f364c6b5ffac9bb4 Mon Sep 17 00:00:00 2001 From: electimon Date: Sun, 7 Jan 2024 10:51:54 +0000 Subject: [PATCH] bangkk: fingerprint: Switch to IOCTL for HBM * On newer moto kernels it is possible to send a SET_PANEL_FEATURE ioctl to /dev/dri/card0 to set a panel feature such as HBM. Motorola has extended the HBM logic to allow FOD HBM to be set in additional to regular HBM. This is done by sending "2" with the HBM id through the ioctl. * Utilize the API provided by Egistec provides via vendor.egistec.hardware.fingerprint to send commands to the internal handler, this allows us to send the finger is on or off the sensor message directly to the HAL. Change-Id: I06ace29567900779e63b9826862964d20b267be6 --- Android.bp | 3 - fingerprint/Android.bp | 3 +- fingerprint/BiometricsFingerprint.cpp | 110 ++++++++++++++------------ fingerprint/BiometricsFingerprint.h | 10 +-- 4 files changed, 67 insertions(+), 59 deletions(-) diff --git a/Android.bp b/Android.bp index 25aa1fe..2805bde 100644 --- a/Android.bp +++ b/Android.bp @@ -4,7 +4,4 @@ // soong_namespace { - imports: [ - "hardware/motorola", - ], } diff --git a/fingerprint/Android.bp b/fingerprint/Android.bp index 9795524..1e6f65a 100644 --- a/fingerprint/Android.bp +++ b/fingerprint/Android.bp @@ -17,6 +17,7 @@ cc_binary { "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", + "vendor.egistec.hardware.fingerprint@4.0", ], + header_libs: ["generated_kernel_headers"] } diff --git a/fingerprint/BiometricsFingerprint.cpp b/fingerprint/BiometricsFingerprint.cpp index 04b34e2..c28e91a 100644 --- a/fingerprint/BiometricsFingerprint.cpp +++ b/fingerprint/BiometricsFingerprint.cpp @@ -17,19 +17,44 @@ #include "BiometricsFingerprint.h" +#include #include +#include +#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 +enum HBM_STATE { OFF = 0, ON = 2 }; -#define FOD_UI_PATH "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_ui" +void setHbmState(int state) { + struct panel_param_info param_info; + int32_t node = open("/dev/dri/card0", O_RDWR); + int32_t ret = 0; + + if (node < 0) { + LOG(ERROR) << "Failed to get card0!"; + return; + } + + param_info.param_idx = PARAM_HBM; + param_info.value = state; + + ret = ioctl(node, DRM_IOCTL_SET_PANEL_FEATURE, ¶m_info); + if (ret < 0) { + LOG(ERROR) << "IOCTL call failed with ret = " << ret; + } else { + LOG(INFO) << "HBM state set successfully. New state: " << state; + } + + close(node); +} namespace android { namespace hardware { @@ -38,52 +63,9 @@ namespace fingerprint { namespace V2_3 { namespace implementation { -static bool readBool(int fd) { - char c; - int rc; - - rc = lseek(fd, 0, SEEK_SET); - if (rc) { - LOG(ERROR) << "failed to seek fd, err: " << rc; - return false; - } - - rc = read(fd, &c, sizeof(char)); - if (rc != 1) { - LOG(ERROR) << "failed to read bool from fd, err: " << rc; - return false; - } - - return c != '0'; -} - BiometricsFingerprint::BiometricsFingerprint() { biometrics_2_1_service = IBiometricsFingerprint_2_1::getService(); - mMotoFingerprint = IMotoFingerPrint::getService(); - - std::thread([this]() { - int fd = open(FOD_UI_PATH, O_RDONLY); - if (fd < 0) { - LOG(ERROR) << "failed to open fd, err: " << fd; - return; - } - - struct pollfd fodUiPoll = { - .fd = fd, - .events = POLLERR | POLLPRI, - .revents = 0, - }; - - while (true) { - int rc = poll(&fodUiPoll, 1, -1); - if (rc < 0) { - LOG(ERROR) << "failed to poll fd, err: " << rc; - continue; - } - mMotoFingerprint->sendFodEvent(readBool(fd) ? NOTIFY_FINGER_DOWN : NOTIFY_FINGER_UP, {}, - [](IMotFodEventResult, const hidl_vec&) {}); - } - }).detach(); + rbs_4_0_service = IBiometricsFingerprintRbs::getService(); } Return BiometricsFingerprint::setNotify( @@ -109,6 +91,7 @@ Return BiometricsFingerprint::getAuthenticatorId() { } Return BiometricsFingerprint::cancel() { + setHbmState(OFF); return biometrics_2_1_service->cancel(); } @@ -126,6 +109,7 @@ Return BiometricsFingerprint::setActiveGroup(uint32_t gid, } Return BiometricsFingerprint::authenticate(uint64_t operationId, uint32_t gid) { + setHbmState(OFF); return biometrics_2_1_service->authenticate(operationId, gid); } @@ -134,10 +118,36 @@ Return BiometricsFingerprint::isUdfps(uint32_t) { } Return BiometricsFingerprint::onFingerDown(uint32_t, uint32_t, float, float) { + setHbmState(ON); + extraApiWrapper(101); + + std::thread([this]() { + std::this_thread::sleep_for(std::chrono::milliseconds(200)); + BiometricsFingerprint::onFingerUp(); + }).detach(); + return Void(); } Return BiometricsFingerprint::onFingerUp() { + setHbmState(OFF); + extraApiWrapper(102); + return Void(); +} + +Return BiometricsFingerprint::extraApiWrapper(int cidValue) { + int cid[1] = {cidValue}; + + // Create a std::vector to store the data from 'cid' + std::vector cid_data(reinterpret_cast(cid), + reinterpret_cast(cid) + sizeof(cid)); + + // Create the hidl_vec from the std::vector + ::android::hardware::hidl_vec hidl_cid = cid_data; + + // Call extra_api with the correct input buffer and an empty lambda callback + rbs_4_0_service->extra_api(7, hidl_cid, [](const ::android::hardware::hidl_vec&) {}); + return Void(); } diff --git a/fingerprint/BiometricsFingerprint.h b/fingerprint/BiometricsFingerprint.h index 7abf9af..3b88b63 100644 --- a/fingerprint/BiometricsFingerprint.h +++ b/fingerprint/BiometricsFingerprint.h @@ -18,9 +18,9 @@ #define ANDROID_HARDWARE_BIOMETRICS_FINGERPRINT_V2_3_BIOMETRICSFINGERPRINT_H #include -#include #include #include +#include namespace android { namespace hardware { @@ -40,9 +40,7 @@ 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; +using ::vendor::egistec::hardware::fingerprint::V4_0::IBiometricsFingerprintRbs; struct BiometricsFingerprint : public IBiometricsFingerprint { BiometricsFingerprint(); @@ -65,9 +63,11 @@ struct BiometricsFingerprint : public IBiometricsFingerprint { Return onFingerDown(uint32_t x, uint32_t y, float minor, float major) override; Return onFingerUp() override; + Return extraApiWrapper(int cidValue); + private: sp biometrics_2_1_service; - sp mMotoFingerprint; + sp rbs_4_0_service; }; } // namespace implementation