Skip to content

feat(native-android): Gruppenchats über die Gruppen-API der Firmware - #27

Open
arturict wants to merge 18 commits into
OffGridCH:mainfrom
arturict:feat/groups
Open

arturict wants to merge 18 commits into
OffGridCH:mainfrom
arturict:feat/groups

Conversation

@arturict

Copy link
Copy Markdown
Contributor

Problem

Die App hat eine Gruppen-Oberfläche, aber sie funktioniert nur mit der simulierten Antenne. Sie ruft group.create und group.send mit einem Format auf, das keine Firmware kennt. Auf Nils' Firmware enden alle group.*-Aufrufe mit E_UNKNOWN_CMD, und Gruppentexte kommen nie an.

Erwartet: Mit der Firmware aus OffGridCH/firmware#16 legt man eine Gruppe aus gekoppelten Kontakten an, verteilt den Schlüssel per Funk, schreibt und empfängt Gruppennachrichten. Auf Firmware ohne Gruppen blendet die App die Funktion aus.

Baut auf #22 auf. Neu ist hier nur der letzte Commit 3b0ba7b. Nach dem Merge von #22 bleibt nur er übrig. Gegenstück in der Firmware: OffGridCH/firmware#16 (Host-Protokoll 1.1).

Change

  • Erkennung: Die App liest features:["groups"] und die Gruppenlimits aus sys.hello. «Gruppe erstellen» erscheint nur, wenn die Antenne Gruppen kann. app_proto ist jetzt 1.1. Nils' main akzeptiert jede Version mit Hauptversion 1.
  • Anlegen und Schlüssel verteilen:
    • createGroup liest das Gruppenobjekt aus result.group. Danach kommt pro Mitglied ein group.sync in die Outbox.
    • Bei E_LOCKED und E_QUEUE_FULL wartet der Sync wie ein msg.send.
    • Den Zustand pro Mitglied («Schlüssel zugestellt», «ausstehend», «fehlgeschlagen») liefert msg.status.
    • Nach einem Reconnect oder Neustart gleicht die App ab wie bei Direktnachrichten.
    • Fehlgeschlagene Schlüssel lassen sich erneut senden.
  • Senden: group.send mit type:"text", ohne ACK. Lange Texte werden an max_group_text_bytes geteilt.
  • Empfangen:
    • group.received zeigt den Kontaktnamen, für Mitglieder ohne eigenen Kontakt die NodeID.
    • group.state holt die Gruppe mit group.get.
    • msg.status mit group_id wird über msg_ref zugeordnet. sent ist bei Gruppen der Endzustand.
    • Beim Verbinden holt group.list/group.get verpasste Beitritte nach.
  • Mitglieder-Screen (Knopf im Chat-Kopf):
    • Mitglieder mit Schlüsselstatus und «Erneut senden».
    • Als Besitzer: Mitglieder hinzufügen und entfernen, beides mit neuem Schlüssel, und die Gruppe löschen (group.delete).
    • Höchstens 8 Mitglieder plus ich, weil die Schlüsselverteilung bei 1 % Duty-Cycle pro Mitglied etwa 43 s dauert.
  • Datenbank v4 mit Migration 3→4 und exportiertem Schema 4.json:
    • GroupEntity bekommt GID, Epoche und Besitzer.
    • group_members hat den Schlüssel (Gruppe, Mitgliedsindex) und eine optionale contactId.
    • Nachrichten speichern die Absender-NodeID.
    • Alte Backups bekommen beim Import eindeutige Indizes.
  • Simulator: alle group.*-Befehle und -Events wie in der Firmware-Spezifikation, mit simuliertem Beitritt und simulierter Verzögerung des Syncs.

Scope

  • 24 Dateien, +2261/−78, nur in native-android/. Davon sind 506 Zeilen das Room-Schema 4.json und rund 830 Zeilen Tests.
  • Neue Testabhängigkeit org.xerial:sqlite-jdbc für den Migrationstest. Sie lag schon über den Room-Compiler im Gradle-Cache.
  • Nicht drin:
    • Standorte in Gruppen; eingehende GEO-Pakete werden ignoriert, die Oberfläche kann nur Text.
    • Reaktionen in Gruppen.
    • Austritt, Übergabe der Besitzerrolle.
  • Gruppen der Datenbankversion 3 (nur Simulator) verlieren beim nächsten Verbinden die Verbindung zur Antenne. Der Verlauf bleibt.
  • Mit Firmware ohne T09: Screens Verbinden und Name, Onboarding-Guard #16 ändert sich nichts. Die Gruppen-Knöpfe bleiben ausgeblendet.

