blob: 36e079e79d6bb2fec0111302e5f8a47b61b9bb8b [file] [log] [blame]
Wei Wang086a2b22018-10-22 13:54:33 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
TeYuan Wang5013fe42021-03-16 19:52:06 +080016
17#pragma once
Wei Wang086a2b22018-10-22 13:54:33 -070018
Wei Wang086a2b22018-10-22 13:54:33 -070019#include <android/hardware/thermal/2.0/IThermal.h>
20#include <android/hardware/thermal/2.0/IThermalChangedCallback.h>
21#include <hidl/Status.h>
22
TeYuan Wang708a1df2022-03-28 20:26:06 +080023#include <mutex>
24#include <thread>
25
Wei Wang086a2b22018-10-22 13:54:33 -070026#include "thermal-helper.h"
27
28namespace android {
29namespace hardware {
30namespace thermal {
31namespace V2_0 {
32namespace implementation {
33
34using ::android::sp;
35using ::android::hardware::hidl_vec;
36using ::android::hardware::Return;
37using ::android::hardware::thermal::V2_0::IThermal;
38using ::android::hardware::thermal::V2_0::IThermalChangedCallback;
39
40struct CallbackSetting {
41 CallbackSetting(sp<IThermalChangedCallback> callback, bool is_filter_type,
42 TemperatureType_2_0 type)
Wei Wang197195f2021-04-02 16:57:32 -070043 : callback(std::move(callback)), is_filter_type(is_filter_type), type(type) {}
Wei Wang086a2b22018-10-22 13:54:33 -070044 sp<IThermalChangedCallback> callback;
45 bool is_filter_type;
46 TemperatureType_2_0 type;
47};
48
49class Thermal : public IThermal {
50 public:
51 Thermal();
52 ~Thermal() = default;
53
54 // Disallow copy and assign.
55 Thermal(const Thermal &) = delete;
56 void operator=(const Thermal &) = delete;
57
58 // Methods from ::android::hardware::thermal::V1_0::IThermal.
59 Return<void> getTemperatures(getTemperatures_cb _hidl_cb) override;
60 Return<void> getCpuUsages(getCpuUsages_cb _hidl_cb) override;
61 Return<void> getCoolingDevices(getCoolingDevices_cb _hidl_cb) override;
62
63 // Methods from ::android::hardware::thermal::V2_0::IThermal follow.
64 Return<void> getCurrentTemperatures(bool filterType, TemperatureType_2_0 type,
65 getCurrentTemperatures_cb _hidl_cb) override;
66 Return<void> getTemperatureThresholds(bool filterType, TemperatureType_2_0 type,
67 getTemperatureThresholds_cb _hidl_cb) override;
TeYuan Wangdcee68c2020-10-21 16:29:37 +080068 Return<void> registerThermalChangedCallback(
69 const sp<IThermalChangedCallback> &callback, bool filterType, TemperatureType_2_0 type,
70 registerThermalChangedCallback_cb _hidl_cb) override;
Wei Wang086a2b22018-10-22 13:54:33 -070071 Return<void> unregisterThermalChangedCallback(
TeYuan Wang708a1df2022-03-28 20:26:06 +080072 const sp<IThermalChangedCallback> &callback,
73 unregisterThermalChangedCallback_cb _hidl_cb) override;
Wei Wang086a2b22018-10-22 13:54:33 -070074 Return<void> getCurrentCoolingDevices(bool filterType, CoolingType type,
75 getCurrentCoolingDevices_cb _hidl_cb) override;
76
77 // Methods from ::android::hidl::base::V1_0::IBase follow.
78 Return<void> debug(const hidl_handle &fd, const hidl_vec<hidl_string> &args) override;
79
80 // Helper function for calling callbacks
TeYuan Wangdcee68c2020-10-21 16:29:37 +080081 void sendThermalChangedCallback(const Temperature_2_0 &t);
Wei Wang086a2b22018-10-22 13:54:33 -070082
83 private:
84 ThermalHelper thermal_helper_;
TeYuan Wangc6186262021-04-27 15:11:44 +080085 void dumpVirtualSensorInfo(std::ostringstream *dump_buf);
86 void dumpThrottlingInfo(std::ostringstream *dump_buf);
87 void dumpThrottlingRequestStatus(std::ostringstream *dump_buf);
TeYuan Wangb8173c12021-07-08 17:45:58 +080088 void dumpPowerRailInfo(std::ostringstream *dump_buf);
Wei Wang086a2b22018-10-22 13:54:33 -070089 std::mutex thermal_callback_mutex_;
90 std::vector<CallbackSetting> callbacks_;
91};
92
93} // namespace implementation
94} // namespace V2_0
95} // namespace thermal
96} // namespace hardware
97} // namespace android