Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable/Enable scheduling of background tasks #256

Merged
merged 2 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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