Skip to content

Commit 4137a39

Browse files
committed
refactor: migrate UI to service-backed flows and harden Android Auto security
Migrate `HomeViewModel` and `PlaylistViewModel` to observe reactive flows from `MusicService` for playback state, position, and context, eliminating UI-side polling loops. Replace substring-based package validation for Android Auto with exact matching in a new `AndroidAutoBrowserClientValidator`. Additional changes include: - Expand test coverage for API v1 contracts, scrobble payloads, and token refresh edge cases - Enhance `SettingsManager` to preserve refresh token expiry when tokens are omitted in responses - Refactor `MusicService` and `MusicPlaybackManager` to expose playback state via `StateFlow` - Update `README.md` and `CHANGELOG.md` with detailed project overview and technical specs - Add `AGENTS.md` with repository instructions and validation workflows for coding assistants
1 parent 2e1cd6b commit 4137a39

14 files changed

Lines changed: 991 additions & 561 deletions

File tree

AGENTS.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Coding Agent Instructions
2+
3+
These instructions apply to coding agents working in this repository.
4+
5+
## Project Shape
6+
7+
- The Git repository root is `melodee-player/`, but the Android Gradle project
8+
root is `melodee-player/src/`.
9+
- Run Gradle from `src/`, not from the repository root.
10+
- The app module is `src/app`; the macrobenchmark module is `src/benchmark`.
11+
- The app targets Melodee API v1 and Android SDK 36, with minSdk 23.
12+
- The local Android SDK path used in this workspace is
13+
`/home/steven/Android/Sdk`.
14+
15+
## Change Discipline
16+
17+
- Keep edits scoped to the requested behavior and existing architecture.
18+
- Do not revert user changes or unrelated workspace changes.
19+
- Prefer the existing Kotlin, Compose, Retrofit, Media3, coroutine, and
20+
SharedPreferences patterns before introducing new frameworks.
21+
- Treat authentication, Android Auto, media playback, API models, and Gradle
22+
configuration as high-risk areas. Add or update tests when touching them.
23+
- Do not add local app-data SQLite/Room persistence unless explicitly requested.
24+
Media3 already uses its own SQLite-backed cache metadata internally.
25+
26+
## Changelog
27+
28+
- Update `CHANGELOG.md` for every notable change before finishing work.
29+
- Add new entries under `## [Unreleased]` by default. If the user says the
30+
current version has not been released yet, or the task is explicitly part of
31+
an in-progress release section such as `## [1.8.0]`, update that active
32+
version section instead.
33+
- Follow the existing Keep a Changelog categories: `Added`, `Changed`,
34+
`Deprecated`, `Removed`, `Fixed`, and `Security`.
35+
- Include user-visible behavior changes, API compatibility changes,
36+
authentication/session changes, Android Auto changes, dependency/toolchain
37+
changes, security hardening, and important test coverage additions.
38+
- Do not add changelog entries for purely mechanical formatting changes unless
39+
they materially affect users, maintainers, CI, or release behavior.
40+
- Keep entries concise and factual. Mention the affected subsystem when useful.
41+
- If a task intentionally skips a changelog update, state why in the final
42+
response.
43+
44+
## README And Docs
45+
46+
- Keep `README.md` accurate when setup, build commands, API behavior,
47+
authentication behavior, Android Auto behavior, or project layout changes.
48+
- Some files under `docs/` are historical review/planning artifacts. Do not
49+
treat them as more authoritative than current source, Gradle files,
50+
`README.md`, and `CHANGELOG.md`.
51+
- If docs contradict source code, verify against source before editing.
52+
53+
## Authentication And API
54+
55+
- Preserve refresh tokens when API responses omit rotated refresh-token values.
56+
- Android Auto must be able to restore existing stored authentication without
57+
requiring the user to open the handheld UI again.
58+
- Invalid/rejected refresh tokens may clear authentication; transient refresh
59+
failures should keep stored credentials available for retry.
60+
- API contract changes should be covered by tests under
61+
`src/app/src/test/java/com/melodee/autoplayer/api` or related model tests.
62+
- The current OpenAPI reference used during this work was
63+
`/home/steven/Downloads/v1.json`; verify with the user before assuming that
64+
path is still current in future sessions.
65+
66+
## Android Auto And Playback
67+
68+
- `MusicService` is exported for Android Auto discovery; caller validation must
69+
remain strict before returning browse content.
70+
- Do not trust Android Auto callers by substring package-name checks. Use exact
71+
trusted packages and package/UID ownership checks.
72+
- UI playback state should be driven by service/manager flows where possible,
73+
not by UI-owned polling loops.
74+
- When changing playback state, verify handheld UI and Android Auto behavior:
75+
current song, play/pause, queue, metadata, notification controls, and auth
76+
restoration.
77+
78+
## Validation
79+
80+
- Always run:
81+
82+
```bash
83+
git diff --check
84+
```
85+
86+
- For Markdown-only changes, `git diff --check` is usually enough.
87+
- For test-only changes, run the targeted test class and preferably the full
88+
unit suite:
89+
90+
```bash
91+
cd src
92+
ANDROID_HOME=/home/steven/Android/Sdk ./gradlew testDebugUnitTest --stacktrace
93+
```
94+
95+
- For production Android code, build logic, shared models, authentication,
96+
Android Auto, networking, or playback changes, run the full build:
97+
98+
```bash
99+
cd src
100+
ANDROID_HOME=/home/steven/Android/Sdk ./gradlew build --stacktrace
101+
```
102+
103+
- Connected tests and benchmarks require a device or emulator:
104+
105+
```bash
106+
cd src
107+
ANDROID_HOME=/home/steven/Android/Sdk ./gradlew connectedDebugAndroidTest
108+
ANDROID_HOME=/home/steven/Android/Sdk ./gradlew :benchmark:connectedCheck
109+
```
110+
111+
- If a validation command cannot be run, explain why and report what was run
112+
instead.
113+
114+
## Final Response Expectations
115+
116+
- Summarize what changed, what was verified, and any residual risk.
117+
- Mention skipped validations explicitly.
118+
- Keep file references precise for important source or documentation changes.

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ This file records notable project changes. It follows the
2727
service before exposing browse content.
2828
- Added debug-symbol keep rules for native libraries used by AndroidX graphics,
2929
benchmark, DataStore, and tracing dependencies.
30+
- Added focused authentication persistence tests for omitted refresh-token
31+
responses, refresh-token expiry retention, transient refresh failures, invalid
32+
refresh failures, and Android Auto service-side authentication restoration.
33+
- Added OpenAPI v1 contract tests covering authentication, refresh-token
34+
requests, playlist and favorite route placeholders, scrobble payloads and
35+
error responses, nullable refresh-token fields, and artist genre arrays.
36+
- Added repository instructions for coding agents requiring changelog updates
37+
for notable code, behavior, dependency, security, and documentation changes.
38+
- Added project-specific coding-agent guidance for nested Gradle usage,
39+
validation, authentication, API contracts, Android Auto, playback, and
40+
documentation expectations.
3041

