Skip to content

Auto-retry download by default#86

Draft
Kisty wants to merge 34 commits into
khushpanchal:masterfrom
Kisty:feature/auto-retry-download-by-default
Draft

Auto-retry download by default#86
Kisty wants to merge 34 commits into
khushpanchal:masterfrom
Kisty:feature/auto-retry-download-by-default

Conversation

@Kisty

@Kisty Kisty commented May 14, 2026

Copy link
Copy Markdown

Adds auto-retry downloads by default if the download is not cancelled. Can be optionally disabled in DownloadConfig.
When the download is scheduled for a retry, a new status RETRY_QUEUED is made, so to differentiate between first attempt and any retries.
Also, fixed demo app links & added some basic Worker tests checking statuses as well as checking the auto-retry functionality.

Kisty added 4 commits May 14, 2026 17:27
When download fails, it will schedule another download attempt.
Defaults autoRetry true. Can be optionally turned off in DownloadConfig.
@Kisty Kisty changed the title Feature/auto retry download by default Auto-retry download by default May 14, 2026
@Kisty

Kisty commented May 15, 2026

Copy link
Copy Markdown
Author

Fixes #85

@Kisty Kisty changed the title Auto-retry download by default wip Auto-retry download by default May 15, 2026
@Kisty

Kisty commented May 15, 2026

Copy link
Copy Markdown
Author

While it does retry the download, it seems to create a new file e.g. myFile(1).zip and does not then report the progress back using the original flow for the download. Needs further work.

@Kisty
Kisty marked this pull request as draft May 15, 2026 00:11
@Kisty Kisty changed the title wip Auto-retry download by default Auto-retry download by default May 15, 2026
@Kisty
Kisty force-pushed the feature/auto-retry-download-by-default branch from ca4bb10 to 5ef9bf3 Compare May 18, 2026 16:11
Kisty added 4 commits May 18, 2026 17:19
- Detect changes in ETag or Content-Length to trigger a fresh download.
- Skip redundant downloads if the file is already successful and headers match the database.
- Reset `downloadedBytes` and update `totalBytes` when server-side changes are detected.
- Add `ServerUpdateTest` to verify update and skip logic.
* Sync database with disk on initialization and during queries to mark missing files as FAILED.
* Use a stable hash of the URL for filenames instead of random UUIDs to ensure predictable naming.
* Update tests to verify disk consistency and stable ID generation.
* Simplify download request preparation logic.
- Throttle disk existence checks in `syncAndMap` to a 5-second interval to reduce I/O.
- Optimize `WorkInfo` observation by using an entity map instead of repeated database lookups.
- Reduce redundant logging by checking for status transitions before logging events.
- Add `PerformanceTest` to verify throttling logic for disk checks.
- Remove unnecessary `runBlocking` call in `Ketch.download`.
@Kisty

Kisty commented May 26, 2026

Copy link
Copy Markdown
Author

I think this works in theory and in our app. Am just fixing an issue where the download doesn't automatically-retry immediately when it has re-established connection. Will do so by adding a param on DownloadConfig for requiresInternet or something like that.

Kisty added 11 commits May 26, 2026 18:41
- Add `retryOnNetworkGain` to `DownloadConfig` to control connectivity-based retries (defaults to `true`).
- Update `DownloadManager` to apply the `NetworkType.CONNECTED` constraint to work requests when enabled.
- Add `ConnectivityRetryTest` to verify `WorkManager` constraint application based on configuration.
Set download work request as expedited to allow retried downloads in background to start notifications (foreground services)
- Introduce a 200ms delay before calling `setForeground()` in `DownloadWorker`.
- Mitigate a race condition in Android 14+ where calling `setForeground()` immediately after an expedited worker starts can trigger a `ForegroundServiceStartNotAllowedException`.
Due to AndroidX Work 2.10.5 upgrade
Start delay increase required for foreground workaround
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant