From c46021f19f1f7605c3ba02ec830a63075bd114be Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 4 Apr 2018 10:07:40 -0400 Subject: [PATCH] Fix screen lock edge case. --- Signal/src/util/OWSScreenLockUI.m | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Signal/src/util/OWSScreenLockUI.m b/Signal/src/util/OWSScreenLockUI.m index d8ef8c844..1a298cd41 100644 --- a/Signal/src/util/OWSScreenLockUI.m +++ b/Signal/src/util/OWSScreenLockUI.m @@ -33,7 +33,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, nullable) NSDate *appEnteredBackgroundDate; @property (nonatomic, nullable) NSDate *appEnteredForegroundDate; -@property (nonatomic, nullable) NSDate *lastUnlockAttemptDate; @property (nonatomic, nullable) NSDate *lastUnlockSuccessDate; @property (nonatomic, nullable) NSTimer *inactiveTimer; @@ -158,7 +157,23 @@ NS_ASSUME_NONNULL_BEGIN - (void)markAppAsInBackground { // Record the time when app entered background. - self.appEnteredBackgroundDate = [NSDate new]; + BOOL shouldResetEnteredBackgroundDate = NO; + if (!self.appEnteredBackgroundDate) { + // If this is the first time we're entering the + // background, record the date. + shouldResetEnteredBackgroundDate = YES; + } + if (self.hasUnlockedScreenLock) { + // If we've unlocked the screen lock, record the date. + shouldResetEnteredBackgroundDate = YES; + } else { + // If we're returning to the background _without_ + // having unlocked the screen lock, DO NOT update this + // value as that would reset the unlock timeout. + } + if (shouldResetEnteredBackgroundDate) { + self.appEnteredBackgroundDate = [NSDate new]; + } self.didLastUnlockAttemptFail = NO; @@ -214,7 +229,6 @@ NS_ASSUME_NONNULL_BEGIN DDLogInfo(@"%@, try to unlock screen lock", self.logTag); self.isShowingScreenLockUI = YES; - self.lastUnlockAttemptDate = [NSDate new]; [OWSScreenLock.sharedManager tryToUnlockScreenLockWithSuccess:^{ DDLogInfo(@"%@ unlock screen lock succeeded.", self.logTag); @@ -531,7 +545,6 @@ NS_ASSUME_NONNULL_BEGIN // Clear the "delay Screen Lock UI" state; we don't want any // delays when presenting the "unlock screen lock UI" after // returning from background. - self.lastUnlockAttemptDate = nil; self.lastUnlockSuccessDate = nil; self.appIsInBackground = NO;