• 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 "hdi_service_status_listener.h"
29 #include "ithermal_level_callback.h"
30 #include "ithermal_temp_callback.h"
31 #include "state_machine.h"
32 #include "thermal_action_manager.h"
33 #include "thermal_callback.h"
34 #include "thermal_config_base_info.h"
35 #include "thermal_config_sensor_cluster.h"
36 #include "thermal_observer.h"
37 #include "thermal_policy.h"
38 #include "thermal_sensor_info.h"
39 #include "thermal_service_subscriber.h"
40 #include "thermal_srv_config_parser.h"
41 #include "thermal_srv_sensor_info.h"
42 #include "thermal_srv_stub.h"
43 #include "v1_1/ithermal_interface.h"
44 #include "v1_1/thermal_types.h"
45 
46 namespace OHOS {
47 namespace PowerMgr {
48 using TypeTempMap = std::map<std::string, int32_t>;
49 using namespace OHOS::HDI::Thermal::V1_1;
50 using namespace OHOS::HDI::ServiceManager::V1_0;
51 class ThermalService final : public SystemAbility, public ThermalSrvStub {
52     DECLARE_SYSTEM_ABILITY(ThermalService);
53     DECLARE_DELAYED_SP_SINGLETON(ThermalService);
54 
55 public:
56     virtual void OnStart() override;
57     virtual void OnStop() override;
58     virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
59     virtual int32_t Dump(int fd, const std::vector<std::u16string>& args) override;
60     bool SubscribeThermalTempCallback(
61         const std::vector<std::string>& typeList, const sptr<IThermalTempCallback>& callback) override;
62     bool UnSubscribeThermalTempCallback(const sptr<IThermalTempCallback>& callback) override;
63     bool SubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback) override;
64     bool UnSubscribeThermalLevelCallback(const sptr<IThermalLevelCallback>& callback) override;
65     bool SubscribeThermalActionCallback(const std::vector<std::string>& actionList, const std::string& desc,
66         const sptr<IThermalActionCallback>& callback) override;
67     bool UnSubscribeThermalActionCallback(const sptr<IThermalActionCallback>& callback) override;
68     bool GetThermalSrvSensorInfo(const SensorType& type, ThermalSrvSensorInfo& sensorInfo) override;
69     bool GetThermalLevel(ThermalLevel& level) override;
70     bool GetThermalInfo() override;
71     bool SetScene(const std::string& scene) override;
72     bool UpdateThermalState(const std::string& tag, const std::string& val, bool isImmed = false) override;
73     bool CreateConfigModule();
74     virtual std::string ShellDump(const std::vector<std::string>& args, uint32_t argc) override;
75 
76     int32_t HandleThermalCallbackEvent(const HdfThermalCallbackInfo& event);
77     int32_t HandleFanCallbackEvent(const HdfThermalCallbackInfo& event);
78 
SetFlag(bool flag)79     void SetFlag(bool flag)
80     {
81         flag_ = flag;
82     }
83 
GetFlag()84     bool GetFlag()
85     {
86         return flag_;
87     }
88 
IsServiceReady()89     bool IsServiceReady() const
90     {
91         return ready_;
92     }
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     }
122 
GetActionPopup()123     std::shared_ptr<ActionPopup> GetActionPopup() const
124     {
125         return popup_;
126     }
127 
GetThermalInterface()128     sptr<IThermalInterface> GetThermalInterface() const
129     {
130         return thermalInterface_;
131     }
132 
GetSimulationXml()133     bool GetSimulationXml()
134     {
135         return isSimulation_;
136     }
137 
SetSimulationXml(bool isSimulation)138     void SetSimulationXml(bool isSimulation)
139     {
140         isSimulation_ = isSimulation;
141     }
142 
GetFanFaultDetect()143     std::shared_ptr<FanFaultDetect> GetFanFaultDetect() const
144     {
145         return fanFaultDetect_;
146     }
147 
GetConfigParser()148     ThermalSrvConfigParser& GetConfigParser()
149     {
150         return configParser_;
151     }
152 
GetScene()153     std::string GetScene()
154     {
155         return scene_;
156     }
157 
InitSystemTestModules()158     void InitSystemTestModules()
159     {
160         InitConfigModule();
161     }
162 private:
163     bool Init();
164     bool InitThermalDriver();
165     bool InitThermalObserver();
166     bool InitThermalAction();
167     bool InitThermalPolicy();
168     bool InitBaseInfo();
169     bool InitSensorCluser();
170     bool InitActionManager();
171     bool InitStateMachine();
172     bool InitModules();
173     bool InitConfigFile();
174     bool InitConfigModule();
175     void RegisterHdiStatusListener();
176     void RegisterThermalHdiCallback();
177     void RegisterFanHdiCallback();
178     void RegisterBootCompletedCallback();
179     bool ready_ {false};
180     static std::atomic_bool isBootCompleted_;
181     bool isSimulation_ {false};
182     std::mutex mutex_;
183     std::shared_ptr<ThermalServiceSubscriber> serviceSubscriber_ {nullptr};
184     std::shared_ptr<ThermalObserver> observer_ {nullptr};
185     std::shared_ptr<ThermalSensorInfo> info_ {nullptr};
186     std::shared_ptr<ThermalPolicy> policy_ {nullptr};
187     std::shared_ptr<ThermalConfigBaseInfo> baseInfo_ {nullptr};
188     std::shared_ptr<StateMachine> state_ {nullptr};
189     std::shared_ptr<ThermalActionManager> actionMgr_ {nullptr};
190     std::shared_ptr<FanFaultDetect> fanFaultDetect_ {nullptr};
191     ThermalSrvConfigParser configParser_;
192     bool flag_ {false};
193     sptr<IThermalInterface> thermalInterface_ {nullptr};
194     sptr<IServiceManager> hdiServiceMgr_ {nullptr};
195     sptr<HdiServiceStatusListener::IServStatListener> hdiServStatListener_ {nullptr};
196     std::shared_ptr<ActionPopup> popup_;
197     std::string scene_;
198     std::atomic<bool> serviceConfigParsed {false};
199 };
200 } // namespace PowerMgr
201 } // namespace OHOS
202 #endif // THERMAL_SERVICE_H
203