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 #include "battery_status.h"
16 #include "periodic_check_task.h"
17 #include "parameters.h"
18 #include "screen_status.h"
19 #include "system_load.h"
20 #include "utils_log.h"
21 
22 namespace OHOS {
23 namespace FileManagement {
24 namespace CloudSync {
25 static const std::string FILEMANAGER_KEY = "persist.kernel.bundle_name.filemanager";
PeriodicCheckTask(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager)26 PeriodicCheckTask::PeriodicCheckTask(std::shared_ptr<CloudFile::DataSyncManager> dataSyncManager)
27     : CycleTask(PeriodicCheckTaskName, {"com.ohos.photos", system::GetParameter(FILEMANAGER_KEY, "")},
28                 THREE_DAY,
29                 dataSyncManager)
30 {
31 }
32 
RunTaskForBundle(int32_t userId,std::string bundleName)33 int32_t PeriodicCheckTask::RunTaskForBundle(int32_t userId, std::string bundleName)
34 {
35     if (ScreenStatus::IsScreenOn() || !BatteryStatus::IsCharging()
36         || !SystemLoadStatus::IsLoadStatusUnderHot()) {
37         LOGI("PeriodicCheckTask::RunTaskForBundle isScreenOn or not charging");
38         return E_STOP;
39     }
40     int32_t ret = dataSyncManager_->TriggerStartSync(bundleName, userId, false, SyncTriggerType::TASK_TRIGGER);
41     if (ret != E_OK) {
42         LOGE("trigger %{public}s periodic sync failed", bundleName.c_str());
43     }
44     return ret;
45 }
46 } // namespace CloudSync
47 } // namespace FileManagement
48 } // namespace OHOS