From 064c24617ef5f2f93583b935c56d835bc0afcabc Mon Sep 17 00:00:00 2001 From: Bruno Martins Date: Sat, 7 Jun 2025 13:55:47 +0100 Subject: [PATCH] touch: Migrate to AIDL Change-Id: If44efbab6ad53701a662788daecfd7678935e8b4 --- aidl/touch/Android.bp | 27 +++++++++++ aidl/touch/HighTouchPollingRate.cpp | 46 +++++++++++++++++++ aidl/touch/HighTouchPollingRate.h | 24 ++++++++++ aidl/touch/service.cpp | 24 ++++++++++ .../vendor.lineage.touch-service.xiaomi.rc | 4 ++ .../vendor.lineage.touch-service.xiaomi.xml | 5 +- hidl/touch/Android.bp | 28 ----------- hidl/touch/HighTouchPollingRate.cpp | 37 --------------- hidl/touch/HighTouchPollingRate.h | 30 ------------ hidl/touch/service.cpp | 33 ------------- ...vendor.lineage.touch@1.0-service.xiaomi.rc | 5 -- 11 files changed, 127 insertions(+), 136 deletions(-) create mode 100644 aidl/touch/Android.bp create mode 100644 aidl/touch/HighTouchPollingRate.cpp create mode 100644 aidl/touch/HighTouchPollingRate.h create mode 100644 aidl/touch/service.cpp create mode 100644 aidl/touch/vendor.lineage.touch-service.xiaomi.rc rename hidl/touch/vendor.lineage.touch@1.0-service.xiaomi.xml => aidl/touch/vendor.lineage.touch-service.xiaomi.xml (71%) delete mode 100644 hidl/touch/Android.bp delete mode 100644 hidl/touch/HighTouchPollingRate.cpp delete mode 100644 hidl/touch/HighTouchPollingRate.h delete mode 100644 hidl/touch/service.cpp delete mode 100644 hidl/touch/vendor.lineage.touch@1.0-service.xiaomi.rc diff --git a/aidl/touch/Android.bp b/aidl/touch/Android.bp new file mode 100644 index 0000000..0377cc6 --- /dev/null +++ b/aidl/touch/Android.bp @@ -0,0 +1,27 @@ +// +// SPDX-FileCopyrightText: 2025 The LineageOS Project +// SPDX-License-Identifier: Apache-2.0 +// + +cc_binary { + name: "vendor.lineage.touch-service.xiaomi", + vintf_fragments: ["vendor.lineage.touch-service.xiaomi.xml"], + init_rc: ["vendor.lineage.touch-service.xiaomi.rc"], + relative_install_path: "hw", + proprietary: true, + cppflags: select(soong_config_variable("XIAOMI_TOUCH", "HIGH_TOUCH_POLLING_PATH"), { + any @ flag_val: ["-DHTPR_CONTROL_PATH=\"" + flag_val + "\""], + default: [], + }), + srcs: [ + "HighTouchPollingRate.cpp", + "service.cpp", + ], + shared_libs: [ + "libbase", + "libbinder_ndk", + "liblog", + "libutils", + "vendor.lineage.touch-V1-ndk", + ], +} diff --git a/aidl/touch/HighTouchPollingRate.cpp b/aidl/touch/HighTouchPollingRate.cpp new file mode 100644 index 0000000..2c0e0c5 --- /dev/null +++ b/aidl/touch/HighTouchPollingRate.cpp @@ -0,0 +1,46 @@ +/* + * SPDX-FileCopyrightText: 2025 The LineageOS Project + * SPDX-License-Identifier: Apache-2.0 + */ + +#define LOG_TAG "vendor.lineage.touch-service.xiaomi" + +#include "HighTouchPollingRate.h" + +#include +#include +#include + +using ::android::base::ReadFileToString; +using ::android::base::Trim; +using ::android::base::WriteStringToFile; + +namespace aidl { +namespace vendor { +namespace lineage { +namespace touch { + +ndk::ScopedAStatus HighTouchPollingRate::getEnabled(bool* _aidl_return) { + std::string buf; + if (!ReadFileToString(HTPR_CONTROL_PATH, &buf)) { + LOG(ERROR) << "Failed to read current HighTouchPollingRate state"; + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + } + + *_aidl_return = Trim(buf) == "1"; + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus HighTouchPollingRate::setEnabled(bool enabled) { + if (!WriteStringToFile(enabled ? "1" : "0", HTPR_CONTROL_PATH)) { + LOG(ERROR) << "Failed to write HighTouchPollingRate state"; + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + } + + return ndk::ScopedAStatus::ok(); +} + +} // namespace touch +} // namespace lineage +} // namespace vendor +} // namespace aidl diff --git a/aidl/touch/HighTouchPollingRate.h b/aidl/touch/HighTouchPollingRate.h new file mode 100644 index 0000000..66efb6d --- /dev/null +++ b/aidl/touch/HighTouchPollingRate.h @@ -0,0 +1,24 @@ +/* + * SPDX-FileCopyrightText: 2025 The LineageOS Project + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include + +namespace aidl { +namespace vendor { +namespace lineage { +namespace touch { + +class HighTouchPollingRate : public BnHighTouchPollingRate { + public: + ndk::ScopedAStatus getEnabled(bool* _aidl_return) override; + ndk::ScopedAStatus setEnabled(bool enabled) override; +}; + +} // namespace touch +} // namespace lineage +} // namespace vendor +} // namespace aidl diff --git a/aidl/touch/service.cpp b/aidl/touch/service.cpp new file mode 100644 index 0000000..0380fe6 --- /dev/null +++ b/aidl/touch/service.cpp @@ -0,0 +1,24 @@ +/* + * SPDX-FileCopyrightText: 2025 The LineageOS Project + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "HighTouchPollingRate.h" + +#include +#include +#include + +using aidl::vendor::lineage::touch::HighTouchPollingRate; + +int main() { + ABinderProcess_setThreadPoolMaxThreadCount(0); + std::shared_ptr htpr = ndk::SharedRefBase::make(); + + const std::string instance = std::string(HighTouchPollingRate::descriptor) + "/default"; + binder_status_t status = AServiceManager_addService(htpr->asBinder().get(), instance.c_str()); + CHECK_EQ(status, STATUS_OK); + + ABinderProcess_joinThreadPool(); + return EXIT_FAILURE; // should not reach +} diff --git a/aidl/touch/vendor.lineage.touch-service.xiaomi.rc b/aidl/touch/vendor.lineage.touch-service.xiaomi.rc new file mode 100644 index 0000000..fcb4343 --- /dev/null +++ b/aidl/touch/vendor.lineage.touch-service.xiaomi.rc @@ -0,0 +1,4 @@ +service vendor.touch-hal /vendor/bin/hw/vendor.lineage.touch-service.xiaomi + class hal + user system + group system diff --git a/hidl/touch/vendor.lineage.touch@1.0-service.xiaomi.xml b/aidl/touch/vendor.lineage.touch-service.xiaomi.xml similarity index 71% rename from hidl/touch/vendor.lineage.touch@1.0-service.xiaomi.xml rename to aidl/touch/vendor.lineage.touch-service.xiaomi.xml index 3d58280..3c2cd7c 100644 --- a/hidl/touch/vendor.lineage.touch@1.0-service.xiaomi.xml +++ b/aidl/touch/vendor.lineage.touch-service.xiaomi.xml @@ -1,8 +1,7 @@ - + vendor.lineage.touch - hwbinder - 1.0 + 1 IHighTouchPollingRate default diff --git a/hidl/touch/Android.bp b/hidl/touch/Android.bp deleted file mode 100644 index 80d57ba..0000000 --- a/hidl/touch/Android.bp +++ /dev/null @@ -1,28 +0,0 @@ -// -// SPDX-FileCopyrightText: 2022-2025 The LineageOS Project -// SPDX-License-Identifier: Apache-2.0 -// - -cc_binary { - name: "vendor.lineage.touch@1.0-service.xiaomi", - defaults: ["hidl_defaults"], - vintf_fragments: ["vendor.lineage.touch@1.0-service.xiaomi.xml"], - init_rc: ["vendor.lineage.touch@1.0-service.xiaomi.rc"], - relative_install_path: "hw", - proprietary: true, - cppflags: select(soong_config_variable("XIAOMI_TOUCH", "HIGH_TOUCH_POLLING_PATH"), { - any @ flag_val: ["-DHIGH_TOUCH_POLLING_PATH=\"" + flag_val + "\""], - default: [], - }), - srcs: [ - "HighTouchPollingRate.cpp", - "service.cpp", - ], - shared_libs: [ - "libbase", - "libbinder", - "libhidlbase", - "libutils", - "vendor.lineage.touch@1.0", - ], -} diff --git a/hidl/touch/HighTouchPollingRate.cpp b/hidl/touch/HighTouchPollingRate.cpp deleted file mode 100644 index b7008c1..0000000 --- a/hidl/touch/HighTouchPollingRate.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2022 The LineageOS Project - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#define LOG_TAG "HighTouchPollingRateService" - -#include "HighTouchPollingRate.h" - -#include - -namespace vendor { -namespace lineage { -namespace touch { -namespace V1_0 { -namespace implementation { - -Return HighTouchPollingRate::isEnabled() { - std::ifstream file(HIGH_TOUCH_POLLING_PATH); - int enabled; - file >> enabled; - - return enabled == 1; -} - -Return HighTouchPollingRate::setEnabled(bool enabled) { - std::ofstream file(HIGH_TOUCH_POLLING_PATH); - file << (enabled ? "1" : "0"); - return !file.fail(); -} - -} // namespace implementation -} // namespace V1_0 -} // namespace touch -} // namespace lineage -} // namespace vendor diff --git a/hidl/touch/HighTouchPollingRate.h b/hidl/touch/HighTouchPollingRate.h deleted file mode 100644 index 1a3a355..0000000 --- a/hidl/touch/HighTouchPollingRate.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2022 The LineageOS Project - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include - -namespace vendor { -namespace lineage { -namespace touch { -namespace V1_0 { -namespace implementation { - -using ::android::hardware::Return; - -class HighTouchPollingRate : public IHighTouchPollingRate { - public: - // Methods from ::vendor::lineage::touch::V1_0::IHighTouchPollingRate follow. - Return isEnabled() override; - Return setEnabled(bool enabled) override; -}; - -} // namespace implementation -} // namespace V1_0 -} // namespace touch -} // namespace lineage -} // namespace vendor diff --git a/hidl/touch/service.cpp b/hidl/touch/service.cpp deleted file mode 100644 index 01f48e1..0000000 --- a/hidl/touch/service.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2022 The LineageOS Project - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#define LOG_TAG "lineage.touch@1.0-service.xiaomi" - -#include -#include - -#include "HighTouchPollingRate.h" - -using ::vendor::lineage::touch::V1_0::IHighTouchPollingRate; -using ::vendor::lineage::touch::V1_0::implementation::HighTouchPollingRate; - -int main() { - android::sp highTouchPollingRate = new HighTouchPollingRate(); - - android::hardware::configureRpcThreadpool(1, true); - - if (highTouchPollingRate->registerAsService() != android::OK) { - LOG(ERROR) << "Cannot register touchscreen high polling rate HAL service."; - return 1; - } - - LOG(INFO) << "Touchscreen HAL service ready."; - - android::hardware::joinRpcThreadpool(); - - LOG(ERROR) << "Touchscreen HAL service failed to join thread pool."; - return 1; -} diff --git a/hidl/touch/vendor.lineage.touch@1.0-service.xiaomi.rc b/hidl/touch/vendor.lineage.touch@1.0-service.xiaomi.rc deleted file mode 100644 index dbc74ca..0000000 --- a/hidl/touch/vendor.lineage.touch@1.0-service.xiaomi.rc +++ /dev/null @@ -1,5 +0,0 @@ -service vendor.touch-hal-1-0 /vendor/bin/hw/vendor.lineage.touch@1.0-service.xiaomi - interface vendor.lineage.touch@1.0::IHighTouchPollingRate default - class hal - user system - group system