aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Stefani <luca.stefani.ge1@gmail.com>2020-08-23 11:29:28 +0200
committerLuca Stefani <luca.stefani.ge1@gmail.com>2020-08-23 12:12:22 +0200
commite2a744760e7f87407074f5ca205b952bfe849b89 (patch)
tree774cadb79f811e4aba9eb70ac1dc7b65fb25e450
parentcb0fedf76c920db56c7cc896eb822c00b8617b3a (diff)
obiwan: Implement lineage touch HIDL HAL
Change-Id: I4eb8e0d29eb0e776914ac121edd1e43949731bdf
-rw-r--r--device.mk4
-rw-r--r--touch/.clang-format11
-rw-r--r--touch/Android.bp34
-rw-r--r--touch/GloveMode.cpp50
-rw-r--r--touch/GloveMode.h40
-rw-r--r--touch/TouchscreenGesture.cpp103
-rw-r--r--touch/TouchscreenGesture.h51
-rw-r--r--touch/lineage.touch@1.0-service.asus_kona.rc6
-rw-r--r--touch/lineage.touch@1.0-service.asus_kona.xml15
-rw-r--r--touch/service.cpp52
10 files changed, 366 insertions, 0 deletions
diff --git a/device.mk b/device.mk
index fe61f57..f706d44 100644
--- a/device.mk
+++ b/device.mk
@@ -54,6 +54,10 @@ PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/keychars/goodix_ts.kcm:$(TARGET_COPY_OUT_SYSTEM)/usr/keychars/goodix_ts.kcm \
$(LOCAL_PATH)/keylayout/goodix_ts.kl:$(TARGET_COPY_OUT_SYSTEM)/usr/keylayout/goodix_ts.kl
+# Touch
+PRODUCT_PACKAGES += \
+ lineage.touch@1.0-service.asus_kona
+
PRODUCT_SHIPPING_API_LEVEL := 29
# Inherit from asus sm8250-common
diff --git a/touch/.clang-format b/touch/.clang-format
new file mode 100644
index 0000000..ae4a451
--- /dev/null
+++ b/touch/.clang-format
@@ -0,0 +1,11 @@
+BasedOnStyle: Google
+AccessModifierOffset: -2
+AllowShortFunctionsOnASingleLine: Inline
+ColumnLimit: 100
+CommentPragmas: NOLINT:.*
+DerivePointerAlignment: false
+IndentWidth: 4
+PointerAlignment: Left
+TabWidth: 4
+UseTab: Never
+PenaltyExcessCharacter: 32
diff --git a/touch/Android.bp b/touch/Android.bp
new file mode 100644
index 0000000..83e2b8e
--- /dev/null
+++ b/touch/Android.bp
@@ -0,0 +1,34 @@
+//
+// Copyright (C) 2020 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.
+
+cc_binary {
+ name: "lineage.touch@1.0-service.asus_kona",
+ init_rc: ["lineage.touch@1.0-service.asus_kona.rc"],
+ defaults: ["hidl_defaults"],
+ relative_install_path: "hw",
+ srcs: [
+ "GloveMode.cpp",
+ "TouchscreenGesture.cpp",
+ "service.cpp",
+ ],
+ shared_libs: [
+ "libbase",
+ "libbinder",
+ "libhidlbase",
+ "libhidltransport",
+ "libutils",
+ "vendor.lineage.touch@1.0",
+ ],
+}
diff --git a/touch/GloveMode.cpp b/touch/GloveMode.cpp
new file mode 100644
index 0000000..5a34058
--- /dev/null
+++ b/touch/GloveMode.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2020 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 "GloveModeService"
+
+#include "GloveMode.h"
+
+#include <fstream>
+
+namespace vendor {
+namespace lineage {
+namespace touch {
+namespace V1_0 {
+namespace implementation {
+
+const std::string kGloveModePath = "/proc/driver/glove";
+
+Return<bool> GloveMode::isEnabled() {
+ std::ifstream file(kGloveModePath);
+ std::string line;
+ while (getline(file, line)) {
+ if (line == "Glove Mode: On") return true;
+ }
+ return false;
+}
+
+Return<bool> GloveMode::setEnabled(bool enabled) {
+ std::ofstream file(kGloveModePath);
+ file << (enabled ? "1" : "0");
+ return !file.fail();
+}
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace touch
+} // namespace lineage
+} // namespace vendor
diff --git a/touch/GloveMode.h b/touch/GloveMode.h
new file mode 100644
index 0000000..20f08e3
--- /dev/null
+++ b/touch/GloveMode.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2020 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 <vendor/lineage/touch/1.0/IGloveMode.h>
+
+namespace vendor {
+namespace lineage {
+namespace touch {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::Return;
+
+class GloveMode : public IGloveMode {
+ public:
+ // Methods from ::vendor::lineage::touch::V1_0::IGloveMode follow.
+ Return<bool> isEnabled() override;
+ Return<bool> setEnabled(bool enabled) override;
+};
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace touch
+} // namespace lineage
+} // namespace vendor
diff --git a/touch/TouchscreenGesture.cpp b/touch/TouchscreenGesture.cpp
new file mode 100644
index 0000000..3313e8e
--- /dev/null
+++ b/touch/TouchscreenGesture.cpp
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2020 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 "TouchscreenGestureService"
+
+#include "TouchscreenGesture.h"
+
+#include <bitset>
+#include <fstream>
+#include <map>
+#include <type_traits>
+#include <vector>
+
+namespace {
+template <typename T>
+std::enable_if_t<std::is_integral<T>::value, std::string> encode_binary(T i) {
+ return std::bitset<sizeof(T) * 8>(i).to_string();
+}
+} // anonymous namespace
+
+namespace vendor {
+namespace lineage {
+namespace touch {
+namespace V1_0 {
+namespace implementation {
+
+const std::string kGesturePath = "/proc/driver/gesture_type";
+
+const std::map<int32_t, TouchscreenGesture::GestureInfo> TouchscreenGesture::kGestureInfoMap = {
+ // clang-format off
+ {0, {17, "Letter W"}},
+ {1, {31, "Letter S"}},
+ {2, {18, "Letter e"}},
+ {3, {50, "Letter M"}},
+ {4, {44, "Letter Z"}},
+ {5, {47, "Letter V"}},
+ {6, {168, "Left arrow"}},
+ {7, {159, "Right arrow"}},
+ {8, {119, "Two fingers down swipe"}},
+ // clang-format on
+};
+
+const uint8_t kKeyMaskGestureControl = 1 << 0;
+const std::vector<uint8_t> kGestureMasks = {
+ 1 << 1, // W gesture mask
+ 1 << 2, // S gesture mask
+ 1 << 3, // e gesture mask
+ 1 << 4, // M gesture mask
+ 1 << 5, // Z gesture mask
+ 1 << 6, // V gesture mask
+ 1 << 7, // Music control mask
+ 1 << 7, // Music control mask
+ 1 << 7, // Music control mask
+};
+
+Return<void> TouchscreenGesture::getSupportedGestures(getSupportedGestures_cb resultCb) {
+ std::vector<Gesture> gestures;
+
+ for (const auto& entry : kGestureInfoMap) {
+ gestures.push_back({entry.first, entry.second.name, entry.second.keycode});
+ }
+ resultCb(gestures);
+
+ return Void();
+}
+
+Return<bool> TouchscreenGesture::setGestureEnabled(
+ const ::vendor::lineage::touch::V1_0::Gesture& gesture, bool enabled) {
+ uint8_t gestureMode;
+ uint8_t mask = kGestureMasks[gesture.id];
+ std::fstream file(kGesturePath);
+ file >> gestureMode;
+
+ if (enabled)
+ gestureMode |= mask;
+ else
+ gestureMode &= ~mask;
+
+ if (gestureMode != 0) gestureMode |= kKeyMaskGestureControl;
+
+ file << encode_binary(gestureMode);
+
+ return !file.fail();
+}
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace touch
+} // namespace lineage
+} // namespace vendor
diff --git a/touch/TouchscreenGesture.h b/touch/TouchscreenGesture.h
new file mode 100644
index 0000000..0f6f097
--- /dev/null
+++ b/touch/TouchscreenGesture.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2020 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 <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;
+
+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 ::vendor::lineage::touch::V1_0::Gesture& gesture,
+ bool enabled) override;
+
+ private:
+ typedef struct {
+ int32_t keycode;
+ const char* name;
+ } GestureInfo;
+ static const std::map<int32_t, GestureInfo> kGestureInfoMap; // id -> info
+};
+
+} // namespace implementation
+} // namespace V1_0
+} // namespace touch
+} // namespace lineage
+} // namespace vendor
diff --git a/touch/lineage.touch@1.0-service.asus_kona.rc b/touch/lineage.touch@1.0-service.asus_kona.rc
new file mode 100644
index 0000000..a6f2ad5
--- /dev/null
+++ b/touch/lineage.touch@1.0-service.asus_kona.rc
@@ -0,0 +1,6 @@
+service touch-hal-1-0 /system/bin/hw/lineage.touch@1.0-service.asus_kona
+ interface vendor.lineage.touch@1.0::IGloveMode default
+ interface vendor.lineage.touch@1.0::ITouchscreenGesture default
+ class hal
+ user system
+ group system
diff --git a/touch/lineage.touch@1.0-service.asus_kona.xml b/touch/lineage.touch@1.0-service.asus_kona.xml
new file mode 100644
index 0000000..c3fbf38
--- /dev/null
+++ b/touch/lineage.touch@1.0-service.asus_kona.xml
@@ -0,0 +1,15 @@
+<manifest version="1.0" type="framework">
+ <hal format="hidl" optional="true">
+ <name>vendor.lineage.touch</name>
+ <transport>hwbinder</transport>
+ <version>1.0</version>
+ <interface>
+ <name>IGloveMode</name>
+ <instance>default</instance>
+ </interface>
+ <interface>
+ <name>ITouchscreenGesture</name>
+ <instance>default</instance>
+ </interface>
+ </hal>
+</manifest>
diff --git a/touch/service.cpp b/touch/service.cpp
new file mode 100644
index 0000000..a0be25f
--- /dev/null
+++ b/touch/service.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2020 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 "lineage.touch@1.0-service.asus_kona"
+
+#include <android-base/logging.h>
+#include <hidl/HidlTransportSupport.h>
+
+#include "GloveMode.h"
+#include "TouchscreenGesture.h"
+
+using ::vendor::lineage::touch::V1_0::IGloveMode;
+using ::vendor::lineage::touch::V1_0::ITouchscreenGesture;
+using ::vendor::lineage::touch::V1_0::implementation::GloveMode;
+using ::vendor::lineage::touch::V1_0::implementation::TouchscreenGesture;
+
+int main() {
+ android::sp<IGloveMode> gloveMode = new GloveMode();
+ android::sp<ITouchscreenGesture> touchscreenGesture = new TouchscreenGesture();
+
+ android::hardware::configureRpcThreadpool(1, true /*callerWillJoin*/);
+
+ if (gloveMode->registerAsService() != android::OK) {
+ LOG(ERROR) << "Cannot register touchscreen glove HAL service.";
+ return 1;
+ }
+
+ if (touchscreenGesture->registerAsService() != android::OK) {
+ LOG(ERROR) << "Cannot register touchscreen gesture HAL service.";
+ return 1;
+ }
+
+ LOG(INFO) << "Touchscreen HAL service ready.";
+
+ android::hardware::joinRpcThreadpool();
+
+ LOG(ERROR) << "Touchscreen HAL service failed to join thread pool.";
+ return 1;
+}