Skip to content

Commit

Permalink
T18656231: Crash when receiving call while app killed
Browse files Browse the repository at this point in the history
cherry picked MEET-4253: CallKit crashes with Do not disturb
commit 6e891fd
# Conflicts:
#	iMEGA/CallsManagement/CallsCoordinator.swift
  • Loading branch information
tomekkuzma-mega committed Oct 15, 2024
1 parent bb52129 commit 674ad73
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
3 changes: 2 additions & 1 deletion iMEGA/AppDelegate/AppDelegate+Additions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,8 @@ extension AppDelegate {
voIpTokenUseCase: VoIPTokenUseCase(repo: VoIPTokenRepository.newRepo),
megaHandleUseCase: MEGAHandleUseCase(repo: MEGAHandleRepository.newRepo),
logger: {
CrashlyticsLogger.log(category: .calls, $0)
CrashlyticsLogger.log($0)
MEGALogDebug($0)
}
)
}
Expand Down
26 changes: 15 additions & 11 deletions iMEGA/CallsManagement/CallsCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import MEGADomain
import MEGAL10n
import MEGAPresentation

@MainActor
protocol CallsCoordinatorFactoryProtocol {
func makeCallsCoordinator(
scheduler: AnySchedulerOf<DispatchQueue>,
Expand Down Expand Up @@ -76,7 +75,6 @@ struct CallKitProviderDelegateProvider: CallKitProviderDelegateProviding {
}
}

@MainActor
@objc final class CallsCoordinator: NSObject {
private let callUseCase: any CallUseCaseProtocol
private let callUpdateUseCase: any CallUpdateUseCaseProtocol
Expand All @@ -100,7 +98,7 @@ struct CallKitProviderDelegateProvider: CallKitProviderDelegateProviding {
var incomingCallForUnknownChat: IncomingCallForUnknownChat?

let scheduler: AnySchedulerOf<DispatchQueue>

@PreferenceWrapper(key: .presentPasscodeLater, defaultValue: false, useCase: PreferenceUseCase.default)
var presentPasscodeLater: Bool

Expand Down Expand Up @@ -138,7 +136,7 @@ struct CallKitProviderDelegateProvider: CallKitProviderDelegateProviding {
callCoordinator: self,
callManager: callManager
)

onCallUpdateListener()
monitorOnChatConnectionStateUpdate()
}
Expand Down Expand Up @@ -322,10 +320,12 @@ struct CallKitProviderDelegateProvider: CallKitProviderDelegateProviding {
}

private func startCallUI(chatRoom: ChatRoomEntity, call: CallEntity, isSpeakerEnabled: Bool) {
MeetingContainerRouter(presenter: UIApplication.mnz_presentingViewController(),
chatRoom: chatRoom,
call: call,
isSpeakerEnabled: isSpeakerEnabled).start()
Task {
await MeetingContainerRouter(presenter: UIApplication.mnz_presentingViewController(),
chatRoom: chatRoom,
call: call,
isSpeakerEnabled: isSpeakerEnabled).start()
}
}

private func isWaitingRoomOpened(inChatRoom chatRoom: ChatRoomEntity) -> Bool {
Expand Down Expand Up @@ -463,11 +463,15 @@ extension CallsCoordinator: CallsCoordinatorProtocol {
}

providerDelegate?.provider.reportNewIncomingCall(with: incomingCallUUID, update: update) { [weak self] error in
guard error == nil else {
if let error {
CrashlyticsLogger.log("[CallKit] Provider Error reporting incoming call: \(String(describing: error))")
MEGALogError("[CallKit] Provider Error reporting incoming call: \(String(describing: error))")
return
if (error as NSError?)?.code == CXErrorCodeIncomingCallError.Code.filteredByDoNotDisturb.rawValue {
MEGALogDebug("[CallKit] Do not disturb enabled")
}
} else {
self?.checkIfIncomingCallHasBeenAlreadyAnsweredElsewhere(for: chatId)
}
self?.checkIfIncomingCallHasBeenAlreadyAnsweredElsewhere(for: chatId)
completion()
}
}
Expand Down
3 changes: 1 addition & 2 deletions iMEGA/CallsManagement/CallsCoordinatorProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import MEGADomain

/// Define methods to coordinate call actions from CallManagerProtocol
/// When manager triggers an action and it is performed by a provider (CallKit basically, but simulator should manage it in different way),
/// the coordinator implementation will execute the corresponding event in the ChatSDK (start, mute, end call...)
@MainActor
/// the coordinator implementation will execute the corresponding event in the ChatSDK (start, mute, end call....)
protocol CallsCoordinatorProtocol: AnyObject {
func startCall(_ callActionSync: CallActionSync) async -> Bool
func answerCall(_ callActionSync: CallActionSync) async -> Bool
Expand Down
4 changes: 1 addition & 3 deletions iMEGA/CallsManagement/VoIP/VoIPPushDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ import PushKit

if isVoIPPush(for: payload) {
logger("[VoIPPushDelegate] correct type of payload")
Task { @MainActor in
callsCoordinator.reportIncomingCall(in: chatId, completion: completion)
}
callsCoordinator.reportIncomingCall(in: chatId, completion: completion)
} else {
logger("[VoIPPushDelegate] wrong type of payload")
}
Expand Down

0 comments on commit 674ad73

Please sign in to comment.