π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile] Preserve iOS background schedules and failed updates
laurenspriem9518a10707ec
diff --git a/mobile/apps/photos/plugins/ente_background_manager/README.md b/mobile/apps/photos/plugins/ente_background_manager/README.mdindex 07c4f6c640..cbd1b71c3c 100644--- a/mobile/apps/photos/plugins/ente_background_manager/README.md+++ b/mobile/apps/photos/plugins/ente_background_manager/README.md@@ -22,6 +22,8 @@ Before supplying `foregroundStopTimeout`, validate the lifetime of the consumer'Each platform has one process-local runtime. Admission checks backend eligibility, the active execution slot, and native foreground visibility before creating an engine. Busy or foreground deliveries finish as skips. Every admitted run captures its configuration and dispatcher binding and uses a fresh engine. On Android, a stop received during Flutter initialization retires the run before creating an engine.+The native eligibility callback controls whether work may run; it preserves future schedules when eligibility is temporarily false. Scheduling follows the configured enablement and task identifiers. On iOS, failed schedule updates remain pending for a later configuration call or normal delivery to apply them; the plugin does not retry automatically.+The slot remains occupied during startup, execution, cleanup, and teardown. Native callbacks and timers are tied to a unique invocation. Foreground entry always requests stopping, including during startup. Stops remain latched; repeated visibility changes cannot revive a task or extend its grace. A callback returning `completed` after a stop request is reported as `stopped`. Configuration updates affect later runs only.Normal completion, startup failure, system interruption, and configured forced teardown share one retirement path. Retirement invalidates timers, detaches the task channel, destroys the background engine, and completes the native invocation once. iOS re-arms normal future opportunities independently of Dart. No plugin retry loop, work queue, engine pool, or persistent event history is used.diff --git a/mobile/apps/photos/plugins/ente_background_manager/ios/Classes/BackgroundRuntime.swift b/mobile/apps/photos/plugins/ente_background_manager/ios/Classes/BackgroundRuntime.swiftindex 9c9d56ea85..759e24dd47 100644--- a/mobile/apps/photos/plugins/ente_background_manager/ios/Classes/BackgroundRuntime.swift+++ b/mobile/apps/photos/plugins/ente_background_manager/ios/Classes/BackgroundRuntime.swift@@ -153,12 +153,12 @@ final class BackgroundRuntime: NSObject {}let pending = Dictionary(requests.map { ($0.identifier, $0) }, uniquingKeysWith: { first, _ in first })- let enabled = self.configuration.enabled && self.isAllowed()- let desired = enabled ? self.configuration.tasks : []+ let desired = self.configuration.enabled ? self.configuration.tasks : []let identifiers = Set(desired.map(\.identifier))for identifier in self.registrations.keys where !identifiers.contains(identifier) {BGTaskScheduler.shared.cancel(taskRequestWithIdentifier: identifier)}+ self.changedTasks.formIntersection(identifiers)var failure: Error?for task in desired {if pending[task.identifier] != nil && !self.changedTasks.contains(task.identifier) {@@ -166,6 +166,7 @@ final class BackgroundRuntime: NSObject {}do {try self.submit(task, delayMs: task.initialDelayMs)+ self.changedTasks.remove(task.identifier)} catch {failure = errorself.report(@@ -173,7 +174,6 @@ final class BackgroundRuntime: NSObject {error: String(describing: error))}}- self.changedTasks.removeAll()self.reconciling = falselet results = self.configurationResultsself.configurationResults.removeAll()@@ -218,7 +218,7 @@ final class BackgroundRuntime: NSObject {private func deliver(_ task: BGTask, startedAt: TimeInterval) {scheduleRevision += 1- guard configuration.enabled, isAllowed(),+ guard configuration.enabled,let policy = configuration.tasks.first(where: { $0.identifier == task.identifier })else {BGTaskScheduler.shared.cancel(taskRequestWithIdentifier: task.identifier)@@ -235,7 +235,9 @@ final class BackgroundRuntime: NSObject {error: String(describing: error))}let skip: String?- if active != nil {+ if !isAllowed() {+ skip = "disabled"+ } else if active != nil {skip = "busy"} else if isForeground || UIApplication.shared.applicationState != .background {skip = "foreground"