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