feat(android): keep the onion published through Doze with a foreground service

WireViewModel owned the single Wire node and called shutdown() from
onCleared(), so a backgrounded node died with the UI. Node lifetime is now
arbitrated by a pure policy (NodeLifetime) with two anchors — UI and
keep-alive — and one process-wide owner (NodeHost) that is the only caller
of flush()/shutdown() in the app.

KeepAliveService holds the process in the foreground behind an ongoing
notification from the "keep-alive" channel, started on unlock and stopped
by Lock or the notification action, so peers can still reach the device
while the screen is off.

- foregroundServiceType="specialUse": dataSync is documented as a finite
  transfer (upload/download/backup) and this is an always-on node
- POST_NOTIFICATIONS requested when the node becomes reachable; denial
  keeps the service running with no visible notice instead of failing
- re-unlock with a node the service kept alive adopts it rather than
  reopening the store the live node still holds
- 9 device-free unit tests for the start/stop/re-unlock state machine
This commit is contained in:
apk-dev 2026-09-12 16:34:40 -04:00
commit e923e06891
No known key found for this signature in database
11 changed files with 814 additions and 87 deletions

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Status-bar icon for the keep-alive notification. Notification icons are
alpha masks, so this is a flat white silhouette: an onion bulb with a sprout.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M12,2.6c-0.7,1.2 -1.1,2.3 -1.1,3.2 0,0.5 0.5,0.9 1.1,0.9s1.1,-0.4 1.1,-0.9c0,-0.9 -0.4,-2 -1.1,-3.2z" />
<path
android:fillColor="#FFFFFFFF"
android:pathData="M12,6.4c-2.2,2 -3.6,4.6 -3.6,7.3 0,3.9 1.6,7.3 3.6,7.3s3.6,-3.4 3.6,-7.3c0,-2.7 -1.4,-5.3 -3.6,-7.3zM12,8.2c1.1,1.3 2.1,3 2.1,5.5 0,1.5 -0.5,2.9 -1,3.3 -0.6,-0.4 -1.1,-1.8 -1.1,-3.3 0,-2.5 1,-4.2 2.1,-5.5z" />
</vector>

View file

@ -1,4 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">OnionWire</string>
<!--
Foreground keep-alive. The notification text is the only place the user
can see what is still running once the screen is off, so it names the
moving parts instead of saying "running in the background".
-->
<string name="keep_alive_channel_name">Node keep-alive</string>
<string name="keep_alive_channel_description">Shown while OnionWire keeps your onion address reachable in the background.</string>
<string name="keep_alive_title">OnionWire is reachable</string>
<string name="keep_alive_text">Tor and the outbox are running so peers can deliver messages.</string>
<string name="keep_alive_text_onion">Tor and the outbox are running so peers can reach %1$s…</string>
<string name="keep_alive_stop">Stop keep-alive</string>
<string name="keep_alive_note_off">Reachable only while this app is open.</string>
<string name="keep_alive_note_on">Kept alive — Tor and the outbox run until you tap Lock.</string>
<string name="keep_alive_note_hidden">Kept alive, but notifications are blocked, so the status notice is hidden. Android still lists the service in the Task Manager.</string>
<string name="keep_alive_note_unavailable">Not kept alive (%1$s). The node stops when the app does.</string>
</resources>