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,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];
}
}
}
}

View File

@ -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()

View File

@ -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
}

View File

@ -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 {

View File

@ -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))

View File

@ -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",