Skip to content

Commit

Permalink
Merge pull request #256 from DP-3T/feature/deactivate-bg-task
Browse files Browse the repository at this point in the history
Disable/Enable scheduling of background tasks
  • Loading branch information
dennisjueni authored Mar 11, 2022
2 parents 998034c + 97997e5 commit 69d3e78
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Switch to Xcode 12.3
run: sudo xcode-select --switch /Applications/Xcode_12.3.app
- name: Switch to Xcode 13.2.1
run: sudo xcode-select --switch /Applications/Xcode_13.2.1.app

- name: Fastlane test
run: fastlane test
Expand All @@ -34,8 +34,8 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Switch to Xcode 12.3
run: sudo xcode-select --switch /Applications/Xcode_12.3.app
- name: Switch to Xcode 13.2.1
run: sudo xcode-select --switch /Applications/Xcode_13.2.1.app

# Compile sample app for iOS Simulator (no signing)
- name: Compile and run tests
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy_to_cocoapods.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
steps:
- uses: actions/checkout@v1

- name: Switch to Xcode 12.3
run: sudo xcode-select --switch /Applications/Xcode_12.3.app
- name: Switch to Xcode 13.2.1
run: sudo xcode-select --switch /Applications/Xcode_13.2.1.app

- name: Install Cocoapods
run: gem install cocoapods
Expand All @@ -26,4 +26,4 @@ jobs:
pod lib lint --allow-warnings
pod trunk push DP3TSDK.podspec --allow-warnings
env:
COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }}
COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/distribute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Switch to Xcode 12.3
run: sudo xcode-select --switch /Applications/Xcode_12.3.app
- name: Switch to Xcode 13.2.1
run: sudo xcode-select --switch /Applications/Xcode_13.2.1.app

- name: Run fastlane build
env:
Expand Down
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 69d3e78

Please sign in to comment.