Fix GPS modem selection and add a GPS-only time source

This commit is contained in:
Luxferre committed 2026-11-10 13:18:14 +02:00
1 parent eaf08abcd4
commit a50c01b416
18 files changed
+682 -16

No files matched your search

+2 -2
View File
@@ -57,7 +57,7 @@ All cross-compilation scripts run inside rootless Docker (`alpine:3.24` `armv7`
- `./scripts/prune-rootfs-packages.sh <rootfs-dir> world|purge` — removes Wayland-only, Rust-based, and retired packages from a target rootfs inside the build container.
- `./scripts/build-bananarchy-daemons.sh` — cross-builds the three compiled ARM idle daemons (`bananarchy-lid`, `bananarchy-cover-idle`, `bananarchy-volume-keys`) from `src/bananarchy-daemons/`; `--check` validates the ARM ELF artifacts and overlay sync. No Python-based daemon runs in the idle system.
- `./scripts/build-lk2nd-beatles.sh` — cross-builds all three beatles lk2nd images (normal, diagnostic and display; the display image is the flasher default) from the pinned upstream lk2nd commit plus `bootloader/lk2nd/nokia-beatles.patch` in rootless Docker (`--check` validates all three shipped images, `--only normal|diagnostic|display` builds one, `--force-panel-init` forces the panel replay, `--with-display` enables SPI display during boot). Offline validators: `scripts/check-lk2nd-beatles.py` and `scripts/test-lk2nd-beatles-port.py`.
- `./scripts/test-webarchy-renderer.py`, `./scripts/test-idle-blank-lock.py`, `./scripts/test-bluetooth-scan.py` and `./scripts/test-battery-charge-event.py` — host unit/integration tests for the Webarchy renderer profile, the idle-blank screenlock wiring, the Bluetooth discovery parser and the charger plug/unplug icon refresh (all also run by `check-rebuild.sh`).
- `./scripts/test-webarchy-renderer.py`, `./scripts/test-idle-blank-lock.py`, `./scripts/test-bluetooth-scan.py`, `./scripts/test-battery-charge-event.py` and `./scripts/test-gps-time-sync.py` — host unit/integration tests for the Webarchy renderer profile, the idle-blank screenlock wiring, the Bluetooth discovery parser, the charger plug/unplug icon refresh and the GPS-only time source (all also run by `check-rebuild.sh`).
- `./scripts/check-rebuild.sh` — offline preflight for a clean clone (syntax, package list, plugin artifacts, overlay sync, SMS long-message rendering guard, ignored local agent config, Docker, version helper).
- `./scripts/sync-prebuilt-overlay.sh [--check]` — mirrors `prebuilt/` artifacts into `overlay/rootfs/`; `--check` only reports drift.
- `./scripts/bootstrap-flash-deps.sh` — installs `pyusb` and `pyserial` into the gitignored `.flash-deps/` directory for `flash-edl.py`.
@@ -85,7 +85,7 @@ and the NetworkManager dispatcher hook, which call `chronyc refresh` / `burst`
over chronyd's root-only Unix socket when a connection comes up; **Config ->
Sync net time** (`src/sxmo-dmenu/dmenu.c` +
`usr/bin/bananarchy-sync-net-time.sh`) forces the same burst manually and
notifies the user, and the helper's `sync` mode reports the result. Keep DNS
notifies the user, and the helper's `sync` mode reports the result. **Config -> Time source** (`network` default, `gps`) and **Config -> Sync GPS time** use `usr/bin/bananarchy-gps-time-sync.sh` to set the datetime solely from GNSS; in GPS mode chronyd is stopped and every NTP burst is skipped. All GPS queries resolve the GNSS-capable modem through `usr/bin/bananarchy-gps-modem.sh`, never `mmcli -m any` on dual-SIM targets. Keep DNS
resolution outside the helper's `flock` so a long boot retry cannot swallow
network-up events, and keep `var/lib/chrony` owned by the `chrony` user. Network state changes are event-driven through `etc/NetworkManager/dispatcher.d/30-bananarchy-network-status.sh` + `usr/bin/bananarchy-network-event.sh`; keep `superctl disable sxmo_networkmonitor` in the session start hooks, and never reintroduce `superctl start sxmo_networkmonitor` or a long-lived `nmcli device monitor`. The status bar clock must be refreshed synchronously on unlock (`sxmo_hook_unlock.sh`), by dmenu's `update_t9_status_indicator()` before `XStoreName()`, and every minute by the `statusbar_clock` aligned job in the session start hooks; `sxmo_hook_statusbar.sh` forces a root-name refresh on `time` / `state_change`, and its `battery` and `refresh` actions republish the charge icon together with a fresh clock (`bananarchy-time-sync.sh` calls `refresh` after an NTP clock step). `postmarketos-zram-swap` uses `/usr/bin/zramstart`, not `/etc/conf.d/zram-init`: keep `deviceinfo_zram_swap_algo="lz4"` in every `devices/*/deviceinfo*` file. Keep `vm.compaction_proactiveness=0` in `etc/sysctl.d/99-bananarchy-power.conf` and `etc/local.d/10-power-save.start`; see `BATTERY-OPTIMIZATION-ANALYSIS.md` §17 and §18. Deep standby is `bananarchy-suspend.sh` / `bananarchy-deep-standby.sh` / `sxmo_autosuspend.sh` / `sxmo_suspend.sh`, gated by `/etc/bananarchy-no-deep-standby` (shipped present = disabled) and inert because `CONFIG_SUSPEND` is off. A full custom module tree rebuild is deliberately **not** planned: this firmware has no PSCI `SYSTEM_SUSPEND`, so `CONFIG_SUSPEND` would only give s2idle (`freeze`), not `mem` / DDR self-refresh, for <1 mA of saving (see `BATTERY-OPTIMIZATION-ANALYSIS.md` §14 and §17). Never force `sxmo.noidle`/`sxmo.nosuspend` from the session scripts and never reintroduce the infinite `sxmo_not_suspendable` wakelock. `/etc/bananarchy/` is root-only.
- **Image residue**: `rebuild-image.sh` strips `/var/cache/apk`, all `apk.log*` files, and unused gettext locale trees before `mke2fs` and aborts the build if any apk cache/log remains; never add an `apk` call after that guard.
+5
View File
@@ -13,6 +13,11 @@ Release versions follow the `<year-letter><MM><DD>` format (where `2026` is `a`,
Work since `a1108` has focused on reliable 2720 Flip hardware support and a reproducible boot/flash path. Earlier incremental and superseded diagnostic entries are consolidated here.
### GPS reception and GPS-only system time
- **GPS never produced a fix**: `bananarchy-gps`, `gps.so` and the new helpers all used `mmcli -m any`, which is ambiguous on the dual-SIM QMI stack of the 2720 Flip and can resolve to a modem without a Location interface. `/usr/bin/bananarchy-gps-modem.sh` now lists the modems, prefers the one advertising `gps-nmea`, enables the modem plus `3gpp`, `gps-nmea`, `gps-raw` and a 2 s refresh rate, and falls back to `any` only when nothing is enumerated. `gps.so`, the CLI (`status|nmea|watch|enable|disable|modem`) and the time helper share this resolver, so `nokia-argon` keeps its single-modem behaviour.
- **Config -> Time source and Config -> Sync GPS time**: `~/.config/sxmo/time_source` selects `network` (default) or `gps`. With GPS selected, `/usr/bin/bananarchy-gps-time-sync.sh` stops `chronyd`, `bananarchy-time-sync.sh` declines all boot/network-up/force NTP bursts, and the datetime is set solely from a valid GNSS UTC/RMC fix (`date -u -s`, `hwclock -w -u`, status bar refresh), including a boot-time sync. `bananarchy-sync-gps-time.sh` is the user-facing one-shot action with a notification. `scripts/test-gps-time-sync.py` verifies ISO and RMC parsing, chronyd/NTP isolation, source switching, the notification wrapper and CLI modem resolution with stubbed commands; `check-rebuild.sh` guards the rebuilt `gps.so` and `dmenu.so`.
### Charger plug/unplug battery icon
- **Charge icon stayed unchanged on VBUS transitions**: `85-bananarchy-battery.rules` treated every PM8916 event as a capacity change, but `sxmo_hook_battery.sh` caches `state:percentage` and the charger `online` / battery `status` sysfs attributes can still hold the old value while the uevent is delivered. The cache therefore swallowed exactly the plug/unplug event the user wanted to see. Charger events now run `/usr/bin/bananarchy-battery-charge-event.sh`, which forces an immediate `sxmo_hook_battery.sh force` republish (the forced path removes the icon file so `sxmo_status.sh` cannot skip an unchanged value), then re-reads sysfs after two seconds; `flock` coalesces the uevent burst. A generic `ENV{POWER_SUPPLY_ONLINE}` rule covers firmware revisions that publish VBUS on a separate USB/Mains supply. `scripts/test-battery-charge-event.py` validates the immediate + delayed refresh with a stubbed hook, and `check-rebuild.sh` guards the rules, helper and overlay installation. `nokia-argon` keeps the same capacity-change path.
+16
View File
@@ -611,7 +611,9 @@ The **Xlibre** display server (`modesetting_drv.so`) uses **Glamor + DRI3 + GLX
bananarchy-gps nmea # print raw NMEA sentences from ModemManager / QMI PDS
bananarchy-gps watch 2 # continuously poll GPS fix and satellite telemetry every 2s
bananarchy-gps disable # stop standalone GNSS engine to save power
bananarchy-gps modem # show the resolved ModemManager modem and its location capabilities
```
All CLI and `gps.so` queries go through `/usr/bin/bananarchy-gps-modem.sh`, which picks the modem advertising `gps-nmea` (with `--location-enable-3gpp`, `--location-enable-gps-nmea`, `--location-enable-gps-raw`, `--location-set-gps-refresh-rate=2` and `--enable`). Plain `mmcli -m any` is ambiguous on the dual-SIM 2720 Flip and used to leave every GPS query empty.
### 5.7 Network time synchronisation (`bananarchy-time-sync.sh`)
@@ -625,6 +627,20 @@ bananarchy-time-sync.sh force # re-resolve the pool and burst immediately
bananarchy-time-sync.sh sync # force and print a human-readable result
```
### 5.8 GPS-only system time (`bananarchy-gps-time-sync.sh`)
**Config -> Time source** toggles between `Network (NTP)` (the default) and `GPS only`. In GPS-only mode `chronyd` is stopped, `bananarchy-time-sync.sh` declines every boot/network-up/force NTP burst, and the system datetime is set **solely** from GNSS: `/usr/bin/bananarchy-gps-time-sync.sh` enables the modem's location sources, reads either ModemManager's `modem.location.gps.utc` or a valid `$GNRMC`/`$GPRMC` fix, steps the clock with `date -u -s`, writes the RTC with `hwclock -w -u`, and republishes the status bar clock. No DNS, NTP pool or network connection is used. The boot service calls `boot` in this mode, so a cold start with a 1970 RTC still recovers the date from GPS.
**Config -> Sync GPS time** (`/usr/bin/bananarchy-sync-gps-time.sh`) runs the same one-shot sync immediately and shows the resulting UTC timestamp (or the failure reason) as a notification; it works in either time-source mode. From the shell:
```bash
bananarchy-gps-time-sync.sh get # network | gps
bananarchy-gps-time-sync.sh source gps # select GNSS as the sole source
bananarchy-gps-time-sync.sh source network # restore NTP and chronyd
bananarchy-gps-time-sync.sh sync # one-shot GPS clock step
bananarchy-gps-time-sync.sh status # source, last fix, modem capabilities
```
---
## 6. Rebuilding the OS from a clean clone
+1
View File
@@ -49,6 +49,7 @@ Instead of spawning slow shell scripts for everyday phone tasks, Bananarchy runs
- **Tox / Trifa P2P messenger and audio call client (`xtox` / `tox.so`)**: encrypted P2P messenger (`Friends`, `Chat`, `My Tox ID`) built on `c-toxcore` (`libtoxcore.so.2`) with DHT + TCP relay bootstrap, friend requests, persistent message history, and `ToxAV` 48 kHz Opus voice calls integrated with `xcallscreen`.
- **Kopher SmallWeb browser (`xkopher` / `kopher` / `xsmallweb` / `smallweb.so`)**: multi-protocol SmallWeb client for **Gopher** (`gopher://`) with optional TLS (`gophers://`), **Gemini** (`gemini://`), **Spartan** (`spartan://`), and **Nex** (`nex://`), featuring WAP-style default keypad controls from [Kopher](https://code.luxferre.top/luxferre/kopher.git), user-adjustable keybindings (`~/.config/sxmo/smallweb_controls.tsv`), 10 bookmarks, custom homepage support, and link focus that always scrolls the viewport to the focused link in both wrapped and unwrapped modes.
- **Webarchy Web browser (`webarchy` / `xwebarchy` / `webarchy.so`)**: full-featured HTML5/CSS3/JS web browser built on WPE / WebKit (`webkit2gtk-4.1` + `libwpe-1.0`) with Adreno 304 hardware acceleration (`WEBKIT_HARDWARE_ACCELERATION_POLICY_ALWAYS`, WebGL, accelerated 2D canvas, and 512 MB RAM pressure tuning), default KaiOS 4.0 User-Agent (`Mozilla/5.0 (Mobile; rv:123.0) Gecko/123.0 Firefox/123.0 KAIOS/4.0`) with preset and custom User-Agent override (`~/.config/sxmo/webarchy_ua.txt`), `UTF-8` default encoding fallback, `Noto Sans` / `Noto Serif` (`font-noto` + `font-noto-emoji`) as the default non-monospace browser fonts and `Fira Code` with OpenType ligatures as the monospace font, full GStreamer multimedia (`MediaSource` / MSE, WebAudio, inline HTML5 `<video>`/`<audio>` autoplay without user gesture requirements), unobtrusive bookmarking (`*HTTPS`/`*HTTP` header badge, `*`+`0-9` save / `#`+`0-9` load chords, and bookmark manager), and dual navigation modes (keypad link-stepping mode with NeoUI multi-tap form input by default, plus an optional `*#` accelerated mouse cursor emulation mode), and a device-aware renderer profile: the 2720 Flip uses the WebKit CPU renderer (with automatic software fallback after a WebProcess crash) while the 8110 4G keeps Adreno 304 acceleration; `~/.config/sxmo/webarchy_software_renderer` forces the CPU profile on any target.
- **GPS-only system time**: **Config -> Time source** switches from NTP to GNSS only (stopping `chronyd` and disabling every network-up NTP burst) and **Config -> Sync GPS time** steps the clock from a ModemManager GPS UTC value or a valid RMC fix, writes the RTC and refreshes the status bar. All GPS queries now resolve the GNSS-capable modem through `bananarchy-gps-modem.sh` instead of the ambiguous `mmcli -m any`, which fixes empty GPS data on the dual-SIM 2720 Flip. See `MANUAL.md` sections 5.6 and 5.8.
- **GPS reception test utility (`bananarchy-gps`) and OpenStreetMap navigator (`xgps` / `xmaps` / `xnav` / `gps.so`)**: CLI GNSS/GPS diagnostic tool (`bananarchy-gps status|enable|disable|nmea|watch`) and 3-tab NeoUI GPS navigator (`1:GPS Status`, `2:OSM Map`, `3:Nav/Search`) with live NMEA/QMI PDS satellite and 3GPP cell telemetry, interactive `240x212` OpenStreetMap slippy-map tile viewer with offline PNG tile cache (`~/.cache/sxmo/osm_tiles/`), Nominatim place search, saved waypoints, and OSRM turn-by-turn route geometry and step navigation.
- **Themes (`xthemes`), wallpapers (`xwallpapers`), and ringtones (`xringtones`)**: installable `.Xresources` color and font themes (`~/.xthemes/*.xth`, 21 preinstalled schemes including `LynxLair.xth`) with live zero-restart reload across the entire UI, `dunst` notification popups (`bananarchy-sync-dunst-theme`), and terminal, alongside dedicated managers for desktop wallpapers and 3-tab call ringtones & notification/SMS alerts (`1:Ringtone`, `2:Notif/SMS`, `3:Settings`, supporting standard audio, tracker modules, and Nokia RTTTL `.nrt`/`.rtttl`/`.rtx`, Ericsson eMelody `.emy`, and IrDA iMelody `.imy` monophonic ringtones via `/usr/bin/bananarchy-melody`, wired into `sxmo_notifs.sh` and `sxmo_hook_notification.sh`) with 3-level vibration control.
+26 -8
View File
@@ -1,24 +1,36 @@
#!/bin/sh
# Bananarchy GPS reception & coordinate detection CLI utility
# Queries Qualcomm QDSP6 / ModemManager GNSS (gps-nmea + gps-raw + 3gpp-lac-ci).
# The modem path is resolved by bananarchy-gps-modem.sh: "mmcli -m any" can
# pick the wrong modem (or fail) on the dual-SIM 2720 Flip.
set -u
ACTION="${1:-status}"
MMCLI="${BANANARCHY_MMCLI:-/usr/bin/mmcli}"
GPS_MODEM="${BANANARCHY_GPS_MODEM:-/usr/bin/bananarchy-gps-modem.sh}"
modem_path() {
m="$("$GPS_MODEM" path 2>/dev/null | head -n1)"
case "$m" in ''|*[!0-9a-zA-Z/_-]*) m=any ;; esac
printf '%s\n' "$m"
}
enable_gps() {
mmcli -m any --location-enable-gps-nmea --location-enable-gps-raw >/dev/null 2>&1 || true
mmcli -m any --location-set-gps-refresh-rate=2 >/dev/null 2>&1 || true
"$GPS_MODEM" enable >/dev/null 2>&1 || true
}
disable_gps() {
mmcli -m any --location-disable-gps-nmea --location-disable-gps-raw >/dev/null 2>&1 || true
"$GPS_MODEM" disable >/dev/null 2>&1 || true
}
print_status() {
enable_gps
RAW="$(mmcli -m any -K --location-get 2>/dev/null)"
m="$(modem_path)"
RAW="$("$MMCLI" -m "$m" -K --location-get 2>/dev/null)"
if [ -z "$RAW" ]; then
echo "GPS Status: Modem not ready"
exit 1
echo "GPS Status: Modem not ready (modem=$m)"
"$GPS_MODEM" status 2>/dev/null || true
return 1
fi
MCC="$(printf '%s\n' "$RAW" | awk -F': ' '/location\.3gpp\.mcc/{print $2}')"
MNC="$(printf '%s\n' "$RAW" | awk -F': ' '/location\.3gpp\.mnc/{print $2}')"
@@ -29,6 +41,7 @@ print_status() {
ALT="$(printf '%s\n' "$RAW" | awk -F': ' '/location\.gps\.altitude/{print $2}')"
UTC="$(printf '%s\n' "$RAW" | awk -F': ' '/location\.gps\.utc/{print $2}')"
echo "=== Bananarchy GNSS / GPS Reception Status ==="
echo "Modem : $m"
echo "3GPP Cell : MCC=${MCC:--} MNC=${MNC:--} TAC=${TAC:--} CID=${CID:--}"
echo "GPS Fix : Lat=${LAT:---} Lon=${LON:---} Alt=${ALT:---}m UTC=${UTC:---}"
echo "--- NMEA Sentences ---"
@@ -38,7 +51,7 @@ print_status() {
case "$ACTION" in
enable)
enable_gps
echo "GPS enabled (2s refresh)"
echo "GPS enabled on $(modem_path) (2s refresh)"
;;
disable)
disable_gps
@@ -46,7 +59,8 @@ case "$ACTION" in
;;
nmea)
enable_gps
mmcli -m any -K --location-get 2>/dev/null | awk -F': ' '/location\.gps\.nmea\.value/{print $2}'
"$MMCLI" -m "$(modem_path)" -K --location-get 2>/dev/null |
awk -F': ' '/location\.gps\.nmea\.value/{print $2}'
;;
watch)
enable_gps
@@ -59,7 +73,11 @@ case "$ACTION" in
gui|open)
exec xgps
;;
modem|status-detail)
"$GPS_MODEM" status
;;
status|test|*)
print_status
;;
esac
exit 0
+70
View File
@@ -0,0 +1,70 @@
#!/bin/sh
# Resolve the ModemManager modem that owns the GNSS/Location interface.
#
# On the 2720 Flip (and any dual-SIM QMI target) "mmcli -m any" can resolve to
# the wrong modem or fail outright with "too many modems matched", which made
# every GPS enable/query a no-op. Prefer the modem that advertises gps-nmea;
# print "any" only when ModemManager reports no usable modem at all.
set -u
MMCLI="${BANANARCHY_MMCLI:-/usr/bin/mmcli}"
list_modems() {
"$MMCLI" -L 2>/dev/null |
awk '{ for (i = 1; i <= NF; i++)
if ($i ~ /^\/org\/freedesktop\/ModemManager1\/Modem\/[0-9]+$/)
print $i }'
}
resolve_modem() {
first=""
for m in $(list_modems); do
[ -n "$first" ] || first="$m"
if "$MMCLI" -m "$m" --location-status 2>/dev/null | grep -q 'gps-nmea'; then
printf '%s\n' "$m"
return 0
fi
done
if [ -n "$first" ]; then
printf '%s\n' "$first"
else
printf 'any\n'
fi
}
enable_gps() {
m="$(resolve_modem)"
# A disabled modem cannot start a QMI LOC session. These calls are
# idempotent and each failure is non-fatal so the CLI stays usable while
# ModemManager is still probing the modem.
"$MMCLI" -m "$m" --enable >/dev/null 2>&1 || true
"$MMCLI" -m "$m" --location-enable-3gpp >/dev/null 2>&1 || true
"$MMCLI" -m "$m" --location-enable-gps-nmea \
--location-enable-gps-raw >/dev/null 2>&1 || true
"$MMCLI" -m "$m" --location-set-gps-refresh-rate=2 >/dev/null 2>&1 || true
printf '%s\n' "$m"
}
disable_gps() {
m="$(resolve_modem)"
"$MMCLI" -m "$m" --location-disable-gps-nmea \
--location-disable-gps-raw >/dev/null 2>&1 || true
printf '%s\n' "$m"
}
case "${1:-path}" in
path) resolve_modem ;;
list) list_modems ;;
enable) enable_gps ;;
disable) disable_gps ;;
status)
m="$(resolve_modem)"
printf 'modem=%s\n' "$m"
"$MMCLI" -m "$m" --location-status 2>/dev/null || true
;;
*)
printf 'Usage: %s [path|list|enable|disable|status]\n' "${0##*/}" >&2
exit 2
;;
esac
exit 0
+191
View File
@@ -0,0 +1,191 @@
#!/bin/sh
# GPS-only system datetime synchronisation for Bananarchy.
#
# "Solely via GPS" means no NTP pool, no DNS and no chronyd step: when the GPS
# time source is selected, chronyd is stopped and bananarchy-time-sync.sh
# declines every network-up burst. The clock is set from a valid GNSS RMC
# sentence (or ModemManager's GPS UTC field) with date -u -s, then written to
# the RTC and republished on the status bar.
set -u
ACTION="${1:-status}"
SOURCE_FILE="${BANANARCHY_TIME_SOURCE_FILE:-/home/user/.config/sxmo/time_source}"
MMCLI="${BANANARCHY_MMCLI:-/usr/bin/mmcli}"
GPS_MODEM="${BANANARCHY_GPS_MODEM:-/usr/bin/bananarchy-gps-modem.sh}"
DATE_CMD="${BANANARCHY_DATE_CMD:-date}"
RC_SERVICE="${BANANARCHY_RC_SERVICE:-rc-service}"
REFRESH_CMD="${BANANARCHY_STATUS_REFRESH:-su}"
NET_SYNC="${BANANARCHY_NET_SYNC:-/usr/bin/bananarchy-time-sync.sh}"
TIMEOUT="${BANANARCHY_GPS_TIME_TIMEOUT:-90}"
RUNDIR="${BANANARCHY_GPS_TIME_RUNDIR:-/run/bananarchy-gps-time}"
NO_ESCALATION="${BANANARCHY_GPS_TIME_NO_ESCALATION:-0}"
log() {
printf 'bananarchy-gps-time-sync: %s\n' "$*" >&2
}
get_source() {
v="network"
if [ -r "$SOURCE_FILE" ]; then
read -r v < "$SOURCE_FILE" 2>/dev/null || v="network"
fi
case "$v" in gps) printf 'gps\n' ;; *) printf 'network\n' ;; esac
}
refresh_statusbar() {
"$REFRESH_CMD" user -s /bin/sh -c '
HOME=/home/user DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/10000 \
SXMO_WM=dwm SXMO_STATUS_NAME=default SXMO_STATE=/run/user/10000/sxmo.state \
PATH=/usr/share/sxmo/default_hooks:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin \
sxmo_hook_statusbar.sh refresh
' >/dev/null 2>&1 || true
}
# Stop chronyd while GPS is the only time source; start it again for NTP.
apply_source() {
if [ "$(get_source)" = "gps" ]; then
"$RC_SERVICE" chronyd stop >/dev/null 2>&1 || true
log "GPS-only time source: chronyd stopped, NTP disabled"
else
"$RC_SERVICE" chronyd start >/dev/null 2>&1 || true
"$NET_SYNC" force >/dev/null 2>&1 || true
log "Network time source: chronyd started"
fi
}
apply_as_root() {
if [ "$(id -u)" = "0" ] || [ "$NO_ESCALATION" = "1" ]; then
apply_source
else
doas -n "$0" apply >/dev/null 2>&1 || true
fi
}
set_source() {
v="${1:-}"
case "$v" in
network|gps) ;;
*) printf 'Usage: %s source <network|gps>\n' "${0##*/}" >&2; exit 2 ;;
esac
dir="${SOURCE_FILE%/*}"
mkdir -p "$dir" 2>/dev/null || exit 1
printf '%s\n' "$v" > "$SOURCE_FILE" || exit 1
apply_as_root
printf 'Time source: %s\n' "$v"
}
utc_to_stamp() {
v="$1"
case "$v" in *Z) v="${v%Z}" ;; esac
v="$(printf '%s' "$v" | tr 'T' ' ' | cut -c1-19)"
case "$v" in
????-??-??' '??:??:??) printf '%s\n' "$v" ;;
*) return 1 ;;
esac
}
rmc_to_stamp() {
printf '%s\n' "$1" | awk -F',' '
/^\$(GP|GN|GL|GA)RMC/ && $3 == "A" {
split($2, t, ".");
d = $10;
if (length(t[1]) < 6 || length(d) < 6) next;
printf "20%s-%s-%s %s:%s:%s\n",
substr(d, 5, 2), substr(d, 3, 2), substr(d, 1, 2),
substr(t[1], 1, 2), substr(t[1], 3, 2), substr(t[1], 5, 2);
exit
}'
}
location_sample() {
m="$("$GPS_MODEM" path 2>/dev/null | head -n1)"
case "$m" in ''|*[!0-9a-zA-Z/_-]*) m=any ;; esac
"$MMCLI" -m "$m" -K --location-get 2>/dev/null
}
stamp_from_sample() {
raw="$1"
iso="$(printf '%s\n' "$raw" | awk -F': ' '
/modem\.location\.gps\.utc/ {
v = $2;
gsub(/^[ \047"]+|[ \047"]+$/, "", v);
if (v ~ /^[0-9][0-9][0-9][0-9]-/) { print v; exit }
}')"
if [ -n "$iso" ]; then
utc_to_stamp "$iso" && return 0
fi
# NMEA sentences are emitted one per line by `mmcli -K`. A here-document
# keeps the loop in this function instead of a subshell, so the first valid
# RMC fix can be returned directly.
nmea="$(printf '%s\n' "$raw" | awk -F': ' '/location\.gps\.nmea\.value/{print $2}')"
while IFS= read -r sentence; do
stamp="$(rmc_to_stamp "$sentence")"
if [ -n "$stamp" ]; then
printf '%s\n' "$stamp"
return 0
fi
done <<EOF
$nmea
EOF
return 1
}
sync_now() {
"$GPS_MODEM" enable >/dev/null 2>&1 || true
end=$(( $("$DATE_CMD" +%s 2>/dev/null || printf '0') + TIMEOUT ))
while [ "$("$DATE_CMD" +%s 2>/dev/null || printf '0')" -lt "$end" ]; do
raw="$(location_sample)"
stamp="$(stamp_from_sample "$raw")"
if [ -n "$stamp" ]; then
if "$DATE_CMD" -u -s "$stamp" >/dev/null 2>&1; then
hwclock -w -u >/dev/null 2>&1 || true
mkdir -p "$RUNDIR" 2>/dev/null || true
printf '%s\n' "$stamp" > "$RUNDIR/last" 2>/dev/null || true
refresh_statusbar
printf 'GPS time synced: %s UTC\n' "$stamp"
return 0
fi
log "date -u -s failed (root privileges required)"
return 1
fi
sleep 2
done
echo "No GPS time fix yet; retry outdoors or check ModemManager location status"
return 1
}
# The user-facing source/get/status paths need no privileges; the clock step,
# boot sync and chronyd control do.
case "$ACTION" in
source|get|status) ;;
*)
if [ "$(id -u)" != "0" ] && [ "$NO_ESCALATION" != "1" ]; then
exec doas -n "$0" "$@"
fi
;;
esac
case "$ACTION" in
get) get_source ;;
source) set_source "${2:-}" ;;
status)
printf 'time_source=%s\n' "$(get_source)"
printf 'last_gps_sync=%s\n' "$(cat "$RUNDIR/last" 2>/dev/null || printf 'never')"
"$GPS_MODEM" status 2>/dev/null || true
;;
apply) apply_source ;;
sync) sync_now; exit $? ;;
boot)
if [ "$(get_source)" != "gps" ]; then
exit 0
fi
( "$0" sync >/dev/null 2>&1 ) &
exit 0
;;
*)
printf 'Usage: %s [status|get|source <network|gps>|sync|boot|apply]\n' \
"${0##*/}" >&2
exit 2
;;
esac
exit 0
+21
View File
@@ -0,0 +1,21 @@
#!/bin/sh
# Config -> Sync GPS time: set the system clock from GNSS only and report it.
# Runs as the X session user; the GPS helper escalates the clock step itself.
set -u
HELPER="${BANANARCHY_GPS_TIME_HELPER:-/usr/bin/bananarchy-gps-time-sync.sh}"
result="$("$HELPER" sync 2>&1)"
[ -n "$result" ] || result="No response from the GPS time helper"
case "$result" in
"GPS time synced"*) urgency=normal ;;
*) urgency=critical ;;
esac
if command -v notify-send >/dev/null 2>&1; then
notify-send --urgency="$urgency" --expire-time=8000 \
"Sync GPS time" "$result" >/dev/null 2>&1 || true
else
sxmo_notify_user.sh "Sync GPS time: $result" >/dev/null 2>&1 || true
fi
exit 0
+33 -1
View File
@@ -17,6 +17,11 @@ CHRONYC=/usr/bin/chronyc
RUNDIR=/run/bananarchy-time-sync
STAMP="$RUNDIR/last"
LOCK="$RUNDIR/lock"
# GPS-only mode: the user can select GNSS as the sole time source. In that
# mode chronyd is stopped by bananarchy-gps-time-sync.sh and no NTP burst,
# source refresh or clock step may be issued from this helper.
TIME_SOURCE_FILE="${BANANARCHY_TIME_SOURCE_FILE:-/home/user/.config/sxmo/time_source}"
GPS_TIME_HELPER="${BANANARCHY_GPS_TIME_HELPER:-/usr/bin/bananarchy-gps-time-sync.sh}"
# /proc/uptime is monotonic, so a multi-decade clock step cannot invalidate
# the stamp. Unsynchronised attempts are spaced 15 s apart; a synchronised
# clock only needs a source refresh every 5 min after a network change.
@@ -30,7 +35,8 @@ ATTEMPTS=8
BOOT_ATTEMPTS=30
SYNC_WAIT=15
if [ "$(id -u)" != "0" ]; then
# Host tests (and callers that already have privileges) can skip the doas hop.
if [ "$(id -u)" != "0" ] && [ "${BANANARCHY_TIME_SYNC_NO_ESCALATION:-0}" != "1" ]; then
exec doas -n "$0" "$@"
fi
@@ -38,6 +44,14 @@ log() {
printf 'bananarchy-time-sync: %s\n' "$*" >&2
}
time_source() {
v="network"
if [ -r "$TIME_SOURCE_FILE" ]; then
read -r v < "$TIME_SOURCE_FILE" 2>/dev/null || v="network"
fi
case "$v" in gps) printf 'gps\n' ;; *) printf 'network\n' ;; esac
}
monotonic() {
awk '{ printf "%d\n", $1 }' /proc/uptime
}
@@ -106,6 +120,10 @@ wait_sources() {
trigger() {
mode="${1:-network-up}"
if [ "$(time_source)" = "gps" ]; then
log "GPS is the sole time source; skipping NTP"
return 1
fi
attempts="$ATTEMPTS"
[ "$mode" = "boot" ] && attempts="$BOOT_ATTEMPTS"
wait_chronyd || {
@@ -142,6 +160,12 @@ trigger() {
# Config -> Sync net time: force a burst and report when the clock is set.
sync_now() {
if [ "$(time_source)" = "gps" ]; then
# Config -> Sync net time must still give the user a result without
# touching NTP when GNSS is the only configured source.
"$GPS_TIME_HELPER" sync
return $?
fi
if ! trigger sync; then
echo "Network time unavailable: chronyd or DNS is not ready"
return 1
@@ -162,9 +186,17 @@ sync_now() {
case "${1:-status}" in
boot|network-up)
if [ "$(time_source)" = "gps" ]; then
[ "${1:-}" = "boot" ] && "$GPS_TIME_HELPER" boot >/dev/null 2>&1 || true
exit 0
fi
trigger "$1" && refresh_statusbar
;;
force)
if [ "$(time_source)" = "gps" ]; then
"$GPS_TIME_HELPER" sync && refresh_statusbar
exit $?
fi
trigger force && refresh_statusbar
;;
sync)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4
View File
@@ -177,6 +177,10 @@ 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-battery-charge-event.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-gps-modem.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-gps-time-sync.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-sync-gps-time.sh" \
"$TARGET_ROOTFS/usr/bin/bananarchy-gps" \
"$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" \
+48
View File
@@ -1205,6 +1205,54 @@ if [ -x "$BASE_DIR/scripts/test-battery-charge-event.py" ] && \
fail "host charger plug/unplug event test failed"
fi
echo "[check] GPS-only time source..."
GPS_TIME="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-gps-time-sync.sh"
GPS_MODEM="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-gps-modem.sh"
GPS_WRAPPER="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-sync-gps-time.sh"
GPS_CLI="$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-gps"
GPS_SRC="$BASE_DIR/src/dwm-plugins/gps_plugin.cpp"
DMENU_SRC="$BASE_DIR/src/sxmo-dmenu/dmenu.c"
for f in "$GPS_TIME" "$GPS_MODEM" "$GPS_WRAPPER" "$GPS_CLI" \
"$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-time-sync.sh"; 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
for token in 'bananarchy-gps-modem.sh' 'gpsModemArg' \
'--location-enable-3gpp'; do
if ! grep -qF -- "$token" "$GPS_SRC"; then
fail "gps_plugin.cpp is missing the GPS modem fix: $token"
fi
done
for token in 'Sync GPS time' '@toggle:time_source' 'read_time_source'; do
if ! grep -qF "$token" "$DMENU_SRC"; then
fail "dmenu.c is missing the GPS time source option: $token"
fi
done
if ! grep -qF 'GPS is the sole time source' \
"$BASE_DIR/overlay/rootfs/usr/bin/bananarchy-time-sync.sh"; then
fail "network time helper no longer honours the GPS-only source"
fi
if ! strings "$BASE_DIR/prebuilt/sxmo-x11/usr/lib/dwm/plugins/gps.so" 2>/dev/null | \
grep -qF 'bananarchy-gps-modem.sh'; then
fail "shipped gps.so is stale: rebuild with scripts/build-sxmo-x11.sh"
fi
if ! strings "$BASE_DIR/prebuilt/sxmo-x11/usr/lib/dwm/plugins/dmenu.so" 2>/dev/null | \
grep -qF 'Sync GPS time'; then
fail "shipped dmenu.so is stale: rebuild with scripts/build-sxmo-x11.sh"
fi
if ! grep -q 'bananarchy-gps-time-sync.sh' "$BASE_DIR/scripts/apply-bananarchy-overlay.sh"; then
fail "apply-bananarchy-overlay.sh no longer installs the GPS time helper"
fi
if [ -x "$BASE_DIR/scripts/test-gps-time-sync.py" ] && \
command -v python3 >/dev/null 2>&1 && \
! "$BASE_DIR/scripts/test-gps-time-sync.py" >/dev/null 2>&1; then
fail "host GPS-only time source test failed"
fi
if [ "$FAILURES" -ne 0 ]; then
echo "[check] $FAILURES check(s) failed."
exit 1
+187
View File
@@ -0,0 +1,187 @@
#!/usr/bin/env python3
"""Host integration test for the GPS-only datetime source.
Runs the real shell helpers with stubbed mmcli/date/chronyd, verifying that a
GNSS fix sets the clock without ever consulting NTP, and that the network time
helper stays inert while the GPS-only source is selected.
"""
import os
import pathlib
import subprocess
import sys
import tempfile
BASE = pathlib.Path(__file__).resolve().parent.parent
BIN = BASE / "overlay/rootfs/usr/bin"
GPS_TIME = BIN / "bananarchy-gps-time-sync.sh"
GPS_WRAPPER = BIN / "bananarchy-sync-gps-time.sh"
NET_TIME = BIN / "bananarchy-time-sync.sh"
GPS_MODEM = BIN / "bananarchy-gps-modem.sh"
GPS_CLI = BIN / "bananarchy-gps"
STUBS = {
"date": '''#!/bin/sh
if [ "$1" = "-u" ] && [ "$2" = "-s" ]; then
printf '%s\\n' "$3" >> "$FAKE_ROOT/date.log"
exit 0
fi
if [ "$1" = "+%s" ]; then
n=0
[ -r "$FAKE_ROOT/epoch" ] && read -r n < "$FAKE_ROOT/epoch"
n=$((n + 1))
printf '%s\\n' "$n" > "$FAKE_ROOT/epoch"
printf '%s\\n' "$n"
exit 0
fi
exit 0
''',
"mmcli": '''#!/bin/sh
case "$*" in
*--location-get*) cat "$FAKE_ROOT/location" ;;
*-L*) printf ' /org/freedesktop/ModemManager1/Modem/0 [QUALCOMM]\\n' ;;
*--location-status*) printf ' capabilities: 3gpp-lac-ci, gps-raw, gps-nmea\\n' ;;
esac
exit 0
''',
"bananarchy-gps-modem.sh": '''#!/bin/sh
case "${1:-path}" in
path|enable|disable) printf '/org/freedesktop/ModemManager1/Modem/0\\n' ;;
status) printf 'modem=/org/freedesktop/ModemManager1/Modem/0\\n' ;;
esac
exit 0
''',
"rc-service": '''#!/bin/sh
printf '%s\\n' "$*" >> "$FAKE_ROOT/rc.log"
exit 0
''',
"chronyc": '''#!/bin/sh
printf 'chronyc %s\\n' "$*" >> "$FAKE_ROOT/chronyc.log"
exit 0
''',
"bananarchy-net-sync-stub": '''#!/bin/sh
printf 'net-sync %s\\n' "$*" >> "$FAKE_ROOT/net.log"
exit 0
''',
"hwclock": '#!/bin/sh\nexit 0\n',
"sleep": '#!/bin/sh\nexit 0\n',
"su": '#!/bin/sh\nexit 0\n',
"notify-send": '''#!/bin/sh
printf '%s\\n' "$*" >> "$FAKE_ROOT/notify.log"
exit 0
''',
}
ISO_SAMPLE = (
"modem.location.gps.utc : '2026-11-10T12:34:56Z'\n"
"modem.location.gps.latitude : 50.4501\n"
"modem.location.gps.longitude : 30.5234\n"
)
RMC_SAMPLE = (
"modem.location.gps.nmea.value : "
"$GNRMC,123456.00,A,5000.0000,N,03000.0000,E,0.0,0.0,101126,,,A\n"
)
def fail(message):
sys.stderr.write("FAIL: %s\n" % message)
return 1
def main():
for path in (GPS_TIME, GPS_WRAPPER, NET_TIME, GPS_MODEM, GPS_CLI):
if not path.is_file():
return fail("missing %s" % path)
if path.suffix == ".sh" or path.name in ("bananarchy-gps", "bananarchy-time-sync.sh"):
if subprocess.run(["sh", "-n", str(path)]).returncode:
return fail("shell syntax: %s" % path.name)
with tempfile.TemporaryDirectory(prefix="bananarchy-gps-time-") as tmp:
root = pathlib.Path(tmp)
bindir = root / "bin"
home = root / "home"
(home / ".config/sxmo").mkdir(parents=True)
bindir.mkdir()
for name, body in STUBS.items():
target = bindir / name
target.write_text(body, encoding="utf-8")
target.chmod(0o755)
env = dict(os.environ)
env.update({
"PATH": str(bindir) + os.pathsep + os.environ["PATH"],
"FAKE_ROOT": str(root),
"HOME": str(home),
"BANANARCHY_TIME_SOURCE_FILE": str(home / ".config/sxmo/time_source"),
"BANANARCHY_GPS_TIME_RUNDIR": str(root / "run"),
"BANANARCHY_GPS_TIME_NO_ESCALATION": "1",
"BANANARCHY_TIME_SYNC_NO_ESCALATION": "1",
"BANANARCHY_GPS_TIME_TIMEOUT": "5",
"BANANARCHY_STATUS_REFRESH": "true",
"BANANARCHY_GPS_MODEM": str(bindir / "bananarchy-gps-modem.sh"),
"BANANARCHY_MMCLI": str(bindir / "mmcli"),
"BANANARCHY_NET_SYNC": str(bindir / "bananarchy-net-sync-stub"),
"BANANARCHY_GPS_TIME_HELPER": str(GPS_TIME),
})
def run(script, *args):
return subprocess.run(["sh", str(script), *args], env=env,
capture_output=True, text=True)
def text(name):
p = root / name
return p.read_text() if p.exists() else ""
(root / "location").write_text(ISO_SAMPLE, encoding="utf-8")
if run(GPS_TIME, "get").stdout.strip() != "network":
return fail("default time source is not network")
res = run(GPS_TIME, "source", "gps")
if "Time source: gps" not in res.stdout or \
(home / ".config/sxmo/time_source").read_text().strip() != "gps":
return fail("cannot select the GPS-only time source")
if "chronyd stop" not in text("rc.log"):
return fail("GPS-only source did not stop chronyd")
print("[ok] source: gps disables chronyd")
res = run(GPS_TIME, "sync")
if "GPS time synced: 2026-11-10 12:34:56 UTC" not in res.stdout:
return fail("ISO GPS UTC did not set the clock: %r %r" %
(res.stdout, res.stderr))
if "2026-11-10 12:34:56" not in text("date.log"):
return fail("date -u -s was not called with the GNSS timestamp")
print("[ok] sync: ModemManager GPS UTC sets the clock")
(root / "location").write_text(RMC_SAMPLE, encoding="utf-8")
res = run(GPS_TIME, "sync")
if "GPS time synced: 2026-11-10 12:34:56 UTC" not in res.stdout:
return fail("RMC fix did not set the clock: %r %r" %
(res.stdout, res.stderr))
print("[ok] sync: RMC sentence fallback sets the clock")
# NTP must stay completely unused while the GPS source is selected.
for action in ("boot", "network-up", "force", "sync"):
run(NET_TIME, action)
if text("chronyc.log"):
return fail("network time helper consulted chronyd in GPS-only mode")
print("[ok] network time helper stays inert in GPS-only mode")
res = run(GPS_WRAPPER)
if res.returncode or "GPS time synced" not in text("notify.log"):
return fail("Config -> Sync GPS time did not notify the user")
print("[ok] user wrapper reports the GPS sync result")
res = run(GPS_TIME, "source", "network")
if "Time source: network" not in res.stdout or \
"chronyd start" not in text("rc.log") or \
"net-sync force" not in text("net.log"):
return fail("switching back to network time did not restore NTP")
print("[ok] source: network restores chronyd and NTP")
# The GPS CLI resolves the modem through the shared helper.
res = run(GPS_CLI, "status")
if "Modem : /org/freedesktop/ModemManager1/Modem/0" not in res.stdout:
return fail("bananarchy-gps did not use the resolved modem path")
print("[ok] CLI: GPS status uses the resolved modem")
print("GPS-only time source: all checks passed")
return 0
if __name__ == "__main__":
sys.exit(main())
+28 -5
View File
@@ -163,8 +163,26 @@ std::vector<std::string> splitCsv(const std::string& s) {
return out;
}
// "mmcli -m any" is ambiguous on dual-SIM QMI targets such as the 2720 Flip:
// ModemManager can resolve the wrong modem or reject the query outright. The
// helper picks the modem that advertises the gps-nmea capability and falls
// back to "any" when no modem is enumerated yet.
std::string gpsModemArg() {
static std::string cached;
if (cached.empty()) {
std::string path = trimStr(runCaptureCmd(
"/usr/bin/bananarchy-gps-modem.sh path 2>/dev/null"));
if (path.rfind("/org/freedesktop/ModemManager1/Modem/", 0) == 0)
cached = "-m " + shellQuote(path);
else
cached = "-m any";
}
return cached;
}
void pollModemGpsStatus(GpsStatus& st) {
std::string raw = runCaptureCmd("mmcli -m any -K --location-get 2>/dev/null");
std::string raw = runCaptureCmd(
"mmcli " + gpsModemArg() + " -K --location-get 2>/dev/null");
if (raw.empty()) return;
st.rawNmea.clear();
@@ -559,7 +577,8 @@ int gps_run_main(int argc, char** argv) {
else if (std::strcmp(argv[i], "--test") == 0) {
// CLI GPS test mode
GpsStatus st;
runAsyncCmd("mmcli -m any --location-enable-gps-nmea --location-enable-gps-raw >/dev/null 2>&1");
runAsyncCmd(std::string("/usr/bin/bananarchy-gps-modem.sh enable >/dev/null 2>&1; ") +
"mmcli " + gpsModemArg() + " --location-enable-3gpp >/dev/null 2>&1");
::usleep(300000);
pollModemGpsStatus(st);
std::printf("Fix: %s (%dD) Sats: %d/%d HDOP: %.1f UTC: %s\n",
@@ -632,8 +651,11 @@ int gps_run_main(int argc, char** argv) {
if (!gps.gpsEnabled) {
gps.gpsEnabled = true;
runAsyncCmd(
"mmcli -m any --location-enable-gps-nmea --location-enable-gps-raw >/dev/null 2>&1; "
"mmcli -m any --location-set-gps-refresh-rate=2 >/dev/null 2>&1");
"mmcli " + gpsModemArg() +
" --location-enable-gps-nmea --location-enable-gps-raw "
"--location-enable-3gpp >/dev/null 2>&1; "
"mmcli " + gpsModemArg() +
" --location-set-gps-refresh-rate=2 >/dev/null 2>&1");
}
};
@@ -641,7 +663,8 @@ int gps_run_main(int argc, char** argv) {
if (gps.gpsEnabled && !keepGpsInBg) {
gps.gpsEnabled = false;
runAsyncCmd(
"mmcli -m any --location-disable-gps-nmea --location-disable-gps-raw >/dev/null 2>&1");
"mmcli " + gpsModemArg() +
" --location-disable-gps-nmea --location-disable-gps-raw >/dev/null 2>&1");
}
};
+50
View File
@@ -1213,6 +1213,10 @@ clear_all_notifications_now(void)
"sxmo_hook_statusbar.sh notifications >/dev/null 2>&1");
}
/* Defined with the Config-menu helpers below; used by the time source toggle. */
static void time_source_path(char *path, size_t len);
static const char *read_time_source(void);
static void
handle_builtin_toggle(const char *toggle_name)
{
@@ -1322,6 +1326,25 @@ handle_builtin_toggle(const char *toggle_name)
} else if (strcmp(toggle_name, "ext_logging") == 0) {
int rc = system("doas -n /usr/bin/bananarchy-engmenu-ctl logging toggle >/dev/null 2>&1 || /usr/bin/bananarchy-engmenu-ctl logging toggle >/dev/null 2>&1");
(void)rc;
} else if (strcmp(toggle_name, "time_source") == 0) {
/* Config -> Time source: switch between NTP and GPS-only datetime sync. */
char path[256], dir[256], value[16];
const char *home = getenv("HOME");
const char *next = strcmp(read_time_source(), "gps") == 0 ? "network" : "gps";
if (!home || !home[0])
home = "/home/user";
snprintf(dir, sizeof(dir), "%s/.config/sxmo", home);
mkdir(dir, 0755);
time_source_path(path, sizeof(path));
snprintf(value, sizeof(value), "%s\n", next);
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
if (fd >= 0) {
(void)!write(fd, value, strlen(value));
close(fd);
spawn_detached_sh(
"doas -n /usr/bin/bananarchy-gps-time-sync.sh apply >/dev/null 2>&1 || "
"/usr/bin/bananarchy-gps-time-sync.sh apply >/dev/null 2>&1 || true");
}
} else if (strcmp(toggle_name, "notif_clear_all") == 0) {
clear_all_notifications_now();
}
@@ -2516,6 +2539,26 @@ idle_blank_label(int secs)
return out;
}
/* Config-menu time source (NTP network vs GNSS only) helpers. */
static void
time_source_path(char *path, size_t len)
{
const char *home = getenv("HOME");
if (!home || !home[0])
home = "/home/user";
snprintf(path, len, "%s/.config/sxmo/time_source", home);
}
static const char *
read_time_source(void)
{
char path[256], buf[32] = "";
time_source_path(path, sizeof(path));
if (read_first_line(path, buf, sizeof(buf)) && strcmp(buf, "gps") == 0)
return "gps";
return "network";
}
static void
populate_timezone_menu(void)
{
@@ -2982,6 +3025,13 @@ open_builtin_menu(const char *menu_name, int keep_idx)
snprintf(label, sizeof(label), "%s Sync net time", ICON_CLK);
add_menu_item(label, "/usr/bin/bananarchy-sync-net-time.sh", 0);
/* Time source: NTP or GNSS only; Sync GPS time works in either mode. */
snprintf(label, sizeof(label), "%s Time source: %s", ICON_CLK,
strcmp(read_time_source(), "gps") == 0 ? "GPS only" : "Network (NTP)");
add_menu_item(label, "@toggle:time_source", 1);
snprintf(label, sizeof(label), "%s Sync GPS time", ICON_CLK);
add_menu_item(label, "/usr/bin/bananarchy-sync-gps-time.sh", 0);
snprintf(label, sizeof(label), "%s Screen blank: %s", ICON_CLK,
idle_blank_label(read_idle_blank_secs()));
add_menu_item(label, "@menu:idle_blank", 1);