π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile] Cancel obsolete iOS background requests before reconfiguring
laurenspriem8a4142b0c25f
diff --git a/mobile/apps/photos/plugins/ente_background_manager/README.md b/mobile/apps/photos/plugins/ente_background_manager/README.mdindex 7e52a367b6..c59e8e6c42 100644--- a/mobile/apps/photos/plugins/ente_background_manager/README.md+++ b/mobile/apps/photos/plugins/ente_background_manager/README.md@@ -24,7 +24,7 @@ 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. iOS stores the last successfully submitted policy for each task, so a later configuration call or normal delivery can apply unfinished updates after a process restart. Older stored configurations without this submission record are reconciled once. Android tags its native requests so later configuration calls can find and cancel removed tasks even if an earlier cancellation was interrupted. Neither platform retries automatically.+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. iOS stores the last successfully submitted policy for each task, so a later configuration call or normal delivery can apply unfinished updates after a process restart. Older stored configurations without this submission record are reconciled once. When reconfigured, iOS cancels this plugin's removed identifiers before replacing their saved configuration, including identifiers the app no longer registers after an update. Android tags its native requests so later configuration calls can find and cancel removed tasks even if an earlier cancellation was interrupted. Neither platform retries 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.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 ead74d15a7..9059591ed9 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@@ -141,6 +141,12 @@ final class BackgroundRuntime: NSObject {return}let identifiers = enabled ? Set(parsed.map(\.identifier)) : []+ let owned = Set(registrations.keys)+ .union(configuration.tasks.map(\.identifier))+ .union((configuration.submitted ?? []).map(\.identifier))+ for identifier in owned.subtracting(identifiers) {+ BGTaskScheduler.shared.cancel(taskRequestWithIdentifier: identifier)+ }let next = StoredConfiguration(enabled: enabled, tasks: parsed,submitted: configuration.submitted?.filter { identifiers.contains($0.identifier) })@@ -168,10 +174,6 @@ final class BackgroundRuntime: NSObject {let pending = Dictionary(requests.map { ($0.identifier, $0) }, uniquingKeysWith: { first, _ in first })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)- }var failure: Error?for task in desired {if pending[task.identifier] != nil && (self.configuration.submitted ?? []).contains(task)