Code Cleanup

- make some logging clearer
- remove noisy unhelpful logging
- clearer method names

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 53d00e61cf
commit f681712ea0

@ -80,21 +80,20 @@ class AccountManager: NSObject {
func getTurnServerInfo() -> Promise<TurnServerInfo> { func getTurnServerInfo() -> Promise<TurnServerInfo> {
return Promise { fulfill, reject in return Promise { fulfill, reject in
self.networkManager.makeRequest(TurnServerInfoRequest(), self.networkManager.makeRequest(TurnServerInfoRequest(),
success: { (task: URLSessionDataTask, responseObject: Any?) in success: { (_: URLSessionDataTask, responseObject: Any?) in
guard responseObject != nil else { guard responseObject != nil else {
return reject(OWSErrorMakeUnableToProcessServerResponseError()) return reject(OWSErrorMakeUnableToProcessServerResponseError())
} }
if let responseDictionary = responseObject as? [String: AnyObject] { if let responseDictionary = responseObject as? [String: AnyObject] {
if let turnServerInfo = TurnServerInfo(attributes:responseDictionary) { if let turnServerInfo = TurnServerInfo(attributes:responseDictionary) {
Logger.debug("\(self.TAG) got valid turnserver info")
return fulfill(turnServerInfo) return fulfill(turnServerInfo)
} }
Logger.error("\(self.TAG) unexpected server response:\(responseDictionary)") Logger.error("\(self.TAG) unexpected server response:\(responseDictionary)")
} }
return reject(OWSErrorMakeUnableToProcessServerResponseError()) return reject(OWSErrorMakeUnableToProcessServerResponseError())
}, },
failure: { (task: URLSessionDataTask, error: Error) in failure: { (_: URLSessionDataTask, error: Error) in
return reject(error) return reject(error)
}) })
} }

@ -87,8 +87,6 @@ class ProfileFetcherJob: NSObject {
} }
private func processResponse(signalServiceProfile: SignalServiceProfile) { private func processResponse(signalServiceProfile: SignalServiceProfile) {
Logger.debug("\(TAG) in \(#function) for \(signalServiceProfile)")
verifyIdentityUpToDateAsync(recipientId: signalServiceProfile.recipientId, latestIdentityKey: signalServiceProfile.identityKey) verifyIdentityUpToDateAsync(recipientId: signalServiceProfile.recipientId, latestIdentityKey: signalServiceProfile.identityKey)
// Eventually we'll want to do more things with new SignalServiceProfile fields here. // Eventually we'll want to do more things with new SignalServiceProfile fields here.

@ -321,8 +321,7 @@ import AVFoundation
let oldMode = session.mode let oldMode = session.mode
let oldOptions = session.categoryOptions let oldOptions = session.categoryOptions
if oldCategory == category, oldMode == mode, oldOptions == options { guard oldCategory != category || oldMode != mode || oldOptions != options else {
Logger.debug("\(self.TAG) in \(#function) doing nothing, since audio session is unchanged.")
return return
} }
@ -333,17 +332,15 @@ import AVFoundation
Logger.debug("\(self.TAG) audio session changed mode: \(oldMode) -> \(mode) ") Logger.debug("\(self.TAG) audio session changed mode: \(oldMode) -> \(mode) ")
} }
if oldOptions != options { if oldOptions != options {
Logger.debug("\(self.TAG) audio session changed category: \(oldOptions) -> \(options) ") Logger.debug("\(self.TAG) audio session changed options: \(oldOptions) -> \(options) ")
} }
Logger.debug("\(self.TAG) setting new category: \(category) mode: \(mode) options: \(options)")
try session.setCategory(category, mode: mode, options: options) try session.setCategory(category, mode: mode, options: options)
} else { } else {
let oldCategory = session.category let oldCategory = session.category
let oldOptions = session.categoryOptions let oldOptions = session.categoryOptions
if session.category == category, session.categoryOptions == options {
Logger.debug("\(self.TAG) in \(#function) doing nothing, since audio session is unchanged.") guard session.category != category || session.categoryOptions != options else {
return return
} }
@ -351,10 +348,8 @@ import AVFoundation
Logger.debug("\(self.TAG) audio session changed category: \(oldCategory) -> \(category) ") Logger.debug("\(self.TAG) audio session changed category: \(oldCategory) -> \(category) ")
} }
if oldOptions != options { if oldOptions != options {
Logger.debug("\(self.TAG) audio session changed category: \(oldOptions) -> \(options) ") Logger.debug("\(self.TAG) audio session changed options: \(oldOptions) -> \(options) ")
} }
Logger.debug("\(self.TAG) setting new category: \(category) options: \(options)")
try session.setCategory(category, with: options) try session.setCategory(category, with: options)
} }

