diff --git a/bundle.json b/bundle.json index 3ddf25323070caa9e07f22300d242117b04af9a4..f8a5a7246d834973f60dc22ef366c1448445dfb7 100644 --- a/bundle.json +++ b/bundle.json @@ -82,7 +82,6 @@ "name": "//base/powermgr/thermal_manager/interfaces/inner_api:thermalsrv_client", "header": { "header_files": [ - "ithermal_srv.h", "thermal_mgr_client.h", "ithermal_temp_callback.h", "ithermal_level_callback.h", diff --git a/frameworks/napi/BUILD.gn b/frameworks/napi/BUILD.gn index 468f880300bf9045f560b2f01bbd05b22972a20a..87aaac3bdaf3043efdb8bd5502c798a843e1f17f 100644 --- a/frameworks/napi/BUILD.gn +++ b/frameworks/napi/BUILD.gn @@ -33,6 +33,7 @@ ohos_shared_library("thermal") { deps = [ "${thermal_inner_api}:thermalsrv_client", "${thermal_service_zidl}:thermalmgr_proxy", + "${utils_path}:thermal_utils", ] external_deps = [ diff --git a/frameworks/native/thermal_mgr_client.cpp b/frameworks/native/thermal_mgr_client.cpp index 7914df826061981dd1c8c08902fd3dc2c8812b8b..5441b2de35469bd05afdee6db6e4d0c10c3b5527 100644 --- a/frameworks/native/thermal_mgr_client.cpp +++ b/frameworks/native/thermal_mgr_client.cpp @@ -154,7 +154,8 @@ bool ThermalMgrClient::GetThermalSrvSensorInfo(const SensorType& type, ThermalSr THERMAL_HILOGI(COMP_FWK, "the thermal pointer is null"); return false; } - bool ret = thermalSrv_->GetThermalSrvSensorInfo(type, sensorInfo); + bool ret = false; + thermalSrv_->GetThermalSrvSensorInfo(static_cast(type), sensorInfo, ret); return ret; } @@ -172,28 +173,34 @@ void ThermalMgrClient::GetLevel(ThermalLevel& level) { THERMAL_HILOGD(COMP_FWK, "Enter"); THERMAL_RETURN_IF(Connect() != ERR_OK); - thermalSrv_->GetThermalLevel(level); + int32_t intLevel = static_cast(level); + thermalSrv_->GetThermalLevel(intLevel); + level = static_cast(intLevel); } bool ThermalMgrClient::SetScene(const std::string& scene) { THERMAL_HILOGD(COMP_FWK, "Enter"); THERMAL_RETURN_IF_WITH_RET(Connect() != ERR_OK, false); - return thermalSrv_->SetScene(scene); + int ret = thermalSrv_->SetScene(scene); + return ret == ERR_OK; } bool ThermalMgrClient::UpdateThermalState(const std::string& tag, const std::string& val, bool isImmed) { THERMAL_HILOGD(COMP_FWK, "Enter"); THERMAL_RETURN_IF_WITH_RET(Connect() != ERR_OK, false); - return thermalSrv_->UpdateThermalState(tag, val, isImmed); + int ret = thermalSrv_->UpdateThermalState(tag, val, isImmed); + return ret == ERR_OK; } bool ThermalMgrClient::UpdateThermalPolicy() { THERMAL_HILOGD(COMP_FWK, "Enter"); THERMAL_RETURN_IF_WITH_RET(Connect() != ERR_OK, false); - return thermalSrv_->GetThermalInfo(); + bool thermalInfoRet = false; + thermalSrv_->GetThermalInfo(thermalInfoRet); + return thermalInfoRet; } ThermalLevel ThermalMgrClient::GetThermalLevel() @@ -209,7 +216,9 @@ std::string ThermalMgrClient::Dump(const std::vector& args) std::string error = "can't connect service"; THERMAL_RETURN_IF_WITH_RET(Connect() != ERR_OK, error); THERMAL_HILOGD(COMP_FWK, "Enter"); - return thermalSrv_->ShellDump(args, args.size()); + std::string dumpShell; + thermalSrv_->ShellDump(args, args.size(), dumpShell); + return dumpShell; } } // namespace PowerMgr } // namespace OHOS diff --git a/interfaces/inner_api/BUILD.gn b/interfaces/inner_api/BUILD.gn index f85c3a0306a3081767728e64c5430edf431eb613..48c3ad5bbbd907e0b42822719db94a530bb90ce7 100644 --- a/interfaces/inner_api/BUILD.gn +++ b/interfaces/inner_api/BUILD.gn @@ -22,17 +22,30 @@ config("thermalsrv_public_config") { } ohos_shared_library("thermalsrv_client") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" - sources = [ "${thermal_frameworks}/native/thermal_mgr_client.cpp" ] + sources = [ + "${thermal_frameworks}/native/thermal_mgr_client.cpp", + "${thermal_frameworks}/native/thermal_srv_sensor_info.cpp", + ] configs = [ + "${thermal_service_zidl}:thermalmgr_ipc_public_config", "${utils_path}:utils_config", ":thermalsrv_private_config", "${utils_path}:coverage_flags", ] - public_configs = [ ":thermalsrv_public_config" ] + public_configs = [ + "${thermal_service_zidl}:thermalmgr_ipc_public_config", + ":thermalsrv_public_config", + ] deps = [ "${thermal_service_zidl}:thermalmgr_proxy" ] @@ -49,10 +62,7 @@ ohos_shared_library("thermalsrv_client") { } ohos_shared_library("thermalmgr_listener") { - sources = [ - "${thermal_frameworks}/native/thermal_level_callback_stub.cpp", - "${thermal_frameworks}/native/thermal_mgr_listener.cpp", - ] + sources = [ "${thermal_frameworks}/native/thermal_mgr_listener.cpp" ] configs = [ "${utils_path}:utils_config", diff --git a/interfaces/inner_api/native/include/ithermal_srv.h b/interfaces/inner_api/native/include/ithermal_srv.h deleted file mode 100644 index 770f4ea9b90eaa532b4e3e55303bdbd3fa9a7a94..0000000000000000000000000000000000000000 --- a/interfaces/inner_api/native/include/ithermal_srv.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef POWERMGR_INNER_API_ITHERMAL_SRV_H -#define POWERMGR_INNER_API_ITHERMAL_SRV_H - -#include "iremote_broker.h" -#include "iremote_object.h" -#include "ithermal_action_callback.h" -#include "ithermal_level_callback.h" -#include "ithermal_temp_callback.h" -#include "thermal_srv_sensor_info.h" - -namespace OHOS { -namespace PowerMgr { -class IThermalSrv : public IRemoteBroker { -public: - virtual bool SubscribeThermalTempCallback( - const std::vector& typeList, const sptr& callback) = 0; - virtual bool UnSubscribeThermalTempCallback(const sptr& callback) = 0; - virtual bool SubscribeThermalLevelCallback(const sptr& callback) = 0; - virtual bool UnSubscribeThermalLevelCallback(const sptr& callback) = 0; - virtual bool SubscribeThermalActionCallback(const std::vector& actionList, const std::string& desc, - const sptr& callback) = 0; - virtual bool UnSubscribeThermalActionCallback(const sptr& callback) = 0; - virtual bool GetThermalSrvSensorInfo(const SensorType& type, ThermalSrvSensorInfo& sensorInfo) = 0; - virtual bool GetThermalLevel(ThermalLevel& level) = 0; - virtual bool GetThermalInfo() = 0; - virtual bool SetScene(const std::string& scene) = 0; - virtual bool UpdateThermalState(const std::string& tag, const std::string& val, bool isImmed = false) = 0; - virtual std::string ShellDump(const std::vector& args, uint32_t argc) = 0; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.powermgr.IThermalSrv"); -}; -} // namespace PowerMgr -} // namespace OHOS -#endif // POWERMGR_INNER_API_ITHERMAL_SRV_H diff --git a/services/native/include/thermal_service.h b/services/native/include/thermal_service.h index 46a6924c78c750bdbc5221bff8f32c5f4e2768f7..bd47f8d1f5c14568e1a3737f6261687b6c0b567e 100644 --- a/services/native/include/thermal_service.h +++ b/services/native/include/thermal_service.h @@ -64,21 +64,21 @@ public: virtual void OnStop() override; virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; virtual int32_t Dump(int fd, const std::vector& args) override; - bool SubscribeThermalTempCallback( + int32_t SubscribeThermalTempCallback( const std::vector& typeList, const sptr& callback) override; - bool UnSubscribeThermalTempCallback(const sptr& callback) override; - bool SubscribeThermalLevelCallback(const sptr& callback) override; - bool UnSubscribeThermalLevelCallback(const sptr& callback) override; - bool SubscribeThermalActionCallback(const std::vector& actionList, const std::string& desc, + int32_t UnSubscribeThermalTempCallback(const sptr& callback) override; + int32_t SubscribeThermalLevelCallback(const sptr& callback) override; + int32_t UnSubscribeThermalLevelCallback(const sptr& callback) override; + int32_t SubscribeThermalActionCallback(const std::vector& actionList, const std::string& desc, const sptr& callback) override; - bool UnSubscribeThermalActionCallback(const sptr& callback) override; - bool GetThermalSrvSensorInfo(const SensorType& type, ThermalSrvSensorInfo& sensorInfo) override; - bool GetThermalLevel(ThermalLevel& level) override; - bool GetThermalInfo() override; - bool SetScene(const std::string& scene) override; - bool UpdateThermalState(const std::string& tag, const std::string& val, bool isImmed = false) override; + int32_t UnSubscribeThermalActionCallback(const sptr& callback) override; + int32_t GetThermalSrvSensorInfo(int32_t type, ThermalSrvSensorInfo& sensorInfo, bool& sensorInfoRet) override; + int32_t GetThermalLevel(int32_t& level) override; + int32_t GetThermalInfo(bool& thermalInfoRet) override; + int32_t SetScene(const std::string& scene) override; + int32_t UpdateThermalState(const std::string& tag, const std::string& val, bool isImmed = false) override; bool CreateConfigModule(); - virtual std::string ShellDump(const std::vector& args, uint32_t argc) override; + int32_t ShellDump(const std::vector& args, uint32_t argc, std::string& dumpShell) override; int32_t HandleThermalCallbackEvent(const HdfThermalCallbackInfo& event); int32_t HandleFanCallbackEvent(const HdfThermalCallbackInfo& event); diff --git a/services/native/src/thermal_policy/thermal_srv_config_parser.cpp b/services/native/src/thermal_policy/thermal_srv_config_parser.cpp index d586039a7c624f850bbb17bcd5f4f4f5e64db918..debec90e9a1b6fed0f6ad1553cf1b6922b585bd7 100644 --- a/services/native/src/thermal_policy/thermal_srv_config_parser.cpp +++ b/services/native/src/thermal_policy/thermal_srv_config_parser.cpp @@ -780,7 +780,7 @@ bool ThermalSrvConfigParser::ParseFanFaultInfo(const xmlNodePtr& node, return true; } - + bool ThermalSrvConfigParser::ParseTempDiffInfo(const xmlNodePtr& cur, SensorClusterPtr& sc) { xmlChar* xmlTempDiff = xmlGetProp(cur, BAD_CAST"temp_diff"); @@ -788,7 +788,7 @@ bool ThermalSrvConfigParser::ParseTempDiffInfo(const xmlNodePtr& cur, SensorClus THERMAL_HILOGD(COMP_SVC, "temp_diff does not exist!"); return true; } - + std::vector sensors; StringOperation::SplitString(reinterpret_cast(xmlTempDiff), sensors, ","); if (sensors.size() != TEMPDIFF_SENSOR_SIZE) { @@ -796,7 +796,7 @@ bool ThermalSrvConfigParser::ParseTempDiffInfo(const xmlNodePtr& cur, SensorClus xmlFree(xmlTempDiff); return false; } - + auto& sensor1 = sensors[0]; auto& sensor2 = sensors[1]; TempDiffInfoList infoList; @@ -805,13 +805,13 @@ bool ThermalSrvConfigParser::ParseTempDiffInfo(const xmlNodePtr& cur, SensorClus xmlFree(xmlTempDiff); return false; } - + sc->SetTempDiffInfo(infoList); sc->SetTempDiffFlag(true); xmlFree(xmlTempDiff); return true; } - + bool ThermalSrvConfigParser::ParseTempDiffLevInfo(const xmlNodePtr& cur, const std::string& sensor1, const std::string& sensor2, TempDiffInfoList& infoList) { @@ -841,7 +841,7 @@ bool ThermalSrvConfigParser::ParseTempDiffLevInfo(const xmlNodePtr& cur, } return true; } - + bool ThermalSrvConfigParser::ParseTempDiffValue(const xmlNodePtr& cur, const std::string& sensor1, const std::string& sensor2, TempDiffItem& item) { @@ -850,7 +850,7 @@ bool ThermalSrvConfigParser::ParseTempDiffValue(const xmlNodePtr& cur, THERMAL_HILOGE(COMP_SVC, "temp diff trigger value is null"); return false; } - + if (!StrToInt(reinterpret_cast(xmlTempDiffTrigger), item.tempDiff)) { THERMAL_HILOGE(COMP_SVC, "temp diff value is a illegal number"); xmlFree(xmlTempDiffTrigger); diff --git a/services/native/src/thermal_service.cpp b/services/native/src/thermal_service.cpp index 58b8a47189a82248a7cfa6bf9f740657b79a68dd..ddef652b3aa0ba4931ccffb080a24695901d02b3 100644 --- a/services/native/src/thermal_service.cpp +++ b/services/native/src/thermal_service.cpp @@ -36,6 +36,7 @@ #include "soc_action_base.h" #include "thermal_common.h" #include "thermal_mgr_dumper.h" +#include "thermal_xcollie.h" #include "xcollie/watchdog.h" namespace OHOS { @@ -49,6 +50,7 @@ const std::string SYSTEM_THERMAL_SERVICE_CONFIG_PATH = "/system/etc/thermal_conf constexpr const char* HDI_SERVICE_NAME = "thermal_interface_service"; FFRTQueue g_queue("thermal_service"); constexpr uint32_t RETRY_TIME = 1000; +constexpr uint32_t ERR_FAIL = -1; auto g_service = ThermalService::GetInstance(); const bool G_REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(g_service.GetRefPtr()); SysParam::BootCompletedCallback g_bootCompletedCallback; @@ -414,97 +416,114 @@ void ThermalService::OnStop() #endif } -bool ThermalService::SubscribeThermalTempCallback( +int32_t ThermalService::SubscribeThermalTempCallback( const std::vector& typeList, const sptr& callback) { + ThermalXCollie thermalXCollie("ThermalService::SubscribeThermalTempCallback", false); if (!Permission::IsSystem()) { - return false; + THERMAL_HILOGE(COMP_SVC, "Permission::IsSystem() failed"); + return ERR_FAIL; } auto uid = IPCSkeleton::GetCallingUid(); THERMAL_HILOGI(COMP_SVC, "%{public}s is called by uid=%{public}d", __func__, uid); observer_->SubscribeThermalTempCallback(typeList, callback); - return true; + return ERR_OK; } -bool ThermalService::UnSubscribeThermalTempCallback(const sptr& callback) +int32_t ThermalService::UnSubscribeThermalTempCallback(const sptr& callback) { + ThermalXCollie thermalXCollie("ThermalService::UnSubscribeThermalTempCallback", false); if (!Permission::IsSystem()) { - return false; + THERMAL_HILOGE(COMP_SVC, "Permission::IsSystem() failed"); + return ERR_FAIL; } auto uid = IPCSkeleton::GetCallingUid(); THERMAL_HILOGI(COMP_SVC, "%{public}s is called by uid=%{public}d", __func__, uid); observer_->UnSubscribeThermalTempCallback(callback); - return true; + return ERR_OK; } -bool ThermalService::GetThermalSrvSensorInfo(const SensorType& type, ThermalSrvSensorInfo& sensorInfo) +int32_t ThermalService::GetThermalSrvSensorInfo(int32_t type, ThermalSrvSensorInfo& sensorInfo, bool& sensorInfoRet) { + ThermalXCollie thermalXCollie("ThermalService::GetThermalSrvSensorInfo", false); THERMAL_HILOGD(COMP_SVC, "Enter"); - if (!(observer_->GetThermalSrvSensorInfo(type, sensorInfo))) { + sensorInfoRet = observer_->GetThermalSrvSensorInfo(static_cast(type), sensorInfo); + if (!(sensorInfoRet)) { THERMAL_HILOGW(COMP_SVC, "failed to get sensor temp, type enum: %{public}u", static_cast(type)); - return false; + return ERR_FAIL; } - return true; + return ERR_OK; } -bool ThermalService::SubscribeThermalLevelCallback(const sptr& callback) +int32_t ThermalService::SubscribeThermalLevelCallback(const sptr& callback) { + ThermalXCollie thermalXCollie("ThermalService::SubscribeThermalLevelCallback", false); auto uid = IPCSkeleton::GetCallingUid(); THERMAL_HILOGI(COMP_SVC, "%{public}s is called by uid=%{public}d", __func__, uid); actionMgr_->SubscribeThermalLevelCallback(callback); - return true; + return ERR_OK; } -bool ThermalService::UnSubscribeThermalLevelCallback(const sptr& callback) +int32_t ThermalService::UnSubscribeThermalLevelCallback(const sptr& callback) { + ThermalXCollie thermalXCollie("ThermalService::UnSubscribeThermalLevelCallback", false); auto uid = IPCSkeleton::GetCallingUid(); THERMAL_HILOGI(COMP_SVC, "%{public}s is called by uid=%{public}d", __func__, uid); actionMgr_->UnSubscribeThermalLevelCallback(callback); - return true; + return ERR_OK; } -bool ThermalService::SubscribeThermalActionCallback( +int32_t ThermalService::SubscribeThermalActionCallback( const std::vector& actionList, const std::string& desc, const sptr& callback) { + ThermalXCollie thermalXCollie("ThermalService::SubscribeThermalActionCallback", false); if (!Permission::IsSystem()) { - return false; + THERMAL_HILOGE(COMP_SVC, "Permission::IsSystem() failed"); + return ERR_FAIL; } auto pid = IPCSkeleton::GetCallingPid(); auto uid = IPCSkeleton::GetCallingUid(); THERMAL_HILOGI(COMP_SVC, "%{public}s is called by pid=%{public}d, uid=%{public}d", __func__, pid, uid); observer_->SubscribeThermalActionCallback(actionList, desc, callback); - return true; + return ERR_OK; } -bool ThermalService::UnSubscribeThermalActionCallback(const sptr& callback) +int32_t ThermalService::UnSubscribeThermalActionCallback(const sptr& callback) { + ThermalXCollie thermalXCollie("ThermalService::UnSubscribeThermalActionCallback", false); if (!Permission::IsSystem()) { - return false; + THERMAL_HILOGE(COMP_SVC, "Permission::IsSystem() failed"); + return ERR_FAIL; } auto pid = IPCSkeleton::GetCallingPid(); auto uid = IPCSkeleton::GetCallingUid(); THERMAL_HILOGI(COMP_SVC, "%{public}s is called by pid=%{public}d, uid=%{public}d", __func__, pid, uid); observer_->UnSubscribeThermalActionCallback(callback); - return true; + return ERR_OK; } -bool ThermalService::GetThermalLevel(ThermalLevel& level) +int32_t ThermalService::GetThermalLevel(int32_t& level) { - uint32_t levelValue = actionMgr_->GetThermalLevel(); - level = static_cast(levelValue); - return true; + ThermalXCollie thermalXCollie("ThermalService::GetThermalLevel", false); + if (actionMgr_ == nullptr) { + THERMAL_HILOGD(COMP_SVC, "actionMgr_ is nullptr"); + return ERR_FAIL; + } + level = actionMgr_->GetThermalLevel(); + return ERR_OK; } -bool ThermalService::GetThermalInfo() +int32_t ThermalService::GetThermalInfo(bool& ret) { + ThermalXCollie thermalXCollie("ThermalService::GetThermalInfo", false); THERMAL_HILOGD(COMP_SVC, "Enter"); HdfThermalCallbackInfo thermalInfo; - bool ret = false; + ret = false; if (thermalInterface_ == nullptr) { thermalInterface_ = IThermalInterface::Get(); if (thermalInterface_ == nullptr) { THERMAL_HILOGD(COMP_SVC, "thermalInterface_ is nullptr"); - return ret; + return ERR_FAIL; } } @@ -515,22 +534,26 @@ bool ThermalService::GetThermalInfo() ret = true; } } - return ret; + return ERR_OK; } -bool ThermalService::SetScene(const std::string& scene) +int32_t ThermalService::SetScene(const std::string& scene) { + ThermalXCollie thermalXCollie("ThermalService::SetScene", false); if (!Permission::IsSystem()) { - return false; + THERMAL_HILOGE(COMP_SVC, "Permission::IsSystem() failed"); + return ERR_FAIL; } scene_ = scene; - return true; + return ERR_OK; } -bool ThermalService::UpdateThermalState(const std::string& tag, const std::string& val, bool isImmed) +int32_t ThermalService::UpdateThermalState(const std::string& tag, const std::string& val, bool isImmed) { + ThermalXCollie thermalXCollie("ThermalService::UpdateThermalState", false); if (!Permission::IsSystem()) { - return false; + THERMAL_HILOGE(COMP_SVC, "Permission::IsSystem() failed"); + return ERR_FAIL; } THERMAL_HILOGI(COMP_SVC, "tag %{public}s, val %{public}s, isImmed %{public}d", tag.c_str(), val.c_str(), isImmed); @@ -539,7 +562,7 @@ bool ThermalService::UpdateThermalState(const std::string& tag, const std::strin if (isImmed) { policy_->ExecutePolicy(); } - return true; + return ERR_OK; } void ThermalService::RegisterHdiStatusListener() @@ -676,18 +699,20 @@ int32_t ThermalService::HandleFanCallbackEvent(const HdfThermalCallbackInfo& eve return ERR_OK; } -std::string ThermalService::ShellDump(const std::vector& args, uint32_t argc) +int32_t ThermalService::ShellDump(const std::vector& args, uint32_t argc, std::string& result) { + ThermalXCollie thermalXCollie("ThermalService::ShellDump", false); if (!Permission::IsSystem() || !isBootCompleted_) { - return ""; + THERMAL_HILOGE(COMP_SVC, "Permission::IsSystem() failed or isBootCompleted_ is false"); + result = ""; + return ERR_FAIL; } std::lock_guard lock(mutex_); pid_t pid = IPCSkeleton::GetCallingPid(); THERMAL_HILOGI(COMP_SVC, "PID: %{public}d", pid); - std::string result; bool ret = ThermalMgrDumper::Dump(args, result); THERMAL_HILOGI(COMP_SVC, "ThermalMgrDumper :%{public}d", ret); - return result; + return ERR_OK; } int32_t ThermalService::Dump(int fd, const std::vector& args) diff --git a/services/zidl/BUILD.gn b/services/zidl/BUILD.gn index cdd81f98b0ff812ef64b580777f0b6ad1527d487..8b269bc585627c09610d4eb90303b4d08ed750ad 100644 --- a/services/zidl/BUILD.gn +++ b/services/zidl/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("../../thermalmgr.gni") config("thermalmgr_ipc_private_config") { @@ -18,7 +19,19 @@ config("thermalmgr_ipc_private_config") { } config("thermalmgr_ipc_public_config") { - include_dirs = [ "include" ] + include_dirs = [ + "include", + "${target_gen_dir}", + ] +} + +idl_gen_interface("thermalmgr_interface") { + sources = [ "IThermalSrv.idl" ] + + log_domainid = "0xD002942" + log_tag = "ThermalSvc" + subsystem_name = "powermgr" + part_name = "thermal_manager" } deps_ex = [ @@ -27,14 +40,24 @@ deps_ex = [ "hicollie:libhicollie", "ipc:ipc_core", "c_utils:utils", + "ipc:ipc_single", + "samgr:samgr_proxy", ] -ohos_shared_library("thermalmgr_stub") { - sources = [ - "${thermal_frameworks}/native/thermal_srv_sensor_info.cpp", - "src/thermal_action_callback_stub.cpp", - "src/thermal_srv_stub.cpp", - "src/thermal_temp_callback_stub.cpp", +ohos_source_set("thermalmgr_proxy") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":thermalmgr_interface") + sources = filter_include(output_values, [ "*_proxy.cpp" ]) + + sources += [ + "src/thermal_action_callback_proxy.cpp", + "src/thermal_level_callback_proxy.cpp", + "src/thermal_level_callback_stub.cpp", + "src/thermal_temp_callback_proxy.cpp", ] configs = [ @@ -45,22 +68,27 @@ ohos_shared_library("thermalmgr_stub") { public_configs = [ ":thermalmgr_ipc_public_config" ] + deps = [ ":thermalmgr_interface" ] + external_deps = deps_ex subsystem_name = "powermgr" part_name = "thermal_manager" } -ohos_shared_library("thermalmgr_proxy") { - branch_protector_ret = "pac_ret" +ohos_source_set("thermalmgr_stub") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + output_values = get_target_outputs(":thermalmgr_interface") + sources = filter_include(output_values, [ "*_stub.cpp" ]) - sources = [ - "${thermal_manager_path}/frameworks/native/thermal_srv_sensor_info.cpp", - "src/thermal_action_callback_proxy.cpp", - "src/thermal_level_callback_proxy.cpp", - "src/thermal_level_callback_stub.cpp", - "src/thermal_srv_proxy.cpp", - "src/thermal_temp_callback_proxy.cpp", + sources += [ + "${thermal_frameworks}/native/thermal_srv_sensor_info.cpp", + "src/thermal_action_callback_stub.cpp", + "src/thermal_temp_callback_stub.cpp", ] configs = [ @@ -71,9 +99,9 @@ ohos_shared_library("thermalmgr_proxy") { public_configs = [ ":thermalmgr_ipc_public_config" ] + deps = [ ":thermalmgr_interface" ] external_deps = deps_ex subsystem_name = "powermgr" - innerapi_tags = [ "platformsdk" ] part_name = "thermal_manager" } diff --git a/services/zidl/IThermalSrv.idl b/services/zidl/IThermalSrv.idl new file mode 100644 index 0000000000000000000000000000000000000000..a86f0fe6677ed2d249297c23bcfdb4e107e579a4 --- /dev/null +++ b/services/zidl/IThermalSrv.idl @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +interface OHOS.PowerMgr.IThermalActionCallback; +interface OHOS.PowerMgr.IThermalLevelCallback; +interface OHOS.PowerMgr.IThermalTempCallback; +sequenceable OHOS.PowerMgr.ThermalSrvSensorInfo; + +interface OHOS.PowerMgr.IThermalSrv { + void SubscribeThermalTempCallback([in] String[] typeList, [in] IThermalTempCallback callbackParam); + void UnSubscribeThermalTempCallback([in] IThermalTempCallback callbackParam); + void SubscribeThermalLevelCallback([in] IThermalLevelCallback callbackParam); + void UnSubscribeThermalLevelCallback([in] IThermalLevelCallback callbackParam); + void SubscribeThermalActionCallback([in] String[] actionList, [in] String desc, [in] IThermalActionCallback callbackParam); + void UnSubscribeThermalActionCallback([in] IThermalActionCallback callbackParam); + void GetThermalSrvSensorInfo([in] int type, [out] ThermalSrvSensorInfo sensorInfo, [out] boolean sensorInfoRet); + void GetThermalLevel([out] int level); + void GetThermalInfo([out] boolean thermalInfoRet); + void SetScene([in] String scene); + void UpdateThermalState([in] String tag, [in] String val, [in] boolean isImmed); + void ShellDump([in] String[] args, [in] unsigned int argc, [out] String dumpShell); +} \ No newline at end of file diff --git a/services/zidl/include/thermal_srv_proxy.h b/services/zidl/include/thermal_srv_proxy.h deleted file mode 100644 index 50b3a8bbfe3d3036c2bd8fc849abfa79a8e47a86..0000000000000000000000000000000000000000 --- a/services/zidl/include/thermal_srv_proxy.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef THERMAL_SRV_PROXY_H -#define THERMAL_SRV_PROXY_H - -#include "iremote_broker.h" -#include "iremote_object.h" -#include "iremote_proxy.h" -#include "ithermal_action_callback.h" -#include "ithermal_level_callback.h" -#include "ithermal_srv.h" -#include "nocopyable.h" -#include "refbase.h" -#include "thermal_level_info.h" -#include "thermal_srv_sensor_info.h" -#include -#include -#include -#include - -namespace OHOS { -namespace PowerMgr { -class ThermalSrvProxy : public IRemoteProxy { -public: - explicit ThermalSrvProxy(const sptr& impl) : IRemoteProxy(impl) {} - ~ThermalSrvProxy() = default; - DISALLOW_COPY_AND_MOVE(ThermalSrvProxy); - - virtual bool SubscribeThermalTempCallback( - const std::vector& typeList, const sptr& callback) override; - virtual bool UnSubscribeThermalTempCallback(const sptr& callback) override; - virtual bool SubscribeThermalLevelCallback(const sptr& callback) override; - virtual bool UnSubscribeThermalLevelCallback(const sptr& callback) override; - virtual bool SubscribeThermalActionCallback(const std::vector& actionList, const std::string& desc, - const sptr& callback) override; - virtual bool UnSubscribeThermalActionCallback(const sptr& callback) override; - virtual bool GetThermalSrvSensorInfo(const SensorType& type, ThermalSrvSensorInfo& sensorInfo) override; - virtual bool GetThermalLevel(ThermalLevel& level) override; - virtual bool GetThermalInfo() override; - virtual bool SetScene(const std::string& scene) override; - virtual bool UpdateThermalState(const std::string& tag, const std::string& val, bool isImmed = false) override; - virtual std::string ShellDump(const std::vector& args, uint32_t argc) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace PowerMgr -} // namespace OHOS -#endif // THERMAL_SRV_PROXY_H diff --git a/services/zidl/include/thermal_srv_stub.h b/services/zidl/include/thermal_srv_stub.h deleted file mode 100644 index 072e8bd7a7482db2f7ab4d905454714e6c8ce76c..0000000000000000000000000000000000000000 --- a/services/zidl/include/thermal_srv_stub.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef THERMAL_MGR_SRV_STUB_H -#define THERMAL_MGR_SRV_STUB_H - -#include "ipc_object_stub.h" -#include "ithermal_srv.h" -#include -#include - -namespace OHOS { -namespace PowerMgr { -class ThermalSrvStub : public IRemoteStub { -public: - DISALLOW_COPY_AND_MOVE(ThermalSrvStub); - ThermalSrvStub() = default; - virtual ~ThermalSrvStub() = default; - int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - -private: - int32_t SubscribeThermalTempCallbackStub(MessageParcel& data); - int32_t UnSubscribeThermalTempCallbackStub(MessageParcel& data); - int32_t SubscribeThermalLevelCallbackStub(MessageParcel& data); - int32_t UnSubscribeThermalLevelCallbackStub(MessageParcel& data); - int32_t SubscribeThermalActionCallbackStub(MessageParcel& data); - int32_t UnSubscribeThermalActionCallbackStub(MessageParcel& data); - int32_t GetThermalSrvSensorInfoStub(MessageParcel& data, MessageParcel& reply); - int32_t GetThermalevelStub(MessageParcel& reply); - int32_t GetThermalInfoStub(MessageParcel& reply); - int32_t SetSceneStub(MessageParcel& data); - int32_t UpdateThermalStateStub(MessageParcel& data); - int32_t ShellDumpStub(MessageParcel& data, MessageParcel& reply); - int32_t CheckRequestCode(const uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option); -}; -} // namespace PowerMgr -} // namespace OHOS -#endif // THERMAL_MGR_SRV_STUB_H diff --git a/services/zidl/src/thermal_srv_proxy.cpp b/services/zidl/src/thermal_srv_proxy.cpp deleted file mode 100644 index d7ba3256feffc14fb3abf01269dade637cf01504..0000000000000000000000000000000000000000 --- a/services/zidl/src/thermal_srv_proxy.cpp +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "thermal_srv_proxy.h" - -#include "errors.h" -#include "ithermal_temp_callback.h" -#include "thermal_common.h" -#include "thermal_log.h" -#include "thermal_srv_ipc_interface_code.h" -#include -#include - -namespace OHOS { -namespace PowerMgr { -bool ThermalSrvProxy::SubscribeThermalTempCallback( - const std::vector& typeList, const sptr& callback) -{ - THERMAL_HILOGD(COMP_FWK, "Enter"); - sptr remote = Remote(); - THERMAL_RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor())) { - THERMAL_HILOGE(COMP_FWK, "write descriptor failed!"); - return false; - } - - THERMAL_WRITE_PARCEL_WITH_RET(data, RemoteObject, callback->AsObject(), false); - THERMAL_WRITE_PARCEL_WITH_RET(data, StringVector, typeList, false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::ThermalMgrInterfaceCode::REG_THERMAL_TEMP_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret); - return false; - } - return true; -} - -bool ThermalSrvProxy::UnSubscribeThermalTempCallback(const sptr& callback) -{ - THERMAL_HILOGD(COMP_FWK, "Enter"); - sptr remote = Remote(); - THERMAL_RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor())) { - THERMAL_HILOGE(COMP_FWK, "write descriptor failed!"); - return false; - } - - THERMAL_WRITE_PARCEL_WITH_RET(data, RemoteObject, callback->AsObject(), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::ThermalMgrInterfaceCode::UNREG_THERMAL_TEMP_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret); - return false; - } - return true; -} - -bool ThermalSrvProxy::SubscribeThermalLevelCallback(const sptr& callback) -{ - THERMAL_HILOGD(COMP_FWK, "Enter"); - sptr remote = Remote(); - THERMAL_RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor())) { - THERMAL_HILOGE(COMP_FWK, "write descriptor failed!"); - return false; - } - - THERMAL_WRITE_PARCEL_WITH_RET(data, RemoteObject, callback->AsObject(), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::ThermalMgrInterfaceCode::REG_THERMAL_LEVEL_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret); - return false; - } - return true; -} - -bool ThermalSrvProxy::UnSubscribeThermalLevelCallback(const sptr& callback) -{ - THERMAL_HILOGD(COMP_FWK, "Enter"); - sptr remote = Remote(); - THERMAL_RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor())) { - THERMAL_HILOGE(COMP_FWK, "write descriptor failed!"); - return false; - } - - THERMAL_WRITE_PARCEL_WITH_RET(data, RemoteObject, callback->AsObject(), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::ThermalMgrInterfaceCode::UNREG_THERMAL_LEVEL_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret); - return false; - } - return true; -} - -bool ThermalSrvProxy::SubscribeThermalActionCallback( - const std::vector& actionList, const std::string& desc, const sptr& callback) -{ - THERMAL_HILOGD(COMP_FWK, "Enter"); - sptr remote = Remote(); - THERMAL_RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor())) { - THERMAL_HILOGE(COMP_FWK, "write descriptor failed!"); - return false; - } - - THERMAL_WRITE_PARCEL_WITH_RET(data, RemoteObject, callback->AsObject(), false); - THERMAL_WRITE_PARCEL_WITH_RET(data, StringVector, actionList, false); - THERMAL_WRITE_PARCEL_WITH_RET(data, String, desc, false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::ThermalMgrInterfaceCode::REG_THERMAL_ACTION_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret); - return false; - } - return true; -} - -bool ThermalSrvProxy::UnSubscribeThermalActionCallback(const sptr& callback) -{ - THERMAL_HILOGD(COMP_FWK, "Enter"); - sptr remote = Remote(); - THERMAL_RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor())) { - THERMAL_HILOGE(COMP_FWK, "write descriptor failed!"); - return false; - } - - THERMAL_WRITE_PARCEL_WITH_RET(data, RemoteObject, callback->AsObject(), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::ThermalMgrInterfaceCode::UNREG_THERMAL_ACTION_CALLBACK), - data, reply, option); - if (ret != ERR_OK) { - THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret); - return false; - } - return true; -} - -bool ThermalSrvProxy::GetThermalSrvSensorInfo(const SensorType& type, ThermalSrvSensorInfo& sensorInfo) -{ - THERMAL_HILOGD(COMP_FWK, "Enter"); - sptr remote = Remote(); - if (remote == nullptr) { - return false; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor())) { - THERMAL_HILOGE(COMP_FWK, "write descriptor failed!"); - return false; - } - - THERMAL_WRITE_PARCEL_WITH_RET(data, Uint32, static_cast(type), false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::ThermalMgrInterfaceCode::GET_SENSOR_INFO), data, reply, option); - if (ret != ERR_OK) { - THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret); - return false; - } - - std::unique_ptr info(reply.ReadParcelable()); - if (!info) { - return false; - } - sensorInfo = *info; - return true; -} - -bool ThermalSrvProxy::GetThermalLevel(ThermalLevel& level) -{ - THERMAL_HILOGD(COMP_FWK, "Enter"); - sptr remote = Remote(); - if (remote == nullptr) { - return false; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor())) { - THERMAL_HILOGE(COMP_FWK, "write descriptor failed!"); - return false; - } - - int ret = remote->SendRequest( - static_cast(PowerMgr::ThermalMgrInterfaceCode::GET_TEMP_LEVEL), data, reply, option); - if (ret != ERR_OK) { - THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret); - return false; - } - uint32_t thermalLevel; - THERMAL_READ_PARCEL_WITH_RET(reply, Uint32, thermalLevel, false); - level = static_cast(thermalLevel); - return true; -} - -bool ThermalSrvProxy::GetThermalInfo() -{ - sptr remote = Remote(); - if (remote == nullptr) { - return false; - } - - bool result = false; - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor())) { - THERMAL_HILOGE(COMP_FWK, "write descriptor failed!"); - return result; - } - - int ret = remote->SendRequest( - static_cast(PowerMgr::ThermalMgrInterfaceCode::GET_THERMAL_INFO), data, reply, option); - if (ret != ERR_OK) { - THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret); - return result; - } - if (!reply.ReadBool(result)) { - THERMAL_HILOGE(COMP_FWK, "ReadBool fail"); - } - return true; -} - -bool ThermalSrvProxy::SetScene(const std::string& scene) -{ - THERMAL_HILOGD(COMP_FWK, "Enter"); - sptr remote = Remote(); - if (remote == nullptr) { - return false; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor())) { - THERMAL_HILOGE(COMP_FWK, "write descriptor failed!"); - return false; - } - - THERMAL_WRITE_PARCEL_WITH_RET(data, String, scene, false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::ThermalMgrInterfaceCode::SET_SCENE), data, reply, option); - if (ret != ERR_OK) { - THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret); - return false; - } - return true; -} - -bool ThermalSrvProxy::UpdateThermalState(const std::string& tag, const std::string& val, bool isImmed) -{ - THERMAL_HILOGD(COMP_FWK, "Enter"); - sptr remote = Remote(); - if (remote == nullptr) { - return false; - } - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor())) { - THERMAL_HILOGE(COMP_FWK, "write descriptor failed!"); - return false; - } - - THERMAL_WRITE_PARCEL_WITH_RET(data, String, tag, false); - THERMAL_WRITE_PARCEL_WITH_RET(data, String, val, false); - THERMAL_WRITE_PARCEL_WITH_RET(data, Bool, isImmed, false); - - int ret = remote->SendRequest( - static_cast(PowerMgr::ThermalMgrInterfaceCode::UPDATE_THERMAL_STATE), data, reply, option); - if (ret != ERR_OK) { - THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret); - return false; - } - return true; -} - -std::string ThermalSrvProxy::ShellDump(const std::vector& args, uint32_t argc) -{ - sptr remote = Remote(); - std::string result = "remote error"; - THERMAL_RETURN_IF_WITH_RET(remote == nullptr, result); - - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor())) { - THERMAL_HILOGE(COMP_FWK, "write descriptor failed!"); - return 0; - } - if (argc > args.size()) { - THERMAL_HILOGE(COMP_FWK, "argc is greater than args size!"); - return result; - } - - data.WriteUint32(argc); - for (uint32_t i = 0; i < argc; i++) { - data.WriteString(args[i]); - } - int ret = remote->SendRequest( - static_cast(PowerMgr::ThermalMgrInterfaceCode::SHELL_DUMP), data, reply, option); - if (ret != ERR_OK) { - THERMAL_HILOGE(COMP_FWK, "SendRequest is failed, error code: %{public}d", ret); - return result; - } - result = reply.ReadString(); - return result; -} -} // namespace PowerMgr -} // namespace OHOS diff --git a/services/zidl/src/thermal_srv_stub.cpp b/services/zidl/src/thermal_srv_stub.cpp deleted file mode 100644 index 6ffe71e235d69c5f03cb7323fc37ad2900d504b7..0000000000000000000000000000000000000000 --- a/services/zidl/src/thermal_srv_stub.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "thermal_srv_stub.h" - -#include "message_parcel.h" -#include "string_ex.h" - -#include "ithermal_action_callback.h" -#include "ithermal_temp_callback.h" -#include "ithermal_level_callback.h" -#include "thermal_common.h" -#include "thermal_srv_ipc_interface_code.h" -#include "thermal_srv_sensor_info.h" -#include "xcollie/xcollie.h" - -namespace OHOS { -namespace PowerMgr { -namespace { -constexpr int PARAM_MAX_NUM = 10; -} -int ThermalSrvStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) -{ - THERMAL_HILOGD(COMP_SVC, - "ThermalSrvStub::OnRemoteRequest, cmd = %{public}d, flags = %{public}d", - code, option.GetFlags()); - std::u16string descriptor = ThermalSrvStub::GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - THERMAL_HILOGE(COMP_SVC, "ThermalSrvStub::OnRemoteRequest failed, descriptor is not matched!"); - return E_GET_THERMAL_SERVICE_FAILED; - } - const int DFX_DELAY_S = 60; - int id = HiviewDFX::XCollie::GetInstance().SetTimer("ThermalSrvStub", DFX_DELAY_S, nullptr, nullptr, - HiviewDFX::XCOLLIE_FLAG_LOG); - int32_t ret = CheckRequestCode(code, data, reply, option); - HiviewDFX::XCollie::GetInstance().CancelTimer(id); - return ret; -} - -int32_t ThermalSrvStub::CheckRequestCode(const uint32_t code, MessageParcel& data, MessageParcel& reply, - MessageOption& option) -{ - switch (code) { - case static_cast(PowerMgr::ThermalMgrInterfaceCode::REG_THERMAL_TEMP_CALLBACK): { - return SubscribeThermalTempCallbackStub(data); - } - case static_cast(PowerMgr::ThermalMgrInterfaceCode::UNREG_THERMAL_TEMP_CALLBACK): { - return UnSubscribeThermalTempCallbackStub(data); - } - case static_cast(PowerMgr::ThermalMgrInterfaceCode::REG_THERMAL_LEVEL_CALLBACK): { - return SubscribeThermalLevelCallbackStub(data); - } - case static_cast(PowerMgr::ThermalMgrInterfaceCode::UNREG_THERMAL_LEVEL_CALLBACK): { - return UnSubscribeThermalLevelCallbackStub(data); - } - case static_cast(PowerMgr::ThermalMgrInterfaceCode::REG_THERMAL_ACTION_CALLBACK): { - return SubscribeThermalActionCallbackStub(data); - } - case static_cast(PowerMgr::ThermalMgrInterfaceCode::UNREG_THERMAL_ACTION_CALLBACK): { - return UnSubscribeThermalActionCallbackStub(data); - } - case static_cast(PowerMgr::ThermalMgrInterfaceCode::GET_SENSOR_INFO): { - return GetThermalSrvSensorInfoStub(data, reply); - } - case static_cast(PowerMgr::ThermalMgrInterfaceCode::GET_TEMP_LEVEL): { - return GetThermalevelStub(reply); - } - case static_cast(PowerMgr::ThermalMgrInterfaceCode::GET_THERMAL_INFO): { - return GetThermalInfoStub(reply); - } - case static_cast(PowerMgr::ThermalMgrInterfaceCode::SET_SCENE): { - return SetSceneStub(data); - } - case static_cast(PowerMgr::ThermalMgrInterfaceCode::UPDATE_THERMAL_STATE): { - return UpdateThermalStateStub(data); - } - case static_cast(PowerMgr::ThermalMgrInterfaceCode::SHELL_DUMP): { - return ShellDumpStub(data, reply); - } - default: { - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } - } -} - -int32_t ThermalSrvStub::SubscribeThermalTempCallbackStub(MessageParcel& data) -{ - THERMAL_HILOGD(COMP_SVC, "Enter"); - sptr obj = data.ReadRemoteObject(); - THERMAL_RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR_THERMAL); - sptr callback = iface_cast(obj); - THERMAL_RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR_THERMAL); - std::vector typeList; - if (!data.ReadStringVector(&typeList)) { - THERMAL_HILOGI(COMP_SVC, "failed to read type list"); - return ERR_INVALID_VALUE; - } - SubscribeThermalTempCallback(typeList, callback); - return ERR_OK; -} - -int32_t ThermalSrvStub::UnSubscribeThermalTempCallbackStub(MessageParcel& data) -{ - THERMAL_HILOGD(COMP_SVC, "Enter"); - sptr obj = data.ReadRemoteObject(); - THERMAL_RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR_THERMAL); - sptr callback = iface_cast(obj); - THERMAL_RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR_THERMAL); - UnSubscribeThermalTempCallback(callback); - return ERR_OK; -} - -int32_t ThermalSrvStub::SubscribeThermalLevelCallbackStub(MessageParcel& data) -{ - THERMAL_HILOGD(COMP_SVC, "SubscribeThermalLevelCallbackStub Enter"); - sptr obj = data.ReadRemoteObject(); - THERMAL_RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR_THERMAL); - sptr callback = iface_cast(obj); - THERMAL_RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR_THERMAL); - SubscribeThermalLevelCallback(callback); - return ERR_OK; -} - -int32_t ThermalSrvStub::UnSubscribeThermalLevelCallbackStub(MessageParcel& data) -{ - THERMAL_HILOGD(COMP_SVC, "Enter"); - sptr obj = data.ReadRemoteObject(); - THERMAL_RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR_THERMAL); - sptr callback = iface_cast(obj); - THERMAL_RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR_THERMAL); - UnSubscribeThermalLevelCallback(callback); - return ERR_OK; -} - -int32_t ThermalSrvStub::SubscribeThermalActionCallbackStub(MessageParcel& data) -{ - THERMAL_HILOGD(COMP_SVC, "Enter"); - sptr obj = data.ReadRemoteObject(); - THERMAL_RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR_THERMAL); - sptr callback = iface_cast(obj); - THERMAL_RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR_THERMAL); - - std::vector actionList; - if (!data.ReadStringVector(&actionList)) { - THERMAL_HILOGI(COMP_SVC, "failed to read action list"); - return ERR_INVALID_VALUE; - } - - std::string desc; - THERMAL_READ_PARCEL_WITH_RET(data, String, desc, E_READ_PARCEL_ERROR_THERMAL); - - SubscribeThermalActionCallback(actionList, desc, callback); - return ERR_OK; -} - -int32_t ThermalSrvStub::UnSubscribeThermalActionCallbackStub(MessageParcel& data) -{ - THERMAL_HILOGD(COMP_SVC, "Enter"); - sptr obj = data.ReadRemoteObject(); - THERMAL_RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR_THERMAL); - sptr callback = iface_cast(obj); - THERMAL_RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR_THERMAL); - UnSubscribeThermalActionCallback(callback); - return ERR_OK; -} - -int32_t ThermalSrvStub::GetThermalSrvSensorInfoStub(MessageParcel& data, MessageParcel& reply) -{ - ThermalSrvSensorInfo sensorInfo; - uint32_t type = 0; - - THERMAL_READ_PARCEL_WITH_RET(data, Uint32, type, E_READ_PARCEL_ERROR_THERMAL); - THERMAL_HILOGD(COMP_SVC, "type is %{public}d", type); - bool ret = GetThermalSrvSensorInfo(static_cast(type), sensorInfo); - if (ret) { - if (!reply.WriteParcelable(&sensorInfo)) { - THERMAL_HILOGE(COMP_SVC, "write failed"); - return -1; - } - } - return ERR_OK; -} - -int32_t ThermalSrvStub::GetThermalevelStub(MessageParcel& reply) -{ - THERMAL_HILOGD(COMP_SVC, "Enter"); - ThermalLevel level; - GetThermalLevel(level); - THERMAL_WRITE_PARCEL_WITH_RET(reply, Uint32, static_cast(level), ERR_OK); - return ERR_OK; -} - -int32_t ThermalSrvStub::GetThermalInfoStub(MessageParcel& reply) -{ - THERMAL_HILOGD(COMP_SVC, "Enter"); - bool ret = false; - ret = GetThermalInfo(); - if (!reply.WriteBool(ret)) { - THERMAL_HILOGE(COMP_FWK, "WriteBool fail"); - return E_READ_PARCEL_ERROR_THERMAL; - } - return ERR_OK; -} - -int32_t ThermalSrvStub::SetSceneStub(MessageParcel& data) -{ - THERMAL_HILOGD(COMP_SVC, "Enter"); - std::string scene; - - THERMAL_READ_PARCEL_WITH_RET(data, String, scene, E_READ_PARCEL_ERROR_THERMAL); - SetScene(scene); - return ERR_OK; -} - -int32_t ThermalSrvStub::UpdateThermalStateStub(MessageParcel& data) -{ - THERMAL_HILOGD(COMP_SVC, "Enter"); - std::string tag; - std::string val; - bool isImmed = false; - THERMAL_READ_PARCEL_WITH_RET(data, String, tag, E_READ_PARCEL_ERROR_THERMAL); - THERMAL_READ_PARCEL_WITH_RET(data, String, val, E_READ_PARCEL_ERROR_THERMAL); - THERMAL_READ_PARCEL_WITH_RET(data, Bool, isImmed, E_READ_PARCEL_ERROR_THERMAL); - UpdateThermalState(tag, val, isImmed); - return ERR_OK; -} - -int32_t ThermalSrvStub::ShellDumpStub(MessageParcel& data, MessageParcel& reply) -{ - uint32_t argc; - std::vector args; - - if (!data.ReadUint32(argc)) { - THERMAL_HILOGE(COMP_SVC, "Readback fail!"); - return E_READ_PARCEL_ERROR_THERMAL; - } - - if (argc >= PARAM_MAX_NUM) { - THERMAL_HILOGE(COMP_SVC, "params exceed limit"); - return E_EXCEED_PARAM_LIMIT; - } - - for (uint32_t i = 0; i < argc; i++) { - std::string arg = data.ReadString(); - if (arg.empty()) { - THERMAL_HILOGE(COMP_SVC, "read value fail:%{public}d", i); - return E_READ_PARCEL_ERROR_THERMAL; - } - args.push_back(arg); - } - - std::string ret = ShellDump(args, argc); - if (!reply.WriteString(ret)) { - THERMAL_HILOGE(COMP_SVC, "PowerMgrStub:: Dump Writeback Fail!"); - return E_READ_PARCEL_ERROR_THERMAL; - } - return ERR_OK; -} -} // namespace PowerMgr -} // namespace OHOS diff --git a/test/common/BUILD.gn b/test/common/BUILD.gn index a1052cc97efee8667189032e1b554c6239586396..85e2374b2f8cfa13316b617ac828b3d2d1022523 100644 --- a/test/common/BUILD.gn +++ b/test/common/BUILD.gn @@ -22,7 +22,10 @@ config("module_private_config") { } ohos_shared_library("mock_thermalsrv_client") { - sources = [ "src/mock_thermal_mgr_client.cpp" ] + sources = [ + "${thermal_frameworks}/native/thermal_srv_sensor_info.cpp", + "src/mock_thermal_mgr_client.cpp", + ] configs = [ "${utils_path}:utils_config", diff --git a/test/common/src/mock_thermal_mgr_client.cpp b/test/common/src/mock_thermal_mgr_client.cpp index cd16fb361989415c99411f9ef9d1c4040878ab9d..c25bcc72027a1349885ed717e5d1b6d7e84d0277 100644 --- a/test/common/src/mock_thermal_mgr_client.cpp +++ b/test/common/src/mock_thermal_mgr_client.cpp @@ -97,7 +97,7 @@ bool MockThermalMgrClient::GetThermalInfo() { THERMAL_RETURN_IF_WITH_RET(Connect() != ERR_OK, false); bool ret = false; - ret = thermalSrv_->GetThermalInfo(); + thermalSrv_->GetThermalInfo(ret); THERMAL_HILOGD(COMP_FWK, "Calling GetThermalInfo Success"); return ret; } diff --git a/test/fuzztest/getthermalinfo_fuzzer/getthermalinfo_fuzzer_test.cpp b/test/fuzztest/getthermalinfo_fuzzer/getthermalinfo_fuzzer_test.cpp index 023bbd8e6cc9797a176a5fef8fc4a238a0f92db9..84dc74cb4c18585909c5b17985451cf52b747435 100644 --- a/test/fuzztest/getthermalinfo_fuzzer/getthermalinfo_fuzzer_test.cpp +++ b/test/fuzztest/getthermalinfo_fuzzer/getthermalinfo_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "getthermalinfo_fuzzer" #include "thermal_fuzzer_test.h" -#include "thermal_srv_ipc_interface_code.h" +#include "ithermal_srv.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ ThermalFuzzerTest g_serviceTest; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - g_serviceTest.TestThermalServiceStub(static_cast(ThermalMgrInterfaceCode::GET_THERMAL_INFO), data, size); + g_serviceTest.TestThermalServiceStub( + static_cast(IThermalSrvIpcCode::COMMAND_GET_THERMAL_INFO), data, size); return 0; } diff --git a/test/fuzztest/getthermallevel_fuzzer/getthermallevel_fuzzer_test.cpp b/test/fuzztest/getthermallevel_fuzzer/getthermallevel_fuzzer_test.cpp index d0597f524d2929e5a4bba006dd44e2689324adb4..fd2a0889025569c0b244cf6bcfac220f0609bd3a 100644 --- a/test/fuzztest/getthermallevel_fuzzer/getthermallevel_fuzzer_test.cpp +++ b/test/fuzztest/getthermallevel_fuzzer/getthermallevel_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "getthermallevel_fuzzer" #include "thermal_fuzzer_test.h" -#include "thermal_srv_ipc_interface_code.h" +#include "ithermal_srv.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ ThermalFuzzerTest g_serviceTest; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - g_serviceTest.TestThermalServiceStub(static_cast(ThermalMgrInterfaceCode::GET_TEMP_LEVEL), data, size); + g_serviceTest.TestThermalServiceStub( + static_cast(IThermalSrvIpcCode::COMMAND_GET_THERMAL_LEVEL), data, size); return 0; } diff --git a/test/fuzztest/getthermalsensortemp_fuzzer/getthermalsensortemp_fuzzer_test.cpp b/test/fuzztest/getthermalsensortemp_fuzzer/getthermalsensortemp_fuzzer_test.cpp index d2898bc8254fb9bcb035b86d2f3e75f2cecb459e..b39e85c35c781675b835ff28fd17ac9b3fa0dcc7 100644 --- a/test/fuzztest/getthermalsensortemp_fuzzer/getthermalsensortemp_fuzzer_test.cpp +++ b/test/fuzztest/getthermalsensortemp_fuzzer/getthermalsensortemp_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "getthermalsensortemp_fuzzer" #include "thermal_fuzzer_test.h" -#include "thermal_srv_ipc_interface_code.h" +#include "ithermal_srv.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,7 @@ ThermalFuzzerTest g_serviceTest; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - g_serviceTest.TestThermalServiceStub(static_cast(ThermalMgrInterfaceCode::GET_SENSOR_INFO), data, size); + g_serviceTest.TestThermalServiceStub( + static_cast(IThermalSrvIpcCode::COMMAND_GET_THERMAL_SRV_SENSOR_INFO), data, size); return 0; } diff --git a/test/fuzztest/setscene_fuzzer/setscene_fuzzer_test.cpp b/test/fuzztest/setscene_fuzzer/setscene_fuzzer_test.cpp index 9785c9848daf19d136d7f8ec1598e1bd743b6fd1..7e3413c71389cb9cfeba7c08d56187788ec50fde 100644 --- a/test/fuzztest/setscene_fuzzer/setscene_fuzzer_test.cpp +++ b/test/fuzztest/setscene_fuzzer/setscene_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "setscene_fuzzer" #include "thermal_fuzzer_test.h" -#include "thermal_srv_ipc_interface_code.h" +#include "ithermal_srv.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,6 @@ ThermalFuzzerTest g_serviceTest; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - g_serviceTest.TestThermalServiceStub(static_cast(ThermalMgrInterfaceCode::SET_SCENE), data, size); + g_serviceTest.TestThermalServiceStub(static_cast(IThermalSrvIpcCode::COMMAND_SET_SCENE), data, size); return 0; } diff --git a/test/fuzztest/thermalactioncallback_fuzzer/thermalactioncallback_fuzzer_test.cpp b/test/fuzztest/thermalactioncallback_fuzzer/thermalactioncallback_fuzzer_test.cpp index 70037041f333b47654dd1978c41ffcd22b18e283..ce5c5c892bac3d2489106158ef870e95746855bf 100644 --- a/test/fuzztest/thermalactioncallback_fuzzer/thermalactioncallback_fuzzer_test.cpp +++ b/test/fuzztest/thermalactioncallback_fuzzer/thermalactioncallback_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "thermalactioncallback_fuzzer" #include "thermal_fuzzer_test.h" -#include "thermal_srv_ipc_interface_code.h" +#include "ithermal_srv.h" using namespace OHOS::PowerMgr; @@ -31,8 +31,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ g_serviceTest.TestThermalServiceStub( - static_cast(ThermalMgrInterfaceCode::REG_THERMAL_ACTION_CALLBACK), data, size); + static_cast(IThermalSrvIpcCode::COMMAND_SUBSCRIBE_THERMAL_ACTION_CALLBACK), data, size); g_serviceTest.TestThermalServiceStub( - static_cast(ThermalMgrInterfaceCode::UNREG_THERMAL_ACTION_CALLBACK), data, size); + static_cast(IThermalSrvIpcCode::COMMAND_UN_SUBSCRIBE_THERMAL_ACTION_CALLBACK), data, size); return 0; } diff --git a/test/fuzztest/thermaldump_fuzzer/thermaldump_fuzzer_test.cpp b/test/fuzztest/thermaldump_fuzzer/thermaldump_fuzzer_test.cpp index 065f298d89f53800b49a1cf09a563e2a7ecae571..6f88d4d190a6af2c1b203d501bf72ccafa9e65c5 100644 --- a/test/fuzztest/thermaldump_fuzzer/thermaldump_fuzzer_test.cpp +++ b/test/fuzztest/thermaldump_fuzzer/thermaldump_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "thermaldump_fuzzer" #include "thermal_fuzzer_test.h" -#include "thermal_srv_ipc_interface_code.h" +#include "ithermal_srv.h" using namespace OHOS::PowerMgr; @@ -30,6 +30,6 @@ ThermalFuzzerTest g_serviceTest; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ - g_serviceTest.TestThermalServiceStub(static_cast(ThermalMgrInterfaceCode::SHELL_DUMP), data, size); + g_serviceTest.TestThermalServiceStub(static_cast(IThermalSrvIpcCode::COMMAND_SHELL_DUMP), data, size); return 0; } diff --git a/test/fuzztest/thermallevelcallback_fuzzer/thermallevelcallback_fuzzer_test.cpp b/test/fuzztest/thermallevelcallback_fuzzer/thermallevelcallback_fuzzer_test.cpp index fc528efbcd51b0548c0e324ddc4d618a15b274e9..500dcd8de370db3032aae977f5fb38b1a72dcae0 100644 --- a/test/fuzztest/thermallevelcallback_fuzzer/thermallevelcallback_fuzzer_test.cpp +++ b/test/fuzztest/thermallevelcallback_fuzzer/thermallevelcallback_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "thermallevelcallback_fuzzer" #include "thermal_fuzzer_test.h" -#include "thermal_srv_ipc_interface_code.h" +#include "ithermal_srv.h" using namespace OHOS::PowerMgr; @@ -31,8 +31,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ g_serviceTest.TestThermalServiceStub( - static_cast(ThermalMgrInterfaceCode::REG_THERMAL_LEVEL_CALLBACK), data, size); + static_cast(IThermalSrvIpcCode::COMMAND_SUBSCRIBE_THERMAL_LEVEL_CALLBACK), data, size); g_serviceTest.TestThermalServiceStub( - static_cast(ThermalMgrInterfaceCode::UNREG_THERMAL_LEVEL_CALLBACK), data, size); + static_cast(IThermalSrvIpcCode::COMMAND_UN_SUBSCRIBE_THERMAL_LEVEL_CALLBACK), data, size); return 0; } diff --git a/test/fuzztest/thermaltempcallback_fuzzer/thermaltempcallback_fuzzer_test.cpp b/test/fuzztest/thermaltempcallback_fuzzer/thermaltempcallback_fuzzer_test.cpp index 0be3c3f8131866fab90b33912dc6e6beb69cec4c..f92a04a3ef3c3a3c7151eb82da3b4ded319893e7 100644 --- a/test/fuzztest/thermaltempcallback_fuzzer/thermaltempcallback_fuzzer_test.cpp +++ b/test/fuzztest/thermaltempcallback_fuzzer/thermaltempcallback_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "thermaltempcallback_fuzzer" #include "thermal_fuzzer_test.h" -#include "thermal_srv_ipc_interface_code.h" +#include "ithermal_srv.h" using namespace OHOS::PowerMgr; @@ -31,8 +31,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ g_serviceTest.TestThermalServiceStub( - static_cast(ThermalMgrInterfaceCode::REG_THERMAL_TEMP_CALLBACK), data, size); + static_cast(IThermalSrvIpcCode::COMMAND_SUBSCRIBE_THERMAL_TEMP_CALLBACK), data, size); g_serviceTest.TestThermalServiceStub( - static_cast(ThermalMgrInterfaceCode::UNREG_THERMAL_TEMP_CALLBACK), data, size); + static_cast(IThermalSrvIpcCode::COMMAND_UN_SUBSCRIBE_THERMAL_TEMP_CALLBACK), data, size); return 0; } diff --git a/test/fuzztest/updatethermalstate_fuzzer/updatethermalstate_fuzzer_test.cpp b/test/fuzztest/updatethermalstate_fuzzer/updatethermalstate_fuzzer_test.cpp index 81be3e0481e305f318f5d8a1622140ff74db5c66..ada12aa56013a50820f92243f651c7602131aa7a 100644 --- a/test/fuzztest/updatethermalstate_fuzzer/updatethermalstate_fuzzer_test.cpp +++ b/test/fuzztest/updatethermalstate_fuzzer/updatethermalstate_fuzzer_test.cpp @@ -18,7 +18,7 @@ #define FUZZ_PROJECT_NAME "updatethermalstate_fuzzer" #include "thermal_fuzzer_test.h" -#include "thermal_srv_ipc_interface_code.h" +#include "ithermal_srv.h" using namespace OHOS::PowerMgr; @@ -31,6 +31,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ g_serviceTest.TestThermalServiceStub( - static_cast(ThermalMgrInterfaceCode::UPDATE_THERMAL_STATE), data, size); + static_cast(IThermalSrvIpcCode::COMMAND_UPDATE_THERMAL_STATE), data, size); return 0; } diff --git a/test/systemtest/BUILD.gn b/test/systemtest/BUILD.gn index 7beb8088616ea2e73b51f413b3e2cc92221bdb92..893a9daab1c2fbdc5ee39c008853d7386e34932f 100644 --- a/test/systemtest/BUILD.gn +++ b/test/systemtest/BUILD.gn @@ -108,6 +108,7 @@ ohos_systemtest("ThermalMgrSystemTest") { ] configs = [ + "${thermal_service_zidl}:thermalmgr_ipc_public_config", "${utils_path}:utils_config", "${utils_path}:coverage_flags", ] @@ -121,6 +122,7 @@ ohos_systemtest("ThermalMgrSystemTest") { "${thermal_manager_path}/services/native/include/thermal_policy", "${thermal_manager_path}/services/native/include/thermal_observer/state_machine", "${thermal_manager_path}/services/native/include/thermal_action/action", + "${thermal_manager_path}/test/common/include", "${thermal_manager_path}/test/unittest/include", ] @@ -206,6 +208,7 @@ ohos_systemtest("ThermalLevelEventSystemTest") { "${thermal_inner_api}:thermalsrv_client", "${thermal_manager_path}/services:thermalservice", "${thermal_manager_path}/test/common:mock_thermalsrv_client", + "${thermal_service_zidl}:thermalmgr_stub", ] external_deps = deps_ex diff --git a/test/systemtest/src/thermal_mgr_interface_test.cpp b/test/systemtest/src/thermal_mgr_interface_test.cpp index f7a04e654a2ba7dceb8a2475a31eb3a72c000a86..27e28f2bf9a175ac4a797e6fc6c89af0d52ab050 100644 --- a/test/systemtest/src/thermal_mgr_interface_test.cpp +++ b/test/systemtest/src/thermal_mgr_interface_test.cpp @@ -204,7 +204,8 @@ HWTEST_F(ThermalMgrInterfaceTest, ThermalMgrInterfaceTest001, TestSize.Level0) event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); ThermalSrvSensorInfo info; - g_service->GetThermalSrvSensorInfo(SensorType::BATTERY, info); + bool thermalInfoRet = false; + g_service->GetThermalSrvSensorInfo(static_cast(SensorType::BATTERY), info, thermalInfoRet); g_thermalMgrClient.GetThermalSensorTemp(SensorType::BATTERY); EXPECT_EQ(info1.temp, info.GetTemp()) << "ThermalMgrInterfaceTest001 Failed"; THERMAL_HILOGI(LABEL_TEST, "ThermalMgrInterfaceTest001 function end!"); @@ -225,7 +226,8 @@ HWTEST_F(ThermalMgrInterfaceTest, ThermalMgrInterfaceTest002, TestSize.Level0) event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); ThermalSrvSensorInfo info; - g_service->GetThermalSrvSensorInfo(SensorType::SOC, info); + bool thermalInfoRet = false; + g_service->GetThermalSrvSensorInfo(static_cast(SensorType::SOC), info, thermalInfoRet); g_thermalMgrClient.GetThermalSensorTemp(SensorType::SOC); EXPECT_EQ(info1.temp, info.GetTemp()) << "ThermalMgrInterfaceTest002 Failed"; THERMAL_HILOGI(LABEL_TEST, "ThermalMgrInterfaceTest002 function end!"); @@ -246,7 +248,8 @@ HWTEST_F(ThermalMgrInterfaceTest, ThermalMgrInterfaceTest003, TestSize.Level0) event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); ThermalSrvSensorInfo info; - g_service->GetThermalSrvSensorInfo(SensorType::SHELL, info); + bool thermalInfoRet = false; + g_service->GetThermalSrvSensorInfo(static_cast(SensorType::SHELL), info, thermalInfoRet); g_thermalMgrClient.GetThermalSensorTemp(SensorType::SHELL); EXPECT_EQ(info1.temp, info.GetTemp()) << "ThermalMgrInterfaceTest003 Failed"; THERMAL_HILOGI(LABEL_TEST, "ThermalMgrInterfaceTest003 function end!"); @@ -267,7 +270,8 @@ HWTEST_F(ThermalMgrInterfaceTest, ThermalMgrInterfaceTest004, TestSize.Level0) event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); ThermalSrvSensorInfo info; - g_service->GetThermalSrvSensorInfo(SensorType::SENSOR1, info); + bool thermalInfoRet = false; + g_service->GetThermalSrvSensorInfo(static_cast(SensorType::SENSOR1), info, thermalInfoRet); g_thermalMgrClient.GetThermalSensorTemp(SensorType::SENSOR1); EXPECT_EQ(info1.temp, info.GetTemp()) << "ThermalMgrInterfaceTest004 Failed"; THERMAL_HILOGI(LABEL_TEST, "ThermalMgrInterfaceTest004 function end!"); @@ -288,7 +292,8 @@ HWTEST_F(ThermalMgrInterfaceTest, ThermalMgrInterfaceTest005, TestSize.Level0) event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); ThermalSrvSensorInfo info; - g_service->GetThermalSrvSensorInfo(SensorType::SENSOR2, info); + bool thermalInfoRet = false; + g_service->GetThermalSrvSensorInfo(static_cast(SensorType::SENSOR2), info, thermalInfoRet); g_thermalMgrClient.GetThermalSensorTemp(SensorType::SENSOR2); EXPECT_EQ(info1.temp, info.GetTemp()) << "ThermalMgrInterfaceTest005 Failed"; THERMAL_HILOGI(LABEL_TEST, "ThermalMgrInterfaceTest005 function end!"); @@ -560,7 +565,8 @@ HWTEST_F(ThermalMgrInterfaceTest, ThermalMgrInterfaceTest012, TestSize.Level0) g_service->HandleThermalCallbackEvent(event); g_thermalMgrClient.GetThermalSensorTemp(SensorType::BATTERY); ThermalSrvSensorInfo info; - g_service->GetThermalSrvSensorInfo(SensorType::BATTERY, info); + bool thermalInfoRet = false; + g_service->GetThermalSrvSensorInfo(static_cast(SensorType::BATTERY), info, thermalInfoRet); EXPECT_EQ(INVAILD_TEMP, info.GetTemp()) << "ThermalMgrInterfaceTest012 Failed"; THERMAL_HILOGI(LABEL_TEST, "ThermalMgrInterfaceTest012 function end!"); } @@ -584,7 +590,7 @@ HWTEST_F(ThermalMgrInterfaceTest, ThermalMgrInterfaceTest013, TestSize.Level0) event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); g_thermalMgrClient.UnSubscribeThermalTempCallback(cb); - EXPECT_TRUE(g_service->UnSubscribeThermalTempCallback(cb)); + EXPECT_EQ(g_service->UnSubscribeThermalTempCallback(cb), ERR_OK); THERMAL_HILOGI(LABEL_TEST, "ThermalMgrInterfaceTest013 function end!"); } @@ -606,7 +612,7 @@ HWTEST_F(ThermalMgrInterfaceTest, ThermalMgrInterfaceTest014, TestSize.Level0) event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); g_thermalMgrClient.UnSubscribeThermalLevelCallback(cb); - EXPECT_TRUE(g_service->UnSubscribeThermalLevelCallback(cb)); + EXPECT_EQ(g_service->UnSubscribeThermalLevelCallback(cb), ERR_OK); THERMAL_HILOGI(LABEL_TEST, "ThermalMgrInterfaceTest014 function end!"); } @@ -628,8 +634,9 @@ HWTEST_F(ThermalMgrInterfaceTest, ThermalMgrInterfaceTest015, TestSize.Level0) event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); g_thermalMgrClient.GetThermalLevel(); - ThermalLevel level; - g_service->GetThermalLevel(level); + int32_t levelValue; + g_service->GetThermalLevel(levelValue); + ThermalLevel level = static_cast(levelValue); GTEST_LOG_(INFO) << "test thermal temp: " << temps[i]; EXPECT_EQ(level, levels[i]) << "ThermalMgrInterfaceTest015 Failed"; } @@ -654,8 +661,9 @@ HWTEST_F(ThermalMgrInterfaceTest, ThermalMgrInterfaceTest016, TestSize.Level0) event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); g_thermalMgrClient.GetThermalLevel(); - ThermalLevel level; - g_service->GetThermalLevel(level); + int32_t levelValue; + g_service->GetThermalLevel(levelValue); + ThermalLevel level = static_cast(levelValue); EXPECT_EQ(level, ThermalLevel::OVERHEATED) << "ThermalMgrInterfaceTest016 Failed"; THERMAL_HILOGI(LABEL_TEST, "ThermalMgrInterfaceTest016 function end!"); } @@ -678,8 +686,9 @@ HWTEST_F(ThermalMgrInterfaceTest, ThermalMgrInterfaceTest017, TestSize.Level0) event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); g_thermalMgrClient.GetThermalLevel(); - ThermalLevel level; - g_service->GetThermalLevel(level); + int32_t levelValue; + g_service->GetThermalLevel(levelValue); + ThermalLevel level = static_cast(levelValue); EXPECT_EQ(level, ThermalLevel::WARNING) << "ThermalMgrInterfaceTest017 Failed"; THERMAL_HILOGI(LABEL_TEST, "ThermalMgrInterfaceTest017 function end!"); } @@ -706,8 +715,9 @@ HWTEST_F(ThermalMgrInterfaceTest, ThermalMgrInterfaceTest018, TestSize.Level0) event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); g_thermalMgrClient.GetThermalLevel(); - ThermalLevel level; - g_service->GetThermalLevel(level); + int32_t levelValue; + g_service->GetThermalLevel(levelValue); + ThermalLevel level = static_cast(levelValue); EXPECT_EQ(level, ThermalLevel::EMERGENCY) << "ThermalMgrInterfaceTest018 Failed"; THERMAL_HILOGI(LABEL_TEST, "ThermalMgrInterfaceTest018 function end!"); } @@ -730,8 +740,9 @@ HWTEST_F(ThermalMgrInterfaceTest, ThermalMgrInterfaceTest019, TestSize.Level0) event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); g_thermalMgrClient.GetThermalLevel(); - ThermalLevel level; - g_service->GetThermalLevel(level); + int32_t levelValue; + g_service->GetThermalLevel(levelValue); + ThermalLevel level = static_cast(levelValue); EXPECT_EQ(level, ThermalLevel::ESCAPE) << "ThermalMgrInterfaceTest019 Failed"; THERMAL_HILOGI(LABEL_TEST, "ThermalMgrInterfaceTest019 function end!"); } @@ -753,7 +764,7 @@ HWTEST_F(ThermalMgrInterfaceTest, ThermalMgrInterfaceTest020, TestSize.Level0) std::map stateMap {{tag1, val1}}; bool result = g_service->GetPolicy()->StateMachineDecision(stateMap); EXPECT_TRUE(result == true); - + HdfThermalCallbackInfo event; ThermalZoneInfo info1; info1.type = "battery"; diff --git a/test/systemtest/src/thermal_mgr_system_test.cpp b/test/systemtest/src/thermal_mgr_system_test.cpp index 6c3aff9eb98d28040c4c4a164a166a4b6ee4fd87..fac1ab36fba796fb6510ef302f60f7859e432641 100644 --- a/test/systemtest/src/thermal_mgr_system_test.cpp +++ b/test/systemtest/src/thermal_mgr_system_test.cpp @@ -364,7 +364,7 @@ HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest005, Function|MediumTest|Lev level = levelValue; value = ThermalMgrSystemTest::ConvertInt(level); EXPECT_EQ(true, value == 1) << "ThermalMgrSystemTest005 failed"; - + ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str()); EXPECT_EQ(true, ret >= EOK); GetSensorClusterName("base_safe", "battery", 4); @@ -418,7 +418,7 @@ HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest006, Function|MediumTest|Lev level = levelValue; value = ThermalMgrSystemTest::ConvertInt(level); EXPECT_EQ(true, value == 2) << "ThermalMgrSystemTest006 failed"; - + ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str()); EXPECT_EQ(true, ret >= EOK); GetSensorClusterName("base_safe", "battery", 4); @@ -472,7 +472,7 @@ HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest007, Function|MediumTest|Lev level = levelValue; value = ThermalMgrSystemTest::ConvertInt(level); EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest007 failed"; - + ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str()); EXPECT_EQ(true, ret >= EOK); GetSensorClusterName("base_safe", "battery", 1); @@ -526,7 +526,7 @@ HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest008, Function|MediumTest|Lev level = levelValue; value = ThermalMgrSystemTest::ConvertInt(level); EXPECT_EQ(true, value == 3) << "ThermalMgrSystemTest008 failed"; - + ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str()); EXPECT_EQ(true, ret >= EOK); GetSensorClusterName("base_safe", "battery", 1); @@ -837,7 +837,7 @@ HWTEST_F (ThermalMgrSystemTest, ThermalMgrSystemTest015, Function|MediumTest|Lev level = levelValue; value = ThermalMgrSystemTest::ConvertInt(level); EXPECT_EQ(true, value == 4) << "ThermalMgrSystemTest015 failed"; - + ret = snprintf_s(batteryTempBuf, MAX_PATH, sizeof(batteryTempBuf) - 1, BATTERY_PATH.c_str()); EXPECT_EQ(true, ret >= EOK); GetSensorClusterName("cold_safe", "battery", 1); diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 1dae0135c7eef4dcc7affac9792262a643e85ff2..26c7612eda7611e7cb97c8cd52fdd355f4f60719 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -70,6 +70,12 @@ deps_ex = [ # thermal mock action test ohos_unittest("ThermalMockActionTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -90,6 +96,7 @@ ohos_unittest("ThermalMockActionTest") { "${thermal_inner_api}:thermalsrv_client", "${thermal_manager_path}/services:thermalservice", "${thermal_manager_path}/test/common:mock_thermalsrv_client", + "${thermal_service_zidl}:thermalmgr_stub", ] external_deps = deps_ex @@ -114,6 +121,12 @@ ohos_unittest("ThermalMockActionTest") { # thermal policy test ohos_unittest("ThermalMgrPolicyTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -150,6 +163,12 @@ ohos_unittest("ThermalMgrPolicyTest") { # thermal level event test ohos_unittest("ThermalLevelEventTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -168,6 +187,7 @@ ohos_unittest("ThermalLevelEventTest") { "${thermal_inner_api}:thermalsrv_client", "${thermal_manager_path}/services:thermalservice", "${thermal_manager_path}/test/common:mock_thermalsrv_client", + "${thermal_service_zidl}:thermalmgr_stub", ] external_deps = deps_ex @@ -192,6 +212,12 @@ ohos_unittest("ThermalLevelEventTest") { # thermal client api test ohos_unittest("ThermalClientApiTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ "src/thermal_client_api_test.cpp" ] @@ -206,6 +232,7 @@ ohos_unittest("ThermalClientApiTest") { "${thermal_inner_api}:thermalsrv_client", "${thermal_manager_path}/services:thermalservice", "${thermal_manager_path}/test/common:mock_thermalsrv_client", + "${thermal_service_zidl}:thermalmgr_stub", ] external_deps = deps_ex @@ -224,6 +251,12 @@ ohos_unittest("ThermalClientApiTest") { # thermal action hub test ohos_unittest("ThermalActionHubTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -261,6 +294,12 @@ ohos_unittest("ThermalActionHubTest") { # thermal action report test ohos_unittest("ThermalActionReportTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -279,6 +318,7 @@ ohos_unittest("ThermalActionReportTest") { "${thermal_inner_api}:thermalsrv_client", "${thermal_manager_path}/services:thermalservice", "${thermal_manager_path}/test/common:mock_thermalsrv_client", + "${thermal_service_zidl}:thermalmgr_stub", ] if (defined(global_parts_info) && @@ -313,6 +353,12 @@ ohos_unittest("ThermalActionReportTest") { # thermal mock proxy test ohos_unittest("ThermalMockProxyTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -349,6 +395,12 @@ ohos_unittest("ThermalMockProxyTest") { # thermal mock proxy remote test ohos_unittest("ThermalMockProxyRemoteTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -386,6 +438,12 @@ ohos_unittest("ThermalMockProxyRemoteTest") { # thermal mock proxy writeinterfacetoken test ohos_unittest("ThermalMockProxyWriteinterfacetokenTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -425,6 +483,12 @@ ohos_unittest("ThermalMockProxyWriteinterfacetokenTest") { # thermal mock proxy writeremoteobject test ohos_unittest("ThermalMockProxyWriteremoteobjectTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -465,6 +529,12 @@ ohos_unittest("ThermalMockProxyWriteremoteobjectTest") { # thermal mock proxy writevector test ohos_unittest("ThermalMockProxyWritevectorTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -505,6 +575,12 @@ ohos_unittest("ThermalMockProxyWritevectorTest") { # thermal mock proxy sendrequest test ohos_unittest("ThermalMockProxySendrequestTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -544,6 +620,12 @@ ohos_unittest("ThermalMockProxySendrequestTest") { # thermal utils test ohos_unittest("ThermalUtilsTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ "src/thermal_utils_test.cpp" ] @@ -577,6 +659,12 @@ ohos_unittest("ThermalUtilsTest") { # thermal application test ohos_unittest("ThermalApplicationTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -610,6 +698,12 @@ ohos_unittest("ThermalApplicationTest") { # thermal service death test ohos_unittest("ThermalServiceDeathTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -648,6 +742,12 @@ ohos_unittest("ThermalServiceDeathTest") { # thermal listener test ohos_unittest("ThermalListenerTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -686,6 +786,12 @@ ohos_unittest("ThermalListenerTest") { # thermal client test ohos_unittest("ThermalClientTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -743,6 +849,12 @@ ohos_unittest("ThermalClientTest") { # thermal mock stub test ohos_unittest("ThermalMockStubTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path defines += [ "THERMAL_GTEST" ] sources = [ "src/thermal_mock_stub_test.cpp" ] @@ -776,6 +888,12 @@ ohos_unittest("ThermalMockStubTest") { # thermal mock stub getdescriptor test ohos_unittest("ThermalMockStubGetdescriptorTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ "src/thermal_mock_stub_getdescriptor_test.cpp" ] @@ -809,6 +927,12 @@ ohos_unittest("ThermalMockStubGetdescriptorTest") { # thermal action test ohos_unittest("ThermalActionTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -847,6 +971,12 @@ ohos_unittest("ThermalActionTest") { # thermal observer test ohos_unittest("ThermalObserverTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path sources = [ @@ -891,6 +1021,12 @@ ohos_unittest("ThermalObserverTest") { # thermal service test ohos_unittest("ThermalServiceTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path defines += [ "THERMAL_GTEST" ] sources = [ "src/thermal_service_test.cpp" ] @@ -924,6 +1060,12 @@ ohos_unittest("ThermalServiceTest") { # thermal config sensor cluster test ohos_unittest("ThermalConfigSensorClusterTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path defines += [ "THERMAL_GTEST" ] sources = [ "src/thermal_config_sensor_cluster_test.cpp" ] @@ -957,6 +1099,12 @@ ohos_unittest("ThermalConfigSensorClusterTest") { # thermal mgr dump test ohos_unittest("ThermalMgrDumpTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path defines += [ "THERMAL_GTEST" ] sources = [ "src/thermal_mgr_dump_test.cpp" ] @@ -990,6 +1138,12 @@ ohos_unittest("ThermalMgrDumpTest") { # thermal policy test ohos_unittest("ThermalPolicyTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path defines += [ "THERMAL_GTEST" ] sources = [ "src/thermal_policy_test.cpp" ] @@ -1023,6 +1177,12 @@ ohos_unittest("ThermalPolicyTest") { # fan fault detect test ohos_unittest("FanFaultDetectTest") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path defines += [ "THERMAL_GTEST" ] sources = [ "src/fan_fault_detect_test.cpp" ] diff --git a/test/unittest/include/thermal_mock_stub_test.h b/test/unittest/include/thermal_mock_stub_test.h index 7289dcd954de3dc9fe03ffeaffe526484d156516..af66b7a81d3a7ebdb47f67d644b61a632e1bcd0d 100644 --- a/test/unittest/include/thermal_mock_stub_test.h +++ b/test/unittest/include/thermal_mock_stub_test.h @@ -23,6 +23,8 @@ namespace PowerMgr { class ThermalMockStubTest : public testing::Test { public: static void SetUpTestCase(); +protected: + const int VECTOR_MAX_SIZE = 102400; }; } // namespace PowerMgr } // namespace OHOS diff --git a/test/unittest/src/thermal_action_report_test.cpp b/test/unittest/src/thermal_action_report_test.cpp index f75229366e70c8b91d78f9df8ccae7621173871c..b904a7eb464f2dcbf57fb0d6377af431208c0f06 100644 --- a/test/unittest/src/thermal_action_report_test.cpp +++ b/test/unittest/src/thermal_action_report_test.cpp @@ -80,9 +80,8 @@ int32_t ThermalActionReportTest::SetCondition(int32_t value, const std::string& int32_t ThermalActionReportTest::GetThermalLevel(int32_t expectValue) { - ThermalLevel level; - g_service->GetThermalLevel(level); - int32_t value = static_cast(level); + int32_t value; + g_service->GetThermalLevel(value); THERMAL_HILOGI(LABEL_TEST, "value: %{public}d", value); EXPECT_EQ(value, expectValue) << "Thermal action policy failed"; return value; diff --git a/test/unittest/src/thermal_client_api_test.cpp b/test/unittest/src/thermal_client_api_test.cpp index 39046e99cc78933920c3f16d4eadd04729b46919..ab0609fb55cc260dc12fddcf6690965421ac244e 100644 --- a/test/unittest/src/thermal_client_api_test.cpp +++ b/test/unittest/src/thermal_client_api_test.cpp @@ -40,7 +40,7 @@ HWTEST_F(ThermalClientApiTest, ThermalClientApiTest_001, TestSize.Level0) std::string result = thermalMgrClient.Dump(cmdsList); THERMAL_HILOGI(LABEL_TEST, "result : %{public}s", result.c_str()); - EXPECT_EQ(true, result == "remote error"); + EXPECT_EQ(true, result == ""); THERMAL_HILOGI(LABEL_TEST, "ThermalClientApiTest_001 function end!"); } diff --git a/test/unittest/src/thermal_config_sensor_cluster_test.cpp b/test/unittest/src/thermal_config_sensor_cluster_test.cpp index e27c301b7c9be7064d8b017b01705c2799770b55..f33d499bbca9a83cfe4a3c0f55b43f58b8f9adfd 100644 --- a/test/unittest/src/thermal_config_sensor_cluster_test.cpp +++ b/test/unittest/src/thermal_config_sensor_cluster_test.cpp @@ -316,6 +316,7 @@ HWTEST_F(ThermalConfigSensorClusterTest, ThermalConfigSensorClusterTest009, Test cluster.auxSensorInfolist_["test1"] = auxLevel; level = 1; EXPECT_FALSE(cluster.IsAuxSensorTrigger(typeTempInfo, level)); + EXPECT_EQ(level, 1); AuxLevelItem item; item.lowerTemp = 1; @@ -328,6 +329,7 @@ HWTEST_F(ThermalConfigSensorClusterTest, ThermalConfigSensorClusterTest009, Test typeTempInfo["test2"] = 5; // The range is not lowerTemp or upperTemp level = 1; EXPECT_FALSE(cluster.IsAuxSensorTrigger(typeTempInfo, level)); + EXPECT_EQ(level, 1); THERMAL_HILOGI(LABEL_TEST, "ThermalConfigSensorClusterTest009 function end!"); } diff --git a/test/unittest/src/thermal_listener_test.cpp b/test/unittest/src/thermal_listener_test.cpp index d12cbea562241ac0d4bf81de910fe49dc5ae329f..2e7fd090b09facfd3e815f8065f3f63da54a8a3b 100644 --- a/test/unittest/src/thermal_listener_test.cpp +++ b/test/unittest/src/thermal_listener_test.cpp @@ -98,8 +98,9 @@ HWTEST_F(ThermalListenerTest, ThermalListenerTest001, TestSize.Level0) g_service->UnSubscribeThermalLevelCallback(callback); thermalListener->GetThermalLevel(); - ThermalLevel level; - g_service->GetThermalLevel(level); + int32_t levelValue; + g_service->GetThermalLevel(levelValue); + ThermalLevel level = static_cast(levelValue); EXPECT_EQ(g_thermalLevel, level); THERMAL_HILOGI(LABEL_TEST, "ThermalListenerTest001 function end!"); } diff --git a/test/unittest/src/thermal_mgr_policy_test.cpp b/test/unittest/src/thermal_mgr_policy_test.cpp index 9052388b052b5966fdbd4a75e97a4a9ab730b5ff..0e6b1486869b3ab025cbafbc28b15ad0cc2fa198 100644 --- a/test/unittest/src/thermal_mgr_policy_test.cpp +++ b/test/unittest/src/thermal_mgr_policy_test.cpp @@ -1710,7 +1710,9 @@ HWTEST_F (ThermalMgrPolicyTest, ThermalMgrPolicyTest071, Function|MediumTest|Lev event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); ThermalSrvSensorInfo info; - EXPECT_TRUE(g_service->GetThermalSrvSensorInfo(SensorType::BATTERY, info)); + bool thermalInfoRet = false; + g_service->GetThermalSrvSensorInfo(static_cast(SensorType::BATTERY), info, thermalInfoRet); + EXPECT_TRUE(thermalInfoRet); THERMAL_HILOGI(LABEL_TEST, "ThermalMgrPolicyTest071 function end!"); } diff --git a/test/unittest/src/thermal_mock_action_test.cpp b/test/unittest/src/thermal_mock_action_test.cpp index 08127084722df8c55975545349d51edcb5a6fc0a..9f5afca9f451b012b824bf5dd17472af401b2c3c 100644 --- a/test/unittest/src/thermal_mock_action_test.cpp +++ b/test/unittest/src/thermal_mock_action_test.cpp @@ -160,7 +160,8 @@ void ThermalMockActionTest::TearDown() { InitNode(); g_service->SetScene(""); - g_service->GetThermalInfo(); + bool ret = false; + g_service->GetThermalInfo(ret); MockSocPerfAction::ClearLimit(); MockSocPerfAction::ClearBoost(); } @@ -186,8 +187,9 @@ HWTEST_F (ThermalMockActionTest, ThermalMockActionTest001, Function|MediumTest|L info1.temp = 40100; event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); - g_service->GetThermalLevel(level); - EXPECT_EQ(expectLevel, static_cast(level)); + int32_t levelValue = static_cast(level); + g_service->GetThermalLevel(levelValue); + EXPECT_EQ(expectLevel, levelValue); EXPECT_EQ(1, MockSocPerfAction::GetBoostRequestCounter()); event.info.clear(); @@ -195,8 +197,8 @@ HWTEST_F (ThermalMockActionTest, ThermalMockActionTest001, Function|MediumTest|L event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); expectLevel = 3; - g_service->GetThermalLevel(level); - EXPECT_EQ(expectLevel, static_cast(level)); + g_service->GetThermalLevel(levelValue); + EXPECT_EQ(expectLevel, levelValue); EXPECT_EQ(2, MockSocPerfAction::GetBoostRequestCounter()); event.info.clear(); @@ -204,8 +206,8 @@ HWTEST_F (ThermalMockActionTest, ThermalMockActionTest001, Function|MediumTest|L event.info.push_back(info1); g_service->HandleThermalCallbackEvent(event); expectLevel = 2; - g_service->GetThermalLevel(level); - EXPECT_EQ(expectLevel, static_cast(level)); + g_service->GetThermalLevel(levelValue); + EXPECT_EQ(expectLevel, levelValue); EXPECT_EQ(3, MockSocPerfAction::GetBoostRequestCounter()); THERMAL_HILOGI(LABEL_TEST, "ThermalMockActionTest001 function end!"); } @@ -230,8 +232,9 @@ HWTEST_F (ThermalMockActionTest, ThermalMockActionTest002, Function|MediumTest|L g_service->HandleThermalCallbackEvent(event); ThermalLevel level = ThermalLevel::COOL; int32_t expectLevel = 3; - g_service->GetThermalLevel(level); - EXPECT_EQ(expectLevel, static_cast(level)); + int32_t levelValue = static_cast(level); + g_service->GetThermalLevel(levelValue); + EXPECT_EQ(expectLevel, levelValue); THERMAL_HILOGI(LABEL_TEST, "ThermalMockActionTest002 function end!"); } @@ -255,9 +258,10 @@ HWTEST_F (ThermalMockActionTest, ThermalMockActionTest003, Function|MediumTest|L g_service->HandleThermalCallbackEvent(event); ThermalLevel level = ThermalLevel::COOL; int32_t expectLevel = 1; - g_service->GetThermalLevel(level); + int32_t levelValue = static_cast(level); + g_service->GetThermalLevel(levelValue); MockSocPerfAction::LimitRequest(LIM_CPU_BIG_ID, 1992000); - EXPECT_EQ(expectLevel, static_cast(level)); + EXPECT_EQ(expectLevel, levelValue); EXPECT_EQ(1992000, MockSocPerfAction::GetLimitValue(LIM_CPU_BIG_ID)); EXPECT_EQ(1991500, MockSocPerfAction::GetLimitValue(LIM_CPU_MED_ID)); EXPECT_EQ(1991200, MockSocPerfAction::GetLimitValue(LIM_CPU_LIT_ID)); @@ -290,8 +294,9 @@ HWTEST_F (ThermalMockActionTest, ThermalMockActionTest004, Function|MediumTest|L g_service->HandleThermalCallbackEvent(event); ThermalLevel level = ThermalLevel::COOL; int32_t expectLevel = 2; - g_service->GetThermalLevel(level); - EXPECT_EQ(expectLevel, static_cast(level)); + int32_t levelValue = static_cast(level); + g_service->GetThermalLevel(levelValue); + EXPECT_EQ(expectLevel, levelValue); EXPECT_EQ(1991000, MockSocPerfAction::GetLimitValue(LIM_CPU_BIG_ID)); EXPECT_EQ(1990500, MockSocPerfAction::GetLimitValue(LIM_CPU_MED_ID)); EXPECT_EQ(1990200, MockSocPerfAction::GetLimitValue(LIM_CPU_LIT_ID)); @@ -324,8 +329,9 @@ HWTEST_F (ThermalMockActionTest, ThermalMockActionTest005, Function|MediumTest|L g_service->HandleThermalCallbackEvent(event); ThermalLevel level = ThermalLevel::COOL; int32_t expectLevel = 3; - g_service->GetThermalLevel(level); - EXPECT_EQ(expectLevel, static_cast(level)); + int32_t levelValue = static_cast(level); + g_service->GetThermalLevel(levelValue); + EXPECT_EQ(expectLevel, levelValue); EXPECT_EQ(1990000, MockSocPerfAction::GetLimitValue(LIM_CPU_BIG_ID)); EXPECT_EQ(1989500, MockSocPerfAction::GetLimitValue(LIM_CPU_MED_ID)); EXPECT_EQ(1989200, MockSocPerfAction::GetLimitValue(LIM_CPU_LIT_ID)); @@ -362,8 +368,9 @@ HWTEST_F (ThermalMockActionTest, ThermalMockActionTest006, Function|MediumTest|L g_service->HandleThermalCallbackEvent(event); ThermalLevel level = ThermalLevel::COOL; int32_t expectLevel = 1; - g_service->GetThermalLevel(level); - EXPECT_EQ(expectLevel, static_cast(level)); + int32_t levelValue = static_cast(level); + g_service->GetThermalLevel(levelValue); + EXPECT_EQ(expectLevel, levelValue); #ifdef BATTERY_MANAGER_ENABLE int64_t cpuLimitValue = MockSocPerfAction::GetLimitValue(LIM_CPU_BIG_ID); if (state) { @@ -396,8 +403,9 @@ HWTEST_F (ThermalMockActionTest, ThermalMockActionTest007, Function|MediumTest|L g_service->HandleThermalCallbackEvent(event); ThermalLevel level = ThermalLevel::COOL; int32_t expectLevel = 2; - g_service->GetThermalLevel(level); - EXPECT_EQ(expectLevel, static_cast(level)); + int32_t levelValue = static_cast(level); + g_service->GetThermalLevel(levelValue); + EXPECT_EQ(expectLevel, levelValue); #ifdef BATTERY_MANAGER_ENABLE int64_t cpuLimitValue = MockSocPerfAction::GetLimitValue(LIM_CPU_BIG_ID); auto chargerState = ChargerStateCollection::GetInstance(); @@ -433,8 +441,9 @@ HWTEST_F (ThermalMockActionTest, ThermalMockActionTest008, Function|MediumTest|L g_service->HandleThermalCallbackEvent(event); ThermalLevel level = ThermalLevel::COOL; int32_t expectLevel = 3; - g_service->GetThermalLevel(level); - EXPECT_EQ(expectLevel, static_cast(level)); + int32_t levelValue = static_cast(level); + g_service->GetThermalLevel(levelValue); + EXPECT_EQ(expectLevel, levelValue); #ifdef BATTERY_MANAGER_ENABLE int64_t cpuLimitValue = MockSocPerfAction::GetLimitValue(LIM_CPU_BIG_ID); auto chargerState = ChargerStateCollection::GetInstance(); diff --git a/test/unittest/src/thermal_mock_proxy_remote_test.cpp b/test/unittest/src/thermal_mock_proxy_remote_test.cpp index f21c32ce78cb9ac7e61fc68be18964413008d6f6..5399025373436d1dc93ab007e226ca34dc52c0ef 100644 --- a/test/unittest/src/thermal_mock_proxy_remote_test.cpp +++ b/test/unittest/src/thermal_mock_proxy_remote_test.cpp @@ -102,24 +102,29 @@ HWTEST_F(ThermalMockProxyRemoteTest, ThermalMockProxyRemoteTest001, TestSize.Lev EXPECT_FALSE(srvProxy == nullptr); SensorType type = SensorType::SOC; sptr sensorInfo = new ThermalSrvSensorInfo(); - EXPECT_FALSE(srvProxy->GetThermalSrvSensorInfo(type, *sensorInfo)); - EXPECT_FALSE(srvProxy->GetThermalLevel(level)); + bool thermalInfoRet = false; + srvProxy->GetThermalSrvSensorInfo(static_cast(type), *sensorInfo, thermalInfoRet); + EXPECT_FALSE(thermalInfoRet); + int32_t levelValue = static_cast(level); + EXPECT_NE(srvProxy->GetThermalLevel(levelValue), ERR_OK); std::string sence; - EXPECT_FALSE(srvProxy->SetScene(sence)); + EXPECT_NE(srvProxy->SetScene(sence), ERR_OK); std::vector args; uint32_t argc = 0; - EXPECT_TRUE(srvProxy->ShellDump(args, argc) == "remote error"); + std::string dumpShell; + srvProxy->ShellDump(args, argc, dumpShell); + EXPECT_TRUE(dumpShell == ""); std::vector typeList; std::string desc; sptr tempCallback; - EXPECT_FALSE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalTempCallback(tempCallback)); + EXPECT_NE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalTempCallback(tempCallback), ERR_OK); sptr levelCallback; - EXPECT_FALSE(srvProxy->SubscribeThermalLevelCallback(levelCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback)); + EXPECT_NE(srvProxy->SubscribeThermalLevelCallback(levelCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback), ERR_OK); sptr actionCallback; - EXPECT_FALSE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalActionCallback(actionCallback)); + EXPECT_NE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalActionCallback(actionCallback), ERR_OK); THERMAL_HILOGI(LABEL_TEST, "ThermalMockProxyRemoteTest001 function end!"); } } // namespace diff --git a/test/unittest/src/thermal_mock_proxy_sendrequest_test.cpp b/test/unittest/src/thermal_mock_proxy_sendrequest_test.cpp index a39ca44e771d5f1b4307c12852af3ec7dbff0e83..19496f408d334b19946ddbfd3f9001916404db5f 100644 --- a/test/unittest/src/thermal_mock_proxy_sendrequest_test.cpp +++ b/test/unittest/src/thermal_mock_proxy_sendrequest_test.cpp @@ -56,16 +56,16 @@ HWTEST_F(ThermalMockProxySendrequestTest, ThermalMockProxySendrequestTest001, Te std::string desc; sptr tempCallback = new ThermalTempCallbackProxy(sptrRemoteObj); EXPECT_FALSE(tempCallback == nullptr); - EXPECT_FALSE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalTempCallback(tempCallback)); + EXPECT_NE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalTempCallback(tempCallback), ERR_OK); sptr levelCallback = new ThermalLevelCallbackProxy(sptrRemoteObj); EXPECT_FALSE(levelCallback == nullptr); - EXPECT_FALSE(srvProxy->SubscribeThermalLevelCallback(levelCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback)); + EXPECT_NE(srvProxy->SubscribeThermalLevelCallback(levelCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback), ERR_OK); sptr actionCallback = new ThermalActionCallbackProxy(sptrRemoteObj); EXPECT_FALSE(actionCallback == nullptr); - EXPECT_FALSE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalActionCallback(actionCallback)); + EXPECT_NE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalActionCallback(actionCallback), ERR_OK); THERMAL_HILOGI(LABEL_TEST, "ThermalMockProxySendrequestTest001 function end!"); } } // namespace diff --git a/test/unittest/src/thermal_mock_proxy_test.cpp b/test/unittest/src/thermal_mock_proxy_test.cpp index 8fffb0ab52b5fc7b3e39086a1a7064e8d28f35d5..bf7299e0fe26f56665a7d100bbce6e7ddb1909f3 100644 --- a/test/unittest/src/thermal_mock_proxy_test.cpp +++ b/test/unittest/src/thermal_mock_proxy_test.cpp @@ -75,27 +75,27 @@ HWTEST_F(ThermalMockProxyTest, ThermalMockProxyTest002, TestSize.Level0) std::vector typeList; std::string desc; sptr tempCallback; - EXPECT_FALSE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalTempCallback(tempCallback)); + EXPECT_NE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalTempCallback(tempCallback), ERR_OK); sptr levelCallback; - EXPECT_FALSE(srvProxy->SubscribeThermalLevelCallback(levelCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback)); + EXPECT_NE(srvProxy->SubscribeThermalLevelCallback(levelCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback), ERR_OK); sptr actionCallback; - EXPECT_FALSE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalActionCallback(actionCallback)); + EXPECT_NE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalActionCallback(actionCallback), ERR_OK); tempCallback = new ThermalTempCallbackProxy(sptrRemoteObj); EXPECT_FALSE(tempCallback == nullptr); - EXPECT_TRUE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback)); - EXPECT_TRUE(srvProxy->UnSubscribeThermalTempCallback(tempCallback)); + EXPECT_EQ(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback), ERR_OK); + EXPECT_EQ(srvProxy->UnSubscribeThermalTempCallback(tempCallback), ERR_OK); levelCallback = new ThermalLevelCallbackProxy(sptrRemoteObj); EXPECT_FALSE(levelCallback == nullptr); - EXPECT_TRUE(srvProxy->SubscribeThermalLevelCallback(levelCallback)); - EXPECT_TRUE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback)); + EXPECT_EQ(srvProxy->SubscribeThermalLevelCallback(levelCallback), ERR_OK); + EXPECT_EQ(srvProxy->UnSubscribeThermalLevelCallback(levelCallback), ERR_OK); actionCallback = new ThermalActionCallbackProxy(sptrRemoteObj); EXPECT_FALSE(actionCallback == nullptr); - EXPECT_TRUE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback)); - EXPECT_TRUE(srvProxy->UnSubscribeThermalActionCallback(actionCallback)); + EXPECT_EQ(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback), ERR_OK); + EXPECT_EQ(srvProxy->UnSubscribeThermalActionCallback(actionCallback), ERR_OK); THERMAL_HILOGI(LABEL_TEST, "ThermalMockProxyTest002 function end!"); } } // namespace diff --git a/test/unittest/src/thermal_mock_proxy_writeinterfacetoken_test.cpp b/test/unittest/src/thermal_mock_proxy_writeinterfacetoken_test.cpp index 832acf648e301b082a308cb7818d907039e1a957..d69035b068c40fa320fbcb574e94f906d5f4902b 100644 --- a/test/unittest/src/thermal_mock_proxy_writeinterfacetoken_test.cpp +++ b/test/unittest/src/thermal_mock_proxy_writeinterfacetoken_test.cpp @@ -46,25 +46,28 @@ HWTEST_F(ThermalMockProxyWriteinterfacetokenTest, ThermalMockProxyWriteinterface std::string desc; sptr tempCallback = new ThermalTempCallbackProxy(sptrRemoteObj); EXPECT_FALSE(tempCallback == nullptr); - EXPECT_FALSE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalTempCallback(tempCallback)); + EXPECT_NE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalTempCallback(tempCallback), ERR_OK); sptr levelCallback = new ThermalLevelCallbackProxy(sptrRemoteObj); EXPECT_FALSE(levelCallback == nullptr); - EXPECT_FALSE(srvProxy->SubscribeThermalLevelCallback(levelCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback)); + EXPECT_NE(srvProxy->SubscribeThermalLevelCallback(levelCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback), ERR_OK); sptr actionCallback = new ThermalActionCallbackProxy(sptrRemoteObj); EXPECT_FALSE(actionCallback == nullptr); - EXPECT_FALSE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalActionCallback(actionCallback)); + EXPECT_NE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalActionCallback(actionCallback), ERR_OK); SensorType type = SensorType::SOC; sptr sensorInfo = new ThermalSrvSensorInfo(); EXPECT_FALSE(sensorInfo == nullptr); - EXPECT_FALSE(srvProxy->GetThermalSrvSensorInfo(type, *sensorInfo)); + bool thermalInfoRet = false; + srvProxy->GetThermalSrvSensorInfo(static_cast(type), *sensorInfo, thermalInfoRet); + EXPECT_FALSE(thermalInfoRet); ThermalLevel level = ThermalLevel::COOL; - EXPECT_FALSE(srvProxy->GetThermalLevel(level)); + int32_t levelValue = static_cast(level); + EXPECT_NE(srvProxy->GetThermalLevel(levelValue), ERR_OK); std::string sence; - EXPECT_FALSE(srvProxy->SetScene(sence)); + EXPECT_NE(srvProxy->SetScene(sence), ERR_OK); THERMAL_HILOGI(LABEL_TEST, "ThermalMockProxyWriteinterfacetokenTest001 function end!"); } diff --git a/test/unittest/src/thermal_mock_proxy_writeremoteobject_test.cpp b/test/unittest/src/thermal_mock_proxy_writeremoteobject_test.cpp index 37914ba947959fa192bc40e83d6a537fcb908b5b..f8b7c4b062c36f19ffb1277f6723e22f7045a684 100644 --- a/test/unittest/src/thermal_mock_proxy_writeremoteobject_test.cpp +++ b/test/unittest/src/thermal_mock_proxy_writeremoteobject_test.cpp @@ -117,16 +117,16 @@ HWTEST_F(ThermalMockProxyWriteremoteobjectTest, ThermalMockProxyWriteremoteobjec std::string desc; sptr tempCallback = new ThermalTempCallbackProxy(sptrRemoteObj); EXPECT_FALSE(tempCallback == nullptr); - EXPECT_FALSE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalTempCallback(tempCallback)); + EXPECT_NE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalTempCallback(tempCallback), ERR_OK); sptr levelCallback = new ThermalLevelCallbackProxy(sptrRemoteObj); EXPECT_FALSE(levelCallback == nullptr); - EXPECT_FALSE(srvProxy->SubscribeThermalLevelCallback(levelCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback)); + EXPECT_NE(srvProxy->SubscribeThermalLevelCallback(levelCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback), ERR_OK); sptr actionCallback = new ThermalActionCallbackProxy(sptrRemoteObj); EXPECT_FALSE(actionCallback == nullptr); - EXPECT_FALSE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback)); - EXPECT_FALSE(srvProxy->UnSubscribeThermalActionCallback(actionCallback)); + EXPECT_NE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback), ERR_OK); + EXPECT_NE(srvProxy->UnSubscribeThermalActionCallback(actionCallback), ERR_OK); THERMAL_HILOGI(LABEL_TEST, "ThermalMockProxyWriteremoteobjectTest001 function end!"); } } // namespace diff --git a/test/unittest/src/thermal_mock_proxy_writevector_test.cpp b/test/unittest/src/thermal_mock_proxy_writevector_test.cpp index 056241032ae47e3a795d1d8be437733dba59b45e..f2ba023591b4e59ac5c09706d96e617b9cede926 100644 --- a/test/unittest/src/thermal_mock_proxy_writevector_test.cpp +++ b/test/unittest/src/thermal_mock_proxy_writevector_test.cpp @@ -56,16 +56,10 @@ HWTEST_F(ThermalMockProxyWritevectorTest, ThermalMockProxyWritevectorTest001, Te std::string desc; sptr tempCallback = new ThermalTempCallbackProxy(sptrRemoteObj); EXPECT_FALSE(tempCallback == nullptr); - EXPECT_FALSE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback)); - EXPECT_TRUE(srvProxy->UnSubscribeThermalTempCallback(tempCallback)); - sptr levelCallback = new ThermalLevelCallbackProxy(sptrRemoteObj); - EXPECT_FALSE(levelCallback == nullptr); - EXPECT_TRUE(srvProxy->SubscribeThermalLevelCallback(levelCallback)); - EXPECT_TRUE(srvProxy->UnSubscribeThermalLevelCallback(levelCallback)); + EXPECT_NE(srvProxy->SubscribeThermalTempCallback(typeList, tempCallback), ERR_OK); sptr actionCallback = new ThermalActionCallbackProxy(sptrRemoteObj); EXPECT_FALSE(actionCallback == nullptr); - EXPECT_FALSE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback)); - EXPECT_TRUE(srvProxy->UnSubscribeThermalActionCallback(actionCallback)); + EXPECT_NE(srvProxy->SubscribeThermalActionCallback(typeList, desc, actionCallback), ERR_OK); THERMAL_HILOGI(LABEL_TEST, "ThermalMockProxyWritevectorTest001 function end!"); } } // namespace diff --git a/test/unittest/src/thermal_mock_stub_test.cpp b/test/unittest/src/thermal_mock_stub_test.cpp index a2437b52c0bb0e2a8704164fad753dc663098a10..bae391489526532bfa4e7c01a42022380baacd82 100644 --- a/test/unittest/src/thermal_mock_stub_test.cpp +++ b/test/unittest/src/thermal_mock_stub_test.cpp @@ -27,7 +27,7 @@ #include "thermal_log.h" #include "thermal_mgr_errors.h" #include "thermal_service.h" -#include "thermal_srv_ipc_interface_code.h" +#include "ithermal_srv.h" #include "thermal_srv_proxy.h" #include "thermal_srv_stub.h" #include "thermal_temp_callback_stub.h" @@ -86,13 +86,13 @@ HWTEST_F(ThermalMockStubTest, ThermalMockStubTest001, TestSize.Level0) HWTEST_F(ThermalMockStubTest, ThermalMockStubTest002, TestSize.Level0) { THERMAL_HILOGI(LABEL_TEST, "ThermalMockStubTest002 function start!"); - uint32_t begin = static_cast(PowerMgr::ThermalMgrInterfaceCode::REG_THERMAL_TEMP_CALLBACK); - uint32_t end = static_cast(PowerMgr::ThermalMgrInterfaceCode::SHELL_DUMP); + uint32_t begin = static_cast(PowerMgr::IThermalSrvIpcCode::COMMAND_SUBSCRIBE_THERMAL_TEMP_CALLBACK); + uint32_t end = static_cast(PowerMgr::IThermalSrvIpcCode::COMMAND_SHELL_DUMP); for (uint32_t code = begin; code <= end; ++code) { g_data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor()); auto ret = g_service->OnRemoteRequest(code, g_data, g_reply, g_option); - EXPECT_TRUE(ret == E_READ_PARCEL_ERROR_THERMAL || ret == E_GET_SYSTEM_ABILITY_MANAGER_FAILED_THERMAL || - ret == 0); + EXPECT_TRUE(ret == ERR_INVALID_DATA || ret == E_GET_SYSTEM_ABILITY_MANAGER_FAILED_THERMAL || + ret == 0) << "code: " << code << " ret:" << ret; } THERMAL_HILOGI(LABEL_TEST, "ThermalMockStubTest002 function end!"); } @@ -105,9 +105,9 @@ HWTEST_F(ThermalMockStubTest, ThermalMockStubTest002, TestSize.Level0) HWTEST_F(ThermalMockStubTest, ThermalMockStubTest003, TestSize.Level0) { THERMAL_HILOGI(LABEL_TEST, "ThermalMockStubTest003 function start!"); - uint32_t code = 0; + uint32_t code = 1; int32_t ret = g_service->OnRemoteRequest(code, g_data, g_reply, g_option); - EXPECT_EQ(ret, E_GET_THERMAL_SERVICE_FAILED) << "code: " << code << " ret:" << ret; + EXPECT_EQ(ret, ERR_TRANSACTION_FAILED) << "code: " << code << " ret:" << ret; THERMAL_HILOGI(LABEL_TEST, "ThermalMockStubTest003 function end!"); } @@ -138,15 +138,32 @@ HWTEST_F(ThermalMockStubTest, ThermalMockStubTest005, TestSize.Level0) sptr tempStub = new ThermalTempCallbackStub(); std::vector typeList; g_data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor()); - THERMAL_WRITE_PARCEL_NO_RET(g_data, RemoteObject, tempStub->AsObject()); - THERMAL_WRITE_PARCEL_NO_RET(g_data, StringVector, typeList); - uint32_t code = static_cast(PowerMgr::ThermalMgrInterfaceCode::REG_THERMAL_TEMP_CALLBACK); + if (typeList.size() > static_cast(VECTOR_MAX_SIZE)) { + THERMAL_HILOGI(LABEL_TEST, "The vector/array size exceeds the security limit!"); + return; + } + g_data.WriteInt32(typeList.size()); + for (auto it1 = typeList.begin(); it1 != typeList.end(); ++it1) { + if (!g_data.WriteString16(Str8ToStr16((*it1)))) { + THERMAL_HILOGI(LABEL_TEST, "Write [(*it1)] failed!"); + return; + } + } + if (tempStub == nullptr) { + THERMAL_HILOGI(LABEL_TEST, "tempStub is nullptr!"); + return; + } + if (!g_data.WriteRemoteObject(tempStub->AsObject())) { + THERMAL_HILOGI(LABEL_TEST, "Write [tempStub] failed!"); + return; + } + uint32_t code = static_cast(PowerMgr::IThermalSrvIpcCode::COMMAND_SUBSCRIBE_THERMAL_TEMP_CALLBACK); int32_t ret = g_service->OnRemoteRequest(code, g_data, g_reply, g_option); EXPECT_EQ(ret, ERR_OK) << " ret:" << ret; g_data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor()); THERMAL_WRITE_PARCEL_NO_RET(g_data, RemoteObject, tempStub->AsObject()); - code = static_cast(PowerMgr::ThermalMgrInterfaceCode::UNREG_THERMAL_TEMP_CALLBACK); + code = static_cast(PowerMgr::IThermalSrvIpcCode::COMMAND_UN_SUBSCRIBE_THERMAL_TEMP_CALLBACK); ret = g_service->OnRemoteRequest(code, g_data, g_reply, g_option); EXPECT_EQ(ret, ERR_OK) << " ret:" << ret; THERMAL_HILOGI(LABEL_TEST, "ThermalMockStubTest005 function end!"); @@ -164,12 +181,21 @@ HWTEST_F(ThermalMockStubTest, ThermalMockStubTest006, TestSize.Level0) MessageParcel data; sptr levelStub = new ThermalLevelCallbackStub(); g_data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor()); - THERMAL_WRITE_PARCEL_NO_RET(g_data, RemoteObject, levelStub->AsObject()); - uint32_t code = static_cast(PowerMgr::ThermalMgrInterfaceCode::REG_THERMAL_LEVEL_CALLBACK); + THERMAL_HILOGI(LABEL_TEST, "WriteInterfaceToken1 success!"); + if (levelStub == nullptr) { + THERMAL_HILOGI(LABEL_TEST, "levelStub is nullptr!"); + return; + } + if (!g_data.WriteRemoteObject(levelStub->AsObject())) { + THERMAL_HILOGI(LABEL_TEST, "Write [levelStub] failed!"); + return; + } + THERMAL_HILOGI(LABEL_TEST, "WriteRemoteObject1 success!"); + uint32_t code = static_cast(PowerMgr::IThermalSrvIpcCode::COMMAND_SUBSCRIBE_THERMAL_LEVEL_CALLBACK); int32_t ret = g_service->OnRemoteRequest(code, g_data, g_reply, g_option); EXPECT_EQ(ret, ERR_OK) << " ret:" << ret; - code = static_cast(PowerMgr::ThermalMgrInterfaceCode::UNREG_THERMAL_LEVEL_CALLBACK); + code = static_cast(PowerMgr::IThermalSrvIpcCode::COMMAND_UN_SUBSCRIBE_THERMAL_LEVEL_CALLBACK); g_data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor()); THERMAL_WRITE_PARCEL_NO_RET(g_data, RemoteObject, levelStub->AsObject()); ret = g_service->OnRemoteRequest(code, g_data, g_reply, g_option); @@ -190,14 +216,34 @@ HWTEST_F(ThermalMockStubTest, ThermalMockStubTest007, TestSize.Level0) sptr actionStub = new ThermalActionCallbackStub(); g_data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor()); std::vector actionList; - THERMAL_WRITE_PARCEL_NO_RET(g_data, RemoteObject, actionStub->AsObject()); - THERMAL_WRITE_PARCEL_NO_RET(g_data, StringVector, actionList); - THERMAL_WRITE_PARCEL_NO_RET(g_data, String, "ThermalMockStubTest007"); - uint32_t code = static_cast(PowerMgr::ThermalMgrInterfaceCode::REG_THERMAL_ACTION_CALLBACK); + if (actionList.size() > static_cast(VECTOR_MAX_SIZE)) { + THERMAL_HILOGI(LABEL_TEST, "The vector/array size exceeds the security limit!"); + return; + } + g_data.WriteInt32(actionList.size()); + for (auto it2 = actionList.begin(); it2 != actionList.end(); ++it2) { + if (!g_data.WriteString16(Str8ToStr16((*it2)))) { + THERMAL_HILOGI(LABEL_TEST, "Write [(*it2)] failed!"); + return; + } + } + if (!g_data.WriteString16(Str8ToStr16("ThermalMockStubTest007"))) { + THERMAL_HILOGI(LABEL_TEST, "Write [desc] failed!"); + return; + } + if (actionStub == nullptr) { + THERMAL_HILOGI(LABEL_TEST, "actionStub is nullptr!"); + return; + } + if (!g_data.WriteRemoteObject(actionStub->AsObject())) { + THERMAL_HILOGI(LABEL_TEST, "Write [actionStub] failed!"); + return; + } + uint32_t code = static_cast(PowerMgr::IThermalSrvIpcCode::COMMAND_SUBSCRIBE_THERMAL_ACTION_CALLBACK); int32_t ret = g_service->OnRemoteRequest(code, g_data, g_reply, g_option); EXPECT_EQ(ret, ERR_OK) << " ret:" << ret; - code = static_cast(PowerMgr::ThermalMgrInterfaceCode::UNREG_THERMAL_ACTION_CALLBACK); + code = static_cast(PowerMgr::IThermalSrvIpcCode::COMMAND_UN_SUBSCRIBE_THERMAL_ACTION_CALLBACK); g_data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor()); THERMAL_WRITE_PARCEL_NO_RET(g_data, RemoteObject, actionStub->AsObject()); ret = g_service->OnRemoteRequest(code, g_data, g_reply, g_option); @@ -216,8 +262,11 @@ HWTEST_F(ThermalMockStubTest, ThermalMockStubTest008, TestSize.Level0) THERMAL_HILOGI(LABEL_TEST, "ThermalMockStubTest008 function start!"); g_data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor()); - THERMAL_WRITE_PARCEL_NO_RET(g_data, Uint32, static_cast(SensorType::BATTERY)); - uint32_t code = static_cast(PowerMgr::ThermalMgrInterfaceCode::GET_SENSOR_INFO); + if (!g_data.WriteInt32(static_cast(SensorType::BATTERY))) { + THERMAL_HILOGI(LABEL_TEST, "Write [type] failed!"); + return; + } + uint32_t code = static_cast(PowerMgr::IThermalSrvIpcCode::COMMAND_GET_THERMAL_SRV_SENSOR_INFO); int32_t ret = g_service->OnRemoteRequest(code, g_data, g_reply, g_option); EXPECT_EQ(ret, ERR_OK) << " ret:" << ret; @@ -234,8 +283,11 @@ HWTEST_F(ThermalMockStubTest, ThermalMockStubTest009, TestSize.Level0) THERMAL_HILOGI(LABEL_TEST, "ThermalMockStubTest009 function start!"); g_data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor()); - THERMAL_WRITE_PARCEL_NO_RET(g_data, String, "test"); - uint32_t code = static_cast(PowerMgr::ThermalMgrInterfaceCode::SET_SCENE); + if (!g_data.WriteString16(Str8ToStr16("test"))) { + THERMAL_HILOGI(LABEL_TEST, "Write [scene] failed!"); + return; + } + uint32_t code = static_cast(PowerMgr::IThermalSrvIpcCode::COMMAND_SET_SCENE); int32_t ret = g_service->OnRemoteRequest(code, g_data, g_reply, g_option); EXPECT_EQ(ret, ERR_OK) << " ret:" << ret; @@ -252,17 +304,11 @@ HWTEST_F(ThermalMockStubTest, ThermalMockStubTest010, TestSize.Level0) THERMAL_HILOGI(LABEL_TEST, "ThermalMockStubTest010 function start!"); g_data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor()); - const int32_t PARAM_MAX_NUM = 100; + const int32_t PARAM_MAX_NUM = 1024000; g_data.WriteUint32(PARAM_MAX_NUM); - uint32_t code = static_cast(PowerMgr::ThermalMgrInterfaceCode::SHELL_DUMP); + uint32_t code = static_cast(PowerMgr::IThermalSrvIpcCode::COMMAND_SHELL_DUMP); int32_t ret = g_service->OnRemoteRequest(code, g_data, g_reply, g_option); - EXPECT_EQ(ret, E_EXCEED_PARAM_LIMIT) << " ret:" << ret; - - g_data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor()); - g_data.WriteUint32(1); - g_data.WriteString(""); - ret = g_service->OnRemoteRequest(code, g_data, g_reply, g_option); - EXPECT_EQ(ret, E_READ_PARCEL_ERROR_THERMAL) << " ret:" << ret; + EXPECT_EQ(ret, ERR_INVALID_DATA) << " ret:" << ret; g_data.WriteInterfaceToken(ThermalSrvProxy::GetDescriptor()); g_data.WriteUint32(1); diff --git a/test/unittest/src/thermal_service_test.cpp b/test/unittest/src/thermal_service_test.cpp index 3427028bb8bb350adfc3ced5e4cdd59f3578a287..5afb9f011191f10f472932122fbe20b49ded2bf9 100644 --- a/test/unittest/src/thermal_service_test.cpp +++ b/test/unittest/src/thermal_service_test.cpp @@ -90,7 +90,8 @@ HWTEST_F(ThermalServiceTest, ThermalServiceTest001, TestSize.Level0) g_service->ready_ = true; g_service->RegisterHdiStatusListener(); - g_service->GetThermalInfo(); + bool ret = false; + g_service->GetThermalInfo(ret); g_service->OnStop(); EXPECT_FALSE(g_service->ready_); diff --git a/utils/BUILD.gn b/utils/BUILD.gn index fb96978b478c97f8e6a9917ecff7d777968195c6..5c412474288939b1cc5c488b6da84401eb0032a5 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -35,6 +35,7 @@ ohos_source_set("thermal_utils") { "native/src/file_operation.cpp", "native/src/string_operation.cpp", "native/src/thermal_hisysevent.cpp", + "native/src/thermal_xcollie.cpp", ] configs = [ "${utils_path}:coverage_flags" ] @@ -43,6 +44,7 @@ ohos_source_set("thermal_utils") { external_deps = [ "c_utils:utils", + "hicollie:libhicollie", "hilog:libhilog", "init:libbegetutil", ] diff --git a/utils/native/include/thermal_log.h b/utils/native/include/thermal_log.h index 63df825710583cb026dcd4c15c52f0daf18d46f3..2e2ef603bb25736b3112e423fbc94f23b257cb86 100644 --- a/utils/native/include/thermal_log.h +++ b/utils/native/include/thermal_log.h @@ -18,6 +18,9 @@ #define CONFIG_HILOG #ifdef CONFIG_HILOG + +#include + #include "hilog/log.h" namespace OHOS { namespace PowerMgr { diff --git a/interfaces/inner_api/native/include/thermal_srv_ipc_interface_code.h b/utils/native/include/thermal_xcollie.h similarity index 50% rename from interfaces/inner_api/native/include/thermal_srv_ipc_interface_code.h rename to utils/native/include/thermal_xcollie.h index 2420130fbb52f3fed71a0ba4fa3ae0fbf65d4f25..95f459a3b99a6e318fc7985848fb87c0de013da3 100644 --- a/interfaces/inner_api/native/include/thermal_srv_ipc_interface_code.h +++ b/utils/native/include/thermal_xcollie.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,27 +13,28 @@ * limitations under the License. */ -#ifndef THERMAL_MGR_IPC_INTERFACE_DODE_H -#define THERMAL_MGR_IPC_INTERFACE_DODE_H +#ifndef THERMAL_XCOLLIE_H +#define THERMAL_XCOLLIE_H + +#include +#include -/* SAID: 3303 */ namespace OHOS { namespace PowerMgr { -enum class ThermalMgrInterfaceCode { - REG_THERMAL_TEMP_CALLBACK = 0, - UNREG_THERMAL_TEMP_CALLBACK, - REG_THERMAL_LEVEL_CALLBACK, - UNREG_THERMAL_LEVEL_CALLBACK, - REG_THERMAL_ACTION_CALLBACK, - UNREG_THERMAL_ACTION_CALLBACK, - GET_SENSOR_INFO, - GET_TEMP_LEVEL, - GET_THERMAL_INFO, - SET_SCENE, - UPDATE_THERMAL_STATE, - SHELL_DUMP +class ThermalXCollie { +public: + ThermalXCollie(const std::string &logTag, bool isRecovery = false); + ~ThermalXCollie(); + +private: + void CancelThermalXCollie(); + + int32_t id_; + std::string logTag_; + bool isCanceled_; }; -} // space PowerMgr + +} // namespace PowerMgr } // namespace OHOS -#endif // THERMAL_MGR_IPC_INTERFACE_DODE_H \ No newline at end of file +#endif // THERMAL_XCOLLIE_H \ No newline at end of file diff --git a/utils/native/src/thermal_xcollie.cpp b/utils/native/src/thermal_xcollie.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6fe752fab811927cdfaed65ada6c157f6885e01e --- /dev/null +++ b/utils/native/src/thermal_xcollie.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "thermal_log.h" +#include "thermal_xcollie.h" +#include "xcollie/xcollie.h" + +namespace OHOS { +namespace PowerMgr { +ThermalXCollie::ThermalXCollie(const std::string &logTag, bool isRecovery) +{ + logTag_ = logTag; + isCanceled_ = false; + const int DFX_DELAY_S = 60; + unsigned int flag = HiviewDFX::XCOLLIE_FLAG_LOG; + if (isRecovery) { + flag = HiviewDFX::XCOLLIE_FLAG_LOG | HiviewDFX::XCOLLIE_FLAG_RECOVERY; + } + id_ = HiviewDFX::XCollie::GetInstance().SetTimer(logTag_, DFX_DELAY_S, nullptr, nullptr, flag); + THERMAL_HILOGD(COMP_SVC, "Start ThermalXCollie, id:%{public}d, tag:%{public}s, timeout(s):%{public}u", id_, + logTag_.c_str(), DFX_DELAY_S); +} + +ThermalXCollie::~ThermalXCollie() +{ + CancelThermalXCollie(); +} + +void ThermalXCollie::CancelThermalXCollie() +{ + if (!isCanceled_) { + HiviewDFX::XCollie::GetInstance().CancelTimer(id_); + isCanceled_ = true; + THERMAL_HILOGD(COMP_SVC, "Cancel ThermalXCollie, id:%{public}d, tag:%{public}s", id_, logTag_.c_str()); + } +} + +} // namespace PowerMgr +} // namespace OHOS \ No newline at end of file