/* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include #include "thermal-helper.h" namespace android { namespace hardware { namespace thermal { namespace V2_0 { namespace implementation { using ::android::sp; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::hardware::thermal::V2_0::IThermal; using ::android::hardware::thermal::V2_0::IThermalChangedCallback; struct CallbackSetting { CallbackSetting(sp callback, bool is_filter_type, TemperatureType_2_0 type) : callback(std::move(callback)), is_filter_type(is_filter_type), type(type) {} sp callback; bool is_filter_type; TemperatureType_2_0 type; }; class Thermal : public IThermal { public: Thermal(); ~Thermal() = default; // Disallow copy and assign. Thermal(const Thermal &) = delete; void operator=(const Thermal &) = delete; // Methods from ::android::hardware::thermal::V1_0::IThermal. Return getTemperatures(getTemperatures_cb _hidl_cb) override; Return getCpuUsages(getCpuUsages_cb _hidl_cb) override; Return getCoolingDevices(getCoolingDevices_cb _hidl_cb) override; // Methods from ::android::hardware::thermal::V2_0::IThermal follow. Return getCurrentTemperatures(bool filterType, TemperatureType_2_0 type, getCurrentTemperatures_cb _hidl_cb) override; Return getTemperatureThresholds(bool filterType, TemperatureType_2_0 type, getTemperatureThresholds_cb _hidl_cb) override; Return registerThermalChangedCallback( const sp &callback, bool filterType, TemperatureType_2_0 type, registerThermalChangedCallback_cb _hidl_cb) override; Return unregisterThermalChangedCallback( const sp &callback, unregisterThermalChangedCallback_cb _hidl_cb) override; Return getCurrentCoolingDevices(bool filterType, CoolingType type, getCurrentCoolingDevices_cb _hidl_cb) override; // Methods from ::android::hidl::base::V1_0::IBase follow. Return debug(const hidl_handle &fd, const hidl_vec &args) override; // Helper function for calling callbacks void sendThermalChangedCallback(const Temperature_2_0 &t); private: ThermalHelper thermal_helper_; void dumpVirtualSensorInfo(std::ostringstream *dump_buf); void dumpThrottlingInfo(std::ostringstream *dump_buf); void dumpThrottlingRequestStatus(std::ostringstream *dump_buf); void dumpPowerRailInfo(std::ostringstream *dump_buf); std::mutex thermal_callback_mutex_; std::vector callbacks_; }; } // namespace implementation } // namespace V2_0 } // namespace thermal } // namespace hardware } // namespace android