From fc0ef0b8abd8011b5b5e7c07384402f00301515a Mon Sep 17 00:00:00 2001 From: Stefan Mitterrutzner Date: Tue, 11 May 2021 16:11:28 +0200 Subject: [PATCH 1/6] set correct PROVISIONING_PROFILE_SPECIFIER --- SampleApp/DP3TSampleApp.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SampleApp/DP3TSampleApp.xcodeproj/project.pbxproj b/SampleApp/DP3TSampleApp.xcodeproj/project.pbxproj index c46d8d25..20e81f97 100644 --- a/SampleApp/DP3TSampleApp.xcodeproj/project.pbxproj +++ b/SampleApp/DP3TSampleApp.xcodeproj/project.pbxproj @@ -321,7 +321,7 @@ OTHER_SWIFT_FLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = ch.admin.bag.dp3t.dev; PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = "dep-3t DEV Deveopment"; + PROVISIONING_PROFILE_SPECIFIER = "dep-3t DEV Development"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -402,7 +402,7 @@ OTHER_SWIFT_FLAGS = ""; PRODUCT_BUNDLE_IDENTIFIER = ch.admin.bag.dp3t.dev; PRODUCT_NAME = "$(TARGET_NAME)"; - PROVISIONING_PROFILE_SPECIFIER = "dep-3t DEV Deveopment"; + PROVISIONING_PROFILE_SPECIFIER = "dep-3t DEV Development"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = ""; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; From d32fd8614ab6c14a4afb5c2235b91002da485939 Mon Sep 17 00:00:00 2001 From: Stefan Mitterrutzner Date: Tue, 11 May 2021 16:12:44 +0200 Subject: [PATCH 2/6] resolves two retain cycles this also resolves a issue where wrong infectionStatus was provided to the app after resetting the SDK --- Sources/DP3TSDK/Background/DP3TBackgroundTaskManager.swift | 2 +- Sources/DP3TSDK/Tracing/ExposureNotificationTracer.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/DP3TSDK/Background/DP3TBackgroundTaskManager.swift b/Sources/DP3TSDK/Background/DP3TBackgroundTaskManager.swift index f0dfc976..76d9d14b 100644 --- a/Sources/DP3TSDK/Background/DP3TBackgroundTaskManager.swift +++ b/Sources/DP3TSDK/Background/DP3TBackgroundTaskManager.swift @@ -30,7 +30,7 @@ class DP3TBackgroundTaskManager { private let serviceClient: ExposeeServiceClientProtocol - private let tracer: Tracer + private weak var tracer: Tracer! init(handler: DP3TBackgroundHandler?, keyProvider: DiagnosisKeysProvider, diff --git a/Sources/DP3TSDK/Tracing/ExposureNotificationTracer.swift b/Sources/DP3TSDK/Tracing/ExposureNotificationTracer.swift index 9a594dc4..61f6c3c5 100644 --- a/Sources/DP3TSDK/Tracing/ExposureNotificationTracer.swift +++ b/Sources/DP3TSDK/Tracing/ExposureNotificationTracer.swift @@ -19,7 +19,7 @@ class ExposureNotificationTracer: Tracer { private var stateObservation: NSKeyValueObservation? private var enabledObservation: NSKeyValueObservation? - var delegate: TracerDelegate? + weak var delegate: TracerDelegate? private let queue = DispatchQueue(label: "org.dpppt.tracer") From 4bc5d967583603e2589851b451a90397ad611d41 Mon Sep 17 00:00:00 2001 From: Stefan Mitterrutzner Date: Tue, 11 May 2021 16:13:13 +0200 Subject: [PATCH 3/6] adds a unit test --- Tests/DP3TSDKTests/DP3TSDKTests.swift | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Tests/DP3TSDKTests/DP3TSDKTests.swift b/Tests/DP3TSDKTests/DP3TSDKTests.swift index b91292b0..7cb070d0 100644 --- a/Tests/DP3TSDKTests/DP3TSDKTests.swift +++ b/Tests/DP3TSDKTests/DP3TSDKTests.swift @@ -292,4 +292,35 @@ class DP3TSDKTests: XCTestCase { XCTAssertEqual(tracer.state, TrackingState.active) } + + func testInfectedAfterReset() { + + XCTAssertEqual(sdk.status.infectionStatus, .healthy) + + let firstInfected = expectation(description: "firstInfected") + sdk.iWasExposed(onset: .init(), authentication: .none) { _ in + firstInfected.fulfill() + } + wait(for: [firstInfected], timeout: 1.0) + + XCTAssertEqual(sdk.status.infectionStatus, .infected) + + sdk.reset() + sdk = nil + //re-init SDK + setUp() + + XCTAssertEqual(sdk.status.infectionStatus, .healthy) + + let secondInfected = expectation(description: "secondInfected") + sdk.iWasExposed(onset: .init(), authentication: .none) { _ in + secondInfected.fulfill() + } + wait(for: [secondInfected], timeout: 1.0) + + XCTAssertEqual(sdk.status.infectionStatus, .infected) + + + + } } From 1da5d1a48558f491c1e23370f85dbe4d7c83ce08 Mon Sep 17 00:00:00 2001 From: Stefan Mitterrutzner Date: Tue, 11 May 2021 16:13:26 +0200 Subject: [PATCH 4/6] removes Xcode warnings --- Sources/DP3TSDK/Cryptography/DiagnosisKeysProvider.swift | 2 +- Sources/DP3TSDK/LoggingDelegate.swift | 2 +- Sources/DP3TSDK/Matching/MatchingProtocols.swift | 2 +- Sources/DP3TSDK/Networking/ExposeeServiceClient.swift | 2 +- Sources/DP3TSDK/Networking/KnownCasesSynchronizer.swift | 2 +- Sources/DP3TSDK/Tracing/TracerProtocols.swift | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/DP3TSDK/Cryptography/DiagnosisKeysProvider.swift b/Sources/DP3TSDK/Cryptography/DiagnosisKeysProvider.swift index c95c1d27..0662eb30 100644 --- a/Sources/DP3TSDK/Cryptography/DiagnosisKeysProvider.swift +++ b/Sources/DP3TSDK/Cryptography/DiagnosisKeysProvider.swift @@ -11,7 +11,7 @@ import ExposureNotification import Foundation -protocol DiagnosisKeysProvider: class { +protocol DiagnosisKeysProvider: AnyObject { func getFakeDiagnosisKeys(completionHandler: @escaping (Result<[CodableDiagnosisKey], DP3TTracingError>) -> Void) func getFakeKeys(count: Int, startingFrom: Date) -> [CodableDiagnosisKey] diff --git a/Sources/DP3TSDK/LoggingDelegate.swift b/Sources/DP3TSDK/LoggingDelegate.swift index 87998c86..4871b8f6 100644 --- a/Sources/DP3TSDK/LoggingDelegate.swift +++ b/Sources/DP3TSDK/LoggingDelegate.swift @@ -12,7 +12,7 @@ import Foundation import os.log /// A logging delegate -public protocol LoggingDelegate: class { +public protocol LoggingDelegate: AnyObject { /// Log a string /// - Parameter LogType: the type of log /// - Parameter string: The string to log diff --git a/Sources/DP3TSDK/Matching/MatchingProtocols.swift b/Sources/DP3TSDK/Matching/MatchingProtocols.swift index c46ac093..1b2a5fab 100644 --- a/Sources/DP3TSDK/Matching/MatchingProtocols.swift +++ b/Sources/DP3TSDK/Matching/MatchingProtocols.swift @@ -11,7 +11,7 @@ import Foundation -protocol Matcher: class { +protocol Matcher: AnyObject { var timingManager: ExposureDetectionTimingManager? { get set } /// returns true if we found a match diff --git a/Sources/DP3TSDK/Networking/ExposeeServiceClient.swift b/Sources/DP3TSDK/Networking/ExposeeServiceClient.swift index 79a67519..67673dd3 100644 --- a/Sources/DP3TSDK/Networking/ExposeeServiceClient.swift +++ b/Sources/DP3TSDK/Networking/ExposeeServiceClient.swift @@ -17,7 +17,7 @@ struct ExposeeSuccess { let keyBundleTag: String? } -protocol ExposeeServiceClientProtocol: class { +protocol ExposeeServiceClientProtocol: AnyObject { typealias ExposeeResult = Result typealias ExposeeCompletion = Result diff --git a/Sources/DP3TSDK/Networking/KnownCasesSynchronizer.swift b/Sources/DP3TSDK/Networking/KnownCasesSynchronizer.swift index cff459e6..f1c6a6a2 100644 --- a/Sources/DP3TSDK/Networking/KnownCasesSynchronizer.swift +++ b/Sources/DP3TSDK/Networking/KnownCasesSynchronizer.swift @@ -12,7 +12,7 @@ import Foundation import UIKit.UIApplication /// A delegate used to respond on DP3T events -protocol KnownCasesSynchronizerDelegate: class { +protocol KnownCasesSynchronizerDelegate: AnyObject { /// We found a match func didFindMatch() } diff --git a/Sources/DP3TSDK/Tracing/TracerProtocols.swift b/Sources/DP3TSDK/Tracing/TracerProtocols.swift index 7bbad27e..48fd30e5 100644 --- a/Sources/DP3TSDK/Tracing/TracerProtocols.swift +++ b/Sources/DP3TSDK/Tracing/TracerProtocols.swift @@ -16,7 +16,7 @@ protocol TracerDelegate: AnyObject { public typealias TracingEnableResult = Result -protocol Tracer { +protocol Tracer: AnyObject { var delegate: TracerDelegate? { get set } var state: TrackingState { get } From 4bf4c19db0c46e7cb00bb0881b5104b2ac398b60 Mon Sep 17 00:00:00 2001 From: Stefan Mitterrutzner Date: Wed, 12 May 2021 16:46:06 +0200 Subject: [PATCH 5/6] Revert "removes Xcode warnings" This reverts commit 1da5d1a48558f491c1e23370f85dbe4d7c83ce08. --- Sources/DP3TSDK/Cryptography/DiagnosisKeysProvider.swift | 2 +- Sources/DP3TSDK/LoggingDelegate.swift | 2 +- Sources/DP3TSDK/Matching/MatchingProtocols.swift | 2 +- Sources/DP3TSDK/Networking/ExposeeServiceClient.swift | 2 +- Sources/DP3TSDK/Networking/KnownCasesSynchronizer.swift | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/DP3TSDK/Cryptography/DiagnosisKeysProvider.swift b/Sources/DP3TSDK/Cryptography/DiagnosisKeysProvider.swift index 0662eb30..c95c1d27 100644 --- a/Sources/DP3TSDK/Cryptography/DiagnosisKeysProvider.swift +++ b/Sources/DP3TSDK/Cryptography/DiagnosisKeysProvider.swift @@ -11,7 +11,7 @@ import ExposureNotification import Foundation -protocol DiagnosisKeysProvider: AnyObject { +protocol DiagnosisKeysProvider: class { func getFakeDiagnosisKeys(completionHandler: @escaping (Result<[CodableDiagnosisKey], DP3TTracingError>) -> Void) func getFakeKeys(count: Int, startingFrom: Date) -> [CodableDiagnosisKey] diff --git a/Sources/DP3TSDK/LoggingDelegate.swift b/Sources/DP3TSDK/LoggingDelegate.swift index 4871b8f6..87998c86 100644 --- a/Sources/DP3TSDK/LoggingDelegate.swift +++ b/Sources/DP3TSDK/LoggingDelegate.swift @@ -12,7 +12,7 @@ import Foundation import os.log /// A logging delegate -public protocol LoggingDelegate: AnyObject { +public protocol LoggingDelegate: class { /// Log a string /// - Parameter LogType: the type of log /// - Parameter string: The string to log diff --git a/Sources/DP3TSDK/Matching/MatchingProtocols.swift b/Sources/DP3TSDK/Matching/MatchingProtocols.swift index 1b2a5fab..c46ac093 100644 --- a/Sources/DP3TSDK/Matching/MatchingProtocols.swift +++ b/Sources/DP3TSDK/Matching/MatchingProtocols.swift @@ -11,7 +11,7 @@ import Foundation -protocol Matcher: AnyObject { +protocol Matcher: class { var timingManager: ExposureDetectionTimingManager? { get set } /// returns true if we found a match diff --git a/Sources/DP3TSDK/Networking/ExposeeServiceClient.swift b/Sources/DP3TSDK/Networking/ExposeeServiceClient.swift index 67673dd3..79a67519 100644 --- a/Sources/DP3TSDK/Networking/ExposeeServiceClient.swift +++ b/Sources/DP3TSDK/Networking/ExposeeServiceClient.swift @@ -17,7 +17,7 @@ struct ExposeeSuccess { let keyBundleTag: String? } -protocol ExposeeServiceClientProtocol: AnyObject { +protocol ExposeeServiceClientProtocol: class { typealias ExposeeResult = Result typealias ExposeeCompletion = Result diff --git a/Sources/DP3TSDK/Networking/KnownCasesSynchronizer.swift b/Sources/DP3TSDK/Networking/KnownCasesSynchronizer.swift index f1c6a6a2..cff459e6 100644 --- a/Sources/DP3TSDK/Networking/KnownCasesSynchronizer.swift +++ b/Sources/DP3TSDK/Networking/KnownCasesSynchronizer.swift @@ -12,7 +12,7 @@ import Foundation import UIKit.UIApplication /// A delegate used to respond on DP3T events -protocol KnownCasesSynchronizerDelegate: AnyObject { +protocol KnownCasesSynchronizerDelegate: class { /// We found a match func didFindMatch() } From 7efb508ad1ad6ec24bd784232912fa8fd1dddda6 Mon Sep 17 00:00:00 2001 From: Stefan Mitterrutzner Date: Wed, 12 May 2021 16:50:14 +0200 Subject: [PATCH 6/6] adds a unit test for deallocation --- Tests/DP3TSDKTests/DP3TSDKTests.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Tests/DP3TSDKTests/DP3TSDKTests.swift b/Tests/DP3TSDKTests/DP3TSDKTests.swift index 7cb070d0..6aad76f4 100644 --- a/Tests/DP3TSDKTests/DP3TSDKTests.swift +++ b/Tests/DP3TSDKTests/DP3TSDKTests.swift @@ -319,8 +319,19 @@ class DP3TSDKTests: XCTestCase { wait(for: [secondInfected], timeout: 1.0) XCTAssertEqual(sdk.status.infectionStatus, .infected) + } + func testCorrectDeallocation() { + weak var weakRef = sdk + sdk.reset() + sdk = nil + let expt = expectation(description: "deallocated") + DispatchQueue.main.async { + XCTAssertNil(weakRef) + expt.fulfill() + } + wait(for: [expt], timeout: 1.0) } }