Fix debug call log submissions when voluntarily ending calls [skip ci]

This commit is contained in:
Ali
2019-12-05 20:39:06 +04:00
parent 6b75d42cd3
commit 14b59eba63
5 changed files with 43 additions and 27 deletions

View File

@@ -419,14 +419,14 @@ public final class PresentationCallImpl: PresentationCall {
Logger.shared.log("PresentationCall", "reportIncomingCall device in DND mode") Logger.shared.log("PresentationCall", "reportIncomingCall device in DND mode")
Queue.mainQueue().async { Queue.mainQueue().async {
if let strongSelf = self { if let strongSelf = self {
strongSelf.callSessionManager.drop(internalId: strongSelf.internalId, reason: .busy) strongSelf.callSessionManager.drop(internalId: strongSelf.internalId, reason: .busy, debugLog: .single(nil))
} }
} }
} else { } else {
Logger.shared.log("PresentationCall", "reportIncomingCall error \(error)") Logger.shared.log("PresentationCall", "reportIncomingCall error \(error)")
Queue.mainQueue().async { Queue.mainQueue().async {
if let strongSelf = self { if let strongSelf = self {
strongSelf.callSessionManager.drop(internalId: strongSelf.internalId, reason: .hangUp) strongSelf.callSessionManager.drop(internalId: strongSelf.internalId, reason: .hangUp, debugLog: .single(nil))
} }
} }
} }
@@ -451,7 +451,7 @@ public final class PresentationCallImpl: PresentationCall {
presentationState = .connecting(keyVisualHash) presentationState = .connecting(keyVisualHash)
case .failed: case .failed:
presentationState = nil presentationState = nil
self.callSessionManager.drop(internalId: self.internalId, reason: .disconnect) self.callSessionManager.drop(internalId: self.internalId, reason: .disconnect, debugLog: .single(nil))
case .connected: case .connected:
let timestamp: Double let timestamp: Double
if let activeTimestamp = self.activeTimestamp { if let activeTimestamp = self.activeTimestamp {
@@ -484,12 +484,14 @@ public final class PresentationCallImpl: PresentationCall {
case let .terminated(id, _, options): case let .terminated(id, _, options):
self.audioSessionShouldBeActive.set(true) self.audioSessionShouldBeActive.set(true)
if wasActive { if wasActive {
self.ongoingContext.stop(callId: id, sendDebugLogs: options.contains(.sendDebugLogs)) let debugLogValue = Promise<String?>()
self.ongoingContext.stop(callId: id, sendDebugLogs: options.contains(.sendDebugLogs), debugLogValue: debugLogValue)
} }
default: default:
self.audioSessionShouldBeActive.set(false) self.audioSessionShouldBeActive.set(false)
if wasActive { if wasActive {
self.ongoingContext.stop() let debugLogValue = Promise<String?>()
self.ongoingContext.stop(debugLogValue: debugLogValue)
} }
} }
if case .terminated = sessionState.state, !wasTerminated { if case .terminated = sessionState.state, !wasTerminated {
@@ -602,15 +604,17 @@ public final class PresentationCallImpl: PresentationCall {
} }
public func hangUp() -> Signal<Bool, NoError> { public func hangUp() -> Signal<Bool, NoError> {
self.callSessionManager.drop(internalId: self.internalId, reason: .hangUp) let debugLogValue = Promise<String?>()
self.ongoingContext.stop() self.callSessionManager.drop(internalId: self.internalId, reason: .hangUp, debugLog: debugLogValue.get())
self.ongoingContext.stop(debugLogValue: debugLogValue)
return self.hungUpPromise.get() return self.hungUpPromise.get()
} }
public func rejectBusy() { public func rejectBusy() {
self.callSessionManager.drop(internalId: self.internalId, reason: .busy) self.callSessionManager.drop(internalId: self.internalId, reason: .busy, debugLog: .single(nil))
self.ongoingContext.stop() let debugLog = Promise<String?>()
self.ongoingContext.stop(debugLogValue: debugLog)
} }
public func toggleIsMuted() { public func toggleIsMuted() {

View File

@@ -309,7 +309,7 @@ public final class PresentationCallManagerImpl: PresentationCallManager {
} else { } else {
for (account, _, state, _, _) in ringingStates { for (account, _, state, _, _) in ringingStates {
if state.id != self.currentCall?.internalId { if state.id != self.currentCall?.internalId {
account.callSessionManager.drop(internalId: state.id, reason: .missed) account.callSessionManager.drop(internalId: state.id, reason: .missed, debugLog: .single(nil))
} }
} }
} }

View File

@@ -360,7 +360,7 @@ private final class CallSessionManagerContext {
} }
} }
func drop(internalId: CallSessionInternalId, reason: DropCallReason) { func drop(internalId: CallSessionInternalId, reason: DropCallReason, debugLog: Signal<String?, NoError>) {
if let context = self.contexts[internalId] { if let context = self.contexts[internalId] {
var dropData: (CallSessionStableId, Int64, DropCallSessionReason)? var dropData: (CallSessionStableId, Int64, DropCallSessionReason)?
var wasRinging = false var wasRinging = false
@@ -421,10 +421,21 @@ private final class CallSessionManagerContext {
if let (id, accessHash, reason) = dropData { if let (id, accessHash, reason) = dropData {
self.contextIdByStableId.removeValue(forKey: id) self.contextIdByStableId.removeValue(forKey: id)
context.state = .dropping((dropCallSession(network: self.network, addUpdates: self.addUpdates, stableId: id, accessHash: accessHash, reason: reason) |> deliverOn(self.queue)).start(next: { [weak self] reportRating, sendDebugLogs in context.state = .dropping((dropCallSession(network: self.network, addUpdates: self.addUpdates, stableId: id, accessHash: accessHash, reason: reason)
|> deliverOn(self.queue)).start(next: { [weak self] reportRating, sendDebugLogs in
if let strongSelf = self { if let strongSelf = self {
if let context = strongSelf.contexts[internalId] { if let context = strongSelf.contexts[internalId] {
context.state = .terminated(id: id, accessHash: accessHash, reason: .ended(.hungUp), reportRating: reportRating, sendDebugLogs: sendDebugLogs) context.state = .terminated(id: id, accessHash: accessHash, reason: .ended(.hungUp), reportRating: reportRating, sendDebugLogs: sendDebugLogs)
if sendDebugLogs {
let network = strongSelf.network
let _ = (debugLog
|> timeout(5.0, queue: strongSelf.queue, alternate: .single(nil))
|> deliverOnMainQueue).start(next: { debugLog in
if let debugLog = debugLog {
let _ = saveCallDebugLog(network: network, callId: CallId(id: id, accessHash: accessHash), log: debugLog).start()
}
})
}
strongSelf.contextUpdated(internalId: internalId) strongSelf.contextUpdated(internalId: internalId)
if context.isEmpty { if context.isEmpty {
strongSelf.contexts.removeValue(forKey: internalId) strongSelf.contexts.removeValue(forKey: internalId)
@@ -443,14 +454,14 @@ private final class CallSessionManagerContext {
func drop(stableId: CallSessionStableId, reason: DropCallReason) { func drop(stableId: CallSessionStableId, reason: DropCallReason) {
if let internalId = self.contextIdByStableId[stableId] { if let internalId = self.contextIdByStableId[stableId] {
self.contextIdByStableId.removeValue(forKey: stableId) self.contextIdByStableId.removeValue(forKey: stableId)
self.drop(internalId: internalId, reason: reason) self.drop(internalId: internalId, reason: reason, debugLog: .single(nil))
} }
} }
func dropAll() { func dropAll() {
let contexts = self.contexts let contexts = self.contexts
for (internalId, _) in contexts { for (internalId, _) in contexts {
self.drop(internalId: internalId, reason: .hangUp) self.drop(internalId: internalId, reason: .hangUp, debugLog: .single(nil))
} }
} }
@@ -463,7 +474,7 @@ private final class CallSessionManagerContext {
if case .accepting = context.state { if case .accepting = context.state {
switch result { switch result {
case .failed: case .failed:
strongSelf.drop(internalId: internalId, reason: .disconnect) strongSelf.drop(internalId: internalId, reason: .disconnect, debugLog: .single(nil))
case let .success(call): case let .success(call):
switch call { switch call {
case let .waiting(config): case let .waiting(config):
@@ -474,7 +485,7 @@ private final class CallSessionManagerContext {
context.state = .active(id: id, accessHash: accessHash, beginTimestamp: timestamp, key: key, keyId: keyId, keyVisualHash: keyVisualHash, connections: connections, maxLayer: maxLayer, allowsP2P: allowsP2P) context.state = .active(id: id, accessHash: accessHash, beginTimestamp: timestamp, key: key, keyId: keyId, keyVisualHash: keyVisualHash, connections: connections, maxLayer: maxLayer, allowsP2P: allowsP2P)
strongSelf.contextUpdated(internalId: internalId) strongSelf.contextUpdated(internalId: internalId)
} else { } else {
strongSelf.drop(internalId: internalId, reason: .disconnect) strongSelf.drop(internalId: internalId, reason: .disconnect, debugLog: .single(nil))
} }
} }
} }
@@ -502,7 +513,7 @@ private final class CallSessionManagerContext {
case let .requested(_, accessHash, a, gA, config, _): case let .requested(_, accessHash, a, gA, config, _):
let p = config.p.makeData() let p = config.p.makeData()
if !MTCheckIsSafeGAOrB(self.network.encryptionProvider, gA, p) { if !MTCheckIsSafeGAOrB(self.network.encryptionProvider, gA, p) {
self.drop(internalId: internalId, reason: .disconnect) self.drop(internalId: internalId, reason: .disconnect, debugLog: .single(nil))
} }
var key = MTExp(self.network.encryptionProvider, gB.makeData(), a, p)! var key = MTExp(self.network.encryptionProvider, gB.makeData(), a, p)!
@@ -528,13 +539,13 @@ private final class CallSessionManagerContext {
if let updatedCall = updatedCall { if let updatedCall = updatedCall {
strongSelf.updateSession(updatedCall, completion: { _ in }) strongSelf.updateSession(updatedCall, completion: { _ in })
} else { } else {
strongSelf.drop(internalId: internalId, reason: .disconnect) strongSelf.drop(internalId: internalId, reason: .disconnect, debugLog: .single(nil))
} }
} }
})) }))
self.contextUpdated(internalId: internalId) self.contextUpdated(internalId: internalId)
default: default:
self.drop(internalId: internalId, reason: .disconnect) self.drop(internalId: internalId, reason: .disconnect, debugLog: .single(nil))
} }
} else { } else {
assertionFailure() assertionFailure()
@@ -610,10 +621,10 @@ private final class CallSessionManagerContext {
self.contextUpdated(internalId: internalId) self.contextUpdated(internalId: internalId)
} }
} else { } else {
self.drop(internalId: internalId, reason: .disconnect) self.drop(internalId: internalId, reason: .disconnect, debugLog: .single(nil))
} }
} else { } else {
self.drop(internalId: internalId, reason: .disconnect) self.drop(internalId: internalId, reason: .disconnect, debugLog: .single(nil))
} }
case let .confirming(id, accessHash, key, keyId, keyVisualHash, _): case let .confirming(id, accessHash, key, keyId, keyVisualHash, _):
switch callProtocol { switch callProtocol {
@@ -761,9 +772,9 @@ public final class CallSessionManager {
} }
} }
public func drop(internalId: CallSessionInternalId, reason: DropCallReason) { public func drop(internalId: CallSessionInternalId, reason: DropCallReason, debugLog: Signal<String?, NoError>) {
self.withContext { context in self.withContext { context in
context.drop(internalId: internalId, reason: reason) context.drop(internalId: internalId, reason: reason, debugLog: debugLog)
} }
} }

View File

@@ -14,8 +14,8 @@ public func rateCall(account: Account, callId: CallId, starsCount: Int32, commen
|> map { _ in } |> map { _ in }
} }
public func saveCallDebugLog(account: Account, callId: CallId, log: String) -> Signal<Void, NoError> { public func saveCallDebugLog(network: Network, callId: CallId, log: String) -> Signal<Void, NoError> {
return account.network.request(Api.functions.phone.saveCallDebug(peer: Api.InputPhoneCall.inputPhoneCall(id: callId.id, accessHash: callId.accessHash), debug: .dataJSON(data: log))) return network.request(Api.functions.phone.saveCallDebug(peer: Api.InputPhoneCall.inputPhoneCall(id: callId.id, accessHash: callId.accessHash), debug: .dataJSON(data: log)))
|> retryRequest |> retryRequest
|> map { _ in } |> map { _ in }
} }

View File

@@ -241,9 +241,10 @@ public final class OngoingCallContext {
})) }))
} }
public func stop(callId: CallId? = nil, sendDebugLogs: Bool = false) { public func stop(callId: CallId? = nil, sendDebugLogs: Bool = false, debugLogValue: Promise<String?>) {
self.withContext { context in self.withContext { context in
context.stop { debugLog, bytesSentWifi, bytesReceivedWifi, bytesSentMobile, bytesReceivedMobile in context.stop { debugLog, bytesSentWifi, bytesReceivedWifi, bytesSentMobile, bytesReceivedMobile in
debugLogValue.set(.single(debugLog))
let delta = NetworkUsageStatsConnectionsEntry( let delta = NetworkUsageStatsConnectionsEntry(
cellular: NetworkUsageStatsDirectionsEntry( cellular: NetworkUsageStatsDirectionsEntry(
incoming: bytesReceivedMobile, incoming: bytesReceivedMobile,
@@ -254,7 +255,7 @@ public final class OngoingCallContext {
updateAccountNetworkUsageStats(account: self.account, category: .call, delta: delta) updateAccountNetworkUsageStats(account: self.account, category: .call, delta: delta)
if let callId = callId, let debugLog = debugLog, sendDebugLogs { if let callId = callId, let debugLog = debugLog, sendDebugLogs {
let _ = saveCallDebugLog(account: self.account, callId: callId, log: debugLog).start() let _ = saveCallDebugLog(network: self.account.network, callId: callId, log: debugLog).start()
} }
} }
let derivedState = context.getDerivedState() let derivedState = context.getDerivedState()