touch: Implement opt-in IHighTouchPollingRate interface

Change-Id: Ia0b45caa224cc9fea38f9b4efacce3287f888baa
This commit is contained in:
LuK1337
2022-04-11 20:28:02 +02:00
parent cf5e10f923
commit a39ee49e45
4 changed files with 103 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ cc_binary {
vendor: true,
relative_install_path: "hw",
srcs: [
"HighTouchPollingRate.cpp",
"TouchscreenGesture.cpp",
"service.cpp",
],

View File

@@ -0,0 +1,51 @@
/*
* Copyright (C) 2022 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "vendor.lineage.touch@1.0-service.oplus"
#include "HighTouchPollingRate.h"
#include <android-base/file.h>
using ::android::base::ReadFileToString;
using ::android::base::WriteStringToFile;
namespace {
constexpr const char* kGameSwitchEnablePath = "/proc/touchpanel/game_switch_enable";
} // anonymous namespace
namespace vendor {
namespace lineage {
namespace touch {
namespace V1_0 {
namespace implementation {
Return<bool> HighTouchPollingRate::isEnabled() {
std::string value;
return ReadFileToString(kGameSwitchEnablePath, &value) && value[0] != '0';
}
Return<bool> HighTouchPollingRate::setEnabled(bool enabled) {
return WriteStringToFile(enabled ? "1" : "0", kGameSwitchEnablePath, true);
}
} // namespace implementation
} // namespace V1_0
} // namespace touch
} // namespace lineage
} // namespace vendor

View File

@@ -0,0 +1,43 @@
/*
* Copyright (C) 2022 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
#include <vendor/lineage/touch/1.0/IHighTouchPollingRate.h>
namespace vendor {
namespace lineage {
namespace touch {
namespace V1_0 {
namespace implementation {
using ::android::hardware::Return;
using ::android::hardware::Void;
class HighTouchPollingRate : public IHighTouchPollingRate {
public:
// Methods from ::vendor::lineage::touch::V1_0::IHighTouchPollingRate follow.
Return<bool> isEnabled() override;
Return<bool> setEnabled(bool enabled) override;
};
} // namespace implementation
} // namespace V1_0
} // namespace touch
} // namespace lineage
} // namespace vendor

View File

@@ -18,20 +18,28 @@
#include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>
#include "HighTouchPollingRate.h"
#include "TouchscreenGesture.h"
using android::sp;
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using vendor::lineage::touch::V1_0::IHighTouchPollingRate;
using vendor::lineage::touch::V1_0::ITouchscreenGesture;
using vendor::lineage::touch::V1_0::implementation::HighTouchPollingRate;
using vendor::lineage::touch::V1_0::implementation::TouchscreenGesture;
int main() {
sp<IHighTouchPollingRate> highToushPollingRateService = new HighTouchPollingRate();
sp<ITouchscreenGesture> gestureService = new TouchscreenGesture();
configureRpcThreadpool(1, true /*callerWillJoin*/);
if (highToushPollingRateService->registerAsService() != android::OK) {
LOG(WARNING) << "Can't register HighTouchPollingRate HAL service";
}
if (gestureService->registerAsService() != android::OK) {
LOG(ERROR) << "Can't register TouchscreenGesture HAL service";
return 1;