• 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_SERVICE_PROXY_H
17 #define OHOS_FILEMGMT_CLOUD_SYNC_SERVICE_PROXY_H
18 
19 #include "iremote_proxy.h"
20 #include "system_ability_load_callback_stub.h"
21 
22 #include "i_cloud_sync_service.h"
23 
24 namespace OHOS::FileManagement::CloudSync {
25 class CloudSyncServiceProxy : public IRemoteProxy<ICloudSyncService> {
26 public:
CloudSyncServiceProxy(const sptr<IRemoteObject> & impl)27     explicit CloudSyncServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<ICloudSyncService>(impl) {}
~CloudSyncServiceProxy()28     ~CloudSyncServiceProxy() override {}
29 
30     static sptr<ICloudSyncService> GetInstance();
31     static void InvaildInstance();
32     int32_t UnRegisterCallbackInner(const std::string &bundleName = "") override;
33     int32_t UnRegisterFileSyncCallbackInner(const std::string &bundleName = "") override;
34     int32_t RegisterCallbackInner(const sptr<IRemoteObject> &remoteObject, const std::string &bundleName = "") override;
35     int32_t RegisterFileSyncCallbackInner(const sptr<IRemoteObject> &remoteObject,
36         const std::string &bundleName = "") override;
37     int32_t StartSyncInner(bool forceFlag, const std::string &bundleName = "") override;
38     int32_t StartFileSyncInner(bool forceFlag, const std::string &bundleName = "") override;
39     int32_t TriggerSyncInner(const std::string &bundleName, const int32_t &userId) override;
40     int32_t StopSyncInner(const std::string &bundleName = "", bool forceFlag = false) override;
41     int32_t StopFileSyncInner(const std::string &bundleName = "", bool forceFlag = false) override;
42     int32_t ResetCursor(const std::string &bundleName = "") override;
43     int32_t ChangeAppSwitch(const std::string &accoutId, const std::string &bundleName, bool status) override;
44     int32_t OptimizeStorage(const OptimizeSpaceOptions &optimizeOptions, bool isCallbackValid = false,
45         const sptr<IRemoteObject> &optimizeCallback = nullptr) override;
46     int32_t StopOptimizeStorage() override;
47     int32_t Clean(const std::string &accountId, const CleanOptions &cleanOptions) override;
48     int32_t NotifyDataChange(const std::string &accoutId, const std::string &bundleName) override;
49     int32_t NotifyEventChange(int32_t userId, const std::string &eventId, const std::string &extraData) override;
50     int32_t EnableCloud(const std::string &accoutId, const SwitchDataObj &switchData) override;
51     int32_t DisableCloud(const std::string &accoutId) override;
52     int32_t StartDownloadFile(const std::string &uri) override;
53     int32_t StartFileCache(const std::vector<std::string> &uriVec,
54                            int64_t &downloadId,
55                            std::bitset<FIELD_KEY_MAX_SIZE> fieldkey = FIELDKEY_CONTENT,
56                            bool isCallbackValid = false,
57                            const sptr<IRemoteObject> &downloadCallback = nullptr,
58                            int32_t timeout = -1) override;
59     int32_t StopDownloadFile(const std::string &uri, bool needClean = false) override;
60     int32_t StopFileCache(int64_t downloadId, bool needClean = false, int32_t timeout = -1) override;
61     int32_t DownloadThumb() override;
62     int32_t RegisterDownloadFileCallback(const sptr<IRemoteObject> &downloadCallback) override;
63     int32_t RegisterFileCacheCallback(const sptr<IRemoteObject> &downloadCallback) override;
64     int32_t UnregisterDownloadFileCallback() override;
65     int32_t UnregisterFileCacheCallback() override;
66     int32_t UploadAsset(const int32_t userId, const std::string &request, std::string &result) override;
67     int32_t DownloadFile(const int32_t userId, const std::string &bundleName, AssetInfoObj &assetInfoObj) override;
68     int32_t DownloadFiles(const int32_t userId,
69                           const std::string &bundleName,
70                           const std::vector<AssetInfoObj> &assetInfoObj,
71                           std::vector<bool> &assetResultMap) override;
72     int32_t DownloadAsset(const uint64_t taskId, const int32_t userId,
73                           const std::string &bundleName,
74                           const std::string &networkId,
75                           AssetInfoObj &assetInfoObj) override;
76     int32_t RegisterDownloadAssetCallback(const sptr<IRemoteObject> &remoteObject) override;
77     int32_t DeleteAsset(const int32_t userId, const std::string &uri) override;
78     int32_t GetSyncTimeInner(int64_t &syncTime, const std::string &bundleName = "") override;
79     int32_t CleanCacheInner(const std::string &uri) override;
80     int32_t BatchCleanFile(const std::vector<CleanFileInfoObj> &fileInfo,
81         std::vector<std::string> &failCloudId) override;
82     int32_t BatchDentryFileInsert(const std::vector<DentryFileInfoObj> &fileInfo,
83         std::vector<std::string> &failCloudId) override;
84 
85     class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub {
86     public:
87         void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr<IRemoteObject> &remoteObject) override;
88         void OnLoadSystemAbilityFail(int32_t systemAbilityId) override;
89 
90         std::condition_variable proxyConVar_;
91         std::atomic<bool> isLoadSuccess_{false};
92     };
93 
94 private:
95     int32_t StartFileCacheWriteParcel(MessageParcel &data,
96                                       const std::vector<std::string> &uriVec,
97                                       std::bitset<FIELD_KEY_MAX_SIZE> &fieldkey,
98                                       bool isCallbackValid,
99                                       const sptr<IRemoteObject> &downloadCallback,
100                                       int32_t timeout = -1);
101     static inline std::mutex proxyMutex_;
102     static inline std::mutex instanceMutex_;
103     static inline std::mutex downloadMutex_;
104     static inline sptr<ICloudSyncService> serviceProxy_;
105     static inline BrokerDelegator<CloudSyncServiceProxy> delegator_;
106 };
107 } // namespace OHOS::FileManagement::CloudSync
108 
109 #endif // OHOS_FILEMGMT_CLOUD_SYNC_SERVICE_PROXY_H
110