power: Implement DT2W through OplusTouch

Co-authored-by: Maitreya25 <maitreyapatni25@gmail.com>
Co-authored-by: Mashopy <eliasgheeraert@gmail.com>
Co-authored-by: Bruno Martins <bgcngm@gmail.com>
Change-Id: I5ad57428aeefe68c8a188aa1e445f4091cbc0d8a
This commit is contained in:
DtHnAme
2024-06-07 20:51:07 +05:30
committed by Bruno Martins
parent 165c5e47a9
commit 00f0edf25e
3 changed files with 95 additions and 0 deletions

View File

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

26
power/Android.bp Normal file
View File

@@ -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",
],
}

66
power/power-mode.cpp Normal file
View File

@@ -0,0 +1,66 @@
/*
* SPDX-FileCopyrightText: 2024-2025 The LineageOS Project
* SPDX-License-Identifier: Apache-2.0
*/
#include <aidl/android/hardware/power/BnPower.h>
#include <aidl/vendor/oplus/hardware/touch/IOplusTouch.h>
#include <android-base/logging.h>
#include <android/binder_manager.h>
#include <OplusTouchConstants.h>
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<IOplusTouch> 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