Fix AppLock

This commit is contained in:
Ali 2019-11-02 22:55:07 +04:00
parent 7a01746ef7
commit da67ea139c
6 changed files with 76 additions and 43 deletions

View File

@ -226,15 +226,18 @@ static void reportMemory() {
silent = [silentString intValue] != 0; silent = [silentString intValue] != 0;
} }
NSString *attachmentDataString = decryptedPayload[@"attachb64"];
NSData *attachmentData = nil; NSData *attachmentData = nil;
id parsedAttachment = nil; id parsedAttachment = nil;
if (_isLockedValue) {
NSString *attachmentDataString = decryptedPayload[@"attachb64"];
if ([attachmentDataString isKindOfClass:[NSString class]]) { if ([attachmentDataString isKindOfClass:[NSString class]]) {
attachmentData = parseBase64(attachmentDataString); attachmentData = parseBase64(attachmentDataString);
if (attachmentData != nil) { if (attachmentData != nil) {
parsedAttachment = parseAttachment(attachmentData); parsedAttachment = parseAttachment(attachmentData);
} }
} }
}
NSString *imagesPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"aps-data"]; NSString *imagesPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"aps-data"];
[[NSFileManager defaultManager] createDirectoryAtPath:imagesPath withIntermediateDirectories:true attributes:nil error:nil]; [[NSFileManager defaultManager] createDirectoryAtPath:imagesPath withIntermediateDirectories:true attributes:nil error:nil];
@ -324,6 +327,7 @@ static void reportMemory() {
} }
_bestAttemptContent.title = title; _bestAttemptContent.title = title;
if (_isLockedValue) { if (_isLockedValue) {
_bestAttemptContent.title = @"";
_bestAttemptContent.subtitle = @""; _bestAttemptContent.subtitle = @"";
if (_lockedMessageTextValue != nil) { if (_lockedMessageTextValue != nil) {
_bestAttemptContent.body = _lockedMessageTextValue; _bestAttemptContent.body = _lockedMessageTextValue;
@ -348,14 +352,21 @@ static void reportMemory() {
} }
} }
if (_isLockedValue) {
_bestAttemptContent.threadIdentifier = @"locked";
} else {
NSString *threadIdString = aps[@"thread-id"]; NSString *threadIdString = aps[@"thread-id"];
if ([threadIdString isKindOfClass:[NSString class]]) { if ([threadIdString isKindOfClass:[NSString class]]) {
_bestAttemptContent.threadIdentifier = threadIdString; _bestAttemptContent.threadIdentifier = threadIdString;
} }
}
NSString *soundString = aps[@"sound"]; NSString *soundString = aps[@"sound"];
if ([soundString isKindOfClass:[NSString class]]) { if ([soundString isKindOfClass:[NSString class]]) {
_bestAttemptContent.sound = [UNNotificationSound soundNamed:soundString]; _bestAttemptContent.sound = [UNNotificationSound soundNamed:soundString];
} }
if (_isLockedValue) {
_bestAttemptContent.categoryIdentifier = @"locked";
} else {
NSString *categoryString = aps[@"category"]; NSString *categoryString = aps[@"category"];
if ([categoryString isKindOfClass:[NSString class]]) { if ([categoryString isKindOfClass:[NSString class]]) {
_bestAttemptContent.categoryIdentifier = categoryString; _bestAttemptContent.categoryIdentifier = categoryString;
@ -382,6 +393,7 @@ static void reportMemory() {
} }
} }
} }
}
_bestAttemptContent.userInfo = userInfo; _bestAttemptContent.userInfo = userInfo;

View File

