From 2b09f044f5e850e7d04f670ee4954450f6e3e2d2 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 27 Oct 2023 11:26:08 +0530 Subject: [PATCH 1/3] Log the source of lockScreen trigger Signed-off-by: Neeraj Gupta <254676+ua741@users.noreply.github.com> --- lib/ui/tools/lock_screen.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ui/tools/lock_screen.dart b/lib/ui/tools/lock_screen.dart index 4aad64efe..fba6e6fc3 100644 --- a/lib/ui/tools/lock_screen.dart +++ b/lib/ui/tools/lock_screen.dart @@ -21,7 +21,7 @@ class _LockScreenState extends State with WidgetsBindingObserver { @override void initState() { _logger.info("initState"); - _showLockScreen(); + _showLockScreen(source: "initState"); WidgetsBinding.instance.addObserver(this); super.initState(); } @@ -47,7 +47,7 @@ class _LockScreenState extends State with WidgetsBindingObserver { text: S.of(context).unlock, iconData: Icons.lock_open_outlined, onTap: () async { - _showLockScreen(); + _showLockScreen(source: "tapUnlock"); }, ), ), @@ -69,7 +69,7 @@ class _LockScreenState extends State with WidgetsBindingObserver { if (!_hasAuthenticationFailed) { // Show the lock screen again only if the app is resuming from the // background, and not when the lock screen was explicitly dismissed - _showLockScreen(); + _showLockScreen(source: "lifeCycle"); } else { _hasAuthenticationFailed = false; // Reset failure state } @@ -90,8 +90,8 @@ class _LockScreenState extends State with WidgetsBindingObserver { super.dispose(); } - Future _showLockScreen() async { - _logger.info("Showing lock screen"); + Future _showLockScreen({String source = ''}) async { + _logger.info("Showing lock screen $source"); try { _isShowingLockScreen = true; final result = await requestAuthentication( From 0c73d17347679f6bcfc722eb69346415c47981c1 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 27 Oct 2023 11:27:03 +0530 Subject: [PATCH 2/3] Skip lifeCycle lockscreen if auth in last 5seconds Signed-off-by: Neeraj Gupta <254676+ua741@users.noreply.github.com> --- lib/ui/tools/lock_screen.dart | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ui/tools/lock_screen.dart b/lib/ui/tools/lock_screen.dart index fba6e6fc3..ae5d92ed3 100644 --- a/lib/ui/tools/lock_screen.dart +++ b/lib/ui/tools/lock_screen.dart @@ -17,6 +17,7 @@ class _LockScreenState extends State with WidgetsBindingObserver { bool _isShowingLockScreen = false; bool _hasPlacedAppInBackground = false; bool _hasAuthenticationFailed = false; + int? lastAuthenticatingTime; @override void initState() { @@ -66,7 +67,10 @@ class _LockScreenState extends State with WidgetsBindingObserver { // This is triggered either when the lock screen is dismissed or when // the app is brought to foreground _hasPlacedAppInBackground = false; - if (!_hasAuthenticationFailed) { + final bool didAuthInLast5Seconds = lastAuthenticatingTime != null && + DateTime.now().millisecondsSinceEpoch - lastAuthenticatingTime! < + 5000; + if (!_hasAuthenticationFailed && !didAuthInLast5Seconds) { // Show the lock screen again only if the app is resuming from the // background, and not when the lock screen was explicitly dismissed _showLockScreen(source: "lifeCycle"); @@ -100,6 +104,7 @@ class _LockScreenState extends State with WidgetsBindingObserver { ); _isShowingLockScreen = false; if (result) { + lastAuthenticatingTime = DateTime.now().millisecondsSinceEpoch; AppLock.of(context)!.didUnlock(); } else { _logger.info("Dismissed"); From 925c640eee6aabf940e498c08557a5ceb5b5e866 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Tue, 31 Oct 2023 06:38:10 +0530 Subject: [PATCH 3/3] Fix: Order for LockScreen init Signed-off-by: Neeraj Gupta <254676+ua741@users.noreply.github.com> --- lib/ui/tools/lock_screen.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ui/tools/lock_screen.dart b/lib/ui/tools/lock_screen.dart index ae5d92ed3..eb31be4d4 100644 --- a/lib/ui/tools/lock_screen.dart +++ b/lib/ui/tools/lock_screen.dart @@ -22,9 +22,11 @@ class _LockScreenState extends State with WidgetsBindingObserver { @override void initState() { _logger.info("initState"); - _showLockScreen(source: "initState"); - WidgetsBinding.instance.addObserver(this); super.initState(); + WidgetsBinding.instance.addObserver(this); + WidgetsBinding.instance!.addPostFrameCallback((_) { + _showLockScreen(source: "initState"); + }); } @override