π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Handle Apple Photos save permission
AmanRajSinghMourya87c12a9beb7a
diff --git a/mobile/apps/photos/ios/Runner/Info.plist b/mobile/apps/photos/ios/Runner/Info.plistindex 499ef0d81a..156e8c1687 100644--- a/mobile/apps/photos/ios/Runner/Info.plist+++ b/mobile/apps/photos/ios/Runner/Info.plist@@ -82,6 +82,8 @@<string>Please allow access to your camera so that you can take photos within ente</string><key>NSPhotoLibraryUsageDescription</key><string>Please allow access to your photos so that ente can encrypt and back them up.</string>+ <key>NSPhotoLibraryAddUsageDescription</key>+ <string>Allow Ente to save photos and videos to Apple Photos.</string><key>NSMotionUsageDescription</key><string>Ente uses device motion to let you look around panoramic photos.</string><key>PHPhotoLibraryPreventAutomaticLimitedAccessAlert</key>diff --git a/mobile/apps/photos/lib/services/permission/service.dart b/mobile/apps/photos/lib/services/permission/service.dartindex e488e8ec29..114a129d67 100644--- a/mobile/apps/photos/lib/services/permission/service.dart+++ b/mobile/apps/photos/lib/services/permission/service.dart@@ -4,8 +4,12 @@ import "package:shared_preferences/shared_preferences.dart";class PermissionService {static const kHasGrantedPermissionsKey = "has_granted_permissions";static const kPermissionStateKey = "permission_state";+ static const _photoLibraryAddRequestOption = PermissionRequestOption(+ iosAccessLevel: IosAccessLevel.addOnly,+ );final SharedPreferences _prefs;PermissionService(this._prefs);+Future<PermissionState> requestPhotoMangerPermissions() {return PhotoManager.requestPermissionExtend(requestOption: const PermissionRequestOption(@@ -17,6 +21,17 @@ class PermissionService {);}+ Future<PermissionState> requestPhotoLibraryAddPermission() async {+ final state = await PhotoManager.getPermissionState(+ requestOption: _photoLibraryAddRequestOption,+ );+ return state == PermissionState.notDetermined+ ? PhotoManager.requestPermissionExtend(+ requestOption: _photoLibraryAddRequestOption,+ )+ : state;+ }+bool hasGrantedPermissions() {return _prefs.getBool(kHasGrantedPermissionsKey) ?? false;}diff --git a/mobile/apps/photos/lib/ui/common/photo_library_add_permission.dart b/mobile/apps/photos/lib/ui/common/photo_library_add_permission.dartnew file mode 100644index 0000000000..3d79641977--- /dev/null+++ b/mobile/apps/photos/lib/ui/common/photo_library_add_permission.dart@@ -0,0 +1,57 @@+import "dart:io";++import "package:ente_strings/ente_strings.dart";+import "package:flutter/material.dart";+import "package:logging/logging.dart";+import "package:photo_manager/photo_manager.dart";+import "package:photos/service_locator.dart";+import "package:photos/ui/components/alert_bottom_sheet.dart";+import "package:photos/ui/components/buttons/button_widget_v2.dart";+import "package:photos/utils/dialog_util.dart";++final _logger = Logger("photo_library_add_permission");++Future<bool> ensurePhotoLibraryAddPermission(BuildContext context) async {+ if (!context.mounted) return false;+ if (!Platform.isIOS) return true;++ PermissionState permission;+ try {+ permission = await permissionService.requestPhotoLibraryAddPermission();+ } catch (e, s) {+ _logger.warning("Could not verify Apple Photos add permission", e, s);+ if (context.mounted) {+ await showGenericErrorDialog(context: context, error: e);+ }+ return false;+ }++ _logger.info("Apple Photos add permission: $permission");+ if (!context.mounted) return false;+ if (permission.hasAccess) return true;++ final isRestricted = permission == PermissionState.restricted;+ await showAlertBottomSheet(+ context,+ title: context.strings.allowPermTitle,+ message: isRestricted+ ? context.strings.photoLibraryAddPermissionRestricted+ : context.strings.photoLibraryAddPermissionRequired,+ assetPath: "assets/ducky_smart_feature.png",+ buttons: isRestricted+ ? null+ : [+ ButtonWidgetV2(+ buttonType: ButtonTypeV2.primary,+ labelText: context.strings.openSettings,+ isInAlert: true,+ shouldSurfaceExecutionStates: false,+ onTap: () async {+ Navigator.of(context).pop();+ await PhotoManager.openSetting();+ },+ ),+ ],+ );+ return false;+}diff --git a/mobile/apps/photos/lib/ui/tools/collage/collage_creator_page.dart b/mobile/apps/photos/lib/ui/tools/collage/collage_creator_page.dartindex 65d5268b85..b86f6510ee 100644--- a/mobile/apps/photos/lib/ui/tools/collage/collage_creator_page.dart+++ b/mobile/apps/photos/lib/ui/tools/collage/collage_creator_page.dart@@ -7,6 +7,7 @@ import "package:photo_manager/photo_manager.dart";import 'package:photos/models/file/file.dart';import "package:photos/module/metadata/local_file.dart";import "package:photos/services/sync/sync_service.dart";+import "package:photos/ui/common/photo_library_add_permission.dart";import "package:photos/ui/notification/toast.dart";import "package:photos/ui/tools/collage/collage_app_bar.dart";import "package:photos/ui/tools/collage/collage_test_grid.dart";@@ -47,6 +48,7 @@ class _CollageCreatorPageState extends State<CollageCreatorPage> {Future<void> _saveCollage() async {if (_controller == null || _isSaving) return;+ if (!await ensurePhotoLibraryAddPermission(context)) return;_clearSwapSelection?.call();await Future<void>.delayed(const Duration(milliseconds: 16));diff --git a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dartindex 0dd21bfa14..c520acb8c2 100644--- a/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart+++ b/mobile/apps/photos/lib/ui/tools/editor/image_editor/image_editor_page.dart@@ -22,6 +22,7 @@ import "package:photos/models/location/location.dart";import "package:photos/module/metadata/local_file.dart";import "package:photos/service_locator.dart";import "package:photos/services/sync/sync_service.dart";+import "package:photos/ui/common/photo_library_add_permission.dart";import "package:photos/ui/components/action_sheet_widget.dart";import "package:photos/ui/components/buttons/button_widget.dart";import "package:photos/ui/components/models/button_type.dart";@@ -89,6 +90,9 @@ class _ImageEditorPageState extends State<ImageEditorPage> {}Future<void> saveImage(ProImageEditorState editorState) async {+ if (!await ensurePhotoLibraryAddPermission(context)) return;+ if (!mounted) return;+final l10n = context.strings;final dialog = createProgressDialog(context, l10n.saving);await dialog.show();diff --git a/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart b/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dartindex 70a68db836..94de533dd0 100644--- a/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart+++ b/mobile/apps/photos/lib/ui/tools/editor/video_editor_page.dart@@ -19,6 +19,7 @@ import "package:photos/service_locator.dart";import "package:photos/services/sync/sync_service.dart";import "package:photos/theme/ente_theme.dart";import "package:photos/ui/common/linear_progress_dialog.dart";+import "package:photos/ui/common/photo_library_add_permission.dart";import "package:photos/ui/notification/toast.dart";import "package:photos/ui/tools/editor/export_video_service.dart";import "package:photos/ui/tools/editor/native_video_export_service.dart";@@ -236,6 +237,9 @@ class _VideoEditorPageState extends State<VideoEditorPage> {}void exportVideo() async {+ if (!await ensurePhotoLibraryAddPermission(context)) return;+ if (!mounted) return;+final shouldUseNative = flagService.internalUser? _useNativeExport: flagService.useNativeVideoEditor;diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dartindex 46d61a5a3c..03e5c20235 100644--- a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart@@ -40,6 +40,7 @@ import "package:photos/theme/ente_theme.dart";import 'package:photos/ui/actions/collection/collection_file_actions.dart';import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';import 'package:photos/ui/collections/collection_action_sheet.dart';+import "package:photos/ui/common/photo_library_add_permission.dart";import 'package:photos/ui/components/action_sheet_widget.dart';import "package:photos/ui/components/bottom_action_bar/selection_action_button_widget.dart";import 'package:photos/ui/components/buttons/button_widget.dart';@@ -1222,6 +1223,9 @@ class _FileSelectionActionsWidgetStateint addedToQueueCount = 0;if (filesToDownload.isNotEmpty) {+ if (!await ensurePhotoLibraryAddPermission(context)) return;+ if (!mounted) return;+if (flagService.internalUser) {try {final enqueueResult = await galleryDownloadQueueService.enqueueFiles(diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dartindex 7cdcf106a0..e937137097 100644--- a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart@@ -32,6 +32,7 @@ import "package:photos/theme/colors.dart";import "package:photos/ui/actions/collection/collection_sharing_actions.dart";import "package:photos/ui/actions/file/file_actions.dart";import 'package:photos/ui/collections/collection_action_sheet.dart';+import "package:photos/ui/common/photo_library_add_permission.dart";import 'package:photos/ui/notification/toast.dart';import 'package:photos/ui/viewer/actions/suggest_delete_sheet.dart';import "package:photos/ui/viewer/file/detail_page.dart";@@ -615,6 +616,10 @@ class FileAppBarState extends State<FileAppBar> {return;}+ if (!mounted) return;+ if (!await ensurePhotoLibraryAddPermission(context)) return;+ if (!mounted) return;+final fileToDownload = !file.isRemoteOnlyFile? (file.copyWith()..localID = null): file;diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dartindex 675f4f7035..e2032a021f 100644--- a/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/gallery/gallery_app_bar_widget.dart@@ -35,6 +35,7 @@ import "package:photos/theme/ente_theme.dart";import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';import "package:photos/ui/cast/cast.dart";import "package:photos/ui/collections/album/smart_album_people.dart";+import "package:photos/ui/common/photo_library_add_permission.dart";import "package:photos/ui/common/web_page.dart";import 'package:photos/ui/components/action_sheet_widget.dart';import 'package:photos/ui/components/buttons/button_widget.dart';@@ -943,6 +944,9 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {if (files == null || files.isEmpty) {return;}+ if (!await ensurePhotoLibraryAddPermission(context)) return;+ if (!mounted) return;+if (flagService.internalUser) {try {await galleryDownloadQueueService.enqueueFiles(diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arbindex b5971414f0..07212dae41 100644--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb@@ -2906,6 +2906,8 @@},"pets": "Furry companions","photoGridSize": "Photo grid size",+ "photoLibraryAddPermissionRequired": "Ente needs permission to save photos and videos to Apple Photos. You can allow access in Settings.",+ "photoLibraryAddPermissionRestricted": "Photo Library access is restricted on this device.","photos": "Photos","photosAddedByYouWillBeRemovedFromTheAlbum": "Photos added by you will be removed from the album","photosAndVideosCount": "{count, plural, one{{formattedCount} photo & video} other{{formattedCount} photos & videos}}",