@ -227,15 +227,11 @@ protocol CallServiceObserver: class {
func didEnterBackground() { func didEnterBackground() {
AssertIsOnMainThread() AssertIsOnMainThread()
Logger.info("\(self.TAG) \(#function)")
self.updateIsVideoEnabled() self.updateIsVideoEnabled()
} }
func didBecomeActive() { func didBecomeActive() {
AssertIsOnMainThread() AssertIsOnMainThread()
Logger.info("\(self.TAG) \(#function)")
self.updateIsVideoEnabled() self.updateIsVideoEnabled()
} }
@ -555,10 +551,11 @@ protocol CallServiceObserver: class {
// Find a sessionDescription compatible with my constraints and the remote sessionDescription // Find a sessionDescription compatible with my constraints and the remote sessionDescription
return peerConnectionClient.negotiateSessionDescription(remoteDescription: offerSessionDescription, constraints: constraints) return peerConnectionClient.negotiateSessionDescription(remoteDescription: offerSessionDescription, constraints: constraints)
}.then { (negotiatedSessionDescription: HardenedRTCSessionDescription) in }.then { (negotiatedSessionDescription: HardenedRTCSessionDescription) in
Logger.debug("\(self.TAG) set the remote description for: \(newCall.identifiersForLogs)")
guard self.call == newCall else { guard self.call == newCall else {
throw CallError.obsoleteCall(description: "negotiateSessionDescription() response for obsolete call") throw CallError.obsoleteCall(description: "negotiateSessionDescription() response for obsolete call")
} }
Logger.debug("\(self.TAG) set the remote description for: \(newCall.identifiersForLogs)")
let answerMessage = OWSCallAnswerMessage(callId: newCall.signalingId, sessionDescription: negotiatedSessionDescription.sdp) let answerMessage = OWSCallAnswerMessage(callId: newCall.signalingId, sessionDescription: negotiatedSessionDescription.sdp)
let callAnswerMessage = OWSOutgoingCallMessage(thread: thread, answerMessage: answerMessage) let callAnswerMessage = OWSOutgoingCallMessage(thread: thread, answerMessage: answerMessage)
@ -630,7 +627,7 @@ protocol CallServiceObserver: class {
return return
} }
peerConnectionClient.addIceCandidate(RTCIceCandidate(sdp: sdp, sdpMLineIndex: lineIndex, sdpMid: mid)) peerConnectionClient.addRemoteIceCandidate(RTCIceCandidate(sdp: sdp, sdpMLineIndex: lineIndex, sdpMid: mid))
} }
/** /**
@ -713,7 +710,7 @@ protocol CallServiceObserver: class {
guard let call = self.call else { guard let call = self.call else {
// This may happen if we hang up slightly before they hang up. // This may happen if we hang up slightly before they hang up.
handleFailedCurrentCall(error: .assertionError(description:"\(TAG) call was unexpectedly nil in \(#function)")) handleFailedCurrentCall(error: .obsoleteCall(description:"\(TAG) call was unexpectedly nil in \(#function)"))
return return
} }
@ -1205,6 +1202,10 @@ protocol CallServiceObserver: class {
public func handleFailedCall(failedCall: SignalCall?, error: CallError) { public func handleFailedCall(failedCall: SignalCall?, error: CallError) {
AssertIsOnMainThread() AssertIsOnMainThread()
if case .assertionError(let description) = error {
assertionFailure(description)
}
if let failedCall = failedCall { if let failedCall = failedCall {
// It's essential to set call.state before terminateCall, because terminateCall nils self.call // It's essential to set call.state before terminateCall, because terminateCall nils self.call
failedCall.error = error failedCall.error = error

@ -444,13 +444,13 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
} }
} }
public func addIceCandidate(_ candidate: RTCIceCandidate) { public func addRemoteIceCandidate(_ candidate: RTCIceCandidate) {
PeerConnectionClient.signalingQueue.async { PeerConnectionClient.signalingQueue.async {
guard self.peerConnection != nil else { guard self.peerConnection != nil else {
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client") Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
return return
} }
Logger.debug("\(self.TAG) adding candidate") Logger.info("\(self.TAG) adding remote ICE candidate: \(candidate.sdp)")
self.peerConnection.add(candidate) self.peerConnection.add(candidate)
} }
} }
@ -672,7 +672,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client") Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
return return
} }
Logger.debug("\(self.TAG) didGenerate IceCandidate:\(candidate.sdp)") Logger.info("\(self.TAG) adding local ICE candidate:\(candidate.sdp)")
if let delegate = self.delegate { if let delegate = self.delegate {
DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
guard let strongSelf = self else { return } guard let strongSelf = self else { return }

@ -29,7 +29,6 @@ class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
public func receivedOffer(_ offer: OWSSignalServiceProtosCallMessageOffer, from callerId: String) { public func receivedOffer(_ offer: OWSSignalServiceProtosCallMessageOffer, from callerId: String) {
AssertIsOnMainThread() AssertIsOnMainThread()
Logger.verbose("\(TAG) handling offer from caller:\(callerId)")
let thread = TSContactThread.getOrCreateThread(contactId: callerId) let thread = TSContactThread.getOrCreateThread(contactId: callerId)
self.callService.handleReceivedOffer(thread: thread, callId: offer.id, sessionDescription: offer.sessionDescription) self.callService.handleReceivedOffer(thread: thread, callId: offer.id, sessionDescription: offer.sessionDescription)
@ -37,7 +36,6 @@ class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
public func receivedAnswer(_ answer: OWSSignalServiceProtosCallMessageAnswer, from callerId: String) { public func receivedAnswer(_ answer: OWSSignalServiceProtosCallMessageAnswer, from callerId: String) {
AssertIsOnMainThread() AssertIsOnMainThread()
Logger.verbose("\(TAG) handling answer from caller:\(callerId)")
let thread = TSContactThread.getOrCreateThread(contactId: callerId) let thread = TSContactThread.getOrCreateThread(contactId: callerId)
self.callService.handleReceivedAnswer(thread: thread, callId: answer.id, sessionDescription: answer.sessionDescription) self.callService.handleReceivedAnswer(thread: thread, callId: answer.id, sessionDescription: answer.sessionDescription)
@ -45,7 +43,6 @@ class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
public func receivedIceUpdate(_ iceUpdate: OWSSignalServiceProtosCallMessageIceUpdate, from callerId: String) { public func receivedIceUpdate(_ iceUpdate: OWSSignalServiceProtosCallMessageIceUpdate, from callerId: String) {
AssertIsOnMainThread() AssertIsOnMainThread()
Logger.verbose("\(TAG) handling iceUpdates from caller:\(callerId)")
let thread = TSContactThread.getOrCreateThread(contactId: callerId) let thread = TSContactThread.getOrCreateThread(contactId: callerId)
@ -58,7 +55,6 @@ class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
public func receivedHangup(_ hangup: OWSSignalServiceProtosCallMessageHangup, from callerId: String) { public func receivedHangup(_ hangup: OWSSignalServiceProtosCallMessageHangup, from callerId: String) {
AssertIsOnMainThread() AssertIsOnMainThread()
Logger.verbose("\(TAG) handling 'hangup' from caller:\(callerId)")
let thread = TSContactThread.getOrCreateThread(contactId: callerId) let thread = TSContactThread.getOrCreateThread(contactId: callerId)
@ -67,7 +63,6 @@ class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
public func receivedBusy(_ busy: OWSSignalServiceProtosCallMessageBusy, from callerId: String) { public func receivedBusy(_ busy: OWSSignalServiceProtosCallMessageBusy, from callerId: String) {
AssertIsOnMainThread() AssertIsOnMainThread()
Logger.verbose("\(TAG) handling 'busy' from caller:\(callerId)")
let thread = TSContactThread.getOrCreateThread(contactId: callerId) let thread = TSContactThread.getOrCreateThread(contactId: callerId)

@ -471,8 +471,6 @@ class SystemContactsFetcher: NSObject {
return return
} }
Logger.debug("\(self.TAG) Notifying delegate that system contacts did change. hash:\(contactsHash)")
self.lastDelegateNotificationDate = Date() self.lastDelegateNotificationDate = Date()
self.lastContactUpdateHash = contactsHash self.lastContactUpdateHash = contactsHash

@ -49,20 +49,26 @@ import Foundation
} }
public func addBlock(blockObject: NSObject) { public func addBlock(blockObject: NSObject) {
AssertIsOnMainThread()
blocks.append(SleepBlock(blockObject: blockObject)) blocks.append(SleepBlock(blockObject: blockObject))
ensureSleepBlocking() ensureSleepBlocking()
} }
public func removeBlock(blockObject: NSObject) { public func removeBlock(blockObject: NSObject) {
AssertIsOnMainThread()
blocks = blocks.filter { blocks = blocks.filter {
$0.blockObject != nil && $0.blockObject != blockObject $0.blockObject != nil && $0.blockObject != blockObject
} }
ensureSleepBlocking() ensureSleepBlocking()
} }
private func ensureSleepBlocking() { private func ensureSleepBlocking() {
AssertIsOnMainThread()
// Cull expired blocks. // Cull expired blocks.
blocks = blocks.filter { blocks = blocks.filter {
$0.blockObject != nil $0.blockObject != nil
@ -71,7 +77,11 @@ import Foundation
if UIApplication.shared.isIdleTimerDisabled != shouldBlock { if UIApplication.shared.isIdleTimerDisabled != shouldBlock {
if shouldBlock { if shouldBlock {
Logger.info("\(self.TAG) \(#function): Blocking sleep") var logString = "\(self.TAG) \(#function): Blocking sleep because of: \(String(describing: blocks.first?.blockObject))"
if blocks.count > 1 {
logString += " and \(blocks.count - 1) others."
}
Logger.info(logString)
} else { } else {
Logger.info("\(self.TAG) \(#function): Unblocking sleep") Logger.info("\(self.TAG) \(#function): Unblocking sleep")
} }

@ -175,7 +175,6 @@ double const OWSExpirationTimerViewBlinkingSeconds = 2;
- (void)stopTimer - (void)stopTimer
{ {
DDLogVerbose(@"%@ Stopping Timer.", self.logTag);
[[NSNotificationCenter defaultCenter] removeObserver:self [[NSNotificationCenter defaultCenter] removeObserver:self
name:OWSMessagesViewControllerDidAppearNotification name:OWSMessagesViewControllerDidAppearNotification
object:nil]; object:nil];

Loading…
Cancel
Save