blob: f52e57bafdf9a9a6927fc3f91e8396fb8b5f5c4c [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>
8#include <linux/input.h>
9
10int open_fingerprint() {
11 DIR *dir=opendir("/dev/input");
12 if(!dir) {
13 return -1;
14 }
15 int fd;
16 struct dirent *entry;
17 while( (entry=readdir(dir))!=NULL) {
18 if(entry->d_type!=DT_CHR)
19 continue;
20 if(strncmp(entry->d_name, "event", 5)==0) {
21 fd = openat(dirfd(dir), entry->d_name, O_RDONLY);
22 if(fd < 0) continue;
23
24 char buf[64];
25 int ret = ioctl(fd, EVIOCGNAME(sizeof(buf)), buf);
26 if(ret < 0) {
27 close(fd);
28 continue;
29 }
30
31 if(strcmp(buf, "fingerprint") != 0) {
32 close(fd);
33 continue;
34 }
35
36 ioctl(fd, EVIOCGRAB, 1);
37 closedir(dir);
38 return fd;
39 break;
40 }
41 }
42 closedir(dir);
43 return -1;
44}
45
46#define FINGERPRINT_CLICK 0xae
47#define FINGERPRINT_LONGPRESS 0x1c
48#define FINGERPRINT_RIGHT 0x6a
49#define FINGERPRINT_LEFT 0x69
50#define FINGERPRINT_UP 0x67
51#define FINGERPRINT_DOWN 0x6c
52#define FINGERPRINT_DOUBLECLICK 0x6f
53int main() {
54 int fd = open_fingerprint();
55 if(fd<0) return 1;
56
57 struct input_event ev;
58 while(read(fd, &ev, sizeof(ev)) == sizeof(ev)) {
59 if(ev.type != EV_KEY) continue;
60 //Huawei kernel code automatically generates both up and down events, just take one
61 if(ev.value != 1) continue;
62
63 switch(ev.code) {
64 case FINGERPRINT_CLICK:
Pierre-Hugues Husson7b7fe452018-01-15 00:10:05 +010065 system("input keyevent KEYCODE_HOME &");
Pierre-Hugues Hussond1cf8d82018-01-14 22:49:15 +010066 break;
67 case FINGERPRINT_LEFT:
Pierre-Hugues Husson7b7fe452018-01-15 00:10:05 +010068 system("input keyevent KEYCODE_BACK &");
Pierre-Hugues Hussond1cf8d82018-01-14 22:49:15 +010069 break;
70 case FINGERPRINT_RIGHT:
Pierre-Hugues Husson7b7fe452018-01-15 00:10:05 +010071 system("input keyevent KEYCODE_VOICE_ASSIST &");
Pierre-Hugues Hussond1cf8d82018-01-14 22:49:15 +010072 break;
73 case FINGERPRINT_UP:
Pierre-Hugues Husson7b7fe452018-01-15 00:10:05 +010074 system("cmd statusbar expand-settings &");
Pierre-Hugues Hussond1cf8d82018-01-14 22:49:15 +010075 break;
76 case FINGERPRINT_DOWN:
Pierre-Hugues Husson7b7fe452018-01-15 00:10:05 +010077 system("cmd statusbar expand-notifications &");
Pierre-Hugues Hussond1cf8d82018-01-14 22:49:15 +010078 break;
79 case FINGERPRINT_LONGPRESS:
Pierre-Hugues Husson7b7fe452018-01-15 00:10:05 +010080 system("input keyevent APP_APP_SWITCH &");
Pierre-Hugues Hussond1cf8d82018-01-14 22:49:15 +010081 break;
82 };
83 }
84}