• 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_IMPL_H
17 #define OHOS_FILEMGMT_CLOUD_SYNC_MANAGER_IMPL_H
18 
19 #include <atomic>
20 
21 #include "nocopyable.h"
22 
23 #include "cloud_sync_callback_client.h"
24 #include "cloud_sync_common.h"
25 #include "cloud_sync_manager.h"
26 #include "svc_death_recipient.h"
27 #include "system_ability_status_change_stub.h"
28 
29 namespace OHOS::FileManagement::CloudSync {
30 class CloudSyncManagerImpl final : public CloudSyncManager, public NoCopyable {
31 public:
32     static CloudSyncManagerImpl &GetInstance();
33 
34     int32_t RegisterCallback(const std::shared_ptr<CloudSyncCallback> callback,
35                              const std::string &bundleName = "") override;
36     int32_t UnRegisterCallback(const std::string &bundleName = "") override;
37     int32_t StartSync(const std::string &bundleName = "") override;
38     int32_t StartSync(bool forceFlag, const std::shared_ptr<CloudSyncCallback> callback) override;
39     int32_t TriggerSync(const std::string &bundleName, const int32_t &userId) override;
40     int32_t StopSync(const std::string &bundleName = "", bool forceFlag = false) override;
41     int32_t ResetCursor(const std::string &bundleName = "") override;
42     int32_t ChangeAppSwitch(const std::string &accoutId, const std::string &bundleName, bool status) override;
43     int32_t OptimizeStorage(const int32_t agingDays) override;
44     int32_t Clean(const std::string &accountId, const CleanOptions &cleanOptions) override;
45     int32_t NotifyDataChange(const std::string &accoutId, const std::string &bundleName) override;
46     int32_t NotifyEventChange(int32_t userId, const std::string &eventId, const std::string &extraData) override;
47     int32_t EnableCloud(const std::string &accoutId, const SwitchDataObj &switchData) override;
48     int32_t DisableCloud(const std::string &accoutId) override;
49     int32_t StartDownloadFile(const std::string &uri) override;
50     int32_t StartFileCache(const std::string &uri) override;
51     int32_t StartFileCache(const std::vector<std::string> &uriVec, int64_t &downloadId,
52                            std::bitset<FIELD_KEY_MAX_SIZE> fieldkey = FIELDKEY_CONTENT,
53                            const std::shared_ptr<CloudDownloadCallback> downloadCallback = nullptr) override;
54     int32_t StopDownloadFile(const std::string &uri, bool needClean = false) override;
55     int32_t StopFileCache(const int64_t &downloadId, bool needClean = false) override;
56     int32_t DownloadThumb() override;
57     int32_t RegisterDownloadFileCallback(const std::shared_ptr<CloudDownloadCallback> downloadCallback) override;
58     int32_t UnregisterDownloadFileCallback() override;
59     int32_t GetSyncTime(int64_t &syncTime, const std::string &bundleName = "") override;
60     int32_t CleanCache(const std::string &uri) override;
61     int32_t BatchDentryFileInsert(const std::vector<DentryFileInfo> &fileInfo,
62         std::vector<std::string> &failCloudId) override;
63 
64     class SystemAbilityStatusChange : public SystemAbilityStatusChangeStub {
65     public:
SystemAbilityStatusChange(const std::string & bundleName)66         SystemAbilityStatusChange(const std::string &bundleName) : bundleName_(bundleName) {};
67         void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId);
68         void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId);
69     private:
70         std::string bundleName_ = "";
71     };
72 private:
73     CloudSyncManagerImpl() = default;
74     void SetDeathRecipient(const sptr<IRemoteObject> &remoteObject);
75     bool ResetProxyCallback(uint32_t retryCount, const std::string &bundleName);
76 
77     std::atomic_flag isFirstCall_{false};
78     sptr<SvcDeathRecipient> deathRecipient_;
79     std::shared_ptr<CloudSyncCallback> callback_;
80     std::shared_ptr<CloudDownloadCallback> downloadCallback_;
81     sptr<CloudSyncManagerImpl::SystemAbilityStatusChange> listener_;
82     std::mutex subscribeMutex_;
83     std::mutex downloadMutex_;
84     std::mutex callbackMutex_;
85     void SubscribeListener(std::string bundleName = "");
86 };
87 } // namespace OHOS::FileManagement::CloudSync
88 
89 #endif // OHOS_FILEMGMT_CLOUD_SYNC_MANAGER_IMPL_H
90