sm6150-common: power: Use xiaomi-touch to handle dt2w

Change-Id: I73f95e32daf9e2c702662ac2c2c8182e6b8eb214
This commit is contained in:
Arian
2021-06-25 19:18:08 +02:00
parent cf3b3272ae
commit 8cf1d5dda3
2 changed files with 11 additions and 49 deletions

View File

@@ -17,42 +17,16 @@
#include <aidl/android/hardware/power/BnPower.h> #include <aidl/android/hardware/power/BnPower.h>
#include <android-base/file.h> #include <android-base/file.h>
#include <android-base/logging.h> #include <android-base/logging.h>
#include <linux/input.h> #include <sys/ioctl.h>
namespace { // defines from drivers/input/touchscreen/xiaomi/xiaomi_touch.h
int open_ts_input() { #define SET_CUR_VALUE 0
int fd = -1; #define Touch_Doubletap_Mode 14
DIR *dir = opendir("/dev/input");
if (dir != NULL) { #define TOUCH_DEV_PATH "/dev/xiaomi-touch"
struct dirent *ent;
while ((ent = readdir(dir)) != NULL) { #define TOUCH_MAGIC 0x5400
if (ent->d_type == DT_CHR) { #define TOUCH_IOC_SETMODE TOUCH_MAGIC + SET_CUR_VALUE
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
namespace aidl { namespace aidl {
namespace google { namespace google {
@@ -61,9 +35,6 @@ namespace power {
namespace impl { namespace impl {
namespace pixel { namespace pixel {
static constexpr int kInputEventWakeupModeOff = 4;
static constexpr int kInputEventWakeupModeOn = 5;
using ::aidl::android::hardware::power::Mode; using ::aidl::android::hardware::power::Mode;
bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return) { bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return) {
@@ -79,17 +50,9 @@ bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return) {
bool setDeviceSpecificMode(Mode type, bool enabled) { bool setDeviceSpecificMode(Mode type, bool enabled) {
switch (type) { switch (type) {
case Mode::DOUBLE_TAP_TO_WAKE: { case Mode::DOUBLE_TAP_TO_WAKE: {
int fd = open_ts_input(); int fd = open(TOUCH_DEV_PATH, O_RDWR);
if (fd == -1) { int arg[2] = {Touch_Doubletap_Mode, enabled ? 1 : 0};
LOG(WARNING) ioctl(fd, TOUCH_IOC_SETMODE, &arg);
<< "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));
close(fd); close(fd);
return true; return true;
} }

View File

@@ -1,8 +1,7 @@
type proc_sched_energy_aware, proc_type, fs_type; type proc_sched_energy_aware, proc_type, fs_type;
type vendor_power_prop, property_type; type vendor_power_prop, property_type;
allow hal_power_default input_device:dir r_dir_perms; allow hal_power_default touchfeature_device:chr_file rw_file_perms;
allow hal_power_default input_device:chr_file rw_file_perms;
# To do powerhint on nodes defined in powerhint.json # To do powerhint on nodes defined in powerhint.json
allow hal_power_default cgroup:dir search; allow hal_power_default cgroup:dir search;