cheeseburger: Refactor touch HAL to AIDL

Co-authored-by: dianlujitao <dianlujitao@lineageos.org>
Co-authored-by: Edwin Moquete <edwinmmoquete@gmail.com>
Co-authored-by: Bruno Martins <bgcngm@gmail.com>
Change-Id: I10545e3f16475973135105f94c5821f96adfd369
This commit is contained in:
hoaysly
2025-07-13 22:55:30 +00:00
committed by ojfnuhjg
parent 2d0ba4b5d1
commit c8b2af03c9
10 changed files with 99 additions and 116 deletions

View File

@@ -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 += \

View File

@@ -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

View File

@@ -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: [],
}),
}

View File

@@ -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<bool> 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<bool> 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

View File

@@ -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 <vendor/lineage/touch/1.0/IKeyDisabler.h>
#include <aidl/vendor/lineage/touch/BnKeyDisabler.h>
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<bool> isEnabled() override;
Return<bool> 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

View File

@@ -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<bool> 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<bool> 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

View File

@@ -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 <vendor/lineage/touch/1.0/IKeySwapper.h>
#include <aidl/vendor/lineage/touch/BnKeySwapper.h>
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<bool> isEnabled() override;
Return<bool> 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

View File

@@ -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 <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <TouchscreenGesture.h>
#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<IKeyDisabler> key_disabler = new KeyDisabler();
sp<IKeySwapper> key_swapper = new KeySwapper();
sp<ITouchscreenGesture> 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> keyDisabler = ndk::SharedRefBase::make<KeyDisabler>();
std::shared_ptr<KeySwapper> keySwapper = ndk::SharedRefBase::make<KeySwapper>();
std::shared_ptr<TouchscreenGesture> gestureService = ndk::SharedRefBase::make<TouchscreenGesture>();
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;
}

View File

@@ -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

View File

@@ -1,8 +1,7 @@
<manifest version="1.0" type="device">
<hal format="hidl">
<hal format="aidl">
<name>vendor.lineage.touch</name>
<transport>hwbinder</transport>
<version>1.0</version>
<version>1</version>
<interface>
<name>IKeyDisabler</name>
<instance>default</instance>