Verification

  • Neue Tests:
    • MigrationTest: Migration 3→4 auf SQLite, Tabellen danach gleich wie das exportierte v4-Schema.
    • SimulatedHeltecGroupsTest: hello, create, sync, send, receive, Beitritt, add/remove, delete gegen den Simulator.
    • MessagingGroupsTest: group.received mit from:null, msg.status mit group_id.
    • GroupSyncTest: Zustände der Schlüsselverteilung, Index-Korrektur beim Backup-Import.
  • ./gradlew testDebugUnitTest lintDebug assembleDebug auf dem Branch: 161 Tests, 0 Fehler, 7 übersprungen (Hardware-Tests ohne Boards). Lint ohne neue Befunde.
  • Zusammen mit feat(native-android): Standort-Pfeil dreht mit dem Handy in die echte Richtung #25 und feat(native-android): Koppeln als geführter Ablauf mit Schritten, Countdown und Testnachricht #26 als Release 0.3.2: 212 Tests, 0 Fehler, Lint ohne Fehler; Release-Build startet auf dem Emulator ohne Absturz.
  • Emulator (API 35, Debug-Build, simulierte Antenne mit Gruppen):
    • Gruppe «Gipfeltour» mit zwei Kontakten angelegt.
    • Beide Schlüssel zugestellt.
    • Nachricht gesendet, Status «gesendet».
    • Der Mitglieder-Screen zeigt den Besitzer, Schlüsselstatus, Entfernen und Hinzufügen.
    • Kein FATAL im Logcat.
Neue Gruppe Gruppenchat Mitglieder
Neue Gruppe Gruppenchat Mitglieder
  • Hardware-Test ausstehend. Er braucht drei Boards mit der Firmware aus feat(mesh): Gruppenchats mit eigenem Sendeschlüssel pro Mitglied firmware#16. Die Boards sind gerade beim Team im Einsatz. Das Ergebnis reiche ich als Kommentar nach.
  • Nicht geprüft: echte Funkstrecke; ob die echte Firmware die Mitgliedsindizes nach group.remove neu vergibt (die App übernimmt, was das Gruppenobjekt meldet); Empfang einer Gruppennachricht auf dem Emulator-Bildschirm (nur im Unit-Test).

Erstellt mit Claude Opus 5.5 in Claude Code via T3 Code, im Auftrag von Artur. Vor dem Merge braucht es ein menschliches Review.

🤖 Generated with Claude Code

arturict and others added 18 commits October 24, 2026 09:19
TokenWrap takes a WrapPurpose so the factory reset can use the
og-reset-wrap-v1 label of link spec 6.11. A new JVM test checks the
unlock and reset envelopes against vectors that tools/wrap_vectors.py
computes with Python cryptography from Security::unwrap, and checks that
an envelope for one purpose or device never verifies for another.
The simulated antenna now follows the lab.3 host contract the app is
written against: msg_ref starts at a random value per boot, msg.pending
lists the queue with its states plus the last 16 final outcomes as
recent, and a message without ACK after its retries reports waiting
(no_ack), is sent again when its contact is heard or every resend
interval, and fails with timeout after the park time. msg.cancel and
contact.delete end pending messages as the firmware does, a restart
drops queue and recent without events, and sys.factory_reset needs the
reset envelope, locks, answers pending and restarts unprovisioned with
the same device_id. sys.hello announces lab_radio and the text codec,
lab.get and lab.set switch OGZ1, and RSSI values are floats as on the
board. Timings are a constructor parameter so tests run fast.
Messages could stay at gesendet for good: msg.status events are lost
while the phone is not connected, and a restart of the antenna cleared
the refs of sent messages so nothing could settle them later.

