1 /* 2 * Copyright (c) 2022 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_FILEMGMT_CLOUD_SYNC_MANAGER_H 17 #define OHOS_FILEMGMT_CLOUD_SYNC_MANAGER_H 18 19 #include <memory> 20 21 #include "cloud_download_callback.h" 22 #include "cloud_optimize_callback.h" 23 #include "cloud_sync_callback.h" 24 #include "cloud_sync_common.h" 25 #include "downgrade_dl_callback.h" 26 27 namespace OHOS::FileManagement::CloudSync { 28 class CloudSyncManager { 29 public: 30 static CloudSyncManager &GetInstance(); 31 /** 32 * @brief 注册 33 * 34 * @param callback 注册同步回调 35 * @return int32_t 同步返回执行结果 36 */ 37 virtual int32_t RegisterCallback(const std::shared_ptr<CloudSyncCallback> callback, 38 const std::string &bundleName = "") = 0; 39 virtual int32_t RegisterFileSyncCallback(const std::shared_ptr<CloudSyncCallback> callback, 40 const std::string &bundleName = "") = 0; 41 /** 42 * @brief 注册 43 * 44 * @param callback 卸载同步回调 45 * @return int32_t 返回执行结果 46 */ 47 virtual int32_t UnRegisterCallback(const std::string &bundleName = "") = 0; 48 virtual int32_t UnRegisterFileSyncCallback(const std::string &bundleName = "") = 0; 49 /** 50 * @brief 启动同步 51 * 52 * @return int32_t 同步返回执行结果 53 */ 54 virtual int32_t StartSync(const std::string &bundleName = "") = 0; 55 virtual int32_t StartFileSync(const std::string &bundleName = "") = 0; 56 /** 57 * @brief 启动同步 58 * 59 * @param forceFlag 是否强制继续同步,当前仅支持低电量下暂停后继续上传 60 * @param callback 注册同步回调 61 * @return int32_t 同步返回执行结果 62 */ 63 virtual int32_t StartSync(bool forceFlag, const std::shared_ptr<CloudSyncCallback> callback) = 0; 64 /** 65 * @brief 触发同步 66 * 67 * @param bundleName 应用包名 68 * @param userId 用户ID 69 * @return int32_t 同步返回执行结果 70 */ 71 virtual int32_t TriggerSync(const std::string &bundleName, const int32_t &userId) = 0; 72 /** 73 * @brief 停止同步 74 * 75 * @return int32_t 同步返回执行结果 76 */ 77 virtual int32_t StopSync(const std::string &bundleName = "", bool forceFlag = false) = 0; 78 virtual int32_t StopFileSync(const std::string &bundleName = "", bool forceFlag = false) = 0; 79 /** 80 * @brief 清理水位 81 * 82 * @return int32_t 同步返回执行结果 83 */ 84 virtual int32_t ResetCursor(const std::string &bundleName = "") = 0; 85 /** 86 * @brief 切换应用云同步开关 87 * 88 * @param accoutId 账号ID 89 * @param bundleName 应用包名 90 * @param status 应用开关状态 91 * @return int32_t 同步返回执行结果 92 */ 93 virtual int32_t ChangeAppSwitch(const std::string &accoutId, const std::string &bundleName, bool status) = 0; 94 /** 95 * @brief 云数据变化触发同步 96 * 97 * @param accoutId 账号ID 98 * @param bundleName 应用包名 99 * @return int32_t 同步返回执行结果 100 */ 101 virtual int32_t NotifyDataChange(const std::string &accoutId, const std::string &bundleName) = 0; 102 virtual int32_t NotifyEventChange(int32_t userId, const std::string &eventId, const std::string &extraData) = 0; 103 virtual int32_t EnableCloud(const std::string &accoutId, const SwitchDataObj &switchData) = 0; 104 virtual int32_t DisableCloud(const std::string &accoutId) = 0; 105 /** 106 * @brief 云账号退出选择保留或清除云数据 107 * 108 * @param accoutId 账号ID 109 * @param cleanOptions 说明云文件如何处理的方式 110 * @return int32_t 同步返回执行结果 111 */ 112 virtual int32_t Clean(const std::string &accountId, const CleanOptions &cleanOptions) = 0; 113 virtual int32_t OptimizeStorage(const OptimizeSpaceOptions &optimizeOptions, 114 const std::shared_ptr<CloudOptimizeCallback> optimizeCallback = nullptr) = 0; 115 virtual int32_t StopOptimizeStorage() = 0; 116 virtual int32_t StartDownloadFile(const std::string &uri, 117 const std::shared_ptr<CloudDownloadCallback> downloadCallback, 118 int64_t &downloadId) = 0; 119 virtual int32_t StartFileCache(const std::vector<std::string> &uriVec, 120 int64_t &downloadId, 121 int32_t fieldkey = FieldKey::FIELDKEY_CONTENT, 122 const std::shared_ptr<CloudDownloadCallback> downloadCallback = nullptr, 123 int32_t timeout = -1) = 0; 124 virtual int32_t StopDownloadFile(int64_t downloadId, bool needClean = false) = 0; 125 virtual int32_t StopFileCache(int64_t downloadId, bool needClean = false, int32_t timeout = -1) = 0; 126 virtual int32_t DownloadThumb() = 0; 127 virtual int32_t GetSyncTime(int64_t &syncTime, const std::string &bundleName = "") = 0; 128 virtual int32_t CleanCache(const std::string &uri) = 0; 129 virtual int32_t CleanFileCache(const std::string &uri) = 0; 130 virtual void CleanGalleryDentryFile() = 0; 131 virtual void CleanGalleryDentryFile(const std::string path) = 0; 132 virtual int32_t BatchCleanFile(const std::vector<CleanFileInfo> &fileInfo, 133 std::vector<std::string> &failCloudId) = 0; 134 virtual int32_t BatchDentryFileInsert(const std::vector<DentryFileInfo> &fileInfo, 135 std::vector<std::string> &failCloudId) = 0; 136 /** 137 * @brief 开始降级下载 138 * 139 * @param bundleName 降级应用包名 140 * @param downloadCallback 下载进度回调函数 141 * @return int32_t 同步返回执行结果 142 */ 143 virtual int32_t StartDowngrade(const std::string &bundleName, 144 const std::shared_ptr<DowngradeDlCallback> downloadCallback) = 0; 145 /** 146 * @brief 停止降级下载 147 * 148 * @param bundleName 降级应用包名 149 * @return int32_t 同步返回执行结果 150 */ 151 virtual int32_t StopDowngrade(const std::string &bundleName) = 0; 152 /** 153 * @brief 获取应用文件信息 154 * 155 * @param bundleName 应用包名 156 * @param cloudFileInfo 不同位置文件总大小信息 157 * @return int32_t 同步返回执行结果 158 */ 159 virtual int32_t GetCloudFileInfo(const std::string &bundleName, CloudFileInfo &cloudFileInfo) = 0; 160 // file version 161 virtual int32_t GetHistoryVersionList(const std::string &uri, const int32_t versionNumLimit, 162 std::vector<CloudSync::HistoryVersion> &historyVersionList) = 0; 163 virtual int32_t DownloadHistoryVersion(const std::string &uri, int64_t &downloadId, const uint64_t versionId, 164 const std::shared_ptr<CloudDownloadCallback> downloadCallback, 165 std::string &versionUri) = 0; 166 virtual int32_t ReplaceFileWithHistoryVersion(const std::string &uri, const std::string &versionUri) = 0; 167 virtual int32_t IsFileConflict(const std::string &uri, bool &isConflict) = 0; 168 virtual int32_t ClearFileConflict(const std::string &uri) = 0; 169 }; 170 } // namespace OHOS::FileManagement::CloudSync 171 172 #endif // OHOS_FILEMGMT_CLOUD_SYNC_MANAGER_H 173