diff --git a/cmds/Android.bp b/cmds/Android.bp index 5896563..bc64ff3 100644 --- a/cmds/Android.bp +++ b/cmds/Android.bp @@ -253,3 +253,13 @@ cc_binary { "libhidlbase", ], } + +cc_binary { + name: "oplus-alert-slider", + srcs: [ + "oplus-alert-slider.cpp", + ], + init_rc: [ + "oplus-alert-slider.rc", + ], +} diff --git a/cmds/oplus-alert-slider.cpp b/cmds/oplus-alert-slider.cpp new file mode 100644 index 0000000..beb1e35 --- /dev/null +++ b/cmds/oplus-alert-slider.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int read_tristate() { + int fd = open("/proc/tristatekey/tri_state", O_RDONLY); + char p[16]; + int ret = read(fd, p, sizeof(p) - 1); + p[ret] = 0; + return atoi(p); +} + +int main() { + int fd = -1; + for(int i=0; i<255; i++) { + char path[256]; + snprintf(path, 256, "/dev/input/event%d", i); + fd = open(path, O_RDWR); + if(fd == -1) continue; + char name[256]; + ioctl(fd, EVIOCGNAME(256), name); + printf("Got input name %s\n", name); + if(strcmp(name, "oplus,hall_tri_state_key") == 0) { + break; + } + close(fd); + fd = -1; + } + if(fd == -1) return 0; + + ioctl(fd, EVIOCGRAB, 1); + + struct input_event ev; + while(read(fd, &ev, sizeof(ev)) != 0) { + if(!(ev.code == 61 && ev.value == 0)) continue; + int state = read_tristate(); + if(state == 1) { + } + printf("State %d\n", read_tristate()); + if(state == 1) { + system("service call audio 31 i32 2 s16 android"); + } else if(state == 2) { + system("service call audio 31 i32 1 s16 android"); + } else if(state == 3) { + system("service call audio 31 i32 0 s16 android"); + } + } +} diff --git a/cmds/oplus-alert-slider.rc b/cmds/oplus-alert-slider.rc new file mode 100644 index 0000000..ee2cbec --- /dev/null +++ b/cmds/oplus-alert-slider.rc @@ -0,0 +1,3 @@ +service phhoplus-alert-slider /system/bin/oplus-alert-slider + seclabel u:r:phhsu_daemon:s0 + class main