• 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 #include "cloud_download_callback_client.h"
17 #include "cloud_sync_manager_impl.h"
18 #include "cloud_sync_callback_client.h"
19 #include "cloud_sync_service_proxy.h"
20 #include "dfs_error.h"
21 #include "system_ability_definition.h"
22 #include "iservice_registry.h"
23 #include "utils_log.h"
24 
25 namespace OHOS::FileManagement::CloudSync {
26 using namespace std;
27 constexpr int32_t MIN_USER_ID = 100;
28 constexpr int32_t MAX_FILE_CACHE_NUM = 400;
29 constexpr int32_t MAX_DENTRY_FILE_SIZE = 500;
GetInstance()30 CloudSyncManagerImpl &CloudSyncManagerImpl::GetInstance()
31 {
32     static CloudSyncManagerImpl instance;
33     return instance;
34 }
35 
RegisterCallback(const std::shared_ptr<CloudSyncCallback> callback,const std::string & bundleName)36 int32_t CloudSyncManagerImpl::RegisterCallback(const std::shared_ptr<CloudSyncCallback> callback,
37                                                const std::string &bundleName)
38 {
39     if (!callback) {
40         LOGE("callback is null");
41         return E_INVAL_ARG;
42     }
43     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
44     if (!CloudSyncServiceProxy) {
45         LOGE("proxy is null");
46         return E_SA_LOAD_FAILED;
47     }
48     auto ret = CloudSyncServiceProxy->RegisterCallbackInner(sptr(new (std::nothrow) CloudSyncCallbackClient(callback)),
49                                                             bundleName);
50     {
51         unique_lock<mutex> lock(callbackMutex_);
52         callback_ = callback;
53     }
54     SubscribeListener(bundleName);
55     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
56     LOGI("RegisterCallback ret %{public}d", ret);
57     return ret;
58 }
59 
UnRegisterCallback(const std::string & bundleName)60 int32_t CloudSyncManagerImpl::UnRegisterCallback(const std::string &bundleName)
61 {
62     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
63     if (!CloudSyncServiceProxy) {
64         LOGE("proxy is null");
65         return E_SA_LOAD_FAILED;
66     }
67 
68     auto ret = CloudSyncServiceProxy->UnRegisterCallbackInner(bundleName);
69     if (!ret) {
70         {
71             unique_lock<mutex> lock(callbackMutex_);
72             callback_ = nullptr;
73         }
74         SubscribeListener();
75     }
76     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
77     LOGI("UnRegisterCallback ret %{public}d", ret);
78     return ret;
79 }
80 
StartSync(const std::string & bundleName)81 int32_t CloudSyncManagerImpl::StartSync(const std::string &bundleName)
82 {
83     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
84     if (!CloudSyncServiceProxy) {
85         LOGE("proxy is null");
86         return E_SA_LOAD_FAILED;
87     }
88     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
89     return CloudSyncServiceProxy->StartSyncInner(true, bundleName);
90 }
91 
GetSyncTime(int64_t & syncTime,const std::string & bundleName)92 int32_t CloudSyncManagerImpl::GetSyncTime(int64_t &syncTime, const std::string &bundleName)
93 {
94     LOGI("GetSyncTime Start");
95     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
96     if (!CloudSyncServiceProxy) {
97         LOGE("proxy is null");
98         return E_SA_LOAD_FAILED;
99     }
100     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
101     return CloudSyncServiceProxy->GetSyncTimeInner(syncTime, bundleName);
102 }
103 
OptimizeStorage(const int32_t agingDays)104 int32_t CloudSyncManagerImpl::OptimizeStorage(const int32_t agingDays)
105 {
106     LOGI("OptimizeStorage Start");
107     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
108     if (!CloudSyncServiceProxy) {
109         LOGE("proxy is null");
110         return E_SA_LOAD_FAILED;
111     }
112     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
113     return CloudSyncServiceProxy->OptimizeStorage(agingDays);
114 }
115 
StartSync(bool forceFlag,const std::shared_ptr<CloudSyncCallback> callback)116 int32_t CloudSyncManagerImpl::StartSync(bool forceFlag, const std::shared_ptr<CloudSyncCallback> callback)
117 {
118     if (!callback) {
119         LOGE("callback is null");
120         return E_INVAL_ARG;
121     }
122     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
123     if (!CloudSyncServiceProxy) {
124         LOGE("proxy is null");
125         return E_SA_LOAD_FAILED;
126     }
127 
128     if (!isFirstCall_.test()) {
129         LOGI("Register callback");
130         auto ret =
131             CloudSyncServiceProxy->RegisterCallbackInner(sptr(new (std::nothrow) CloudSyncCallbackClient(callback)));
132         if (ret) {
133             LOGE("Register callback failed");
134             isFirstCall_.clear();
135             return ret;
136         }
137         callback_ = callback;
138         SubscribeListener();
139         SetDeathRecipient(CloudSyncServiceProxy->AsObject());
140     }
141 
142     return CloudSyncServiceProxy->StartSyncInner(forceFlag);
143 }
144 
TriggerSync(const std::string & bundleName,const int32_t & userId)145 int32_t CloudSyncManagerImpl::TriggerSync(const std::string &bundleName, const int32_t &userId)
146 {
147     if (bundleName.empty() || userId < MIN_USER_ID) {
148         LOGE("Trigger Sync parameter is invalid");
149         return E_INVAL_ARG;
150     }
151     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
152     if (!CloudSyncServiceProxy) {
153         LOGE("proxy is null");
154         return E_SA_LOAD_FAILED;
155     }
156     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
157     return CloudSyncServiceProxy->TriggerSyncInner(bundleName, userId);
158 }
159 
StopSync(const std::string & bundleName,bool forceFlag)160 int32_t CloudSyncManagerImpl::StopSync(const std::string &bundleName, bool forceFlag)
161 {
162     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
163     if (!CloudSyncServiceProxy) {
164         LOGE("proxy is null");
165         return E_SA_LOAD_FAILED;
166     }
167     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
168     return CloudSyncServiceProxy->StopSyncInner(bundleName, forceFlag);
169 }
170 
ResetCursor(const std::string & bundleName)171 int32_t CloudSyncManagerImpl::ResetCursor(const std::string &bundleName)
172 {
173     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
174     if (!CloudSyncServiceProxy) {
175         LOGE("proxy is null");
176         return E_SA_LOAD_FAILED;
177     }
178     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
179     return CloudSyncServiceProxy->ResetCursor(bundleName);
180 }
181 
ChangeAppSwitch(const std::string & accoutId,const std::string & bundleName,bool status)182 int32_t CloudSyncManagerImpl::ChangeAppSwitch(const std::string &accoutId, const std::string &bundleName, bool status)
183 {
184     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
185     if (!CloudSyncServiceProxy) {
186         LOGE("proxy is null");
187         return E_SA_LOAD_FAILED;
188     }
189 
190     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
191 
192     int32_t ret = CloudSyncServiceProxy->ChangeAppSwitch(accoutId, bundleName, status);
193     LOGI("ChangeAppSwitch ret %{public}d", ret);
194     return ret;
195 }
196 
NotifyDataChange(const std::string & accoutId,const std::string & bundleName)197 int32_t CloudSyncManagerImpl::NotifyDataChange(const std::string &accoutId, const std::string &bundleName)
198 {
199     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
200     if (!CloudSyncServiceProxy) {
201         LOGE("proxy is null");
202         return E_SA_LOAD_FAILED;
203     }
204 
205     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
206 
207     int32_t ret = CloudSyncServiceProxy->NotifyDataChange(accoutId, bundleName);
208     LOGI("NotifyDataChange ret %{public}d", ret);
209     return ret;
210 }
211 
NotifyEventChange(int32_t userId,const std::string & eventId,const std::string & extraData)212 int32_t CloudSyncManagerImpl::NotifyEventChange(
213     int32_t userId, const std::string &eventId, const std::string &extraData)
214 {
215     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
216     if (!CloudSyncServiceProxy) {
217         LOGE("proxy is null");
218         return E_SA_LOAD_FAILED;
219     }
220 
221     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
222 
223     int32_t ret = CloudSyncServiceProxy->NotifyEventChange(userId, eventId, extraData);
224     LOGI("NotifyDataChange ret %{public}d", ret);
225     return ret;
226 }
227 
StartDownloadFile(const std::string & uri)228 int32_t CloudSyncManagerImpl::StartDownloadFile(const std::string &uri)
229 {
230     LOGI("StartDownloadFile start");
231     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
232     if (!CloudSyncServiceProxy) {
233         LOGE("proxy is null");
234         return E_SA_LOAD_FAILED;
235     }
236     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
237     int32_t ret = CloudSyncServiceProxy->StartDownloadFile(uri);
238     LOGI("StartDownloadFile ret %{public}d", ret);
239     return ret;
240 }
241 
StartFileCache(const std::string & uri)242 int32_t CloudSyncManagerImpl::StartFileCache(const std::string &uri)
243 {
244     LOGI("StartFileCache start");
245     int64_t downloadId = 0;
246     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
247     if (!CloudSyncServiceProxy) {
248         LOGE("proxy is null");
249         return E_SA_LOAD_FAILED;
250     }
251     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
252     std::vector<std::string> uriVec;
253     uriVec.push_back(uri);
254     int32_t ret = CloudSyncServiceProxy->StartFileCache(uriVec, downloadId);
255     LOGI("StartFileCache ret %{public}d", ret);
256     return ret;
257 }
258 
StartFileCache(const std::vector<std::string> & uriVec,int64_t & downloadId,std::bitset<FIELD_KEY_MAX_SIZE> fieldkey,const std::shared_ptr<CloudDownloadCallback> downloadCallback)259 int32_t CloudSyncManagerImpl::StartFileCache(const std::vector<std::string> &uriVec,
260                                              int64_t &downloadId, std::bitset<FIELD_KEY_MAX_SIZE> fieldkey,
261                                              const std::shared_ptr<CloudDownloadCallback> downloadCallback)
262 {
263     LOGI("StartFileCache batch start, uriVec size: %{public}zu, fieldKey: %{public}llu, Callback is null: %{public}d",
264          uriVec.size(), static_cast<unsigned long long>(fieldkey.to_ulong()), (downloadCallback == nullptr));
265     if (uriVec.empty()) {
266         LOGE("StartFileCache, uri list is empty");
267         return E_INVAL_ARG;
268     }
269     if (uriVec.size() > MAX_FILE_CACHE_NUM) {
270         LOGE("StartFileCache, the size of uri list exceeded the maximum limit, size: %{public}zu", uriVec.size());
271         return E_EXCEED_MAX_SIZE;
272     }
273     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
274     if (!CloudSyncServiceProxy) {
275         LOGE("proxy is null");
276         return E_SA_LOAD_FAILED;
277     }
278     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
279 
280     bool isCallbackValid = false;
281     sptr<CloudDownloadCallbackClient> dlCallback = nullptr;
282     if (downloadCallback != nullptr) {
283         dlCallback = sptr(new (std::nothrow) CloudDownloadCallbackClient(downloadCallback));
284         isCallbackValid = true;
285         if (dlCallback == nullptr) {
286             LOGE("register download callback failed");
287             isCallbackValid = false;
288         }
289     }
290 
291     int32_t ret = CloudSyncServiceProxy->StartFileCache(uriVec, downloadId, isCallbackValid, dlCallback);
292     LOGI("StartFileCache batch ret %{public}d", ret);
293     return ret;
294 }
295 
StopDownloadFile(const std::string & uri,bool needClean)296 int32_t CloudSyncManagerImpl::StopDownloadFile(const std::string &uri,  bool needClean)
297 {
298     LOGI("StopDownloadFile start");
299     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
300     if (!CloudSyncServiceProxy) {
301         LOGE("proxy is null");
302         return E_SA_LOAD_FAILED;
303     }
304     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
305     int32_t ret = CloudSyncServiceProxy->StopDownloadFile(uri, needClean);
306     LOGI("StopDownloadFile ret %{public}d", ret);
307     return ret;
308 }
309 
StopFileCache(const int64_t & downloadId,bool needClean)310 int32_t CloudSyncManagerImpl::StopFileCache(const int64_t &downloadId,  bool needClean)
311 {
312     LOGI("StopFileCache start");
313     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
314     if (!CloudSyncServiceProxy) {
315         LOGE("proxy is null");
316         return E_SA_LOAD_FAILED;
317     }
318     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
319     int32_t ret = CloudSyncServiceProxy->StopFileCache(downloadId, needClean);
320     LOGI("StopFileCache ret %{public}d", ret);
321     return ret;
322 }
323 
DownloadThumb()324 int32_t CloudSyncManagerImpl::DownloadThumb()
325 {
326     LOGI("DownloadThumb start");
327     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
328     if (!CloudSyncServiceProxy) {
329         LOGE("proxy is null");
330         return E_SA_LOAD_FAILED;
331     }
332     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
333     int32_t ret = CloudSyncServiceProxy->DownloadThumb();
334     LOGI("DownloadThumb ret %{public}d", ret);
335     return ret;
336 }
337 
RegisterDownloadFileCallback(const std::shared_ptr<CloudDownloadCallback> downloadCallback)338 int32_t CloudSyncManagerImpl::RegisterDownloadFileCallback(
339     const std::shared_ptr<CloudDownloadCallback> downloadCallback)
340 {
341     LOGI("RegisterDownloadFileCallback start");
342     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
343     if (!CloudSyncServiceProxy) {
344         LOGE("proxy is null");
345         return E_SA_LOAD_FAILED;
346     }
347     {
348         unique_lock<mutex> lock(downloadMutex_);
349         auto dlCallback = sptr(new (std::nothrow) CloudDownloadCallbackClient(downloadCallback));
350         if (dlCallback == nullptr ||
351             CloudSyncServiceProxy->RegisterDownloadFileCallback(dlCallback) != E_OK) {
352             LOGE("register download callback failed");
353         } else  {
354             downloadCallback_ = downloadCallback;
355         }
356     }
357     SubscribeListener();
358     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
359     return E_OK;
360 }
361 
UnregisterDownloadFileCallback()362 int32_t CloudSyncManagerImpl::UnregisterDownloadFileCallback()
363 {
364     LOGI("UnregisterDownloadFileCallback start");
365     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
366     if (!CloudSyncServiceProxy) {
367         LOGE("proxy is null");
368         return E_SA_LOAD_FAILED;
369     }
370     int32_t ret = E_OK;
371     {
372         unique_lock<mutex> lock(downloadMutex_);
373         ret = CloudSyncServiceProxy->UnregisterDownloadFileCallback();
374         LOGI("UnregisterDownloadFileCallback ret %{public}d", ret);
375         if (ret == E_OK) {
376             downloadCallback_ = nullptr;
377         }
378     }
379     SubscribeListener();
380     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
381     return ret;
382 }
SetDeathRecipient(const sptr<IRemoteObject> & remoteObject)383 void CloudSyncManagerImpl::SetDeathRecipient(const sptr<IRemoteObject> &remoteObject)
384 {
385     if (!isFirstCall_.test_and_set()) {
386         auto deathCallback = [this](const wptr<IRemoteObject> &obj) {
387             LOGE("service died.");
388             CloudSyncServiceProxy::InvaildInstance();
389             if (callback_) {
390                 callback_->OnSyncStateChanged(CloudSyncState::COMPLETED, ErrorType::NO_ERROR);
391             }
392             isFirstCall_.clear();
393         };
394         deathRecipient_ = sptr(new SvcDeathRecipient(deathCallback));
395         if (!remoteObject->AddDeathRecipient(deathRecipient_)) {
396             LOGE("add death recipient failed");
397             isFirstCall_.clear();
398         }
399     }
400 }
401 
EnableCloud(const std::string & accoutId,const SwitchDataObj & switchData)402 int32_t CloudSyncManagerImpl::EnableCloud(const std::string &accoutId,
403                                           const SwitchDataObj &switchData)
404 {
405     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
406     if (!CloudSyncServiceProxy) {
407         LOGE("proxy is null");
408         return E_SA_LOAD_FAILED;
409     }
410 
411     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
412 
413     return CloudSyncServiceProxy->EnableCloud(accoutId, switchData);
414 }
415 
DisableCloud(const std::string & accoutId)416 int32_t CloudSyncManagerImpl::DisableCloud(const std::string &accoutId)
417 {
418     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
419     if (!CloudSyncServiceProxy) {
420         LOGE("proxy is null");
421         return E_SA_LOAD_FAILED;
422     }
423 
424     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
425     return CloudSyncServiceProxy->DisableCloud(accoutId);
426 }
427 
Clean(const std::string & accountId,const CleanOptions & cleanOptions)428 int32_t CloudSyncManagerImpl::Clean(const std::string &accountId, const CleanOptions &cleanOptions)
429 {
430     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
431     if (!CloudSyncServiceProxy) {
432         LOGE("proxy is null");
433         return E_SA_LOAD_FAILED;
434     }
435 
436     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
437 
438     return CloudSyncServiceProxy->Clean(accountId, cleanOptions);
439 }
440 
CleanCache(const std::string & uri)441 int32_t CloudSyncManagerImpl::CleanCache(const std::string &uri)
442 {
443     LOGI("CleanCache Start");
444     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
445     if (!CloudSyncServiceProxy) {
446         LOGE("proxy is null");
447         return E_SA_LOAD_FAILED;
448     }
449     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
450     return CloudSyncServiceProxy->CleanCacheInner(uri);
451 }
452 
BatchDentryFileInsert(const std::vector<DentryFileInfo> & fileInfo,std::vector<std::string> & failCloudId)453 int32_t CloudSyncManagerImpl::BatchDentryFileInsert(const std::vector<DentryFileInfo> &fileInfo,
454     std::vector<std::string> &failCloudId)
455 {
456     if (fileInfo.size() > MAX_DENTRY_FILE_SIZE) {
457         LOGE("BatchDentryFileInsert parameter is invalid");
458         return E_INVAL_ARG;
459     }
460     auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
461     if (!CloudSyncServiceProxy) {
462         LOGE("proxy is null");
463         return E_SA_LOAD_FAILED;
464     }
465 
466     SetDeathRecipient(CloudSyncServiceProxy->AsObject());
467     std::vector<DentryFileInfoObj> fileInfoObj;
468     for (const auto &info : fileInfo) {
469         DentryFileInfoObj obj(info);
470         fileInfoObj.emplace_back(obj);
471     }
472 
473     return CloudSyncServiceProxy->BatchDentryFileInsert(fileInfoObj, failCloudId);
474 }
475 
SubscribeListener(std::string bundleName)476 void CloudSyncManagerImpl::SubscribeListener(std::string bundleName)
477 {
478     unique_lock<mutex> lock(subscribeMutex_);
479     auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
480     if (samgr == nullptr) {
481         LOGE("Samgr is nullptr");
482         return;
483     }
484     if (listener_ != nullptr) {
485         auto ret = samgr->UnSubscribeSystemAbility(FILEMANAGEMENT_CLOUD_SYNC_SERVICE_SA_ID, listener_);
486         LOGI("unsubscribed to systemAbility ret %{public}d", ret);
487     }
488     if (callback_ != nullptr || downloadCallback_ != nullptr) {
489         listener_ = new SystemAbilityStatusChange(bundleName);
490         auto ret = samgr->SubscribeSystemAbility(FILEMANAGEMENT_CLOUD_SYNC_SERVICE_SA_ID, listener_);
491         LOGI("subscribed to systemAbility ret %{public}d", ret);
492     } else {
493         listener_ = nullptr;
494     }
495 }
496 
ResetProxyCallback(uint32_t retryCount,const string & bundleName)497 bool CloudSyncManagerImpl::ResetProxyCallback(uint32_t retryCount, const string &bundleName)
498 {
499     auto cloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance();
500     if (cloudSyncServiceProxy == nullptr) {
501         LOGE("proxy is null");
502         return false;
503     }
504     bool hasCallback = false;
505     {
506         unique_lock<mutex> downloadLock(downloadMutex_);
507         if (downloadCallback_ != nullptr) {
508             auto dlCallback = sptr(new (std::nothrow) CloudDownloadCallbackClient(downloadCallback_));
509             if (dlCallback == nullptr ||
510                 cloudSyncServiceProxy->RegisterDownloadFileCallback(dlCallback) != E_OK) {
511                 LOGW("register download callback failed, try time is %{public}d", retryCount);
512             } else {
513                 hasCallback = true;
514             }
515         }
516     }
517     if (callback_ != nullptr) {
518         auto callback = sptr(new (std::nothrow) CloudSyncCallbackClient(callback_));
519         if (callback == nullptr ||
520             cloudSyncServiceProxy->RegisterCallbackInner(callback, bundleName) != E_OK) {
521             LOGW("register callback failed, try time is %{public}d", retryCount);
522         } else {
523             hasCallback = true;
524         }
525     }
526     if (hasCallback) {
527         CloudSyncManagerImpl::GetInstance().SetDeathRecipient(cloudSyncServiceProxy->AsObject());
528     }
529     return true;
530 }
531 
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)532 void CloudSyncManagerImpl::SystemAbilityStatusChange::OnAddSystemAbility(int32_t systemAbilityId,
533     const std::string &deviceId)
534 {
535     const uint32_t RETRY_TIMES = 3;
536     const uint32_t SLEEP_TIME = 20 * 1000;
537     uint32_t retryCount = 0;
538     LOGI("saId %{public}d loaded", systemAbilityId);
539     do {
540         usleep(SLEEP_TIME);
541         if (!CloudSyncManagerImpl::GetInstance().ResetProxyCallback(retryCount, bundleName_)) {
542             continue;
543         }
544         return;
545     } while (++retryCount < RETRY_TIMES);
546     LOGE("register callback failed, try too many times");
547 }
548 
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)549 void CloudSyncManagerImpl::SystemAbilityStatusChange::OnRemoveSystemAbility(int32_t systemAbilityId,
550     const std::string &deviceId)
551 {
552     return;
553 }
554 } // namespace OHOS::FileManagement::CloudSync
555