diff options
author | Paul Keith <javelinanddart@gmail.com> | 2019-01-09 00:11:40 +0100 |
---|---|---|
committer | Kevin Haggerty <haggertk@lineageos.org> | 2019-04-11 05:41:47 +0200 |
commit | 2b27b275b3e2713da5b8e21465a35fd5962194ed (patch) | |
tree | f3636b09f4295e9ad12f93151c2f8b8e49fbf007 | |
parent | 5b3bd86278b79217c5ee7d591e11e3ffaabb3911 (diff) | |
download | android_hardware_samsung-2b27b275b3e2713da5b8e21465a35fd5962194ed.tar.gz android_hardware_samsung-2b27b275b3e2713da5b8e21465a35fd5962194ed.tar.bz2 android_hardware_samsung-2b27b275b3e2713da5b8e21465a35fd5962194ed.zip |
hidl: touch: Add binderized service implementation
* Change default ::implementation namespace to ::samsung
* Fill in required methods for used impls
* Cleanup passthrough code for used impls
* Add and setup binderized service
Change-Id: Iadc3b6e385233d103c3349ce31a08d6d040886c7
-rw-r--r-- | lineagehw/hidl/touch/Android.bp | 18 | ||||
-rw-r--r-- | lineagehw/hidl/touch/GloveMode.cpp | 43 | ||||
-rw-r--r-- | lineagehw/hidl/touch/GloveMode.h | 17 | ||||
-rw-r--r-- | lineagehw/hidl/touch/KeyDisabler.cpp | 34 | ||||
-rw-r--r-- | lineagehw/hidl/touch/KeyDisabler.h | 17 | ||||
-rw-r--r-- | lineagehw/hidl/touch/StylusMode.cpp | 43 | ||||
-rw-r--r-- | lineagehw/hidl/touch/StylusMode.h | 17 | ||||
-rw-r--r-- | lineagehw/hidl/touch/TouchscreenGesture.cpp | 55 | ||||
-rw-r--r-- | lineagehw/hidl/touch/TouchscreenGesture.h | 21 | ||||
-rw-r--r-- | lineagehw/hidl/touch/service.cpp | 122 | ||||
-rw-r--r-- | lineagehw/hidl/touch/vendor.lineage.touch@1.0-service.samsung.rc | 4 |
11 files changed, 309 insertions, 82 deletions
diff --git a/lineagehw/hidl/touch/Android.bp b/lineagehw/hidl/touch/Android.bp index 310fb52..0197b6c 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 '-<hardware identifier>' 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 37c58ed..dcac846 100644 --- a/lineagehw/hidl/touch/GloveMode.cpp +++ b/lineagehw/hidl/touch/GloveMode.cpp @@ -14,28 +14,49 @@ * limitations under the License. */ +#include <fstream> + #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<void> 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<bool> 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<bool> 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 925ceb4..7208a8d 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<void> setEnabled(bool enabled) override; + Return<bool> isEnabled() override; + Return<bool> 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 469e147..54691a0 100644 --- a/lineagehw/hidl/touch/KeyDisabler.cpp +++ b/lineagehw/hidl/touch/KeyDisabler.cpp @@ -14,28 +14,40 @@ * limitations under the License. */ +#include <fstream> + #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<void> 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<bool> 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<bool> 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 ffe4f0d..3b56b46 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<void> setEnabled(bool enabled) override; + Return<bool> isEnabled() override; + Return<bool> 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 5f5a33a..aa86e7a 100644 --- a/lineagehw/hidl/touch/StylusMode.cpp +++ b/lineagehw/hidl/touch/StylusMode.cpp @@ -14,28 +14,49 @@ * limitations under the License. */ +#include <fstream> + #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<void> 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<bool> 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<bool> 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 4e7401d..2eae6c8 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<void> setEnabled(bool enabled) override; + Return<bool> isEnabled() override; + Return<bool> 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 cadea2b..1f47115 100644 --- a/lineagehw/hidl/touch/TouchscreenGesture.cpp +++ b/lineagehw/hidl/touch/TouchscreenGesture.cpp @@ -14,33 +14,66 @@ * limitations under the License. */ +#include <fstream> + #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<int32_t, TouchscreenGesture::GestureInfo> 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<void> TouchscreenGesture::getSupportedGestures(getSupportedGestures_cb _hidl_cb) { - // TODO implement +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<void> TouchscreenGesture::setGestureEnabled(const ::vendor::lineage::touch::V1_0::Gesture& gesture, bool enabled) { - // TODO implement - return Void(); +Return<bool> 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 bb2d336..c1d7c70 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<void> getSupportedGestures(getSupportedGestures_cb _hidl_cb) override; - Return<void> setGestureEnabled(const ::vendor::lineage::touch::V1_0::Gesture& gesture, bool enabled) override; + Return<void> getSupportedGestures(getSupportedGestures_cb resultCb) override; + Return<bool> 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<int32_t, GestureInfo> 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 0000000..1bdc66f --- /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 <android-base/logging.h> +#include <binder/ProcessState.h> +#include <hidl/HidlTransportSupport.h> + +#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> gloveMode; + sp<KeyDisabler> keyDisabler; + sp<StylusMode> stylusMode; + sp<TouchscreenGesture> 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 0000000..2f0d14f --- /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 |