Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
68f4ad8
Token wrap: reset label and firmware vectors
arturict Oct 24, 2026
6d2115c
Simulator: behave like the lab.3 image
arturict Oct 24, 2026
d18cd94
Reconcile the outbox with msg.pending on every connect
arturict Oct 24, 2026
f3b380c
Real security: unlock errors, authenticated reset, reflashed antennas
arturict Oct 24, 2026
d30c36e
Match the commands to Commands.cpp
arturict Oct 24, 2026
5628a36
Version 0.1.0-lab3 and the lab.3 notes
arturict Oct 24, 2026
91f39d6
Simulator: Nils' 0.3.0 serial API and the lab.3 extras
arturict Oct 24, 2026
e680014
Setup and unlock: every device state, rate-limit countdown, 1 s heart…
arturict Oct 24, 2026
69466b6
Pairing: keep the shown code bound to the antenna's session
arturict Oct 24, 2026
3d610b1
One request in flight, as the link spec recommends
arturict Oct 24, 2026
bbd1504
Delivery details per message and a details sheet
arturict Oct 24, 2026
15e77c0
Split texts longer than one packet into several messages
arturict Oct 24, 2026
b667d6c
Release 0.2.0: sign with a release key from the environment, never th…
arturict Oct 24, 2026
a9e57c2
Erweitert / Lab: firmware info, mesh and lab settings, radio statistics
arturict Oct 24, 2026
85a4364
Token rotation: drop the old phone's token once ours opens the antenna
arturict Oct 24, 2026
f2de17f
Ignore list hint: point to the board's own NodeID
arturict Oct 24, 2026
8f52c6d
Hardware test: the app's link, security and pairing code against two …
arturict Oct 24, 2026
0ca1e16
Location screen: compass arrow that turns with the phone
arturict Oct 24, 2026
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
78 changes: 61 additions & 17 deletions native-android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ contacts, messages and settings.

This is a standalone experiment next to the team app in `OffGridCH/app`. It has no remote.

- Package `ch.offgrid.android`, minSdk 26, target/compile SDK 35, version 0.1.0
- Package `ch.offgrid.android`, minSdk 26, target/compile SDK 35, version 0.1.0-lab3 (versionCode 2),
written against the lab firmware image 0.2.0-lab.3 and the team stack `feature/mesh-direct`
- Specs followed: `OffGridCH/firmware/docs/offgrid-link.md` (link), `offgrid-protocol.md`
(radio protocol, crypto test vectors), designs in `offgrid-landing/design/*.png`

Expand All @@ -29,16 +30,33 @@ POSTHOG_KEY=phc_...
| APK | Path | Use |
|---|---|---|
| Debug | `app/build/outputs/apk/debug/app-debug.apk` | Development: test menu, simulated contacts, debug pairing buttons |
| Release-style | `app/build/outputs/apk/release/app-release.apk` | Demos: no test menu, no debug buttons. Signed with the SDK debug key (`CN=Android Debug`), so it installs without a keystore. A real release key is an open decision; none was created. |
| Release | `app/build/outputs/apk/release/app-release.apk` (signed) or `app-release-unsigned.apk` | Download from the landing page: no test menu, no debug buttons, no TCP bridge, no forced codec. Signed only with the release key below; without it the APK is unsigned, never signed with the debug key. |

Release signing reads four values from Gradle properties (`-P…` or `~/.gradle/gradle.properties`) or
environment variables of the same names; no key or password is in this repository:

```sh
OFFGRID_RELEASE_STORE_FILE=/path/to/offgrid-release.jks
OFFGRID_RELEASE_STORE_PASSWORD=…
OFFGRID_RELEASE_KEY_ALIAS=offgrid
OFFGRID_RELEASE_KEY_PASSWORD=…
./gradlew assembleRelease
```

When only some of them are set, or the keystore file does not exist, the build stops with the missing names.

