π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Improve local backup auth prompts and tooling
Prateek Sunal5b5ab96dd605
diff --git a/mobile/apps/auth/lib/onboarding/view/onboarding_page.dart b/mobile/apps/auth/lib/onboarding/view/onboarding_page.dartindex 434eb0ff10..880b732c07 100644--- a/mobile/apps/auth/lib/onboarding/view/onboarding_page.dart+++ b/mobile/apps/auth/lib/onboarding/view/onboarding_page.dart@@ -26,7 +26,6 @@ import 'package:ente_auth/utils/toast_util.dart';import 'package:ente_events/event_bus.dart';import 'package:flutter/material.dart';import 'package:flutter/rendering.dart';-import 'package:flutter/widgets.dart';import 'package:flutter_svg/flutter_svg.dart';import 'package:local_auth/local_auth.dart';diff --git a/mobile/apps/auth/lib/services/local_backup_service.dart b/mobile/apps/auth/lib/services/local_backup_service.dartindex 2b940b4bad..33e6ed4e73 100644--- a/mobile/apps/auth/lib/services/local_backup_service.dart+++ b/mobile/apps/auth/lib/services/local_backup_service.dart@@ -9,6 +9,7 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart';import 'package:intl/intl.dart';import 'package:logging/logging.dart';import 'package:saf_stream/saf_stream.dart';+import 'package:saf_util/saf_util.dart';import 'package:shared_preferences/shared_preferences.dart';class LocalBackupService {@@ -74,6 +75,7 @@ class LocalBackupService {try {if (target.treeUri != null) {await _writeBackupWithSaf(target.treeUri!, fileName, content);+ await _pruneSafBackups(target.treeUri!, limit: _maxBackups);return true;}@@ -108,6 +110,30 @@ class LocalBackupService {_logger.info('Automatic encrypted backup saved via SAF: $fileName');}+ Future<void> _pruneSafBackups(String treeUri, {required int limit}) async {+ try {+ final safUtil = SafUtil();+ final entries = await safUtil.list(treeUri);+ final backupFiles = entries+ .where((file) => !file.isDir && _isBackupFile(file.name))+ .toList();++ backupFiles.sort((a, b) {+ final timeCompare = a.lastModified.compareTo(b.lastModified);+ if (timeCompare != 0) return timeCompare;+ return a.name.compareTo(b.name);+ });++ while (backupFiles.length > limit) {+ final file = backupFiles.removeAt(0);+ await safUtil.delete(file.uri, file.isDir);+ _logger.info('Deleted old backup via SAF: ${file.name}');+ }+ } catch (e, s) {+ _logger.severe('Error pruning SAF backups', e, s);+ }+ }+Future<void> _manageOldBackups(String backupPath) async {try {final directory = Directory(backupPath);diff --git a/mobile/apps/auth/lib/ui/scanner_page.dart b/mobile/apps/auth/lib/ui/scanner_page.dartindex 6b4f85b329..59ec73a5d7 100644--- a/mobile/apps/auth/lib/ui/scanner_page.dart+++ b/mobile/apps/auth/lib/ui/scanner_page.dart@@ -53,9 +53,13 @@ class ScannerPageState extends State<ScannerPage> {final theme = Theme.of(context);final bool isLight = theme.brightness == Brightness.light;final Color galleryBackgroundColor =- isLight ? Colors.black.withOpacity(0.035) : Colors.white.withOpacity(0.18);+ isLight+ ? Colors.black.withValues(alpha: 0.035)+ : Colors.white.withValues(alpha: 0.18);final Color galleryPressedColor =- isLight ? Colors.black.withOpacity(0.07) : Colors.white.withOpacity(0.26);+ isLight+ ? Colors.black.withValues(alpha: 0.07)+ : Colors.white.withValues(alpha: 0.26);final Color galleryIconColor = isLight ? Colors.black : Colors.white;return Scaffold(appBar: AppBar(diff --git a/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart b/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dartindex a28e19b205..38e6271991 100644--- a/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart+++ b/mobile/apps/auth/lib/ui/settings/data/local_backup/local_backup_experience.dart@@ -60,6 +60,8 @@ class LocalBackupExperienceController {Future<bool> hasPasswordConfigured() => _state._hasStoredPassword();+ Future<bool> clearBackupPassword() => _state._clearBackupPassword();+String simplifyPath(String fullPath) => _state._simplifyPath(fullPath);void showSnackBar(String message) => _state._showSnackBar(message);@@ -140,9 +142,8 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {return false;}- final selected = await _handleLocationSetup();- if (!selected) {- _showSnackBar('Select a folder to continue');+ final hasLocation = await _ensureBackupLocationSelected();+ if (!hasLocation) {return false;}if (Platform.isAndroid &&@@ -229,7 +230,14 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {return true;}- Future<bool> _authenticateForBackupAction(String reason) async {+ Future<bool> _authenticateForBackupAction(+ String reason, {+ bool forceAuthPrompt = false,+ }) async {+ if (forceAuthPrompt) {+ // Reset cached auth window to force a fresh prompt for sensitive flows.+ LocalAuthenticationService.instance.lastAuthTime = 0;+ }return LocalAuthenticationService.instance.requestLocalAuthentication(context,reason,@@ -259,30 +267,33 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {}}- Future<bool> _updatePassword(BuildContext context) async {- // Request app lock authentication first- final hasAuthenticated =- await LocalAuthenticationService.instance.requestLocalAuthentication(- context,- 'Authenticate to update backup password',- );-- if (!hasAuthenticated) {- return false;- }-- return _promptPassword(- forcePrompt: true,- disableOnCancel: false,- isUpdateFlow: true,- );- }+ Future<bool> _updatePassword(BuildContext context) async =>+ _promptPassword(+ forcePrompt: true,+ disableOnCancel: false,+ isUpdateFlow: true,+ );Future<bool> _promptPassword({required bool forcePrompt,bool disableOnCancel = false,bool isUpdateFlow = false,}) async {+ final hasAuthenticated = await _authenticateForBackupAction(+ isUpdateFlow+ ? 'Authenticate to update backup password'+ : 'Authenticate to set backup password',+ forceAuthPrompt: true,+ );+ if (!hasAuthenticated) {+ if (disableOnCancel && mounted) {+ setState(() {+ _isBackupEnabled = false;+ });+ }+ return false;+ }+if (!forcePrompt) {final stored = await _readStoredPassword();if (stored != null && stored.isNotEmpty) {@@ -312,6 +323,16 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {return stored != null && stored.isNotEmpty;}+ Future<bool> _clearBackupPassword() async {+ if (_isBackupEnabled) {+ return false;+ }+ const storage = FlutterSecureStorage();+ await storage.delete(key: _passwordKey);+ _showSnackBar('Backup password cleared');+ return true;+ }+Future<String?> _readStoredPassword() async {const storage = FlutterSecureStorage();try {@@ -359,39 +380,41 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {content: Column(mainAxisSize: MainAxisSize.min,crossAxisAlignment: CrossAxisAlignment.start,- children: [- Text(- _passwordDialogHint,- style: getEnteTextTheme(context).smallFaint,- ),- const SizedBox(height: 12),- TextField(- controller: textController,- autofocus: true,- obscureText: isPasswordHidden,- decoration: InputDecoration(- hintText: l10n.enterPassword,- hintStyle: getEnteTextTheme(context).mini,- suffixIcon: IconButton(- icon: Icon(- isPasswordHidden- ? Icons.visibility_off- : Icons.visibility,+ children: [+ Text(+ _passwordDialogHint,+ style: getEnteTextTheme(context).smallFaint,+ ),+ const SizedBox(height: 12),+ TextField(+ controller: textController,+ autofocus: true,+ obscureText: isPasswordHidden,+ decoration: InputDecoration(+ hintText: l10n.enterPassword,+ hintStyle: getEnteTextTheme(context).mini,+ suffixIcon: IconButton(+ icon: Icon(+ isPasswordHidden+ ? Icons.visibility_off+ : Icons.visibility,+ ),+ onPressed: () {+ setState(() {+ isPasswordHidden = !isPasswordHidden;+ });+ },+ ),+ errorText: errorText,),- onPressed: () {+ onChanged: (text) {setState(() {- isPasswordHidden = !isPasswordHidden;+ if (text.length >= 8 && errorText != null) {+ errorText = null;+ }});},),- errorText: errorText,- ),- onChanged: (text) {- setState(() {- if (text.length >= 8 && errorText != null) errorText = null;- });- },- ),AnimatedSwitcher(duration: const Duration(milliseconds: 200),child: errorText == nulldiff --git a/mobile/apps/auth/lib/ui/settings/data/local_backup_settings_page.dart b/mobile/apps/auth/lib/ui/settings/data/local_backup_settings_page.dartindex 5b4330022b..abaac6450f 100644--- a/mobile/apps/auth/lib/ui/settings/data/local_backup_settings_page.dart+++ b/mobile/apps/auth/lib/ui/settings/data/local_backup_settings_page.dart@@ -86,9 +86,8 @@ class LocalBackupSettingsPage extends StatelessWidget {textTheme: textTheme,),const SizedBox(height: 12),- _BackupButton(- onPressed: controller.runManualBackup,- label: 'Backup now (manual)',+ _BackupActionCard(+ controller: controller,colorScheme: colorScheme,textTheme: textTheme,),@@ -97,11 +96,22 @@ class LocalBackupSettingsPage extends StatelessWidget {: (kDebugMode? Padding(padding: const EdgeInsets.only(top: 12),- child: _BackupButton(- onPressed: controller.resetBackupLocation,- label: 'Reset backup folder',- colorScheme: colorScheme,- textTheme: textTheme,+ child: Column(+ children: [+ _BackupButton(+ onPressed: controller.resetBackupLocation,+ label: 'Clear backup folder',+ colorScheme: colorScheme,+ textTheme: textTheme,+ ),+ const SizedBox(height: 10),+ _BackupButton(+ onPressed: controller.clearBackupPassword,+ label: 'Clear backup password',+ colorScheme: colorScheme,+ textTheme: textTheme,+ ),+ ],),): const SizedBox.shrink()),@@ -300,6 +310,66 @@ class _BackupButton extends StatelessWidget {}}+class _BackupActionCard extends StatelessWidget {+ const _BackupActionCard({+ required this.controller,+ required this.colorScheme,+ required this.textTheme,+ });++ final LocalBackupExperienceController controller;+ final dynamic colorScheme;+ final dynamic textTheme;++ @override+ Widget build(BuildContext context) {+ return Material(+ color: colorScheme.fillFaint,+ borderRadius: BorderRadius.circular(12),+ child: Padding(+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),+ child: Row(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Expanded(+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ 'Manual backup',+ style: textTheme.bodyBold,+ ),+ const SizedBox(height: 6),+ Text(+ 'Create an on-demand encrypted backup to your selected folder.',+ style: textTheme.miniFaint,+ ),+ ],+ ),+ ),+ TextButton(+ onPressed: controller.runManualBackup,+ style: TextButton.styleFrom(+ backgroundColor: colorScheme.fillMuted,+ shape: const StadiumBorder(),+ padding: const EdgeInsets.symmetric(+ horizontal: 18,+ vertical: 10,+ ),+ minimumSize: const Size(0, 40),+ ),+ child: Text(+ 'Backup now',+ style: textTheme.smallBold,+ ),+ ),+ ],+ ),+ ),+ );+ }+}+Color _scaleAlpha(Color color, double factor) {final normalized = (color.a * factor).clamp(0.0, 1.0);return color.withValues(alpha: normalized);