9.5 KiB · text History 3ec21a7

Vigil Android client

A read-only phone companion for Vigil: what’s breaking across an organization, each issue’s latest event with its stack trace, and which cron and uptime monitors are failing. It talks to the same Sentry-shaped /api/0 that sentry-cli uses, with an API token scanned from the web.

Sister app to ../../gitgud/android, ../../bigtrippr/android and the rest of the neiam family: the same Compose shell, the web’s own OKLCh themes (plus System, following the phone’s light or dark) and the B612 typeface.

What it does

Surface
Pairing Scan the QR from Settings → API tokens, open its vigil://pair link on the phone, or type the server and token. Verified before anything is stored
Organizations Picked once and remembered; skipped when you’re in only one. Switch from the menu
Issues Across the organization or one project; Unresolved (the default), Ignored, Resolved or All; the web’s search syntax (level:error, release:1.2, browser:Firefox, free text). Level, title, culprit, events, users, last seen and project per row. Pages load as you scroll (Sentry’s Link-header cursors); pull to refresh
Issue Counts, first and last seen, releases, assignee; the latest event’s exception chain and stack, newest call first, in-app frames outlined with their source lines and library frames folded; breadcrumbs, the request, the event’s tags, user and runtime; a tag summary. Open in browser goes to the web page, where it can be triaged
Monitors Cron monitors (health, schedule, last check-in, next due) and uptime monitors (up or down, why, response time, certificate expiry), failing ones first

Nothing in the app changes anything on the server: the token it asks for is read-only.

The summary and description F-Droid shows come from DESCRIPTION.md: the summary on the first line (80 characters at most), a blank line, then the description. CI sends both with every upload.

Stack

Layer Choice
Language / UI Kotlin 2.0 · Jetpack Compose · Material 3
HTTP Retrofit · OkHttp · kotlinx.serialization
Storage EncryptedSharedPreferences for the server and token; excluded from backup and device transfer
Scanner com.journeyapps:zxing-android-embedded (ScanContract)
Build Gradle 9.0 · AGP 8.5.2 · JDK 17–21
SDK minSdk 26 (Android 8) · targetSdk 34

Single activity, single module, no DI framework. Dependency versions match bigtrippr’s and waxx’s, so the family builds from one Gradle cache.

Pairing

  1. Signed in on the web: Settings → API tokens. Tick Mobile app, which ticks the read-only bundle the app needs (org:read, project:read, team:read, member:read, event:read), give the token a label and create it.
  2. A QR appears beside the token, encoding vigil://pair?base=<server>&token=<token>, with the same link under it.
  3. In the app, Scan code and point it at the QR. Or open the link on the phone, or enter the server and token by hand.
  4. The app calls GET /api/0/ and keeps the pair only once the server names the token’s owner. If the token lacks part of the bundle it says which scopes, and pairing anyway is your choice.

A paired phone is its token: there is no separate device list. Revoke the token on the tokens page and the app notices on its next request and returns to pairing. Unpair this phone in the menu forgets the token on the phone, but doesn’t revoke it.

In each organization a token can do only what your role there allows, so the app shows what you’d see on the web. The QR carries a bearer token in plain text: treat a screenshot of it as you would a password.

