     }
     
     open func applicationWillEnterForeground(_ application: UIApplication) {
-        lockScreen()
+        if shouldShowPasscode(),
+            let backgroundDuration = self.backgroundTimestamp?.timeIntervalSinceNow,
+            abs(backgroundDuration) > backgroundTimeout {
+            lockScreen()
+        }
     }
     
     open func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {

        return true
    }
    
    open func applicationWillResignActive(_ application: UIApplication) {
        if shouldShowPasscode() {
            // Hide content so it doesn't appear in the app switcher.
            rootViewController?.contentHidden = true
        }
        
        // Save any outstanding clientData profile item updates to Bridge.
        SBAClientDataProfileItem.updateChangesToBridge()
    }

    open func presentViewController(_ viewController: UIViewController, animated: Bool, completion: (() -> Void)?) {
        guard let rootVC = self.window?.rootViewController else { return }
        var topViewController: UIViewController = rootVC
        while let presentedVC = topViewController.presentedViewController {
            if presentedVC.modalPresentationStyle != .fullScreen {
                presentedVC.dismiss(animated: false, completion: nil)
                break
            }
            else {
                topViewController = presentedVC
            }
        }
        topViewController.present(viewController, animated: animated, completion: completion)
    }
