|
|
|
@ -36,6 +36,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
@property (nonatomic, nullable) NSDate *lastUnlockAttemptDate;
|
|
|
|
|
@property (nonatomic, nullable) NSDate *lastUnlockSuccessDate;
|
|
|
|
|
|
|
|
|
|
@property (nonatomic, nullable) NSTimer *inactiveTimer;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
@ -116,8 +118,27 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
- (void)setAppIsInactive:(BOOL)appIsInactive
|
|
|
|
|
{
|
|
|
|
|
BOOL didChange = _appIsInactive != appIsInactive;
|
|
|
|
|
|
|
|
|
|
_appIsInactive = appIsInactive;
|
|
|
|
|
|
|
|
|
|
if (didChange) {
|
|
|
|
|
// If app is inactive for more than N seconds,
|
|
|
|
|
// treat this as "entering the background" for the purposes
|
|
|
|
|
// of Screen Lock.
|
|
|
|
|
if (!appIsInactive) {
|
|
|
|
|
[self.inactiveTimer invalidate];
|
|
|
|
|
self.inactiveTimer = nil;
|
|
|
|
|
} else if (!self.isShowingScreenLockUI) {
|
|
|
|
|
[self.inactiveTimer invalidate];
|
|
|
|
|
self.inactiveTimer = [NSTimer weakScheduledTimerWithTimeInterval:45.f
|
|
|
|
|
target:self
|
|
|
|
|
selector:@selector(inactiveTimerDidFire)
|
|
|
|
|
userInfo:nil
|
|
|
|
|
repeats:NO];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self ensureScreenProtection];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -125,10 +146,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
{
|
|
|
|
|
if (appIsInBackground) {
|
|
|
|
|
if (!_appIsInBackground) {
|
|
|
|
|
// Record the time when app entered background.
|
|
|
|
|
self.appEnteredBackgroundDate = [NSDate new];
|
|
|
|
|
|
|
|
|
|
self.didLastUnlockAttemptFail = NO;
|
|
|
|
|
[self markAppAsInBackground];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -137,6 +155,17 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
[self ensureScreenProtection];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)markAppAsInBackground
|
|
|
|
|
{
|
|
|
|
|
// Record the time when app entered background.
|
|
|
|
|
self.appEnteredBackgroundDate = [NSDate new];
|
|
|
|
|
|
|
|
|
|
self.didLastUnlockAttemptFail = NO;
|
|
|
|
|
|
|
|
|
|
[self.inactiveTimer invalidate];
|
|
|
|
|
self.inactiveTimer = nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)ensureScreenProtection
|
|
|
|
|
{
|
|
|
|
|
OWSAssertIsOnMainThread();
|
|
|
|
@ -514,6 +543,11 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
self.appIsInBackground = YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)inactiveTimerDidFire
|
|
|
|
|
{
|
|
|
|
|
[self markAppAsInBackground];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|
|
|
|
|