touch: Implement GloveMode support

Change-Id: I1bb2f502e5b6947dfb2d68572b098d0e5b058c28
This commit is contained in:
Bruno Martins
2025-06-10 19:38:24 +01:00
parent 74dbc92458
commit 1a462ed83c
7 changed files with 124 additions and 2 deletions

View File

@@ -8,6 +8,7 @@
| OPLUS_LINEAGE_LIVEDISPLAY_HAL | ENABLE_DM | Enable DisplayModes feature | false |
| OPLUS_LINEAGE_LIVEDISPLAY_HAL | ENABLE_PA | Enable PictureAdjustment feature | true |
| OPLUS_LINEAGE_LIVEDISPLAY_HAL | ENABLE_SE | Enable SunlightEnhancement feature | true |
| OPLUS_LINEAGE_TOUCH_HAL | ENABLE_GM | Enable GloveMode feature | false |
| OPLUS_LINEAGE_TOUCH_HAL | ENABLE_HTPR | Enable HighTouchPollingRate feature | true |
| OPLUS_LINEAGE_TOUCH_HAL | ENABLE_TG | Enable TouchscreenGesture feature | true |
| OPLUS_LINEAGE_TOUCH_HAL | INCLUDE_DIR | Device specific include dir path | |

View File

@@ -6,7 +6,10 @@
cc_binary {
name: "vendor.lineage.touch-service.oplus",
init_rc: ["vendor.lineage.touch-service.oplus.rc"],
vintf_fragments: select(soong_config_variable("OPLUS_LINEAGE_TOUCH_HAL", "ENABLE_HTPR"), {
vintf_fragments: select(soong_config_variable("OPLUS_LINEAGE_TOUCH_HAL", "ENABLE_GM"), {
"true": ["vendor.lineage.touch-service.oplus-gm.xml"],
default: [],
}) + select(soong_config_variable("OPLUS_LINEAGE_TOUCH_HAL", "ENABLE_HTPR"), {
"false": [],
default: ["vendor.lineage.touch-service.oplus-htpr.xml"],
}) + select(soong_config_variable("OPLUS_LINEAGE_TOUCH_HAL", "ENABLE_TG"), {
@@ -16,6 +19,7 @@ cc_binary {
vendor: true,
relative_install_path: "hw",
srcs: [
"GloveMode.cpp",
"HighTouchPollingRate.cpp",
"TouchscreenGesture.cpp",
"service.cpp",
@@ -35,7 +39,10 @@ cc_binary {
any @ flag_val: [flag_val],
default: [],
}),
cflags: select(soong_config_variable("OPLUS_LINEAGE_TOUCH_HAL", "ENABLE_HTPR"), {
cflags: select(soong_config_variable("OPLUS_LINEAGE_TOUCH_HAL", "ENABLE_GM"), {
"true": ["-DENABLE_GM=true"],
default: ["-DENABLE_GM=false"],
}) + select(soong_config_variable("OPLUS_LINEAGE_TOUCH_HAL", "ENABLE_HTPR"), {
"false": ["-DENABLE_HTPR=false"],
default: ["-DENABLE_HTPR=true"],
}) + select(soong_config_variable("OPLUS_LINEAGE_TOUCH_HAL", "ENABLE_TG"), {

63
aidl/touch/GloveMode.cpp Normal file
View File

@@ -0,0 +1,63 @@
/*
* SPDX-FileCopyrightText: 2025 The LineageOS Project
* SPDX-License-Identifier: Apache-2.0
*/
#define LOG_TAG "vendor.lineage.touch-service.oplus"
#include "GloveMode.h"
#include <android-base/file.h>
#include <android-base/logging.h>
#include <OplusTouchConstants.h>
using ::android::base::ReadFileToString;
using ::android::base::WriteStringToFile;
namespace {
constexpr const char* kGloveModeEnablePath = "/proc/touchpanel/glove_mode_enable";
} // anonymous namespace
namespace aidl {
namespace vendor {
namespace lineage {
namespace touch {
GloveMode::GloveMode(std::shared_ptr<IOplusTouch> oplusTouch)
: mOplusTouch(std::move(oplusTouch)) {}
ndk::ScopedAStatus GloveMode::getEnabled(bool* _aidl_return) {
std::string value;
if (mOplusTouch) {
mOplusTouch->touchReadNodeFile(OplusTouchConstants::DEFAULT_TP_IC_ID,
OplusTouchConstants::GLOVE_MODE_ENABLE_NODE, &value);
} else if (!ReadFileToString(kGloveModeEnablePath, &value)) {
LOG(ERROR) << "Failed to read current GloveMode state";
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
*_aidl_return = value[0] != '0';
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus GloveMode::setEnabled(bool enable) {
if (mOplusTouch) {
mOplusTouch->touchWriteNodeFileOneWay(OplusTouchConstants::DEFAULT_TP_IC_ID,
OplusTouchConstants::GLOVE_MODE_ENABLE_NODE,
enable ? "1" : "0");
} else if (!WriteStringToFile(enable ? "1" : "0", kGloveModeEnablePath, true)) {
LOG(ERROR) << "Failed to write GloveMode state";
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
return ndk::ScopedAStatus::ok();
}
} // namespace touch
} // namespace lineage
} // namespace vendor
} // namespace aidl

32
aidl/touch/GloveMode.h Normal file
View File

@@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: 2025 The LineageOS Project
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <aidl/vendor/lineage/touch/BnGloveMode.h>
#include <aidl/vendor/oplus/hardware/touch/IOplusTouch.h>
namespace aidl {
namespace vendor {
namespace lineage {
namespace touch {
using aidl::vendor::oplus::hardware::touch::IOplusTouch;
class GloveMode : public BnGloveMode {
public:
explicit GloveMode(std::shared_ptr<IOplusTouch> oplusTouch);
ndk::ScopedAStatus getEnabled(bool* _aidl_return) override;
ndk::ScopedAStatus setEnabled(bool enabled) override;
private:
std::shared_ptr<IOplusTouch> mOplusTouch;
};
} // namespace touch
} // namespace lineage
} // namespace vendor
} // namespace aidl

View File

@@ -5,6 +5,7 @@
#define LOG_TAG "vendor.lineage.touch-service.oplus"
#include "GloveMode.h"
#include "HighTouchPollingRate.h"
#include "TouchscreenGesture.h"
@@ -12,6 +13,7 @@
#include <android/binder_manager.h>
#include <android/binder_process.h>
using aidl::vendor::lineage::touch::GloveMode;
using aidl::vendor::lineage::touch::HighTouchPollingRate;
using aidl::vendor::lineage::touch::TouchscreenGesture;
using aidl::vendor::oplus::hardware::touch::IOplusTouch;
@@ -25,11 +27,20 @@ int main() {
AServiceManager_waitForService(instance.c_str())))
: nullptr;
std::shared_ptr<GloveMode> gm =
ENABLE_GM ? ndk::SharedRefBase::make<GloveMode>(oplusTouch) : nullptr;
std::shared_ptr<HighTouchPollingRate> htpr =
ENABLE_HTPR ? ndk::SharedRefBase::make<HighTouchPollingRate>(oplusTouch) : nullptr;
std::shared_ptr<TouchscreenGesture> tg =
ENABLE_TG ? ndk::SharedRefBase::make<TouchscreenGesture>(oplusTouch) : nullptr;
if (gm) {
const std::string instance = std::string(GloveMode::descriptor) + "/default";
const binder_status_t status =
AServiceManager_addService(gm->asBinder().get(), instance.c_str());
CHECK_EQ(status, STATUS_OK) << "Failed to add service " << instance << " " << status;
}
if (htpr) {
const std::string instance = std::string(HighTouchPollingRate::descriptor) + "/default";
const binder_status_t status =

View File

@@ -18,5 +18,6 @@ constexpr int DOUBLE_TAP_GESTURE = 1 << 1;
constexpr int DOUBLE_TAP_ENABLE_NODE = 1;
constexpr int DOUBLE_TAP_INDEP_NODE = 21;
constexpr int GAME_SWITCH_ENABLE_NODE = 26;
constexpr int GLOVE_MODE_ENABLE_NODE = 192;
} // namespace OplusTouchConstants

View File

@@ -0,0 +1,7 @@
<manifest version="1.0" type="device">
<hal format="aidl">
<name>vendor.lineage.touch</name>
<version>1</version>
<fqname>IGloveMode/default</fqname>
</hal>
</manifest>