1 /* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_CLOUD_MEDIA_ASSET_MANAGER_H 17 #define OHOS_CLOUD_MEDIA_ASSET_MANAGER_H 18 19 #include <iostream> 20 #include <memory> 21 #include <chrono> 22 #include <mutex> 23 24 #include "cloud_media_asset_download_operation.h" 25 #include "cloud_media_asset_types.h" 26 #include "medialibrary_command.h" 27 #include "rdb_store.h" 28 29 namespace OHOS { 30 namespace Media { 31 #define EXPORT __attribute__ ((visibility ("default"))) 32 33 enum class TaskDeleteState : int32_t { 34 IDLE = 0, 35 ACTIVE_DELETE = 1, 36 BACKGROUND_DELETE = 2 37 }; 38 39 class CloudMediaAssetManager { 40 public: 41 EXPORT static CloudMediaAssetManager& GetInstance(); 42 EXPORT int32_t HandleCloudMediaAssetUpdateOperations(MediaLibraryCommand &cmd); 43 EXPORT std::string HandleCloudMediaAssetGetTypeOperations(MediaLibraryCommand &cmd); 44 EXPORT int32_t StartDownloadCloudAsset(const CloudMediaDownloadType &type); 45 EXPORT int32_t RecoverDownloadCloudAsset(const CloudMediaTaskRecoverCause &cause); 46 EXPORT int32_t PauseDownloadCloudAsset(const CloudMediaTaskPauseCause &pauseCause); 47 EXPORT int32_t CancelDownloadCloudAsset(); 48 EXPORT int32_t ForceRetainDownloadCloudMedia( 49 CloudMediaRetainType retainType = CloudMediaRetainType::RETAIN_FORCE, 50 bool needAvoidRepeatedDoing = true); 51 EXPORT std::string GetCloudMediaAssetTaskStatus(); 52 EXPORT bool SetIsThumbnailUpdate(); 53 EXPORT int32_t GetTaskStatus(); 54 EXPORT int32_t GetDownloadType(); 55 EXPORT bool SetBgDownloadPermission(const bool &flag); 56 EXPORT void CheckStorageAndRecoverDownloadTask(); 57 EXPORT static void DeleteAllCloudMediaAssetsAsync(); 58 EXPORT static void StartDeleteCloudMediaAssets(); 59 EXPORT static void StopDeleteCloudMediaAssets(); 60 EXPORT void RestartForceRetainCloudAssets(); 61 62 private: CloudMediaAssetManager()63 CloudMediaAssetManager() {} ~CloudMediaAssetManager()64 ~CloudMediaAssetManager() {} 65 CloudMediaAssetManager(const CloudMediaAssetManager &manager) = delete; 66 const CloudMediaAssetManager &operator=(const CloudMediaAssetManager &manager) = delete; 67 68 EXPORT int32_t CheckDownloadTypeOfTask(const CloudMediaDownloadType &type); 69 EXPORT static int32_t DeleteBatchCloudFile(const std::vector<std::string> &fileIds); 70 EXPORT static int32_t ReadyDataForDelete(std::vector<std::string> &fileIds, std::vector<std::string> &paths, 71 std::vector<std::string> &dateTakens); 72 static void DeleteAllCloudMediaAssetsOperation(AsyncTaskData *data); 73 EXPORT int32_t UpdateCloudMediaAssets(CloudMediaRetainType retainType = CloudMediaRetainType::RETAIN_FORCE); 74 EXPORT int32_t DeleteEmptyCloudAlbums(); 75 EXPORT int32_t UpdateLocalAlbums(); 76 EXPORT int32_t UpdateBothLocalAndCloudAssets( 77 CloudMediaRetainType retainType = CloudMediaRetainType::RETAIN_FORCE); 78 EXPORT static std::string GetEditDataDirPath(const std::string &path); 79 EXPORT static int32_t DeleteEditdata(const std::string &path); 80 EXPORT bool HasDataForUpdate(CloudMediaRetainType retainType, std::vector<std::string> &updateFileIds, 81 const std::string &lastFileId); 82 EXPORT int32_t UpdateCloudAssets(const std::vector<std::string> &updateFileIds); 83 EXPORT void NotifyUpdateAssetsChange(const std::vector<std::string> ¬ifyFileIds); 84 EXPORT bool HasLocalAndCloudAssets(CloudMediaRetainType retainType, std::vector<std::string> &updateFileIds, 85 const std::string &lastFileId); 86 EXPORT int32_t UpdateLocalAndCloudAssets(const std::vector<std::string> &updateFileIds); 87 EXPORT void SetCloudsyncStatusKey(const int32_t statusKey); 88 EXPORT void TryToStartSync(); 89 EXPORT int32_t ClearDeletedDbData(); 90 EXPORT int32_t ForceRetainDownloadCloudMediaEx(CloudMediaRetainType retainType); 91 92 private: 93 std::shared_ptr<CloudMediaAssetDownloadOperation> operation_{nullptr}; 94 inline static std::atomic<TaskDeleteState> doDeleteTask_{TaskDeleteState::IDLE}; 95 inline static std::mutex deleteMutex_; 96 std::mutex updateMutex_; 97 }; 98 } // namespace Media 99 } // namespace OHOS 100 #endif // OHOS_CLOUD_MEDIA_ASSET_MANAGER_H