Wei Wang | 086a2b2 | 2018-10-22 13:54:33 -0700 | [diff] [blame] | 1 | /* |
| 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 Wang | 5013fe4 | 2021-03-16 19:52:06 +0800 | [diff] [blame] | 16 | |
| 17 | #pragma once |
Wei Wang | 086a2b2 | 2018-10-22 13:54:33 -0700 | [diff] [blame] | 18 | |
Wei Wang | 086a2b2 | 2018-10-22 13:54:33 -0700 | [diff] [blame] | 19 | #include <android/hardware/thermal/2.0/IThermal.h> |
| 20 | #include <android/hardware/thermal/2.0/IThermalChangedCallback.h> |
| 21 | #include <hidl/Status.h> |
| 22 | |
TeYuan Wang | 708a1df | 2022-03-28 20:26:06 +0800 | [diff] [blame] | 23 | #include <mutex> |
| 24 | #include <thread> |
| 25 | |
Wei Wang | 086a2b2 | 2018-10-22 13:54:33 -0700 | [diff] [blame] | 26 | #include "thermal-helper.h" |
| 27 | |
| 28 | namespace android { |
| 29 | namespace hardware { |
| 30 | namespace thermal { |
| 31 | namespace V2_0 { |
| 32 | namespace implementation { |
| 33 | |
| 34 | using ::android::sp; |
| 35 | using ::android::hardware::hidl_vec; |
| 36 | using ::android::hardware::Return; |
| 37 | using ::android::hardware::thermal::V2_0::IThermal; |
| 38 | using ::android::hardware::thermal::V2_0::IThermalChangedCallback; |
| 39 | |
| 40 | struct CallbackSetting { |
| 41 | CallbackSetting(sp<IThermalChangedCallback> callback, bool is_filter_type, |
| 42 | TemperatureType_2_0 type) |
Wei Wang | 197195f | 2021-04-02 16:57:32 -0700 | [diff] [blame] | 43 | : callback(std::move(callback)), is_filter_type(is_filter_type), type(type) {} |
Wei Wang | 086a2b2 | 2018-10-22 13:54:33 -0700 | [diff] [blame] | 44 | sp<IThermalChangedCallback> callback; |
| 45 | bool is_filter_type; |
| 46 | TemperatureType_2_0 type; |
| 47 | }; |
| 48 | |
| 49 | class 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 Wang | dcee68c | 2020-10-21 16:29:37 +0800 | [diff] [blame] | 68 | Return<void> registerThermalChangedCallback( |
| 69 | const sp<IThermalChangedCallback> &callback, bool filterType, TemperatureType_2_0 type, |
| 70 | registerThermalChangedCallback_cb _hidl_cb) override; |
Wei Wang | 086a2b2 | 2018-10-22 13:54:33 -0700 | [diff] [blame] | 71 | Return<void> unregisterThermalChangedCallback( |
TeYuan Wang | 708a1df | 2022-03-28 20:26:06 +0800 | [diff] [blame] | 72 | const sp<IThermalChangedCallback> &callback, |
| 73 | unregisterThermalChangedCallback_cb _hidl_cb) override; |
Wei Wang | 086a2b2 | 2018-10-22 13:54:33 -0700 | [diff] [blame] | 74 | 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 Wang | dcee68c | 2020-10-21 16:29:37 +0800 | [diff] [blame] | 81 | void sendThermalChangedCallback(const Temperature_2_0 &t); |
Wei Wang | 086a2b2 | 2018-10-22 13:54:33 -0700 | [diff] [blame] | 82 | |
| 83 | private: |
| 84 | ThermalHelper thermal_helper_; |
TeYuan Wang | c618626 | 2021-04-27 15:11:44 +0800 | [diff] [blame] | 85 | void dumpVirtualSensorInfo(std::ostringstream *dump_buf); |
| 86 | void dumpThrottlingInfo(std::ostringstream *dump_buf); |
| 87 | void dumpThrottlingRequestStatus(std::ostringstream *dump_buf); |
TeYuan Wang | b8173c1 | 2021-07-08 17:45:58 +0800 | [diff] [blame] | 88 | void dumpPowerRailInfo(std::ostringstream *dump_buf); |
Wei Wang | 086a2b2 | 2018-10-22 13:54:33 -0700 | [diff] [blame] | 89 | 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 |