Fix idle-blank wake race and PIN-locked SIM DSDS provisioning

Two issues reported after the recovery image booted:

1. Pressing the power key turned the screen on and immediately back off.
   Root cause: U1 used sxmo_idle.sh + xprintidle, but dwm consumes keypad
   events at the evdev level before X sees them, so the X idle counter never
   reliably reset and the blank/resume commands raced. Replaced it with a
   dwm-native idle timer (src/sxmo-dwm/dwm.c): last_input_ms is updated from
   evdev and X key events, poll() is armed with the SXMO_UNLOCK_IDLE_TIME
   deadline (default 60 s), bananarchy-idle-blank.sh off fires once, and
   wake_phone() clears idle_blanked and resets the timer on the next real key.
   sxmo.noidle still disables it; idle_locker was removed from
   sxmo_hook_unlock.sh. Added a defensive wake-grace guard to
   bananarchy-idle-blank.sh and a /tmp/bananarchy_last_wake timestamp in
   sxmo_wm.sh display on so an already-flashed device is fixed too.

2. A PIN on one SIM prevented the other SIM from registering. provision_slot()
   tried to bind the preferred slot to primary-gw-provisioning even when its
   app was pin1/puk1 or PIN1 state enabled-not-verified, so no session came up
   and neither subscription registered. It now detects a locked preferred slot
   and falls back to the other ready slot for the primary GW; verify-pin/xmodem
   re-run boot after unlock and provision both slots normally.

Verified on the connected phone: all three deployed scripts pass sh -n, all
5 embedded Python heredocs parse, SIM status still reports both slots
registered, and off -> on -> immediate off leaves the screen on (grace guard).
Rebuilt dwm/plugins and images/bananarchy-nokia-argon.img with --mkinitfs;
boot.img still contains the known-good zImage + DTB byte-for-byte.
check-rebuild.sh passes and artifact drift is 0.

Docs: CHANGELOG.md, MANUAL.md, BATTERY-OPTIMIZATION-ANALYSIS.md (section 12).
This commit is contained in:
Bantam committed 2026-11-07 17:56:55 +02:00
1 parent 0dbb37fba3
commit 22d629f59b
10 files changed
+138 -12

No files matched your search

@@ -2,9 +2,28 @@
# Blank/restore the display without engaging the passcode locker (U1).
# sxmo_wm.sh display off/on already handles brightness, bl_power, DPMS,
# the CPU governor and the keyboard backlight.
#
# A wake-grace guard makes this safe even on the legacy sxmo_idle.sh path:
# xprintidle can report a stale large idle value right after a wake, which
# used to fire the blank command again immediately.
WAKE_TS=/tmp/bananarchy_last_wake
GRACE="${BANANARCHY_IDLE_BLANK_GRACE:-10}"
case "${1:-}" in
off) exec /usr/bin/sxmo_wm.sh display off ;;
on) exec /usr/bin/sxmo_wm.sh display on ;;
off)
now=$(date +%s)
last=0
[ -r "$WAKE_TS" ] && { read -r last < "$WAKE_TS" 2>/dev/null || last=0; }
case "$last" in ''|*[!0-9]*) last=0 ;; esac
if [ $((now - last)) -lt "$GRACE" ]; then
exit 0
fi
exec /usr/bin/sxmo_wm.sh display off
;;
on)
date +%s > "$WAKE_TS" 2>/dev/null || true
exec /usr/bin/sxmo_wm.sh display on
;;
*)
printf 'Usage: %s [off|on]\n' "${0##*/}" >&2
exit 1
Binary file not shown.
+3
View File
@@ -98,6 +98,9 @@ xorgdisplay() {
printf '%s\n' "${_restore_kbd:-255}" > /sys/class/leds/white:kbd_backlight/brightness 2>/dev/null || true
fi
doas -n /usr/bin/bananarchy-display-power-sync >/dev/null 2>&1 || true
# U1: record every wake so the idle-blank grace guard can suppress an
# immediate re-blank (also covers dwm's wake_phone() path).
date +%s > /tmp/bananarchy_last_wake 2>/dev/null || true
;;
"")
_cur_bl=14
@@ -505,6 +505,31 @@ provision_slot() {
eval "$(parse_uim_card_status "$QMI_CARDS" "$req_slot")"
# A PIN/PUK-locked SIM cannot be bound to a provisioning session yet.
# Prefer the other (ready) slot for the primary GW so the unlocked SIM
# still registers at boot instead of both subscriptions stalling.
# xmodem re-runs `boot` after the PIN is entered (verify-pin also calls
# provision_slot), at which point both slots are provisioned normally.
_pref_pin_locked=0
eval "_pref_app_state=\${SLOT${req_slot}_APP_STATE:-none}"
eval "_pref_pin_state=\${SLOT${req_slot}_PIN1_STATE:-not-initialized}"
case "$_pref_app_state" in
pin1|puk1|pin2|puk2|illegal|none) _pref_pin_locked=1 ;;
esac
case "$_pref_pin_state" in
enabled-not-verified|blocked|permanently-blocked) _pref_pin_locked=1 ;;
esac
if [ "$_pref_pin_locked" = "1" ]; then
_alt_slot=1
[ "$req_slot" = "1" ] && _alt_slot=2
eval "_alt_state=\${SLOT${_alt_slot}_STATE:-absent}"
eval "_alt_app_state=\${SLOT${_alt_slot}_APP_STATE:-none}"
if [ "$_alt_state" = "present" ] && [ "$_alt_app_state" = "ready" ]; then
echo "Slot $req_slot is PIN-locked; using ready slot $_alt_slot for primary GW"
req_slot="$_alt_slot"
fi
fi
chosen_slot=""
chosen_aid=""
if [ "$req_slot" = "2" ]; then
@@ -33,14 +33,10 @@ if [ -r /tmp/bananarchy_autosuspend.pid ]; then
rm -f /tmp/bananarchy_autosuspend.pid
fi
# U1: blank the display after an idle timeout without engaging the locker.
# Create ~/.cache/sxmo/sxmo.noidle to restore the old "never blank" policy.
if [ -e "$XDG_CACHE_HOME/sxmo/sxmo.noidle" ]; then
sxmo_jobs.sh stop idle_locker
else
sxmo_jobs.sh start idle_locker sxmo_idle.sh -w \
timeout "${SXMO_UNLOCK_IDLE_TIME:-60}" 'sh -c "/usr/bin/bananarchy-idle-blank.sh off"' \
resume 'sh -c "/usr/bin/bananarchy-idle-blank.sh on"'
fi
# U1: idle blanking is now driven by dwm's own evdev input timer, which
# resets on every real key press. sxmo_idle.sh/xprintidle raced with dwm's
# evdev handling and turned the screen back off immediately after a wake.
# Create ~/.cache/sxmo/sxmo.noidle to disable it entirely.
sxmo_jobs.sh stop idle_locker 2>/dev/null || true
wait