android: Grain on Android, drawn by HUD's Android kit
MergedThis adds android/, the Android app drawn by hudkit from next/grain.social.json. It also adds the just android* recipes, an android check and a vendored copy of HUD's Android kit.
Must change: any app on the device can repoint a release build at its own server. MainActivity is exported="true". handle() passes any server string extra on the incoming intent to Shell.useServer. That call stores the value in SharedPreferences, swaps serverURL, and restarts every tab. The --es server path is only a dev aid (just android-run), but nothing limits it to debug builds. A malicious app can launch Grain with its own server extra. Grain then calls that server's tools and runs the sign-in (AuthServer.discover(serverURL), a Custom Tab) against it. The override also persists across launches. Only honor the extra when BuildConfig.DEBUG is true. A release build should ignore it and read the stored value only in debug. Also clear any stored server pref on release so a debug-era value can't stick.
Not reviewed. I read the manifest, build files, workflow, Justfile, AGENTS.md, GrainConfig, MainActivity, UpdateGate, Level and Shell. I did not read LevelScreen.kt, ShellScreen.kt, SignInScreen.kt, StoryPager.kt or vendor/hud.sh, because the combined diff was too large to read in this pass. I also skipped the vendored vendor/hud/android/** code, which the body says HUD reviews, and the binary and resource assets.
The android check builds the debug APK, so I did not look at build failures.
android/app/src/main/java/social/grain/MainActivity.ktline 70Outdated
| |
/** A server named, and a link to open as its route. */ | |
private fun handle(intent: Intent) { | |
intent.getStringExtra("server")?.let(shell::useServer) |
The activity is exported, so any app can send this server extra. In a release build it would repoint the app, and its sign-in, at an arbitrary HUD server, and the choice is persisted. Gate it on BuildConfig.DEBUG.
Since my last review, the changes are a data-driven Notifications badge (Tab.badge), an -PappFile option, a workflow formatting change, and a re-vendored HUD (chips list style, ComposeSheet fix). None of these is a problem.
The earlier finding is still open. MainActivity.handle() still calls shell::useServer for any server extra, in release builds too. Shell.useServer writes the value to prefs, swaps serverURL and restarts the tabs. The activity is exported. Any app on the device can therefore send an intent that persistently repoints a release Grain at its own server, and sign-in then runs against that server. This is not fixed. Please do both of these:
- Honor the
serverextra only whenBuildConfig.DEBUGis true. - On a release build, ignore the stored
serverpref and remove it, so a debug-era value can't stick.
android/app/src/main/java/social/grain/MainActivity.ktline 68Outdated
shell.attach(null) | |
} | |
| |
/** A server named, and a link to open as its route. */ |
Gate this on BuildConfig.DEBUG. As written, any app can send this exported activity a server extra and repoint a release build.
Fixed in c31c2b9b: MainActivity honours the server extra only when BuildConfig.DEBUG, Shell.useServer returns at once in a release, and a release build ignores and removes a stored server pref (keptServer). A build's own server is now -Pserver=<url> (BuildConfig.SERVER), next.grain.social by default. Also: each build signs in at its own <applicationId>:/oauth/callback (HUD fa7bdbe), so no other app on hudkit shares the redirect.
The earlier finding is fixed. MainActivity.handle() reads the server extra only when BuildConfig.DEBUG is true. Shell.useServer also returns early on release builds. keptServer() ignores the stored pref on release and removes it, so a debug-era value can't stick. Both things I asked for were done.
I looked only at the code behind that finding. I did not read the rest of the diff since my last review, which also touches the README, .gitignore and the sign-in redirect. The android check builds the debug APK, so I did not look at build failures.
I read the diff since my approval at c31c2b9. It adds push, re-vendors HUD, and updates the README and manifest. The server extra is still honored only when BuildConfig.DEBUG is true, so that earlier fix stands.
Push (Push.kt, and the Shell and MainActivity wiring) holds up:
- The device registers after sign-in and unregisters before sign-out, before an account switch, and before another account signs in.
onNewTokenregisters a rotated token as the signed-in account.- A build without
google-services.jsonmakes no token and registers nothing. - The exported
MainActivitynow also takes asocial.grain.pushextra from any app.Push.tappedonly maps it to an in-app route path, so the worst an outside app can do is open one of the app's own screens.
I did not run the build. The conditional google-services plugin setup and the Firebase BOM are only checked by the android check. I read the vendored HUD changes (Push, the confirm dialog title, and Format.time) only as far as push needs them, since they are reviewed in HUD.
Since my approval at ad9596b, the only change is android/README.md, where the assetlinks.json example is reformatted. The JSON and fingerprints are unchanged. My earlier approval stands.
Thanks. Push was checked end to end on a release build (with grain-android's google-services.json) against a local stack: harness PDS, grain-serve, HUD 84d7175 behind https. Signing in as alice.test registered the FCM token through HUD (social.grain.notification.registerPush 200; a push_token row, platform android); signing out unregistered it (unregisterPush 200, the row gone) before /oauth/revoke. A real delivery needs production's FCM credentials and wasn't tested. 332f9e4 only formats android/README.md for the web check.
6 passed, 2 skipped
- android: Grain on Android, drawn by HUD's Android kit
- main
What changes
Grain on Android.
android/is the next version of grain-android (social.grain, versionCode 16, 0.9.0), asios/is the next grain-ios:next/grain.social.json's tabs along the foot (Home, Explore, Notifications, Profile), each a stack of the views a HUD server resolves, drawn natively by HUD's Android kit (hudkit, Jetpack Compose), againsthttps://next.grain.socialor the server an intent names (just android-run http://10.0.2.2:8787).What it does, as the iOS app does. Home opens the first feed pinned once signed in (the tab's
first); a screen draws its tree as last drawn (LastTree) or its skeleton while it loads, is read afresh each time it shows (a thin line under the bar), pulled to refresh, paged at its foot; itsBargoes up into the top bar. Stories open over the tabs, swiped between and dragged down to close; a story's comments open as a sheet. Signing in is the app file'ssignInover grain-android's photo (typeahead, Create one, the legal line), then HUD's OAuth in a Custom Tab; several accounts are kept, sealed with a Keystore key, and switched from Settings' Accounts. Links to grain.social open as their routes (App Links for the routes' paths, and grain-android'sgrain://profile/…); other links open in a Custom Tab. Titles are Syne at 800, text Plus Jakarta Sans. Belowhttps://grain.social/app-version.json'sandroid.minimumVersionCodeit shows only "Update Grain", remembered offline.HUD's Android kit gets its data layer (HUD 4e58504, 97a888e, 6e7bf60 on app/shell), vendored here at 6e7bf60: calling HUD's tools and uploading, signing in through HUD (PKCE, Custom Tabs, the
place.hud.app:redirect iOS uses), kept accounts, routes, a tab'sfirst, last trees, skeletons, feed interactions, the scheme chosen, push plans.vendor/hud.shcopiesandroid/hudkitand HUD's version catalog, whichandroid/settings.gradle.ktsbuilds as:hudkit.just android,just android-build,just android-run,android/README.md, and anandroidcheck building the debug APK on Linux as grain-android's own workflows do.Why
The iOS app is drawn from the same app file and views as the web; Android had only grain-android, which draws everything itself. This brings Android to the same footing, so a view changed in
next/viewschanges all three.How it was checked
:hudkit:testDebugUnitTest(137 tests, the new data layer's ported from iOS's) and HUD's gallery app builds.just android-build; on an emulator (API 35), signed out against next.grain.social: Home with the stories strip and the feed, a story opened and dragged down, a profile and a gallery pushed and gone back from, Explore, Notifications and Profile asking to sign in.Shortcomings
google-services.jsongrain-android keeps out of its repo).place.hud.app:for the OAuth redirect, so with HUD's gallery app (or a debug and a release Grain) on one device Android asks which app opens it.assetlinks.jsonnames it.Review
Start at
android/app/src/main/java/social/grain/Shell.ktandLevelScreen.kt, which followios/Grain/Shell.swiftandLevelScreen.swift; the kit is HUD's, reviewed there.