3142
### Changed
3243

@@ -57,6 +68,17 @@ This file records notable project changes. It follows the
5768
SDK 36, JDK 21, Gradle 9.5.1, and dependency-version changes.
5869
- Updated the benchmark module to compile and target SDK 36 with the same JDK
5970
21 toolchain configuration as the app module.
71+
- Updated `HomeViewModel` and `PlaylistViewModel` to collect playback state,
72+
current song, playback context, duration, and position from service-backed
73+
flows instead of running UI-owned polling loops.
74+
- Updated `MusicService` and `MusicPlaybackManager` to expose and maintain
75+
flow-backed playback progress for bound UI consumers.
76+
- Updated the README to document current setup, API v1 authentication behavior,
77+
Android Auto behavior, testing commands, and repository layout.
78+
- Cleaned Android Studio commit-inspection warnings in playback, playlist,
79+
home, service, and model serialization code by removing dead helpers,
80+
simplifying redundant conditions, and keeping only intentional Android
81+
lifecycle suppressions.
6082

6183
### Fixed
6284

@@ -84,3 +106,5 @@ This file records notable project changes. It follows the
84106
disabling OkHttp body logging.
85107
- Kept the media browser service exported for Android Auto discovery while
86108
adding caller checks before returning a browser root.
109+
- Tightened Android Auto media browser caller classification by replacing
110+
package-name substring trust with exact trusted package matching.

0 commit comments

Comments
 (0)