The lab test APK for phones with a lab board is the debug build with `OFFGRID_TEXT_CODEC=ogz1` and
without `OFFGRID_TCP_LINK` in `local.properties`: it switches a lab image to OGZ1 with `lab.set` after
unlocking and counts bytes with the codec, and it uses USB, not the TCP bridge.

## Install

1. Enable USB debugging on the phone (Settings, About phone, tap "Build number" seven times,
then Developer options, USB debugging) and connect it, or start an emulator.
2. Check that it shows up: `adb devices`.
3. Install or update: `adb install -r app/build/outputs/apk/debug/app-debug.apk`
(or the release-style APK). Debug and release-style builds share the package name and the
signing key, so one replaces the other and keeps the data.
(or the signed release APK). Debug and release builds share the package name but not the
signing key: switching between them needs an uninstall, which deletes the app's data.
4. Without adb: copy the APK to the phone and open it in the file manager; Android asks once to
allow installs from that app.

Expand All @@ -47,16 +65,20 @@ A long press on the antenna picture in "Antenne verbinden" switches a debug buil
simulated antenna on a phone as well.

Unit tests cover line framing and the 2048-byte limit, the request/response/event codec and
client (timeouts, parse errors without id, unplugging), the simulated antenna end to end
(provision, pair, send, deliver, wrong token), the crypto test vectors from the protocol spec
(fingerprint, node ids, token wrap), message and name limits, backup encryption, geo
client (timeouts, parse errors without id, unplugging, float RSSI), the simulated antenna end to
end (provision, pair, send, deliver, wrong token) and its lab.3 behaviour (random refs, waiting,
`recent`, cancel, authenticated factory reset, OGZ1), the crypto test vectors from the protocol
spec (fingerprint, node ids, token wrap) and vectors for the unlock and reset wrap computed with
Python `cryptography` from the firmware's `Security::unwrap` (`tools/wrap_vectors.py`), the
outbox reconciliation, the antenna session against the simulator (wrong phone, rate limit,
auto-lock, factory reset, backup token), message and name limits, backup encryption, geo
formatting and analytics.

## Architecture

| Package | Content |
|---|---|
| `link` | `Link` interface, `LineFramer`, `LinkCodec`, `LinkClient` (ids, max 4 in flight, timeouts, events) |
| `link` | `Link` interface, `LineFramer`, `LinkCodec`, `LinkClient` (ids, one request in flight, timeouts, events) |
| `link/usb` | `UsbSerialLink` on usb-serial-for-android (CP210x, CH34x, ESP32-S3 CDC), permission request |
| `link/sim` | `SimulatedHeltec`, an in-process antenna that speaks the same JSON Lines, with virtual peers |
| `crypto` | X25519/HKDF/AES-GCM token wrap, fingerprint, Keystore-backed unlock token |
Expand Down Expand Up @@ -150,7 +172,30 @@ next try.

