From 8cf1d5dda3afebab794b863cc3e7afcbdf085bbd Mon Sep 17 00:00:00 2001 From: Arian Date: Fri, 25 Jun 2021 19:18:08 +0200 Subject: [PATCH] sm6150-common: power: Use xiaomi-touch to handle dt2w Change-Id: I73f95e32daf9e2c702662ac2c2c8182e6b8eb214 --- power/power-mode.cpp | 57 +++++----------------------- sepolicy/vendor/hal_power_default.te | 3 +- 2 files changed, 11 insertions(+), 49 deletions(-) diff --git a/power/power-mode.cpp b/power/power-mode.cpp index ed93ef9..1886dc3 100644 --- a/power/power-mode.cpp +++ b/power/power-mode.cpp @@ -17,42 +17,16 @@ #include #include #include -#include +#include -namespace { -int open_ts_input() { - int fd = -1; - DIR *dir = opendir("/dev/input"); +// defines from drivers/input/touchscreen/xiaomi/xiaomi_touch.h +#define SET_CUR_VALUE 0 +#define Touch_Doubletap_Mode 14 - if (dir != NULL) { - struct dirent *ent; +#define TOUCH_DEV_PATH "/dev/xiaomi-touch" - while ((ent = readdir(dir)) != NULL) { - if (ent->d_type == DT_CHR) { - char absolute_path[PATH_MAX] = {0}; - char name[80] = {0}; - - strcpy(absolute_path, "/dev/input/"); - strcat(absolute_path, ent->d_name); - - fd = open(absolute_path, O_RDWR); - if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) > 0) { - if (strcmp(name, "fts") == 0 || strcmp(name, "goodix_ts") == 0 || - strcmp(name, "NVTCapacitiveTouchScreen") == 0) - break; - } - - close(fd); - fd = -1; - } - } - - closedir(dir); - } - - return fd; -} -} // anonymous namespace +#define TOUCH_MAGIC 0x5400 +#define TOUCH_IOC_SETMODE TOUCH_MAGIC + SET_CUR_VALUE namespace aidl { namespace google { @@ -61,9 +35,6 @@ namespace power { namespace impl { namespace pixel { -static constexpr int kInputEventWakeupModeOff = 4; -static constexpr int kInputEventWakeupModeOn = 5; - using ::aidl::android::hardware::power::Mode; bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return) { @@ -79,17 +50,9 @@ bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return) { bool setDeviceSpecificMode(Mode type, bool enabled) { switch (type) { case Mode::DOUBLE_TAP_TO_WAKE: { - int fd = open_ts_input(); - if (fd == -1) { - LOG(WARNING) - << "DT2W won't work because no supported touchscreen input devices were found"; - return false; - } - struct input_event ev; - ev.type = EV_SYN; - ev.code = SYN_CONFIG; - ev.value = enabled ? kInputEventWakeupModeOn : kInputEventWakeupModeOff; - write(fd, &ev, sizeof(ev)); + int fd = open(TOUCH_DEV_PATH, O_RDWR); + int arg[2] = {Touch_Doubletap_Mode, enabled ? 1 : 0}; + ioctl(fd, TOUCH_IOC_SETMODE, &arg); close(fd); return true; } diff --git a/sepolicy/vendor/hal_power_default.te b/sepolicy/vendor/hal_power_default.te index 8f7f52b..353cec2 100644 --- a/sepolicy/vendor/hal_power_default.te +++ b/sepolicy/vendor/hal_power_default.te @@ -1,8 +1,7 @@ type proc_sched_energy_aware, proc_type, fs_type; type vendor_power_prop, property_type; -allow hal_power_default input_device:dir r_dir_perms; -allow hal_power_default input_device:chr_file rw_file_perms; +allow hal_power_default touchfeature_device:chr_file rw_file_perms; # To do powerhint on nodes defined in powerhint.json allow hal_power_default cgroup:dir search;