• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <atomic>
20 #include <memory>
21 #include "delayed_sp_singleton.h"
22 #include "iremote_object.h"
23 #include "system_ability.h"
24 
25 #include "action_popup.h"
26 #include "fan_callback.h"
27 #include "fan_fault_detect.h"
28 #include "ithermal_level_callback.h"
29 #include "ithermal_temp_callback.h"
30 #include "thermal_srv_sensor_info.h"
31 #include "thermal_srv_stub.h"
32 #include "hdi_service_status_listener.h"
33 #include "state_machine.h"
34 #include "thermal_action_manager.h"
35 #include "thermal_callback.h"
36 #include "thermal_config_base_info.h"
37 #include "thermal_config_sensor_cluster.h"
38 #include "thermal_observer.h"
39 #include "thermal_policy.h"
40 #include "thermal_sensor_info.h"
41 #include "thermal_service_subscriber.h"
42 #include "v1_1/ithermal_interface.h"
43 #include "v1_1/thermal_types.h"
44 
45 namespace OHOS {
46 namespace PowerMgr {
47 using TypeTempMap = std::map<std::string, int32_t>;
48 using namespace OHOS::HDI::Thermal::V1_1;
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 
54 public:
55     virtual void OnStart() override;
56     virtual void OnStop() override;
57     virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
58     virtual int32_t Dump(int fd, const std::vector<std::u16string>& args) override;
59     bool SubscribeThermalTempCallback(
60         const std::vector<std::string>& typeList, const sptr<IThermalTempCallback>& callback) override;
61     bool UnSubscribeThermalTempCallback(const sptr<IThermalTempCallback>& callback) override;
62     bool SubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback) override;
63     bool UnSubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback) override;
64     bool SubscribeThermalActionCallback(const std::vector<std::string>& actionList, const std::string& desc,
65         const sptr<IThermalActionCallback>& callback) override;
66     bool UnSubscribeThermalActionCallback(const sptr<IThermalActionCallback>& callback) override;
67     bool GetThermalSrvSensorInfo(const SensorType& type, ThermalSrvSensorInfo& sensorInfo) override;
68     bool GetThermalLevel(ThermalLevel& level) override;
69     bool GetThermalInfo() override;
70     bool SetScene(const std::string& scene) override;
71     virtual std::string ShellDump(const std::vector<std::string>& args, uint32_t argc) override;
72 
73     int32_t HandleThermalCallbackEvent(const HdfThermalCallbackInfo& event);
74     int32_t HandleFanCallbackEvent(const HdfThermalCallbackInfo& event);
75 
SetFlag(bool flag)76     void SetFlag(bool flag)
77     {
78         flag_ = flag;
79     }
80 
GetFlag()81     bool GetFlag()
82     {
83         return flag_;
84     }
85 
IsServiceReady()86     bool IsServiceReady() const
87     {
88         return ready_;
89     }
90 
GetBaseinfoObj()91     std::shared_ptr<ThermalConfigBaseInfo> GetBaseinfoObj() const
92     {
93         return baseInfo_;
94     }
GetStateMachineObj()95     std::shared_ptr<StateMachine> GetStateMachineObj() const
96     {
97         return state_;
98     }
GetActionManagerObj()99     std::shared_ptr<ThermalActionManager> GetActionManagerObj() const
100     {
101         return actionMgr_;
102     }
GetPolicy()103     std::shared_ptr<ThermalPolicy> GetPolicy() const
104     {
105         return policy_;
106     }
GetObserver()107     std::shared_ptr<ThermalObserver> GetObserver() const
108     {
109         return observer_;
110     }
GetSensorInfo()111     std::shared_ptr<ThermalSensorInfo> GetSensorInfo() const
112     {
113         return info_;
114     }
GetSubscriber()115     std::shared_ptr<ThermalServiceSubscriber> GetSubscriber() const
116     {
117         return serviceSubscriber_;
118     }
119 
GetActionPopup()120     std::shared_ptr<ActionPopup> GetActionPopup() const
121     {
122         return popup_;
123     }
124 
GetThermalInterface()125     sptr<IThermalInterface> GetThermalInterface() const
126     {
127         return thermalInterface_;
128     }
129 
GetSimulationXml()130     bool GetSimulationXml()
131     {
132         return isSimulation_;
133     }
134 
SetSimulationXml(bool isSimulation)135     void SetSimulationXml(bool isSimulation)
136     {
137         isSimulation_ = isSimulation;
138     }
139 
GetFanFaultDetect()140     std::shared_ptr<FanFaultDetect> GetFanFaultDetect() const
141     {
142         return fanFaultDetect_;
143     }
144 
GetScene()145     std::string GetScene()
146     {
147         return scene_;
148     }
149 
InitSystemTestModules()150     void InitSystemTestModules()
151     {
152         InitConfigModule();
153     }
154 private:
155     bool Init();
156     bool InitThermalDriver();
157     bool InitThermalObserver();
158     bool InitThermalAction();
159     bool InitThermalPolicy();
160     bool InitBaseInfo();
161     bool InitSensorCluser();
162     bool InitActionManager();
163     bool InitStateMachine();
164     bool InitModules();
165     bool InitConfigFile();
166     bool InitConfigModule();
167     bool CreateConfigModule();
168     void RegisterHdiStatusListener();
169     void RegisterThermalHdiCallback();
170     void RegisterFanHdiCallback();
171     void RegisterBootCompletedCallback();
172     bool ready_ {false};
173     static std::atomic_bool isBootCompleted_;
174     bool isSimulation_ {false};
175     std::mutex mutex_;
176     std::shared_ptr<ThermalServiceSubscriber> serviceSubscriber_ {nullptr};
177     std::shared_ptr<ThermalObserver> observer_ {nullptr};
178     std::shared_ptr<ThermalSensorInfo> info_ {nullptr};
179     std::shared_ptr<ThermalPolicy> policy_ {nullptr};
180     std::shared_ptr<ThermalConfigBaseInfo> baseInfo_ {nullptr};
181     std::shared_ptr<StateMachine> state_ {nullptr};
182     std::shared_ptr<ThermalActionManager> actionMgr_ {nullptr};
183     std::shared_ptr<FanFaultDetect> fanFaultDetect_ {nullptr};
184     bool flag_ {false};
185     sptr<IThermalInterface> thermalInterface_ {nullptr};
186     sptr<IServiceManager> hdiServiceMgr_ {nullptr};
187     sptr<HdiServiceStatusListener::IServStatListener> hdiServStatListener_ {nullptr};
188     std::shared_ptr<ActionPopup> popup_;
189     std::string scene_;
190 };
191 } // namespace PowerMgr
192 } // namespace OHOS
193 #endif // THERMAL_SERVICE_H
194