fix(background): keep library scans and update downloads running with the screen off

Android froze the process once the activity stopped, because only track downloads held a foreground service. A dataSync BackgroundWorkService with a partial wake lock now covers library scans and in-app APK downloads, and stops when the last task ends or the system timeout fires. Its notification shows the existing localized progress, so no duplicate appears. If Android refuses the service, work continues as before.

On iOS a scan holds its own background task; on expiry it cancels the scan cleanly instead of being suspended.
This commit is contained in:
zarzet committed 2026-10-01 18:46:21 +07:00
1 parent ad9670eb46
commit 6e6d9dd00e
8 files changed
+455 -25

No files matched your search

+30 -18
View File
@@ -69,26 +69,38 @@ class _UpdateDialogState extends State<UpdateDialog> {
final notificationService = NotificationService();
final filePath = await ApkDownloader.downloadApk(
url: apkUrl,
// Without a foreground service the download freezes when the screen
// turns off; its notification then carries the progress.
await notificationService.beginUpdateDownloadWork(
version: widget.updateInfo.version,
expectedSha256: widget.updateInfo.apkSha256,
onProgress: (received, total) {
if (mounted) {
setState(() {
_progress = total > 0 ? received / total : 0;
final receivedMB = formatMegabytes(received);
final totalMB = formatMegabytes(total);
_statusText = '$receivedMB / $totalMB MB';
});
}
notificationService.showUpdateDownloadProgress(
version: widget.updateInfo.version,
received: received,
total: total,
);
},
);
final String? filePath;
try {
filePath = await ApkDownloader.downloadApk(
url: apkUrl,
version: widget.updateInfo.version,
expectedSha256: widget.updateInfo.apkSha256,
onProgress: (received, total) {
if (mounted) {
setState(() {
_progress = total > 0 ? received / total : 0;
final receivedMB = formatMegabytes(received);
final totalMB = formatMegabytes(total);
_statusText = '$receivedMB / $totalMB MB';
});
}
notificationService.showUpdateDownloadProgress(
version: widget.updateInfo.version,
received: received,
total: total,
);
},
);
} finally {
await notificationService.endBackgroundWork(
NotificationService.updateDownloadWorkKind,
);
}
if (filePath != null) {
await notificationService.cancelUpdateNotification();