fix(android): ExclusionsViewModel in factory — 0.10.7 launch crash #1374

Merged
chris merged 2 commits from fix/exclusions-viewmodel-factory into main 2026-10-25 14:28:59 +01:00
Owner

Root cause (verified on the user's device)

Release 0.10.7 crashes on every launch:

IllegalArgumentException: Unknown ViewModel class: dev.memories.android.ui.exclusions.ExclusionsViewModel
    at AppViewModelFactory.create(AppViewModelFactory.kt:200)  // else -> throw
    at MemoriesAppKt.MemoriesApp(MemoriesApp.kt:709)

MemoriesApp creates the shared exclusion ledger (exclusionLedger: ExclusionsViewModel = viewModel(factory = viewModelFactory), app-scope, line 217) eagerly at startup, but AppViewModelFactory had no branch for ExclusionsViewModel — the when fell through to else -> throw. The feature PR (#1372) shipped the ViewModel and screen but never registered the factory branch; the per-VM unit tests construct the ViewModel directly and structurally cannot catch a missing branch.

Fix

  1. Register the branch in AppViewModelFactory (pattern-identical to TrashViewModel):

    • excludedMedia = container.excludedMedia, mediaStates = container.mediaStates (both already on AppContainer)
    • excludedAlbumsSource = PreferenceExcludedAlbumsSource(container.albumPreferences) — the same album-preference store the album screens read
    • api / sessionProvider / onUnauthorized wired like every other authenticated branch
    • intentRecorder = the same spec-044-S3 record-on-failure retry queue the trash/timeline branches use ("Auch aus Memories entfernen" reuses the trash endpoint)
    • resolver keeps the ViewModel default for now — the production ScanResolvingExclusions needs a MediaStoreScanner, which the container does not expose (follow-up wiring, noted in a code comment; excludes still work — only the pre-exclude "already in Memories?" analysis degrades until then)
  2. Minimal testability seam: the factory now takes a narrow AppViewModelFactory.Deps interface (one member per AppContainer property it reads) with a ContainerDeps adapter; the existing AppViewModelFactory(container) constructor is kept, so MainActivity and all call sites are unchanged. AppContainer itself cannot be built in a JVM test (eager EncryptedSharedPreferences/AndroidKeyStore + WorkManager).

  3. Regression canary test (AppViewModelFactoryTest, Robolectric because one branch reads Build.MANUFACTURER):

    • creates ExclusionsViewModel — the 0_10_7 launch crash regression — the exact call that crashed every launch
    • creates every other ViewModel the app requests from the factory — all 17 remaining branches, asserting the created instance is of the requested class (catches missing branches and dispatch-order mistakes)
    • an unregistered ViewModel class still fails loudly — the else guard stays
  4. KNOWN_ISSUES.md: ISSUE-202 (high / resolved / area:android).

Validation

./gradlew :app:testDebugUnitTest — 691 tests, 0 failures, 0 errors, 0 skipped (new canary: 3/3).

## Root cause (verified on the user's device) Release 0.10.7 crashes on **every launch**: ``` IllegalArgumentException: Unknown ViewModel class: dev.memories.android.ui.exclusions.ExclusionsViewModel at AppViewModelFactory.create(AppViewModelFactory.kt:200) // else -> throw at MemoriesAppKt.MemoriesApp(MemoriesApp.kt:709) ``` `MemoriesApp` creates the shared exclusion ledger (`exclusionLedger: ExclusionsViewModel = viewModel(factory = viewModelFactory)`, app-scope, line 217) eagerly at startup, but `AppViewModelFactory` had no branch for `ExclusionsViewModel` — the `when` fell through to `else -> throw`. The feature PR (#1372) shipped the ViewModel and screen but never registered the factory branch; the per-VM unit tests construct the ViewModel directly and structurally cannot catch a missing branch. ## Fix 1. **Register the branch** in `AppViewModelFactory` (pattern-identical to `TrashViewModel`): - `excludedMedia = container.excludedMedia`, `mediaStates = container.mediaStates` (both already on `AppContainer`) - `excludedAlbumsSource = PreferenceExcludedAlbumsSource(container.albumPreferences)` — the same album-preference store the album screens read - `api` / `sessionProvider` / `onUnauthorized` wired like every other authenticated branch - `intentRecorder` = the same spec-044-S3 record-on-failure retry queue the trash/timeline branches use ("Auch aus Memories entfernen" reuses the trash endpoint) - `resolver` keeps the ViewModel default for now — the production `ScanResolvingExclusions` needs a `MediaStoreScanner`, which the container does not expose (follow-up wiring, noted in a code comment; **excludes still work** — only the pre-exclude "already in Memories?" analysis degrades until then) 2. **Minimal testability seam**: the factory now takes a narrow `AppViewModelFactory.Deps` interface (one member per `AppContainer` property it reads) with a `ContainerDeps` adapter; the existing `AppViewModelFactory(container)` constructor is kept, so `MainActivity` and all call sites are unchanged. `AppContainer` itself cannot be built in a JVM test (eager `EncryptedSharedPreferences`/AndroidKeyStore + WorkManager). 3. **Regression canary test** (`AppViewModelFactoryTest`, Robolectric because one branch reads `Build.MANUFACTURER`): - `creates ExclusionsViewModel — the 0_10_7 launch crash regression` — the exact call that crashed every launch - `creates every other ViewModel the app requests from the factory` — all 17 remaining branches, asserting the created instance is of the requested class (catches missing branches *and* dispatch-order mistakes) - `an unregistered ViewModel class still fails loudly` — the `else` guard stays 4. `KNOWN_ISSUES.md`: ISSUE-202 (`high` / `resolved` / `area:android`). ## Validation `./gradlew :app:testDebugUnitTest` — **691 tests, 0 failures, 0 errors, 0 skipped** (new canary: 3/3).
fix(android): register ExclusionsViewModel in AppViewModelFactory — launch crash
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 3s
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build Android CI image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Deploy review instance (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 7s
Build and Deploy / Android unit tests and debug APK (push) Successful in 3m49s
855b69dc32
fix(android): wire production exclusions resolver via container scanner
All checks were successful
Wiki Sync / Sync wiki from docs (push) Has been skipped
Build and Deploy / Detect changed services and test scopes (push) Successful in 3s
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Smoke people worker (push) Has been skipped
Build and Deploy / Build postgres image (push) Has been skipped
Build and Deploy / Build Android CI image (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Deploy postgres (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Deploy review instance (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 5s
Build and Deploy / Android unit tests and debug APK (push) Successful in 4m9s
500ef4eac3
chris merged commit 1de0a88468 into main 2026-10-25 14:28:59 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!1374
No description provided.