Skip to content

Cancel active downloads on network change#479

Open
ElCruncharino wants to merge 1 commit into
LivingWithHippos:masterfrom
ElCruncharino:fix/pause-downloads-on-network-change
Open

Cancel active downloads on network change#479
ElCruncharino wants to merge 1 commit into
LivingWithHippos:masterfrom
ElCruncharino:fix/pause-downloads-on-network-change

Conversation

@ElCruncharino

Copy link
Copy Markdown
Contributor

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

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.
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.

Pause/stop downloads on network change

1 participant