Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/omamobile-gnss/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pkgdesc="Omarchy Mobile GNSS for the Pixel 7 Pro: Broadcom's lhd/gpsd in a vendo
arch=(aarch64)
url="https://github.com/derekross/omarchy-mobile"
license=(MIT)
depends=(bash python curl iproute2 util-linux coreutils systemd geoclue libnotify)
depends=(bash python curl iproute2 util-linux coreutils procps-ng systemd geoclue libnotify)
optdepends=('gpsd: NMEA for gpsd clients through /run/omamobile-gnss/nmea-tty')
backup=(etc/geoclue/conf.d/90-omamobile-gnss.conf etc/omamobile/gnss.conf)
install=omamobile-gnss.install
Expand Down
55 changes: 53 additions & 2 deletions packages/omamobile-gnss/lib/omamobile-gnss-start
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,34 @@ SESSION=/run/omamobile-gnss/session
STOP_REQUEST=/run/omamobile-gnss/stop-request
say() { printf 'omamobile-gnss: %s\n' "$*" >&2; }

# The 9a's gnssd: up when its socket is listening. The modem profile starts it
# some 20 s after the CP is ONLINE (OMAMOBILE_MODEM_GNSS_DELAY), when the
# modem unit runs with OMAMOBILE_MODEM_GNSS=1; a location request in that
# window waits for it (GNSSD_WAIT s at most) rather than finding nothing.
GNSSD_WAIT=${OMAMOBILE_GNSS_GNSSD_WAIT:-90}
# Without gnssd, and with no modem unit bringing it, the start holds the
# client's connection this long before it exits, looking every 5 s whether
# the modem has started meanwhile: a client that reconnects at once (GeoClue)
# would otherwise start the unit five times in a second, and systemd's start
# limit would fail it and its socket for the rest of the boot. A client that
# keeps asking with the modem off so starts the unit once a minute.
NOTHING_HOLD=${OMAMOBILE_GNSS_NOTHING_HOLD:-60}
# The sleep inhibitor (block mode), which logind and omamobile-sleepd honour
# (device/cheetah/SUSPEND-PLAN.md 6.1). The 7 Pro holds it for the whole
# start, as its unit always did. The 9a takes it for a session only: the
# wait and the hold above run without it, so a 9a whose modem is off isn't
# kept awake by a client that asks for a position it can't have.
INHIBIT=("${OMAMOBILE_GNSS_INHIBIT:-/usr/bin/systemd-inhibit}" --what=sleep --mode=block
"--who=Omarchy Mobile GNSS" "--why=A location session is running")
# Read with a builtin: this runs once a second while it waits.
gnssd_up() { [[ $(< /proc/net/unix) == *@GNSSND* ]]; }
gnssd_coming() {
local state env
state=$(${OMAMOBILE_GNSS_SYSTEMCTL:-systemctl} show -p ActiveState --value omamobile-tegu-modem.service 2>/dev/null) || return 1
env=$(${OMAMOBILE_GNSS_SYSTEMCTL:-systemctl} show -p Environment --value omamobile-tegu-modem.service 2>/dev/null) || return 1
[[ $state == active || $state == activating ]] && [[ " $env " == *" OMAMOBILE_MODEM_GNSS=1 "* ]]
}

# the Pixel 9a (zumapro-tegu) runs the gnss-slsi profile, the Pixel 7 Pro gnss
# OMAMOBILE_DT lets the tests run both branches on any machine (as
# omamobile-setup-user does).
Expand Down Expand Up @@ -50,6 +78,10 @@ if [[ ${1:-} == --stop ]]; then
exec /usr/lib/omamobile-vendor/omamobile-vendor-chroot "$profile" stop
fi

