11.4 KiB · text History 7ad8440

Vigil Android client

A 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; and triage: resolve, ignore and assign issues from the list or the issue. 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, assigned:me, browser:Firefox, free text). Level, title, culprit, events, users, status, assignee, last seen and project per row. Pages load as you scroll (Sentry’s Link-header cursors); pull to refresh
Triage in the list Swipe right to resolve, left to ignore (from Resolved: right reopens; from Ignored: right resolves, left reopens), with Undo in the snackbar. Long-press to select, tap to add more, then resolve, ignore, assign, resolve in next release or unresolve them all: one request per project. A row that no longer matches the filter leaves the list
Issue Status and assignee; counts, first and last seen, releases; 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
Triage on an issue Resolve, Resolve in next release, Ignore, Unresolve (whichever make sense from its status), and Assign: to you, a member, or nobody. Each with Undo; a refusal shows the server’s reason
Monitors Cron monitors (health, schedule, last check-in, next due) and uptime monitors (up or down, why, response time, certificate expiry), failing ones first

The only changes the app makes are an issue’s status and assignee, through Sentry’s bulk PUT …/issues/?id=…, which needs event:write. A token made with Read-only ticked (or before the app could triage) has no event:write: the app then shows no triage controls, and the issue screen says that a new token, paired again, brings them. The app asks the server for its scopes at every start (Check again asks at once), but a token’s scopes never change, so re-pairing is the way.

Not here, on purpose: delete (it needs project:admin, which the mobile bundle doesn’t carry, so a lost phone can’t delete), comments, sharing, and ignoring “for a while” or “until N more events” (the server’s ignore, like the web’s, is for good).

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 bundle the app uses (org:read, project:read, team:read, member:read, event:read, and event:write for triage), give the token a label and create it. Tick Read-only under it to leave out event:write: the phone can look but not touch.
  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 read bundle it says which scopes, and pairing anyway is your choice. A token without event:write pairs without a word, read-only.

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
GET /organizations/{org}/members/ member:read Sentry’s member shape; who to assign to
PUT /projects/{org}/{project}/issues/?id=…&id=… event:write Sentry’s bulk mutate: {"status": …} and/or {"assignedTo": "user:<id>" | ""}; one per project

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; Account
    Triage.kt            # status actions, undo plans, filter matching
  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; swipes, multi-select
    IssueScreen.kt       # details, triage, latest event, tags
    Triage.kt            # runs a triage with Undo; assign dialog
    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, TriageTest.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.