Skip to content

Commit

Permalink
Merge pull request #515 from SwissCovid/bugfix/use-cached-config-for-…
Browse files Browse the repository at this point in the history
…deaktivation-screen
  • Loading branch information
stmitt authored Mar 18, 2022
2 parents c3b433c + a205134 commit 57ea274
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 37 deletions.
6 changes: 3 additions & 3 deletions DP3TApp/Logic/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

window?.makeKeyAndVisible()

let deactivated = UserStorage.shared.appDeactivated

guard !deactivated else { return }
guard !(ConfigManager.currentConfig?.deactivate ?? false) else { return }

if UserStorage.shared.appClipCheckinUrl() != nil {
let checkinOnboardingVC = NSCheckinOnboardingViewController()
Expand Down Expand Up @@ -167,6 +165,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
_ = jumpToMessageIfRequired(onlyFirst: false)
}

ConfigManager.presentDeactivationIfNeeded(config: ConfigManager.currentConfig, window: window)

startForceUpdateCheck()

FakePublishManager.shared.runTask()
Expand Down
8 changes: 4 additions & 4 deletions DP3TApp/Logic/Config/ConfigLoadOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ class ConfigLoadOperation: Operation {
appDelegate.window?.rootViewController? = vc
}

TracingManager.shared.setBackgroundRefreshEnabled(false)

if TracingManager.shared.isActivated {
TracingManager.shared.endTracing()
UserStorage.shared.tracingWasActivatedBeforeDeaktivation = true
}

TracingManager.shared.setBackgroundRefreshEnabled(false)
UBPushManager.shared.setActive(false)
CheckInManager.shared.cleanUpOldData(maxDaysToKeep: 0)

if !UserStorage.shared.appDeactivated {
UserStorage.shared.appDeactivated = true
}
UserStorage.shared.appDeactivated = true

} else {
self.cancel()
Expand Down
53 changes: 30 additions & 23 deletions DP3TApp/Logic/Config/ConfigManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,8 @@ class ConfigManager: NSObject {
loadConfig(backgroundTask: false) { config in
// self must be strong
if let config = config {
self.presentDeactivationIfNeeded(config: config, window: window)
Self.presentDeactivationIfNeeded(config: config, window: window)
self.presentAlertIfNeeded(config: config, window: window)
} else {
//still show deactivationScreen if no internet
self.presentDeactivationIfNeeded(config: ConfigManager.currentConfig)
}
}
}
Expand Down Expand Up @@ -219,45 +216,55 @@ class ConfigManager: NSObject {
}
}

