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