Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add lockscreen fixes from photos

Neeraj Gupta03b1accfda02
diff --git a/lib/l10n/arb/app_en.arb b/lib/l10n/arb/app_en.arb
index 0e883b1c0a..b0d4a3244e 100644
--- a/lib/l10n/arb/app_en.arb
+++ b/lib/l10n/arb/app_en.arb
@@ -1,5 +1,6 @@
{
"account": "Account",
+ "unlock": "Unlock",
"recoveryKey": "Recovery key",
"counterAppBarTitle": "Counter",
"@counterAppBarTitle": {
@@ -97,6 +98,7 @@
"authToViewYourRecoveryKey": "Please authenticate to view your recovery key",
"authToChangeYourEmail": "Please authenticate to change your email",
"authToChangeYourPassword": "Please authenticate to change your password",
+ "authToViewSecrets": "Please authenticate to view your secrets",
"ok": "Ok",
"cancel": "Cancel",
"yes": "Yes",
diff --git a/lib/services/local_authentication_service.dart b/lib/services/local_authentication_service.dart
index f161bb89fa..d21d1bcb26 100644
--- a/lib/services/local_authentication_service.dart
+++ b/lib/services/local_authentication_service.dart
@@ -1,5 +1,3 @@
-
-
import 'package:ente_auth/core/configuration.dart';
import 'package:ente_auth/ui/tools/app_lock.dart';
import 'package:ente_auth/utils/auth_util.dart';
@@ -19,7 +17,7 @@ class LocalAuthenticationService {
) async {
if (await _isLocalAuthSupportedOnDevice()) {
AppLock.of(context)!.setEnabled(false);
- final result = await requestAuthentication(infoMessage);
+ final result = await requestAuthentication(context, infoMessage);
AppLock.of(context)!.setEnabled(
Configuration.instance.shouldShowLockScreen(),
);
@@ -43,6 +41,7 @@ class LocalAuthenticationService {
if (await LocalAuthentication().isDeviceSupported()) {
AppLock.of(context)!.disable();
final result = await requestAuthentication(
+ context,
infoMessage,
);
if (result) {
diff --git a/lib/ui/tools/lock_screen.dart b/lib/ui/tools/lock_screen.dart
index a1389fc4ec..dbd050c61b 100644
--- a/lib/ui/tools/lock_screen.dart
+++ b/lib/ui/tools/lock_screen.dart
@@ -1,5 +1,4 @@
-
-
+import 'package:ente_auth/l10n/l10n.dart';
import 'package:ente_auth/ui/common/gradient_button.dart';
import 'package:ente_auth/ui/tools/app_lock.dart';
import 'package:ente_auth/utils/auth_util.dart';
@@ -13,13 +12,19 @@ class LockScreen extends StatefulWidget {
State<LockScreen> createState() => _LockScreenState();
}
-class _LockScreenState extends State<LockScreen> {
+class _LockScreenState extends State<LockScreen> with WidgetsBindingObserver {
final _logger = Logger("LockScreen");
+ bool _isShowingLockScreen = false;
+ bool _hasPlacedAppInBackground = false;
+ bool _hasAuthenticationFailed = false;
+ int? lastAuthenticatingTime;
@override
void initState() {
- _showLockScreen();
+ _logger.info("initState");
super.initState();
+ _showLockScreen(source: "initState");
+ WidgetsBinding.instance.addObserver(this);
}
@override
@@ -34,16 +39,16 @@ class _LockScreenState extends State<LockScreen> {
alignment: Alignment.center,
children: [
Opacity(
- opacity: 0.3,
+ opacity: 0.2,
child: Image.asset('assets/loading_photos_background.png'),
),
SizedBox(
- width: 142,
+ width: 180,
child: GradientButton(
- text: "Unlock",
+ text: context.l10n.unlock,
iconData: Icons.lock_open_outlined,
onTap: () async {
- _showLockScreen();
+ _showLockScreen(source: "tapUnlock");
},
),
),
@@ -55,14 +60,61 @@ class _LockScreenState extends State<LockScreen> {
);
}
- Future<void> _showLockScreen() async {
- _logger.info("Showing lockscreen");
+ @override
+ void didChangeAppLifecycleState(AppLifecycleState state) {
+ _logger.info(state.toString());
+ if (state == AppLifecycleState.resumed && !_isShowingLockScreen) {
+ // This is triggered either when the lock screen is dismissed or when
+ // the app is brought to foreground
+ _hasPlacedAppInBackground = false;
+ 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");
+ } else {
+ _hasAuthenticationFailed = false; // Reset failure state
+ }
+ } else if (state == AppLifecycleState.paused ||
+ state == AppLifecycleState.inactive) {
+ // This is triggered either when the lock screen pops up or when
+ // the app is pushed to background
+ if (!_isShowingLockScreen) {
+ _hasPlacedAppInBackground = true;
+ _hasAuthenticationFailed = false; // reset failure state
+ }
+ }
+ }
+
+ @override
+ void dispose() {
+ WidgetsBinding.instance.removeObserver(this);
+ super.dispose();
+ }
+
+ Future<void> _showLockScreen({String source = ''}) async {
+ final int id = DateTime.now().millisecondsSinceEpoch;
+ _logger.info("Showing lock screen $source $id");
try {
+ _isShowingLockScreen = true;
final result = await requestAuthentication(
- "Please authenticate to view your secrets",
+ context,
+ context.l10n.authToViewSecrets,
);
+ _logger.finest("LockScreen Result $result $id");
+ _isShowingLockScreen = false;
if (result) {
+ lastAuthenticatingTime = DateTime.now().millisecondsSinceEpoch;
AppLock.of(context)!.didUnlock();
+ } else {
+ if (!_hasPlacedAppInBackground) {
+ // Treat this as a failure only if user did not explicitly
+ // put the app in background
+ _hasAuthenticationFailed = true;
+ _logger.info("Authentication failed");
+ }
}
} catch (e, s) {
_logger.severe(e, s);
diff --git a/lib/utils/auth_util.dart b/lib/utils/auth_util.dart
index 77f9732041..4726d7c842 100644
--- a/lib/utils/auth_util.dart
+++ b/lib/utils/auth_util.dart
@@ -1,8 +1,9 @@
+import 'package:flutter/cupertino.dart';
import 'package:local_auth/local_auth.dart';
import 'package:local_auth_android/local_auth_android.dart';
import 'package:logging/logging.dart';
-Future<bool> requestAuthentication(String reason) async {
+Future<bool> requestAuthentication(BuildContext context, String reason) async {
Logger("AuthUtil").info("Requesting authentication");
await LocalAuthentication().stopAuthentication();
return await LocalAuthentication().authenticate(