diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 15f456bab..74c2fb57b 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -7819,7 +7819,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 510; + CURRENT_PROJECT_VERSION = 511; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -7890,7 +7890,7 @@ CODE_SIGN_ENTITLEMENTS = Session/Meta/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 510; + CURRENT_PROJECT_VERSION = 511; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", diff --git a/Session/Calls/Call Management/SessionCall.swift b/Session/Calls/Call Management/SessionCall.swift index 036825a4d..0f398c66a 100644 --- a/Session/Calls/Call Management/SessionCall.swift +++ b/Session/Calls/Call Management/SessionCall.swift @@ -185,7 +185,7 @@ public final class SessionCall: CurrentCallProtocol, WebRTCSessionDelegate { // stringlint:ignore_contents func reportIncomingCallIfNeeded(completion: @escaping (Error?) -> Void) { guard case .answer = mode else { - SessionCallManager.reportFakeCall(info: "Call not in answer mode", using: dependencies) + Singleton.callManager.reportFakeCall(info: "Call not in answer mode") return } diff --git a/Session/Calls/Call Management/SessionCallManager.swift b/Session/Calls/Call Management/SessionCallManager.swift index 49a0a6fbf..d2496c138 100644 --- a/Session/Calls/Call Management/SessionCallManager.swift +++ b/Session/Calls/Call Management/SessionCallManager.swift @@ -9,16 +9,6 @@ import SessionMessagingKit import SignalUtilitiesKit import SessionUtilitiesKit -// MARK: - Cache - -public extension Cache { - static let callManager: CacheInfo.Config = CacheInfo.create( - createInstance: { SessionCallManager.Cache() }, - mutableInstance: { $0 }, - immutableInstance: { $0 } - ) -} - // MARK: - SessionCallManager public final class SessionCallManager: NSObject, CallManagerProtocol { @@ -47,9 +37,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { self.dependencies = dependencies if Preferences.isCallKitSupported { - self.provider = dependencies.caches.mutate(cache: .callManager) { - $0.getOrCreateProvider(useSystemCallLog: useSystemCallLog) - } + self.provider = Self.createProvider(useSystemCallLog: useSystemCallLog) self.callController = CXCallController() } else { @@ -63,20 +51,31 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { self.provider?.setDelegate(self, queue: nil) } + public static func createProvider(useSystemCallLog: Bool) -> CXProvider { + let iconMaskImage: UIImage = #imageLiteral(resourceName: "SessionGreen32") + let configuration = CXProviderConfiguration() + configuration.supportsVideo = true + configuration.maximumCallGroups = 1 + configuration.maximumCallsPerCallGroup = 1 + configuration.supportedHandleTypes = [.generic] + configuration.iconTemplateImageData = iconMaskImage.pngData() + configuration.includesCallsInRecents = useSystemCallLog + + let provider: CXProvider = CXProvider(configuration: configuration) + return provider + } + // MARK: - Report calls - public static func reportFakeCall(info: String, using dependencies: Dependencies) { + public func reportFakeCall(info: String) { let callId = UUID() - let provider: CXProvider = dependencies.caches.mutate(cache: .callManager) { - $0.getOrCreateProvider(useSystemCallLog: false) - } - provider.reportNewIncomingCall( + self.provider?.reportNewIncomingCall( with: callId, update: CXCallUpdate() ) { _ in SNLog("[Calls] Reported fake incoming call to CallKit due to: \(info)") } - provider.reportCall( + self.provider?.reportCall( with: callId, endedAt: nil, reason: .failed @@ -104,9 +103,6 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { } public func reportIncomingCall(_ call: CurrentCallProtocol, callerName: String, completion: @escaping (Error?) -> Void) { - let provider: CXProvider = dependencies.caches.mutate(cache: .callManager) { - $0.getOrCreateProvider(useSystemCallLog: false) - } // Construct a CXCallUpdate describing the incoming call, including the caller. let update = CXCallUpdate() update.localizedCallerName = callerName @@ -116,7 +112,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { disableUnsupportedFeatures(callUpdate: update) // Report the incoming call to the system - provider.reportNewIncomingCall(with: call.callId, update: update) { error in + self.provider?.reportNewIncomingCall(with: call.callId, update: update) { error in guard error == nil else { self.reportCurrentCallEnded(reason: .failed) completion(error) @@ -294,40 +290,3 @@ public final class SessionCallManager: NSObject, CallManagerProtocol { MiniCallView.current?.dismiss() } } - -// MARK: - SessionCallManager Cache - -public extension SessionCallManager { - class Cache: CallManagerCacheType { - public var provider: CXProvider? - - public func getOrCreateProvider(useSystemCallLog: Bool) -> CXProvider { - SNLog("[Calls] getOrCreateProvider") - if let provider: CXProvider = self.provider { - return provider - } - - let iconMaskImage: UIImage = #imageLiteral(resourceName: "SessionGreen32") - let configuration = CXProviderConfiguration() - configuration.supportsVideo = true - configuration.maximumCallGroups = 1 - configuration.maximumCallsPerCallGroup = 1 - configuration.supportedHandleTypes = [.generic] - configuration.iconTemplateImageData = iconMaskImage.pngData() - configuration.includesCallsInRecents = useSystemCallLog - - let provider: CXProvider = CXProvider(configuration: configuration) - self.provider = provider - return provider - } - } -} - -// MARK: - OGMCacheType - -/// This is a read-only version of the Cache designed to avoid unintentionally mutating the instance in a non-thread-safe way -public protocol CallManagerImmutableCacheType: ImmutableCacheType {} - -public protocol CallManagerCacheType: CallManagerImmutableCacheType, MutableCacheType { - func getOrCreateProvider(useSystemCallLog: Bool) -> CXProvider -} diff --git a/Session/Meta/AppDelegate.swift b/Session/Meta/AppDelegate.swift index 4cf9f05e1..1f728c06e 100644 --- a/Session/Meta/AppDelegate.swift +++ b/Session/Meta/AppDelegate.swift @@ -42,8 +42,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD verifyDBKeysAvailableBeforeBackgroundLaunch() _ = AppVersion.shared - /// Create a proper `SessionCallManager` for the main app (defaults to a no-op version) - Singleton.setCallManager(SessionCallManager(using: dependencies)) Singleton.setPushRegistrationManager(PushRegistrationManager(using: dependencies)) Singleton.pushRegistrationManager.createVoipRegistryIfNecessary() @@ -62,7 +60,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD Log.info("[AppDelegate] Setting up environment.") /// Create a proper `SessionCallManager` for the main app (defaults to a no-op version) -// Singleton.setCallManager(SessionCallManager(using: dependencies)) + Singleton.setCallManager(SessionCallManager(using: dependencies)) // Setup LibSession LibSession.addLogger() diff --git a/Session/Notifications/PushRegistrationManager.swift b/Session/Notifications/PushRegistrationManager.swift index fde9a15e0..800ca29ef 100644 --- a/Session/Notifications/PushRegistrationManager.swift +++ b/Session/Notifications/PushRegistrationManager.swift @@ -285,7 +285,7 @@ public class PushRegistrationManager: NSObject, PKPushRegistryDelegate, PushRegi let timestampMs: UInt64 = payload["timestamp"] as? UInt64, TimestampUtils.isWithinOneMinute(timestampMs: timestampMs) else { - SessionCallManager.reportFakeCall(info: "Missing payload data", using: dependencies) // stringlint:ignore + Singleton.callManager.reportFakeCall(info: "Missing payload data") // stringlint:ignore return } @@ -318,7 +318,7 @@ public class PushRegistrationManager: NSObject, PKPushRegistryDelegate, PushRegi } guard let call: SessionCall = maybeCall else { - SessionCallManager.reportFakeCall(info: "Could not retrieve call from database", using: dependencies) // stringlint:ignore + Singleton.callManager.reportFakeCall(info: "Could not retrieve call from database") // stringlint:ignore return } diff --git a/SessionMessagingKit/Calls/CallManagerProtocol.swift b/SessionMessagingKit/Calls/CallManagerProtocol.swift index b1b3587c5..6bc5d8759 100644 --- a/SessionMessagingKit/Calls/CallManagerProtocol.swift +++ b/SessionMessagingKit/Calls/CallManagerProtocol.swift @@ -22,6 +22,7 @@ public protocol CallManagerProtocol { var currentCall: CurrentCallProtocol? { get set } func setCurrentCall(_ call: CurrentCallProtocol?) + func reportFakeCall(info: String) func reportIncomingCall(_ call: CurrentCallProtocol, callerName: String, completion: @escaping (Error?) -> Void) func reportCurrentCallEnded(reason: CXCallEndedReason?) func suspendDatabaseIfCallEndedInBackground() diff --git a/SessionMessagingKit/Calls/NoopSessionCallManager.swift b/SessionMessagingKit/Calls/NoopSessionCallManager.swift index afa3e9280..5f70680b7 100644 --- a/SessionMessagingKit/Calls/NoopSessionCallManager.swift +++ b/SessionMessagingKit/Calls/NoopSessionCallManager.swift @@ -7,6 +7,7 @@ internal struct NoopSessionCallManager: CallManagerProtocol { var currentCall: CurrentCallProtocol? func setCurrentCall(_ call: CurrentCallProtocol?) {} + func reportFakeCall(info: String) {} func reportIncomingCall(_ call: CurrentCallProtocol, callerName: String, completion: @escaping (Error?) -> Void) {} func reportCurrentCallEnded(reason: CXCallEndedReason?) {} func suspendDatabaseIfCallEndedInBackground() {}