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

+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) {