Modern Apps git

← Modern-Apps.git

music: merge music-wear into the single music APK

Commit
e8e1b7daf86547cee3125a78647a9b46b461f1d7
Author
Vayun Mathur <[email protected]>
When
2026-12-04 18:54 UTC (1 day ago)
Parents
702784c
Owner directive: singular apps that detect when they are on a watch
and adapt, instead of a separate *-wear APK per companion. Music
follows the merged clock pilot (adec0c398 + 31a81d3c5).

The merged :music APK keeps applicationId com.vayunmathur.music and
the convention signing on both form factors, as the WearLink
handshake requires; neither side's identity changed. Runtime
detection is PackageManager.FEATURE_WATCH (new
platform/FormFactor): MainActivity, the sole launcher entry,
forwards watches to ui/WearMainActivity before any phone state
(Room, phone sync, permission gate) is touched, and phones keep the
tab UI. The phone-only entry points gate on the same signal:
sync/WearMusicSync.start is a no-op on a watch, and
service/PlaybackService creates no player or session on a watch
(onGetSession returns null), so the watch never becomes a player.

Manifest shape, verified against AGP lint: no
android.hardware.type.watch uses-feature is declared. required=true
would block phone installs and required=false is disallowed for
this feature (InvalidWearFeatureAttribute; Google's packaging
model does not support a single Wear/non-Wear APK through Play).
Distribution here is sideload/F-Droid, not Play's watch channel,
so installation on a watch needs no feature declaration; the
standalone=false meta-data, WAKE_LOCK, touchscreen
not-required, and the watch activity are carried into the phone
application element. The wear launcher activity is
exported=false with no intent-filter of its own.

All music-wear sources move into music's closed package roots
(wear/data -> data, wear/sync -> sync, wear/ui -> ui), R
references retarget to com.vayunmathur.music.R, and wear strings
merge as res/values/wear_strings.xml (duplicate app_name dropped)
plus wear_colors.xml. The watch unit tests move with them; the
wear WearMusicProtocolTest copy is dropped because :music already
pins the same golden JSON. Watch screenshot previews become
ui/WearMetadataPreviews with group=wear, so :music:metadata
renders them into metadata_data/photos/music/wear/. To satisfy
the app lint the wear module never faced, WearHomeScreen and
WearPageLoader split out of WearMusicRoot into their own files
(OneComposablePerFile). The music-wear module and its settings
include are deleted; root, music, and library/wearlink AGENTS.md
describe the merged state. The watch UI binds to phone-reported
state in data/WearMusicStore and only sends ops, never owning
playback, keeping playback state solely in the phone service.

Verified on devvm21958: :music:lint and :music:lintVitalRelease
green. :music:testDevUnitTest run per affected/batched classes
is green (36 tests in the changed area including the moved
WearPendingOpsTest and new FormFactorTest; intents, platform,
ui, service, and data batches all pass, including
MusicRepositoryExpandedTest run standalone). A single
unfiltered full-suite invocation stalls under shared box load,
as the task brief warned, so the suite was verified in batches
instead. Only a real watch can confirm install, FEATURE_WATCH
routing, and the Wear OS launcher surface.

Diff

