Skip to content

armgit / ente

Public Imported from GitHub
0

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

[auth] simplify iOS backup and fix Android storage backend

Prateek Sunald6acb0455c11
diff --git a/mobile/apps/auth/lib/l10n/arb/app_en.arb b/mobile/apps/auth/lib/l10n/arb/app_en.arb
index 07332f16c2..86bcd2ce62 100644
--- a/mobile/apps/auth/lib/l10n/arb/app_en.arb
+++ b/mobile/apps/auth/lib/l10n/arb/app_en.arb
@@ -576,6 +576,7 @@
"currentBackupFolder": "Current backup folder:",
"selectFolder": "Select folder",
"selectFolderToContinue": "Select a folder to continue",
+ "iosOnMyDeviceNotSupported": "\"On My iPhone\" cannot be used directly. Please select or create a folder inside it.",
"done": "Done",
"addNew": "Add new",
"selected": "selected",
diff --git a/mobile/apps/auth/lib/services/local_backup_service.dart b/mobile/apps/auth/lib/services/local_backup_service.dart
index dbe708b9ca..2afd8c5188 100644
--- a/mobile/apps/auth/lib/services/local_backup_service.dart
+++ b/mobile/apps/auth/lib/services/local_backup_service.dart
@@ -153,29 +153,20 @@ class LocalBackupService {
return success;
}
- // iOS with bookmark
+ // iOS with bookmark - write directly to the selected directory
if (Platform.isIOS && target.iosBookmark != null) {
final dir = PickedDirectory(
path: target.path!,
bookmark: target.iosBookmark,
);
final result = await dirUtils.withAccess(dir, (path) async {
- // Create EnteAuthBackups subdirectory using native method
- final created = await dirUtils.createDirectory(
- PickedDirectory(path: path),
- 'EnteAuthBackups',
- );
- if (!created) {
- return false;
- }
- final backupPath = '$path/EnteAuthBackups';
final success = await dirUtils.writeFile(
- PickedDirectory(path: backupPath),
+ PickedDirectory(path: path),
fileName,
contentBytes,
);
if (success) {
- await _manageOldBackups(backupPath);
+ await _manageOldBackups(path);
}
return success;
});
@@ -251,8 +242,7 @@ class LocalBackupService {
Future<void> deleteAllBackupsIn(String path, {String? iosBookmark}) async {
try {
final dirUtils = DirUtils.instance;
- // On iOS, backups are in EnteAuthBackups subdirectory
- final backupPath = Platform.isIOS ? '$path/EnteAuthBackups' : path;
+ final backupPath = path;
Future<void> doDelete() async {
final backupDir = Directory(backupPath);
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.dart
index d8566e3241..bb67d38b7d 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
@@ -575,6 +575,10 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {
final pickResult = await SecurityBookmarkService.instance
.pickDirectoryAndCreateBookmark();
if (pickResult != null) {
+ if (_isInvalidIosPath(pickResult.path)) {
+ _showSnackBar(context.l10n.iosOnMyDeviceNotSupported);
+ return false;
+ }
return _persistLocationWithBookmark(
pickResult.path,
pickResult.bookmark,
@@ -706,6 +710,10 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {
final result = await SecurityBookmarkService.instance
.pickDirectoryAndCreateBookmark();
if (result != null) {
+ if (_isInvalidIosPath(result.path)) {
+ _showSnackBar(context.l10n.iosOnMyDeviceNotSupported);
+ return false;
+ }
final saved = await _persistLocationWithBookmark(
result.path,
result.bookmark,
@@ -761,21 +769,12 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {
}
try {
- // Create EnteAuthBackups subdirectory using native method for iOS
- final created = await DirUtils.instance.createDirectory(
- PickedDirectory(path: path),
- 'EnteAuthBackups',
- );
- if (!created) {
- _logger.severe('iOS: Failed to create EnteAuthBackups subdirectory');
- return false;
- }
- await LocalBackupService.instance
- .writeBackupToDirectory('$path/EnteAuthBackups');
+ // Write backup directly to the selected directory
+ await LocalBackupService.instance.writeBackupToDirectory(path);
} finally {
await SecurityBookmarkService.instance.stopAccessingBookmark(bookmark);
}
- // Store the parent path (with bookmark) - backups go to EnteAuthBackups subdir
+
await prefs.setString('autoBackupPath', path);
await prefs.setString(_iosBookmarkKey, bookmark);
await prefs.remove(_treeUriKey);
@@ -930,4 +929,54 @@ class _LocalBackupExperienceState extends State<LocalBackupExperience> {
context,
).showSnackBar(SnackBar(content: Text(message)));
}
+
+ /// Check if the selected iOS path is the device root ("On My iPhone").
+ ///
+ /// "On My iPhone" root cannot store files directly - user must select
+ /// or create a folder inside it.
+ bool _isInvalidIosPath(String path) {
+ if (!Platform.isIOS) return false;
+ if (path.isEmpty) return true;
+
+ // Normalize the path
+ var normalized = path;
+ if (normalized.startsWith('file://')) {
+ normalized = normalized.substring(7);
+ }
+
+ // iCloud Drive paths are always valid
+ if (normalized.contains('Mobile Documents/')) {
+ return false;
+ }
+
+ // Check if path ends at a root-level location without a subfolder
+ // Valid paths should have content after the container/app identifier
+ // e.g., /var/mobile/Containers/Shared/AppGroup/xxx/File Provider Storage/SomeApp/MyFolder
+ // Invalid: just the root with no actual folder selected
+
+ // If path contains File Provider Storage with a folder after it, it's valid
+ final fileProviderIndex = normalized.indexOf('File Provider Storage/');
+ if (fileProviderIndex != -1) {
+ final afterProvider = normalized
+ .substring(fileProviderIndex + 'File Provider Storage/'.length);
+ // Must have at least one more path component (the actual folder)
+ if (afterProvider.isNotEmpty && afterProvider.contains('/')) {
+ return false;
+ }
+ // Just "File Provider Storage/AppName" without a subfolder - invalid
+ _logger
+ .warning('iOS: Path appears to be app root without subfolder: $path');
+ return true;
+ }
+
+ // Documents directory is valid
+ if (normalized.contains('/Documents/') ||
+ normalized.endsWith('/Documents')) {
+ return false;
+ }
+
+ // If none of the known valid patterns match, assume it's the device root
+ _logger.warning('iOS: Potentially invalid backup path: $path');
+ return true;
+ }
}
diff --git a/mobile/packages/configuration/lib/secure_storage_service.dart b/mobile/packages/configuration/lib/secure_storage_service.dart
index 447bd1cad0..5bbe51b7be 100644
--- a/mobile/packages/configuration/lib/secure_storage_service.dart
+++ b/mobile/packages/configuration/lib/secure_storage_service.dart
@@ -13,9 +13,6 @@ class SecureStorageService {
iOptions: IOSOptions(
accessibility: KeychainAccessibility.first_unlock_this_device,
),
- aOptions: AndroidOptions(
- encryptedSharedPreferences: true,
- ),
);
Future<String?> read(String key) => _storage.read(key: key);
diff --git a/mobile/packages/dir_utils/ios/Classes/DirUtilsPlugin.swift b/mobile/packages/dir_utils/ios/Classes/DirUtilsPlugin.swift
index c600a1d748..964b203b11 100644
--- a/mobile/packages/dir_utils/ios/Classes/DirUtilsPlugin.swift
+++ b/mobile/packages/dir_utils/ios/Classes/DirUtilsPlugin.swift
@@ -31,8 +31,6 @@ public class DirUtilsPlugin: NSObject, FlutterPlugin {
handleDeleteFile(call: call, result: result)
case "listFiles":
handleListFiles(call: call, result: result)
- case "createDirectory":
- handleCreateDirectory(call: call, result: result)
case "exists":
handleExists(call: call, result: result)
default:
@@ -233,27 +231,6 @@ public class DirUtilsPlugin: NSObject, FlutterPlugin {
}
}
- private func handleCreateDirectory(call: FlutterMethodCall, result: @escaping FlutterResult) {
- guard let args = call.arguments as? [String: Any],
- let path = args["path"] as? String else {
- result(FlutterError(code: "INVALID_ARGS", message: "Missing 'path' argument", details: nil))
- return
- }
-
- let url = URL(fileURLWithPath: path)
-
- do {
- try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
- result(true)
- } catch {
- result(FlutterError(
- code: "CREATE_DIR_ERROR",
- message: "Failed to create directory: \(error.localizedDescription)",
- details: nil
- ))
- }
- }
-
private func handleExists(call: FlutterMethodCall, result: @escaping FlutterResult) {
guard let args = call.arguments as? [String: Any],
let path = args["path"] as? String else {
diff --git a/mobile/packages/dir_utils/lib/dir_utils.dart b/mobile/packages/dir_utils/lib/dir_utils.dart
index 058c51315d..7b51093fb0 100644
--- a/mobile/packages/dir_utils/lib/dir_utils.dart
+++ b/mobile/packages/dir_utils/lib/dir_utils.dart
@@ -446,41 +446,4 @@ class DirUtils {
return false;
}
}
-
- /// Create a subdirectory within a picked directory.
- /// On iOS, this uses the native method channel for security-scoped access.
- Future<bool> createDirectory(PickedDirectory dir, String subPath) async {
- if (Platform.isAndroid && dir.treeUri != null) {
- // SAF creates directories automatically when writing files
- return true;
- } else if (Platform.isIOS && dir.bookmark != null) {
- return _createDirectoryIos(dir, subPath);
- } else {
- return _createDirectoryOther(dir.path, subPath);
- }
- }
-
- Future<bool> _createDirectoryIos(PickedDirectory dir, String subPath) async {
- try {
- final fullPath = '${dir.path}/$subPath';
- final result = await _channel.invokeMethod<bool>(
- 'createDirectory',
- {'path': fullPath},
- );
- return result ?? false;
- } on PlatformException catch (e) {
- _logger.severe('iOS: Failed to create directory: ${e.message}');
- return false;
- }
- }
-
- Future<bool> _createDirectoryOther(String basePath, String subPath) async {
- try {
- await Directory('$basePath/$subPath').create(recursive: true);
- return true;
- } catch (e) {
- _logger.severe('Other: Failed to create directory: $e');
- return false;
- }
- }
}