From 4b8b52d599e1a5d2eb797fe3149503a7e7111420 Mon Sep 17 00:00:00 2001 From: Arian Date: Tue, 21 May 2024 13:32:01 +0200 Subject: [PATCH] sensors: Implement udfps long press sensor Change-Id: I49773535f47c538b1ff210245109dd63c18d32cb --- sensors/v2/Sensor.cpp | 34 ++++++++++++++++++++++++++++++++++ sensors/v2/Sensor.h | 17 +++++++++++++++++ sensors/v2/SensorsSubHal.cpp | 4 ++++ 3 files changed, 55 insertions(+) diff --git a/sensors/v2/Sensor.cpp b/sensors/v2/Sensor.cpp index ed3ff71..cf9a277 100644 --- a/sensors/v2/Sensor.cpp +++ b/sensors/v2/Sensor.cpp @@ -361,6 +361,40 @@ bool SysfsPollingOneShotSensor::readFd(const int fd) { return readBool(fd, true /* seek */); } +void UdfpsSensor::fillEventData(Event& event) { + event.u.data[0] = mScreenX; + event.u.data[1] = mScreenY; +} + +bool UdfpsSensor::readFd(const int fd) { + char buffer[512]; + int state = 0; + int rc; + + rc = lseek(fd, 0, SEEK_SET); + if (rc < 0) { + ALOGE("failed to seek: %d", rc); + return false; + } + rc = read(fd, &buffer, sizeof(buffer)); + if (rc < 0) { + ALOGE("failed to read state: %d", rc); + return false; + } + rc = sscanf(buffer, "%d,%d,%d", &mScreenX, &mScreenY, &state); + if (rc == 1) { + // If fod_press_status contains only one value, + // assume that just reports the state + state = mScreenX; + mScreenX = 0; + mScreenY = 0; + } else if (rc < 3) { + ALOGE("failed to parse fp state: %d", rc); + return false; + } + return state > 0; +} + } // namespace implementation } // namespace subhal } // namespace V2_1 diff --git a/sensors/v2/Sensor.h b/sensors/v2/Sensor.h index 869f14a..02c0c73 100644 --- a/sensors/v2/Sensor.h +++ b/sensors/v2/Sensor.h @@ -143,6 +143,23 @@ class SingleTapSensor : public SysfsPollingOneShotSensor { 2)) {} }; +class UdfpsSensor : public SysfsPollingOneShotSensor { + public: + UdfpsSensor(int32_t sensorHandle, ISensorsEventCallback* callback) + : SysfsPollingOneShotSensor( + sensorHandle, callback, "/sys/class/touch/touch_dev/fod_press_status", + "/sys/class/touch/touch_dev/fod_longpress_gesture_enabled", "UDFPS Sensor", + "org.lineageos.sensor.udfps", + static_cast(static_cast(SensorType::DEVICE_PRIVATE_BASE) + + 3)) {} + virtual void fillEventData(Event& event); + virtual bool readFd(const int fd); + + private: + int mScreenX; + int mScreenY; +}; + } // namespace implementation } // namespace subhal } // namespace V2_1 diff --git a/sensors/v2/SensorsSubHal.cpp b/sensors/v2/SensorsSubHal.cpp index bb125b5..b1d499c 100644 --- a/sensors/v2/SensorsSubHal.cpp +++ b/sensors/v2/SensorsSubHal.cpp @@ -17,6 +17,7 @@ #include "SensorsSubHal.h" #include +#include #include using ::android::hardware::sensors::V2_1::implementation::ISensorsSubHal; @@ -39,6 +40,9 @@ SensorsSubHal::SensorsSubHal() : mCallback(nullptr), mNextHandle(1) { if (property_get_bool("ro.vendor.sensors.xiaomi.single_tap", false)) { AddSensor(); } + if (property_get_bool("ro.vendor.sensors.xiaomi.udfps", false)) { + AddSensor(); + } } Return SensorsSubHal::getSensorsList_2_1(ISensors::getSensorsList_2_1_cb _hidl_cb) {