From 727d6834e52d3482107999cbb178d6bb9d42f394 Mon Sep 17 00:00:00 2001 From: Arian Date: Wed, 24 Jul 2024 23:17:19 +0200 Subject: [PATCH] sm8450-common: sensors: Cleanup code and drop unused dependencies Change-Id: I553fb6f441cde1d3a5c4b19e42e3bd696a92bbd3 --- sensors/Android.bp | 6 ------ sensors/NonUiNotifier.cpp | 41 +++++++++++++++------------------------ 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/sensors/Android.bp b/sensors/Android.bp index b45058e..8ef9379 100644 --- a/sensors/Android.bp +++ b/sensors/Android.bp @@ -16,14 +16,8 @@ cc_binary { shared_libs: [ "libbase", - "libcutils", "libhidlbase", "libutils", "android.frameworks.sensorservice@1.0", - "android.hardware.sensors@1.0", - ], - - header_libs: [ - "generated_kernel_headers", ], } diff --git a/sensors/NonUiNotifier.cpp b/sensors/NonUiNotifier.cpp index fc119fe..24f3b0d 100644 --- a/sensors/NonUiNotifier.cpp +++ b/sensors/NonUiNotifier.cpp @@ -7,32 +7,27 @@ #define LOG_TAG "NonUiNotifier" #include -#include -#include - #include -#include #include #include #include -#include #include "xiaomi_touch.h" -#define SENSOR_TYPE_XIAOMI_SENSOR_NONUI 33171027 #define SENSOR_NAME_XIAOMI_SENSOR_NONUI "xiaomi.sensor.nonui" -using ::android::frameworks::sensorservice::V1_0::IEventQueue; -using ::android::frameworks::sensorservice::V1_0::IEventQueueCallback; -using ::android::frameworks::sensorservice::V1_0::ISensorManager; -using ::android::frameworks::sensorservice::V1_0::Result; -using ::android::hardware::Return; -using ::android::hardware::Void; -using ::android::hardware::sensors::V1_0::Event; -using ::android::hardware::sensors::V1_0::SensorType; - using android::sp; +using android::frameworks::sensorservice::V1_0::IEventQueue; +using android::frameworks::sensorservice::V1_0::IEventQueueCallback; +using android::frameworks::sensorservice::V1_0::ISensorManager; +using android::frameworks::sensorservice::V1_0::Result; +using android::hardware::Return; +using android::hardware::Void; +using android::hardware::sensors::V1_0::Event; +using android::hardware::sensors::V1_0::SensorFlagBits; +using android::hardware::sensors::V1_0::SensorInfo; +using android::hardware::sensors::V1_0::SensorType; #define TOUCH_DEV_PATH "/dev/xiaomi-touch" #define TOUCH_MAGIC 'T' @@ -62,13 +57,8 @@ static bool readBool(int fd) { struct NonUiSensorCallback : IEventQueueCallback { Return onEvent(const Event& e) { - /* handle sensor event e */ - LOG(ERROR) << "onEvent scalar: " << e.u.scalar; bool nonUi = e.u.scalar == 1; - // android::base::unique_fd touch_fd_; - // touch_fd_ = android::base::unique_fd(open(TOUCH_DEV_PATH, O_RDWR)); - int buf[MAX_BUF_SIZE] = {0, Touch_Nonui_Mode, nonUi ? 2 : 0}; ioctl(open(TOUCH_DEV_PATH, O_RDWR), TOUCH_IOC_SET_CUR_VALUE, &buf); @@ -79,9 +69,13 @@ struct NonUiSensorCallback : IEventQueueCallback { } // namespace int main() { + Result res; + sp queue; + sp manager = ISensorManager::getService(); if (manager == nullptr) { LOG(ERROR) << "failed to get ISensorManager"; + return EXIT_FAILURE; } int32_t sensorHandle = -1; @@ -90,13 +84,12 @@ int main() { sensorHandle = info.sensorHandle; }); - sp queue; - Result res; manager->createEventQueue(new NonUiSensorCallback(), [&queue, &res](const auto& q, auto r) { queue = q; res = r; }); if (res != Result::OK) { + LOG(ERROR) << "failed to create event queue"; return EXIT_FAILURE; } @@ -121,7 +114,6 @@ int main() { while (true) { int rc = poll(pollfds, paths.size(), -1); - LOG(ERROR) << "poll: " << rc; if (rc < 0) { LOG(ERROR) << "failed to poll, err: " << rc; continue; @@ -129,7 +121,7 @@ int main() { for (size_t i = 0; i < paths.size(); ++i) { if (pollfds[i].revents & (POLLERR | POLLPRI)) { - LOG(ERROR) << "Event on " << paths[i]; + LOG(VERBOSE) << "polled change on " << paths[i]; } } @@ -137,7 +129,6 @@ int main() { for (size_t i = 0; i < paths.size(); ++i) { enabled = enabled || readBool(pollfds[i].fd); } - LOG(ERROR) << "got notified about poll, enabled: " << enabled; if (enabled) { res = queue->enableSensor(sensorHandle, 20000 /* sample period */, 0 /* latency */); if (res != Result::OK) {