<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[lomiri-location-service GPS reliability patches (navius branch, v3.4.1+navius5)]]></title><description><![CDATA[<h1>lomiri-location-service GPS reliability patches (navius branch, v3.4.1+navius5)</h1>
<p dir="auto">While building <strong>Navius</strong> (a GPS navigator for Ubuntu Touch) I ran into several GPS reliability issues in <code>lomiri-location-service</code>, particularly on devices that run <strong>Waydroid</strong> alongside UT.</p>
<p dir="auto">I have collected the fixes in a branch called <strong>navius</strong> (currently at <strong>navius5</strong>). All patches are tested on a <strong>Xiaomi Redmi Note 9 Pro (HALIUM_10, arm64)</strong> running Ubuntu Touch Noble (24.04), but they address generic race conditions and watchdog issues that should benefit any device.</p>
<p dir="auto">I would like to share them here and eventually propose the relevant ones upstream.</p>
<hr />
<h2>Bugs fixed</h2>
<h3>1. Waydroid GPS callback race → SIGSEGV <code>navius1</code></h3>
<p dir="auto">On HALIUM_10, Waydroid and Ubuntu Touch both access the GPS HAL via <code>host_hwbinder</code>. Waydroid can call <code>register_callbacks()</code> at any time; that function does <code>u_hardware_gps_delete()</code> + <code>u_hardware_gps_new()</code>. If a GPS callback fires between those two calls it dereferences the freed handle — <strong>SIGSEGV, daemon crash</strong>.</p>
<p dir="auto"><strong>Fix:</strong> <code>std::shared_mutex callback_mutex</code> in <code>Impl</code>. All seven GPS callbacks hold a <em>shared</em> lock (run concurrently with each other). <code>register_callbacks()</code> holds an <em>exclusive</em> lock only while deleting/installing the handle — callbacks complete first, then the swap happens safely.</p>
<h3>2. EDEADLK at service start <code>navius1</code></h3>
<p dir="auto">The initial mutex fix held the exclusive lock across the whole delete → new sequence. <code>u_hardware_gps_new()</code> fires <code>on_set_capabilities</code> synchronously on the calling thread, which tries to take a shared lock on the same mutex: <strong>EDEADLK</strong>, daemon aborts at start-up.</p>
<p dir="auto"><strong>Fix:</strong> Three-phase lock:</p>
<ol>
<li>Exclusive lock → delete old handle → release.</li>
<li>Create new handle <em>without any lock</em> (re-entrant callbacks are now safe).</li>
<li>Exclusive lock → install new handle → dispatch position mode → release.</li>
</ol>
<h3>3. <code>start_positioning()</code> blocking the daemon forever <code>navius2</code></h3>
<p dir="auto"><code>start_positioning()</code> was called from a D-Bus handler thread. Its internal <code>QEventLoop</code> blocked that thread indefinitely. LLS started, satellites were tracked, but <strong>no position fix ever arrived</strong>.</p>
<p dir="auto"><strong>Fix:</strong> <code>start_positioning()</code> dispatched to the main thread via <code>Qt::QueuedConnection</code> / <code>QMetaObject::invokeMethod</code>.</p>
<h3>4. GPS stops after Waydroid closes and never restarts <code>navius4</code></h3>
<p dir="auto">When Waydroid shuts down it calls <code>u_hardware_gps_stop()</code> on the shared HAL, halting GPS globally. LLS's handle remained valid so it never detected the stall — <strong>GPS frozen until LLS was manually restarted</strong>.</p>
<p dir="auto"><strong>Fix — watchdog thread:</strong> a detached thread ticks every 5 s and reads <code>last_gps_ms</code> (updated by <code>on_location_update</code> and <code>on_sv_status_update</code>). If no GPS data for 10 s, it re-runs <code>register_callbacks()</code> and restarts the chipset automatically.</p>
<h3>5. No fixes despite 37+ satellites in view <code>navius4</code></h3>
<p dir="auto"><code>dispatch_updated_modes_to_driver()</code> (which sends the position mode to the chipset via <code>u_hardware_gps_set_position_mode()</code>) was called in <code>register_callbacks()</code> but <strong>not</strong> in the fast path inside <code>start_positioning()</code>. The chipset tracked satellites but never computed fixes.</p>
<p dir="auto"><strong>Fix:</strong> call <code>dispatch_updated_modes_to_driver()</code> before <code>u_hardware_gps_start()</code> in the fast path.</p>
<blockquote>
<p dir="auto"><strong>Result after navius4:</strong> Waydroid and Ubuntu Touch GPS now work simultaneously. After Waydroid opens and steals the HAL, the watchdog reclaims callbacks within 10 s; accuracy converges to ~4 m while Waydroid keeps positioning.</p>
</blockquote>
<hr />
<h2>Feature additions</h2>
<h3><code>GetVisibleSpaceVehicles</code> D-Bus method <code>navius2</code></h3>
<p dir="auto">QML clients that cannot subscribe to D-Bus property-change signals have no way to get a satellite snapshot without keeping a persistent session. Added a synchronous method and read-only property <code>VisibleSpaceVehicles</code> to the service interface:</p>
<pre><code>dbus-send --system --dest=com.lomiri.location.Service \
          --print-reply \
          /com/lomiri/location/Service \
          com.lomiri.location.Service.Interface.GetVisibleSpaceVehicles
</code></pre>
<h3>Compile-time debug traces (<code>LLS_DEBUG</code>) <code>navius5</code></h3>
<p dir="auto">All GPS trace logging is gated behind <code>LLS_DEBUG</code> (default <code>false</code>) in <code>include/…/lls_trace.h</code>. Zero runtime cost when disabled; set to <code>true</code> and rebuild for full per-fix traces in journald.</p>
<hr />
<h2>Build &amp; install</h2>
<p dir="auto">The branch ships a <code>build-deb.sh</code> script that produces a <code>.deb</code> inside an isolated Docker container (Ubuntu 24.04 + UBports repo). No host modifications needed. Requires Docker on an ARM64 host.</p>
<pre><code class="language-bash">git clone https://github.com/woodyst/lomiri-location-service -b navius
cd lomiri-location-service
bash build-deb.sh            # output to ./debs/
</code></pre>
<pre><code class="language-bash"># Deploy to device
scp debs/liblomiri-location-service3_*_arm64.deb phablet@&lt;device&gt;:/tmp/
ssh root@&lt;device&gt; "mount -o remount,rw / &amp;&amp; \
    dpkg -i /tmp/liblomiri-location-service3_*_arm64.deb &amp;&amp; \
    systemctl restart lomiri-location-service"
</code></pre>
<hr />
<h2>Upstream proposal</h2>
<p dir="auto">I intend to open two MRs on <a href="https://gitlab.com/ubports/development/core/lomiri-location-service" target="_blank" rel="noopener noreferrer nofollow ugc">gitlab.com/ubports/…/lomiri-location-service</a>:</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>MR</th>
<th>What</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>MR 1</td>
<td><strong>Bug fix:</strong> mutex/EDEADLK race in <code>register_callbacks()</code></td>
<td>Ready to propose</td>
</tr>
<tr>
<td>MR 2</td>
<td><strong>Feature:</strong> <code>GetVisibleSpaceVehicles</code> D-Bus method</td>
<td>Ready, needs API discussion</td>
</tr>
<tr>
<td>—</td>
<td>Watchdog thread, LLS_DEBUG, build script</td>
<td>Navius-specific; not proposing upstream</td>
</tr>
</tbody>
</table>
<p dir="auto">Before opening the MRs I wanted to share the work here and get feedback, especially on whether there is already upstream work addressing the Waydroid race condition or the <code>GetVisibleSpaceVehicles</code> API.</p>
<p dir="auto">Any review or testing on other devices is very welcome. Full patch documentation: <a href="https://github.com/woodyst/lomiri-location-service/blob/navius/doc/navius-patches.md" target="_blank" rel="noopener noreferrer nofollow ugc">doc/navius-patches.md</a>.</p>
]]></description><link>https://forums.ubports.com/topic/12310/lomiri-location-service-gps-reliability-patches-navius-branch-v3.4.1-navius5</link><generator>RSS for Node</generator><lastBuildDate>Thu, 28 May 2026 19:26:17 GMT</lastBuildDate><atom:link href="https://forums.ubports.com/topic/12310.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 28 May 2026 17:36:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to lomiri-location-service GPS reliability patches (navius branch, v3.4.1+navius5) on Thu, 28 May 2026 19:09:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/projectmoon" aria-label="Profile: projectmoon">@<bdi>projectmoon</bdi></a> A GPS Navigator. I was a lot of time searching for a GPS navigator with the functionality I like for me, but I didn't found anyone. So I decided to code my own. I'm reviewing it now for publishing it.</p>
]]></description><link>https://forums.ubports.com/post/96096</link><guid isPermaLink="true">https://forums.ubports.com/post/96096</guid><dc:creator><![CDATA[woodyst]]></dc:creator><pubDate>Thu, 28 May 2026 19:09:50 GMT</pubDate></item><item><title><![CDATA[Reply to lomiri-location-service GPS reliability patches (navius branch, v3.4.1+navius5) on Thu, 28 May 2026 19:06:27 GMT]]></title><description><![CDATA[<p dir="auto">What is the Navius app, exactly?</p>
]]></description><link>https://forums.ubports.com/post/96095</link><guid isPermaLink="true">https://forums.ubports.com/post/96095</guid><dc:creator><![CDATA[projectmoon]]></dc:creator><pubDate>Thu, 28 May 2026 19:06:27 GMT</pubDate></item><item><title><![CDATA[Reply to lomiri-location-service GPS reliability patches (navius branch, v3.4.1+navius5) on Thu, 28 May 2026 18:48:53 GMT]]></title><description><![CDATA[<p dir="auto">I misstyped the patch documentation link. Te correct one is: <a href="https://github.com/woodyst/lomiri-location-service/blob/main/doc/navius-patches.md" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/woodyst/lomiri-location-service/blob/main/doc/navius-patches.md</a></p>
]]></description><link>https://forums.ubports.com/post/96092</link><guid isPermaLink="true">https://forums.ubports.com/post/96092</guid><dc:creator><![CDATA[woodyst]]></dc:creator><pubDate>Thu, 28 May 2026 18:48:53 GMT</pubDate></item></channel></rss>