public func presentDeactivationIfNeeded(config: ConfigResponseBody?, window: UIWindow? = nil) {
public static func presentDeactivationIfNeeded(config: ConfigResponseBody?, window: UIWindow? = nil) {
guard let config = config else { return }

if config.deactivate {
if (window?.rootViewController as? UINavigationController)?.visibleViewController is NSDeactivatedInfoViewController {
// The NSDeactivatedInfoViewController is already visible
return
}

let vc = NSNavigationController(rootViewController: NSDeactivatedInfoViewController())

if let window = window {
if (window.rootViewController as? NSNavigationController)?.visibleViewController as? NSDeactivatedInfoViewController == nil {
window.rootViewController = vc
}
} else {
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }
if (appDelegate.window?.rootViewController as? NSNavigationController)?.visibleViewController as? NSDeactivatedInfoViewController == nil {
appDelegate.window?.rootViewController? = vc
}
window.rootViewController = vc
}

TracingManager.shared.setBackgroundRefreshEnabled(false)

if TracingManager.shared.isActivated {
UserStorage.shared.tracingWasActivatedBeforeDeaktivation = true
TracingManager.shared.endTracing()
}

TracingManager.shared.setBackgroundRefreshEnabled(false)
UBPushManager.shared.setActive(false)
CheckInManager.shared.cleanUpOldData(maxDaysToKeep: 0)
if !UserStorage.shared.appDeactivated {
UserStorage.shared.appDeactivated = true
}

UserStorage.shared.appDeactivated = true

} else if !config.deactivate, UserStorage.shared.appDeactivated {
if TracingManager.shared.isAuthorized {
if TracingManager.shared.isAuthorized, UserStorage.shared.tracingWasActivatedBeforeDeaktivation {
TracingManager.shared.startTracing()
}

TracingManager.shared.setBackgroundRefreshEnabled(true)
UserStorage.shared.appDeactivated = false

if !UserStorage.shared.hasCompletedOnboarding {
let onboardingViewController = NSOnboardingViewController()
onboardingViewController.modalPresentationStyle = .fullScreen
window?.rootViewController?.present(onboardingViewController, animated: false)
if TracingManager.shared.isSupported {
window?.rootViewController = (UIApplication.shared.delegate as? AppDelegate)?.navigationController

if !UserStorage.shared.hasCompletedOnboarding {
let onboardingViewController = NSOnboardingViewController()
onboardingViewController.modalPresentationStyle = .fullScreen
window?.rootViewController?.present(onboardingViewController, animated: false)
}

} else {
window?.rootViewController = NSUnsupportedOSViewController()
}

UserStorage.shared.appDeactivated = false
UserStorage.shared.tracingWasActivatedBeforeDeaktivation = true
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions DP3TApp/Logic/Networking/Base/URLSession+pinning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,14 @@ class CertificateEvaluator: NSObject, URLSessionDelegate {
"www.pt-a.bfs.admin.ch",
"www.pt-t.bfs.admin.ch",
"www.pt.bfs.admin.ch"]

if let QuovadisRootCA = bundle.getCertificate(with: "QuoVadis-Root-CA-2-G3", fileExtension: "cer") {
for host in hosts {
let evaluator = UBPinnedCertificatesTrustEvaluator(certificates: [QuovadisRootCA],
acceptSelfSignedCertificates: true,
performDefaultValidation: false,
validateHost: true)
acceptSelfSignedCertificates: true,
performDefaultValidation: false,
validateHost: true)
evaluators[host] = evaluator

}
} else {
assertionFailure("Could not load certificate for pinned host")
Expand Down
2 changes: 1 addition & 1 deletion DP3TApp/Logic/Tracing/TracingManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ extension TracingManager: DP3TTracingDelegate {
isAuthorized = (state.trackingState != .inactive(error: .authorizationUnknown) &&
state.trackingState != .inactive(error: .permissionError))

let needsPush = !isAuthorized && CrowdNotifier.hasCheckins() && !UserStorage.shared.appDeactivated
let needsPush = !isAuthorized && CrowdNotifier.hasCheckins() && !(ConfigManager.currentConfig?.deactivate ?? false)
UBPushManager.shared.setActive(needsPush)

// update tracing error states if needed
Expand Down
3 changes: 3 additions & 0 deletions DP3TApp/Logic/User/UserStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class UserStorage {
@UBUserDefault(key: "appDeactivated", defaultValue: false)
var appDeactivated: Bool

@UBUserDefault(key: "tracingWasActivatedBeforeDeaktivation", defaultValue: false)
var tracingWasActivatedBeforeDeaktivation: Bool

// method to get AppClip url in Main App
public func appClipCheckinUrl() -> String? {
let bi = (Bundle.main.bundleIdentifier ?? "")
Expand Down
2 changes: 1 addition & 1 deletion DP3TApp/Screens/Deactivated/NSDeactivatedInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class NSDeactivatedInfoView: NSSimpleModuleBaseView {
}

private func moreInfoTouched() {
if let url = ConfigManager.currentConfig?.deactivationMessage?.value?.url {
if let url = ConfigManager.currentConfig?.deactivationMessage?.value?.url {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
print("URL is null")
Expand Down

0 comments on commit 57ea274

Please sign in to comment.