Files
hardware_oplus/aidl/touch/HighTouchPollingRate.cpp
Maitreya25 165c5e47a9 touch: Support interfacing with stock OplusTouch service
Co-authored-by: inferno0230 <mail@inferno0230.in>
Co-authored-by: Mashopy <eliasgheeraert@gmail.com>
Co-authored-by: Bruno Martins <bgcngm@gmail.com>
Change-Id: I305ac931dac35a7fa422745f4250ffb1145c3bf6
2025-07-06 15:39:16 +02:00

64 lines
2.0 KiB
C++

/*
* SPDX-FileCopyrightText: 2025 The LineageOS Project
* SPDX-License-Identifier: Apache-2.0
*/
#define LOG_TAG "vendor.lineage.touch-service.oplus"
#include "HighTouchPollingRate.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* kGameSwitchEnablePath = "/proc/touchpanel/game_switch_enable";
} // anonymous namespace
namespace aidl {
namespace vendor {
namespace lineage {
namespace touch {
HighTouchPollingRate::HighTouchPollingRate(std::shared_ptr<IOplusTouch> oplusTouch)
: mOplusTouch(std::move(oplusTouch)) {}
ndk::ScopedAStatus HighTouchPollingRate::getEnabled(bool* _aidl_return) {
std::string value;
if (mOplusTouch) {
mOplusTouch->touchReadNodeFile(OplusTouchConstants::DEFAULT_TP_IC_ID,
OplusTouchConstants::GAME_SWITCH_ENABLE_NODE, &value);
} else if (!ReadFileToString(kGameSwitchEnablePath, &value)) {
LOG(ERROR) << "Failed to read current HighTouchPollingRate state";
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}
*_aidl_return = value[0] != '0';
return ndk::ScopedAStatus::ok();
}
ndk::ScopedAStatus HighTouchPollingRate::setEnabled(bool enable) {
if (mOplusTouch) {
mOplusTouch->touchWriteNodeFileOneWay(OplusTouchConstants::DEFAULT_TP_IC_ID,
OplusTouchConstants::GAME_SWITCH_ENABLE_NODE,
enable ? "1" : "0");
} else if (!WriteStringToFile(enable ? "1" : "0", kGameSwitchEnablePath, true)) {
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