diff --git a/hidl/touch/.clang-format b/hidl/touch/.clang-format new file mode 120000 index 0000000..0457b53 --- /dev/null +++ b/hidl/touch/.clang-format @@ -0,0 +1 @@ +../../../../build/soong/scripts/system-clang-format \ No newline at end of file diff --git a/hidl/touch/Android.bp b/hidl/touch/Android.bp new file mode 100644 index 0000000..7a82894 --- /dev/null +++ b/hidl/touch/Android.bp @@ -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"], +} diff --git a/hidl/touch/TouchscreenGesture.cpp b/hidl/touch/TouchscreenGesture.cpp new file mode 100644 index 0000000..117c338 --- /dev/null +++ b/hidl/touch/TouchscreenGesture.cpp @@ -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 +#include + +#include +#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 TouchscreenGesture::getSupportedGestures(getSupportedGestures_cb resultCb) { + std::vector gestures; + + for (const auto& [id, name] : kGestureNames) { + if (kSupportedGestures & (1 << id)) { + gestures.push_back({static_cast(gestures.size()), name, kGestureStartKey + id}); + } + } + + resultCb(gestures); + + return Void(); +} + +Return 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 diff --git a/hidl/touch/include/touch/oplus/TouchscreenGesture.h b/hidl/touch/include/touch/oplus/TouchscreenGesture.h new file mode 100644 index 0000000..2b0abf6 --- /dev/null +++ b/hidl/touch/include/touch/oplus/TouchscreenGesture.h @@ -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 +#include +#include +#include + +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 getSupportedGestures(getSupportedGestures_cb resultCb) override; + Return 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 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 + 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 diff --git a/hidl/touch/include/touch/oplus/TouchscreenGestureConfig.h b/hidl/touch/include/touch/oplus/TouchscreenGestureConfig.h new file mode 100644 index 0000000..b9eb43f --- /dev/null +++ b/hidl/touch/include/touch/oplus/TouchscreenGestureConfig.h @@ -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 diff --git a/hidl/touch/service.cpp b/hidl/touch/service.cpp new file mode 100644 index 0000000..3ac15c9 --- /dev/null +++ b/hidl/touch/service.cpp @@ -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 +#include +#include + +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 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 +} diff --git a/hidl/touch/vendor.lineage.touch@1.0-service.oplus.rc b/hidl/touch/vendor.lineage.touch@1.0-service.oplus.rc new file mode 100644 index 0000000..2320bf0 --- /dev/null +++ b/hidl/touch/vendor.lineage.touch@1.0-service.oplus.rc @@ -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 diff --git a/hidl/touch/vendor.lineage.touch@1.0-service.oplus.xml b/hidl/touch/vendor.lineage.touch@1.0-service.oplus.xml new file mode 100644 index 0000000..fb862bb --- /dev/null +++ b/hidl/touch/vendor.lineage.touch@1.0-service.oplus.xml @@ -0,0 +1,11 @@ + + + vendor.lineage.touch + hwbinder + 1.0 + + ITouchscreenGesture + default + + +