Every message the antenna accepts now records the link session its
msg_ref was confirmed in (messages.refSession, Room migration 1 to 2).
msg.status events only update messages of the current session. After
the antenna is ready and the contacts are synced, messages of earlier
sessions are settled against msg.pending: still queued takes over the
antenna state and the new session, an entry in recent applies its
final state, and anything else fails with reason lost. Final states
drop ref and session, so a ref from an earlier boot can never reach a
newer message. Open states only move forward. The app does not resend
on its own; the user can retry.

The lab image's waiting state is a new status: a clock and Wartet auf
<Name> instead of a check mark, until delivered or failed. Failures
after the antenna had the message read Nicht zugestellt, refusals by
the antenna keep Nicht gesendet. The migration marks version 1 direct
messages that lost their ref at gesendet as lost.
Unlock and provisioning now follow Security.cpp: every attempt uses a
fresh sys.hello session, a state that changed in between gets one more
try, E_ALREADY_UNLOCKED counts as open, and E_UNLOCK_FAILED,
E_RATE_LIMITED, E_NO_SESSION and E_INTERNAL end the session with their
own German text instead of Die Antenne antwortet nicht. Other codes are
shown with the code. The reason of a sec.state lock is kept for the
connect screen, and a failed re-unlock after an auto-lock now ends the
session with its reason instead of leaving a locked antenna marked
ready.

Alle Daten löschen erases a connected antenna with sys.factory_reset
(method app, token wrapped with og-reset-wrap-v1, the transfer token
from a backup as fallback). Local data is only deleted once the
antenna confirmed; a refusal keeps everything and says why. After the
restart the app provisions the empty antenna again for this phone.
Without an antenna only the phone is cleared, and the dialog says so.

A known antenna that reports unprovisioned (reflashed or reset) is set
up again; a backup transfer token for it is dropped because it can
never open the new vault (the token itself is derived, not stored).
Contacts it no longer lists become unpaired: Neu koppeln in the list
and the chat, a banner with the number on the contact list, and no
sending until they are paired again.
Checked every command the app sends against Commands.cpp on
feature/mesh-direct and fixed what differed:

- RSSI is a float in msg.received and contact views; the app read it
  as an integer and dropped every fractional value. It is now rounded.
- E_BUSY from msg.send means the counter is exhausted (re-pair), not a
  passing state; it no longer blocks the local queue forever.
- contact.rename and contact.delete are not sent for contacts without
  a slot (contact_id must be 1 to 32).
- A final msg.status frees a queue slot, so messages that met
  E_QUEUE_FULL are handed over then instead of at the next connect.

The hardware test accepts the lab.3 waiting state and checks
msg.pending, msg.cancel and recent there.
versionCode 2 (database version 2), versionName 0.1.0-lab3. README,
STATUS and docs/hardware.md describe the security handling, the
factory reset, reflashed antennas, the reconnect reconciliation and
the command fixes, how the lab test APK is built, and that all of it
was checked against firmware source, vectors and the simulator, not
on a board.
The simulated antenna now follows the link spec of firmware 0.3.0
(feature/firmware-hardening) and, with labRadio (default), the lab
image 0.3.0-lab.3 on top:

- sys.hello and sys.boot report mock:false, recovery and storage
  fields; sys.status has radio, storage and security in every state;
  sec.provision, sec.unlock and sec.rotate_token return the spec shapes.
- mesh.get in every state, mesh.set (hop_default, relay_enabled,
  relay_when_locked, retries, cad_enabled) persisted and validated;
  msg.send uses hop_default.
- radio.stats with the spec counters, the lab extras (resends,
  locked buffer) and reset.
- Lab: pair.begin keeps one salt per 5-minute window, lab.get/lab.set
  with fw and ignore_nodes (up to 8 NodeIDs, persisted; an ignored
  peer is out of reach, there are no relays to simulate), compressed
  in msg.send and msg.received.
- Team mode (labRadio = false): a new salt on every pair.begin and
  completion ends the session, failed timeout after the retries, no
  recent, lab.* answers E_UNKNOWN_CMD.

OGZ1 counting follows the lab image: texts that fit 83 bytes raw stay
raw so team boards can read them, only longer ones are compressed.
…beat

Checked against the state machine, error codes and app checklist of the
0.3.0 link spec:

- sys.hello with mock:true is refused (old image without real
  authentication).
