Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ secrets/
/ios
/android

# Gradle output of local Expo modules
/modules/*/android/build/

# local EAS build output (eas build --local --output)
/build/

Expand Down
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ The Expo / React Native player for iOS and Android, with its own `package.json`,
- **`ios/` and `android/` are generated** (Continuous Native Generation, gitignored). Change `app.json`, `plugins/` or `assets/`, never the native folders.
- **iOS uses the UIScene life cycle (`expo-build-properties` `ios.enableSceneSupport`).** Without it an iOS 27-SDK build is killed at launch on iOS 27; drop it with the SDK 58 upgrade, whose template does the same (TESTING.md).
- **OTA cannot reach native code.** The Live Activity card (Lock Screen, Dynamic Island, the Apple Watch Smart Stack) is SwiftUI under `targets/live-activity/` and `modules/live-activity/ios/`, so a change there ships only in a new binary, like a dependency, `patches/`, plugin or native `app.json` change; the JS that drives it (`src/hooks/useLiveActivity.ts`) is OTA-able. The same holds for the App Intents (Siri, Shortcuts): Swift under `targets/live-activity/_shared/` and `modules/app-intents/ios/`, JS under `src/intents/`. `SubwaveLiveAttributes.swift` is compiled into both and must stay byte-identical (`npm test` checks): a mismatch stops the card rendering instead of failing the build.
- **Android Auto's browse session is RNTP's own**, reached through the patch's `MediaBrowserBridge`; `modules/android-auto` only lists stations, and a pick reaches `service.ts` as `remote-play-id`. Play enforced against a TTS-reading app once (#477); TESTING.md has the history and the device check.
- **The station password is not the station login** (#478). Every check is the fail-closed `POST /station-auth`, and only the controller's own answers count: a 200 with its `{ ok: true }` body is a right password and a 401 with its `{ ok: false }` body a wrong one, while anything else keeps a saved password and saves no typed one (`stationAuthResult`, #2143, #2164); the password rides the stream as `?auth=` so Cast works; `createApi` reads it through a getter because the feed reset and the Live Activity lifecycle key on the `api` object's identity, so rebuilding the client on unlock would reset both. While playback is stuck, `src/lib/stuck-password-check.ts` asks again after every answer but a denial, never within 120 s of the last check or before a 429's `Retry-After` runs out, capped at the route's own window: it allows a household's address 20 attempts per 15 minutes (#2141, #2164). When the gate's stop takes a tuned-in listener off the air, the right typed password tunes them back in with no second press (`src/lib/gate-resume.ts`, the twin of the web's `lib/gateResume.ts`), through `tune`, so it is a listener's own load in `stream-recovery.ts`. `useStationGate` outlives a station switch, so the hold names the `api` it was taken on, and `tune` toggles, so it never runs for a listener already tuned in.
- **Every stream reload goes through `src/lib/stream-recovery.ts` while the player is mounted** (#2114, #2139): one at a time, and never on a state event alone. A listener's own load (a tune-in, a retune, a Play from the lock screen, a headset, CarPlay or Bluetooth) always loads, queued behind one in flight. `service.ts` hands a remote Play to the mounted player (`src/lib/remote-play.ts`) and loads directly only when none is mounted, which Android's headless service allows; an App Intent's tune-in and station switch do the same (`src/intents/tune-flow.ts`). The watchdog, churn guard and error backoff each check the native media clock first, because a reload re-sends Icecast's burst and the listener hears audio twice; a regained link reads it through the pending check it brings forward, and with none pending reloads at once. Every load is checked even when it reports no state (iOS drops a repeated Loading, #2143), and an automatic reload is a failure until its item stays up, so a hung station backs off to 60 s. Playing resets that only provisionally: an item that fails after stopping within 4 s of its first Playing, judged from the moment it stopped, takes the reset back, and the reload after it waits at most 16 s, so a stream cut a moment in can't reload 35-60 times a minute. A stall never counts, however early, and stays on the 6 s watchdog: Icecast closes a stalled socket about 15 s after its source stops, so a longer wait hears that close as a failure, and a flapping source climbs to a minute of silence. A hold counts as the item's Playing, because JS can miss the real one. None of this runs during an iOS audio interruption (a call, Siri), which freezes the clock without a state event.
- **Every stream reload goes through `src/lib/stream-recovery.ts` while the player is mounted** (#2114, #2139): one at a time, and never on a state event alone. A listener's own load (a tune-in, a retune, a Play from the lock screen, a headset, CarPlay or Bluetooth) always loads, queued behind one in flight. `service.ts` hands a remote Play to the mounted player (`src/lib/remote-play.ts`) and loads directly only when none is mounted, which Android's headless service allows; an App Intent's tune-in and station switch do the same (`src/intents/tune-flow.ts`), and so does an Android Auto pick. The watchdog, churn guard and error backoff each check the native media clock first, because a reload re-sends Icecast's burst and the listener hears audio twice; a regained link reads it through the pending check it brings forward, and with none pending reloads at once. Every load is checked even when it reports no state (iOS drops a repeated Loading, #2143), and an automatic reload is a failure until its item stays up, so a hung station backs off to 60 s. Playing resets that only provisionally: an item that fails after stopping within 4 s of its first Playing, judged from the moment it stopped, takes the reset back, and the reload after it waits at most 16 s, so a stream cut a moment in can't reload 35-60 times a minute. A stall never counts, however early, and stays on the 6 s watchdog: Icecast closes a stalled socket about 15 s after its source stops, so a longer wait hears that close as a failure, and a flapping source climbs to a minute of silence. A hold counts as the item's Playing, because JS can miss the real one. None of this runs during an iOS audio interruption (a call, Siri), which freezes the clock without a state event.
- **The idle skip changes only the native rate, never seeks or reloads** (#9, the port of web's `idleSkip.ts`, kept in step with it). It runs on an MP3 load in the foreground, reads `/state` only after that load's first Playing, and ends on any stall, pause, interruption or backgrounding, since JS timers can stop while the 8x would not. `loadAndPlay` resets the rate to 1x because RNTP carries it to the next item. What it shed reaches the feed as `leadTrimMs`, so the track clock and the DJ's lines move with the listener.
- **Playback lines go through `plog` (`src/hooks/usePlayer.ts`), and are redacted before they are stored** (#2140). Release builds keep the last few hundred for the About sheet's Share playback log, so `src/lib/playback-log.ts` strips the station password, the Station login, URL queries and route device names first; a line that can carry a new kind of secret needs a rule and a test there. `PlaybackLog.add` never throws, because `plog` runs mid-reload and ahead of each event's dispatch: a line it can't redact is lost, never stored raw (#2160).
- **Every request to a station sends the Station login as a header, from `loginHeaders` (`src/lib/api.ts`)** (#764, #1873): API calls go to the credential-free base, and images get the header too. Android's fetch and image loaders, and AVPlayer, ignore URL userinfo.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Native iOS + Android player for [SUB/WAVE](../README.md) — built with Expo + r
## Stack

- **Expo SDK 57** (RN 0.86, React 19, New Architecture) · **expo-router** (file-based)
- **react-native-track-player** — background audio + lock-screen / CarPlay controls (Android Auto is intentionally not declared — Google Play rejected it under the Auto content policy, #477)
- **react-native-track-player** — background audio + lock-screen / CarPlay controls, and the session Android Auto browses (`modules/android-auto`; Play enforced against an earlier declaration, #477, so this is a second attempt)
- **react-native-google-cast** — Google Cast sender (Chromecast / Nest / Android TV). The Cast device fetches the stream itself; the phone becomes a remote (`src/hooks/useCast.ts` merges cast state over the local player). Uses the Default Media Receiver, so no receiver registration. Basic-auth stations can't cast (the `Authorization` header can't ride along) — the button hides for them.
- **AirPlay** (iOS) — a local Expo module (`modules/airplay-route-picker`) wraps `AVRoutePickerView`; routing itself is system-level, the button just makes it discoverable in-app.
- **NativeWind 4** (Tailwind for RN) — reuses the web's class names + the 7 theme tokens
Expand Down
2 changes: 1 addition & 1 deletion docs/PRODUCTION-READINESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ The pipeline is already proven (ascAppId `6778786696`, submit config in `eas.jso
- Lock-screen metadata + persona/cover swap on song change
- Headphone unplug → pauses; resume returns to live edge (validates A3)
- Phone-call interruption + resume (`autoHandleInterruptions`)
- CarPlay controls (iOS; Android Auto intentionally not declared — Play policy)
- CarPlay controls (iOS) and the Android Auto station list (Android)
- Wifi→cellular switch: banner shows, reconnect within a beat (validates A1)
- Airplane-mode cold start: banner shows, no stuck splash
- Station off-air mid-listen
Expand Down
2 changes: 1 addition & 1 deletion docs/QA-CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Mark each box per platform. Note the device + OS version you tested on.
## Platform controls

- [ ] **iOS** — **CarPlay**: SUB/WAVE appears, shows now-playing, Play/Pause/Stop work.
_(Android Auto is intentionally **not** declared — rejected by Google Play under the Auto TTS-content policy; nothing to test there.)_
- [ ] **Android** — **Android Auto** (Desktop Head Unit or a car): the saved stations are listed; a tap plays and opens Now Playing; play/pause work; "play <station name>" by voice switches station; force-stopped app → connect → pick a station still plays (TESTING.md, Android Auto).
- [ ] **iOS 17+** — **Live Activity appears on tune-in**: lock the phone → the SUB/WAVE card is on the Lock Screen with station name, title, artist, cover and a running clock. Tune out → the card disappears.
- [ ] **iOS 17+** — **Card tracks the broadcast while backgrounded**: leave it locked across a song change → title/artist/cover swap and the progress bar restarts. While the DJ talks, the artist line + artwork swap to the persona (same as the lock screen).
- [ ] **iOS 17+** — **Cover art renders**, not the fallback disc mark. _(a disc mark on every track means the App Group entitlement is missing on one side — see TESTING.md)_
Expand Down
96 changes: 86 additions & 10 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ RNTP 4.1.2 is not natively New-Architecture-compatible — out of the box, Andro
playback crashes with `You should not use ReactNativeHost directly in the New
Architecture` from `MusicService`. **The fix is `patches/react-native-track-player+4.1.2.patch`**,
whose New Architecture half is two source edits (the rest of the patch is the
progress and iOS metadata fixes described below):
progress, iOS metadata and Android Auto changes described below):

- `MusicModule.kt` — routes async `@ReactMethod`s through a Unit-returning
`launch` helper (TurboModule interop requires void-returning async methods).
Expand All @@ -53,6 +53,15 @@ The iOS metadata patch clears omitted song-clock fields and preserves artwork
on progress-only refreshes, while retaining `isLiveStream` and the LIVE controls.
These changes require a new binary, not an OTA update.

The patch also carries Android Auto's half of the player (see "Android Auto"
below). `MediaBrowserBridge` reads the same two pinned KotlinAudio fields to
give the session a `PlaybackPreparer` and hand its token to the browse service,
and clears that token when `MusicService` is destroyed. `MusicModule.setupPlayer`
skips RNTP's no-activity-in-front refusal while a media browser is bound, a
background-setup bypass that only the car's callers can switch on
(`CarCallers`), and turns a start Android still refuses into a rejection
instead of a crash. Every Android session runs through both.

For a device smoke test, play a track with a known duration and inspect
`adb shell dumpsys media_session`: its duration should be the song's duration
in milliseconds, and position should match the app's elapsed time, including
Expand Down Expand Up @@ -253,14 +262,80 @@ stream in the phone app first, then connect the car. RNTP feeds the iOS surface
Play/Pause work; no scrubber (the `isLiveStream` track hides it). On iOS 26+
the Live Activity's `.small` card also appears on the CarPlay Dashboard.

> **Android Auto is intentionally not declared.** The earlier
> `plugins/withAndroidAuto.js` declaration (#444) was **rejected by Google Play**
> (20 Jun 2026) under the Auto App Quality Guidelines: media apps that use a TTS
> engine to read out content aren't permitted on Android Auto, which is exactly
> what SUB/WAVE's AI DJ does. The declaration was removed so the Android build
> stays Play-compliant. iOS CarPlay is unaffected (separate `MPNowPlayingInfoCenter`
> path, no manifest declaration). Revisit only if Google's policy changes **and**
> a compliant `MediaBrowserService` browse tree is added.
### Android Auto — the station list in the car (Android only)

SUB/WAVE lists in Android Auto as a media app: the saved stations, tap one to tune
in, then Auto's own Now Playing screen with play and pause. "Hey Google, play
Night Shift on SUB/WAVE" tunes in by name.

> **Play history.** A manifest-only declaration (#444) was **enforced against by
> Google Play** (20 Jun 2026): *media apps that use a TTS engine to read out
> content aren't permitted*, which is what the AI DJ does, and #477 removed it.
> This is a second attempt, now with a real browse tree. If Play enforces again,
> remove `modules/android-auto` from the build rather than shipping around it.

The pieces, all in a new binary (none of it reaches a phone over the air):

- **`modules/android-auto`** declares the car app (`subwave_automotive_app_desc.xml`
and the `com.google.android.gms.car.application` meta-data, merged from the
module's manifest) and `SubwaveBrowseService`, a `MediaBrowserServiceCompat`.
It lists the stations JS mirrors into SharedPreferences (`setStations`, from
StationContext beside the Siri mirror), names and bases only.
- **The browse session is the player's own.** The RNTP patch's
`MediaBrowserBridge` hands the service KotlinAudio's session token, and gives
the session a `PlaybackPreparer`: Auto's play-from-id and voice search become
RNTP's `remote-play-id` and `remote-play-search` events, which 4.1.2 declares
but never fires. `service.ts` answers them with `tuneIn` / `tuneInByName`
(`src/intents/tune.ts`), the tune-in Siri uses, so a pick goes through
`tune-flow.ts` like an App Intent's: with the player mounted it is handed to
it, and so to StreamRecovery, and a pick of another station switches through
it; only with none mounted does it load the stream itself. Play on an idle player still
takes the connector's own path (`onPrepare` just prepares).
- **The car can launch the app with no screen.** The session exists only once JS
has set the player up, so the first connection starts React Native and runs the
`SubwaveCarConnect` headless task (`src/intents/car.ts`), which calls
`setupPlayer()` and nothing else: Auto forbids autoplay on launch. RNTP refuses
`setupPlayer` with no activity in front; the patch lets it through while a
media browser is bound (Android allows the foreground service then), and turns
a refused start into a rejection instead of a crash.
- **System UI's resumption query is refused** (`EXTRA_RECENT` → no root): it
would otherwise start the app in the background on every boot.
- **Only the car, the Assistant and the system get a root** (`CarCallers`,
after Google's media sample): this app, the system UID, a platform-signed
caller or one holding `MEDIA_CONTENT_CONTROL`, or Android Auto, Automotive's
media centre or the Google app when the package owns the calling UID and is a
system app or installed by Play. Any other app gets no root, so it can't read
the saved stations or start the player in the background.
- **A session token is taken once.** `MediaBrowserServiceCompat` accepts one,
so the bridge clears its token when `MusicService` is destroyed, and a browse
service still holding the dead one answers no root until its clients unbind;
the car's next bind gets a fresh service that waits for the next session.
- **A prepare doesn't play.** A pick with `playWhenReady` false (the
Assistant's prepare-then-play) is held in JS (`src/intents/car-picks.ts`) and
the next Play tunes in to it; pause or stop drops it. A refused or failed
pick is a line in the playback log.
- **A spoken name that matches nothing plays the station listened to last**,
as Siri does: a generic word ("play radio") names no station.

Testing needs the Android Auto app on a phone and Google's **Desktop Head Unit**
(SDK Manager → SDK Tools → Android Auto Desktop Head Unit Emulator). In Android
Auto's settings tap the version 10 times for developer mode, then ⋮ → **Start head
unit server**; `adb forward tcp:5277 tcp:5277` and run `desktop-head-unit`. Check:
the list shows each saved station with its host; a tap plays and opens Now
Playing, with the DJ's title and artwork; play and pause work; adding a station on
the phone updates the list; "play <station name>" by voice switches station. Then
cold: force-stop the app, connect, pick a station (it must play), then open the
phone app (it must show the same playback). With the phone app open, pick
another station in the car, then the playing one again: the playback log shows
`intent station switch: handed to the player` and `intent tune-in: handed to
the player`, never a direct load. Then the session restart: with the
car connected, swipe the app away (or reload JS in a dev build), reconnect, and
pick a station; it must play, not show a dead session. `adb shell dumpsys
media_session` should list one SUB/WAVE session. Finally a **release build**
(`eas build --profile preview` or `./gradlew :app:assembleRelease`): the bridge
reads KotlinAudio's fields by reflection, so only R8's output proves the keep
rules still pin them, and the car's list, a pick and play/pause must all work
there too.

### iPad — every orientation, Split View, Stage Manager

Expand Down Expand Up @@ -552,7 +627,8 @@ port types without device names, with `Other` for a word that isn't a known port
## Known issues / gotchas

- **`patches/react-native-track-player+4.1.2.patch`** contains the RNTP new-arch
and media-session progress fixes (see "Architecture-critical facts"). It was previously bloated
and media-session progress fixes and Android Auto's `MediaBrowserBridge` (see
"Architecture-critical facts"). It was previously bloated
to 229 files with accidental Gradle build artifacts; slimmed in 2026-06 and
re-verified with a clean `BUILD SUCCESSFUL` before the progress fix was added.
Keep it lean — never run `patch-package` after a Gradle build has populated
Expand Down
Loading
Loading