touch: Migrate to AIDL
Change-Id: If44efbab6ad53701a662788daecfd7678935e8b4
This commit is contained in:
27
aidl/touch/Android.bp
Normal file
27
aidl/touch/Android.bp
Normal file
@@ -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",
|
||||
],
|
||||
}
|
||||
46
aidl/touch/HighTouchPollingRate.cpp
Normal file
46
aidl/touch/HighTouchPollingRate.cpp
Normal file
@@ -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 <android-base/file.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/strings.h>
|
||||
|
||||
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
|
||||
24
aidl/touch/HighTouchPollingRate.h
Normal file
24
aidl/touch/HighTouchPollingRate.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 The LineageOS Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <aidl/vendor/lineage/touch/BnHighTouchPollingRate.h>
|
||||
|
||||
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
|
||||
24
aidl/touch/service.cpp
Normal file
24
aidl/touch/service.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 The LineageOS Project
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "HighTouchPollingRate.h"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
|
||||
using aidl::vendor::lineage::touch::HighTouchPollingRate;
|
||||
|
||||
int main() {
|
||||
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
||||
std::shared_ptr<HighTouchPollingRate> htpr = ndk::SharedRefBase::make<HighTouchPollingRate>();
|
||||
|
||||
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
|
||||
}
|
||||
4
aidl/touch/vendor.lineage.touch-service.xiaomi.rc
Normal file
4
aidl/touch/vendor.lineage.touch-service.xiaomi.rc
Normal file
@@ -0,0 +1,4 @@
|
||||
service vendor.touch-hal /vendor/bin/hw/vendor.lineage.touch-service.xiaomi
|
||||
class hal
|
||||
user system
|
||||
group system
|
||||
@@ -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>IHighTouchPollingRate</name>
|
||||
<instance>default</instance>
|
||||
@@ -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",
|
||||
],
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define LOG_TAG "HighTouchPollingRateService"
|
||||
|
||||
#include "HighTouchPollingRate.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace vendor {
|
||||
namespace lineage {
|
||||
namespace touch {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
Return<bool> HighTouchPollingRate::isEnabled() {
|
||||
std::ifstream file(HIGH_TOUCH_POLLING_PATH);
|
||||
int enabled;
|
||||
file >> enabled;
|
||||
|
||||
return enabled == 1;
|
||||
}
|
||||
|
||||
Return<bool> 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
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The LineageOS Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vendor/lineage/touch/1.0/IHighTouchPollingRate.h>
|
||||
|
||||
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<bool> isEnabled() override;
|
||||
Return<bool> setEnabled(bool enabled) override;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace touch
|
||||
} // namespace lineage
|
||||
} // namespace vendor
|
||||
@@ -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 <android-base/logging.h>
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
|
||||
#include "HighTouchPollingRate.h"
|
||||
|
||||
using ::vendor::lineage::touch::V1_0::IHighTouchPollingRate;
|
||||
using ::vendor::lineage::touch::V1_0::implementation::HighTouchPollingRate;
|
||||
|
||||
int main() {
|
||||
android::sp<IHighTouchPollingRate> 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;
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user