AGENTS.md
diff --git a/AGENTS.md b/AGENTS.mdindex bfdd71792d..3ae0142ca7 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -49,7 +49,7 @@ Monorepo: ~100 Gradle modules + Rust workspace. Do scoped work only. ### Apps (Gradle key → dir) Reference: `backup/` satisfies every rule; `notes/` second + `intents/` demo. `camera` + `games/voxels` hand-commit screenshots. Full canonical index (Gradle key → dir + group + notes): `.llms/repo-map.md`.-`clock`, `notes`, `calendar`, `launcher`, `todo`, `maps`, `camera`, `findfamily`, `contacts`, `appstore`, `weather` and `communicate` are single merged APKs for phone and watch (watch experience inside the phone app's module; the remaining `*-wear` modules are separate companion APKs with the phone app's applicationId/signing).+`clock`, `notes`, `calendar`, `launcher`, `todo`, `maps`, `camera`, `findfamily`, `contacts`, `appstore`, `weather`, `communicate` and `music` are single merged APKs for phone and watch (watch experience inside the phone app's module; the remaining `*-wear` modules are separate companion APKs with the phone app's applicationId/signing). `appstore→appstore/` `astronomy→astronomy/` `auto→auto/,auto/protocol/` `backup→backup/` `calculator→calculator/` `calendar→calendar/` `camera→camera/` `cast→cast/,cast/protocol/,cast/tv/` `clock→clock/` `code→code/` `communicate→communicate/` `contacts→contacts/` `education→education/` `email→email/` `emergency→emergency/` `euicc→euicc/` `everysync→everysync/` `files→files/` `findfamily→findfamily/` `findfamily-ios→apple/FindFamily/` (SwiftPM/xtool, not Gradle) `flashcards→flashcards/` `fooddelivery→fooddelivery/` `health→health/` `keyboard→keyboard/` `launcher→launcher/` `logviewer→logviewer/` `maps→maps/` `measure→measure/` `music→music/` `networklocation→networklocation/` `news→news/` `notes→notes/` `office→office/` `openassistant→openassistant/` `passwords→passwords/` `pdf→pdf/` `photos→photos/` `parentalcontrols→parentalcontrols/` `screentime→screentime/` `setupwizard→setupwizard/` `share→share/` `speech→speech/` `taxi→taxi/` `things→things/` `todo→todo/` `translate→translate/` `travel→travel/` `tuner→tuner/` `updater→updater/` `vpn→vpn/` `weather→weather/` `watch→watch/,watch-wear/` `web→web/` `youpipe→youpipe/,youpipe/extractor/` `games-hub→games/hub/` `games-arrows→games/arrows/` `games-chess→games/chess/` `games-logicgate→games/logicgate/` `games-minesweeper→games/minesweeper/` `games-nonogram→games/nonogram/` `games-pipes→games/pipes/` `games-solitaire→games/solitaire/` `games-sudoku→games/sudoku/` `games-unblockjam→games/unblockjam/` `games-voxels→games/voxels/` `games-wordmaker→games/wordmaker/` Slash == colon for Gradle (`games/voxels` == `games:voxels`). 
library/wearlink/AGENTS.md
diff --git a/library/wearlink/AGENTS.md b/library/wearlink/AGENTS.mdindex 8cdcf053aa..3933be2333 100644--- a/library/wearlink/AGENTS.md+++ b/library/wearlink/AGENTS.md@@ -34,8 +34,8 @@ unregistered apps, status fan-out, counters), `WearLinkClientNode` (drop-in `WearLinkNode` replacement over the conduit binding; reports `NotInstalled`/`Unavailable` when the Watch app is absent), and `ConduitHost`/`ConduitRuntime` used by the two Watch apps'-`ConduitService`s. Clock and Calendar each ship as one merged APK (`:clock`, `:calendar`)-whose phone and watch experiences both use the client; the remaining app pairs still own their `WearLinkNode`s, and+`ConduitService`s. Merged phone/watch pairs ship as single APKs whose phone and watch+experiences pick their side at runtime; the remaining app pairs still own their `WearLinkNode`s, and this module's manifest Bluetooth permissions stay until they migrate.  ## Verify
music-wear/AGENTS.md
diff --git a/music-wear/AGENTS.md b/music-wear/AGENTS.mddeleted file mode 100644index 1f6f436bbc..0000000000--- a/music-wear/AGENTS.md+++ /dev/null@@ -1,44 +0,0 @@-# AGENTS.md — music-wear/ (':music:wear')--> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside-> `music-wear/` + `music/` (the phone side of the same feature).--- Gradle: :music:wear / dir: music-wear/ (convention: `common-conventions-wear`)-- Package roots present: ui, data, domain, sync-- Entry file: ui/WearMainActivity.kt--## Why this module exists (read before changing identity)-Wear OS companion of the phone Music (`:music`). This module deliberately-uses `applicationId = "com.vayunmathur.music"` (the phone app's) with the-shared dev/release signing from the convention plugins: WearLink's-handshake token requires the same signing certificate on both sides, so-changing either breaks phone<->watch sync. Bootstrap is a one-time ADB-sideload of this APK onto the watch.--## Protocol-The wire protocol lives in `:library:wearlink` at-`com.vayunmathur.library.wearlink.music.WearMusicProtocol` (shared by-`:music` and `:music:wear`; neither app module depends on the other).-Each side's `WearMusicProtocolTest` pins the same golden JSON against-that shared code.--- Page snapshots: WearLink data item (`/music/page`, phone -> watch),-  requested by message (`/music/page-request`, watch -> phone)-- Now-playing: WearLink data item (`/music/playback`, phone -> watch)-- Watch state: WearLink data item (`/music/watch-state`, watch -> phone)-- Playback/library ops: WearLink message (`/music/op`, watch -> phone)-- Search: WearLink message (`/music/search-request`, watch -> phone)-- Transport: :library:wearlink (RFCOMM, no Play services); app-lifecycle-bound--## Execution model (stated, not implied)-The phone owns the catalog and is the ONLY audio player. The watch stores-no music files and no whole catalog: it caches only visited page snapshots-and the latest playback state, and renders them offline. 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.--## Verify (this module only)-```-./gradlew :music:wear:assembleDev-./gradlew :music:wear:testDebugUnitTest-```
music-wear/build.gradle.kts
diff --git a/music-wear/build.gradle.kts b/music-wear/build.gradle.ktsdeleted file mode 100644index dbedc7a9d2..0000000000--- a/music-wear/build.gradle.kts+++ /dev/null@@ -1,35 +0,0 @@-plugins {-    id("common-conventions-wear")-    // Listing screenshots come from Compose previews (src/screenshotTest), not from an-    // instrumented test on a device. Renders land in this module's own-    // metadata_data/photos/<wear-module-key>/wear/ bucket.-    id("common-conventions-preview-metadata")-}--launcherIcon {-    symbol = "music_note"-}--// Version shared with the phone app (root version.txt).-val wearVersionLines = file("../version.txt").readLines()-val wearVersionCode = wearVersionLines[0].trim().toInt()-val wearVersionName = wearVersionLines[1].trim()--android {-    // WearLink handshake requires same package + signing as the phone app.-    namespace = "com.vayunmathur.music.wear"-    defaultConfig {-        applicationId = "com.vayunmathur.music"-        minSdk = 31-        versionCode = wearVersionCode-        versionName = wearVersionName-    }-}--dependencies {-    implementation(libs.kotlinx.coroutines.android)-    implementation(libs.kotlinx.serialization.json)-    implementation(project(":library:wearlink"))-    testImplementation(libs.kotlin.test)-    testImplementation(libs.kotlin.test.junit)-}
music-wear/src/main/AndroidManifest.xml
diff --git a/music-wear/src/main/AndroidManifest.xml b/music-wear/src/main/AndroidManifest.xmldeleted file mode 100644index 611334d9b3..0000000000--- a/music-wear/src/main/AndroidManifest.xml+++ /dev/null@@ -1,21 +0,0 @@-<?xml version="1.0" encoding="utf-8"?>-<manifest xmlns:android="http://schemas.android.com/apk/res/android">-    <uses-feature android:name="android.hardware.type.watch" android:required="true" />-    <uses-feature android:name="android.hardware.touchscreen" android:required="false" />-    <uses-permission android:name="android.permission.WAKE_LOCK" />-    <application-        android:allowBackup="false"-        android:icon="@mipmap/ic_launcher"-        android:label="@string/app_name"-        android:roundIcon="@mipmap/ic_launcher"-        android:supportsRtl="true"-        android:theme="@android:style/Theme.Material.NoActionBar">-        <meta-data android:name="com.google.android.wearable.standalone" android:value="false" />-        <activity android:name=".ui.WearMainActivity" android:exported="true" android:taskAffinity="">-            <intent-filter>-                <action android:name="android.intent.action.MAIN" />-                <category android:name="android.intent.category.LAUNCHER" />-            </intent-filter>-        </activity>-    </application>-</manifest>
music-wear/src/test/java/com/vayunmathur/music/wear/domain/WearMusicProtocolTest.kt
diff --git a/music-wear/src/test/java/com/vayunmathur/music/wear/domain/WearMusicProtocolTest.kt b/music-wear/src/test/java/com/vayunmathur/music/wear/domain/WearMusicProtocolTest.ktdeleted file mode 100644index d4a015e6c9..0000000000--- a/music-wear/src/test/java/com/vayunmathur/music/wear/domain/WearMusicProtocolTest.kt+++ /dev/null@@ -1,104 +0,0 @@-package com.vayunmathur.music.wear.domain-import com.vayunmathur.library.wearlink.music.WearMusicOp-import com.vayunmathur.library.wearlink.music.WearMusicProtocol-import com.vayunmathur.library.wearlink.music.WearOpKind-import com.vayunmathur.library.wearlink.music.WearPageId-import com.vayunmathur.library.wearlink.music.WearPageKey-import com.vayunmathur.library.wearlink.music.WearPageSnapshot-import com.vayunmathur.library.wearlink.music.WearPlaybackState-import com.vayunmathur.library.wearlink.music.WearTrack-import com.vayunmathur.library.wearlink.music.nextWearRepeatMode-import com.vayunmathur.library.wearlink.music.paginateWearPage-import com.vayunmathur.library.wearlink.music.reducePlayback--import kotlin.test.Test-import kotlin.test.assertEquals-import kotlin.test.assertTrue-import kotlinx.serialization.encodeToString--class WearMusicProtocolTest {--    @Test-    fun goldenPageJson() {-        val snapshot = WearPageSnapshot(-            page = WearPageId(WearPageKey.HOME),-            generation = 7L,-            tracks = listOf(WearTrack(3L, "Blue", "Artist", "Album", 1_000L)),-            nextCursor = "30",-            totalCount = 31,-        )-        assertEquals(-            """{"page":{"key":"HOME"},"generation":7,"tracks":[{"id":3,"title":"Blue","artist":"Artist","album":"Album","durationMs":1000}],"nextCursor":"30","totalCount":31}""",-            WearMusicProtocol.json.encodeToString(snapshot),-        )-    }--    @Test-    fun goldenOpJson() {-        val op = WearMusicOp(WearOpKind.PLAY_TRACKS, trackIds = listOf(3L, 4L), startIndex = 1)-        assertEquals(-            """{"kind":"PLAY_TRACKS","trackIds":[3,4],"startIndex":1}""",-            WearMusicProtocol.json.encodeToString(op),-        )-    }--    @Test-    fun goldenPlaybackJson() {-        val state = WearPlaybackState(trackId = 3L, title = "Blue", isPlaying = true, shuffle = true, repeatMode = 2)-        assertEquals(-            """{"trackId":3,"title":"Blue","isPlaying":true,"shuffle":true,"repeatMode":2}""",-            WearMusicProtocol.json.encodeToString(state),-        )-    }--    @Test-    fun paginationWalksAllItemsOnce() {-        val items = (1..75).toList()-        val seen = mutableListOf<Int>()-        var cursor = ""-        var pages = 0-        do {-            val (slice, next) = paginateWearPage(items, cursor, pageSize = 30)-            seen += slice-            cursor = next-            pages++-        } while (cursor.isNotEmpty())-        assertEquals(items, seen)-        assertEquals(3, pages)-    }--    @Test-    fun paginationMalformedCursorRestarts() {-        val (slice, _) = paginateWearPage((1..10).toList(), "junk", pageSize = 4)-        assertEquals(listOf(1, 2, 3, 4), slice)-    }--    @Test-    fun playbackReducerReflectsPhoneReportOnly() {-        val before = WearPlaybackState(title = "Old", isPlaying = false)-        val reported = WearPlaybackState(title = "New", isPlaying = true, positionMs = 5L)-        val after = reducePlayback(before, WearMusicOp(WearOpKind.TOGGLE_PLAY_PAUSE), reported)-        assertEquals(reported, after)-        assertTrue(after.isPlaying)-    }--    @Test-    fun repeatCycleMatchesPhoneOrder() {-        assertEquals(2, nextWearRepeatMode(0))-        assertEquals(1, nextWearRepeatMode(2))-        assertEquals(0, nextWearRepeatMode(1))-    }--    @Test-    fun pageRoundTrip() {-        val snapshot = WearPageSnapshot(-            WearPageId(WearPageKey.SEARCH, query = "blue"),-            tracks = listOf(WearTrack(1L, "Blue Suede")),-            totalCount = 1,-        )-        assertEquals(-            snapshot,-            WearMusicProtocol.json.decodeFromString<WearPageSnapshot>(WearMusicProtocol.json.encodeToString(snapshot)),-        )-    }-}
music/AGENTS.md
diff --git a/music/AGENTS.md b/music/AGENTS.mdindex e0150bf2ba..547f86bdb3 100644--- a/music/AGENTS.md+++ b/music/AGENTS.md@@ -4,9 +4,9 @@  _Install: ./install music (dev by default)._ - Gradle: :music / dir: music/-- Package roots present: ui, data, platform, intents, service-- Entry files: MainActivity.kt, Route.kt, Navigation.kt-- Deps: :library:room, :library:image, :sdk:cast, :library:media+- 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 @@ -19,10 +19,41 @@ _Install: ./install music (dev by default)._ **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+- 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 WearLink+node) is a no-op on a watch, and `service/PlaybackService` creates no+player or session on a watch.++## Wear sync (phone <-> watch)+**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: WearLink data item (`/music/page`, phone -> watch), requested by message (`/music/page-request`, watch -> phone)+- Now-playing: WearLink data item (`/music/playback`, phone -> watch)+- Watch state: WearLink data item (`/music/watch-state`, watch -> phone)+- Playback/library ops: WearLink message (`/music/op`, watch -> phone)+- Search: WearLink message (`/music/search-request`, watch -> phone)+- Transport: :library:wearlink (RFCOMM, no Play services); app-lifecycle-bound. Phone side is `sync/WearMusicSync.kt`, watch side is `sync/WearLinkBridge.kt`; `FormFactor` picks the side at runtime.++## Watch experience (in this module)+- `ui/WearMainActivity` (a `WearShellActivity`) 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@@ -44,11 +75,19 @@ _Install: ./install music (dev by default)._ - 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)+- com/vayunmathur/music/sync/WearMusicSync.kt — phone WearLink node; page publish, playback stream, op execution+- com/vayunmathur/music/sync/WearLinkBridge.kt — watch WearLink node; page/playback receive, op send, watch-state publish+### Watch experience (ui/ + data/)+- com/vayunmathur/music/ui/WearMainActivity.kt — watch entry (WearShellActivity)+- 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@@ -96,6 +135,7 @@ _Install: ./install music (dev by default)._ ## Verify (this module only) ``` ./gradlew :music:compileDevKotlin-./gradlew :music:lint+./gradlew :music:lint :music:lintVitalRelease+./gradlew :music:testDevUnitTest ./gradlew :music:checkMetadata ```
music/build.gradle.kts
diff --git a/music/build.gradle.kts b/music/build.gradle.ktsindex fb8913511d..8306442f37 100644--- a/music/build.gradle.kts+++ b/music/build.gradle.kts@@ -45,6 +45,15 @@ dependencies {     implementation(project(":library:wearlink"))     implementation(libs.kotlinx.serialization.json) +    // Watch experience (ui/Wear*): Wear Compose + the repo log facade the+    // watch store/bridge code writes through. Both form factors live in+    // this one APK (same applicationId and signing, as the WearLink+    // handshake requires); FormFactor picks the side at runtime.+    implementation(libs.androidx.wear.compose.material)+    implementation(libs.androidx.wear.compose.foundation)+    implementation(project(":library:log"))+    implementation(libs.kotlinx.coroutines.android)+     // Car-view store-listing screenshots render through the shared host renderer.     add("screenshotTestImplementation", project(":library:carhost")) }\ No newline at end of file
music/src/main/AndroidManifest.xml
diff --git a/music/src/main/AndroidManifest.xml b/music/src/main/AndroidManifest.xmlindex 77d01ceca3..e4bc06af3c 100644--- a/music/src/main/AndroidManifest.xml+++ b/music/src/main/AndroidManifest.xml@@ -10,6 +10,23 @@     <!-- Sensors permission at install instead of auto-granting it. -->     <uses-permission android:name="com.vayunmathur.permission.SENSORS_OPTOUT" /> +    <!-- Single APK for phone and watch. Deliberately NO+         android.hardware.type.watch uses-feature here: required="true"+         would block every phone install, and required="false" is+         disallowed for this feature (lint InvalidWearFeatureAttribute;+         Google's packaging model does not support one APK for Wear and+         non-Wear via Play). This app does not distribute through Play's+         watch channel — it is sideloaded / F-Droid-installed, where no+         feature declaration is needed to install on a watch — so the+         APK carries no watch feature filter at all and+         FormFactor.isWatch (PackageManager.FEATURE_WATCH, still+         reported by watch hardware at runtime) routes the experience. -->+    <uses-feature+        android:name="android.hardware.touchscreen"+        android:required="false" />+    <!-- The watch experience's WearLink transport wakes the watch CPU. -->+    <uses-permission android:name="android.permission.WAKE_LOCK" />+     <uses-permission android:name="android.permission.INTERNET" tools:node="remove" />     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" tools:node="remove" /> @@ -37,6 +54,11 @@         android:supportsRtl="true"         android:theme="@style/Theme.General"> +        <!-- Watch experience is paired with the phone app, not standalone. -->+        <meta-data+            android:name="com.google.android.wearable.standalone"+            android:value="false" />+         <meta-data             android:name="com.google.android.gms.car.application"             android:resource="@xml/automotive_app_desc" />@@ -53,6 +75,16 @@             </intent-filter>         </activity> +        <!-- Watch experience: entered only via MainActivity's watch routing+             (no launcher filter of its own). Inert on a phone: nothing+             starts it there, and the phone player/sync it talks to over+             WearLink is the phone side of this same APK. -->+        <activity+            android:name=".ui.WearMainActivity"+            android:exported="false"+            android:taskAffinity=""+            android:theme="@android:style/Theme.Material.NoActionBar" />+         <!-- ExportedService: MediaLibrary/MediaSession service must be exported without a              permission so Android Auto and other media controllers (different UIDs) can bind;              Media3 validates controllers itself. tools:ignore is the genuine-false-positive
music/src/main/java/com/vayunmathur/music/MainActivity.kt
diff --git a/music/src/main/java/com/vayunmathur/music/MainActivity.kt b/music/src/main/java/com/vayunmathur/music/MainActivity.ktindex 183ef1299a..8fc0cbca83 100644--- a/music/src/main/java/com/vayunmathur/music/MainActivity.kt+++ b/music/src/main/java/com/vayunmathur/music/MainActivity.kt@@ -1,7 +1,9 @@ package com.vayunmathur.music  import android.Manifest+import android.content.Intent import android.os.Build+import android.os.Bundle import androidx.activity.viewModels import androidx.compose.runtime.Composable import com.vayunmathur.library.ui.AppPermissionsGate@@ -10,18 +12,42 @@ import com.vayunmathur.library.ui.MaActivity import com.vayunmathur.library.ui.PermissionRequirement import com.vayunmathur.music.R import com.vayunmathur.music.data.MusicRepository+import com.vayunmathur.music.platform.FormFactor import com.vayunmathur.music.platform.MusicViewModel import com.vayunmathur.music.platform.MusicViewModelFactory import com.vayunmathur.music.platform.PlaybackManager import com.vayunmathur.music.sync.WearMusicSync+import com.vayunmathur.music.ui.WearMainActivity -/** Main Activity: a ma activity implementation for main activity. */+/**+ * Sole launcher entry of the single merged Music APK. On a watch (the+ * `android.hardware.type.watch` system feature, see [FormFactor]) it hands+ * off to [WearMainActivity] and finishes before any phone state (Room,+ * playback, phone sync, permission gate) is touched; on a phone it owns+ * the [MusicViewModel] and gates the UI on the audio permission. Playback+ * state lives in the playback service on the phone; the watch UI only+ * sends WearLink ops and reflects phone-reported state.+ */ class MainActivity : MaActivity() {++    /** True on a watch, where this activity only forwards to [WearMainActivity]. */+    private var routedToWear = false++    override fun onCreate(savedInstanceState: Bundle?) {+        routedToWear = FormFactor.isWatch(this)+        super.onCreate(savedInstanceState)+        if (routedToWear) {+            startActivity(Intent(this, WearMainActivity::class.java))+            finish()+        }+    }+     private val musicViewModel: MusicViewModel by viewModels {         MusicViewModelFactory(application, MusicRepository.get(application), PlaybackManager.getInstance(this))     }      override fun onCreateBeforeContent() {+        if (routedToWear) return         // Phone side of the Wear OS companion: page server + playback-state         // streamer + op executor (see sync/WearMusicSync.kt).         WearMusicSync.start(this)@@ -29,6 +55,9 @@ class MainActivity : MaActivity() {      @Composable     override fun Content() {+        // On a watch this activity is finishing towards WearMainActivity;+        // compose nothing (and touch no phone state) in the meantime.+        if (routedToWear) return         val (permissions, message) = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)             arrayOf(Manifest.permission.READ_MEDIA_AUDIO) to getString(R.string.grant_audio_permissions)         else
music/src/main/java/com/vayunmathur/music/data/WearMusicStore.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/data/WearMusicStore.kt b/music/src/main/java/com/vayunmathur/music/data/WearMusicStore.ktsimilarity index 98%rename from music-wear/src/main/java/com/vayunmathur/music/wear/data/WearMusicStore.ktrename to music/src/main/java/com/vayunmathur/music/data/WearMusicStore.ktindex 27e9f5d956..01e9e9996b 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/data/WearMusicStore.kt+++ b/music/src/main/java/com/vayunmathur/music/data/WearMusicStore.kt@@ -1,4 +1,4 @@-package com.vayunmathur.music.wear.data+package com.vayunmathur.music.data  import android.content.Context import com.vayunmathur.library.log.Log@@ -10,7 +10,7 @@ import com.vayunmathur.library.wearlink.music.WearPageKey import com.vayunmathur.library.wearlink.music.WearPageSnapshot import com.vayunmathur.library.wearlink.music.WearPlaybackState import com.vayunmathur.library.wearlink.music.WearWatchState-import com.vayunmathur.music.wear.sync.WearLinkBridge+import com.vayunmathur.music.sync.WearLinkBridge import java.io.File import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow
music/src/main/java/com/vayunmathur/music/platform/FormFactor.kt
diff --git a/music/src/main/java/com/vayunmathur/music/platform/FormFactor.kt b/music/src/main/java/com/vayunmathur/music/platform/FormFactor.ktnew file mode 100644index 0000000000..a97aca1786--- /dev/null+++ b/music/src/main/java/com/vayunmathur/music/platform/FormFactor.kt@@ -0,0 +1,25 @@+package com.vayunmathur.music.platform++import android.content.Context+import android.content.pm.PackageManager++/**+ * Runtime form-factor detection for the single merged Music APK.+ *+ * One APK ships to phones and watches (same applicationId and signing, as+ * the WearLink handshake requires). [PackageManager.FEATURE_WATCH] is the+ * canonical signal: Wear OS devices report the `android.hardware.type.watch`+ * system feature, phones and tablets do not. The manifest deliberately+ * declares no such uses-feature (required=true would block phones,+ * required=false is disallowed for this feature), so the same APK+ * installs on both; this runtime check is what routes the experience.+ */+object FormFactor {++    /** True when this device reports the watch system feature. */+    fun isWatch(context: Context): Boolean =+        isWatch(context.packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH))++    /** Pure core of [isWatch], split out so unit tests need no Android runtime. */+    fun isWatch(hasWatchSystemFeature: Boolean): Boolean = hasWatchSystemFeature+}
music/src/main/java/com/vayunmathur/music/service/PlaybackService.kt
diff --git a/music/src/main/java/com/vayunmathur/music/service/PlaybackService.kt b/music/src/main/java/com/vayunmathur/music/service/PlaybackService.ktindex 504f5b2fbb..8a7079761c 100644--- a/music/src/main/java/com/vayunmathur/music/service/PlaybackService.kt+++ b/music/src/main/java/com/vayunmathur/music/service/PlaybackService.kt@@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableList import com.google.common.util.concurrent.Futures import com.google.common.util.concurrent.ListenableFuture import com.vayunmathur.music.MainActivity+import com.vayunmathur.music.platform.FormFactor import com.vayunmathur.music.platform.nextRepeatMode  /**@@ -85,6 +86,12 @@ class PlaybackService : MediaLibraryService() {     override fun onCreate() {         super.onCreate() +        // Phone-side playback only: on a watch this APK is a remote control+        // for the phone's player (WearLink ops), never a player itself, so+        // no player or session is created there (onGetSession then returns+        // null and controllers simply find no session).+        if (FormFactor.isWatch(this)) return+         libraryTree = MusicLibraryTree(this)          val audioAttributes = AudioAttributes.Builder()@@ -269,6 +276,11 @@ class PlaybackService : MediaLibraryService() {     }      override fun onDestroy() {+        // Mirrors the onCreate watch gate: nothing was created there.+        if (FormFactor.isWatch(this)) {+            super.onDestroy()+            return+        }         libraryTree.release()         castQueue?.release()         castQueue = null
music/src/main/java/com/vayunmathur/music/sync/WearLinkBridge.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/sync/WearLinkBridge.kt b/music/src/main/java/com/vayunmathur/music/sync/WearLinkBridge.ktsimilarity index 98%rename from music-wear/src/main/java/com/vayunmathur/music/wear/sync/WearLinkBridge.ktrename to music/src/main/java/com/vayunmathur/music/sync/WearLinkBridge.ktindex 8261a5a05c..47d2fc7f35 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/sync/WearLinkBridge.kt+++ b/music/src/main/java/com/vayunmathur/music/sync/WearLinkBridge.kt@@ -1,11 +1,11 @@-package com.vayunmathur.music.wear.sync+package com.vayunmathur.music.sync  import android.content.Context import com.vayunmathur.library.log.Log import com.vayunmathur.library.wearlink.WearLinkListener import com.vayunmathur.library.wearlink.WearLinkNode import com.vayunmathur.library.wearlink.WearLinkState-import com.vayunmathur.music.wear.data.WearMusicStore+import com.vayunmathur.music.data.WearMusicStore import com.vayunmathur.library.wearlink.music.WearMusicOp import com.vayunmathur.library.wearlink.music.WearMusicProtocol import com.vayunmathur.library.wearlink.music.WearPageRequest
music/src/main/java/com/vayunmathur/music/sync/WearMusicSync.kt
diff --git a/music/src/main/java/com/vayunmathur/music/sync/WearMusicSync.kt b/music/src/main/java/com/vayunmathur/music/sync/WearMusicSync.ktindex 8de7f98156..d8e4753109 100644--- a/music/src/main/java/com/vayunmathur/music/sync/WearMusicSync.kt+++ b/music/src/main/java/com/vayunmathur/music/sync/WearMusicSync.kt@@ -19,6 +19,7 @@ import com.vayunmathur.library.wearlink.music.WearSearchRequest import com.vayunmathur.library.wearlink.music.WearTrack import com.vayunmathur.library.wearlink.music.capWearTrack import com.vayunmathur.library.wearlink.music.paginateWearPage+import com.vayunmathur.music.platform.FormFactor import com.vayunmathur.music.platform.PlaybackManager import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers@@ -39,8 +40,9 @@ object WearMusicSync {     private var node: WearLinkNode? = null     private var generation = 0L -    /** Start phone-side WearLink (call from the app's main activity once). */+    /** Start phone-side WearLink (call from the app's main activity once). No-op on a watch: there the watch-side bridge ([com.vayunmathur.music.sync.WearLinkBridge]) runs instead, and this phone node (catalog, playback) must never start. */     fun start(context: Context) {+        if (FormFactor.isWatch(context)) return         val appContext = context.applicationContext         if (node != null) return         synchronized(this) {
music/src/main/java/com/vayunmathur/music/ui/WearAddToPlaylistScreen.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearAddToPlaylistScreen.kt b/music/src/main/java/com/vayunmathur/music/ui/WearAddToPlaylistScreen.ktsimilarity index 95%rename from music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearAddToPlaylistScreen.ktrename to music/src/main/java/com/vayunmathur/music/ui/WearAddToPlaylistScreen.ktindex a5ebcc2821..661ae2f6b7 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearAddToPlaylistScreen.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/WearAddToPlaylistScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.music.wear.ui+package com.vayunmathur.music.ui  import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding@@ -14,8 +14,8 @@ import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState import androidx.wear.compose.material.Chip import androidx.wear.compose.material.ChipDefaults import androidx.wear.compose.material.Text-import com.vayunmathur.music.wear.R-import com.vayunmathur.music.wear.data.WearMusicStore+import com.vayunmathur.music.R+import com.vayunmathur.music.data.WearMusicStore import com.vayunmathur.library.wearlink.music.WearMusicOp import com.vayunmathur.library.wearlink.music.WearOpKind import com.vayunmathur.library.wearlink.music.WearPageId
music/src/main/java/com/vayunmathur/music/ui/WearAlbumListScreen.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearAlbumListScreen.kt b/music/src/main/java/com/vayunmathur/music/ui/WearAlbumListScreen.ktsimilarity index 94%rename from music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearAlbumListScreen.ktrename to music/src/main/java/com/vayunmathur/music/ui/WearAlbumListScreen.ktindex c7fff30138..e79f38af2e 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearAlbumListScreen.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/WearAlbumListScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.music.wear.ui+package com.vayunmathur.music.ui  import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding@@ -14,8 +14,8 @@ import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState import androidx.wear.compose.material.Chip import androidx.wear.compose.material.ChipDefaults import androidx.wear.compose.material.Text-import com.vayunmathur.music.wear.R-import com.vayunmathur.music.wear.data.WearMusicStore+import com.vayunmathur.music.R+import com.vayunmathur.music.data.WearMusicStore import com.vayunmathur.library.wearlink.music.WearPageId import com.vayunmathur.library.wearlink.music.WearPageKey 
music/src/main/java/com/vayunmathur/music/ui/WearArtistListScreen.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearArtistListScreen.kt b/music/src/main/java/com/vayunmathur/music/ui/WearArtistListScreen.ktsimilarity index 94%rename from music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearArtistListScreen.ktrename to music/src/main/java/com/vayunmathur/music/ui/WearArtistListScreen.ktindex 71b84f4670..33d82dc75f 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearArtistListScreen.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/WearArtistListScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.music.wear.ui+package com.vayunmathur.music.ui  import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding@@ -14,8 +14,8 @@ import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState import androidx.wear.compose.material.Chip import androidx.wear.compose.material.ChipDefaults import androidx.wear.compose.material.Text-import com.vayunmathur.music.wear.R-import com.vayunmathur.music.wear.data.WearMusicStore+import com.vayunmathur.music.R+import com.vayunmathur.music.data.WearMusicStore import com.vayunmathur.library.wearlink.music.WearPageId import com.vayunmathur.library.wearlink.music.WearPageKey 
music/src/main/java/com/vayunmathur/music/ui/WearHomeScreen.kt
diff --git a/music/src/main/java/com/vayunmathur/music/ui/WearHomeScreen.kt b/music/src/main/java/com/vayunmathur/music/ui/WearHomeScreen.ktnew file mode 100644index 0000000000..a287f5587a--- /dev/null+++ b/music/src/main/java/com/vayunmathur/music/ui/WearHomeScreen.kt@@ -0,0 +1,70 @@+package com.vayunmathur.music.ui++import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.ui.res.stringResource+import androidx.wear.compose.foundation.lazy.ScalingLazyColumn+import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState+import com.vayunmathur.music.R+import com.vayunmathur.music.data.WearMusicStore+import com.vayunmathur.library.wearlink.music.WearMusicOp+import com.vayunmathur.library.wearlink.music.WearPageId+import com.vayunmathur.library.wearlink.music.WearPageKey+import com.vayunmathur.library.wearlink.music.WearPageSnapshot+import com.vayunmathur.library.wearlink.music.WearPlaybackState++/**+ * Watch home: library navigation first (albums/artists/playlists/search/+ * now-playing/about), then the Songs page. Before this hub existed the+ * Albums/Artists/Playlists/Search/Settings routes were unreachable.+ */+@Composable+fun WearHomeScreen(store: WearMusicStore, onRoute: (WearRoute) -> Unit) {+    val page = WearPageId(WearPageKey.HOME)+    WearPageLoader(store, page)+    val pages by store.pages.collectAsState()+    val playback by store.playback.collectAsState()+    WearHomeContent(+        page = page,+        snapshot = pages[page],+        playback = playback,+        onEnqueueOp = store::enqueueOp,+        onRoute = onRoute,+    )+}++/**+ * Stateless home body behind [WearHomeScreen]: page snapshot and playback state are+ * parameters, so Compose previews (src/screenshotTest) render literal fixtures with+ * no store or phone.+ */+@Composable+internal fun WearHomeContent(+    page: WearPageId,+    snapshot: WearPageSnapshot?,+    playback: WearPlaybackState,+    onEnqueueOp: (WearMusicOp) -> Unit,+    onRoute: (WearRoute) -> Unit,+) {+    // Hoisted: ScalingLazyColumn's scope lambda is not a @Composable context.+    val appName = stringResource(R.string.app_name)+    val nowPlayingLabel = stringResource(R.string.wear_now_playing)+    val albumsLabel = stringResource(R.string.wear_albums)+    val artistsLabel = stringResource(R.string.wear_artists)+    val playlistsLabel = stringResource(R.string.wear_playlists)+    val searchLabel = stringResource(R.string.wear_search)+    val settingsLabel = stringResource(R.string.wear_settings)+    val songsLabel = stringResource(R.string.wear_songs)+    ScalingLazyColumn(state = rememberScalingLazyListState()) {+        item { WearTitle(appName) }+        wearNavItem(nowPlayingLabel, WearRoute.NowPlaying, onRoute)+        wearNavItem(albumsLabel, WearRoute.Albums, onRoute)+        wearNavItem(artistsLabel, WearRoute.Artists, onRoute)+        wearNavItem(playlistsLabel, WearRoute.Playlists, onRoute)+        wearNavItem(searchLabel, WearRoute.Search, onRoute)+        wearNavItem(settingsLabel, WearRoute.Settings, onRoute)+        item { WearTitle(songsLabel) }+        wearTrackItems(onEnqueueOp, page, snapshot, playback, onRoute)+    }+}
music/src/main/java/com/vayunmathur/music/ui/WearMainActivity.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearMainActivity.kt b/music/src/main/java/com/vayunmathur/music/ui/WearMainActivity.ktsimilarity index 84%rename from music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearMainActivity.ktrename to music/src/main/java/com/vayunmathur/music/ui/WearMainActivity.ktindex ac24d5a964..e11a3a97a1 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearMainActivity.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/WearMainActivity.kt@@ -1,9 +1,9 @@-package com.vayunmathur.music.wear.ui+package com.vayunmathur.music.ui  import androidx.compose.runtime.Composable import com.vayunmathur.library.wearlink.WearShellActivity-import com.vayunmathur.music.wear.data.WearMusicStore-import com.vayunmathur.music.wear.sync.WearLinkBridge+import com.vayunmathur.music.data.WearMusicStore+import com.vayunmathur.music.sync.WearLinkBridge  /**  * Watch music entry: mirrors the phone's pages (tabs, details, now playing,
music/src/main/java/com/vayunmathur/music/ui/WearMusicRoot.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearMusicRoot.kt b/music/src/main/java/com/vayunmathur/music/ui/WearMusicRoot.ktsimilarity index 66%rename from music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearMusicRoot.ktrename to music/src/main/java/com/vayunmathur/music/ui/WearMusicRoot.ktindex 43b07aacfe..c86d89324d 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearMusicRoot.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/WearMusicRoot.kt@@ -1,26 +1,21 @@-package com.vayunmathur.music.wear.ui+package com.vayunmathur.music.ui  import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable-import androidx.compose.runtime.LaunchedEffect-import androidx.compose.runtime.collectAsState-import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp-import androidx.wear.compose.foundation.lazy.ScalingLazyColumn import androidx.wear.compose.foundation.lazy.ScalingLazyListScope import androidx.wear.compose.foundation.lazy.items-import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState import androidx.wear.compose.material.Chip import androidx.wear.compose.material.ChipDefaults import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text-import com.vayunmathur.music.wear.R-import com.vayunmathur.music.wear.data.WearMusicStore+import com.vayunmathur.music.R+import com.vayunmathur.music.data.WearMusicStore import com.vayunmathur.library.wearlink.music.WearMusicOp import com.vayunmathur.library.wearlink.music.WearOpKind import com.vayunmathur.library.wearlink.music.WearPageId@@ -28,7 +23,7 @@ import com.vayunmathur.library.wearlink.music.WearPageKey import com.vayunmathur.library.wearlink.music.WearPageRequest import com.vayunmathur.library.wearlink.music.WearPageSnapshot import com.vayunmathur.library.wearlink.music.WearPlaybackState-import com.vayunmathur.music.wear.sync.WearLinkBridge+import com.vayunmathur.music.sync.WearLinkBridge  /** Root switch over [WearRoute]: every phone page has exactly one watch screen here. */ @Composable@@ -58,71 +53,6 @@ fun WearMusicRoot(store: WearMusicStore, route: WearRoute, onRoute: (WearRoute)     } } -/**- * Watch home: library navigation first (albums/artists/playlists/search/- * now-playing/about), then the Songs page. Before this hub existed the- * Albums/Artists/Playlists/Search/Settings routes were unreachable.- */-@Composable-fun WearHomeScreen(store: WearMusicStore, onRoute: (WearRoute) -> Unit) {-    val page = WearPageId(WearPageKey.HOME)-    WearPageLoader(store, page)-    val pages by store.pages.collectAsState()-    val playback by store.playback.collectAsState()-    WearHomeContent(-        page = page,-        snapshot = pages[page],-        playback = playback,-        onEnqueueOp = store::enqueueOp,-        onRoute = onRoute,-    )-}--/**- * Stateless home body behind [WearHomeScreen]: page snapshot and playback state are- * parameters, so Compose previews (src/screenshotTest) render literal fixtures with- * no store or phone.- */-@Composable-internal fun WearHomeContent(-    page: WearPageId,-    snapshot: WearPageSnapshot?,-    playback: WearPlaybackState,-    onEnqueueOp: (WearMusicOp) -> Unit,-    onRoute: (WearRoute) -> Unit,-) {-    // Hoisted: ScalingLazyColumn's scope lambda is not a @Composable context.-    val appName = stringResource(R.string.app_name)-    val nowPlayingLabel = stringResource(R.string.wear_now_playing)-    val albumsLabel = stringResource(R.string.wear_albums)-    val artistsLabel = stringResource(R.string.wear_artists)-    val playlistsLabel = stringResource(R.string.wear_playlists)-    val searchLabel = stringResource(R.string.wear_search)-    val settingsLabel = stringResource(R.string.wear_settings)-    val songsLabel = stringResource(R.string.wear_songs)-    ScalingLazyColumn(state = rememberScalingLazyListState()) {-        item { WearTitle(appName) }-        wearNavItem(nowPlayingLabel, WearRoute.NowPlaying, onRoute)-        wearNavItem(albumsLabel, WearRoute.Albums, onRoute)-        wearNavItem(artistsLabel, WearRoute.Artists, onRoute)-        wearNavItem(playlistsLabel, WearRoute.Playlists, onRoute)-        wearNavItem(searchLabel, WearRoute.Search, onRoute)-        wearNavItem(settingsLabel, WearRoute.Settings, onRoute)-        item { WearTitle(songsLabel) }-        wearTrackItems(onEnqueueOp, page, snapshot, playback, onRoute)-    }-}--/** Requests the first snapshot for [page] when the watch has not visited it yet. */-@Composable-fun WearPageLoader(store: WearMusicStore, page: WearPageId) {-    val context = LocalContext.current-    val pages by store.pages.collectAsState()-    LaunchedEffect(page, pages.containsKey(page)) {-        if (!pages.containsKey(page)) WearLinkBridge.requestPage(context, WearPageRequest(page))-    }-}- /** Centred screen title, inset so the round bezel never clips it. */ @Composable internal fun WearTitle(text: String) {
music/src/main/java/com/vayunmathur/music/ui/WearNowPlayingScreen.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearNowPlayingScreen.kt b/music/src/main/java/com/vayunmathur/music/ui/WearNowPlayingScreen.ktsimilarity index 98%rename from music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearNowPlayingScreen.ktrename to music/src/main/java/com/vayunmathur/music/ui/WearNowPlayingScreen.ktindex 8995e2cc3a..a0fc90106e 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearNowPlayingScreen.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/WearNowPlayingScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.music.wear.ui+package com.vayunmathur.music.ui  import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding@@ -15,8 +15,8 @@ import androidx.wear.compose.material.Chip import androidx.wear.compose.material.ChipDefaults import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text-import com.vayunmathur.music.wear.R-import com.vayunmathur.music.wear.data.WearMusicStore+import com.vayunmathur.music.R+import com.vayunmathur.music.data.WearMusicStore import com.vayunmathur.library.wearlink.music.WearMusicOp import com.vayunmathur.library.wearlink.music.WearOpKind 
music/src/main/java/com/vayunmathur/music/ui/WearPageLoader.kt
diff --git a/music/src/main/java/com/vayunmathur/music/ui/WearPageLoader.kt b/music/src/main/java/com/vayunmathur/music/ui/WearPageLoader.ktnew file mode 100644index 0000000000..e653f4ef66--- /dev/null+++ b/music/src/main/java/com/vayunmathur/music/ui/WearPageLoader.kt@@ -0,0 +1,21 @@+package com.vayunmathur.music.ui++import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.ui.platform.LocalContext+import com.vayunmathur.music.data.WearMusicStore+import com.vayunmathur.library.wearlink.music.WearPageId+import com.vayunmathur.library.wearlink.music.WearPageRequest+import com.vayunmathur.music.sync.WearLinkBridge++/** Requests the first snapshot for [page] when the watch has not visited it yet. */+@Composable+fun WearPageLoader(store: WearMusicStore, page: WearPageId) {+    val context = LocalContext.current+    val pages by store.pages.collectAsState()+    LaunchedEffect(page, pages.containsKey(page)) {+        if (!pages.containsKey(page)) WearLinkBridge.requestPage(context, WearPageRequest(page))+    }+}
music/src/main/java/com/vayunmathur/music/ui/WearPlaylistListScreen.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearPlaylistListScreen.kt b/music/src/main/java/com/vayunmathur/music/ui/WearPlaylistListScreen.ktsimilarity index 94%rename from music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearPlaylistListScreen.ktrename to music/src/main/java/com/vayunmathur/music/ui/WearPlaylistListScreen.ktindex c57e3eb9e3..5a027ab5b8 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearPlaylistListScreen.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/WearPlaylistListScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.music.wear.ui+package com.vayunmathur.music.ui  import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding@@ -14,8 +14,8 @@ import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState import androidx.wear.compose.material.Chip import androidx.wear.compose.material.ChipDefaults import androidx.wear.compose.material.Text-import com.vayunmathur.music.wear.R-import com.vayunmathur.music.wear.data.WearMusicStore+import com.vayunmathur.music.R+import com.vayunmathur.music.data.WearMusicStore import com.vayunmathur.library.wearlink.music.WearPageId import com.vayunmathur.library.wearlink.music.WearPageKey 
music/src/main/java/com/vayunmathur/music/ui/WearQueueScreen.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearQueueScreen.kt b/music/src/main/java/com/vayunmathur/music/ui/WearQueueScreen.ktsimilarity index 95%rename from music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearQueueScreen.ktrename to music/src/main/java/com/vayunmathur/music/ui/WearQueueScreen.ktindex bdb2b6b205..9fc0cab851 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearQueueScreen.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/WearQueueScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.music.wear.ui+package com.vayunmathur.music.ui  import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding@@ -14,8 +14,8 @@ import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState import androidx.wear.compose.material.Chip import androidx.wear.compose.material.ChipDefaults import androidx.wear.compose.material.Text-import com.vayunmathur.music.wear.R-import com.vayunmathur.music.wear.data.WearMusicStore+import com.vayunmathur.music.R+import com.vayunmathur.music.data.WearMusicStore import com.vayunmathur.library.wearlink.music.WearMusicOp import com.vayunmathur.library.wearlink.music.WearOpKind 
music/src/main/java/com/vayunmathur/music/ui/WearRoute.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearRoute.kt b/music/src/main/java/com/vayunmathur/music/ui/WearRoute.ktsimilarity index 97%rename from music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearRoute.ktrename to music/src/main/java/com/vayunmathur/music/ui/WearRoute.ktindex 9827fa348f..b4cb24bee1 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearRoute.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/WearRoute.kt@@ -1,4 +1,4 @@-package com.vayunmathur.music.wear.ui+package com.vayunmathur.music.ui  /** Watch navigation destinations mirroring the phone `Route` 1:1; detail routes carry IDs, never selection state. */ sealed interface WearRoute {
music/src/main/java/com/vayunmathur/music/ui/WearSearchScreen.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearSearchScreen.kt b/music/src/main/java/com/vayunmathur/music/ui/WearSearchScreen.ktsimilarity index 94%rename from music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearSearchScreen.ktrename to music/src/main/java/com/vayunmathur/music/ui/WearSearchScreen.ktindex 5548167d1e..033042f35d 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearSearchScreen.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/WearSearchScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.music.wear.ui+package com.vayunmathur.music.ui  import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding@@ -18,11 +18,11 @@ import androidx.compose.ui.unit.dp import androidx.wear.compose.foundation.lazy.ScalingLazyColumn import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState import androidx.wear.compose.material.MaterialTheme-import com.vayunmathur.music.wear.R-import com.vayunmathur.music.wear.data.WearMusicStore+import com.vayunmathur.music.R+import com.vayunmathur.music.data.WearMusicStore import com.vayunmathur.library.wearlink.music.WearPageId import com.vayunmathur.library.wearlink.music.WearPageKey-import com.vayunmathur.music.wear.sync.WearLinkBridge+import com.vayunmathur.music.sync.WearLinkBridge  /** Search page: typed/dictated query is sent to the phone; paged results render as a track page. */ @Composable
music/src/main/java/com/vayunmathur/music/ui/WearSettingsScreen.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearSettingsScreen.kt b/music/src/main/java/com/vayunmathur/music/ui/WearSettingsScreen.ktsimilarity index 91%rename from music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearSettingsScreen.ktrename to music/src/main/java/com/vayunmathur/music/ui/WearSettingsScreen.ktindex f1ce852a73..8b431617a3 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearSettingsScreen.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/WearSettingsScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.music.wear.ui+package com.vayunmathur.music.ui  import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState@@ -6,8 +6,8 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.res.stringResource import androidx.wear.compose.foundation.lazy.ScalingLazyColumn import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState-import com.vayunmathur.music.wear.R-import com.vayunmathur.music.wear.data.WearMusicStore+import com.vayunmathur.music.R+import com.vayunmathur.music.data.WearMusicStore  /** Library info page: the phone app has no settings page, so this shows sync/cache truth only. */ @Composable
music/src/main/java/com/vayunmathur/music/ui/WearTrackListScreen.kt
diff --git a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearTrackListScreen.kt b/music/src/main/java/com/vayunmathur/music/ui/WearTrackListScreen.ktsimilarity index 94%rename from music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearTrackListScreen.ktrename to music/src/main/java/com/vayunmathur/music/ui/WearTrackListScreen.ktindex 481b0e514d..008b865e70 100644--- a/music-wear/src/main/java/com/vayunmathur/music/wear/ui/WearTrackListScreen.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/WearTrackListScreen.kt@@ -1,11 +1,11 @@-package com.vayunmathur.music.wear.ui+package com.vayunmathur.music.ui  import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.wear.compose.foundation.lazy.ScalingLazyColumn import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState-import com.vayunmathur.music.wear.data.WearMusicStore+import com.vayunmathur.music.data.WearMusicStore import com.vayunmathur.library.wearlink.music.WearPageId  /** Watch-sized track list for album / artist / playlist detail pages. */
music/src/main/res/values/wear_colors.xml
diff --git a/music-wear/src/main/res/values/colors.xml b/music/src/main/res/values/wear_colors.xmlsimilarity index 66%rename from music-wear/src/main/res/values/colors.xmlrename to music/src/main/res/values/wear_colors.xmlindex fede27e2cb..f40d4ef356 100644--- a/music-wear/src/main/res/values/colors.xml+++ b/music/src/main/res/values/wear_colors.xml@@ -1,5 +1,4 @@ <?xml version="1.0" encoding="utf-8"?> <resources>     <color name="wear_background">#000000</color>-    <color name="ic_launcher_background">#FFFFFF</color> </resources>
music/src/main/res/values/wear_strings.xml
diff --git a/music-wear/src/main/res/values/strings.xml b/music/src/main/res/values/wear_strings.xmlsimilarity index 97%rename from music-wear/src/main/res/values/strings.xmlrename to music/src/main/res/values/wear_strings.xmlindex 092a66d121..5eb7d7c750 100644--- a/music-wear/src/main/res/values/strings.xml+++ b/music/src/main/res/values/wear_strings.xml@@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <resources>-    <string name="app_name">Music</string>     <string name="wear_empty">Nothing synced yet. Open Music on your phone to sync this watch.</string>     <string name="wear_no_phone">Phone not reachable — showing pages you already visited</string>     <string name="wear_load_more">Load more</string>
music/src/screenshotTest/kotlin/com/vayunmathur/music/ui/WearMetadataPreviews.kt
diff --git a/music-wear/src/screenshotTest/kotlin/com/vayunmathur/music/wear/ui/MetadataPreviews.kt b/music/src/screenshotTest/kotlin/com/vayunmathur/music/ui/WearMetadataPreviews.ktsimilarity index 95%rename from music-wear/src/screenshotTest/kotlin/com/vayunmathur/music/wear/ui/MetadataPreviews.ktrename to music/src/screenshotTest/kotlin/com/vayunmathur/music/ui/WearMetadataPreviews.ktindex a66b8de556..54f5ef769b 100644--- a/music-wear/src/screenshotTest/kotlin/com/vayunmathur/music/wear/ui/MetadataPreviews.kt+++ b/music/src/screenshotTest/kotlin/com/vayunmathur/music/ui/WearMetadataPreviews.kt@@ -1,4 +1,4 @@-package com.vayunmathur.music.wear.ui+package com.vayunmathur.music.ui  import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box@@ -23,14 +23,13 @@ import com.vayunmathur.library.wearlink.music.WearPlaylist private const val ROUND = "spec:width=227dp,height=227dp,dpi=320"  /**- * Store listing images for `:music:wear`, rendered from Compose previews instead of+ * Store listing images for the watch experience of `:music`, rendered from Compose previews instead of  * from an instrumented test on a device. Every top-level route is captured at least  * once: home, now-playing, albums, artists, playlists, track-list (album/artist/  * playlist detail share this screen), queue, add-to-playlist, search, settings.  *- * `./gradlew :music:wear:metadata` renders these and copies the PNGs into- * `metadata_data/photos/music-wear/wear/` — the wear module's own bucket, not the- * phone Music app's folder — where the release build picks them up.+ * `./gradlew :music:metadata` renders these and copies the PNGs into+ * `metadata_data/photos/music/wear/` — the merged app's wear bucket — where the release build picks them up.  *  * Rules (same as every other module's MetadataPreviews): order comes from the  * function names, each preview needs `@PreviewTest` plus `group = "wear"`, previews@@ -38,7 +37,7 @@ private const val ROUND = "spec:width=227dp,height=227dp,dpi=320"  * playback state — no store, no phone). Layoutlib renders a rectangular canvas, so  * round previews clip to a circle: what is visible is what a round watch shows.  */-class MetadataPreviews {+class WearMetadataPreviews {      @PreviewTest     @Preview(name = "1-home-round", device = ROUND, group = "wear")
music/src/test/java/com/vayunmathur/music/data/WearPendingOpsTest.kt
diff --git a/music-wear/src/test/java/com/vayunmathur/music/wear/data/WearPendingOpsTest.kt b/music/src/test/java/com/vayunmathur/music/data/WearPendingOpsTest.ktsimilarity index 98%rename from music-wear/src/test/java/com/vayunmathur/music/wear/data/WearPendingOpsTest.ktrename to music/src/test/java/com/vayunmathur/music/data/WearPendingOpsTest.ktindex 3a49622de4..a48bcb9825 100644--- a/music-wear/src/test/java/com/vayunmathur/music/wear/data/WearPendingOpsTest.kt+++ b/music/src/test/java/com/vayunmathur/music/data/WearPendingOpsTest.kt@@ -1,4 +1,4 @@-package com.vayunmathur.music.wear.data+package com.vayunmathur.music.data  import com.vayunmathur.library.wearlink.music.WearMusicOp import com.vayunmathur.library.wearlink.music.WearOpKind
music/src/test/java/com/vayunmathur/music/platform/FormFactorTest.kt
diff --git a/music/src/test/java/com/vayunmathur/music/platform/FormFactorTest.kt b/music/src/test/java/com/vayunmathur/music/platform/FormFactorTest.ktnew file mode 100644index 0000000000..bfd669040b--- /dev/null+++ b/music/src/test/java/com/vayunmathur/music/platform/FormFactorTest.kt@@ -0,0 +1,19 @@+package com.vayunmathur.music.platform++import kotlin.test.Test+import kotlin.test.assertFalse+import kotlin.test.assertTrue++/** The watch system feature is the single-APK routing signal. */+class FormFactorTest {++    @Test+    fun watchFeatureMeansWatch() {+        assertTrue(FormFactor.isWatch(hasWatchSystemFeature = true))+    }++    @Test+    fun noWatchFeatureMeansPhone() {+        assertFalse(FormFactor.isWatch(hasWatchSystemFeature = false))+    }+}
settings.gradle.kts
diff --git a/settings.gradle.kts b/settings.gradle.ktsindex 044e451a2d..63e9d1e531 100644--- a/settings.gradle.kts+++ b/settings.gradle.kts@@ -108,8 +108,6 @@ include(":games:chess") include(":games:unblockjam") include(":games:wordmaker") include(":music")-include(":music:wear")-project(":music:wear").projectDir = file("music-wear") include(":clock") include(":games:pipes") include(":games:solitaire")