From 58dd99657ab5de7c69bc43464302f0e51f52d611 Mon Sep 17 00:00:00 2001 From: Michael Cheah Date: Thu, 26 Mar 2020 09:51:58 +0800 Subject: [PATCH] [xiaomi] Use persist.sys.phh.xiaomi.dt2w prop to control DT2W --- base.mk | 1 + phh-prop-handler.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++ rw-system.sh | 7 ------ vndk.rc | 3 +++ 4 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 phh-prop-handler.sh diff --git a/base.mk b/base.mk index 2a4bbf5..97126ac 100644 --- a/base.mk +++ b/base.mk @@ -57,6 +57,7 @@ PRODUCT_PACKAGES += \ PRODUCT_COPY_FILES += \ device/phh/treble/rw-system.sh:system/bin/rw-system.sh \ + device/phh/treble/phh-prop-handler.sh:system/bin/phh-prop-handler.sh \ device/phh/treble/fixSPL/getSPL.arm:system/bin/getSPL PRODUCT_COPY_FILES += \ diff --git a/phh-prop-handler.sh b/phh-prop-handler.sh new file mode 100644 index 0000000..1382212 --- /dev/null +++ b/phh-prop-handler.sh @@ -0,0 +1,60 @@ +#!/system/bin/sh +set -o pipefail + +display_usage() { + echo -e "\nUsage:\n ./phh-prop-handler.sh [prop]\n" +} + +if [ "$#" -ne 1 ]; then + display_usage + exit 1 +fi + +prop_value=$(getprop "$1") + +xiaomi_toggle_dt2w_proc_node() { + DT2W_PROC_NODES=("/proc/touchpanel/wakeup_gesture" + "/proc/tp_wakeup_gesture" + "/proc/tp_gesture") + for node in "${DT2W_PROC_NODES[@]}"; do + [ ! -f "${node}" ] && continue + echo "Trying to set dt2w mode with /proc node: ${node}" + echo "$1" >"${node}" + [[ "$(cat "${node}")" -eq "$1" ]] # Check result + return + done + return 1 +} + +xiaomi_toggle_dt2w_event_node() { + for ev in $( + cd /sys/class/input || return + echo event* + ); do + [ ! -f "/sys/class/input/${ev}/device/device/gesture_mask" ] && + [ ! -f "/sys/class/input/${ev}/device/wake_gesture" ] && continue + echo "Trying to set dt2w mode with event node: /dev/input/${ev}" + if [ "$1" -eq 1 ]; then + # Enable + sendevent /dev/input/"${ev}" 0 1 5 + return + else + # Disable + sendevent /dev/input/"${ev}" 0 1 4 + return + fi + done + return 1 +} + +if [ "$1" == "persist.sys.phh.xiaomi.dt2w" ]; then + if [[ "$prop_value" -ne 0 && "$prop_value" -ne 1 ]]; then + exit 1 + fi + + if ! xiaomi_toggle_dt2w_proc_node "$prop_value"; then + # Fallback to event node method + xiaomi_toggle_dt2w_event_node "$prop_value" + fi + exit $? +fi diff --git a/rw-system.sh b/rw-system.sh index cb68841..782c17b 100644 --- a/rw-system.sh +++ b/rw-system.sh @@ -449,13 +449,6 @@ if [ -c /dev/dsm ];then mount /data/sec_storage_data /sec_storage fi -#Try to detect DT2W -for ev in $(cd /sys/class/input;echo event*);do - if [ -f "/sys/class/input/$ev/device/device/gesture_mask" ];then - setprop persist.sys.phh.dt2w_evnode /dev/input/$ev - fi -done - has_hostapd=false for i in odm oem vendor product;do if grep -qF android.hardware.wifi.hostapd /$i/etc/vintf/manifest.xml;then diff --git a/vndk.rc b/vndk.rc index 135ccd7..3accbed 100644 --- a/vndk.rc +++ b/vndk.rc @@ -15,3 +15,6 @@ on property:sys.boot_completed=1 on property:persist.sys.phh.mainkeys=* setprop qemu.hw.mainkeys ${persist.sys.phh.mainkeys} + +on property:persist.sys.phh.xiaomi.dt2w=* + exec_background u:r:phhsu_daemon:s0 root -- /system/bin/phh-prop-handler.sh "persist.sys.phh.xiaomi.dt2w"