Trigger the screenlock daemon on idle screen blanking
This commit is contained in:
1 parent
77d95c715c
commit
5d859d7b11
11 files changed
+382
-12
No files matched your search
@@ -171,7 +171,12 @@ chown 0:0 "$TARGET_ROOTFS/etc/chrony/chrony.conf" \
|
||||
"$TARGET_ROOTFS/etc/NetworkManager/dispatcher.d/30-bananarchy-network-status.sh" \
|
||||
2>/dev/null || true
|
||||
chmod 0644 "$TARGET_ROOTFS/etc/chrony/chrony.conf" 2>/dev/null || true
|
||||
chmod 0755 "$TARGET_ROOTFS/usr/bin/bananarchy-time-sync.sh" \
|
||||
# The idle-blank lock helper is spawned directly by dwm's blank handler, so
|
||||
# keep it executable even if the overlay was copied with restrictive modes.
|
||||
chmod 0755 "$TARGET_ROOTFS/usr/bin/bananarchy-idle-blank.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-idle-lock.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-screen-wake.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-time-sync.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-sync-net-time.sh" \
|
||||
"$TARGET_ROOTFS/usr/bin/bananarchy-network-event.sh" \
|
||||
"$TARGET_ROOTFS/etc/init.d/bananarchy-time-sync" \
|
||||
|
||||
@@ -1126,6 +1126,38 @@ if command -v g++ >/dev/null 2>&1 && \
|
||||
fail "host webarchy renderer profile test failed"
|
||||
fi
|
||||
|
||||
echo "[check] Idle blank screenlock wiring..."
|
||||
IDLE_BLANK="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-idle-blank.sh"
|
||||
IDLE_LOCK="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-idle-lock.sh"
|
||||
SCREEN_WAKE="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-screen-wake.sh"
|
||||
UNLOCK_HOOK="$BASE_DIR/overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_unlock.sh"
|
||||
for f in "$IDLE_BLANK" "$IDLE_LOCK" "$SCREEN_WAKE" "$UNLOCK_HOOK"; do
|
||||
if [ ! -x "$f" ]; then
|
||||
fail "${f#$BASE_DIR/} is missing or not executable"
|
||||
fi
|
||||
if ! sh -n "$f" 2>/dev/null; then
|
||||
fail "shell syntax: ${f#$BASE_DIR/}"
|
||||
fi
|
||||
done
|
||||
if ! grep -q '"$LOCK_HELPER" arm' "$IDLE_BLANK" || \
|
||||
! grep -q 'bananarchy-idle-lock.sh' "$IDLE_BLANK" || \
|
||||
! grep -q 'set screenoff' "$IDLE_LOCK"; then
|
||||
fail "idle blanking no longer arms the trusted screenoff lock"
|
||||
fi
|
||||
for f in "$SCREEN_WAKE" "$UNLOCK_HOOK"; do
|
||||
if ! grep -q 'bananarchy-idle-lock.sh' "$f"; then
|
||||
fail "${f#$BASE_DIR/} no longer cancels a pending idle lock on wake"
|
||||
fi
|
||||
done
|
||||
if ! grep -q 'bananarchy-idle-lock.sh' "$BASE_DIR/scripts/apply-bananarchy-overlay.sh"; then
|
||||
fail "apply-bananarchy-overlay.sh no longer installs the idle lock helper"
|
||||
fi
|
||||
if [ -x "$BASE_DIR/scripts/test-idle-blank-lock.py" ] && \
|
||||
command -v python3 >/dev/null 2>&1 && \
|
||||
! "$BASE_DIR/scripts/test-idle-blank-lock.py" >/dev/null 2>&1; then
|
||||
fail "host idle-blank screenlock integration test failed"
|
||||
fi
|
||||
|
||||
if [ "$FAILURES" -ne 0 ]; then
|
||||
echo "[check] $FAILURES check(s) failed."
|
||||
exit 1
|
||||
|
||||
Executable
+191
@@ -0,0 +1,191 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Host integration test for idle-blank -> screenlock daemon wiring.
|
||||
|
||||
Runs the real shell helpers against stubbed sxmo_wm.sh / sxmo_state.sh and a
|
||||
temporary home, so the lock arming, cancellation and wake paths are verified
|
||||
without an X session or a phone.
|
||||
"""
|
||||
import os
|
||||
import pathlib
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
BASE = pathlib.Path(__file__).resolve().parent.parent
|
||||
BIN = BASE / "overlay/rootfs/usr/bin"
|
||||
LOCK = BIN / "bananarchy-idle-lock.sh"
|
||||
BLANK = BIN / "bananarchy-idle-blank.sh"
|
||||
WAKE = BIN / "bananarchy-screen-wake.sh"
|
||||
UNLOCK_HOOK = BASE / "overlay/rootfs/usr/share/sxmo/default_hooks/sxmo_hook_unlock.sh"
|
||||
|
||||
WM_STUB = '''#!/bin/sh
|
||||
if [ "$1" = "display" ]; then
|
||||
case "$2" in
|
||||
off) printf 'off\\n' > "$FAKE_ROOT/display_state" ;;
|
||||
on) printf 'on\\n' > "$FAKE_ROOT/display_state" ;;
|
||||
"") cat "$FAKE_ROOT/display_state" ;;
|
||||
esac
|
||||
fi
|
||||
exit 0
|
||||
'''
|
||||
|
||||
STATE_STUB = '''#!/bin/sh
|
||||
printf '%s\\n' "$*" >> "$FAKE_ROOT/state.log"
|
||||
exit 0
|
||||
'''
|
||||
|
||||
|
||||
def failure(message):
|
||||
sys.stderr.write("FAIL: %s\n" % message)
|
||||
return 1
|
||||
|
||||
|
||||
def main():
|
||||
for path in (LOCK, BLANK, WAKE, UNLOCK_HOOK):
|
||||
if not path.is_file():
|
||||
return failure("missing %s" % path)
|
||||
if subprocess.run(["sh", "-n", str(LOCK)]).returncode or \
|
||||
subprocess.run(["sh", "-n", str(BLANK)]).returncode or \
|
||||
subprocess.run(["sh", "-n", str(WAKE)]).returncode:
|
||||
return failure("shell syntax")
|
||||
with tempfile.TemporaryDirectory(prefix="bananarchy-idle-lock-") as tmp:
|
||||
root = pathlib.Path(tmp)
|
||||
bindir = root / "bin"
|
||||
home = root / "home"
|
||||
(home / ".config/sxmo").mkdir(parents=True)
|
||||
bindir.mkdir()
|
||||
for name, body in (("sxmo_wm.sh", WM_STUB), ("sxmo_state.sh", STATE_STUB)):
|
||||
target = bindir / name
|
||||
target.write_text(body, encoding="utf-8")
|
||||
target.chmod(0o755)
|
||||
display = root / "display_state"
|
||||
state_log = root / "state.log"
|
||||
lock_flag = root / "locked"
|
||||
cfg = home / ".config/sxmo/idle_lock_delay"
|
||||
env = dict(os.environ)
|
||||
env.update({
|
||||
"HOME": str(home),
|
||||
"XDG_CONFIG_HOME": str(home / ".config"),
|
||||
"FAKE_ROOT": str(root),
|
||||
"BANANARCHY_WM_CMD": str(bindir / "sxmo_wm.sh"),
|
||||
"BANANARCHY_STATE_CMD": str(bindir / "sxmo_state.sh"),
|
||||
"BANANARCHY_IDLE_LOCK_HELPER": str(LOCK),
|
||||
"BANANARCHY_IDLE_LOCK_PIDFILE": str(root / "lock.pid"),
|
||||
"BANANARCHY_LOCK_FLAG": str(lock_flag),
|
||||
"BANANARCHY_WAKE_TS": str(root / "wake.ts"),
|
||||
"BANANARCHY_IDLE_BLANK_GRACE": "0",
|
||||
})
|
||||
|
||||
def run(script, *args):
|
||||
cmd = ["sh", str(script), *args]
|
||||
if os.environ.get("BANANARCHY_TEST_DEBUG"):
|
||||
cmd.insert(1, "-x")
|
||||
res = subprocess.run(cmd, env=env, capture_output=True, text=True)
|
||||
if os.environ.get("BANANARCHY_TEST_DEBUG"):
|
||||
sys.stderr.write("%s %s: %s\n" % (script.name, args, res.stderr[-1200:]))
|
||||
return res
|
||||
|
||||
def log():
|
||||
return state_log.read_text() if state_log.exists() else ""
|
||||
|
||||
def clear():
|
||||
if state_log.exists():
|
||||
state_log.unlink()
|
||||
if lock_flag.exists():
|
||||
lock_flag.unlink()
|
||||
|
||||
def dark(value=True):
|
||||
display.write_text("off\n" if value else "on\n", encoding="utf-8")
|
||||
|
||||
# Defaults and user configuration.
|
||||
dark()
|
||||
if run(LOCK, "get").stdout.strip() != "30":
|
||||
return failure("default lock delay is not 30 s")
|
||||
if run(LOCK, "label").stdout.strip() != "30s":
|
||||
return failure("default lock delay label")
|
||||
if run(LOCK, "set", "off").stdout.strip() != "off" or \
|
||||
run(LOCK, "label").stdout.strip() != "Off":
|
||||
return failure("lock delay cannot be disabled")
|
||||
if run(LOCK, "set", "bogus").returncode == 0:
|
||||
return failure("invalid lock delay accepted")
|
||||
if run(LOCK, "set", "0").stdout.strip() != "0":
|
||||
return failure("immediate lock delay cannot be configured")
|
||||
print("[ok] config: default, off, immediate and invalid values")
|
||||
|
||||
# Immediate arm must call the trusted screenoff transition.
|
||||
clear()
|
||||
run(LOCK, "arm")
|
||||
if "set screenoff" not in log():
|
||||
return failure("immediate arm did not trigger the screenlock daemon")
|
||||
print("[ok] arm: immediate screenoff transition")
|
||||
|
||||
# Delayed arm must fire while the panel is still dark.
|
||||
clear()
|
||||
cfg.write_text("1\n", encoding="utf-8")
|
||||
run(LOCK, "arm")
|
||||
if "set screenoff" in log():
|
||||
return failure("delayed arm locked before the deadline")
|
||||
time.sleep(1.4)
|
||||
if "set screenoff" not in log():
|
||||
return failure("delayed arm did not trigger the screenlock daemon")
|
||||
print("[ok] arm: delayed screenoff transition")
|
||||
|
||||
# Cancel before the deadline must prevent the lock.
|
||||
clear()
|
||||
run(LOCK, "arm")
|
||||
run(LOCK, "cancel")
|
||||
time.sleep(1.4)
|
||||
if log():
|
||||
return failure("cancel did not stop the pending lock")
|
||||
print("[ok] cancel: pending lock stopped")
|
||||
|
||||
# Waking the panel before the deadline must prevent the lock.
|
||||
clear()
|
||||
dark()
|
||||
run(LOCK, "arm")
|
||||
time.sleep(0.2)
|
||||
dark(False)
|
||||
time.sleep(1.3)
|
||||
if log():
|
||||
return failure("lock fired after the panel was already awake")
|
||||
print("[ok] wake: no lock after the panel is on")
|
||||
|
||||
# The blank handler itself must arm (and its inverse must cancel) the lock.
|
||||
clear()
|
||||
cfg.write_text("0\n", encoding="utf-8")
|
||||
dark(False)
|
||||
run(BLANK, "off")
|
||||
if display.read_text().strip() != "off" or "set screenoff" not in log():
|
||||
return failure("bananarchy-idle-blank.sh off did not arm the lock: "
|
||||
"display=%r log=%r" % (display.read_text().strip(), log()))
|
||||
print("[ok] blank: off arms the screenlock daemon")
|
||||
|
||||
clear()
|
||||
cfg.write_text("1\n", encoding="utf-8")
|
||||
dark(False)
|
||||
run(BLANK, "off")
|
||||
run(BLANK, "on")
|
||||
time.sleep(1.4)
|
||||
if log():
|
||||
return failure("bananarchy-idle-blank.sh on did not cancel the lock")
|
||||
print("[ok] blank: on cancels the pending lock")
|
||||
|
||||
# An incoming call / SMS wake must cancel the pending lock too.
|
||||
clear()
|
||||
dark(False)
|
||||
run(BLANK, "off")
|
||||
run(WAKE)
|
||||
time.sleep(1.4)
|
||||
if log():
|
||||
return failure("bananarchy-screen-wake.sh did not cancel the lock")
|
||||
if "bananarchy-idle-lock.sh cancel" not in UNLOCK_HOOK.read_text():
|
||||
return failure("sxmo_hook_unlock.sh does not cancel the pending lock")
|
||||
print("[ok] wake: screen-wake and unlock hook cancel the pending lock")
|
||||
run(LOCK, "cancel")
|
||||
print("idle blank screenlock wiring: all checks passed")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user