5.6 KiB · text History 1ba5ec3

CartoSnap for Android

Share photos from the phone’s gallery or camera straight into CartoSnap. Two entries in the share sheet:

  • Add to a trip…: a card with the photos and a dropdown of your trips (and “No trip”), then Upload.
  • Add to last trip: straight into the trip you used last, no questions. The first time, with no last trip yet, it asks.

The app’s own screen signs the phone in, shows the upload queue (with failed photos to retry or discard), and lets you change the last trip.

Uploads that don’t get lost

  • Shared photos are copied into the app’s own storage the moment you share them (the permission to read them ends when the share card closes), then uploaded from there.
  • The queue is files on disk, worked through by WorkManager: it survives the app being closed or killed, the phone restarting, and the network coming and going (it waits for a connection, and backs off on errors).
  • Each photo carries an id (client_ref) the server remembers, so a retry after a lost answer gets back the photo already stored rather than storing it twice.
  • Uploads run as a foreground job with a progress notification.
  • A photo the server will never take (not an image, too big) is set aside with the reason; the rest carry on. A trip that’s gone or that you’ve left doesn’t lose the photo: it lands among your own photos, and the app tells you.
  • If the phone’s key stops working, everything waits, and goes up once you pair again.

Where photos were taken

Android takes the GPS out of photos shared to other apps unless the app may see it. With Allow photo locations on the app’s screen (the media-location permission, plus reading photos), each shared photo that arrives without a position is looked up again as its original:

  • a gallery or Files share: the phone’s media store entry behind it;
  • a Google Photos share: its link wraps the media store entry for a photo that’s on the phone, and that’s opened instead.

What can’t come back is a location that was never in the file: one Google Photos estimated, or one added or edited there, lives only in its cloud, and Google offers no way for other apps to read it. Photos still without one say so when shared; set them on the web (the place search on a photo’s page). See upload/Originals.kt.

Signing in

The log-in page has three ways in, each in a bottom sheet (? opens Help):

  • Pair, as before:
    1. On the web: Settings → Connected devices → Pair a device. It shows the server’s address and a code like XK4F-9TQ2 (one use, ten minutes).
    2. In the app: tap Pair, enter both, and Pair.
  • OIDC: “Sign in with NEIAM” in the system browser (a Custom Tab, with PKCE), handed back to the app on cartosnap://auth.
  • Username: email me a sign-in link, or a password (for accounts that set one). The emailed link, https://cs.neiam.org/users/log-in/<token>, opens the app as a verified App Link; that works for cs.neiam.org only, every other way in works with any server.

Each gives the phone the same kind of key, listed under Connected devices. The API, the security decisions and the server’s deploy notes (ANDROID_CERT_FINGERPRINTS, /.well-known/assetlinks.json) are in ../docs/app-login.md. The page itself is auth/login/ (shared with the sibling apps) and auth/CartosnapLoginHost.kt.

A dev server on localhost isn’t reachable from the phone: set CARTOSNAP_PUBLIC_URL to the laptop’s LAN address (e.g. http://192.168.1.20:4000) so settings shows that, or http://10.0.2.2:4000 from the emulator. Debug builds allow plain http; release builds don’t.

Build

Needs a JDK 17–21 (Android Studio’s jbr/ will do) and the Android SDK (local.properties with sdk.dir, or ANDROID_HOME):

cd android
JAVA_HOME=~/.local/share/JetBrains/Toolbox/apps/android-studio/jbr ./gradlew assembleDebug
# -> app/build/outputs/apk/debug/app-debug.apk
./gradlew testDebugUnitTest   # the queue, error handling, API client and log-in parsing, no device needed
./gradlew installDebug        # onto a connected phone

The same toolchain versions as the sibling apps (../../clayman/android), so the family builds from one Gradle cache.

The API it uses

All under /api/v1, with Authorization: Bearer <key> except pairing:

POST /pair {code, label} → {token, user}
/auth/* the log-in page: methods, password, magic links, the SSO exchange (docs/app-login.md)
GET /me the user
GET /trips trips you can add to
POST /photos multipart photo, client_ref, trip_id? → 201 new, 200 already had it
PUT /device / DELETE /device name / unpair this phone

CI and releases

.forgejo/workflows/android.yml runs the unit tests in android/Dockerfile on every push and, on master, builds a signed release APK and publishes it to the forge’s F-Droid repository, as the sibling apps do. It needs two repository secrets, and skips publishing without them:

  • ANDROID_KEYSTORE: base64 of the release keystore (.jks)
  • ANDROID_KEYSTORE_PASS: its password

Make the keystore once and keep it: Android checks its certificate on every update, so losing it means uninstalling and reinstalling by hand. Its SHA-256 fingerprint goes in the server’s ANDROID_CERT_FINGERPRINTS, so emailed sign-in links open the app (keytool -list -v -keystore release.jks).

keytool -genkeypair -v -keystore release.jks -storetype PKCS12 \
  -keyalg RSA -keysize 4096 -validity 10000 -alias cartosnap
base64 -w0 release.jks   # -> ANDROID_KEYSTORE

The tests alone, as CI runs them:

docker buildx build --target android-test --progress=plain --file android/Dockerfile android