From 9407fb90fbd6e18d2c315bdbf74da1bd94d3790a Mon Sep 17 00:00:00 2001 From: Shirayuki39 Date: Wed, 14 Aug 2024 03:04:43 +0800 Subject: [PATCH] LG8n: Introduce shirayuki-dt2w service as a helper for DT2W service app * The code can use some improvements Signed-off-by: Shirayuki39 --- dt2w/Android.bp | 11 ++++- dt2w/shirayuki-dt2w.c | 70 +++++++++++++++++++++++++++++ rootdir/etc/init/hw/init.project.rc | 3 ++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 dt2w/shirayuki-dt2w.c diff --git a/dt2w/Android.bp b/dt2w/Android.bp index 89c5597..8251ee8 100644 --- a/dt2w/Android.bp +++ b/dt2w/Android.bp @@ -30,7 +30,8 @@ android_app { }, required: [ - "privapp-permissions_co.potatoproject.dt2w.MT6789" + "privapp-permissions_co.potatoproject.dt2w.MT6789", + "shirayuki-dt2w" ] } @@ -40,3 +41,11 @@ prebuilt_etc { src: "privapp-permissions_co.potatoproject.dt2w.MT6789.xml", filename_from_src: true, } + +cc_binary { + name: "shirayuki-dt2w", + srcs: [ + "shirayuki-dt2w", + ], + vendor: true +} diff --git a/dt2w/shirayuki-dt2w.c b/dt2w/shirayuki-dt2w.c new file mode 100644 index 0000000..c60ce9c --- /dev/null +++ b/dt2w/shirayuki-dt2w.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include + +#define GESTURE_FUNCTION_PATH "/proc/gesture_function" +#define GESTURE_STATE_PATH "/proc/gesture_state" +#define DT2W_STATE_PROP "persist.sys.MT6789.dt2w" + +// me noob sar + +// sounds like a great idea, with the best of intentions + +int main() { + FILE *fp, *fpState; + char cmd[100]; + char buffer[20]; + char stateBuffer[20]; + + // Wait until we finish boot + sprintf(cmd, "getprop sys.boot_completed"); + while (system(cmd) != 0); // Assuming 'getprop' returns 0 when boot is completed + + // Main loop to continuously monitor and adjust gesture function + while (1) { + sprintf(cmd, "getprop %s", DT2W_STATE_PROP); + fp = popen(cmd, "r"); + if (fp == NULL) { + printf("prop not found\n"); + exit(1); + } + + fgets(buffer, sizeof(buffer)-1, fp); + pclose(fp); + + // Remove trailing newline character, just so it's clean + buffer[strcspn(buffer, "\n")] = 0; + + // see if gesture_state nude already has the value we want + sprintf(cmd, "awk '/cc:/ {print $2}' %s", GESTURE_STATE_PATH); + fpState = popen(cmd, "r"); + if (fpState != NULL) { + fgets(stateBuffer, sizeof(stateBuffer)-1, fpState); + pclose(fpState); + + // Remove trailing newline character + stateBuffer[strcspn(stateBuffer, "\n")] = 0; + + if ((strcmp(buffer, "0") == 0 && strcmp(stateBuffer, "cc:0") != 0) || + (strcmp(buffer, "1") == 0 && strcmp(stateBuffer, "cc:1") != 0)) { + // it doesn't have the value we want, go write + fp = fopen(GESTURE_FUNCTION_PATH, "w"); + if (fp != NULL) { + if (strcmp(buffer, "0") == 0) { + fputs("cc2", fp); + } else if (strcmp(buffer, "1") == 0) { + fputs("cc1", fp); + } + fclose(fp); + } + } + } else { + printf("Failed to read gesture state\n"); + } + + sleep(1); // Sleep for 1 second before checking again + } + + return 0; +} diff --git a/rootdir/etc/init/hw/init.project.rc b/rootdir/etc/init/hw/init.project.rc index d3d6b20..8945bc6 100644 --- a/rootdir/etc/init/hw/init.project.rc +++ b/rootdir/etc/init/hw/init.project.rc @@ -102,3 +102,6 @@ on property:sys.boot_completed=1 write /sys/kernel/tracing/instances/mmstat/events/mmstat/enable 1 write /sys/kernel/tracing/instances/mmstat/tracing_on 1 +# Shirayuki-DT2W Helper Service +on property:sys.boot_completed=1 + exec - root -- /vendor/bin/shirayuki-dt2w