hidl: Setup touchscreen gestures with Lineage touch HIDL HAL

This takes advantage of the touchscreen gesture nodes exposed by Oplus
touchscreen drivers.

Change-Id: I5a43b8f922a8d1c940e367d22d377b7161913d3a
This commit is contained in:
LuK1337
2021-09-16 18:33:12 +02:00
parent 745a264171
commit ce722bdb50
8 changed files with 288 additions and 0 deletions

1
hidl/touch/.clang-format Symbolic link
View File

@@ -0,0 +1 @@
../../../../build/soong/scripts/system-clang-format

19
hidl/touch/Android.bp Normal file
View File

@@ -0,0 +1,19 @@
cc_binary {
name: "vendor.lineage.touch@1.0-service.oplus",
defaults: ["hidl_defaults"],
init_rc: ["vendor.lineage.touch@1.0-service.oplus.rc"],
vintf_fragments: ["vendor.lineage.touch@1.0-service.oplus.xml"],
vendor: true,
relative_install_path: "hw",
srcs: [
"TouchscreenGesture.cpp",
"service.cpp",
],
shared_libs: [
"libbase",
"libhidlbase",
"libutils",
"vendor.lineage.touch@1.0",
],
local_include_dirs: ["include"],
}

View File

@@ -0,0 +1,76 @@
/*
* 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 <android-base/file.h>
#include <android-base/strings.h>
#include <touch/oplus/TouchscreenGesture.h>
#include "touch/oplus/TouchscreenGestureConfig.h"
using ::android::base::ReadFileToString;
using ::android::base::Trim;
using ::android::base::WriteStringToFile;
namespace {
constexpr const char* kGestureEnableIndepPath = "/proc/touchpanel/double_tap_enable_indep";
} // anonymous namespace
namespace vendor {
namespace lineage {
namespace touch {
namespace V1_0 {
namespace implementation {
Return<void> TouchscreenGesture::getSupportedGestures(getSupportedGestures_cb resultCb) {
std::vector<Gesture> gestures;
for (const auto& [id, name] : kGestureNames) {
if (kSupportedGestures & (1 << id)) {
gestures.push_back({static_cast<int>(gestures.size()), name, kGestureStartKey + id});
}
}
resultCb(gestures);
return Void();
}
Return<bool> TouchscreenGesture::setGestureEnabled(const Gesture& gesture, bool enabled) {
std::string tmp;
int contents = 0;
if (ReadFileToString(kGestureEnableIndepPath, &tmp)) {
contents = std::stoi(Trim(tmp), nullptr, 16);
}
if (enabled) {
contents |= (1 << (gesture.keycode - kGestureStartKey));
} else {
contents &= ~(1 << (gesture.keycode - kGestureStartKey));
}
return WriteStringToFile(std::to_string(contents), kGestureEnableIndepPath, true);
}
} // namespace implementation
} // namespace V1_0
} // namespace touch
} // namespace lineage
} // namespace vendor

View File

@@ -0,0 +1,98 @@
/*
* 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/ITouchscreenGesture.h>
#include <map>
namespace vendor {
namespace lineage {
namespace touch {
namespace V1_0 {
namespace implementation {
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::vendor::lineage::touch::V1_0::Gesture;
class TouchscreenGesture : public ITouchscreenGesture {
public:
// Methods from ::vendor::lineage::touch::V1_0::ITouchscreenGesture follow.
Return<void> getSupportedGestures(getSupportedGestures_cb resultCb) override;
Return<bool> setGestureEnabled(const Gesture& gesture, bool enabled) override;
private:
// See: drivers/input/touchscreen/oplus_touchscreen_v2/touchpanel_common.h
static constexpr int kGestureStartKey = 246;
enum {
kGestureUnknown,
kGestureDoubleTap,
kGestureUpVee,
kGestureDownVee,
kGestureLeftVee,
kGestureRightVee,
kGestureCircle,
kGestureDoubleSwipe,
kGestureLeftToRight,
kGestureRightToLeft,
kGestureUpToDown,
kGestureDownToUp,
kGestureM,
kGestureW,
kGestureFingerprintDown,
kGestureFingerprintUp,
kGestureSingleTap,
kGestureHeart,
kGestureS,
};
const std::map<int, std::string> kGestureNames = {
{kGestureUnknown, "Unknown"},
{kGestureDoubleTap, "Double tap"},
{kGestureUpVee, "Down arrow"},
{kGestureDownVee, "Up arrow"},
{kGestureLeftVee, "Right arrow"},
{kGestureRightVee, "Left arrow"},
{kGestureCircle, "Letter O"},
{kGestureDoubleSwipe, "Two fingers down swipe"},
{kGestureLeftToRight, "One finger right swipe"},
{kGestureRightToLeft, "One finger left swipe"},
{kGestureUpToDown, "One finger down swipe"},
{kGestureDownToUp, "One finger up swipe"},
{kGestureM, "Letter M"},
{kGestureW, "Letter W"},
{kGestureFingerprintDown, "Fingerprint down"},
{kGestureFingerprintUp, "Fingerprint up"},
{kGestureSingleTap, "Single tap"},
{kGestureHeart, "Heart"},
{kGestureS, "Letter S"},
};
template <typename H, typename... T>
static constexpr int makeBitField(H head, T... tail) {
return ((1 << head) | ... | (1 << tail));
}
static const int kSupportedGestures;
};
} // namespace implementation
} // namespace V1_0
} // namespace touch
} // namespace lineage
} // namespace vendor

View File

@@ -0,0 +1,36 @@
/*
* 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 "TouchscreenGesture.h"
namespace vendor {
namespace lineage {
namespace touch {
namespace V1_0 {
namespace implementation {
const int TouchscreenGesture::kSupportedGestures = makeBitField(
kGestureUpVee, kGestureDownVee, kGestureLeftVee, kGestureRightVee, kGestureCircle,
kGestureDoubleSwipe, kGestureLeftToRight, kGestureRightToLeft, kGestureUpToDown,
kGestureDownToUp, kGestureM, kGestureW, kGestureSingleTap, kGestureS);
} // namespace implementation
} // namespace V1_0
} // namespace touch
} // namespace lineage
} // namespace vendor

43
hidl/touch/service.cpp Normal file
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.
*/
#define LOG_TAG "vendor.lineage.touch@1.0-service.oplus"
#include <android-base/logging.h>
#include <hidl/HidlTransportSupport.h>
#include <touch/oplus/TouchscreenGesture.h>
using android::sp;
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
using vendor::lineage::touch::V1_0::ITouchscreenGesture;
using vendor::lineage::touch::V1_0::implementation::TouchscreenGesture;
int main() {
sp<ITouchscreenGesture> gestureService = new TouchscreenGesture();
configureRpcThreadpool(1, true /*callerWillJoin*/);
if (gestureService->registerAsService() != android::OK) {
LOG(ERROR) << "Can't register TouchscreenGesture HAL service";
return 1;
}
joinRpcThreadpool();
return 0; // should never get here
}

View File

@@ -0,0 +1,4 @@
service vendor.touch-hal-1-0 /vendor/bin/hw/vendor.lineage.touch@1.0-service.oplus
class hal
user system
group system

View File

@@ -0,0 +1,11 @@
<manifest version="1.0" type="device">
<hal format="hidl">
<name>vendor.lineage.touch</name>
<transport>hwbinder</transport>
<version>1.0</version>
<interface>
<name>ITouchscreenGesture</name>
<instance>default</instance>
</interface>
</hal>
</manifest>