blob: 9538cd17f5ceeb9120cd7e69d59a42b12d9d8c63 [file] [log] [blame]
Pierre-Hugues Hussond1cf8d82018-01-14 22:49:15 +01001#include <stdio.h>
2#include <sys/types.h>
3#include <sys/stat.h>
4#include <dirent.h>
5#include <fcntl.h>
6#include <unistd.h>
7#include <stdlib.h>
Pierre-Hugues Husson50edf2d2018-02-11 21:11:47 +01008#include <string.h>
Pierre-Hugues Hussond1cf8d82018-01-14 22:49:15 +01009#include <linux/input.h>
10
11int open_fingerprint() {
12 DIR *dir=opendir("/dev/input");
13 if(!dir) {
14 return -1;
15 }
16 int fd;
17 struct dirent *entry;
18 while( (entry=readdir(dir))!=NULL) {
19 if(entry->d_type!=DT_CHR)
20 continue;
21 if(strncmp(entry->d_name, "event", 5)==0) {
22 fd = openat(dirfd(dir), entry->d_name, O_RDONLY);
23 if(fd < 0) continue;
24
25 char buf[64];
26 int ret = ioctl(fd, EVIOCGNAME(sizeof(buf)), buf);
27 if(ret < 0) {
28 close(fd);
29 continue;
30 }
31
32 if(strcmp(buf, "fingerprint") != 0) {
33 close(fd);
34 continue;
35 }
36
37 ioctl(fd, EVIOCGRAB, 1);
38 closedir(dir);
39 return fd;
40 break;
41 }
42 }
43 closedir(dir);
44 return -1;
45}
46
47#define FINGERPRINT_CLICK 0xae
48#define FINGERPRINT_LONGPRESS 0x1c
49#define FINGERPRINT_RIGHT 0x6a
50#define FINGERPRINT_LEFT 0x69
51#define FINGERPRINT_UP 0x67
52#define FINGERPRINT_DOWN 0x6c
53#define FINGERPRINT_DOUBLECLICK 0x6f
54int main() {
55 int fd = open_fingerprint();
56 if(fd<0) return 1;
57
58 struct input_event ev;
59 while(read(fd, &ev, sizeof(ev)) == sizeof(ev)) {
60 if(ev.type != EV_KEY) continue;
61 //Huawei kernel code automatically generates both up and down events, just take one
62 if(ev.value != 1) continue;
63
64 switch(ev.code) {
65 case FINGERPRINT_CLICK:
Pierre-Hugues Husson7b7fe452018-01-15 00:10:05 +010066 system("input keyevent KEYCODE_HOME &");
Pierre-Hugues Hussond1cf8d82018-01-14 22:49:15 +010067 break;
68 case FINGERPRINT_LEFT:
Pierre-Hugues Husson7b7fe452018-01-15 00:10:05 +010069 system("input keyevent KEYCODE_BACK &");
Pierre-Hugues Hussond1cf8d82018-01-14 22:49:15 +010070 break;
71 case FINGERPRINT_RIGHT:
Pierre-Hugues Husson7b7fe452018-01-15 00:10:05 +010072 system("input keyevent KEYCODE_VOICE_ASSIST &");
Pierre-Hugues Hussond1cf8d82018-01-14 22:49:15 +010073 break;
74 case FINGERPRINT_UP:
Pierre-Hugues Husson7b7fe452018-01-15 00:10:05 +010075 system("cmd statusbar expand-settings &");
Pierre-Hugues Hussond1cf8d82018-01-14 22:49:15 +010076 break;
77 case FINGERPRINT_DOWN:
Pierre-Hugues Husson7b7fe452018-01-15 00:10:05 +010078 system("cmd statusbar expand-notifications &");
Pierre-Hugues Hussond1cf8d82018-01-14 22:49:15 +010079 break;
80 case FINGERPRINT_LONGPRESS:
Pierre-Hugues Husson0dedfd62018-01-15 00:26:40 +010081 system("input keyevent KEYCODE_APP_SWITCH &");
Pierre-Hugues Hussond1cf8d82018-01-14 22:49:15 +010082 break;
83 };
84 }
85}