Skip to content

armgit / ente

Public Imported from GitHub
0

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

Consolidate lock screen settings

vishnukvmd33a64c9887d8
diff --git a/auth/lib/core/configuration.dart b/auth/lib/core/configuration.dart
index 7264ff6863..7ba6fa4922 100644
--- a/auth/lib/core/configuration.dart
+++ b/auth/lib/core/configuration.dart
@@ -14,7 +14,6 @@ import 'package:ente_auth/models/key_gen_result.dart';
import 'package:ente_auth/models/private_key_attributes.dart';
import 'package:ente_auth/store/authenticator_db.dart';
import 'package:ente_auth/utils/directory_utils.dart';
-import 'package:ente_auth/utils/lock_screen_settings.dart';
import 'package:ente_crypto_dart/ente_crypto_dart.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:logging/logging.dart';
@@ -33,7 +32,6 @@ class Configuration {
static const emailKey = "email";
static const keyAttributesKey = "key_attributes";
- static const keyShouldShowLockScreen = "should_show_lock_screen";
static const lastTempFolderClearTimeKey = "last_temp_folder_clear_time";
static const keyKey = "key";
static const secretKeyKey = "secret_key";
@@ -133,7 +131,6 @@ class Configuration {
key: key,
);
}
- await LockScreenSettings.instance.removePinAndPassword();
await AuthenticatorDB.instance.clearTable();
_key = null;
_cachedToken = null;
@@ -468,24 +465,6 @@ class Configuration {
await _preferences.setBool(hasOptedForOfflineModeKey, true);
}
- Future<bool> shouldShowLockScreen() async {
- final bool isPin = await LockScreenSettings.instance.isPinSet();
- final bool isPass = await LockScreenSettings.instance.isPasswordSet();
- return isPin || isPass || shouldShowSystemLockScreen();
- }
-
- bool shouldShowSystemLockScreen() {
- if (_preferences.containsKey(keyShouldShowLockScreen)) {
- return _preferences.getBool(keyShouldShowLockScreen)!;
- } else {
- return false;
- }
- }
-
- Future<void> setSystemLockScreen(bool value) {
- return _preferences.setBool(keyShouldShowLockScreen, value);
- }
-
void setVolatilePassword(String volatilePassword) {
_volatilePassword = volatilePassword;
}
diff --git a/auth/lib/main.dart b/auth/lib/main.dart
index 03eb2846d3..b0adde52fa 100644
--- a/auth/lib/main.dart
+++ b/auth/lib/main.dart
@@ -103,7 +103,7 @@ Future<void> _runInForeground() async {
AppLock(
builder: (args) => App(locale: locale),
lockScreen: const LockScreen(),
- enabled: await Configuration.instance.shouldShowLockScreen(),
+ enabled: await LockScreenSettings.instance.shouldShowLockScreen(),
locale: locale,
lightTheme: lightThemeData,
darkTheme: darkThemeData,
diff --git a/auth/lib/services/local_authentication_service.dart b/auth/lib/services/local_authentication_service.dart
index 02c609591d..1502b2a36e 100644
--- a/auth/lib/services/local_authentication_service.dart
+++ b/auth/lib/services/local_authentication_service.dart
@@ -1,6 +1,5 @@
import 'dart:io';
-import 'package:ente_auth/core/configuration.dart';
import 'package:ente_auth/ui/settings/lock_screen/lock_screen_password.dart';
import 'package:ente_auth/ui/settings/lock_screen/lock_screen_pin.dart';
import 'package:ente_auth/ui/tools/app_lock.dart';
@@ -42,7 +41,7 @@ class LocalAuthenticationService {
isAuthenticatingForInAppChange: true,
);
AppLock.of(context)!.setEnabled(
- await Configuration.instance.shouldShowLockScreen(),
+ await LockScreenSettings.instance.shouldShowLockScreen(),
);
if (!result) {
showToast(context, infoMessage);
@@ -114,12 +113,13 @@ class LocalAuthenticationService {
);
if (result) {
AppLock.of(context)!.setEnabled(shouldEnableLockScreen);
- await Configuration.instance
+ await LockScreenSettings.instance
.setSystemLockScreen(shouldEnableLockScreen);
return true;
} else {
- AppLock.of(context)!
- .setEnabled(await Configuration.instance.shouldShowLockScreen());
+ AppLock.of(context)!.setEnabled(
+ await LockScreenSettings.instance.shouldShowLockScreen(),
+ );
}
} else {
// ignore: unawaited_futures
diff --git a/auth/lib/ui/home_page.dart b/auth/lib/ui/home_page.dart
index cd522b7746..3a3d650259 100644
--- a/auth/lib/ui/home_page.dart
+++ b/auth/lib/ui/home_page.dart
@@ -319,7 +319,7 @@ class _HomePageState extends State<HomePage> {
Future<void> navigateToLockScreen() async {
final bool shouldShowLockScreen =
- await Configuration.instance.shouldShowLockScreen();
+ await LockScreenSettings.instance.shouldShowLockScreen();
if (shouldShowLockScreen) {
await AppLock.of(context)!.showLockScreen();
} else {
diff --git a/auth/lib/ui/settings/lock_screen/lock_screen_options.dart b/auth/lib/ui/settings/lock_screen/lock_screen_options.dart
index 9f53f10248..e8065fb373 100644
--- a/auth/lib/ui/settings/lock_screen/lock_screen_options.dart
+++ b/auth/lib/ui/settings/lock_screen/lock_screen_options.dart
@@ -1,7 +1,6 @@
import "dart:async";
import "dart:io";
-import "package:ente_auth/core/configuration.dart";
import "package:ente_auth/l10n/l10n.dart";
import "package:ente_auth/services/local_authentication_service.dart";
import "package:ente_auth/theme/ente_theme.dart";
@@ -31,8 +30,7 @@ class LockScreenOptions extends StatefulWidget {
}
class _LockScreenOptionsState extends State<LockScreenOptions> {
- final Configuration _configuration = Configuration.instance;
- final LockScreenSettings _lockscreenSetting = LockScreenSettings.instance;
+ final LockScreenSettings _lockScreenSetting = LockScreenSettings.instance;
late bool appLock = false;
bool isPinEnabled = false;
bool isPasswordEnabled = false;
@@ -43,18 +41,18 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
@override
void initState() {
super.initState();
- hideAppContent = _lockscreenSetting.getShouldHideAppContent();
- autoLockTimeInMilliseconds = _lockscreenSetting.getAutoLockTime();
+ hideAppContent = _lockScreenSetting.getShouldHideAppContent();
+ autoLockTimeInMilliseconds = _lockScreenSetting.getAutoLockTime();
_initializeSettings();
- appLock = _lockscreenSetting.getIsAppLockSet();
+ appLock = _lockScreenSetting.getIsAppLockSet();
}
Future<void> _initializeSettings() async {
- final bool passwordEnabled = await _lockscreenSetting.isPasswordSet();
- final bool pinEnabled = await _lockscreenSetting.isPinSet();
+ final bool passwordEnabled = await _lockScreenSetting.isPasswordSet();
+ final bool pinEnabled = await _lockScreenSetting.isPinSet();
final bool shouldHideAppContent =
- _lockscreenSetting.getShouldHideAppContent();
- final bool systemLockEnabled = _configuration.shouldShowSystemLockScreen();
+ _lockScreenSetting.getShouldHideAppContent();
+ final bool systemLockEnabled = _lockScreenSetting.shouldShowSystemLockScreen();
setState(() {
isPasswordEnabled = passwordEnabled;
isPinEnabled = pinEnabled;
@@ -66,8 +64,8 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
Future<void> _deviceLock() async {
if (await LocalAuthenticationService.instance
.isLocalAuthSupportedOnDevice()) {
- await _lockscreenSetting.removePinAndPassword();
- await _configuration.setSystemLockScreen(!isSystemLockEnabled);
+ await _lockScreenSetting.removePinAndPassword();
+ await _lockScreenSetting.setSystemLockScreen(!isSystemLockEnabled);
} else {
await showDialogWidget(
context: context,
@@ -96,10 +94,10 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
);
if (result) {
- await _configuration.setSystemLockScreen(false);
- await _lockscreenSetting.setAppLockEnabled(true);
+ await _lockScreenSetting.setSystemLockScreen(false);
+ await _lockScreenSetting.setAppLockEnabled(true);
setState(() {
- appLock = _lockscreenSetting.getIsAppLockSet();
+ appLock = _lockScreenSetting.getIsAppLockSet();
});
}
await _initializeSettings();
@@ -114,9 +112,9 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
),
);
if (result) {
- await _configuration.setSystemLockScreen(false);
+ await _lockScreenSetting.setSystemLockScreen(false);
setState(() {
- appLock = _lockscreenSetting.getIsAppLockSet();
+ appLock = _lockScreenSetting.getIsAppLockSet();
});
}
await _initializeSettings();
@@ -126,17 +124,17 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
AppLock.of(context)!.setEnabled(!appLock);
if (await LocalAuthenticationService.instance
.isLocalAuthSupportedOnDevice()) {
- await _configuration.setSystemLockScreen(!appLock);
- await _lockscreenSetting.setAppLockEnabled(!appLock);
+ await _lockScreenSetting.setSystemLockScreen(!appLock);
+ await _lockScreenSetting.setAppLockEnabled(!appLock);
} else {
- await _configuration.setSystemLockScreen(false);
- await _lockscreenSetting.setAppLockEnabled(false);
+ await _lockScreenSetting.setSystemLockScreen(false);
+ await _lockScreenSetting.setAppLockEnabled(false);
}
- await _lockscreenSetting.removePinAndPassword();
+ await _lockScreenSetting.removePinAndPassword();
if (PlatformUtil.isMobile()) {
- await _lockscreenSetting.setHideAppContent(!appLock);
+ await _lockScreenSetting.setHideAppContent(!appLock);
setState(() {
- hideAppContent = _lockscreenSetting.getShouldHideAppContent();
+ hideAppContent = _lockScreenSetting.getShouldHideAppContent();
});
}
await _initializeSettings();
@@ -152,7 +150,7 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
).then(
(value) {
setState(() {
- autoLockTimeInMilliseconds = _lockscreenSetting.getAutoLockTime();
+ autoLockTimeInMilliseconds = _lockScreenSetting.getAutoLockTime();
});
},
);
@@ -162,7 +160,7 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
setState(() {
hideAppContent = !hideAppContent;
});
- await _lockscreenSetting.setHideAppContent(hideAppContent);
+ await _lockScreenSetting.setHideAppContent(hideAppContent);
}
String _formatTime(Duration duration) {
diff --git a/auth/lib/ui/settings/security_section_widget.dart b/auth/lib/ui/settings/security_section_widget.dart
index 41b04c80b5..dab16cb56f 100644
--- a/auth/lib/ui/settings/security_section_widget.dart
+++ b/auth/lib/ui/settings/security_section_widget.dart
@@ -166,7 +166,7 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
return;
}
}
- if (await Configuration.instance.shouldShowLockScreen()) {
+ if (await LockScreenSettings.instance.shouldShowLockScreen()) {
final bool result = await requestAuthentication(
context,
context.l10n.authToChangeLockscreenSetting,
diff --git a/auth/lib/utils/lock_screen_settings.dart b/auth/lib/utils/lock_screen_settings.dart
index b87323e37d..247f7ae4b2 100644
--- a/auth/lib/utils/lock_screen_settings.dart
+++ b/auth/lib/utils/lock_screen_settings.dart
@@ -3,6 +3,8 @@ import "dart:io";
import "dart:typed_data";
import "package:ente_auth/core/configuration.dart";
+import "package:ente_auth/core/event_bus.dart";
+import "package:ente_auth/events/signed_out_event.dart";
import "package:ente_auth/utils/platform_util.dart";
import "package:ente_crypto_dart/ente_crypto_dart.dart";
import "package:flutter/material.dart";
@@ -26,6 +28,7 @@ class LockScreenSettings {
static const keyHasMigratedLockScreenChanges =
"ls_has_migrated_lock_screen_changes";
static const keyShowOfflineModeWarning = "ls_show_offline_mode_warning";
+ static const keyShouldShowLockScreen = "should_show_lock_screen";
static const String kIsLightMode = "is_light_mode";
final List<Duration> autoLockDurations = const [
@@ -52,6 +55,10 @@ class LockScreenSettings {
await runLockScreenChangesMigration();
await _clearLsDataInKeychainIfFreshInstall();
+
+ Bus.instance.on<SignedOutEvent>().listen((event) {
+ removePinAndPassword();
+ });
}
Future<void> setOfflineModeWarningStatus(bool value) async {
@@ -69,8 +76,7 @@ class LockScreenSettings {
final bool passwordEnabled = await isPasswordSet();
final bool pinEnabled = await isPinSet();
- final bool systemLockEnabled =
- Configuration.instance.shouldShowSystemLockScreen();
+ final bool systemLockEnabled = shouldShowSystemLockScreen();
if (passwordEnabled || pinEnabled || systemLockEnabled) {
await setAppLockEnabled(true);
@@ -214,6 +220,24 @@ class LockScreenSettings {
return await _secureStorage.containsKey(key: password);
}
+ Future<bool> shouldShowLockScreen() async {
+ final bool isPin = await isPinSet();
+ final bool isPass = await isPasswordSet();
+ return isPin || isPass || shouldShowSystemLockScreen();
+ }
+
+ bool shouldShowSystemLockScreen() {
+ if (_preferences.containsKey(keyShouldShowLockScreen)) {
+ return _preferences.getBool(keyShouldShowLockScreen)!;
+ } else {
+ return false;
+ }
+ }
+
+ Future<void> setSystemLockScreen(bool value) {
+ return _preferences.setBool(keyShouldShowLockScreen, value);
+ }
+
// If the app was uninstalled (without logging out if it was used with
// backups), keychain items of the app persist in the keychain. To avoid using
// old keychain items, we delete them on reinstall.