diff --git a/Riot/Managers/LocalAuthentication/LocalAuthenticationService.swift b/Riot/Managers/LocalAuthentication/LocalAuthenticationService.swift index 6ac05a910..247d75dd3 100644 --- a/Riot/Managers/LocalAuthentication/LocalAuthenticationService.swift +++ b/Riot/Managers/LocalAuthentication/LocalAuthenticationService.swift @@ -17,6 +17,8 @@ import Foundation +// bwi: sexucity fix: lastActiveTime is now set by AppDelegate and only when state pinUnLocked is reached + @objcMembers class LocalAuthenticationService: NSObject { @@ -41,7 +43,6 @@ class LocalAuthenticationService: NSObject { } private func setup() { - NotificationCenter.default.addObserver(self, selector: #selector(applicationWillResignActive), name: UIApplication.willResignActiveNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(biometricsDidFallbackToPin), name: .biometricsDidFallbackToPin, object: nil) } @@ -61,8 +62,8 @@ class LocalAuthenticationService: NSObject { var isProtectionSet: Bool { return pinCodePreferences.isPinSet || pinCodePreferences.isBiometricsSet } - - func applicationWillResignActive() { + + func setLastActiveTime() { appLastActiveTime = systemUptime } diff --git a/Riot/Modules/Application/LegacyAppDelegate.m b/Riot/Modules/Application/LegacyAppDelegate.m index b5b054dfd..b290153b5 100644 --- a/Riot/Modules/Application/LegacyAppDelegate.m +++ b/Riot/Modules/Application/LegacyAppDelegate.m @@ -258,6 +258,8 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni */ @property (nonatomic, assign, getter=isClearingCache) BOOL clearingCache; + +@property (nonatomic, assign) BOOL isPinUnlocked; @end @implementation LegacyAppDelegate @@ -572,6 +574,10 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni self.setPinCoordinatorBridgePresenter.delegate = self; [self.setPinCoordinatorBridgePresenter presentWithMainAppWindow:self.window]; } + + if (self.isPinUnlocked) { + [self.localAuthenticationService setLastActiveTime]; + } } - (void)applicationDidEnterBackground:(UIApplication *)application @@ -657,6 +663,7 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni } if (createIfRequired) { + self.isPinUnlocked = false; self.setPinCoordinatorBridgePresenter = [[SetPinCoordinatorBridgePresenter alloc] initWithSession:mxSessionArray.firstObject viewMode:SetPinCoordinatorViewModeUnlock]; self.setPinCoordinatorBridgePresenter.delegate = self; [self.setPinCoordinatorBridgePresenter presentWithMainAppWindow:self.window]; @@ -762,6 +769,8 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni [BWIAnalytics.sharedTracker trackEvent:@"Session" action:@"PinLogin"]; + + self.isPinUnlocked = true; [_masterTabBarController bwiOnUnlockedByPin]; [self.delegate legacyAppDelegateDidUnlockPin:self]; diff --git a/Riot/Modules/SetPinCode/SetupBiometrics/SetupBiometricsViewModel.swift b/Riot/Modules/SetPinCode/SetupBiometrics/SetupBiometricsViewModel.swift index fe65d1371..55272c3fb 100644 --- a/Riot/Modules/SetPinCode/SetupBiometrics/SetupBiometricsViewModel.swift +++ b/Riot/Modules/SetPinCode/SetupBiometrics/SetupBiometricsViewModel.swift @@ -105,6 +105,7 @@ final class SetupBiometricsViewModel: SetupBiometricsViewModelType { // biometrics can't be used until further unlock with pin or a new log in self.pinCodePreferences.canUseBiometricsToUnlock = false self.coordinatorDelegate?.setupBiometricsViewModelDidCompleteWithReset(self, dueToTooManyErrors: true) + self.userCancelledUnlockWithBiometrics() } else if nsError.code == LAError.Code.userCancel.rawValue || nsError.code == LAError.Code.userFallback.rawValue { self.userCancelledUnlockWithBiometrics() } else {