From 00f0edf25e61c3fe75f62c4350a8b2f70a0ee894 Mon Sep 17 00:00:00 2001 From: DtHnAme <32587943+DtHnAme@users.noreply.github.com> Date: Fri, 7 Jun 2024 20:51:07 +0530 Subject: [PATCH] power: Implement DT2W through OplusTouch Co-authored-by: Maitreya25 Co-authored-by: Mashopy Co-authored-by: Bruno Martins Change-Id: I5ad57428aeefe68c8a188aa1e445f4091cbc0d8a --- .../touch/touch-headers/OplusTouchConstants.h | 3 + power/Android.bp | 26 ++++++++ power/power-mode.cpp | 66 +++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 power/Android.bp create mode 100644 power/power-mode.cpp diff --git a/aidl/touch/touch-headers/OplusTouchConstants.h b/aidl/touch/touch-headers/OplusTouchConstants.h index 45ef7d4..d2e9c8d 100644 --- a/aidl/touch/touch-headers/OplusTouchConstants.h +++ b/aidl/touch/touch-headers/OplusTouchConstants.h @@ -11,6 +11,9 @@ namespace OplusTouchConstants { constexpr int DEFAULT_TP_IC_ID = 0; constexpr int SUB_DISPLAY_TP_IC_ID = 1; +// Features +constexpr int DOUBLE_TAP_GESTURE = 1 << 1; + // Node IDs constexpr int DOUBLE_TAP_ENABLE_NODE = 1; constexpr int DOUBLE_TAP_INDEP_NODE = 21; diff --git a/power/Android.bp b/power/Android.bp new file mode 100644 index 0000000..a78ea62 --- /dev/null +++ b/power/Android.bp @@ -0,0 +1,26 @@ +// +// SPDX-FileCopyrightText: 2024-2025 The LineageOS Project +// SPDX-License-Identifier: Apache-2.0 +// + +cc_library_static { + name: "power-ext-oplus", + defaults: ["android.hardware.power-ndk_shared"], + vendor: true, + srcs: [ + "power-mode.cpp", + ], + cppflags: select(soong_config_variable("power_libperfmgr", "mode_extension_lib"), { + any: ["-DLIBPERFMGR_EXT"], + default: [], + }), + header_libs: [ + "vendor.oplus.hardware.touch-headers", + ], + shared_libs: [ + "libbase", + ], + whole_static_libs: [ + "vendor.oplus.hardware.touch-V2-ndk", + ], +} diff --git a/power/power-mode.cpp b/power/power-mode.cpp new file mode 100644 index 0000000..208bcfc --- /dev/null +++ b/power/power-mode.cpp @@ -0,0 +1,66 @@ +/* + * SPDX-FileCopyrightText: 2024-2025 The LineageOS Project + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include +#include + +#include + +using aidl::android::hardware::power::Mode; +using aidl::vendor::oplus::hardware::touch::IOplusTouch; + +#ifdef LIBPERFMGR_EXT +namespace aidl::google::hardware::power::impl::pixel { +#else +namespace aidl::android::hardware::power::impl { +#endif + +bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return) { + switch (type) { + case Mode::DOUBLE_TAP_TO_WAKE: + *_aidl_return = true; + return true; + default: + return false; + } +} + +bool setDeviceSpecificMode(Mode type, bool enabled) { + switch (type) { + case Mode::DOUBLE_TAP_TO_WAKE: { + std::string tmp; + int contents = 0; + + const std::string instance = std::string() + IOplusTouch::descriptor + "/default"; + std::shared_ptr oplusTouch = IOplusTouch::fromBinder( + ndk::SpAIBinder(AServiceManager_waitForService(instance.c_str()))); + LOG(INFO) << "Power mode: " << toString(type) << " isDoubleTapEnabled: " << enabled; + + oplusTouch->touchReadNodeFile(OplusTouchConstants::DEFAULT_TP_IC_ID, + OplusTouchConstants::DOUBLE_TAP_INDEP_NODE, &tmp); + contents = std::stoi(tmp, nullptr, 16); + + if (enabled) { + contents |= OplusTouchConstants::DOUBLE_TAP_GESTURE; + } else { + contents &= ~OplusTouchConstants::DOUBLE_TAP_GESTURE; + } + + oplusTouch->touchWriteNodeFileOneWay(OplusTouchConstants::DEFAULT_TP_IC_ID, + OplusTouchConstants::DOUBLE_TAP_ENABLE_NODE, "1"); + oplusTouch->touchWriteNodeFileOneWay(OplusTouchConstants::DEFAULT_TP_IC_ID, + OplusTouchConstants::DOUBLE_TAP_INDEP_NODE, + std::to_string(contents)); + return true; + } + default: + return false; + } +} + +} // namespace