Skip to content

Commit

Permalink
Add possibility to disable scheduling of background tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Jüni committed Mar 9, 2022
1 parent 998034c commit 460c357
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/DP3TSDK/Background/DP3TBackgroundTaskManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class DP3TBackgroundTaskManager {
private let serviceClient: ExposeeServiceClientProtocol

private weak var tracer: Tracer!

var shouldReschedule: Bool = true

init(handler: DP3TBackgroundHandler?,
keyProvider: DiagnosisKeysProvider,
Expand Down Expand Up @@ -183,6 +185,8 @@ class DP3TBackgroundTaskManager {

@available(iOS 13.0, *)
private func scheduleBackgroundTasks() {
guard self.shouldReschedule else { return }

logger.trace()

// Schedule next app refresh task 12h in the future
Expand Down
4 changes: 4 additions & 0 deletions Sources/DP3TSDK/DP3TSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ class DP3TSDK {
exposureDayStorage.reset()
URLCache.shared.removeAllCachedResponses()
}

func setBackgroundTasksEnabled(_ enabled: Bool) {
backgroundTaskManager.shouldReschedule = enabled
}

@objc func backgroundRefreshStatusDidChange() {
let new = UIApplication.shared.backgroundRefreshStatus
Expand Down
6 changes: 6 additions & 0 deletions Sources/DP3TSDK/DP3TTracing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ public enum DP3TTracing {
instance = nil
}

@available(iOS 12.5, *)
public static func setBackgroundTasksEnabled(_ enabled: Bool) {
instancePrecondition()
instance.setBackgroundTasksEnabled(enabled)
}

public static var loggingEnabled: Bool {
set {
Logger.loggingEnabled = newValue
Expand Down

0 comments on commit 460c357

Please sign in to comment.