Files
SoftwareApp 6d031082a3 fix: keep the scan's foreground service inside Android's start budget
ScanController called stopService() from a Dispatchers.Default coroutine right
after startForegroundService(), so a scan that finished at once or a Cancel tap
could beat the pending foreground start on the main thread. ScanService then
never reached startForeground() and Android killed the process a few seconds
later with
RemoteServiceException$ForegroundServiceDidNotStartInTimeException - a stack
with no app frames.

- ScanService enters the foreground in onCreate() and at the top of every
  onStartCommand(), before the Cancel early-return.
- A refused startForeground() (start not allowed, missing service type or
  permission, rejected notification) is logged instead of crashing, and a
  notification error can no longer kill the state collector.
- The service stops itself when it observes scanning == false; nothing outside
  it calls stopService() any more.
- New Robolectric ScanServiceTest covers onCreate, the idle and cancel paths, a
  failing startForeground() and the Android 15 onTimeout path.
- Version 1.1.2 / versionCode 7: versionCode 6 (1.1.1) is already on a Play
  track. CHANGELOG, AGENTS.md, codemap, ROADMAP and the release checklist
  (1.1.2 artefact record and paste-ready notes) are updated.
2026-11-09 00:25:56 +01:00

278 lines
16 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Changelog
All notable changes to Foto Dup Finder are documented in this file.
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the
project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
`versionCode` and `versionName` are defined in `app/build.gradle.kts`. Each Play
upload needs a **higher `versionCode`** than every previous upload.
## [Unreleased]
## [1.1.2] — 2026-11-09 · versionCode 7
### Fixed
- **`ForegroundServiceDidNotStartInTimeException` when a scan starts or cancels
quickly.** `ScanController` called `stopService()` from a background coroutine
immediately after `startForegroundService()` (a scan that finished at once, or a
Cancel tap). When that stop beat the pending foreground start, `ScanService` never
ran `startForeground()` and Android killed the process a few seconds later with
`RemoteServiceException$ForegroundServiceDidNotStartInTimeException` — a stack with
no app frames. The service now enters the foreground in `onCreate()` *and* at the
top of every `onStartCommand()` (before the Cancel early-return), tolerates a
`startForeground()` that the system refuses instead of crashing, and stops itself
once `ScanState.scanning` goes false; nothing outside it calls `stopService()`
anymore. Covered by the new Robolectric `ScanServiceTest`.
### Changed
- **`versionName` 1.1.2 / `versionCode` 7.** `versionCode` 6 (1.1.1) is already on a
Play track, so the fix needs a new code.
## [1.1.1] — 2026-10-20 · versionCode 6
### Fixed
- **Release-only startup crash.** The minified release build died before
`Application.onCreate` in `androidx.startup.InitializationProvider` with
`Failed to create an instance of androidx.work.impl.WorkDatabase`. WorkManager
arrives transitively through `play-services-ads`, and R8 removed the generated
Room `WorkDatabase_Impl` no-argument constructor that Room invokes reflectively.
`app/proguard-rules.pro` now keeps that constructor. Debug builds were unaffected,
which is why the first internal-testing upload looked fine locally.
- **Release smoke testing.** `AGENTS.md` and `docs/PLAY_RELEASE_CHECKLIST.md` now
require launching a minified build before uploading; unit tests and
`assembleDebug` cannot catch R8-only startup failures.
### Changed
- **`versionName` 1.1.1 / `versionCode` 6.** The 1.1.0 build (`versionCode` 4) crashed
on startup, and the first 1.1.1 build consumed `versionCode` 5 before this corrected
build was uploaded. Play has therefore used codes 4 and 5; this build takes 6.
## [1.1.0] — 2026-10-20 · versionCode 4
### Added
- **Freemium model.** The app is free to download and use. The free tier shows one
anchored adaptive AdMob banner at the bottom of the scanner; a one-time in-app
purchase (`pro_no_ads`) removes it. Every duplicate-finding, selection and deletion
feature stays free — Pro only removes advertising.
- **Play Billing 9.1.0** with purchase, pending-purchase, acknowledgement and restore
handling. The entitlement is cached locally so an already-Pro install opens ad-free
offline and is reconciled with Play on resume.
- **UMP consent** (`user-messaging-platform` 4.0.0) before ad initialization, plus a
**Privacy options** entry point when UMP requires it.
- **Legacy paid-install grandfathering** through a build-time
`legacyPro.cutoffEpochMs`, so customers who bought the paid app keep the ad-free
tier.
- **Debug tools:** `DebugProToggle` (adb-driven free/Pro switch) and the existing
scan trigger.
- **Documentation:** [`AGENTS.md`](AGENTS.md), [`docs/codemap.md`](docs/codemap.md),
[`docs/codemap.mmd`](docs/codemap.mmd) and
[`docs/MONETIZATION.md`](docs/MONETIZATION.md).
### Changed
- **`versionName` 1.1.0 / `versionCode` 4.** Play has consumed codes 1–3.
- **New Play application id:** `de.softwareapp_hb.fotodup.finder.free` (debug
`.free.debug`). The Kotlin package and `namespace` stay
`de.softwareapp_hb.fotodup.finder`; only the installed/listing identity changes. This
makes the freemium build a **separate Play listing** from the old paid app, so the old
listing's price does not have to be changed irreversibly. Grandfathering checks both
packages' first-install times, but the old paid app must still be installed on the
first freemium launch; otherwise use promo codes/support.
- **Permissions.** The merged manifest now includes `INTERNET`,
`ACCESS_NETWORK_STATE`, `AD_ID`, the `ACCESS_ADSERVICES_*` Privacy Sandbox
permissions, `WAKE_LOCK` and `com.android.vending.BILLING`, merged by the ads and
Billing SDKs. The previous “no INTERNET permission” claim no longer applies.
- **Privacy policy and store copy** now describe advertising, consent, the
advertising ID and the optional purchase. Photo processing remains on-device;
photos are never uploaded.
- **Store/Play documentation** now treats the paid-app pricing section as historical
and documents the freemium Console steps, Data Safety answers and required
screenshot re-shoot.
### Fixed
- The old paid-app claims (“ad-free”, “no internet permission”, “pay once”) were
removed from the current README/PRIVACY/store wording so they cannot contradict the
shipped SDKs.
## [1.0.2] — 2026-10-18 · versionCode 3
### Changed
- **`versionCode` 3 instead of 2.** Play already holds a bundle with `versionCode` 2 and rejects
re-uploading it (*"Version code 2 has already been used"*), so this patch takes the next code.
`versionName` moves to 1.0.2 with it.
### Fixed
- **Play Console no longer reports deprecated edge-to-edge APIs.** The release build contained
`Window.setStatusBarColor`, `Window.setNavigationBarColor` and
`LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES`, all of which Android 15 deprecates for apps
targeting SDK 35+. They came from `ComponentActivity.enableEdgeToEdge()` (androidx.activity
1.13.0), whose per-API-level implementations still set the status/navigation bar scrims and use
the deprecated cutout mode on API 28/29. `ui/theme/EdgeToEdge` now performs the same setup with
current APIs only: `WindowCompat.setDecorFitsSystemWindows`, navigation-bar contrast off, cutout
mode `always` on API 30+, and light/dark bar icons following the system night mode. `MainActivity`
calls it instead of `enableEdgeToEdge()`; the theme still supplies the transparent bars below
API 35, and the existing inset handling in `ScannerScreen` is unchanged.
## [1.0.1] — 2026-10-13 · versionCode 2
### Fixed
- **A stalled media provider could still make a scan look frozen.** The per-call deadline above
stops a *single* stuck file, but not a provider that has stopped answering altogether — on the
test device `MediaProvider` was restarting repeatedly during the scan. Every remaining photo then
waits out the full deadline, so the scan grinds at roughly one photo per timeout and looks hung,
while each abandoned call parks another thread. `data/BoundedCall` now counts abandoned calls:
after three in a row with nothing succeeding in between it treats the provider as **stalled** and
lets the remaining calls fail fast, so the phase reaches its end and the unreadable files are
reported instead of the scan appearing to freeze. The cooldown scales with the call deadline, and
a successful call clears it, so a brief `MediaProvider` restart is picked up again. Pinned by
`BoundedCallTest` (50 blocking calls park a bounded number of threads; the breaker clears once
the provider answers) and by an end-to-end test that a provider read which never returns cannot
freeze the scan.
- **One unresponsive thumbnail could freeze the whole scan.** The perceptual pass asks the media
provider for a thumbnail (`ContentResolver.loadThumbnail`). On the test device that call never
returned for a single, perfectly valid HEIC — the provider hung inside its own decode — and the
scan sat at 99 % of "Looking for visually similar photos…" for ever, at 0 % CPU. The per-photo
`withTimeoutOrNull` could not help: coroutine cancellation is **cooperative**, so it cannot
interrupt a thread parked in a binder transaction. Every provider call (signature read, content
hash, thumbnail/fallback decode) now runs under a hard deadline (`data/BoundedCall`), and a call
that overruns is abandoned — that one photo is skipped and counted among the unreadable ones
instead of stopping the scan. `BoundedCallTest` pins the behaviour.
## [1.0.0] — 2026-10-13 · versionCode 1
First public release.
### Added
- Exact duplicate detection: files are bucketed by size, refined with a cheap
`SHA-256(size + first & last 32 KB)` signature, then confirmed with a full
SHA-256 content hash.
- Near-duplicate detection via a 64-bit perceptual difference hash (`dHash`) on a
9×8 grayscale downscale, clustered by Hamming distance with union-find.
- Three sensitivity presets: Exact copies only / Balanced (default) / Aggressive.
- Tiered, CPU-parallel scan pipeline with a persistent SQLite hash index, so repeat
scans only re-read files that changed.
- Results UI grouped by duplicate set, with thumbnails, a "BEST" marker and
per-group All / None selection.
- "Select all but best" helper that keeps the largest (then newest) copy.
- Safe deletion through the system consent dialog
(`MediaStore.createDeleteRequest`) or the system trash
(`createTrashRequest`); legacy direct delete on Android 10.
- Scans run in a `dataSync` **foreground service**, so a long scan keeps going while
the app is backgrounded, with a progress notification that can cancel it.
- Android 13/14 permission handling, including the partial "Selected photos" mode.
- Material 3 UI with dynamic colour and dark-mode support.
- No ads, no accounts, no analytics and no network permission.
### Changed
- **Localisation groundwork (M8).** Every user-visible string moved out of Kotlin into
`res/values/strings.xml`, with real `<plurals>` where the count can be one ("1 duplicate"
vs "3 duplicates", "1 bit" vs "5 bits"). The screen and the progress notification share a
single enum-to-resource mapping (`text.labelRes()`) so their wording cannot drift apart.
English is currently the only locale — but note that **Play's automatic translation covers
the store listing, not the app UI**, so this is the prerequisite for translating the UI.
- Near-duplicate detection now uses a **DCT perceptual hash (pHash)** plus **per-channel
RGB difference hashes**. A pair must satisfy both. Measured on the benchmark harness,
pHash alone recovered 0.683 of duplicates at zero false positives versus 0.530 for the
previous dHash, and joint accuracy was 0.867 F1 versus 0.738.
- The pHash distance cut is **fitted to each library** (`AdaptiveThreshold`) instead of
being a fixed constant, because unrelated pairs grow with n² and a constant cannot hold
across library sizes.
### Fixed
- **Scan hang at the head/tail read (real root cause).** The byte-reading loops treated only a
negative result as end-of-stream. A non-blocking, pipe-backed file descriptor — which some media
providers hand back — reports **0** ("no bytes yet") instead, so `while (buffer.hasRemaining())`
spun forever and the scan froze mid-phase, pegging a CPU core. `PhotoHasher.readAt`,
`readAtMost` and the streaming SHA-256 now all treat a non-positive read as the end of the data.
Two watchdog tests (daemon thread + join timeout) make a regression fail rather than hang.
- Note on the per-photo timeout added just before: coroutine cancellation is cooperative, so it
bounds a *slow* file but cannot interrupt a call blocked in a native read. The loop guard above
is the actual fix for a stuck descriptor; the timeout stays as a bound on slow work.
- **A slow scan tail looked like a freeze.** Progress was only reported every `1/n` of a phase and
then at completion, so the final ~1 % of the library (up to ~50 photos) produced no update at
all — a stall of a minute looked identical to a hang. Progress now keeps updating through the
last interval.
- **One pathological file could stall a whole scan.** Each per-photo step now runs under a 15 s
budget, so a corrupt entry a provider blocks on, or an unusually expensive HEIC/RAW decode, is
abandoned and reported as unreadable instead of freezing the scan.
- **Hardened file handling (M7).** Every per-file step now sits behind a single failure
boundary, so a corrupt, truncated, zero-byte, RAW or outright hostile file is skipped
instead of aborting the scan or crashing the app. Coroutine cancellation still propagates
through it, a failed index write no longer discards a scan that already completed, and the
number of unreadable files is reported in the results rather than passing silently.
- Decode arithmetic moved to `core/DecodeMath` with division rather than multiplication, so a
crafted image declaring 100 000 x 100 000 cannot overflow the sample-size calculation.
- The per-group button now counts the copies **actually ticked in that row** rather than the
app's suggestion, and acts on exactly what it counts. With BEST + DUP1 + DUP2, unticking
DUP2 now reads "Remove 1 duplicate" instead of still claiming 2. When nothing in a row is
ticked the button says so and is disabled.
- **EXIF orientation** is now applied on the fallback decode path. `BitmapFactory` ignores
EXIF while the media provider's thumbnail does not, so the same photo could hash
differently depending on which path served it — and a thumbnail-cache eviction between
scans could leave a cached hash that no longer matched.
- Candidate-pair enumeration no longer keeps a global set of compared pairs, which for a
20 000-photo library meant millions of boxed `Long`s. Memory is now bounded by the
largest neighbour set.
- The bottom action bar no longer overlaps the system navigation bar (it now applies
`navigationBarsPadding()`); previously the trash/delete button sat underneath the
gesture handle or the 3-button bar on edge-to-edge devices.
- Deleting one group no longer clears a selection made in a different group.
- The *BEST* badge, "select all but best" and the per-group delete all use one rule
(`DuplicateGroup.suggestedKeep()`), so they can no longer disagree.
- Only one system confirmation dialog can be in flight; rapidly tapping a delete button
no longer queues up several approvals to dismiss one after another.
### Added (UI)
- **Two-step removal.** "Remove N duplicates" on a group row (or "Remove all selected" in
the action bar) only *stages* photos: the row disappears from the list immediately and
**nothing is deleted**. A separate **Apply** button performs the real removal, so on
Android 11+ there is **one** system confirmation for the whole batch instead of one
dialog per group. **Discard** undoes all staging.
- The list always shows what is *still* duplicated: staged copies are taken out of their
group, and a group left with fewer than two copies is dropped entirely.
- The copy marked *BEST* is always shown **first** in its group
(`DuplicateGroup.displayOrder()`), so it is visible as a reference even when the
group is collapsed. Previously it could be scrolled out of view.
### Performance
- Exact-duplicate hashing now runs **only** for photos that share a file size with
at least one other photo. In a typical library most photos have a unique size, so
for those no file is opened at all.
- The perceptual hash is taken from the media provider's **thumbnail cache**
(`loadThumbnail`) instead of decoding the full-resolution original, with a heavily
subsampled decode as a fallback.
- The head and tail bytes of a file are read through a **single** file descriptor.
- Hashing runs in small batches, reducing coroutine overhead from one coroutine per
photo to one per batch.
- The hash index is written with a compiled SQLite statement.
- Per-stage timings are shown in the results summary so slow stages are visible.
### Known limitations
- Images only — video files are not scanned.
- `dHash` ignores EXIF rotation, so a physically rotated copy will not match.
- The Aggressive preset may miss a few pairs because of the banded candidate search.
- The first scan of a very large library takes a while; later scans reuse the index.