- The connect screen says what the session does: antenna starting, new
  antenna being set up (unprovisioned), unlocking, unlocking again
  after an auto-lock or restart, factory reset. The contact list status
  line shows locked, connecting and error states instead of only
  verbunden/getrennt.
- E_RATE_LIMITED has no remaining time, so the app estimates it from its
  own failures like Security::failure (2 s from the third, doubling to
  60 s), shows a countdown and tries once more when it ends.
- sys.ping every second as the spec asks (was 5 s); three unanswered
  pings while open end the session as "antwortet nicht mehr".
- An E_LOCKED answer while the app thinks the antenna is open (lost
  sec.state) opens it again; one relock at a time, skipped when a fresh
  hello says it is still open. A restart seen through sys.boot and every
  lock are kept as lastLock with reason and time.
- After unlocking the app reads sys.status (radio running and last
  error, vault status, secure boot), mesh.get, sec.get_policy and on lab
  images lab.get. An unlocked antenna whose radio does not run is shown
  as "Funkmodul nicht bereit"; E_INTERNAL during unlock names the
  vault_status.
- Commands that write NVS or the vault get the 5 s timeout.
Nils' firmware draws a new salt on every pair.begin, so opening
"Kontakt hinzufügen" twice gave the peer a code the antenna no longer
completes with (the 2026-10-24 field bug, fixed only in the lab image).

Pairing now keeps the session of the last pair.begin and shows it again
when the screen is opened again; it asks for a new one only when less
than a minute is left, after the antenna locked or restarted, or when
the antenna answers E_NO_PAIRING. Leaving the screen no longer sends
pair.cancel (that wiped the salt); only a finished pairing does. After
our own scan the code is never refreshed, the peer may still scan it.

E_NO_PAIRING renews the session (pair.cancel, pair.begin), shows the new
code with a note that whoever scanned the old one has to scan again, and
retries once. A second refusal is the lab image's guard against
completing the same peer code twice: "Diesen Code hat die Antenne schon
verwendet". E_CONTACT_EXISTS offers "Neu koppeln" with replace:true.

The simulator follows the lab fix: a completion ends the session and the
same peer code is refused within the window. PairingTest covers both
firmwares through a small Pairing.Store seam instead of Room.
Messages store hops, RSSI, SNR, retries, the time to the ACK, the OGZ1 flag,
bytes on air and the last device state from msg.send, msg.status and
msg.received (database version 3). A delivery the reconciliation finds only
in msg.pending.recent shows as "zugestellt, während offline". A long press
on any bubble opens the details; on a peer's message together with the
reactions.
The firmware does not fragment (link spec 10). A text that does not fit one
packet, also not OGZ1-compressed on a lab image, goes out as up to four raw
messages cut at spaces, which boards on the team firmware can read.
…e debug key

The release signingConfig reads OFFGRID_RELEASE_STORE_FILE, _STORE_PASSWORD,
_KEY_ALIAS and _KEY_PASSWORD from Gradle properties or the environment.
Without them the release APK is unsigned; a partial setup or a missing
keystore stops the build. Releases no longer take the TCP bridge or the forced
TEXT codec from local.properties.
A new screen under Einstellungen shows device id, NodeID, firmware version
and build, lab or team firmware, vault and security state, the last lock and
device error, lost events and the radio settings. Hop limit, relaying and
relaying while locked go to mesh.set; on lab boards the text codec and the
ignore list (up to eight NodeIDs, not the own one) go to lab.set. radio.stats
can be refreshed and reset. Lab boards always reach it, team boards behind a
switch.
If the answer to sec.rotate_token is lost, the next connect opens the vault
with this phone's token and then forgets the transfer token. Test covers the
import, the lost answer and the old phone being locked out.
…group events)

Show groups only when sys.hello lists the groups feature and take the limits from it.
createGroup reads result.group, queues one group.sync per member and tracks the key
state (queued, pending, delivered, failed) from msg.status, with a resend action.
group.send carries type text and no ack. group.received, group.state and msg.status with
group_id are handled; senders without a contact show their NodeID. The owner can add and
remove members (every remaining member gets a new key) and delete a group.

