device_phh_treble/phh-prop-handler.sh

61 lines
1.5 KiB
Bash
Raw Permalink Normal View History

#!/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