diff --git a/sensors/Sensor.cpp b/sensors/Sensor.cpp index c2b34c5..ed87ce5 100644 --- a/sensors/Sensor.cpp +++ b/sensors/Sensor.cpp @@ -20,8 +20,26 @@ #include #include +#include + #include +#define TSP_ENABLED_PATH "/sys/class/sec/tsp/input/enabled" + +template +static void set(const std::string& path, const T& value) { + std::ofstream file(path); + file << value; +} + +template +static T get(const std::string& path, const T& def) { + std::ifstream file(path); + T result; + file >> result; + return file.fail() ? def : result; +} + static bool readBool(int fd, bool seek) { char c; int rc; @@ -262,6 +280,10 @@ SysfsPollingOneShotSensor::~SysfsPollingOneShotSensor() { void SysfsPollingOneShotSensor::activate(bool enable, bool notify, bool lock) { std::unique_lock runLock(mRunMutex, std::defer_lock); + if (!enable && strcmp(get(TSP_ENABLED_PATH, "0").c_str(), "0") == 0) { + set(TSP_ENABLED_PATH, "1"); + } + if (lock) { runLock.lock(); } @@ -278,6 +300,10 @@ void SysfsPollingOneShotSensor::activate(bool enable, bool notify, bool lock) { if (lock) { runLock.unlock(); } + + if (enable && strcmp(get(TSP_ENABLED_PATH, "0").c_str(), "1") == 0) { + set(TSP_ENABLED_PATH, "0"); + } } void SysfsPollingOneShotSensor::activate(bool enable) { @@ -310,6 +336,9 @@ void SysfsPollingOneShotSensor::run() { } if (mPolls[1].revents == mPolls[1].events && readBool(mPollFd, true /* seek */)) { + if (strcmp(get(TSP_ENABLED_PATH, "0").c_str(), "0") == 0) { + set(TSP_ENABLED_PATH, "1"); + } activate(false, false, false); mCallback->postEvents(readEvents(), isWakeUpSensor()); } else if (mPolls[0].revents == mPolls[0].events) { diff --git a/sepolicy/vendor/hal_sensors_default.te b/sepolicy/vendor/hal_sensors_default.te index e79311e..b3e3a63 100644 --- a/sepolicy/vendor/hal_sensors_default.te +++ b/sepolicy/vendor/hal_sensors_default.te @@ -37,7 +37,7 @@ allow hal_sensors_default sysfs_sec_touchscreen:dir r_dir_perms; allow hal_sensors_default sysfs_sec_touchscreen:file r_file_perms; allow hal_sensors_default sysfs_sec_touchscreen:lnk_file r_file_perms; allow hal_sensors_default sysfs_power_writable:dir search; -allow hal_sensors_default sysfs_power_writable:file { read open }; +allow hal_sensors_default sysfs_power_writable:file rw_file_perms; # /sys/class/sec/tsp/cmd allow hal_sensors_default sysfs_touchscreen_writable:file rw_file_perms;