• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
26 namespace OHOS::FileManagement::CloudSync {
27 class CloudSyncManager {
28 public:
29     static CloudSyncManager &GetInstance();
30     /**
31      * @brief 注册
32      *
33      * @param callback 注册同步回调
34      * @return int32_t 同步返回执行结果
35      */
36     virtual int32_t RegisterCallback(const std::shared_ptr<CloudSyncCallback> callback,
37                                      const std::string &bundleName = "") = 0;
38     virtual int32_t RegisterFileSyncCallback(const std::shared_ptr<CloudSyncCallback> callback,
39                                      const std::string &bundleName = "") = 0;
40     /**
41      * @brief 注册
42      *
43      * @param callback 卸载同步回调
44      * @return int32_t 返回执行结果
45      */
46     virtual int32_t UnRegisterCallback(const std::string &bundleName = "") = 0;
47     virtual int32_t UnRegisterFileSyncCallback(const std::string &bundleName = "") = 0;
48     /**
49      * @brief 启动同步
50      *
51      * @return int32_t 同步返回执行结果
52      */
53     virtual int32_t StartSync(const std::string &bundleName = "") = 0;
54     virtual int32_t StartFileSync(const std::string &bundleName = "") = 0;
55     /**
56      * @brief 启动同步
57      *
58      * @param forceFlag 是否强制继续同步,当前仅支持低电量下暂停后继续上传
59      * @param callback 注册同步回调
60      * @return int32_t 同步返回执行结果
61      */
62     virtual int32_t StartSync(bool forceFlag, const std::shared_ptr<CloudSyncCallback> callback) = 0;
63     /**
64      * @brief 触发同步
65      *
66      * @param bundleName 应用包名
67      * @param userId 用户ID
68      * @return int32_t 同步返回执行结果
69      */
70     virtual int32_t TriggerSync(const std::string &bundleName, const int32_t &userId) = 0;
71     /**
72      * @brief 停止同步
73      *
74      * @return int32_t 同步返回执行结果
75      */
76     virtual int32_t StopSync(const std::string &bundleName = "", bool forceFlag = false) = 0;
77     virtual int32_t StopFileSync(const std::string &bundleName = "", bool forceFlag = false) = 0;
78     /**
79      * @brief 清理水位
80      *
81      * @return int32_t 同步返回执行结果
82      */
83     virtual int32_t ResetCursor(const std::string &bundleName = "") = 0;
84     /**
85      * @brief 切换应用云同步开关
86      *
87      * @param accoutId 账号ID
88      * @param bundleName 应用包名
89      * @param status 应用开关状态
90      * @return int32_t 同步返回执行结果
91      */
92     virtual int32_t ChangeAppSwitch(const std::string &accoutId, const std::string &bundleName, bool status) = 0;
93     /**
94      * @brief 云数据变化触发同步
95      *
96      * @param accoutId 账号ID
97      * @param bundleName 应用包名
98      * @return int32_t 同步返回执行结果
99      */
100     virtual int32_t NotifyDataChange(const std::string &accoutId, const std::string &bundleName) = 0;
101     virtual int32_t NotifyEventChange(int32_t userId, const std::string &eventId, const std::string &extraData) = 0;
102     virtual int32_t EnableCloud(const std::string &accoutId, const SwitchDataObj &switchData) = 0;
103     virtual int32_t DisableCloud(const std::string &accoutId) = 0;
104     /**
105      * @brief 云账号退出选择保留或清除云数据
106      *
107      * @param accoutId 账号ID
108      * @param cleanOptions 说明云文件如何处理的方式
109      * @return int32_t 同步返回执行结果
110      */
111     virtual int32_t Clean(const std::string &accountId, const CleanOptions &cleanOptions) = 0;
112     virtual int32_t OptimizeStorage(const OptimizeSpaceOptions &optimizeOptions,
113         const std::shared_ptr<CloudOptimizeCallback> optimizeCallback = nullptr) = 0;
114     virtual int32_t StopOptimizeStorage() = 0;
115     virtual int32_t StartDownloadFile(const std::string &path) = 0;
116     virtual int32_t StartFileCache(const std::string &path) = 0;
117     virtual int32_t StartFileCache(const std::vector<std::string> &pathVec, int64_t &downloadId,
118                                    std::bitset<FIELD_KEY_MAX_SIZE> fieldkey = FIELDKEY_CONTENT,
119                                    const std::shared_ptr<CloudDownloadCallback> downloadCallback = nullptr,
120                                    int32_t timeout = -1) = 0;
121     virtual int32_t StopDownloadFile(const std::string &path, bool needClean = false) = 0;
122     virtual int32_t StopFileCache(int64_t downloadId, bool needClean = false, int32_t timeout = -1) = 0;
123     virtual int32_t DownloadThumb() = 0;
124     virtual int32_t RegisterDownloadFileCallback(const std::shared_ptr<CloudDownloadCallback> downloadCallback) = 0;
125     virtual int32_t RegisterFileCacheCallback(const std::shared_ptr<CloudDownloadCallback> downloadCallback) = 0;
126     virtual int32_t UnregisterDownloadFileCallback() = 0;
127     virtual int32_t UnregisterFileCacheCallback() = 0;
128     virtual int32_t GetSyncTime(int64_t &syncTime, const std::string &bundleName = "") = 0;
129     virtual int32_t CleanCache(const std::string &uri) = 0;
130     virtual void CleanGalleryDentryFile() = 0;
131     virtual int32_t BatchCleanFile(const std::vector<CleanFileInfo> &fileInfo,
132         std::vector<std::string> &failCloudId) = 0;
133     virtual int32_t BatchDentryFileInsert(const std::vector<DentryFileInfo> &fileInfo,
134          std::vector<std::string> &failCloudId) = 0;
135 };
136 } // namespace OHOS::FileManagement::CloudSync
137 
138 #endif // OHOS_FILEMGMT_CLOUD_SYNC_MANAGER_H
139