1 /*
2 * Copyright (c) 2025 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_sync_manager_core.h"
17
18 #include <sys/types.h>
19
20 #include "cloud_sync_manager.h"
21 #include "dfs_error.h"
22 #include "utils_log.h"
23
24 namespace OHOS::FileManagement::CloudSync {
25 using namespace std;
26
DoChangeAppCloudSwitch(const string & accountId,const string & bundleName,bool status)27 FsResult<void> CloudSyncManagerCore::DoChangeAppCloudSwitch(
28 const string &accountId, const string &bundleName, bool status)
29 {
30 LOGI("change app cloud switch.");
31 int32_t result = CloudSyncManager::GetInstance().ChangeAppSwitch(accountId, bundleName, status);
32 if (result == E_PERMISSION_DENIED || result == E_PERMISSION_SYSTEM) {
33 LOGE("ChangeAppSwitch failed. ret = %{public}d", result);
34 return FsResult<void>::Error(Convert2ErrNum(result));
35 }
36
37 return FsResult<void>::Success();
38 }
39
DoNotifyEventChange(int32_t userId,const string & eventId,const string & extraData)40 FsResult<void> CloudSyncManagerCore::DoNotifyEventChange(
41 int32_t userId, const string &eventId, const string &extraData)
42 {
43 LOGI("NotifyEventChange entrance");
44 int32_t result = CloudSyncManager::GetInstance().NotifyEventChange(userId, eventId, extraData);
45 if (result == E_PERMISSION_DENIED || result == E_PERMISSION_SYSTEM) {
46 LOGE("NotifyEventChange failed. ret = %{public}d", result);
47 return FsResult<void>::Error(Convert2ErrNum(result));
48 }
49
50 return FsResult<void>::Success();
51 }
52
DoNotifyDataChange(const string & accountId,const string & bundleName)53 FsResult<void> CloudSyncManagerCore::DoNotifyDataChange(const string &accountId, const string &bundleName)
54 {
55 LOGI("NotifyDataChange entrance");
56 int32_t result = CloudSyncManager::GetInstance().NotifyDataChange(accountId, bundleName);
57 if (result == E_PERMISSION_DENIED || result == E_PERMISSION_SYSTEM) {
58 LOGE("NotifyDataChange failed. ret = %{public}d", result);
59 return FsResult<void>::Error(Convert2ErrNum(result));
60 }
61
62 return FsResult<void>::Success();
63 }
64
DoDisableCloud(const string & accountId)65 FsResult<void> CloudSyncManagerCore::DoDisableCloud(const string &accountId)
66 {
67 LOGI("DisableCloud");
68 int32_t result = CloudSyncManager::GetInstance().DisableCloud(accountId);
69 if (result == E_PERMISSION_DENIED || result == E_PERMISSION_SYSTEM) {
70 LOGE("DisableCloud failed. ret = %{public}d", result);
71 return FsResult<void>::Error(Convert2ErrNum(result));
72 }
73
74 return FsResult<void>::Success();
75 }
76
DoEnableCloud(const string & accountId,const SwitchDataObj & switchData)77 FsResult<void> CloudSyncManagerCore::DoEnableCloud(const string &accountId, const SwitchDataObj &switchData)
78 {
79 LOGI("EnableCloud");
80 int32_t result = CloudSyncManager::GetInstance().EnableCloud(accountId, switchData);
81 if (result == E_PERMISSION_DENIED || result == E_PERMISSION_SYSTEM) {
82 LOGE("EnableCloud failed. ret = %{public}d", result);
83 return FsResult<void>::Error(Convert2ErrNum(result));
84 }
85
86 return FsResult<void>::Success();
87 }
88
DoClean(const std::string & accountId,const CleanOptions & cleanOptions)89 FsResult<void> CloudSyncManagerCore::DoClean(const std::string &accountId, const CleanOptions &cleanOptions)
90 {
91 LOGI("Clean");
92 int32_t result = CloudSyncManager::GetInstance().Clean(accountId, cleanOptions);
93 if (result == E_PERMISSION_DENIED || result == E_PERMISSION_SYSTEM) {
94 LOGE("Clean failed. ret = %{public}d", result);
95 return FsResult<void>::Error(Convert2ErrNum(result));
96 }
97
98 return FsResult<void>::Success();
99 }
100 } // namespace OHOS::FileManagement::CloudSync