if [[ $# -eq 0 && -z ${OMAMOBILE_GNSS_INHIBITED:-} ]] && ! tegu; then
OMAMOBILE_GNSS_INHIBITED=1 exec "${INHIBIT[@]}" "$0"
fi

if [[ ${1:-} == --retry ]]; then
rm -f "$MARK"
# By hand on the 9a this only clears the marker: GNSS starts inside its
Expand All @@ -61,6 +93,10 @@ if [[ ${1:-} == --retry ]]; then
elif [[ -e $MARK ]]; then
if tegu; then
say "the last bring-up ($(cat "$MARK")) never finished; skipping GNSS (/usr/lib/omamobile-vendor/omamobile-gnss-start --retry clears the marker; the next location request then starts GNSS)"
# Held as "nothing to do" below is: GeoClue reconnects at once, and five
# quick exits failed the socket (trigger limit) for the rest of the boot,
# so after --retry the next request still found nothing listening.
sleep "$NOTHING_HOLD"
else
say "the last bring-up ($(cat "$MARK")) never finished; skipping GNSS (run /usr/lib/omamobile-vendor/omamobile-gnss-start --retry)"
fi
Expand All @@ -71,7 +107,22 @@ fi
# the modem profile, and the gnss-slsi profile runs the HAL and our client,
# which writes NMEA to the FIFO the bridge reads. Nothing to load here.
if tegu; then
if ! grep -c '@GNSSND' /proc/net/unix >/dev/null; then
# Before the marker and the session: a give-up here leaves nothing behind.
coming=0 idle=0 told=
until gnssd_up; do
if gnssd_coming; then
[[ -n $told ]] || say "waiting for gnssd: the modem profile starts it some 20 s after the modem is ONLINE"
told=1
((coming++ < GNSSD_WAIT)) || break
sleep 1
else
((idle < NOTHING_HOLD)) || break
step=$((NOTHING_HOLD - idle < 5 ? NOTHING_HOLD - idle : 5))
sleep "$step"
idle=$((idle + step))
fi
done
if ! gnssd_up; then
say "gnssd isn't running (the modem profile with OMAMOBILE_MODEM_GNSS=1); nothing to do"
exit 0
fi
Expand All @@ -96,7 +147,7 @@ if tegu; then
printf '%s\n' "$INVOCATION_ID" > "$SESSION"
sync
say "starting the 9a's GNSS HAL and client"
OMAMOBILE_GNSS_NMEA_OUT=fifo exec /usr/lib/omamobile-vendor/omamobile-vendor-chroot gnss-slsi start
OMAMOBILE_GNSS_NMEA_OUT=fifo exec "${INHIBIT[@]}" /usr/lib/omamobile-vendor/omamobile-vendor-chroot gnss-slsi start
fi
# The DT must have the GNSS node enabled (gnss overlay); otherwise nothing to do.
if ! grep -qs okay /sys/firmware/devicetree/base/soc@0/usi@109400c0/spi@10940000/status; then
Expand Down
8 changes: 7 additions & 1 deletion packages/omamobile-gnss/lib/omamobile-vendor-chroot
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ profile_stop() { :; }
source "$PROFILE_CONF"
ROOT=$RUN/root
NSPID=$RUN/ns.pid
# A profile's graceful stop (profile_stop, from the host) may end one of its
# daemons on purpose before systemd's stop signals the rest; it writes this
# file first, and the supervision below then takes that exit as part of the
# stop: a clean one, not "a service exited".
STOP_REQUESTED=$RUN/stop-requested

LIBS_VENDOR=/vendor/lib64:/vendor/lib64/hw:/system/lib64:/omamobile/lib64
LIBS_SYSTEM=/system/lib64:/vendor/lib64:/omamobile/lib64
Expand Down Expand Up @@ -282,7 +287,7 @@ start() {
check
mkdir -p "$RUN"
if [[ -z ${OMAMOBILE_VENDOR_IN_NS:-} ]]; then
rm -f "$NSPID"
rm -f "$NSPID" "$STOP_REQUESTED"
exec unshare --mount --propagation private --pid --fork --kill-child \
env OMAMOBILE_VENDOR_IN_NS=1 "$0" "$PROFILE" start
fi
Expand All @@ -299,6 +304,7 @@ start() {
# whether to restart it).
wait -n || true
# wait also returns when TERM/INT arrives; then the trap is already stopping
[[ -e $STOP_REQUESTED ]] && stop 0
[[ -n $STOPPING ]] || say "a service exited"
stop 1
}
Expand Down
29 changes: 29 additions & 0 deletions packages/omamobile-gnss/profiles/gnss-slsi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,43 @@ profile_setup() {
# registers android.hardware.gnss.IGnss/vendor there.
GNSS_SERVICE=${OMAMOBILE_GNSS_SERVICE:-android.hardware.gnss.IGnss/vendor}

# A graceful stop, from the host before systemd signals the daemons. The
# client stops positioning through the HAL (stopNmea, stop) when it gets TERM,
# but the runner's stop signals every daemon at once, and the HAL went before
# the client's stop reached it: gnssd kept the receiver running, with the
# GNSS core streaming over SPI, until the next boot. So the client goes first
# and alone, while the HAL is still there; the stop-requested file tells the
# runner its exit is part of this stop.
profile_stop() {
local pid
pid=$(pgrep -o -f '^/omamobile/bin/omamobile-gnss-client ') || return 0
[[ -n $pid ]] || return 0
: > "$STOP_REQUESTED"
kill -TERM "$pid" 2>/dev/null || return 0
for _ in $(seq 1 30); do
kill -0 "$pid" 2>/dev/null || return 0
sleep 0.1
done
say "the client did not stop within 3 s"
}

profile_start() {
spawn vndservicemanager vendor /vendor/bin/vndservicemanager /dev/vndbinder
sleep 1
spawn hal vendor /vendor/bin/hw/android.hardware.gnss-service
sleep 3
# The client writes the HAL's NMEA into the FIFO the bridge reads, and the
# bridge stops before this stack (it is ordered after it): at shutdown, and
# at its idle exit. A write with no reader raised SIGPIPE and killed the
# client, the profile then stopped itself before systemd's stop came, and
# that unexpected exit kept the hang marker, so the next boot skipped GNSS.
# With SIGPIPE ignored the write fails and the client stays until the stack
# is stopped.
trap '' PIPE
if [[ $NMEA_OUT == fifo ]]; then
spawn client vendor /omamobile/bin/omamobile-gnss-client /data/vendor/gps/nmea_out "$GNSS_SERVICE"
else
spawn client vendor /omamobile/bin/omamobile-gnss-client - "$GNSS_SERVICE"
fi
trap - PIPE
}
Loading