From edc839a999c2fd9170db2df6ba2f178c648c999a Mon Sep 17 00:00:00 2001 From: Ali <> Date: Thu, 19 Dec 2019 01:46:30 +0400 Subject: [PATCH] Use the legacy device lock reporting on iOS 9 --- .../Sources/AccountContext.swift | 1 + submodules/AppLock/Sources/AppLock.swift | 27 +++++++++++++++++++ .../TelegramUI/TelegramUI/AppDelegate.swift | 15 ++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/submodules/AccountContext/Sources/AccountContext.swift b/submodules/AccountContext/Sources/AccountContext.swift index 1fe5648935..c4ac2bf9a1 100644 --- a/submodules/AccountContext/Sources/AccountContext.swift +++ b/submodules/AccountContext/Sources/AccountContext.swift @@ -387,6 +387,7 @@ public enum CreateGroupMode { public protocol AppLockContext: class { var invalidAttempts: Signal { get } + var autolockDeadline: Signal { get } func lock() func unlock() diff --git a/submodules/AppLock/Sources/AppLock.swift b/submodules/AppLock/Sources/AppLock.swift index 7db119a63e..8e8ecda201 100644 --- a/submodules/AppLock/Sources/AppLock.swift +++ b/submodules/AppLock/Sources/AppLock.swift @@ -80,6 +80,7 @@ public final class AppLockContextImpl: AppLockContext { private let currentState = Promise() private let autolockTimeout = ValuePromise(nil, ignoreRepeated: true) + private let autolockReportTimeout = ValuePromise(nil, ignoreRepeated: true) private let isCurrentlyLockedPromise = Promise() public var isCurrentlyLocked: Signal { @@ -148,10 +149,24 @@ public final class AppLockContextImpl: AppLockContext { } strongSelf.autolockTimeout.set(nil) + strongSelf.autolockReportTimeout.set(nil) } else { if let autolockTimeout = passcodeSettings.autolockTimeout, !appInForeground { shouldDisplayCoveringView = true } + + if !appInForeground { + if let autolockTimeout = passcodeSettings.autolockTimeout { + strongSelf.autolockReportTimeout.set(autolockTimeout) + } else if state.isManuallyLocked { + strongSelf.autolockReportTimeout.set(1) + } else { + strongSelf.autolockReportTimeout.set(nil) + } + } else { + strongSelf.autolockReportTimeout.set(nil) + } + strongSelf.autolockTimeout.set(passcodeSettings.autolockTimeout) if isLocked(passcodeSettings: passcodeSettings, state: state, isApplicationActive: appInForeground) { @@ -296,6 +311,18 @@ public final class AppLockContextImpl: AppLockContext { } } + public var autolockDeadline: Signal { + return self.autolockReportTimeout.get() + |> distinctUntilChanged + |> map { value -> Int32? in + if let value = value { + return Int32(Date().timeIntervalSince1970) + value + } else { + return nil + } + } + } + public func lock() { self.updateLockState { state in var state = state diff --git a/submodules/TelegramUI/TelegramUI/AppDelegate.swift b/submodules/TelegramUI/TelegramUI/AppDelegate.swift index 71e8f9a73f..95d6ab23e4 100644 --- a/submodules/TelegramUI/TelegramUI/AppDelegate.swift +++ b/submodules/TelegramUI/TelegramUI/AppDelegate.swift @@ -375,6 +375,19 @@ final class SharedApplicationContext { let apiHash: String = buildConfig.apiHash let languagesCategory = "ios" + let autolockDeadine: Signal + if #available(iOS 10.0, *) { + autolockDeadine = .single(nil) + } else { + autolockDeadine = self.context.get() + |> mapToSignal { context -> Signal in + guard let context = context else { + return .single(nil) + } + return context.context.sharedContext.appLockContext.autolockDeadline + } + } + let networkArguments = NetworkInitializationArguments(apiId: apiId, apiHash: apiHash, languagesCategory: languagesCategory, appVersion: appVersion, voipMaxLayer: PresentationCallManagerImpl.voipMaxLayer, appData: self.deviceToken.get() |> map { token in let data = buildConfig.bundleData(withAppToken: token, signatureDict: signatureDict) @@ -384,7 +397,7 @@ final class SharedApplicationContext { Logger.shared.log("data", "can't deserialize") } return data - }, autolockDeadine: .single(nil), encryptionProvider: OpenSSLEncryptionProvider()) + }, autolockDeadine: autolockDeadine, encryptionProvider: OpenSSLEncryptionProvider()) guard let appGroupUrl = maybeAppGroupUrl else { UIAlertView(title: nil, message: "Error 2", delegate: nil, cancelButtonTitle: "OK").show()