114 lines
3.6 KiB
Diff
114 lines
3.6 KiB
Diff
From 0ccf2a04cb307a2bc113d70c8f597d746f061923 Mon Sep 17 00:00:00 2001
|
|
From: Arian <arian.kulmer@web.de>
|
|
Date: Tue, 21 May 2024 13:32:01 +0200
|
|
Subject: [PATCH 11/15] sensors: Implement udfps long press sensor
|
|
|
|
Change-Id: I49773535f47c538b1ff210245109dd63c18d32cb
|
|
---
|
|
sensors/Sensor.cpp | 34 ++++++++++++++++++++++++++++++++++
|
|
sensors/Sensor.h | 17 +++++++++++++++++
|
|
sensors/SensorsSubHal.cpp | 7 ++++++-
|
|
3 files changed, 57 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/sensors/Sensor.cpp b/sensors/Sensor.cpp
|
|
index ea5f00e..646e852 100644
|
|
--- a/sensors/Sensor.cpp
|
|
+++ b/sensors/Sensor.cpp
|
|
@@ -368,6 +368,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/Sensor.h b/sensors/Sensor.h
|
|
index 31dbbc1..91c835e 100644
|
|
--- a/sensors/Sensor.h
|
|
+++ b/sensors/Sensor.h
|
|
@@ -124,6 +124,23 @@ class SysfsPollingOneShotSensor : public OneShotSensor {
|
|
int mPollFd;
|
|
};
|
|
|
|
+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<SensorType>(static_cast<int32_t>(SensorType::DEVICE_PRIVATE_BASE) +
|
|
+ 1)) {}
|
|
+ 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/SensorsSubHal.cpp b/sensors/SensorsSubHal.cpp
|
|
index 6cbcb56..8522213 100644
|
|
--- a/sensors/SensorsSubHal.cpp
|
|
+++ b/sensors/SensorsSubHal.cpp
|
|
@@ -17,6 +17,7 @@
|
|
#include "SensorsSubHal.h"
|
|
|
|
#include <android/hardware/sensors/2.1/types.h>
|
|
+#include <cutils/properties.h>
|
|
#include <log/log.h>
|
|
|
|
using ::android::hardware::sensors::V2_1::implementation::ISensorsSubHal;
|
|
@@ -32,7 +33,11 @@ namespace implementation {
|
|
using ::android::hardware::Void;
|
|
using ::android::hardware::sensors::V2_0::implementation::ScopedWakelock;
|
|
|
|
-SensorsSubHal::SensorsSubHal() : mCallback(nullptr), mNextHandle(1) {}
|
|
+SensorsSubHal::SensorsSubHal() : mCallback(nullptr), mNextHandle(1) {
|
|
+ if (property_get_bool("ro.vendor.sensors.xiaomi.udfps", false)) {
|
|
+ AddSensor<UdfpsSensor>();
|
|
+ }
|
|
+}
|
|
|
|
Return<void> SensorsSubHal::getSensorsList_2_1(ISensors::getSensorsList_2_1_cb _hidl_cb) {
|
|
std::vector<SensorInfo> sensors;
|
|
--
|
|
2.25.1
|
|
|