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 EXPORT std::string GetCloudMediaAssetTaskStatus(); 50 EXPORT bool SetIsThumbnailUpdate(); 51 EXPORT int32_t GetTaskStatus(); 52 EXPORT int32_t GetDownloadType(); 53 EXPORT bool SetBgDownloadPermission(const bool &flag); 54 static void DeleteAllCloudMediaAssetsAsync(); 55 static void StartDeleteCloudMediaAssets(); 56 static void StopDeleteCloudMediaAssets(); 57 58 private: CloudMediaAssetManager()59 CloudMediaAssetManager() {} ~CloudMediaAssetManager()60 ~CloudMediaAssetManager() {} 61 CloudMediaAssetManager(const CloudMediaAssetManager &manager) = delete; 62 const CloudMediaAssetManager &operator=(const CloudMediaAssetManager &manager) = delete; 63 64 EXPORT int32_t CheckDownloadTypeOfTask(const CloudMediaDownloadType &type); 65 EXPORT static int32_t DeleteBatchCloudFile(const std::vector<std::string> &fileIds); 66 EXPORT static int32_t ReadyDataForDelete(std::vector<std::string> &fileIds, std::vector<std::string> &paths, 67 std::vector<std::string> &dateTakens); 68 static void DeleteAllCloudMediaAssetsOperation(AsyncTaskData *data); 69 int32_t UpdateCloudMeidaAssets(); 70 71 private: 72 static std::shared_ptr<CloudMediaAssetDownloadOperation> operation_; 73 static std::mutex mutex_; 74 static std::atomic<TaskDeleteState> doDeleteTask_; 75 }; 76 } // namespace Media 77 } // namespace OHOS 78 #endif // OHOS_CLOUD_MEDIA_ASSET_MANAGER_H