Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mobile][photos] Anchor iOS background task deadline to task start

laurenspriemf14ebeaf9506
diff --git a/mobile/apps/photos/lib/utils/bg_task_utils.dart b/mobile/apps/photos/lib/utils/bg_task_utils.dart
index 09db1d83a2..d365288ed3 100644
--- a/mobile/apps/photos/lib/utils/bg_task_utils.dart
+++ b/mobile/apps/photos/lib/utils/bg_task_utils.dart
@@ -14,6 +14,7 @@ import "package:workmanager/workmanager.dart" as workmanager;
@pragma('vm:entry-point')
void callbackDispatcher() {
workmanager.Workmanager().executeTask((taskName, inputData) async {
+ final DateTime taskStartedAt = DateTime.now();
final TimeLogger tlog = TimeLogger();
// Deferred error construction: an eagerly created Future.error with no
// listener surfaces as an unhandled exception even on success.
@@ -24,8 +25,11 @@ void callbackDispatcher() {
() async {
try {
BgTaskUtils.$.info('Task started $tlog');
+ final Duration remainingBudget = Platform.isIOS
+ ? kBGTaskTimeout - DateTime.now().difference(taskStartedAt)
+ : const Duration(hours: 1);
await runBackgroundTask(taskName, tlog).timeout(
- Platform.isIOS ? kBGTaskTimeout : const Duration(hours: 1),
+ remainingBudget.isNegative ? Duration.zero : remainingBudget,
onTimeout: () async {
BgTaskUtils.$.warning(
"TLE, committing seppuku for taskID: $taskName",