Further fixes

• Fixed an issue where the default log level was set too low
• Fixed an issue where sending the app to the background without any pending jobs could result in the database and network not being suspended correctly
• Updated to latest libSession (don't try to recover paths, just rebuild)
pull/986/head
Morgan Pretty 9 months ago
parent ea7b4a2de3
commit e2fc0a5b51

@ -1 +1 @@
Subproject commit c9a98dbb2e2ef45aa85075576247d61355269e1c
Subproject commit 3ad5920794d6c84d7ebd44936a23627f574fdc73

@ -38,7 +38,7 @@ extension ProjectState {
.contains("print(", caseSensitive: false),
.contains("SNLog(", caseSensitive: false),
.contains("Log.setup(", caseSensitive: false),
.contains("Log.trace(", caseSensitive: false),
.contains("Log.verbose(", caseSensitive: false),
.contains("Log.debug(", caseSensitive: false),
.contains("Log.info(", caseSensitive: false),
.contains("Log.warn(", caseSensitive: false),

@ -8042,7 +8042,7 @@
CLANG_WARN__ARC_BRIDGE_CAST_NONARC = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 454;
CURRENT_PROJECT_VERSION = 458;
ENABLE_BITCODE = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
@ -8120,7 +8120,7 @@
CLANG_WARN__ARC_BRIDGE_CAST_NONARC = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CURRENT_PROJECT_VERSION = 454;
CURRENT_PROJECT_VERSION = 458;
ENABLE_BITCODE = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;

@ -196,7 +196,7 @@ public final class SessionCallManager: NSObject, CallManagerProtocol {
let dependencies: Dependencies = Dependencies()
// Stop all jobs except for message sending and when completed suspend the database
JobRunner.stopAndClearPendingJobs(exceptForVariant: .messageSend, using: dependencies) {
JobRunner.stopAndClearPendingJobs(exceptForVariant: .messageSend, using: dependencies) { _ in
LibSession.suspendNetworkAccess()
Storage.suspendDatabaseAccess()
Log.flush()

@ -51,7 +51,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
AppSetup.setupEnvironment(
appSpecificBlock: {
Log.setup(with: Logger(primaryPrefix: "Session"))
Log.setup(with: Logger(primaryPrefix: "Session", level: .info))
Log.info("[AppDelegate] Setting up environment.")
// Setup LibSession
@ -210,8 +210,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
let dependencies: Dependencies = Dependencies()
// Stop all jobs except for message sending and when completed suspend the database
JobRunner.stopAndClearPendingJobs(exceptForVariant: .messageSend, using: dependencies) {
if !self.hasCallOngoing() && Singleton.hasAppContext && Singleton.appContext.isInBackground {
JobRunner.stopAndClearPendingJobs(exceptForVariant: .messageSend, using: dependencies) { neededBackgroundProcessing in
if !self.hasCallOngoing() && (!neededBackgroundProcessing || Singleton.hasAppContext && Singleton.appContext.isInBackground) {
LibSession.suspendNetworkAccess()
Storage.suspendDatabaseAccess()
Log.info("[AppDelegate] completed network and database shutdowns.")

@ -88,17 +88,17 @@ class ScreenLockUI {
private var desiredUIState: ScreenLockViewController.State {
if isScreenLockLocked {
if appIsInactiveOrBackground {
Log.trace("desiredUIState: screen protection 1.")
Log.verbose("desiredUIState: screen protection 1.")
return .protection
}
Log.trace("desiredUIState: screen lock 2.")
Log.verbose("desiredUIState: screen lock 2.")
return (isShowingScreenLockUI ? .protection : .lock)
}
if !self.appIsInactiveOrBackground {
// App is inactive or background.
Log.trace("desiredUIState: none 3.");
Log.verbose("desiredUIState: none 3.");
return .none;
}
@ -106,7 +106,7 @@ class ScreenLockUI {
return .none;
}
Log.trace("desiredUIState: screen protection 4.")
Log.verbose("desiredUIState: screen protection 4.")
return .protection;
}
@ -181,17 +181,17 @@ class ScreenLockUI {
//
// We don't need to try to lock the screen lock;
// It will be initialized by `setupWithRootWindow`.
Log.trace("tryToActivateScreenLockUponBecomingActive NO 0")
Log.verbose("tryToActivateScreenLockUponBecomingActive NO 0")
return
}
guard Storage.shared[.isScreenLockEnabled] else {
// Screen lock is not enabled.
Log.trace("tryToActivateScreenLockUponBecomingActive NO 1")
Log.verbose("tryToActivateScreenLockUponBecomingActive NO 1")
return;
}
guard !isScreenLockLocked else {
// Screen lock is already activated.
Log.trace("tryToActivateScreenLockUponBecomingActive NO 2")
Log.verbose("tryToActivateScreenLockUponBecomingActive NO 2")
return;
}
@ -211,7 +211,7 @@ class ScreenLockUI {
}
let desiredUIState: ScreenLockViewController.State = self.desiredUIState
Log.trace("ensureUI: \(desiredUIState)")
Log.verbose("ensureUI: \(desiredUIState)")
// Show the "iOS auth UI to unlock" if necessary.
if desiredUIState == .lock && !didLastUnlockAttemptFail {
@ -368,7 +368,7 @@ class ScreenLockUI {
//
// We don't need to try to lock the screen lock;
// It will be initialized by `setupWithRootWindow`.
Log.trace("clockDidChange 0")
Log.verbose("clockDidChange 0")
return;
}

@ -210,7 +210,7 @@ public struct ProfileManager {
let filePath: String = ProfileManager.profileAvatarFilepath(filename: fileName)
var backgroundTask: OWSBackgroundTask? = OWSBackgroundTask(label: funcName)
Log.trace("downloading profile avatar: \(profile.id)")
Log.verbose("downloading profile avatar: \(profile.id)")
currentAvatarDownloads.mutate { $0.insert(profile.id) }
LibSession

@ -295,6 +295,7 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
appSpecificBlock: {
Log.setup(with: Logger(
primaryPrefix: "NotificationServiceExtension", // stringlint:disable
level: .info,
customDirectory: "\(OWSFileSystem.appSharedDataDirectoryPath())/Logs/NotificationExtension", // stringlint:disable
forceNSLog: true
))

@ -54,6 +54,7 @@ final class ShareNavController: UINavigationController, ShareViewDelegate {
appSpecificBlock: {
Log.setup(with: Logger(
primaryPrefix: "SessionShareExtension", // stringlint:disable
level: .info,
customDirectory: "\(OWSFileSystem.appSharedDataDirectoryPath())/Logs/ShareExtension" // stringlint:disable
))

@ -10,8 +10,8 @@ import SignalCoreKit
public enum Log {
fileprivate typealias LogInfo = (level: Log.Level, message: String, withPrefixes: Bool, silenceForTests: Bool)
public enum Level {
case trace
public enum Level: Comparable {
case verbose
case debug
case info
case warn
@ -116,12 +116,12 @@ public enum Log {
}
}
public static func trace(
public static func verbose(
_ message: String,
withPrefixes: Bool = true,
silenceForTests: Bool = false
) {
custom(.trace, message, withPrefixes: withPrefixes, silenceForTests: silenceForTests)
custom(.verbose, message, withPrefixes: withPrefixes, silenceForTests: silenceForTests)
}
public static func debug(
@ -184,6 +184,7 @@ public enum Log {
public class Logger {
private let isRunningTests: Bool = (ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] == nil)
private let primaryPrefix: String
private var level: Log.Level
private let forceNSLog: Bool
fileprivate let fileLogger: DDFileLogger
fileprivate let isSuspended: Atomic<Bool> = Atomic(true)
@ -191,10 +192,12 @@ public class Logger {
public init(
primaryPrefix: String,
level: Log.Level,
customDirectory: String? = nil,
forceNSLog: Bool = false
) {
self.primaryPrefix = primaryPrefix
self.level = level
self.forceNSLog = forceNSLog
switch customDirectory {
@ -341,6 +344,7 @@ public class Logger {
silenceForTests: Bool
) {
guard !silenceForTests || !isRunningTests else { return }
guard level >= self.level else { return }
// Sort out the prefixes
let logPrefix: String = {
@ -367,7 +371,7 @@ public class Logger {
switch level {
case .off: return
case .trace: OWSLogger.verbose(logMessage)
case .verbose: OWSLogger.verbose(logMessage)
case .debug: OWSLogger.debug(logMessage)
case .info: OWSLogger.info(logMessage)
case .warn: OWSLogger.warn(logMessage)

@ -20,7 +20,10 @@ public protocol JobRunnerType {
func appDidFinishLaunching(using dependencies: Dependencies)
func appDidBecomeActive(using dependencies: Dependencies)
func startNonBlockingQueues(using dependencies: Dependencies)
func stopAndClearPendingJobs(exceptForVariant: Job.Variant?, using dependencies: Dependencies, onComplete: (() -> ())?)
/// Stops and clears any pending jobs except for the specified variant, the `onComplete` closure will be called once complete providing a flag indicating whether any additionak
/// processing was needed before the closure was called (if not then the closure will be called synchronously)
func stopAndClearPendingJobs(exceptForVariant: Job.Variant?, using dependencies: Dependencies, onComplete: ((Bool) -> ())?)
// MARK: - Job Scheduling
@ -577,7 +580,7 @@ public final class JobRunner: JobRunnerType {
public func stopAndClearPendingJobs(
exceptForVariant: Job.Variant?,
using dependencies: Dependencies,
onComplete: (() -> ())?
onComplete: ((Bool) -> ())?
) {
// Inform the JobRunner that it can't start any queues (this is to prevent queues from
// rescheduling themselves while in the background, when the app restarts or becomes active
@ -602,7 +605,7 @@ public final class JobRunner: JobRunnerType {
let queue: JobQueue = queues.wrappedValue[exceptForVariant],
queue.isRunning.wrappedValue == true
else {
onComplete?()
onComplete?(false)
return
}
@ -619,7 +622,7 @@ public final class JobRunner: JobRunnerType {
}
guard state != .success else { return }
onComplete?()
onComplete?(true)
queue?.onQueueDrained = oldQueueDrained
queue?.stopAndClearPendingJobs()
}
@ -629,7 +632,7 @@ public final class JobRunner: JobRunnerType {
queue.onQueueDrained = { [weak self, weak queue] in
oldQueueDrained?()
queue?.onQueueDrained = oldQueueDrained
onComplete?()
onComplete?(true)
self?.shutdownBackgroundTask.mutate { $0 = nil }
}
@ -1887,7 +1890,7 @@ public extension JobRunner {
static func stopAndClearPendingJobs(
exceptForVariant: Job.Variant? = nil,
using dependencies: Dependencies,
onComplete: (() -> ())? = nil
onComplete: ((Bool) -> ())? = nil
) {
instance.stopAndClearPendingJobs(exceptForVariant: exceptForVariant, using: dependencies, onComplete: onComplete)
}

@ -83,7 +83,7 @@ extension LibSession {
fileprivate extension Log.Level {
init(_ level: LOG_LEVEL) {
switch level {
case LOG_LEVEL_TRACE: self = .trace
case LOG_LEVEL_TRACE: self = .verbose
case LOG_LEVEL_DEBUG: self = .debug
case LOG_LEVEL_INFO: self = .info
case LOG_LEVEL_WARN: self = .warn

@ -13,4 +13,8 @@ class MockGeneralCache: Mock<GeneralCacheType>, GeneralCacheType {
get { return (accept() as? [Int64] ?? []) }
set { accept(args: [newValue]) }
}
func clearCachedUserPublicKey() {
accept()
}
}

@ -32,9 +32,9 @@ class MockJobRunner: Mock<JobRunnerType>, JobRunnerType {
func appDidBecomeActive(using dependencies: Dependencies) {}
func startNonBlockingQueues(using dependencies: Dependencies) {}
func stopAndClearPendingJobs(exceptForVariant: Job.Variant?, onComplete: (() -> ())?) {
func stopAndClearPendingJobs(exceptForVariant: Job.Variant?, using dependencies: Dependencies, onComplete: ((Bool) -> ())?) {
accept(args: [exceptForVariant, onComplete])
onComplete?()
onComplete?(false)
}
// MARK: - Job Scheduling

Loading…
Cancel
Save