Cancel active downloads on network change#479
Open
ElCruncharino wants to merge 1 commit into
Open
Conversation
Real-Debrid can flag an account for downloading from multiple IPs, so add an opt-in setting that cancels active embedded (OkHttp/WorkManager) downloads whenever the device's default network changes, such as switching from wi-fi to mobile data. A new NetworkChangeDownloadCanceller is registered once from the Application class, since embedded downloads run in a foreground service backed WorkManager worker that can keep going while the app is backgrounded, unlike the existing connectivity check tied to the main activity's lifecycle. It compares the Network instance Android hands back on each connectivity change, and on an actual change cancels every active download through a new shared WorkManager tag, reusing the same stop mechanism already wired to the per-download notification's Stop action. There is no resume support anywhere in the download code, so this cancels the transfer outright rather than pausing it; the user has to restart it manually afterward, which the setting's description makes explicit. The system download manager path is left out of this change: it only exposes enqueue/query/remove with no pause-resume primitive, and the app currently discards the download IDs it would need to cancel anything, so it needs its own follow-up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Real-Debrid can flag an account for downloading from multiple IPs, so this adds an opt-in
setting that cancels active embedded downloads whenever the device's default network changes,
like switching from wi-fi to mobile data.
A NetworkChangeDownloadCanceller is registered once from the Application class instead of an
Activity, since downloads run in a foreground-service-backed WorkManager worker that can keep
going while the app is backgrounded. It compares the Network instance Android hands back on
each connectivity change, and cancels every active download through a shared WorkManager tag
on an actual change, reusing the same stop mechanism already wired to the per-download
notification's Stop action.
There's no resume support anywhere in the download code, so this cancels the transfer outright
instead of pausing it; the user has to restart it manually, which the setting's description
says plainly.
The system download manager is left out of this since it only exposes enqueue/query/remove
with no pause-resume primitive, and the app currently discards the download IDs it would need
to cancel anything, matching what you were unsure about in the issue.
Closes #421