@ -6,6 +6,16 @@ import BuildConfig
class ShareRootController: UIViewController { class ShareRootController: UIViewController {
private var impl: ShareRootControllerImpl? 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() { override func loadView() {
super.loadView() super.loadView()

View File

@ -17,12 +17,12 @@ private func isLocked(passcodeSettings: PresentationPasscodeSettings, state: Loc
} else if let autolockTimeout = passcodeSettings.autolockTimeout { } else if let autolockTimeout = passcodeSettings.autolockTimeout {
var bootTimestamp: Int32 = 0 var bootTimestamp: Int32 = 0
let uptime = getDeviceUptimeSeconds(&bootTimestamp) let uptime = getDeviceUptimeSeconds(&bootTimestamp)
let timestamp = MonotonicTimestamp(bootTimestap: bootTimestamp, uptime: uptime) let timestamp = MonotonicTimestamp(bootTimestamp: bootTimestamp, uptime: uptime)
let applicationActivityTimestamp = state.applicationActivityTimestamp let applicationActivityTimestamp = state.applicationActivityTimestamp
if let applicationActivityTimestamp = applicationActivityTimestamp { if let applicationActivityTimestamp = applicationActivityTimestamp {
if timestamp.bootTimestap != applicationActivityTimestamp.bootTimestap { if timestamp.bootTimestamp != applicationActivityTimestamp.bootTimestamp {
return true return true
} }
if timestamp.uptime >= applicationActivityTimestamp.uptime + autolockTimeout { if timestamp.uptime >= applicationActivityTimestamp.uptime + autolockTimeout {
@ -249,7 +249,7 @@ public final class AppLockContextImpl: AppLockContext {
let uptime = getDeviceUptimeSeconds(&bootTimestamp) let uptime = getDeviceUptimeSeconds(&bootTimestamp)
var state = state var state = state
state.applicationActivityTimestamp = MonotonicTimestamp(bootTimestap: bootTimestamp, uptime: uptime) state.applicationActivityTimestamp = MonotonicTimestamp(bootTimestamp: bootTimestamp, uptime: uptime)
return state return state
} }
} }
@ -276,7 +276,7 @@ public final class AppLockContextImpl: AppLockContext {
return self.currentState.get() return self.currentState.get()
|> map { state in |> map { state in
return state.unlockAttemts.flatMap { unlockAttemts 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 var bootTimestamp: Int32 = 0
let uptime = getDeviceUptimeSeconds(&bootTimestamp) let uptime = getDeviceUptimeSeconds(&bootTimestamp)
let timestamp = MonotonicTimestamp(bootTimestap: bootTimestamp, uptime: uptime) let timestamp = MonotonicTimestamp(bootTimestamp: bootTimestamp, uptime: uptime)
state.applicationActivityTimestamp = timestamp state.applicationActivityTimestamp = timestamp
return state return state
@ -309,9 +309,15 @@ public final class AppLockContextImpl: AppLockContext {
public func failedUnlockAttempt() { public func failedUnlockAttempt() {
self.updateLockState { state in self.updateLockState { state in
var state = state 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.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 state.unlockAttemts = unlockAttemts
return state return state
} }

View File

@ -2,22 +2,22 @@ import Foundation
import MonotonicTime import MonotonicTime
public struct MonotonicTimestamp: Codable, Equatable { public struct MonotonicTimestamp: Codable, Equatable {
public var bootTimestap: Int32 public var bootTimestamp: Int32
public var uptime: Int32 public var uptime: Int32
public init(bootTimestap: Int32, uptime: Int32) { public init(bootTimestamp: Int32, uptime: Int32) {
self.bootTimestap = bootTimestap self.bootTimestamp = bootTimestamp
self.uptime = uptime self.uptime = uptime
} }
} }
public struct UnlockAttempts: Codable, Equatable { public struct UnlockAttempts: Codable, Equatable {
public var count: Int32 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.count = count
self.wallClockTimestamp = wallClockTimestamp self.timestamp = timestamp
} }
} }
@ -45,10 +45,10 @@ public func isAppLocked(state: LockState) -> Bool {
} else if let autolockTimeout = state.autolockTimeout { } else if let autolockTimeout = state.autolockTimeout {
var bootTimestamp: Int32 = 0 var bootTimestamp: Int32 = 0
let uptime = getDeviceUptimeSeconds(&bootTimestamp) let uptime = getDeviceUptimeSeconds(&bootTimestamp)
let timestamp = MonotonicTimestamp(bootTimestap: bootTimestamp, uptime: uptime) let timestamp = MonotonicTimestamp(bootTimestamp: bootTimestamp, uptime: uptime)
if let applicationActivityTimestamp = state.applicationActivityTimestamp { if let applicationActivityTimestamp = state.applicationActivityTimestamp {
if timestamp.bootTimestap != applicationActivityTimestamp.bootTimestap { if timestamp.bootTimestamp != applicationActivityTimestamp.bootTimestamp {
return true return true
} }
if timestamp.uptime >= applicationActivityTimestamp.uptime + autolockTimeout { if timestamp.uptime >= applicationActivityTimestamp.uptime + autolockTimeout {

View File

@ -899,6 +899,8 @@ public class Window1 {
self.presentationContext.updateToInterfaceOrientation(orientation) self.presentationContext.updateToInterfaceOrientation(orientation)
self.overlayPresentationContext.updateToInterfaceOrientation(orientation) self.overlayPresentationContext.updateToInterfaceOrientation(orientation)
self.topPresentationContext.updateToInterfaceOrientation(orientation)
for controller in self.topLevelOverlayControllers { for controller in self.topLevelOverlayControllers {
controller.updateToInterfaceOrientation(orientation) controller.updateToInterfaceOrientation(orientation)
} }
@ -973,6 +975,8 @@ public class Window1 {
self.presentationContext.containerLayoutUpdated(childLayout, transition: updatingLayout.transition) self.presentationContext.containerLayoutUpdated(childLayout, transition: updatingLayout.transition)
self.overlayPresentationContext.containerLayoutUpdated(childLayout, transition: updatingLayout.transition) self.overlayPresentationContext.containerLayoutUpdated(childLayout, transition: updatingLayout.transition)
self.topPresentationContext.containerLayoutUpdated(childLayout, transition: updatingLayout.transition)
for controller in self.topLevelOverlayControllers { for controller in self.topLevelOverlayControllers {
updatingLayout.transition.updateFrame(node: controller.displayNode, frame: CGRect(origin: CGPoint(), size: self.windowLayout.size)) updatingLayout.transition.updateFrame(node: controller.displayNode, frame: CGRect(origin: CGPoint(), size: self.windowLayout.size))
controller.containerLayoutUpdated(childLayout, transition: updatingLayout.transition) controller.containerLayoutUpdated(childLayout, transition: updatingLayout.transition)

View File

@ -21,6 +21,7 @@ static_library(
"//submodules/ImageBlur:ImageBlur", "//submodules/ImageBlur:ImageBlur",
"//submodules/AppBundle:AppBundle", "//submodules/AppBundle:AppBundle",
"//submodules/PasscodeInputFieldNode:PasscodeInputFieldNode", "//submodules/PasscodeInputFieldNode:PasscodeInputFieldNode",
"//submodules/MonotonicTime:MonotonicTime",
], ],
frameworks = [ frameworks = [
"$SDKROOT/System/Library/Frameworks/Foundation.framework", "$SDKROOT/System/Library/Frameworks/Foundation.framework",