From d1e74a28d9afb12c5da75076c83700c84c4cad44 Mon Sep 17 00:00:00 2001 From: shalong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:29:49 +0000 Subject: [PATCH] fix(mobile): LivePhoto video not uploaded during manual asset upload (#3732) --- .../providers/manual_upload.provider.dart | 47 ++++++++++++------- mobile/pubspec.yaml | 2 +- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/mobile/lib/modules/backup/providers/manual_upload.provider.dart b/mobile/lib/modules/backup/providers/manual_upload.provider.dart index 3a335a7b1f..6d585e289a 100644 --- a/mobile/lib/modules/backup/providers/manual_upload.provider.dart +++ b/mobile/lib/modules/backup/providers/manual_upload.provider.dart @@ -149,16 +149,30 @@ class ManualUploadNotifier extends StateNotifier { } Future _startUpload(Iterable allManualUploads) async { + bool hasErrors = false; try { _backupProvider.updateBackupProgress(BackUpProgressEnum.manualInProgress); if (ref.read(galleryPermissionNotifier.notifier).hasPermission) { await PhotoManager.clearFileCache(); - Set allUploadAssets = allManualUploads - .where((e) => e.isLocal && e.local != null) - .map((e) => e.local!) - .toSet(); + // We do not have 1:1 mapping of all AssetEntity fields to Asset. This results in cases + // where platform specific fields such as `subtype` used to detect platform specific assets such as + // LivePhoto in iOS is lost when we directly fetch the local asset from Asset using Asset.local + List allAssetsFromDevice = await Future.wait( + allManualUploads + // Filter local only assets + .where((e) => e.isLocal && !e.isRemote) + .map((e) => e.local!.obtainForNewProperties()), + ); + + if (allAssetsFromDevice.length != allManualUploads.length) { + _log.warning( + '[_startUpload] Refreshed upload list -> ${allManualUploads.length - allAssetsFromDevice.length} asset will not be uploaded', + ); + } + + Set allUploadAssets = allAssetsFromDevice.nonNulls.toSet(); if (allUploadAssets.isEmpty) { debugPrint("[_startUpload] No Assets to upload - Abort Process"); @@ -213,7 +227,7 @@ class ManualUploadNotifier extends StateNotifier { '[_startUpload] Manual Upload Completed - success: ${state.successfulUploads},' ' failed: ${state.totalAssetsToUpload - state.successfulUploads}', ); - bool hasErrors = false; + // User cancelled upload if (!ok && state.cancelToken.isCancelled) { await _localNotificationService.showOrUpdateManualUploadStatus( @@ -237,32 +251,29 @@ class ManualUploadNotifier extends StateNotifier { presentBanner: true, ); } - - _backupProvider.updateBackupProgress(BackUpProgressEnum.idle); - _handleAppInActivity(); - await _backupProvider.notifyBackgroundServiceCanRun(); - return !hasErrors; } else { openAppSettings(); debugPrint("[_startUpload] Do not have permission to the gallery"); } } catch (e) { debugPrint("ERROR _startUpload: ${e.toString()}"); + hasErrors = true; + } finally { + _backupProvider.updateBackupProgress(BackUpProgressEnum.idle); + _handleAppInActivity(); + await _localNotificationService.closeNotification( + LocalNotificationService.manualUploadDetailedNotificationID, + ); + await _backupProvider.notifyBackgroundServiceCanRun(); } - _backupProvider.updateBackupProgress(BackUpProgressEnum.idle); - _handleAppInActivity(); - await _localNotificationService.closeNotification( - LocalNotificationService.manualUploadDetailedNotificationID, - ); - await _backupProvider.notifyBackgroundServiceCanRun(); - return false; + return !hasErrors; } void _handleAppInActivity() { final appState = ref.read(appStateProvider.notifier).getAppState(); // The app is currently in background. Perform the necessary cleanups which // are on-hold for upload completion - if (appState != AppStateEnum.active || appState != AppStateEnum.resumed) { + if (appState != AppStateEnum.active && appState != AppStateEnum.resumed) { ref.read(appStateProvider.notifier).handleAppInactivity(); } } diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yaml index dc90a5373c..d1790b6f3e 100644 --- a/mobile/pubspec.yaml +++ b/mobile/pubspec.yaml @@ -6,7 +6,7 @@ version: 1.73.0+96 isar_version: &isar_version 3.1.0+1 environment: - sdk: ">=3.0.0-0 <4.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: flutter: