diff --git a/README.md b/README.md index 9925af4..c9c09a8 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,5 @@ | --------- | -------- | ----------- | ------- | | XIAOMI_BIOMETRICS_FINGERPRINT | RUN_32BIT | Opt to run service in 32-bit mode only | false | | XIAOMI_TOUCH | HIGH_TOUCH_POLLING_PATH | HighTouchPollingRate feature control path | | +| XIAOMI_TOUCH | KEY_DISABLER_CONTROL_PATH | KeyDisabler feature control path | | +| XIAOMI_TOUCH | KEY_SWAPPER_CONTROL_PATH | KeySwapper feature control path | | diff --git a/aidl/touch/Android.bp b/aidl/touch/Android.bp index 0377cc6..22110af 100644 --- a/aidl/touch/Android.bp +++ b/aidl/touch/Android.bp @@ -5,18 +5,39 @@ cc_binary { name: "vendor.lineage.touch-service.xiaomi", - vintf_fragments: ["vendor.lineage.touch-service.xiaomi.xml"], init_rc: ["vendor.lineage.touch-service.xiaomi.rc"], + vintf_fragments: select(soong_config_variable("XIAOMI_TOUCH", "HIGH_TOUCH_POLLING_PATH"), { + any: ["vendor.lineage.touch-service.xiaomi-htpr.xml"], + default: [], + }) + select(soong_config_variable("XIAOMI_TOUCH", "KEY_DISABLER_CONTROL_PATH"), { + any: ["vendor.lineage.touch-service.xiaomi-kd.xml"], + default: [], + }) + select(soong_config_variable("XIAOMI_TOUCH", "KEY_SWAPPER_CONTROL_PATH"), { + any: ["vendor.lineage.touch-service.xiaomi-ks.xml"], + default: [], + }), 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: [], + }) + select(soong_config_variable("XIAOMI_TOUCH", "KEY_DISABLER_CONTROL_PATH"), { + any @ flag_val: ["-DKD_CONTROL_PATH=\"" + flag_val + "\""], + default: [], + }) + select(soong_config_variable("XIAOMI_TOUCH", "KEY_SWAPPER_CONTROL_PATH"), { + any @ flag_val: ["-DKS_CONTROL_PATH=\"" + flag_val + "\""], + default: [], }), - srcs: [ - "HighTouchPollingRate.cpp", - "service.cpp", - ], + srcs: select(soong_config_variable("XIAOMI_TOUCH", "HIGH_TOUCH_POLLING_PATH"), { + any: ["HighTouchPollingRate.cpp"], + default: [], + }) + select(soong_config_variable("XIAOMI_TOUCH", "KEY_DISABLER_CONTROL_PATH"), { + any: ["KeyDisabler.cpp"], + default: [], + }) + select(soong_config_variable("XIAOMI_TOUCH", "KEY_SWAPPER_CONTROL_PATH"), { + any: ["KeySwapper.cpp"], + default: [], + }) + ["service.cpp"], shared_libs: [ "libbase", "libbinder_ndk", diff --git a/aidl/touch/KeyDisabler.cpp b/aidl/touch/KeyDisabler.cpp new file mode 100644 index 0000000..4061904 --- /dev/null +++ b/aidl/touch/KeyDisabler.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 "KeyDisabler.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 KeyDisabler::getEnabled(bool* _aidl_return) { + std::string buf; + if (!ReadFileToString(KD_CONTROL_PATH, &buf)) { + LOG(ERROR) << "Failed to read current KeyDisabler state"; + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + } + + *_aidl_return = Trim(buf) == "0"; + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus KeyDisabler::setEnabled(bool enabled) { + if (!WriteStringToFile(enabled ? "0" : "1", KD_CONTROL_PATH, true)) { + LOG(ERROR) << "Failed to write KeyDisabler 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/KeyDisabler.h b/aidl/touch/KeyDisabler.h new file mode 100644 index 0000000..13ccb67 --- /dev/null +++ b/aidl/touch/KeyDisabler.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 KeyDisabler : public BnKeyDisabler { + 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/KeySwapper.cpp b/aidl/touch/KeySwapper.cpp new file mode 100644 index 0000000..9d89d0f --- /dev/null +++ b/aidl/touch/KeySwapper.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 "KeySwapper.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 KeySwapper::getEnabled(bool* _aidl_return) { + std::string buf; + if (!ReadFileToString(KS_CONTROL_PATH, &buf)) { + LOG(ERROR) << "Failed to read current KeySwapper state"; + return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); + } + + *_aidl_return = Trim(buf) == "1"; + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus KeySwapper::setEnabled(bool enabled) { + if (!WriteStringToFile(enabled ? "1" : "0", KS_CONTROL_PATH, true)) { + LOG(ERROR) << "Failed to write KeySwapper 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/KeySwapper.h b/aidl/touch/KeySwapper.h new file mode 100644 index 0000000..fa8e649 --- /dev/null +++ b/aidl/touch/KeySwapper.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 KeySwapper : public BnKeySwapper { + 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 index 0380fe6..b025864 100644 --- a/aidl/touch/service.cpp +++ b/aidl/touch/service.cpp @@ -3,21 +3,45 @@ * SPDX-License-Identifier: Apache-2.0 */ +#define LOG_TAG "vendor.lineage.touch-service.xiaomi" + #include "HighTouchPollingRate.h" +#include "KeyDisabler.h" +#include "KeySwapper.h" #include #include #include using aidl::vendor::lineage::touch::HighTouchPollingRate; +using aidl::vendor::lineage::touch::KeyDisabler; +using aidl::vendor::lineage::touch::KeySwapper; int main() { - ABinderProcess_setThreadPoolMaxThreadCount(0); - std::shared_ptr htpr = ndk::SharedRefBase::make(); + binder_status_t status = STATUS_OK; - 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_setThreadPoolMaxThreadCount(0); + +#ifdef HTPR_CONTROL_PATH + std::shared_ptr htpr = ndk::SharedRefBase::make(); + const std::string htpr_instance = std::string(HighTouchPollingRate::descriptor) + "/default"; + status = AServiceManager_addService(htpr->asBinder().get(), htpr_instance.c_str()); + CHECK_EQ(status, STATUS_OK) << "Failed to add service " << htpr_instance << " " << status; +#endif + +#ifdef KD_CONTROL_PATH + std::shared_ptr kd = ndk::SharedRefBase::make(); + const std::string kd_instance = std::string(KeyDisabler::descriptor) + "/default"; + status = AServiceManager_addService(kd->asBinder().get(), kd_instance.c_str()); + CHECK_EQ(status, STATUS_OK) << "Failed to add service " << kd_instance << " " << status; +#endif + +#ifdef KS_CONTROL_PATH + std::shared_ptr ks = ndk::SharedRefBase::make(); + const std::string ks_instance = std::string(KeySwapper::descriptor) + "/default"; + status = AServiceManager_addService(ks->asBinder().get(), ks_instance.c_str()); + CHECK_EQ(status, STATUS_OK) << "Failed to add service " << ks_instance << " " << status; +#endif ABinderProcess_joinThreadPool(); return EXIT_FAILURE; // should not reach diff --git a/aidl/touch/vendor.lineage.touch-service.xiaomi.xml b/aidl/touch/vendor.lineage.touch-service.xiaomi-htpr.xml similarity index 100% rename from aidl/touch/vendor.lineage.touch-service.xiaomi.xml rename to aidl/touch/vendor.lineage.touch-service.xiaomi-htpr.xml diff --git a/aidl/touch/vendor.lineage.touch-service.xiaomi-kd.xml b/aidl/touch/vendor.lineage.touch-service.xiaomi-kd.xml new file mode 100644 index 0000000..8237fb5 --- /dev/null +++ b/aidl/touch/vendor.lineage.touch-service.xiaomi-kd.xml @@ -0,0 +1,10 @@ + + + vendor.lineage.touch + 1 + + IKeyDisabler + default + + + diff --git a/aidl/touch/vendor.lineage.touch-service.xiaomi-ks.xml b/aidl/touch/vendor.lineage.touch-service.xiaomi-ks.xml new file mode 100644 index 0000000..60a0a8e --- /dev/null +++ b/aidl/touch/vendor.lineage.touch-service.xiaomi-ks.xml @@ -0,0 +1,10 @@ + + + vendor.lineage.touch + 1 + + IKeySwapper + default + + +