• 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 
16 #include "schedule_manager.h"
17 
18 #include "schedule_config.h"
19 #include "update_log.h"
20 
21 namespace OHOS {
22 namespace UpdateEngine {
ScheduleManager(const std::shared_ptr<IAccessManager> & accessManager,const std::shared_ptr<IStartupSchedule> & startupSchedule)23 ScheduleManager::ScheduleManager(
24     const std::shared_ptr<IAccessManager> &accessManager, const std::shared_ptr<IStartupSchedule> &startupSchedule)
25 {
26     ENGINE_LOGD("ScheduleManager constructor");
27     accessManager_ = accessManager;
28     startupSchedule_ = startupSchedule;
29 }
30 
~ScheduleManager()31 ScheduleManager::~ScheduleManager()
32 {
33     ENGINE_LOGD("ScheduleManager deConstructor");
34 }
35 
IdleCheck()36 bool ScheduleManager::IdleCheck()
37 {
38     if (accessManager_ != nullptr && !accessManager_->IsIdle()) {
39         return false;
40     }
41     ENGINE_LOGI("IdleCheck true");
42     TaskManage(scheduleTask_);
43     return true;
44 }
45 
Exit()46 bool ScheduleManager::Exit()
47 {
48     if (accessManager_ != nullptr && !accessManager_->Exit()) {
49         return false;
50     }
51     return TaskSchedule(scheduleTask_);
52 }
53 
TaskManage(ScheduleTask & scheduleTask)54 bool ScheduleManager::TaskManage(ScheduleTask &scheduleTask)
55 {
56     scheduleTask.minDelayTime = ScheduleConfig::GetPullupInterval();
57     ENGINE_LOGI("TaskManage task idle");
58     return true;
59 }
60 
TaskSchedule(const ScheduleTask & scheduleTask)61 bool ScheduleManager::TaskSchedule(const ScheduleTask &scheduleTask)
62 {
63     if (startupSchedule_ == nullptr) {
64         ENGINE_LOGE("TaskSchedule startupSchedule null, return false");
65         return false;
66     }
67     ENGINE_LOGI("TaskSchedule: %{public}s", scheduleTask.ToString().c_str());
68     return startupSchedule_->Schedule(scheduleTask);
69 }
70 } // namespace UpdateEngine
71 } // namespace OHOS