1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef THERMAL_SERVICE_H 17 #define THERMAL_SERVICE_H 18 19 #include "delayed_sp_singleton.h" 20 #include "iremote_object.h" 21 #include "system_ability.h" 22 #include <memory> 23 24 #include "action_popup.h" 25 #include "ithermal_level_callback.h" 26 #include "ithermal_temp_callback.h" 27 #include "thermal_srv_sensor_info.h" 28 #include "thermal_srv_stub.h" 29 #include "thermalsrv_event_handler.h" 30 31 #include "hdi_service_status_listener.h" 32 #include "state_machine.h" 33 #include "thermal_action_manager.h" 34 #include "thermal_callback.h" 35 #include "thermal_config_base_info.h" 36 #include "thermal_config_sensor_cluster.h" 37 #include "thermal_observer.h" 38 #include "thermal_policy.h" 39 #include "thermal_sensor_info.h" 40 #include "thermal_service_subscriber.h" 41 #include "v1_0/ithermal_interface.h" 42 #include "v1_0/thermal_types.h" 43 44 namespace OHOS { 45 namespace PowerMgr { 46 using TypeTempMap = std::map<std::string, int32_t>; 47 using namespace OHOS::HDI::Thermal::V1_0; 48 using namespace OHOS::HDI::ServiceManager::V1_0; 49 class ThermalService final : public SystemAbility, public ThermalSrvStub { 50 DECLARE_SYSTEM_ABILITY(ThermalService); 51 DECLARE_DELAYED_SP_SINGLETON(ThermalService); 52 53 public: 54 virtual void OnStart() override; 55 virtual void OnStop() override; 56 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 57 virtual int32_t Dump(int fd, const std::vector<std::u16string>& args) override; 58 bool SubscribeThermalTempCallback( 59 const std::vector<std::string>& typeList, const sptr<IThermalTempCallback>& callback) override; 60 bool UnSubscribeThermalTempCallback(const sptr<IThermalTempCallback>& callback) override; 61 bool SubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback) override; 62 bool UnSubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback) override; 63 bool SubscribeThermalActionCallback(const std::vector<std::string>& actionList, const std::string& desc, 64 const sptr<IThermalActionCallback>& callback) override; 65 bool UnSubscribeThermalActionCallback(const sptr<IThermalActionCallback>& callback) override; 66 bool GetThermalSrvSensorInfo(const SensorType& type, ThermalSrvSensorInfo& sensorInfo) override; 67 bool GetThermalLevel(ThermalLevel& level) override; 68 bool GetThermalInfo() override; 69 bool SetScene(const std::string& scene) override; 70 virtual std::string ShellDump(const std::vector<std::string>& args, uint32_t argc) override; 71 72 void HandleEvent(int event); 73 int32_t HandleThermalCallbackEvent(const HdfThermalCallbackInfo& event); 74 SetFlag(bool flag)75 void SetFlag(bool flag) 76 { 77 flag_ = flag; 78 } 79 GetFlag()80 bool GetFlag() 81 { 82 return flag_; 83 } 84 IsServiceReady()85 bool IsServiceReady() const 86 { 87 return ready_; 88 } 89 GetHandler()90 std::shared_ptr<ThermalsrvEventHandler> GetHandler() const 91 { 92 return handler_; 93 } GetEventRunner()94 std::shared_ptr<AppExecFwk::EventRunner> GetEventRunner() const 95 { 96 return eventRunner_; 97 } GetBaseinfoObj()98 std::shared_ptr<ThermalConfigBaseInfo> GetBaseinfoObj() const 99 { 100 return baseInfo_; 101 } GetStateMachineObj()102 std::shared_ptr<StateMachine> GetStateMachineObj() const 103 { 104 return state_; 105 } GetActionManagerObj()106 std::shared_ptr<ThermalActionManager> GetActionManagerObj() const 107 { 108 return actionMgr_; 109 } GetPolicy()110 std::shared_ptr<ThermalPolicy> GetPolicy() const 111 { 112 return policy_; 113 } GetObserver()114 std::shared_ptr<ThermalObserver> GetObserver() const 115 { 116 return observer_; 117 } GetSensorInfo()118 std::shared_ptr<ThermalSensorInfo> GetSensorInfo() const 119 { 120 return info_; 121 } GetSubscriber()122 std::shared_ptr<ThermalServiceSubscriber> GetSubscriber() const 123 { 124 return serviceSubscriber_; 125 } GetSensorCluster()126 std::shared_ptr<ThermalConfigSensorCluster> GetSensorCluster() const 127 { 128 return cluster_; 129 } 130 GetActionPopup()131 std::shared_ptr<ActionPopup> GetActionPopup() const 132 { 133 return popup_; 134 } 135 GetThermalInterface()136 sptr<IThermalInterface> GetThermalInterface() const 137 { 138 return thermalInterface_; 139 } 140 GetSimulationXml()141 bool GetSimulationXml() 142 { 143 return isSimulation_; 144 } 145 GetScene()146 std::string GetScene() 147 { 148 return scene_; 149 } 150 private: 151 bool Init(); 152 bool InitThermalDriver(); 153 bool InitThermalObserver(); 154 bool InitThermalAction(); 155 bool InitThermalPolicy(); 156 bool InitBaseInfo(); 157 bool InitSensorCluser(); 158 bool InitActionManager(); 159 bool InitStateMachine(); 160 bool InitModules(); 161 bool CreateConfigModule(); 162 void RegisterHdiStatusListener(); 163 void RegisterThermalHdiCallback(); 164 void SendEvent(int32_t event, int64_t delayTime); 165 bool ready_ {false}; 166 bool isSimulation_ {false}; 167 std::mutex mutex_; 168 std::shared_ptr<AppExecFwk::EventRunner> eventRunner_ {nullptr}; 169 std::shared_ptr<ThermalsrvEventHandler> handler_ {nullptr}; 170 std::shared_ptr<ThermalServiceSubscriber> serviceSubscriber_ {nullptr}; 171 std::shared_ptr<ThermalObserver> observer_ {nullptr}; 172 std::shared_ptr<ThermalSensorInfo> info_ {nullptr}; 173 std::shared_ptr<ThermalPolicy> policy_ {nullptr}; 174 std::shared_ptr<ThermalConfigBaseInfo> baseInfo_ {nullptr}; 175 std::shared_ptr<StateMachine> state_ {nullptr}; 176 std::shared_ptr<ThermalActionManager> actionMgr_ {nullptr}; 177 std::shared_ptr<ThermalConfigSensorCluster> cluster_ {nullptr}; 178 bool flag_ {false}; 179 sptr<IThermalInterface> thermalInterface_ {nullptr}; 180 sptr<IServiceManager> hdiServiceMgr_ {nullptr}; 181 sptr<HdiServiceStatusListener::IServStatListener> hdiServStatListener_ {nullptr}; 182 std::shared_ptr<ActionPopup> popup_; 183 std::string scene_; 184 }; 185 } // namespace PowerMgr 186 } // namespace OHOS 187 #endif // THERMAL_SERVICE_H 188