mirror of
https://github.com/Anything-at-25-00/android_device_tecno_LG8n.git
synced 2024-11-22 13:46:26 -08:00
LG8n: Introduce shirayuki-dt2w service as a helper for DT2W service app
* The code can use some improvements Signed-off-by: Shirayuki39 <lorddemecrius83@proton.me>
This commit is contained in:
parent
1eba94acbd
commit
9407fb90fb
|
@ -30,7 +30,8 @@ android_app {
|
||||||
},
|
},
|
||||||
|
|
||||||
required: [
|
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",
|
src: "privapp-permissions_co.potatoproject.dt2w.MT6789.xml",
|
||||||
filename_from_src: true,
|
filename_from_src: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cc_binary {
|
||||||
|
name: "shirayuki-dt2w",
|
||||||
|
srcs: [
|
||||||
|
"shirayuki-dt2w",
|
||||||
|
],
|
||||||
|
vendor: true
|
||||||
|
}
|
||||||
|
|
70
dt2w/shirayuki-dt2w.c
Normal file
70
dt2w/shirayuki-dt2w.c
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
|
@ -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/events/mmstat/enable 1
|
||||||
write /sys/kernel/tracing/instances/mmstat/tracing_on 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
|
||||||
|
|
Loading…
Reference in a new issue