- **Keys stay on the antenna.** The phone holds only an unlock token derived from a Keystore
key (`HMAC(K_phone, "og-unlock-v1" || device_id)`), wrapped per session with X25519 + HKDF +
AES-GCM as link spec 6 describes. Every `sec.*` call uses a fresh `sys.hello` session.
AES-GCM as link spec 6 describes (label `og-unlock-wrap-v1`, salt the 16-byte session nonce,
AAD the 6-byte device_id, envelope iv || ciphertext || tag = 60 bytes). Every `sec.*` call uses a
fresh `sys.hello` session; a session that expired or a state that changed in between gets one
more try. `E_UNLOCK_FAILED`, `E_RATE_LIMITED`, `E_NO_SESSION` and `E_INTERNAL` each have their
own text on "Antenne verbinden", other codes are shown with the code, and the reason of an
auto-lock (`sec.state`) is shown until the antenna is open again.
- **"Alle Daten löschen" erases the antenna** with `sys.factory_reset` (`method: "app"`, token
wrapped with the label `og-reset-wrap-v1`, link spec 6.11). The phone's data is only deleted
when the antenna confirmed; afterwards the app sets the empty antenna up again for this phone.
Without an antenna only the phone is cleared and the dialog says that the antenna keeps its
contacts.
- **Reflashed or reset antenna:** a known antenna that reports `unprovisioned` is provisioned
again. The token is derived each time, so nothing stored has to be replaced; a token from a
backup import for that antenna is dropped. Contacts the antenna no longer lists become
"Neu koppeln" (slot detached, history kept) with a banner on the contact list; pairing the same
key again reuses the row.
- **Delivery state survives reconnects.** A `msg_ref` is only valid within one boot of one antenna,
and `msg.status` events are lost while the phone is away. Each accepted message stores the link
session its ref belongs to; events only update messages of the current session. After every
connect (antenna ready, contacts synced) the app compares its open messages with `msg.pending`:
still queued takes over the antenna state, an entry in `recent` (lab.3) applies its final state,
and anything else becomes "Nicht zugestellt" (reason `lost`) with "Erneut senden". The app never
resends on its own. The lab image's `waiting` state shows a clock and "Wartet auf <Name>"
instead of a check mark. See `domain/OutboxReconciler.kt`.
- **Pairing is mutual QR.** Both phones scan each other (`pair.begin`/`pair.complete`). The
contact stays "pending" until the first delivered message; the app sends a small ping after
pairing so the firmware can activate it.
Expand All @@ -172,8 +217,6 @@ next try.
"Diese Antennen-Firmware kennt noch keine Gruppen."
- **Composer placeholder** uses the contact's display name ("Nachricht an Anna Meier"), as the
screens skill says. `Chat.png` shows only the first name, `chat-standort.png` the full name.
- **Firmware reset:** contacts the antenna no longer lists become "pending" (slot detached)
instead of being deleted, so history stays and the user can pair again.

## Firmware status

Expand All @@ -183,12 +226,13 @@ image (`lab_radio`) and what only a second board can show. It is kept by the age

## Missing for a real antenna

- Firmware: real token authentication, identity and contacts that survive a reboot, real LoRa
delivery in the team image, the reaction fix (`JsonObjectConst`), a boot animation that does
not block `setup()`, and `group.*` if groups stay in scope.
- App: a test on a physical phone with a Heltec (only the emulator was used so far), battery use
of the background receive service, a release signing key, and a decision on the 83-byte
versus 153-character conflict.
- Firmware: `group.*` if groups stay in scope. Real token authentication, persistent contacts and
real delivery come with the team stack `feature/mesh-direct` and the lab image 0.2.0-lab.3; the
app's side of them was checked against the firmware source, independent vectors and the
simulator, not on a board.
- App: a test on a physical phone with a lab.3 board (security, factory reset, reconnect
reconciliation), battery use of the background receive service, and a
decision on the 83-byte versus 153-character conflict.

## Screenshots

Expand Down
16 changes: 13 additions & 3 deletions native-android/STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ Snapshot for the 02:00 team sync on 2026-10-24. The branch builds and passes
`./gradlew testDebugUnitTest lint assembleDebug assembleRelease` (lint: 0 errors). APKs:

- Debug: `app/build/outputs/apk/debug/app-debug.apk`
- Release-style, signed with the SDK debug key: `app/build/outputs/apk/release/app-release.apk`
- Release 0.2.0 (versionCode 3): `app/build/outputs/apk/release/app-release.apk` when the release key is
configured (README, Build), else `app-release-unsigned.apk`; never signed with the debug key.

Install with `adb install -r <apk>`; details in the [README](README.md). Everything runs against
the simulated antenna on the emulator; a real Heltec is the hardware agent's lane on `main`,
which is merged in (last merge: `1b19e72`, OGZ1 text codec).

## Lab.3 adaptation (0.1.0-lab3)

The app follows the lab image 0.2.0-lab.3 and the team stack `feature/mesh-direct`: real token checks
with their own error texts, the authenticated factory reset behind «Alle Daten löschen», reflashed
boards set up again with their contacts marked «Neu koppeln», and the lost-message fix (waiting state
«Wartet auf <Name>», reconnect reconciliation with `msg.pending`, «Nicht zugestellt» instead of a
permanent «gesendet»). Database version 2. Checked against the firmware source, independent vectors and
the simulator only; see [`docs/hardware.md`](docs/hardware.md), "App against lab.3".

