-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathservice.sh
More file actions
112 lines (95 loc) · 2.88 KB
/
service.sh
File metadata and controls
112 lines (95 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/system/bin/sh
KILLER="/data/adb/modules/QuiteKill/QuiteKill.sh"
STOPPER="/sdcard/stopQuiteKill"
LOGDIR="/data/adb/modules/QuiteKill/logs"
LOGFILE="$LOGDIR/kill.log"
DEBUG=0
CLICK_THRESHOLD=0.3
COOLDOWN=5
mkdir -p "$LOGDIR"
log() {
if [ "$DEBUG" -eq 1 ]; then
echo "[DEBUG] $(date '+%m-%d %H:%M:%S') - $*" | tee -a "$LOGFILE"
else
echo "$(date '+%m-%d %H:%M:%S') - $*" >> "$LOGFILE"
fi
}
monitor_event0() {
log "Starting event0 monitor (low CPU)..."
last_down=0
# Read lines blocking from event0
getevent /dev/input/event0 | while read -r line; do
[ -f "$STOPPER" ] && log "Key Smasher disabled" && exit 0
case "$line" in
*"0001 0074 00000001"*) # POWER DOWN
last_down=$(date +%s.%N)
log "Power button DOWN"
;;
*"0001 0074 00000000"*) # POWER UP
if [ "$last_down" != 0 ]; then
up_time=$(date +%s.%N)
# Calculate diff with shell arithmetic for speed (use bc if available, else awk)
if command -v bc >/dev/null 2>&1; then
diff=$(echo "$up_time - $last_down" | bc)
else
diff=$(awk "BEGIN {print $up_time - $last_down}")
fi
last_down=0
# Compare diff without awk for speed if possible
diff_check() {
awk "BEGIN {exit !($1 < $2)}"
}
if diff_check "$diff" "$CLICK_THRESHOLD"; then
log "Quick tap detected (${diff}s)"
sh "$KILLER" &
log "🤫🔪 Murdered all running apps"
sleep "$COOLDOWN"
else
log "Long press ignored (${diff}s)"
fi
fi
;;
esac
done
}
# Fallback polling with minimal CPU usage
polling_loop() {
log "Starting fallback polling loop (low CPU)..."
while true; do
[ -f "$STOPPER" ] && log "Key Smasher disabled" && exit 0
EVENT=$(getevent -lqc1)
case "$EVENT" in
*KEY_POWER*DOWN*)
down_time=$(date +%s.%N)
# Wait for UP event max 4s, but poll every 0.2s to reduce CPU usage
end=$((SECONDS + 4))
while [ $SECONDS -lt $end ]; do
sleep 0.2
next_event=$(getevent -lqc1)
if echo "$next_event" | grep -q "KEY_POWER.*UP"; then
up_time=$(date +%s.%N)
if command -v bc >/dev/null 2>&1; then
diff=$(echo "$up_time - $down_time" | bc)
else
diff=$(awk "BEGIN {print $up_time - $down_time}")
fi
if awk "BEGIN {exit !($diff < $CLICK_THRESHOLD)}"; then
log "Quick tap detected (${diff}s)"
sh "$KILLER" &
log "🤫🔪 Murdered all running apps"
sleep "$COOLDOWN"
else
log "Long press ignored (${diff}s)"
fi
break
fi
done
;;
esac
done
}
if [ -r /dev/input/event0 ]; then
monitor_event0
else
polling_loop
fi