1 /*
2 * Copyright (C) 2025 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 "thermal_info_catcher.h"
16
17 #include "file_util.h"
18 #include "freeze_common.h"
19 #include "hiview_logger.h"
20 #include "thermal_mgr_client.h"
21
22 namespace OHOS {
23 namespace HiviewDFX {
24 namespace {
25 constexpr int TEMP_EVENT_LIMIT = 5;
26 }
27
28 DEFINE_LOG_LABEL(0xD002D01, "EventLogger-ThermalInfoCatcher");
29
ThermalInfoCatcher()30 ThermalInfoCatcher::ThermalInfoCatcher() : EventLogCatcher()
31 {
32 name_ = "ThermalInfoCatcher";
33 }
34
Initialize(const std::string & strParam1,int intParam1,int intParam2)35 bool ThermalInfoCatcher::Initialize(const std::string& strParam1, int intParam1, int intParam2)
36 {
37 // this catcher do not need parameters, just return true
38 description_ = "ThermalInfoCatcher --";
39 return true;
40 }
41
Catch(int fd,int jsonFd)42 int ThermalInfoCatcher::Catch(int fd, int jsonFd)
43 {
44 int originSize = GetFdSize(fd);
45 PowerMgr::ThermalLevel temp = PowerMgr::ThermalMgrClient::GetInstance().GetThermalLevel();
46 int tempNum = static_cast<int>(temp);
47 FileUtil::SaveStringToFd(fd, "\nThermalLevel info: " + std::to_string(tempNum) + "\n");
48 if (tempNum >= TEMP_EVENT_LIMIT && event_) {
49 event_->SetEventValue(FreezeCommon::HOST_RESOURCE_WARNING, "Yes");
50 }
51
52 logSize_ = GetFdSize(fd) - originSize;
53 return logSize_;
54 }
55
SetEvent(std::shared_ptr<SysEvent> event)56 void ThermalInfoCatcher::SetEvent(std::shared_ptr<SysEvent> event)
57 {
58 event_ = event;
59 }
60 } // namespace HiviewDFX
61 } // namespace OHOS
62