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

Modern-Apps.git / music / AGENTS.md

AGENTS.md10.8 KiBRenderedCodeRaw

AGENTS.md — music/ (':music')

Scoped supplement. Global rules in root AGENTS.md apply. Stay inside music/ + allowed shared modules. Do not root-scan.

Install: ./install music (dev by default).

  • Gradle: :music / dir: music/
  • Package roots present: ui, data, platform, intents, service, sync
  • Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity), Route.kt, Navigation.kt, ui/WearMainActivity.kt
  • Deps: :library:room, :library:image, :sdk:cast, :library:media, :library:wearlink, :library:log, Wear Compose (material + foundation)
  • Metadata: metadata_data/music.md (present)
  • Rust: no / screenshotTest: yes

Overview

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. Key features:

  • Library scan into Room (Music/Album/Artist/Playlist) with SyncWorker; now-playing + queue + shuffle, wide-layout player
  • 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)
  • Playback in service/PlaybackService (local) / CastingPlayer (remote via :sdk:cast); MusicLibraryTree exposes the Auto tree

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. Entry points + reading order: Route → MainActivity.kt → Navigation.kt → ui/MusicTabsScreen.kt → platform/PlaybackManager.kt → service/PlaybackService.kt → data/MusicRepository.kt. Gotchas:

  • 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.
  • Cast and local are separate player paths sharing one queue model; test handoff, not just each side
  • 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)

One APK, two form factors (phone + watch)

This module is the single Music APK for phones and watches: same applicationId = "com.vayunmathur.music" and signing on both, as the WearLink handshake requires. The manifest deliberately declares no android.hardware.type.watch feature (required=true would block phones; required=false is disallowed for this feature), plus touchscreen not-required and com.google.android.wearable.standalone=false; distribution is sideload/F-Droid, not Play's watch channel, so the APK installs on phones and watches alike. platform/FormFactor.kt reads PackageManager.FEATURE_WATCH at runtime: MainActivity (the sole launcher entry) forwards watches to ui/WearMainActivity before any phone state loads; phones get the tab UI. The phone-only entry points gate on the same signal: sync/WearMusicSync.start (phone conduit client node) is a no-op on a watch, and service/PlaybackService creates no player or session on a watch.

Wear sync (Watch conduit client)

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.

  • Page snapshots: conduit data item (/music/page, phone -> watch), requested by message (/music/page-request, watch -> phone)
  • Now-playing: conduit data item (/music/playback, phone -> watch)
  • Watch state: conduit data item (/music/watch-state, watch -> phone)
  • Playback/library ops: conduit message (/music/op, watch -> phone)
  • Search: conduit message (/music/search-request, watch -> phone)
  • 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.
  • 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.
  • 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.

Watch experience (in this module)

  • 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.
  • 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.
  • 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.

Key files

Root — entry + navigation

  • com/vayunmathur/music/MainActivity.kt
  • com/vayunmathur/music/Navigation.kt
  • com/vayunmathur/music/Route.kt

data/ — Room library

  • com/vayunmathur/music/data/MusicDatabase.kt
  • com/vayunmathur/music/data/MusicRepository.kt
  • com/vayunmathur/music/data/Music.kt
  • com/vayunmathur/music/data/Album.kt
  • com/vayunmathur/music/data/Artist.kt
  • com/vayunmathur/music/data/Playlist.kt

platform/ — ViewModel, playback glue, lyrics

  • com/vayunmathur/music/platform/MusicViewModel.kt
  • com/vayunmathur/music/platform/MusicUiContract.kt
  • com/vayunmathur/music/platform/PlaybackManager.kt
  • com/vayunmathur/music/platform/CastPlayback.kt
  • com/vayunmathur/music/platform/Lyrics.kt
  • com/vayunmathur/music/platform/EmbeddedLyrics.kt
  • com/vayunmathur/music/platform/SyncWorker.kt
  • com/vayunmathur/music/platform/Util.kt
  • com/vayunmathur/music/platform/FormFactor.kt — watch detection (FEATURE_WATCH)

service/ — playback + Auto tree + cast queue

  • com/vayunmathur/music/service/PlaybackService.kt
  • com/vayunmathur/music/service/MusicLibraryTree.kt
  • com/vayunmathur/music/service/CastingPlayer.kt
  • com/vayunmathur/music/service/CastQueue.kt

