diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk index 3cd78ec..358bf97 100644 --- a/BoardConfigCommon.mk +++ b/BoardConfigCommon.mk @@ -147,7 +147,7 @@ TARGET_COPY_OUT_PRODUCT := product TARGET_BOARD_PLATFORM := lahaina # Power -TARGET_TAP_TO_WAKE_NODE := "/sys/devices/virtual/touch/tp_dev/double_tap" +TARGET_POWERHAL_MODE_EXT := $(COMMON_PATH)/power/power-mode.cpp # Properties TARGET_ODM_PROP += $(COMMON_PATH)/odm.prop diff --git a/power/power-mode.cpp b/power/power-mode.cpp new file mode 100644 index 0000000..ae1fc70 --- /dev/null +++ b/power/power-mode.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +// defines from drivers/input/touchscreen/xiaomi/xiaomi_touch.h +#define SET_CUR_VALUE 0 +#define Touch_Doubletap_Mode 14 + +#define TOUCH_DEV_PATH "/dev/xiaomi-touch" +#define TOUCH_ID 0 +#define TOUCH_MAGIC 0x5400 +#define TOUCH_IOC_SETMODE TOUCH_MAGIC + SET_CUR_VALUE + +namespace aidl { +namespace android { +namespace hardware { +namespace power { +namespace impl { + +using ::aidl::android::hardware::power::Mode; + +bool isDeviceSpecificModeSupported(Mode type, bool* _aidl_return) { + switch (type) { + case Mode::DOUBLE_TAP_TO_WAKE: + *_aidl_return = true; + return true; + default: + return false; + } +} + +bool setDeviceSpecificMode(Mode type, bool enabled) { + switch (type) { + case Mode::DOUBLE_TAP_TO_WAKE: { + int fd = open(TOUCH_DEV_PATH, O_RDWR); + int arg[3] = {TOUCH_ID, Touch_Doubletap_Mode, enabled ? 1 : 0}; + ioctl(fd, TOUCH_IOC_SETMODE, &arg); + close(fd); + return true; + } + default: + return false; + } +} + +} // namespace impl +} // namespace power +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/rootdir/etc/init.target.rc b/rootdir/etc/init.target.rc index 1d09761..ee7438f 100644 --- a/rootdir/etc/init.target.rc +++ b/rootdir/etc/init.target.rc @@ -118,6 +118,10 @@ on boot chown system system /sys/class/thermal/thermal_message/balance_mode chown system system /sys/devices/virtual/touch/tp_dev/double_tap + # Set xiaomi touch permissions + chown system system /dev/xiaomi-touch + chmod 0660 /dev/xiaomi-touch + write /dev/cpuset/audio-app/cpus 1-2 # Add a cpuset for the camera daemon diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index 48fef25..3e2875f 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -20,6 +20,9 @@ # Power /sys/devices/virtual/touch/tp_dev/double_tap u:object_r:vendor_sysfs_double_tap:s0 +# Power +/dev/xiaomi-touch u:object_r:vendor_touchfeature_device:s0 + # Powershare /vendor/bin/hw/vendor\.lineage\.powershare@1\.0-service\.xiaomi_sm8350 u:object_r:hal_lineage_powershare_default_exec:s0 diff --git a/sepolicy/vendor/hal_power_default.te b/sepolicy/vendor/hal_power_default.te index e583b49..ccbd8f3 100644 --- a/sepolicy/vendor/hal_power_default.te +++ b/sepolicy/vendor/hal_power_default.te @@ -1,3 +1,5 @@ type vendor_sysfs_double_tap, sysfs_type, fs_type; +type vendor_touchfeature_device, dev_type; allow hal_power_default vendor_sysfs_double_tap:file rw_file_perms; +allow hal_power_default vendor_touchfeature_device:chr_file rw_file_perms;