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

+12
View File
@@ -405,3 +405,15 @@ a kernel with the original ABI and accepting that those config-level savings are
Kept because they do not depend on the kernel config: K2 (`clock-latency-ns` in the DTB),
K3/K4/K5 (patch 0006, rebuilt with the original config), K10 (IPv6 sysctl), and all U1-U14
userspace changes. Deep standby (U2) stays disabled and inert.
---
## 12. Post-flash fixes (after the recovery image booted)
- **U1 idle blank wake race**: replaced the `sxmo_idle.sh`/`xprintidle` job with
a dwm-native idle timer (`src/sxmo-dwm/dwm.c`), because dwm consumes evdev key
events before X sees them. `wake_phone()` now resets the timer, so pressing the
power key can no longer turn the screen on and immediately back off.
- **DSDS with a PIN-locked SIM**: `provision_slot()` now prefers the ready slot
for `primary-gw-provisioning` when the preferred slot is `pin1`/`puk1`, so the
unlocked SIM registers at boot. `verify-pin` re-runs `boot` after unlock.
+28
View File
@@ -9,6 +9,34 @@ Release versions follow the `<year-letter><MM><DD>` format (where `2026` is `a`,
---
## Unreleased — idle-blank wake fix and PIN-locked SIM provisioning
Two issues reported after the recovery image booted:
- **Idle blank turned the screen back off immediately after a wake (U1)**:
`sxmo_hook_unlock.sh` 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. Idle blanking is
now driven by dwm's own input timer: `src/sxmo-dwm/dwm.c` tracks
`last_input_ms` from evdev and X key events, arms `poll()` with the
`SXMO_UNLOCK_IDLE_TIME` deadline (default 60 s), calls
`bananarchy-idle-blank.sh off` once, and `wake_phone()` clears the flag and
resets the timer on the next real key press. `sxmo.noidle` still disables it.
The `idle_locker` job was removed from `sxmo_hook_unlock.sh`. A defensive
wake-grace guard was also added to `bananarchy-idle-blank.sh` (and
`sxmo_wm.sh display on` records `/tmp/bananarchy_last_wake`) so the
legacy path cannot re-blank within 10 s of a wake on an already-flashed
device. Verified live: `off -> on -> immediate off` leaves the screen on.
- **PIN on one SIM prevented the other SIM from registering (DSDS)**:
`msm-modem-uim-selection provision_slot` tried to bind the preferred slot to
`primary-gw-provisioning` even when its application was `pin1`/`puk1` (or
`PIN1 state: enabled-not-verified`), so no provisioning 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; after the PIN is
entered `xmodem`/`verify-pin` re-runs `boot` and both slots are provisioned.
---
## Unreleased — recovery: restore the known-good kernel (module ABI)
**The previous battery pass produced an unbootable image.** Two independent incompatibilities
+1 -1
View File
@@ -101,7 +101,7 @@ sudo dd if=./images/bananarchy-nokia-argon.img of=/dev/sdX bs=4M status=progress
| **Slider close / open** | `SW_LID` (`lid:on` / `lid:off`) | **Close**: close open menu, turn off keypad backlight, and lock phone with passcode (`xlocker`); **Open**: restore screen and keypad backlight and show passcode lock screen |
> **Screen blanking, idle blanking, deep standby, passcode locking (`xlocker`), waking, and brightness persistence**:
> While unlocked, the display now blanks automatically after `SXMO_UNLOCK_IDLE_TIME` seconds of inactivity (60 by default) via `bananarchy-idle-blank.sh`; any keypad, lid or power key restores it immediately without engaging the passcode locker. Create `~/.cache/sxmo/sxmo.noidle` to restore the old "unlocked screen never blanks" policy. X11 screensaver timeouts stay at `0 0 0`; DPMS is driven by the backlight state. Optional **deep standby** is currently **unavailable**: the shipped kernel keeps the pmaports module ABI and has no sleep states in `/sys/power/state`. It stays disabled via `/etc/bananarchy-no-deep-standby`; enabling it requires a full custom kernel module tree (see `BATTERY-OPTIMIZATION-ANALYSIS.md`). Active calls, SSH sessions and VPN/tether connections would block suspension. Locking the phone (`Power -> Lock`, `Power -> Lock (Screen off)`, `2x End / Power`, or closing the physical slider) activates the fullscreen `240x320` **Passcode Locker (`xlocker` / `locker.so`)**, which verifies your numeric system password (`147147` by default, checked against `/etc/shadow` via `/usr/bin/bananarchy-verify-passcode`). While locked, there is no keypad, softkey, slider, or power-button bypass (`dmenu`, `xdrawer`, terminal spawning, and desktop shortcuts are blocked, and only incoming calls can temporarily overlay `xcallscreen`). Screen and keypad brightness levels configured in **XDrawer** or **Config -> Brightness** are persisted in `~/.config/sxmo/brightness` and `/tmp/sxmo_saved_brightness` and restored on every wake.
> While unlocked, the display now blanks automatically after `SXMO_UNLOCK_IDLE_TIME` seconds of inactivity (60 by default) via `dwm`'s own evdev input timer and `bananarchy-idle-blank.sh`; any keypad, lid or power key restores it immediately without engaging the passcode locker (the timer resets on the wake key, so it cannot blank again right away). Create `~/.cache/sxmo/sxmo.noidle` to restore the old "unlocked screen never blanks" policy. X11 screensaver timeouts stay at `0 0 0`; DPMS is driven by the backlight state. Optional **deep standby** is currently **unavailable**: the shipped kernel keeps the pmaports module ABI and has no sleep states in `/sys/power/state`. It stays disabled via `/etc/bananarchy-no-deep-standby`; enabling it requires a full custom kernel module tree (see `BATTERY-OPTIMIZATION-ANALYSIS.md`). Active calls, SSH sessions and VPN/tether connections would block suspension. Locking the phone (`Power -> Lock`, `Power -> Lock (Screen off)`, `2x End / Power`, or closing the physical slider) activates the fullscreen `240x320` **Passcode Locker (`xlocker` / `locker.so`)**, which verifies your numeric system password (`147147` by default, checked against `/etc/shadow` via `/usr/bin/bananarchy-verify-passcode`). While locked, there is no keypad, softkey, slider, or power-button bypass (`dmenu`, `xdrawer`, terminal spawning, and desktop shortcuts are blocked, and only incoming calls can temporarily overlay `xcallscreen`). Screen and keypad brightness levels configured in **XDrawer** or **Config -> Brightness** are persisted in `~/.config/sxmo/brightness` and `/tmp/sxmo_saved_brightness` and restored on every wake.
#### 3.1.1 Window tiling modes and switching combos
By default, `dwm` uses the **vertical bottom-stack (`bstack`, `TTT`)** layout so multiple `st` terminals stack **vertically (one under another)** to preserve full line width on the `240x320` portrait screen.
@@ -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
Binary file not shown.
+43
View File
@@ -336,6 +336,14 @@ static struct HoldKey *holdkeyroot = NULL;
static int input_fds[MAX_INPUT_FDS];
static int num_input_fds = 0;
static long long last_wake_ms = 0;
/* U1: dwm-native idle blanking. The sxmo_idle.sh/xprintidle path races
* with evdev input because dwm consumes key events before X sees them,
* which made the screen turn back off immediately after a wake. */
static long long last_input_ms = 0;
static int idle_blank_secs = 60;
static int idle_blank_enabled = 1;
static int idle_blanked = 0;
static int idle_cfg_loaded = 0;
static int star_down = 0;
static int pound_down = 0;
static long long last_screenshot_ms = 0;
@@ -2497,6 +2505,8 @@ wake_phone(void)
lid_close_pending = 0;
lid_close_deadline_ms = 0;
last_wake_ms = now;
last_input_ms = now;
idle_blanked = 0;
softkey_pending = 0;
softkey_first_ms = 0;
softkey_deadline_ms = 0;
@@ -2529,6 +2539,7 @@ keypress(XEvent *e)
XKeyEvent *ev;
ev = &e->xkey;
last_input_ms = dwm_now_ms();
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
dwm_sync_mouse_cursor();
if (!dwm_has_external_mouse() && cursor_hidden == 0 && (dwm_now_ms() - last_mouse_ms) > 4000)
@@ -3125,6 +3136,18 @@ run(void)
/* main event loop */
XSync(dpy, False);
if (!idle_cfg_loaded) {
const char *env = getenv("SXMO_UNLOCK_IDLE_TIME");
char noidle[256];
idle_cfg_loaded = 1;
if (env && atoi(env) > 0)
idle_blank_secs = atoi(env);
snprintf(noidle, sizeof(noidle), "%s/.cache/sxmo/sxmo.noidle",
getenv("HOME") ? getenv("HOME") : "/home/user");
if (access(noidle, F_OK) == 0)
idle_blank_enabled = 0;
last_input_ms = dwm_now_ms();
}
xfd = ConnectionNumber(dpy);
while (running) {
while (XPending(dpy)) {
@@ -3197,11 +3220,30 @@ run(void)
timeout_ms = (int)rem;
}
}
/* U1: arm the poll timeout for the idle-blank deadline. */
if (idle_blank_enabled && idle_blank_secs > 0 && !idle_blanked &&
!is_screen_off() && !is_passcode_locked() && !is_phone_locked()) {
long long now = dwm_now_ms();
long long rem = (long long)idle_blank_secs * 1000LL - (now - last_input_ms);
if (rem < 50)
rem = 50;
if (timeout_ms < 0 || rem < timeout_ms)
timeout_ms = (int)rem;
}
if (poll(fds, nfds, timeout_ms) < 0) {
if (errno == EINTR)
continue;
break;
}
/* U1: blank only after a genuine period with no keypad/X input.
* wake_phone() clears idle_blanked on the next key press. */
if (idle_blank_enabled && idle_blank_secs > 0 && !idle_blanked &&
!is_screen_off() && !is_passcode_locked() && !is_phone_locked() &&
(dwm_now_ms() - last_input_ms) >= (long long)idle_blank_secs * 1000LL) {
const Arg blankcmd = SHCMD("bananarchy-idle-blank.sh off");
idle_blanked = 1;
spawn(&blankcmd);
}
for (i = 0; i < num_input_fds; i++) {
if (fds[1 + i].revents & (POLLHUP | POLLERR | POLLNVAL)) {
dwm_rescan_input_fds(1);
@@ -3210,6 +3252,7 @@ run(void)
}
if (fds[1 + i].revents & POLLIN) {
ssize_t nread;
last_input_ms = dwm_now_ms();
while ((nread = read(input_fds[i], &ie, sizeof(ie))) == (ssize_t)sizeof(ie)) {
if (ie.type == EV_SW && ie.code == SW_LID) {
if (ie.value == 1) {