// 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.
"KeyDisabler.cpp",
"StylusMode.cpp",
"TouchscreenGesture.cpp",
+ "service.cpp"
],
shared_libs: [
+ "libbase",
+ "libbinder",
"libhidlbase",
"libhidltransport",
"libutils",
* 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
namespace lineage {
namespace touch {
namespace V1_0 {
-namespace implementation {
+namespace samsung {
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
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
* 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
namespace lineage {
namespace touch {
namespace V1_0 {
-namespace implementation {
+namespace samsung {
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
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
* 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
namespace lineage {
namespace touch {
namespace V1_0 {
-namespace implementation {
+namespace samsung {
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
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
* 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
namespace lineage {
namespace touch {
namespace V1_0 {
-namespace implementation {
+namespace samsung {
using ::android::hardware::hidl_array;
using ::android::hardware::hidl_memory;
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
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+service vendor.touch-hal-1-0-samsung /vendor/bin/hw/vendor.lineage.touch@1.0-service.samsung
+ class hal
+ user system
+ group system