11.6 KiB · text History 4934a5d

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, or made for it when it signs in (/api/v1/auth/*).

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
Log-in The family’s shared log-in page: Scan (the QR from Settings → API tokens, its vigil://pair link, or the server and token typed in), Sign in with NEIAM (SSO in a Custom Tab), or Username (email me a sign-in link, or a password). Each way in ends with the same kind of read-only token. See docs/app-login.md
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 (Scan)

  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 and point it at the QR. Or open the link on the phone (the Scan sheet opens filled in; tap Pair), or paste the link or enter the server and token by hand in the sheet.
  4. The app calls GET /api/0/ and keeps the pair only once the server names the token’s owner. A token short of the bundle still pairs; the screens it can’t read say so.

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 the log-in page. Unpair this phone in the menu forgets the token on the phone, but doesn’t revoke it.

The log-in page (Scan, OIDC, Username), the sign-in API and the App Links are described in docs/app-login.md. Signing in with SSO, a password or an emailed link makes a token like the Mobile app one (the same read-only scopes), labelled with the phone’s name, listed and revoked on Settings → API tokens.

App Links need the server to vouch for this app’s signing certificate. /.well-known/assetlinks.json is built from the server’s ANDROID_CERT_FINGERPRINTS env (comma-separated SHA-256 fingerprints). Read them with:

keytool -list -v -keystore release.jks -alias vigil | grep SHA256
keytool -list -v -keystore ~/.android/debug.keystore \
  -storepass android -alias androiddebugkey | grep SHA256

Without them, Android doesn’t verify the links, and sign-in links open in the browser (where they work as before). Scan, SSO and passwords still work.

App Links are for magic links only (/users/log-in/<token>). “Sign in with NEIAM” comes back on vigil://auth?code=… (the server’s redirect_uri), so it works with any server; the code is useless without the PKCE verifier kept in the app.

The App Links host is appLinksHost in app/build.gradle.kts (vigil.neiam.org). It is also the server a fresh install signs in to; Change, next to the server in the OIDC and Username sheets, picks another.

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 open Scan and, under Or paste it, give the address above with the token. For the other ways in, Change next to the server (OIDC or Username sheet) to the same address.

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

Signing in (no token yet) uses /api/v1/auth/*, the API every neiam app shares: see docs/app-login.md.

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, vigil://auth and magic 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/
    VigilLoginHost.kt    # Vigil's glue for the shared log-in page
    login/               # the log-in page, the same in every neiam app:
                         #   Scan | OIDC | Username sheets, Help, App Links,
                         #   PKCE, the /api/v1/auth client
  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
  …/auth/login/          # methods parsing, PKCE, link matching, errors
  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.