From 7dda5d81e376307ce945a3b5e874ad0aa640d441 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Tue, 27 Oct 2026 18:46:19 -0647 Subject: [PATCH 1/5] omamobile-shell 0.2.33: NFC polls only while the screen is lit A poll loop is the NFC radio searching for cards. On the Pixel 9a it costs about 60 mA with the screen off (252 mA against 315 mA, awake, 10-27), and stock Android polls only while the screen is on. omamobile-nfc-open now stops neard's poll loop once every display connector has been DPMS off for 4 s, and starts it again when the screen lights, unless the NFC switch is off. Tested on the 9a: no controller interrupts with the screen off, polling again within 2 s of it lighting. --- .../omamobile-shell/bin/omamobile-nfc-open | 65 +++++++++++++++++++ packages/omamobile-shell/test/all | 1 + packages/omamobile-shell/version | 2 +- 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/packages/omamobile-shell/bin/omamobile-nfc-open b/packages/omamobile-shell/bin/omamobile-nfc-open index 734ea024f..39d8eb2c0 100644 --- a/packages/omamobile-shell/bin/omamobile-nfc-open +++ b/packages/omamobile-shell/bin/omamobile-nfc-open @@ -15,6 +15,11 @@ told when the kernel blocks the radio, so on a block the adapter is powered off through neard (on a kernel that already did, neard's view stays stale), and on an unblock neard is restarted: it finds the adapter again, powers it (DefaultPowered), and a new poll loop starts. + +And it polls only while the screen is lit, as stock Android does: with every +display connector off (DPMS) for SCREEN_OFF_SECONDS, the poll loop stops, +and it starts again when the screen comes on. A poll loop is the radio +searching for cards, which costs the Pixel 9a about 60 mA. """ import glob import subprocess @@ -30,6 +35,7 @@ NEARD = "org.neard" RECORD = "org.neard.Record" ADAPTER = "org.neard.Adapter" REPEAT_SECONDS = 3.0 +SCREEN_OFF_SECONDS = 4 last = {"uri": None, "time": 0.0} @@ -141,6 +147,61 @@ def set_powered(bus, powered): rfkill = {"blocked": None} +screen = {"lit": True, "dark_for": 0} + + +def screen_lit(): + """True unless every connected display connector reports DPMS off.""" + states = [] + for path in glob.glob("/sys/class/drm/card*-*"): + try: + with open(f"{path}/status") as f: + if f.read().strip() != "connected": + continue + with open(f"{path}/dpms") as f: + states.append(f.read().strip()) + except OSError: + continue + return not states or any(state == "On" for state in states) + + +def stop_polling(bus): + try: + objects = bus.call_sync(NEARD, "/", "org.freedesktop.DBus.ObjectManager", + "GetManagedObjects", None, None, + Gio.DBusCallFlags.NONE, -1, None).unpack()[0] + except GLib.Error: + return + for path, interfaces in objects.items(): + adapter = interfaces.get(ADAPTER) + if adapter is None or not adapter.get("Polling"): + continue + try: + bus.call_sync(NEARD, path, ADAPTER, "StopPollLoop", None, None, + Gio.DBusCallFlags.NONE, -1, None) + log(f"screen off: polling stopped on {path}") + except GLib.Error as error: + log(f"could not stop polling on {path}: {error.message}") + + +def follow_screen(bus): + """Every 2 s: stop the poll loop once the screen has been off for a while, + start it again when the screen lights (unless NFC is switched off).""" + lit = screen_lit() + if lit: + screen["dark_for"] = 0 + if not screen["lit"]: + screen["lit"] = True + if not rfkill["blocked"]: + log("screen on: polling again") + start_polling(bus) + return True + screen["dark_for"] += 2 + if screen["lit"] and screen["dark_for"] >= SCREEN_OFF_SECONDS: + screen["lit"] = False + if not rfkill["blocked"]: + stop_polling(bus) + return True def follow_rfkill(bus): @@ -154,6 +215,9 @@ def follow_rfkill(bus): elif previous is not None: log("NFC switched on: restarting neard") restart_neard(bus) + if not screen["lit"]: + # neard powers the adapter and polls by itself: stop it again + GLib.timeout_add_seconds(4, lambda: stop_polling(bus) or False) return True @@ -172,6 +236,7 @@ def main(): # earlier run of it): start from a fresh neard. restart_neard(bus) GLib.timeout_add_seconds(2, follow_rfkill, bus) + GLib.timeout_add_seconds(2, follow_screen, bus) GLib.MainLoop().run() diff --git a/packages/omamobile-shell/test/all b/packages/omamobile-shell/test/all index 37dc8b355..b202a8128 100755 --- a/packages/omamobile-shell/test/all +++ b/packages/omamobile-shell/test/all @@ -376,6 +376,7 @@ grep -c 'Quickshell.execDetached(HomeModel.urlLaunchArgv(text))' plugins/omamobi grep -c 'HomeModel.commandLaunchArgv(\["sh", "-c", tap\])' plugins/omamobile.home/CommandWidget.qml >/dev/null || fail "the text widget's tap goes through omamobile-launch" grep -c '"omamobile-launch", "url", uri' bin/omamobile-nfc-open >/dev/null || fail "NFC links open through omamobile-launch" grep -c 'GLib.timeout_add_seconds(2, follow_rfkill, bus)' bin/omamobile-nfc-open >/dev/null || fail "the NFC service follows the rfkill switch" +grep -c 'GLib.timeout_add_seconds(2, follow_screen, bus)' bin/omamobile-nfc-open >/dev/null || fail "the NFC service stops polling with the screen off" grep -c '"systemctl", "restart", "neard"' bin/omamobile-nfc-open >/dev/null || fail "an NFC unblock restarts neard" grep -c '^Requires=neard' systemd/omamobile-nfc-open.service >/dev/null && fail "omamobile-nfc-open restarts neard, so it must not Require= it (the restart would loop)" grep -c '"omamobile-launch", "empty"' bin/omamobile-widget >/dev/null || fail "the widget agent's terminal gets an empty workspace" diff --git a/packages/omamobile-shell/version b/packages/omamobile-shell/version index a8498651b..d9955e456 100644 --- a/packages/omamobile-shell/version +++ b/packages/omamobile-shell/version @@ -1 +1 @@ -0.2.32 +0.2.33 From 24d50df330627046e8f239fd04d1c1983c94dae2 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Wed, 28 Oct 2026 07:47:19 -0647 Subject: [PATCH 2/5] omamobile-shell 0.2.33: the screen-off stop holds while the screen stays dark The stop was a single shot on the lit-to-dark transition, so anything that started polling afterwards kept it on until the next screen cycle: the unblock path's start_polling retries, the 9a's sleep hook after a wake, or neard restarted by systemd. Now every 2 s check stops any poll loop once the screen has been dark for 4 s, and start_polling powers the adapter but leaves the loop off while it's dark. The one-shot stop after an unblock is gone. test/nfc-screen.py checks screen_lit() against temporary sysfs trees. --- .../omamobile-shell/bin/omamobile-nfc-open | 19 ++++++------ packages/omamobile-shell/test/all | 3 ++ packages/omamobile-shell/test/nfc-screen.py | 31 +++++++++++++++++++ 3 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 packages/omamobile-shell/test/nfc-screen.py diff --git a/packages/omamobile-shell/bin/omamobile-nfc-open b/packages/omamobile-shell/bin/omamobile-nfc-open index 39d8eb2c0..193f9ee4a 100644 --- a/packages/omamobile-shell/bin/omamobile-nfc-open +++ b/packages/omamobile-shell/bin/omamobile-nfc-open @@ -102,7 +102,9 @@ def start_polling(bus): bus.call_sync(NEARD, path, "org.freedesktop.DBus.Properties", "Set", GLib.Variant("(ssv)", (ADAPTER, "Powered", GLib.Variant("b", True))), None, Gio.DBusCallFlags.NONE, -1, None) - if not adapter.get("Polling"): + if not adapter.get("Polling") and not screen["lit"]: + log(f"screen off: {path} powered, polling waits for the screen") + elif not adapter.get("Polling"): try: bus.call_sync(NEARD, path, ADAPTER, "StartPollLoop", GLib.Variant("(s)", ("Initiator",)), None, @@ -150,10 +152,10 @@ rfkill = {"blocked": None} screen = {"lit": True, "dark_for": 0} -def screen_lit(): +def screen_lit(drm="/sys/class/drm"): """True unless every connected display connector reports DPMS off.""" states = [] - for path in glob.glob("/sys/class/drm/card*-*"): + for path in glob.glob(f"{drm}/card*-*"): try: with open(f"{path}/status") as f: if f.read().strip() != "connected": @@ -185,8 +187,10 @@ def stop_polling(bus): def follow_screen(bus): - """Every 2 s: stop the poll loop once the screen has been off for a while, - start it again when the screen lights (unless NFC is switched off).""" + """Every 2 s: once the screen has been off for a while, stop any poll loop + (each time, so one that neard, a restart or the sleep hook started while + the screen was dark stops too); start it again when the screen lights + (unless NFC is switched off).""" lit = screen_lit() if lit: screen["dark_for"] = 0 @@ -197,7 +201,7 @@ def follow_screen(bus): start_polling(bus) return True screen["dark_for"] += 2 - if screen["lit"] and screen["dark_for"] >= SCREEN_OFF_SECONDS: + if screen["dark_for"] >= SCREEN_OFF_SECONDS: screen["lit"] = False if not rfkill["blocked"]: stop_polling(bus) @@ -215,9 +219,6 @@ def follow_rfkill(bus): elif previous is not None: log("NFC switched on: restarting neard") restart_neard(bus) - if not screen["lit"]: - # neard powers the adapter and polls by itself: stop it again - GLib.timeout_add_seconds(4, lambda: stop_polling(bus) or False) return True diff --git a/packages/omamobile-shell/test/all b/packages/omamobile-shell/test/all index b202a8128..64beb8250 100755 --- a/packages/omamobile-shell/test/all +++ b/packages/omamobile-shell/test/all @@ -377,6 +377,9 @@ grep -c 'HomeModel.commandLaunchArgv(\["sh", "-c", tap\])' plugins/omamobile.hom grep -c '"omamobile-launch", "url", uri' bin/omamobile-nfc-open >/dev/null || fail "NFC links open through omamobile-launch" grep -c 'GLib.timeout_add_seconds(2, follow_rfkill, bus)' bin/omamobile-nfc-open >/dev/null || fail "the NFC service follows the rfkill switch" grep -c 'GLib.timeout_add_seconds(2, follow_screen, bus)' bin/omamobile-nfc-open >/dev/null || fail "the NFC service stops polling with the screen off" +python3 -B test/nfc-screen.py >/dev/null || { python3 -B test/nfc-screen.py | grep -v '^ok'; fail "screen_lit reads the connectors"; } +grep -c 'polling waits for the screen' bin/omamobile-nfc-open >/dev/null || fail "start_polling leaves the loop off while the screen is dark" +grep -c 'timeout_add_seconds(4' bin/omamobile-nfc-open >/dev/null && fail "the one-shot stop is gone: the screen check stops polling every time" grep -c '"systemctl", "restart", "neard"' bin/omamobile-nfc-open >/dev/null || fail "an NFC unblock restarts neard" grep -c '^Requires=neard' systemd/omamobile-nfc-open.service >/dev/null && fail "omamobile-nfc-open restarts neard, so it must not Require= it (the restart would loop)" grep -c '"omamobile-launch", "empty"' bin/omamobile-widget >/dev/null || fail "the widget agent's terminal gets an empty workspace" diff --git a/packages/omamobile-shell/test/nfc-screen.py b/packages/omamobile-shell/test/nfc-screen.py new file mode 100644 index 000000000..0c0f63010 --- /dev/null +++ b/packages/omamobile-shell/test/nfc-screen.py @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: MIT +# omamobile-nfc-open's screen_lit() against temporary sysfs trees: connected +# and disconnected connectors, DPMS On and Off, and no connectors at all. +import importlib.machinery, importlib.util, os, sys, tempfile, types +sys.dont_write_bytecode = True # never a __pycache__ next to bin/omamobile-nfc-open + +gi = types.ModuleType("gi"); gi.require_version = lambda *a: None +repo = types.ModuleType("gi.repository"); repo.Gio = repo.GLib = types.SimpleNamespace() +sys.modules.update({"gi": gi, "gi.repository": repo}) +loader = importlib.machinery.SourceFileLoader("nfc_open", os.path.join(os.path.dirname(__file__), "..", "bin", "omamobile-nfc-open")) +nfc = importlib.util.module_from_spec(importlib.util.spec_from_loader("nfc_open", loader)); loader.exec_module(nfc) + +fails = 0 +def case(name, connectors, want): + global fails + with tempfile.TemporaryDirectory() as drm: + for conn, (status, dpms) in connectors.items(): + os.makedirs(f"{drm}/{conn}") + open(f"{drm}/{conn}/status", "w").write(status + "\n") + open(f"{drm}/{conn}/dpms", "w").write(dpms + "\n") + got = nfc.screen_lit(drm) + print(("ok" if got == want else "not ok") + f" - {name}") + fails += got != want + +case("panel on", {"card1-DSI-1": ("connected", "On")}, True) +case("panel off", {"card1-DSI-1": ("connected", "Off")}, False) +case("panel off, a disconnected output on", {"card1-DSI-1": ("connected", "Off"), "card1-DP-1": ("disconnected", "On")}, False) +case("two connected, one on", {"card1-DSI-1": ("connected", "Off"), "card1-HDMI-A-1": ("connected", "On")}, True) +case("only a disconnected output", {"card1-DP-1": ("disconnected", "Off")}, True) +case("no connectors at all", {}, True) +sys.exit(1 if fails else 0) From b24a2b3b288cecbe5f126e9991dd5a4db18d212f Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Wed, 28 Oct 2026 13:03:57 -0647 Subject: [PATCH 3/5] omamobile-shell 0.2.33: a failed power-on in start_polling is logged, not raised start_polling runs from follow_screen's GLib timeout since the screen-off change, and a timeout callback that raises is removed by GLib for good. Wrap the adapter's Powered Set in try/except GLib.Error, log it and retry on the next tick, as set_powered does. --- packages/omamobile-shell/bin/omamobile-nfc-open | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/omamobile-shell/bin/omamobile-nfc-open b/packages/omamobile-shell/bin/omamobile-nfc-open index 193f9ee4a..e6f861234 100644 --- a/packages/omamobile-shell/bin/omamobile-nfc-open +++ b/packages/omamobile-shell/bin/omamobile-nfc-open @@ -99,9 +99,15 @@ def start_polling(bus): if adapter is None: continue if not adapter.get("Powered"): - bus.call_sync(NEARD, path, "org.freedesktop.DBus.Properties", "Set", - GLib.Variant("(ssv)", (ADAPTER, "Powered", GLib.Variant("b", True))), - None, Gio.DBusCallFlags.NONE, -1, None) + # This runs from GLib timeouts too: an exception would remove the + # timer for good, so a failed power-on is logged and retried. + try: + bus.call_sync(NEARD, path, "org.freedesktop.DBus.Properties", "Set", + GLib.Variant("(ssv)", (ADAPTER, "Powered", GLib.Variant("b", True))), + None, Gio.DBusCallFlags.NONE, -1, None) + except GLib.Error as error: + log(f"{path}: Powered=True: {error.message}") + return True if not adapter.get("Polling") and not screen["lit"]: log(f"screen off: {path} powered, polling waits for the screen") elif not adapter.get("Polling"): From 56d6005980780330df709ac68168e28b050a6552 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Wed, 28 Oct 2026 15:37:28 -0647 Subject: [PATCH 4/5] omamobile-shell 0.2.33: screen-on keeps trying the power-on until it works or NFC is switched off --- packages/omamobile-shell/bin/omamobile-nfc-open | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/omamobile-shell/bin/omamobile-nfc-open b/packages/omamobile-shell/bin/omamobile-nfc-open index e6f861234..cd9311e03 100644 --- a/packages/omamobile-shell/bin/omamobile-nfc-open +++ b/packages/omamobile-shell/bin/omamobile-nfc-open @@ -86,7 +86,10 @@ def on_interfaces_added(_conn, _sender, _path, _iface, _signal, params, _data): def start_polling(bus): """Power the first adapter and start a poll loop (neard's ConstantPoll - keeps it going after each tag).""" + keeps it going after each tag). True means "try again": neard isn't + answering, has no adapter yet, or refused the power-on.""" + if rfkill["blocked"]: + return False # switched off meanwhile; the next unblock restarts neard try: objects = bus.call_sync(NEARD, "/", "org.freedesktop.DBus.ObjectManager", "GetManagedObjects", None, None, @@ -155,7 +158,7 @@ def set_powered(bus, powered): rfkill = {"blocked": None} -screen = {"lit": True, "dark_for": 0} +screen = {"lit": True, "dark_for": 0, "start": False} def screen_lit(drm="/sys/class/drm"): @@ -202,9 +205,11 @@ def follow_screen(bus): screen["dark_for"] = 0 if not screen["lit"]: screen["lit"] = True - if not rfkill["blocked"]: + screen["start"] = not rfkill["blocked"] + if screen["start"]: log("screen on: polling again") - start_polling(bus) + if screen["start"]: + screen["start"] = start_polling(bus) return True screen["dark_for"] += 2 if screen["dark_for"] >= SCREEN_OFF_SECONDS: From 025f08d02f1dab878306873720e5324ff7df2f0e Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Sat, 31 Oct 2026 11:12:45 -0400 Subject: [PATCH 5/5] omamobile-shell 0.2.48: the NFC poll loop runs only while the screen is lit Restores this pull request's change: the merge at b3ceaf1 resolved to main's tree and dropped it. 0.2.46 and 0.2.47 are held by #183 and #197. Co-Authored-By: Claude Opus 5.5 --- .../omamobile-shell/bin/omamobile-nfc-open | 87 +++++++++++++++++-- packages/omamobile-shell/test/all | 4 + packages/omamobile-shell/test/nfc-screen.py | 31 +++++++ packages/omamobile-shell/version | 2 +- 4 files changed, 118 insertions(+), 6 deletions(-) create mode 100644 packages/omamobile-shell/test/nfc-screen.py diff --git a/packages/omamobile-shell/bin/omamobile-nfc-open b/packages/omamobile-shell/bin/omamobile-nfc-open index 734ea024f..cd9311e03 100644 --- a/packages/omamobile-shell/bin/omamobile-nfc-open +++ b/packages/omamobile-shell/bin/omamobile-nfc-open @@ -15,6 +15,11 @@ told when the kernel blocks the radio, so on a block the adapter is powered off through neard (on a kernel that already did, neard's view stays stale), and on an unblock neard is restarted: it finds the adapter again, powers it (DefaultPowered), and a new poll loop starts. + +And it polls only while the screen is lit, as stock Android does: with every +display connector off (DPMS) for SCREEN_OFF_SECONDS, the poll loop stops, +and it starts again when the screen comes on. A poll loop is the radio +searching for cards, which costs the Pixel 9a about 60 mA. """ import glob import subprocess @@ -30,6 +35,7 @@ NEARD = "org.neard" RECORD = "org.neard.Record" ADAPTER = "org.neard.Adapter" REPEAT_SECONDS = 3.0 +SCREEN_OFF_SECONDS = 4 last = {"uri": None, "time": 0.0} @@ -80,7 +86,10 @@ def on_interfaces_added(_conn, _sender, _path, _iface, _signal, params, _data): def start_polling(bus): """Power the first adapter and start a poll loop (neard's ConstantPoll - keeps it going after each tag).""" + keeps it going after each tag). True means "try again": neard isn't + answering, has no adapter yet, or refused the power-on.""" + if rfkill["blocked"]: + return False # switched off meanwhile; the next unblock restarts neard try: objects = bus.call_sync(NEARD, "/", "org.freedesktop.DBus.ObjectManager", "GetManagedObjects", None, None, @@ -93,10 +102,18 @@ def start_polling(bus): if adapter is None: continue if not adapter.get("Powered"): - bus.call_sync(NEARD, path, "org.freedesktop.DBus.Properties", "Set", - GLib.Variant("(ssv)", (ADAPTER, "Powered", GLib.Variant("b", True))), - None, Gio.DBusCallFlags.NONE, -1, None) - if not adapter.get("Polling"): + # This runs from GLib timeouts too: an exception would remove the + # timer for good, so a failed power-on is logged and retried. + try: + bus.call_sync(NEARD, path, "org.freedesktop.DBus.Properties", "Set", + GLib.Variant("(ssv)", (ADAPTER, "Powered", GLib.Variant("b", True))), + None, Gio.DBusCallFlags.NONE, -1, None) + except GLib.Error as error: + log(f"{path}: Powered=True: {error.message}") + return True + if not adapter.get("Polling") and not screen["lit"]: + log(f"screen off: {path} powered, polling waits for the screen") + elif not adapter.get("Polling"): try: bus.call_sync(NEARD, path, ADAPTER, "StartPollLoop", GLib.Variant("(s)", ("Initiator",)), None, @@ -141,6 +158,65 @@ def set_powered(bus, powered): rfkill = {"blocked": None} +screen = {"lit": True, "dark_for": 0, "start": False} + + +def screen_lit(drm="/sys/class/drm"): + """True unless every connected display connector reports DPMS off.""" + states = [] + for path in glob.glob(f"{drm}/card*-*"): + try: + with open(f"{path}/status") as f: + if f.read().strip() != "connected": + continue + with open(f"{path}/dpms") as f: + states.append(f.read().strip()) + except OSError: + continue + return not states or any(state == "On" for state in states) + + +def stop_polling(bus): + try: + objects = bus.call_sync(NEARD, "/", "org.freedesktop.DBus.ObjectManager", + "GetManagedObjects", None, None, + Gio.DBusCallFlags.NONE, -1, None).unpack()[0] + except GLib.Error: + return + for path, interfaces in objects.items(): + adapter = interfaces.get(ADAPTER) + if adapter is None or not adapter.get("Polling"): + continue + try: + bus.call_sync(NEARD, path, ADAPTER, "StopPollLoop", None, None, + Gio.DBusCallFlags.NONE, -1, None) + log(f"screen off: polling stopped on {path}") + except GLib.Error as error: + log(f"could not stop polling on {path}: {error.message}") + + +def follow_screen(bus): + """Every 2 s: once the screen has been off for a while, stop any poll loop + (each time, so one that neard, a restart or the sleep hook started while + the screen was dark stops too); start it again when the screen lights + (unless NFC is switched off).""" + lit = screen_lit() + if lit: + screen["dark_for"] = 0 + if not screen["lit"]: + screen["lit"] = True + screen["start"] = not rfkill["blocked"] + if screen["start"]: + log("screen on: polling again") + if screen["start"]: + screen["start"] = start_polling(bus) + return True + screen["dark_for"] += 2 + if screen["dark_for"] >= SCREEN_OFF_SECONDS: + screen["lit"] = False + if not rfkill["blocked"]: + stop_polling(bus) + return True def follow_rfkill(bus): @@ -172,6 +248,7 @@ def main(): # earlier run of it): start from a fresh neard. restart_neard(bus) GLib.timeout_add_seconds(2, follow_rfkill, bus) + GLib.timeout_add_seconds(2, follow_screen, bus) GLib.MainLoop().run() diff --git a/packages/omamobile-shell/test/all b/packages/omamobile-shell/test/all index bc9f6533a..b0253eb06 100755 --- a/packages/omamobile-shell/test/all +++ b/packages/omamobile-shell/test/all @@ -469,6 +469,10 @@ grep -c 'Quickshell.execDetached(HomeModel.urlLaunchArgv(text))' plugins/omamobi grep -c 'HomeModel.commandLaunchArgv(\["sh", "-c", tap\])' plugins/omamobile.home/CommandWidget.qml >/dev/null || fail "the text widget's tap goes through omamobile-launch" grep -c '"omamobile-launch", "url", uri' bin/omamobile-nfc-open >/dev/null || fail "NFC links open through omamobile-launch" grep -c 'GLib.timeout_add_seconds(2, follow_rfkill, bus)' bin/omamobile-nfc-open >/dev/null || fail "the NFC service follows the rfkill switch" +grep -c 'GLib.timeout_add_seconds(2, follow_screen, bus)' bin/omamobile-nfc-open >/dev/null || fail "the NFC service stops polling with the screen off" +python3 -B test/nfc-screen.py >/dev/null || { python3 -B test/nfc-screen.py | grep -v '^ok'; fail "screen_lit reads the connectors"; } +grep -c 'polling waits for the screen' bin/omamobile-nfc-open >/dev/null || fail "start_polling leaves the loop off while the screen is dark" +grep -c 'timeout_add_seconds(4' bin/omamobile-nfc-open >/dev/null && fail "the one-shot stop is gone: the screen check stops polling every time" grep -c '"systemctl", "restart", "neard"' bin/omamobile-nfc-open >/dev/null || fail "an NFC unblock restarts neard" grep -c '^Requires=neard' systemd/omamobile-nfc-open.service >/dev/null && fail "omamobile-nfc-open restarts neard, so it must not Require= it (the restart would loop)" grep -c '"omamobile-launch", "empty"' bin/omamobile-widget >/dev/null || fail "the widget agent's terminal gets an empty workspace" diff --git a/packages/omamobile-shell/test/nfc-screen.py b/packages/omamobile-shell/test/nfc-screen.py new file mode 100644 index 000000000..0c0f63010 --- /dev/null +++ b/packages/omamobile-shell/test/nfc-screen.py @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: MIT +# omamobile-nfc-open's screen_lit() against temporary sysfs trees: connected +# and disconnected connectors, DPMS On and Off, and no connectors at all. +import importlib.machinery, importlib.util, os, sys, tempfile, types +sys.dont_write_bytecode = True # never a __pycache__ next to bin/omamobile-nfc-open + +gi = types.ModuleType("gi"); gi.require_version = lambda *a: None +repo = types.ModuleType("gi.repository"); repo.Gio = repo.GLib = types.SimpleNamespace() +sys.modules.update({"gi": gi, "gi.repository": repo}) +loader = importlib.machinery.SourceFileLoader("nfc_open", os.path.join(os.path.dirname(__file__), "..", "bin", "omamobile-nfc-open")) +nfc = importlib.util.module_from_spec(importlib.util.spec_from_loader("nfc_open", loader)); loader.exec_module(nfc) + +fails = 0 +def case(name, connectors, want): + global fails + with tempfile.TemporaryDirectory() as drm: + for conn, (status, dpms) in connectors.items(): + os.makedirs(f"{drm}/{conn}") + open(f"{drm}/{conn}/status", "w").write(status + "\n") + open(f"{drm}/{conn}/dpms", "w").write(dpms + "\n") + got = nfc.screen_lit(drm) + print(("ok" if got == want else "not ok") + f" - {name}") + fails += got != want + +case("panel on", {"card1-DSI-1": ("connected", "On")}, True) +case("panel off", {"card1-DSI-1": ("connected", "Off")}, False) +case("panel off, a disconnected output on", {"card1-DSI-1": ("connected", "Off"), "card1-DP-1": ("disconnected", "On")}, False) +case("two connected, one on", {"card1-DSI-1": ("connected", "Off"), "card1-HDMI-A-1": ("connected", "On")}, True) +case("only a disconnected output", {"card1-DP-1": ("disconnected", "Off")}, True) +case("no connectors at all", {}, True) +sys.exit(1 if fails else 0) diff --git a/packages/omamobile-shell/version b/packages/omamobile-shell/version index 16c9e92a2..16eb842d8 100644 --- a/packages/omamobile-shell/version +++ b/packages/omamobile-shell/version @@ -1 +1 @@ -0.2.45 +0.2.48