From 7950f1ec26ab6ca4c790ff723fa11165481fc3b0 Mon Sep 17 00:00:00 2001 From: Ashil <77285023+ashilkn@users.noreply.github.com> Date: Sat, 30 Mar 2024 16:48:15 +0530 Subject: [PATCH] [mobile][photos] Explicitly ask for media location (#1261) ## Description On bumping up photo_manager version, it introduced a breaking change where we need to explicitly ask for ACCESS_MEDIA_LOCATION permission. ## Tests Tested on android 13 and 14 devices. --- mobile/lib/services/local_sync_service.dart | 9 ++++++++- mobile/lib/ui/components/home_header_widget.dart | 9 ++++++++- mobile/lib/ui/home/grant_permissions_widget.dart | 9 ++++++++- mobile/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart | 9 ++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/mobile/lib/services/local_sync_service.dart b/mobile/lib/services/local_sync_service.dart index b480661cb..858a98c6e 100644 --- a/mobile/lib/services/local_sync_service.dart +++ b/mobile/lib/services/local_sync_service.dart @@ -61,7 +61,14 @@ class LocalSyncService { return; } if (Platform.isAndroid && AppLifecycleService.instance.isForeground) { - final permissionState = await PhotoManager.requestPermissionExtend(); + final permissionState = await PhotoManager.requestPermissionExtend( + requestOption: const PermissionRequestOption( + androidPermission: AndroidPermission( + type: RequestType.common, + mediaLocation: true, + ), + ), + ); if (permissionState != PermissionState.authorized) { _logger.severe( "sync requested with invalid permission", diff --git a/mobile/lib/ui/components/home_header_widget.dart b/mobile/lib/ui/components/home_header_widget.dart index 6fb8f0f6d..567c138f0 100644 --- a/mobile/lib/ui/components/home_header_widget.dart +++ b/mobile/lib/ui/components/home_header_widget.dart @@ -48,7 +48,14 @@ class _HomeHeaderWidgetState extends State { onTap: () async { try { final PermissionState state = - await PhotoManager.requestPermissionExtend(); + await PhotoManager.requestPermissionExtend( + requestOption: const PermissionRequestOption( + androidPermission: AndroidPermission( + type: RequestType.common, + mediaLocation: true, + ), + ), + ); await LocalSyncService.instance.onUpdatePermission(state); } on Exception catch (e) { Logger("HomeHeaderWidget").severe( diff --git a/mobile/lib/ui/home/grant_permissions_widget.dart b/mobile/lib/ui/home/grant_permissions_widget.dart index 29c8e5e1b..13a4ad466 100644 --- a/mobile/lib/ui/home/grant_permissions_widget.dart +++ b/mobile/lib/ui/home/grant_permissions_widget.dart @@ -91,7 +91,14 @@ class GrantPermissionsWidget extends StatelessWidget { key: const ValueKey("grantPermissionButton"), child: Text(S.of(context).grantPermission), onPressed: () async { - final state = await PhotoManager.requestPermissionExtend(); + final state = await PhotoManager.requestPermissionExtend( + requestOption: const PermissionRequestOption( + androidPermission: AndroidPermission( + type: RequestType.common, + mediaLocation: true, + ), + ), + ); if (state == PermissionState.authorized || state == PermissionState.limited) { await SyncService.instance.onPermissionGranted(state); diff --git a/mobile/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart b/mobile/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart index 0f2510d74..2db611d47 100644 --- a/mobile/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart +++ b/mobile/lib/ui/viewer/gallery/hooks/add_photos_sheet.dart @@ -203,7 +203,14 @@ class AddPhotosPhotoWidget extends StatelessWidget { } } catch (e) { if (e is StateError) { - final PermissionState ps = await PhotoManager.requestPermissionExtend(); + final PermissionState ps = await PhotoManager.requestPermissionExtend( + requestOption: const PermissionRequestOption( + androidPermission: AndroidPermission( + type: RequestType.common, + mediaLocation: true, + ), + ), + ); if (ps != PermissionState.authorized && ps != PermissionState.limited) { await showChoiceDialog( context,