Recently Written · git

assistkey

Hardware key remapper for the Viwoods AiPaper Reader: AI key, volume keys and power, with multi-tap, hold and chords

git clone https://github.com/equwal/assistkey

Log | Files | Refs


tools/e2e/power-wake.sh (2605 bytes)

1 #!/usr/bin/env bash
2 # Regression test, on a device: in managed Power mode a Power press on a sleeping
3 # device wakes it, and is NOT read as a gesture.
4 #
5 # Bug it guards: with tap bound to Back, the press that woke the reader could
6 # also run Back, and a locked or charging reader had no sure way to wake.
7 #
8 # Needs: adb root, release build installed, key remapping on, shell access on,
9 # Power tap bound to Back and triple tap to Lock screen (Navigation > Power key). Presses go through the kernel input
10 # node, because `adb shell input keyevent` skips the input filter stage.
11 set -u
12 export MSYS_NO_PATHCONV=1
13 NODE=${POWER_NODE:-/dev/input/event1}
14 E="sendevent $NODE"; TAP="$E 1 116 1; $E 0 0 0; sleep 0.06; $E 1 116 0; $E 0 0 0"
15 wake()  { adb shell dumpsys power | grep -oE 'mWakefulness=[A-Za-z]+' | head -1 | cut -d= -f2; }
16 top()   { # dumpsys now and then answers before the activity has settled; ask again.
17   local t="" i
18   for i in 1 2 3 4 5; do
19     t=$(adb shell "dumpsys activity activities" | grep -m1 topResumedActivity | grep -oE '[A-Za-z0-9_.]+/[A-Za-z0-9_.$]+' | head -1)
20     [ -n "$t" ] && break; sleep 1
21   done; echo "$t"; }
22 fail=0
23 check() { if [ "$2" = "$3" ]; then echo "PASS  $1: $2"; else echo "FAIL  $1: got '$2', want '$3'"; fail=1; fi; }
24 
25 [ "$(adb shell settings get global power_button_short_press | tr -d '\r')" = "0" ] || { echo "SKIP  Power is not managed (power_button_short_press is not 0)"; exit 2; }
26 
27 adb shell input keyevent KEYCODE_WAKEUP; sleep 2   # let any earlier tap window run out
28 # Two AssistKey screens deep, so that Back would visibly change the top activity.
29 # (Not the Settings app: on the Viwoods reader an injected SLEEP key is ignored
30 # while Settings > Display is in front.)
31 P=dev.equwal.assistkey
32 adb shell "am start -n $P/.ui.MainActivity" >/dev/null 2>&1; sleep 2
33 adb shell "su 0 am start -n $P/.ui.TimingActivity" >/dev/null 2>&1; sleep 2.5
34 before=$(top)
35 
36 # Sleep with the triple tap the app binds to Lock screen. An injected SLEEP key
37 # is not reliable on this firmware.
38 QUICK="$E 1 116 1; $E 0 0 0; $E 1 116 0; $E 0 0 0;"
39 adb shell "su 0 sh -c '$QUICK sleep 0.05; $QUICK sleep 0.05; $QUICK'"; sleep 4
40 check "device sleeps" "$(wake | sed 's/Dozing/Asleep/')" "Asleep"
41 
42 adb shell "su 0 sh -c '$TAP'"; sleep 3
43 check "one Power press wakes it" "$(wake)" "Awake"
44 check "the waking press is not a Back gesture" "$(top)" "$before"
45 
46 adb shell "su 0 sh -c '$TAP'"; sleep 2.5
47 [ "$(top)" != "$before" ] && echo "PASS  the next press is a gesture again" || { echo "FAIL  a press while awake did nothing"; fail=1; }
48 adb shell input keyevent KEYCODE_HOME
49 exit $fail