• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "thermal_kernel_service.h"
17 #include "thermal_common.h"
18 #include "thermal_kernel_config_file.h"
19 
20 
21 namespace OHOS {
22 namespace PowerMgr {
23 namespace {
24 constexpr const char* CONFIG_FILE_PATH = "/system/etc/thermal_config/thermal_kernel_config.xml";
25 }
OnStart()26 void ThermalKernelService::OnStart()
27 {
28     if (!Init()) {
29         THERMAL_HILOGE(FEATURE_PROTECTOR, "failed to init service");
30     }
31 }
32 
Init()33 bool ThermalKernelService::Init()
34 {
35     if (provision_ == nullptr) {
36         provision_ = std::make_shared<ThermalSensorProvision>();
37     }
38 
39     if (control_ == nullptr) {
40         control_ = std::make_shared<ThermalDeviceControl>();
41     }
42 
43     if (policy_ == nullptr) {
44         policy_ = std::make_shared<ThermalKernelPolicy>();
45     }
46 
47     if (timer_ == nullptr) {
48         timer_ = std::make_shared<ThermalProtectorTimer>(provision_);
49     }
50 
51     ThermalKernelConfigFile::GetInstance().Init(CONFIG_FILE_PATH);
52 
53     if (!policy_->Init()) {
54         THERMAL_HILOGE(FEATURE_PROTECTOR, "failed to init policy");
55         return false;
56     }
57 
58     if (!control_->Init()) {
59         THERMAL_HILOGE(FEATURE_PROTECTOR, "failed to init device control");
60         return false;
61     }
62 
63     provision_->InitProvision();
64 
65     timer_->Init();
66     return true;
67 }
68 } // namespace PowerMgr
69 } // namespace OHOS
70