Use the legacy device lock reporting on iOS 9

This commit is contained in:
Ali 2019-12-19 01:46:30 +04:00
parent f9529bc7d1
commit edc839a999
3 changed files with 42 additions and 1 deletions

View File

@ -387,6 +387,7 @@ public enum CreateGroupMode {
public protocol AppLockContext: class { public protocol AppLockContext: class {
var invalidAttempts: Signal<AccessChallengeAttempts?, NoError> { get } var invalidAttempts: Signal<AccessChallengeAttempts?, NoError> { get }
var autolockDeadline: Signal<Int32?, NoError> { get }
func lock() func lock()
func unlock() func unlock()

View File

@ -80,6 +80,7 @@ public final class AppLockContextImpl: AppLockContext {
private let currentState = Promise<LockState>() private let currentState = Promise<LockState>()
private let autolockTimeout = ValuePromise<Int32?>(nil, ignoreRepeated: true) private let autolockTimeout = ValuePromise<Int32?>(nil, ignoreRepeated: true)
private let autolockReportTimeout = ValuePromise<Int32?>(nil, ignoreRepeated: true)
private let isCurrentlyLockedPromise = Promise<Bool>() private let isCurrentlyLockedPromise = Promise<Bool>()
public var isCurrentlyLocked: Signal<Bool, NoError> { public var isCurrentlyLocked: Signal<Bool, NoError> {
@ -148,10 +149,24 @@ public final class AppLockContextImpl: AppLockContext {
} }
strongSelf.autolockTimeout.set(nil) strongSelf.autolockTimeout.set(nil)
strongSelf.autolockReportTimeout.set(nil)
} else { } else {
if let autolockTimeout = passcodeSettings.autolockTimeout, !appInForeground { if let autolockTimeout = passcodeSettings.autolockTimeout, !appInForeground {
shouldDisplayCoveringView = true 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) strongSelf.autolockTimeout.set(passcodeSettings.autolockTimeout)
if isLocked(passcodeSettings: passcodeSettings, state: state, isApplicationActive: appInForeground) { if isLocked(passcodeSettings: passcodeSettings, state: state, isApplicationActive: appInForeground) {
@ -296,6 +311,18 @@ public final class AppLockContextImpl: AppLockContext {
} }
} }
public var autolockDeadline: Signal<Int32?, NoError> {
return self.autolockReportTimeout.get()
|> distinctUntilChanged
|> map { value -> Int32? in
if let value = value {
return Int32(Date().timeIntervalSince1970) + value
} else {
return nil
}
}
}
public func lock() { public func lock() {
self.updateLockState { state in self.updateLockState { state in
var state = state var state = state

View File

@ -375,6 +375,19 @@ final class SharedApplicationContext {
let apiHash: String = buildConfig.apiHash let apiHash: String = buildConfig.apiHash
let languagesCategory = "ios" let languagesCategory = "ios"
let autolockDeadine: Signal<Int32?, NoError>
if #available(iOS 10.0, *) {
autolockDeadine = .single(nil)
} else {
autolockDeadine = self.context.get()
|> mapToSignal { context -> Signal<Int32?, NoError> 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() let networkArguments = NetworkInitializationArguments(apiId: apiId, apiHash: apiHash, languagesCategory: languagesCategory, appVersion: appVersion, voipMaxLayer: PresentationCallManagerImpl.voipMaxLayer, appData: self.deviceToken.get()
|> map { token in |> map { token in
let data = buildConfig.bundleData(withAppToken: token, signatureDict: signatureDict) let data = buildConfig.bundleData(withAppToken: token, signatureDict: signatureDict)
@ -384,7 +397,7 @@ final class SharedApplicationContext {
Logger.shared.log("data", "can't deserialize") Logger.shared.log("data", "can't deserialize")
} }
return data return data
}, autolockDeadine: .single(nil), encryptionProvider: OpenSSLEncryptionProvider()) }, autolockDeadine: autolockDeadine, encryptionProvider: OpenSSLEncryptionProvider())
guard let appGroupUrl = maybeAppGroupUrl else { guard let appGroupUrl = maybeAppGroupUrl else {
UIAlertView(title: nil, message: "Error 2", delegate: nil, cancelButtonTitle: "OK").show() UIAlertView(title: nil, message: "Error 2", delegate: nil, cancelButtonTitle: "OK").show()