## Done

- **Shared components** match the HTML designs and animate their state changes: buttons,
Expand Down Expand Up @@ -64,5 +74,5 @@ which is merged in (last merge: `1b19e72`, OGZ1 text codec).
contact list header is not in `Kontakte.png`.
4. **Composer placeholder.** `Chat.png` shows "Nachricht an Anna", `chat-standort.png`
"Nachricht an Anna Meier". The app follows the screens skill (display name).
5. **Release key.** The release-style APK is signed with the debug key; a store release needs a
real key.
5. **Release key.** The build signs releases with a key from `OFFGRID_RELEASE_*` Gradle properties or
environment variables; the keystore itself is created and kept outside the repository.
40 changes: 35 additions & 5 deletions native-android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import java.util.Properties

/**
* Release signing from Gradle properties (`-POFFGRID_RELEASE_STORE_FILE=…`, or `~/.gradle/gradle.properties`) or
* environment variables of the same names. No key lives in this repository. Without any of them the release APK
* is built unsigned (`app-release-unsigned.apk`); it is never signed with the debug key.
*/
val releaseSigningNames = listOf(
"OFFGRID_RELEASE_STORE_FILE", "OFFGRID_RELEASE_STORE_PASSWORD", "OFFGRID_RELEASE_KEY_ALIAS", "OFFGRID_RELEASE_KEY_PASSWORD",
)
val releaseSigning: Map<String, String> = releaseSigningNames.mapNotNull { name ->
(providers.gradleProperty(name).orNull ?: providers.environmentVariable(name).orNull)?.takeIf { it.isNotBlank() }?.let { name to it }
}.toMap()
if (releaseSigning.isNotEmpty() && releaseSigning.size < releaseSigningNames.size) {
throw GradleException("Release signing is incomplete, missing: ${(releaseSigningNames - releaseSigning.keys).joinToString()}")
}

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
Expand All @@ -16,8 +31,9 @@ android {
applicationId = "ch.offgrid.android"
minSdk = 26
targetSdk = 35
versionCode = 1
versionName = "0.1.0"
// 3: database version 3 (delivery details), Nils' 0.3.0 contract and the lab.3 settings.
versionCode = 3
versionName = "0.2.0"

// PostHog project key from the untracked local.properties (`POSTHOG_KEY=phc_...`). Empty means
// analytics is a no-op, which is the default for every checkout.
Expand All @@ -35,12 +51,26 @@ android {
buildConfigField("String", "TEXT_CODEC", "\"$textCodec\"")
}

signingConfigs {
if (releaseSigning.isNotEmpty()) {
create("release") {
val store = file(releaseSigning.getValue("OFFGRID_RELEASE_STORE_FILE"))
if (!store.isFile) throw GradleException("OFFGRID_RELEASE_STORE_FILE does not exist: $store")
storeFile = store
storePassword = releaseSigning.getValue("OFFGRID_RELEASE_STORE_PASSWORD")
keyAlias = releaseSigning.getValue("OFFGRID_RELEASE_KEY_ALIAS")
keyPassword = releaseSigning.getValue("OFFGRID_RELEASE_KEY_PASSWORD")
}
}
}

buildTypes {
release {
// Debug-only bridges: no TCP link to a dev machine and no forced TEXT codec in a release.
buildConfigField("String", "TCP_LINK", "\"\"")
// Release-style APK for demos, signed with the SDK debug key so it installs without a
// keystore. A real release key is an open decision; no key was created.
signingConfig = signingConfigs.getByName("debug")
buildConfigField("String", "TEXT_CODEC", "\"\"")
// Unsigned when the release key is not configured (see releaseSigning above), never the debug key.
signingConfig = if (releaseSigning.isNotEmpty()) signingConfigs.getByName("release") else null
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
Expand Down
Loading
Loading