From da67ea139c6326480e0e6d8ccc63e524aa49ad3b Mon Sep 17 00:00:00 2001 From: Ali <> Date: Sat, 2 Nov 2019 22:55:07 +0400 Subject: [PATCH] Fix AppLock --- NotificationService/NotificationService.m | 68 +++++++++++-------- Share/ShareRootController.swift | 10 +++ submodules/AppLock/Sources/AppLock.swift | 20 ++++-- .../AppLockState/Sources/AppLockState.swift | 16 ++--- .../Display/Display/WindowContent.swift | 4 ++ submodules/PasscodeUI/BUCK | 1 + 6 files changed, 76 insertions(+), 43 deletions(-) diff --git a/NotificationService/NotificationService.m b/NotificationService/NotificationService.m index 955b2c13ff..8d2df09a25 100644 --- a/NotificationService/NotificationService.m +++ b/NotificationService/NotificationService.m @@ -226,13 +226,16 @@ static void reportMemory() { silent = [silentString intValue] != 0; } - NSString *attachmentDataString = decryptedPayload[@"attachb64"]; NSData *attachmentData = nil; id parsedAttachment = nil; - if ([attachmentDataString isKindOfClass:[NSString class]]) { - attachmentData = parseBase64(attachmentDataString); - if (attachmentData != nil) { - parsedAttachment = parseAttachment(attachmentData); + + if (_isLockedValue) { + NSString *attachmentDataString = decryptedPayload[@"attachb64"]; + if ([attachmentDataString isKindOfClass:[NSString class]]) { + attachmentData = parseBase64(attachmentDataString); + if (attachmentData != nil) { + parsedAttachment = parseAttachment(attachmentData); + } } } @@ -324,6 +327,7 @@ static void reportMemory() { } _bestAttemptContent.title = title; if (_isLockedValue) { + _bestAttemptContent.title = @""; _bestAttemptContent.subtitle = @""; if (_lockedMessageTextValue != nil) { _bestAttemptContent.body = _lockedMessageTextValue; @@ -348,37 +352,45 @@ static void reportMemory() { } } - NSString *threadIdString = aps[@"thread-id"]; - if ([threadIdString isKindOfClass:[NSString class]]) { - _bestAttemptContent.threadIdentifier = threadIdString; + if (_isLockedValue) { + _bestAttemptContent.threadIdentifier = @"locked"; + } else { + NSString *threadIdString = aps[@"thread-id"]; + if ([threadIdString isKindOfClass:[NSString class]]) { + _bestAttemptContent.threadIdentifier = threadIdString; + } } NSString *soundString = aps[@"sound"]; if ([soundString isKindOfClass:[NSString class]]) { _bestAttemptContent.sound = [UNNotificationSound soundNamed:soundString]; } - NSString *categoryString = aps[@"category"]; - if ([categoryString isKindOfClass:[NSString class]]) { - _bestAttemptContent.categoryIdentifier = categoryString; - if (peerId != 0 && messageId != 0 && parsedAttachment != nil && attachmentData != nil) { - userInfo[@"peerId"] = @(peerId); - userInfo[@"messageId.namespace"] = @(0); - userInfo[@"messageId.id"] = @(messageId); - - userInfo[@"media"] = [attachmentData base64EncodedStringWithOptions:0]; - - if (isExpandableMedia) { - if ([categoryString isEqualToString:@"r"]) { - _bestAttemptContent.categoryIdentifier = @"withReplyMedia"; - } else if ([categoryString isEqualToString:@"m"]) { - _bestAttemptContent.categoryIdentifier = @"withMuteMedia"; + if (_isLockedValue) { + _bestAttemptContent.categoryIdentifier = @"locked"; + } else { + NSString *categoryString = aps[@"category"]; + if ([categoryString isKindOfClass:[NSString class]]) { + _bestAttemptContent.categoryIdentifier = categoryString; + if (peerId != 0 && messageId != 0 && parsedAttachment != nil && attachmentData != nil) { + userInfo[@"peerId"] = @(peerId); + userInfo[@"messageId.namespace"] = @(0); + userInfo[@"messageId.id"] = @(messageId); + + userInfo[@"media"] = [attachmentData base64EncodedStringWithOptions:0]; + + if (isExpandableMedia) { + if ([categoryString isEqualToString:@"r"]) { + _bestAttemptContent.categoryIdentifier = @"withReplyMedia"; + } else if ([categoryString isEqualToString:@"m"]) { + _bestAttemptContent.categoryIdentifier = @"withMuteMedia"; + } } } } - } - - if (accountInfos.accounts.count > 1) { - if (_bestAttemptContent.title.length != 0 && account.peerName.length != 0) { - _bestAttemptContent.title = [NSString stringWithFormat:@"%@ → %@", _bestAttemptContent.title, account.peerName]; + + if (accountInfos.accounts.count > 1) { + if (_bestAttemptContent.title.length != 0 && account.peerName.length != 0) { + _bestAttemptContent.title = [NSString stringWithFormat:@"%@ → %@", _bestAttemptContent.title, account.peerName]; + } } } } diff --git a/Share/ShareRootController.swift b/Share/ShareRootController.swift index cd0fd1e4d2..5dac1a0097 100644 --- a/Share/ShareRootController.swift +++ b/Share/ShareRootController.swift @@ -6,6 +6,16 @@ import BuildConfig class ShareRootController: UIViewController { private var impl: ShareRootControllerImpl? + override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { + super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) + + self.modalPresentationStyle = .fullScreen + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + override func loadView() { super.loadView() diff --git a/submodules/AppLock/Sources/AppLock.swift b/submodules/AppLock/Sources/AppLock.swift index 17ead4e47e..c8cdc58649 100644 --- a/submodules/AppLock/Sources/AppLock.swift +++ b/submodules/AppLock/Sources/AppLock.swift @@ -17,12 +17,12 @@ private func isLocked(passcodeSettings: PresentationPasscodeSettings, state: Loc } else if let autolockTimeout = passcodeSettings.autolockTimeout { var bootTimestamp: Int32 = 0 let uptime = getDeviceUptimeSeconds(&bootTimestamp) - let timestamp = MonotonicTimestamp(bootTimestap: bootTimestamp, uptime: uptime) + let timestamp = MonotonicTimestamp(bootTimestamp: bootTimestamp, uptime: uptime) let applicationActivityTimestamp = state.applicationActivityTimestamp if let applicationActivityTimestamp = applicationActivityTimestamp { - if timestamp.bootTimestap != applicationActivityTimestamp.bootTimestap { + if timestamp.bootTimestamp != applicationActivityTimestamp.bootTimestamp { return true } if timestamp.uptime >= applicationActivityTimestamp.uptime + autolockTimeout { @@ -249,7 +249,7 @@ public final class AppLockContextImpl: AppLockContext { let uptime = getDeviceUptimeSeconds(&bootTimestamp) var state = state - state.applicationActivityTimestamp = MonotonicTimestamp(bootTimestap: bootTimestamp, uptime: uptime) + state.applicationActivityTimestamp = MonotonicTimestamp(bootTimestamp: bootTimestamp, uptime: uptime) return state } } @@ -276,7 +276,7 @@ public final class AppLockContextImpl: AppLockContext { return self.currentState.get() |> map { state in return state.unlockAttemts.flatMap { unlockAttemts in - return AccessChallengeAttempts(count: unlockAttemts.count, timestamp: unlockAttemts.wallClockTimestamp) + return AccessChallengeAttempts(count: unlockAttemts.count, bootTimestamp: unlockAttemts.timestamp.bootTimestamp, uptime: unlockAttemts.timestamp.uptime) } } } @@ -299,7 +299,7 @@ public final class AppLockContextImpl: AppLockContext { var bootTimestamp: Int32 = 0 let uptime = getDeviceUptimeSeconds(&bootTimestamp) - let timestamp = MonotonicTimestamp(bootTimestap: bootTimestamp, uptime: uptime) + let timestamp = MonotonicTimestamp(bootTimestamp: bootTimestamp, uptime: uptime) state.applicationActivityTimestamp = timestamp return state @@ -309,9 +309,15 @@ public final class AppLockContextImpl: AppLockContext { public func failedUnlockAttempt() { self.updateLockState { state in var state = state - var unlockAttemts = state.unlockAttemts ?? UnlockAttempts(count: 0, wallClockTimestamp: 0) + var unlockAttemts = state.unlockAttemts ?? UnlockAttempts(count: 0, timestamp: MonotonicTimestamp(bootTimestamp: 0, uptime: 0)) + unlockAttemts.count += 1 - unlockAttemts.wallClockTimestamp = Int32(CFAbsoluteTimeGetCurrent()) + + var bootTimestamp: Int32 = 0 + let uptime = getDeviceUptimeSeconds(&bootTimestamp) + let timestamp = MonotonicTimestamp(bootTimestamp: bootTimestamp, uptime: uptime) + + unlockAttemts.timestamp = timestamp state.unlockAttemts = unlockAttemts return state } diff --git a/submodules/AppLockState/Sources/AppLockState.swift b/submodules/AppLockState/Sources/AppLockState.swift index a044c7901c..c632725ab1 100644 --- a/submodules/AppLockState/Sources/AppLockState.swift +++ b/submodules/AppLockState/Sources/AppLockState.swift @@ -2,22 +2,22 @@ import Foundation import MonotonicTime public struct MonotonicTimestamp: Codable, Equatable { - public var bootTimestap: Int32 + public var bootTimestamp: Int32 public var uptime: Int32 - public init(bootTimestap: Int32, uptime: Int32) { - self.bootTimestap = bootTimestap + public init(bootTimestamp: Int32, uptime: Int32) { + self.bootTimestamp = bootTimestamp self.uptime = uptime } } public struct UnlockAttempts: Codable, Equatable { public var count: Int32 - public var wallClockTimestamp: Int32 + public var timestamp: MonotonicTimestamp - public init(count: Int32, wallClockTimestamp: Int32) { + public init(count: Int32, timestamp: MonotonicTimestamp) { self.count = count - self.wallClockTimestamp = wallClockTimestamp + self.timestamp = timestamp } } @@ -45,10 +45,10 @@ public func isAppLocked(state: LockState) -> Bool { } else if let autolockTimeout = state.autolockTimeout { var bootTimestamp: Int32 = 0 let uptime = getDeviceUptimeSeconds(&bootTimestamp) - let timestamp = MonotonicTimestamp(bootTimestap: bootTimestamp, uptime: uptime) + let timestamp = MonotonicTimestamp(bootTimestamp: bootTimestamp, uptime: uptime) if let applicationActivityTimestamp = state.applicationActivityTimestamp { - if timestamp.bootTimestap != applicationActivityTimestamp.bootTimestap { + if timestamp.bootTimestamp != applicationActivityTimestamp.bootTimestamp { return true } if timestamp.uptime >= applicationActivityTimestamp.uptime + autolockTimeout { diff --git a/submodules/Display/Display/WindowContent.swift b/submodules/Display/Display/WindowContent.swift index fec5ee6303..49b8e12ca1 100644 --- a/submodules/Display/Display/WindowContent.swift +++ b/submodules/Display/Display/WindowContent.swift @@ -899,6 +899,8 @@ public class Window1 { self.presentationContext.updateToInterfaceOrientation(orientation) self.overlayPresentationContext.updateToInterfaceOrientation(orientation) + self.topPresentationContext.updateToInterfaceOrientation(orientation) + for controller in self.topLevelOverlayControllers { controller.updateToInterfaceOrientation(orientation) } @@ -972,6 +974,8 @@ public class Window1 { } self.presentationContext.containerLayoutUpdated(childLayout, transition: updatingLayout.transition) self.overlayPresentationContext.containerLayoutUpdated(childLayout, transition: updatingLayout.transition) + + self.topPresentationContext.containerLayoutUpdated(childLayout, transition: updatingLayout.transition) for controller in self.topLevelOverlayControllers { updatingLayout.transition.updateFrame(node: controller.displayNode, frame: CGRect(origin: CGPoint(), size: self.windowLayout.size)) diff --git a/submodules/PasscodeUI/BUCK b/submodules/PasscodeUI/BUCK index 2421d5404e..4ef81d0bff 100644 --- a/submodules/PasscodeUI/BUCK +++ b/submodules/PasscodeUI/BUCK @@ -21,6 +21,7 @@ static_library( "//submodules/ImageBlur:ImageBlur", "//submodules/AppBundle:AppBundle", "//submodules/PasscodeInputFieldNode:PasscodeInputFieldNode", + "//submodules/MonotonicTime:MonotonicTime", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework",