back to old powerhal

This commit is contained in:
Valera1978 2020-05-26 11:14:51 +03:00
parent 3896a8816e
commit f9558e890f

View File

@ -17,74 +17,29 @@
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <ctype.h>
#define LOG_TAG "PowerHAL_K_Ext"
#include <utils/Log.h>
#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);
}