From f9558e890f33dc415a01bf7677042d54c264170c Mon Sep 17 00:00:00 2001 From: Valera1978 Date: Tue, 26 May 2020 11:14:51 +0300 Subject: [PATCH] back to old powerhal --- power/power_ext.c | 110 +++++++--------------------------------------- 1 file changed, 15 insertions(+), 95 deletions(-) diff --git a/power/power_ext.c b/power/power_ext.c index 2aac5c8..e7289c6 100755 --- a/power/power_ext.c +++ b/power/power_ext.c @@ -17,74 +17,29 @@ #include #include #include -#include #define LOG_TAG "PowerHAL_K_Ext" #include -#define MAX_INPUTS 20 -#define INPUT_PREFIX "/sys/class/input/input" -#define MAX_PATH_SIZE 256 +/* touchkeys */ +#define TK_POWER "/sys/class/input/input1/enabled" -static const char *names[] = { - "sec_touchscreen", // 3 - "light_sensor" // 5 - "proximity_sensor" // 6 - "gpio-keys" // 7 -}; -#define N_NAMES (sizeof(names) / sizeof(names[0])) -static char paths[N_NAMES][MAX_PATH_SIZE]; -static int have_found_paths; - -static size_t sysfs_read(char *path, char *buffer, size_t n) -{ - char buf[MAX_PATH_SIZE]; - int fd; - size_t len; - - if ((fd = open(path, O_RDONLY)) < 0) - { - if (errno != ENOENT) - { - strerror_r(errno, buf, sizeof(buf)); - ALOGE("Error opening %s: %s\n", path, buf); - } - return 0; - } - - len = read(fd, buffer, n); - if (len < 0) - { - strerror_r(errno, buf, sizeof(buf)); - ALOGE("Error reading from %s: %s\n", path, buf); - return 0; - } - - while (len > 0 && isspace(buffer[len-1])) - len--; - if (len < n) - buffer[len] = '\0'; - - close(fd); - - return len; -} - -static void sysfs_write(char *path, char *s) -{ - char buf[MAX_PATH_SIZE]; +/* touchscreen */ +#define TS_POWER "/sys/class/input/input2/enabled" +static void sysfs_write(char *path, char *s) { + char buf[80]; + int len; int fd = open(path, O_WRONLY); - if (fd < 0) - { + + if (fd < 0) { strerror_r(errno, buf, sizeof(buf)); ALOGE("Error opening %s: %s\n", path, buf); return; } - size_t len = write(fd, s, strlen(s)); - if (len < 0) - { + len = write(fd, s, strlen(s)); + if (len < 0) { strerror_r(errno, buf, sizeof(buf)); ALOGE("Error writing to %s: %s\n", path, buf); } @@ -92,47 +47,12 @@ static void sysfs_write(char *path, char *s) close(fd); } -static void find_paths(void) -{ - size_t i, j; - char path[MAX_PATH_SIZE]; - char name[MAX_PATH_SIZE]; - - for (i = 0; i < N_NAMES; i++) - paths[i][0] = 0; - - for (i = 0; i < MAX_INPUTS; i++) - { - sprintf(path, "%s%d/name", INPUT_PREFIX, i); - if (sysfs_read(path, name, sizeof(name)) > 0) - { - for (j = 0; j < N_NAMES; j++) - { - if (strcmp(name, names[j]) == 0) - { - sprintf(paths[j], "%s%d/enabled", INPUT_PREFIX, i); - ALOGD("%s => %s\n", names[j], paths[j]); - } - } - } - } -} - -void power_set_interactive_ext(int on) -{ +void power_set_interactive_ext(int on) { ALOGD("%s: %s input devices", __func__, on ? "enabling" : "disabling"); - - if (!have_found_paths) - { - find_paths(); - have_found_paths = 1; - } - - for (size_t i = 0; i < N_NAMES; i++) - sysfs_write(paths[i], on ? "1" : "0"); + sysfs_write(TK_POWER, on ? "1" : "0"); + sysfs_write(TS_POWER, on ? "1" : "0"); } -void cm_power_set_interactive_ext(int on) -{ +void cm_power_set_interactive_ext(int on) { power_set_interactive_ext(on); }