The server in the code is Vigil’s configured URL (in production https://$PHX_HOST), not the address the page was loaded from.

Build

cd android
echo "sdk.dir=$HOME/Android/Sdk" > local.properties   # or set ANDROID_HOME
./gradlew :app:assembleDebug        # → app/build/outputs/apk/debug/app-debug.apk
./gradlew :app:testDebugUnitTest    # JVM tests: links, times, API contract
./gradlew :app:installDebug         # onto a connected phone or emulator

AGP 8.5 needs a JDK 17–21. A system java that is 25, or a JRE with no compiler, fails with “does not provide the required capabilities: [JAVA_COMPILER]”, which reads like a project problem and isn’t. Point JAVA_HOME at a JDK 21, such as the one Gradle provisioned for the sibling apps:

export JAVA_HOME=$HOME/.gradle/jdks/eclipse_adoptium-21-amd64-linux.2

Or open this directory in Android Studio and press Run.

Against a local dev server

  1. mix phx.server binds http://localhost:4000.
  2. The emulator reaches the host as http://10.0.2.2:4000; a phone on the LAN uses the host’s LAN address.
  3. In dev the endpoint’s URL is http://localhost:4000, so the pairing code names localhost, which the phone can’t reach. Make the token with Mobile app ticked as usual, then on the phone choose Enter it by hand and give the address above with the token.

Debug builds allow plain http://; release builds don’t. The app upgrades http:// to https:// for real domain names (a proxy that doesn’t send X-Forwarded-Proto can put http in the code), never for IPs, localhost or bare host names.

The API contract

ContractTest decodes real responses in app/src/test/resources/api/, written by the server’s test/vigil_web/api/android_fixtures_test.exs. When the API changes shape, capture them again and re-run, from the repo root:

mix test --only android_fixtures
(cd android && ./gradlew :app:testDebugUnitTest)

Endpoints

All under /api/0, with Authorization: Bearer <token>:

Call Scope
GET / any the token’s user and scopes (pairing)
GET /organizations/ any
GET /organizations/{org}/projects/ project:read the project filter
GET /organizations/{org}/issues/?query=&project=&cursor= event:read Vigil’s own, in Sentry’s shape
GET /projects/{org}/{project}/issues/{id}/ event:read details and tag summary
GET /projects/{org}/{project}/issues/{id}/events/latest/ event:read Sentry’s event shape (entries)
GET /organizations/{org}/monitors/ project:read cron monitors, with Vigil’s health
GET /organizations/{org}/uptime/ project:read Vigil’s own

An issue’s id is its short id within the project (SHOP-12 is 12), as in the web’s issue URLs.

CI and releases

.forgejo/workflows/android.yml runs on any push or pull request that touches android/:

  • test: the JVM unit tests, in the container below.
  • publish (master only, after test): builds the release APK, signs it, and uploads it to the forge’s F-Droid repository, with the summary and description from DESCRIPTION.md. versionCode is the CI run number.

Publishing needs two repository secrets, and skips cleanly without them:

Secret
ANDROID_KEYSTORE the release keystore, base64
ANDROID_KEYSTORE_PASS its password

Make the keystore once and keep it somewhere safe. Android checks the signing certificate on every update; lose it and every install has to be uninstalled and redone by hand.

keytool -genkeypair -v -keystore release.jks -storetype PKCS12 \
  -alias vigil -keyalg RSA -keysize 4096 -validity 36500 \
  -dname "CN=Vigil"
base64 -w0 release.jks     # → ANDROID_KEYSTORE

This is the APK signing key, not the F-Droid index key: that one is the forge owner’s and never comes near CI. Add the repository in F-Droid (Settings → Repositories → +) with the URL the publish job prints.

Everything runs in Dockerfile, so the runner needs docker and nothing else, and the same commands reproduce CI locally from the repo root. With podman:

# the tests
podman build --target android-test -f android/Dockerfile android

# a signed release APK into ./apk
podman build --target android-export \
  --secret id=keystore,src=./release.jks \
  --secret id=keystore_password,src=./keystore.pass \
  --output type=local,dest=./apk \
  -f android/Dockerfile android

The build context is android/, not the repository: the root .dockerignore excludes android/ so the server image doesn’t carry it.

Layout

app/src/main/java/org/neiam/vigil/app/
  MainActivity.kt        # nav host; vigil://pair links; theme
  data/
    Links.kt             # vigil://pair parsing; the Link header's next cursor
    TokenStore.kt        # (server, token), encrypted; https upgrade
    PrefsStore.kt        # theme and organization
    VigilClient.kt       # Retrofit interface, error messages
    Models.kt            # JSON shapes; the mobile scope bundle
  auth/
    PairScreen.kt        # scan | link | by hand, verified, scope check
  ui/
    OrgPickerScreen.kt
    HomeScreen.kt        # Issues | Monitors tabs; menu: org, theme, unpair
    IssuesTab.kt         # search, filters, paged list
    IssueScreen.kt       # details, latest event, tags
    MonitorsTab.kt       # cron and uptime
    Loading.kt           # load / refresh / error states
    Common.kt            # app bar title, pills, sections, times
    ThemePicker.kt
    theme/               # the web's themes, status colours and B612
app/src/test/
  …/LinksTest.kt, ContractTest.kt, CommonTest.kt
  resources/api/*.json   # real API responses the contract test decodes

The launcher icon is the web header’s mark (Heroicons’ eye, MIT) as a vector, on afterdark, with a monochrome layer for Android 13 themed icons.