From 63cfbf969ee79e4e64e68c01129ab6081ec73b46 Mon Sep 17 00:00:00 2001 From: Danny Trunk Date: Mon, 7 Jul 2025 07:53:18 +0200 Subject: [PATCH] tama-common: Move to touch AIDL Change-Id: Ic31d3c29a31ece625de67db57de2b8a246b4c7a1 Signed-off-by: Sorayukii --- common.mk | 2 +- sepolicy/vendor/file_contexts | 2 +- touch/Android.bp | 17 ++++---- touch/GloveMode.cpp | 42 +++++++++++-------- touch/GloveMode.h | 19 ++++----- touch/service.cpp | 35 +++++++--------- touch/vendor.lineage.touch-service.tama.rc | 4 ++ touch/vendor.lineage.touch-service.tama.xml | 7 ++++ .../vendor.lineage.touch@1.0-service.tama.rc | 10 ----- .../vendor.lineage.touch@1.0-service.tama.xml | 11 ----- 10 files changed, 68 insertions(+), 81 deletions(-) create mode 100644 touch/vendor.lineage.touch-service.tama.rc create mode 100644 touch/vendor.lineage.touch-service.tama.xml delete mode 100644 touch/vendor.lineage.touch@1.0-service.tama.rc delete mode 100644 touch/vendor.lineage.touch@1.0-service.tama.xml diff --git a/common.mk b/common.mk index 78b2339..551f80f 100644 --- a/common.mk +++ b/common.mk @@ -431,7 +431,7 @@ PRODUCT_PACKAGES += \ # Touch PRODUCT_PACKAGES += \ - vendor.lineage.touch@1.0-service.tama + vendor.lineage.touch-service.tama # USB PRODUCT_PACKAGES += \ diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index 1c148f6..d2d1f08 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -88,7 +88,7 @@ # Vendor HALs /(vendor|system/vendor)/bin/hw/fpc_fingerprint@2\.1_HIDL-service u:object_r:hal_fingerprint_default_exec:s0 -/(vendor|system/vendor)/bin/hw/vendor\.lineage\.touch@1\.0-service\.tama u:object_r:hal_lineage_touch_default_exec:s0 +/(vendor|system/vendor)/bin/hw/vendor\.lineage\.touch-service\.tama u:object_r:hal_lineage_touch_default_exec:s0 /(vendor|system/vendor)/bin/hw/vendor\.semc\.hardware\.secd@1\.0-service u:object_r:hal_secd_default_exec:s0 /(vendor|system/vendor)/bin/hw/vendor\.semc\.system\.idd@1\.0-service u:object_r:hal_idd_default_exec:s0 /(vendor|system/vendor)/bin/hw/vendor\.somc\.hardware\.camera\.provider@1\.0-service u:object_r:hal_camera_default_exec:s0 diff --git a/touch/Android.bp b/touch/Android.bp index 12318cf..b01844b 100644 --- a/touch/Android.bp +++ b/touch/Android.bp @@ -1,13 +1,13 @@ // -// Copyright (C) 2021 The LineageOS Project +// SPDX-FileCopyrightText: 2025 The LineageOS Project // SPDX-License-Identifier: Apache-2.0 // cc_binary { - name: "vendor.lineage.touch@1.0-service.tama", - init_rc: ["vendor.lineage.touch@1.0-service.tama.rc"], - vintf_fragments: ["vendor.lineage.touch@1.0-service.tama.xml"], - defaults: ["hidl_defaults"], + name: "vendor.lineage.touch-service.tama", + init_rc: ["vendor.lineage.touch-service.tama.rc"], + vintf_fragments: ["vendor.lineage.touch-service.tama.xml"], + vendor: true, relative_install_path: "hw", srcs: [ "GloveMode.cpp", @@ -15,10 +15,9 @@ cc_binary { ], shared_libs: [ "libbase", - "libbinder", - "libhidlbase", + "liblog", + "libbinder_ndk", "libutils", - "vendor.lineage.touch@1.0", + "vendor.lineage.touch-V1-ndk", ], - vendor: true, } diff --git a/touch/GloveMode.cpp b/touch/GloveMode.cpp index 63e3ef4..5799adc 100644 --- a/touch/GloveMode.cpp +++ b/touch/GloveMode.cpp @@ -1,43 +1,51 @@ /* - * Copyright (C) 2021-2022 The LineageOS Project + * SPDX-FileCopyrightText: 2025 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ -#define LOG_TAG "GloveModeService" - #include "GloveMode.h" -#include -#include #include -namespace vendor { -namespace lineage { -namespace touch { -namespace V1_0 { -namespace implementation { +namespace { const std::string kGloveModePath = "/sys/devices/common_touch/touch/glove_mode"; -Return GloveMode::isEnabled() { +} // anonymous namespace + +namespace aidl { +namespace vendor { +namespace lineage { +namespace touch { + +ndk::ScopedAStatus GloveMode::getEnabled(bool* _aidl_return) { std::ifstream file(kGloveModePath); + + if (file.fail()) { + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + } + bool enabled; file >> enabled; - return enabled; + *_aidl_return = enabled; + return ndk::ScopedAStatus::ok(); } -Return GloveMode::setEnabled(bool enabled) { +ndk::ScopedAStatus GloveMode::setEnabled(bool enable) { std::ofstream file(kGloveModePath); - file << enabled << std::flush; + if (file.fail()) { + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + } - return !file.fail(); + file << enable << std::flush; + + return ndk::ScopedAStatus::ok(); } -} // namespace implementation -} // namespace V1_0 } // namespace touch } // namespace lineage } // namespace vendor +} // namespace aidl diff --git a/touch/GloveMode.h b/touch/GloveMode.h index 0475688..04c7fa0 100644 --- a/touch/GloveMode.h +++ b/touch/GloveMode.h @@ -1,29 +1,24 @@ /* - * Copyright (C) 2021 The LineageOS Project + * SPDX-FileCopyrightText: 2025 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ #pragma once -#include +#include +namespace aidl { namespace vendor { namespace lineage { namespace touch { -namespace V1_0 { -namespace implementation { -using ::android::hardware::Return; - -class GloveMode : public IGloveMode { +class GloveMode : public BnGloveMode { public: - // Methods from ::vendor::lineage::touch::V1_0::IGloveMode follow. - Return isEnabled() override; - Return setEnabled(bool enabled) override; + ndk::ScopedAStatus getEnabled(bool* _aidl_return) override; + ndk::ScopedAStatus setEnabled(bool enabled) override; }; -} // namespace implementation -} // namespace V1_0 } // namespace touch } // namespace lineage } // namespace vendor +} // namespace aidl diff --git a/touch/service.cpp b/touch/service.cpp index 0b443a2..96263e0 100644 --- a/touch/service.cpp +++ b/touch/service.cpp @@ -1,32 +1,27 @@ /* - * Copyright (C) 2021 The LineageOS Project + * SPDX-FileCopyrightText: 2025 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ -#define LOG_TAG "vendor.lineage.touch@1.0-service.tama" - -#include -#include +#define LOG_TAG "vendor.lineage.touch-service.tama" #include "GloveMode.h" -using ::vendor::lineage::touch::V1_0::IGloveMode; -using ::vendor::lineage::touch::V1_0::implementation::GloveMode; +#include +#include +#include + +using aidl::vendor::lineage::touch::GloveMode; int main() { - android::sp gloveMode = new GloveMode(); + ABinderProcess_setThreadPoolMaxThreadCount(0); + std::shared_ptr glovemode = ndk::SharedRefBase::make(); - android::hardware::configureRpcThreadpool(1, true /*callerWillJoin*/); + const std::string instance = std::string(GloveMode::descriptor) + "/default"; + binder_status_t status = + AServiceManager_addService(glovemode->asBinder().get(), instance.c_str()); + CHECK_EQ(status, STATUS_OK) << "Failed to add service " << instance << " " << status; - if (gloveMode->registerAsService() != android::OK) { - LOG(ERROR) << "Cannot register touchscreen glove 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; + ABinderProcess_joinThreadPool(); + return EXIT_FAILURE; // should not reach } diff --git a/touch/vendor.lineage.touch-service.tama.rc b/touch/vendor.lineage.touch-service.tama.rc new file mode 100644 index 0000000..d66a927 --- /dev/null +++ b/touch/vendor.lineage.touch-service.tama.rc @@ -0,0 +1,4 @@ +service vendor.touch-hal /vendor/bin/hw/vendor.lineage.touch-service.tama + class hal + user system + group system diff --git a/touch/vendor.lineage.touch-service.tama.xml b/touch/vendor.lineage.touch-service.tama.xml new file mode 100644 index 0000000..45c175f --- /dev/null +++ b/touch/vendor.lineage.touch-service.tama.xml @@ -0,0 +1,7 @@ + + + vendor.lineage.touch + 1 + IGloveMode/default + + diff --git a/touch/vendor.lineage.touch@1.0-service.tama.rc b/touch/vendor.lineage.touch@1.0-service.tama.rc deleted file mode 100644 index 1960b88..0000000 --- a/touch/vendor.lineage.touch@1.0-service.tama.rc +++ /dev/null @@ -1,10 +0,0 @@ -# -# Copyright (C) 2021-2022 The LineageOS Project -# -# SPDX-License-Identifier: Apache-2.0 -# - -service vendor.touch-hal-1-0 /vendor/bin/hw/vendor.lineage.touch@1.0-service.tama - class hal - user system - group system diff --git a/touch/vendor.lineage.touch@1.0-service.tama.xml b/touch/vendor.lineage.touch@1.0-service.tama.xml deleted file mode 100644 index 0b0f2a8..0000000 --- a/touch/vendor.lineage.touch@1.0-service.tama.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - vendor.lineage.touch - hwbinder - 1.0 - - IGloveMode - default - - -