1 /*
2  * Copyright (c) 2023 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 "save_subscription_task.h"
17 
18 #include "cloud_file_kit.h"
19 #include "utils_log.h"
20 
21 namespace OHOS {
22 namespace FileManagement {
23 namespace CloudSync {
SaveSubscriptionTask(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager)24 SaveSubscriptionTask::SaveSubscriptionTask(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager)
25     : CycleTask("save_subscription_task", {}, ONE_DAY, dataSyncManager)
26 {
27 }
28 
RunTaskForBundle(int32_t userId,std::string bundleName)29 int32_t SaveSubscriptionTask::RunTaskForBundle(int32_t userId, std::string bundleName)
30 {
31     auto instance = CloudFile::CloudFileKit::GetInstance();
32     if (instance == nullptr) {
33         LOGE("get cloud file helper instance failed");
34         return E_NULLPTR;
35     }
36 
37     auto cloudSyncHelper = instance->GetCloudSyncHelper(userId, bundleName);
38     if (cloudSyncHelper == nullptr) {
39         LOGE("get cloudSyncHelper failed");
40         return E_NULLPTR;
41     }
42 
43     return cloudSyncHelper->SaveSubScription();
44 }
45 } // namespace CloudSync
46 } // namespace FileManagement
47 } // namespace OHOS