sync/ — wear companion sync (both sides, one APK)

  • com/vayunmathur/music/sync/WearMusicSync.kt — phone conduit client node; page publish, playback stream, op execution
  • com/vayunmathur/music/sync/WearLinkBridge.kt — watch conduit client node; page/playback receive, op send, watch-state publish

Watch experience (ui/ + data/)

  • com/vayunmathur/music/ui/WearMainActivity.kt — watch entry
  • 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
  • com/vayunmathur/music/data/WearMusicStore.kt — visited page snapshots + latest playback state (wear-music-pages.json)

intents/ — assistant playback IPC

  • com/vayunmathur/music/intents/PlayIntent.kt
  • com/vayunmathur/music/intents/SearchIntent.kt
  • com/vayunmathur/music/intents/NowPlayingIntent.kt — music_get_now_playing (NowPlayingData)
  • com/vayunmathur/music/intents/GetPlaylistsIntent.kt — music_get_playlists (names/counts, cap 10)
  • com/vayunmathur/music/intents/GetPlaylistTracksIntent.kt — music_get_playlist_tracks (titles, cap 10)
  • com/vayunmathur/music/intents/AudioPreviewActivity.kt

ui/ + ui/components/ + ui/dialogs/ — library, player, playlists

  • com/vayunmathur/music/ui/MusicTabsScreen.kt
  • com/vayunmathur/music/ui/HomeScreen.kt
  • com/vayunmathur/music/ui/SongsScreen.kt
  • com/vayunmathur/music/ui/SongScreen.kt
  • com/vayunmathur/music/ui/AlbumScreen.kt
  • com/vayunmathur/music/ui/AlbumDetailScreen.kt
  • com/vayunmathur/music/ui/AlbumDetailContent.kt
  • com/vayunmathur/music/ui/ArtistScreen.kt
  • com/vayunmathur/music/ui/ArtistDetailScreen.kt
  • com/vayunmathur/music/ui/PlaylistScreen.kt
  • com/vayunmathur/music/ui/PlaylistDetailScreen.kt
  • com/vayunmathur/music/ui/NowPlayingScreen.kt
  • com/vayunmathur/music/ui/NowPlayingColumn.kt
  • com/vayunmathur/music/ui/NowPlayingQueue.kt
  • com/vayunmathur/music/ui/NowPlayingWideLayout.kt
  • com/vayunmathur/music/ui/LyricsView.kt
  • com/vayunmathur/music/ui/components/NowPlayingBar.kt
  • com/vayunmathur/music/ui/components/PlayingBottomBar.kt
  • com/vayunmathur/music/ui/components/PlayShuffleRow.kt
  • com/vayunmathur/music/ui/components/ShufflePlayFab.kt
  • com/vayunmathur/music/ui/components/NewPlaylistFab.kt
  • com/vayunmathur/music/ui/components/AddToPlaylistButton.kt
  • com/vayunmathur/music/ui/components/MusicTabsBar.kt
  • com/vayunmathur/music/ui/components/TrackListItem.kt
  • com/vayunmathur/music/ui/AlbumsContent.kt
  • com/vayunmathur/music/ui/ArtistsContent.kt
  • com/vayunmathur/music/ui/PlaylistsContent.kt
  • com/vayunmathur/music/ui/AlbumDetailContent.kt
  • com/vayunmathur/music/ui/ArtistDetailContent.kt
  • com/vayunmathur/music/ui/PlaylistDetailContent.kt
  • com/vayunmathur/music/ui/dialogs/AddToPlaylistDialog.kt
  • com/vayunmathur/music/ui/dialogs/AddToPlaylistDialogContent.kt
  • com/vayunmathur/music/ui/dialogs/CreatePlaylistDialog.kt
  • com/vayunmathur/music/ui/dialogs/DeletePlaylistDialogContent.kt
  • com/vayunmathur/music/ui/dialogs/RenamePlaylistDialogContent.kt

Verify (this module only)

./gradlew :music:compileDevKotlin
./gradlew :music:lint :music:lintVitalRelease
./gradlew :music:testDevUnitTest
./gradlew :music:checkMetadata