aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Barezzi <barezzisebastiano@gmail.com>2022-05-09 01:34:54 +0200
committerdrishal <drishalballaney@gmail.com>2022-09-19 14:12:13 +0530
commitc085da38cedaa4067a0b26c72e9014ca0a902429 (patch)
tree720c50cba1d97b04bb50fbe0982be92d6d4bc0f3
parentee0606806460e6b01120ad0b7ec009fca16a2c9e (diff)
sm8250-common: Implement UDFPS handler
Change-Id: I7afff305140639d38ebb8bc51fbe790a1636db9e
-rw-r--r--kona.mk3
-rw-r--r--udfps/Android.bp17
-rw-r--r--udfps/UdfpsHandler.cpp105
3 files changed, 125 insertions, 0 deletions
diff --git a/kona.mk b/kona.mk
index b902fa0..59e6eb6 100644
--- a/kona.mk
+++ b/kona.mk
@@ -230,6 +230,9 @@ PRODUCT_PACKAGES += \
ifeq ($(TARGET_HAS_FOD),true)
PRODUCT_PACKAGES += \
+ libudfpshandler
+
+PRODUCT_PACKAGES += \
vendor.goodix.hardware.biometrics.fingerprint@2.1.vendor
endif
diff --git a/udfps/Android.bp b/udfps/Android.bp
new file mode 100644
index 0000000..41adbf2
--- /dev/null
+++ b/udfps/Android.bp
@@ -0,0 +1,17 @@
+//
+// Copyright (C) 2022 The LineageOS Project
+//
+// SPDX-License-Identifier: Apache-2.0
+//
+
+cc_library {
+ name: "libudfpshandler",
+ vendor: true,
+ srcs: ["UdfpsHandler.cpp"],
+ shared_libs: [
+ "libbase",
+ ],
+ header_libs: [
+ "//hardware/xiaomi:xiaomifingerprint_headers",
+ ],
+}
diff --git a/udfps/UdfpsHandler.cpp b/udfps/UdfpsHandler.cpp
new file mode 100644
index 0000000..6604dd5
--- /dev/null
+++ b/udfps/UdfpsHandler.cpp
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2022 The LineageOS Project
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#define LOG_TAG "UdfpsHander.xiaomi_kona"
+
+#include "UdfpsHandler.h"
+
+#include <android-base/logging.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <thread>
+#include <unistd.h>
+
+#define COMMAND_NIT 10
+#define PARAM_NIT_FOD 1
+#define PARAM_NIT_NONE 0
+
+static const char* kFodUiPaths[] = {
+ "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/fod_ui",
+ "/sys/devices/platform/soc/soc:qcom,dsi-display/fod_ui",
+};
+
+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';
+}
+
+class XiaomiKonaUdfpsHander : public UdfpsHandler {
+ public:
+ void init(fingerprint_device_t *device) {
+ mDevice = device;
+
+ std::thread([this]() {
+ int fd;
+ for (auto& path : kFodUiPaths) {
+ fd = open(path, O_RDONLY);
+ if (fd >= 0) {
+ break;
+ }
+ }
+
+ 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;
+ }
+
+ mDevice->extCmd(mDevice, COMMAND_NIT,
+ readBool(fd) ? PARAM_NIT_FOD : PARAM_NIT_NONE);
+ }
+ }).detach();
+ }
+
+ void onFingerDown(uint32_t /*x*/, uint32_t /*y*/, float /*minor*/, float /*major*/) {
+ // nothing
+ }
+
+ void onFingerUp() {
+ // nothing
+ }
+ private:
+ fingerprint_device_t *mDevice;
+};
+
+static UdfpsHandler* create() {
+ return new XiaomiKonaUdfpsHander();
+}
+
+static void destroy(UdfpsHandler* handler) {
+ delete handler;
+}
+
+extern "C" UdfpsHandlerFactory UDFPS_HANDLER_FACTORY = {
+ .create = create,
+ .destroy = destroy,
+};