Skip to content

feat(app): Android Auto error states, Stations tab, and a build flag - #17

Draft
perminder-klair wants to merge 1 commit into
mainfrom
feat/android-auto-fixes
Draft

perminder-klair wants to merge 1 commit into
mainfrom
feat/android-auto-fixes

Conversation

@perminder-klair

Copy link
Copy Markdown
Contributor

Follows #16 (Android Auto station list, 967d0bd), on main after #15 (CarPlay). Fixes the gaps a read-only review of #16 against Google's media app docs and car app quality guidelines found, then puts Android Auto behind SUBWAVE_ANDROID_AUTO=1, as CarPlay is behind SUBWAVE_CARPLAY=1.

Summary

Android Auto, made reviewable and switchable:

  • A failed pick shows the car why, instead of a silent line in the playback log. The RNTP patch's MediaBrowserBridge.showError calls ExoPlayer's setCustomErrorMessage, which puts the session in STATE_ERROR with the message, and Auto shows it in place of Now Playing. The next pick clears it, and so does audio playing.
  • A cold start that never gets a session fails in 8 s, not never. If setupPlayer rejects or no token arrives, the car gets an error session (SUB/WAVE couldn't start. When it's safe, open SUB/WAVE on your phone.), and the pending React Native start is reset.
  • One browsable Stations tab (the active station first), not playable items at the root, which Google's root hints don't allow by default. The hints are honoured.
  • An empty state: with no station saved, the tab holds No stations yet — When it's safe, add one in SUB/WAVE on your phone (neither browsable nor playable).
  • CarCallers lets in the Gemini app (guideline VC-1; the package is unconfirmed until logcat on the DHU shows it) and Google's Media Controller Test, in debuggable builds only.
  • Behind a build flag: plugins/withAndroidAuto.js declares the browse service, the car meta-data and the automotive descriptor only when SUBWAVE_ANDROID_AUTO=1. Unset, the merged manifest has no Android Auto support at all. eas.json gains production-auto (Play closed testing) and apk (sideload), and production stays without it.
car pick → remote-play-id / -search → service.ts → car-picks.ts
  clearCarError()                                  # every new pick, prepare included
  tuneIn / tuneInByName → TuneReply { ok, reason?, station? }
    not ok:
      reason 'unreachable'? → activeStationLocked()  # one /state read, no stream probe
      carErrorFor(reply, locked) → showCarError(kind, message)
        SubwaveAndroidAutoModule.showError → MediaBrowserBridge.showError
          connector.setCustomErrorMessage(message, code)  # STATE_ERROR in the car
  audio plays → bridge's Player.Listener → clearError()

car binds SubwaveBrowseService (only declared with SUBWAVE_ANDROID_AUTO=1)
  no session yet → CarConnectTask.run + 8 s timeout
    setupPlayer rejects → carSetupFailed() ─┐
    timeout ────────────────────────────────┴→ connectFailed()
      CarConnectTask.reset(); error MediaSessionCompat as the token
  root hints → "subwave-root" → [Stations tab] → stations, active first
                                           or → [No stations yet]

Messages, each sending the driver to the phone only "when it's safe" (guideline VI-1):

Kind Code Car shows
not-saved ERROR_CODE_NOT_SUPPORTED That station isn't saved. When it's safe, add it in SUB/WAVE on your phone.
no-station ERROR_CODE_NOT_SUPPORTED No station yet. When it's safe, add one in SUB/WAVE on your phone.
locked ERROR_CODE_AUTHENTICATION_EXPIRED Night Shift needs its password. When it's safe, unlock it in SUB/WAVE on your phone.
unreachable ERROR_CODE_APP_ERROR Couldn't reach Night Shift. Try again in a moment.

Session restart mid-drive, documented rather than rebuilt. Reading RNTP 4.1.2 shows the dead-session case is narrow. Swiping the app away runs onTaskRemoved, which calls exitProcess(0), so the car rebinds to a fresh process. A JS reload keeps the same MusicService and session, because MusicModule never unbinds and MusicService.setupPlayer returns early once its player exists. MediaBrowserServiceCompat.setSessionToken throws on a second token, so a bound instance can't be repointed. The existing "answer no root until the clients unbind" stays, and TESTING.md says why.

The decision this PR doesn't make: Play's TTS policy

