Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / music / AGENTS.md

AGENTS.md10.8 KiBRenderedCodeRaw
1# AGENTS.md — music/ (':music')
2
3> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `music/` + allowed shared modules. Do not root-scan.
4
5_Install: ./install music (dev by default)._
6- Gradle: :music / dir: music/
7- Package roots present: ui, data, platform, intents, service, sync
8- Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity), Route.kt, Navigation.kt, ui/WearMainActivity.kt
9- Deps: :library:room, :library:image, :sdk:cast, :library:media, :library:wearlink, :library:log, Wear Compose (material + foundation)
10- Metadata: metadata_data/music.md (present)
11- Rust: no / screenshotTest: yes
12
13## Overview
14**Purpose:** Offline M3Y music player — local library by song/album/artist/playlist, synced lyrics from file tags, Cast to TV, Android Auto. No network permission at all.
15**Key features:**
16- Library scan into Room (`Music`/`Album`/`Artist`/`Playlist`) with `SyncWorker`; now-playing + queue + shuffle, wide-layout player
17- Embedded + synced lyrics views; playlist CRUD as dialog routes (`CreatePlaylistDialog`, `DeletePlaylistDialog`, `RenamePlaylistDialog`, `AddToPlaylistDialog` with `DialogPage()` metadata and stateless contents under `ui/dialogs/`); audio-preview + play/search assistant intents + capped assistant reads (now-playing summary, playlist names/counts ≤10, playlist track titles ≤10, search capped at 20 hits)
18- Playback in `service/PlaybackService` (local) / `CastingPlayer` (remote via `:sdk:cast`); `MusicLibraryTree` exposes the Auto tree
19**Architecture / data-flow:** `ui/` tabs + now-playing → `platform/MusicViewModel` (+ `MusicUiContract`) + `platform/PlaybackManager` → `data/MusicRepository` over Room + `service/PlaybackService`; `platform/CastPlayback` + `service/CastQueue` take over when casting.
20**Entry points + reading order:** `Route` → `MainActivity.kt` → `Navigation.kt` → `ui/MusicTabsScreen.kt` → `platform/PlaybackManager.kt` → `service/PlaybackService.kt` → `data/MusicRepository.kt`.
21**Gotchas:**
22- Playback state lives in the service, not the ViewModel — UI binds, never owns. The watch UI is bound the same way: it renders phone-reported state from `data/WearMusicStore` and sends ops, never owns playback.
23- Cast and local are separate player paths sharing one queue model; test handoff, not just each side
24- While casting, the TV plays single resources and knows no repeat/shuffle: `CastQueue` honours the phone's repeat mode on a TV `ended` (repeat-one re-offers the same track, repeat-all wraps via the local queue, shuffle order comes from the local timeline)
25
26## One APK, two form factors (phone + watch)
27This module is the single Music APK for phones and watches: same
28`applicationId = "com.vayunmathur.music"` and signing on both, as the
29WearLink handshake requires. The manifest deliberately declares no
30`android.hardware.type.watch` feature (required=true would block
31phones; required=false is disallowed for this feature), plus
32touchscreen not-required and
33`com.google.android.wearable.standalone=false`; distribution is
34sideload/F-Droid, not Play's watch channel, so the APK installs on
35phones and watches alike. `platform/FormFactor.kt` reads
36`PackageManager.FEATURE_WATCH` at runtime: `MainActivity` (the sole
37launcher entry) forwards watches to `ui/WearMainActivity` before any
38phone state loads; phones get the tab UI. The phone-only entry points
39gate on the same signal: `sync/WearMusicSync.start` (phone conduit
40client node) is a no-op on a watch, and `service/PlaybackService` creates no
41player or session on a watch.
42
43## Wear sync (Watch conduit client)
44**Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.music.WearMusicProtocol`; the golden-JSON tests in this module pin the shared code's wire format.
45- Page snapshots: conduit data item (`/music/page`, phone -> watch), requested by message (`/music/page-request`, watch -> phone)
46- Now-playing: conduit data item (`/music/playback`, phone -> watch)
47- Watch state: conduit data item (`/music/watch-state`, watch -> phone)
48- Playback/library ops: conduit message (`/music/op`, watch -> phone)
49- Search: conduit message (`/music/search-request`, watch -> phone)
50- **Transport: Watch conduit client** — phone side `sync/WearMusicSync.kt` and watch side `sync/WearLinkBridge.kt` both use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `music`); this app owns no RFCOMM link and holds no Bluetooth permission for this channel, so neither entry activity prompts for Bluetooth. With the Watch app absent the node reports `NotInstalled`/`Unavailable` and the sync stays idle; playback state republishes on conduit `Connected`, and pending watch ops resend on `Connected`. `FormFactor` picks the side at runtime, so only one of the two nodes runs on a given device.
51- **Push triggers:** the publish also runs on the phone Watch app's scheduled sync-trigger intent (`sync/ConduitSyncTriggerReceiver`, exported only under the `CONDUIT` signature permission, invoking `WearMusicSync.triggerPush()` — no UI, no prompt). Data arriving while the receiving process is dead lands in the conduit host's persistent store and replays on registration.
52- **Open on phone:** the watch request (`/<appId>/open-on-phone` conduit message; camera: `OPEN_ON_PHONE` op) is handled live by the sync message listener when this app is registered, and otherwise the phone conduit host broadcasts `OpenOnPhoneContract.ACTION` (package-addressed, `CONDUIT` signature permission) to `sync/OpenOnPhoneReceiver`, which launches the main activity as a new task — no phone process needs to be running first.
53
54## Watch experience (in this module)
55- `ui/WearMainActivity` routes `ui/WearRoute` (home / albums / artists / playlists / now playing / queue / search / add-to-playlist / settings) over the phone's pages, rendered from cached page snapshots + streamed playback state in `data/WearMusicStore` (`wear-music-pages.json`), so visited pages work offline.
56- The phone owns the catalog and is the only audio player: the watch stores no music files and no whole catalog, and every playback action is an op executed by the phone's playback service; the watch UI reflects the phone-reported state and never claims an unconfirmed result.
57- Watch listing screenshots are the `group = "wear"` previews in `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by `:music:metadata` into `metadata_data/photos/music/wear/`; phone shots use the `phone` bucket.
58
59## Key files
60### Root — entry + navigation
61- com/vayunmathur/music/MainActivity.kt
62- com/vayunmathur/music/Navigation.kt
63- com/vayunmathur/music/Route.kt
64### data/ — Room library
65- com/vayunmathur/music/data/MusicDatabase.kt
66- com/vayunmathur/music/data/MusicRepository.kt
67- com/vayunmathur/music/data/Music.kt
68- com/vayunmathur/music/data/Album.kt
69- com/vayunmathur/music/data/Artist.kt
70- com/vayunmathur/music/data/Playlist.kt
71### platform/ — ViewModel, playback glue, lyrics
72- com/vayunmathur/music/platform/MusicViewModel.kt
73- com/vayunmathur/music/platform/MusicUiContract.kt
74- com/vayunmathur/music/platform/PlaybackManager.kt
75- com/vayunmathur/music/platform/CastPlayback.kt
76- com/vayunmathur/music/platform/Lyrics.kt
77- com/vayunmathur/music/platform/EmbeddedLyrics.kt
78- com/vayunmathur/music/platform/SyncWorker.kt
79- com/vayunmathur/music/platform/Util.kt
80- com/vayunmathur/music/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`)
81### service/ — playback + Auto tree + cast queue
82- com/vayunmathur/music/service/PlaybackService.kt
83- com/vayunmathur/music/service/MusicLibraryTree.kt
84- com/vayunmathur/music/service/CastingPlayer.kt
85- com/vayunmathur/music/service/CastQueue.kt
86### sync/ — wear companion sync (both sides, one APK)
87- com/vayunmathur/music/sync/WearMusicSync.kt — phone conduit client node; page publish, playback stream, op execution
88- com/vayunmathur/music/sync/WearLinkBridge.kt — watch conduit client node; page/playback receive, op send, watch-state publish
89### Watch experience (ui/ + data/)
90- com/vayunmathur/music/ui/WearMainActivity.kt — watch entry
91- com/vayunmathur/music/ui/WearRoute.kt, WearMusicRoot.kt, WearHomeScreen.kt, WearPageLoader.kt, WearNowPlayingScreen.kt, WearTrackListScreen.kt, WearAlbumListScreen.kt, WearArtistListScreen.kt, WearPlaylistListScreen.kt, WearQueueScreen.kt, WearSearchScreen.kt, WearAddToPlaylistScreen.kt, WearSettingsScreen.kt
92- com/vayunmathur/music/data/WearMusicStore.kt — visited page snapshots + latest playback state (`wear-music-pages.json`)
93### intents/ — assistant playback IPC
94- com/vayunmathur/music/intents/PlayIntent.kt
95- com/vayunmathur/music/intents/SearchIntent.kt
96- com/vayunmathur/music/intents/NowPlayingIntent.kt — `music_get_now_playing` (`NowPlayingData`)
97- com/vayunmathur/music/intents/GetPlaylistsIntent.kt — `music_get_playlists` (names/counts, cap 10)
98- com/vayunmathur/music/intents/GetPlaylistTracksIntent.kt — `music_get_playlist_tracks` (titles, cap 10)
99- com/vayunmathur/music/intents/AudioPreviewActivity.kt
100### ui/ + ui/components/ + ui/dialogs/ — library, player, playlists
101- com/vayunmathur/music/ui/MusicTabsScreen.kt
102- com/vayunmathur/music/ui/HomeScreen.kt
103- com/vayunmathur/music/ui/SongsScreen.kt
104- com/vayunmathur/music/ui/SongScreen.kt
105- com/vayunmathur/music/ui/AlbumScreen.kt
106- com/vayunmathur/music/ui/AlbumDetailScreen.kt
107- com/vayunmathur/music/ui/AlbumDetailContent.kt
108- com/vayunmathur/music/ui/ArtistScreen.kt
109- com/vayunmathur/music/ui/ArtistDetailScreen.kt
110- com/vayunmathur/music/ui/PlaylistScreen.kt
111- com/vayunmathur/music/ui/PlaylistDetailScreen.kt
112- com/vayunmathur/music/ui/NowPlayingScreen.kt
113- com/vayunmathur/music/ui/NowPlayingColumn.kt
114- com/vayunmathur/music/ui/NowPlayingQueue.kt
115- com/vayunmathur/music/ui/NowPlayingWideLayout.kt
116- com/vayunmathur/music/ui/LyricsView.kt
117- com/vayunmathur/music/ui/components/NowPlayingBar.kt
118- com/vayunmathur/music/ui/components/PlayingBottomBar.kt
119- com/vayunmathur/music/ui/components/PlayShuffleRow.kt
120- com/vayunmathur/music/ui/components/ShufflePlayFab.kt
121- com/vayunmathur/music/ui/components/NewPlaylistFab.kt
122- com/vayunmathur/music/ui/components/AddToPlaylistButton.kt
123- com/vayunmathur/music/ui/components/MusicTabsBar.kt
124- com/vayunmathur/music/ui/components/TrackListItem.kt
125- com/vayunmathur/music/ui/AlbumsContent.kt
126- com/vayunmathur/music/ui/ArtistsContent.kt
127- com/vayunmathur/music/ui/PlaylistsContent.kt
128- com/vayunmathur/music/ui/AlbumDetailContent.kt
129- com/vayunmathur/music/ui/ArtistDetailContent.kt
130- com/vayunmathur/music/ui/PlaylistDetailContent.kt
131- com/vayunmathur/music/ui/dialogs/AddToPlaylistDialog.kt
132- com/vayunmathur/music/ui/dialogs/AddToPlaylistDialogContent.kt
133- com/vayunmathur/music/ui/dialogs/CreatePlaylistDialog.kt
134- com/vayunmathur/music/ui/dialogs/DeletePlaylistDialogContent.kt
135- com/vayunmathur/music/ui/dialogs/RenamePlaylistDialogContent.kt
136
137## Verify (this module only)
138```
139./gradlew :music:compileDevKotlin
140./gradlew :music:lint :music:lintVitalRelease
141./gradlew :music:testDevUnitTest
142./gradlew :music:checkMetadata
143```