From 5e70da34b735769d3eb431bfc281c814b30b3b6a Mon Sep 17 00:00:00 2001 From: Sebastiano Barezzi Date: Mon, 9 May 2022 01:34:54 +0200 Subject: [PATCH] Spacewar: Implement UDFPS handler Change-Id: I7afff305140639d38ebb8bc51fbe790a1636db9e --- udfps/Android.bp | 17 ++++++++ udfps/UdfpsHandler.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 udfps/Android.bp create mode 100644 udfps/UdfpsHandler.cpp diff --git a/udfps/Android.bp b/udfps/Android.bp new file mode 100644 index 0000000..4f5ce70 --- /dev/null +++ b/udfps/Android.bp @@ -0,0 +1,17 @@ +// +// Copyright (C) 2023 The LineageOS Project +// +// SPDX-License-Identifier: Apache-2.0 +// + +cc_library { + name: "libudfpshandler", + vendor: true, + srcs: ["UdfpsHandler.cpp"], + shared_libs: [ + "libbase", + ], + header_libs: [ + "//hardware/nothing:nothingfingerprint_headers", + ], +} diff --git a/udfps/UdfpsHandler.cpp b/udfps/UdfpsHandler.cpp new file mode 100644 index 0000000..628083f --- /dev/null +++ b/udfps/UdfpsHandler.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2023 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define LOG_TAG "UdfpsHandler.nothing_Spacewar" + +#include "UdfpsHandler.h" + +#include +#include +#include +#include +#include + +#define FOD_UI_PATH "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/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 seek fd, err: " << rc; + return false; + } + + return c != '0'; +} + +class NothingUdfpsHander : public UdfpsHandler { + public: + void init(fingerprint_device_t *device) { + mDevice = device; + + 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; + } + + mDevice->goodixExtCmd(mDevice, readBool(fd) ? 1 : 0, 0); + } + }).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 NothingUdfpsHander(); +} + +static void destroy(UdfpsHandler* handler) { + delete handler; +} + +extern "C" UdfpsHandlerFactory UDFPS_HANDLER_FACTORY = { + .create = create, + .destroy = destroy, +};