Play enforced against the first car listing (#477, 20 Jun 2026): media apps that use a TTS engine to read out content aren't permitted. A browse tree and error states don't answer that; nothing in code does. docs/RELEASE.md → Android Auto: closed testing first has the plan:

  1. Ship production-auto to Play's closed testing track (alpha). Google's car review is non-blocking there and blocking on open testing and production, while internal testing gets no car review, so internal would never tell us whether the listing passes.
  2. Use review notes saying the DJ voice is generated on the station's server and mixed into the Icecast stream, the app runs no TTS engine, plus a station for the reviewer to play.
  3. If the car review rejects it, ship Play with the flag off (production).
  4. Separately, publish the flagged apk build on GitHub Releases and the website, with the Android Auto developer mode → Unknown sources note, and the note that a Play install and the APK can't update each other.

Whether to make that second attempt at all is yours to call.

Changes

  • RNTP patch (regenerated with patch-package, only the MediaBrowserBridge.kt hunk changed): showError / clearError and a Player.Listener that clears on play.
  • modules/android-auto: SubwaveBrowseService (tab root, hints, empty state, connect timeout, error session), CarConnectTask.reset, CarStations active-first, CarCallers (Gemini, MCT in debug), module functions showError / clearError / setupFailed, strings in res/values/subwave_android_auto.xml. The module manifest now declares nothing.
  • JS: src/intents/car-errors.ts (new), car-picks.ts (clear on each pick, show only the latest failure), tune-flow.ts (TuneReply with reason, station; the Swift bridge still reads only ok, message), tune.ts (activeStationLocked), car.ts (setup failure → carSetupFailed), service.ts wiring.
  • plugins/withAndroidAuto.js (new), in app.json; eas.json profiles production-auto, apk and submit production-auto → alpha, draft.
  • Docs: TESTING.md's Android Auto section and checklist, RELEASE.md's Android Auto plan and profile table, CLAUDE.md's Android Auto rule.

Evidence

  • npm test: 612 pass, 5 skipped, 0 fail (617). New: scripts/android-auto-plugin.test.ts (flag unset, "", 0, true, yes and " 1" declare nothing and write no descriptor; 1 declares the service, the meta-data and the descriptor once, even across two prebuilds; a later flag-off prebuild removes them; the module manifest declares nothing), and in scripts/android-auto.test.ts / intent-tune.test.ts: each error's message and its VI-1 wording, a pick and a prepare clear the last error, only a failed stream asks for the lock, a failing lock check reads as unreachable, an older pick's failure never covers a newer one, CAR_ERROR_KINDS matches Kotlin's errorCode, the car-connect task reports a setup failure, and TuneReply reasons.
  • npm run lint: no errors (the existing onboarding.tsx warning).
  • npx expo prebuild -p android --clean + ./gradlew :app:assembleDebug (JDK 17, /opt/homebrew/opt/openjdk@17; Android Studio's bundled JBR is 25, and TESTING.md says 21+ fails), both flag states: BUILD SUCCESSFUL.
    • Flag off: the merged manifest (app/build/intermediates/merged_manifests/debug/processDebugManifest/AndroidManifest.xml) has no SubwaveBrowseService, gms.car.application, MediaBrowserService or automotive, and the APK has no subwave_automotive_app_desc.xml.
    • Flag on: the diff against flag off is exactly the com.google.android.gms.car.application meta-data and the SubwaveBrowseService with its intent filter; the APK carries res/xml/subwave_automotive_app_desc.xml.
  • npx expo-updates fingerprint:generate --platform android gives the same hash with and without the flag (289eeda…), so one eas update on production reaches all three Android builds.
  • The RNTP patch was regenerated with patch-package before any Gradle build populated RNTP's build/; only the MediaBrowserBridge.kt hunk changed. MediaSessionConnector.setCustomErrorMessage(CharSequence, int) was checked in ExoPlayer 2.19.0's bytecode: a custom error sets state 7 (STATE_ERROR) and setErrorMessage.
  • Not run: EAS builds, submits or any upload (none were asked for), a release build, and anything on a device.

Merge Danger

Door: two-way in code, one-way at Play review

Flag off, the build declares nothing for the car, so merging changes no listing. The first production-auto upload to closed testing starts Google's car review; a rejection there doesn't block the track, and production stays the flag-off fallback.

Blast Radius: every Android listener (native), car users (behaviour)

The patch hunk runs in every Android session: a Player.Listener that only clears an error it set, and a connector reference. With the flag off, nothing binds to browse, so the car-connect task, the timeout and the background-setup bypass never run. TuneReply adds optional fields that iOS's bridge ignores. Native, so it ships in a new binary, not over the air.

Device checks still needed

Nothing here has run on a phone, the Desktop Head Unit or a car (this Mac has no DHU, no emulator image and no device attached). TESTING.md → Testing on a phone with the Desktop Head Unit has the full list:

  • Stations tab, active station first; list updates when a station is added on the phone
  • Each error message appears, then clears on the next pick and when audio plays (dumpsys media_session state 7)
  • Empty state after pm clear
  • Cold start after force-stop: plays, or shows couldn't start with a car setup failed line or the 8 s timeout
  • Gemini's real package in logcat (fix CarCallers if it isn't com.google.android.apps.bard)
  • Media Controller Test: root in debug, none in release
  • Swipe-away and JS reload with the car connected
  • Flag-off install doesn't appear in the car
  • A release build (eas build --profile apk, or assembleRelease after a flagged prebuild) for R8 and the reflection keep rules

A failed car pick now shows the car why (the RNTP patch's
MediaBrowserBridge.showError, through setCustomErrorMessage), cleared on
the next pick and when audio plays; a cold start with no session fails
in 8 s with an error session instead of waiting forever; the root is
one browsable Stations tab (active station first, root hints honoured)
with an empty state; CarCallers admits Gemini and, in debug builds,
Media Controller Test.

Android Auto is now off unless SUBWAVE_ANDROID_AUTO=1 at prebuild
(plugins/withAndroidAuto.js): unset, the merged manifest declares no
car support. eas.json gains production-auto (Play closed testing,
submit track alpha) and apk (sideload); docs/RELEASE.md has the plan.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant