--- /dev/null
+#include "test_hal_libinput_info.h"
+#include <limits.h>
+#include <libevdev/libevdev.h>
+#include <libevdev/libevdev-uinput.h>
+
+struct record_device devices[10];
+int devices_cnt = 0;
+
+#define NLONGS(n) (((n) + LONG_BIT - 1) / LONG_BIT)
+
+static bool evdev_bit_is_set(const unsigned long *array, int bit)
+{
+ return array[bit / LONG_BIT] & (1LL << (bit % LONG_BIT));
+}
+
+int handle_device_notify(struct libinput_event *ev)
+{
+ struct libinput_device *dev = libinput_event_get_device(ev);
+ struct udev_device *udev_device = libinput_device_get_udev_device(dev);
+ enum libinput_event_type type;
+ const char *devnode;
+
+ switch(libinput_event_get_type(ev)) {
+ case LIBINPUT_EVENT_DEVICE_ADDED:
+ type = LIBINPUT_EVENT_DEVICE_ADDED;
+ break;
+ case LIBINPUT_EVENT_DEVICE_REMOVED:
+ type = LIBINPUT_EVENT_DEVICE_REMOVED;
+ break;
+ default:
+ abort();
+ }
+
+ if(strstr(udev_device_get_property_value(udev_device, "DEVPATH"), "virtual")){
+ LOG("It's contain virtual. No Check.\n");
+ return 0;
+ }
+
+ if (libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_KEYBOARD)) {
+ devnode = udev_device_get_devnode(libinput_device_get_udev_device(dev));
+ if(type == LIBINPUT_EVENT_DEVICE_ADDED) { // TODO. save using linked list
+ const char *test = NULL;
+ test = udev_device_get_property_value(udev_device, "ID_INPUT_KEYBOARD");
+ LOG("devnode = %s\n", devnode);
+ if(test && (test[0] == '1')){
+ LOG("ID_INPUT_KEYBOARD test = %s\n", test);
+ devices[devices_cnt].cap = LIBINPUT_DEVICE_CAP_KEYBOARD;
+ devices[devices_cnt++].path = devnode;
+ int fd = open(devnode, O_RDWR);
+ unsigned long evbits[NLONGS(EV_CNT)] = { 0 };
+ ioctl(fd, EVIOCGBIT(0, sizeof(evbits)), evbits);
+ if (!evdev_bit_is_set(evbits, EV_KEY))
+ LOG("no evdev bit is set\n");
+ unsigned long keybits[NLONGS(KEY_CNT)] = { 0 };
+ ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits);
+ for(int i = KEY_RESERVED; i< KEY_MIN_INTERESTING; ++i)
+ if(evdev_bit_is_set(keybits, i)){
+ break;
+ }
+ }
+ }
+ }
+ if (libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_POINTER)) {
+ devnode = udev_device_get_devnode(libinput_device_get_udev_device(dev));
+ if(type == LIBINPUT_EVENT_DEVICE_ADDED) { // TODO. save using linked list
+ const char *test = NULL;
+ test = udev_device_get_property_value(udev_device, "ID_INPUT_MOUSE");
+ LOG("devnode = %s\n", devnode);
+ if(test && (test[0] == '1')){
+ LOG("ID_INPUT_MOUSE test = %s\n", test);
+ devices[devices_cnt].cap = LIBINPUT_DEVICE_CAP_POINTER;
+ devices[devices_cnt++].path = devnode;
+ }
+ }
+ }
+ if (libinput_device_has_capability(dev, LIBINPUT_DEVICE_CAP_TOUCH)) {
+ devnode = udev_device_get_devnode(libinput_device_get_udev_device(dev));
+ if(type == LIBINPUT_EVENT_DEVICE_ADDED) { // TODO. save using linked list
+ const char *test = NULL;
+ test = udev_device_get_property_value(udev_device, "ID_INPUT_TOUCHSCREEN");
+ LOG("devnode = %s\n", devnode);
+ if(test && (test[0] == '1')){
+ LOG("ID_INPUT_TOUCHSCREEN test = %s\n", test);
+ devices[devices_cnt].cap = LIBINPUT_DEVICE_CAP_TOUCH;
+ devices[devices_cnt++].path = devnode;
+ }
+ }
+ }
+ LOG("total device cnt = %d\n", devices_cnt);
+ return 0;
+}
+
+int handle_libinput_add_event(struct libinput *li)
+{
+ devices_cnt = 0;
+ struct libinput_event *ev;
+ libinput_dispatch(li);
+ while((ev = libinput_get_event(li))) {
+ switch (libinput_event_get_type(ev))
+ {
+ case LIBINPUT_EVENT_NONE:
+ abort();
+ case LIBINPUT_EVENT_DEVICE_ADDED:
+ case LIBINPUT_EVENT_DEVICE_REMOVED:
+ handle_device_notify(ev);
+ break;
+ default:
+ break;
+ }
+ libinput_event_destroy(ev);
+ libinput_dispatch(li);
+ }
+ return 0;
+}
--- /dev/null
+
+#ifndef __LIBINPUT_TESTS_INFO_H__
+#define __LIBINPUT_TESTS_INFO_H__
+
+#include <libinput.h>
+#include <stdio.h>
+#include <gtest/gtest.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <linux/input.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <time.h>
+#include <poll.h>
+#include <dlog.h>
+#include <string.h>
+
+#define COLOR_RED "\x1b[31m" /* for error */
+#define COLOR_RESET "\x1b[0m"
+
+#define DEBUG_STDOUT
+#ifdef DEBUG_STDOUT
+#undef LOG_TAG
+#undef LOG
+#undef LOGD
+#undef LOGE
+#define LOG_TAG "TEST_HAL_LIBINPUT"
+
+#define LOG(fmt, args...) \
+ LOGD(fmt, ##args)
+#define LOGD(fmt, args...) \
+ dlog_print(DLOG_DEBUG, LOG_TAG, COLOR_RESET "%s : %s(%d) " fmt, __FILE__, __func__, __LINE__, ##args)
+#define LOGE(fmt, args...) \
+ dlog_print(DLOG_ERROR, LOG_TAG, COLOR_RED "%s : %s(%d) " fmt, __FILE__, __func__, __LINE__, ##args)
+#endif
+
+int handle_libinput_add_event(struct libinput *li);
+
+struct record_device {
+ enum libinput_device_capability cap;
+ const char *path;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __LIBINPUT_TESTS_INFO_H__
\ No newline at end of file