/* * Copyright (c) 2021-2022 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_SERVICE_H #define THERMAL_SERVICE_H #include #include #include "delayed_sp_singleton.h" #include "iremote_object.h" #include "system_ability.h" #include "action_popup.h" #include "fan_callback.h" #include "fan_fault_detect.h" #include "ithermal_level_callback.h" #include "ithermal_temp_callback.h" #include "thermal_srv_sensor_info.h" #include "thermal_srv_stub.h" #include "hdi_service_status_listener.h" #include "state_machine.h" #include "thermal_action_manager.h" #include "thermal_callback.h" #include "thermal_config_base_info.h" #include "thermal_config_sensor_cluster.h" #include "thermal_observer.h" #include "thermal_policy.h" #include "thermal_sensor_info.h" #include "thermal_service_subscriber.h" #include "v1_1/ithermal_interface.h" #include "v1_1/thermal_types.h" namespace OHOS { namespace PowerMgr { using TypeTempMap = std::map; using namespace OHOS::HDI::Thermal::V1_1; using namespace OHOS::HDI::ServiceManager::V1_0; class ThermalService final : public SystemAbility, public ThermalSrvStub { DECLARE_SYSTEM_ABILITY(ThermalService); DECLARE_DELAYED_SP_SINGLETON(ThermalService); public: virtual void OnStart() override; 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( 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, 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; virtual std::string ShellDump(const std::vector& args, uint32_t argc) override; int32_t HandleThermalCallbackEvent(const HdfThermalCallbackInfo& event); int32_t HandleFanCallbackEvent(const HdfThermalCallbackInfo& event); void SetFlag(bool flag) { flag_ = flag; } bool GetFlag() { return flag_; } bool IsServiceReady() const { return ready_; } std::shared_ptr GetBaseinfoObj() const { return baseInfo_; } std::shared_ptr GetStateMachineObj() const { return state_; } std::shared_ptr GetActionManagerObj() const { return actionMgr_; } std::shared_ptr GetPolicy() const { return policy_; } std::shared_ptr GetObserver() const { return observer_; } std::shared_ptr GetSensorInfo() const { return info_; } std::shared_ptr GetSubscriber() const { return serviceSubscriber_; } std::shared_ptr GetActionPopup() const { return popup_; } sptr GetThermalInterface() const { return thermalInterface_; } bool GetSimulationXml() { return isSimulation_; } void SetSimulationXml(bool isSimulation) { isSimulation_ = isSimulation; } std::shared_ptr GetFanFaultDetect() const { return fanFaultDetect_; } std::string GetScene() { return scene_; } void InitSystemTestModules() { InitConfigModule(); } private: bool Init(); bool InitThermalDriver(); bool InitThermalObserver(); bool InitThermalAction(); bool InitThermalPolicy(); bool InitBaseInfo(); bool InitSensorCluser(); bool InitActionManager(); bool InitStateMachine(); bool InitModules(); bool InitConfigFile(); bool InitConfigModule(); bool CreateConfigModule(); void RegisterHdiStatusListener(); void RegisterThermalHdiCallback(); void RegisterFanHdiCallback(); void RegisterBootCompletedCallback(); bool ready_ {false}; static std::atomic_bool isBootCompleted_; bool isSimulation_ {false}; std::mutex mutex_; std::shared_ptr serviceSubscriber_ {nullptr}; std::shared_ptr observer_ {nullptr}; std::shared_ptr info_ {nullptr}; std::shared_ptr policy_ {nullptr}; std::shared_ptr baseInfo_ {nullptr}; std::shared_ptr state_ {nullptr}; std::shared_ptr actionMgr_ {nullptr}; std::shared_ptr fanFaultDetect_ {nullptr}; bool flag_ {false}; sptr thermalInterface_ {nullptr}; sptr hdiServiceMgr_ {nullptr}; sptr hdiServStatListener_ {nullptr}; std::shared_ptr popup_; std::string scene_; }; } // namespace PowerMgr } // namespace OHOS #endif // THERMAL_SERVICE_H