diff --git a/lineagehw/hidl/touch/Android.bp b/lineagehw/hidl/touch/Android.bp index 310fb529..0197b6cb 100644 --- a/lineagehw/hidl/touch/Android.bp +++ b/lineagehw/hidl/touch/Android.bp @@ -12,17 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -cc_library_shared { - // FIXME: this should only be -impl for a passthrough hal. - // In most cases, to convert this to a binderized implementation, you should: - // - change '-impl' to '-service' here and make it a cc_binary instead of a - // cc_library_shared. - // - add a *.rc file for this module. - // - delete HIDL_FETCH_I* functions. - // - call configureRpcThreadpool and registerAsService on the instance. - // You may also want to append '-impl/-service' with a specific identifier like - // '-vendor' or '-' etc to distinguish it. - name: "vendor.lineage.touch@1.0-impl", +cc_binary { + name: "vendor.lineage.touch@1.0-service.samsung", + init_rc: ["vendor.lineage.touch@1.0-service.samsung.rc"], + defaults: ["hidl_defaults"], relative_install_path: "hw", // FIXME: this should be 'vendor: true' for modules that will eventually be // on AOSP. @@ -32,8 +25,11 @@ cc_library_shared { "KeyDisabler.cpp", "StylusMode.cpp", "TouchscreenGesture.cpp", + "service.cpp" ], shared_libs: [ + "libbase", + "libbinder", "libhidlbase", "libhidltransport", "libutils", diff --git a/lineagehw/hidl/touch/GloveMode.cpp b/lineagehw/hidl/touch/GloveMode.cpp index 37c58ede..dcac846a 100644 --- a/lineagehw/hidl/touch/GloveMode.cpp +++ b/lineagehw/hidl/touch/GloveMode.cpp @@ -14,28 +14,49 @@ * limitations under the License. */ +#include + #include "GloveMode.h" namespace vendor { namespace lineage { namespace touch { namespace V1_0 { -namespace implementation { +namespace samsung { -// Methods from ::vendor::lineage::touch::V1_0::IGloveMode follow. -Return GloveMode::setEnabled(bool enabled) { - // TODO implement - return Void(); +bool GloveMode::isSupported() { + std::ifstream file("/sys/class/sec/tsp/cmd_list"); + if (file.is_open()) { + std::string line; + while (getline(file, line)) { + if (!line.compare("glove_mode")) + return true; + } + file.close(); + } + return false; } +// Methods from ::vendor::lineage::touch::V1_0::IGloveMode follow. +Return GloveMode::isEnabled() { + std::ifstream file("/sys/class/sec/tsp/cmd_result"); + if (file.is_open()) { + std::string line; + getline(file, line); + if (!line.compare("glove_mode,1:OK")) + return true; + file.close(); + } + return false; +} -// Methods from ::android::hidl::base::V1_0::IBase follow. +Return GloveMode::setEnabled(bool enabled) { + std::ofstream file("/sys/class/sec/tsp/cmd"); + file << "glove_mode," << (enabled ? "1" : "0"); + return true; +} -//IGloveMode* HIDL_FETCH_IGloveMode(const char* /* name */) { - //return new GloveMode(); -//} -// -} // namespace implementation +} // namespace samsung } // namespace V1_0 } // namespace touch } // namespace lineage diff --git a/lineagehw/hidl/touch/GloveMode.h b/lineagehw/hidl/touch/GloveMode.h index 925ceb40..7208a8d7 100644 --- a/lineagehw/hidl/touch/GloveMode.h +++ b/lineagehw/hidl/touch/GloveMode.h @@ -25,7 +25,7 @@ namespace vendor { namespace lineage { namespace touch { namespace V1_0 { -namespace implementation { +namespace samsung { using ::android::hardware::hidl_array; using ::android::hardware::hidl_memory; @@ -35,18 +35,21 @@ using ::android::hardware::Return; using ::android::hardware::Void; using ::android::sp; -struct GloveMode : public IGloveMode { +class GloveMode : public IGloveMode { + public: + GloveMode() = default; + + bool isSupported(); + // Methods from ::vendor::lineage::touch::V1_0::IGloveMode follow. - Return setEnabled(bool enabled) override; + Return isEnabled() override; + Return setEnabled(bool enabled) override; // Methods from ::android::hidl::base::V1_0::IBase follow. }; -// FIXME: most likely delete, this is only for passthrough implementations -// extern "C" IGloveMode* HIDL_FETCH_IGloveMode(const char* name); - -} // namespace implementation +} // namespace samsung } // namespace V1_0 } // namespace touch } // namespace lineage diff --git a/lineagehw/hidl/touch/KeyDisabler.cpp b/lineagehw/hidl/touch/KeyDisabler.cpp index 469e1472..54691a00 100644 --- a/lineagehw/hidl/touch/KeyDisabler.cpp +++ b/lineagehw/hidl/touch/KeyDisabler.cpp @@ -14,28 +14,40 @@ * limitations under the License. */ +#include + #include "KeyDisabler.h" namespace vendor { namespace lineage { namespace touch { namespace V1_0 { -namespace implementation { +namespace samsung { -// Methods from ::vendor::lineage::touch::V1_0::IKeyDisabler follow. -Return KeyDisabler::setEnabled(bool enabled) { - // TODO implement - return Void(); +bool KeyDisabler::isSupported() { + std::ofstream file("/sys/class/sec/sec_touchkey/input/enabled"); + return file.good(); } +// Methods from ::vendor::lineage::touch::V1_0::IKeyDisabler follow. +Return KeyDisabler::isEnabled() { + std::ifstream file("/sys/class/sec/sec_touchkey/input/enabled"); + int status = -1; + + if (file.is_open()) { + file >> status; + } -// Methods from ::android::hidl::base::V1_0::IBase follow. + return file.good() && status == 0; +} + +Return KeyDisabler::setEnabled(bool enabled) { + std::ofstream file("/sys/class/sec/sec_touchkey/input/enabled"); + file << (enabled ? "0" : "1"); + return true; +} -//IKeyDisabler* HIDL_FETCH_IKeyDisabler(const char* /* name */) { - //return new KeyDisabler(); -//} -// -} // namespace implementation +} // namespace samsung } // namespace V1_0 } // namespace touch } // namespace lineage diff --git a/lineagehw/hidl/touch/KeyDisabler.h b/lineagehw/hidl/touch/KeyDisabler.h index ffe4f0d1..3b56b469 100644 --- a/lineagehw/hidl/touch/KeyDisabler.h +++ b/lineagehw/hidl/touch/KeyDisabler.h @@ -25,7 +25,7 @@ namespace vendor { namespace lineage { namespace touch { namespace V1_0 { -namespace implementation { +namespace samsung { using ::android::hardware::hidl_array; using ::android::hardware::hidl_memory; @@ -35,18 +35,21 @@ using ::android::hardware::Return; using ::android::hardware::Void; using ::android::sp; -struct KeyDisabler : public IKeyDisabler { +class KeyDisabler : public IKeyDisabler { + public: + KeyDisabler() = default; + + bool isSupported(); + // Methods from ::vendor::lineage::touch::V1_0::IKeyDisabler follow. - Return setEnabled(bool enabled) override; + Return isEnabled() override; + Return setEnabled(bool enabled) override; // Methods from ::android::hidl::base::V1_0::IBase follow. }; -// FIXME: most likely delete, this is only for passthrough implementations -// extern "C" IKeyDisabler* HIDL_FETCH_IKeyDisabler(const char* name); - -} // namespace implementation +} // namespace samsung } // namespace V1_0 } // namespace touch } // namespace lineage diff --git a/lineagehw/hidl/touch/StylusMode.cpp b/lineagehw/hidl/touch/StylusMode.cpp index 5f5a33a9..aa86e7ab 100644 --- a/lineagehw/hidl/touch/StylusMode.cpp +++ b/lineagehw/hidl/touch/StylusMode.cpp @@ -14,28 +14,49 @@ * limitations under the License. */ +#include + #include "StylusMode.h" namespace vendor { namespace lineage { namespace touch { namespace V1_0 { -namespace implementation { +namespace samsung { -// Methods from ::vendor::lineage::touch::V1_0::IStylusMode follow. -Return StylusMode::setEnabled(bool enabled) { - // TODO implement - return Void(); +bool StylusMode::isSupported() { + std::ifstream file("/sys/class/sec/tsp/cmd_list"); + if (file.is_open()) { + std::string line; + while (getline(file, line)) { + if (!line.compare("hover_enable")) + return true; + } + file.close(); + } + return false; } +// Methods from ::vendor::lineage::touch::V1_0::IStylusMode follow. +Return StylusMode::isEnabled() { + std::ifstream file("/sys/class/sec/tsp/cmd_result"); + if (file.is_open()) { + std::string line; + getline(file, line); + if (!line.compare("hover_enable,1:OK")) + return true; + file.close(); + } + return false; +} -// Methods from ::android::hidl::base::V1_0::IBase follow. +Return StylusMode::setEnabled(bool enabled) { + std::ofstream file("/sys/class/sec/tsp/cmd"); + file << "hover_enable," << (enabled ? "1" : "0"); + return true; +} -//IStylusMode* HIDL_FETCH_IStylusMode(const char* /* name */) { - //return new StylusMode(); -//} -// -} // namespace implementation +} // namespace samsung } // namespace V1_0 } // namespace touch } // namespace lineage diff --git a/lineagehw/hidl/touch/StylusMode.h b/lineagehw/hidl/touch/StylusMode.h index 4e7401d5..2eae6c8f 100644 --- a/lineagehw/hidl/touch/StylusMode.h +++ b/lineagehw/hidl/touch/StylusMode.h @@ -25,7 +25,7 @@ namespace vendor { namespace lineage { namespace touch { namespace V1_0 { -namespace implementation { +namespace samsung { using ::android::hardware::hidl_array; using ::android::hardware::hidl_memory; @@ -35,18 +35,21 @@ using ::android::hardware::Return; using ::android::hardware::Void; using ::android::sp; -struct StylusMode : public IStylusMode { +class StylusMode : public IStylusMode { + public: + StylusMode() = default; + + bool isSupported(); + // Methods from ::vendor::lineage::touch::V1_0::IStylusMode follow. - Return setEnabled(bool enabled) override; + Return isEnabled() override; + Return setEnabled(bool enabled) override; // Methods from ::android::hidl::base::V1_0::IBase follow. }; -// FIXME: most likely delete, this is only for passthrough implementations -// extern "C" IStylusMode* HIDL_FETCH_IStylusMode(const char* name); - -} // namespace implementation +} // namespace samsung } // namespace V1_0 } // namespace touch } // namespace lineage diff --git a/lineagehw/hidl/touch/TouchscreenGesture.cpp b/lineagehw/hidl/touch/TouchscreenGesture.cpp index cadea2bd..1f47115e 100644 --- a/lineagehw/hidl/touch/TouchscreenGesture.cpp +++ b/lineagehw/hidl/touch/TouchscreenGesture.cpp @@ -14,33 +14,66 @@ * limitations under the License. */ +#include + #include "TouchscreenGesture.h" namespace vendor { namespace lineage { namespace touch { namespace V1_0 { -namespace implementation { +namespace samsung { + +static constexpr const char* kGeasturePath = "/sys/class/sec/sec_epen/epen_gestures"; + +const std::map TouchscreenGesture::kGestureInfoMap = { + {0, {0x2f1, "Swipe up stylus"}}, + {1, {0x2f2, "Swipe down stylus"}}, + {2, {0x2f3, "Swipe left stylus"}}, + {3, {0x2f4, "Swipe right stylus"}}, + {4, {0x2f5, "Long press stylus"}}, +}; + + +bool TouchscreenGesture::isSupported() { + std::ifstream file(kGeasturePath); + return file.good(); +} // Methods from ::vendor::lineage::touch::V1_0::ITouchscreenGesture follow. -Return TouchscreenGesture::getSupportedGestures(getSupportedGestures_cb _hidl_cb) { - // TODO implement +Return TouchscreenGesture::getSupportedGestures(getSupportedGestures_cb resultCb) { + std::vector gestures; + + for (const auto& entry : kGestureInfoMap) { + gestures.push_back({entry.first, entry.second.name, entry.second.keycode}); + } + resultCb(gestures); + return Void(); } -Return TouchscreenGesture::setGestureEnabled(const ::vendor::lineage::touch::V1_0::Gesture& gesture, bool enabled) { - // TODO implement - return Void(); +Return TouchscreenGesture::setGestureEnabled( + const ::vendor::lineage::touch::V1_0::Gesture& gesture, bool enabled) { + std::fstream file(kGeasturePath); + int gestureMode; + int mask = 1 << gesture.id; + + file >> gestureMode; + + if (enabled) + gestureMode |= mask; + else + gestureMode &= ~mask; + + file << gestureMode; + + return !file.fail(); } // Methods from ::android::hidl::base::V1_0::IBase follow. -//ITouchscreenGesture* HIDL_FETCH_ITouchscreenGesture(const char* /* name */) { - //return new TouchscreenGesture(); -//} -// -} // namespace implementation +} // namespace samsung } // namespace V1_0 } // namespace touch } // namespace lineage diff --git a/lineagehw/hidl/touch/TouchscreenGesture.h b/lineagehw/hidl/touch/TouchscreenGesture.h index bb2d3360..c1d7c708 100644 --- a/lineagehw/hidl/touch/TouchscreenGesture.h +++ b/lineagehw/hidl/touch/TouchscreenGesture.h @@ -25,7 +25,7 @@ namespace vendor { namespace lineage { namespace touch { namespace V1_0 { -namespace implementation { +namespace samsung { using ::android::hardware::hidl_array; using ::android::hardware::hidl_memory; @@ -35,19 +35,28 @@ using ::android::hardware::Return; using ::android::hardware::Void; using ::android::sp; -struct TouchscreenGesture : public ITouchscreenGesture { +class TouchscreenGesture : public ITouchscreenGesture { + public: + bool isSupported(); + // Methods from ::vendor::lineage::touch::V1_0::ITouchscreenGesture follow. - Return getSupportedGestures(getSupportedGestures_cb _hidl_cb) override; - Return setGestureEnabled(const ::vendor::lineage::touch::V1_0::Gesture& gesture, bool enabled) override; + Return getSupportedGestures(getSupportedGestures_cb resultCb) override; + Return setGestureEnabled(const ::vendor::lineage::touch::V1_0::Gesture& gesture, + bool enabled) override; - // Methods from ::android::hidl::base::V1_0::IBase follow. + private: + typedef struct { + int32_t keycode; + const char* name; + } GestureInfo; + static const std::map kGestureInfoMap; // id -> info }; // FIXME: most likely delete, this is only for passthrough implementations // extern "C" ITouchscreenGesture* HIDL_FETCH_ITouchscreenGesture(const char* name); -} // namespace implementation +} // namespace samsung } // namespace V1_0 } // namespace touch } // namespace lineage diff --git a/lineagehw/hidl/touch/service.cpp b/lineagehw/hidl/touch/service.cpp new file mode 100644 index 00000000..1bdc66fc --- /dev/null +++ b/lineagehw/hidl/touch/service.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2019 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.samsung" + +#include +#include +#include + +#include "GloveMode.h" +#include "KeyDisabler.h" +#include "StylusMode.h" +#include "TouchscreenGesture.h" + +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; +using android::sp; +using android::status_t; +using android::OK; + +using ::vendor::lineage::touch::V1_0::samsung::GloveMode; +using ::vendor::lineage::touch::V1_0::samsung::KeyDisabler; +using ::vendor::lineage::touch::V1_0::samsung::StylusMode; +using ::vendor::lineage::touch::V1_0::samsung::TouchscreenGesture; + +int main() { + sp gloveMode; + sp keyDisabler; + sp stylusMode; + sp touchscreenGesture; + status_t status; + + LOG(INFO) << "Touch HAL service is starting."; + + gloveMode = new GloveMode(); + if (gloveMode == nullptr) { + LOG(ERROR) << "Can not create an instance of Touch HAL GloveMode Iface, exiting."; + goto shutdown; + } + + keyDisabler = new KeyDisabler(); + if (keyDisabler == nullptr) { + LOG(ERROR) << "Can not create an instance of Touch HAL KeyDisabler Iface, exiting."; + goto shutdown; + } + + stylusMode = new StylusMode(); + if (stylusMode == nullptr) { + LOG(ERROR) << "Can not create an instance of Touch HAL StylusMode Iface, exiting."; + goto shutdown; + } + + touchscreenGesture = new TouchscreenGesture(); + if (touchscreenGesture == nullptr) { + LOG(ERROR) << "Can not create an instance of Touch HAL TouchscreenGesture Iface, exiting."; + goto shutdown; + } + + configureRpcThreadpool(1, true /*callerWillJoin*/); + + if (gloveMode->isSupported()) { + status = gloveMode->registerAsService(); + if (status != OK) { + LOG(ERROR) + << "Could not register service for Touch HAL GloveMode Iface (" + << status << ")"; + goto shutdown; + } + } + + if (keyDisabler->isSupported()) { + status = keyDisabler->registerAsService(); + if (status != OK) { + LOG(ERROR) + << "Could not register service for Touch HAL KeyDisabler Iface (" + << status << ")"; + goto shutdown; + } + } + + if (stylusMode->isSupported()) { + status = stylusMode->registerAsService(); + if (status != OK) { + LOG(ERROR) + << "Could not register service for Touch HAL StylusMode Iface (" + << status << ")"; + goto shutdown; + } + } + + if (touchscreenGesture->isSupported()) { + status = touchscreenGesture->registerAsService(); + if (status != OK) { + LOG(ERROR) + << "Could not register service for Touch HAL TouchscreenGesture Iface (" + << status << ")"; + goto shutdown; + } + } + + LOG(INFO) << "Touch HAL service is ready."; + joinRpcThreadpool(); + // Should not pass this line + +shutdown: + // In normal operation, we don't expect the thread pool to shutdown + LOG(ERROR) << "Touch HAL service is shutting down."; + return 1; +} diff --git a/lineagehw/hidl/touch/vendor.lineage.touch@1.0-service.samsung.rc b/lineagehw/hidl/touch/vendor.lineage.touch@1.0-service.samsung.rc new file mode 100644 index 00000000..2f0d14f2 --- /dev/null +++ b/lineagehw/hidl/touch/vendor.lineage.touch@1.0-service.samsung.rc @@ -0,0 +1,4 @@ +service vendor.touch-hal-1-0-samsung /vendor/bin/hw/vendor.lineage.touch@1.0-service.samsung + class hal + user system + group system