|
|
@ -13,6 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
// updated conservatively, e.g. the flag is cleared during
|
|
|
|
// updated conservatively, e.g. the flag is cleared during
|
|
|
|
// "will enter background."
|
|
|
|
// "will enter background."
|
|
|
|
@property (nonatomic) BOOL appIsInactive;
|
|
|
|
@property (nonatomic) BOOL appIsInactive;
|
|
|
|
|
|
|
|
@property (nonatomic) BOOL appIsInBackground;
|
|
|
|
@property (nonatomic, nullable) NSDate *appBecameInactiveDate;
|
|
|
|
@property (nonatomic, nullable) NSDate *appBecameInactiveDate;
|
|
|
|
@property (nonatomic) UIWindow *screenBlockingWindow;
|
|
|
|
@property (nonatomic) UIWindow *screenBlockingWindow;
|
|
|
|
@property (nonatomic) BOOL hasUnlockedScreenLock;
|
|
|
|
@property (nonatomic) BOOL hasUnlockedScreenLock;
|
|
|
@ -64,6 +65,14 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
selector:@selector(applicationWillResignActive:)
|
|
|
|
selector:@selector(applicationWillResignActive:)
|
|
|
|
name:OWSApplicationWillResignActiveNotification
|
|
|
|
name:OWSApplicationWillResignActiveNotification
|
|
|
|
object:nil];
|
|
|
|
object:nil];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
|
|
|
selector:@selector(applicationWillEnterForeground:)
|
|
|
|
|
|
|
|
name:OWSApplicationWillEnterForegroundNotification
|
|
|
|
|
|
|
|
object:nil];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
|
|
|
selector:@selector(applicationDidEnterBackground:)
|
|
|
|
|
|
|
|
name:OWSApplicationDidEnterBackgroundNotification
|
|
|
|
|
|
|
|
object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(registrationStateDidChange)
|
|
|
|
selector:@selector(registrationStateDidChange)
|
|
|
|
name:RegistrationStateDidChangeNotification
|
|
|
|
name:RegistrationStateDidChangeNotification
|
|
|
@ -105,6 +114,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
[self ensureScreenProtection];
|
|
|
|
[self ensureScreenProtection];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)setAppIsInBackground:(BOOL)appIsInBackground
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_appIsInBackground = appIsInBackground;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[self ensureScreenProtection];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void)ensureScreenProtection
|
|
|
|
- (void)ensureScreenProtection
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSAssertIsOnMainThread();
|
|
|
|
OWSAssertIsOnMainThread();
|
|
|
@ -123,12 +139,14 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
// Don't show 'Screen Lock' if 'Screen Lock' isn't enabled.
|
|
|
|
// Don't show 'Screen Lock' if 'Screen Lock' isn't enabled.
|
|
|
|
} else if (self.hasUnlockedScreenLock) {
|
|
|
|
} else if (self.hasUnlockedScreenLock) {
|
|
|
|
// Don't show 'Screen Lock' if 'Screen Lock' has been unlocked.
|
|
|
|
// Don't show 'Screen Lock' if 'Screen Lock' has been unlocked.
|
|
|
|
|
|
|
|
} else if (self.appIsInBackground) {
|
|
|
|
|
|
|
|
// Don't show 'Screen Lock' if app is in background.
|
|
|
|
|
|
|
|
} else if (self.appIsInactive) {
|
|
|
|
|
|
|
|
// Don't show 'Screen Lock' if app is inactive.
|
|
|
|
} else if (!self.appBecameInactiveDate) {
|
|
|
|
} else if (!self.appBecameInactiveDate) {
|
|
|
|
// Show 'Screen Lock' if app hasn't become inactive yet (just launched).
|
|
|
|
// Show 'Screen Lock' if app has just launched.
|
|
|
|
shouldHaveScreenLock = YES;
|
|
|
|
shouldHaveScreenLock = YES;
|
|
|
|
DDLogVerbose(@"%@, shouldHaveScreenLock 2: %d", self.logTag, self.appIsInactive);
|
|
|
|
DDLogVerbose(@"%@, shouldHaveScreenLock 2: %d", self.logTag, self.appIsInBackground);
|
|
|
|
} else if (!self.appIsInactive) {
|
|
|
|
|
|
|
|
// Don't show 'Screen Lock' if app is inactive.
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
OWSAssert(self.appBecameInactiveDate);
|
|
|
|
OWSAssert(self.appBecameInactiveDate);
|
|
|
|
|
|
|
|
|
|
|
@ -136,13 +154,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
NSTimeInterval screenLockTimeout = OWSScreenLock.sharedManager.screenLockTimeout;
|
|
|
|
NSTimeInterval screenLockTimeout = OWSScreenLock.sharedManager.screenLockTimeout;
|
|
|
|
OWSAssert(screenLockInterval >= 0);
|
|
|
|
OWSAssert(screenLockInterval >= 0);
|
|
|
|
OWSAssert(screenLockTimeout >= 0);
|
|
|
|
OWSAssert(screenLockTimeout >= 0);
|
|
|
|
if (self.appBecameInactiveDate && screenLockInterval < screenLockTimeout) {
|
|
|
|
if (screenLockInterval < screenLockTimeout) {
|
|
|
|
// Don't show 'Screen Lock' if 'Screen Lock' timeout hasn't elapsed.
|
|
|
|
// Don't show 'Screen Lock' if 'Screen Lock' timeout hasn't elapsed.
|
|
|
|
shouldHaveScreenLock = NO;
|
|
|
|
shouldHaveScreenLock = NO;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Otherwise, show 'Screen Lock'.
|
|
|
|
// Otherwise, show 'Screen Lock'.
|
|
|
|
shouldHaveScreenLock = YES;
|
|
|
|
shouldHaveScreenLock = YES;
|
|
|
|
DDLogVerbose(@"%@, shouldHaveScreenLock 1: %d", self.logTag, self.appIsInactive);
|
|
|
|
DDLogVerbose(@"%@, shouldHaveScreenLock 1: %d", self.logTag, self.appIsInBackground);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -248,6 +266,16 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
self.appIsInactive = YES;
|
|
|
|
self.appIsInactive = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)applicationWillEnterForeground:(NSNotification *)notification
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
self.appIsInBackground = NO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)applicationDidEnterBackground:(NSNotification *)notification
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
self.appIsInBackground = YES;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|
|
|
|
NS_ASSUME_NONNULL_END
|
|
|
|