From a66fa56752fbbc1b38339622d8e71cb885c243cc Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Wed, 9 Feb 2022 21:05:39 +0000 Subject: [PATCH] Fix DT2W on Xiaomi Mi 11 Lite 5G by using xiaomi-touch It may also fix for other Xiaomi devices --- base.mk | 3 +++ cmds/Android.bp | 7 ++++++ cmds/asus-motor.cpp | 2 ++ cmds/xiaomi-touch.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++ phh-prop-handler.sh | 20 +++++++++++++----- sepolicy/file_contexts | 1 + 6 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 cmds/xiaomi-touch.cpp diff --git a/base.mk b/base.mk index 4a5c652..73abbab 100644 --- a/base.mk +++ b/base.mk @@ -218,4 +218,7 @@ PRODUCT_COPY_FILES += \ PRODUCT_PACKAGES += phh-ota +PRODUCT_PACKAGES += \ + xiaomi-touch + include build/make/target/product/gsi_release.mk diff --git a/cmds/Android.bp b/cmds/Android.bp index 4568089..a2f373d 100644 --- a/cmds/Android.bp +++ b/cmds/Android.bp @@ -204,3 +204,10 @@ cc_binary { "oplus-alert-slider.rc", ], } + +cc_binary { + name: "xiaomi-touch", + srcs: [ + "xiaomi-touch.cpp", + ], +} diff --git a/cmds/asus-motor.cpp b/cmds/asus-motor.cpp index 7f18858..6cd0ae8 100644 --- a/cmds/asus-motor.cpp +++ b/cmds/asus-motor.cpp @@ -3,6 +3,7 @@ #include #include #include +#include typedef struct { int dir; @@ -27,4 +28,5 @@ int main(int argc, char **argv) { cfg.speed = 4; ioctl(fd, ASUS_MOTOR_DRV_MANUAL_MODE, &cfg); + close(fd); } diff --git a/cmds/xiaomi-touch.cpp b/cmds/xiaomi-touch.cpp new file mode 100644 index 0000000..0ce94fc --- /dev/null +++ b/cmds/xiaomi-touch.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +#define SET_CUR_VALUE 0 + +#define Touch_Game_Mode 0 +#define Touch_Active_MODE 1 +#define Touch_UP_THRESHOLD 2 +#define Touch_Tolerance 3 +#define Touch_Aim_Sensitivity 4 +#define Touch_Tap_Stability 5 +#define Touch_Expert_Mode 6 +#define Touch_Edge_Filter 7 +#define Touch_Panel_Orientation 8 +#define Touch_Report_Rate 9 +#define Touch_Fod_Enable 10 +#define Touch_Aod_Enable 11 +#define Touch_Resist_RF 12 +#define Touch_Idle_Time 13 +#define Touch_Doubletap_Mode 14 +#define Touch_Grip_Mode 15 +#define Touch_FodIcon_Enable 16 +#define Touch_Nonui_Mode 17 +#define Touch_Debug_Level 18 +#define Touch_Power_Status 19 +#define Touch_Mode_NUM 20 + +#define TOUCH_DEV_PATH "/dev/xiaomi-touch" +#define TOUCH_ID 0 +#define TOUCH_MAGIC 0x5400 +#define TOUCH_IOC_SETMODE TOUCH_MAGIC + SET_CUR_VALUE + +int main(int argc, char **argv) { + if(argc != 3) { + fprintf(stderr, "Usage: %s <0|1>\n", argv[0]); + return -1; + } + int mode = atoi(argv[1]); + int enabled = atoi(argv[2]); + if (mode < 0 || mode > 20) return -1; + if (enabled != 0 && enabled != 1) return -1; + int fd = open(TOUCH_DEV_PATH, O_RDWR); + int arg[3] = {TOUCH_ID, mode, enabled}; + ioctl(fd, TOUCH_IOC_SETMODE, &arg); + close(fd); +} diff --git a/phh-prop-handler.sh b/phh-prop-handler.sh index 8b65a68..4371632 100644 --- a/phh-prop-handler.sh +++ b/phh-prop-handler.sh @@ -52,6 +52,15 @@ xiaomi_toggle_dt2w_event_node() { return 1 } +xiaomi_toggle_dt2w_ioctl() { + if [ -c "/dev/xiaomi-touch" ]; then + echo "Trying to set dt2w mode with ioctl on /dev/xiaomi-touch" + # 14 - Touch_Doubletap_Mode + xiaomi-touch 14 "$1" + return + fi + return 1 +} restartAudio() { setprop ctl.restart audioserver @@ -66,11 +75,12 @@ if [ "$1" == "persist.sys.phh.xiaomi.dt2w" ]; 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 $? + xiaomi_toggle_dt2w_proc_node "$prop_value" + # Fallback to event node method + xiaomi_toggle_dt2w_event_node "$prop_value" + # Fallback to ioctl method + xiaomi_toggle_dt2w_ioctl "$prop_value" + exit fi if [ "$1" == "persist.sys.phh.oppo.dt2w" ]; then diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts index 4ae5095..999ff97 100644 --- a/sepolicy/file_contexts +++ b/sepolicy/file_contexts @@ -5,6 +5,7 @@ /system/bin/phh-on-boot.sh u:object_r:phhsu_exec:s0 /system/bin/phh-on-data.sh u:object_r:phhsu_exec:s0 /system/bin/asus-motor u:object_r:phhsu_exec:s0 +/system/bin/xiaomi-touch u:object_r:phhsu_exec:s0 #/system/bin/fsck\.exfat u:object_r:fsck_exec:s0 /system/bin/fsck\.ntfs u:object_r:fsck_exec:s0