diff --git a/device.mk b/device.mk index c8c8a2a..f8a2406 100644 --- a/device.mk +++ b/device.mk @@ -41,7 +41,7 @@ PRODUCT_SOONG_NAMESPACES += \ # Touch PRODUCT_PACKAGES += \ - vendor.lineage.touch@1.0-service.cheeseburger + vendor.lineage.touch-service.cheeseburger # Wifi PRODUCT_PACKAGES += \ diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index 791d124..b4bab56 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -14,4 +14,4 @@ /vendor/usr/keylayout/synaptics_s3320.kl u:object_r:vendor_keylayout_file:s0 # Touch -/(vendor|system/vendor)/bin/hw/vendor\.lineage\.touch@1\.0-service\.cheeseburger u:object_r:hal_touch_oneplus_msm8998_exec:s0 +/(vendor|system/vendor)/bin/hw/vendor\.lineage\.touch-service\.cheeseburger u:object_r:hal_touch_oneplus_msm8998_exec:s0 diff --git a/touch/Android.bp b/touch/Android.bp index df747c7..7c5c231 100644 --- a/touch/Android.bp +++ b/touch/Android.bp @@ -1,29 +1,32 @@ // -// Copyright (C) 2019,2021 The LineageOS Project +// SPDX-FileCopyrightText: 2019-2025 The LineageOS Project // SPDX-License-Identifier: Apache-2.0 // cc_binary { - name: "vendor.lineage.touch@1.0-service.cheeseburger", - init_rc: ["vendor.lineage.touch@1.0-service.cheeseburger.rc"], - defaults: ["hidl_defaults"], - vintf_fragments: ["vendor.lineage.touch@1.0-service.cheeseburger.xml"], + name: "vendor.lineage.touch-service.cheeseburger", + init_rc: ["vendor.lineage.touch-service.cheeseburger.rc"], + vintf_fragments: ["vendor.lineage.touch-service.cheeseburger.xml"], relative_install_path: "hw", vendor: true, srcs: [ - ":vendor.lineage.touch@1.0-oneplus-touchgesture", + ":vendor.lineage.touch-oneplus-touchgesture", "KeyDisabler.cpp", "KeySwapper.cpp", "service.cpp" ], shared_libs: [ "libbase", - "libbinder", - "libhidlbase", + "liblog", + "libbinder_ndk", "libutils", - "vendor.lineage.touch@1.0", + "vendor.lineage.touch-V1-ndk", ], header_libs: [ - "vendor.lineage.touch@1.0-oneplus-headers", + "vendor.lineage.touch-oneplus-headers", ], + include_dirs: select(soong_config_variable("ONEPLUS_LINEAGE_TOUCH_HAL", "INCLUDE_DIR"), { + any @ flag_val: [flag_val], + default: [], + }), } diff --git a/touch/KeyDisabler.cpp b/touch/KeyDisabler.cpp index 73d970c..969b6d3 100644 --- a/touch/KeyDisabler.cpp +++ b/touch/KeyDisabler.cpp @@ -1,6 +1,5 @@ /* - * Copyright (C) 2019 The LineageOS Project - * + * SPDX-FileCopyrightText: 2019 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ @@ -16,51 +15,50 @@ constexpr const char kFpcPath[] = "/sys/module/fpc1020_tee/parameters/ignor_home_for_ESD"; }; // anonymous namespace +namespace aidl { namespace vendor { namespace lineage { namespace touch { -namespace V1_0 { -namespace implementation { KeyDisabler::KeyDisabler() : has_key_disabler_(!access(kControlPath, R_OK | W_OK)) {} -// Methods from ::vendor::lineage::touch::V1_0::IKeyDisabler follow. -Return KeyDisabler::isEnabled() { - if (!has_key_disabler_) return false; - - std::string buf; - if (!android::base::ReadFileToString(kControlPath, &buf)) { - LOG(ERROR) << "Failed to read " << kControlPath; - return false; +ndk::ScopedAStatus KeyDisabler::getEnabled(bool* _aidl_return) { + if (!has_key_disabler_) { + *_aidl_return = false; + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } - if (!android::base::ReadFileToString(kFpcPath, &buf)) { - LOG(ERROR) << "Failed to read " << kFpcPath; - return false; + std::string controlBuf, fpcBuf; + if (!android::base::ReadFileToString(kControlPath, &controlBuf) || + !android::base::ReadFileToString(kFpcPath, &fpcBuf)) { + LOG(ERROR) << "Failed to read key disabler state files"; + *_aidl_return = false; + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } - return std::stoi(android::base::Trim(buf)) == 0; + *_aidl_return = android::base::Trim(controlBuf) == "0" && android::base::Trim(fpcBuf) == "0"; + return ndk::ScopedAStatus::ok(); } -Return KeyDisabler::setEnabled(bool enabled) { - if (!has_key_disabler_) return false; +ndk::ScopedAStatus KeyDisabler::setEnabled(bool enabled) { + if (!has_key_disabler_) { + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + } if (!android::base::WriteStringToFile(std::to_string(enabled), kControlPath)) { LOG(ERROR) << "Failed to write " << kControlPath; - return false; + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } if (!android::base::WriteStringToFile((enabled ? "1" : "0"), kFpcPath)) { LOG(ERROR) << "Failed to write " << kFpcPath; - return false; + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } - return true; + return ndk::ScopedAStatus::ok(); } -} // namespace implementation -} // namespace V1_0 } // namespace touch } // namespace lineage } // namespace vendor - +} // namespace aidl diff --git a/touch/KeyDisabler.h b/touch/KeyDisabler.h index 73fadf7..e510c1b 100644 --- a/touch/KeyDisabler.h +++ b/touch/KeyDisabler.h @@ -1,36 +1,29 @@ /* - * Copyright (C) 2021 The LineageOS Project - * + * SPDX-FileCopyrightText: 2021 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; -using ::android::sp; - -class KeyDisabler : public IKeyDisabler { +class KeyDisabler : public BnKeyDisabler { public: KeyDisabler(); - // Methods from ::vendor::lineage::touch::V1_0::IKeyDisabler follow. - Return isEnabled() override; - Return setEnabled(bool enabled) override; + ndk::ScopedAStatus getEnabled(bool* _aidl_return) override; + ndk::ScopedAStatus setEnabled(bool enabled) override; private: const bool has_key_disabler_; }; -} // namespace implementation -} // namespace V1_0 } // namespace touch } // namespace lineage } // namespace vendor +} // namespace aidl diff --git a/touch/KeySwapper.cpp b/touch/KeySwapper.cpp index 14614a9..960e806 100644 --- a/touch/KeySwapper.cpp +++ b/touch/KeySwapper.cpp @@ -1,6 +1,5 @@ /* - * Copyright (C) 2019,2021 The LineageOS Project - * + * SPDX-FileCopyrightText: 2019-2025 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ @@ -14,40 +13,44 @@ namespace { constexpr const char kControlPath[] = "/proc/s1302/key_rep"; }; // anonymous namespace +namespace aidl { namespace vendor { namespace lineage { namespace touch { -namespace V1_0 { -namespace implementation { KeySwapper::KeySwapper() : has_key_swapper_(!access(kControlPath, R_OK | W_OK)) {} -// Methods from ::vendor::lineage::touch::V1_0::IKeySwapper follow. -Return KeySwapper::isEnabled() { - if (!has_key_swapper_) return false; +ndk::ScopedAStatus KeySwapper::getEnabled(bool* _aidl_return) { + if (!has_key_swapper_) { + *_aidl_return = false; + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + } std::string buf; if (!android::base::ReadFileToString(kControlPath, &buf)) { LOG(ERROR) << "Failed to read " << kControlPath; - return false; + *_aidl_return = false; + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } - return std::stoi(android::base::Trim(buf)) == 1; + *_aidl_return = std::stoi(android::base::Trim(buf)) == 1; + return ndk::ScopedAStatus::ok(); } -Return KeySwapper::setEnabled(bool enabled) { - if (!has_key_swapper_) return false; +ndk::ScopedAStatus KeySwapper::setEnabled(bool enabled) { + if (!has_key_swapper_) { + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + } if (!android::base::WriteStringToFile(std::to_string(enabled), kControlPath)) { LOG(ERROR) << "Failed to write " << kControlPath; - return false; + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); } - return true; + return ndk::ScopedAStatus::ok(); } -} // namespace implementation -} // namespace V1_0 } // namespace touch } // namespace lineage } // namespace vendor +} // namespace aidl diff --git a/touch/KeySwapper.h b/touch/KeySwapper.h index 4c82bad..0198731 100644 --- a/touch/KeySwapper.h +++ b/touch/KeySwapper.h @@ -1,34 +1,29 @@ /* - * Copyright (C) 2019,2021 The LineageOS Project - * + * SPDX-FileCopyrightText: 2019-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 KeySwapper : public IKeySwapper { +class KeySwapper : public BnKeySwapper { public: KeySwapper(); - // Methods from ::vendor::lineage::touch::V1_0::IKeySwapper follow. - Return isEnabled() override; - Return setEnabled(bool enabled) override; + + ndk::ScopedAStatus getEnabled(bool* _aidl_return) override; + ndk::ScopedAStatus setEnabled(bool enabled) override; private: const bool has_key_swapper_; }; -} // namespace implementation -} // namespace V1_0 } // namespace touch } // namespace lineage } // namespace vendor +} // namespace aidl diff --git a/touch/service.cpp b/touch/service.cpp index 51daa09..8e29a87 100644 --- a/touch/service.cpp +++ b/touch/service.cpp @@ -1,56 +1,48 @@ /* - * Copyright (C) 2019,2021 The LineageOS Project - * + * SPDX-FileCopyrightText: 2019-2025 The LineageOS Project * SPDX-License-Identifier: Apache-2.0 */ -#define LOG_TAG "vendor.lineage.touch@1.0-service.cheeseburger" +#define LOG_TAG "vendor.lineage.touch-service.cheeseburger" #include -#include +#include +#include #include #include "KeyDisabler.h" #include "KeySwapper.h" -using android::OK; -using android::sp; -using android::hardware::configureRpcThreadpool; -using android::hardware::joinRpcThreadpool; - -using ::vendor::lineage::touch::V1_0::IKeyDisabler; -using ::vendor::lineage::touch::V1_0::IKeySwapper; -using ::vendor::lineage::touch::V1_0::ITouchscreenGesture; -using ::vendor::lineage::touch::V1_0::implementation::KeyDisabler; -using ::vendor::lineage::touch::V1_0::implementation::KeySwapper; -using ::vendor::lineage::touch::V1_0::implementation::TouchscreenGesture; +using aidl::vendor::lineage::touch::KeyDisabler; +using aidl::vendor::lineage::touch::KeySwapper; +using aidl::vendor::lineage::touch::TouchscreenGesture; int main() { - sp key_disabler = new KeyDisabler(); - sp key_swapper = new KeySwapper(); - sp gestureService = new TouchscreenGesture(); + binder_status_t status = STATUS_OK; - configureRpcThreadpool(1, true /*callerWillJoin*/); + ABinderProcess_setThreadPoolMaxThreadCount(0); - if (key_disabler->registerAsService() != OK) { - LOG(ERROR) << "Cannot register keydisabler HAL service."; - return 1; - } + std::shared_ptr keyDisabler = ndk::SharedRefBase::make(); + std::shared_ptr keySwapper = ndk::SharedRefBase::make(); + std::shared_ptr gestureService = ndk::SharedRefBase::make(); - if (key_swapper->registerAsService() != OK) { - LOG(ERROR) << "Cannot register keyswapper HAL service."; - return 1; - } + const std::string keyDisabler_instance = std::string(KeyDisabler::descriptor) + "/default"; + status = AServiceManager_addService(keyDisabler->asBinder().get(), keyDisabler_instance.c_str()); + CHECK_EQ(status, STATUS_OK) << "Failed to add service " << keyDisabler_instance << " " << status; - if (gestureService->registerAsService() != android::OK) { - LOG(ERROR) << "Cannot register touchscreen gesture HAL service."; - return 1; - } + const std::string keySwapper_instance = std::string(KeySwapper::descriptor) + "/default"; + status = AServiceManager_addService(keySwapper->asBinder().get(), keySwapper_instance.c_str()); + CHECK_EQ(status, STATUS_OK) << "Failed to add service " << keySwapper_instance << " " << status; + + const std::string gesture_instance = std::string(TouchscreenGesture::descriptor) + "/default"; + status = AServiceManager_addService(gestureService->asBinder().get(), gesture_instance.c_str()); + CHECK_EQ(status, STATUS_OK) << "Failed to add service " << gesture_instance << " " << status; LOG(INFO) << "Touch HAL service is ready."; - joinRpcThreadpool(); - // Should not pass this line + ABinderProcess_joinThreadPool(); + + // Should never reach here LOG(ERROR) << "Touchscreen HAL service failed to join thread pool."; - return 1; + return EXIT_FAILURE; } diff --git a/touch/vendor.lineage.touch@1.0-service.cheeseburger.rc b/touch/vendor.lineage.touch-service.cheeseburger.rc similarity index 56% rename from touch/vendor.lineage.touch@1.0-service.cheeseburger.rc rename to touch/vendor.lineage.touch-service.cheeseburger.rc index e387fca..ace6758 100644 --- a/touch/vendor.lineage.touch@1.0-service.cheeseburger.rc +++ b/touch/vendor.lineage.touch-service.cheeseburger.rc @@ -2,7 +2,7 @@ on boot chown system system /proc/s1302/key_rep chmod 0660 /proc/s1302/key_rep -service vendor.touch-hal-1-0-cheeseburger /vendor/bin/hw/vendor.lineage.touch@1.0-service.cheeseburger +service vendor.touch-hal.cheeseburger /vendor/bin/hw/vendor.lineage.touch-service.cheeseburger class hal user system group system diff --git a/touch/vendor.lineage.touch@1.0-service.cheeseburger.xml b/touch/vendor.lineage.touch-service.cheeseburger.xml similarity index 83% rename from touch/vendor.lineage.touch@1.0-service.cheeseburger.xml rename to touch/vendor.lineage.touch-service.cheeseburger.xml index d0815dc..8c2ff24 100644 --- a/touch/vendor.lineage.touch@1.0-service.cheeseburger.xml +++ b/touch/vendor.lineage.touch-service.cheeseburger.xml @@ -1,8 +1,7 @@ - + vendor.lineage.touch - hwbinder - 1.0 + 1 IKeyDisabler default