Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions packages/omamobile-shell/bin/omamobile-sleepd
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
# and the sleep hook apply) once the screen has been off and the lock secure
# for OMAMOBILE_SLEEP_AFTER_OFF seconds (30), and again OMAMOBILE_SLEEP_GRACE
# seconds (5) after a dark resume: a wake that left the screen off (an alarm,
# the RTC, Bluetooth, the fuel gauge, a volume key). A power-key wake lights
# the PIN pad (omamobile-keys wake, from here), and a lit screen never sleeps.
# the RTC, Bluetooth, the fuel gauge, a volume key). A power-key or a touch
# wake lights the PIN pad (omamobile-keys wake, from here), and a lit screen
# never sleeps.
#
# Never while:
# - the toggle is off, the screen is on, or the lock isn't secure;
Expand Down Expand Up @@ -117,6 +118,31 @@ wake_reason() {
echo "IRQ $irq:${name:- (unknown)}"
}

# The touchscreen's interrupt, as /proc/interrupts names it: the driver
# requests it under its device's name (the SPI or I2C device, "spi3.0"), so
# find the input device that is a direct touch surface (INPUT_PROP_DIRECT)
# with a parent device, and take that parent's name. A virtual input device
# (uinput, a test tool) has no `device` link and is skipped, so it can't
# mask the real touchscreen. Empty when there is none.
touch_irq_name() {
local d props
for d in "$sys"/class/input/input*; do
props=$(cat "$d/properties" 2>/dev/null) || continue
(( (0x${props:-0} & 0x2) )) || continue
[[ -e $d/device ]] || continue
basename "$(readlink -f "$d/device")"
return 0
done
return 1
}

# A touch woke the phone: the wake IRQ is the touchscreen's.
touch_woke() {
local name
name=$(touch_irq_name) || return 1
[[ -n $name && $1 == *" $name" ]]
}

request() {
log "sleeping ($1)"
# The lock goes back to its glance view before the freeze, for a screen
Expand Down Expand Up @@ -155,10 +181,19 @@ watch() {
# The press that woke the phone never reaches Hyprland's binds: the
# session is frozen while the kernel takes it. Light the PIN pad here,
# as that press would have (omamobile-keys ignores the press itself if
# it does arrive, so the screen doesn't go straight back off).
if [[ $woke == *KEY_POWER* ]] && command -v omamobile-keys >/dev/null; then
log "a power-key wake: lighting the lock screen"
omamobile-keys wake >/dev/null 2>&1 &
# it does arrive, so the screen doesn't go straight back off). A touch
# wake is the same: Hyprland's DPMS state and the panel's backlight
# power stay as the sleep left them unless the lock is lit through
# omamobile-keys, and on tegu that left a lit lock screen that Hyprland
# read as dark and whose panel refused the fingerprint circle.
if command -v omamobile-keys >/dev/null; then
if [[ $woke == *KEY_POWER* ]]; then
log "a power-key wake: lighting the lock screen"
omamobile-keys wake >/dev/null 2>&1 &
elif touch_woke "$woke"; then
log "a touch wake: lighting the lock screen"
omamobile-keys wake >/dev/null 2>&1 &
fi
fi
# Any wake that leaves the screen off and locked is dark: back to
# sleep after the grace. A power-key wake lights the screen and
Expand Down
17 changes: 17 additions & 0 deletions packages/omamobile-shell/test/sleepd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,23 @@ grep -c '^omamobile-keys' "$t/log" >/dev/null && fail "an RTC wake doesn't light
reset; echo 111 >"$t/wake_irq"; printf 'echo 0 >"%s"; echo true >"%s"\n' "$t/sys/class/backlight/panel/bl_power" "$t/dpms" >"$t/on_resume"; watch 700
grep -c '^omamobile-keys wake' "$t/log" >/dev/null || fail "a power-key wake asks omamobile-keys to light the PIN pad"
grep -c 'a power-key wake: lighting the lock screen' "$t/out" >/dev/null || fail "the power-key wake is logged"
# A touch woke it: the touchscreen's interrupt carries its device's name
# (the input device with INPUT_PROP_DIRECT, parent "spi3.0"), and the lock
# is lit the same way; Hyprland's DPMS state and bl_power would otherwise
# stay as the sleep left them.
reset; mkdir -p "$t/sys/class/input/input0" "$t/sys/devices/spi3.0"; echo 2 >"$t/sys/class/input/input0/properties"; ln -sfn "$t/sys/devices/spi3.0" "$t/sys/class/input/input0/device"
printf ' 73: 12 0 gpa7 6 Edge spi3.0\n' >>"$t/proc/interrupts"
echo 73 >"$t/wake_irq"; printf 'echo 0 >"%s"; echo true >"%s"\n' "$t/sys/class/backlight/panel/bl_power" "$t/dpms" >"$t/on_resume"; watch 700
grep -c '^omamobile-keys wake' "$t/log" >/dev/null || fail "a touch wake asks omamobile-keys to light the PIN pad"
grep -c 'a touch wake: lighting the lock screen' "$t/out" >/dev/null || fail "the touch wake is logged"
# The same interrupt line with no touchscreen among the input devices is a dark resume.
reset; rm -rf "$t/sys/class/input"; printf ' 73: 12 0 gpa7 6 Edge spi3.0\n' >>"$t/proc/interrupts"; echo 73 >"$t/wake_irq"; watch 700
grep -c '^omamobile-keys' "$t/log" >/dev/null && fail "an unknown wake doesn't light the screen"
# A virtual direct-touch device (no `device` link, as uinput makes) listed
# before the real one must not mask it: the real touchscreen's name is used.
reset; mkdir -p "$t/sys/class/input/input0" "$t/sys/class/input/input1" "$t/sys/devices/spi3.0"; echo 2 >"$t/sys/class/input/input0/properties"; echo 2 >"$t/sys/class/input/input1/properties"; ln -sfn "$t/sys/devices/spi3.0" "$t/sys/class/input/input1/device"
printf ' 73: 12 0 gpa7 6 Edge spi3.0\n' >>"$t/proc/interrupts"; echo 73 >"$t/wake_irq"; printf 'echo 0 >"%s"; echo true >"%s"\n' "$t/sys/class/backlight/panel/bl_power" "$t/dpms" >"$t/on_resume"; watch 700
grep -c 'a touch wake: lighting the lock screen' "$t/out" >/dev/null || fail "a virtual touch device without a parent doesn't mask the real touchscreen"
# A failed suspend is logged and retried no sooner than 30 s later.
reset
fake systemctl 'echo "systemctl $* at $(cat "$T/clock")" >>"$T/log"
Expand Down
2 changes: 1 addition & 1 deletion packages/omamobile-shell/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.45
0.2.46