Room migration 3 to 4 (gid, epoch, owner, member index and nodeId, senderNodeId) with the
exported schema and a test that runs the SQL against the 3.json and 4.json schemas.
The simulator implements the same commands, events and result shapes, plus a simulated
invitation and a sync delay.
@arturict

Copy link
Copy Markdown
Contributor Author

Bitte um Review. Baut auf #22 auf; neu ist nur 3b0ba7b (Gruppenchats über die Gruppen-API aus OffGridCH/firmware#16). Gehört zu Release 0.3.2. Hardware-Test mit drei Boards folgt als Kommentar.

Geschrieben von Claude Opus 5.5 (KI) im Auftrag von Artur.

@arturict arturict left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ergebnis: FAIL. Gruppenaktionen können die falsche Antenne treffen; Rekey-Wiederherstellung und Simulator-Upgrade verlieren Zustand.

Befunde

Kotlin-Pfade relativ zu native-android/app/src/main/java/ch/offgrid/android/.

  1. Blocker: domain/Messaging.kt:388–392, ui/screens/GroupScreens.kt:257–259. Gruppenaktionen benutzen gespeicherte Slots auf der aktuell verbundenen Antenne ohne Geräte-/GID-Prüfung; die Auswahl bietet zudem Kontakte anderer Geräte an. Repro mit tatsächlichem Messaging: lokale Gruppe von A mit Slot 1 löschen, während B verbunden ist und dort ebenfalls Slot 1 belegt ist. Ergebnis: Löschen erfolgreich, B hat null Gruppen. Auch Versand, Sync, Einladungen und Mitgliederänderungen an das gespeicherte Gerät binden; Selektoren filtern und einen Wechsel vor der Übergabe abfangen.
  2. Wichtig: domain/Messaging.kt:424–430, :451. Nach auf der Antenne angenommenem group.add/remove, dessen Antwort nicht gespeichert wurde, lädt Reconnect die neue Epoche mit queueSyncs=false. Vorige Mitglieder behalten DELIVERED, neue erhalten NONE; die neuen Schlüssel werden nicht verteilt. Regressionstest bestätigt Epoche 2 mit Zuständen [delivered, none] ohne passenden Sync. Bei neuer Owner-Epoche alte Referenzen/Zustände verwerfen und alle verbleibenden Mitglieder einreihen oder sichtbar wiederholbar fehlschlagen lassen. Gruppe und Mitglieder gemeinsam transaktional speichern, damit ein Abbruch dazwischen nicht die erneute Aktualisierung verhindert.
  3. Wichtig: link/sim/SimState.kt:57–64. Das neue Gruppenformat kann alte sim-heltec.json mit vorhandener Gruppe nicht lesen. Repro mit unverändertem Serializer: derselbe alte Datensatz ohne Gruppe lädt seinen Kontakt; mit alter Gruppe liefert load() null. SimulatedHeltec.kt:84–85 ersetzt dann den gesamten Flash einschliesslich Identität, Kontakten und Peers. Alte Gruppen migrieren oder gezielt verwerfen und die übrigen Daten erhalten. Das geht über den beschriebenen Verlust der alten Gruppenzuordnung hinaus.

Ticket-Abdeckung

Den neuen Commit 3b0ba7b gegen die Gruppen-API aus firmware#16 geprüft. Capability-Erkennung, grundlegende Befehle, Room-v3→v4-Migration und Import sind schlüssig. Hardware-Abnahme fehlt. Der unveränderte Unterbau aus #22 enthält weiterhin dessen offene Befunde; das Firmware-Gegenstück hat ebenfalls offene Befunde. Kein Ticket verlinkt.

CI

app-checks und docs-check grün. Auf hack-b: vollständiger nativer Lauf mit 161 Tests, 7 Hardware-Skips, 1 Fehler in AntennaSecurityTest:253; derselbe Test bestand isoliert. Lint und Debug-Build separat erfolgreich. Zwei zusätzliche Gruppen-Regressionsfälle schlagen an den oben beschriebenen Assertions fehl. Simulator-Altformat separat reproduziert. git diff --check erfolgreich. Kein eigener Emulator-/Funk-/Boardtest.

— Automatisches Review mit GPT-6.1 Sol (Codex) im Auftrag von @arturict; ersetzt kein menschliches Review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant